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.axis2.jaxws.spi.handler.BaseHandlerResolver.java

/**
 * The old match algorithm combines the namespace and localpart into
 * a single string to do the matching.  Unfortunately this will cause
 * the pure wildcard (*) pattern to fail.  And in addition, it may cause
 * other patterns to succeed.  Prefer the doesPatternMatch_Official algorithm
 * @param portInfoQName/*from  w  ww. j  av a2s .co m*/
 * @param pattern
 * @return
 */
private static boolean doesPatternMatch_Old(QName portInfoQName, QName pattern) {
    if (pattern == null)
        return true;

    // build up the strings according to the regular expression defined at http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd
    // use the prefix, not the literal namespace
    String portInfoPrefix = portInfoQName.getNamespaceURI(); //Prefix();
    String portInfoLocalPart = portInfoQName.getLocalPart();
    String portInfoString = ((portInfoPrefix == null) || (portInfoPrefix.equals(""))) ? ""
            : portInfoPrefix + ":";
    portInfoString += portInfoLocalPart;

    String patternStringPrefix = pattern.getNamespaceURI(); //Prefix();
    String patternInfoLocalPart = pattern.getLocalPart();
    String patternString = ((patternStringPrefix == null) || (patternStringPrefix.equals(""))) ? ""
            : patternStringPrefix + ":";
    patternString += patternInfoLocalPart;

    // now match the portInfoQName to the user pattern
    // But first, convert the user pattern to a regular expression.  Remember, the only non-QName character allowed is "*", which
    // is a wildcard, with obvious restrictions on what characters can match (for example, a .java filename cannot contain perentheses).
    // We'll just use part of the above reg ex to form the appropriate restrictions on the user-specified "*" character:
    Pattern userp = Pattern.compile(patternString.replace("*", "(\\w|\\.|-|_)*"));
    Matcher userm = userp.matcher(portInfoString);
    boolean match = userm.matches();
    if (log.isDebugEnabled()) {
        if (!match) {
            log.debug("Pattern match failed: \"" + portInfoString + "\" does not match \"" + patternString
                    + "\"");
        } else {
            log.debug("Pattern match succeeded: \"" + portInfoString + "\" matches \"" + patternString + "\"");
        }
    }
    return match;

}

From source file:org.apache.axis2.jaxws.spi.handler.BaseHandlerResolver.java

/**
 * Determine if the indicated qname matches the pattern
 * @param qName/*from  w  w w. j a v  a  2s  .c o  m*/
 * @param pattern
 * @return
 */
private static boolean doesPatternMatch_Official(QName qName, QName pattern) {
    if (log.isDebugEnabled()) {
        log.debug("entry pattern=" + pattern + " qname=" + qName);
    }
    if (pattern == null) {
        if (log.isDebugEnabled()) {
            log.debug("Successful Match: Pattern is null");
        }
        return true;
    }

    // Do a pattern match on the local part of the qname.
    String patternLocalPart = pattern.getLocalPart();
    String localPart = qName.getLocalPart();

    // Replace the wildcard (*) references in the QName with an appropriate regular expression.
    String regEx = patternLocalPart.replace("*", "(\\w|\\.|-|_)*");
    Pattern userp = Pattern.compile(regEx);
    Matcher userm = userp.matcher(localPart);
    boolean match = userm.matches();
    if (!match) {
        if (log.isDebugEnabled()) {
            log.debug("No Match: The local name does not match the regex pattern: " + regEx);
        }
        return false;
    }

    // Now do the matching with the namespace.
    // If the entire pattern is a wildcard (*), then all namespaces are acceptable.
    // For example:
    //     <port-name-pattern>*</port-name-pattern>
    // 
    // In such cases, the assumption is that the pattern namespace will be empty.
    String patternNamespace = pattern.getNamespaceURI();
    String namespace = qName.getNamespaceURI();
    if (patternNamespace.length() == 0) { // By definition, a namespace will never be null.
        if (log.isDebugEnabled()) {
            log.debug("Successful Match: The local name matches and the pattern namespace is empty.");
        }
        return true;
    }

    // If a namespace is specified, it will be done via a prefix.  For example:
    //    <port-name-pattern>p:MyPortName</port-name-pattern>
    // Thus according to the current pattern structure there is no way to 
    // specify wildcards for the namespace portion of the match
    if (patternNamespace.equals(namespace)) {
        if (log.isDebugEnabled()) {
            log.debug("Successful Match: The local names and namespaces match.");
        }
        return true;
    }

    if (log.isDebugEnabled()) {
        log.debug("No Match");
    }
    return false;
}

From source file:org.apache.axis2.json.gson.GsonXMLStreamReader.java

