You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Aseem Bansal <as...@in.fiorano.com> on 2004/04/10 00:45:55 UTC
Merlin:: How to create/add new components dynamically
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
Re: Merlin:: How to create/add new components dynamically
Posted by Stephen McConnell <mc...@apache.org>.
Aseem Bansal wrote:
> 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. :)
>
It's much simpler than that.
You need to invoke ContainmentModel.addModel( ... ). This operation
ComponentProfile profile =
new ComponentProfile(name,Myclass.class.getName());
DeploymentModel model =
m_containmentModel.addModel( profile );
Cheers, Stephen.
--
|------------------------------------------------|
| Magic by Merlin |
| Production by Avalon |
| |
| http://avalon.apache.org/merlin |
| http://dpml.net/merlin/distributions/latest |
|------------------------------------------------|
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org