org.apache.ws.commons.schema.XmlSchemaSequence Java Examples

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaSequence. 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 boolean isWrappableSequence(XmlSchemaComplexType type) {
    if (type.getParticle() instanceof XmlSchemaSequence) {
        XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();
        List<XmlSchemaSequenceMember> items = seq.getItems();

        for (XmlSchemaSequenceMember member : items) {
            if (!(member instanceof XmlSchemaElement)) {
                return false;
            }
        }

        return true;
    } else if (type.getParticle() == null) {
        return true;
    }
    return false;
}
 
Example #2
Source File: MapType.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void writeSchema(XmlSchema root) {
    XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
    complex.setName(getSchemaType().getLocalPart());
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    complex.setParticle(sequence);

    AegisType kType = getKeyType();
    AegisType vType = getValueType();

    XmlSchemaElement element = new XmlSchemaElement(root, false);
    sequence.getItems().add(element);
    element.setName(getEntryName().getLocalPart());
    element.setMinOccurs(0);
    element.setMaxOccurs(Long.MAX_VALUE);

    XmlSchemaComplexType evType = new XmlSchemaComplexType(root, false);
    element.setType(evType);

    XmlSchemaSequence evSequence = new XmlSchemaSequence();
    evType.setParticle(evSequence);

    createElement(root, evSequence, getKeyName(), kType, false);
    createElement(root, evSequence, getValueName(), vType, true);
}
 
Example #3
Source File: XmlSchemaExtractor.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private void handleGroupParticle(XmlSchemaGroupParticle target, XmlSchemaGroupParticle source) throws ParserException {
    final List sourceItems;
    final List targetItems;

    // unfortunately the group 'all, choice and sequence' classes don't implement a common interface
    // hence the kludgy code below
    if (source instanceof XmlSchemaAll) {
        sourceItems = ((XmlSchemaAll) source).getItems();
        targetItems = ((XmlSchemaAll) target).getItems();
    } else if (source instanceof XmlSchemaChoice) {
        sourceItems = ((XmlSchemaChoice)source).getItems();
        targetItems = ((XmlSchemaChoice)target).getItems();
    } else if (source instanceof XmlSchemaSequence) {
        sourceItems = ((XmlSchemaSequence)source).getItems();
        targetItems = ((XmlSchemaSequence)target).getItems();
    } else {
        throw new ParserException("Unsupported Group Particle type " + source.getClass().getName());
    }

    // add all source items to target schemas
    for (Object item : sourceItems) {
        targetItems.add(createXmlSchemaObjectBase((XmlSchemaObjectBase) item));
    }
}
 
Example #4
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Recursively parse through an XmlSchemaPatricle to the elements
 * collecting all DidRefSources
 */
private XmlSchemaElement parseParticleForIdentityType(XmlSchemaParticle particle) {
    XmlSchemaElement identityType = null;
    if (particle != null) {
        if (particle instanceof XmlSchemaElement) {
            XmlSchemaElement element = (XmlSchemaElement) particle;
            String elementName = element.getSchemaTypeName().getLocalPart();
            if (elementName.contains(IDENTITY_TYPE)) {
                identityType = element;
            }
        } else 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 XmlSchemaParticle) {
                    identityType = parseParticleForIdentityType((XmlSchemaParticle) item);
                }
            }
        }
    }
    return identityType;
}
 
Example #5
Source File: OperationVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void visitOpTypeSpec(AST node, XmlSchemaSequence outputWrappingSequence) {
    if (node.getType() == IDLTokenTypes.LITERAL_void) {
        // nothing to do here, move along
        return;
    }
    ParamTypeSpecVisitor visitor = new ParamTypeSpecVisitor(getScope(),
                                                            definition,
                                                            schema,
                                                            wsdlVisitor);

    visitor.visit(node);

    XmlSchemaType schemaType = visitor.getSchemaType();
    CorbaTypeImpl corbaType = visitor.getCorbaType();
    Scope fqName = visitor.getFullyQualifiedName();

    addElement(outputWrappingSequence, schemaType, fqName, RETURN_PARAMETER);
    addCorbaReturn(corbaType, fqName, RETURN_PARAMETER);
}
 
