Пример #1
0
 /** Get the value from the wrapped POJO, wrapping in DataObjects as necessary. */
 public Object getDeclaredProperty(int propertyIndex) {
   SDOProperty declaredProperty =
       (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
   if (declaredProperty.getType().isChangeSummaryType()) {
     return dataObject.getChangeSummary();
   }
   Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
   Object value = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
   if (declaredProperty.isMany()) {
     JAXBListWrapper listWrapper = listWrappers.get(declaredProperty);
     if (null != listWrapper) {
       return listWrapper;
     }
     listWrapper = new JAXBListWrapper(this, declaredProperty);
     listWrappers.put(declaredProperty, listWrapper);
     return listWrapper;
   } else if (null == value || declaredProperty.getType().isDataType()) {
     return value;
   } else {
     if (declaredProperty.isContainment()) {
       return jaxbHelperContext.wrap(value, declaredProperty, dataObject);
     } else {
       return jaxbHelperContext.wrap(value);
     }
   }
 }
Пример #2
0
  /**
   * Create a shallow copy of the DataObject dataObject: Creates a new DataObject copiedDataObject
   * with the same values as the source dataObject for each property where
   * property.getType().isDataType() is true. The value of such a Property property in
   * copiedDataObject is: dataObject.get(property) for single-valued Properties
   * (copiedDataObject.get(property) equals() dataObject.get(property)), or a List where each member
   * is equal to the member at the same index in dataObject for multi-valued Properties
   * copiedDataObject.getList(property).get(i) equals() dataObject.getList(property).get(i) The
   * copied Object is unset for each Property where property.getType().isDataType() is false since
   * they are not copied. Read-only properties are copied. A copied object shares metadata with the
   * source object sourceDO.getType() == copiedDO.getType() If a ChangeSummary is part of the source
   * DataObject the copy has a new, empty ChangeSummary. Logging state is the same as the source
   * ChangeSummary.
   *
   * @param dataObject to be copied
   * @return copy of dataObject
   */
  public DataObject copyShallow(DataObject dataObject) {
    if (null == dataObject) {
      return null;
    }
    SDODataObject copy =
        (SDODataObject)
            getHelperContext()
                .getDataFactory()
                .create(dataObject.getType().getURI(), dataObject.getType().getName());

    List ocListOriginal = ((SDODataObject) dataObject)._getOpenContentProperties();
    for (Iterator anOCIterator = ocListOriginal.iterator(); anOCIterator.hasNext(); ) {
      copy.addOpenContentProperty((Property) anOCIterator.next());
    }

    List ocAttrsListOriginal = ((SDODataObject) dataObject)._getOpenContentPropertiesAttributes();
    for (Iterator anOCAttrIterator = ocAttrsListOriginal.iterator(); anOCAttrIterator.hasNext(); ) {
      copy.addOpenContentProperty((Property) anOCAttrIterator.next());
    }

    List allProperties = copy.getInstanceProperties(); // start iterating all copy's properties
    Iterator iterProperties = allProperties.iterator();
    while (iterProperties.hasNext()) {
      SDOProperty eachProperty = (SDOProperty) iterProperties.next();
      if (dataObject.isSet(eachProperty)) {
        Object o = getValue((SDODataObject) dataObject, eachProperty, null);
        if (eachProperty.getType().isDataType()) {
          if (!eachProperty.getType().isChangeSummaryType()) {
            // we defer sequence updates at this point
            copy.setInternal(eachProperty, o, false); // make copy if current property is datatype
          }
        }
      }
    }

    if (dataObject.getType().isSequenced()) {
      List settings = ((SDOSequence) dataObject.getSequence()).getSettings();
      for (int index = 0, size = dataObject.getSequence().size(); index < size; index++) {
        Setting nextSetting = (Setting) settings.get(index);

        Property prop = dataObject.getSequence().getProperty(index);
        if (prop == null || ((SDOType) prop.getType()).isDataType()) {
          Setting copySetting = nextSetting.copy(copy);
          copy.getSequence().getSettings().add(copySetting);
          copy.getSequence().addValueToSettings(copySetting);
        }
      }
    }

    if ((copy != null)
        && (copy.getChangeSummary() != null)
        && (copy.getType().getChangeSummaryProperty() != null)) {
      if (((SDODataObject) dataObject).getChangeSummary().isLogging()) {
        copy.getChangeSummary().setLogging(true);
      }
    }

    return copy;
  }
 private void validateType(SDOType type) {
   assertNotNull(type);
   List<SDOProperty> properties = type.getProperties();
   for (SDOProperty nextProp : properties) {
     assertNotNull(nextProp);
     assertNotNull(nextProp.getType());
   }
 }
  // 20. purpose: getBigInteger with Defined integer Property
  public void testGetIntegerConversionFromDefinedIntegerProperty() {
    // dataObject's type add int property
    SDOProperty property = ((SDOProperty) type.getProperty(PROPERTY_NAME));
    property.setType(SDOConstants.SDO_INTEGER);

    BigInteger bi = new BigInteger("12");
    dataObject.setBigInteger(property, bi); // add it to instance list

    this.assertEquals(bi, dataObject.getBigInteger(property));
  }
 // 17. purpose: getBigDecimal with bytes property
 public void testGetDecimalFromBytes() {
   SDOProperty property = (SDOProperty) dataObject.getInstanceProperty(PROPERTY_NAME);
   property.setType(SDOConstants.SDO_BYTES);
   dataObject.set(property, new String("abcd").getBytes());
   try {
     dataObject.getBigDecimal(property);
     fail("ClassCastException should be thrown.");
   } catch (ClassCastException e) {
   }
 }
 // 3. purpose: getBigInteger with character property
 public void testGetIntegerFromCharacter() {
   SDOProperty property = (SDOProperty) dataObject.getInstanceProperty(PROPERTY_NAME);
   property.setType(SDOConstants.SDO_CHARACTER);
   dataObject.set(property, 'd');
   try {
     dataObject.getBigInteger(property);
     fail("ClassCastException should be thrown.");
   } catch (ClassCastException e) {
   }
 }
 // 1. purpose: getBigInteger with boolean property
 public void testGetIntegerFromBoolean() {
   SDOProperty property = (SDOProperty) dataObject.getInstanceProperty(PROPERTY_NAME);
   property.setType(SDOConstants.SDO_BOOLEAN);
   dataObject.set(property, true);
   try {
     BigInteger bigIntegerValue = dataObject.getBigInteger(property);
     assertEquals(1, bigIntegerValue);
   } catch (ClassCastException e) {
   }
 }
Пример #8
0
  /** Set the value on the underlying POJO, unwrapping values as necessary. */
  public void setDeclaredProperty(int propertyIndex, Object value) {
    SDOProperty declaredProperty =
        (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    if (declaredProperty.getType().isChangeSummaryType()) {
      return;
    }

    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);

    Object newValue = value;
    Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);

    if (declaredProperty.getType().isDataType()) {
      if (!declaredProperty.isMany()) {
        AbstractSession session =
            ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
        XMLDirectMapping directMapping = (XMLDirectMapping) mapping;
        if (directMapping.hasConverter()) {
          newValue = directMapping.getConverter().convertDataValueToObjectValue(newValue, session);
        } else {
          CoreField field = mapping.getField();
          newValue =
              session
                  .getDatasourcePlatform()
                  .getConversionManager()
                  .convertObject(
                      newValue,
                      descriptor.getObjectBuilder().getFieldClassification((XMLField) field));
        }
      }
      mapping.setAttributeValueInObject(entity, newValue);
    } else if (declaredProperty.isMany()) {
      // Get a ListWrapper and set it's current elements
      ListWrapper listWrapper = (ListWrapper) getDeclaredProperty(propertyIndex);
      listWrapper.addAll((List) newValue);
    } else {
      // OLD VALUE
      if (mapping.isAbstractCompositeObjectMapping()) {
        XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
        if (oldValue != null && compositeMapping.getContainerAccessor() != null) {
          compositeMapping.getContainerAccessor().setAttributeValueInObject(oldValue, null);
        }
      }

      // NEW VALUE
      newValue = jaxbHelperContext.unwrap((DataObject) value);
      mapping.getAttributeAccessor().setAttributeValueInObject(entity, newValue);
      if (mapping.isAbstractCompositeObjectMapping()) {
        XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
        if (value != null && compositeMapping.getContainerAccessor() != null) {
          compositeMapping.getContainerAccessor().setAttributeValueInObject(newValue, entity);
        }
      }
    }
  }
  // 9. purpose: getBigInteger with Defined int Property
  public void testGetIntegerConversionFromDefinedIntProperty() {
    // dataObject's type add int property
    SDOProperty property = ((SDOProperty) type.getProperty(PROPERTY_NAME));
    property.setType(SDOConstants.SDO_INT);

    int in = 12;
    BigInteger bd = new BigInteger(String.valueOf(in));
    dataObject.setInt(property, in); // add it to instance list

    this.assertEquals(bd, dataObject.getBigInteger(property));
  }
  // 6. purpose: getBigInteger with Undefined Double Property
  public void testGetIntegerConversionFromUnDefinedDoubleProperty() {
    SDOProperty property = new SDOProperty(aHelperContext);
    property.setName(PROPERTY_NAME);
    property.setType(SDOConstants.SDO_DOUBLE);

    try {
      dataObject.getBigInteger(property);
      fail("IllegalArgumentException should be thrown.");
    } catch (IllegalArgumentException e) {
    }
  }
  // 22. purpose: getBigInteger with date property
  public void testGetIntegerFromDate() {
    SDOProperty property = (SDOProperty) dataObject.getInstanceProperty(PROPERTY_NAME);
    property.setType(SDOConstants.SDO_DATE);

    dataObject.set(property, Calendar.getInstance().getTime());
    try {
      dataObject.getBigInteger(property);
      fail("ClassCastException should be thrown.");
    } catch (ClassCastException e) {
    }
  }
  // 11. purpose: getBigInteger with Defined long Property
  public void testGetIntegerConversionFromDefinedLongProperty() {
    // dataObject's type add short property
    SDOProperty property = ((SDOProperty) type.getProperty(PROPERTY_NAME));
    property.setType(SDOConstants.SDO_LONG);

    long lg = 12;
    BigInteger bd = new BigInteger(String.valueOf(lg));
    dataObject.setLong(property, lg); // add it to instance list

    this.assertEquals(bd, dataObject.getBigInteger(property));
  }
  // 14. purpose: getBigInteger with Defined String Property
  public void testGetgetIntegerConversionFromDefinedStringProperty() {
    // dataObject's type add int property
    SDOProperty property = ((SDOProperty) type.getProperty(PROPERTY_NAME));
    property.setType(SDOConstants.SDO_STRING);

    String str = "12";
    BigInteger bd = new BigInteger(str);
    dataObject.setString(property, str); // add it to instance list

    this.assertEquals(bd, dataObject.getBigInteger(property));
  }
  // 5. purpose: getBigInteger with Defined Double Property
  public void testGetIntegerConversionFromDefinedDoubleProperty() {
    // dataObject's type add boolean property
    SDOProperty property = ((SDOProperty) type.getProperty(PROPERTY_NAME));
    property.setType(SDOConstants.SDO_DOUBLE);

    double db = 12;
    int il = (int) db;
    BigInteger bd = new BigInteger(String.valueOf(il));
    dataObject.setDouble(property, db); // add it to instance list

    this.assertEquals(bd, dataObject.getBigInteger(property));
  }
  public void
      testGetBooleanConversionWithPathFromDefinedBooleanPropertyEqualSignBracketInPathDotSet() {
    SDOProperty prop = (SDOProperty) dataObject_c0.getType().getProperty("test");
    prop.setType(SDOConstants.SDO_INT);
    Integer bb = new Integer(12);

    // List b = new ArrayList();
    // dataObject_c.set(property_c, b);// c dataobject's a property has value boolean 'true'
    dataObject_a.setInt(propertyTest + "test", bb.intValue());

    this.assertEquals(bb.intValue(), dataObject_a.getInt(propertyTest + "test"));
  }
  // 18. purpose: getBigInteger with Defined Decimal Property
  public void testGetIntegerConversionFromDefinedDecimalProperty() {
    // dataObject's type add int property
    SDOProperty property = ((SDOProperty) type.getProperty(PROPERTY_NAME));
    property.setType(SDOConstants.SDO_DECIMAL);

    int db = 12;
    BigDecimal bd = new BigDecimal(db);
    BigInteger bd_ = new BigInteger(String.valueOf(bd));
    dataObject.setBigDecimal(property, bd); // add it to instance list

    this.assertEquals(bd_, dataObject.getBigInteger(property));
  }
  // 16. purpose: getBigInteger with Defined Bytes Property !! OX Pro    !!
  public void testGetIntegerConversionFromDefinedBytesProperty() {
    // dataObject's type add boolean property
    SDOProperty property = ((SDOProperty) type.getProperty(PROPERTY_NAME));
    property.setType(SDOConstants.SDO_BYTES);

    byte[] b = {12, 13};
    BigInteger bin = new BigInteger(b);

    dataObject.setBytes(property, b); // add it to instance list

    this.assertEquals(bin, dataObject.getBigInteger(property));
  }
  // 7. purpose: getBigInteger with Defined float Property
  public void testGetIntegerConversionFromDefinedFloatProperty() {
    // dataObject's type add float property
    SDOProperty property = ((SDOProperty) type.getProperty(PROPERTY_NAME));
    property.setType(SDOConstants.SDO_FLOAT);

    float fl = 12;
    int il = (int) fl;
    BigInteger bd = new BigInteger(String.valueOf(il));
    dataObject.setFloat(property, fl); // add it to instance list

    this.assertEquals(bd, dataObject.getBigInteger(property));
  }
  // 2. purpose: getBigInteger with byte property
  public void testGetIntegerFromByte() {
    SDOProperty property = (SDOProperty) dataObject.getInstanceProperty(PROPERTY_NAME);
    property.setType(SDOConstants.SDO_BYTE);

    byte theByte = 10;
    dataObject.set(property, theByte);
    try {
      BigInteger value = dataObject.getBigInteger(property);
      BigInteger control = new BigInteger("10");
      assertEquals(control, value);
      // TODO: conversion not supported by sdo spec but is supported by TopLink
    } catch (ClassCastException e) {
    }
  }
  // purpose: detach a dataobject from one tree and set it to another tree, see changesummary doc.
  // issue number 9
  public void testIsModifiedMoveDataObjectFromOneTreeToAnother() {
    changeSummary.beginLogging();

    SDOType changeSummaryType =
        (SDOType) typeHelper.getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY);
    SDOType dataObjectType =
        (SDOType) typeHelper.getType(SDOConstants.SDO_URL, SDOConstants.DATAOBJECT);

    SDODataObject o; // = new SDODataObject();
    SDOType ty = new SDOType("newTypeUri", "newType");
    ty.setOpen(true);
    SDOProperty p = new SDOProperty(aHelperContext);
    p.setName("new Property");
    p.setContainment(true);
    p.setType(dataObjectType);
    ty.addDeclaredProperty(p);
    SDOProperty p1 = new SDOProperty(aHelperContext);
    p1.setName("new Property ChangeSummary");
    p1.setContainment(false);
    p1.setType(changeSummaryType);
    ty.addDeclaredProperty(p1);

    o = (SDODataObject) dataFactory.create(ty);
    o.getChangeSummary().beginLogging();

    containedDataObject.detach();
    assertDetached(containedDataObject, changeSummary, true); // container and cs will not be set

    o.set(p, containedDataObject);

    assertCreated(containedDataObject, o.getChangeSummary());
    assertModified(o, o.getChangeSummary());
    assertDetached(containedDataObject, changeSummary, false); // container and cs will be set
    assertModified(root, changeSummary);
  }
 // 13. purpose: getBigInteger with Undefined short Property
 public void testGetIntegerConversionFromUnDefinedShortProperty() {
   ((SDOType) dataObject.getType()).setOpen(true);
   SDOProperty property = new SDOProperty(aHelperContext);
   property.setName(PROPERTY_NAME);
   property.setType(SDOConstants.SDO_SHORT);
   short shortValue = 2;
   dataObject.set(property, shortValue);
   try {
     BigInteger value = dataObject.getBigInteger(property);
     BigInteger controlValue = new BigInteger("2");
     assertEquals(controlValue, value);
     // TODO: conversion not supported by sdo spec but is supported by TopLink
   } catch (ClassCastException e) {
   }
 }
  // purpose: after logging, dataobject create dataobject
  public void testIsModifiedFactory() {
    changeSummary.beginLogging();
    SDODataObject o; // = new SDODataObject();
    SDOType ty = new SDOType("newTypeUri", "newType");
    ty.setOpen(true);
    SDOProperty p = new SDOProperty(aHelperContext);
    p.setName("new Property");
    p.setContainment(false);
    p.setType(SDOConstants.SDO_STRING);
    ty.addDeclaredProperty(p);

    o = (SDODataObject) root.createDataObject(rootProperty, ty);

    assertCreated(o, changeSummary);
  }
