1 package org.jbpm.bpel.def; 2 3 import java.util.*; 4 5 import javax.wsdl.*; 6 import javax.xml.namespace.QName ; 7 8 import com.ibm.wsdl.Constants; 9 10 import org.jbpm.module.def.ModuleDefinition; 11 import org.jbpm.module.exe.ModuleInstance; 12 13 import org.jbpm.bpel.data.def.ElementTypeInfo; 14 import org.jbpm.bpel.data.def.MessageTypeInfo; 15 import org.jbpm.bpel.data.def.SchemaTypeInfo; 16 import org.jbpm.bpel.def.Import.Type; 17 import org.jbpm.bpel.wsdl.def.PartnerLinkType; 18 import org.jbpm.bpel.wsdl.def.Property; 19 import org.jbpm.bpel.wsdl.util.WsdlUtil; 20 import org.jbpm.bpel.wsdl.xml.WsdlConstants; 21 27 public class ImportsDefinition extends ModuleDefinition { 28 29 private List imports; 30 31 private Map messageTypeInfos; 32 private Map elementTypeInfos; 33 private Map schemaTypeInfos; 34 35 private static final long serialVersionUID = 1L; 36 37 public ImportsDefinition() { 38 } 39 40 public List getImports() { 41 return imports; 42 } 43 44 public void setImports(List imports) { 45 this.imports = imports; 46 } 47 48 public void addImport(Import imp) { 49 if (imports == null) { 50 imports = new ArrayList(); 51 } 52 imports.add(imp); 53 } 54 55 public PartnerLinkType getPartnerLinkType(QName name) { 56 PartnerLinkType partnerLinkType = null; 57 String namespace = name.getNamespaceURI(); 58 for (int i = 0, n = imports.size(); i < n; i++) { 59 Import imp = (Import) imports.get(i); 60 if (namespace.equals(imp.getNamespace()) && imp.getType().equals(Type.WSDL)) { 61 partnerLinkType = WsdlUtil.getPartnerLinkType((Definition) imp.getDocument(), name); 62 if (partnerLinkType != null) break; 63 } 64 } 65 return partnerLinkType; 66 } 67 68 public Property getProperty(QName name) { 69 Property property = null; 70 String namespace = name.getNamespaceURI(); 71 for (int i = 0, n = imports.size(); i < n; i++) { 72 Import imp = (Import) imports.get(i); 73 if (namespace.equals(imp.getNamespace()) && imp.getType().equals(Type.WSDL)) { 74 property = WsdlUtil.getProperty((Definition) imp.getDocument(), name); 75 if (property != null) break; 76 } 77 } 78 return property; 79 } 80 81 public Message getMessage(QName name) { 82 Message message = null; 83 String namespace = name.getNamespaceURI(); 84 for (int i = 0, n = imports.size(); i < n; i++) { 85 Import imp = (Import) imports.get(i); 86 if (namespace.equals(imp.getNamespace()) && imp.getType().equals(Type.WSDL)) { 87 message = ((Definition) imp.getDocument()).getMessage(name); 88 if (message != null) break; 89 } 90 } 91 return message; 92 } 93 94 public PortType getPortType(QName name) { 95 PortType portType = null; 96 String namespace = name.getNamespaceURI(); 97 for (int i = 0, n = imports.size(); i < n; i++) { 98 Import imp = (Import) imports.get(i); 99 if (namespace.equals(imp.getNamespace()) && imp.getType().equals(Type.WSDL)) { 100 portType = ((Definition) imp.getDocument()).getPortType(name); 101 if (portType != null) break; 102 } 103 } 104 return portType; 105 } 106 107 public Binding getBinding(QName name) { 108 Binding binding = null; 109 String namespace = name.getNamespaceURI(); 110 for (int i = 0, n = imports.size(); i < n; i++) { 111 Import imp = (Import) imports.get(i); 112 if (namespace.equals(imp.getNamespace()) && imp.getType().equals(Type.WSDL)) { 113 binding = ((Definition) imp.getDocument()).getBinding(name); 114 if (binding != null) break; 115 } 116 } 117 return binding; 118 } 119 120 public Service getService(QName name) { 121 Service service = null; 122 String namespace = name.getNamespaceURI(); 123 for (int i = 0, n = imports.size(); i < n; i++) { 124 Import imp = (Import) imports.get(i); 125 if (namespace.equals(imp.getNamespace()) && imp.getType().equals(Type.WSDL)) { 126 service = ((Definition) imp.getDocument()).getService(name); 127 if (service != null) break; 128 } 129 } 130 return service; 131 } 132 133 139 public Import getDeclaringImport(QName name, QName type) { 140 String namespace = name.getNamespaceURI(); 141 for (int i = 0, n = imports.size(); i < n; i++) { 142 Import imp = (Import) imports.get(i); 143 if (namespace.equals(imp.getNamespace()) && imp.getType().equals(Type.WSDL)) { 144 Definition def = (Definition) imp.getDocument(); 145 if ((Constants.Q_ELEM_MESSAGE.equals(type) && def.getMessage(name) != null) || 146 (Constants.Q_ELEM_PORT_TYPE.equals(type) && def.getPortType(name) != null) || 147 (WsdlConstants.Q_PARTNER_LINK_TYPE.equals(type) && WsdlUtil.getPartnerLinkType(def, name) != null) || 148 (WsdlConstants.Q_PROPERTY.equals(type) && WsdlUtil.getProperty(def, name) != null) || 149 (Constants.Q_ELEM_BINDING.equals(type) && def.getBinding(name) != null) || 150 (Constants.Q_ELEM_SERVICE.equals(type) && def.getService(name) != null)) { 151 return imp; 152 } 153 } 154 } 155 return null; 156 } 157 158 public MessageTypeInfo getMessageTypeInfo(QName name) { 159 if (messageTypeInfos == null) { 160 messageTypeInfos = new HashMap(); 161 } 162 MessageTypeInfo type = (MessageTypeInfo) messageTypeInfos.get(name); 163 if (type == null) { 164 Message message = getMessage(name); 165 if (message != null) { 166 type = new MessageTypeInfo(message); 167 messageTypeInfos.put(name, type); 168 } 169 } 170 return type; 171 } 172 173 public ElementTypeInfo getElementTypeInfo(QName name) { 174 if (elementTypeInfos == null) { 175 elementTypeInfos = new HashMap(); 176 } 177 ElementTypeInfo type = (ElementTypeInfo) elementTypeInfos.get(name); 178 if (type == null) { 179 type = new ElementTypeInfo(name); 180 elementTypeInfos.put(name, type); 181 } 182 return type; 183 } 184 185 public SchemaTypeInfo getSchemaTypeInfo(QName name) { 186 if (schemaTypeInfos == null) { 187 schemaTypeInfos = new HashMap(); 188 } 189 SchemaTypeInfo type = (SchemaTypeInfo) schemaTypeInfos.get(name); 190 if (type == null) { 191 type = new SchemaTypeInfo(name); 192 schemaTypeInfos.put(name, type); 193 } 194 return type; 195 } 196 197 public ModuleInstance createInstance() { 198 return null; 199 } 200 } 201 | Popular Tags |