Example usage for javax.xml.namespace QName getLocalPart

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

Introduction

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

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

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 -//from w  ww  .  j  a  va2s  .c  o  m
 * @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/*from  w w  w .j a  v a  2  s  .  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//w ww  . j av a2  s  .  c o  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);
}

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

private BeanWriterMetaInfoHolder processSimpleType(XmlSchemaSimpleType simpleType, XmlSchema parentSchema)
        throws SchemaCompilationException {
    BeanWriterMetaInfoHolder metaInfHolder = new BeanWriterMetaInfoHolder();

    // handle the restriction
    XmlSchemaSimpleTypeContent content = simpleType.getContent();
    QName parentSimpleTypeQname = simpleType.getQName();
    if (parentSimpleTypeQname == null) {
        parentSimpleTypeQname = (QName) simpleType.getMetaInfoMap()
                .get(SchemaConstants.SchemaCompilerInfoHolder.FAKE_QNAME);
    }//from  w ww  .ja  va  2  s  .  c o  m
    if (content != null) {
        if (content instanceof XmlSchemaSimpleTypeRestriction) {
            XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;

            QName baseTypeName = restriction.getBaseTypeName();
            //check whether the base type is one of the base schema types

            if (baseSchemaTypeMap.containsKey(baseTypeName)) {
                //process restriction base type

                processSimpleRestrictionBaseType(parentSimpleTypeQname, restriction.getBaseTypeName(),
                        metaInfHolder, parentSchema);
                //process facets
                if (!SchemaConstants.XSD_BOOLEAN.equals(baseTypeName)) {
                    processFacets(restriction, metaInfHolder, parentSchema);
                }
            } else {
                //recurse
                // this must be a xmlschema bug
                // it should return the schematype for restriction.getBaseType():
                XmlSchema resolvedSchema = getParentSchema(parentSchema, baseTypeName, COMPONENT_TYPE);
                if (resolvedSchema == null) {
                    throw new SchemaCompilationException("can not find the type " + baseTypeName
                            + " from the parent schema " + parentSchema.getTargetNamespace());
                } else {
                    XmlSchemaType restrictionBaseType = resolvedSchema.getTypeByName(baseTypeName);
                    if (restrictionBaseType instanceof XmlSchemaSimpleType) {
                        if ((restrictionBaseType != null) && (!isAlreadyProcessed(baseTypeName))) {
                            processSimpleSchemaType((XmlSchemaSimpleType) restrictionBaseType, null,
                                    resolvedSchema, null);
                        }
                        // process restriction
                        processSimpleRestrictionBaseType(parentSimpleTypeQname, restriction.getBaseTypeName(),
                                metaInfHolder, resolvedSchema);
                    }
                }

            }
        } else if (content instanceof XmlSchemaSimpleTypeUnion) {
            XmlSchemaSimpleTypeUnion simpleTypeUnion = (XmlSchemaSimpleTypeUnion) content;
            QName[] qnames = simpleTypeUnion.getMemberTypesQNames();
            if (qnames != null) {
                QName qname;
                for (int i = 0; i < qnames.length; i++) {
                    qname = qnames[i];
                    if (baseSchemaTypeMap.containsKey(qname)) {
                        metaInfHolder.addMemberType(qname, baseSchemaTypeMap.get(qname));
                    } else {
                        XmlSchema resolvedSchema = getParentSchema(parentSchema, qname, COMPONENT_TYPE);
                        if (resolvedSchema == null) {
                            throw new SchemaCompilationException("can not find the type " + qname
                                    + " from the parent schema " + parentSchema.getTargetNamespace());
                        } else {
                            XmlSchemaType type = resolvedSchema.getTypeByName(qname);
                            if (type instanceof XmlSchemaSimpleType) {
                                XmlSchemaSimpleType memberSimpleType = (XmlSchemaSimpleType) type;
                                if (!isAlreadyProcessed(qname)) {
                                    processSimpleSchemaType(memberSimpleType, null, resolvedSchema, null);
                                }
                                metaInfHolder.addMemberType(qname, processedTypemap.get(qname));
                            } else {
                                throw new SchemaCompilationException(
                                        "Unions can not have complex types as a member type");
                            }
                        }
                    }
                }
            } else {
                XmlSchemaObjectCollection xmlSchemaObjectCollection = simpleTypeUnion.getBaseTypes();
                XmlSchemaObject xmlSchemaObject;
                QName childQname;
                int i = 1;
                for (Iterator iter = xmlSchemaObjectCollection.getIterator(); iter.hasNext();) {
                    xmlSchemaObject = (XmlSchemaObject) iter.next();
                    i++;
                    if (xmlSchemaObject instanceof XmlSchemaSimpleType) {
                        XmlSchemaSimpleType unionSimpleType = (XmlSchemaSimpleType) xmlSchemaObject;
                        childQname = unionSimpleType.getQName();
                        if (childQname == null) {
                            // we create a fake Qname for all these simple types since most propably they don't have one
                            childQname = new QName(parentSimpleTypeQname.getNamespaceURI(),
                                    parentSimpleTypeQname.getLocalPart()
                                            + getNextTypeSuffix(parentSimpleTypeQname.getLocalPart()));
                        }
                        // this is an inner simple type of the union so it shold not have
                        // processed
                        processSimpleSchemaType(unionSimpleType, null, parentSchema, childQname);
                        metaInfHolder.addMemberType(childQname, processedTypemap.get(childQname));
                    }

                }
            }

            metaInfHolder.setUnion(true);

        } else if (content instanceof XmlSchemaSimpleTypeList) {
            XmlSchemaSimpleTypeList simpleTypeList = (XmlSchemaSimpleTypeList) content;
            QName itemTypeQName = simpleTypeList.getItemTypeName();

            if (itemTypeQName != null) {
                if (!isAlreadyProcessed(itemTypeQName)) {
                    XmlSchema resolvedSchema = getParentSchema(parentSchema, itemTypeQName, COMPONENT_TYPE);
                    if (resolvedSchema == null) {
                        throw new SchemaCompilationException("can not find the type " + itemTypeQName
                                + " from the parent type " + parentSchema.getTargetNamespace());
                    } else {
                        XmlSchemaType simpleSchemaType = resolvedSchema.getTypeByName(itemTypeQName);
                        if (simpleSchemaType instanceof XmlSchemaSimpleType) {
                            processSimpleSchemaType((XmlSchemaSimpleType) simpleSchemaType, null,
                                    resolvedSchema, null);
                        }
                    }
                }
            } else {
                XmlSchemaSimpleType listSimpleType = simpleTypeList.getItemType();
                itemTypeQName = listSimpleType.getQName();
                if (itemTypeQName == null) {
                    // we create a fake Qname for all these simple types since most propably they don't have one
                    itemTypeQName = new QName(parentSimpleTypeQname.getNamespaceURI(),
                            parentSimpleTypeQname.getLocalPart() + "_type0");
                }
                processSimpleSchemaType(listSimpleType, null, parentSchema, itemTypeQName);

            }

            String className = findClassName(itemTypeQName, false);
            metaInfHolder.setList(true);
            metaInfHolder.setItemTypeQName(itemTypeQName);
            metaInfHolder.setItemTypeClassName(className);

        }
    }
    return metaInfHolder;
}

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

private boolean isComponetExists(XmlSchema schema, QName componentQName, int componetType) {
    boolean isExists = false;
    switch (componetType) {
    case COMPONENT_TYPE: {
        isExists = (schema.getTypeByName(componentQName.getLocalPart()) != null);
        break;// w ww.java2 s.  c  o m
    }
    case COMPONENT_ELEMENT: {
        isExists = (schema.getElementByName(componentQName.getLocalPart()) != null);
        break;
    }
    case COMPONENT_ATTRIBUTE: {
        isExists = (schema.getAttributes().getItem(componentQName) != null);
        break;
    }
    case COMPONENT_ATTRIBUTE_GROUP: {
        isExists = (schema.getAttributeGroups().getItem(componentQName) != null);
        break;
    }
    case COMPONENT_GROUP: {
        isExists = (schema.getGroups().getItem(componentQName) != null);
        break;
    }
    }
    return isExists;
}

From source file:org.apache.axis2.schema.writer.JavaBeanWriter.java

/**
 * Make the fully qualified class name for an element or named type
 *
 * @param qName the qualified Name for this element or type in the schema
 * @return the appropriate fully qualified class name to use in generated
 *         code//  w  w w  .j  a v  a 2 s  .com
 */
