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

private static void validatePattern(QName pattern) {
    if (pattern == null) {
        if (log.isDebugEnabled()) {
            log.debug("The pattern qname is null.  This is accepted and interpretted as a wildcard");
        }//from  www. j  a v a  2  s.co  m
        return;
    }
    String patternStringPrefix = pattern.getPrefix();
    String patternInfoLocalPart = pattern.getLocalPart();
    String patternString = ((patternStringPrefix == null) || (patternStringPrefix.equals(""))) ? ""
            : patternStringPrefix + ":";
    patternString += patternInfoLocalPart;

    /*
     * Below pattern is ported from:  http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd
     * Schema regular expressions are defined differently from Java regular expressions which are different from Perl regular
     * expressions.  I've converted the pattern defined in the above linked schema to its Java equivalent, as best as I can.
     * 
     * Schema reg ex:  "\*|([\i-[:]][\c-[:]]*:)?[\i-[:]][\c-[:]]*\*?"
     * Java reg ex:  "\\*|((\\w|_)(\\w|\\.|-|_)*:)?(\\w|_)(\\w|\\.|-|_)*\\*?"
     */

    // first, confirm the defined pattern is legal
    Pattern p = Pattern.compile("\\*|((\\w|_)(\\w|\\.|-|_)*:)?(\\w|_)(\\w|\\.|-|_)*\\*?");
    Matcher m = p.matcher(patternString);
    if (!m.matches()) {
        // pattern defined by user in handler chain xml file is illegal -- report it but continue
        log.warn("Pattern defined by user is illegal:  \"" + patternString
                + "\" does not match regular expression in schema http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd.  Pattern matching should now be considered \"best-effort.\"");
    }
}

From source file:org.apache.axis2.jaxws.spi.ServiceDelegate.java

public void addPort(QName portName, String bindingId, String endpointAddress) throws WebServiceException {
    verifyServiceDescriptionActive();/*from  www  .  ja  v a 2s .  c  o m*/
    if (log.isDebugEnabled()) {
        log.debug("Calling addPort : (" + portName + "," + bindingId + "," + endpointAddress + ")");
    }
    if (endpointAddress != null && endpointAddress.trim().length() == 0) {
        ExceptionFactory.makeWebServiceException(Messages.getMessage("addPortErr1",
                (portName != null) ? portName.getLocalPart() : "", endpointAddress));
    }
    EndpointDescription endpointDesc = DescriptionFactory.updateEndpoint(serviceDescription, null, portName,
            DescriptionFactory.UpdateType.ADD_PORT, this, bindingId, endpointAddress);
    // TODO: Need to set endpointAddress and set or check bindingId on the EndpointDesc
    endpointDesc.setEndpointAddress(endpointAddress);
    endpointDesc.setClientBindingID(bindingId);
}

From source file:org.apache.axis2.jaxws.util.WSDL4JWrapper.java

private Port getPort(QName serviceQname, QName eprQname) {
    Service service = getService(serviceQname);
    if (service == null) {
        return null;
    }/*from   ww w . j  av a  2s . c  o m*/
    return service.getPort(eprQname.getLocalPart());

}

From source file:org.apache.axis2.jaxws.utility.XMLRootElementUtil.java

/**
 * The JAXBClass has a set of bean properties each represented by a PropertyDescriptor Each of
 * the fields of the class has an associated xml name. The method returns a map where the key is
 * the xml name and value is the PropertyDescriptor
 *
 * @param jaxbClass/*from w w w .j  a v a 2  s  .  c o m*/
 * @return map
 */
