Package org.exoplatform.management.spi

Examples of org.exoplatform.management.spi.ManagedMethodMetaData


         //
         Impact impactAnn = method.getAnnotation(Impact.class);
         ImpactType impactType = impactAnn != null ? impactAnn.value() : ImpactType.WRITE;

         // Build the default mbean info
         ManagedMethodMetaData managedMethod = new ManagedMethodMetaData(method, impactType);
         managedMethod.setDescription(methodDescription);

         // Overload with annotations meta data
         Annotation[][] parameterAnnotations = method.getParameterAnnotations();
         for (int i = 0; i < parameterAnnotations.length; i++)
         {
            ManagedMethodParameterMetaData mmpMD = new ManagedMethodParameterMetaData(i);
            for (Annotation parameterAnnotation : parameterAnnotations[i])
            {
               if (parameterAnnotation instanceof ManagedName)
               {
                  mmpMD.setName(((ManagedName) parameterAnnotation).value());
               }
               else if (parameterAnnotation instanceof ManagedDescription)
               {
                  mmpMD.setDescription(((ManagedDescription) parameterAnnotation).value());
               }
            }
            managedMethod.addParameter(mmpMD);
         }

         //
         bilto.put(method, managedMethod);
      }

      //
      ManagedTypeMetaData managedType = new ManagedTypeMetaData(clazz);
      managedType.setDescription(typeDescription);

      //
      Map<String, ManagedMethodMetaData> setters = new HashMap<String, ManagedMethodMetaData>();
      Map<String, ManagedMethodMetaData> getters = new HashMap<String, ManagedMethodMetaData>();
      for (Map.Entry<Method, ManagedMethodMetaData> entry : bilto.entrySet())
      {

         Method method = entry.getKey();

         //
         String methodName = method.getName();
         Class[] parameterTypes = method.getParameterTypes();

         //
         OperationType type = OperationType.OP;
         Integer index = null;
         if (method.getReturnType() == void.class)
         {
            if (parameterTypes.length == 1 && methodName.startsWith("set") && methodName.length() > 4)
            {
               type = OperationType.SET;
               index = 3;
            }
         }
         else
         {
            if (parameterTypes.length == 0)
            {
               type = OperationType.GET;
               if (methodName.startsWith("get") && methodName.length() > 3)
               {
                  index = 3;
               }
               else if (methodName.startsWith("is") && methodName.length() > 2)
               {
                  index = 2;
               }
            }
         }

         // Put in the correct map if it is an attribute
         if (index != null)
         {
            String attributeName = methodName.substring(index);

            //
            Map<String, ManagedMethodMetaData> map = type == OperationType.SET ? setters : getters;
            ManagedMethodMetaData previous = map.put(attributeName, entry.getValue());
            if (previous != null)
            {
               throw new IllegalArgumentException("Duplicate attribute " + type + " " + previous + " and " + method);
            }
         }
         else
         {
            ManagedName managedName = methodNames.get(method);
            if (managedName != null)
            {
               throw new IllegalArgumentException("Managed operation " + method.getName()
                        + " cannot be annoated with @" + ManagedName.class.getName() + " with value "
                        + managedName.value());
            }

            //
            managedType.addMethod(entry.getValue());
         }
      }

      // Process attributes
      Set<String> attributeNames = new HashSet<String>();
      attributeNames.addAll(getters.keySet());
      attributeNames.addAll(setters.keySet());
      for (String attributeName : attributeNames)
      {
         ManagedMethodMetaData managedGetter = getters.get(attributeName);
         ManagedMethodMetaData managedSetter = setters.get(attributeName);

         String propertyDescription = null;
         ManagedName getterName = null;
         ManagedName setterName = null;
         String getterDescription = null;
         String setterDescription = null;
         Method getter = null;
         Method setter = null;
         ManagedParameterMetaData mpm = null;
         if (managedGetter != null)
         {
            getter = managedGetter.getMethod();
            getterName = methodNames.get(getter);
            getterDescription = managedGetter.getDescription();
            propertyDescription = getterDescription;
         }
         if (managedSetter != null)
         {
            setter = managedSetter.getMethod();
            setterName = methodNames.get(setter);
            setterDescription = managedSetter.getDescription();
            if (propertyDescription == null)
            {
               propertyDescription = setterDescription;
            }
            mpm = managedSetter.getParameters().iterator().next();
         }

         // Consistency check
         if (getterName != null)
         {
View Full Code Here


         //
         Impact impactAnn = method.getAnnotation(Impact.class);
         ImpactType impactType = impactAnn != null ? impactAnn.value() : ImpactType.WRITE;

         // Build the default mbean info
         ManagedMethodMetaData managedMethod = new ManagedMethodMetaData(method, impactType);
         managedMethod.setDescription(methodDescription);

         // Overload with annotations meta data
         Annotation[][] parameterAnnotations = method.getParameterAnnotations();
         for (int i = 0; i < parameterAnnotations.length; i++)
         {
            ManagedMethodParameterMetaData mmpMD = new ManagedMethodParameterMetaData(i);
            for (Annotation parameterAnnotation : parameterAnnotations[i])
            {
               if (parameterAnnotation instanceof ManagedName)
               {
                  mmpMD.setName(((ManagedName)parameterAnnotation).value());
               }
               else if (parameterAnnotation instanceof ManagedDescription)
               {
                  mmpMD.setDescription(((ManagedDescription)parameterAnnotation).value());
               }
            }
            managedMethod.addParameter(mmpMD);
         }

         //
         bilto.put(method, managedMethod);
      }

      //
      ManagedTypeMetaData managedType = new ManagedTypeMetaData(clazz);
      managedType.setDescription(typeDescription);

      //
      Map<String, ManagedMethodMetaData> setters = new HashMap<String, ManagedMethodMetaData>();
      Map<String, ManagedMethodMetaData> getters = new HashMap<String, ManagedMethodMetaData>();
      for (Map.Entry<Method, ManagedMethodMetaData> entry : bilto.entrySet())
      {

         Method method = entry.getKey();

         //
         String methodName = method.getName();
         Class[] parameterTypes = method.getParameterTypes();

         //
         OperationType type = OperationType.OP;
         Integer index = null;
         if (method.getReturnType() == void.class)
         {
            if (parameterTypes.length == 1 && methodName.startsWith("set") && methodName.length() > 4)
            {
               type = OperationType.SET;
               index = 3;
            }
         }
         else
         {
            if (parameterTypes.length == 0)
            {
               type = OperationType.GET;
               if (methodName.startsWith("get") && methodName.length() > 3)
               {
                  index = 3;
               }
               else if (methodName.startsWith("is") && methodName.length() > 2)
               {
                  index = 2;
               }
            }
         }

         // Put in the correct map if it is an attribute
         if (index != null)
         {
            String attributeName = methodName.substring(index);

            //
            Map<String, ManagedMethodMetaData> map = type == OperationType.SET ? setters : getters;
            ManagedMethodMetaData previous = map.put(attributeName, entry.getValue());
            if (previous != null)
            {
               throw new IllegalArgumentException("Duplicate attribute " + type + " " + previous + " and " + method);
            }
         }
         else
         {
            ManagedName managedName = methodNames.get(method);
            if (managedName != null)
            {
               throw new IllegalArgumentException("Managed operation " + method.getName()
                  + " cannot be annoated with @" + ManagedName.class.getName() + " with value " + managedName.value());
            }

            //
            managedType.addMethod(entry.getValue());
         }
      }

      // Process attributes
      Set<String> attributeNames = new HashSet<String>();
      attributeNames.addAll(getters.keySet());
      attributeNames.addAll(setters.keySet());
      for (String attributeName : attributeNames)
      {
         ManagedMethodMetaData managedGetter = getters.get(attributeName);
         ManagedMethodMetaData managedSetter = setters.get(attributeName);

         String propertyDescription = null;
         ManagedName getterName = null;
         ManagedName setterName = null;
         String getterDescription = null;
         String setterDescription = null;
         Method getter = null;
         Method setter = null;
         ManagedParameterMetaData mpm = null;
         if (managedGetter != null)
         {
            getter = managedGetter.getMethod();
            getterName = methodNames.get(getter);
            getterDescription = managedGetter.getDescription();
            propertyDescription = getterDescription;
         }
         if (managedSetter != null)
         {
            setter = managedSetter.getMethod();
            setterName = methodNames.get(setter);
            setterDescription = managedSetter.getDescription();
            if (propertyDescription == null)
            {
               propertyDescription = setterDescription;
            }
            mpm = managedSetter.getParameters().iterator().next();
         }

         // Consistency check
         if (getterName != null)
         {
View Full Code Here

         //
         Impact impactAnn = method.getAnnotation(Impact.class);
         ImpactType impactType = impactAnn != null ? impactAnn.value() : ImpactType.WRITE;

         // Build the default mbean info
         ManagedMethodMetaData managedMethod = new ManagedMethodMetaData(method, impactType);
         managedMethod.setDescription(methodDescription);

         // Overload with annotations meta data
         Annotation[][] parameterAnnotations = method.getParameterAnnotations();
         for (int i = 0; i < parameterAnnotations.length; i++)
         {
            ManagedMethodParameterMetaData mmpMD = new ManagedMethodParameterMetaData(i);
            for (Annotation parameterAnnotation : parameterAnnotations[i])
            {
               if (parameterAnnotation instanceof ManagedName)
               {
                  mmpMD.setName(((ManagedName) parameterAnnotation).value());
               }
               else if (parameterAnnotation instanceof ManagedDescription)
               {
                  mmpMD.setDescription(((ManagedDescription) parameterAnnotation).value());
               }
            }
            managedMethod.addParameter(mmpMD);
         }

         //
         bilto.put(method, managedMethod);
      }

      //
      ManagedTypeMetaData managedType = new ManagedTypeMetaData(clazz);
      managedType.setDescription(typeDescription);

      //
      Map<String, ManagedMethodMetaData> setters = new HashMap<String, ManagedMethodMetaData>();
      Map<String, ManagedMethodMetaData> getters = new HashMap<String, ManagedMethodMetaData>();
      for (Map.Entry<Method, ManagedMethodMetaData> entry : bilto.entrySet())
      {

         Method method = entry.getKey();

         //
         String methodName = method.getName();
         Class[] parameterTypes = method.getParameterTypes();

         //
         OperationType type = OperationType.OP;
         Integer index = null;
         if (method.getReturnType() == void.class)
         {
            if (parameterTypes.length == 1 && methodName.startsWith("set") && methodName.length() > 4)
            {
               type = OperationType.SET;
               index = 3;
            }
         }
         else
         {
            if (parameterTypes.length == 0)
            {
               type = OperationType.GET;
               if (methodName.startsWith("get") && methodName.length() > 3)
               {
                  index = 3;
               }
               else if (methodName.startsWith("is") && methodName.length() > 2)
               {
                  index = 2;
               }
            }
         }

         // Put in the correct map if it is an attribute
         if (index != null)
         {
            String attributeName = methodName.substring(index);

            //
            Map<String, ManagedMethodMetaData> map = type == OperationType.SET ? setters : getters;
            ManagedMethodMetaData previous = map.put(attributeName, entry.getValue());
            if (previous != null)
            {
               throw new IllegalArgumentException("Duplicate attribute " + type + " " + previous + " and " + method);
            }
         }
         else
         {
            ManagedName managedName = methodNames.get(method);
            if (managedName != null)
            {
               throw new IllegalArgumentException("Managed operation " + method.getName()
                        + " cannot be annoated with @" + ManagedName.class.getName() + " with value "
                        + managedName.value());
            }

            //
            managedType.addMethod(entry.getValue());
         }
      }

      // Process attributes
      Set<String> attributeNames = new HashSet<String>();
      attributeNames.addAll(getters.keySet());
      attributeNames.addAll(setters.keySet());
      for (String attributeName : attributeNames)
      {
         ManagedMethodMetaData managedGetter = getters.get(attributeName);
         ManagedMethodMetaData managedSetter = setters.get(attributeName);

         String propertyDescription = null;
         ManagedName getterName = null;
         ManagedName setterName = null;
         String getterDescription = null;
         String setterDescription = null;
         Method getter = null;
         Method setter = null;
         ManagedParameterMetaData mpm = null;
         if (managedGetter != null)
         {
            getter = managedGetter.getMethod();
            getterName = methodNames.get(getter);
            getterDescription = managedGetter.getDescription();
            propertyDescription = getterDescription;
         }
         if (managedSetter != null)
         {
            setter = managedSetter.getMethod();
            setterName = methodNames.get(setter);
            setterDescription = managedSetter.getDescription();
            if (propertyDescription == null)
            {
               propertyDescription = setterDescription;
            }
            mpm = managedSetter.getParameters().iterator().next();
         }

         // Consistency check
         if (getterName != null)
         {
View Full Code Here

   public void testImpact()
   {
      MetaDataBuilder builder = new MetaDataBuilder(Foo.class);
      ManagedTypeMetaData type = builder.build();
      Map<String, ManagedMethodMetaData> methodMap = getMethodMap(type);
      ManagedMethodMetaData read = methodMap.get("read");
      assertEquals(ImpactType.READ, read.getImpact());
      ManagedMethodMetaData write = methodMap.get("write");
      assertEquals(ImpactType.WRITE, write.getImpact());
      ManagedMethodMetaData idempotentWrite = methodMap.get("idempotentWrite");
      assertEquals(ImpactType.IDEMPOTENT_WRITE, idempotentWrite.getImpact());
   }
View Full Code Here

TOP

Related Classes of org.exoplatform.management.spi.ManagedMethodMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.