@Override public DaoBase load(BeanSpec spec) { List<Type> typeList = spec.typeParams(); int sz = typeList.size(); if (sz > 1) { Class<?> modelType = BeanSpec.rawTypeOf(typeList.get(1)); return (DaoBase) dbServiceManager.dao(modelType); } return null; }
@Override public Dao load(BeanSpec spec) { List<Type> typeList = spec.typeParams(); int sz = typeList.size(); if (sz > 1) { Class<?> modelType = BeanSpec.rawTypeOf(typeList.get(1)); return dbServiceManager.dao(modelType); } return (Dao)Act.getInstance(spec.rawType()); }
private BeanSpec valueSpec() { List<Type> typeParams = targetSpec.typeParams(); E.illegalArgumentIf(typeParams.size() != 2); return BeanSpec.of(typeParams.get(1), targetSpec.injector()); } }
private static String toString(BeanSpec spec) { if (spec.typeParams().isEmpty()) { return spec.rawType().getName(); } else { return spec.type().toString(); } }
String interpret(BeanSpec beanSpec) { if (beanSpec.hasAnnotation(DbBind.class)) { return "String"; Class<?> rawType = beanSpec.rawType(); if (Collection.class.isAssignableFrom(rawType)) { List<Type> types = beanSpec.typeParams(); if (types.size() > 0) { return interpret(BeanSpec.of(types.get(0), null, beanSpec.injector())) + "[]"; List<Type> types = beanSpec.typeParams(); if (types.size() > 1) { Type key = types.get(0); Type val = types.get(1); String keyStr = interpret(BeanSpec.of(key, null, beanSpec.injector())); String valStr = interpret(BeanSpec.of(val, null, beanSpec.injector())); if ("String".equals(keyStr) && "Object".equals(valStr)) { return "js object";
Class<?> rawType = spec.rawType(); final NamedProvider namedProvider = namedRegistry.get(rawType); if (null != namedProvider && spec.hasAnnotation(Named.class)) { final String name = spec.name(); return new Provider<Object>() { @Override if (null != spec.name()) { provider = registry.get(spec.withoutName()); if (null != provider) { return provider; if (spec.isProvider() && !spec.typeParams().isEmpty()) { provider = new Provider<Provider<?>>() { @Override if (spec.hasValueLoader()) { provider = ValueLoaderFactory.create(spec, this); } else { if (spec.isArray()) { return ArrayProvider.of(spec, this); final GenericTypedBeanLoader loader = genericTypedBeanLoaders.get(spec.rawType()); if (null != loader) { provider = new Provider<Object>() { if (spec.notConstructable()) {
boolean isReturn ) { Type type = spec.type(); if (void.class == type) { return null; if (typeChain.contains(type) && !isCollection(type) && !$.isSimpleType(spec.rawType())) { return S.concat(spec.name(), ":", type); // circular reference detected String name = spec.name(); if (S.notBlank(name)) { nameChain.add(name); String path = S.join(nameChain).by(".").get(); if (!fastJsonPropertyPreFilter.matches(path)) { if (spec.isArray() || Iterable.class.isAssignableFrom(spec.rawType())) { return Act.getInstance(spec.rawType()); } else { return null; SampleData.Category anno = spec.getAnnotation(SampleData.Category.class); SampleDataCategory category = null != anno ? anno.value() : null; Class<?> classType = spec.rawType(); SampleDataProviderManager sampleDataProviderManager = Act.app().sampleDataProviderManager(); Object o = sampleDataProviderManager.getSampleData(category, name, classType, false); } else if (String.class == classType || Keyword.class == classType) { String mockValue = sampleDataProviderManager.getSampleData(category, name, String.class); if (spec.hasAnnotation(Sensitive.class)) {
List<BeanSpec> retVal = new ArrayList<>(); BeanSpec current = this; Class<?> rawType = rawType(); if ($.isSimpleType(rawType)) { return C.list(); while (null != current && current.isNotObject()) { Type[] fieldTypeParams = null; Type[] classTypeParams; Map<String, Type> typeParamsMapping = new HashMap<>(); for (Field field : current.rawType().getDeclaredFields()) { if (!filter.test(field)) { continue; fieldTypeParams = ((ParameterizedType) fieldGenericType).getActualTypeArguments(); if (fieldTypeParams != null && fieldTypeParams.length > 0) { classTypeParams = current.rawType().getTypeParameters(); if (classTypeParams != null && classTypeParams.length > 0) { List<Type> classTypeImpls = current.typeParams(); for (int i = 0; i < classTypeParams.length; ++i) { if (i >= classTypeImpls.size()) { retVal.add(beanSpecOf(field, fieldGenericType)); } else if (fieldGenericType instanceof TypeVariable) { if (null == typeImplLookup) { Class clazz = typeImplLookup.get(fieldType.getName()); if (null != clazz) { retVal.add(of(field, fieldGenericType, injector, typeImplLookup));
$.Var<File> fileBag = $.var(); if (isDir(url, entryBag, jarFileBag, fileBag)) { E.unsupportedIfNot(Map.class.isAssignableFrom(spec.rawType()), "Does not support loading directory into " + spec); JarEntry entry = entryBag.get(); Map map = $.cast(Act.getInstance(spec.rawType())); List<Type> mapTypes = spec.typeParams(); Type valType = mapTypes.size() > 1 ? mapTypes.get(1) : String.class; BeanSpec subSpec = BeanSpec.of(valType, spec.injector()); boolean isKeyword = false; if (mapTypes.size() > 0) { Class<?> rawType = spec.rawType(); if (URL.class == rawType) { return url; content = content.trim(); Object o = content.startsWith("[") ? JSON.parseArray(content) : JSON.parseObject(content); return $.map(o).targetGenericType(spec.type()).to(rawType); return $.map(o).targetGenericType(spec.type()).to(rawType); if ($.isCollectionType(rawType)) { JSONArray array = $.convert(o).to(JSONArray.class); return $.map(array).targetGenericType(spec.type()).to(rawType); } else { JSONObject json = $.convert(o).to(JSONObject.class); return $.map(json).targetGenericType(spec.type()).to(rawType); return IO.readContentAsString(url);
private BeanSpec(Type type, Annotation[] annotations, String name, Injector injector, int modifiers, Map<String, Class> typeParamImplLookup) { this.injector = injector; this.type = type; this.originalName = name; this.name = name; this.rawType = rawTypeOf(type, typeParamImplLookup); this.typeParams(typeParamImplLookup); if (null != typeParamImplLookup && type instanceof TypeVariable && rawType.getTypeParameters().length > 0 && !typeParamImplLookup.isEmpty()) { this.fieldTypeImplLookup = Generics.subLookup(typeParamImplLookup, ((TypeVariable) type).getName()); } this.isArray = rawType.isArray(); this.resolveTypeAnnotations(injector); this.resolveAnnotations(annotations, injector, typeParamImplLookup); this.hc = calcHashCode(); this.modifiers = modifiers; }
App app = App.instance(); rawType = spec.rawType(); notNull = spec.hasAnnotation(NotNull.class); findOne = !(Iterable.class.isAssignableFrom(rawType)); dao = app.dbServiceManager().dao(findOne ? rawType : (Class) spec.typeParams().get(0)); SessionVariable sessionVariable = spec.getAnnotation(SessionVariable.class); if (null != sessionVariable) { isSessionVariable = true;
public boolean subjectToInject(BeanSpec beanSpec) { if (!beanSpec.hasInjectDecorator()) { Class<?> type = beanSpec.rawType(); if ($.isSimpleType(type)) { return false; List<Type> typeParams = beanSpec.typeParams(); if (typeParams.isEmpty()) { return false; List<Type> typeParams = beanSpec.typeParams(); if (typeParams.isEmpty()) { return false; return true; if (beanSpec.hasAnnotation(Inject.class)) { return true; if (beanSpec.hasAnnotation(tag)) { return true; for (Annotation tag : beanSpec.allAnnotations()) { Class<? extends Annotation> tagType = tag.annotationType(); if (tagType.isAnnotationPresent(InjectTag.class)) { return beanSpec.hasAnnotation(Singleton.class);
private JsonDtoPatch(String name, BeanSpec spec) { this.name = S.requireNotBlank(name); this.loader = valueLoaderOf(spec); if (null == loader) { for (BeanSpec fieldSpec : spec.nonStaticFields()) { Class fieldType = fieldSpec.rawType(); if (fieldSpec.isTransient() || fieldSpec.hasAnnotation(Transient.class)) { continue; } if (Collection.class.isAssignableFrom(fieldType) || Map.class.isAssignableFrom(fieldType)) { continue; } String fieldName = fieldSpec.name(); JsonDtoPatch child = new JsonDtoPatch(fieldName, fieldSpec); if (!child.isEmpty()) { fieldsPatches.add(child); } } } }
public BeanSpec componentSpec() { if (!componentSpecSet) { synchronized (this) { if (!componentSpecSet) { componentSpecSet = true; if (isArray()) { componentSpec = BeanSpec.of(rawType.getComponentType(), injector); } else { List<Type> typeParams = typeParams(); if (!typeParams.isEmpty()) { componentSpec = BeanSpec.of(typeParams.get(0), injector); } } } } } return componentSpec; }
@Override public void fireInjectedEvent(Object bean, BeanSpec spec) { Class c = spec.rawType(); List<DependencyInjectionListener> list = listeners.get(c); if (null != list) { for (DependencyInjectionListener listener : list) { listener.onInjection(bean, spec); } } }
@Override public Class rawType() { if (null == rawType) { synchronized (this) { if (null == rawType) { rawType = rawTypeOf(type); } } } return rawType; }
public boolean isProvided(BeanSpec beanSpec) { Class rawType = beanSpec.rawType(); boolean provided = (ActProviders.isProvided(rawType) || null != beanSpec.getAnnotation(Inject.class) || null != beanSpec.getAnnotation(Provided.class) || null != beanSpec.getAnnotation(Context.class) || null != beanSpec.getAnnotation(Singleton.class) || beanSpec.isInstanceOf(SingletonBase.class) || subjectToInject(beanSpec) ); return provided && (!($.isSimpleType(rawType) && !beanSpec.hasAnnotation())); }