Java Code Examples for org.apache.ws.commons.schema.XmlSchemaComplexType#getParticle()
The following examples show how to use
org.apache.ws.commons.schema.XmlSchemaComplexType#getParticle() .
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 |
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: WSDLToCorbaHelper.java From cxf with Apache License 2.0 | 6 votes |
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 3
Source File: DidSchemaParser.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * Extract a particle from a complex type * returns null if it can't be extracted. */ private XmlSchemaParticle extractParticle(XmlSchemaComplexType complexType) { XmlSchemaParticle particle = complexType.getParticle(); // handle case where the complexType is an extension if (particle == null && complexType.getContentModel() != null && complexType.getContentModel().getContent() != null) { XmlSchemaContent content = complexType.getContentModel().getContent(); if (content instanceof XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension complexContent = (XmlSchemaComplexContentExtension) content; particle = complexContent.getParticle(); } } return particle; }
Example 4
Source File: SchemaCollection.java From cxf with Apache License 2.0 | 6 votes |
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 5
Source File: DidSchemaParser.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * Extract a particle from a complex type * returns null if it can't be extracted. */ private XmlSchemaParticle extractParticleWithRestriction(XmlSchemaComplexType complexType) { XmlSchemaParticle particle = complexType.getParticle(); if (particle == null && complexType.getContentModel() != null && complexType.getContentModel().getContent() != null) { XmlSchemaContent content = complexType.getContentModel().getContent(); if (content instanceof XmlSchemaComplexContentRestriction) { XmlSchemaComplexContentRestriction complexContent = (XmlSchemaComplexContentRestriction) content; particle = complexContent.getParticle(); } } return particle; }
Example 6
Source File: WSDLToDataService.java From micro-integrator with Apache License 2.0 | 5 votes |
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 7
Source File: ServiceModelUtil.java From cxf with Apache License 2.0 | 5 votes |
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 8
Source File: ServiceJavascriptBuilder.java From cxf with Apache License 2.0 | 5 votes |
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 9
Source File: ServiceJavascriptBuilder.java From cxf with Apache License 2.0 | 5 votes |
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 10
Source File: BeanTest.java From cxf with Apache License 2.0 | 5 votes |
@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 11
Source File: BeanTest.java From cxf with Apache License 2.0 | 5 votes |
@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 12
Source File: BeanTest.java From cxf with Apache License 2.0 | 5 votes |
@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 13
Source File: BeanTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testNillableInt() throws Exception { defaultContext(); BeanTypeInfo info = new BeanTypeInfo(IntBean.class, "urn:Bean"); info.setTypeMapping(mapping); BeanType type = new BeanType(info); type.setTypeClass(IntBean.class); type.setTypeMapping(mapping); type.setSchemaType(new QName("urn:Bean", "bean")); XmlSchema schema = newXmlSchema("urn:Bean"); type.writeSchema(schema); XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("bean"); XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle(); boolean int1ok = false; boolean int2ok = 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; assertTrue(oe.isNillable()); assertEquals(0, oe.getMinOccurs()); } else if ("int2".equals(oe.getName())) { int2ok = true; assertEquals(0, oe.getMinOccurs()); assertFalse(oe.isNillable()); } } } assertTrue(int1ok); assertTrue(int2ok); }
Example 14
Source File: ProcessorUtil.java From cxf with Apache License 2.0 | 5 votes |
private static List<WrapperElement> createWrappedElementsFromExtension(SchemaCollection schema, XmlSchemaComplexType type, int maxStackDepth) { List<WrapperElement> qnames = new ArrayList<>(); XmlSchemaContent schemaContent = type.getContentModel().getContent(); if (!(schemaContent instanceof XmlSchemaComplexContentExtension) || maxStackDepth == 0) { return qnames; } XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)schemaContent; QName baseTypeName = extension.getBaseTypeName(); XmlSchemaType baseType = schema.getTypeByQName(baseTypeName); if (baseType instanceof XmlSchemaComplexType) { XmlSchemaComplexType complexBaseType = (XmlSchemaComplexType)baseType; if (complexBaseType.getParticle() == null && complexBaseType.getContentModel() != null) { // continue up the extension ladder qnames.addAll(createWrappedElementsFromExtension(schema, complexBaseType, maxStackDepth - 1)); } else if (complexBaseType.getParticle() instanceof XmlSchemaSequence) { XmlSchemaSequence seq = (XmlSchemaSequence)complexBaseType.getParticle(); qnames.addAll(createWrappedElements(seq)); } } if (extension.getParticle() instanceof XmlSchemaSequence) { XmlSchemaSequence xmlSchemaSeq = (XmlSchemaSequence)extension.getParticle(); qnames.addAll(createWrappedElements(xmlSchemaSeq)); } return qnames; }
Example 15
Source File: ProcessorUtil.java From cxf with Apache License 2.0 | 5 votes |
public static List<WrapperElement> getWrappedElement(ToolContext context, QName partElement) { ServiceInfo serviceInfo = context.get(ServiceInfo.class); SchemaCollection schema = serviceInfo.getXmlSchemaCollection(); XmlSchemaElement elementByName = schema.getElementByQName(partElement); XmlSchemaComplexType type = (XmlSchemaComplexType)elementByName.getSchemaType(); XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle(); List<WrapperElement> qnames = createWrappedElements(seq); //If it's extension if (seq == null && type.getContentModel() != null) { Object configuredMaxStackDepth = context.get(ToolConstants.CFG_MAX_EXTENSION_STACK_DEPTH); Integer maxStackDepth = Integer.valueOf(5); if (configuredMaxStackDepth instanceof Integer) { maxStackDepth = (Integer)configuredMaxStackDepth; } else if (configuredMaxStackDepth instanceof String) { maxStackDepth = Integer.valueOf((String)configuredMaxStackDepth); } qnames.addAll(createWrappedElementsFromExtension(schema, type, maxStackDepth)); } return qnames; }
Example 16
Source File: BeanTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testByteMappings() 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 littleByteOk = false; boolean bigByteOk = 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 ("littleByte".equals(oe.getName())) { littleByteOk = true; assertNotNull(oe.getSchemaTypeName()); assertEquals(Constants.XSD_BYTE, oe.getSchemaTypeName()); } else if ("bigByte".equals(oe.getName())) { bigByteOk = true; assertNotNull(oe.getSchemaTypeName()); assertEquals(Constants.XSD_BYTE, oe.getSchemaTypeName()); } } } assertTrue(littleByteOk); assertTrue(bigByteOk); SimpleBean bean = new SimpleBean(); bean.setBigByte(Byte.valueOf((byte)0xfe)); bean.setLittleByte((byte)0xfd); Element element = writeObjectToElement(type, bean, getContext()); Byte bb = Byte.valueOf((byte)0xfe); String bbs = bb.toString(); assertValid("/b:root/bz:bigByte[text()='" + bbs + "']", element); // Test reading ElementReader reader = new ElementReader(getResourceAsStream("byteBeans.xml")); bean = (SimpleBean)type.readObject(reader, getContext()); assertEquals(-5, bean.getLittleByte()); assertEquals(25, bean.getBigByte().byteValue()); reader.getXMLStreamReader().close(); }
Example 17
Source File: WSDLToCorbaHelper.java From cxf with Apache License 2.0 | 4 votes |
private CorbaType processStruct(XmlSchemaComplexType complex, QName defaultName) throws Exception { QName name; Struct corbaStruct = null; QName schematypeName = checkPrefix(complex.getQName()); if (schematypeName == null) { schematypeName = createQNameTargetNamespace(defaultName.getLocalPart()); if (defaultName.getNamespaceURI().isEmpty()) { schematypeName = checkPrefix(schematypeName); } else { schematypeName = checkPrefix(defaultName); } name = checkPrefix(createQNameCorbaNamespace(defaultName.getLocalPart())); } else { name = checkPrefix(createQNameCorbaNamespace(schematypeName.getLocalPart())); } corbaStruct = (Struct)recursionMap.get(name); if (corbaStruct != null) { return corbaStruct; } corbaStruct = new Struct(); corbaStruct.setName(name.getLocalPart()); corbaStruct.setQName(name); String repoId = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION; corbaStruct.setRepositoryID(repoId); corbaStruct.setType(schematypeName); recursionMap.put(name, corbaStruct); if (complex.getContentModel() instanceof XmlSchemaSimpleContent) { corbaStruct = processSimpleContentStruct((XmlSchemaSimpleContent)complex.getContentModel(), defaultName, corbaStruct, schematypeName); } else if (complex.getContentModel() instanceof XmlSchemaComplexContent) { corbaStruct = processComplexContentStruct((XmlSchemaComplexContent)complex.getContentModel(), defaultName, corbaStruct, schematypeName); } // Process attributes at ComplexType level if (!complex.getAttributes().isEmpty()) { String uri; if (schematypeName != null) { uri = schematypeName.getNamespaceURI(); } else { uri = defaultName.getNamespaceURI(); } List<MemberType> attlist2 = processAttributesAsMembers(complex.getAttributes(), uri); for (int i = 0; i < attlist2.size(); i++) { MemberType member = attlist2.get(i); corbaStruct.getMember().add(member); } } if (complex.getParticle() != null) { List<MemberType> members = processContainerAsMembers(complex.getParticle(), defaultName, schematypeName); for (MemberType memberType : members) { corbaStruct.getMember().add(memberType); } } recursionMap.remove(name); return corbaStruct; }