org.apache.ws.commons.schema.XmlSchemaChoice Java Examples
The following examples show how to use
org.apache.ws.commons.schema.XmlSchemaChoice.
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: 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 #2
Source File: Xsd2CobolTypesModelBuilder.java From legstar-core2 with GNU Affero General Public License v3.0 | 6 votes |
/** * Retrieve the properties of a choice element. * <p/> * Use the opportunity to visit each of the choice's alternatives. * * @param fieldIndex the order of the choice in the parent complex type * @param xsdChoice the choice element * @param compositeTypes the lists of composite types being populated * @return the choice's properties */ private Map < String, Object > getProps(int fieldIndex, XmlSchemaChoice xsdChoice, RootCompositeType compositeTypes) { String choiceTypeName = getComplexTypeName(xsdChoice); visit(xsdChoice, compositeTypes, choiceTypeName); Map < String, Object > props = new LinkedHashMap < String, Object >(); props.put(FIELD_INDEX_PROP_NAME, fieldIndex); props.put(CHOICE_TYPE_PROP_NAME, true); props.put(CHOICE_TYPE_NAME_PROP_NAME, choiceTypeName); props.put(ALTERNATIVES_PROP_NAME, compositeTypes.choiceTypes.get(choiceTypeName)); return props; }
Example #3
Source File: WSDLToCorbaHelper.java From cxf with Apache License 2.0 | 6 votes |
protected MemberType processComplexContentStructChoice(XmlSchemaChoice choice, QName schematypeName, QName defaultName) throws Exception { QName choicename = createQNameTargetNamespace(schematypeName.getLocalPart() + "ChoiceType"); Union choiceunion = createUnion(choicename, choice, defaultName, schematypeName); MemberType choicemem = new MemberType(); if (choiceunion != null) { String repoId = REPO_STRING + choiceunion.getQName().getLocalPart().replace('.', '/') + IDL_VERSION; choiceunion.setRepositoryID(repoId); choicemem.setName(choiceunion.getQName().getLocalPart() + "_f"); choicemem.setIdltype(createQNameCorbaNamespace(choiceunion.getQName().getLocalPart())); if (!isDuplicate(choiceunion)) { typeMappingType.getStructOrExceptionOrUnion().add(choiceunion); } } return choicemem; }
Example #4
Source File: XmlSchemaExtractor.java From syndesis with Apache License 2.0 | 6 votes |
@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 #5
Source File: WSDLToCorbaHelper.java From cxf with Apache License 2.0 | 5 votes |
private CorbaType processChoice(XmlSchemaChoice choice, QName defaultName, QName schemaTypeName) throws Exception { QName choicename = null; if (schemaTypeName == null) { choicename = createQNameCorbaNamespace(defaultName.getLocalPart()); } else { choicename = createQNameCorbaNamespace(schemaTypeName.getLocalPart()); } choicename = checkPrefix(choicename); CorbaType corbatype = createUnion(choicename, choice, defaultName, schemaTypeName); String repoId = REPO_STRING + corbatype.getQName().getLocalPart().replace('.', '/') + IDL_VERSION; ((Union)corbatype).setRepositoryID(repoId); if (choice.getMaxOccurs() != 1 || choice.getMinOccurs() != 1) { QName name = createQNameTargetNamespace(corbatype.getQName().getLocalPart() + "Array"); CorbaType arrayType = createArray(name, corbatype.getQName(), corbatype.getQName(), choice.getMaxOccurs(), choice.getMinOccurs(), false); if (arrayType != null && !isDuplicate(arrayType)) { typeMappingType.getStructOrExceptionOrUnion().add(arrayType); } } return corbatype; }
Example #6
Source File: SchemaCollection.java From cxf with Apache License 2.0 | 5 votes |
private void addCrossImports(XmlSchema schema, XmlSchemaChoice choice) { for (XmlSchemaObjectBase seqMember : choice.getItems()) { if (seqMember instanceof XmlSchemaElement) { addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember); } } }
Example #7
Source File: JavascriptUtils.java From cxf with Apache License 2.0 | 5 votes |
/** * 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 #8
Source File: WSDLToCorbaHelper.java From cxf with Apache License 2.0 | 5 votes |
private CorbaType processRegularUnion(XmlSchemaComplexType complex, QName defaultName) throws Exception { //NEED TO DO QName name = null; QName schematypeName = complex.getQName(); if (schematypeName == null) { schematypeName = defaultName; name = createQNameCorbaNamespace(defaultName.getLocalPart() + "Type"); } else { name = createQNameCorbaNamespace(schematypeName.getLocalPart()); } return createUnion(name, (XmlSchemaChoice)complex.getParticle(), defaultName, schematypeName); }
Example #9
Source File: WSDLToCorbaHelper.java From cxf with Apache License 2.0 | 5 votes |
private MemberType processChoiceMember(XmlSchemaChoice choice, QName defaultName, QName schemaTypeName) throws Exception { CorbaType corbatype = processChoice(choice, defaultName, schemaTypeName); MemberType member = new MemberType(); member.setName(corbatype.getQName().getLocalPart()); member.setIdltype(corbatype.getQName()); if (corbatype.isSetQualified() && corbatype.isQualified()) { member.setQualified(true); } return member; }
Example #10
Source File: Xsd2CobolTypesModelBuilder.java From legstar-core2 with GNU Affero General Public License v3.0 | 5 votes |
/** * A choice is given a name built using its first alternative name (choices * do not have names in the XSD). * * @param xsdChoice the XSD choice * @return a field name to use for this choice in its parent complex type */ private static String getFieldName(XmlSchemaChoice xsdChoice) { for (XmlSchemaChoiceMember alternative : xsdChoice.getItems()) { if (alternative instanceof XmlSchemaElement) { return getFieldName((XmlSchemaElement) alternative) + CHOICE_FIELD_NAME_SUFFIX; } } throw new Xsd2ConverterException( "Choice without any alternative at line " + xsdChoice.getLineNumber()); }
Example #11
Source File: Xsd2CobolTypesModelBuilder.java From legstar-core2 with GNU Affero General Public License v3.0 | 5 votes |
/** * Add a field with associated properties to a complex type. * * @param index the order of the field in the parent complex type * @param xsdSchemaObject the potential field * @param xsdSchemaObject the potential field * @param fields the parent complex type's fields collection * @param compositeTypes the lists of composite types being populated */ private void addField(int fieldIndex, XmlSchemaObjectBase xsdSchemaObject, Map < String, Object > fields, RootCompositeType compositeTypes) { if (xsdSchemaObject instanceof XmlSchemaElement) { XmlSchemaElement xsdElement = (XmlSchemaElement) xsdSchemaObject; fields.put(getFieldName(xsdElement), getProps(fieldIndex, xsdElement, compositeTypes)); } else if (xsdSchemaObject instanceof XmlSchemaChoice) { XmlSchemaChoice xsdChoice = (XmlSchemaChoice) xsdSchemaObject; fields.put(getFieldName(xsdChoice), getProps(fieldIndex, xsdChoice, compositeTypes)); } // TODO Add Groups }
Example #12
Source File: Xsd2CobolTypesModelBuilder.java From legstar-core2 with GNU Affero General Public License v3.0 | 5 votes |
/** * Visit each alternative of a choice in turn. * <p/> * Note that this produces a new complex type. * * @param xsdChoice the XML schema choice * @param compositeTypes the lists of composite types being populated * @param choiceTypeName the name to use for this choice type */ private void visit(XmlSchemaChoice xsdChoice, RootCompositeType compositeTypes, String choiceTypeName) { Map < String, Object > alternatives = new LinkedHashMap < String, Object >(); int fieldIndex = 0; for (XmlSchemaChoiceMember alternative : xsdChoice.getItems()) { if (alternative instanceof XmlSchemaElement) { addField(fieldIndex, alternative, alternatives, compositeTypes); fieldIndex++; } } compositeTypes.choiceTypes.put(choiceTypeName, alternatives); }
Example #13
Source File: UnionVisitor.java From cxf with Apache License 2.0 | 4 votes |
private void processCaseNodes(AST caseNode, Scope scope, XmlSchemaChoice choice, Union corbaUnion) { while (caseNode != null) { AST typeNode = null; AST nameNode = null; AST labelNode = null; // xmlschema:element XmlSchemaElement element = new XmlSchemaElement(schema, false); // corba:unionbranch Unionbranch unionBranch = new Unionbranch(); if (caseNode.getType() == IDLTokenTypes.LITERAL_default) { // default: unionBranch.setDefault(true); typeNode = caseNode.getFirstChild(); nameNode = typeNode.getNextSibling(); } else { // case: createCase(caseNode, unionBranch); labelNode = caseNode.getFirstChild(); if (labelNode.getType() == IDLTokenTypes.LITERAL_case) { labelNode = labelNode.getNextSibling(); } typeNode = labelNode.getNextSibling(); nameNode = typeNode.getNextSibling(); } TypesVisitor visitor = new TypesVisitor(scope, definition, schema, wsdlVisitor, null); visitor.visit(typeNode); XmlSchemaType stype = visitor.getSchemaType(); CorbaType ctype = visitor.getCorbaType(); Scope fullyQualifiedName = visitor.getFullyQualifiedName(); // needed for anonymous arrays in unions if (ArrayVisitor.accept(nameNode)) { Scope anonScope = new Scope(scope, TypesUtils.getCorbaTypeNameNode(nameNode)); ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope, definition, schema, wsdlVisitor, null, fullyQualifiedName); arrayVisitor.setSchemaType(stype); arrayVisitor.setCorbaType(ctype); arrayVisitor.visit(nameNode); stype = arrayVisitor.getSchemaType(); ctype = arrayVisitor.getCorbaType(); fullyQualifiedName = visitor.getFullyQualifiedName(); } // xmlschema:element element.setName(nameNode.toString()); if (stype != null) { element.setSchemaTypeName(stype.getQName()); if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) { element.setNillable(true); } } else { UnionDeferredAction elementAction = new UnionDeferredAction(element); wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction); } choice.getItems().add(element); // corba:unionbranch unionBranch.setName(nameNode.toString()); if (ctype != null) { unionBranch.setIdltype(ctype.getQName()); } else { // its type is forward declared. UnionDeferredAction unionBranchAction = new UnionDeferredAction(unionBranch); wsdlVisitor.getDeferredActions().add(fullyQualifiedName, unionBranchAction); } corbaUnion.getUnionbranch().add(unionBranch); caseNode = caseNode.getNextSibling(); } }
Example #14
Source File: WSDLToCorbaHelper.java From cxf with Apache License 2.0 | 4 votes |
private Struct processComplexContentStructParticle(XmlSchemaParticle extype, QName defaultName, Struct corbaStruct, QName schematypeName, QName extName, List<XmlSchemaAttributeOrGroupRef> list) throws Exception { String uri; if (schematypeName != null) { uri = schematypeName.getNamespaceURI(); } else { uri = defaultName.getNamespaceURI(); } // Add base as a member of this struct MemberType memberType = new MemberType(); memberType.setName(extName.getLocalPart() + "_f"); if ("anyType".equals(extName.getLocalPart())) { memberType.setIdltype(processPrimitiveType(extName).getQName()); } else { memberType.setIdltype(createQNameCorbaNamespace(extName.getLocalPart())); } corbaStruct.getMember().add(memberType); // process attributes at complexContent level List<MemberType> attlist1 = processAttributesAsMembers(list, uri); for (int i = 0; i < attlist1.size(); i++) { MemberType member = attlist1.get(i); corbaStruct.getMember().add(member); } // Process members of Current Type if (extype instanceof XmlSchemaChoice) { XmlSchemaChoice choice = (XmlSchemaChoice)extype; MemberType choicemem = processComplexContentStructChoice(choice, schematypeName, defaultName); choicemem.setAnonschematype(true); corbaStruct.getMember().add(choicemem); } else if (extype instanceof XmlSchemaSequence) { XmlSchemaSequence seq = (XmlSchemaSequence)extype; corbaStruct = processComplexContentStructSequence(corbaStruct, seq, defaultName, schematypeName); } else if (extype instanceof XmlSchemaAll) { XmlSchemaAll all = (XmlSchemaAll)extype; corbaStruct = processComplexContentStructSchemaAll(corbaStruct, all, defaultName, schematypeName); } return corbaStruct; }
Example #15
Source File: UnionVisitor.java From cxf with Apache License 2.0 | 4 votes |
public void visitDeclaredUnion(AST identifierNode) { Scope unionScope = new Scope(getScope(), identifierNode); AST discriminatorNode = identifierNode.getNextSibling(); AST caseNode = discriminatorNode.getNextSibling(); // xmlschema:union XmlSchemaComplexType unionSchemaComplexType = new XmlSchemaComplexType(schema, true); unionSchemaComplexType.setName(mapper.mapToQName(unionScope)); // REVISIT // TEMPORARILY // using TypesVisitor to visit <const_type> // it should be visited by a SwitchTypeSpecVisitor TypesVisitor visitor = new TypesVisitor(getScope(), definition, schema, wsdlVisitor, null); visitor.visit(discriminatorNode); CorbaType ctype = visitor.getCorbaType(); Scope fullyQualifiedName = visitor.getFullyQualifiedName(); XmlSchemaChoice choice = new XmlSchemaChoice(); choice.setMinOccurs(1); choice.setMaxOccurs(1); unionSchemaComplexType.setParticle(choice); // corba:union Union corbaUnion = new Union(); corbaUnion.setQName(new QName(typeMap.getTargetNamespace(), unionScope.toString())); corbaUnion.setRepositoryID(unionScope.toIDLRepositoryID()); corbaUnion.setType(unionSchemaComplexType.getQName()); if (ctype != null) { corbaUnion.setDiscriminator(ctype.getQName()); } else { // Discriminator type is forward declared. UnionDeferredAction unionDiscriminatorAction = new UnionDeferredAction(corbaUnion); wsdlVisitor.getDeferredActions().add(fullyQualifiedName, unionDiscriminatorAction); } boolean recursiveAdd = addRecursiveScopedName(identifierNode); processCaseNodes(caseNode, unionScope, choice, corbaUnion); if (recursiveAdd) { removeRecursiveScopedName(identifierNode); } // add corbaType typeMap.getStructOrExceptionOrUnion().add(corbaUnion); // REVISIT: are these assignments needed? setSchemaType(unionSchemaComplexType); setCorbaType(corbaUnion); // Need to check if the union was forward declared processForwardUnionActions(unionScope); // Once we've finished declaring the union, we should make sure it has been removed from // the list of scopedNames so that we indicate that is no longer simply forward declared. scopedNames.remove(unionScope); }
Example #16
Source File: WSDLToCorbaHelper.java From cxf with Apache License 2.0 | 4 votes |
protected Union createUnion(QName name, XmlSchemaChoice choice, QName defaultName, QName schematypeName) throws Exception { Union corbaUnion = null; if (recursionMap.get(name) instanceof Union) { corbaUnion = (Union)recursionMap.get(name); if (corbaUnion != null) { return corbaUnion; } } corbaUnion = new Union(); corbaUnion.setName(name.getLocalPart()); corbaUnion.setQName(name); corbaUnion.setType(schematypeName); String id = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION; corbaUnion.setRepositoryID(id); //Set Integer as Discriminator corbaUnion.setDiscriminator(CorbaConstants.NT_CORBA_LONG); // add to the list of possible recursive types recursionMap.put(name, corbaUnion); List<MemberType> fields = processContainerAsMembers(choice, defaultName, schematypeName); //Choose an Integer as a Discriminator List<String> caselist = new ArrayList<>(); for (int i = 0; i < fields.size(); i++) { caselist.add(Integer.toString(i)); } corbaUnion = WSDLTypes.processUnionBranches(corbaUnion, fields, caselist); recursionMap.remove(name); if (!isDuplicate(corbaUnion)) { typeMappingType.getStructOrExceptionOrUnion().add(corbaUnion); } return corbaUnion; }
Example #17
Source File: ParticleInfo.java From cxf with Apache License 2.0 | 4 votes |
private static void factoryCommon(XmlSchemaParticle particle, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, ParticleInfo elementInfo) { if (particle instanceof XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement)particle; QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, currentSchema); String elementNamespaceURI = elementQName.getNamespaceURI(); boolean elementNoNamespace = "".equals(elementNamespaceURI); XmlSchema elementSchema = null; if (!elementNoNamespace) { elementSchema = schemaCollection.getSchemaByTargetNamespace(elementNamespaceURI); if (elementSchema == null) { throw new RuntimeException("Missing schema " + elementNamespaceURI); } } boolean qualified = !elementNoNamespace && XmlSchemaUtils.isElementQualified(element, true, currentSchema, elementSchema); elementInfo.xmlName = prefixAccumulator.xmlElementString(elementQName, qualified); // we are assuming here that we are not dealing, in close proximity, // with elements with identical local names and different // namespaces. elementInfo.javascriptName = elementQName.getLocalPart(); String schemaDefaultValue = element.getDefaultValue(); /* * Schema default values are carried as strings. * In javascript, for actual strings, we need quotes, but not for * numbers. The following is a trick. */ schemaDefaultValue = protectDefaultValue(schemaDefaultValue); elementInfo.defaultValue = schemaDefaultValue; factorySetupType(element, schemaCollection, elementInfo); elementInfo.isGroup = false; } else if (particle instanceof XmlSchemaChoice) { elementInfo.isGroup = true; } else if (particle instanceof XmlSchemaSequence) { elementInfo.isGroup = true; } else { // any elementInfo.any = true; elementInfo.xmlName = null; // unknown until runtime. // TODO: multiple 'any' elementInfo.javascriptName = "any"; elementInfo.type = null; // runtime for any. elementInfo.isGroup = false; } }
Example #18
Source File: Xsd2CobolTypesModelBuilder.java From legstar-core2 with GNU Affero General Public License v3.0 | 2 votes |
/** * Choices are artificially associated with a complex type name. * * @param xsdChoice the XSD choice element * @return a unique complex type name for this choice */ private static String getComplexTypeName(XmlSchemaChoice xsdChoice) { return StringUtils.capitalize(getFieldName(xsdChoice)); }