Example #6
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static List<WrapperElement> createWrappedElements(XmlSchemaSequence seq) {

        List<WrapperElement> qnames = new ArrayList<>();
        if (seq != null) {

            List<XmlSchemaSequenceMember> items = seq.getItems();

            for (XmlSchemaSequenceMember seqMember : items) {
                XmlSchemaElement subElement = (XmlSchemaElement)seqMember;

                if (subElement.getQName() != null) {
                    qnames.add(new WrapperElement(subElement.getWireName(), subElement.getSchemaTypeName()));
                } else {
                    qnames.add(new WrapperElement(subElement.getRef().getTargetQName(),
                                                  subElement.getSchemaTypeName()));
                }
            }
        }
        return qnames;
    }
 
Example #7
Source File: SchemaCollection.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void addCrossImportsType(XmlSchema schema, XmlSchemaType schemaType) {
    // the base type might cross schemas.
    if (schemaType instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType)schemaType;
        XmlSchemaUtils.addImportIfNeeded(schema, complexType.getBaseSchemaTypeName());
        addCrossImports(schema, complexType.getContentModel());
        addCrossImportsAttributeList(schema, complexType.getAttributes());
        // could it be a choice or something else?

        if (complexType.getParticle() instanceof XmlSchemaChoice) {
            XmlSchemaChoice choice = (XmlSchemaChoice)complexType.getParticle();
            addCrossImports(schema, choice);
        } else if (complexType.getParticle() instanceof XmlSchemaAll) {
            XmlSchemaAll all = (XmlSchemaAll)complexType.getParticle();
            addCrossImports(schema, all);
        } else if (complexType.getParticle() instanceof XmlSchemaSequence) {
            XmlSchemaSequence sequence = (XmlSchemaSequence)complexType.getParticle();
            addCrossImports(schema, sequence);
        }
    }
}
 
Example #8
Source File: OperationVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement addElement(XmlSchemaSequence schemaSequence,
                                    XmlSchemaType schemaType,
                                    Scope fqName,
                                    String name) {
    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    element.setName(name);
    if (schemaType != null) {
        element.setSchemaTypeName(schemaType.getQName());
        if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new OperationDeferredAction(element));
    }
    schemaSequence.getItems().add(element);

    return element;
}
 
Example #9
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void addExceptionMessage(Class<?> cls, XmlSchema schema, XmlSchemaSequence seq) {
    try {
        //a subclass could mark the message method as transient
        Method m = cls.getMethod("getMessage");
        if (!m.isAnnotationPresent(XmlTransient.class)
            && m.getDeclaringClass().equals(Throwable.class)) {
            JAXBBeanInfo beanInfo = getBeanInfo(java.lang.String.class);
            XmlSchemaElement exEle = new XmlSchemaElement(schema, false);
            exEle.setName("message");
            exEle.setSchemaTypeName(getTypeName(beanInfo));
            exEle.setMinOccurs(0);
            seq.getItems().add(exEle);
        }
    } catch (Exception e) {
        //ignore, just won't have the message element
    }
}
 
Example #10
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Struct processComplexContentStructSequence(Struct corbaStruct, XmlSchemaSequence seq,
                                             QName defaultName, QName schematypeName)
    throws Exception {

    CorbaType seqtype =
        processSequenceType(seq, defaultName, schematypeName);

    MemberType seqmem = new MemberType();
    seqmem.setName(seqtype.getQName().getLocalPart() + "_f");
    QName type = createQNameCorbaNamespace(seqtype.getQName().getLocalPart());
    seqmem.setIdltype(type);
    seqmem.setAnonschematype(true);
    if (seqtype.isSetQualified() && seqtype.isQualified()) {
        seqmem.setQualified(true);
    }
    corbaStruct.getMember().add(seqmem);
    if (!isDuplicate(seqtype)) {
        typeMappingType.getStructOrExceptionOrUnion().add(seqtype);
    }

    return corbaStruct;
}
 
