Package org.jboss.managed.spi.factory

Examples of org.jboss.managed.spi.factory.InstanceClassFactory


   {
      if (object == null)
         throw new IllegalArgumentException("Null object");

      Class<? extends Serializable> clazz = object.getClass();
      InstanceClassFactory icf = getInstanceClassFactory(clazz);
      Class<? extends Serializable> moClass;
      try
      {
         moClass = icf.getManagedObjectClass(object);
      }
      catch(ClassNotFoundException e)
      {
         return null;
      }
View Full Code Here


    * @param object the object
    */
   @SuppressWarnings("unchecked")
   protected void populateValues(ManagedObjectImpl managedObject, Serializable object)
   {
      InstanceClassFactory icf = getInstanceClassFactory(object.getClass());
      Class moClass;
      try
      {
         moClass = icf.getManagedObjectClass(object);
      }
      catch(ClassNotFoundException e)
      {
         throw new IllegalStateException(e);
      }
      BeanInfo beanInfo = configuration.getBeanInfo(moClass);

      Object componentName = null;
      Map<String, ManagedProperty> properties = managedObject.getProperties();
      if (properties != null && properties.size() > 0)
      {
         for (ManagedProperty property : properties.values())
         {
            MetaValue value = icf.getValue(beanInfo, property, object);
            if (value != null)
               property.setField(Fields.VALUE, value);
            /* Need to look for a ManagementObjectID at the property level which
               defines the ManagedObject id name from the property value.
             */
            Map<String, Annotation> annotations = property.getAnnotations();
            if (annotations == null)
               continue;
            ManagementObjectID id = (ManagementObjectID) annotations.get(ManagementObjectID.class.getName());
            if (id != null)
            {
               if (value == null || value.getMetaType().isSimple() == false)
               {
                  log.warn("Cannot create String name from non-Simple property: "
                        +property+", value="+value);
                  continue;
               }
               SimpleValue svalue = (SimpleValue) value;
               String name = "" + svalue.getValue();
               managedObject.setName(name);
            }
            ManagementRuntimeRef runtimeRef = (ManagementRuntimeRef) annotations.get(ManagementRuntimeRef.class.getName());
            if (runtimeRef != null)
            {
               componentName = icf.getComponentName(beanInfo, property, object, value);
               // let's try this as well
               if (componentName == null && icf != this)
                  componentName = getComponentName(beanInfo, property, object, value);
            }
         }
      }
      if (componentName == null)
         componentName = icf.getComponentName(null, null, object, null);
      // set it, even if it's null
      managedObject.setComponentName(componentName);
   }
View Full Code Here

   @SuppressWarnings("unchecked")
   public <T extends Serializable> InstanceClassFactory<T> getInstanceClassFactory(Class<T> clazz)
   {
      synchronized (instanceFactories)
      {
         InstanceClassFactory factory = instanceFactories.get(clazz);
         if (factory != null)
            return factory;
      }
      return (InstanceClassFactory<T>)this;
   }
View Full Code Here

      {
         Object attachment = getManagedObject().getAttachment();
         if (attachment != null)
         {
            MetaValue metaValue = value;
            InstanceClassFactory icf = getMOFactory().getInstanceClassFactory(attachment.getClass());
            BeanInfo beanInfo = propertyInfo.getBeanInfo();
            icf.setValue(beanInfo, this, attachment, metaValue);
         }
      }
   }
