View Javadoc

1   /***
2    *
3    * Copyright RAJD Consultancy Ltd
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   **/
18  
19  package org.logicblaze.lingo.jmx.remote.jms;
20  
21  import org.apache.activemq.util.IntrospectionSupport;
22  import org.apache.activemq.util.URISupport;
23  
24  import javax.management.remote.JMXServiceURL;
25  
26  import java.io.IOException;
27  import java.net.MalformedURLException;
28  import java.net.URI;
29  import java.net.URISyntaxException;
30  import java.util.Map;
31  
32  /***
33   * @version $Revision: 1.4 $
34   */
35  class JmsJmxConnectorSupport {
36      /***
37       * Default destination prefix
38       */
39      static final String DEFAULT_DESTINATION_PREFIX = "org.logicblaze.jms.jmx.";
40      /***
41       * The default destination server name
42       */
43      static final String MBEAN_SERVER_NAME = "*";
44      /***
45       * The default destination group name
46       */
47      static final String MBEAN_GROUP_NAME = "*";
48  
49      static URI getProviderURL(JMXServiceURL serviceURL) throws IOException {
50          String protocol = serviceURL.getProtocol();
51          if (!"jms".equals(protocol))
52              throw new MalformedURLException("Wrong protocol " + protocol + " expecting jms ");
53          try {
54              String path = serviceURL.getURLPath();
55              while (path.startsWith("/")) {
56                  path = path.substring(1);
57              }
58              return new URI(path);
59          }
60          catch (URISyntaxException e) {
61              e.printStackTrace();
62              throw new IOException(e.toString());
63          }
64      }
65  
66      static void populateProperties(Object value, URI url) throws IOException {
67          String query = url.getQuery();
68          if (query != null) {
69              try {
70                  Map map = URISupport.parseQuery(query);
71                  if (map != null && !map.isEmpty()) {
72                      IntrospectionSupport.setProperties(value, map);
73                  }
74              }
75              catch (URISyntaxException e) {
76                  e.printStackTrace();
77                  throw new IOException(e.toString());
78              }
79  
80          }
81      }
82  
83  }