RE: Embedding Merlin in Main method
S V Subramonian <[email protected]>
| Newsgroups | gmane.comp.jakarta.avalon.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Steve,
I am trying to do the following. Please let me know
what could be the better way for achiving this.
All the examples that I looked at are executing all
the components while running Merlin from command line,
instaed I am looking for an example that executes a
given component name. In other words, I was not able
to find an example that triggers an event that
executes a component.
I browsed through Merlin website and source code and
found "Embedding Merlin in a Main method" and an
AbstractMerlinTestCase class that has a method
resolve. I thought of using this approach to execute a
given component name.
For your information, My component "/tahiti/simple" is
getting executed when I run using the Merlin command
line , with the same environment that I tried the
"Embedding Merlin in a Main method". I have attached a
file that conatins code snippets which I used for
testing.
Is my approach correct or do you have any other idea.
Could you please help me with this.
For your quick reference here is the code snippet
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
public static void main(String[] args) {
ClassLoader classloader =
Framework.class.getClassLoader();
File repository = new File( getMavenHome(),
"repository" );
File basedir = getBaseDirectory();
Map criteria = null;
org.apache.avalon.repository.provider.Factory
factory = null;
try {
Artifact artifact =
DefaultBuilder.createImplementationArtifact(
classloader,
getMerlinHome(),
basedir,
MERLIN_PROPERTIES,
IMPLEMENTATION_KEY );
InitialContextFactory icFactory =
new DefaultInitialContextFactory( "merlin",
basedir );
icFactory.setCacheDirectory( repository );
InitialContext context =
icFactory.createInitialContext();
Builder builder = new DefaultBuilder( context,
artifact );
m_classloader = builder.getClassLoader();
factory = builder.getFactory();
criteria = factory.createDefaultCriteria();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// go ahead with the deployment of the
kernel
//
try {
m_kernel = factory.create( criteria );
m_shutdown =
m_kernel.getClass().getMethod(
"shutdown",
new Class[0] );
Method method =
m_kernel.getClass().getMethod(
"getModel",
new Class[0] );
m_root = method.invoke( m_kernel, new Object[0] );
m_locate =
m_root.getClass().getMethod(
"getModel",
new Class[]{ String.class } );
Class modelClass =
m_classloader.loadClass(
DEPLOYMENT_MODEL_CLASSNAME );
m_resolve =
modelClass.getMethod( "resolve", new Class[0] );
initialized = true;
} catch (SecurityException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
} catch (IllegalArgumentException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
} catch (NoSuchMethodException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
} catch (IllegalAccessException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
} catch (InvocationTargetException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
} catch (ClassNotFoundException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
} catch (Exception e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
}
public Object resolve( String path ) throws
Exception
{
if( null == m_kernel )
throw new IllegalStateException( "kernel
does not exist" );
try
{
Object model = m_locate.invoke( m_root,
new Object[]{ path } );
return m_resolve.invoke( model, new
Object[0] );
}
catch( InvocationTargetException ite )
{
Throwable cause =
ite.getTargetException();
final String error =
ExceptionHelper.packException( cause, true );
throw new Exception( error );
}
catch( Throwable e )
{
final String error =
ExceptionHelper.packException( e, true );
throw new Exception( error );
}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
regards,
Subbu
--- Stephen McConnell <[email protected]> wrote:
>
>
> From the following we can see that your deployment
> scenario is
> presumable defined within the kernel because your
> not declaring any
> deployment targets.
>
>
> > ${merlin.kernel} ==
> file:/D:/merlin/config/kernel.xml
> > ${merlin.deployment} ==
>
>
> Later on in the trace we can see that your
> classloader definition isn't
> adding much - in fact it not adding anything in the
> classpath, and
> reasonably there are no component types located.
>
>
> > [DEBUG ] (classloader): base: ${merlin.dir}
> > [DEBUG ] (classloader): classpath:
> > [DEBUG ] (classloader.types): type install count:
> 0
> > [DEBUG ] (classloader.types): type registration
> complete
>
>
> Moving on with what is in effect an empty container
> ...
>
> > [DEBUG ] (kernel): state: initializing
> > [DEBUG ] (kernel): kernel established
> > [DEBUG ] (kernel): state: initialized
> > [DEBUG ] (kernel): install phase
> > [DEBUG ] (kernel): customize phase
> > [DEBUG ] (kernel): startup phase
> > [DEBUG ] (kernel): application assembly
> > [DEBUG ] (kernel): state: assembly
> > [DEBUG ] (): assembly phase
> > [DEBUG ] (kernel): application deployment
> > [DEBUG ] (kernel): state: deployment
> > [DEBUG ] (kernel): state: started
> > Calling HelloWorld in Test
> > [DEBUG ] (): Can't find 'tahiti' in model
> repository:
> > {}
> > java.lang.Exception: ---- runtime exception report
> > --------------------------------------------------
> > Exception: java.lang.IllegalArgumentException
> > Message: Unable to locate a container with name
> > [tahiti] within the container [[/]].
>
> Which is a perfectly reasonable situation - you're
> asking for a
> component that does not exist.
>
> Can we roll back a bit here and provide a summary of
> what exactly are
> you trying to do (sorry if you have already provided
> this info). Anyway
> - seems to me you may be going about it the wrong
> way.
>
> Stephen.
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [email protected]
> For additional commands, e-mail:
> [email protected]
>
>
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail