use of org.eclipse.persistence.sdo.SDOType in project eclipselink by eclipse-ee4j.
the class SDOTypeHelperDelegate method define.
/**
* Define the DataObject as a Type.
* The Type is available through TypeHelper and DataGraph getType() methods.
* @param dataObject the DataObject representing the Type.
* @return the defined Type.
* @throws IllegalArgumentException if the Type could not be defined.
*/
public synchronized Type define(DataObject dataObject, List types) {
SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
if ((dataObject == null) || (dataObject.getType() == null) || (!dataObject.getType().getURI().equals(SDOConstants.SDO_URL)) || (!dataObject.getType().getName().equals(SDOConstants.TYPE))) {
throw new IllegalArgumentException(SDOException.errorDefiningType());
}
String uri = dataObject.getString("uri");
String name = dataObject.getString("name");
if (name == null) {
throw new IllegalArgumentException(SDOException.errorDefiningTypeNoName());
}
SDOType type = (SDOType) typeHelper.getType(uri, name);
if (null != type) {
return type;
}
if (isXmlNameValidationEnabled && !SDOUtil.isValidXmlNCName(name)) {
throw new IllegalArgumentException(SDOException.errorDefiningTypeInvalidName(name));
}
boolean isDataType = dataObject.getBoolean("dataType");
if (isDataType) {
type = new SDODataType(uri, name, this);
} else {
type = new SDOType(uri, name, this);
if (dataObject.getBoolean("sequenced")) {
type.setSequenced(true);
type.setMixed(true);
}
}
type.setDataType(isDataType);
addType(type);
types.add(type);
type.setAppInfoElements((List) dataObject.get(SDOConstants.APPINFO));
type.setAbstract(dataObject.getBoolean("abstract"));
List baseTypes = dataObject.getList("baseType");
for (int i = 0; i < baseTypes.size(); i++) {
SDOType baseType = (SDOType) getValueFromObject(baseTypes.get(i), types);
type.addBaseType(baseType);
}
List aliasNames = dataObject.getList("aliasName");
for (int i = 0; i < aliasNames.size(); i++) {
Object aliasName = aliasNames.get(i);
type.getAliasNames().add(aliasName);
}
List openProps = ((SDODataObject) dataObject)._getOpenContentProperties();
for (int i = 0; i < openProps.size(); i++) {
SDOProperty nextProp = (SDOProperty) openProps.get(i);
Object value = getValueFromObject(dataObject.get(nextProp), types);
type.setInstanceProperty(nextProp, value);
}
List openPropsAttrs = ((SDODataObject) dataObject)._getOpenContentPropertiesAttributes();
for (int i = 0; i < openPropsAttrs.size(); i++) {
SDOProperty nextProp = (SDOProperty) openPropsAttrs.get(i);
Object value = getValueFromObject(dataObject.get(nextProp), types);
type.setInstanceProperty(nextProp, value);
}
if (!type.isDataType()) {
type.preInitialize(null, null);
}
List properties = dataObject.getList("property");
for (int i = 0; i < properties.size(); i++) {
Object nextValue = properties.get(i);
if (nextValue instanceof DataObject) {
buildPropertyFromDataObject((DataObject) nextValue, type, types);
}
}
type.setOpen(dataObject.getBoolean("open"));
if (type.isDataType()) {
QName typeQName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, name);
if (typeHelper.getWrappersHashMap().get(typeQName) != null) {
// wrappers created, so do not continue on building a new WrapperType.
return type;
}
// Defining a new simple type from a DataObject.
// See also: SDOTypesGenerator:startNewSimpleType for "types from XSD" equivalent
// If this simple type is a restriction, get the QName for the base type and
// include it when creating the WrapperType. The QName will be used during
// conversions (eg. "myBinaryElement" could be a restriction of base64Binary
// or hexBinary.
QName currentTypeQName = null;
if (type.isSubType()) {
SDOType baseType = (SDOType) type.getBaseTypes().get(0);
currentTypeQName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, baseType.getName());
}
// Create the new WrapperType
SDOWrapperType wrapperType = new SDOWrapperType(type, name, this, currentTypeQName);
// Register WrapperType with maps on TypeHelper
typeHelper.getWrappersHashMap().put(typeQName, wrapperType);
typeHelper.getTypesHashMap().put(typeQName, wrapperType);
typeHelper.getImplClassesToSDOType().put(wrapperType.getXmlDescriptor().getJavaClass(), wrapperType);
// Add descriptor to XMLHelper
ArrayList list = new ArrayList(1);
list.add(wrapperType);
((SDOXMLHelper) aHelperContext.getXMLHelper()).addDescriptors(list);
}
return type;
}
use of org.eclipse.persistence.sdo.SDOType in project eclipselink by eclipse-ee4j.
the class TypeStringConverter method convertObjectValueToDataValue.
@Override
public Object convertObjectValueToDataValue(Object object, Session session) {
if (!(object instanceof SDOType)) {
return null;
}
SDOType type = (SDOType) object;
String typeString = type.getURI() + "#" + type.getName();
return typeString;
}
use of org.eclipse.persistence.sdo.SDOType in project eclipselink by eclipse-ee4j.
the class SDOEqualityHelperTest method testDeepEqualWithTwoDataObjectsHavingManyTypePropertiesDataObjectsFailListSizeUnequal.
// compare DataObject with properties as many
public void testDeepEqualWithTwoDataObjectsHavingManyTypePropertiesDataObjectsFailListSizeUnequal() {
// rootProperty4.setContainment(false);
// SDOType rootProperty4_type = new SDOType("", "");
// rootProperty4.setType(SDOConstants.SDO_STRING);
SDOType mockType = new SDOType("uri", "name");
SDOProperty p = new SDOProperty(aHelperContext);
p.setContainment(false);
p.setMany(false);
p.setName("fortest");
p.setType(SDOConstants.SDO_STRING);
mockType.addDeclaredProperty(p);
DataObject d1 = dataFactory.create(mockType);
DataObject d2 = dataFactory.create(mockType);
DataObject d3 = dataFactory.create(mockType);
DataObject d4 = dataFactory.create(mockType);
objects.add(d1);
objects.add(d3);
// objects1.add(d4);
objects1.add(d2);
// d4.set(p, "fail");
rootProperty4.setMany(true);
root.set(rootProperty4, objects);
root1.set(rootProperty4, objects1);
assertFalse(equalityHelper.equal(root, root1));
}
use of org.eclipse.persistence.sdo.SDOType in project eclipselink by eclipse-ee4j.
the class SDOEqualityHelperTest method testDeepEqualWithADataObjectToAnotherOpenContentPropertiesNotDataTypeBoth.
// purpose: one has open content datatype property while another doesn't
public void testDeepEqualWithADataObjectToAnotherOpenContentPropertiesNotDataTypeBoth() {
SDOProperty openP = new SDOProperty(aHelperContext);
openP.setName("open");
openP.setContainment(true);
openP.setMany(false);
openP.setType(new SDOType("", ""));
containedType.setOpen(true);
SDOType mockType = new SDOType("uri", "name");
DataObject d1 = dataFactory.create(mockType);
DataObject d2 = dataFactory.create(mockType);
containedDataObject.set(openP, d1);
containedDataObject_1.set(openP, d2);
assertTrue(equalityHelper.equal(root, root1));
}
use of org.eclipse.persistence.sdo.SDOType in project eclipselink by eclipse-ee4j.
the class SDOHelperContextTest method testMultipleInstancesOfContexts.
public void testMultipleInstancesOfContexts() {
SDOProperty property1 = aNonStaticHelperContext1DataObject.getInstanceProperty("address");
SDOProperty property2 = aNonStaticHelperContext2DataObject.getInstanceProperty("address");
SDOProperty property3 = aStaticHelperContextDataObject.getInstanceProperty("address");
SDOType type1 = aNonStaticHelperContext1DataObject.getInstanceProperty("address").getType();
SDOType type2 = aNonStaticHelperContext2DataObject.getInstanceProperty("address").getType();
SDOType type3 = aStaticHelperContextDataObject.getInstanceProperty("address").getType();
// verify types do not xref
assertNotSame(type1, type2);
assertNotSame(type1, type3);
assertNotSame(type2, type3);
// modify types in one context
assertFalse(property1.isMany());
assertFalse(property2.isMany());
assertFalse(property3.isMany());
// change one type from bounded to unbounded
property1.setMany(true);
// verify modified types do not affect other context
assertTrue(property1.isMany());
assertFalse(property2.isMany());
assertFalse(property3.isMany());
}
Aggregations