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.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);
    }// w  w w.j a v  a 2 s  .c  om
    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

/**
 * returns the parent schema of the componet having QName compoentTypeQName.
 * withe the componet type.//from w  w w . j  av  a  2s . c o  m
 * @param parentSchema - parent schema of the given componet
 * @param componentQName - qname of the componet, of which we want to get the parent schema
 * @param componetType - type of the componet. this can either be type,element,attribute or attribute group
 * @return parent schema.
 */

private XmlSchema getParentSchema(XmlSchema parentSchema, QName componentQName, int componetType)
        throws SchemaCompilationException {
    // if the componet do not have a propernamesapce or
    // it is equals to the xsd schema namesapce
    // we do not have to do any thing.
    if ((componentQName == null) || (componentQName.getNamespaceURI() == null)
            || Constants.URI_2001_SCHEMA_XSD.equals(componentQName.getNamespaceURI())) {
        return parentSchema;
    }

    List<XmlSchema> visitedSchemas = new ArrayList<XmlSchema>();
    visitedSchemas.add(parentSchema);
    XmlSchema newParentSchema = getParentSchemaFromIncludes(parentSchema, componentQName, componetType,
            visitedSchemas);
    if (newParentSchema == null) {
        String targetNamespace = componentQName.getNamespaceURI();
        if (loadedSchemaMap.containsKey(targetNamespace)) {
            XmlSchema tempSchema = loadedSchemaMap.get(targetNamespace);
            if (isComponetExists(tempSchema, componentQName, componetType)) {
                newParentSchema = tempSchema;
            }
        } else if (availableSchemaMap.containsKey(targetNamespace)) {
            XmlSchema tempSchema = availableSchemaMap.get(targetNamespace);
            if (isComponetExists(tempSchema, componentQName, componetType)) {
                compile(tempSchema);
                newParentSchema = tempSchema;
            }
        }
    }
    return newParentSchema;
}

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//from  w w  w  .  j ava 2  s .  c  o  m
 */
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/*from  w ww  . j a  va  2s. c om*/
 * @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

/**
 * @param model/*  www.  j  ava2 s .  co m*/
 * @param className
 * @param originalName
 * @param packageName
 * @param qName
 * @param isElement
 * @param metainf
 * @param propertyNames
 * @param typeMap
 * @return Returns Element.
 * @throws SchemaCompilationException
 */
private Element getBeanElement(Document model, String className, String originalName, String packageName,
        QName qName, boolean isElement, boolean isAbstract, BeanWriterMetaInfoHolder metainf,
        ArrayList<String> propertyNames, Map<QName, String> typeMap, Map<QName, String> groupTypeMap)
        throws SchemaCompilationException {

    Element rootElt = XSLTUtils.getElement(model, "bean");
    XSLTUtils.addAttribute(model, "name", className, rootElt);
    XSLTUtils.addAttribute(model, "originalName", originalName, rootElt);
    XSLTUtils.addAttribute(model, "package", packageName, rootElt);
    XSLTUtils.addAttribute(model, "nsuri", qName.getNamespaceURI(), rootElt);
    XSLTUtils.addAttribute(model, "nsprefix",
            isSuppressPrefixesMode ? "" : getPrefixForURI(qName.getNamespaceURI(), qName.getPrefix()), rootElt);

    if (!wrapClasses) {
        XSLTUtils.addAttribute(model, "unwrapped", "yes", rootElt);
    }

    if (isAbstract) {
        XSLTUtils.addAttribute(model, "isAbstract", "yes", rootElt);
    }

    if (!writeClasses) {
        XSLTUtils.addAttribute(model, "skip-write", "yes", rootElt);
    }

    if (!isElement) {
        XSLTUtils.addAttribute(model, "type", "yes", rootElt);
    }

    if (metainf.isAnonymous()) {
        XSLTUtils.addAttribute(model, "anon", "yes", rootElt);
    }

    if (isUseWrapperClasses) {
        XSLTUtils.addAttribute(model, "usewrapperclasses", "yes", rootElt);
    }

    if (metainf.isExtension()) {
        XSLTUtils.addAttribute(model, "extension", metainf.getExtensionClassName(), rootElt);

    }
    if (metainf.isRestriction()) {
        XSLTUtils.addAttribute(model, "restriction", metainf.getRestrictionClassName(), rootElt);

    }
    //add the mapper class name
    XSLTUtils.addAttribute(model, "mapperClass", getFullyQualifiedMapperClassName(), rootElt);

    if (metainf.isChoice()) {
        XSLTUtils.addAttribute(model, "choice", "yes", rootElt);
    }

    if (metainf.isSimple()) {
        XSLTUtils.addAttribute(model, "simple", "yes", rootElt);
    }

    if (metainf.isUnion()) {
        XSLTUtils.addAttribute(model, "union", "yes", rootElt);
    }

    if (metainf.isList()) {
        XSLTUtils.addAttribute(model, "list", "yes", rootElt);
    }

    if (metainf.isOrdered()) {
        XSLTUtils.addAttribute(model, "ordered", "yes", rootElt);
    }

    if (isElement && metainf.isNillable(qName)) {
        XSLTUtils.addAttribute(model, "nillable", "yes", rootElt);
    }

    if (metainf.isParticleClass()) {
        XSLTUtils.addAttribute(model, "particleClass", "yes", rootElt);
    }

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

    // populate all the information
    populateInfo(metainf, model, rootElt, propertyNames, typeMap, groupTypeMap, false);

    if (metainf.isSimple() && metainf.isUnion()) {
        populateMemberInfo(metainf, model, rootElt, typeMap);
    }

    if (metainf.isSimple() && metainf.isList()) {
        populateListInfo(metainf, model, rootElt, typeMap, groupTypeMap);
    }
    //////////////////////////////////////////////////////////
    //        System.out.println(DOM2Writer.nodeToString(rootElt));
    ////////////////////////////////////////////////////////////

    return rootElt;
}

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);
        }/*from   ww w  . ja  va  2s.  com*/

        // 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// www.j  a v a2 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

