private boolean isMoreThanOneDolphinModel(Class<?> clazz) { List<Field> fields = ReflectionHelper.getInheritedDeclaredFields(clazz); int count = 0; for (Field field : fields) { if (field.isAnnotationPresent(DolphinModel.class)) { count++; } } return count > 1; }
private void firePreChildDestroyed(final Object parentController, final Object childController) { final List<Method> allMethods = ReflectionHelper.getInheritedDeclaredMethods(parentController.getClass()); for(Method method : allMethods) { if(method.isAnnotationPresent(PreChildDestroyed.class)) { if(method.getParameters()[0].getType().isAssignableFrom(childController.getClass())) { ReflectionHelper.invokePrivileged(method, parentController, childController); } } } }
private IdentitySet<Property> getAllProperties(Object bean) { IdentitySet<Property> ret = new IdentitySet<>(); List<Field> fields = propertyFieldCache.get(bean.getClass()); if (fields == null) { fields = new ArrayList<>(); for (Field field : ReflectionHelper.getInheritedDeclaredFields(bean.getClass())) { if (Property.class.isAssignableFrom(field.getType())) { fields.add(field); } } propertyFieldCache.put(bean.getClass(), fields); } for (Field field : fields) { ret.add((Property) ReflectionHelper.getPrivileged(field, bean)); } return ret; }
private void attachModel(final String controllerId, final Object controller) { Assert.requireNonNull(controllerId, "controllerId"); Assert.requireNonNull(controller, "controller"); List<Field> allFields = ReflectionHelper.getInheritedDeclaredFields(controller.getClass()); Field modelField = null; for (Field field : allFields) { if (field.isAnnotationPresent(DolphinModel.class)) { if (modelField != null) { throw new RuntimeException("More than one Model was found for controller " + controller.getClass().getName()); } modelField = field; } } if (modelField != null) { Object model = beanBuilder.createRootModel(modelField.getType()); ReflectionHelper.setPrivileged(modelField, controller, model); models.put(controllerId, model); } }
public <T> Binding bind(final Property<T> property, final Qualifier<T> qualifier) { Assert.requireNonNull(property, "property"); Assert.requireNonNull(qualifier, "qualifier"); if(property instanceof PropertyImpl) { try { final PropertyImpl p = (PropertyImpl) property; final Field attributeField = ReflectionHelper.getInheritedDeclaredField(PropertyImpl.class, "attribute"); final ServerAttribute attribute = (ServerAttribute) ReflectionHelper.getPrivileged(attributeField, p); if(attribute == null) { throw new NullPointerException("attribute == null"); } attribute.setQualifier(qualifier.getIdentifier()); return new Binding() { @Override public void unbind() { attribute.setQualifier(null); } }; } catch (Exception e) { throw new BindingException("Can not bind the given property to the qualifier! Property: " + property + ", qualifier: " + qualifier , e); } } else { throw new BindingException("Can not bind the given property to the qualifier! Property: " + property + ", qualifier: " + qualifier); } }
private boolean isMoreThanOnePreDestroy(Class<?> clazz) { int count = 0; List<Method> methods = ReflectionHelper.getInheritedDeclaredMethods(clazz); for (Method method : methods) { if (method.isAnnotationPresent(PreDestroy.class)) { count++; } } return count > 1; }
ReflectionHelper.invokePrivileged(actionMethod, controller, args.toArray()); } catch (InvokeActionException e) { throw e;
private IdentitySet<ObservableList> getAllLists(Object bean) { IdentitySet<ObservableList> ret = new IdentitySet<>(); List<Field> fields = listFieldCache.get(bean.getClass()); if (fields == null) { fields = new ArrayList<>(); for (Field field : ReflectionHelper.getInheritedDeclaredFields(bean.getClass())) { if (ObservableList.class.isAssignableFrom(field.getType())) { fields.add(field); } } listFieldCache.put(bean.getClass(), fields); } for (Field field : fields) { ret.add((ObservableList) ReflectionHelper.getPrivileged(field, bean)); } return ret; }
private void attachParent(final String controllerId, final Object controller, final String parentControllerId) { Assert.requireNonNull(controllerId, "controllerId"); Assert.requireNonNull(controller, "controller"); Assert.requireNonNull(parentControllerId, "parentControllerId"); final List<Field> allFields = ReflectionHelper.getInheritedDeclaredFields(controller.getClass()); Field parentField = null; for (Field field : allFields) { if (field.isAnnotationPresent(ParentController.class)) { if (parentField != null) { throw new RuntimeException("More than one parent was found for controller " + controller.getClass().getName()); } parentField = field; } } if (parentField != null) { final Object parentController = controllers.get(parentControllerId); Assert.requireNonNull(parentController, "parentController"); if(!parentField.getType().isAssignableFrom(parentController.getClass())) { throw new RuntimeException("Parent controller in " + controller.getClass() + " defined of wrong type. Should be " + parentController.getClass()); } ReflectionHelper.setPrivileged(parentField, controller, parentController); if(parentChildRelations.get(parentControllerId) == null) { parentChildRelations.put(parentControllerId, new ArrayList<String>()); } parentChildRelations.get(parentControllerId).add(controllerId); childToParentRelations.put(controllerId, parentControllerId); } }
private boolean isMoreThanOnePostConstruct(Class<?> clazz) { int count = 0; List<Method> methods = ReflectionHelper.getInheritedDeclaredMethods(clazz); for (Method method : methods) { if (method.isAnnotationPresent(PostConstruct.class)) { count++; } } return count > 1; } }
for(Field field : ReflectionHelper.getInheritedDeclaredFields(dolphinModel.getClass())) { if(DolphinUtils.isProperty(field.getType())) { Property property = (Property) ReflectionHelper.getPrivileged(field, dolphinModel); Object value = property.get(); if(value == null) { ObservableList list = (ObservableList) ReflectionHelper.getPrivileged(field, dolphinModel); JsonArray jsonArray = new JsonArray(); for(Object value : list) {
private void firePostChildCreated(final Object parentController, final Object childController) { Assert.requireNonNull(parentController, "parentController"); Assert.requireNonNull(childController, "childController"); final List<Method> allMethods = ReflectionHelper.getInheritedDeclaredMethods(parentController.getClass()); for(Method method : allMethods) { if(method.isAnnotationPresent(PostChildCreated.class)) { if(method.getParameters()[0].getType().isAssignableFrom(childController.getClass())) { ReflectionHelper.invokePrivileged(method, parentController, childController); } } } }
private boolean isDolphinActionVoid(Class<?> clazz) { List<Method> methods = ReflectionHelper.getInheritedDeclaredMethods(clazz); for (Method method : methods) { if (method.isAnnotationPresent(DolphinAction.class)) { return method.getReturnType().equals(Void.TYPE); } } return true; }
private boolean isDolphinModelPresent(Class<?> clazz) { List<Field> fields = ReflectionHelper.getInheritedDeclaredFields(clazz); for (Field field : fields) { if (field.isAnnotationPresent(DolphinModel.class)) { return true; } } return false; }
private boolean postConstructContainsParameter(Class<?> clazz) { List<Method> methods = ReflectionHelper.getInheritedDeclaredMethods(clazz); for (Method method : methods) { if (method.isAnnotationPresent(PostConstruct.class)) { return checkParameterLength(method); } } return false; }
private boolean preDestroyContainsParameter(Class<?> clazz) { List<Method> methods = ReflectionHelper.getInheritedDeclaredMethods(clazz); for (Method method : methods) { if (method.isAnnotationPresent(PreDestroy.class)) { return checkParameterLength(method); } } return false; }
private boolean isAnnotatedWithParam(Class<?> clazz) { List<Method> methods = ReflectionHelper.getInheritedDeclaredMethods(clazz); for (Method method : methods) { if (method.isAnnotationPresent(DolphinAction.class)) { Annotation[][] paramAnnotations = method.getParameterAnnotations(); for(Annotation[] annotations : paramAnnotations) { boolean paramAnnotationFound = false; for(Annotation annotation : annotations) { if (annotation.annotationType().equals(Param.class)) { paramAnnotationFound = true; break; } } if(!paramAnnotationFound) { return false; } } } } return true; }
private <T> Method getActionMethod(Class<T> controllerClass, String actionName) { Assert.requireNonNull(controllerClass, "controllerClass"); Assert.requireNonNull(actionName, "actionName"); List<Method> allMethods = ReflectionHelper.getInheritedDeclaredMethods(controllerClass); Method foundMethod = null; for (Method method : allMethods) { if (method.isAnnotationPresent(DolphinAction.class)) { DolphinAction actionAnnotation = method.getAnnotation(DolphinAction.class); String currentActionName = method.getName(); if (actionAnnotation.value() != null && !actionAnnotation.value().trim().isEmpty()) { currentActionName = actionAnnotation.value(); } if (currentActionName.equals(actionName)) { if (foundMethod != null) { throw new RuntimeException("More than one method for action " + actionName + " found in " + controllerClass); } foundMethod = method; } } } return foundMethod; }