List of usage examples for javax.xml.namespace QName getLocalPart
public String getLocalPart()
Get the local part of this QName
.
From source file:org.apache.axis.wsdl.fromJava.Emitter.java
/** * Create a Part//w w w.j a va 2 s . c o m * * @param def * @param msg * @param request message is for a request * @param param ParamRep object * @return The parameter name added or null * @throws WSDLException * @throws AxisFault */ public String writePartToMessage(Definition def, Message msg, boolean request, ParameterDesc param) throws WSDLException, AxisFault { // Return if this is a void type if ((param == null) || (param.getJavaType() == java.lang.Void.TYPE)) { return null; } // If Request message, only continue if IN or INOUT // If Response message, only continue if OUT or INOUT if (request && (param.getMode() == ParameterDesc.OUT)) { return null; } if (!request && (param.getMode() == ParameterDesc.IN)) { return null; } // Create the Part Part part = def.createPart(); if (param.getDocumentation() != null) { part.setDocumentationElement(createDocumentationElement(param.getDocumentation())); } // Get the java type to represent in the wsdl // (if the mode is OUT or INOUT and this // parameter does not represent the return type, // the type held in the Holder is the one that should // be written.) Class javaType = param.getJavaType(); if ((param.getMode() != ParameterDesc.IN) && (param.getIsReturn() == false)) { javaType = JavaUtils.getHolderValueType(javaType); } if ((use == Use.ENCODED) || (style == Style.RPC)) { // Add the type representing the param // Write <part name=param_name type=param_type> QName typeQName = param.getTypeQName(); if (javaType != null) { typeQName = types.writeTypeAndSubTypeForPart(javaType, typeQName); } // types.writeElementForPart(javaType, param.getTypeQName()); if (typeQName != null) { part.setName(param.getName()); part.setTypeName(typeQName); msg.addPart(part); } } else if (use == Use.LITERAL) { // This is doc/lit. So we should write out an element // declaration whose name and type may be found in the // ParameterDesc. QName qname = param.getQName(); if (param.getTypeQName() == null) { log.warn(Messages.getMessage("registerTypeMappingFor01", param.getJavaType().getName())); QName qName = types.writeTypeForPart(param.getJavaType(), null); if (qName != null) { param.setTypeQName(qName); } else { param.setTypeQName(Constants.XSD_ANYTYPE); } } if (param.getTypeQName().getNamespaceURI().equals("")) { param.setTypeQName(new QName(intfNS, param.getTypeQName().getLocalPart())); } if (param.getQName().getNamespaceURI().equals("")) { qname = new QName(intfNS, param.getQName().getLocalPart()); param.setQName(qname); } // Make sure qname's value is unique. ArrayList names = (ArrayList) usedElementNames.get(qname.getNamespaceURI()); if (names == null) { names = new ArrayList(1); usedElementNames.put(qname.getNamespaceURI(), names); } else if (names.contains(qname.getLocalPart())) { qname = new QName(qname.getNamespaceURI(), JavaUtils.getUniqueValue(names, qname.getLocalPart())); } names.add(qname.getLocalPart()); types.writeElementDecl(qname, param.getJavaType(), param.getTypeQName(), false, param.getItemQName()); part.setName(param.getName()); part.setElementName(qname); msg.addPart(part); } // return the name of the parameter added return param.getName(); }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Loads the types from the input schema file. * * @param inputSchema file or URL/*from ww w . j a va 2 s.c o m*/ * @throws IOException * @throws WSDLException * @throws SAXException * @throws ParserConfigurationException */ public void loadInputSchema(String inputSchema) throws IOException, WSDLException, SAXException, ParserConfigurationException { // Read the input wsdl file into a Document Document doc = XMLUtils.newDocument(inputSchema); // Ensure that the root element is xsd:schema Element root = doc.getDocumentElement(); if (root.getLocalName().equals("schema") && Constants.isSchemaXSD(root.getNamespaceURI())) { Node schema = docHolder.importNode(root, true); if (null == wsdlTypesElem) { writeWsdlTypesElement(); } wsdlTypesElem.appendChild(schema); // Create a symbol table and populate it with the input types BaseTypeMapping btm = new BaseTypeMapping() { public String getBaseName(QName qNameIn) { QName qName = new QName(qNameIn.getNamespaceURI(), qNameIn.getLocalPart()); Class cls = defaultTM.getClassForQName(qName); if (cls == null) { return null; } else { return JavaUtils.getTextClassName(cls.getName()); } } }; SymbolTable symbolTable = new SymbolTable(btm, true, false, false); symbolTable.populateTypes(new URL(inputSchema), doc); processSymTabEntries(symbolTable); } else { // If not, we'll just bail out... perhaps we should log a warning // or throw an exception? ; } }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Load the types from the input wsdl file. * * @param inputWSDL file or URL//ww w .j av a 2s. com * @throws IOException * @throws WSDLException * @throws SAXException * @throws ParserConfigurationException */ public void loadInputTypes(String inputWSDL) throws IOException, WSDLException, SAXException, ParserConfigurationException { // Read the input wsdl file into a Document Document doc = XMLUtils.newDocument(inputWSDL); // Search for the 'types' element NodeList elements = doc.getChildNodes(); if ((elements.getLength() > 0) && elements.item(0).getLocalName().equals("definitions")) { elements = elements.item(0).getChildNodes(); for (int i = 0; (i < elements.getLength()) && (wsdlTypesElem == null); i++) { Node node = elements.item(i); if ((node.getLocalName() != null) && node.getLocalName().equals("types")) { wsdlTypesElem = (Element) node; } } } // If types element not found, there is no need to continue. if (wsdlTypesElem == null) { return; } // Import the types element into the Types docHolder document wsdlTypesElem = (Element) docHolder.importNode(wsdlTypesElem, true); docHolder.appendChild(wsdlTypesElem); // Create a symbol table and populate it with the input wsdl document BaseTypeMapping btm = new BaseTypeMapping() { public String getBaseName(QName qNameIn) { QName qName = new QName(qNameIn.getNamespaceURI(), qNameIn.getLocalPart()); Class cls = tm.getClassForQName(qName); if (cls == null) { return null; } else { return JavaUtils.getTextClassName(cls.getName()); } } }; SymbolTable symbolTable = new SymbolTable(btm, true, false, false); symbolTable.populate(null, doc); processSymTabEntries(symbolTable); }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Write out a type referenced by a part type attribute. * * @param type <code>Class</code> to generate the XML Schema info for * @param qname <code>QName</code> of the type. If null, qname is * defaulted from the class. * @return the QName of the generated Schema type, null if void, * if the Class type cannot be converted to a schema type * then xsd:anytype is returned. * @throws AxisFault//from w w w . ja v a2 s . c o m */ public QName writeTypeForPart(Class type, QName qname) throws AxisFault { // patch by costin to fix an NPE; commented out till we find out what the problem is // if you get NullPointerExceptions in this class, turn it on and submit some // replicable test data to the Axis team via bugzilla /* * if( type==null ) { * return null; * } */ if (type.getName().equals("void")) { return null; } if (Holder.class.isAssignableFrom(type)) { type = JavaUtils.getHolderValueType(type); } // Get the qname if ((qname == null) || (Constants.isSOAP_ENC(qname.getNamespaceURI()) && "Array".equals(qname.getLocalPart()))) { qname = getTypeQName(type); if (qname == null) { throw new AxisFault("Class:" + type.getName()); } } if (!makeTypeElement(type, qname, null)) { qname = Constants.XSD_ANYTYPE; } return qname; }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Write out an element referenced by a part element attribute. * * @param type <code>Class</code> to generate the XML Schema info for * @param qname <code>QName</code> of the element. If null, qname is * defaulted from the class. * @return the QName of the generated Schema type, null if no element * @throws AxisFault//from w ww .j av a 2 s. c o m */ public QName writeElementForPart(Class type, QName qname) throws AxisFault { // patch by costin to fix an NPE; commented out till we find out what the problem is // if you get NullPointerExceptions in this class, turn it on and submit some // replicable test data to the Axis team via bugzilla /* * if( type==null ) { * return null; * } */ if (type.getName().equals("void")) { return null; } if (Holder.class.isAssignableFrom(type)) { type = JavaUtils.getHolderValueType(type); } // Get the qname if ((qname == null) || (Constants.isSOAP_ENC(qname.getNamespaceURI()) && "Array".equals(qname.getLocalPart()))) { qname = getTypeQName(type); if (qname == null) { throw new AxisFault("Class:" + type.getName()); } } // Return null it a simple type (not an element) String nsURI = qname.getNamespaceURI(); if (Constants.isSchemaXSD(nsURI) || (Constants.isSOAP_ENC(nsURI) && !"Array".equals(qname.getLocalPart()))) { return null; } // Make sure a types section is present if (wsdlTypesElem == null) { writeWsdlTypesElement(); } // Write Element, if problems occur return null. if (writeTypeAsElement(type, qname) == null) { qname = null; } return qname; }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Write the element definition for a WRAPPED operation. This will * write out any necessary namespace/schema declarations, an an element * definition with an internal (anonymous) complexType. The name of the * element will be *foo*Request or *foo*Response depending on whether the * request boolean is true. If the operation contains parameters, then * we also generate a >sequence< node underneath the complexType, * and return it for later use by writeWrappedParameter() below. * * @param qname the desired element QName * @param request true if we're writing the request wrapper, false if * writing the response. * @param hasParams true if there are parameters, and thus a sequence * node is needed// w w w. j av a 2s . c o m * @return a DOM Element for the sequence, inside which we'll write the * parameters as elements, or null if there are no parameters * @throws AxisFault */ public Element writeWrapperElement(QName qname, boolean request, boolean hasParams) throws AxisFault { // Make sure a types section is present if (wsdlTypesElem == null) { writeWsdlTypesElement(); } // Write the namespace definition for the wrapper writeTypeNamespace(qname.getNamespaceURI()); // Create an <element> for the wrapper Element wrapperElement = docHolder.createElement("element"); writeSchemaElementDecl(qname, wrapperElement); wrapperElement.setAttribute("name", qname.getLocalPart()); // Create an anonymous <complexType> for the wrapper Element complexType = docHolder.createElement("complexType"); wrapperElement.appendChild(complexType); // If we have parameters in the operation, create a <sequence> // under the complexType and return it. if (hasParams) { Element sequence = docHolder.createElement("sequence"); complexType.appendChild(sequence); return sequence; } return null; }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Write a parameter (a sub-element) into a sequence generated by * writeWrapperElement() above./*from w w w .j a v a2s . c om*/ * * @param sequence the <sequence> in which we're writing * @param name is the name of an element to add to the wrapper element. * @param type is the QName of the type of the element. * @param javaType * @throws AxisFault */ public void writeWrappedParameter(Element sequence, String name, QName type, Class javaType) throws AxisFault { if (javaType == void.class) { return; } // JAX-RPC 1.1 says that byte[] should always be a Base64Binary // This (rather strange) hack will ensure that we don't map it // in to an maxoccurs=unbounded array. if (javaType.isArray() && !javaType.equals(byte[].class)) { type = writeTypeForPart(javaType.getComponentType(), null); } else { type = writeTypeForPart(javaType, type); } if (type == null) { // TODO: throw an Exception!! return; } Element childElem; if (isAnonymousType(type)) { childElem = createElementWithAnonymousType(name, javaType, false, docHolder); } else { // Create the child <element> and add it to the wrapper <sequence> childElem = docHolder.createElement("element"); childElem.setAttribute("name", name); String prefix = namespaces.getCreatePrefix(type.getNamespaceURI()); String prefixedName = prefix + ":" + type.getLocalPart(); childElem.setAttribute("type", prefixedName); // JAX-RPC 1.1 says that byte[] should always be a Base64Binary // This (rather strange) hack will ensure that we don't map it // in to an maxoccurs=unbounded array. if (javaType.isArray() && !javaType.equals(byte[].class)) { childElem.setAttribute("maxOccurs", "unbounded"); } } sequence.appendChild(childElem); }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Method isAnonymousType//from w w w. j a va2 s .c om * * @param type * @return */ private boolean isAnonymousType(QName type) { return type.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) != -1; }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Return the QName of the specified javaType * * @param javaType input javaType Class/*from w ww . j av a 2s. com*/ * @return QName */ public QName getTypeQName(Class javaType) { QName qName = null; // Use the typeMapping information to lookup the qName. qName = tm.getTypeQName(javaType); // If the javaType is an array and the qName is // SOAP_ARRAY, construct the QName using the // QName of the component type if (isArray(javaType) && Constants.equals(Constants.SOAP_ARRAY, qName)) { Class componentType = getComponentType(javaType); // For WS-I BP compliance, we can't use "ArrayOf" as a type prefix // instead use "MyArrayOf" (gag) String arrayTypePrefix = "ArrayOf"; boolean isWSICompliant = JavaUtils .isTrue(AxisProperties.getProperty(Constants.WSIBP11_COMPAT_PROPERTY)); if (isWSICompliant) { arrayTypePrefix = "MyArrayOf"; } // If component namespace uri == targetNamespace // Construct ArrayOf<componentLocalPart> // Else // Construct ArrayOf_<componentPrefix>_<componentLocalPart> QName cqName = getTypeQName(componentType); if (targetNamespace.equals(cqName.getNamespaceURI())) { qName = new QName(targetNamespace, arrayTypePrefix + cqName.getLocalPart()); } else { String pre = namespaces.getCreatePrefix(cqName.getNamespaceURI()); qName = new QName(targetNamespace, arrayTypePrefix + "_" + pre + "_" + cqName.getLocalPart()); } return qName; } // If a qName was not found construct one using the // class name information. if (qName == null) { String pkg = getPackageNameFromFullName(javaType.getName()); String lcl = getLocalNameFromFullName(javaType.getName()); String ns = namespaces.getCreate(pkg); namespaces.getCreatePrefix(ns); String localPart = lcl.replace('$', '_'); qName = new QName(ns, localPart); } return qName; }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Return a string suitable for representing a given QName in the context * of this WSDL document. If the namespace of the QName is not yet * registered, we will register it up in the Definitions. * * @param qname a QName (typically a type) * @return a String containing a standard "ns:localPart" rep of the QName *//* w ww .j av a 2s. co m*/ public String getQNameString(QName qname) { String prefix = namespaces.getCreatePrefix(qname.getNamespaceURI()); return prefix + ":" + qname.getLocalPart(); }