當前位置: 首頁>>代碼示例>>Java>>正文


Java StringValueResolver類代碼示例

本文整理匯總了Java中org.osgl.util.StringValueResolver的典型用法代碼示例。如果您正苦於以下問題:Java StringValueResolver類的具體用法?Java StringValueResolver怎麽用?Java StringValueResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringValueResolver類屬於org.osgl.util包,在下文中一共展示了StringValueResolver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolver

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
public <T> StringValueResolver<T> resolver(final Class<T> targetType) {
    StringValueResolver<T> r = resolvers.get(targetType);
    final Class<? extends Enum> clazz = $.cast(targetType);
    if (null == r && Enum.class.isAssignableFrom(targetType)) {
        if (app().config().enumResolvingCaseSensitive()) {
            r = new StringValueResolver<T>(targetType) {
                @Override
                public T resolve(String value) {
                    //TODO should we handle exception here?
                    return (T)Enum.valueOf(clazz, value);
                }
            };
        } else {
            r = new StringValueResolver<T>(targetType) {
                @Override
                public T resolve(String value) {
                    return (T) $.asEnum(clazz, value);
                }
            };
        }
        resolvers.put(targetType, r);
    }
    return r;
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:25,代碼來源:StringValueResolverManager.java

示例2: findContextSpecificLoader

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
@Override
protected ParamValueLoader findContextSpecificLoader(
        String bindName,
        Class<?> rawType,
        BeanSpec spec,
        Type type,
        Annotation[] annotations
) {
    boolean isArray = rawType.isArray();
    StringValueResolver resolver = findResolver(spec, rawType, isArray); //= isArray ? resolverManager.resolver(rawType.getComponentType(), spec) : resolverManager.resolver(rawType, spec);

    Required required = filter(annotations, Required.class);
    Optional optional = null == required ? filter(annotations, Optional.class) : null;
    if (null != required) {
        return new OptionLoader(bindName, required, resolver, spec);
    } else if (null != optional) {
        return new OptionLoader(bindName, optional, resolver, spec);
    }
    return isArray ? new CliVarArgumentLoader(rawType.getComponentType(), resolver) : new CliArgumentLoader(resolver);
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:21,代碼來源:CliContextParamLoader.java

示例3: findIndirectAnnotatedResolver

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
private StringValueResolver findIndirectAnnotatedResolver(BeanSpec spec, Class rawType) {
    Annotation[] aa = spec.allAnnotations();
    for (Annotation a : aa) {
        Resolve resolve = AnnotationUtil.tagAnnotation(a, Resolve.class);
        if (null != resolve) {
            Class<? extends StringValueResolver>[] resolvers = resolve.value();
            for (Class<? extends StringValueResolver> resolverClass : resolvers) {
                StringValueResolver resolver = injector.get(resolverClass);
                resolver.attributes($.evaluate(a));
                if (rawType.isAssignableFrom(resolver.targetType())) {
                    return resolver;
                }
            }
        }
    }
    return null;
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:18,代碼來源:CliContextParamLoader.java

示例4: cast

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
private T cast(Object val, BeanSpec spec) {
    Class<?> type = spec.rawType();
    if (type.isInstance(val)) {
        return (T) val;
    }
    if ($.isSimpleType(type)) {
        StringValueResolver svr = StringValueResolver.predefined(type);
        if (null != svr) {
            return (T) svr.resolve(S.string(val));
        }
    }
    throw new InjectException("Cannot cast value type[%s] to required type[%]", val.getClass(), type);
}
 
開發者ID:osglworks,項目名稱:java-di,代碼行數:14,代碼來源:ConfigurationValueLoader.java

示例5: collectionResolver

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
public <T extends Collection> StringValueResolver<T> collectionResolver(final Class<T> targetType, final Class<?> elementType, final char separator) {
    final StringValueResolver elementResolver = resolver(elementType);
    return new StringValueResolver<T>(targetType) {
        @Override
        public T resolve(String value) {
            T col = app().getInstance(targetType);
            List<String> parts = S.fastSplit(value, String.valueOf(separator));
            for (String part : parts) {
                col.add(elementResolver.resolve(part));
            }
            return col;
        }
    };
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:15,代碼來源:StringValueResolverManager.java

示例6: found

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
@Override
protected void found(Class<? extends StringValueResolver> target, App app) {
    if (target == Param.DEFAULT_RESOLVER.class) {
        return;
    }
    if (target.isAnnotationPresent(NoAutoRegister.class)) {
        return;
    }
    StringValueResolver resolver = app.getInstance(target);
    app.resolverManager().register(resolver.targetType(), resolver);
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:12,代碼來源:StringValueResolverFinder.java

示例7: StringValueResolverValueLoaderBase

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
public StringValueResolverValueLoaderBase(ParamKey key, StringValueResolver<?> resolver, Param param, DefaultValue def, Class<?> type, boolean simpleKeyOnly) {
    E.illegalArgumentIf(simpleKeyOnly && !key.isSimple());
    this.paramKey = key;
    this.stringValueResolver = resolver;
    this.defSpec = def;
    Object _defVal = defVal(param, type);
    if (null == _defVal && null != def) {
        _defVal = resolver.resolve(def.value());
    }
    this.defVal = _defVal;
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:12,代碼來源:StringValueResolverValueLoaderBase.java

示例8: findDirectAnnotatedResolver

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
private StringValueResolver findDirectAnnotatedResolver(BeanSpec spec, Class rawType) {
    Resolve resolve = spec.getAnnotation(Resolve.class);
    if (null != resolve) {
        Class<? extends StringValueResolver>[] resolvers = resolve.value();
        for (Class<? extends StringValueResolver> resolverClass : resolvers) {
            StringValueResolver resolver = injector.get(resolverClass);
            if (rawType.isAssignableFrom(resolver.targetType())) {
                return resolver;
            }
        }
    }
    return null;
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:14,代碼來源:CliContextParamLoader.java

示例9: OptionLoader

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
OptionLoader(String bindName, Optional optional, StringValueResolver resolver, BeanSpec beanSpec) {
    this.bindName = bindName;
    this.required = false;
    this.parseLeads(optional.lead());
    this.defVal = optional.defVal();
    this.requiredGroup = null;
    this.beanSpec = beanSpec;
    this.errorTemplate = errorTemplate(optional);
    this.resolver = resolver;
    CliContext.ParsingContextBuilder.foundOptional();
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:12,代碼來源:OptionLoader.java

示例10: resolve

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
private <T> T resolve(String val, StringValueResolver<T> resolver) {
    if (null == errorTemplate) {
        return resolver.resolve(val);
    }
    try {
        return resolver.resolve(val);
    } catch (Exception e) {
        throw E.unexpected(errorTemplate, val);
    }
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:11,代碼來源:OptionLoader.java

示例11: register

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
@Override
public void register() {
    StringValueResolver.addPredefinedResolver(targetType(), this);
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:5,代碼來源:StringValueResolverPlugin.java

示例12: amended

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
@Override
public final StringValueResolver<T> amended(AnnotationAware beanSpec) {
    Pattern pattern = beanSpec.getAnnotation(Pattern.class);
    return null == pattern ? this : create(pattern.value());
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:6,代碼來源:JodaDateTimeCodecBase.java

示例13: register

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
public <T> StringValueResolverManager register(Class<T> targetType, StringValueResolver<T> resolver) {
    resolvers.put(targetType, resolver);
    return this;
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:5,代碼來源:StringValueResolverManager.java

示例14: resolve

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
public <T> T resolve(String strVal, Class<T> targetType) {
    StringValueResolver<T> r = resolver(targetType);
    return null != r ? r.resolve(strVal) : null;
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:5,代碼來源:StringValueResolverManager.java

示例15: registerPredefinedResolvers

import org.osgl.util.StringValueResolver; //導入依賴的package包/類
private void registerPredefinedResolvers() {
    resolvers.putAll(StringValueResolver.predefined());
}
 
開發者ID:actframework,項目名稱:actframework,代碼行數:4,代碼來源:StringValueResolverManager.java


注:本文中的org.osgl.util.StringValueResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。