use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDOType method addClassIndicator.
/**
* 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");
field.initialize();
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);
}
}
use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDOTypeInstanceClassTestCases method testIsInstanceNullInstanceClassWithType.
public void testIsInstanceNullInstanceClassWithType() {
SDOType type = new SDOType("http://testing", "USAddress");
type.setAbstract(false);
type.setInstanceClass(null);
SDOProperty prop = new SDOProperty(aHelperContext);
prop.setName("name");
prop.setType(SDOConstants.SDO_STRING);
prop.setContainingType(type);
type.addDeclaredProperty(prop);
SDOProperty prop2 = new SDOProperty(aHelperContext);
prop2.setName("street");
prop2.setType(SDOConstants.SDO_STRING);
prop2.setContainingType(type);
type.addDeclaredProperty(prop2);
((SDOTypeHelper) typeHelper).addType(type);
DataObject address = dataFactory.create(type);
boolean isInstance = type.isInstance(address);
assertTrue(isInstance);
}
use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDOTypeHelperDelegate method defineOpenContentProperty.
/**
* INTERNAL:
* @param propertyUri
* @param property
*/
private void defineOpenContentProperty(String propertyUri, String propertyName, Property property) {
if (propertyUri != null) {
QName propertyQName = new QName(propertyUri, propertyName);
openContentProperties.put(propertyQName, property);
boolean isElement = aHelperContext.getXSDHelper().isElement(property);
((SDOXSDHelper) aHelperContext.getXSDHelper()).addGlobalProperty(propertyQName, property, isElement);
((SDOProperty) property).setUri(propertyUri);
XMLDescriptor aDescriptor;
if (property.getType().isDataType()) {
// RICK: Types from DataObjects: isDataType() == true so:
// - find the SDOWrapperType from TypeHelper's WrappersHashMap
// - add the descriptor to XMLContext's DescriptorsByQName map
// See also: SDOTypesGenerator:addRootElementToDescriptor
SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
SDOWrapperType wrapperType = (SDOWrapperType) typeHelper.getWrappersHashMap().get(((SDOProperty) property).getType().getQName());
if (wrapperType != null) {
QName descriptorQname = new QName(propertyUri, propertyName);
((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().addDescriptorByQName(descriptorQname, wrapperType.getXmlDescriptor(((SDOProperty) property).getXsdType()));
}
return;
} else {
aDescriptor = ((SDOType) property.getType()).getXmlDescriptor();
}
// synchronized threads that access the NonSynchronizedVector tables in XMLDescriptor
if (aDescriptor != null) {
synchronized (aDescriptor) {
String rootName = propertyName;
String prefix = aDescriptor.getNonNullNamespaceResolver().resolveNamespaceURI(propertyUri);
if ((prefix == null) || prefix.equals(SDOConstants.EMPTY_STRING)) {
prefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(propertyUri);
aDescriptor.getNonNullNamespaceResolver().put(prefix, propertyUri);
}
if ((prefix != null) && !prefix.equals(SDOConstants.EMPTY_STRING)) {
rootName = prefix + ":" + rootName;
}
aDescriptor.setDefaultRootElement(rootName);
QName elementType = new QName(propertyUri, rootName);
aDescriptor.setDefaultRootElementType(elementType);
((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().storeXMLDescriptorByQName(aDescriptor);
}
}
}
}
use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDOXMLHelperDelegate method getXmlMarshaller.
@Override
public XMLMarshaller getXmlMarshaller() {
XMLMarshaller marshaller = xmlMarshallerMap.get(Thread.currentThread());
if (marshaller == null) {
marshaller = getXmlContext().createMarshaller();
marshaller.setMarshalListener(new SDOMarshalListener(marshaller, (SDOTypeHelper) aHelperContext.getTypeHelper()));
xmlMarshallerMap.put(Thread.currentThread(), marshaller);
}
XMLContext context = getXmlContext();
if (marshaller.getXMLContext() != context) {
marshaller.setXMLContext(context);
}
return marshaller;
}
use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDODataFactoryDelegate method create.
@Override
public DataObject create(Type type) {
if (type == null) {
throw new IllegalArgumentException(SDOException.cannotPerformOperationWithNullInputParameter("create", "type"));
}
SDOType sdoType = (SDOType) type;
if (sdoType.isAbstract()) {
// spec page 40
throw new IllegalArgumentException(SDOException.errorCreatingDataObjectForType(sdoType.getURI(), sdoType.getName()));
}
if (sdoType.isDataType()) {
SDOTypeHelper sth = (SDOTypeHelper) getHelperContext().getTypeHelper();
sdoType = (SDOType) sth.getWrappersHashMap().get(sdoType.getQName());
}
Class<?> implClass;
try {
implClass = sdoType.getImplClass();
if (implClass != null) {
// initialization of the properties Map Implementation will be done in the default constructor call below
// testcase is in org.apache.tuscany.sdo.test
SDODataObject theDataObject = (SDODataObject) implClass.getConstructor().newInstance();
theDataObject._setType(sdoType);
theDataObject._setHelperContext(getHelperContext());
return theDataObject;
}
} catch (ReflectiveOperationException e) {
throw new IllegalArgumentException(SDOException.errorCreatingDataObjectForClass(e, (sdoType).getInstanceClassName(), sdoType.getURI(), sdoType.getName()));
}
SDODataObject dataObject = new SDODataObject();
dataObject._setType(sdoType);
dataObject._setHelperContext(getHelperContext());
return dataObject;
}
Aggregations