当前位置: 首页>>代码示例>>Java>>正文


Java Mirror.me方法代码示例

本文整理汇总了Java中org.nutz.lang.Mirror.me方法的典型用法代码示例。如果您正苦于以下问题:Java Mirror.me方法的具体用法?Java Mirror.me怎么用?Java Mirror.me使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.nutz.lang.Mirror的用法示例。


在下文中一共展示了Mirror.me方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inject

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
Object inject(Object model, Type type) {
    if (model == null) {
        return null;
    }
    Mirror<?> me = Mirror.me(type);
    Object obj = null;
    if (Collection.class.isAssignableFrom(me.getType())) {
        obj = injectCollection(model, me);
    } else if (Map.class.isAssignableFrom(me.getType())) {
        obj = injectMap(model, me);
    } else if (me.getType().isArray()) {
        obj = injectArray(model, me);
    } else {
        obj = injectObj(model, me);
    }
    if (path.size() > 0)
        path.pop();
    return obj;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:20,代码来源:ObjConvertImpl.java

示例2: find

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <F, T> Castor<F, T> find(Mirror<F> from, Class<T> toType) {
    String key = Castor.key(from.getType(), toType);
    // 哈,这种类型以前转过,直接返回转换器就行了
    if (map.containsKey(key)) {
        return (Castor<F, T>) map.get(key);
    }

    Mirror<T> to = Mirror.me(toType, extractor);
    Class<?>[] fets = from.extractTypes();
    Class<?>[] tets = to.extractTypes();
    for (Class<?> ft : fets) {
        for (Class<?> tt : tets) {
            if (map.containsKey(Castor.key(ft, tt))) {
                Castor<F, T> castor = (Castor<F, T>) map.get(Castor.key(ft,
                                                                        tt));
                // 缓存转换器,加速下回转换速度
                map.put(key, castor);
                return castor;
            }
        }
    }
    return null;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:25,代码来源:Castors.java

示例3: calculate

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
public Object calculate() {
    //如果直接调用计算方法,那基本上就是直接调用属性了吧...我也不知道^^
    Object obj = fetchVar();
    if (obj == null) {
        throw new ElException("obj is NULL, can't call obj." + right);
    }
    if(obj instanceof Map){
        Map<?,?> om = (Map<?, ?>) obj;
        if(om.containsKey(right.toString())){
            return om.get(right.toString());
        }
    }
    if (obj instanceof Context) {
        Context sc = (Context) obj;
        if (sc.has(right.toString())) {
            return sc.get(right.toString());
        }
    }
    
    Mirror<?> me = Mirror.me(obj);
    return me.getValue(obj, right.toString());
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:23,代码来源:AccessOpt.java

示例4: pojo2Json

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
private Map<String, Object> pojo2Json(Object obj, Map<String, Object> map) {
    if (null == obj)
        return null;
    Class<? extends Object> type = obj.getClass();
    JsonEntity jen = Json.getEntity(Mirror.me(type));
    List<JsonEntityField> fields = jen.getFields();
    ArrayList<Pair> list = new ArrayList<Pair>(fields.size());
    for (JsonEntityField jef : fields) {
        String name = jef.getName();
        try {
            Object value = jef.getValue(obj);
            if (null != value) {
                // 递归
                Mirror<?> mirror = Mirror.me(value);
                if (mirror.isPojo()) {
                    value = parse(value);
                }
            }
            // 加入输出列表 ...
            list.add(new Pair(name, value));
        }
        catch (FailToGetValueException e) {}
    }
    return writeItem(list, map);
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:26,代码来源:ObjCompileImpl.java

示例5: buildDataSource

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
/**
 * 构建DataSource,子类可覆盖. 如果存在Druid,则使用之,否则使用内置的SimpleDataSource
 * @param props 配置信息
 * @return 目标DataSource
 */
protected DataSource buildDataSource(Properties props) {
    if (druidFactoryClass != null) {
        log.debug("build DruidDataSource by props");
        Mirror<?> mirror = Mirror.me(druidFactoryClass);
        DataSource ds = (DataSource) mirror.invoke(null, "createDataSource", props);
        if (!props.containsKey("maxWait"))
            Mirror.me(ds).setValue(ds, "maxWait", 15*1000);
        return ds;
    }
    log.debug("build SimpleteDataSource by props");
    return SimpleDataSource.createDataSource(props);
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:18,代码来源:DaoUp.java

示例6: _createTableInfo

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
/**
 * 向父类递归查找实体的配置
 * 
 * @param type
 *            实体类型
 * @return 实体表描述
 */
private TableInfo _createTableInfo(Class<?> type) {
    TableInfo info = new TableInfo();
    Mirror<?> mirror = Mirror.me(type);
    info.annTable = mirror.getAnnotation(Table.class);
    info.annView = mirror.getAnnotation(View.class);
    info.annMeta = mirror.getAnnotation(TableMeta.class);
    info.annPK = mirror.getAnnotation(PK.class);
    info.annIndexes = mirror.getAnnotation(TableIndexes.class);
    info.tableComment = mirror.getAnnotation(Comment.class);
    return info;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:19,代码来源:AnnotationEntityMaker.java

示例7: toObject

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
public <T> T toObject(Class<T> classOfT) {
    Mirror<T> mirror = Mirror.me(classOfT);
    T re = mirror.born();
    Entry current = head;
    while (current != null) {
        mirror.setValue(re, current.name, current.value);
        current = current.next;
    }
    return re;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:11,代码来源:Chain.java

示例8: cast

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
@Override
public Number cast(Enum src, Class<?> toType, String... args)
        throws FailToCastObjectException {
    Mirror<?> mi = Mirror.me(src);

    // 首先尝试调用枚举对象的 value() 方法
    try {
        return (Number) mi.invoke(src, "value");
    }
    // 如果失败,就用其顺序号
    catch (Exception e) {
        Integer re = src.ordinal();
        return (Number) Mirror.me(toType).born(re.toString());
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:16,代码来源:Enum2Number.java

示例9: EntityService

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
/**
 * 本抽象类能提供一些帮助方法,减少重复写实体类型的麻烦
 */
@SuppressWarnings("unchecked")
public EntityService() {
    try {
        Class<T> entryClass = (Class<T>) Mirror.getTypeParam(getClass(), 0);
        mirror = Mirror.me(entryClass);
        if (log.isDebugEnabled())
            log.debugf("Get TypeParams for self : %s", entryClass.getName());
    }
    catch (Throwable e) {
        if (log.isWarnEnabled())
            log.warn("!!!Fail to get TypeParams for self!", e);
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:17,代码来源:EntityService.java

示例10: configure

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static final <T> T configure(T t, Object obj) {
	if (t == null)
		return t;
	if (obj == null)
		return t;
	Map<String, Object> map = null;
	if (obj instanceof Map) {
		map = (Map<String, Object>)obj;
	} else {
		map = asConfigureMap(obj);
	}
	Mirror mirror = Mirror.me(t);
	Mirror m2 = Mirror.me(obj);
	for(Field field : mirror.getFields()) {
		Object value = null;
		if (map != null)
			value = map.get(field.getName());
		else {
			try {
				value = m2.getValue(obj, field.getName());
			} catch (FailToGetValueException e) {
				// skip;
			}
		}
		if (value != null) {
			mirror.setValue(t, field.getName(), value);
		}
	}
	return t;
}
 
开发者ID:nutzam,项目名称:nutzwx,代码行数:32,代码来源:BeanConfigures.java

示例11: mapField

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static void mapField(StringBuilder sb, Class<?> klass, Field field) {
    sb.append("\r\n");
    String fieldName = field.getName();
    String className = klass.getSimpleName();
    Mirror mirror = Mirror.me(field.getType());
    String getterTmpl = "return (${fieldType})get(\"${fieldName}\")";
    if (mirror.isPrimitiveNumber()) {
        if (mirror.isBoolean()) {
            getterTmpl = "return getBoolean(\"${fieldName}\", false)";
        } else {
            getterTmpl = "return get"
                         + Strings.upperFirst(mirror.getType().getSimpleName())
                         + "(\"${fieldName}\", 0)";
        }
    }

    Tmpl tmpl = Tmpl.parse("    public ${className} set${upperFieldName}(${fieldType} ${fieldName}){\r\n"
                           + "        put(\"${fieldName}\", ${fieldName});\r\n"
                           + "        return this;\r\n"
                           + "    }\r\n"
                           + "\r\n"
                           + "    public ${fieldType} get${upperFieldName}(){\r\n"
                           + "        "
                           + getterTmpl
                           + ";\r\n"
                           + "    }\r\n");
    NutMap ctx = new NutMap().setv("className", className).setv("fieldName", fieldName);
    ctx.setv("upperFieldName", Strings.upperFirst(fieldName));
    ctx.setv("fieldType", field.getType().getSimpleName());
    sb.append(tmpl.render(ctx));
}
 
开发者ID:nutzam,项目名称:nutzwx,代码行数:33,代码来源:Wxs.java

示例12: getFieldTypeMirror

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
public Mirror<?> getFieldTypeMirror() {
    return Mirror.me(getFieldTypeClass());
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:4,代码来源:MappingInfo.java

示例13: setType

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
public void setType(Type type) {
    this.type = type;
    this.typeClass = Lang.getTypeClass(type);
    this.mirror = Mirror.me(typeClass);
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:6,代码来源:AbstractEntityField.java

示例14: makeEntity

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
public <T extends Map<String, ?>> Entity<T> makeEntity(String tableName, T map) {
    final NutEntity<T> en = new NutEntity(map.getClass());
    en.setTableName(tableName);
    en.setViewName(tableName);
    for (Entry<String, ?> entry : map.entrySet()) {
        String key = entry.getKey();
        // 是实体补充描述吗?
        if (key.startsWith("#")) {
            en.getMetas().put(key.substring(1), entry.getValue().toString());
            continue;
        }
        // 以 "." 开头的字段,不是实体字段
        else if (key.startsWith(".")) {
            continue;
        }

        // 是实体字段
        Object value = entry.getValue();
        Mirror<?> mirror = Mirror.me(value);
        NutMappingField ef = new NutMappingField(en);

        if (key.startsWith("+")) {
            ef.setAsAutoIncreasement();
            key = key.substring(1);
        }
        if (key.startsWith("!")) {
            ef.setAsNotNull();
            key = key.substring(1);
        }
        if (key.startsWith("*")) {
            key = key.substring(1);
            if (mirror != null && mirror.isIntLike())
                ef.setAsId();
            else
                ef.setAsName();
        }
        ef.setName(key);

        ef.setType(null == value ? Object.class : value.getClass());
        ef.setColumnName(key);

        // 猜测一下数据库类型
        Jdbcs.guessEntityFieldColumnType(ef);
        ef.setAdaptor(support.expert.getAdaptor(ef));
        if (mirror != null)
            ef.setType(mirror.getType());
        ef.setInjecting(new InjectToMap(key));
        ef.setEjecting(new EjectFromMap(key));

        en.addMappingField(ef);
    }
    en.checkCompositeFields(null);

    // 最后在数据库中验证一下实体各个字段
    support.run(new ConnCallback() {
        public void invoke(Connection conn) throws Exception {
            support.expert.setupEntityField(conn, en);
        }
    });

    // 搞定返回
    return en;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:65,代码来源:EntityHolder.java

示例15: eval

import org.nutz.lang.Mirror; //导入方法依赖的package包/类
public static JsonEntityField eval(Mirror<?> mirror, Field fld) {
    if (fld == null) {
        return null;
    }

    // 以特殊字符开头的字段,看起来是隐藏字段
    // XXX 有用户就是_开头的字段也要啊! by wendal
    // if (fld.getName().startsWith("_") || fld.getName().startsWith("$"))
    if (fld.getName().startsWith("$")
        && fld.getAnnotation(JsonField.class) == null)
        return null;

    JsonField jf = fld.getAnnotation(JsonField.class);

    JsonEntityField jef = new JsonEntityField();
    jef.genericType = Lang.getFieldType(mirror, fld);
    jef.name = Strings.sBlank(null == jf ? null : jf.value(), fld.getName());
    jef.ejecting = mirror.getEjecting(fld.getName());
    jef.injecting = mirror.getInjecting(fld.getName());

    // 瞬时变量和明确声明忽略的,变 ignore
    if (Modifier.isTransient(fld.getModifiers())
        || (null != jf && jf.ignore())) {
        jef.setIgnore(true);
    }


    // 判断字段是否被强制输出为字符串
    if (null != jf) {
        jef.setForceString(jf.forceString());
        if (!Strings.isBlank(jf.dateFormat())) {
            jef.dateFormat = new SimpleDateFormat(jf.dateFormat());
        }
    }
    
    JsonIgnore jsonIgnore = fld.getAnnotation(JsonIgnore.class);
    if (jsonIgnore != null) {
        Mirror<?> fldMirror = Mirror.me(fld.getType());
        jef.isInt = fldMirror.isInt();
        jef.isDouble = fldMirror.isDouble() || fldMirror.isFloat();
    	jef.hasJsonIgnore = true;
        if (jef.isDouble)
        	jef.ignoreNullDouble = jsonIgnore.null_double();
        if (jef.isInt)
        	jef.ignoreNullInt = jsonIgnore.null_int();
    }
    
    return jef;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:50,代码来源:JsonEntityField.java


注:本文中的org.nutz.lang.Mirror.me方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。