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


Java Mirror类代码示例

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


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

示例1: create

import org.nutz.lang.Mirror; //导入依赖的package包/类
private static <T extends FieldInfo> T create(Class<T> classOfT, final Method method) {
    final T info = Mirror.me(classOfT).born();
    Mirror.evalGetterSetter(method, ERR_MSG, new Callback3<String, Method, Method>() {
        public void invoke(String name, Method getter, Method setter) {
            // 木有 getter
            if (null == getter) {
                throw Lang.makeThrow(    "Method '%s'(%s) has '@Column', but NO setter!",
                                        method.getName(),
                                        method.getDeclaringClass().getName());
            }
            // 木有 setter
            if (null == setter) {
                throw Lang.makeThrow(    "Method '%s'(%s) has '@Column', but NO setter!",
                                        method.getName(),
                                        method.getDeclaringClass().getName());
            }
            // 正常,开始设值
            info.name = name;
            info.fieldType = getter.getGenericReturnType();
            info.ejecting = new EjectByGetter(getter);
            info.injecting = new InjectBySetter(setter);
        }
    });
    return info;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:26,代码来源:_Infos.java

示例2: createMappingInfo

import org.nutz.lang.Mirror; //导入依赖的package包/类
/**
 * 根据 Java 字段创建一个实体字段信息对象
 * 
 * @param pk
 *            复合主键
 * @param field
 *            Java 字段
 * @return 字段信息对象
 */
public static MappingInfo createMappingInfo(PK pk, Field field) {
    MappingInfo info = create(MappingInfo.class, field);
    info.annPK = pk;
    info.annColumn = field.getAnnotation(Column.class);
    info.annDefine = field.getAnnotation(ColDefine.class);
    info.annDefault = field.getAnnotation(Default.class);
    info.annId = field.getAnnotation(Id.class);
    info.annName = field.getAnnotation(Name.class);
    info.annNext = field.getAnnotation(Next.class);
    info.annPrev = field.getAnnotation(Prev.class);
    info.annReadonly = field.getAnnotation(Readonly.class);
    info.columnComment = field.getAnnotation(Comment.class);
    
    //检查@Id和@Name的属性类型
    if (info.annId != null) {
        if (!Mirror.me(field.getType()).isIntLike())
            throw Lang.makeThrow(DaoException.class, "Field(%s) annotation @Id , but not Number type!!", field);
    }
    
    if (info.annName != null)
        if (!Mirror.me(field.getType()).isStringLike())
            throw Lang.makeThrow(DaoException.class, "Field(%s) annotation @Name , but not String type!!", field);
    
    return info;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:35,代码来源:_Infos.java

示例3: toJson

import org.nutz.lang.Mirror; //导入依赖的package包/类
/**
 * 将一个 JAVA 对象以 JSON 的形式写到一个文本输出流里,并且可以设定 JSON 字符串的格式化方式
 * 
 * @param writer
 *            文本输出流
 * @param obj
 *            JAVA 对象
 * @param format
 *            JSON 字符串格式化方式 ,若 format 为 null ,则以 JsonFormat.nice() 格式输出
 */
public static void toJson(Writer writer, Object obj, JsonFormat format) {
    try {
        if (format == null)
            format = JsonFormat.nice();

        Class<? extends JsonRender> jrCls = getJsonRenderCls();
        if (jrCls == null)
            jrCls = JsonRenderImpl.class;

        JsonRender jr = Mirror.me(jrCls).born();
        jr.setWriter(writer);
        jr.setFormat(format);
        jr.render(obj);

        writer.flush();
    }
    catch (IOException e) {
        throw Lang.wrapThrow(e, JsonException.class);
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:31,代码来源:Json.java

示例4: 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

示例5: Castor

import org.nutz.lang.Mirror; //导入依赖的package包/类
protected Castor() {
    Class<?> myType = getClass();
    Class<?> mySuper = myType.getSuperclass();

    Type[] myParams = Mirror.getTypeParams(myType);
    Type[] superParams = Mirror.getTypeParams(mySuper);

    if (null != superParams && superParams.length == 2) {
        Class<?>[] args = new Class<?>[2];
        int n = 0;
        for (int i = 0; i < superParams.length; i++) {
            if (superParams[i] instanceof Class<?>)
                args[i] = (Class<?>) superParams[i];
            else
                args[i] = (Class<?>) myParams[n++];
        }
        fromClass = args[0];
        toClass = args[1];
    } else {
        fromClass = (Class<?>) myParams[0];
        toClass = (Class<?>) myParams[1];
    }

}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:25,代码来源:Castor.java

示例6: _begain

import org.nutz.lang.Mirror; //导入依赖的package包/类
static void _begain(int level) throws Exception {
    Transaction tn = trans.get();
    if (null == tn) {
        tn = null == implClass ? new NutTransaction() : Mirror.me(implClass).born();
        tn.setLevel(level);
        trans.set(tn);
        count.set(0);
        if (DEBUG)
            log.debugf("Start New Transaction id=%d, level=%d", tn.getId(), level);
    } else {
        if (DEBUG)
            log.debugf("Attach Transaction    id=%d, level=%d", tn.getId(), level);
    }
    int tCount = count.get() + 1;
    count.set(tCount);
    //if (DEBUG)
    //    log.debugf("trans_begain: %d", tCount);

}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:20,代码来源:Trans.java

示例7: compare

import org.nutz.lang.Mirror; //导入依赖的package包/类
public static int compare(Class<?>[] mps1, Class<?>[] mps2) {
    if (mps1.length > mps2.length)
        return 1;
    if (mps1.length < mps2.length)
        return -1;
    for (int i = 0; i < mps1.length; i++) {
        if (mps1[i] == mps2[i])
            continue;
        if (mps1[i].isPrimitive() && (!mps2[i].isPrimitive()))
            return -1;
        else if (mps2[i].isPrimitive() && (!mps1[i].isPrimitive()))
            return 1;
        if (mps1[i].isPrimitive() || mps2[i].isPrimitive())
            if (Mirror.me(mps1[i]).getWrapper() == Mirror.me(mps2[i])
                                                         .getWrapper()) {
                if (mps1[i].isPrimitive())
                    return -1;
                else
                    return 1;
            }
        if (mps2[i].isAssignableFrom(mps1[i]))
            return 1;
    }
    return 0;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:26,代码来源:FastClassFactory.java

示例8: EnumRandom

import org.nutz.lang.Mirror; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected EnumRandom() {
    try {
        Class<T> type = (Class<T>) Mirror.getTypeParams(this.getClass())[0];
        Field[] fields = type.getFields();
        List<T> list = new ArrayList<T>(fields.length);
        for (Field f : fields) {
            if (f.getType() == type) {
                list.add((T) f.get(null));
            }
        }
        T[] ens = (T[]) Array.newInstance(type, list.size());
        this.r = new RecurArrayRandom<T>(list.toArray(ens));
    }
    catch (Exception e) {
        throw Lang.wrapThrow(e);
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:19,代码来源:EnumRandom.java

示例9: 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

示例10: 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

示例11: 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

示例12: convert

import org.nutz.lang.Mirror; //导入依赖的package包/类
public Object convert(Object obj) {
    StringBuilder sb = new StringBuilder();
    Writer writer = new StringWriter(sb);
    try {
        Class<? extends JsonRender> jrCls = getJsonRenderCls();
        if (jrCls == null)
            jrCls = JsonRenderImpl.class;

        JsonRender jr = Mirror.me(jrCls).born();
        jr.setWriter(writer);
        jr.setFormat(format);
        jr.render(obj);

        writer.flush();
        return sb.toString();
    }
    catch (IOException e) {
        throw Lang.wrapThrow(e, JsonException.class);
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:21,代码来源:JsonConvertImpl.java

示例13: AutoLoadCacheAopInterceptor

import org.nutz.lang.Mirror; //导入依赖的package包/类
public AutoLoadCacheAopInterceptor(AbstractCacheManager cacheManager, Cache cache, Method method) {
    this.cachePointCut=cacheManager;
    this.cache=cache;
    if(method.isAnnotationPresent(Cache.class)) {
        if(log.isDebugEnabled()) {
            log.debugf("class %s , method %s", method.getDeclaringClass().getName(), method.getName());
        }
        this.haveCache=true;
    }
    mirror=Mirror.me(InterceptorChain.class);
}
 
开发者ID:qiujiayu,项目名称:AutoLoadCache-nutz,代码行数:12,代码来源:AutoLoadCacheAopInterceptor.java

示例14: matchExpert

import org.nutz.lang.Mirror; //导入依赖的package包/类
public JdbcExpert matchExpert(String dbName) {
    for (Entry<Pattern, Class<? extends JdbcExpert>> entry : _experts.entrySet()) {
        if (entry.getKey().matcher(dbName).find())
            return Mirror.me(entry.getValue()).born(this);
    }
    return null;
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:8,代码来源:JdbcExpertConfigFile.java

示例15: 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


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