avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aseem Bansal" <as...@in.fiorano.com>
Subject Merlin:: How to create/add new components dynamically
Date Fri, 09 Apr 2004 22:45:55 GMT

I am facing some problem in creating/adding new components in Merlin. 

I have a component named Mycomponent which is already deployed in the container and wants
to create/add new components dynamically. I guess the only way to add is to use the merlin
composition APIs. (In case there is some other approach, let us know)

Here are the steps which i am trying to do in my MyComponent. 

- Get the Containment model from the container.  (using context.get("urn:composition:containment.model"

- Create a Component Model 

    - Create an instance of DefaultComponentModel. But the problem is i don't how to create
it should it. :)

- Add it to the containment model.

Here is the relevant code 

        // get the containment model
        ContainmentModel model = (ContainmentModel) context.get("urn:composition:containment.model"

       // To create a new component model, I need to have Component context (which in turn
requires logger, system context, classloader, container dependency graph, parent containment
model, component deployment profile, component type) and a security context. 

        // get the logger
       Logger logger = model.getLogger();
       /** @todo how to get the System context */
       // get the loader
       ClassLoader loader = model.getClassLoaderModel().getClassLoader();

        // dependency graph
       DependencyGraph graph = new DependencyGraph();

        // component profile
       ComponentProfile profile = new ComponentProfile(name,Myclass.class.getName());

      // construct component type   
       Type type = new TypeBuilder().buildType(Myclass.class);

      // construct a component context
     DefaultComponentContext ctx = new DefaultComponentContext(logger, name, null,
              loader, graph, model, profile, type, MyClass.class, home, temp,

     // construct a security model
      DefaultSecurityModel securityModel = new DefaultSecurityModel();

    // construct a component model
     DefaultComponentModel dm = new DefaultComponentModel(ctx,securityModel);

    // add the model to the container


The above code is throwing null pointer exception as system context is null. So please tell
me how can i get an instance of system context.


Fiorano MailServer
All incoming and outgoing mails are scanned for Virus and Spam

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message