org.apache.ws.commons.schema.XmlSchemaObject Java Examples
The following examples show how to use
org.apache.ws.commons.schema.XmlSchemaObject.
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: ObjectReferenceVisitor.java From cxf with Apache License 2.0 | 6 votes |
private boolean isReferenceSchemaTypeDefined(QName objectReferenceName, XmlSchema refSchema) { List<XmlSchemaObject> schemaObjects = refSchema.getItems(); for (XmlSchemaObject schemaObj : schemaObjects) { if (schemaObj instanceof XmlSchemaElement) { XmlSchemaElement el = (XmlSchemaElement)schemaObj; if (el.getName().equals(objectReferenceName.getLocalPart())) { return true; } } } return false; }
Example #2
Source File: XsdToNeutralSchemaRepo.java From secure-data-service with Apache License 2.0 | 6 votes |
void loadSchema(XmlSchema schema) { XmlSchemaObjectCollection schemaItems = schema.getItems(); // Iterate XML Schema items for (int i = 0; i < schemaItems.getCount(); i++) { XmlSchemaObject schemaObject = schemaItems.getItem(i); NeutralSchema neutralSchema; if (schemaObject instanceof XmlSchemaType) { neutralSchema = parse((XmlSchemaType) schemaObject, schema); } else if (schemaObject instanceof XmlSchemaElement) { neutralSchema = parseElement((XmlSchemaElement) schemaObject, schema); } else if (schemaObject instanceof XmlSchemaInclude) { continue; // nothing to do for includes } else { throw new RuntimeException("Unhandled XmlSchemaObject: " + schemaObject.getClass().getCanonicalName()); } schemas.put(neutralSchema.getType(), neutralSchema); partialSchemas.clear(); } }
Example #3
Source File: Xsd2UmlConvert.java From secure-data-service with Apache License 2.0 | 6 votes |
private static final List<Attribute> parseFields(final XmlSchemaComplexType schemaComplexType, final XmlSchema schema, final Xsd2UmlConfig context) { final List<Attribute> attributes = new LinkedList<Attribute>(); final XmlSchemaObjectCollection schemaItems = schemaComplexType.getAttributes(); for (int i = 0, count = schemaItems.getCount(); i < count; i++) { final XmlSchemaObject schemaObject = schemaItems.getItem(i); if (schemaObject instanceof XmlSchemaAttribute) { final XmlSchemaAttribute schemaAttribute = (XmlSchemaAttribute) schemaObject; attributes.add(parseAttribute(schemaAttribute, schema, context)); } else { throw new AssertionError(schemaObject); } } // parseAttributes(schemaComplexType.getAttributes(), schema); attributes.addAll(parseParticle(schemaComplexType.getParticle(), schema, context)); return Collections.unmodifiableList(attributes); }
Example #4
Source File: JavascriptUtils.java From cxf with Apache License 2.0 | 6 votes |
/** * If the object is an attribute or an anyAttribute, * return the 'Annotated'. If it's not one of those, or it's a group, * throw. We're not ready for groups yet. * @param object */ public static XmlSchemaAnnotated getObjectAnnotated(XmlSchemaObject object, QName contextName) { if (!(object instanceof XmlSchemaAnnotated)) { unsupportedConstruct("NON_ANNOTATED_ATTRIBUTE", object.getClass().getSimpleName(), contextName, object); } if (!(object instanceof XmlSchemaAttribute) && !(object instanceof XmlSchemaAnyAttribute)) { unsupportedConstruct("EXOTIC_ATTRIBUTE", object.getClass().getSimpleName(), contextName, object); } return (XmlSchemaAnnotated) object; }
Example #5
Source File: SchemaJavascriptBuilder.java From cxf with Apache License 2.0 | 6 votes |
/** * Build the serialization code for a complex type. At the top level, this operates on single items, so it * does not pay attention to minOccurs and maxOccurs. However, as it works through the sequence, it * manages optional elements and arrays. * * @param type * @param elementPrefix * @param bodyUtils * @return */ protected void complexTypeSerializerBody(XmlSchemaComplexType type, String elementPrefix, JavascriptUtils bodyUtils) { List<XmlSchemaObject> items = JavascriptUtils.getContentElements(type, xmlSchemaCollection); for (XmlSchemaObject sequenceItem : items) { ParticleInfo itemInfo = ParticleInfo.forLocalItem(sequenceItem, xmlSchema, xmlSchemaCollection, prefixAccumulator, type.getQName()); // If the item is 'any', it could be ANY of our top-level elements. if (itemInfo.isAny()) { serializeAny(itemInfo, bodyUtils); } else { bodyUtils.generateCodeToSerializeElement(itemInfo, "this._", xmlSchemaCollection); } } }
Example #6
Source File: DidSchemaParser.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * 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 #7
Source File: DidSchemaParser.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * extract all complex types from a schema and cache into a map */ private void cacheComplexTypes(XmlSchema schema) { XmlSchemaObjectCollection schemaItems = schema.getItems(); int numElements = schemaItems.getCount(); // Iterate XML Schema items for (int i = 0; i < numElements; i++) { XmlSchemaObject schemaObject = schemaItems.getItem(i); if (schemaObject instanceof XmlSchemaComplexType) { XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaObject; String elementTypeName = complexType.getName(); complexTypes.put(elementTypeName, complexType); } } }
Example #8
Source File: ServiceJavascriptBuilder.java From cxf with Apache License 2.0 | 5 votes |
public static void unsupportedConstruct(String messageKey, String what, QName subjectName, XmlSchemaObject subject) { Message message = new Message(messageKey, LOG, what, subjectName == null ? "anonymous" : subjectName, cleanedUpSchemaSource(subject)); LOG.severe(message.toString()); throw new UnsupportedConstruct(message); }
Example #9
Source File: XsdToNeutralSchemaRepo.java From secure-data-service with Apache License 2.0 | 5 votes |
private void parseAppInfo(NeutralSchema neutralSchema, XmlSchemaType schemaType) { XmlSchemaObjectCollection annotations = schemaType.getAnnotation().getItems(); for (int annotationIdx = 0; annotationIdx < annotations.getCount(); ++annotationIdx) { XmlSchemaObject annotation = annotations.getItem(annotationIdx); if (annotation instanceof XmlSchemaAppInfo) { XmlSchemaAppInfo info = (XmlSchemaAppInfo) annotation; neutralSchema.addAnnotation(new AppInfo(info.getMarkup())); } } }
Example #10
Source File: XsdToNeutralSchemaRepo.java From secure-data-service with Apache License 2.0 | 5 votes |
private void parseDocumentation(NeutralSchema neutralSchema, XmlSchemaType schemaType) { XmlSchemaObjectCollection annotations = schemaType.getAnnotation().getItems(); for (int annotationIdx = 0; annotationIdx < annotations.getCount(); ++annotationIdx) { XmlSchemaObject annotation = annotations.getItem(annotationIdx); if (annotation instanceof XmlSchemaDocumentation) { XmlSchemaDocumentation docs = (XmlSchemaDocumentation) annotation; neutralSchema.addAnnotation(new Documentation(docs.getMarkup())); } } }
Example #11
Source File: Xsd2UmlConvert.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * The xs:annotation is parsed into {@link TaggedValue} with one entry per * xs:documentation or xs:appinfo. */ private static final List<TaggedValue> annotations(final XmlSchemaAnnotated schemaType, final Xsd2UmlConfig config) { if (schemaType == null) { return EMPTY_TAGGED_VALUES; } final XmlSchemaAnnotation annotation = schemaType.getAnnotation(); if (annotation == null) { return EMPTY_TAGGED_VALUES; } else { final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>(); final XmlSchemaObjectCollection children = annotation.getItems(); for (int childIdx = 0; childIdx < children.getCount(); ++childIdx) { final XmlSchemaObject child = children.getItem(childIdx); if (child instanceof XmlSchemaDocumentation) { final XmlSchemaDocumentation documentation = (XmlSchemaDocumentation) child; taggedValues.add(documentation(documentation, config)); } else if (child instanceof XmlSchemaAppInfo) { final XmlSchemaAppInfo appInfo = (XmlSchemaAppInfo) child; taggedValues.addAll(config.getPlugin().tagsFromAppInfo(appInfo, config)); } else { throw new AssertionError(child); } } return taggedValues; } }
Example #12
Source File: DidSchemaParser.java From secure-data-service with Apache License 2.0 | 5 votes |
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 #13
Source File: DidSchemaParser.java From secure-data-service with Apache License 2.0 | 5 votes |
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 #14
Source File: MimeSerializer.java From cxf with Apache License 2.0 | 5 votes |
public void serialize(XmlSchemaObject schemaObject, @SuppressWarnings("rawtypes") Class classOfType, Node domNode) { Map<Object, Object> metaInfoMap = schemaObject.getMetaInfoMap(); MimeAttribute mimeType = (MimeAttribute)metaInfoMap.get(MimeAttribute.MIME_QNAME); Element elt = (Element)domNode; Attr att1 = elt.getOwnerDocument().createAttributeNS(MimeAttribute.MIME_QNAME.getNamespaceURI(), MimeAttribute.MIME_QNAME.getLocalPart()); att1.setValue(mimeType.getValue()); elt.setAttributeNodeNS(att1); }
Example #15
Source File: AttributeInfo.java From cxf with Apache License 2.0 | 5 votes |
/** * Fill in an AttributeInfo for an attribute or anyAttribute from a sequence. * * @param sequenceObject * @param currentSchema * @param schemaCollection * @param prefixAccumulator * @param contextName * @return */ public static AttributeInfo forLocalItem(XmlSchemaObject sequenceObject, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, QName contextName) { XmlSchemaAnnotated annotated = JavascriptUtils.getObjectAnnotated(sequenceObject, contextName); AttributeInfo attributeInfo = new AttributeInfo(); XmlSchemaAnnotated realAnnotated = annotated; if (annotated instanceof XmlSchemaAttribute) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)annotated; attributeInfo.use = attribute.getUse(); if (attribute.getRef().getTarget() != null) { realAnnotated = attribute.getRef().getTarget(); attributeInfo.global = true; } } else if (annotated instanceof XmlSchemaAnyAttribute) { attributeInfo.any = true; attributeInfo.xmlName = null; // unknown until runtime. attributeInfo.javascriptName = "any"; attributeInfo.type = null; // runtime for any. attributeInfo.use = XmlSchemaUse.OPTIONAL; } else { throw new UnsupportedConstruct(LOG, "UNSUPPORTED_ATTRIBUTE_ITEM", annotated, contextName); } factoryCommon(realAnnotated, currentSchema, schemaCollection, prefixAccumulator, attributeInfo); attributeInfo.annotated = realAnnotated; return attributeInfo; }
Example #16
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 #17
Source File: SchemaJavascriptBuilder.java From cxf with Apache License 2.0 | 5 votes |
/** * Generate a JavaScript function that takes an element for a complex type and walks through its children * using them to fill in the values for a JavaScript object. * * @param type schema type for the process * @return the string contents of the JavaScript. */ public void domDeserializerFunction(QName name, XmlSchemaComplexType type) { utils = new JavascriptUtils(code); List<XmlSchemaObject> contentElements = JavascriptUtils.getContentElements(type, xmlSchemaCollection); String typeObjectName = nameManager.getJavascriptName(name); code.append("function " + typeObjectName + "_deserialize (cxfjsutils, element) {\n"); // create the object we are deserializing into. utils.appendLine("var newobject = new " + typeObjectName + "();"); utils.appendLine("cxfjsutils.trace('element: ' + cxfjsutils.traceElementName(element));"); utils.appendLine("var curElement = cxfjsutils.getFirstElementChild(element);"); utils.appendLine("var item;"); int nContentElements = contentElements.size(); for (int i = 0; i < contentElements.size(); i++) { XmlSchemaObject contentElement = contentElements.get(i); utils.appendLine("cxfjsutils.trace('curElement: ' + cxfjsutils.traceElementName(curElement));"); ParticleInfo itemInfo = ParticleInfo.forLocalItem(contentElement, xmlSchema, xmlSchemaCollection, prefixAccumulator, type.getQName()); if (itemInfo.isAny()) { ParticleInfo nextItem = null; if (i != nContentElements - 1) { XmlSchemaObject nextThing = contentElements.get(i + 1); nextItem = ParticleInfo.forLocalItem(nextThing, xmlSchema, xmlSchemaCollection, prefixAccumulator, type.getQName()); // theoretically, you could have two anys with different // namespaces. if (nextItem.isAny()) { unsupportedConstruct("MULTIPLE_ANY", type.getQName()); } } deserializeAny(type, itemInfo, nextItem); } else { deserializeElement(type, itemInfo); } } utils.appendLine("return newobject;"); code.append("}\n\n"); }
Example #18
Source File: JavascriptUtils.java From cxf with Apache License 2.0 | 5 votes |
static void unsupportedConstruct(String messageKey, String what, QName subjectName, XmlSchemaObject subject) { Message message = new Message(messageKey, LOG, what, subjectName == null ? "anonymous" : subjectName, cleanedUpSchemaSource(subject)); throw new UnsupportedConstruct(message); }
Example #19
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 #20
Source File: JavascriptUtils.java From cxf with Apache License 2.0 | 5 votes |
/** * We really don't want to take the attitude that 'all base64Binary elements are candidates for MTOM'. * So we look for clues. * @param schemaObject * @return */ private boolean treatAsMtom(XmlSchemaObject schemaObject) { if (schemaObject == null) { return false; } Map<Object, Object> metaInfoMap = schemaObject.getMetaInfoMap(); if (metaInfoMap != null) { Map<?, ?> attribMap = (Map<?, ?>)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES); Attr ctAttr = (Attr)attribMap.get(MimeAttribute.MIME_QNAME); if (ctAttr != null) { return true; } } if (schemaObject instanceof XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement) schemaObject; if (element.getSchemaType() == null) { return false; } QName typeName = element.getSchemaType().getQName(); // We could do something much more complex in terms of evaluating whether the type // permits the contentType attribute. This, however, is enough to clue us in for what Aegis // does. if (new QName("http://www.w3.org/2005/05/xmlmime", "base64Binary").equals(typeName)) { return true; } } return false; }
Example #21
Source File: CorbaHandlerUtils.java From cxf with Apache License 2.0 | 5 votes |
public static boolean isAnonType(XmlSchemaObject schemaObj) { boolean result = false; if ((schemaObj != null) && !(schemaObj instanceof XmlSchemaElement) && !(schemaObj instanceof XmlSchemaComplexType)) { result = true; } return result; }
Example #22
Source File: ServiceJavascriptBuilder.java From cxf with Apache License 2.0 | 4 votes |
public static String cleanedUpSchemaSource(XmlSchemaObject subject) { if (subject == null || subject.getSourceURI() == null) { return ""; } return subject.getSourceURI() + ":" + subject.getLineNumber(); }
Example #23
Source File: JavascriptUtils.java From cxf with Apache License 2.0 | 4 votes |
static String cleanedUpSchemaSource(XmlSchemaObject subject) { if (subject == null || subject.getSourceURI() == null) { return ""; } return subject.getSourceURI() + ':' + subject.getLineNumber(); }
Example #24
Source File: BeanTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testAttributeMap() throws Exception { defaultContext(); BeanTypeInfo info = new BeanTypeInfo(SimpleBean.class, "urn:Bean"); info.mapAttribute("howdy", new QName("urn:Bean", "howdy")); info.mapAttribute("bleh", new QName("urn:Bean", "bleh")); info.setTypeMapping(mapping); BeanType type = new BeanType(info); type.setTypeClass(SimpleBean.class); type.setTypeMapping(mapping); type.setSchemaType(new QName("urn:Bean", "bean")); ElementReader reader = new ElementReader(getResourceAsStream("bean4.xml")); SimpleBean bean = (SimpleBean)type.readObject(reader, getContext()); assertEquals("bleh", bean.getBleh()); assertEquals("howdy", bean.getHowdy()); reader.getXMLStreamReader().close(); // Test writing Element element = writeObjectToElement(type, bean, getContext()); assertValid("/b:root[@b:bleh='bleh']", element); assertValid("/b:root[@b:howdy='howdy']", element); XmlSchema schema = newXmlSchema("urn:Bean"); type.writeSchema(schema); XmlSchemaComplexType stype = (XmlSchemaComplexType)schema.getTypeByName("bean"); boolean howdy = false; boolean bleh = false; for (int x = 0; x < stype.getAttributes().size(); x++) { XmlSchemaObject o = stype.getAttributes().get(x); if (o instanceof XmlSchemaAttribute) { XmlSchemaAttribute a = (XmlSchemaAttribute)o; if ("howdy".equals(a.getName())) { howdy = true; } if ("bleh".equals(a.getName())) { bleh = true; } } } assertTrue(howdy); assertTrue(bleh); }
Example #25
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; }