public String makeFullyQualifiedClassName(QName qName) {

    String namespaceURI = qName.getNamespaceURI();

    String packageName = getPackage(namespaceURI);

    String originalName = qName.getLocalPart();
    String className = null;

    // when wrapping classes all the data binding and exception class should have
    // a unique name since package name is not being applied.
    // otherewise we can make unique with the package name
    if (!wrapClasses) {
        className = makeUniqueJavaClassName(this.nameList, originalName);
    } else {
        if (!this.packageNameToClassNamesMap.containsKey(packageName)) {
            this.packageNameToClassNamesMap.put(packageName, new ArrayList<String>());
        }
        className = makeUniqueJavaClassName(this.packageNameToClassNamesMap.get(packageName), originalName);
    }

    String packagePrefix = null;

    String fullyqualifiedClassName;

    if (wrapClasses)
        packagePrefix = (this.packageName == null ? DEFAULT_PACKAGE + "." : this.packageName)
                + WRAPPED_DATABINDING_CLASS_NAME;
    else if (writeClasses)
        packagePrefix = packageName;
    if (packagePrefix != null)
        fullyqualifiedClassName = packagePrefix + (packagePrefix.endsWith(".") ? "" : ".") + className;
    else
        fullyqualifiedClassName = className;
    // return the fully qualified class name
    return fullyqualifiedClassName;
}

