Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2007, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.managed.plugins.factory;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
AbstractManagedObjectFactory.

Author(s):
Adrian Brock
Scott.Stark@jboss.org
Version:
$Revision: 1.1 $
 
 {
    private static final Logger log = Logger.getLogger(AbstractManagedObjectFactory.class);

   
The configuration
   private static final Configuration configuration = PropertyConfigurationAccess.getConfiguration();

   
The managed object meta type
   public static final GenericMetaType MANAGED_OBJECT_META_TYPE = new GenericMetaType(ManagedObject.class.getName(), ManagedObject.class.getName());
   
   
The meta type factory
   private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance(); 

   
The meta value factory
   private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
   
   
The managed object builders
   private Map<Class<?>, ManagedObjectBuilderbuilders = new WeakHashMap<Class<?>, ManagedObjectBuilder>();

   
The instance to class factories
   private Map<Class<?>, InstanceClassFactory<? extends Serializable>> instanceFactories = new WeakHashMap<Class<?>, InstanceClassFactory<? extends Serializable>>();

   
The instance to name transformers
Create a ManagedProperty by looking to the factory for ctor(Fields)

Parameters:
factory - the ManagedProperty implementation class
fields - the fields to pass to the ctor
Returns:
the managed property if successful, null otherwise
   public static ManagedProperty createManagedProperty(Class<? extends ManagedPropertyfactoryFields fields)
   {
      ManagedProperty property = null;
      try
      {
         Class<?>[] sig = {Fields.class};
         Constructor<? extends ManagedPropertyctor = factory.getConstructor(sig);
         Object[] args = {fields};
         property = ctor.newInstance(args);
      }
      catch(Exception e)
      {
         .debug("Failed to create ManagedProperty"e);
      }
      return property;
   }
   public <T extends SerializableManagedObject createManagedObject(Class<T> clazz)
   {
      if (clazz == null)
         throw new IllegalArgumentException("Null class");
      ManagedObject result = createSkeletonManagedObject(clazz);
      ManagedObjectPopulator<Serializablepopulator = getPopulator(clazz);
      populator.createObject(resultclazz);
      
      return result;
   }
   @SuppressWarnings("unchecked")
   public ManagedObject initManagedObject(Serializable objectString nameString nameType)
   {
      if (object == null)
         throw new IllegalArgumentException("Null object");
      Class<? extends Serializableclazz = object.getClass();
      Class<? extends SerializablemoClass;
      try
      {
         moClass = icf.getManagedObjectClass(object);
      }
      catch(ClassNotFoundException e)
      {
         return null;
      }
      ManagedObject result = createSkeletonManagedObject(moClass);
      if (result == null )
      {
         .debug("Null ManagedObject created for: "+moClass);
         return null;
      }
      ManagedObjectPopulator<Serializablepopulator = getPopulator(moClass);
      populator.populateManagedObject(resultobject);
      return result;
   }
   public void setBuilder(Class<?> clazzManagedObjectBuilder builder)
   {
      synchronized ()
      {
         if (builder == null)
            .remove(clazz);
         else
            .put(clazzbuilder);
      }
   }
   public <T extends Serializablevoid setInstanceClassFactory(Class<T> clazzInstanceClassFactory<T> factory)
   {
      synchronized ()
      {
         if (factory == null)
            .remove(clazz);
         else
            .put(clazzfactory);
      }      
   }
   public void setNameTransformers(Class<?> clazzRuntimeComponentNameTransformer transformer)
   {
      TypeInfo type = .getTypeInfo(clazz);
      setNameTransformers(typetransformer);
   }
   public void setNameTransformers(TypeInfo typeRuntimeComponentNameTransformer transformer)
   {
      synchronized ()
      {
         if (transformer == null)
            .remove(type);
         else
            .put(typetransformer);
      }
   }

   
Default InstanceClassFactory implementation simply returns the instance class.
   public Class<? extends SerializablegetManagedObjectClass(Serializable instance)
   {
      return instance.getClass();
   }

   
Create a skeleton managed object

Parameters:
<T> the type
clazz the clazz
Returns:
the skeleton managed object, null if clazz is not marked as a ManagementObject. org.jboss.managed.api.annotation.ManagementObject
   protected <T extends SerializableManagedObject createSkeletonManagedObject(Class<T> clazz)
   {
      if (clazz == null)
         throw new IllegalArgumentException("Null class");
      ManagedObjectBuilder builder = getBuilder(clazz);
      return builder.buildManagedObject(clazz);
   }
   
   
The ManagedObjectBuilder.buildManagedObject implementation. This is based on the org.jboss.managed.api.annotation.* package annotations.

Parameters:
clazz the attachment class
Returns:
the ManagementObject if clazz is properly annotated, null if it does not have a ManagementObject annotation.
   @SuppressWarnings("unchecked")
   public ManagedObject buildManagedObject(Class<? extends Serializableclazz)
   {
      boolean trace = .isTraceEnabled();
      BeanInfo beanInfo = .getBeanInfo(clazz);
      ClassInfo classInfo = beanInfo.getClassInfo();
      ManagementObject managementObject = classInfo.getUnderlyingAnnotation(ManagementObject.class);
      ifmanagementObject == null )
      {
         if (trace)
            .trace("No ManagementObject annotation, skipping ManagedObject for class: "+clazz);
         // Skip the ManagedObject creation
         return null;
      }
      HashMap<StringAnnotationmoAnnotations = new HashMap<StringAnnotation>();
      moAnnotations.put(ManagementObject.class.getName(), managementObject);
      ManagementObjectID moID = classInfo.getUnderlyingAnnotation(ManagementObjectID.class);
      if (moID != null)
         moAnnotations.put(ManagementObjectID.class.getName(), moID);
      // Process the ManagementObject fields
      boolean isRuntime = managementObject.isRuntime();
      String name = classInfo.getName();
      String nameType = null;
      String attachmentName = classInfo.getName();
      Class<? extends FieldsmoFieldsFactory = null;
      Class<? extends ManagedPropertyConstraintsPopulatorFactorymoConstraintsFactory = null;
      Class<? extends ManagedPropertymoPropertyFactory = null;
      if (managementObject != null)
      {
         name = managementObject.name();
         if (name.length() == 0 || name.equals(.))
            name = classInfo.getName();
         nameType = managementObject.type();
         if (nameType.length() == 0)
            nameType = null;
         attachmentName = managementObject.attachmentName();
         if (attachmentName.length() == 0)
            attachmentName = classInfo.getName();
         // Check for a component specification
         ManagementComponent mc = managementObject.componentType();
         if (mc.equals(.) == false)
            moAnnotations.put(ManagementComponent.class.getName(), mc);
         // ManagementObject level default factory classes
         moFieldsFactory = managementObject.fieldsFactory();
         moConstraintsFactory = managementObject.constraintsFactory();
         moPropertyFactory = managementObject.propertyFactory();
      }
      if (trace)
      {
         .trace("Building MangedObject(name="+name+",nameType="+nameType
               +",attachmentName="+attachmentName+",isRuntime="+isRuntime+")");
      }
      ManagementProperties propertyType = .;
      if (managementObject != null)
         propertyType = managementObject.properties();
      // Build the ManagedProperties
      Set<ManagedPropertyproperties = new HashSet<ManagedProperty>();
      Set<PropertyInfopropertyInfos = beanInfo.getProperties();
      if (propertyInfos != null && propertyInfos.isEmpty() == false)
      {
         for (PropertyInfo propertyInfo : propertyInfos)
         {
            // Ignore the "class" property
            if ("class".equals(propertyInfo.getName()))
               continue;
            ManagementProperty managementProperty = propertyInfo.getUnderlyingAnnotation(ManagementProperty.class);
            ManagementObjectID id = propertyInfo.getUnderlyingAnnotation(ManagementObjectID.class);
            ManagementObjectRef ref = propertyInfo.getUnderlyingAnnotation(ManagementObjectRef.class);
            ManagementRuntimeRef runtimeRef = propertyInfo.getUnderlyingAnnotation(ManagementRuntimeRef.class);
            HashMap<StringAnnotationpropAnnotations = new HashMap<StringAnnotation>();
            if (managementProperty != null)
               propAnnotations.put(ManagementProperty.class.getName(), managementProperty);
            if (id != null)
            {
               propAnnotations.put(ManagementObjectID.class.getName(), id);
               // This overrides the MO nameType
               nameType = id.type();
            }
            if (ref != null)
               propAnnotations.put(ManagementObjectRef.class.getName(), ref);
            if (runtimeRef != null)
               propAnnotations.put(ManagementRuntimeRef.class.getName(), runtimeRef);
            // Check for a simple property
            boolean includeProperty = (propertyType == .);
            if (managementProperty != null)
               includeProperty = (managementProperty.ignored() == false);
            if (includeProperty)
            {
               Fields fields = null;
               if (managementProperty != null)
               {
                  Class<? extends Fieldsfactory = moFieldsFactory;
                  if (factory == ManagementProperty.NULL_FIELDS_FACTORY.class)
                     factory = managementProperty.fieldsFactory();
                  if (factory != ManagementProperty.NULL_FIELDS_FACTORY.class)
                  {
                     try
                     {
                        fields = factory.newInstance();
                     }
                     catch (Exception e)
                     {
                        .debug("Failed to created Fields"e);
                     }
                  }
               }
               if (fields == null)
                  fields = new DefaultFieldsImpl();
               ifpropertyInfo instanceof Serializable )
               {
                  Serializable info = Serializable.class.cast(propertyInfo);
                  fields.setField(.info);
               }
               String propertyName = propertyInfo.getName();
               if (managementProperty != null)
                  propertyName = managementProperty.name();
               ifpropertyName.length() == 0 )
                  propertyName = propertyInfo.getName();
               fields.setField(.propertyName);
               // This should probably always the the propertyInfo name?
               String mappedName = propertyInfo.getName();
               if (managementProperty != null)
                  mappedName = managementProperty.mappedName();
               ifmappedName.length() == 0 )
                  mappedName = propertyInfo.getName();
               fields.setField(.mappedName);
               String description = .;
               if (managementProperty != null)
                  description = managementProperty.description();
               if (description.equals(.))
                  description = propertyName;
               fields.setField(.description);
               if (trace)
               {
                  .trace("Building MangedProperty(name="+propertyName
                        +",mappedName="+mappedName
                        +") ,annotations="+propAnnotations);
               }
               boolean mandatory = false;
               if (managementProperty != null)
                  mandatory = managementProperty.mandatory();
               if (mandatory)
                  fields.setField(..);
               
               boolean managed = false;
               if (managementProperty != null)
                  managed = managementProperty.managed();
               
               MetaType metaType;
               if (managed)
               {
                  TypeInfo typeInfo = propertyInfo.getType();
                  if(typeInfo.isArray())
                     metaType = new ArrayMetaType(1, );
                  else if (typeInfo.isCollection())
                     metaType = new CollectionMetaType(typeInfo.getName(), );
                  else
                     metaType = ;
               }
               else
               {
                  metaType = .resolve(propertyInfo.getType());
               }
               fields.setField(.metaType);
               if (propAnnotations.isEmpty() == false)
                  fields.setField(.propAnnotations);
               // Delegate others (legal values, min/max etc.) to the constraints factory
               try
               {
                  Class<? extends ManagedPropertyConstraintsPopulatorFactoryfactoryClass = moConstraintsFactory;
                  if (factoryClass == ManagementProperty.NULL_CONSTRAINTS.class)
                  {
                     if (managementProperty != null)
                        factoryClass = managementProperty.constraintsFactory();
                  }
                  ManagedPropertyConstraintsPopulatorFactory factory = factoryClass.newInstance();
                  ManagedPropertyConstraintsPopulator populator = factory.newInstance();
                  if (populator != null)
                     populator.populateManagedProperty(clazzpropertyInfofields);
               }
               catch(Exception e)
               {
                  .debug("Failed to populate constraints for: "+propertyInfoe);
               }
               ManagedProperty property = null;
               if (managementProperty != null)
               {
                  Class<? extends ManagedPropertyfactory = moPropertyFactory;
                  if (factory == ManagementProperty.NULL_PROPERTY_FACTORY.class)
                     factory = managementProperty.propertyFactory();
                  if (factory != ManagementProperty.NULL_PROPERTY_FACTORY.class)
                     property = getManagedProperty(factoryfields);
               }
               // we should have write-through by default
               // use factory to change this default behavior
               if (property == null)
                  property = createDefaultManagedProperty(fields);
               properties.add(property);
            }
            else if (trace)
               .trace("Ignoring property: " + propertyInfo);
         }
      }
      /* TODO: Operations. In general the bean metadata does not contain
         operation information.
      */
      Set<ManagedOperationoperations = new HashSet<ManagedOperation>();
      
      Set<MethodInfomethodInfos = beanInfo.getMethods();
      if (methodInfos != null && methodInfos.isEmpty() == false)
      {
         for (MethodInfo methodInfo : methodInfos)
         {
            ManagementOperation managementOp = methodInfo.getUnderlyingAnnotation(ManagementOperation.class);
            if (managementOp == null)
               continue;
            ManagedOperation op = getManagedOperation(methodInfomanagementOp);
            operations.add(op);
         }
      }
      ManagedObjectImpl result = new ManagedObjectImpl(nameproperties);
      result.setAnnotations(moAnnotations);
      if (nameType != null)
         result.setNameType(nameType);
      if (attachmentName != null)
         result.setAttachmentName(attachmentName);
      if (operations.size() > 0 )
         result.setOperations(operations);
      for (ManagedProperty property : properties)
         property.setManagedObject(result);
      return result;
   }

   