Пример #23
0
  /**
   * INTERNAL: Recursive function deep copies all contained properties. Requirements: The value
   * object has isSet=true for all callers.
   *
   * @param copy
   * @param property
   * @param value
   * @param doMap (cache original -> copy DataObject instances to set non-containment properties
   *     after tree construction)
   * @param propMap (cache original DO:non-containment property values to be set after tree
   *     construction)
   */
  private void copyContainmentPropertyValue(
      SDODataObject copy,
      SDOProperty property,
      Object value, //
      HashMap doMap,
      HashMap ncPropMap,
      SDOChangeSummary cs) {
    if (property.isMany()) {
      List copyValue = new ArrayList();

      // set the copy to an empty list and add each items from the original in sequence
      // updateSequence flag is false - we will populate the sequence in order after subtree
      // creation
      copy.setInternal(property, copyValue, false);
      for (Iterator iterValues = ((List) value).iterator(); iterValues.hasNext(); ) {
        SDODataObject o = (SDODataObject) iterValues.next();
        SDODataObject copyO = copyPrivate(o, doMap, ncPropMap, cs);
        ((ListWrapper) copy.getList(property)).add(copyO, false);
        // set changeSummary on all cs-root elements in the list after they are added to the
        // containment tree
        if ((copyO != null)
            && (copyO.getChangeSummary() != null)
            && (copyO.getType().getChangeSummaryProperty() != null)) {
          // re-reference copy objects in the copy changeSummary
          if (o.getChangeSummary().isLogging()) {
            (copyO.getChangeSummary()).setLogging(true);
          }
          copyChangeSummary(
              o.getChangeSummary(), //
              copyO.getChangeSummary(),
              doMap);
        }
      }
    } else { // handle non-many case
      // implementers of this function will always pass in a DataObject that may be null
      SDODataObject copyO = copyPrivate((SDODataObject) value, doMap, ncPropMap, cs);

      //  #5852525 handle null properties with isSet=true - fixed 20070130
      // we will set the isSet index in the ValueStore to true for all isSet=true objects, even NULL
      // ones.
      // updateSequence flag is false - we will populate the sequence in order after subtree
      // creation
      copy.setInternal(property, copyO, false);

      // set changeSummary on all cs-root elements in the list after they are added to the
      // containment tree using the original logging value
      if ((copyO != null)
          && (copyO.getChangeSummary() != null)
          && (copyO.getType().getChangeSummaryProperty() != null)) {
        // re-reference copy objects in the copy changeSummary
        if (((SDODataObject) value).getChangeSummary().isLogging()) {
          copyO.getChangeSummary().setLogging(true);
        }
        copyChangeSummary(
            ((SDODataObject) value).getChangeSummary(), //
            copyO.getChangeSummary(),
            doMap);
      }
    }
  }
  // purpose: opencontent properties
  public void testGetIntConversionFromDefinedPropertyWithPath() {
    SDOProperty property_c1_object = ((SDOProperty) dataObject_c1.getInstanceProperty("PName-c1"));
    property_c1_object.setType(SDOConstants.SDO_INT);

    // type_c0.addDeclaredProperty(property_c1_object);
    List objects = new ArrayList();
    Integer b = new Integer(12);
    Integer bb = new Integer(2);
    objects.add(b);
    objects.add(bb);

    dataObject_c1.set(property_c1_object, objects); // add it to instance list

    this.assertEquals(
        bb.intValue(), dataObject_a.getInt("PName-a0/PName-b0[number='1']/PName-c1.1"));
  }
  public void testSetGetDataObjectWithQueryPath() {
    SDOProperty property_c1_object = new SDOProperty(aHelperContext);
    property_c1_object.setName("PName-c1");
    property_c1_object.setContainment(true);
    property_c1_object.setMany(true);
    property_c1_object.setType(SDOConstants.SDO_INT);

    type_c0.addDeclaredProperty(property_c1_object);

    Integer b = new Integer(12);

    dataObject_a.setInt("PName-a0/PName-b0[number='1']/PName-c1.0", b.intValue());

    this.assertEquals(
        b.intValue(), dataObject_a.getInt("PName-a0/PName-b0[number='1']/PName-c1.0"));
  }
