/** * INTERNAL: Convenience method that sets up class indicator and @sdoRef attribute. * * @param xdesc * @param pCls */ private void addClassIndicator(XMLDescriptor xdesc, Class pCls, boolean isInheritanceRoot) { XMLField field = (XMLField) getXmlDescriptor().buildField("@xsi:type"); xdesc.getInheritancePolicy().setClassIndicatorField(field); String parentIndicator = getName(); String parentPrefix = xdesc.getNamespaceResolver().resolveNamespaceURI(getURI()); if (parentPrefix != null) { parentIndicator = parentPrefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + parentIndicator; } xdesc.getInheritancePolicy().addClassIndicator(pCls, parentIndicator); // only add the @sdoRef attribute if necessary if (xdesc.getMappingForAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME) == null) { String sdoPrefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(SDOConstants.SDO_URL); XMLDirectMapping sdoRefMapping = new XMLDirectMapping(); sdoRefMapping.setAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME); XMLField xmlField = new XMLField( "@" + sdoPrefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + SDOConstants.CHANGESUMMARY_REF); xmlField.getXPathFragment().setNamespaceURI(SDOConstants.SDO_URL); xmlField.getLastXPathFragment().setNamespaceURI(SDOConstants.SDO_URL); sdoRefMapping.setField(xmlField); xdesc.addMapping(sdoRefMapping); } }
public void setMixed(boolean isMixed) { String textAttribute = "text"; XMLDirectMapping textMapping = (XMLDirectMapping) xmlDescriptor.getMappingForAttributeName(textAttribute); if (isMixed) { if (null == textMapping) { textMapping = new XMLDirectMapping(); textMapping.setAttributeName(textAttribute); textMapping.setXPath("text()"); xmlDescriptor.addMapping(textMapping); } } else { xmlDescriptor.removeMappingForAttributeName(textAttribute); } }
public DirectIsSetNodeNullPolicyTrueTestCases(String name) throws Exception { super(name); setControlDocument(XML_RESOURCE); AbstractNullPolicy aNullPolicy = new IsSetNullPolicy(); // alter unmarshal policy state aNullPolicy.setNullRepresentedByEmptyNode(true); // no effect aNullPolicy.setNullRepresentedByXsiNil(false); // no effect // alter marshal policy state aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL); // .EMPTY_NODE); ((IsSetNullPolicy) aNullPolicy).setIsSetMethodName("isSetFirstName"); Project aProject = new DirectNodeNullPolicyProject(true); XMLDescriptor employeeDescriptor = (XMLDescriptor) aProject.getDescriptor(Employee.class); NamespaceResolver namespaceResolver = new NamespaceResolver(); namespaceResolver.put(XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL); employeeDescriptor.setNamespaceResolver(namespaceResolver); XMLDirectMapping aMapping = (XMLDirectMapping) employeeDescriptor.getMappingForAttributeName("firstName"); aMapping.setNullPolicy(aNullPolicy); setProject(aProject); }
@SuppressWarnings("unchecked") @Override public void handleSqlType(String sqlTypeName, int typecode, String targetTypeName) { if (!stac.isEmpty()) { ListenerHelper listenerHelper = stac.pop(); if (listenerHelper.isAttribute()) { AttributeFieldHelper attributeFieldHelper = (AttributeFieldHelper) listenerHelper; attributeFieldHelper.setSqlTypeName(sqlTypeName); String fieldName = attributeFieldHelper.attributeFieldName(); String attributeName = fieldName.toLowerCase(); ListenerHelper listenerHelper2 = stac.peek(); if (listenerHelper2.isObject()) { ObjectTypeHelper objectTypeHelper = (ObjectTypeHelper) listenerHelper2; XMLDescriptor xdesc = descriptorMap.get(objectTypeHelper.objectTypename()); DatabaseMapping dm = xdesc.getMappingForAttributeName(attributeName); if (dm == null) { XMLDirectMapping fieldMapping = new XMLDirectMapping(); fieldMapping.setAttributeName(attributeName); XMLField xField = new XMLField(attributeName + "/text()"); xField.setRequired(true); QName qnameFromDatabaseType = qnameFromDatabaseType(listenerHelper); xField.setSchemaType(qnameFromDatabaseType); // special case to avoid Calendar problems if (qnameFromDatabaseType == DATE_QNAME) { fieldMapping.setAttributeClassification(java.sql.Date.class); xField.addXMLConversion(DATE_QNAME, java.sql.Date.class); xField.addJavaConversion(java.sql.Date.class, DATE_QNAME); xdesc.getNamespaceResolver().put(SCHEMA_PREFIX, W3C_XML_SCHEMA_NS_URI); } else { Class attributeClass = (Class) XMLConversionManager.getDefaultXMLTypes().get(qnameFromDatabaseType); if (attributeClass == null) { attributeClass = Object_Class; } fieldMapping.setAttributeClassification(attributeClass); } fieldMapping.setField(xField); AbstractNullPolicy nullPolicy = fieldMapping.getNullPolicy(); nullPolicy.setNullRepresentedByEmptyNode(false); nullPolicy.setMarshalNullRepresentation(XSI_NIL); nullPolicy.setNullRepresentedByXsiNil(true); fieldMapping.setNullPolicy(nullPolicy); xdesc .getNamespaceResolver() .put( SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI); // to support xsi:nil policy xdesc.addMapping(fieldMapping); } // last attribute, pop ObjectTypeHelper off stack int numAttributes = objectTypeHelper.decrNumAttributes(); if (numAttributes == 0) { stac.pop(); } } else if (listenerHelper2.isArray()) { SqlArrayTypeHelper sqlArrayTypeHelper = (SqlArrayTypeHelper) listenerHelper2; XMLDescriptor xdesc = descriptorMap.get(sqlArrayTypeHelper.arrayTypename()); DatabaseMapping dm = xdesc.getMappingForAttributeName(attributeName); if (dm == null) { XMLCompositeDirectCollectionMapping dirCollectMapping = new XMLCompositeDirectCollectionMapping(); SqltypeHelper componentType = new SqltypeHelper(sqlTypeName); dirCollectMapping.setAttributeElementClass( attributeClassFromDatabaseType((DefaultListenerHelper) componentType)); dirCollectMapping.setAttributeName(attributeName); dirCollectMapping.setUsesSingleNode(true); dirCollectMapping.setXPath(attributeName + "/text()"); XMLField xField = (XMLField) dirCollectMapping.getField(); xField.setRequired(true); xField.setSchemaType(qnameFromDatabaseType(componentType)); dirCollectMapping.useCollectionClassName("java.util.ArrayList"); AbstractNullPolicy nullPolicy = dirCollectMapping.getNullPolicy(); nullPolicy.setNullRepresentedByEmptyNode(false); nullPolicy.setMarshalNullRepresentation(XSI_NIL); nullPolicy.setNullRepresentedByXsiNil(true); dirCollectMapping.setNullPolicy(nullPolicy); xdesc .getNamespaceResolver() .put( SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI); // to support xsi:nil policy xdesc.addMapping(dirCollectMapping); } } } else if (listenerHelper.isArray()) { SqlArrayTypeHelper sqlArrayTypeHelper2 = (SqlArrayTypeHelper) listenerHelper; XMLDescriptor xdesc = descriptorMap.get(sqlArrayTypeHelper2.arrayTypename()); DatabaseMapping dm = xdesc.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME); if (dm == null) { XMLCompositeDirectCollectionMapping itemsMapping = new XMLCompositeDirectCollectionMapping(); SqltypeHelper componentType = new SqltypeHelper(sqlTypeName); itemsMapping.setAttributeElementClass( attributeClassFromDatabaseType((DefaultListenerHelper) componentType)); itemsMapping.setAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME); itemsMapping.setUsesSingleNode(true); itemsMapping.setXPath(ITEM_MAPPING_NAME + "/text()"); XMLField xField = (XMLField) itemsMapping.getField(); xField.setRequired(true); xField.setSchemaType(qnameFromDatabaseType(componentType)); itemsMapping.useCollectionClassName("java.util.ArrayList"); AbstractNullPolicy nullPolicy = itemsMapping.getNullPolicy(); nullPolicy.setNullRepresentedByEmptyNode(false); nullPolicy.setMarshalNullRepresentation(XSI_NIL); nullPolicy.setNullRepresentedByXsiNil(true); itemsMapping.setNullPolicy(nullPolicy); xdesc .getNamespaceResolver() .put( SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI); // to support xsi:nil policy xdesc.addMapping(itemsMapping); } ListenerHelper listenerHelper2 = stac.peek(); if (listenerHelper2.isAttribute()) { // type built above used in field definition of object further up stack stac.pop(); AttributeFieldHelper fieldHelper = (AttributeFieldHelper) listenerHelper2; ListenerHelper listenerHelper3 = stac.peek(); if (listenerHelper3.isObject()) { ObjectTypeHelper objectTypeHelper = (ObjectTypeHelper) listenerHelper3; XMLDescriptor xdesc2 = descriptorMap.get(objectTypeHelper.objectTypename()); String fieldName = fieldHelper.attributeFieldName(); DatabaseMapping dm2 = xdesc2.getMappingForAttributeName(fieldName.toLowerCase()); if (dm2 == null) { XMLCompositeDirectCollectionMapping fieldMapping = new XMLCompositeDirectCollectionMapping(); SqltypeHelper componentType = new SqltypeHelper(sqlTypeName); fieldMapping.setAttributeElementClass( attributeClassFromDatabaseType((DefaultListenerHelper) componentType)); fieldMapping.setAttributeName(fieldName.toLowerCase()); XMLField field = new XMLField(fieldName.toLowerCase() + "/" + ITEM_MAPPING_NAME + "/text()"); field.setRequired(true); fieldMapping.setField(field); field.setSchemaType(qnameFromDatabaseType(componentType)); fieldMapping.useCollectionClassName("java.util.ArrayList"); AbstractNullPolicy nullPolicy = fieldMapping.getNullPolicy(); nullPolicy.setNullRepresentedByEmptyNode(false); nullPolicy.setMarshalNullRepresentation(XSI_NIL); nullPolicy.setNullRepresentedByXsiNil(true); fieldMapping.setNullPolicy(nullPolicy); xdesc2 .getNamespaceResolver() .put( SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI); // to support xsi:nil policy xdesc2.addMapping(fieldMapping); } // last attribute, pop ObjectTypeHelper off stack int numAttributes = objectTypeHelper.decrNumAttributes(); if (numAttributes == 0) { stac.pop(); } } } } } }
@Override public void handleObjectType(String objectTypeName, String targetTypeName, int numAttributes) { // JDBC Advanced type? if (numAttributes > 0) { // trim-off dotted-prefix, toLowerCase String objectTypeNameAlias = trimDotPrefix(objectTypeName).toLowerCase(); XMLDescriptor xdesc = descriptorMap.get(objectTypeNameAlias); String userType = nct.generateSchemaAlias(objectTypeNameAlias); if (xdesc == null) { xdesc = new XMLDescriptor(); xdesc.setAlias(objectTypeNameAlias); xdesc.setJavaClassName(packageName.toLowerCase() + "." + objectTypeNameAlias); xdesc.getQueryManager(); XMLSchemaURLReference schemaReference = new XMLSchemaURLReference(); schemaReference.setSchemaContext("/" + userType); schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE); xdesc.setSchemaReference(schemaReference); NamespaceResolver nr = new NamespaceResolver(); nr.setDefaultNamespaceURI(targetNamespace); xdesc.setNamespaceResolver(nr); descriptorMap.put(objectTypeNameAlias, xdesc); } // before we push the new ObjectTypeHelper, check stac to see if we are part // of nested chain of object types if (!stac.isEmpty()) { ListenerHelper listenerHelper = stac.peek(); if (listenerHelper.isAttribute()) { AttributeFieldHelper fieldHelper = (AttributeFieldHelper) stac.pop(); fieldHelper.setSqlTypeName(objectTypeNameAlias); String fieldName = fieldHelper.attributeFieldName(); String attributeName = fieldName.toLowerCase(); ListenerHelper listenerHelper2 = stac.peek(); if (listenerHelper2.isObject()) { ObjectTypeHelper objectTypeHelper2 = (ObjectTypeHelper) listenerHelper2; String objectTypeNameAlias2 = objectTypeHelper2.objectTypename(); XMLDescriptor xdesc2 = descriptorMap.get(objectTypeNameAlias2); if (xdesc2 != null) { DatabaseMapping dm = xdesc2.getMappingForAttributeName(attributeName); if (dm == null) { XMLCompositeObjectMapping compMapping = new XMLCompositeObjectMapping(); compMapping.setAttributeName(attributeName); compMapping.setReferenceClassName(xdesc.getJavaClassName()); compMapping.setXPath(attributeName); XMLField xField = (XMLField) compMapping.getField(); xField.setRequired(true); xdesc2.addMapping(compMapping); } // last attribute, pop ObjectTypeHelper off stack int numAttributes2 = objectTypeHelper2.decrNumAttributes(); if (numAttributes2 == 0) { stac.pop(); } } } } else if (listenerHelper.isArray()) { SqlArrayTypeHelper sqlArrayTypeHelper = (SqlArrayTypeHelper) stac.pop(); String sqlArrayTypeAlias = sqlArrayTypeHelper.arrayTypename(); XMLDescriptor xdesc2 = descriptorMap.get(sqlArrayTypeAlias); if (xdesc2 != null) { boolean itemsMappingFound = xdesc2.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME) == null ? false : true; if (!itemsMappingFound) { XMLCompositeCollectionMapping itemsMapping = new XMLCompositeCollectionMapping(); itemsMapping.setAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME); itemsMapping.setXPath(ITEM_MAPPING_NAME); itemsMapping.useCollectionClassName("java.util.ArrayList"); itemsMapping.setReferenceClassName(xdesc.getJavaClassName()); xdesc2.addMapping(itemsMapping); } } } else if (listenerHelper.isReturnArg()) { // ReturnArgHelper returnArgHelper = (ReturnArgHelper)stac.pop(); stac.pop(); xdesc.setDefaultRootElement(userType); } } stac.push(new ObjectTypeHelper(objectTypeNameAlias, targetTypeName, numAttributes)); } }