Java Code Examples for org.apache.ws.commons.schema.XmlSchemaElement#getSchemaTypeName()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaElement#getSchemaTypeName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParticleInfo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static void factorySetupType(XmlSchemaElement element, SchemaCollection schemaCollection,
                                     ParticleInfo elementInfo) {
    elementInfo.type = element.getSchemaType();
    if (elementInfo.type == null) {
        if (element.getSchemaTypeName() == null // no type at all -> anyType
            || element.getSchemaTypeName().equals(Constants.XSD_ANYTYPE)) {
            elementInfo.anyType = true;
        } else {
            elementInfo.type = schemaCollection.getTypeByQName(element.getSchemaTypeName());
            if (elementInfo.type == null
                && !element.getSchemaTypeName()
                        .getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
                JavascriptUtils.unsupportedConstruct("MISSING_TYPE", element.getSchemaTypeName()
                        .toString(), element.getQName(), element);
            }
        }
    } else if (elementInfo.type.getQName() != null
        && Constants.XSD_ANYTYPE.equals(elementInfo.type.getQName())) {
        elementInfo.anyType = true;
    }
}
 
Example 2
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void createBridgeXsElement(MessagePartInfo part, QName qn, QName typeName) {
    XmlSchemaElement el = null;
    SchemaInfo schemaInfo = serviceInfo.getSchema(qn.getNamespaceURI());
    if (schemaInfo != null) {
        el = schemaInfo.getElementByQName(qn);
        if (el == null) {
            createXsElement(schemaInfo.getSchema(), part, typeName, schemaInfo);

        } else if (!typeName.equals(el.getSchemaTypeName())) {
            throw new Fault(new Message("CANNOT_CREATE_ELEMENT", LOG,
                                        qn, typeName, el.getSchemaTypeName()));
        }
        return;
    }

    XmlSchema schema = schemas.newXmlSchemaInCollection(qn.getNamespaceURI());
    if (qualifiedSchemas) {
        schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    }
    schemaInfo = new SchemaInfo(qn.getNamespaceURI(), qualifiedSchemas, false);
    schemaInfo.setSchema(schema);

    el = createXsElement(schema, part, typeName, schemaInfo);

    NamespaceMap nsMap = new NamespaceMap();
    nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, schema.getTargetNamespace());
    nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
    schema.setNamespaceContext(nsMap);

    serviceInfo.addSchema(schemaInfo);
}
 
Example 3
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Code elsewhere in this function will fill in the name of the type of an
 * element but not the reference to the type. This function fills in the
 * type references. This does not set the type reference for elements that
 * are declared as refs to other elements. It is a giant pain to find them,
 * since they are not (generally) root elements and the code would have to
 * traverse all the types to find all of them. Users should look them up
 * through the collection, that's what it is for.
 */
private void fillInSchemaCrossreferences() {
    Service service = getService();
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();

        // First pass, fill in any types for which we have a name but no
        // type.
        for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
            Map<QName, XmlSchemaElement> elementsTable = schemaInfo.getSchema().getElements();
            for (XmlSchemaElement element : elementsTable.values()) {
                if (element.getSchemaType() == null) {
                    QName typeName = element.getSchemaTypeName();
                    if (typeName != null) {
                        XmlSchemaType type = schemaCollection.getTypeByQName(typeName);
                        if (type == null) {
                            Message message = new Message("REFERENCE_TO_UNDEFINED_TYPE", LOG, element
                                .getQName(), typeName, service.getName());
                            LOG.severe(message.toString());
                        } else {
                            element.setSchemaType(type);
                        }
                    }
                }
            }

        }
    }
}
 
Example 4
Source File: CommonsSchemaInfoBuilder.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void addGlobalElement(XmlSchemaElement element) {
    // Nested anonymous type
    QName xmlType = element.getSchemaTypeName();
    if (xmlType == null) {
        // Rule 1.b: Anonymous type inside an element ">E"
        xmlType = new QName(element.getQName().getNamespaceURI(), ">" + element.getQName().getLocalPart());
        addType(xmlType, element.getSchemaType());
    }

    // create the XmlElementInfo
    XmlElementInfo elementInfo = createXmlElementInfo(element.getQName(), xmlType, element);
    xmlElements.put(element.getQName(), elementInfo);

}
 
