Element reference = new Element(); reference.setMinOccurs(referencedElement.getMinOccurs()); reference.setMaxOccurs(referencedElement.getMaxOccurs()); Schema attributeSchema = this.getSchemaForNamespace(referencedElementURI); if (attributeSchema != null && attributeSchema.getTopLevelElements().get(referencedElement.getName()) == null) { referencedElement.setMinOccurs(null); referencedElement.setMaxOccurs(null); attributeSchema.getTopLevelElements().put(referencedElement.getName(), referencedElement); reference.setRef(referencedElement.getName()); } else { reference.setRef(prefix + COLON + referencedElement.getName()); if (elementExistsInParticle(reference.getName(), reference.getRef(), compositor) == null) { compositor.addElement(reference);
private SDOType processElement(String targetNamespace, String defaultNamespace, SDOType owningType, TypeDefParticle typeDefParticle, Element element, boolean isGlobal, boolean isMany) { SDOType type = null; boolean addedNR = addNextNamespaceResolver(element.getAttributesMap()); ComplexType complexType = element.getComplexType(); boolean qualified = true; if (!isGlobal) { qualified = rootSchema.isElementFormDefault(); } if (!isMany && maxOccursGreaterThanOne(element.getMaxOccurs())) { isMany = true; } if (complexType != null) { type = processComplexType(targetNamespace, defaultNamespace, element.getName(), complexType); type.setXsdLocalName(element.getName()); type.setXsd(true); processSimpleElement(targetNamespace, defaultNamespace, owningType, type, typeDefParticle, element, qualified, isGlobal, isMany); } else if (element.getSimpleType() != null) { type = processSimpleType(targetNamespace, defaultNamespace, element.getName(), element.getSimpleType()); type.setXsdLocalName(element.getName()); type.setXsd(true); processSimpleElement(targetNamespace, defaultNamespace, owningType, type, typeDefParticle, element, qualified, isGlobal, isMany); } else { processSimpleElement(targetNamespace, defaultNamespace, owningType, null, typeDefParticle, element, qualified, isGlobal, isMany); } if (addedNR) { namespaceResolvers.remove(namespaceResolvers.size() - 1); } return type; }
/** * Build and return an Element based on a given name, minOccurs and * maxOccurs. * * @param name * @param minOccurs * @param maxOccurs * @return */ protected Element buildElement(String name, String minOccurs, String maxOccurs) { Element element = new Element(); element.setName(name); element.setMinOccurs(minOccurs); element.setMaxOccurs(maxOccurs); return element; }
/** * Create an element reference and add it to a given particle. This * method will typically be called when processing an XPath and a * prefixed path element is encountered that requires an element ref. * * @param elementRefName * @param particle * @return */ public Element createRefElement(String elementRefName, TypeDefParticle particle) { Element refElement = new Element(); // ref won't have a complex type refElement.setComplexType(null); refElement.setMinOccurs(Occurs.ZERO); refElement.setMaxOccurs(Occurs.ONE); refElement.setRef(elementRefName); particle.addElement(refElement); return refElement; }
private void processFacet(Element element, Facet facet) { if (element.getSimpleType() == null) element.setSimpleType(new SimpleType()); Restriction restriction = element.getSimpleType().getRestriction(); if (restriction == null) { restriction = new Restriction(element.getType()); element.getSimpleType().setRestriction(restriction); } element.setType(null); // Prevent error: "Cannot have both a 'type' attribute and an 'anonymous type' child". facet.accept(FacetVisitorHolder.VISITOR, restriction); }
Element element = new Element(); element.setNillable(true); element.setDefaultValue(property.getDefaultValue()); element.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, property.getMimeType()); element.setName(elementName.getLocalPart()); String typeName = getTypeNameForComponent(property, schema, javaType, element, true); list.setItemType(typeName); localSimpleType.setList(list); element.setSimpleType(localSimpleType); } else { element.setMaxOccurs(Occurs.UNBOUNDED); element.setType(typeName); addMapToSchema(property, element, schema, typeInfo); } else { element.setType(typeName); element.setMinOccurs(String.valueOf(minOccurs)); } else { element.setMinOccurs(property.isRequired() ? Occurs.ONE : Occurs.ZERO); if (maxOccurs != null) element.setMaxOccurs(String.valueOf(maxOccurs));
/** * Create and return an Element for a given XMLDescriptor. * * @param desc * @param schemaForNamespace * @param workingSchema * @param properties * @param descriptors * @param simple * @return */ protected Element buildElement(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean simple) { Element element = new Element(); element.setName(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart()); if (simple) { if (isComplexTypeWithSimpleContentRequired(desc)) { element.setComplexType(buildComplexTypeWithSimpleContent(desc, schemaForNamespace, workingSchema, properties, descriptors)); } else { element.setSimpleType(buildSimpleType(desc, workingSchema, false)); } } else { element.setComplexType(buildComplexType(true, desc, schemaForNamespace, workingSchema, properties, descriptors)); } return element; }
currentElement = new Element(); XPathFragment nextFragment = frag.getNextFragment(); if (frag.containsIndex() || frag.getPredicate() != null || (!next.isXmlList() && null != nextFragment && nextFragment.isAttribute() && helper.isCollectionType(next.getType()))) { currentElement.setMaxOccurs(Occurs.UNBOUNDED); currentElement.setComplexType(cType); } else { if(currentElement.getType() != null && currentElement.getComplexType() == null) { SimpleType type = currentElement.getSimpleType(); if(type != null) { ComplexType cType = new ComplexType(); extension.setBaseType(type.getRestriction().getBaseType()); cType.getSimpleContent().setExtension(extension); currentElement.setSimpleType(null); currentElement.setComplexType(cType); } else { String eType = currentElement.getType(); ComplexType cType = new ComplexType(); SimpleContent sContent = new SimpleContent(); sContent.setExtension(extension); cType.setSimpleContent(sContent); currentElement.setType(null); currentElement.setComplexType(cType);
Element wrapperElement = new Element(); String name = wrapper.getName(); wrapperElement.setNillable(wrapper.isNillable()); wrapperElement.setMinOccurs(Occurs.ONE); wrapperElement.setMaxOccurs(Occurs.ONE); wrapperElement.setRef(prefix + COLON + name); compositor.addElement(wrapperElement); wrapperElement.setName(name); if (wrapper.isRequired()) { wrapperElement.setMinOccurs(Occurs.ONE); } else { wrapperElement.setMinOccurs(Occurs.ZERO); Sequence wrapperSequence = new Sequence(); wrapperType.setSequence(wrapperSequence); wrapperElement.setComplexType(wrapperType); return new AddToSchemaResult(wrapperSequence, wrapperType);
String manyValue = (String) element.getAttributesMap().get(SDOConstants.SDOXML_MANY_QNAME); if (manyValue != null) { isMany = Boolean.valueOf(manyValue); if (element.getRef() != null) { String ref = element.getRef(); String localName = null; String uri = null; theProp.setMany(isMany); theProp.setInstanceProperty(SDOConstants.XMLELEMENT_PROPERTY, Boolean.TRUE); if (element.getAnnotation() != null) { java.util.List doc = element.getAnnotation().getDocumentation(); if (doc != null) { theProp.setInstanceProperty(SDOConstants.DOCUMENTATION_PROPERTY, doc); } else { if (isGlobal) { SDOProperty lookedUpProp = getExistingGlobalProperty(targetNamespace, element.getName(), true); if (lookedUpProp != null && lookedUpProp.isFinalized()) { return; p = createNewProperty(targetNamespace, element.getName(), isQualified, isGlobal, true, element.isNillable(), element.getAnnotation()); if (element.getAnnotation() != null) { p.setAppInfoElements(element.getAnnotation().getAppInfo()); if (element.getType() != null) { typeName = element.getType(); p.setName(element.getName());
Element element = new Element(); element.setName(next.getLocalPart()); element.setNillable(nextElement.isNillable()); JavaClass javaClass = nextElement.getJavaType(); element.setType(Constants.SCHEMA_PREFIX + COLON + schemaType.getLocalPart()); } else if (areEquals(javaClass, JAVAX_ACTIVATION_DATAHANDLER) || areEquals(javaClass, byte[].class) || areEquals(javaClass, Byte[].class) || areEquals(javaClass, Image.class) || areEquals(javaClass, Source.class) || areEquals(javaClass, JAVAX_MAIL_INTERNET_MIMEMULTIPART)) { schemaType = Constants.BASE_64_BINARY_QNAME; element.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, nextElement.getXmlMimeType()); element.setType(prefix + COLON + schemaType.getLocalPart()); } else if (areEquals(javaClass, CoreClassConstants.XML_GREGORIAN_CALENDAR)) { schemaType = Constants.ANY_SIMPLE_TYPE_QNAME; element.setType(Constants.SCHEMA_PREFIX + COLON + schemaType.getLocalPart()); } else { element.setComplexType(cType); } else { element.setType(prefix + COLON + typeName); } else { element.setType(typeName); element.setType(prefix + COLON + typeName); } else { element.setType(typeName); String prefix = getPrefixForNamespace(targetSchema, subNamespace);
boolean currentElementExists = (currentElement != null); if (currentElement == null) { currentElement = new Element(); currentElement.setComplexType(cType); globalElement = new Element(); globalElement.setName(frag.getLocalName()); ComplexType gCType = new ComplexType(); Sequence gSequence = new Sequence(); gCType.setSequence(gSequence); globalElement.setComplexType(gCType); s.addTopLevelElement(globalElement); currentElement.setComplexType(null); currentElement.setRef(frag.getShortName()); currentSequence.addElement(currentElement); currentElementExists = true; currentElement.setName(frag.getLocalName()); currentSequence.addElement(currentElement); currentSequence = currentElement.getComplexType().getSequence();
if (frag.getNamespaceURI() != null) { elem = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, null, schemaTypeString); elem.setMaxOccurs(Occurs.UNBOUNDED); } else { elem = buildElement(frag, schemaTypeString, Occurs.ZERO, Occurs.UNBOUNDED); elem.setNillable(true); elem.setMinOccurs("1"); elem.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, mapping.getMimeType());
private Element buildElementForComplexType(Schema schema, ComplexType type) { Element elem = new Element(); String name = type.getName(); if (name == null) { return null; } String lowerName = Character.toLowerCase(name.charAt(0)) + name.substring(1, name.length()); Object exists = schema.getTopLevelElements().get(lowerName); if (exists != null) { elem.setName(name); } else { elem.setName(lowerName); } elem.setType(type.getName()); return elem; }
if ((s.isElementFormDefault() && !fragUri.equals(targetNS)) || (!s.isElementFormDefault() && fragUri.length() > 0)) { if (s.getTopLevelElements().get(frag.getLocalName()) == null) { Element globalElement = new Element(); globalElement.setName(frag.getLocalName()); globalElement.setType(schemaTypeString); s.addTopLevelElement(globalElement); element = new Element(); element.setRef(frag.getShortName()); } else { element = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
element.setSimpleType(st); } else { if (frag.getNamespaceURI() != null) { element = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, element, schemaTypeString); element.setMaxOccurs(Occurs.UNBOUNDED); } else { element = buildElement(frag, schemaTypeString, Occurs.ZERO, Occurs.UNBOUNDED); element.setNillable(true); element.setMinOccurs("1");
ctype = buildComplexType(true, refDesc, schemaForNamespace, workingSchema, properties, descriptors); } else { element.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema)); } else if (ctype != null) { element.setComplexType(ctype); isNillable = ((CompositeCollectionMapping) mapping).getNullPolicy().isNullRepresentedByXsiNil(); element.setNillable(isNillable); element.setMinOccurs("1");
elem.setNillable(true); elem.setMinOccurs("1"); elem.getAttributesMap().put(XMLConstants.EXPECTED_CONTENT_TYPES_QNAME, mapping.getMimeType());
/** * Convenience method that adds an element to a given schema. * * @param element the Property that the Element will be based on * @param compositor the sequence/choice/all that the Element will be added to * @param schema the schema currently being built */ private void addElementToSchema(Element element, String elementURI, boolean isPositional, TypeDefParticle compositor, Schema schema, String packageName) { String lookupNamespace = schema.getTargetNamespace(); if (lookupNamespace == null) { lookupNamespace = EMPTY_STRING; } NamespaceInfo namespaceInfo = getNamespaceInfoForNamespace(lookupNamespace, packageName); boolean isElementFormQualified = false; if (namespaceInfo != null) { isElementFormQualified = namespaceInfo.isElementFormQualified(); } boolean addRef = shouldAddRefAndSetForm(element, elementURI, lookupNamespace, isElementFormQualified, true); if(addRef){ addElementRefToSchema(schema, compositor, element, elementURI); } else { // for positional mappings we could have multiple elements with same name; check before adding if (elementExistsInParticle(element.getName(), element.getRef(), compositor) == null) { if (isPositional) { element.setMaxOccurs(Occurs.UNBOUNDED); } compositor.addElement(element); } } }