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.axis2.context.OperationContext.java
/** * Get the name associated with the operation. * * @return The name String// w w w . ja v a 2 s .co m */ public String getOperationName() { String opName = null; if (axisOperation != null) { QName qname = axisOperation.getName(); if (qname != null) { opName = qname.getLocalPart(); } } return opName; }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static String convertToString(QName o) { if (o != null) { return o.getLocalPart(); } else {//from ww w . j av a 2s. co m return ""; } }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static void serializeAnyType(Object value, XMLStreamWriter xmlStreamWriter) throws XMLStreamException { if (value instanceof String) { serializeAnyType("string", value.toString(), xmlStreamWriter); } else if (value instanceof Integer) { serializeAnyType("int", value.toString(), xmlStreamWriter); } else if (value instanceof Boolean) { serializeAnyType("boolean", value.toString(), xmlStreamWriter); } else if (value instanceof URI) { serializeAnyType("anyURI", value.toString(), xmlStreamWriter); } else if (value instanceof Byte) { serializeAnyType("byte", value.toString(), xmlStreamWriter); } else if (value instanceof Date) { serializeAnyType("date", convertToString((Date) value), xmlStreamWriter); } else if (value instanceof Calendar) { serializeAnyType("dateTime", convertToString((Calendar) value), xmlStreamWriter); } else if (value instanceof Time) { serializeAnyType("time", convertToString((Time) value), xmlStreamWriter); } else if (value instanceof Float) { serializeAnyType("float", value.toString(), xmlStreamWriter); } else if (value instanceof Long) { serializeAnyType("long", value.toString(), xmlStreamWriter); } else if (value instanceof Double) { serializeAnyType("double", value.toString(), xmlStreamWriter); } else if (value instanceof Short) { serializeAnyType("short", value.toString(), xmlStreamWriter); } else if (value instanceof BigDecimal) { serializeAnyType("decimal", ((BigDecimal) value).toPlainString(), xmlStreamWriter); } else if (value instanceof DataHandler) { addTypeAttribute(xmlStreamWriter, "base64Binary"); try {// ww w . j a v a 2 s . c o m XMLStreamWriterUtils.writeDataHandler(xmlStreamWriter, (DataHandler) value, null, true); } catch (IOException ex) { throw new XMLStreamException("Unable to read data handler", ex); } } else if (value instanceof QName) { QName qNameValue = (QName) value; String prefix = xmlStreamWriter.getPrefix(qNameValue.getNamespaceURI()); if (prefix == null) { prefix = BeanUtil.getUniquePrefix(); xmlStreamWriter.writeNamespace(prefix, qNameValue.getNamespaceURI()); xmlStreamWriter.setPrefix(prefix, qNameValue.getNamespaceURI()); } String attributeValue = qNameValue.getLocalPart(); if (!prefix.equals("")) { attributeValue = prefix + ":" + attributeValue; } serializeAnyType("QName", attributeValue, xmlStreamWriter); } else if (value instanceof UnsignedByte) { serializeAnyType("unsignedByte", convertToString((UnsignedByte) value), xmlStreamWriter); } else if (value instanceof UnsignedLong) { serializeAnyType("unsignedLong", convertToString((UnsignedLong) value), xmlStreamWriter); } else if (value instanceof UnsignedShort) { serializeAnyType("unsignedShort", convertToString((UnsignedShort) value), xmlStreamWriter); } else if (value instanceof UnsignedInt) { serializeAnyType("unsignedInt", convertToString((UnsignedInt) value), xmlStreamWriter); } else if (value instanceof PositiveInteger) { serializeAnyType("positiveInteger", convertToString((PositiveInteger) value), xmlStreamWriter); } else if (value instanceof NegativeInteger) { serializeAnyType("negativeInteger", convertToString((NegativeInteger) value), xmlStreamWriter); } else if (value instanceof NonNegativeInteger) { serializeAnyType("nonNegativeInteger", convertToString((NonNegativeInteger) value), xmlStreamWriter); } else if (value instanceof NonPositiveInteger) { serializeAnyType("nonPositiveInteger", convertToString((NonPositiveInteger) value), xmlStreamWriter); } else { throw new XMLStreamException("Unknow type can not serialize"); } }
From source file:org.apache.axis2.deployment.util.Utils.java
private static void populateHttpEndpoint(AxisService axisService, AxisEndpoint axisEndpoint, HashMap bindingCache) {/*from www .j a va 2 s. co m*/ String serviceName = axisService.getName(); String name = serviceName + "HttpBinding"; Parameter param = axisService.getParameter(Java2WSDLConstants.REST_BINDING_NAME_OPTION_LONG); if (param != null) { name = (String) param.getValue(); } QName bindingName = new QName(name); AxisBinding axisBinding = (bindingCache != null) ? (AxisBinding) bindingCache.get(name) : null; if (axisBinding == null) { axisBinding = new AxisBinding(); axisBinding.setName(bindingName); axisBinding.setType(WSDL2Constants.URI_WSDL2_HTTP); axisBinding.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, "POST"); Map httpLocationMap = new TreeMap<String, AxisOperation>(new Comparator() { public int compare(Object o1, Object o2) { return (-1 * ((Comparable) o1).compareTo(o2)); } }); for (Iterator iterator = axisService.getChildren(); iterator.hasNext();) { AxisOperation operation = (AxisOperation) iterator.next(); AxisBindingOperation axisBindingOperation = new AxisBindingOperation(); QName operationQName = operation.getName(); axisBindingOperation.setName(operationQName); axisBindingOperation.setAxisOperation(operation); String httpLocation = operationQName.getLocalPart(); String tempParam = null; String tempHTTPMethodParam = null; String tempHTTPLocationParam = null; // dealing with the REST data specified in Service.xml @ service class itself(using annotations) Parameter parameter = operation.getParameter(Constants.JSR311_ANNOTATIONS); JAXRSModel methodModel = (parameter != null && (parameter.getValue() instanceof JAXRSModel)) ? (JAXRSModel) parameter.getValue() : null; // Setting the Produces value in the operation if ((tempParam = Utils.getHTTPOutputSerializationFromservicesXML(operation)) != null) { // first we get produce from services xml if available axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_OUTPUT_SERIALIZATION, tempParam); } else if (methodModel != null && methodModel.getProduces() != null) { // then get it from the JAX-RS if available axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_OUTPUT_SERIALIZATION, methodModel.getProduces()); } //Setting the Consumes value in the operation if ((tempParam = Utils.getHTTPInputSerializationFromServicesXML(operation)) != null) { // first we get Consumes from services xml if available axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION, tempParam); } else if (methodModel != null && methodModel.getConsumes() != null) { // then get it from the JAX-RS if available axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION, methodModel.getConsumes()); } //Setting the HttpMethod in the operation if ((tempHTTPMethodParam = Utils.getHTTPMethodFromServicesXML(operation)) != null) { // first we get Consumes from services xml if available axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, tempHTTPMethodParam); } else if (methodModel != null && (tempHTTPMethodParam = methodModel.getHTTPMethod()) != null) { // then get it from the JAX-RS if available if (tempHTTPMethodParam.equals(Constants.Configuration.HTTP_METHOD_HEAD)) { log.warn("[JAXRS] http method HEAD is not supported by AXIS2 " + operation.getName()); tempHTTPMethodParam = null; // resetting the HTTP Method if it is head } else { axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, tempHTTPMethodParam); } } //setting the Http Location in the operation if ((tempHTTPLocationParam = Utils.getHTTPLoacationFromServicesXML(operation)) == null) { tempHTTPLocationParam = (methodModel != null) ? methodModel.getPath() : null; } if (tempHTTPLocationParam != null && tempHTTPMethodParam != null) { axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, tempHTTPLocationParam); httpLocationMap.put( WSDLUtil.getConstantFromHTTPLocation(tempHTTPLocationParam, tempHTTPMethodParam), operation); } else if (tempHTTPLocationParam != null && tempHTTPMethodParam == null) { axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, tempHTTPLocationParam); httpLocationMap.put(WSDLUtil.getConstantFromHTTPLocation(tempHTTPLocationParam, Constants.Configuration.HTTP_METHOD_POST), operation); } else if (tempHTTPLocationParam == null && tempHTTPMethodParam != null) { axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, httpLocation); httpLocationMap.put(WSDLUtil.getConstantFromHTTPLocation(httpLocation, tempHTTPMethodParam), operation); } else { // default scenario : No REST related params in services XML or source file axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, httpLocation); } axisBinding.addChild(axisBindingOperation.getName(), axisBindingOperation); populateBindingOperation(axisBinding, axisBindingOperation); // resetting my temperory parameters tempParam = null; tempHTTPMethodParam = null; tempHTTPLocationParam = null; } if (!httpLocationMap.isEmpty()) { axisBinding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, httpLocationMap); } if (bindingCache != null) { bindingCache.put(name, axisBinding); } } axisBinding.setParent(axisEndpoint); axisEndpoint.setBinding(axisBinding); }
From source file:org.apache.axis2.description.AxisService.java
/** * Method getOperation./*from w w w .java 2 s. com*/ * * @param operationName * @return Returns AxisOperation. */ public AxisOperation getOperation(QName operationName) { if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) log.debug("Get operation for " + operationName); AxisOperation axisOperation = (AxisOperation) getChild(operationName); if (axisOperation == null) { axisOperation = (AxisOperation) getChild(new QName(getTargetNamespace(), operationName.getLocalPart())); if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) log.debug("Target namespace: " + getTargetNamespace()); } if (axisOperation == null) { axisOperation = (AxisOperation) operationsAliasesMap.get(operationName.getLocalPart()); if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) log.debug("Operations aliases map: " + operationsAliasesMap); } //The operation may be associated with a namespace other than the //target namespace, e.g. if the operation is from an imported wsdl. if (axisOperation == null) { List namespaces = getImportedNamespaces(); if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) log.debug("Imported namespaces: " + namespaces); if (namespaces != null) { Iterator iterator = namespaces.iterator(); while (iterator.hasNext()) { String namespace = (String) iterator.next(); axisOperation = (AxisOperation) getChild(new QName(namespace, operationName.getLocalPart())); if (axisOperation != null) break; } } } if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) log.debug("Found axis operation: " + axisOperation); return axisOperation; }
From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java
private QName generateSchemaTypeforNameCommon(XmlSchemaSequence sequence, String partName, boolean isArrayType, Class<?> type, String classTypeName) throws Exception { QName schemaTypeName = typeTable.getSimpleSchemaTypeName(classTypeName); if (schemaTypeName == null) { schemaTypeName = generateSchema(type); if (isGenerateWrappedArrayTypes && isArrayType) { XmlSchemaElement xmlSchemaElement = new XmlSchemaElement(); xmlSchemaElement.setName(partName + "Wrapper"); xmlSchemaElement.setNillable(true); sequence.getItems().add(xmlSchemaElement); String complexTypeName = schemaTypeName.getLocalPart() + "Wrapper"; XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace); XmlSchemaComplexType xmlSchemaComplexType = null; if (xmlSchema.getTypeByName(complexTypeName) == null) { xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema); XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence(); xmlSchemaComplexType.setParticle(xmlSchemaSequence); xmlSchemaComplexType.setName(complexTypeName); xmlSchema.getItems().add(xmlSchemaComplexType); xmlSchema.getSchemaTypes().add(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()), xmlSchemaComplexType); addContentToMethodSchemaType(xmlSchemaSequence, schemaTypeName, "array", isArrayType); } else { xmlSchemaComplexType = (XmlSchemaComplexType) xmlSchema.getTypeByName(complexTypeName); }/* www . ja v a 2s . co m*/ xmlSchemaElement.setSchemaType(xmlSchemaComplexType); xmlSchemaElement .setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName())); } else { addContentToMethodSchemaType(sequence, schemaTypeName, partName, isArrayType); } String schemaNamespace; schemaNamespace = resolveSchemaNamespace(getQualifiedName(type.getPackage())); addImport(getXmlSchema(schemaNamespace), schemaTypeName); } else { if (isGenerateWrappedArrayTypes && isArrayType) { XmlSchemaElement xmlSchemaElement = new XmlSchemaElement(); xmlSchemaElement.setName(partName + "Wrapper"); xmlSchemaElement.setNillable(true); sequence.getItems().add(xmlSchemaElement); String complexTypeName = schemaTypeName.getLocalPart() + "Wrapper"; XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace); XmlSchemaComplexType xmlSchemaComplexType = null; if (xmlSchema.getTypeByName(complexTypeName) == null) { xmlSchemaComplexType = new XmlSchemaComplexType(xmlSchema); XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence(); xmlSchemaComplexType.setParticle(xmlSchemaSequence); xmlSchemaComplexType.setName(complexTypeName); xmlSchema.getItems().add(xmlSchemaComplexType); xmlSchema.getSchemaTypes().add(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName()), xmlSchemaComplexType); addContentToMethodSchemaType(xmlSchemaSequence, schemaTypeName, "array", isArrayType); } else { xmlSchemaComplexType = (XmlSchemaComplexType) xmlSchema.getTypeByName(complexTypeName); } xmlSchemaElement.setSchemaType(xmlSchemaComplexType); xmlSchemaElement .setSchemaTypeName(new QName(schemaTargetNameSpace, xmlSchemaComplexType.getName())); } else { addContentToMethodSchemaType(sequence, schemaTypeName, partName, isArrayType); } } addImport(getXmlSchema(schemaTargetNameSpace), schemaTypeName); return schemaTypeName; }
From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java
protected void addContentToMethodSchemaType(XmlSchemaSequence sequence, QName schemaTypeName, String paraName, boolean isArray) { XmlSchemaElement elt1 = new XmlSchemaElement(); elt1.setName(paraName);//from w w w .j a va 2s . c om elt1.setSchemaTypeName(schemaTypeName); if (sequence != null) { sequence.getItems().add(elt1); } if (isArray) { elt1.setMaxOccurs(Long.MAX_VALUE); } elt1.setMinOccurs(0); boolean disallowNillables = false; Parameter param = service.getParameter(Java2WSDLConstants.DISALLOW_NILLABLE_ELEMENTS_OPTION_LONG); if (param != null) { disallowNillables = JavaUtils.isTrueExplicitly(param.getValue()); } if (!("int".equals(schemaTypeName.getLocalPart()) || "double".equals(schemaTypeName.getLocalPart()) || "long".equals(schemaTypeName.getLocalPart()) || "boolean".equals(schemaTypeName.getLocalPart()) || "short".equals(schemaTypeName.getLocalPart()) || "float".equals(schemaTypeName.getLocalPart())) && !disallowNillables) { elt1.setNillable(true); } }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
/** * @param part// w w w . j a v a2s .c o m * @param document * @param xsdPrefix * @param namespaceImportsMap * @param namespacePrefixMap * @param cmplxTypeSequence * @param isOutMessage (true is part is referenced by the output clause) * @param boe BindingOperationEntry that caused the creation of this part. */ private void addPartToElement(Part part, Document document, String xsdPrefix, Map namespaceImportsMap, Map namespacePrefixMap, Element cmplxTypeSequence, boolean isOutMessage, BindingOperationEntry boe) { Element child; String elementName = part.getName(); // the type name QName schemaTypeName = part.getTypeName(); if (schemaTypeName != null) { child = document.createElementNS(XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":" + XML_SCHEMA_ELEMENT_LOCAL_NAME); // always child attribute should be in no namespace child.setAttribute("form", "unqualified"); child.setAttribute("nillable", "true"); String prefix; if (XMLSCHEMA_NAMESPACE_URI.equals(schemaTypeName.getNamespaceURI())) { prefix = xsdPrefix; if (log.isDebugEnabled()) { log.debug( "Unable to find a namespace for " + xsdPrefix + ". Creating a new namespace attribute"); } cmplxTypeSequence.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + xsdPrefix, XMLSCHEMA_NAMESPACE_URI); } else { // this schema is a third party one. So we need to have // an import statement in our generated schema String uri = schemaTypeName.getNamespaceURI(); if (!namespaceImportsMap.containsKey(uri)) { // create Element for namespace import Element namespaceImport = document.createElementNS(XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":" + XML_SCHEMA_IMPORT_LOCAL_NAME); namespaceImport.setAttribute(NAMESPACE_URI, uri); // add this to the map namespaceImportsMap.put(uri, namespaceImport); // we also need to associate this uri with a prefix // and include that prefix // in the schema's namspace declarations. So add // theis particular namespace to the // prefix map as well prefix = getTemporaryNamespacePrefix(); namespacePrefixMap.put(uri, prefix); } else { // this URI should be already in the namspace prefix // map prefix = (String) namespacePrefixMap.get(uri); } } child.setAttribute(XSD_NAME, elementName); child.setAttribute(XSD_TYPE, prefix + ":" + schemaTypeName.getLocalPart()); cmplxTypeSequence.appendChild(child); } else { String bindingOperationName = boe.getBindingOperation().getName(); String partName = part.getName(); if (boe.isRPC()) { // see the basic profile 4.4.1 for rpc-literal. // messages parts can have only types throw new WSDLProcessingException("The binding operation " + bindingOperationName + " is RPC/literal. " + "The message parts for this operation must use the type " + "attribute as specificed by " + "WS-I Basic Profile specification (4.4.1). Message part, " + partName + ", violates" + "this rule. Please remove the element attribute " + "and use the type attribute."); } else { // The presense of an element means that a wrapper xsd element is not needed. boe.setWrappedOutput(false); if (log.isDebugEnabled()) { log.debug("The binding operation " + bindingOperationName + " references message part " + partName + ". This part does not use the " + "type attribute, so a wrappering element is not added."); } } } }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
/** * Look deeper in the imports to find the requested Message. Use a HashSet to make * sure we don't traverse the same Definition object twice (avoid recursion). * /*ww w . j a v a 2 s . c o m*/ * @param definition * @param message * @param instances * @return */ private Message getMessage(Definition definition, QName message, Set seen) { Message msg = definition.getMessage(message); if (msg != null) { if (log.isDebugEnabled()) { log.debug("getMessage returning = " + ((message.getLocalPart() != null) ? message.getLocalPart() : "NULL")); } return msg; } seen.add(definition); Iterator iter = definition.getImports().values().iterator(); while (iter.hasNext()) { Vector values = (Vector) iter.next(); for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) { Import wsdlImport = (Import) valuesIter.next(); Definition innerDefinition = wsdlImport.getDefinition(); if (seen.contains(innerDefinition)) { continue; // Skip seen } Message result = getMessage(innerDefinition, message, seen); if (result != null) { return result; } } } if (log.isDebugEnabled()) { log.debug("getMessage: Unable to find message, returning NULL"); } return null; }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
/** * Copies the extension attributes/*from w w w . ja va2 s.c o m*/ * * @param extAttributes * @param description * @param origin */ private void copyExtensionAttributes(Map extAttributes, AxisDescription description, String origin) { QName key; QName value; for (Iterator iterator = extAttributes.keySet().iterator(); iterator.hasNext();) { key = (QName) iterator.next(); if (Constants.URI_POLICY_NS.equals(key.getNamespaceURI()) && "PolicyURIs".equals(key.getLocalPart())) { value = (QName) extAttributes.get(key); String policyURIs = value.getLocalPart(); if (policyURIs.length() != 0) { String[] uris = policyURIs.split(" "); PolicyReference ref; for (int i = 0; i < uris.length; i++) { ref = new PolicyReference(); ref.setURI(uris[i]); if (PORT_TYPE.equals(origin) || PORT_TYPE_OPERATION.equals(origin) || PORT_TYPE_OPERATION_INPUT.equals(origin) || PORT_TYPE_OPERATION_OUTPUT.equals(origin)) { if (description != null) { PolicySubject subject = description.getPolicySubject(); if (subject != null) { subject.attachPolicyReference(ref); } } } } } } } }