Example #11
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void buildGenericElements(XmlSchema schema, XmlSchemaSequence seq, Field f) {
    XmlSchemaComplexType generics = new XmlSchemaComplexType(schema, true);
    Type type = f.getGenericType();
    String rawType = ((ParameterizedType)type).getRawType().toString();
    String typeName = StringUtils.uncapitalize(rawType.substring(rawType.lastIndexOf('.') + 1));
    generics.setName(typeName);

    Class<?> genericsClass = f.getType();
    buildGenericSeq(schema, generics, genericsClass);

    String name = Character.toLowerCase(f.getName().charAt(0)) + f.getName().substring(1);
    XmlSchemaElement newel = new XmlSchemaElement(schema, false);
    newel.setName(name);
    newel.setSchemaTypeName(generics.getQName());
    newel.setMinOccurs(0);
    if (!seq.getItems().contains(newel)) {
        seq.getItems().add(newel);
    }
}
 
Example #12
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
public boolean isLiteralArray(XmlSchemaComplexType type) {
    boolean array = false;

    if ((type.getAttributes().isEmpty())
        && (type.getParticle() instanceof XmlSchemaSequence)) {
        XmlSchemaSequence stype = (XmlSchemaSequence)type.getParticle();

        if ((stype.getItems().size() == 1)
            && (stype.getItems().get(0) instanceof XmlSchemaElement)) {
            XmlSchemaElement el = (XmlSchemaElement)stype.getItems().get(0);
            if (el.getMaxOccurs() != 1) {
                // it's a literal array
                array = true;
            }
            if (el.getMaxOccurs() == 1
                && el.getMinOccurs() == 1
                && type.getName() != null
                &&  WSDLTypes.isAnonymous(type.getName())) {
                array = true;
            }
        }
    }
    return array;
}
 
Example #13
Source File: BeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCharMappings() throws Exception {
    defaultContext();

    BeanType type = (BeanType)mapping.getTypeCreator().createType(SimpleBean.class);
    type.setTypeClass(SimpleBean.class);
    type.setTypeMapping(mapping);

    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);

    XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("SimpleBean");
    XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle();
    boolean charok = false;

    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("character".equals(oe.getName())) {
                charok = true;
                assertNotNull(oe.getSchemaTypeName());
                assertTrue(oe.isNillable());
                assertEquals(CharacterAsStringType.CHARACTER_AS_STRING_TYPE_QNAME,
                             oe.getSchemaTypeName());
            }
        }
    }
    assertTrue(charok);
}
 
Example #14
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void addElement(XmlSchema schema,
                          XmlSchemaSequence seq, JAXBBeanInfo beanInfo,
                          QName name, boolean isArray, XmlElement xmlElementAnno) {
    XmlSchemaElement el = new XmlSchemaElement(schema, false);
    if (isArray) {
        el.setMinOccurs(0);
        el.setMaxOccurs(Long.MAX_VALUE);
    } else {
        if (xmlElementAnno == null) {
            el.setMinOccurs(0);
            el.setNillable(false);
        } else {
            el.setNillable(xmlElementAnno.nillable());
            int minOccurs = xmlElementAnno.required() ? 1 : 0;
            el.setMinOccurs(minOccurs);
        }
    }

    if (beanInfo.isElement()) {
        QName ename = new QName(beanInfo.getElementNamespaceURI(null),
                               beanInfo.getElementLocalName(null));
        XmlSchemaElement el2 = schemas.getElementByQName(ename);
        el.setNillable(false);
        el.getRef().setTargetQName(el2.getQName());
    } else {
        if (xmlElementAnno != null && !StringUtils.isEmpty(xmlElementAnno.name())) {
            el.setName(xmlElementAnno.name());
        } else {
            el.setName(name.getLocalPart());
        }
        Iterator<QName> itr = beanInfo.getTypeNames().iterator();
        if (!itr.hasNext()) {
            return;
        }
        QName typeName = itr.next();
        el.setSchemaTypeName(typeName);
    }

    seq.getItems().add(el);
}
 
