* @return unwrapped value
*/
@SuppressWarnings("deprecation")
protected Object unwrapComposite(CompositeValue compositeValue, TypeInfo typeInfo)
{
CompositeMetaType compositeMetaType = compositeValue.getMetaType();
String typeName = compositeMetaType.getTypeName();
ClassLoader cl;
if (typeInfo != null)
cl = typeInfo.getType().getClassLoader();
else
cl = Thread.currentThread().getContextClassLoader();
try
{
BeanInfo beanInfo = configuration.getBeanInfo(typeName, cl);
ClassInfo classInfo = beanInfo.getClassInfo();
Class<?> clazz = classInfo.getType();
if (classInfo.isInterface())
{
// Handle map specially
if (clazz.isAssignableFrom(Map.class))
return unwrapCompositeMap(compositeValue);
InvocationHandler handler = createCompositeValueInvocationHandler(compositeValue);
Class<?>[] interfaces = new Class[]{clazz};
return Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, handler);
}
else if(clazz.isAssignableFrom(ObjectName.class))
{
// TODO: this should be handled more generically
MetaValue domain = compositeValue.get("domain");
String domainUnwrap = (String) unwrap(domain, String.class);
MetaValue keys = compositeValue.get("keyPropertyList");
Hashtable keysUnwrap = null;
if(keys instanceof PropertiesMetaValue)
keysUnwrap = (PropertiesMetaValue) keys;
ObjectName name = new ObjectName(domainUnwrap, keysUnwrap);
return name;
}
Object bean = createNewInstance(beanInfo);
for (String name : compositeMetaType.itemSet())
{
MetaValue itemValue = compositeValue.get(name);
PropertyInfo propertyInfo = beanInfo.getProperty(name);
Object value = unwrap(itemValue, propertyInfo.getType());
propertyInfo.set(bean, value);