/** * Resolves action method for given action class ane method name. */ public Method resolveActionMethod(final Class<?> actionClass, final String methodName) { MethodDescriptor methodDescriptor = ClassIntrospector.get().lookup(actionClass).getMethodDescriptor(methodName, false); if (methodDescriptor == null) { throw new MadvocException("Public method not found: " + actionClass.getSimpleName() + "#" + methodName); } return methodDescriptor.getMethod(); }
/** * Sets new bean instance. */ private void setBean(final Object bean) { this.bean = bean; this.cd = (bean == null ? null : introspector.lookup(bean.getClass())); this.first = false; this.updateProperty = true; }
/** * Returns all bean property names. */ protected String[] getAllBeanPropertyNames(Class type, boolean declared) { ClassDescriptor classDescriptor = ClassIntrospector.lookup(type); PropertyDescriptor[] propertyDescriptors = classDescriptor.getAllPropertyDescriptors(); ArrayList<String> names = new ArrayList<>(propertyDescriptors.length); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { MethodDescriptor getter = propertyDescriptor.getReadMethodDescriptor(); if (getter != null) { if (getter.matchDeclared(declared)) { names.add(propertyDescriptor.getName()); } } else if (includeFields) { FieldDescriptor field = propertyDescriptor.getFieldDescriptor(); if (field != null) { if (field.matchDeclared(declared)) { names.add(field.getName()); } } } } return names.toArray(new String[names.size()]); }
/** * Locates property field. Field is being searched also in all * superclasses of current class. */ protected FieldDescriptor findField(final String fieldName) { FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor(fieldName, true); if (fieldDescriptor != null) { return fieldDescriptor; } // field descriptor not found in this class // try to locate it in the superclasses Class[] superclasses = classDescriptor.getAllSuperclasses(); for (Class superclass : superclasses) { ClassDescriptor classDescriptor = ClassIntrospector.get().lookup(superclass); fieldDescriptor = classDescriptor.getFieldDescriptor(fieldName, true); if (fieldDescriptor != null) { return fieldDescriptor; } } // nothing found return null; }
/** * Locates property field. Field is being searched also in all * superclasses of current class. */ protected FieldDescriptor findField(String fieldName) { FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor(fieldName, true); if (fieldDescriptor != null) { return fieldDescriptor; } // field descriptor not found in this class // try to locate it in the superclasses Class[] superclasses = classDescriptor.getAllSuperclasses(); for (Class superclass : superclasses) { ClassDescriptor classDescriptor = ClassIntrospector.lookup(superclass); fieldDescriptor = classDescriptor.getFieldDescriptor(fieldName, true); if (fieldDescriptor != null) { return fieldDescriptor; } } // nothing found return null; }
/** * Parses class annotations and adds all checks. * @see #resolveFor(Class) */ public void addClassChecks(final Class target) { final List<Check> list = cache.get(target, () -> { final List<Check> newList = new ArrayList<>(); final ClassDescriptor cd = ClassIntrospector.get().lookup(target); final PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : allProperties) { collectPropertyAnnotationChecks(newList, propertyDescriptor); } return newList; }); addAll(list); }
/** * Sets new bean instance. */ private void setBean(final Object bean) { this.bean = bean; this.cd = (bean == null ? null : introspector.lookup(bean.getClass())); this.first = false; this.updateProperty = true; }
/** * Creates new object or a <code>HashMap</code> if type is not specified. */ protected Object newObjectInstance(final Class targetType) { if (targetType == null || targetType == Map.class) { return mapSupplier.get(); } ClassDescriptor cd = ClassIntrospector.get().lookup(targetType); CtorDescriptor ctorDescriptor = cd.getDefaultCtorDescriptor(true); if (ctorDescriptor == null) { throw new JsonException("Default ctor not found for: " + targetType.getName()); } try { // return ClassUtil.newInstance(targetType); return ctorDescriptor.getConstructor().newInstance(); } catch (Exception e) { throw new JsonException(e); } }
/** * Lookups for annotated fields. Caches all annotated fields on the first * action class scan. */ protected Field[] lookupAnnotatedFields(Class type) { Field[] fields = annotatedField.get(type); if (fields == null) { ClassDescriptor cd = ClassIntrospector.lookup(type); Field[] allFields = cd.getAllFields(true); List<Field> fieldlist = new ArrayList<Field>(); for (Field field : allFields) { Annotation ann = field.getAnnotation(fieldAnnotation); if (ann != null) { fieldlist.add(field); } } if (fieldlist.isEmpty()) { fields = EMPTY_FIELD; } else { fields = fieldlist.toArray(new Field[fieldlist.size()]); } annotatedField.put(type, fields); } return fields; }
/** * Registers static method provider. * * @param providerName provider name * @param type class type * @param staticMethodName static method name * @param arguments method argument types */ public void registerPetiteProvider(final String providerName, final Class type, final String staticMethodName, final Class[] arguments) { ClassDescriptor cd = ClassIntrospector.get().lookup(type); MethodDescriptor md = cd.getMethodDescriptor(staticMethodName, arguments, true); if (md == null) { throw new PetiteException("Provider method not found: " + staticMethodName); } ProviderDefinition providerDefinition = new ProviderDefinition(providerName, md.getMethod()); providers.put(providerName, providerDefinition); }
public DbEntitySearcher(Object entity) { this.entity = entity; this.dbOomManager = DbOomManager.getInstance(); this.ded = dbOomManager.lookupType(entity.getClass()); if (ded == null) { throw new DbSqlException("Type '" + entity.getClass() + "' is not an database entity."); } entityClassDescriptor = ClassIntrospector.lookup(entity.getClass()); }
/** * Registers set injection point. * * @param beanName bean name * @param property set property name */ public void registerPetiteSetInjectionPoint(final String beanName, final String property) { BeanDefinition beanDefinition = lookupExistingBeanDefinition(beanName); ClassDescriptor cd = ClassIntrospector.get().lookup(beanDefinition.type); PropertyDescriptor propertyDescriptor = cd.getPropertyDescriptor(property, true); if (propertyDescriptor == null) { throw new PetiteException("Property not found: " + beanDefinition.type.getName() + '#' + property); } SetInjectionPoint sip = new SetInjectionPoint(propertyDescriptor); beanDefinition.addSetInjectionPoint(sip); }
/** * Parses class annotations and adds all checks. * @see #resolveFor(Class) */ public void addClassChecks(Class target) { List<Check> list = cache.get(target); if (list == null) { list = new ArrayList<Check>(); ClassDescriptor cd = ClassIntrospector.lookup(target); Field[] fields = cd.getAllFields(true); for (Field field : fields) { collectFieldAnnotationChecks(list, field); } cache.put(target, list); } addAll(list); }
/** * Finds type data of first annotated superclass or interface. */ protected TypeData findSubclassTypeData(final Class type) { final Class<? extends Annotation> defaultAnnotation = jsonAnnotation; if (type.getAnnotation(defaultAnnotation) != null) { // current type has annotation, don't find anything, let type data be created return null; } ClassDescriptor cd = ClassIntrospector.get().lookup(type); // lookup superclasses Class[] superClasses = cd.getAllSuperclasses(); for (Class superClass : superClasses) { if (superClass.getAnnotation(defaultAnnotation) != null) { // annotated subclass founded! return _lookupTypeData(superClass); } } Class[] interfaces = cd.getAllInterfaces(); for (Class interfaze : interfaces) { if (interfaze.getAnnotation(defaultAnnotation) != null) { // annotated subclass founded! return _lookupTypeData(interfaze); } } return null; }
private PropertyInjectionPoint definePropertyInjectionPoint(Class type, String property, String[] references) { ClassDescriptor cd = ClassIntrospector.lookup(type); Field field = cd.getField(property, true); if (field == null) { throw new PetiteException("Property '" + type.getName() + '#' + property + "' doesn't exist"); } return injectionPointFactory.createPropertyInjectionPoint(field, references); }
/** * Registers action with provided action path, class and method name. */ public ActionConfig register(Class actionClass, String actionMethod, String actionPath) { Method method = ClassIntrospector.lookup(actionClass).getMethod(actionMethod); if (method == null) { throw new MadvocException("Provided action class '" + actionClass.getSimpleName() + "' doesn't contain public method '" + actionMethod + "'."); } return registerAction(actionClass, method, actionPath); }
private PropertyDescriptor field(Class type, String name) { PropertyDescriptor[] propertyDescriptors = ClassIntrospector.get().lookup(type).getAllPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (propertyDescriptor.getName().equals(name)) { return propertyDescriptor; } } throw new IllegalArgumentException(); }
ClassDescriptor cd = ClassIntrospector.lookup(type); List<SetInjectionPoint> list = new ArrayList<SetInjectionPoint>(); Field[] allFields = cd.getAllFields(true);