From source file:org.apache.axis2.schema.writer.JavaBeanWriter.java

/**
 * A util method that holds common code for the complete schema that the
 * generated XML complies to look under other/beanGenerationSchema.xsd
 *
 * @param qName/* w w  w. jav a2 s.  c  o  m*/
 * @param metainf
 * @param typeMap
 * @param isElement
 * @param fullyQualifiedClassName the name returned by makeFullyQualifiedClassName() or null if
 *                                it wasn't called
 * @return Returns String.
 * @throws Exception
 */
private String process(QName qName, BeanWriterMetaInfoHolder metainf, Map<QName, String> typeMap,
        Map<QName, String> groupTypeMap, boolean isElement, boolean isAbstract) throws Exception {
    String fullyQualifiedClassName = metainf.getOwnClassName();
    if (fullyQualifiedClassName == null)
        fullyQualifiedClassName = makeFullyQualifiedClassName(qName);
    String className = fullyQualifiedClassName.substring(1 + fullyQualifiedClassName.lastIndexOf('.'));
    String basePackageName;
    if (fullyQualifiedClassName.lastIndexOf('.') == -1) {// no 'dots' so
        // the package
        // is not there
        basePackageName = "";
    } else {
        basePackageName = fullyQualifiedClassName.substring(0, fullyQualifiedClassName.lastIndexOf('.'));
    }

    String originalName = qName == null ? "" : qName.getLocalPart();
    ArrayList<String> propertyNames = new ArrayList<String>();

    if (!templateLoaded) {
        loadTemplate();
    }

    // if wrapped then do not write the classes now but add the models to a
    // global document. However in order to write the
    // global class that is generated, one needs to call the writeBatch()
    // method
    if (wrapClasses) {
        globalWrappedDocument.getDocumentElement()
                .appendChild(getBeanElement(globalWrappedDocument, className, originalName, basePackageName,
                        qName, isElement, isAbstract, metainf, propertyNames, typeMap, groupTypeMap));

    } else {
        // create the model
        Document model = XSLTUtils.getDocument();
        // make the XML
        model.appendChild(getBeanElement(model, className, originalName, basePackageName, qName, isElement,
                isAbstract, metainf, propertyNames, typeMap, groupTypeMap));

        if (writeClasses) {
            // create the file
            File out = createOutFile(basePackageName, className);
            // parse with the template and create the files

            if (isHelperMode) {

                XSLTUtils.addAttribute(model, "helperMode", "yes", model.getDocumentElement());

                // Generate bean classes
                parse(model, out);

                // Generating the helper classes
                out = createOutFile(basePackageName, className + "Helper");
                XSLTUtils.addAttribute(model, "helper", "yes", model.getDocumentElement());
                parse(model, out);

            } else {
                //No helper mode - just generate the classes
                parse(model, out);
            }
        }

        // add the model to the model map
        modelMap.put(new QName(qName.getNamespaceURI(), className), model);

    }

    // return the fully qualified class name
    return fullyQualifiedClassName;

}

From source file:org.apache.axis2.schema.writer.JavaBeanWriter.java

