/** * INTERNAL: */ public boolean shouldAddXsiType(XMLMarshaller xmlMarshaller, XMLDescriptor xmlDescriptor, Object originalObject, boolean wasXMLRoot) { if ((xmlDescriptor.getSchemaReference() != null) && xmlMarshaller.shouldWriteTypeAttribute(originalObject, xmlDescriptor, wasXMLRoot)) { return true; } return false; }
/** * INTERNAL: */ public boolean shouldAddXsiType(XMLMarshaller xmlmarshaller, XMLDescriptor xmlDescriptor, Object originalObject, boolean wasXMLRoot) { if ((xmlDescriptor.getSchemaReference() != null) && xmlmarshaller.shouldWriteTypeAttribute(originalObject, xmlDescriptor, wasXMLRoot)) { return true; } return false; }
private void initializeSchemas() { if (!schemasAreInitialized) { HashSet schemas = new HashSet(); Iterator xmlDescriptors; XMLDescriptor xmlDescriptor; XMLSchemaReference xmlSchemaReference; int numberOfSessions = ((XMLContext) context).getSessions().size(); for (int x = 0; x < numberOfSessions; x++) { xmlDescriptors = ((CoreSession)context.getSessions().get(x)).getDescriptors().values().iterator(); URL schemaURL; while (xmlDescriptors.hasNext()) { xmlDescriptor = (XMLDescriptor)xmlDescriptors.next(); xmlSchemaReference = xmlDescriptor.getSchemaReference(); if (null != xmlSchemaReference) { schemaURL = xmlSchemaReference.getURL(); if (null != schemaURL) { schemas.add(schemaURL.toString()); } } } } schemas.remove(null); platformUnmarshaller.setSchemas(schemas.toArray()); schemasAreInitialized = true; } }
private void initializeSchemas() { if (!schemasAreInitialized) { HashSet schemas = new HashSet(); Iterator xmlDescriptors; XMLDescriptor xmlDescriptor; XMLSchemaReference xmlSchemaReference; int numberOfSessions = xmlContext.getSessions().size(); for (int x = 0; x < numberOfSessions; x++) { xmlDescriptors = ((DatabaseSession)xmlContext.getSessions().get(x)).getDescriptors().values().iterator(); URL schemaURL; while (xmlDescriptors.hasNext()) { xmlDescriptor = (XMLDescriptor)xmlDescriptors.next(); xmlSchemaReference = xmlDescriptor.getSchemaReference(); if (null != xmlSchemaReference) { schemaURL = xmlSchemaReference.getURL(); if (null != schemaURL) { schemas.add(schemaURL.toString()); } } } } schemas.remove(null); platformUnmarshaller.setSchemas(schemas.toArray()); schemasAreInitialized = true; } }
protected void addTypeAttributeIfNeeded(XMLDescriptor descriptor, DatabaseMapping mapping, MarshalRecord marshalRecord) { XMLSchemaReference xmlRef = descriptor.getSchemaReference(); if (xmlCompositeCollectionMapping.shouldAddXsiType(marshalRecord, descriptor) && (xmlRef != null)) { addTypeAttribute(descriptor, marshalRecord, xmlRef.getSchemaContext()); } }
private void initializeSchemas() { if (!schemasAreInitialized) { HashSet schemas = new HashSet(); Iterator xmlDescriptors; XMLDescriptor xmlDescriptor; XMLSchemaReference xmlSchemaReference; int numberOfSessions = ((XMLContext) context).getSessions().size(); for (int x = 0; x < numberOfSessions; x++) { xmlDescriptors = ((CoreSession)context.getSessions().get(x)).getDescriptors().values().iterator(); URL schemaURL; while (xmlDescriptors.hasNext()) { xmlDescriptor = (XMLDescriptor)xmlDescriptors.next(); xmlSchemaReference = xmlDescriptor.getSchemaReference(); if (null != xmlSchemaReference) { schemaURL = xmlSchemaReference.getURL(); if (null != schemaURL) { schemas.add(schemaURL.toString()); } } } } schemas.remove(null); platformUnmarshaller.setSchemas(schemas.toArray()); schemasAreInitialized = true; } }
protected void addTypeAttributeIfNeeded(XMLDescriptor descriptor, DatabaseMapping mapping, MarshalRecord marshalRecord) { XMLSchemaReference xmlRef = descriptor.getSchemaReference(); if (xmlCompositeObjectMapping.shouldAddXsiType(marshalRecord, descriptor) && (xmlRef != null)) { addTypeAttribute(descriptor, marshalRecord, xmlRef.getSchemaContext()); } }
/** * <p>INTERNAL: */ @SuppressWarnings("rawtypes") public void buildDescriptorIndex() { for (Iterator i = xrService.oxSession.getProject().getOrderedDescriptors().iterator(); i.hasNext();) { XMLDescriptor xd = (XMLDescriptor)i.next(); XMLSchemaReference schemaReference = xd.getSchemaReference(); if (schemaReference != null && schemaReference.getType() == XMLSchemaReference.COMPLEX_TYPE) { String context = schemaReference.getSchemaContext(); if (context != null && context.lastIndexOf(SLASH_CHAR) == 0) { String elementNameNS = context.substring(1); QName elementName = resolveName(elementNameNS, xd.getNamespaceResolver()); if (elementName == null) { continue; } xrService.descriptorsByQName.put(elementName, xd); } } } }
/** * <p>INTERNAL: */ @SuppressWarnings("rawtypes") public void buildDescriptorIndex() { for (Iterator i = xrService.oxSession.getProject().getOrderedDescriptors().iterator(); i.hasNext();) { XMLDescriptor xd = (XMLDescriptor)i.next(); XMLSchemaReference schemaReference = xd.getSchemaReference(); if (schemaReference != null && schemaReference.getType() == XMLSchemaReference.COMPLEX_TYPE) { String context = schemaReference.getSchemaContext(); if (context != null && context.lastIndexOf(SLASH_CHAR) == 0) { String elementNameNS = context.substring(1); QName elementName = resolveName(elementNameNS, xd.getNamespaceResolver()); if (elementName == null) { continue; } xrService.descriptorsByQName.put(elementName, xd); } } } }
/** * Validate the given root object. * @param rootObject A single root object to validate * @return true if this is a valid object, otherwise false */ public boolean validateRoot(Object rootObject) throws XMLMarshalException { if (rootObject == null) { throw XMLMarshalException.nullArgumentException(); } XMLDescriptor xmlDescriptor = (XMLDescriptor)xmlContext.getSession(rootObject).getDescriptor(rootObject); Document document = marshaller.objectToXML(rootObject, xmlDescriptor, false); if (xmlDescriptor.getSchemaReference() == null) { throw XMLMarshalException.schemaReferenceNotSet(xmlDescriptor); } return xmlDescriptor.getSchemaReference().isValid(document, getErrorHandler()); }
/** * Validate the given root object. * @param rootObject A single root object to validate * @return true if this is a valid object, otherwise false */ public boolean validateRoot(Object rootObject) throws XMLMarshalException { if (rootObject == null) { throw XMLMarshalException.nullArgumentException(); } XMLDescriptor xmlDescriptor = (XMLDescriptor)xmlContext.getSession(rootObject).getDescriptor(rootObject); Document document = marshaller.objectToXML(rootObject, xmlDescriptor, false); if (xmlDescriptor.getSchemaReference() == null) { throw XMLMarshalException.schemaReferenceNotSet(xmlDescriptor); } return xmlDescriptor.getSchemaReference().isValid(document, getErrorHandler()); }
/** * Validate the given root object. * @param rootObject A single root object to validate * @return true if this is a valid object, otherwise false */ public boolean validateRoot(Object rootObject) throws XMLMarshalException { if (rootObject == null) { throw XMLMarshalException.nullArgumentException(); } XMLDescriptor xmlDescriptor = (XMLDescriptor)xmlContext.getSession(rootObject).getDescriptor(rootObject); Document document = marshaller.objectToXML(rootObject, xmlDescriptor, false); if (xmlDescriptor.getSchemaReference() == null) { throw XMLMarshalException.schemaReferenceNotSet(xmlDescriptor); } return xmlDescriptor.getSchemaReference().isValid(document, getErrorHandler()); }
private void writeTypeAttribute(MarshalRecord marshalRecord, XMLDescriptor descriptor, String xsiPrefix) { //xsi:type=schemacontext String typeValue = descriptor.getSchemaReference().getSchemaContext(); // handle case where the schema context is set as a QName if (typeValue == null) { QName contextAsQName = descriptor.getSchemaReference().getSchemaContextAsQName(); if (contextAsQName == null) { return; } String uri = contextAsQName.getNamespaceURI(); String localPart = contextAsQName.getLocalPart(); String prefix = marshalRecord.getNamespaceResolver().resolveNamespaceURI(uri); if (prefix == null) { String defaultUri = marshalRecord.getNamespaceResolver().getDefaultNamespaceURI(); if (defaultUri != null && defaultUri.equals(uri)) { typeValue = localPart; } else { prefix = marshalRecord.getNamespaceResolver().generatePrefix(); marshalRecord.attribute(XMLConstants.XMLNS_URL, prefix, XMLConstants.XMLNS + XMLConstants.COLON + prefix, uri); typeValue = prefix + XMLConstants.COLON + localPart; } } else { typeValue = prefix + XMLConstants.COLON + localPart; } } else { typeValue = typeValue.substring(1); } marshalRecord.attribute(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE, xsiPrefix + XMLConstants.COLON + XMLConstants.SCHEMA_TYPE_ATTRIBUTE, typeValue); }
/** * INTERNAL: */ public boolean shouldAddXsiType(XMLRecord record, ClassDescriptor aDescriptor) { XMLDescriptor xmlDescriptor = (XMLDescriptor) aDescriptor; if ((getReferenceDescriptor() == null) && (xmlDescriptor.getSchemaReference() != null)) { if (aDescriptor.hasInheritance()) { XMLField indicatorField = (XMLField) aDescriptor.getInheritancePolicy().getClassIndicatorField(); if ((indicatorField.getLastXPathFragment().getNamespaceURI() != null) // && indicatorField.getLastXPathFragment().getNamespaceURI().equals(XMLConstants.SCHEMA_INSTANCE_URL) // && indicatorField.getLastXPathFragment().getLocalName().equals(XMLConstants.SCHEMA_TYPE_ATTRIBUTE)) { return false; } } XMLSchemaReference xmlRef = xmlDescriptor.getSchemaReference(); if ((xmlRef.getType() == XMLSchemaReference.COMPLEX_TYPE) && xmlRef.isGlobalDefinition()) { QName ctxQName = xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver()); QName leafType = ((XMLField) getField()).getLeafElementType(); if ((leafType == null) || (!ctxQName.equals(record.getLeafElementType()))) { return true; } } } return false; }
/** * INTERNAL: */ public boolean shouldAddXsiType(XMLRecord record, ClassDescriptor descriptor) { XMLDescriptor xmlDescriptor = (XMLDescriptor) descriptor; if ((getReferenceDescriptor() == null) && (xmlDescriptor.getSchemaReference() != null)) { if (descriptor.hasInheritance()) { XMLField indicatorField = (XMLField) descriptor.getInheritancePolicy().getClassIndicatorField(); if ((indicatorField.getLastXPathFragment().getNamespaceURI() != null) && indicatorField.getLastXPathFragment().getNamespaceURI().equals(XMLConstants.SCHEMA_INSTANCE_URL) && indicatorField.getLastXPathFragment().getLocalName().equals(XMLConstants.SCHEMA_TYPE_ATTRIBUTE)) { return false; } } XMLSchemaReference xmlRef = xmlDescriptor.getSchemaReference(); if ((xmlRef.getType() == XMLSchemaReference.COMPLEX_TYPE) && xmlRef.isGlobalDefinition()) { QName ctxQName = xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver()); QName leafType = ((XMLField) getField()).getLeafElementType(); if ((leafType == null) || (!ctxQName.equals(record.getLeafElementType()))) { return true; } } } return false; }
/** * 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(XMLDescriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<XMLDescriptor> 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; }
private DatabaseMapping buildXMLCompositeCollectionMapping(String mappingUri) { XMLCompositeCollectionMapping mapping = new XMLCompositeCollectionMapping(); mapping.setAttributeName(getName()); String xpath = getQualifiedXPath(mappingUri, false); mapping.setXPath(xpath); if (!getType().isDataObjectType()) { QName schemaContext = getType().getXmlDescriptor().getSchemaReference().getSchemaContextAsQName(getType().getXmlDescriptor().getNamespaceResolver()); ((XMLField)mapping.getField()).setLeafElementType(schemaContext); mapping.setReferenceClassName(getType().getImplClassName()); mapping.setReferenceClass(getType().getImplClass()); }else{ if(getXsdType()!= null){ ((XMLField)mapping.getField()).setLeafElementType(getXsdType()); } } mapping.useCollectionClass(ListWrapper.class); // Set null policy on mapping for xsi:nil support: // - aNullPolicy.setNullRepresentedByEmptyNode(false); // - aNullPolicy.setNullRepresentedByXsiNil(true); setIsSetNillablePolicyOnMapping(mapping, propertyName); return mapping; }
private DatabaseMapping buildXMLCompositeCollectionMapping(String mappingUri) { XMLCompositeCollectionMapping mapping = new XMLCompositeCollectionMapping(); mapping.setAttributeName(getName()); String xpath = getQualifiedXPath(mappingUri, false); mapping.setXPath(xpath); if (!getType().isDataObjectType()) { QName schemaContext = getType().getXmlDescriptor().getSchemaReference().getSchemaContextAsQName(getType().getXmlDescriptor().getNamespaceResolver()); ((XMLField)mapping.getField()).setLeafElementType(schemaContext); mapping.setReferenceClassName(getType().getImplClassName()); mapping.setReferenceClass(getType().getImplClass()); }else{ if(getXsdType()!= null){ ((XMLField)mapping.getField()).setLeafElementType(getXsdType()); } } mapping.useCollectionClass(ListWrapper.class); // Set null policy on mapping for xsi:nil support: // - aNullPolicy.setNullRepresentedByEmptyNode(false); // - aNullPolicy.setNullRepresentedByXsiNil(true); setIsSetNillablePolicyOnMapping(mapping, propertyName); return mapping; }
private DatabaseMapping buildXMLCompositeObjectMapping(String mappingUri) { XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping(); mapping.setAttributeName(getName()); String xpath = getQualifiedXPath(mappingUri, false); mapping.setXPath(xpath); if (!getType().isDataObjectType()) { QName schemaContext = getType().getXmlDescriptor().getSchemaReference().getSchemaContextAsQName(getType().getXmlDescriptor().getNamespaceResolver()); ((XMLField)mapping.getField()).setLeafElementType(schemaContext); mapping.setReferenceClassName(getType().getImplClassName()); mapping.setReferenceClass(getType().getImplClass()); }else{ if(getXsdType()!= null){ ((XMLField)mapping.getField()).setLeafElementType(getXsdType()); } } // Handle nillable element support via the nullable property if (nullable) { setIsSetNillablePolicyOnMapping(mapping, propertyName); } else { // elements or attributes setIsSetOptionalPolicyOnMapping(mapping, propertyName); } return mapping; }
private DatabaseMapping buildXMLCompositeObjectMapping(String mappingUri) { XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping(); mapping.setAttributeName(getName()); String xpath = getQualifiedXPath(mappingUri, false); mapping.setXPath(xpath); if (!getType().isDataObjectType()) { QName schemaContext = getType().getXmlDescriptor().getSchemaReference().getSchemaContextAsQName(getType().getXmlDescriptor().getNamespaceResolver()); ((XMLField)mapping.getField()).setLeafElementType(schemaContext); mapping.setReferenceClassName(getType().getImplClassName()); mapping.setReferenceClass(getType().getImplClass()); }else{ if(getXsdType()!= null){ ((XMLField)mapping.getField()).setLeafElementType(getXsdType()); } } // Handle nillable element support via the nullable property if (nullable) { setIsSetNillablePolicyOnMapping(mapping, propertyName); } else { // elements or attributes setIsSetOptionalPolicyOnMapping(mapping, propertyName); } return mapping; }