Example 5
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private Long parseRefParticleForMinOccurs(XmlSchemaParticle particle, String naturalKeyElement) {
    Long minOccurs = null;

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

        for (int i = 0; i < schemaSequence.getItems().getCount(); i++) {
            XmlSchemaObject item = schemaSequence.getItems().getItem(i);
            if (item instanceof XmlSchemaElement) {
                XmlSchemaElement element = (XmlSchemaElement) item;
                QName elementType = element.getSchemaTypeName();
                if (elementType != null && referenceTypes.containsKey(elementType.getLocalPart())) {

                    //This element is of reference type check the elements of the identity type of this reference
                    XmlSchemaParticle refParticle = getParticleByType(elementType.getLocalPart());
                    XmlSchemaElement identityTypeElement = parseParticleForIdentityType(refParticle);
                    XmlSchemaParticle identityTypeParticle = getParticleByType(identityTypeElement.getSchemaTypeName().getLocalPart());
                    minOccurs = parseParticleForMinOccurs(identityTypeParticle, naturalKeyElement);
                    if(minOccurs != null) {
                        return minOccurs;
                    }
                }
            }
        }
    }
    return minOccurs;
}
 
Example 6
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) {

        MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput();

        final List<MessagePartInfo> messageParts = message.getMessageParts();
        if (messageParts.isEmpty()) {
            return;
        }

        Method method = (Method)opInfo.getProperty(METHOD);
        int paraNumber = 0;
        for (MessagePartInfo mpi : messageParts) {
            SchemaInfo schemaInfo = null;
            XmlSchema schema = null;

            QName qname = (QName)mpi.getProperty(ELEMENT_NAME);
            if (messageParts.size() == 1 && qname == null) {
                qname = !isOut ? getInParameterName(opInfo, method, -1)
                        : getOutParameterName(opInfo, method, -1);

                if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) {
                    qname = isOut
                        ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname
                            .getNamespaceURI(), method.getName());
                }
            } else if (isOut && messageParts.size() > 1 && qname == null) {
                while (!isOutParam(method, paraNumber)) {
                    paraNumber++;
                }
                qname = getOutParameterName(opInfo, method, paraNumber);
            } else if (qname == null) {
                qname = getInParameterName(opInfo, method, paraNumber);
            }

            for (SchemaInfo s : serviceInfo.getSchemas()) {
                if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
                    schemaInfo = s;
                    break;
                }
            }

            if (schemaInfo == null) {
                schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true);
                schema = schemaInfo.getSchema();
            } else {
                schema = schemaInfo.getSchema();
                if (schema != null && schema.getElementByName(qname) != null) {
                    mpi.setElement(true);
                    mpi.setElementQName(qname);
                    mpi.setXmlSchema(schema.getElementByName(qname));
                    paraNumber++;
                    continue;
                }
            }

            schemaInfo.setElement(null); //cached element is now invalid
            XmlSchemaElement el = new XmlSchemaElement(schema, true);
            el.setName(qname.getLocalPart());
            el.setNillable(true);

            if (mpi.isElement()) {
                XmlSchemaElement oldEl = (XmlSchemaElement)mpi.getXmlSchema();
                if (null != oldEl && !oldEl.getQName().equals(qname)) {
                    el.setSchemaTypeName(oldEl.getSchemaTypeName());
                    el.setSchemaType(oldEl.getSchemaType());
                    if (oldEl.getSchemaTypeName() != null) {
                        addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
                    }
                }
                mpi.setElement(true);
                mpi.setXmlSchema(el);
                mpi.setElementQName(qname);
                mpi.setConcreteName(qname);
                continue;
            }
            if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) {
                throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG,
                                                                   method.getDeclaringClass().getName(),
                                                                   method.getName(),
                                                                   mpi.getName()));
            }
            if (mpi.getTypeQName() != null) {
                el.setSchemaTypeName(mpi.getTypeQName());
            } else {
                el.setSchemaType((XmlSchemaType)mpi.getXmlSchema());
            }
            mpi.setXmlSchema(el);
            mpi.setConcreteName(qname);
            if (mpi.getTypeQName() != null) {
                addImport(schema, mpi.getTypeQName().getNamespaceURI());
            }

            mpi.setElement(true);
            mpi.setElementQName(qname);
            paraNumber++;
        }
    }
 