public static Map<String, PropertyDescriptorPlus> createPropertyDescriptorMap(Class jaxbClass)
        throws NoSuchFieldException, IntrospectionException {

    if (log.isDebugEnabled()) {
        log.debug("Get the PropertyDescriptor[] for " + jaxbClass);
    }

    PropertyDescriptor[] pds = Introspector.getBeanInfo(jaxbClass).getPropertyDescriptors();
    Map<String, PropertyDescriptorPlus> map = new HashMap<String, PropertyDescriptorPlus>();

    // Unfortunately the element names are stored on the fields.
    // Get all of the fields in the class and super classes

    List<Field> fields = getFields(jaxbClass);

    // Now match up the fields with the property descriptors...Sigh why didn't JAXB put the @XMLElement annotations on the 
    // property methods!
    for (PropertyDescriptor pd : pds) {

        // Skip over the class property..it is never represented as an xml element
        if (pd.getName().equals("class")) {
            continue;
        }

        // For the current property, find a matching field...so that we can get the xml name
        boolean found = false;
        if (log.isDebugEnabled()) {
            log.debug("  Start: Find xmlname for property:" + pd.getName());
        }
        for (Field field : fields) {
            String fieldName = field.getName();

            // Use the name of the field and property to find the match
            if (fieldName.equalsIgnoreCase(pd.getDisplayName()) || fieldName.equalsIgnoreCase(pd.getName())) {
                // Get the xmlElement name for this field
                QName xmlName = getXmlElementRefOrElementQName(field.getDeclaringClass(), field);
                found = true;
                if (log.isDebugEnabled()) {
                    log.debug("    Found field " + field.getName() + " which has xmlname=" + xmlName);
                }
                if (map.get(xmlName) != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("    ALERT: property " + map.get(xmlName).getPropertyName()
                                + " already has this same xmlName..this may cause problems.");
                    }
                }
                map.put(xmlName.getLocalPart(), new PropertyDescriptorPlus(pd, xmlName));
                break;
            }

            // Unfortunately, sometimes the field name is preceeded by an underscore
            if (fieldName.startsWith("_")) {
                fieldName = fieldName.substring(1);
                if (fieldName.equalsIgnoreCase(pd.getDisplayName())
                        || fieldName.equalsIgnoreCase(pd.getName())) {
                    // Get the xmlElement name for this field
                    QName xmlName = getXmlElementRefOrElementQName(field.getDeclaringClass(), field);
                    found = true;
                    if (log.isDebugEnabled()) {
                        log.debug("    Found field " + field.getName() + " which has xmlname=" + xmlName);
                    }
                    if (map.get(xmlName) != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("    ALERT: property " + map.get(xmlName).getPropertyName()
                                    + " already has this same xmlName..this may cause problems.");
                        }
                    }
                    map.put(xmlName.getLocalPart(), new PropertyDescriptorPlus(pd, xmlName));
                    break;
                }
            }
        }

        // We didn't find a field.  Default the xmlname to the property name
        if (!found) {
            String xmlName = pd.getName();
            if (log.isDebugEnabled()) {
                log.debug("    A matching field was not found.  Defaulting xmlname to " + xmlName);
            }
            if (map.get(xmlName) != null) {
                if (log.isDebugEnabled()) {
                    log.debug("    ALERT: property " + map.get(xmlName).getPropertyName()
                            + " already has this same xmlName..this may cause problems.");
                }
            }
            map.put(xmlName, new PropertyDescriptorPlus(pd, xmlName));
        }
        if (log.isDebugEnabled()) {
            log.debug("  End: Find xmlname for property:" + pd.getName());
        }
    }
    return map;
}

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

@Validated
@Test/* ww w . j  a  v  a 2 s . c om*/
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

/**
 * Process and Element//from  ww  w  . j  ava 2  s . co m
 *
 * @param xsElt
 * @param isOuter We need to know this since the treatment of outer elements is different that
 *                inner elements
 * @throws SchemaCompilationException
 */
