List of usage examples for javax.xml.namespace QName getNamespaceURI
public String getNamespaceURI()
Get the Namespace URI of this QName
.
From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java
/** * Generate schema construct for given type * * @param javaType : Class to whcih need to generate Schema * @return : Generated QName/*from w ww . j a v a 2s . c o m*/ */ protected QName generateSchema(Class<?> javaType) throws Exception { String name = getClassName(javaType); QName schemaTypeName = typeTable.getComplexSchemaType(name); if (schemaTypeName == null) { String simpleName = getSimpleClassName(javaType); String packageName = getQualifiedName(javaType.getPackage()); String targetNameSpace = resolveSchemaNamespace(packageName); XmlSchema xmlSchema = getXmlSchema(targetNameSpace); String targetNamespacePrefix = targetNamespacePrefixMap.get(targetNameSpace); if (targetNamespacePrefix == null) { targetNamespacePrefix = generatePrefix(); targetNamespacePrefixMap.put(targetNameSpace, targetNamespacePrefix); } XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema); XmlSchemaSequence sequence = new XmlSchemaSequence(); XmlSchemaComplexContentExtension complexExtension = new XmlSchemaComplexContentExtension(); XmlSchemaElement eltOuter = new XmlSchemaElement(); schemaTypeName = new QName(targetNameSpace, simpleName, targetNamespacePrefix); eltOuter.setName(simpleName); eltOuter.setQName(schemaTypeName); Class<?> sup = javaType.getSuperclass(); if ((sup != null) && (!"java.lang.Object".equals(sup.getName())) && (!"java.lang.Exception".equals(sup.getName())) && !getQualifiedName(sup.getPackage()).startsWith("org.apache.axis2") && !getQualifiedName(sup.getPackage()).startsWith("java.util")) { String superClassName = sup.getName(); String superclassname = getSimpleClassName(sup); String tgtNamespace; String tgtNamespacepfx; QName qName = typeTable.getSimpleSchemaTypeName(superClassName); if (qName != null) { tgtNamespace = qName.getNamespaceURI(); tgtNamespacepfx = qName.getPrefix(); } else { tgtNamespace = resolveSchemaNamespace(getQualifiedName(sup.getPackage())); tgtNamespacepfx = targetNamespacePrefixMap.get(tgtNamespace); QName superClassQname = generateSchema(sup); if (superClassQname != null) { tgtNamespacepfx = superClassQname.getPrefix(); tgtNamespace = superClassQname.getNamespaceURI(); } } if (tgtNamespacepfx == null) { tgtNamespacepfx = generatePrefix(); targetNamespacePrefixMap.put(tgtNamespace, tgtNamespacepfx); } //if the parent class package name is differ from the child if (!((NamespaceMap) xmlSchema.getNamespaceContext()).values().contains(tgtNamespace)) { XmlSchemaImport importElement = new XmlSchemaImport(); importElement.setNamespace(tgtNamespace); xmlSchema.getItems().add(importElement); ((NamespaceMap) xmlSchema.getNamespaceContext()).put(generatePrefix(), tgtNamespace); } QName basetype = new QName(tgtNamespace, superclassname, tgtNamespacepfx); complexExtension.setBaseTypeName(basetype); complexExtension.setParticle(sequence); XmlSchemaComplexContent contentModel = new XmlSchemaComplexContent(); contentModel.setContent(complexExtension); complexType.setContentModel(contentModel); } else { complexType.setParticle(sequence); } complexType.setName(simpleName); if (Modifier.isAbstract(javaType.getModifiers())) { complexType.setAbstract(true); } // xmlSchema.getItems().add(eltOuter); xmlSchema.getElements().add(schemaTypeName, eltOuter); eltOuter.setSchemaTypeName(complexType.getQName()); xmlSchema.getItems().add(complexType); xmlSchema.getSchemaTypes().add(schemaTypeName, complexType); // adding this type to the table typeTable.addComplexSchema(name, eltOuter.getQName()); // adding this type's package to the table, to support inheritance. typeTable.addComplexSchema(getQualifiedName(javaType.getPackage()), eltOuter.getQName()); typeTable.addClassNameForQName(eltOuter.getQName(), name); BeanExcludeInfo beanExcludeInfo = null; if (service.getExcludeInfo() != null) { beanExcludeInfo = service.getExcludeInfo().getBeanExcludeInfoForClass(getClassName(javaType)); } // we need to get properties only for this bean. hence ignore the super // class properties BeanInfo beanInfo = Introspector.getBeanInfo(javaType, javaType.getSuperclass()); for (PropertyDescriptor property : beanInfo.getPropertyDescriptors()) { String propertyName = property.getName(); if (!property.getName().equals("class") && (property.getPropertyType() != null)) { if ((beanExcludeInfo == null) || !beanExcludeInfo.isExcludedProperty(propertyName)) { Type genericFieldType = null; try { Field field = javaType.getDeclaredField(propertyName); genericFieldType = field.getGenericType(); } catch (Exception e) { //log.info(e.getMessage()); } if (genericFieldType instanceof ParameterizedType) { ParameterizedType aType = (ParameterizedType) genericFieldType; Type[] fieldArgTypes = aType.getActualTypeArguments(); try { generateSchemaforGenericFields(xmlSchema, sequence, fieldArgTypes[0], propertyName); } catch (Exception e) { generateSchemaforFieldsandProperties(xmlSchema, sequence, property.getPropertyType(), propertyName, property.getPropertyType().isArray()); } } else { generateSchemaforFieldsandProperties(xmlSchema, sequence, property.getPropertyType(), propertyName, property.getPropertyType().isArray()); } } } } } return schemaTypeName; }
From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java
protected void addImport(XmlSchema xmlSchema, QName schemaTypeName) { NamespacePrefixList map = xmlSchema.getNamespaceContext(); if (map == null || ((map instanceof NamespaceMap) && ((NamespaceMap) map).values() == null) || schemaTypeName == null) { return;//from w w w. j a v a2s . co m } if (map instanceof NamespaceMap && !((NamespaceMap) map).values().contains(schemaTypeName.getNamespaceURI())) { XmlSchemaImport importElement = new XmlSchemaImport(); importElement.setNamespace(schemaTypeName.getNamespaceURI()); xmlSchema.getItems().add(importElement); ((NamespaceMap) xmlSchema.getNamespaceContext()).put(generatePrefix(), schemaTypeName.getNamespaceURI()); } }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
/** * @param part//from w w w . java 2s. c om * @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
/** * Copies the extension attributes/*from w ww . ja v a 2s.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); } } } } } } } }
From source file:org.apache.axis2.jaxws.addressing.factory.impl.Axis2EndpointReferenceFactoryImpl.java
public EndpointReference createEndpointReference(String address, QName serviceName, QName portName, String wsdlDocumentLocation, String addressingNamespace) { EndpointReference axis2EPR = null; if (address != null) { if (serviceName == null && portName != null) { throw new IllegalStateException( Messages.getMessage("axisEndpointReferenceFactoryErr", portName.toString())); }/*from w w w .ja v a2 s . c o m*/ axis2EPR = createEndpointReference(address); } else if (serviceName != null && portName != null) { axis2EPR = createEndpointReference(serviceName, portName); } else { throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr2")); } //TODO If no service name and port name are specified, but the wsdl location is //specified, and the WSDL only contains one service and one port then maybe we //should simply use those. try { //This code is locate here instead of in the createEndpointReference(QName, QName) //method so that if the address is also specified the EPR metadata will still be //filled in correctly. EndpointReferenceUtils.addService(axis2EPR, serviceName, portName, addressingNamespace); if (wsdlDocumentLocation != null) { URL wsdlURL; try { wsdlURL = new URL(wsdlDocumentLocation); } catch (MalformedURLException e) { // just to keep it clean: if (axis2EPR.getAddress().endsWith("/") && wsdlDocumentLocation.startsWith("/")) { wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation.substring(1); } else if (axis2EPR.getAddress().endsWith("/")) { String eprAddress = axis2EPR.getAddress(); wsdlDocumentLocation = eprAddress.substring(0, eprAddress.length() - 1) + wsdlDocumentLocation; } else { wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation; } } wsdlURL = new URL(wsdlDocumentLocation); // This is a temporary usage, so use a memory sensitive wrapper WSDLWrapper wrapper = new WSDL4JWrapper(wsdlURL, true, 2); if (serviceName != null) { QName serviceNameNoTrailingSlash = new QName(""); // TODO: why in the world would we have to do this? if (serviceName.getNamespaceURI().endsWith("/")) { String ns = serviceName.getNamespaceURI(); serviceNameNoTrailingSlash = new QName(ns.substring(0, ns.length() - 1), serviceName.getLocalPart()); } if ((wrapper.getService(serviceName) == null) && (wrapper.getService(serviceNameNoTrailingSlash) == null)) { throw new IllegalStateException(Messages.getMessage("MissingServiceName", serviceName.toString(), wsdlDocumentLocation)); } if (portName != null) { String[] ports = wrapper.getPorts(serviceName); // search the other name. TODO: again, why do we have to do this? if (ports == null) { ports = wrapper.getPorts(serviceNameNoTrailingSlash); } String portLocalName = portName.getLocalPart(); boolean found = false; if (ports != null) { for (String port : ports) { // TODO: axis2 perhaps is deploying with "TypeImplPort" appended, but not reading/honoring the WSDL? if (port.equals(portLocalName) || (port + "TypeImplPort").equals(portLocalName)) { log.debug("found port: " + port); found = true; break; } } } if (!found) { throw new IllegalStateException(Messages.getMessage("MissingPortName", portName.toString(), wsdlDocumentLocation)); } log.debug("Setting wsdlDocumentLocation to " + wsdlDocumentLocation + " for EndpointReference at port " + portName); EndpointReferenceUtils.addLocation(axis2EPR, portName.getNamespaceURI(), wsdlDocumentLocation, addressingNamespace); } } } } catch (IllegalStateException ise) { throw ise; } catch (Exception e) { throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointRefCreationError"), e); } return axis2EPR; }
From source file:org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl.java
/** * @see org.apache.axis2.jaxws.description.DescriptionFactory#updateEndpoint(ServiceDescription, * Class, EndpointReference, String, DescriptionFactory.UpdateType, DescriptionBuilderComposite, Object) */// w w w.j av a2 s . com public static EndpointDescription updateEndpoint(ServiceDescription serviceDescription, Class sei, EndpointReference epr, String addressingNamespace, DescriptionFactory.UpdateType updateType, DescriptionBuilderComposite composite, Object sparseCompositeKey, String bindingId, String endpointAddress) { QName portQName = null; try { ServiceName serviceName = EndpointReferenceHelper.getServiceNameMetadata(epr, addressingNamespace); QName serviceQName = serviceDescription.getServiceQName(); //We need to throw an exception if the service name in the EPR metadata does not //match the service name associated with the JAX-WS service instance. if (serviceName.getName() != null && !serviceQName.equals(serviceName.getName())) { throw ExceptionFactory.makeWebServiceException(Messages.getMessage("serviceNameMismatch", serviceName.getName().toString(), serviceQName.toString())); } //If a port name is available from the EPR metadata then use that, otherwise //leave it to the runtime to find a suitable port, based on WSDL/annotations. if (serviceName.getEndpointName() != null) { portQName = new QName(serviceQName.getNamespaceURI(), serviceName.getEndpointName()); } } catch (Exception e) { throw ExceptionFactory .makeWebServiceException(Messages.getMessage("updateEndpointError", e.getMessage())); } return updateEndpoint(serviceDescription, sei, portQName, updateType, composite, sparseCompositeKey, bindingId, endpointAddress); }
From source file:org.apache.axis2.jaxws.handler.SOAPHeadersAdapter.java
/** * Returns a list of XML strings that have the same namespace as the QName key. The * returned list is not "live"; it manipulating the list will not result in changed * headers on the message.// w w w .j ava 2 s .c om * @param _key Object -- QName key of header XML strings you intend to retrieve */ public List<String> get(Object _key) { // notify the HandlerChainProcessor that a transformation has occurred possibly due to a handler method call into here HandlerChainProcessor.trackInternalCall(mc, HandlerChainProcessor.TRACKER.SOAP_HEADERS_ADAPTER_CALLED); try { if (!(keySet().contains(_key))) { return null; } QName key = (QName) _key; Message m = mc.getMessage(); List<Block> blocks = m.getHeaderBlocks(key.getNamespaceURI(), key.getLocalPart(), null, getXMLStringBlockFactory(), null); if (blocks == null || blocks.size() == 0) { return null; } // Get the strings from the blocks ArrayList<String> xmlStrings = new ArrayList<String>(); for (int i = 0; i < blocks.size(); i++) { Block block = blocks.get(i); String value = (block == null) ? null : (String) block.getBusinessObject(false); xmlStrings.add(value); } return xmlStrings; } catch (Throwable t) { throw ExceptionFactory.makeWebServiceException(t); } }
From source file:org.apache.axis2.jaxws.handler.SOAPHeadersAdapter.java
/** * put will inject the headers into the SOAP message immediately * @param key Object -- QName key of header XML strings you wish to be put on the SOAP header * @param values List<String> -- list of XML strings that have the same namespace as the QName key *///ww w. j a v a 2s .c o m public List<String> put(QName key, List<String> values) { // notify the HandlerChainProcessor that a transformation has occurred possibly due to a handler method call into here HandlerChainProcessor.trackInternalCall(mc, HandlerChainProcessor.TRACKER.SOAP_HEADERS_ADAPTER_CALLED); Message m = mc.getMessage(); if (log.isDebugEnabled()) { log.debug("put(" + key + " , " + values + ")"); } // Get the old value List<String> old = get(key); if (values != null) { if (old != null) { // Replace the existing header blocks m.removeHeaderBlock(key.getNamespaceURI(), key.getLocalPart()); } for (int i = 0; i < values.size(); i++) { String value = values.get(i); Block block = getXMLStringBlockFactory().createFrom(value, null, key); m.appendHeaderBlock(key.getNamespaceURI(), key.getLocalPart(), block); } } return old; }
From source file:org.apache.axis2.jaxws.handler.SOAPHeadersAdapter.java
/** * remove will immediately remove the headers from the SOAP message that match the QName key * @param _key Object -- QName key of header XML strings you wish to remove from the SOAP header *//*from w ww . j av a 2 s . c o m*/ public List<String> remove(Object _key) { // notify the HandlerChainProcessor that a transformation has occurred possibly due to a handler method call into here HandlerChainProcessor.trackInternalCall(mc, HandlerChainProcessor.TRACKER.SOAP_HEADERS_ADAPTER_CALLED); try { if (!(keySet().contains(_key))) { return null; } if (!(_key instanceof QName)) { throw ExceptionFactory.makeWebServiceException("key must be of type " + QName.class.getName()); } QName key = (QName) _key; if (log.isDebugEnabled()) { log.debug("remove(" + key + ")"); } // Get the old value List<String> old = get(key); Message m = mc.getMessage(); List<Block> blocks = m.getHeaderBlocks(key.getNamespaceURI(), key.getLocalPart(), null, getXMLStringBlockFactory(), null); if (blocks == null || blocks.size() == 0) { return null; } // Get the strings from the blocks ArrayList<String> xmlStrings = new ArrayList<String>(); for (Block block : blocks) { String value = (block == null) ? null : (String) block.getBusinessObject(false); xmlStrings.add(value); m.removeHeaderBlock(key.getNamespaceURI(), key.getLocalPart()); } keySet().remove(key); return old; } catch (Throwable t) { throw ExceptionFactory.makeWebServiceException(t); } }
From source file:org.apache.axis2.jaxws.handler.SoapMessageContext.java
public Object[] getHeaders(QName qname, JAXBContext jaxbcontext, boolean allRoles) { if (log.isDebugEnabled()) { log.debug("Getting all Headers for Qname: " + qname); }// w w w . ja v a2s . c o m if (qname == null) { if (log.isDebugEnabled()) { log.debug("Invalid QName, QName cannot be null"); } throw ExceptionFactory.makeWebServiceException(Messages.getMessage("soapMessageContextErr1")); } if (jaxbcontext == null) { if (log.isDebugEnabled()) { log.debug("Invalid JAXBContext, JAXBContext cannot be null"); } throw ExceptionFactory.makeWebServiceException(Messages.getMessage("soapMessageContextErr2")); } // The header information is returned as a list of jaxb objects List<Object> list = new ArrayList<Object>(); String namespace = qname.getNamespaceURI(); String localPart = qname.getLocalPart(); BlockFactory blockFactory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class); Message m = messageCtx.getMessage(); JAXBBlockContext jbc = new JAXBBlockContext(jaxbcontext); // If allRoles is not specified, pass in a set of roles. // The headers must support that role. RolePlayer rolePlayer = null; if (allRoles == false) { rolePlayer = getRolePlayer(); } if (m.getNumHeaderBlocks() > 0) { // Get the list of JAXB Blocks List<Block> blockList = m.getHeaderBlocks(namespace, localPart, jbc, blockFactory, rolePlayer); // Create list of JAXB objects if (blockList != null && blockList.size() > 0) { try { Iterator it = blockList.iterator(); while (it.hasNext()) { Block block = (Block) it.next(); Object bo = block.getBusinessObject(false); if (bo != null) { if (log.isDebugEnabled()) { log.debug("Extracted BO from Header Block"); } list.add(bo); } } } catch (XMLStreamException e) { throw ExceptionFactory.makeWebServiceException(e); } } } return list.toArray(new Object[0]); }