protected void populateMemberInfo(BeanWriterMetaInfoHolder metainf, Document model, Element rootElement,
        Map<QName, String> typeMap) {
    Map<QName, String> memberTypes = metainf.getMemberTypes();
    for (QName memberQName : metainf.getMemberTypesKeys()) {
        String memberClass = memberTypes.get(memberQName);
        if (PrimitiveTypeFinder.isPrimitive(memberClass)) {
            memberClass = PrimitiveTypeWrapper.getWrapper(memberClass);
        }/*w ww  . j  a  v a 2  s. co m*/

        // add member type element
        Element memberType = XSLTUtils.addChildElement(model, "memberType", rootElement);
        XSLTUtils.addAttribute(model, "type", memberClass, memberType);
        XSLTUtils.addAttribute(model, "nsuri", memberQName.getNamespaceURI(), memberType);
        XSLTUtils.addAttribute(model, "originalName", memberQName.getLocalPart(), memberType);
        if (typeMap.containsKey(memberQName)) {
            XSLTUtils.addAttribute(model, "ours", "true", memberType);
        }
        String shortTypeName = getShortTypeName(memberClass);
        XSLTUtils.addAttribute(model, "shorttypename", shortTypeName, memberType);

    }
}

From source file:org.apache.axis2.schema.writer.JavaBeanWriter.java

/**
 * @param metainf//from w  w  w  .j  av a  2 s.c om
 * @param model
 * @param rootElt
 * @param propertyNames
 * @param typeMap
 * @throws SchemaCompilationException
 */
