/** * Indicates if a complex type with simple content is to be generated. This is true when * the given descriptor has more than one mapping. It is assumed that isSimple(desc) * will return true for the given descriptor, and that the descriptor will contain at most * one direct with a 'text()' xpath, and any additional mappings are attribute mappings. * * @param desc * @return */ protected boolean isComplexTypeWithSimpleContentRequired(XMLDescriptor desc) { return desc.getMappings().size() > 1 ? true : false; }
private Class getTypeForTargetField(XMLField targetField, XMLDescriptor reference) { for(DatabaseMapping next: reference.getMappings()) { if(next.isDirectToFieldMapping()) { DirectMapping directMapping = (DirectMapping)next; if(directMapping.getField().equals(targetField)) { return directMapping.getAttributeClassification(); } } } return null; }
private Class getTypeForTargetField(XMLField targetField, XMLDescriptor reference) { for(DatabaseMapping next: reference.getMappings()) { if(next.isDirectToFieldMapping()) { DirectMapping directMapping = (DirectMapping)next; if(directMapping.getField().equals(targetField)) { return directMapping.getAttributeClassification(); } } } return null; }
/** * Determines if a given descriptor contains a direct mapping to "text()" indicating a * simple mapping. In this case, a simple type or complex type with simple content * will be generated * * @param desc * @return */ protected boolean isSimple(XMLDescriptor desc) { boolean isSimple = false; for (DatabaseMapping mapping : desc.getMappings()) { if (mapping.isDirectToFieldMapping()) { XMLField xFld = (XMLField) mapping.getField(); if (xFld.getXPath().equals(TEXT)) { isSimple = true; break; } } else { break; } } return isSimple; }
Iterator mappings = parentDesc.getMappings().iterator(); int mappingsInContext = 0; while (mappings.hasNext()) {
Iterator mappings = parentDesc.getMappings().iterator(); int mappingsInContext = 0; while (mappings.hasNext()) {
/** * INTERNAL: * @param type a type to become this Type's base Type. */ public void addBaseType(SDOType type) { if (!this.getBaseTypes().contains(type)) { getBaseTypes().add(type); updateSubtypes(type); if(!(type.isDataType() && (type.getQName().getNamespaceURI() == SDOConstants.SDO_URL || type.getQName().getNamespaceURI() == SDOConstants.SDOJAVA_URL))) { type.getSubTypes().add(this); } if (type.isOpen() && this.isOpen()) { //don't want any mappings on this descriptor DatabaseMapping anyCollectionMapping = getXmlDescriptor().getMappingForAttributeName(ANY_MAPPING_ATTRIBUTE_NAME); getXmlDescriptor().getMappings().remove(anyCollectionMapping); DatabaseMapping anyAttrMapping = getXmlDescriptor().getMappingForAttributeName("openContentPropertiesAttributes"); getXmlDescriptor().getMappings().remove(anyAttrMapping); } //int increaseBy = type.getProperties().size(); //increaseIndices(increaseBy); } }
/** * INTERNAL: * @param type a type to become this Type's base Type. */ public void addBaseType(SDOType type) { if (!this.getBaseTypes().contains(type)) { getBaseTypes().add(type); updateSubtypes(type); if(!(type.isDataType() && (type.getQName().getNamespaceURI() == SDOConstants.SDO_URL || type.getQName().getNamespaceURI() == SDOConstants.SDOJAVA_URL))) { type.getSubTypes().add(this); } if (type.isOpen() && this.isOpen()) { //don't want any mappings on this descriptor DatabaseMapping anyCollectionMapping = getXmlDescriptor().getMappingForAttributeName(ANY_MAPPING_ATTRIBUTE_NAME); getXmlDescriptor().getMappings().remove(anyCollectionMapping); DatabaseMapping anyAttrMapping = getXmlDescriptor().getMappingForAttributeName("openContentPropertiesAttributes"); getXmlDescriptor().getMappings().remove(anyAttrMapping); } //int increaseBy = type.getProperties().size(); //increaseIndices(increaseBy); } }
/** * Create and return a SimpleType for a given XMLDescriptor. * * @param desc * @param workingSchema * @return */ protected SimpleType buildSimpleType(XMLDescriptor desc, Schema workingSchema, boolean global) { SimpleType st; if (global) { st = buildNewSimpleType(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart()); } else { st = new SimpleType(); } DatabaseMapping mapping = desc.getMappings().get(0); QName qname = (QName) XMLConversionManager.getDefaultJavaTypes().get(mapping.getAttributeClassification()); String baseType = qname.getLocalPart(); if (qname.getNamespaceURI() != null) { String prefix = workingSchema.getNamespaceResolver().resolveNamespaceURI(qname.getNamespaceURI()); if (prefix == null) { prefix = workingSchema.getNamespaceResolver().generatePrefix(); workingSchema.getNamespaceResolver().put(prefix, qname.getNamespaceURI()); } baseType = prefix + XMLConstants.COLON + baseType; } Restriction restriction = new Restriction(); restriction.setBaseType(baseType); st.setRestriction(restriction); return st; }
private boolean hasAnyMappings(XMLDescriptor descriptor) { for(DatabaseMapping next:descriptor.getMappings()) { if(next instanceof XMLAnyAttributeMapping || next instanceof XMLAnyObjectMapping || next instanceof XMLAnyCollectionMapping || next instanceof XMLFragmentCollectionMapping || next instanceof XMLFragmentMapping ) { return true; } else if(next instanceof CompositeCollectionMapping) { CompositeCollectionMapping ccm = (CompositeCollectionMapping)next; if(ccm.getReferenceDescriptor() == null && ((XMLField)ccm.getField()).isSelfField()) { return true; } } else if(next instanceof CompositeObjectMapping) { CompositeObjectMapping ccm = (CompositeObjectMapping)next; if(ccm.getReferenceDescriptor() == null && ((XMLField)ccm.getField()).isSelfField()) { return true; } } } return false; }
private boolean hasAnyMappings(XMLDescriptor descriptor) { for(DatabaseMapping next:descriptor.getMappings()) { if(next instanceof XMLAnyAttributeMapping || next instanceof XMLAnyObjectMapping || next instanceof XMLAnyCollectionMapping || next instanceof XMLFragmentCollectionMapping || next instanceof XMLFragmentMapping ) { return true; } else if(next instanceof CompositeCollectionMapping) { CompositeCollectionMapping ccm = (CompositeCollectionMapping)next; if(ccm.getReferenceDescriptor() == null && ((XMLField)ccm.getField()).isSelfField()) { return true; } } else if(next instanceof CompositeObjectMapping) { CompositeObjectMapping ccm = (CompositeObjectMapping)next; if(ccm.getReferenceDescriptor() == null && ((XMLField)ccm.getField()).isSelfField()) { return true; } } } return false; }
@Override protected ClassDescriptor buildOXXMLDescriptorDescriptor() { XMLDescriptor descriptor = (XMLDescriptor)super.buildOXXMLDescriptorDescriptor(); XMLCompositeObjectMapping defaultRootElementFieldMapping = new XMLCompositeObjectMapping(); defaultRootElementFieldMapping.setAttributeName("defaultRootElementField"); defaultRootElementFieldMapping.setGetMethodName("getDefaultRootElementField"); defaultRootElementFieldMapping.setSetMethodName("setDefaultRootElementField"); defaultRootElementFieldMapping.setXPath(getPrimaryNamespaceXPath() + "default-root-element-field"); defaultRootElementFieldMapping.setReferenceClass(XMLField.class); NullPolicy defaultRootElementFieldNullPolicy = new NullPolicy(); defaultRootElementFieldNullPolicy.setSetPerformedForAbsentNode(false); defaultRootElementFieldMapping.setNullPolicy(defaultRootElementFieldNullPolicy); /* order is important for writing out * don't use addMapping: set parent descriptor and add after * first mapping built in super.buildOXXMLDescriptorDescriptor() */ defaultRootElementFieldMapping.setDescriptor(descriptor); descriptor.getMappings().add(1, defaultRootElementFieldMapping); return descriptor; }
@Override protected ClassDescriptor buildOXXMLDescriptorDescriptor() { XMLDescriptor descriptor = (XMLDescriptor)super.buildOXXMLDescriptorDescriptor(); XMLCompositeObjectMapping defaultRootElementFieldMapping = new XMLCompositeObjectMapping(); defaultRootElementFieldMapping.setAttributeName("defaultRootElementField"); defaultRootElementFieldMapping.setGetMethodName("getDefaultRootElementField"); defaultRootElementFieldMapping.setSetMethodName("setDefaultRootElementField"); defaultRootElementFieldMapping.setXPath(getPrimaryNamespaceXPath() + "default-root-element-field"); defaultRootElementFieldMapping.setReferenceClass(XMLField.class); NullPolicy defaultRootElementFieldNullPolicy = new NullPolicy(); defaultRootElementFieldNullPolicy.setSetPerformedForAbsentNode(false); defaultRootElementFieldMapping.setNullPolicy(defaultRootElementFieldNullPolicy); /* order is important for writing out * don't use addMapping: set parent descriptor and add after * first mapping built in super.buildOXXMLDescriptorDescriptor() */ defaultRootElementFieldMapping.setDescriptor(descriptor); descriptor.getMappings().add(1, defaultRootElementFieldMapping); return descriptor; }
@Override protected ClassDescriptor buildOXXMLDescriptorDescriptor() { XMLDescriptor descriptor = (XMLDescriptor)super.buildOXXMLDescriptorDescriptor(); XMLCompositeObjectMapping defaultRootElementFieldMapping = new XMLCompositeObjectMapping(); defaultRootElementFieldMapping.setAttributeName("defaultRootElementField"); defaultRootElementFieldMapping.setGetMethodName("getDefaultRootElementField"); defaultRootElementFieldMapping.setSetMethodName("setDefaultRootElementField"); defaultRootElementFieldMapping.setXPath(getPrimaryNamespaceXPath() + "default-root-element-field"); defaultRootElementFieldMapping.setReferenceClass(XMLField.class); NullPolicy defaultRootElementFieldNullPolicy = new NullPolicy(); defaultRootElementFieldNullPolicy.setSetPerformedForAbsentNode(false); defaultRootElementFieldMapping.setNullPolicy(defaultRootElementFieldNullPolicy); /* order is important for writing out * don't use addMapping: set parent descriptor and add after * first mapping built in super.buildOXXMLDescriptorDescriptor() */ defaultRootElementFieldMapping.setDescriptor(descriptor); descriptor.getMappings().add(1, defaultRootElementFieldMapping); return descriptor; }
for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { try { DatabaseMapping mapping = (DatabaseMapping) mappingsEnum.nextElement();
/** * Create and return a ComplexType containing simple content for a given XMLDescriptor. Assumes * that the descriptor has a schema context set. * * @param desc * @param schemaForNamespace * @param workingSchema * @param properties * @param descriptors * @return */ private ComplexType buildComplexTypeWithSimpleContent(XMLDescriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<XMLDescriptor> descriptors) { ComplexType ct = new ComplexType(); SimpleContent sc = new SimpleContent(); Extension extension = new Extension(); sc.setExtension(extension); ct.setSimpleContent(sc); for (DatabaseMapping mapping : desc.getMappings()) { XMLField xFld = (XMLField) mapping.getField(); if (xFld.getXPath().equals(TEXT)) { extension.setBaseType(getSchemaTypeForDirectMapping((XMLDirectMapping) mapping, workingSchema)); } else if (xFld.getXPathFragment().isAttribute()) { String schemaTypeString = getSchemaTypeForDirectMapping((XMLDirectMapping) mapping, workingSchema); Attribute attr = buildAttribute((XMLDirectMapping) mapping, schemaTypeString); extension.getOrderedAttributes().add(attr); } } return ct; }
/** * INTERNAL: * Allow the descriptor to initialize any dependencies on this session. */ public void preInitialize(AbstractSession session) throws DescriptorException { // Avoid repetitive initialization (this does not solve loops) if (isInitialized(PREINITIALIZED)) { return; } setInitializationStage(PREINITIALIZED); // Allow mapping pre init, must be done before validate. for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { try { DatabaseMapping mapping = (DatabaseMapping) mappingsEnum.nextElement(); mapping.preInitialize(session); } catch (DescriptorException exception) { session.getIntegrityChecker().handleError(exception); } } getCachePolicy().useNoIdentityMap(); getQueryManager().getDoesExistQuery().setExistencePolicy(DoesExistQuery.CheckDatabase); validateBeforeInitialization(session); preInitializeInheritancePolicy(session); verifyTableQualifiers(session.getDatasourcePlatform()); initializeProperties(session); if (hasInterfacePolicy()) { preInterfaceInitialization(session); } getCachePolicy().assignDefaultValues(session); }
/** * INTERNAL: * Allow the descriptor to initialize any dependencies on this session. */ public void preInitialize(AbstractSession session) throws DescriptorException { // Avoid repetitive initialization (this does not solve loops) if (isInitialized(PREINITIALIZED)) { return; } setInitializationStage(PREINITIALIZED); // Allow mapping pre init, must be done before validate. for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { try { DatabaseMapping mapping = (DatabaseMapping) mappingsEnum.nextElement(); mapping.preInitialize(session); } catch (DescriptorException exception) { session.getIntegrityChecker().handleError(exception); } } getCachePolicy().useNoIdentityMap(); getQueryManager().getDoesExistQuery().setExistencePolicy(DoesExistQuery.CheckDatabase); validateBeforeInitialization(session); preInitializeInheritancePolicy(session); verifyTableQualifiers(session.getDatasourcePlatform()); initializeProperties(session); if (hasInterfacePolicy()) { preInterfaceInitialization(session); } getCachePolicy().assignDefaultValues(session); }
private DatabaseMapping getTextMapping(XMLDescriptor descriptor) { for(DatabaseMapping next:descriptor.getMappings()) { if(next.isAbstractDirectMapping()) { DirectMapping mapping = (DirectMapping)next; if(((XMLField)mapping.getField()).getXPathFragment().nameIsText()) { return next; } } if(next.isAbstractCompositeDirectCollectionMapping()) { DirectCollectionMapping mapping = (DirectCollectionMapping)next; if(((XMLField)mapping.getField()).getXPathFragment().nameIsText()) { return next; } } if(next instanceof BinaryDataMapping) { BinaryDataMapping mapping = (BinaryDataMapping)next; if(((XMLField)mapping.getField()).isSelfField()) { return next; } } if(next instanceof BinaryDataCollectionMapping) { BinaryDataCollectionMapping mapping = (BinaryDataCollectionMapping)next; if(((XMLField)mapping.getField()).isSelfField()) { return next; } } } return null; }
private DatabaseMapping getTextMapping(XMLDescriptor descriptor) { for(DatabaseMapping next:descriptor.getMappings()) { if(next.isAbstractDirectMapping()) { DirectMapping mapping = (DirectMapping)next; if(((XMLField)mapping.getField()).getXPathFragment().nameIsText()) { return next; } } if(next.isAbstractCompositeDirectCollectionMapping()) { DirectCollectionMapping mapping = (DirectCollectionMapping)next; if(((XMLField)mapping.getField()).getXPathFragment().nameIsText()) { return next; } } if(next instanceof BinaryDataMapping) { BinaryDataMapping mapping = (BinaryDataMapping)next; if(((XMLField)mapping.getField()).isSelfField()) { return next; } } if(next instanceof BinaryDataCollectionMapping) { BinaryDataCollectionMapping mapping = (BinaryDataCollectionMapping)next; if(((XMLField)mapping.getField()).isSelfField()) { return next; } } } return null; }