/**
 * Write the extension classes - this is needed to process
 * the hierarchy of classes/*from   w w w  .  java2  s.  co  m*/
 *
 * @param metainfArray
 */
public void writeExtensionMapper(BeanWriterMetaInfoHolder[] metainfArray) throws SchemaCompilationException {
    //generate the element
    try {

        String mapperClassName = getFullyQualifiedMapperClassName();

        Document model = XSLTUtils.getDocument();
        Element rootElt = XSLTUtils.getElement(model, "mapper");
        String mapperName = mapperClassName.substring(mapperClassName.lastIndexOf(".") + 1);
        XSLTUtils.addAttribute(model, "name", mapperName, rootElt);
        String basePackageName = "";
        if (mapperClassName.indexOf(".") != -1) {
            basePackageName = mapperClassName.substring(0, mapperClassName.lastIndexOf("."));
            XSLTUtils.addAttribute(model, "package", basePackageName, rootElt);
        } else {
            XSLTUtils.addAttribute(model, "package", "", rootElt);
        }

        if (!wrapClasses) {
            XSLTUtils.addAttribute(model, "unwrapped", "yes", rootElt);
        }

        if (!writeClasses) {
            XSLTUtils.addAttribute(model, "skip-write", "yes", rootElt);
        }

        if (isHelperMode) {
            XSLTUtils.addAttribute(model, "helpermode", "yes", rootElt);
        }

        for (int i = 0; i < metainfArray.length; i++) {
            QName ownQname = metainfArray[i].getOwnQname();
            String className = metainfArray[i].getOwnClassName();
            //do  not add when the qname is not availble
            if (ownQname != null) {
                Element typeChild = XSLTUtils.addChildElement(model, "type", rootElt);
                XSLTUtils.addAttribute(model, "nsuri", ownQname.getNamespaceURI(), typeChild);
                XSLTUtils.addAttribute(model, "classname", className == null ? "" : className, typeChild);
                XSLTUtils.addAttribute(model, "shortname", ownQname == null ? "" : ownQname.getLocalPart(),
                        typeChild);
            }
        }

        model.appendChild(rootElt);

        if (!templateLoaded) {
            loadTemplate();
        }

        if (wrapClasses) {
            rootElt = (Element) globalWrappedDocument.importNode(rootElt, true);
            //add to the global wrapped document
            globalWrappedDocument.getDocumentElement().appendChild(rootElt);
        } else {
            if (writeClasses) {
                // create the file
                File out = createOutFile(basePackageName, mapperName);
                // parse with the template and create the files
                parse(model, out);

            }

            // add the model to the model map
            modelMap.put(new QName(mapperName), model);
        }

    } catch (ParserConfigurationException e) {
        throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.docuement.error"), e);
    } catch (Exception e) {
        e.printStackTrace();
        throw new SchemaCompilationException(e);
    }

}

