Yo!
hi stephen,
After adding the model via something like the model.addContainmentModel( url ) operation or as your describing above - what you have is a new sub-model within the container - however, the sub-model isn't wired-up yet. Once you have added all of the models you want you need to commission the model. Commissioning the model results in the automatic assembly (wiring) of consumer components with provider components and so on. Once commissioned you can safely proceed with component instantiation.
For example for a container:
ContainmentModel model = kernel.getModel(); ContainmentModel test = model.addContainmentModel( myBlockUrl ); test.commission();
Commissioning of a container results in the automatic deployment of any components that have startup policy set to true, or any components implied by the consequence of assembly.
With a commissioned container you can go ahead and access actual component models from the container, create new component instances, etc. The dynamics tutorial contains details on how to do this, including dynamic re-configuration of component models and so on.
i tried to merge some lines from the dynamics tutorial:
InitialContextFactory initial = new DefaultInitialContextFactory("merlin");
File home = initial.getHomeDirectory(); initial.setCacheDirectory(new File(home, "system")); InitialContext context = initial.createInitialContext();
String spec = "artifact:merlin/merlin-impl#3.3.0"; Artifact artifact = Artifact.createArtifact(spec); Builder builder = context.newBuilder(artifact);
Factory factory = builder.getFactory(); Map criteria = factory.createDefaultCriteria(); criteria.put("merlin.deployment", new String[] { "bin"});
The above line looks like a problem in the making. The "merlin.deployment" property is used when you want to add a set of blocks via properties (the merlin.deployment should be a comma separated set of block urls). But for the purposes of this example - its not needed because your adding a block url explicitly a few lines down.
Instead you may want to replace the line with the following criteria modifiers.
criteria.put( "merlin.debug", "true" ); criteria.put( "merlin.info", "true" );
DefaultKernel kernel = (DefaultKernel) factory.create(criteria);
So assuming you have removed the merlin.deployment line, the result of the above would be an empty root container.
ContainmentModel containmentModel = kernel.getModel(); // URL blockURL = new URL("file:bin/BLOCK-INF/block.xml"); // ContainmentModel block = containmentModel.addContainmentModel(blockURL); // <====== EXCEPTION 2 // block.commission();
You need to add something to your container - so I recommend you uncomment the comments . Basically all that is happening is that your getting a reference to the root model, and requesting the addition of a sub-container based on the block referenced by the url.
ContainmentModel containmentModel = kernel.getModel(); URL blockURL = new URL("file:bin/BLOCK-INF/block.xml"); ContainmentModel block = containmentModel.addContainmentModel(blockURL);
With the debug policy turned on you should see some messages about the registration of component types (whatever is in the supplied block.xml). If the next step produces errors then its very probably an issue with the contents of the block.
block.commission();
Just for reference - can you post the content of block.xml and any exception you get.
Cheers, Stephen.
--
|---------------------------------------| | Magic by Merlin | | Production by Avalon | | | | http://avalon.apache.org | |---------------------------------------|
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]