private void processElement(XmlSchemaElement xsElt, boolean isOuter, Map<QName, String> innerElementMap,
        List<QName> localNillableList, XmlSchema parentSchema) throws SchemaCompilationException {

    //if the element is null, which usually happens when the qname is not
    //proper, throw an exceptions
    if (xsElt == null) {
        throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.elementNull"));
    }

    //The processing element logic seems to be quite simple. Look at the relevant schema type
    //for each and every element and process that accordingly.
    //this means that any unused type definitions would not be generated!
    if (isOuter && processedElementList.contains(xsElt.getQName())) {
        return;
    }

    XmlSchemaType schemaType = xsElt.getSchemaType();
    if (schemaType != null) {
        processSchema(xsElt, schemaType, parentSchema, false);
        //at this time it is not wise to directly write the class for the element
        //so we push the complete element to an arraylist and let the process
        //pass through. We'll be iterating through the elements writing them
        //later

        if (!isOuter) {
            if (schemaType.getName() != null) {
                // this element already has a name. Which means we can directly
                // register it
                String className = findClassName(schemaType.getQName(), isArray(xsElt));

                innerElementMap.put(xsElt.getQName(), className);

                // always store the class name in the element meta Info itself
                // this details only needed by the unwrappig to set the complex type
                if (options.isUseWrapperClasses() && PrimitiveTypeFinder.isPrimitive(className)) {
                    className = PrimitiveTypeWrapper.getWrapper(className);
                }
                schemaType.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, className);
                xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, className);

                if (baseSchemaTypeMap.containsValue(className)) {
                    schemaType.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_PRIMITVE_KEY,
                            Boolean.TRUE);
                }
                //since this is a inner element we should add it to the inner element map
            } else {
                //this is an anon type. This should have been already processed and registered at
                //the anon map. we've to write it just like we treat a referenced type(giving due
                //care that this is meant to be an attribute in some class)

                QName generatedTypeName = generateTypeQName(xsElt.getQName(), parentSchema);

                if (schemaType instanceof XmlSchemaComplexType) {
                    //set a name
                    schemaType.setName(generatedTypeName.getLocalPart());
                    changedComplexTypeSet.add((XmlSchemaComplexType) schemaType);
                    // Must do this up front to support recursive types
                    String fullyQualifiedClassName = writer.makeFullyQualifiedClassName(schemaType.getQName());
                    processedTypemap.put(schemaType.getQName(), fullyQualifiedClassName);

                    BeanWriterMetaInfoHolder metaInfHolder = processedAnonymousComplexTypesMap.get(xsElt);
                    metaInfHolder.setOwnQname(schemaType.getQName());
                    metaInfHolder.setOwnClassName(fullyQualifiedClassName);

                    writeComplexType((XmlSchemaComplexType) schemaType, metaInfHolder);
                    //remove the reference from the anon list since we named the type
                    processedAnonymousComplexTypesMap.remove(xsElt);
                    String className = findClassName(schemaType.getQName(), isArray(xsElt));
                    innerElementMap.put(xsElt.getQName(), className);

                    //store in the schema map to retrive in the unwrapping
                    xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, className);
                } else if (schemaType instanceof XmlSchemaSimpleType) {
                    //set a name
                    schemaType.setName(generatedTypeName.getLocalPart());
                    changedSimpleTypeSet.add((XmlSchemaSimpleType) schemaType);
                    // Must do this up front to support recursive types
                    String fullyQualifiedClassName = writer.makeFullyQualifiedClassName(schemaType.getQName());
                    processedTypemap.put(schemaType.getQName(), fullyQualifiedClassName);

                    BeanWriterMetaInfoHolder metaInfHolder = processedAnonymousComplexTypesMap.get(xsElt);
                    metaInfHolder.setOwnQname(schemaType.getQName());
                    metaInfHolder.setOwnClassName(fullyQualifiedClassName);

                    writeSimpleType((XmlSchemaSimpleType) schemaType, metaInfHolder);
                    //remove the reference from the anon list since we named the type
                    processedAnonymousComplexTypesMap.remove(xsElt);
                    String className = findClassName(schemaType.getQName(), isArray(xsElt));
                    innerElementMap.put(xsElt.getQName(), className);

                    //store in the schema map
                    xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, className);
                }
            }
        } else {
            // set the binary status of this element
            this.processedElementList.add(xsElt.getQName());
        }
        //referenced name
    } else if (xsElt.getRefName() != null) {

        if (xsElt.getRefName().equals(SchemaConstants.XSD_SCHEMA)) {
            innerElementMap.put(xsElt.getQName(), writer.getDefaultClassName());
            return;
        }
        //process the referenced type. It could be thought that the referenced element replaces this
        //element
        XmlSchema resolvedSchema = getParentSchema(parentSchema, xsElt.getRefName(), COMPONENT_ELEMENT);
        if (resolvedSchema == null) {
            throw new SchemaCompilationException("can not find the element " + xsElt.getRefName()
                    + " from the parent schema " + parentSchema.getTargetNamespace());
        }
        XmlSchemaElement referencedElement = resolvedSchema.getElementByName(xsElt.getRefName());
        if (referencedElement == null) {
            throw new SchemaCompilationException(SchemaCompilerMessages
                    .getMessage("schema.referencedElementNotFound", xsElt.getRefName().toString()));
        }

        // here what we want is to set the schema type name for the element
        if ((referencedElement.getSchemaType() != null)
                && (referencedElement.getSchemaType().getQName() != null)) {

            // i.e this element refers to an complex type name
            if (!this.processedElementRefMap.containsKey(referencedElement.getQName())) {
                if (this.baseSchemaTypeMap.containsKey(referencedElement.getSchemaTypeName())) {
                    this.processedElementRefMap.put(referencedElement.getQName(),
                            this.baseSchemaTypeMap.get(referencedElement.getSchemaTypeName()));
                } else {
                    XmlSchema resolvedTypeSchema = getParentSchema(resolvedSchema,
                            referencedElement.getSchemaTypeName(), COMPONENT_TYPE);
                    XmlSchemaType xmlSchemaType = resolvedTypeSchema
                            .getTypeByName(referencedElement.getSchemaTypeName().getLocalPart());
                    processSchema(referencedElement, xmlSchemaType, resolvedTypeSchema, true);
                    this.processedElementRefMap.put(referencedElement.getQName(),
                            this.processedTypemap.get(referencedElement.getSchemaTypeName()));
                }
            }
            String javaClassName;
            if (this.baseSchemaTypeMap.containsKey(referencedElement.getSchemaTypeName())) {
                // here we have to do nothing since we do not generate a name
            } else {
                javaClassName = this.processedTypemap.get(referencedElement.getSchemaTypeName());
                referencedElement.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY,
                        javaClassName);
                xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, javaClassName);
            }
        } else if (referencedElement.getSchemaType() != null) {
            if (!this.processedElementRefMap.containsKey(referencedElement.getQName())) {

                processSchema(referencedElement, referencedElement.getSchemaType(), resolvedSchema, true);
                // if this is an anonomous complex type we have to set this
                this.processedElementRefMap.put(referencedElement.getQName(),
                        this.processedTypemap.get(referencedElement.getSchemaTypeName()));

            }

            String javaClassName = this.processedTypemap.get(referencedElement.getSchemaTypeName());
            referencedElement.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY,
                    javaClassName);
            xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, javaClassName);
        } else if (referencedElement.getSchemaTypeName() != null) {
            QName schemaTypeName = referencedElement.getSchemaTypeName();
            XmlSchema newResolvedSchema = getParentSchema(resolvedSchema, schemaTypeName, COMPONENT_TYPE);
            XmlSchemaType xmlSchemaType = newResolvedSchema.getTypeByName(schemaTypeName);
            if (xmlSchemaType != null) {
                if (!this.processedElementRefMap.containsKey(referencedElement.getQName())) {
                    // we know this is a named complex type
                    processSchema(referencedElement, xmlSchemaType, newResolvedSchema, false);
                    // if this is an anonomous complex type we have to set this
                    this.processedElementRefMap.put(referencedElement.getQName(),
                            this.processedTypemap.get(schemaTypeName));

                }

                String javaClassName = this.processedTypemap.get(referencedElement.getSchemaTypeName());
                referencedElement.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY,
                        javaClassName);
                xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, javaClassName);
            } else {
                throw new SchemaCompilationException(
                        " Can not find the schema type with name " + schemaTypeName);
            }

        }

        // schema type name is present but not the schema type object
    } else if (xsElt.getSchemaTypeName() != null) {
        //There can be instances where the SchemaType is null but the schemaTypeName is not!
        //this specifically happens with xsd:anyType.
        QName schemaTypeName = xsElt.getSchemaTypeName();

        XmlSchema resolvedSchema = getParentSchema(parentSchema, schemaTypeName, COMPONENT_TYPE);
        XmlSchemaType typeByName = null;
        if (resolvedSchema != null) {
            typeByName = resolvedSchema.getTypeByName(schemaTypeName);
        }

        if (typeByName != null) {
            //this type is found in the schema so we can process it
            processSchema(xsElt, typeByName, resolvedSchema, false);
            if (!isOuter) {
                String className = findClassName(schemaTypeName, isArray(xsElt));
                //since this is a inner element we should add it to the inner element map
                innerElementMap.put(xsElt.getQName(), className);
                // set the class name to be used in unwrapping
                xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, className);
            } else {
                this.processedElementList.add(xsElt.getQName());
            }
        } else {
            //this type is not found at all. we'll just register it with whatever the class name we can comeup with
            if (!isOuter) {
                String className = findClassName(schemaTypeName, isArray(xsElt));
                innerElementMap.put(xsElt.getQName(), className);
                // set the class name to be used in unwrapping
                xsElt.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, className);
            } else {
                this.processedElementList.add(xsElt.getQName());
            }
        }
    }

    //add this elements QName to the nillable group if it has the  nillable attribute
    if (xsElt.isNillable()) {
        if (isOuter) {
            this.nillableElementList.add(xsElt.getQName());
        } else {
            localNillableList.add(xsElt.getQName());
        }
    }

}

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

