Search in sources :

Example 16 with SDOTypeHelper

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);
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 17 with SDOTypeHelper

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);
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) DataObject(commonj.sdo.DataObject) SDOType(org.eclipse.persistence.sdo.SDOType) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 18 with SDOTypeHelper

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);
            }
        }
    }
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) QName(javax.xml.namespace.QName) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 19 with SDOTypeHelper

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;
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) XMLContext(org.eclipse.persistence.oxm.XMLContext) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener)

Example 20 with SDOTypeHelper

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;
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) SDOType(org.eclipse.persistence.sdo.SDOType) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Aggregations

SDOTypeHelper (org.eclipse.persistence.sdo.helper.SDOTypeHelper)31 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)17 SDOType (org.eclipse.persistence.sdo.SDOType)17 DataObject (commonj.sdo.DataObject)13 Type (commonj.sdo.Type)9 ArrayList (java.util.ArrayList)9 List (java.util.List)7 QName (javax.xml.namespace.QName)3 SequencedObject (org.eclipse.persistence.oxm.sequenced.SequencedObject)3 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)3 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)3 Collection (java.util.Collection)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)2 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)2 XMLField (org.eclipse.persistence.oxm.XMLField)2 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)2 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)2 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)2 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)2