Search in sources :

Example 16 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class XPathHelper method processComplexQuery.

/**
 * Evaluate the query represented by the XPath Expression fragment against
 * the DataObject. A complex query contains logical operators.
 *
 * @param dataObject
 * @param reference
 * @param bracketContents
 * @return
 */
private Object processComplexQuery(DataObject dataObject, String reference, String bracketContents) {
    // convert the expression to postfix notation
    OPStack opStack = new OPStack();
    List expressionParts = opStack.processExpression(bracketContents);
    ArrayList queryParts = new ArrayList();
    // position of any 'and' / 'or'
    for (int i = 0; i < expressionParts.size(); i++) {
        Token tok = (Token) expressionParts.get(i);
        if (tok.getName().equals(AND_STR) || tok.getName().equals(OR_STR)) {
            queryParts.add(tok.getName());
        } else {
            // assume next three entries make up a query part
            String propertyName = ((Token) expressionParts.get(i)).getName();
            String queryValue = ((Token) expressionParts.get(++i)).getName();
            int operator = getOperandFromString(((Token) expressionParts.get(++i)).getName());
            queryParts.add(new QueryPart(propertyName.trim(), queryValue, operator));
        }
    }
    // get the DataObject(s) to execute the query against
    Property prop = dataObject.getInstanceProperty(reference);
    List objects;
    if (prop.isMany()) {
        objects = dataObject.getList(prop);
    } else {
        objects = new ArrayList();
        DataObject obj = dataObject.getDataObject(prop);
        if (obj != null) {
            objects.add(obj);
        }
    }
    List valuesToReturn = new ArrayList();
    Iterator iterObjects = objects.iterator();
    while (iterObjects.hasNext()) {
        SDODataObject cur = (SDODataObject) iterObjects.next();
        // this iteration, evaluate each QueryPart against the current DataObject
        ArrayList booleanValues = new ArrayList();
        for (int j = 0; j < queryParts.size(); j++) {
            if (queryParts.get(j).equals(AND_STR) || queryParts.get(j).equals(OR_STR)) {
                // add 'and'/'or' keeping in correct order
                booleanValues.add(queryParts.get(j));
            } else {
                // assume QueryPart - evaluate and add the result
                QueryPart qp = (QueryPart) queryParts.get(j);
                booleanValues.add(qp.evaluate(cur));
            }
        }
        // single result is achieved
        for (int k = 0; k < booleanValues.size(); k++) {
            if (booleanValues.get(k).equals(AND_STR) || booleanValues.get(k).equals(OR_STR)) {
                if (k >= 2) {
                    Boolean b1 = (Boolean) booleanValues.get(k - 1);
                    Boolean b2 = (Boolean) booleanValues.get(k - 2);
                    int logicalOp = getOperandFromString((String) booleanValues.get(k));
                    booleanValues.remove(k);
                    booleanValues.remove(k - 1);
                    booleanValues.set(k - 2, evaluate(b1, b2, logicalOp));
                    k = 0;
                }
            }
        }
        // if there isn't a single result something went wrong...
        if (booleanValues.size() == 1) {
            if ((Boolean) booleanValues.get(0)) {
                valuesToReturn.add(cur);
            }
        }
    }
    return valuesToReturn;
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 17 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class XPathHelper method processFragment.

/**
 * Process an XPath expression fragment.
 *
 * @param xpFrag
 * @param dataObject
 * @return
 */
private Object processFragment(String xpFrag, DataObject dataObject) {
    // handle self expression
    if (xpFrag.equals(".")) {
        return dataObject;
    }
    // handle containing DataObject expression
    if (xpFrag.equals("..")) {
        return dataObject.getContainer();
    }
    // ignore '@'
    xpFrag = getPathWithAtRemoved(xpFrag);
    // handle positional '[]' expression
    int idx = xpFrag.indexOf('[');
    if (idx > -1) {
        return processBracket(xpFrag, dataObject, idx);
    }
    // handle non-positional expression
    Property prop = dataObject.getInstanceProperty(xpFrag);
    try {
        return dataObject.get(prop);
    } catch (IllegalArgumentException e) {
        return null;
    }
}
Also used : SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property)

Example 18 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class JAXBHelperContext method getType.

/**
 * Return the SDO type corresponding to the wrapped class.
 * <pre>
 * Type customerType = jaxbHelperContext.getType(Customer.class);
 * DataObject customerDO = jaxbHelperContext.getDataFactory().create(customerType);
 * </pre>
 */