/**
 * Generate a unique type Qname using an element name
 *
 * @param referenceEltQName//from w  ww.  j  av  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

/**
 * @param complexType/*from  w  w  w.  j  a v  a2s  . c  o m*/
 * @throws SchemaCompilationException
 */
private void processAnonymousComplexSchemaType(XmlSchemaElement elt, XmlSchemaComplexType complexType,
        XmlSchema parentSchema, boolean isWriteAnonComplexType) throws SchemaCompilationException {

    //here we have a problem when processing the circulare element
    // references if we differ this processing
    // generate a name to the complex type and register it here
    QName generatedTypeName = null;
    String javaClassName = null;
    if (isWriteAnonComplexType) {

        generatedTypeName = generateTypeQName(elt.getQName(), parentSchema);

        if (elt.getSchemaTypeName() == null) {
            elt.setSchemaTypeName(generatedTypeName);
            this.changedElementSet.add(elt);
        }

        //set a name
        complexType.setName(generatedTypeName.getLocalPart());
        this.changedComplexTypeSet.add(complexType);

        javaClassName = writer.makeFullyQualifiedClassName(generatedTypeName);
        processedTypemap.put(generatedTypeName, javaClassName);
        this.processedElementRefMap.put(elt.getQName(), javaClassName);
        complexType.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, javaClassName);
    }

    BeanWriterMetaInfoHolder metaInfHolder = processComplexType(elt.getQName(), complexType, parentSchema);

    // here the only difference is that we generate the class
    // irrespective of where we need it or not
    if (isWriteAnonComplexType) {
        metaInfHolder.setOwnClassName(javaClassName);
        metaInfHolder.setOwnQname(generatedTypeName);
        writeComplexType(complexType, metaInfHolder);
    }

    //since this is a special case (an unnamed complex type) we'll put the already processed
    //metainf holder in a special map to be used later
    this.processedAnonymousComplexTypesMap.put(elt, metaInfHolder);

}

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