View Full Code Here

   {
      if (instance == null)
         throw new IllegalArgumentException("instance cannot be null");

      Class<?> clazz = instance.getClass();
      InstanceClassFactory icf = defaultInstanceFactory;
      if(instanceType != null && instanceType != clazz)
         icf = getInstanceClassFactory(instanceType, metaData);
      if(icf == defaultInstanceFactory)
         icf = getInstanceClassFactory(clazz, metaData);

      Class<Object> moClass;
      try
      {
         moClass = icf.getManagedObjectClass(instance);
      }
      catch(ClassNotFoundException e)
      {
         log.debug("Failed to load class for ManagedObject", e);
         return null;
View Full Code Here

    */
   @SuppressWarnings("unchecked")
   public <X> InstanceClassFactory<X> getInstanceClassFactory(Class<X> clazz,
         MetaData metaData)
   {
      InstanceClassFactory defaultFactory = defaultInstanceFactory;
      if(metaData != null)
      {
         InstanceClassFactory mdrFactory = metaData.getMetaData(InstanceClassFactory.class);
         if(mdrFactory != null)
            defaultFactory = mdrFactory;
      }
      InstanceClassFactory<X> factory = (InstanceClassFactory<X>)
         Utility.getInstanceClassFactory(clazz, instanceFactories,
View Full Code Here

    */
   @SuppressWarnings("unchecked")
   protected void populateValues(MutableManagedObject managedObject, T object,
         MetaData metaData)
   {
      InstanceClassFactory icf = getInstanceClassFactory(object.getClass(), metaData);
      Class moClass;
      try
      {
         moClass = icf.getManagedObjectClass(object);
      }
      catch(ClassNotFoundException e)
      {
         throw new IllegalStateException(e);
      }
     
      BeanInfo beanInfo = managedObject.getTransientAttachment(BeanInfo.class);
      if(beanInfo == null)
         beanInfo = configuration.getBeanInfo(moClass);

      Object componentName = null;
      Map<String, ManagedProperty> properties = managedObject.getProperties();
      if (properties != null && properties.size() > 0)
      {
         for (ManagedProperty property : properties.values())
         {
            MetaValue value = null;
            try
            {
               value = icf.getValue(beanInfo, property, metaData, object);
            }
            catch(Throwable t)
            {
               if(log.isTraceEnabled())
                  log.trace("Failed to access value for property: "+property, t);
            }

            if (value != null)
               property.setField(Fields.VALUE, value);
            /* Need to look for a ManagementObjectID at the property level which
               defines the ManagedObject id name from the property value.
             */
            Map<String, Annotation> annotations = property.getAnnotations();
            if (annotations == null && metaData == null)
               continue;
           
            ManagementObjectID id = getAnnotation(ManagementObjectID.class, annotations, metaData);
            if (id != null)
            {
               if (value == null || value.getMetaType().isSimple() == false)
               {
                  log.debug("Cannot create String name from non-Simple property: " + property + ", value=" + value);
                  continue;
               }
               SimpleValue svalue = (SimpleValue) value;
               String name = id.prefix() + svalue.getValue() + id.suffix();
               log.debug("Created name: "+name+" from property: "+property.getName());
               managedObject.setName(name);
               managedObject.setTransientAttachment("ManagedObject.hasDefaultName", Boolean.FALSE);
            }
            ManagementRuntimeRef runtimeRef = getAnnotation(ManagementRuntimeRef.class, annotations, metaData);
            if (runtimeRef != null)
            {
               componentName = icf.getComponentName(beanInfo, property, object, value);
               if(componentName == null && defaultInstanceFactory != null)
               {
                  InstanceClassFactory dicf = defaultInstanceFactory;
                  componentName = dicf.getComponentName(beanInfo, property, object, value);
               }
            }
         }
      }
      if (componentName == null)
View Full Code Here

      LocalDSInstanceClassFactory dsicf = new LocalDSInstanceClassFactory();
      mof.addInstanceClassFactory(dsicf);
      NoTxICF nticf = new NoTxICF();
      mof.addInstanceClassFactory(nticf);

      InstanceClassFactory icf = mof.getInstanceClassFactory(IBeanMetaData.class);
      assertEquals("IBeanMetaData ICF", bicf, icf);
      icf = mof.getInstanceClassFactory(LocalDataSourceDeploymentMetaData.class);
      assertEquals("LocalDataSourceDeploymentMetaData ICF", dsicf, icf);
      icf = mof.getInstanceClassFactory(NoTxConnectionFactoryDeploymentMetaData.class);
      assertEquals("NoTxConnectionFactoryDeploymentMetaData ICF", nticf, icf);
View Full Code Here

            }
         }
      }
     
      // Set value
      InstanceClassFactory icf = managedObjectFactory.getInstanceClassFactory(attachment.getClass(), null);
      BeanInfo beanInfo = propertyInfo.getBeanInfo();
      icf.setValue(beanInfo, property, attachment, value);
   }
View Full Code Here

   {
      if (object == null)
         throw new IllegalArgumentException("Null object");

      Class<? extends Serializable> clazz = object.getClass();
      InstanceClassFactory icf = getInstanceClassFactory(clazz);
      Class<? extends Serializable> moClass;
      try
      {
         moClass = icf.getManagedObjectClass(object);
      }
      catch(ClassNotFoundException e)
      {
         return null;
      }
View Full Code Here

TOP

Related Classes of org.jboss.managed.spi.factory.InstanceClassFactory

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.