private void processSchemaUpdates(QName elementQname, List<XmlSchema> xmlSchemaList,
        ConfigurationContext configContext) {
    Object ob = configContext.getProperty(JsonConstant.CURRENT_XML_SCHEMA);
    if (ob != null) {
        Map<QName, XmlSchema> schemaMap = (Map<QName, XmlSchema>) ob;
        if (schemaMap != null) {
            XmlSchema currentXmlSchema = schemaMap.get(elementQname);
            for (XmlSchema xmlSchema : xmlSchemaList) {
                if (xmlSchema.getTargetNamespace().equals(elementQname.getNamespaceURI())) {
                    if (currentXmlSchema != xmlSchema) {
                        schemaMap.put(elementQname, xmlSchema);
                        configContext.setProperty(JsonConstant.XMLNODES, null);
                        if (log.isDebugEnabled()) {
                            log.debug("Updating message schema. [Current:" + currentXmlSchema + ", New:"
                                    + xmlSchema + "]");
                        }//from   www  .j a  v a2 s  .  co m
                    }
                    break;
                }
            }
        }
    } else {
        Map<QName, XmlSchema> schemaMap = new HashMap<QName, XmlSchema>();
        for (XmlSchema xmlSchema : xmlSchemaList) {
            if (xmlSchema.getTargetNamespace().equals(elementQname.getNamespaceURI())) {
                schemaMap.put(elementQname, xmlSchema);
                configContext.setProperty(JsonConstant.CURRENT_XML_SCHEMA, schemaMap);
                break;
            }
        }
    }
}

From source file:org.apache.axis2.rpc.receivers.RPCMessageReceiver.java

/**
 * reflect and get the Java method - for each i'th param in the java method - get the first
 * child's i'th child -if the elem has an xsi:type attr then find the deserializer for it - if
 * not found, lookup deser for th i'th param (java type) - error if not found - deserialize &
 * save in an object array - end for//from w w w. j  ava 2s  .c  om
 * <p/>
 * - invoke method and get the return value
 * <p/>
 * - look up serializer for return value based on the value and type
 * <p/>
 * - create response msg and add return value as grand child of <soap:body>
 *
 * @param inMessage incoming MessageContext
 * @param outMessage outgoing MessageContext
 * @throws AxisFault
 */