From source file:org.apache.axis2.transport.sms.DefaultSMSMessageBuilderImpl.java

private SOAPEnvelope createSoapEnvelope(MessageContext messageContext, Map params) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope inEnvlope = soapFactory.getDefaultEnvelope();
    SOAPBody inBody = inEnvlope.getBody();
    XmlSchemaElement xmlSchemaElement;//from  www.ja  v a 2  s  .c o  m
    AxisOperation axisOperation = messageContext.getAxisOperation();
    if (axisOperation != null) {
        AxisMessage axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        xmlSchemaElement = axisMessage.getSchemaElement();

        if (xmlSchemaElement == null) {
            OMElement bodyFirstChild = soapFactory.createOMElement(messageContext.getAxisOperation().getName(),
                    inBody);
            createSOAPMessageWithoutSchema(soapFactory, bodyFirstChild, params);
        } else {

            // first get the target namespace from the schema and the wrapping element.
            // create an OMElement out of those information. We are going to extract parameters from
            // url, create OMElements and add them as children to this wrapping element.
            String targetNamespace = xmlSchemaElement.getQName().getNamespaceURI();
            QName bodyFirstChildQName;
            if (targetNamespace != null && !"".equals(targetNamespace)) {
                bodyFirstChildQName = new QName(targetNamespace, xmlSchemaElement.getName());
            } else {
                bodyFirstChildQName = new QName(xmlSchemaElement.getName());
            }
            OMElement bodyFirstChild = soapFactory.createOMElement(bodyFirstChildQName, inBody);

            // Schema should adhere to the IRI style in this. So assume IRI style and dive in to
            // schema
            XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
            if (schemaType instanceof XmlSchemaComplexType) {
                XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
                XmlSchemaParticle particle = complexType.getParticle();
                if (particle instanceof XmlSchemaSequence || particle instanceof XmlSchemaAll) {
                    XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) particle;
                    Iterator iterator = xmlSchemaGroupBase.getItems().getIterator();

                    // now we need to know some information from the binding operation.

                    while (iterator.hasNext()) {
                        XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next();
                        QName qName = innerElement.getQName();
                        if (qName == null && innerElement.getSchemaTypeName()
                                .equals(org.apache.ws.commons.schema.constants.Constants.XSD_ANYTYPE)) {
                            createSOAPMessageWithoutSchema(soapFactory, bodyFirstChild, params);
                            break;
                        }
                        long minOccurs = innerElement.getMinOccurs();
                        boolean nillable = innerElement.isNillable();
                        String name = qName != null ? qName.getLocalPart() : innerElement.getName();
                        Object value;
                        OMNamespace ns = (qName == null || qName.getNamespaceURI() == null
                                || qName.getNamespaceURI().length() == 0) ? null
                                        : soapFactory.createOMNamespace(qName.getNamespaceURI(), null);

                        // FIXME changed
                        if ((value = params.get(name)) != null) {
                            addRequestParameter(soapFactory, bodyFirstChild, ns, name, value);
                            minOccurs--;
                        }
                        if (minOccurs > 0) {
                            if (nillable) {

                                OMNamespace xsi = soapFactory.createOMNamespace(
                                        Constants.URI_DEFAULT_SCHEMA_XSI, Constants.NS_PREFIX_SCHEMA_XSI);
                                OMAttribute omAttribute = soapFactory.createOMAttribute("nil", xsi, "true");
                                soapFactory.createOMElement(name, ns, bodyFirstChild).addAttribute(omAttribute);

                            } else {
                                //                                    throw new AxisFault("Required element " + qName +
                                //                                                        " defined in the schema can not be" +
                                //                                                        " found in the request");
                            }
                        }
                    }
                }
            }
        }

    }

    return inEnvlope;

}

From source file:org.apache.axis2.util.MessageContextBuilder.java

