Example usage for javax.xml.namespace QName getNamespaceURI

List of usage examples for javax.xml.namespace QName getNamespaceURI

Introduction

In this page you can find the example usage for javax.xml.namespace QName getNamespaceURI.

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

From source file:org.apache.axis.MessageContext.java

/**
 * Returns a list of operation descriptors that could may
 * possibly match a body containing an element of the given QName.
 * For non-DOCUMENT, the list of operation descriptors that match
 * the name is returned.  For DOCUMENT, all the operations that have
 * qname as a parameter are returned//from ww w .jav a2  s  . co m
 *
 * @param qname of the first element in the body
 * @return list of operation descriptions
 * @throws AxisFault if the operation names could not be looked up
 */
public OperationDesc[] getPossibleOperationsByQName(QName qname) throws AxisFault {
    if (currentOperation != null) {
        return new OperationDesc[] { currentOperation };
    }

    OperationDesc[] possibleOperations = null;

    if (serviceHandler == null) {
        try {
            if (log.isDebugEnabled()) {
                log.debug(Messages.getMessage("dispatching00", qname.getNamespaceURI()));
            }

            // Try looking this QName up in our mapping table...
            setService(axisEngine.getConfig().getServiceByNamespaceURI(qname.getNamespaceURI()));
        } catch (ConfigurationException e) {
            // Didn't find one...
        }

    }

    if (serviceHandler != null) {
        ServiceDesc desc = serviceHandler.getInitializedServiceDesc(this);

        if (desc != null) {
            if (desc.getStyle() != Style.DOCUMENT) {
                possibleOperations = desc.getOperationsByQName(qname);
            } else {
                // DOCUMENT Style
                // Get all of the operations that have qname as
                // a possible parameter QName
                ArrayList allOperations = desc.getOperations();
                ArrayList foundOperations = new ArrayList();
                for (int i = 0; i < allOperations.size(); i++) {
                    OperationDesc tryOp = (OperationDesc) allOperations.get(i);
                    if (tryOp.getParamByQName(qname) != null) {
                        foundOperations.add(tryOp);
                    }
                }
                if (foundOperations.size() > 0) {
                    possibleOperations = (OperationDesc[]) JavaUtils.convert(foundOperations,
                            OperationDesc[].class);
                }
            }
        }
    }
    return possibleOperations;
}

From source file:org.apache.axis.utils.WSDLUtils.java

/**
 * Return the endpoint address from a <soap:address location="..."> tag
 *///from  w  ww  .  j  ava  2  s  . c  o  m
public static String getAddressFromPort(Port p) {
    // Get the endpoint for a port
    List extensibilityList = p.getExtensibilityElements();
    for (ListIterator li = extensibilityList.listIterator(); li.hasNext();) {
        Object obj = li.next();
        if (obj instanceof SOAPAddress) {
            return ((SOAPAddress) obj).getLocationURI();
        } else if (obj instanceof UnknownExtensibilityElement) {
            //TODO: After WSDL4J supports soap12, change this code
            UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
            QName name = unkElement.getElementType();
            if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP)
                    && name.getLocalPart().equals("address")) {
                return unkElement.getElement().getAttribute("location");
            }
        }
    }
    // didn't find it
    return null;
}

From source file:org.apache.axis.utils.XMLUtils.java

/**
 * Return a string for a particular QName, mapping a new prefix
 * if necessary./*from   ww w .  jav  a2 s . co m*/
 */
public static String getStringForQName(QName qname, Element e) {
    String uri = qname.getNamespaceURI();
    String prefix = getPrefix(uri, e);
    if (prefix == null) {
        int i = 1;
        prefix = "ns" + i;
        while (getNamespace(prefix, e) != null) {
            i++;
            prefix = "ns" + i;
        }
        e.setAttributeNS(Constants.NS_URI_XMLNS, "xmlns:" + prefix, uri);
    }
    return prefix + ":" + qname.getLocalPart();
}

From source file:org.apache.axis.wsdl.fromJava.Emitter.java

/**
 * Create a SOAPHeader element//w w  w.jav  a 2 s . co  m
 */
