Java Code Examples for org.apache.ws.commons.schema.XmlSchema#getElementByName()

The following examples show how to use org.apache.ws.commons.schema.XmlSchema#getElementByName() . 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: WSDLParameter.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static XmlSchemaElement findElement(XmlSchema xmlSchema, QName elName) {
    XmlSchemaElement schemaElement = null;

    schemaElement = xmlSchema.getElementByName(elName);
    if (schemaElement == null) {
        String prefix = definition.getPrefix(elName.getNamespaceURI());
        QName name = new QName(elName.getNamespaceURI(), prefix + ":" + elName.getLocalPart(), prefix);
        schemaElement = xmlSchema.getElementByName(name);
    }
    if (schemaElement != null) {
        return schemaElement;
    }
    for (XmlSchemaExternal ext : xmlSchema.getExternals()) {
        if (!(ext instanceof XmlSchemaImport)) {
            schemaElement = findElement(ext.getSchema(), elName);
            if (schemaElement != null) {
                return schemaElement;
            }
        }
    }
    return schemaElement;
}
 
Example 2
Source File: WSDLParameter.java    From cxf with Apache License 2.0 6 votes vote down vote up
private boolean isObjectReference(SchemaCollection schemaList, QName name) {
    for (XmlSchema schema : schemaList.getXmlSchemas()) {
        XmlSchemaElement element = schema.getElementByName(name);
        if (element != null) {
            XmlSchemaAnnotation annotation = element.getAnnotation();
            if (annotation != null) {
                List<XmlSchemaAnnotationItem> annotationColl = annotation.getItems();
                for (XmlSchemaAnnotationItem item : annotationColl) {
                    if (item instanceof XmlSchemaAppInfo) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected XmlSchemaType lookUpType(Part part) {
    XmlSchemaType schemaType = null;
    for (XmlSchema xmlSchema : xmlSchemaList.getXmlSchemas()) {
        if (part.getElementName() != null) {
            XmlSchemaElement schemaElement = xmlSchema.getElementByName(part.getElementName());
            if (schemaElement != null) {
                schemaType = schemaElement.getSchemaType();
            }
        } else {
            if (part.getTypeName() != null) {
                schemaType = xmlSchema.getTypeByName(part.getTypeName());
            }
        }
        if (schemaType != null) {
            return schemaType;
        }
    }

    return schemaType;
}
 
Example 4
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaType findTypeInSchema(XmlSchema xmlSchema, QName typeName) {
    XmlSchemaType schemaType = null;

    if (xmlSchema.getElementByName(typeName) != null) {
        XmlSchemaElement schemaElement = xmlSchema.getElementByName(typeName);
        schemaType = schemaElement.getSchemaType();
    } else if (xmlSchema.getTypeByName(typeName) != null) {
        schemaType = xmlSchema.getTypeByName(typeName);
    }
    if (schemaType != null) {
        return schemaType;
    }
    for (XmlSchemaExternal extSchema : xmlSchema.getExternals()) {
        if (!(extSchema instanceof XmlSchemaImport)) {
            schemaType = findTypeInSchema(extSchema.getSchema(), typeName);
            if (schemaType != null) {
                return schemaType;
            }
        }
    }

    return null;
}
 
Example 5
Source File: WSDLParameter.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static XmlSchemaElement getSchemaObject(WSDLToCorbaBinding wsdlToCorbaBinding, QName typeName) {

        SchemaCollection schemaList = wsdlToCorbaBinding.getHelper().getXMLSchemaList();
        for (XmlSchema s : schemaList.getXmlSchemas()) {
            XmlSchemaElement e = s.getElementByName(typeName);
            if (e != null) {
                return e;
            }
        }
        return null;
    }
 
Example 6
Source File: SchemaCollection.java    From cxf with Apache License 2.0 5 votes vote down vote up
public XmlSchema getSchemaForElement(QName name) {
    for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
        if (name.getNamespaceURI().equals(schema.getTargetNamespace())) {

            if (schema.getElementByName(name.getLocalPart()) != null) {
                return schema;
            } else if (schema.getElementByName(name) != null) {
                return schema;
            }
        }
    }
    return null;
}
 
Example 7
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 4 votes vote down vote up
private boolean isExistSchemaElement(XmlSchema schema, QName qn) {
    return schema.getElementByName(qn) != null;
}
 
Example 8
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++;
        }
    }