> What's with the parameter in the constructor? What does that do?
The parameter in the first constructor in this example:
InitialContextFactory initial =
new DefaultInitialContextFactory( "merlin" );
Ok - the string "merlin" defines an application namespace (which is a
bit a fancy way of saying that things are established relative to this
name). In particular, properties are loaded using:
[name].properties
In the above example [name] is "merlin" so the property files located
are based on the name "merlin.properties". If you change the argument
to "demo" then the properties files located would be "demo.properties".
One more thing - the [name] is used to attempt to resolve a home
envi9ronment variable. For example, "merlin" will result in the attempt
to locate %MELRIN_HOME%\merlin.properties.
> 30 <initial.setHosts( new String[0] );
> What's this for? Why would we set this to an empty array?
> Simply for initialization? This seems rather strange to me.
In the example we simply wanted to ensure that the demo example not
reaching out to any remote hosts (which causes some people problems when
building off-line).
> 45 <String spec = "@MERLIN-IMPL-SPEC@";
> 46 <Artifact artifact = Artifact.createArtifact( spec );
> 47 <Builder builder = context.newBuilder( artifact );
>
> I'm not getting this spec thing... I want to create my own component
> as an artifact. Isn't this where I would do it? How would I name it?
> I'm fine with "name" and "version", but where does "group" come from?
>
>
> Concretely, if my component's name is fooComponent, how do I create
> an artifact out of my component to get things rolling?
>
> Or am I missing the point entirely?
:-)
The artifact that your referring to is the merlin system. Keep in mind
that the initial context stuff does not know anything about merlin but
it does not about a plugin architecture. Relative to the initial
context, merlin is just a plugin but to load the plugin the context
needs to find the definition of the plugin - and that's what the
artifact is referring to. You component is not in scope here. Instead
it comes into scope when you declare a deployment target (block, jar,
etc.) as a factory parameter or if you dynamically add container
definitions to a root container.
For example, if you did the following:
criteria.put( "merlin.deployment", " your-container-defintion.block "
);
and if your-container-defintion.block declares you component - then your
in business.
Cheers, Steve.
-----Original Message-----
From: David Leangen [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 20, 2004 3:46 PM
To: [EMAIL PROTECTED]
Subject: Embedding - howto
First, I'd like to thank everyone who has been so helpful in the last
few
days... especially Steve!
Now, I'd like to ask another series of questions. I'm now at the point
where
I would like to embed what I've done into an application. I have looked
at
the samples, but there are obviously a few concepts that I'm lacking.
If we go through the lines one by one in the examples, noting that if we
do
a primitive kind of "diff" between the tutorial main example and the
example
on the website (">" refers to the website, while "<" refers to the
tutorial):
01 //
02 // Create the initial context factory. This establishes
03 // the application group from which properties will
04 // be resolved. It also provides operations supporting
05 // customization of the application environment.
06 //
07
08 >InitialContextFactory initial =
09 > new DefaultInitialContextFactory( "merlin" );
Explanation of context is here:
http://avalon.apache.org/products/runtime/reference/component/artifacts/
cont
ext.html
Javadoc for this concrete constructor is here:
http://avalon.apache.org/avalon/runtime/3.3.0/impl/org/apache/avalon/rep
osit
ory/main/DefaultInitialContextFactory.html#DefaultInitialContextFactory(
java
.lang.String)
However, I don't quite get what happens here. I understand that the
context
is creating, well, the context for the component. I can see in the
Javadoc
for InitialContext that this hold values for the repository, cache, and
other useful objects. Javadoc is here:
http://avalon.apache.org/avalon/runtime/3.3.0/spi/org/apache/avalon/repo
sito
ry/provider/InitialContext.html
What's with the parameter in the constructor? What does that do?
10 >File home = initial.getHomeDirectory();
21 >initial.setCacheDirectory( new File( home, "system" ) );
22 >InitialContext context = initial.createInitialContext();
23
24 <String cache = System.getProperty( "project.cache" );
25 <
26 <InitialContextFactory initial =
27 < new DefaultInitialContextFactory( "demo" );
28 <File home = initial.getHomeDirectory();
29 <initial.setCacheDirectory( new File( cache ) );
30 <initial.setHosts( new String[0] );
What's this for? Why would we set this to an empty array? Simply for
initialization? This seems rather strange to me.
31 <InitialContext context = initial.createInitialContext();
32
33 //
34 // Using the initial context we can now load any repository
35 // application using an artifact specification. Meta
36 // information associated with the artifact is used to
37 // construct the classloader that the application needs in
38 // order to execute.
39 //
40
41 >String spec =
@artifact:jar:avalon/merlin/avalon-merlin-impl#SNAPSHOT@;
42 >Artifact artifact = Artifact.createArtifact( spec );
43 >Builder builder = context.newBuilder( artifact );
44
45 <String spec = "@MERLIN-IMPL-SPEC@";
46 <Artifact artifact = Artifact.createArtifact( spec );
47 <Builder builder = context.newBuilder( artifact );
I'm not getting this spec thing... I want to create my own component as
an
artifact. Isn't this where I would do it? How would I name it? I'm fine
with
"name" and "version", but where does "group" come from?
Concretely, if my component's name is fooComponent, how do I create an
artifact out of my component to get things rolling?
Or am I missing the point entirely?
48
49 //
50 // With the classloader established we can go ahead and
51 // and get the application factory. The factory has already
52 // been parameterized with defaults derived from properties
53 // based on the application group. We can provide
54 // overriding values by setting the factory criteria to
55 // application specific values following which we instantiate
56 // the application.
57 //
58
59 >Factory factory = builder.getFactory();
60 >Map criteria = factory.createDefaultCriteria();
61 >factory.create( criteria );
62
63 <Factory factory = builder.getFactory();
64 <Map criteria = factory.createDefaultCriteria();
65 <criteria.put( "merlin.server", "false" );
66 <criteria.put( "merlin.repository", cache );
67 <Object kernel = factory.create( criteria );
68 <
69 <System.out.println( "Kernel established." );
70 <
71 <Method shutdown = kernel.getClass().getMethod( "shutdown",
new
Class[0] );
72 <shutdown.invoke( kernel, new Object[0] );
73 <
74 <System.out.println( "Shutdown complete." );
I kinda got lost at this point. I can see that the concrete
implementations
are determined at runtime, but I don't see what's getting built here and
how
to use the parameters to build whatever it is we're building.
Any enlightenment would be greatly appreciated.
Thanks !
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]