001: package org.objectweb.jonas.webapp.jonasadmin.jonasmqconnect.util;
002:
003: import java.util.Iterator;
004: import java.util.Set;
005: import java.util.ArrayList;
006:
007: import javax.management.MalformedObjectNameException;
008: import javax.management.ObjectName;
009:
010: import org.objectweb.jonas.jmx.JonasManagementRepr;
011:
012: public class MqObjectNames {
013:
014: /**
015: * ObjectName of JOnAS MQ connector
016: * @param domainName domain name
017: * @param name connector name
018: * @return ObjectName of JOnAS MQ connector
019: */
020: public static ObjectName getConnectorONByName(String domainName,
021: String name) {
022: try {
023: return ObjectName.getInstance(domainName
024: + ":type=JonasMQConnector,name=" + name);
025: } catch (Exception ex) {
026: ex.printStackTrace();
027: return null;
028: }
029: }
030:
031: /**
032: * ObjectName of all JOnAS MQ connectors deployed in a given JOnAS server
033: * @param domainName domain name
034: * @param serverName server name
035: * @return ObjectName of all JOnAS MQ connectors deployed in a given JOnAS server
036: */
037: public static ObjectName[] getConnectorsON(String domainName,
038: String serverName) {
039: try {
040: ObjectName on = ObjectName.getInstance(domainName
041: + ":type=JonasMQConnector,*");
042: Set set = JonasManagementRepr.queryNames(on, serverName);
043: ObjectName[] list = new ObjectName[set.size()];
044: int j = 0;
045: for (Iterator i = set.iterator(); i.hasNext();) {
046: list[j++] = (ObjectName) i.next();
047: }
048: return list;
049: } catch (Exception ex) {
050: ex.printStackTrace(System.err);
051: return null;
052: }
053: }
054:
055: /**
056: * ObjectName of all JOnAS MQ connectors deployed in a given JOnAS server
057: * @param domainName domain name
058: * @param serverName server name
059: * @return ObjectName list of all JOnAS MQ connectors deployed in a given JOnAS server
060: */
061: public static ArrayList getConnectorsONList(String domainName,
062: String serverName) {
063: try {
064: ObjectName ons = ObjectName.getInstance(domainName
065: + ":type=JonasMQConnector,*");
066: Set set = JonasManagementRepr.queryNames(ons, serverName);
067: ArrayList list = new ArrayList();
068: int j = 0;
069: for (Iterator i = set.iterator(); i.hasNext();) {
070: ObjectName on = (ObjectName) i.next();
071: list.add(on.getKeyProperty("name"));
072: }
073: return list;
074: } catch (Exception ex) {
075: ex.printStackTrace(System.err);
076: return null;
077: }
078: }
079:
080: /**
081: * ObjectName of a MQ destination created by deploying a given MQ connector
082: * @param connector connector name
083: * @param jndiName JNDI name of the MQ destination
084: * @param domainName domain name
085: * @return ObjectName of the MQ destination
086: */
087: public static ObjectName getDestinationON(String domainName,
088: String jndiName, String connector) {
089: try {
090: return new ObjectName(domainName
091: + ":type=MQDestination,name=" + jndiName
092: + ",JonasMQConnector=" + connector);
093: } catch (Exception ex) {
094: ex.printStackTrace(System.err);
095: }
096: return null;
097: }
098:
099: /**
100: * ObjectName of all the destination created by deploying a given MQ connector
101: * @param connector connector name
102: * @param domainName domain name
103: * @return ObjectName of the MQ destination
104: */
105: public static ObjectName getDestinationsON(String domainName,
106: String connector) {
107: try {
108: return new ObjectName(domainName
109: + ":type=MQDestination,JonasMQConnector="
110: + connector + ",*");
111: } catch (Exception ex) {
112: ex.printStackTrace(System.err);
113: }
114: return null;
115: }
116:
117: /**
118: * ObjectName of Mdb
119: * @param connectorON conector ObjectName
120: * @param name the name of the requested MDB
121: * @param serverName JOnAS server name
122: * @return ObjectName of Mdb
123: */
124: public static ObjectName getMdbON(ObjectName connectorON,
125: String name, String serverName) {
126: try {
127: Object[] params = {};
128: String[] signature = {};
129: String[] onMdbs = (String[]) JonasManagementRepr.invoke(
130: connectorON, "listConsumerObjectNames", params,
131: signature, serverName);
132: for (int i = 0; i < onMdbs.length; i++) {
133: ObjectName on = new ObjectName(onMdbs[i]);
134: String onName = on.getKeyProperty("name");
135: if (onName.equals(name)) {
136: return on;
137: }
138: }
139: } catch (Exception ex) {
140: ex.printStackTrace();
141: }
142: return null;
143: }
144:
145: /**
146: * ObjectName of parent connector
147: * @param on ObjectName of ..
148: * @param domainName domain name
149: * @return the ObjectName of the parent connector, or null
150: */
151: public static ObjectName getParentConnectorON(String domainName,
152: ObjectName on) {
153:
154: /*
155: * If on is a connector, simply return it
156: */
157: if ("JonasMQConnector".equals(on.getKeyProperty("type"))) {
158: return on;
159: }
160:
161: /*
162: * Else guess the connector on
163: */
164: ObjectName connectorON = null;
165: try {
166: connectorON = ObjectName.getInstance(domainName
167: + ":type=JonasMQConnector,name="
168: + on.getKeyProperty("JonasMQConnector"));
169: } catch (MalformedObjectNameException e) {
170: // TODO Auto-generated catch block
171: e.printStackTrace(System.err);
172: }
173: return connectorON;
174: }
175:
176: }
|