001: package org.objectweb.celtix.bus.wsdl;
002:
003: import java.util.ArrayList;
004: import java.util.HashSet;
005: import java.util.Iterator;
006: import java.util.List;
007: import java.util.Set;
008: import java.util.WeakHashMap;
009:
010: import javax.wsdl.Binding;
011: import javax.wsdl.Definition;
012: import javax.wsdl.Operation;
013: import javax.wsdl.PortType;
014: import javax.xml.namespace.QName;
015:
016: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedAttribute;
017: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedOperation;
018: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedResource;
019: import org.objectweb.celtix.management.Instrumentation;
020:
021: @ManagedResource(componentName="WSDLManager",description="The Celtix bus wsdl model component ",currencyTimeLimit=15,persistPolicy="OnUpdate")
022: public class WSDLManagerInstrumentation implements Instrumentation {
023: private static final String INSTRUMENTED_NAME = "Bus.WSDLManager";
024: private String objectName;
025: private WSDLManagerImpl wsdlManager;
026: private WeakHashMap<Object, Definition> definitionsMap;
027:
028: public WSDLManagerInstrumentation(WSDLManagerImpl wsdl) {
029: wsdlManager = wsdl;
030: objectName = ",name=WSDLManager";
031: definitionsMap = wsdlManager.definitionsMap;
032: }
033:
034: // get the wsdl model information
035:
036: @ManagedAttribute(description="The celtix bus WSDL provider the Service",persistPolicy="OnUpdate")
037: public String[] getServices() {
038: List<String> strList = new ArrayList<String>();
039: Set<Definition> defSet = new HashSet<Definition>(definitionsMap
040: .values());
041: for (Iterator<Definition> it = defSet.iterator(); it.hasNext();) {
042: Definition definition = it.next();
043: String defName = "Definition: "
044: + definition.getQName().toString();
045: for (Iterator jt = definition.getServices().keySet()
046: .iterator(); jt.hasNext();) {
047: QName serviceQName = (QName) jt.next();
048: String name = defName + " Service: "
049: + serviceQName.toString();
050: strList.add(name);
051: }
052: }
053: String[] strings = new String[strList.size()];
054: return strList.toArray(strings);
055: }
056:
057: @ManagedAttribute(description="The celtix bus WSDL provider the Bindings",persistPolicy="OnUpdate")
058: public String[] getBindings() {
059: List<String> strList = new ArrayList<String>();
060: Set<Definition> defSet = new HashSet<Definition>(definitionsMap
061: .values());
062: for (Iterator<Definition> it = defSet.iterator(); it.hasNext();) {
063: Definition definition = it.next();
064: String defName = "Definition: "
065: + definition.getQName().toString();
066: for (Iterator jt = definition.getBindings().values()
067: .iterator(); jt.hasNext();) {
068: Binding binding = (Binding) jt.next();
069: String name = defName + " Binding: "
070: + binding.getQName().toString();
071: strList.add(name);
072: }
073: }
074: String[] strings = new String[strList.size()];
075: return strList.toArray(strings);
076: }
077:
078: @ManagedAttribute(description="The celtix bus WSDL provider the PortTypes",persistPolicy="OnUpdate")
079: public String[] getPorts() {
080: List<String> strList = new ArrayList<String>();
081: Set<Definition> defSet = new HashSet<Definition>(definitionsMap
082: .values());
083: for (Iterator<Definition> it = defSet.iterator(); it.hasNext();) {
084: Definition definition = it.next();
085: String defName = "Definition: "
086: + definition.getQName().toString();
087: for (Iterator jt = definition.getPortTypes().values()
088: .iterator(); jt.hasNext();) {
089: PortType port = (PortType) jt.next();
090: String name = defName + " PortType: "
091: + port.getQName().toString();
092: strList.add(name);
093: }
094: }
095: String[] strings = new String[strList.size()];
096: return strList.toArray(strings);
097: }
098:
099: // get the address
100:
101: @ManagedOperation(currencyTimeLimit=30,description="The celtix bus WSDL defined service and port provider operation")
102: public String[] getOperation(String def, String pt) {
103: List<String> strList = new ArrayList<String>();
104: Definition definition = null;
105: PortType port = null;
106: Set<Definition> defSet = new HashSet<Definition>(definitionsMap
107: .values());
108: for (Iterator<Definition> it = defSet.iterator(); it.hasNext();) {
109: definition = it.next();
110: if (def.compareTo(definition.getQName().getLocalPart()) == 0) {
111: for (Iterator jt = definition.getPortTypes().values()
112: .iterator(); jt.hasNext();) {
113: port = (PortType) jt.next();
114: if (pt.compareTo(port.getQName().getLocalPart()) == 0) {
115: break;
116: }
117: }
118: break;
119: }
120: }
121: if (definition != null && port != null) {
122: for (Iterator it = port.getOperations().iterator(); it
123: .hasNext();) {
124: Operation opt = (Operation) it.next();
125: String name = "Operation: " + opt.getName();
126: strList.add(name);
127: }
128: }
129: String[] strings = new String[strList.size()];
130: return strList.toArray(strings);
131: }
132:
133: public String getInstrumentationName() {
134: return INSTRUMENTED_NAME;
135: }
136:
137: public Object getComponent() {
138: return wsdlManager;
139: }
140:
141: public String getUniqueInstrumentationName() {
142: return objectName;
143: }
144:
145: }
|