public void invokeBusinessLogic(MessageContext inMessage, MessageContext outMessage) throws AxisFault {
    Method method = null;
    try {
        // get the implementation class for the Web Service
        Object obj = getTheImplementationObject(inMessage);

        Class implClass = obj.getClass();

        AxisOperation op = inMessage.getOperationContext().getAxisOperation();
        method = (Method) (op.getParameterValue("myMethod"));
        // If the declaring class has changed, then the cached method is invalid, so we need to
        // reload it. This is to fix AXIS2-3947.
        if (method != null && method.getDeclaringClass() != implClass) {
            method = null;
        }
        AxisService service = inMessage.getAxisService();
        OMElement methodElement = inMessage.getEnvelope().getBody().getFirstElement();
        AxisMessage inAxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        String messageNameSpace = null;

        if (method == null) {
            String methodName = op.getName().getLocalPart();
            Method[] methods = implClass.getMethods();

            for (Method method1 : methods) {
                if (method1.isBridge()) {
                    continue;
                }
                if (method1.getName().equals(methodName)) {
                    method = method1;
                    op.addParameter("myMethod", method);
                    break;
                }
            }
            if (method == null) {
                throw new AxisFault("No such method '" + methodName + "' in class " + implClass.getName());
            }
        }
        Object resObject = null;
        if (inAxisMessage != null) {
            resObject = RPCUtil.invokeServiceClass(inAxisMessage, method, obj, messageNameSpace, methodElement,
                    inMessage);
        }

        SOAPFactory fac = getSOAPFactory(inMessage);

        // Handling the response
        AxisMessage outaxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
        if (outaxisMessage != null && outaxisMessage.getElementQName() != null) {
            messageNameSpace = outaxisMessage.getElementQName().getNamespaceURI();
        } else {
            messageNameSpace = service.getTargetNamespace();
        }

        OMNamespace ns = fac.createOMNamespace(messageNameSpace, service.getSchemaTargetNamespacePrefix());
        SOAPEnvelope envelope = fac.getDefaultEnvelope();
        OMElement bodyContent = null;

        if (WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(op.getMessageExchangePattern())) {
            OMElement bodyChild = fac.createOMElement(outMessage.getAxisMessage().getName(), ns);
            envelope.getBody().addChild(bodyChild);
            outMessage.setEnvelope(envelope);
            return;
        }
        Parameter generateBare = service.getParameter(Java2WSDLConstants.DOC_LIT_BARE_PARAMETER);
        if (generateBare != null && "true".equals(generateBare.getValue())) {
            RPCUtil.processResonseAsDocLitBare(resObject, service, envelope, fac, ns, bodyContent, outMessage);
        } else {
            RPCUtil.processResponseAsDocLitWrapped(resObject, service, method, envelope, fac, ns, bodyContent,
                    outMessage);
        }
        outMessage.setEnvelope(envelope);
    } catch (InvocationTargetException e) {
        String msg = null;
        Throwable cause = e.getCause();
        if (cause != null) {
            msg = cause.getMessage();
        }
        if (msg == null) {
            msg = "Exception occurred while trying to invoke service method "
                    + (method != null ? method.getName() : "null");
        }
        if (cause instanceof AxisFault) {
            log.debug(msg, cause);
            throw (AxisFault) cause;
        }

        Class[] exceptionTypes = method.getExceptionTypes();
        for (Class exceptionType : exceptionTypes) {
            if (exceptionType.getName().equals(cause.getClass().getName())) {
                // this is an bussiness logic exception so handle it properly
                String partQName = inMessage.getAxisService().getName() + getSimpleClassName(exceptionType);
                TypeTable typeTable = inMessage.getAxisService().getTypeTable();
                QName elementQName = typeTable.getQNamefortheType(partQName);
                SOAPFactory fac = getSOAPFactory(inMessage);
                OMElement exceptionElement = fac.createOMElement(elementQName);

                if (exceptionType.getName().equals(Exception.class.getName())) {
                    // this is an exception class. so create a element by hand and add the message
                    OMElement innterExceptionElement = fac.createOMElement(elementQName);
                    OMElement messageElement = fac.createOMElement("Message",
                            inMessage.getAxisService().getTargetNamespace(), null);
                    messageElement.setText(cause.getMessage());

                    innterExceptionElement.addChild(messageElement);
                    exceptionElement.addChild(innterExceptionElement);
                } else {
                    // if it is a normal bussiness exception we need to generate the schema assuming it is a pojo
                    QName innerElementQName = new QName(elementQName.getNamespaceURI(),
                            getSimpleClassName(exceptionType));
                    XMLStreamReader xr = BeanUtil.getPullParser(cause, innerElementQName, typeTable, true,
                            false);
                    StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(),
                            new StreamWrapper(xr));
                    OMElement documentElement = stAXOMBuilder.getDocumentElement();
                    exceptionElement.addChild(documentElement);
                }

                AxisFault axisFault = new AxisFault(cause.getMessage());
                axisFault.setDetail(exceptionElement);
                throw axisFault;
            }
        }

        log.error(msg, e);
        throw new AxisFault(msg, e);
    } catch (RuntimeException e) {
        log.error(e.getMessage(), e);
        throw AxisFault.makeFault(e);
    } catch (Exception e) {
        String msg = "Exception occurred while trying to invoke service method "
                + (method != null ? method.getName() : "null");
        log.error(msg, e);
        throw AxisFault.makeFault(e);
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test/* ww w  . j a v a2 s  .  co  m*/
public void testCreateElement() {
    try {
        //SOAPFactory sf = SOAPFactory.newInstance();
        SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        if (sf == null) {
            fail("createElementTest4() could not create SOAPFactory object");
        }
        //Create QName object with localName=MyName1,prefix=MyPrefix1, uri=MyUri1
        QName name = new QName("MyUri1", "MyName1", "MyPrefix1");
        SOAPElement se = sf.createElement(name);
        assertNotNull(se);
        name = se.getElementQName();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
        String uri = name.getNamespaceURI();
        if (localName == null) {
            fail("localName is null (expected MyName1)");
        } else if (!localName.equals("MyName1")) {
            fail("localName is wrong (expected MyName1)");
        } else if (prefix == null) {
            fail("prefix is null (expected MyPrefix1)");
        } else if (!prefix.equals("MyPrefix1")) {
            fail("prefix is wrong (expected MyPrefix1)");
        } else if (uri == null) {
            fail("uri is null (expected MyUri1)");
        } else if (!uri.equals("MyUri1")) {
            fail("uri is wrong (expected MyUri1)");
        }
    } catch (Exception e) {
        fail();
    }
}

From source file:org.apache.axis2.schema.SchemaCompiler.java

/**
 * Generate a unique type Qname using an element name
 *
 * @param referenceEltQName/*from   www  .ja  v  a 2  s .  c o  m*/
 * @param parentSchema
 */
private QName generateTypeQName(QName referenceEltQName, XmlSchema parentSchema) {
    QName generatedTypeName = new QName(referenceEltQName.getNamespaceURI(),
            referenceEltQName.getLocalPart() + getNextTypeSuffix(referenceEltQName.getLocalPart()));
    while (parentSchema.getTypeByName(generatedTypeName) != null) {
        generatedTypeName = new QName(referenceEltQName.getNamespaceURI(),
                referenceEltQName.getLocalPart() + getNextTypeSuffix(referenceEltQName.getLocalPart()));
    }
    return generatedTypeName;
}

From source file:org.apache.axis2.schema.SchemaCompiler.java

/**
 * Finds a class name from the given Qname
 *
 * @param qName//  ww w  . j  a v  a 2s . c o m
 * @param isArray
 * @return FQCN
 */
private String findClassName(QName qName, boolean isArray) throws SchemaCompilationException {

    //find the class name
    String className;
    if (processedTypemap.containsKey(qName)) {
        className = processedTypemap.get(qName);
    } else if (simpleTypesMap.containsKey(qName)) {
        className = simpleTypesMap.get(qName);
    } else if (baseSchemaTypeMap.containsKey(qName)) {
        className = baseSchemaTypeMap.get(qName);
    } else {
        if (isSOAP_ENC(qName.getNamespaceURI())) {
            throw new SchemaCompilationException(
                    SchemaCompilerMessages.getMessage("schema.soapencoding.error", qName.toString()));

        }
        // We seem to have failed in finding a class name for the
        //contained schema type. We better set the default then
        //however it's better if the default can be set through the
        //property file
        className = writer.getDefaultClassName();
        log.warn(SchemaCompilerMessages.getMessage("schema.typeMissing", qName.toString()));
    }

    if (isArray) {
        //append the square braces that say this is an array
        //hope this works for all cases!!!!!!!
        //todo this however is a thing that needs to be
        //todo fixed to get complete language support
        className = className + "[]";
    }
    return className;
}

From source file:org.apache.axis2.schema.SchemaCompiler.java

/**
 * Process a particle- A particle may be a sequence,all or a choice
 * @param parentElementQName - this can either be parent element QName or parent Complex type qname
 * @param particle - particle being processed
 * @param metainfHolder -//  w w w.  j  ava  2 s  .c  om
 * @param parentSchema
 * @throws SchemaCompilationException
 */
private void processParticle(QName parentElementQName, XmlSchemaParticle particle,
        BeanWriterMetaInfoHolder metainfHolder, XmlSchema parentSchema) throws SchemaCompilationException {

    if (particle instanceof XmlSchemaSequence) {
        XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) particle;

        XmlSchemaObjectCollection items = xmlSchemaSequence.getItems();
        if ((xmlSchemaSequence.getMaxOccurs() > 1) && (parentElementQName != null)) {
            // we have to process many sequence types
            BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
            process(parentElementQName, items, beanWriterMetaInfoHolder, true, parentSchema);
            beanWriterMetaInfoHolder.setParticleClass(true);
            QName sequenceQName = new QName(parentElementQName.getNamespaceURI(),
                    parentElementQName.getLocalPart() + "Sequence");
            String javaClassName = writeComplexParticle(sequenceQName, beanWriterMetaInfoHolder);
            processedTypemap.put(sequenceQName, javaClassName);

            // add this as an array to the original class
            metainfHolder.registerMapping(sequenceQName, sequenceQName, findClassName(sequenceQName, true),
                    SchemaConstants.ARRAY_TYPE);
            metainfHolder.setOrdered(true);
            metainfHolder.registerQNameIndex(sequenceQName, metainfHolder.getOrderStartPoint() + 1);
            metainfHolder.setHasParticleType(true);
            metainfHolder.addtStatus(sequenceQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
            metainfHolder.addMaxOccurs(sequenceQName, xmlSchemaSequence.getMaxOccurs());
            metainfHolder.addMinOccurs(sequenceQName, xmlSchemaSequence.getMinOccurs());

        } else {
            if (options.isBackwordCompatibilityMode()) {
                process(parentElementQName, items, metainfHolder, false, parentSchema);
            } else {
                process(parentElementQName, items, metainfHolder, true, parentSchema);
            }
        }

    } else if (particle instanceof XmlSchemaAll) {
        XmlSchemaObjectCollection items = ((XmlSchemaAll) particle).getItems();
        process(parentElementQName, items, metainfHolder, false, parentSchema);
    } else if (particle instanceof XmlSchemaChoice) {
        XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice) particle;
        XmlSchemaObjectCollection items = ((XmlSchemaChoice) particle).getItems();

        if ((xmlSchemaChoice.getMaxOccurs() > 1)) {
            // we have to process many sequence types
            BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
            beanWriterMetaInfoHolder.setChoice(true);
            process(parentElementQName, items, beanWriterMetaInfoHolder, false, parentSchema);
            beanWriterMetaInfoHolder.setParticleClass(true);
            QName choiceQName = new QName(parentElementQName.getNamespaceURI(),
                    parentElementQName.getLocalPart() + "Choice");
            String javaClassName = writeComplexParticle(choiceQName, beanWriterMetaInfoHolder);
            processedTypemap.put(choiceQName, javaClassName);

            // add this as an array to the original class
            metainfHolder.registerMapping(choiceQName, choiceQName, findClassName(choiceQName, true),
                    SchemaConstants.ARRAY_TYPE);
            metainfHolder.setOrdered(true);
            metainfHolder.setHasParticleType(true);
            metainfHolder.registerQNameIndex(choiceQName, metainfHolder.getOrderStartPoint() + 1);
            metainfHolder.addtStatus(choiceQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
            metainfHolder.addMaxOccurs(choiceQName, xmlSchemaChoice.getMaxOccurs());
            metainfHolder.addMinOccurs(choiceQName, xmlSchemaChoice.getMinOccurs());

        } else {
            metainfHolder.setChoice(true);
            process(parentElementQName, items, metainfHolder, false, parentSchema);
        }

    } else if (particle instanceof XmlSchemaGroupRef) {

        XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) particle;
        QName groupQName = xmlSchemaGroupRef.getRefName();
        if (groupQName != null) {
            if (!processedGroupTypeMap.containsKey(groupQName)) {
                // processe the schema here
                XmlSchema resolvedParentSchema = getParentSchema(parentSchema, groupQName, COMPONENT_GROUP);
                if (resolvedParentSchema == null) {
                    throw new SchemaCompilationException("can not find the group " + groupQName
                            + " from the parent schema " + parentSchema.getTargetNamespace());
                } else {
                    XmlSchemaGroup xmlSchemaGroup = (XmlSchemaGroup) resolvedParentSchema.getGroups()
                            .getItem(groupQName);
                    processGroup(xmlSchemaGroup, groupQName, resolvedParentSchema);
                }
            }
        } else {
            throw new SchemaCompilationException("Referenced name is null");
        }
        boolean isArray = xmlSchemaGroupRef.getMaxOccurs() > 1;

        // add this as an array to the original class
        String groupClassName = processedGroupTypeMap.get(groupQName);
        if (isArray) {
            groupClassName = groupClassName + "[]";
        }
        metainfHolder.registerMapping(groupQName, groupQName, groupClassName);
        if (isArray) {
            metainfHolder.addtStatus(groupQName, SchemaConstants.ARRAY_TYPE);
        }
        metainfHolder.addtStatus(groupQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
        metainfHolder.addMaxOccurs(groupQName, xmlSchemaGroupRef.getMaxOccurs());
        metainfHolder.addMinOccurs(groupQName, xmlSchemaGroupRef.getMinOccurs());
        metainfHolder.setHasParticleType(true);
        metainfHolder.setOrdered(true);
        metainfHolder.registerQNameIndex(groupQName, metainfHolder.getOrderStartPoint() + 1);

    }
}

From source file:org.apache.axis2.schema.SchemaCompiler.java

/**
 *
 * @param parentElementQName - this could either be the complex type parentElementQName or element parentElementQName
 * @param items/* w w  w. j  av a2s .c o  m*/
 * @param metainfHolder
 * @param order
 * @param parentSchema
 * @throws SchemaCompilationException
 */
private void process(QName parentElementQName, XmlSchemaObjectCollection items,
        BeanWriterMetaInfoHolder metainfHolder, boolean order, XmlSchema parentSchema)
        throws SchemaCompilationException {
    int count = items.getCount();
    Map<XmlSchemaObject, Boolean> processedElementArrayStatusMap = new LinkedHashMap<XmlSchemaObject, Boolean>();
    Map processedElementTypeMap = new LinkedHashMap(); // TODO: not sure what is the correct generic type here
    List<QName> localNillableList = new ArrayList<QName>();

    Map<XmlSchemaObject, QName> particleQNameMap = new HashMap<XmlSchemaObject, QName>();

    // this list is used to keep the details of the
    // elements within a choice withing sequence
    List<QName> innerChoiceElementList = new ArrayList<QName>();

    Map<XmlSchemaObject, Integer> elementOrderMap = new HashMap<XmlSchemaObject, Integer>();

    int sequenceCounter = 0;
    for (int i = 0; i < count; i++) {
        XmlSchemaObject item = items.getItem(i);

        if (item instanceof XmlSchemaElement) {
            //recursively process the element
            XmlSchemaElement xsElt = (XmlSchemaElement) item;

            boolean isArray = isArray(xsElt);
            processElement(xsElt, processedElementTypeMap, localNillableList, parentSchema); //we know for sure this is not an outer type
            processedElementArrayStatusMap.put(xsElt, isArray);
            if (order) {
                //we need to keep the order of the elements. So push the elements to another
                //hashmap with the order number
                elementOrderMap.put(xsElt, sequenceCounter);
            }

            //handle xsd:any ! We place an OMElement (or an array of OMElements) in the generated class
        } else if (item instanceof XmlSchemaAny) {
            XmlSchemaAny any = (XmlSchemaAny) item;
            processedElementTypeMap.put(new QName(ANY_ELEMENT_FIELD_NAME), any);
            //any can also be inside a sequence
            if (order) {
                elementOrderMap.put(any, new Integer(sequenceCounter));
            }
            //we do not register the array status for the any type
            processedElementArrayStatusMap.put(any, isArray(any));
        } else if (item instanceof XmlSchemaSequence) {
            // we have to process many sequence types

            XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) item;
            if (xmlSchemaSequence.getItems().getCount() > 0) {
                BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
                process(parentElementQName, xmlSchemaSequence.getItems(), beanWriterMetaInfoHolder, true,
                        parentSchema);
                beanWriterMetaInfoHolder.setParticleClass(true);
                String localName = parentElementQName.getLocalPart() + "Sequence";
                QName sequenceQName = new QName(parentElementQName.getNamespaceURI(),
                        localName + getNextTypeSuffix(localName));
                String javaClassName = writeComplexParticle(sequenceQName, beanWriterMetaInfoHolder);
                processedTypemap.put(sequenceQName, javaClassName);

                //put the partical to array
                Boolean isArray = xmlSchemaSequence.getMaxOccurs() > 1 ? Boolean.TRUE : Boolean.FALSE;
                processedElementArrayStatusMap.put(item, isArray);
                particleQNameMap.put(item, sequenceQName);

                if (order) {
                    elementOrderMap.put(item, new Integer(sequenceCounter));
                }
            }

        } else if (item instanceof XmlSchemaChoice) {
            // we have to process many sequence types

            XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice) item;
            if (xmlSchemaChoice.getItems().getCount() > 0) {
                BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
                beanWriterMetaInfoHolder.setChoice(true);
                process(parentElementQName, xmlSchemaChoice.getItems(), beanWriterMetaInfoHolder, false,
                        parentSchema);
                beanWriterMetaInfoHolder.setParticleClass(true);
                String localName = parentElementQName.getLocalPart() + "Choice";
                QName choiceQName = new QName(parentElementQName.getNamespaceURI(),
                        localName + getNextTypeSuffix(localName));
                String javaClassName = writeComplexParticle(choiceQName, beanWriterMetaInfoHolder);
                processedTypemap.put(choiceQName, javaClassName);

                //put the partical to array
                Boolean isArray = xmlSchemaChoice.getMaxOccurs() > 1 ? Boolean.TRUE : Boolean.FALSE;
                processedElementArrayStatusMap.put(item, isArray);
                particleQNameMap.put(item, choiceQName);

                if (order) {
                    elementOrderMap.put(item, new Integer(sequenceCounter));
                }
            }

        } else if (item instanceof XmlSchemaGroupRef) {

            XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) item;
            QName groupQName = xmlSchemaGroupRef.getRefName();
            if (groupQName != null) {
                if (!processedGroupTypeMap.containsKey(groupQName)) {
                    // processe the schema here
                    XmlSchema resolvedParentSchema = getParentSchema(parentSchema, groupQName, COMPONENT_GROUP);
                    if (resolvedParentSchema == null) {
                        throw new SchemaCompilationException("Can not find the group with the qname"
                                + groupQName + " from the parent schema " + parentSchema.getTargetNamespace());
                    } else {
                        XmlSchemaGroup xmlSchemaGroup = (XmlSchemaGroup) resolvedParentSchema.getGroups()
                                .getItem(groupQName);
                        if (xmlSchemaGroup != null) {
                            processGroup(xmlSchemaGroup, groupQName, resolvedParentSchema);
                        }
                    }
                }

                Boolean isArray = xmlSchemaGroupRef.getMaxOccurs() > 1 ? Boolean.TRUE : Boolean.FALSE;
                processedElementArrayStatusMap.put(item, isArray);
                particleQNameMap.put(item, groupQName);

                if (order) {
                    elementOrderMap.put(item, new Integer(sequenceCounter));
                }

            } else {
                throw new SchemaCompilationException("Referenced name is null");
            }
        } else {
            //there may be other types to be handled here. Add them
            //when we are ready
        }
        sequenceCounter++;
    }

    // loop through the processed items and add them to the matainf object
    int startingItemNumberOrder = metainfHolder.getOrderStartPoint();
    for (XmlSchemaObject child : processedElementArrayStatusMap.keySet()) {

        // process the XmlSchemaElement
        if (child instanceof XmlSchemaElement) {
            XmlSchemaElement elt = (XmlSchemaElement) child;
            QName referencedQName = null;

            if (elt.getQName() != null) {
                referencedQName = elt.getQName();
                QName schemaTypeQName = elt.getSchemaType() != null ? elt.getSchemaType().getQName()
                        : elt.getSchemaTypeName();
                if (schemaTypeQName != null) {
                    String clazzName = (String) processedElementTypeMap.get(elt.getQName());
                    metainfHolder.registerMapping(referencedQName, schemaTypeQName, clazzName,
                            processedElementArrayStatusMap.get(elt) ? SchemaConstants.ARRAY_TYPE
                                    : SchemaConstants.ELEMENT_TYPE);
                    if (innerChoiceElementList.contains(referencedQName)) {
                        metainfHolder.addtStatus(referencedQName, SchemaConstants.INNER_CHOICE_ELEMENT);
                    }
                    // register the default value as well
                    if (elt.getDefaultValue() != null) {
                        metainfHolder.registerDefaultValue(referencedQName, elt.getDefaultValue());
                    }

                }
            }

            if (elt.getRefName() != null) { //probably this is referenced
                referencedQName = elt.getRefName();
                boolean arrayStatus = processedElementArrayStatusMap.get(elt);
                String clazzName = findRefClassName(referencedQName, arrayStatus);
                if (clazzName == null) {
                    clazzName = findClassName(referencedQName, arrayStatus);
                }
                XmlSchema resolvedParentSchema = getParentSchema(parentSchema, referencedQName,
                        COMPONENT_ELEMENT);
                if (resolvedParentSchema == null) {
                    throw new SchemaCompilationException("Can not find the element " + referencedQName
                            + " from the parent schema " + parentSchema.getTargetNamespace());
                } else {
                    XmlSchemaElement refElement = resolvedParentSchema.getElementByName(referencedQName);

                    // register the mapping if we found the referenced element
                    // else throw an exception
                    if (refElement != null) {
                        metainfHolder.registerMapping(referencedQName, refElement.getSchemaTypeName(),
                                clazzName,
                                arrayStatus ? SchemaConstants.ARRAY_TYPE : SchemaConstants.ELEMENT_TYPE);
                    } else {
                        if (referencedQName.equals(SchemaConstants.XSD_SCHEMA)) {
                            metainfHolder.registerMapping(referencedQName, null, writer.getDefaultClassName(),
                                    SchemaConstants.ANY_TYPE);
                        } else {
                            throw new SchemaCompilationException(SchemaCompilerMessages.getMessage(
                                    "schema.referencedElementNotFound", referencedQName.toString()));
                        }
                    }
                }
            }

            if (referencedQName == null) {
                throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.emptyName"));
            }

            //register the occurence counts
            metainfHolder.addMaxOccurs(referencedQName, elt.getMaxOccurs());
            // if the strict validation off then we consider all elements have minOccurs zero on it
            if (this.options.isOffStrictValidation()) {
                metainfHolder.addMinOccurs(referencedQName, 0);
            } else {
                metainfHolder.addMinOccurs(referencedQName, elt.getMinOccurs());
            }
            //we need the order to be preserved. So record the order also
            if (order) {
                //record the order in the metainf holder
                metainfHolder.registerQNameIndex(referencedQName,
                        startingItemNumberOrder + elementOrderMap.get(elt));
            }

            //get the nillable state and register that on the metainf holder
            if (localNillableList.contains(elt.getQName())) {
                metainfHolder.registerNillableQName(elt.getQName());
            }

            //get the binary state and add that to the status map
            if (isBinary(elt)) {
                metainfHolder.addtStatus(elt.getQName(), SchemaConstants.BINARY_TYPE);
            }
            // process the XMLSchemaAny
        } else if (child instanceof XmlSchemaAny) {
            XmlSchemaAny any = (XmlSchemaAny) child;

            //since there is only one element here it does not matter
            //for the constant. However the problem occurs if the users
            //uses the same name for an element decalration
            QName anyElementFieldName = new QName(ANY_ELEMENT_FIELD_NAME);

            //this can be an array or a single element
            boolean isArray = processedElementArrayStatusMap.get(any);
            metainfHolder.registerMapping(anyElementFieldName, null,
                    isArray ? writer.getDefaultClassArrayName() : writer.getDefaultClassName(),
                    SchemaConstants.ANY_TYPE);
            //if it's an array register an extra status flag with the system
            if (isArray) {
                metainfHolder.addtStatus(anyElementFieldName, SchemaConstants.ARRAY_TYPE);
            }
            metainfHolder.addMaxOccurs(anyElementFieldName, any.getMaxOccurs());
            metainfHolder.addMinOccurs(anyElementFieldName, any.getMinOccurs());

            if (order) {
                //record the order in the metainf holder for the any
                metainfHolder.registerQNameIndex(anyElementFieldName,
                        startingItemNumberOrder + elementOrderMap.get(any));
            }
        } else if (child instanceof XmlSchemaSequence) {
            XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) child;
            QName sequenceQName = particleQNameMap.get(child);
            boolean isArray = xmlSchemaSequence.getMaxOccurs() > 1;

            // add this as an array to the original class
            metainfHolder.registerMapping(sequenceQName, sequenceQName, findClassName(sequenceQName, isArray));
            if (isArray) {
                metainfHolder.addtStatus(sequenceQName, SchemaConstants.ARRAY_TYPE);
            }
            metainfHolder.addtStatus(sequenceQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
            metainfHolder.addMaxOccurs(sequenceQName, xmlSchemaSequence.getMaxOccurs());
            metainfHolder.addMinOccurs(sequenceQName, xmlSchemaSequence.getMinOccurs());
            metainfHolder.setHasParticleType(true);

            if (order) {
                //record the order in the metainf holder for the any
                metainfHolder.registerQNameIndex(sequenceQName,
                        startingItemNumberOrder + elementOrderMap.get(child));
            }
        } else if (child instanceof XmlSchemaChoice) {
            XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice) child;
            QName choiceQName = particleQNameMap.get(child);
            boolean isArray = xmlSchemaChoice.getMaxOccurs() > 1;

            // add this as an array to the original class
            metainfHolder.registerMapping(choiceQName, choiceQName, findClassName(choiceQName, isArray));
            if (isArray) {
                metainfHolder.addtStatus(choiceQName, SchemaConstants.ARRAY_TYPE);
            }
            metainfHolder.addtStatus(choiceQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
            metainfHolder.addMaxOccurs(choiceQName, xmlSchemaChoice.getMaxOccurs());
            metainfHolder.addMinOccurs(choiceQName, xmlSchemaChoice.getMinOccurs());
            metainfHolder.setHasParticleType(true);

            if (order) {
                //record the order in the metainf holder for the any
                metainfHolder.registerQNameIndex(choiceQName,
                        startingItemNumberOrder + elementOrderMap.get(child));
            }
        } else if (child instanceof XmlSchemaGroupRef) {
            XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) child;
            QName groupQName = particleQNameMap.get(child);
            boolean isArray = xmlSchemaGroupRef.getMaxOccurs() > 1;

            // add this as an array to the original class
            String groupClassName = processedGroupTypeMap.get(groupQName);
            if (isArray) {
                groupClassName = groupClassName + "[]";
            }
            metainfHolder.registerMapping(groupQName, groupQName, groupClassName);
            if (isArray) {
                metainfHolder.addtStatus(groupQName, SchemaConstants.ARRAY_TYPE);
            }
            metainfHolder.addtStatus(groupQName, SchemaConstants.PARTICLE_TYPE_ELEMENT);
            metainfHolder.addMaxOccurs(groupQName, xmlSchemaGroupRef.getMaxOccurs());
            metainfHolder.addMinOccurs(groupQName, xmlSchemaGroupRef.getMinOccurs());
            metainfHolder.setHasParticleType(true);

            if (order) {
                //record the order in the metainf holder for the any
                metainfHolder.registerQNameIndex(groupQName,
                        startingItemNumberOrder + elementOrderMap.get(child));
            }
        }
    }

    //set the ordered flag in the metainf holder
    metainfHolder.setOrdered(order);
}