Пример #26
0
  /**
   * For isMany=false properties set the value to null. For isMany=true set the value to an empty
   * container of the appropriate type.
   */
  public void unsetDeclaredProperty(int propertyIndex) {
    SDOProperty declaredProperty =
        (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
    if (declaredProperty.isMany()) {
      ContainerMapping containerMapping = (ContainerMapping) mapping;
      ContainerPolicy containerPolicy = containerMapping.getContainerPolicy();

      // OLD VALUE
      if (mapping.isAbstractCompositeCollectionMapping()) {
        XMLCompositeCollectionMapping compositeMapping = (XMLCompositeCollectionMapping) mapping;
        if (compositeMapping.getContainerAccessor() != null) {

          Object oldContainer = mapping.getAttributeValueFromObject(entity);
          if (oldContainer != null) {
            AbstractSession session =
                ((JAXBContext) jaxbHelperContext.getJAXBContext())
                    .getXMLContext()
                    .getSession(entity);
            Object iterator = containerPolicy.iteratorFor(oldContainer);
            while (containerPolicy.hasNext(iterator)) {
              Object oldValue = containerPolicy.next(iterator, session);
              compositeMapping.getContainerAccessor().setAttributeValueInObject(oldValue, null);
            }
          }
        }
      }

      // NEW VALUE
      Object container = containerPolicy.containerInstance();
      mapping.getAttributeAccessor().setAttributeValueInObject(entity, container);
    } else {
      // OLD VALUE
      Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
      if (mapping.isAbstractCompositeObjectMapping()) {
        XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
        if (compositeMapping.getContainerAccessor() != null) {
          if (oldValue != null) {
            compositeMapping.getContainerAccessor().setAttributeValueInObject(oldValue, null);
          }
        }
      }

      // NEW VALUE
      mapping.getAttributeAccessor().setAttributeValueInObject(entity, null);
    }
  }
 /**
  * INTERNAL:
  *
  * @param qname
  * @param prop
  * @param isElement Register the given property with the given qname.
  */
 public void addGlobalProperty(QName qname, Property prop, boolean isElement) {
   ((SDOProperty) prop).setUri(qname.getNamespaceURI());
   if (isElement) {
     getGlobalElements().put(qname, prop);
   } else {
     getGlobalAttributes().put(qname, prop);
   }
 }
Пример #28
0
 /**
  * For isMany=false properties return true if not null. For collection properties return true if
  * the collection is not empty.
  */
 public boolean isSetDeclaredProperty(int propertyIndex) {
   SDOProperty declaredProperty =
       (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
   if (declaredProperty.getType().isChangeSummaryType()) {
     return true;
   }
   Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
   if (declaredProperty.isMany()) {
     Collection collection =
         (Collection) mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
     if (null == collection) {
       return false;
     }
     return !collection.isEmpty();
   } else {
     return null != mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
   }
 }
  public void testAddDeclaredPropertyToRoot() {
    child3SDOType.addBaseType(child2SDOType);
    child2SDOType.addBaseType(child1SDOType);
    child1SDOType.addBaseType(rootSDOType);

    SDOProperty testProp = new SDOProperty(aHelperContext);
    testProp.setName("tester");
    rootSDOType.addDeclaredProperty(testProp, 1);
    assertEquals(4, rootSDOType.getDeclaredProperties().size());
    assertEquals(4, rootSDOType.getProperties().size());
    assertEquals(3, child1SDOType.getDeclaredProperties().size());
    assertEquals(7, child1SDOType.getProperties().size());
    assertEquals(3, child2SDOType.getDeclaredProperties().size());
    assertEquals(10, child2SDOType.getProperties().size());
    assertEquals(3, child3SDOType.getDeclaredProperties().size());
    assertEquals(13, child3SDOType.getProperties().size());

    assertEquals(1, testProp.getIndexInType());
  }
Пример #30
0
  public ValueStore copy() {
    AbstractSession session =
        ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
    Object originalEntity = entity;
    entity = descriptor.getInstantiationPolicy().buildNewInstance();

    for (SDOProperty sdoProperty : (List<SDOProperty>) dataObject.getType().getProperties()) {
      if (!sdoProperty.getType().isChangeSummaryType()) {
        Mapping mapping = getJAXBMappingForProperty(sdoProperty);
        CoreAttributeAccessor attributeAccessor = mapping.getAttributeAccessor();
        Object attributeValue = attributeAccessor.getAttributeValueFromObject(originalEntity);
        if (mapping.isCollectionMapping()) {
          Object containerCopy = null;
          SDOChangeSummary sdoChangeSummary = dataObject.getChangeSummary();
          if (null != sdoChangeSummary) {
            List list = listWrappers.get(sdoProperty);
            containerCopy = sdoChangeSummary.getOriginalElements().get(list);
          }
          if (null == containerCopy) {
            CoreContainerPolicy containerPolicy = mapping.getContainerPolicy();
            containerCopy = containerPolicy.containerInstance();
            if (null != attributeValue) {
              Object attributeValueIterator = containerPolicy.iteratorFor(attributeValue);
              while (containerPolicy.hasNext(attributeValueIterator)) {
                containerPolicy.addInto(
                    containerPolicy.nextEntry(attributeValueIterator), containerCopy, session);
              }
            }
          }
          attributeAccessor.setAttributeValueInObject(entity, containerCopy);
        } else {
          attributeAccessor.setAttributeValueInObject(entity, attributeValue);
        }
      }
    }
    return new JAXBValueStore(
        jaxbHelperContext, originalEntity, descriptor, dataObject, listWrappers);
  }