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;
}
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;
}
}
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;
}
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();
}
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());
}
Aggregations