/**
 * Information to create the SOAPFault can be extracted from different places.
 * 1. Those information may have been put in to the message context by some handler. When someone
 * is putting like that, he must make sure the SOAPElements he is putting must be from the
 * correct SOAP Version./*from   w  w  w .j  a  v a  2s  .  co  m*/
 * 2. SOAPProcessingException is flexible enough to carry information about the fault. For example
 * it has an attribute to store the fault code. The fault reason can be extracted from the
 * message of the exception. I opted to put the stacktrace under the detail element.
 * eg : <Detail>
 * <Exception> stack trace goes here </Exception>
 * <Detail>
 * <p/>
 * If those information can not be extracted from any of the above places, I default the soap
 * fault values to following.
 * <Fault>
 * <Code>
 * <Value>env:Receiver</Value>
 * </Code>
 * <Reason>
 * <Text>unknown</Text>
 * </Reason>
 * <Role/>
 * <Node/>
 * <Detail/>
 * </Fault>
 * <p/>
 * -- EC
 *
 * @param context
 * @param e
 */
private static SOAPEnvelope createFaultEnvelope(MessageContext context, Throwable e) {
    SOAPEnvelope envelope;

    if (log.isDebugEnabled()) {
        log.debug("start createFaultEnvelope()");
    }
    if (context.isSOAP11()) {
        envelope = OMAbstractFactory.getSOAP11Factory().getDefaultFaultEnvelope();
    } else {
        // Following will make SOAP 1.2 as the default, too.
        envelope = OMAbstractFactory.getSOAP12Factory().getDefaultFaultEnvelope();
    }
    SOAPFault fault = envelope.getBody().getFault();
    SOAPProcessingException soapException = null;
    AxisFault axisFault = null;

    if (e == null)
        return envelope;

    if (e instanceof AxisFault) {
        axisFault = (AxisFault) e;
    } else if (e.getCause() instanceof AxisFault) {
        axisFault = (AxisFault) e.getCause();
    }

    if (axisFault != null) {
        Iterator iter = axisFault.headerIterator();
        while (iter.hasNext()) {
            SOAPHeaderBlock header = (SOAPHeaderBlock) iter.next();
            envelope.getHeader().addChild(header);
        }
    }

    if (e instanceof SOAPProcessingException) {
        soapException = (SOAPProcessingException) e;
    } else if (axisFault != null) {
        if (axisFault.getCause() instanceof SOAPProcessingException) {
            soapException = (SOAPProcessingException) axisFault.getCause();
        }
    }

    // user can set the fault information to the message context or to the AxisFault itself.
    // whatever user sets to the message context, supercedes eerything.

    Object faultCode = context.getProperty(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME);
    String soapFaultCode = "";

    if (faultCode != null) {
        if (log.isDebugEnabled()) {
            log.debug("faultCode != null");
        }
        fault.setCode((SOAPFaultCode) faultCode);
        soapFaultCode = ((SOAPFaultCode) faultCode).getText();
    } else if (soapException != null) {
        if (log.isDebugEnabled()) {
            log.debug("soapException != null");
        }
        soapFaultCode = soapException.getFaultCode();
        OMNamespace namespace = null;
        if (envelope != null) {
            if (log.isDebugEnabled()) {
                log.debug("envelope!=null");
            }
            namespace = envelope.getNamespace();
        }

        if (namespace != null) {
            String sfcLocalPart = soapFaultCode.substring(soapFaultCode.lastIndexOf(":") + 1);

            //If the fault code is one of the predefined ones that make sure the prefix 
            //matches that of the envelope NS
            if (sfcLocalPart.equals(SOAPConstants.FAULT_CODE_VERSION_MISMATCH)
                    || sfcLocalPart.equals(SOAPConstants.FAULT_CODE_MUST_UNDERSTAND)
                    || sfcLocalPart.equals(SOAPConstants.FAULT_CODE_DATA_ENCODING_UNKNOWN)
                    || sfcLocalPart.equals(SOAPConstants.FAULT_CODE_RECEIVER)
                    || sfcLocalPart.equals(SOAPConstants.FAULT_CODE_SENDER)) {

                if (log.isDebugEnabled()) {
                    log.debug("SoapFaultCode local part= " + sfcLocalPart);
                }

                String prefix = namespace.getPrefix() + ":";

                if (!soapFaultCode.contains(":")) {
                    soapFaultCode = prefix + soapFaultCode;
                } else {
                    soapFaultCode = prefix + soapFaultCode.substring(soapFaultCode.indexOf(":") + 1);
                }

                if (log.isDebugEnabled()) {
                    log.debug("SoapFaultCode reset to " + soapFaultCode);
                }

            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Namespace is null, cannot attach prefix to SOAPFaultCode");
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("SoapFaultCode =" + soapFaultCode);
        }

    } else if (axisFault != null) {
        if (log.isDebugEnabled()) {
            log.debug("axisFault != null");
        }
        if (axisFault.getFaultCodeElement() != null) {
            fault.setCode(axisFault.getFaultCodeElement());
            soapFaultCode = axisFault.getFaultCodeElement().getText();
        } else {
            QName faultCodeQName = axisFault.getFaultCode();
            if (faultCodeQName != null) {
                if (log.isDebugEnabled()) {
                    log.debug("prefix =" + faultCodeQName.getPrefix());
                    log.debug("Fault Code namespace =" + faultCodeQName.getNamespaceURI());
                    log.debug("Fault Code =" + faultCodeQName.getLocalPart());
                }
                if (faultCodeQName.getLocalPart().indexOf(":") == -1) {
                    if (log.isDebugEnabled()) {
                        log.debug("faultCodeQName.getLocalPart().indexOf(\":\") == -1");
                    }
                    String prefix = faultCodeQName.getPrefix();
                    if (log.isDebugEnabled()) {
                        log.debug("prefix = " + prefix);
                    }
                    String uri = faultCodeQName.getNamespaceURI();
                    // Get the specified prefix and uri
                    prefix = prefix == null ? "" : prefix;
                    uri = uri == null || "".equals(uri) ? fault.getNamespace().getNamespaceURI() : uri;
                    // Make sure the prefix and uri are declared on the fault, and 
                    // get the resulting prefix.
                    prefix = fault.declareNamespace(uri, prefix).getPrefix();
                    soapFaultCode = prefix + ":" + faultCodeQName.getLocalPart();
                    if (log.isDebugEnabled()) {
                        log.debug("Altered soapFaultCode =" + soapFaultCode);
                    }
                } else {
                    soapFaultCode = faultCodeQName.getLocalPart();
                }
            }
        }
    }

    // defaulting to fault code Receiver, if no message is available
    if (faultCode == null && context.getEnvelope() != null) {
        soapFaultCode = ("".equals(soapFaultCode) || (soapFaultCode == null))
                ? SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX + ":"
                        + context.getEnvelope().getVersion().getReceiverFaultCode().getLocalPart()
                : soapFaultCode;
    }

    if (faultCode == null) {
        if (log.isDebugEnabled()) {
            log.debug("faultCode == null");
        }
        if (context.isSOAP11()) {
            if (log.isDebugEnabled()) {
                log.debug("context.isSOAP11() = true");
                SOAPFaultCode code = (fault != null) ? fault.getCode() : null;
                SOAPFaultValue value = (code != null) ? code.getValue() : null;
                if (value != null) {
                    QName name = value.getQName();
                    log.debug("prefix =" + name.getPrefix());
                    log.debug("Fault Code namespace =" + name.getNamespaceURI());
                    log.debug("Fault Code =" + name.getLocalPart());
                }
            }

            fault.getCode().setText(soapFaultCode);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("context.isSOAP11() = false");
                SOAPFaultCode code = (fault != null) ? fault.getCode() : null;
                SOAPFaultValue value = (code != null) ? code.getValue() : null;
                if (value != null) {
                    QName name = value.getQName();
                    log.debug("prefix =" + name.getPrefix());
                    log.debug("Fault Code namespace =" + name.getNamespaceURI());
                    log.debug("Fault Code =" + name.getLocalPart());
                }
            }
            SOAPFaultValue value = fault.getCode().getValue();
            if (log.isDebugEnabled()) {
                log.debug("soapFaultCode originally was set to : " + soapFaultCode);
            }
            OMNamespace namespace = value.getNamespace();
            soapFaultCode = switchNamespacePrefix(soapFaultCode, namespace);
            value.setText(soapFaultCode);
        }
    }

    if (axisFault != null && !context.isSOAP11()) {
        if (axisFault.getFaultSubCodes() != null) {

            List faultSubCodes = axisFault.getFaultSubCodes();

            QName faultSubCodeQName;

            for (Object faultSubCode : faultSubCodes) {

                faultSubCodeQName = (QName) faultSubCode;

                SOAPFactory sf = (SOAPFactory) envelope.getOMFactory();
                SOAPFaultSubCode soapFaultSubCode = sf.createSOAPFaultSubCode(fault.getCode());
                SOAPFaultValue saopFaultValue = sf.createSOAPFaultValue(fault.getCode());
                saopFaultValue.setText(faultSubCodeQName);
                soapFaultSubCode.setValue(saopFaultValue);
                fault.getCode().setSubCode(soapFaultSubCode);
            }

        }
    }

    SOAPFaultReason faultReason = (SOAPFaultReason) context
            .getProperty(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME);

    if (faultReason == null && axisFault != null) {
        faultReason = axisFault.getFaultReasonElement();
    }
    if (faultReason != null) {
        fault.setReason(faultReason);
    } else {
        String message = "";
        if (soapException != null) {
            message = soapException.getMessage();
        } else if (axisFault != null) {
            // Couldn't find FaultReasonElement, try reason string
            message = axisFault.getReason();
        }

        if (message == null || "".equals(message)) {
            message = getFaultReasonFromException(e, context);
        }

        if (message == null || "".equals(message))
            message = "unknown";

        if (context.isSOAP11()) {
            fault.getReason().setText(message);
        } else {
            fault.getReason().getFirstSOAPText().setLang("en-US");
            fault.getReason().getFirstSOAPText().setText(message);
        }
    }

    Object faultRole = context.getProperty(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME);
    if (faultRole != null) {
        fault.getRole().setText((String) faultRole);
    } else if (axisFault != null) {
        if (axisFault.getFaultRoleElement() != null) {
            fault.setRole(axisFault.getFaultRoleElement());
        }
    }

    Object faultNode = context.getProperty(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME);
    if (faultNode != null) {
        SOAPFaultNode soapFaultNode = fault.getNode();
        if (soapFaultNode != null) {
            soapFaultNode.setText((String) faultNode);
        }
    } else if (axisFault != null) {
        if (axisFault.getFaultNodeElement() != null) {
            fault.setNode(axisFault.getFaultNodeElement());
        }
    }

    // Allow handlers to override the sendStacktraceDetailsWithFaults setting from the Configuration to allow
    // WS-* protocol faults to not include the exception.
    boolean sendStacktraceDetailsWithFaults = false;
    OperationContext oc = context.getOperationContext();
    Object flagFromContext = null;
    if (oc != null) {
        flagFromContext = context.getOperationContext()
                .getProperty(Constants.Configuration.SEND_STACKTRACE_DETAILS_WITH_FAULTS);
    }
    if (flagFromContext != null) {
        sendStacktraceDetailsWithFaults = JavaUtils.isTrue(flagFromContext);
    } else {
        Parameter param = context.getParameter(Constants.Configuration.SEND_STACKTRACE_DETAILS_WITH_FAULTS);
        if (param != null) {
            sendStacktraceDetailsWithFaults = JavaUtils.isTrue(param.getValue());
        }
    }

    Object faultDetail = context.getProperty(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME);
    if (faultDetail != null) {
        fault.setDetail((SOAPFaultDetail) faultDetail);
    } else if (axisFault != null) {
        if (axisFault.getFaultDetailElement() != null) {
            fault.setDetail(axisFault.getFaultDetailElement());
        } else {
            OMElement detail = axisFault.getDetail();
            if (detail != null) {
                fault.getDetail().addDetailEntry(detail);
            } else if (sendStacktraceDetailsWithFaults) {
                fault.setException(axisFault);
            }
        }
    } else if (fault.getException() == null && sendStacktraceDetailsWithFaults) {
        if (e instanceof Exception) {
            fault.setException((Exception) e);
        } else {
            fault.setException(new Exception(e));
        }
    }

    if (log.isDebugEnabled())
        log.debug("End createFaultEnvelope()");
    return envelope;
}