protected SOAPHeader writeSOAPHeader(ParameterDesc p, QName messageQName, String partName) {
    SOAPHeaderImpl soapHeader = new SOAPHeaderImpl();

    // for now, if its document, it is literal use.
    if (use == Use.ENCODED) {
        soapHeader.setUse("encoded");
        soapHeader.setEncodingStyles(encodingList);
    } else {
        soapHeader.setUse("literal");
    }

    // Set namespace
    if (targetService == null) {
        soapHeader.setNamespaceURI(intfNS);
    } else {
        soapHeader.setNamespaceURI(targetService);
    }
    QName headerQName = p.getQName();
    if ((headerQName != null) && !headerQName.getNamespaceURI().equals("")) {
        soapHeader.setNamespaceURI(headerQName.getNamespaceURI());
    }

    // Set the Message and Part information
    soapHeader.setMessage(messageQName);
    soapHeader.setPart(partName);

    return soapHeader;
}

From source file:org.apache.axis.wsdl.fromJava.Emitter.java

/**
 * Method writeSOAPBody//w ww.ja  v  a  2  s. c o  m
 * 
 * @param operQName 
 * @return 
 */
protected ExtensibilityElement writeSOAPBody(QName operQName) {

    SOAPBody soapBody = new SOAPBodyImpl();

    // for now, if its document, it is literal use.
    if (use == Use.ENCODED) {
        soapBody.setUse("encoded");
        soapBody.setEncodingStyles(encodingList);
    } else {
        soapBody.setUse("literal");
    }

    if (style == Style.RPC) {
        if (targetService == null) {
            soapBody.setNamespaceURI(intfNS);
        } else {
            soapBody.setNamespaceURI(targetService);
        }

        if ((operQName != null) && !operQName.getNamespaceURI().equals("")) {
            soapBody.setNamespaceURI(operQName.getNamespaceURI());
        }
    }

    // The parts attribute will get set if we have headers.
    // This gets done when the Message & parts are generated
    // soapBody.setParts(...);

    return soapBody;
}

From source file:org.apache.axis.wsdl.fromJava.Emitter.java

/**
 * Method writeSOAPFault/* www . j av  a2  s  .co m*/
 * 
 * @param faultDesc 
 * @return 
 */
protected SOAPFault writeSOAPFault(FaultDesc faultDesc) {

    SOAPFault soapFault = new com.ibm.wsdl.extensions.soap.SOAPFaultImpl();

    soapFault.setName(faultDesc.getName());

    if (use != Use.ENCODED) {
        soapFault.setUse("literal");

        // no namespace for literal, gets it from the element
    } else {
        soapFault.setUse("encoded");
        soapFault.setEncodingStyles(encodingList);

        // Set the namespace from the fault QName if it exists
        // otherwise use the target (or interface) namespace
        QName faultQName = faultDesc.getQName();

        if ((faultQName != null) && !faultQName.getNamespaceURI().equals("")) {
            soapFault.setNamespaceURI(faultQName.getNamespaceURI());
        } else {
            if (targetService == null) {
                soapFault.setNamespaceURI(intfNS);
            } else {
                soapFault.setNamespaceURI(targetService);
            }
        }
    }

    return soapFault;
}

From source file:org.apache.axis.wsdl.fromJava.Emitter.java

/**
 * Method qualifyOperation//from w  w  w  .ja  va 2s  . com
 * 
 * @param oper 
 */
private void qualifyOperation(OperationDesc oper) {

    if ((style == Style.WRAPPED) && (use == Use.LITERAL)) {
        QName qname = oper.getElementQName();

        if (qname == null) {
            qname = new QName(intfNS, oper.getName());
        } else if (qname.getNamespaceURI().equals("")) {
            qname = new QName(intfNS, qname.getLocalPart());
        }

        oper.setElementQName(qname);
    }
}

From source file:org.apache.axis.wsdl.fromJava.Emitter.java

/**
 * Method getResponseQName//from w w  w  . ja v a 2  s  .c  o m
 * 
 * @param oper 
 * @return 
 */
protected QName getResponseQName(OperationDesc oper) {

    qualifyOperation(oper);

    QName qname = oper.getElementQName();

    if (qname == null) {
        return new QName(oper.getName() + "Response");
    }

    return new QName(qname.getNamespaceURI(), qname.getLocalPart() + "Response");
}

From source file:org.apache.axis.wsdl.fromJava.Emitter.java

/**
 * Create a Part/* ww  w .  j av a 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//  w  w  w .  j  av a 2 s  .  c om
 * @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?
        ;
    }
}