Create default MangedProperty instance. Override this method for different default.

Parameters:
fields the fields
Returns:
new ManagedProperty instance
   {
      return new WritethroughManagedPropertyImpl(fieldsthis);
   }
   public void createObject(ManagedObject managedObjectClass<? extends Serializableclazz)
   {
      if (managedObject == null)
         throw new IllegalArgumentException("Null managed object");
      
      if (managedObject instanceof ManagedObjectImpl == false)
         throw new IllegalStateException("Unable to create object " + managedObject.getClass().getName());
      
      ManagedObjectImpl managedObjectImpl = (ManagedObjectImplmanagedObject;
      Serializable object = createUnderlyingObject(managedObjectImplclazz);
      populateManagedObject(managedObjectobject);
   }
   
   public void populateManagedObject(ManagedObject managedObjectSerializable object)
   {
      if (managedObject instanceof ManagedObjectImpl == false)
         throw new IllegalStateException("Unable to populate managed object " + managedObject.getClass().getName());
      
      ManagedObjectImpl managedObjectImpl = (ManagedObjectImplmanagedObject;
      managedObjectImpl.setAttachment(object);
      populateValues(managedObjectImplobject);
   }
   
   
Create the underlying object

Parameters:
managedObject the managed object
clazz the class
Returns:
the object
   protected Serializable createUnderlyingObject(ManagedObjectImpl managedObjectClass<? extends Serializableclazz)
   {
      BeanInfo beanInfo = .getBeanInfo(clazz);
      try
      {
         Object result = beanInfo.newInstance();
         return Serializable.class.cast(result);
      }
      catch (Throwable t)
      {
         throw new RuntimeException("Unable to create new object for " + managedObject + " clazz=" + clazzt);
      }
   }
   
   
Populate the values

Parameters:
managedObject the managed object
object the object
   @SuppressWarnings("unchecked")
   protected void populateValues(ManagedObjectImpl managedObjectSerializable object)
   {
      Class moClass;
      try
      {
         moClass = icf.getManagedObjectClass(object);
      }
      catch(ClassNotFoundException e)
      {
         throw new IllegalStateException(e);
      }
      BeanInfo beanInfo = .getBeanInfo(moClass);
      Object componentName = null;
      Map<StringManagedPropertyproperties = managedObject.getProperties();
      if (properties != null && properties.size() > 0)
      {
         for (ManagedProperty property : properties.values())
         {
            MetaValue value = icf.getValue(beanInfopropertyobject);
            if (value != null)
               property.setField(.value);
            /* Need to look for a ManagementObjectID at the property level which
               defines the ManagedObject id name from the property value.
             */
            Map<StringAnnotationannotations = property.getAnnotations();
            if (annotations == null)
               continue;
            ManagementObjectID id = (ManagementObjectIDannotations.get(ManagementObjectID.class.getName());
            if (id != null)
            {
               if (value == null || value.getMetaType().isSimple() == false)
               {
                  .warn("Cannot create String name from non-Simple property: "
                        +property+", value="+value);
                  continue;
               }
               SimpleValue svalue = (SimpleValuevalue;
               String name = "" + svalue.getValue();
               managedObject.setName(name);
            }
            ManagementRuntimeRef runtimeRef = (ManagementRuntimeRefannotations.get(ManagementRuntimeRef.class.getName());
            if (runtimeRef != null)
            {
               componentName = icf.getComponentName(beanInfopropertyobjectvalue);
               // let's try this as well
               if (componentName == null && icf != this)
                  componentName = getComponentName(beanInfopropertyobjectvalue);
            }
         }
      }
      if (componentName == null)
         componentName = icf.getComponentName(nullnullobjectnull);
      // set it, even if it's null
      managedObject.setComponentName(componentName);
   }

   
Get the property name.

Parameters:
property managed property
Returns:
property name
   protected String getPropertyName(ManagedProperty property)
   {
      // First look to the mapped name
      String name = property.getMappedName();
      if (name == null)
         property.getName();
      return name;
   }
   public Object getComponentName(BeanInfo beanInfoManagedProperty propertySerializable objectMetaValue value)
   {
      if (beanInfo != null && property != null && value != null)
      {
         String name = getPropertyName(property);
         PropertyInfo propertyInfo = beanInfo.getProperty(name);
         ManagementRuntimeRef componentRef = propertyInfo.getUnderlyingAnnotation(ManagementRuntimeRef.class);
         if (componentRef != null)
         {
            Object original = .unwrap(valuepropertyInfo.getType());
            try
            {
               Class<? extends RuntimeComponentNameTransformertClass = componentRef.transformer();
               RuntimeComponentNameTransformer transformer;
               if (tClass != ManagementRuntimeRef.DEFAULT_NAME_TRANSFORMER.class)
                  transformer = getComponentNameTransformer(.getTypeInfo(tClass));
               else
                  transformer = getComponentNameTransformer(propertyInfo.getType());
               return (transformer != null) ? transformer.transform(original) : original;
            }
            catch (Throwable t)
            {
               throw new UndeclaredThrowableException(t);
            }
         }
      }
      return null;
   }

   
Get a value

Parameters:
beanInfo the bean info
property the property
object the object
Returns:
the meta value
   @SuppressWarnings("unchecked")
   public MetaValue getValue(BeanInfo beanInfoManagedProperty propertySerializable object)
   {
      String name = getPropertyName(property);
      PropertyInfo propertyInfo = beanInfo.getProperty(name);
      Object value;
      try
      {
         value = propertyInfo.get(object);
      }
      catch (RuntimeException e)
      {
         throw e;
      }
      catch (Error e)
      {
         throw e;
      }
      catch (Throwable t)
      {
         throw new RuntimeException("Error getting property " + name + " for " + object.getClass().getName(), t);
      }
      if (value == null)
         return null;
      MetaType propertyType = property.getMetaType();
      if ( == propertyType)
      {
         if (value instanceof Serializable == false)
            throw new IllegalStateException("Object is not serializable: " + value.getClass().getName());
         // Look for a ManagementObjectRef
         ManagementObjectRef ref = (ManagementObjectRefproperty.getAnnotations().get(ManagementObjectRef.class.getName());
         String moName = (ref != null ? ref.name() : value.getClass().getName());
         String moNameType = (ref != null ? ref.type() : "");
         ManagedObject mo = initManagedObject((SerializablevaluemoNamemoNameType);
         return new GenericValueSupport(mo);
      }
      else if (propertyType.isArray())
      {
         ArrayMetaType arrayType = ArrayMetaType.class.cast(propertyType);
         if ( == arrayType.getElementType())
         {
            Collection<?> cvalue = getAsCollection(value);
            // todo - AJ: changed some generics by best guess
            ArrayMetaType moType = new ArrayMetaType(1, );
            ArrayValueSupport moArrayValue = new ArrayValueSupport(moType);
            List<GenericValueSupporttmp = new ArrayList<GenericValueSupport>();
            for(Object element : cvalue)
            {
               ManagedObject mo = initManagedObject((Serializableelementnullnull);
               tmp.add(new GenericValueSupport(mo));
            }
            GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
            moArrayValue.setValue(tmp.toArray(mos));
            return moArrayValue;
         }
      }
      else if (propertyType.isCollection())
      {
         CollectionMetaType collectionType = CollectionMetaType.class.cast(propertyType);
         if ( == collectionType.getElementType())
         {
            Collection<?> cvalue = getAsCollection(value);
            List<GenericValueSupporttmp = new ArrayList<GenericValueSupport>();
            for(Object element : cvalue)
            {
               ManagedObject mo = initManagedObject((Serializableelementnullnull);
               tmp.add(new GenericValueSupport(mo));
            }
            GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
            CollectionMetaType moType = new CollectionMetaType(propertyType.getClassName(), );
            return new CollectionValueSupport(moTypetmp.toArray(mos));
         }
      }
      return .create(valuepropertyInfo.getType());
   }

   
Set a value

Parameters:
beanInfo the bean info
property the property
object the object
value the meta value
   public void setValue(BeanInfo beanInfoManagedProperty propertySerializable objectMetaValue value)
   {
      String name = getPropertyName(property);
      PropertyInfo propertyInfo = beanInfo.getProperty(name);
      Object plainValue = .unwrap(valuepropertyInfo.getType());
      try
      {
         propertyInfo.set(objectplainValue);
      }
      catch (Throwable t)
      {
         throw new UndeclaredThrowableException(t);
      }
   }

   

Parameters:
methodInfo
opAnnotation
Returns:
the managed operation
   protected ManagedOperation getManagedOperation(MethodInfo methodInfoManagementOperation opAnnotation)
   {
      String name = methodInfo.getName();
      String description = opAnnotation.description();
      Impact impact = opAnnotation.impact();
      ManagementParameter[] params = opAnnotation.params();
      ParameterInfo[] paramInfo = methodInfo.getParameters();
      TypeInfo returnInfo = methodInfo.getReturnType();
      MetaType returnType = .resolve(returnInfo);
      ArrayList<ManagedParametermparams = new ArrayList<ManagedParameter>();
      Class<? extends ManagedParameterConstraintsPopulatorFactoryopConstraintsFactor = opAnnotation.constraintsFactory();
      ifparamInfo != null )
      {
         for(int i = 0; i < paramInfo.lengthi ++)
         {
            ParameterInfo pinfo = paramInfo[i];
            String pname = pinfo.getName();
            String pdescription = null;
            ManagementParameter mpa = null;
            // Look to ManagementParameter for info
            if (i < params.length)
            {
               mpa = params[i];
               if (mpa.name().equals(.) == false)
                  pname = mpa.name();
               if (mpa.description().equals(.) == false)
                  pdescription = mpa.description();
            }
            // Generate a name if there is none
            if (pname == null)
               pname = "arg#" + i;
            Fields fields =  new DefaultFieldsImpl(pname);
            if (pdescription != null)
               fields.setField(.pdescription);
            MetaType metaType = .resolve(pinfo.getParameterType());
            fields.setField(.metaType);
            // Delegate others (legal values, min/max etc.) to the constraints factory
            try
            {
               Class<? extends ManagedParameterConstraintsPopulatorFactoryfactoryClass = opConstraintsFactor;
               if (factoryClass == ManagementParameter.NULL_CONSTRAINTS.class)
               {
                  if (mpa != null)
                     factoryClass = mpa.constraintsFactory();
               }
               ManagedParameterConstraintsPopulatorFactory factory = factoryClass.newInstance();
               ManagedParameterConstraintsPopulator populator = factory.newInstance();
               if (populator != null)
                  populator.populateManagedParameter(namepinfofields);
            }
            catch(Exception e)
            {
               .debug("Failed to populate constraints for: "+pinfoe);
            }
            ManagedParameterImpl mp = new ManagedParameterImpl(fields);
            mparams.add(mp);
         }
      }
      ManagedParameter[] parameters = new ManagedParameter[mparams.size()];
      mparams.toArray(parameters);
      return new ManagedOperationImpl(namedescriptionimpactparametersreturnType);
   }

   
Get the builder for a class

Parameters:
clazz the class
Returns:
the builder
   protected ManagedObjectBuilder getBuilder(Class<?> clazz)
   {
      synchronized ()
      {
         ManagedObjectBuilder builder = .get(clazz);
         if (builder != null)
            return builder;
      }
      return this;
   }

   
Get the instance factory for a class

Parameters:
clazz the class
Returns:
the InstanceClassFactory
   @SuppressWarnings("unchecked")
   public <T extends SerializableInstanceClassFactory<T> getInstanceClassFactory(Class<T> clazz)
   {
      synchronized ()
      {
         InstanceClassFactory factory = .get(clazz);
         if (factory != null)
            return factory;
      }
      return (InstanceClassFactory<T>)this;
   }

   
Get component name transformer.

Parameters:
type the type info
Returns:
transformer instance
Throws:
java.lang.Throwable for any error
   {
      synchronized()
      {
         RuntimeComponentNameTransformer transformer = .get(type);
         if (transformer != null)
            return transformer;
         if (rcntType.isAssignableFrom(type))
         {
            BeanInfo beanInfo = .getBeanInfo(type);
            RuntimeComponentNameTransformer newTransformer = (RuntimeComponentNameTransformer)beanInfo.newInstance();
            .put(typenewTransformer);
            return newTransformer;
         }
         return null;
      }
   }

   
Get the populator for a class

Parameters:
clazz the class
Returns:
the populator
   @SuppressWarnings("unchecked")
   {
      ManagedObjectBuilder builder = getBuilder(clazz);
      if (builder instanceof ManagedObjectPopulator)
         return (ManagedObjectPopulatorbuilder;
      return this;
   }
   protected Collection<?> getAsCollection(Object value)
   {
      ifvalue.getClass().isArray() )
         return Arrays.asList(value);
      else if (value instanceof Collection)
         return Collection.class.cast(value);
      return null;
   }

   
Look for ctor(Fields)

Parameters:
factory - the ManagedProperty implementation class
fields - the fields to pass to the ctor
Returns:
the managed property
   protected ManagedProperty getManagedProperty(Class<? extends ManagedPropertyfactoryFields fields)
   {
      return createManagedProperty(factoryfields);
   }
New to GrepCode? Check out our FAQ X