private void processAttributeGroupReference(XmlSchemaAttributeGroupRef attributeGroupRef,
        BeanWriterMetaInfoHolder metaInfHolder, XmlSchema parentSchema) throws SchemaCompilationException {

    QName attributeGroupRefName = attributeGroupRef.getRefName();
    if (attributeGroupRefName != null) {
        XmlSchema resolvedSchema = getParentSchema(parentSchema, attributeGroupRefName,
                COMPONENT_ATTRIBUTE_GROUP);
        if (resolvedSchema == null) {
            throw new SchemaCompilationException("can not find the attribute group reference name "
                    + attributeGroupRefName + " from the parent schema " + parentSchema.getTargetNamespace());
        } else {/*from w  w w. java 2s. c o m*/
            XmlSchemaAttributeGroup xmlSchemaAttributeGroup = (XmlSchemaAttributeGroup) resolvedSchema
                    .getAttributeGroups().getItem(attributeGroupRefName);
            if (xmlSchemaAttributeGroup != null) {
                processAttributes(xmlSchemaAttributeGroup.getAttributes(), metaInfHolder, resolvedSchema);
            } else {
                throw new SchemaCompilationException("Can not find an attribute group for group reference "
                        + attributeGroupRefName.getLocalPart());
            }
        }

    } else {
        throw new SchemaCompilationException("No group refernce has given");
    }
}

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

/**
 * Process the attribute//from  w  w  w  .j  a  v  a  2s  . com
 *
 * @param att
 * @param metainf
 */