public Type getType(Class<?> entityClass) {
    if (null == entityClass) {
        return null;
    }
    XMLDescriptor entityDescriptor = null;
    try {
        entityDescriptor = (XMLDescriptor) jaxbContext.getXMLContext().getSession(entityClass).getDescriptor(entityClass);
    } catch (Exception e) {
        return null;
    }
    XMLSchemaReference schemaReference = entityDescriptor.getSchemaReference();
    if (null == schemaReference) {
        throw SDOException.sdoJaxbNoSchemaReference(entityClass);
    }
    QName qName = schemaReference.getSchemaContextAsQName(entityDescriptor.getNamespaceResolver());
    if (null == qName) {
        throw SDOException.sdoJaxbNoSchemaContext(entityClass);
    }
    Type wrapperType;
    if (entityDescriptor.getSchemaReference().getType() == XMLSchemaReference.COMPLEX_TYPE) {
        wrapperType = getTypeHelper().getType(qName.getNamespaceURI(), qName.getLocalPart());
    } else {
        Property property = getXSDHelper().getGlobalProperty(qName.getNamespaceURI(), qName.getLocalPart(), true);
        wrapperType = property.getType();
    }
    if (null == wrapperType) {
        throw SDOException.sdoJaxbNoTypeForClassBySchemaContext(entityClass, qName);
    }
    return wrapperType;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) Type(commonj.sdo.Type) SDOType(org.eclipse.persistence.sdo.SDOType) XMLSchemaReference(org.eclipse.persistence.oxm.schema.XMLSchemaReference) QName(javax.xml.namespace.QName) Property(commonj.sdo.Property) SDOException(org.eclipse.persistence.exceptions.SDOException)

Example 19 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class SDOResolvableTestCases method dataObjectToString.

/**
 * Write an object representation of the SDODataObject to the stream
 * @return
 * String
 */
private String dataObjectToString(DataObject anObject) {
    if (anObject == null) {
        return SDOConstants.EMPTY_STRING;
    }
    StringBuffer aBuffer = new StringBuffer();
    aBuffer.append(anObject.toString());
    aBuffer.append("\n\t root: ");
    aBuffer.append(anObject.getRootObject());
    aBuffer.append("\n\t type: ");
    aBuffer.append(anObject.getType());
    aBuffer.append(" name: ");
    aBuffer.append(anObject.getType().getName());
    aBuffer.append("\n\t properties: (");
    // iterate any properties
    List properties = anObject.getInstanceProperties();
    if (!properties.isEmpty()) {
        List keys = anObject.getInstanceProperties();
        Iterator anIterator = keys.iterator();
        while (anIterator.hasNext()) {
            Property aKey = (Property) anIterator.next();
            aBuffer.append(aKey.getName());
            aBuffer.append(":");
            aBuffer.append(anObject.get(aKey));
            aBuffer.append(",\n\t\t");
        }
    }
    aBuffer.append(")");
    return aBuffer.toString();
}
Also used : Iterator(java.util.Iterator) List(java.util.List) Property(commonj.sdo.Property)

Example 20 with Property

use of commonj.sdo.Property in project eclipselink by eclipse-ee4j.

the class ChangeSummaryTestCases method testDataTypeManyPropertyWasNotSetXML.

public void testDataTypeManyPropertyWasNotSetXML() throws IOException {
    Type rootType = jaxbHelperContext.getType(Root.class);
    Property controlDataTypeManyProperty = rootType.getProperty(CONTROL_DATATYPE_MANY_PROPERTY);
    InputStream xml = Thread.currentThread().getContextClassLoader().getResourceAsStream(XML_DATA_TYPE_MANY_PROPERTY_WAS_NOT_SET);
    DataObject rootDO = jaxbHelperContext.getXMLHelper().load(xml).getRootObject();
    assertEquals(1, rootDO.getList(controlDataTypeManyProperty).size());
    assertEquals(CONTROL_DATATYPE_MANY_PROPERTY_NEW_VALUE, rootDO.getList(controlDataTypeManyProperty).get(0));
    ChangeSummary.Setting setting = rootDO.getChangeSummary().getOldValue(rootDO, controlDataTypeManyProperty);
    List testOldValue = (List) setting.getValue();
    assertEquals(0, testOldValue.size());
    assertEquals(false, setting.isSet());
}
Also used : Type(commonj.sdo.Type) DataObject(commonj.sdo.DataObject) InputStream(java.io.InputStream) List(java.util.List) ChangeSummary(commonj.sdo.ChangeSummary) Property(commonj.sdo.Property)

Aggregations

Property (commonj.sdo.Property)354 DataObject (commonj.sdo.DataObject)204 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)194 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)124 List (java.util.List)99 Type (commonj.sdo.Type)87 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)76 ArrayList (java.util.ArrayList)73 ChangeSummary (commonj.sdo.ChangeSummary)56 SDOType (org.eclipse.persistence.sdo.SDOType)54 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)47 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)37 SDOException (org.eclipse.persistence.exceptions.SDOException)35 Iterator (java.util.Iterator)24 QName (javax.xml.namespace.QName)12 InputStream (java.io.InputStream)11 SDOSetting (org.eclipse.persistence.sdo.SDOSetting)11 Map (java.util.Map)5 XMLDocument (commonj.sdo.helper.XMLDocument)4 SequencedObject (org.eclipse.persistence.oxm.sequenced.SequencedObject)4