Skip to content

Commit

Permalink
Merge branch 'parser' of git.evolveum.com:/srv/git/projects/midpoint …
Browse files Browse the repository at this point in the history
…into parser
  • Loading branch information
katkav committed Mar 7, 2014
2 parents f64ccb6 + 3679784 commit ceee79c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
Expand Up @@ -31,12 +31,15 @@
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.dom.PrismDomProcessor;
import com.evolveum.midpoint.prism.parser.XNodeProcessor;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.JAXBUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.ExpressionReturnMultiplicityType;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.ExpressionType;
import com.evolveum.prism.xml.ns._public.types_2.RawType;

/**
* Utility class for manipulation of static values in expressions. This is not
Expand Down Expand Up @@ -95,26 +98,28 @@ public static <X> Collection<X> getPropertyStaticRealValues(ExpressionType expre
public static <V extends PrismValue> Item<V> parseValueElements(Collection<?> valueElements, ItemDefinition outputDefinition,
String contextDescription, PrismContext prismContext) throws SchemaException {

PrismDomProcessor domProcessor = prismContext.getPrismDomProcessor();
Item<V> output = null;
XNodeProcessor xnodeProcessor = prismContext.getXnodeProcessor();

for (Object valueElement: valueElements) {
if (!(valueElement instanceof JAXBElement<?>)) {
throw new SchemaException("Literal expression cannot handle element "+valueElement+" "+valueElement.getClass().getName()+" in "
+contextDescription);
}
QName valueElementName = JAXBUtil.getElementQName(valueElement);
if (!valueElementName.equals(SchemaConstants.C_VALUE)) {
throw new SchemaException("Literal expression cannot handle element <"+valueElementName + "> in "+ contextDescription);
}

if (valueElement instanceof JAXBElement<?>) {
valueElement = ((JAXBElement<?>)valueElement).getValue();
}

if (!(valueElement instanceof Element)) {
throw new SchemaException("Literal expression can only handle DOM elements, but got "+valueElement.getClass().getName()+" in "
JAXBElement<?> jaxbElement = (JAXBElement<?>)valueElement;
if (!RawType.class.isAssignableFrom(jaxbElement.getDeclaredType())) {
throw new SchemaException("Literal expression cannot handle JAXBElement value type "+jaxbElement.getDeclaredType()+" in "
+contextDescription);
}
Element valueDomElement = (Element)valueElement;

Item<V> elementItem = domProcessor.parseValueElement(valueDomElement, outputDefinition);
RawType rawType = (RawType)jaxbElement.getValue();

Item<V> elementItem = xnodeProcessor.parseItem(rawType.getXnode(), outputDefinition.getName(), outputDefinition);
if (output == null) {
output = elementItem;
} else {
Expand All @@ -128,11 +133,13 @@ public static <V extends PrismValue> List<?> serializeValueElements(Item<V> item
if (item == null) {
return null;
}
PrismDomProcessor domProcessor = item.getPrismContext().getPrismDomProcessor();
XNodeProcessor xnodeProcessor = item.getPrismContext().getXnodeProcessor();
List<Object> elements = new ArrayList<Object>(1);
Element valueElement = DOMUtil.createElement(DOMUtil.getDocument(), SchemaConstants.C_VALUE);
domProcessor.serializeItemToDom(item, valueElement);
elements.add(valueElement);
XNode xnode = xnodeProcessor.serializeItem(item);
RawType rawType = new RawType();
rawType.setXnode(xnode);
JAXBElement<RawType> jaxbElement = new JAXBElement<RawType>(SchemaConstants.C_VALUE, RawType.class, rawType);
elements.add(jaxbElement);
return elements;
}

Expand Down
Expand Up @@ -559,14 +559,8 @@ public <T> T unmarshallPrimitive(PrimitiveXNode<?> xprim, Class<T> classType) th
}

if (RawType.class.isAssignableFrom(classType)) {
QName typeQName = xprim.getTypeQName();
if (typeQName == null) {
typeQName = DOMUtil.XSD_STRING;
}
Object parsedValue = xprim.getParsedValue(typeQName);
RawType rawType = new RawType();
rawType.setType(typeQName);
rawType.setValue(parsedValue);
rawType.setXnode(xprim);
return (T) rawType;
}

Expand Down Expand Up @@ -840,10 +834,7 @@ private <T> PrimitiveXNode<T> createPrimitiveXNode(T value, QName fieldTypeName,
}

private XNode marshalRawValue(RawType value) {
PrimitiveXNode xprim = new PrimitiveXNode();
xprim.setTypeQName(value.getType());
xprim.setValue(value.getValue());
return xprim;
return value.getXnode();
}

private XNode marshalSearchFilterType(SearchFilterType value) {
Expand Down
Expand Up @@ -812,6 +812,11 @@ public <C extends Containerable> RootXNode serializeContainerValueRoot(PrismCont
XNodeSerializer serializer = createSerializer();
return serializer.serializeContainerValueRoot(cval);
}

public <V extends PrismValue> XNode serializeItem(Item<V> item) throws SchemaException {
XNodeSerializer serializer = createSerializer();
return serializer.serializeItem(item);
}

public XNodeSerializer createSerializer() {
return new XNodeSerializer(PrismUtil.getBeanConverter(prismContext));
Expand Down
Expand Up @@ -22,6 +22,7 @@

import org.apache.commons.collections.CollectionUtils;

import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.MiscUtil;


Expand Down Expand Up @@ -53,31 +54,21 @@
"content"
})
public class RawType implements Serializable{

private static final long serialVersionUID = 4430291958902286779L;

@XmlTransient
private Object value;
private XNode xnode;

@XmlTransient
private QName type;

@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> content;

public Object getValue() {
return value;
}

public void setValue(Object value) {
this.value = value;
}

public QName getType() {
return type;
public XNode getXnode() {
return xnode;
}

public void setType(QName type) {
this.type = type;
public void setXnode(XNode xnode) {
this.xnode = xnode;
}

/**
Expand Down Expand Up @@ -112,30 +103,36 @@ public List<Object> getContent() {
return this.content;
}

// Shallow clone. Do we need deep clone?
public RawType clone() {
RawType clone = new RawType();
clone.getContent().addAll(content);
clone.setXnode(xnode);
return clone;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof RawType)){
return false;
}

RawType other = (RawType) obj;

return MiscUtil.unorderedCollectionEquals(getContent(), other.getContent());
}

@Override
public int hashCode() {
final int prime = 31;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((xnode == null) ? 0 : xnode.hashCode());
return result;
}

}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RawType other = (RawType) obj;
if (xnode == null) {
if (other.xnode != null)
return false;
} else if (!xnode.equals(other.xnode))
return false;
return true;
}

}

0 comments on commit ceee79c

Please sign in to comment.