@Override public void handleSqlTableType(String tableTypeName, String targetTypeName) { // trim-off dotted-prefix, toLowerCase String tableTypeNameAlias = trimDotPrefix(tableTypeName).toLowerCase(); String userType = nct.generateSchemaAlias(tableTypeNameAlias); XMLDescriptor xdesc = descriptorMap.get(tableTypeNameAlias); if (xdesc == null) { xdesc = new XMLDescriptor(); xdesc.setAlias(tableTypeNameAlias); xdesc.setJavaClassName( packageName.toLowerCase() + "." + tableTypeNameAlias + COLLECTION_WRAPPER_SUFFIX); 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(tableTypeNameAlias, xdesc); } // before we push the new SqlArrayTypeHelper, check stac to see if we are part // of nested chain of object types if (!stac.isEmpty()) { ListenerHelper listenerHelper = stac.peek(); if (listenerHelper.isReturnArg()) { xdesc.setDefaultRootElement(userType); } } stac.push(new SqlArrayTypeHelper(tableTypeNameAlias, targetTypeName)); }
protected XMLDescriptor getEmployeeDescriptor() { XMLDescriptor descriptor = new XMLDescriptor(); descriptor.setJavaClass(Employee.class); // descriptor.setDefaultRootElement("employee"); XMLDirectMapping idMapping = new XMLDirectMapping(); idMapping.setXPath("id/text()"); idMapping.setAttributeName("id"); descriptor.addMapping(idMapping); XMLCompositeObjectMapping emailMapping = new XMLCompositeObjectMapping(); emailMapping.setAttributeName("emailAddress"); emailMapping.setXPath("info/email-address"); emailMapping.setGetMethodName("getEmailAddress"); emailMapping.setSetMethodName("setEmailAddress"); emailMapping.setReferenceClass(EmailAddress.class); descriptor.addMapping(emailMapping); URL schemaURL = ClassLoader.getSystemResource("org/eclipse/persistence/testing/oxm/jaxb/Employee.xsd"); XMLSchemaURLReference schemaRef = new XMLSchemaURLReference(schemaURL); schemaRef.setType(XMLSchemaURLReference.COMPLEX_TYPE); schemaRef.setSchemaContext("employee-root"); descriptor.setSchemaReference(schemaRef); /* NamespaceResolver try_test = new NamespaceResolver(); try_test.put("xsi", XMLConstants.SCHEMA_INSTANCE_URL); descriptor.setNamespaceResolver(try_test);*/ return descriptor; }
private XMLDescriptor getEmployeeDescriptor() { XMLDescriptor xmlDescriptor = new XMLDescriptor(); xmlDescriptor.setJavaClass( org.eclipse.persistence.testing.oxm.mappings.transformation.Employee.class); xmlDescriptor.setDefaultRootElement("ns:root"); XMLSchemaURLReference schemaReference = new XMLSchemaURLReference(); URL url = ClassLoader.getSystemResource(XML_SCHEMA_RESOURCE); schemaReference.setURL(url); xmlDescriptor.setSchemaReference(schemaReference); NamespaceResolver nsResolver = new NamespaceResolver(); nsResolver.put("ns", "ElemDecl/maxOccurs"); nsResolver.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); xmlDescriptor.setNamespaceResolver(nsResolver); XMLDirectMapping nameMapping = new XMLDirectMapping(); nameMapping.setAttributeName("name"); nameMapping.setXPath("ns:Local"); xmlDescriptor.addMapping(nameMapping); return xmlDescriptor; }
@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)); } }