private void addPropertyEntries(BeanWriterMetaInfoHolder metainf, Document model, Element rootElt,
        ArrayList<String> propertyNames, Map<QName, String> typeMap, Map<QName, String> groupTypeMap,
        boolean isInherited) throws SchemaCompilationException {
    // go in the loop and add the part elements
    QName[] qName;
    String javaClassNameForElement;
    ArrayList<QName> missingQNames = new ArrayList<QName>();
    ArrayList<QName> qNames = new ArrayList<QName>();

    BeanWriterMetaInfoHolder parentMetaInf = metainf.getParent();

    if (metainf.isOrdered()) {
        qName = metainf.getOrderedQNameArray();
    } else {
        qName = metainf.getQNameArray();
    }

    for (int i = 0; i < qName.length; i++) {
        qNames.add(qName[i]);
    }

    //adding missing QNames to the end, including elements & attributes.
    // for the simple types we have already add the parent elements
    // it is almost consider as an extension
    if (metainf.isRestriction() && !metainf.isSimple()) {
        addMissingQNames(metainf, qNames, missingQNames);
    }

    List<BeanWriterMetaInfoHolder> parents = new ArrayList<BeanWriterMetaInfoHolder>();
    BeanWriterMetaInfoHolder immediateParent = metainf.getParent();
    while (immediateParent != null) {
        parents.add(immediateParent);
        immediateParent = immediateParent.getParent();
    }

    for (QName name : qNames) {
        Element property = XSLTUtils.addChildElement(model, "property", rootElt);

        String xmlName = name.getLocalPart();

        String xmlNameNew = identifyUniqueNameForQName(parents, xmlName, metainf, name, name);
        while (!xmlName.equalsIgnoreCase(xmlNameNew)) {
            xmlName = xmlNameNew;
            xmlNameNew = identifyUniqueNameForQName(parents, xmlNameNew, metainf, name, new QName(xmlNameNew));
        }

        XSLTUtils.addAttribute(model, "name", xmlName, property);
        XSLTUtils.addAttribute(model, "nsuri", name.getNamespaceURI(), property);

        String javaName;
        if (metainf.isJavaNameMappingAvailable(xmlName)) {
            javaName = metainf.getJavaName(xmlName);
        } else {
            javaName = makeUniqueJavaClassName(propertyNames, xmlName);
            // in a restriction if this element already there and array status have changed
            // then we have to generate a new  name for this
            if (parentMetaInf != null && metainf.isRestriction() && !missingQNames.contains(name)
                    && (parentMetaInf.getArrayStatusForQName(name) && !metainf.getArrayStatusForQName(name))) {
                javaName = makeUniqueJavaClassName(propertyNames, xmlName);
            }
            metainf.addXmlNameJavaNameMapping(xmlName, javaName);
        }

        XSLTUtils.addAttribute(model, "javaname", javaName, property);

        if (parentMetaInf != null && metainf.isRestriction() && missingQNames.contains(name)) {
            javaClassNameForElement = parentMetaInf.getClassNameForQName(name);
        } else {
            javaClassNameForElement = metainf.getClassNameForQName(name);
        }

        if (javaClassNameForElement == null) {
            javaClassNameForElement = getDefaultClassName();
            log.warn(SchemaCompilerMessages.getMessage("schema.typeMissing", name.toString()));
        }

        if (metainf.isRestriction() && typeChanged(name, missingQNames, metainf)) {
            XSLTUtils.addAttribute(model, "typeChanged", "yes", property);
            //XSLTUtils.addAttribute(model, "restricted", "yes", property);
        }

        long minOccurs = metainf.getMinOccurs(name);
        if (PrimitiveTypeFinder.isPrimitive(javaClassNameForElement) && isUseWrapperClasses
                && ((minOccurs == 0) || metainf.isNillable(name))) {
            // if this is an primitive class and user wants to use the
            // wrapper type we change the type to wrapper type.
            javaClassNameForElement = PrimitiveTypeWrapper.getWrapper(javaClassNameForElement);
        }

        XSLTUtils.addAttribute(model, "type", javaClassNameForElement, property);

        if (PrimitiveTypeFinder.isPrimitive(javaClassNameForElement)) {

            XSLTUtils.addAttribute(model, "primitive", "yes", property);
        }

        // add the default value
        if (metainf.isDefaultValueAvailable(name)) {
            QName schemaQName = metainf.getSchemaQNameForQName(name);
            if (baseTypeMap.containsKey(schemaQName)) {
                XSLTUtils.addAttribute(model, "defaultValue", metainf.getDefaultValueForQName(name), property);
            }
        }

        //in the case the original element is an array but the derived one is not.
        if (parentMetaInf != null && metainf.isRestriction() && !missingQNames.contains(name)
                && (parentMetaInf.getArrayStatusForQName(name) && !metainf.getArrayStatusForQName(name))) {

            XSLTUtils.addAttribute(model, "rewrite", "yes", property);
            XSLTUtils.addAttribute(model, "occuranceChanged", "yes", property);
        } else if (metainf.isRestriction() && !missingQNames.contains(name)
                && (minOccursChanged(name, missingQNames, metainf)
                        || maxOccursChanged(name, missingQNames, metainf))) {

            XSLTUtils.addAttribute(model, "restricted", "yes", property);
            XSLTUtils.addAttribute(model, "occuranceChanged", "yes", property);
        }

        // set the is particle class
        if (metainf.getParticleTypeStatusForQName(name)) {
            XSLTUtils.addAttribute(model, "particleClassType", "yes", property);
        }

        // if we have an particle class in a extension class then we have
        // to consider the whole class has a particle type.

        if (metainf.isHasParticleType()) {
            XSLTUtils.addAttribute(model, "hasParticleType", "yes", rootElt);
        }

        // what happed if this contain attributes
        // TODO: check the meaning of this removed property

        if (metainf.isRestriction() && missingQNames.contains(name) && !metainf.isSimple()) {
            //XSLTUtils.addAttribute(model, "restricted", "yes", property);
            XSLTUtils.addAttribute(model, "removed", "yes", property);
        }

        if (isInherited) {
            XSLTUtils.addAttribute(model, "inherited", "yes", property);
        }

        if (metainf.getInnerChoiceStatusForQName(name)) {
            XSLTUtils.addAttribute(model, "innerchoice", "yes", property);
        }

        if ((parentMetaInf != null) && metainf.isRestriction() && missingQNames.contains(name)) {
            // this element details should be there with the parent meta Inf
            addAttributesToProperty(parentMetaInf, name, model, property, typeMap, groupTypeMap,
                    javaClassNameForElement);

        } else {
            addAttributesToProperty(metainf, name, model, property, typeMap, groupTypeMap,
                    javaClassNameForElement);
        }
    } // end of foo
}

From source file:org.apache.axis2.schema.writer.JavaBeanWriter.java

private boolean qNameNotFound(QName qname, BeanWriterMetaInfoHolder metainf) {

    boolean found = false;
    QName[] qNames;//from w w  w . ja  va  2s .c  om

    if (metainf.isOrdered()) {
        qNames = metainf.getOrderedQNameArray();
    } else {
        qNames = metainf.getQNameArray();
    }

    for (int j = 0; j < qNames.length; j++) {
        if (qname.getLocalPart().equals(qNames[j].getLocalPart())) {
            found = true;
        }
    }
    return !found;
}