Example 7
Source File: CommonsSchemaInfoBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
private void addNestedElement(XmlSchemaElement element, XmlTypeInfo enclosingType) {
    QName elementQName;
    QName typeQName;
    if (element.getRefName() == null) {
        //
        // Normal element in a type
        //

        // Element Name with namespace
        String elementNamespace = element.getQName().getNamespaceURI();
        if (elementNamespace == null || elementNamespace.equals("")) {
            elementNamespace = enclosingType.qname.getNamespaceURI();
        }
        elementQName = new QName(elementNamespace, element.getQName().getLocalPart());

        // Type name
        if (element.getSchemaTypeName() != null) {
            // Global type
            typeQName = element.getSchemaTypeName();
        } else {
            // Anonymous type, so we need to declare it

            // Rule 2.b: Anonymous element absolute name "T>N"
            String anonymoustName = enclosingType.qname.getLocalPart() + ">" + elementQName.getLocalPart();
            QName anonymousQName = new QName(elementNamespace, anonymoustName);

            // Rule 1.b: Anonymous type name ">E"
            typeQName = new QName(elementNamespace, ">" + anonymousQName.getLocalPart());
            addType(typeQName, element.getSchemaType());
        }
    } else {
        //
        // Referenced global element
        //

        // Local the referenced global element
        XmlSchemaElement refElement = xmlSchemaCollection.getElementByQName(element.getRefName());

        // The name and type of the nested element are determined by the referenced element
        elementQName = refElement.getQName();
        typeQName = refElement.getSchemaTypeName();
    }

    // Add element to enclosing type
    XmlElementInfo nestedElement = createXmlElementInfo(elementQName, typeQName, element);
    enclosingType.elements.put(nestedElement.qname, nestedElement);
}
 
Example 8
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private NeutralSchema parseElement(XmlSchemaElement element, XmlSchema schema) {

        QName elementTypeName = element.getSchemaTypeName();

        // Derive Element Schema
        XmlSchemaType elementSchemaType = element.getSchemaType();

        // Element annotations override type annotations.
        if (element.getAnnotation() != null) {
            elementSchemaType.setAnnotation(element.getAnnotation());
        }

        NeutralSchema elementSchema = null;
        if (elementSchemaType != null) {
            if (elementSchemaType.getName() != null) {
                elementSchema = this.parse(elementSchemaType, schema);
            } else {
                elementSchema = this.parse(elementSchemaType, element.getName(), schema);
            }
        } else if (elementTypeName != null) {
            elementSchema = getSchemaFactory().createSchema(elementTypeName);
        }

        if (elementSchema != null) {

            // List Schema
            if (element.getMaxOccurs() > 1) {
                ListSchema listSchema = (ListSchema) getSchemaFactory().createSchema("list");
                listSchema.getList().add(elementSchema);
                listSchema.updateAnnotations();
                elementSchema = listSchema;
            }
        }




        Long min = element.getMinOccurs();
        Long max = element.getMaxOccurs();
        QName type = element.getSchemaTypeName();

        if(min != null) {
            elementSchema.getProperties().put("minCardinality", min);
        }
        if( max != null) {
            elementSchema.getProperties().put("maxCardinality", max);
        }
        if(type != null) {
            elementSchema.getProperties().put("elementType", type.toString());
        }

        return elementSchema;
    }