From source file:org.apache.axis2.schema.SchemaCompiler.java

/**
 * @param simpleType//from w  ww. j  ava  2 s .co  m
 * @param xsElt
 * @param parentSchema
 * @param qname        - fake Qname to use if the xsElt is null.
 * @throws SchemaCompilationException
 */
private void processSimpleSchemaType(XmlSchemaSimpleType simpleType, XmlSchemaElement xsElt,
        XmlSchema parentSchema, QName qname) throws SchemaCompilationException {

    String fullyQualifiedClassName = null;
    if (simpleType.getQName() != null) {
        if (processedTypemap.containsKey(simpleType.getQName())
                || baseSchemaTypeMap.containsKey(simpleType.getQName())) {
            return;
        }

        // Must do this up front to support recursive types
        fullyQualifiedClassName = writer.makeFullyQualifiedClassName(simpleType.getQName());
        // we put the qname to processed type map it is only named type
        // otherwise we have to any way process that element.
        processedTypemap.put(simpleType.getQName(), fullyQualifiedClassName);
    } else {

        QName fakeQname;
        if (xsElt != null) {
            fakeQname = new QName(xsElt.getQName().getNamespaceURI(),
                    xsElt.getQName().getLocalPart() + getNextTypeSuffix(xsElt.getQName().getLocalPart()));
            // we have to set this otherwise the ours attribute would not set properly if refered to this simple
            // type from any other element
            xsElt.setSchemaTypeName(fakeQname);
            changedElementSet.add(xsElt);

        } else {
            fakeQname = qname;
        }
        if (processedTypemap.containsKey(fakeQname) || baseSchemaTypeMap.containsKey(fakeQname)) {
            return;
        }
        fullyQualifiedClassName = writer.makeFullyQualifiedClassName(fakeQname);
        simpleType.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.FAKE_QNAME, fakeQname);

        // should put this to the processedTypemap to generate the code correctly
        processedTypemap.put(fakeQname, fullyQualifiedClassName);
    }

    //register that in the schema metainfo bag
    simpleType.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, fullyQualifiedClassName);

    BeanWriterMetaInfoHolder metaInfHolder = processSimpleType(simpleType, parentSchema);
    metaInfHolder.setSimple(true);

    if (simpleType.getQName() == null) {
        this.processedAnonymousComplexTypesMap.put(xsElt, metaInfHolder);
        QName fakeQname;
        if (xsElt != null) {
            fakeQname = new QName(xsElt.getQName().getNamespaceURI(), xsElt.getQName().getLocalPart());
        } else {
            fakeQname = qname;
            simpleType.setName(fakeQname.getLocalPart());
            changedSimpleTypeSet.add(simpleType);
            simpleType.setSourceURI(fakeQname.getNamespaceURI());
        }
        simpleTypesMap.put(fakeQname, fullyQualifiedClassName);
    }
    //add this information to the metainfo holder
    metaInfHolder.setOwnQname(simpleType.getQName());
    if (fullyQualifiedClassName != null) {
        metaInfHolder.setOwnClassName(fullyQualifiedClassName);
    }
    //write the class. This type mapping would have been populated right now
    //Note - We always write classes for named complex types
    writeSimpleType(simpleType, metaInfHolder);
}