org.nutz.ioc.impl.DefaultValueProxyMaker Maven / Gradle / Ivy
package org.nutz.ioc.impl;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Map;
import org.nutz.ioc.IocException;
import org.nutz.ioc.IocMaking;
import org.nutz.ioc.ValueProxy;
import org.nutz.ioc.ValueProxyMaker;
import org.nutz.ioc.meta.IocObject;
import org.nutz.ioc.meta.IocValue;
import org.nutz.ioc.val.*;
import org.nutz.lang.Lang;
public class DefaultValueProxyMaker implements ValueProxyMaker {
@SuppressWarnings("unchecked")
public ValueProxy make(IocMaking ing, IocValue iv) {
Object value = iv.getValue();
String type = iv.getType();
// Null
if ("null".equals(type) || null == value) {
return new StaticValue(null);
}
if (value instanceof ValueProxy) {
return (ValueProxy)value;
}
// String, Number, .....
else if ("normal".equals(type) || null == type) {
// Array
if (value.getClass().isArray()) {
Object[] vs = (Object[]) value;
IocValue[] tmp = new IocValue[vs.length];
for (int i = 0; i < tmp.length; i++)
tmp[i] = (IocValue) vs[i];
return new ArrayValue(ing, tmp);
}
// Map
else if (value instanceof Map, ?>) {
return new MapValue(ing,
(Map) value,
(Class extends Map>) value.getClass());
}
// Collection
else if (value instanceof Collection>) {
return new CollectionValue( ing,
(Collection) value,
(Class extends Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy