Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  private static <A extends Annotation> void findRepeatableAnnotations(
      Annotation[] candidates,
      Class<A> annotationType,
      Class<? extends Annotation> containerType,
      boolean inherited,
      Set<A> found,
      Set<Annotation> visited) {

    for (Annotation candidate : candidates) {
      if (!isInJavaLangAnnotationPackage(candidate) && visited.add(candidate)) {
        // Exact match?
        if (candidate.annotationType().equals(annotationType)) {
          found.add(annotationType.cast(candidate));
        }
        // Container?
        else if (candidate.annotationType().equals(containerType)) {
          // Note: it's not a legitimate container annotation if it doesn't declare
          // a 'value' attribute that returns an array of the contained annotation type.
          // Thus we proceed without verifying this assumption.
          Method method = ReflectionUtils.getMethod(containerType, "value").get();
          Annotation[] containedAnnotations =
              (Annotation[]) ReflectionUtils.invokeMethod(method, candidate);
          found.addAll((Collection<? extends A>) asList(containedAnnotations));
        }
        // Otherwise search recursively through the meta-annotation hierarchy...
        else {
          findRepeatableAnnotations(
              candidate.annotationType(), annotationType, containerType, inherited, found, visited);
        }
      }
    }
  }
Ejemplo n.º 2
0
  @Test
  public void testMethodAnnotation() throws Exception {
    Method m = ReflectionUtils.getMethod(Bar1.class, "yelp");
    Annotation a = ReflectionUtils.getMethodAnnotation(m, ControllerMethod.class);
    assertNotNull(a);
    assertTrue(a instanceof ControllerMethod);
    assertEquals("false", ((ControllerMethod) a).allow());

    m = ReflectionUtils.getMethod(Alpha1.class, "yelp");
    a = ReflectionUtils.getMethodAnnotation(m, ControllerMethod.class);
    assertNotNull(a);
    assertTrue(a instanceof ControllerMethod);

    m = ReflectionUtils.getMethod(Bogus1.class, "yelp");
    a = ReflectionUtils.getMethodAnnotation(m, ControllerMethod.class);
    assertNull(a);
  }
Ejemplo n.º 3
0
  /**
   * @param mBeanName
   * @param mBeanInstance
   * @param mBeanClassHierarchy
   * @param target
   * @param componentInstantiator
   * @param duServiceName the deployment unit's service name
   */
  MBeanServices(
      final String mBeanName,
      final Object mBeanInstance,
      final List<ClassReflectionIndex<?>> mBeanClassHierarchy,
      final ServiceTarget target,
      ServiceComponentInstantiator componentInstantiator,
      final ServiceName duServiceName) {
    if (mBeanClassHierarchy == null) {
      throw SarMessages.MESSAGES.nullVar("mBeanName");
    }
    if (mBeanInstance == null) {
      throw SarMessages.MESSAGES.nullVar("mBeanInstance");
    }
    if (target == null) {
      throw SarMessages.MESSAGES.nullVar("target");
    }

    final Method createMethod =
        ReflectionUtils.getMethod(mBeanClassHierarchy, CREATE_METHOD_NAME, NO_ARGS, false);
    final Method destroyMethod =
        ReflectionUtils.getMethod(mBeanClassHierarchy, DESTROY_METHOD_NAME, NO_ARGS, false);
    createDestroyService =
        new CreateDestroyService(
            mBeanInstance, createMethod, destroyMethod, componentInstantiator, duServiceName);
    createDestroyServiceName = ServiceNameFactory.newCreateDestroy(mBeanName);
    createDestroyServiceBuilder = target.addService(createDestroyServiceName, createDestroyService);
    if (componentInstantiator != null) {
      // the service that starts the EE component needs to start first
      createDestroyServiceBuilder.addDependency(
          componentInstantiator.getComponentStartServiceName());
    }

    final Method startMethod =
        ReflectionUtils.getMethod(mBeanClassHierarchy, START_METHOD_NAME, NO_ARGS, false);
    final Method stopMethod =
        ReflectionUtils.getMethod(mBeanClassHierarchy, STOP_METHOD_NAME, NO_ARGS, false);
    startStopService = new StartStopService(mBeanInstance, startMethod, stopMethod, duServiceName);
    startStopServiceName = ServiceNameFactory.newStartStop(mBeanName);
    startStopServiceBuilder = target.addService(startStopServiceName, startStopService);
    startStopServiceBuilder.addDependency(createDestroyServiceName);

    this.mBeanName = mBeanName;
    this.target = target;
    this.duServiceName = duServiceName;
  }
Ejemplo n.º 4
0
 /**
  * Reset the title settings
  *
  * @param player Player
  */
 public static void resetTitle(Player player) {
   try {
     // Send timings first
     Object handle = ReflectionUtils.getHandle(player);
     Object connection =
         ReflectionUtils.getField(handle.getClass(), "playerConnection").get(handle);
     Object[] actions = packetActions.getEnumConstants();
     Method sendPacket = ReflectionUtils.getMethod(connection.getClass(), "sendPacket");
     Object packet =
         packetTitle
             .getConstructor(packetActions, chatBaseComponent)
             .newInstance(actions[4], null);
     sendPacket.invoke(connection, packet);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 private static Value<?> getValue(
     final ValueFactory valueFactory,
     final List<ClassReflectionIndex> mBeanClassHierarchy,
     final ClassLoader classLoader)
     throws DeploymentUnitProcessingException {
   final String methodName = valueFactory.getMethodName();
   final ValueFactoryParameter[] parameters = valueFactory.getParameters();
   final List<Class<?>> paramTypes = new ArrayList<Class<?>>(parameters.length);
   final List<Value<?>> paramValues = new ArrayList<Value<?>>(parameters.length);
   for (ValueFactoryParameter parameter : parameters) {
     final Class<?> attributeTypeValue =
         ReflectionUtils.getClass(parameter.getType(), classLoader);
     paramTypes.add(attributeTypeValue);
     paramValues.add(
         new ImmediateValue<Object>(newValue(attributeTypeValue, parameter.getValue())));
   }
   final Value<Method> methodValue =
       new ImmediateValue<Method>(
           ReflectionUtils.getMethod(
               mBeanClassHierarchy, methodName, paramTypes.toArray(new Class<?>[0]), true));
   return cached(new MethodValue<Object>(methodValue, Values.injectedValue(), paramValues));
 }
Ejemplo n.º 6
0
 /**
  * Get a craft handle for a bukkit entity.
  *
  * @param entity entity to get the handle for.
  * @return the craft handle.
  */
 public static Object getHandle(Entity entity) throws Exception {
   Object nms_entity = null;
   Method entity_getHandle = ReflectionUtils.getMethod(entity.getClass(), "getHandle");
   nms_entity = entity_getHandle.invoke(entity);
   return nms_entity;
 }