[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Adding ManagedObjectCreator support to AbstractSimpleRea

alesj do-not-reply at jboss.com
Wed Sep 5 06:20:36 EDT 2007


"scott.stark at jboss.org" wrote : 
  | that is true and will show up when we try to do management in a profile service setup without the real deployers. The first parsing deployer AbstractParsingDeployerWithOutput. The buildManagedObject could control whether the managed object is created and the Serializable cast could be implicit rather than explicit. In the future we may want to relax the Serializable since jboss serialization does not need it.
  | 

I changed the code that you've added.
There is no need to search/find attachment in order to determine if it is Serializable.
And there was a small bug - no return on non-Serializable. ;-)

Previous code:

  |    public void build(DeploymentUnit unit, Map<String, ManagedObject> managedObjects)
  |       throws DeploymentException
  |    {
  |       if (buildManagedObject == false)
  |          return;
  | 
  |       T deployment = unit.getAttachment(getOutput());
  |       if ((deployment instanceof Serializable) == false)
  |          log.debug("Skipping ManagedObject since T("+getOutput()+") is not Serializable");
  | 
  |       Serializable instance = (Serializable) deployment;
  |       if (deployment != null)
  |       {
  |          ManagedObjectFactory factory = ManagedObjectFactoryBuilder.create();
  |          ManagedObject mo = factory.initManagedObject(instance, null, null);
  |          if (mo != null)
  |             managedObjects.put(mo.getName(), mo);
  |       }
  |    }

My fix:

  |    public void build(DeploymentUnit unit, Map<String, ManagedObject> managedObjects) throws DeploymentException
  |    {
  |       if (buildManagedObject)
  |       {
  |          // we can check for Serializable w/o searching for attachment
  |          if (Serializable.class.isAssignableFrom(getOutput()) == false)
  |          {
  |             log.debug("Skipping ManagedObject since T(" + getOutput() + ") is not Serializable");
  |             return;
  |          }
  | 
  |          T deployment = unit.getAttachment(getOutput());
  |          if (deployment != null)
  |          {
  |             // must be Serializable - see getAttachment method contract (expectedType.cast(result))
  |             Serializable instance = (Serializable) deployment;
  |             ManagedObjectFactory factory = ManagedObjectFactoryBuilder.create();
  |             ManagedObject mo = factory.initManagedObject(instance, null, null);
  |             if (mo != null)
  |                managedObjects.put(mo.getName(), mo);
  |          }
  |       }
  |    }
  | 

OK?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4081240#4081240

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4081240



More information about the jboss-dev-forums mailing list