Example #15
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void sortItems(final XmlSchemaSequence seq, final String[] propertyOrder) {
    final List<String> propList = Arrays.asList(propertyOrder);
    Collections.sort(seq.getItems(), new Comparator<XmlSchemaSequenceMember>() {
        public int compare(XmlSchemaSequenceMember o1, XmlSchemaSequenceMember o2) {
            XmlSchemaElement element1 = (XmlSchemaElement)o1;
            XmlSchemaElement element2 = (XmlSchemaElement)o2;
            int index1 = propList.indexOf(element1.getName());
            int index2 = propList.indexOf(element2.getName());
            return index1 - index2;
        }

    });
}
 
Example #16
Source File: BeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNillableIntMinOccurs1() throws Exception {
    context = new AegisContext();
    TypeCreationOptions config = new TypeCreationOptions();
    config.setDefaultMinOccurs(1);
    config.setDefaultNillable(false);
    context.setTypeCreationOptions(config);
    context.initialize();
    mapping = context.getTypeMapping();

    BeanType type = (BeanType)mapping.getTypeCreator().createType(IntBean.class);
    type.setTypeClass(IntBean.class);
    type.setTypeMapping(mapping);

    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);

    XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("IntBean");
    XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle();
    boolean int1ok = false;
    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("int1".equals(oe.getName())) {
                int1ok = true;
                assertFalse(oe.isNillable());
                assertEquals(1, oe.getMinOccurs());
            }
        }
    }
    assertTrue(int1ok);
}
 
Example #17
Source File: BeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNillableAnnotation() throws Exception {
    context = new AegisContext();
    TypeCreationOptions config = new TypeCreationOptions();
    config.setDefaultNillable(false);
    config.setDefaultMinOccurs(1);
    context.setTypeCreationOptions(config);
    context.initialize();
    mapping = context.getTypeMapping();

    BeanType type = (BeanType)mapping.getTypeCreator().createType(BeanWithNillableItem.class);
    type.setTypeClass(BeanWithNillableItem.class);
    type.setTypeMapping(mapping);

    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);

    XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("BeanWithNillableItem");
    XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle();
    boolean itemFound = false;
    boolean itemNotNillableFound = false;
    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("item".equals(oe.getName())) {
                itemFound = true;
                assertTrue(oe.isNillable());
                assertEquals(0, oe.getMinOccurs());
            } else if ("itemNotNillable".equals(oe.getName())) {
                itemNotNillableFound = true;
                assertFalse(oe.isNillable());
            }
        }
    }
    assertTrue(itemFound);
    assertTrue(itemNotNillableFound);
}
 
Example #18
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 #19
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void sort(final XmlSchemaSequence seq) {
    Collections.sort(seq.getItems(), new Comparator<XmlSchemaSequenceMember>() {
        public int compare(XmlSchemaSequenceMember o1, XmlSchemaSequenceMember o2) {
            XmlSchemaElement element1 = (XmlSchemaElement)o1;
            XmlSchemaElement element2 = (XmlSchemaElement)o2;
            return element1.getName().compareTo(element2.getName());
        }

    });
}
 
Example #20
Source File: JavascriptUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * If the object is an element or an any, return the particle. If it's not a particle, or it's a group,
 * throw. We're not ready for groups yet.
 * @param object
 */
public static XmlSchemaParticle getObjectParticle(XmlSchemaObject object, QName contextName,
                                                  XmlSchema currentSchema) {

    if (!(object instanceof XmlSchemaParticle)) {
        unsupportedConstruct("NON_PARTICLE_CHILD",
                                            object.getClass().getSimpleName(),
                                            contextName, object);
    }

    if (object instanceof XmlSchemaGroupRef) {
        QName groupName = ((XmlSchemaGroupRef) object).getRefName();
        XmlSchemaGroup group = currentSchema.getGroupByName(groupName);
        if (group == null) {
            unsupportedConstruct("MISSING_GROUP",
                    groupName.toString(), contextName, null);
        }

        XmlSchemaParticle groupParticle = group.getParticle();

        if (!(groupParticle instanceof XmlSchemaSequence)) {
            unsupportedConstruct("GROUP_REF_UNSUPPORTED_TYPE",
                    groupParticle.getClass().getSimpleName(), contextName, groupParticle);
        }

        return groupParticle;
    }

    if (!(object instanceof XmlSchemaElement)
        && !(object instanceof XmlSchemaAny)
        && !(object instanceof XmlSchemaChoice)
        && !(object instanceof XmlSchemaSequence)) {
        unsupportedConstruct("GROUP_CHILD",
                object.getClass().getSimpleName(), contextName,
                                            object);
    }

    return (XmlSchemaParticle) object;
}
 
