org.apache.ws.commons.schema.utils.XmlSchemaObjectBase Java Examples
The following examples show how to use
org.apache.ws.commons.schema.utils.XmlSchemaObjectBase.
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: 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 #2
Source File: XmlSchemaExtractor.java From syndesis with Apache License 2.0 | 5 votes |
/** * Copy all objects from source schema to target schema after calling extract methods to setup objects to extract. * * @throws ParserException on error. */ public void copyObjects() throws ParserException { while (!objectPairStack.isEmpty()) { // get objects in LIFO insertion order final ObjectPair<? extends XmlSchemaObjectBase> pair = objectPairStack.pop(); final XmlSchemaObjectBase source = pair.getSource(); final XmlSchemaObjectBase target = pair.getTarget(); // namespace for new target objects created by pair handler final String targetNamespace; if (source instanceof XmlSchemaNamed) { targetNamespace = ((XmlSchemaNamed)source).getParent().getTargetNamespace(); } else { targetNamespace = pair.getSourceSchemaNamespace(); } // handle based on type withNamespace(targetNamespace, () -> HANDLER_MAP.entrySet().stream() .filter(e -> e.getKey().test(source)) .findFirst() .map(Map.Entry::getValue) .orElseThrow(() -> new ParserException("Unsupported type " + source.getClass().getName())) .apply(this, target, source) ); } // resolve targetSchemas imports targetSchemas.addCrossImports(); }
Example #3
Source File: XmlSchemaExtractor.java From syndesis with Apache License 2.0 | 5 votes |
private <T extends XmlSchemaObjectBase> void copyXmlSchemaObjectBase(T target, T source) throws ParserException { // copy non-blacklisted properties to target object copyNonBlackListedProperties(target, source); // put objects at top of stack (DFS) to be handled in copyObjects objectPairStack.push(new ObjectPair<>(target, source, getCurrentNamespace())); }
Example #4
Source File: XmlSchemaExtractor.java From syndesis with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private <T extends XmlSchemaObjectBase> T createXmlSchemaObject(T source, String targetNamespace) throws ReflectiveOperationException { T target; final Constructor<?> constructor = source.getClass().getConstructors()[0]; if (constructor.getParameterCount() == 0) { target = (T) constructor.newInstance(); } else { // some ref types have a constructor that takes an XmlSchema, final XmlSchema targetSchema = targetSchemas.getSchemaByTargetNamespace(targetNamespace); target = (T) constructor.newInstance(targetSchema); } return target; }
Example #5
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 #6
Source File: SchemaCollection.java From cxf with Apache License 2.0 | 5 votes |
private void addCrossImports(XmlSchema schema, XmlSchemaAll all) { for (XmlSchemaObjectBase seqMember : all.getItems()) { if (seqMember instanceof XmlSchemaElement) { addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember); } } }
Example #7
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 #8
Source File: XmlSchemaExtractor.java From syndesis with Apache License 2.0 | 4 votes |
private void handleAttributeGroup(XmlSchemaAttributeGroup target, XmlSchemaAttributeGroup source) throws ParserException { for (XmlSchemaAttributeGroupMember member : source.getAttributes()) { // add group member target.getAttributes().add((XmlSchemaAttributeGroupMember) createXmlSchemaObjectBase((XmlSchemaObjectBase)member)); } }
Example #9
Source File: XmlSchemaExtractor.java From syndesis with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private <T extends XmlSchemaObjectBase> T createXmlSchemaObjectBase(T source) throws ParserException { // if source is an xsd:* type, return it as result if (source instanceof XmlSchemaType) { final QName qName = ((XmlSchemaType) source).getQName(); if (qName != null && isXSDSchemaType(qName)) { return source; } } final String targetNamespace; final T target; try { // is it an XmlSchemaNamed that takes a schema as ctor argument? if (source instanceof XmlSchemaNamed) { final XmlSchemaNamed namedSource = (XmlSchemaNamed) source; // get target schema targetNamespace = namedSource.getParent().getTargetNamespace(); final XmlSchema targetSchema = getOrCreateTargetSchema(targetNamespace); // if top-level, check if it already exists in targetSchema final boolean topLevel = namedSource.isTopLevel(); if (topLevel) { final Optional<XmlSchemaObject> targetObject = targetSchema.getItems().stream() // find matching class and QName .filter(i -> source.getClass().isInstance(i) && ((XmlSchemaNamed) i).getQName().equals(namedSource.getQName())) .findFirst(); if (targetObject.isPresent()) { // no need to create a new target object return (T) targetObject.get(); } } target = (T) createXmlSchemaNamedObject(namedSource, targetSchema, topLevel); } else { // other XmlSchemaObject targetNamespace = getCurrentNamespace(); target = createXmlSchemaObject(source, targetNamespace); } } catch (ReflectiveOperationException e) { throw new ParserException(String.format("Error extracting type %s: %s", source.getClass().getName(), e.getMessage()), e); } // copy source to target using appropriate handlers withNamespace(targetNamespace, () -> copyXmlSchemaObjectBase(target, source)); return target; }