public void processAttribute(XmlSchemaAttribute att, BeanWriterMetaInfoHolder metainf, XmlSchema parentSchema)
        throws SchemaCompilationException {

    QName schemaTypeName = att.getSchemaTypeName();
    if (schemaTypeName != null) {
        if (att.getQName() != null) {
            if (baseSchemaTypeMap.containsKey(schemaTypeName)) {

                metainf.registerMapping(att.getQName(), schemaTypeName,
                        baseSchemaTypeMap.get(schemaTypeName).toString(), SchemaConstants.ATTRIBUTE_TYPE);

                // add optional attribute status if set
                String use = att.getUse().getValue();
                if (USE_NONE.equals(use) || USE_OPTIONAL.equals(use)) {
                    metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
                }

                String className = findClassName(schemaTypeName, false);

                att.addMetaInfo(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY, className);
                // set the default value
                if (att.getDefaultValue() != null) {
                    metainf.registerDefaultValue(att.getQName(), att.getDefaultValue());
                }
                // after
            } else {
                XmlSchema resolvedSchema = getParentSchema(parentSchema, schemaTypeName, COMPONENT_TYPE);
                if (resolvedSchema == null) {
                    throw new SchemaCompilationException("can not find the type " + schemaTypeName
                            + " from the parent schema " + parentSchema.getTargetNamespace());
                } else {
                    XmlSchemaType type = resolvedSchema.getTypeByName(schemaTypeName);
                    if (type instanceof XmlSchemaSimpleType) {
                        XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;

                        if (simpleType != null) {
                            if (!isAlreadyProcessed(schemaTypeName)) {
                                //process simple type
                                processSimpleSchemaType(simpleType, null, resolvedSchema, null);
                            }
                            metainf.registerMapping(att.getQName(), schemaTypeName,
                                    processedTypemap.get(schemaTypeName).toString(),
                                    SchemaConstants.ATTRIBUTE_TYPE);
                            // add optional attribute status if set
                            String use = att.getUse().getValue();
                            if (USE_NONE.equals(use) || USE_OPTIONAL.equals(use)) {
                                metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
                            }
                        }

                    }
                }
            }
        } else {
            // this attribute has a type but does not have a name, seems to be invalid
        }

    } else if (att.getRefName() != null) {

        XmlSchema resolvedSchema = getParentSchema(parentSchema, att.getRefName(), COMPONENT_ATTRIBUTE);
        if (resolvedSchema == null) {
            throw new SchemaCompilationException("can not find the attribute " + att.getRefName()
                    + " from the parent schema " + parentSchema.getTargetNamespace());
        } else {
            XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute) resolvedSchema.getAttributes()
                    .getItem(att.getRefName());
            if (xmlSchemaAttribute != null) {
                // call recursively to process the schema
                processAttribute(xmlSchemaAttribute, metainf, resolvedSchema);
            } else {
                throw new SchemaCompilationException(
                        "Attribute QName reference refer to an invalid attribute " + att.getRefName());
            }
        }

    } else {
        // this attribute refers to a custom type, probably one of the extended simple types.
        // with the inline schema definition
        QName attributeQName = att.getQName();
        if (attributeQName != null) {
            XmlSchemaSimpleType attributeSimpleType = att.getSchemaType();
            XmlSchema resolvedSchema = parentSchema;
            if (attributeSimpleType == null) {
                // try to get the schema for using qname
                QName attributeSchemaQname = att.getSchemaTypeName();
                if (attributeSchemaQname != null) {
                    resolvedSchema = getParentSchema(parentSchema, attributeSchemaQname, COMPONENT_TYPE);
                    if (resolvedSchema == null) {
                        throw new SchemaCompilationException("can not find the type " + attributeSchemaQname
                                + " from the parent schema " + parentSchema.getTargetNamespace());
                    } else {
                        attributeSimpleType = (XmlSchemaSimpleType) resolvedSchema
                                .getTypeByName(attributeSchemaQname);
                    }
                }
            }

            if (attributeSimpleType != null) {
                QName schemaTypeQName = att.getSchemaTypeName();
                if (schemaTypeQName == null) {
                    // set the parent schema target name space since attribute Qname uri is ""
                    if (attributeSimpleType.getQName() != null) {
                        schemaTypeQName = attributeSimpleType.getQName();
                    } else {
                        schemaTypeQName = new QName(parentSchema.getTargetNamespace(),
                                attributeQName.getLocalPart()
                                        + getNextTypeSuffix(attributeQName.getLocalPart()));

                    }
                }
                if (!isAlreadyProcessed(schemaTypeQName)) {
                    // we have to process only if it has not processed
                    processSimpleSchemaType(attributeSimpleType, null, resolvedSchema, schemaTypeQName);
                }
                metainf.registerMapping(att.getQName(), schemaTypeQName,
                        processedTypemap.get(schemaTypeQName).toString(), SchemaConstants.ATTRIBUTE_TYPE);
                // add optional attribute status if set
                String use = att.getUse().getValue();
                if (USE_NONE.equals(use) || USE_OPTIONAL.equals(use)) {
                    metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
                }
            } else {
                // TODO: handle the case when no attribute type specifed
                log.warn("No attribute type has defined to the Attribute " + attributeQName);
            }

        } else {
            throw new SchemaCompilationException(
                    "Attribute QName reference refer to an invalid attribute " + attributeQName);
        }

    }
}