Example #21
Source File: ServiceJavascriptBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaSequence getTypeSequence(XmlSchemaComplexType type,
                                          QName parentName) {
    if (!(type.getParticle() instanceof XmlSchemaSequence)) {
        unsupportedConstruct("NON_SEQUENCE_PARTICLE",
                             type.getQName() != null ? type.getQName()
                                 :
                                 parentName);
    }
    return (XmlSchemaSequence)type.getParticle();
}
 
Example #22
Source File: ServiceJavascriptBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean isEmptyType(XmlSchemaType type, QName parentName) {
    if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType)type;
        if (complexType.getParticle() == null) {
            return true;
        }
        XmlSchemaSequence sequence = getTypeSequence(complexType, parentName);
        if (sequence.getItems().isEmpty()) {
            return true;
        }
    }
    return false;
}
 
Example #23
Source File: ServiceModelUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static List<String> getOperationInputPartNames(OperationInfo operation) {
    List<String> names = new ArrayList<>();
    List<MessagePartInfo> parts = operation.getInput().getMessageParts();
    if (parts == null || parts.isEmpty()) {
        return names;
    }

    for (MessagePartInfo part : parts) {
        XmlSchemaAnnotated schema = part.getXmlSchema();

        if (schema instanceof XmlSchemaElement
            && ((XmlSchemaElement)schema).getSchemaType() instanceof XmlSchemaComplexType) {
            XmlSchemaElement element = (XmlSchemaElement)schema;
            XmlSchemaComplexType cplxType = (XmlSchemaComplexType)element.getSchemaType();
            XmlSchemaSequence seq = (XmlSchemaSequence)cplxType.getParticle();
            if (seq == null || seq.getItems() == null) {
                return names;
            }
            for (int i = 0; i < seq.getItems().size(); i++) {
                XmlSchemaElement elChild = (XmlSchemaElement)seq.getItems().get(i);
                names.add(elChild.getName());
            }
        } else {
            names.add(part.getConcreteName().getLocalPart());
        }
    }
    return names;
}
 
Example #24
Source File: SchemaCollection.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addCrossImports(XmlSchema schema, XmlSchemaSequence sequence) {
    for (XmlSchemaSequenceMember seqMember : sequence.getItems()) {
        if (seqMember instanceof XmlSchemaElement) {
            addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
        }
    }
}
 
Example #25
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void createTypeImportingElement(XmlSchema importingSchema) {
    XmlSchemaComplexType typeWithElementRef = new XmlSchemaComplexType(importingSchema, true);
    typeWithElementRef.setName("typeWithRef");
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    typeWithElementRef.setParticle(sequence);
    XmlSchemaElement refElement = new XmlSchemaElement(importingSchema, false);
    refElement.getRef().setTargetQName(new QName(ELEMENT_SCHEMA, "importedElement"));
}
 
Example #26
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private Long parseParticleForMinOccurs(XmlSchemaParticle particle, String naturalKeyElement) {
    Long minOccurs = null;

    if (particle != null) {
        if (particle instanceof XmlSchemaElement) {
            XmlSchemaElement element = (XmlSchemaElement) particle;
            String elementName = element.getName();
            if (elementName.equals(naturalKeyElement)) {
              minOccurs = element.getMinOccurs();
              return minOccurs;
            }

        } else 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 XmlSchemaParticle) {
                    minOccurs = parseParticleForMinOccurs((XmlSchemaParticle) item, naturalKeyElement);
                    if(minOccurs != null) {
                        return minOccurs;
                    }
                }
            }
        }
    }
    return minOccurs;
}
 
