1 19 package org.netbeans.modules.xml.wsdl.ui.api.property; 20 21 import java.util.Collection ; 22 import java.util.List ; 23 24 import javax.xml.namespace.QName ; 25 26 import org.netbeans.modules.xml.schema.model.GlobalElement; 27 import org.netbeans.modules.xml.schema.model.GlobalType; 28 import org.netbeans.modules.xml.schema.model.Schema; 29 import org.netbeans.modules.xml.wsdl.model.Message; 30 import org.netbeans.modules.xml.wsdl.model.Part; 31 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 32 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 33 import org.netbeans.modules.xml.wsdl.ui.api.property.ElementOrTypeOrMessagePartProvider.ParameterType; 34 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility; 35 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 36 37 public class ElementOrTypeOrMessagePart { 38 GlobalElement mElement; 39 GlobalType mType; 40 Part mPart; 41 Message mMessage; 42 QName mQName; 43 ParameterType pType = ParameterType.NONE; 44 WSDLModel mModel; 45 46 public ElementOrTypeOrMessagePart(QName qname, WSDLModel model, ParameterType pType) { 47 this.pType = pType; 48 mQName = qname; 49 mModel = model; 50 List <Schema> schemas = mModel.findSchemas(qname.getNamespaceURI()); 51 if (schemas != null) { 52 for (Schema schema : schemas) { 53 if (pType == ParameterType.ELEMENT) { 54 Collection <GlobalElement> ges = schema.findAllGlobalElements(); 55 if (ges != null) { 56 for (GlobalElement ele : ges) { 57 if (qname.getLocalPart().equals(ele.getName())) { 58 mElement = ele; 59 } 60 } 61 } 62 } else if (pType == ParameterType.TYPE){ 63 Collection <GlobalType> gts = schema.findAllGlobalTypes(); 64 if (gts != null) { 65 for (GlobalType type : gts) { 66 if (qname.getLocalPart().equals(type.getName())) { 67 mType = type; 68 } 69 } 70 } 71 } 72 } 73 } 74 } 75 76 public Part getMessagePart() { 77 return mPart; 78 } 79 80 public ParameterType getParameterType() { 81 return pType; 82 } 83 84 public ElementOrTypeOrMessagePart(QName qname, WSDLModel model, String partName) { 85 pType = ParameterType.MESSAGEPART; 86 mModel = model; 87 mMessage = mModel.findComponentByName(qname, Message.class); 88 if (mMessage != null) { 89 for (Part part : mMessage.getParts()) { 90 if (part.getName().equals(partName)) { 91 mPart = part; 92 break; 93 } 94 } 95 } 96 } 97 98 public ElementOrTypeOrMessagePart(GlobalElement element, WSDLModel model) { 99 mElement = element; 100 mModel = model; 101 pType = ParameterType.ELEMENT; 102 } 103 104 public ElementOrTypeOrMessagePart(GlobalType type, WSDLModel model) { 105 mType= type; 106 mModel = model; 107 pType = ParameterType.TYPE; 108 } 109 110 public ElementOrTypeOrMessagePart(Part part, WSDLModel model) { 111 mPart= part; 112 mMessage = (Message) part.getParent(); 113 mModel = model; 114 pType = ParameterType.MESSAGEPART; 115 } 116 117 public GlobalElement getElement() { 118 return mElement; 119 } 120 121 public GlobalType getType() { 122 return mType; 123 } 124 125 @Override 126 public String toString() { 127 if (mQName != null) { 128 return Utility.fromQNameToString(mQName); 129 } 130 131 String namespace = null; 132 String localPart = null; 133 if (mElement != null) { 134 namespace = mElement.getModel().getSchema().getTargetNamespace(); 135 localPart = mElement.getName(); 136 } 137 if (mType != null) { 138 namespace = mType.getModel().getSchema().getTargetNamespace(); 139 localPart = mType.getName(); 140 } 141 142 if (mMessage != null) { 143 namespace = mMessage.getModel().getDefinitions().getTargetNamespace(); 144 localPart = mMessage.getName(); 145 } 146 147 if (namespace == null) { 148 return localPart; 149 } 150 if (mModel == null) { 151 return new QName (namespace, localPart).toString(); 152 } 153 String namespacePrefix = Utility.getNamespacePrefix(namespace, mModel); 154 if (namespacePrefix == null) { 155 namespacePrefix = NameGenerator.getInstance().generateNamespacePrefix(null, mModel); 156 boolean isInTransaction = Utility.startTransaction(mModel); 157 ((AbstractDocumentComponent)mModel.getDefinitions()).addPrefix(namespacePrefix, namespace); 158 159 Utility.endTransaction(mModel, isInTransaction); 160 } 161 if (pType == ParameterType.MESSAGEPART) { 162 return namespacePrefix + ":" + localPart + "/" + mPart.getName(); 163 } 164 return namespacePrefix + ":" + localPart; 165 } 166 } 167 | Popular Tags |