Hi, 

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,
              "test");

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

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

    // add the model to the container
      model.addModel(dm);

*************************************************************************************************************************************

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.

-Aseem

Fiorano MailServer
All incoming and outgoing mails are scanned for Virus and Spam
http://www.fiorano.com

Reply via email to