private void updateNullPolicyForAttribute(Project aProject, String attributeName) {

    AbstractNullPolicy aNullPolicy = new NullPolicy();
    // Alter unmarshal policy state
    ((NullPolicy) aNullPolicy).setSetPerformedForAbsentNode(true); // no effect
    aNullPolicy.setNullRepresentedByEmptyNode(true); // no effect
    aNullPolicy.setNullRepresentedByXsiNil(false); // no effect
    //  Alter marshal policy state
    aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
    XMLDirectMapping aMapping =
        (XMLDirectMapping)
            aProject
                .getDescriptor(Employee.class) //
                .getMappingForAttributeName(attributeName);
    aMapping.setNullPolicy(aNullPolicy);
  }
  public DirectOptionalNodeNullPolicyAttributeTestCases(String name) throws Exception {
    super(name);
    setControlDocument(XML_RESOURCE);

    AbstractNullPolicy aNullPolicy = new NullPolicy();
    // alter unmarshal policy state
    aNullPolicy.setNullRepresentedByEmptyNode(false);
    aNullPolicy.setNullRepresentedByXsiNil(false);
    // alter marshal policy state
    aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.ABSENT_NODE);

    Project aProject = new DirectNodeNullPolicyProject(false);
    XMLDirectMapping aMapping =
        (XMLDirectMapping)
            aProject
                .getDescriptor(Employee.class) //
                .getMappingForAttributeName("firstName");
    aMapping.setNullPolicy(aNullPolicy);
    setProject(aProject);
  }
  public DirectIsSetNullPolicyElementSetEmptyFalseTestCases(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.EMPTY_NODE); // no effect when isset=false
    ((IsSetNullPolicy) aNullPolicy).setIsSetMethodName("isSetFirstName");
    Project aProject = new DirectNodeNullPolicyProject(true);
    XMLDirectMapping aMapping =
        (XMLDirectMapping)
            aProject
                .getDescriptor(Employee.class) //
                .getMappingForAttributeName("firstName");
    aMapping.setNullPolicy(aNullPolicy);
    setProject(aProject);
  }
  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);
  }
コード例 #5
0
 @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();
           }
         }
       }
     }
   }
 }