Skip to content

Commit

Permalink
some other test fixes..
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Mar 3, 2014
1 parent 5978a7b commit 21b7f2f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public <T> T unmarshall(MapXNode xnode, Class<T> beanClass) throws SchemaExcepti
if (field == null) {
propertyGetter = findPropertyGetter(beanClass, propName);
}


Method elementMethod = null;
Object objectFactory = null;
if (field == null && propertyGetter == null) {
Expand Down Expand Up @@ -143,6 +145,7 @@ public <T> T unmarshall(MapXNode xnode, Class<T> beanClass) throws SchemaExcepti
}
Type genericReturnType = getter.getGenericReturnType();
Type typeArgument = getTypeArgument(genericReturnType, "for field "+fieldName+" in "+beanClass+", cannot determine collection type");
// System.out.println("type argument " + typeArgument);
if (typeArgument instanceof Class) {
paramType = (Class<?>) typeArgument;
} else if (typeArgument instanceof ParameterizedType) {
Expand Down Expand Up @@ -302,7 +305,7 @@ private Method findElementMethodInObjectFactory(Object objectFactory, String pro
if (propName.equals(xmlElementDecl.name())) {
return method;
}
}
}
return null;
}

Expand Down Expand Up @@ -722,8 +725,9 @@ private <T> XNode marshallValue(T value, QName fieldTypeName, boolean isAttribut
return marshalItemPath((ItemPathType) value);
} else if (value instanceof QueryType){
return marshalQueryType((QueryType) value);
} else

} else if (value instanceof RawType){
return marshalRawValue((RawType) value);
} else
if (canConvert(value.getClass())) {
// This must be a bean
return marshall(value);
Expand All @@ -740,6 +744,13 @@ private <T> XNode marshallValue(T value, QName fieldTypeName, boolean isAttribut
}
}

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

private XNode marshalQueryType(QueryType value) {
MapXNode queryNode = new MapXNode();
XNode description = marshallValue(value.getDescription(), DOMUtil.XSD_STRING, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static <T> T toJavaValue(String stringContent, Class<T> type, boolean exc


public static Object toJavaValue(Element xmlElement, QName type) throws SchemaException {
return toJavaValue(xmlElement, XsdTypeMapper.toJavaType(type));
return toJavaValue(xmlElement, XsdTypeMapper.getXsdToJavaMapping(type));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.math.BigInteger;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.xml.XMLConstants;
import javax.xml.datatype.Duration;
Expand All @@ -35,6 +37,7 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.prism.xml.ns._public.types_2.ItemPathType;
Expand Down Expand Up @@ -123,6 +126,16 @@ public static QName getJavaToXsdMapping(Class<?> type) {
}

public static <T> Class<T> getXsdToJavaMapping(QName xsdType) {
Class clazz = xsdToJavaTypeMap.get(xsdType);
if (clazz == null){
Set<QName> keys = xsdToJavaTypeMap.keySet();
for (Iterator<QName> iterator = keys.iterator(); iterator.hasNext();){
QName key = iterator.next();
if (QNameUtil.match(key, xsdType)){
return xsdToJavaTypeMap.get(key);
}
}
}
return xsdToJavaTypeMap.get(xsdType);
}

Expand Down
8 changes: 6 additions & 2 deletions infra/schema/src/test/resources/common/resource-opendj.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ This is now the only account type that midPoint can work with. -->
<strength>weak</strength>
<expression>
<description>Expression that assigns a fixed value</description>
<!-- <value>Created by IDM</value> -->
<value>Created by IDM</value>
</expression>
</outbound>
<!-- No inbound expression for description. We don't want to synchronize that -->
Expand Down Expand Up @@ -519,7 +519,7 @@ This is now the only account type that midPoint can work with. -->
<expression>
<variable xmlns:my="http://whatever.com/my">
<name>my:defaultLocation</name>
<!-- <value xsi:type="xsd:string">middle of nowhere</value> -->
<value xsi:type="xsd:string">middle of nowhere</value>
</variable>
<script>
<description>XPath expression that is using a variable declared above</description>
Expand Down Expand Up @@ -560,6 +560,10 @@ This is now the only account type that midPoint can work with. -->
</inbound>
</administrativeStatus>
</activation>

<protected>
<icfs:name>uid=idm,ou=Administrators,dc=example,dc=com</icfs:name>
</protected>
</accountType>
</schemaHandling>

Expand Down

0 comments on commit 21b7f2f

Please sign in to comment.