Example #27
Source File: WSDLToDataService.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static boolean hasResultRowName(XmlSchemaComplexType wrapperSchemaComplexType) {
	XmlSchemaParticle wrapperSchemaParticle = wrapperSchemaComplexType.getParticle();
	// a single sequence must be there
	if (!(wrapperSchemaParticle instanceof XmlSchemaSequence)) {
		return false;
	}
	XmlSchemaSequence wrapperSchemaSequence = (XmlSchemaSequence) wrapperSchemaParticle;
	XmlSchemaObjectCollection objects = wrapperSchemaSequence.getItems(); 
	if (objects.getCount() != 1) {
		return false;
	}
	XmlSchemaObject schemaObject = objects.getItem(0); 
	if (!(schemaObject instanceof XmlSchemaElement)) {
		return false;
	}
	XmlSchemaElement schemaElement = (XmlSchemaElement) schemaObject;
	if (!((((XmlSchemaComplexType) schemaElement.getSchemaType())
			.getParticle()) instanceof XmlSchemaSequence)) {
		return false;
	}
	// cannot contain any attributes
	if (wrapperSchemaComplexType.getAttributes().getCount() > 0) {
		return false;
	}
	
	return true;
}
 
Example #28
Source File: OperationVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaElement generateWrapper(QName el, XmlSchemaSequence wrappingSequence) {
    XmlSchemaComplexType schemaComplexType = new XmlSchemaComplexType(schema, false);
    schemaComplexType.setParticle(wrappingSequence);

    XmlSchemaElement wrappingSchemaElement = new XmlSchemaElement(schema, true);
    wrappingSchemaElement.setName(el.getLocalPart());
    wrappingSchemaElement.setSchemaType(schemaComplexType);

    return wrappingSchemaElement;
}
 
Example #29
Source File: SequenceVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaType generateSchemaType(XmlSchemaType stype, Scope scopedName,
                                         long bound, Scope fullyQualifiedName) {
    XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true);
    ct.setName(mapper.mapToQName(scopedName));
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    XmlSchemaElement el = new XmlSchemaElement(schema, false);
    el.setName(ELEMENT_NAME);
    el.setMinOccurs(0);
    if (bound != -1) {
        el.setMaxOccurs(bound);
    } else {
        el.setMaxOccurs(Long.MAX_VALUE);
    }
    if (stype != null) {
        el.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            el.setNillable(true);
        }
    } else {
        SequenceDeferredAction elementAction =
            new SequenceDeferredAction(el);
        wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);
    }
    sequence.getItems().add(el);
    ct.setParticle(sequence);
    return ct;
}
 
Example #30
Source File: StructVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void visitDeclaredStruct(AST identifierNode) {
    Scope structScope = new Scope(getScope(), identifierNode);

    // xmlschema:struct
    XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
    complexType.setName(mapper.mapToQName(structScope));
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    complexType.setParticle(sequence);

    // corba:struct
    Struct struct = new Struct();
    struct.setQName(new QName(typeMap.getTargetNamespace(), structScope.toString()));
    struct.setType(complexType.getQName());
    struct.setRepositoryID(structScope.toIDLRepositoryID());

    boolean recursiveAdd = addRecursiveScopedName(identifierNode);

    // struct members
    visitStructMembers(identifierNode, struct, sequence, structScope);

    if (recursiveAdd) {
        removeRecursiveScopedName(identifierNode);
    }

    // add corbaType
    typeMap.getStructOrExceptionOrUnion().add(struct);

    // REVISIT: are there assignment needed?
    setSchemaType(complexType);
    setCorbaType(struct);

    // Need to check if the struct was forward declared
    processForwardStructActions(structScope);

    // Once we've finished declaring the struct, we should make sure it has been removed from
    // the list of scopedNames so that we inidicate that is no longer simply forward declared.
    scopedNames.remove(structScope);
}