Hi Eduardo Lobo, I'm interested if you can copy this comment into the
"Howtos" of the forum: http://www.tapestryforums.com/
TapestryForums, was made to keep this kind of good solutions instead
of leaving it as a comment at the mailing list by Tapestry users and
developers and be able to find them faster.
Thank you.
On 4/27/05, Eduardo Lobo <[EMAIL PROTECTED]> wrote:
>
> Originally I had a problem to load specification files(.page) at runtime
> located in external JAR files.
>
> Finally I found a solution by myself, if somebody is interested in it
> here is.
>
> First, you must extends the ApplicationServlet class overloading the
> createResourceResolver() method to return your own IResourceResolver
> implementation.
> (Of course you must use this new servlet class for your Tapestry
> application).
> <!-- Sample -->
> <servlet>
> <servlet-name>app</servlet-name>
> <servlet-class>com.project.web.SiteManagerServlet</servlet-class>
> </servlet>
>
> Here is my IResourceResolver implementation:
>
> public class MyResourceResolver extends DefaultResourceResolver {
>
> private ClassLoader currentLoader;
> private ClassLoader parentLoader;
>
> public MyResourceResolver () {
> currentLoader = Thread.currentThread().getContextClassLoader();
> parentLoader =
> Thread.currentThread().getContextClassLoader().getParent();
> }
>
> public MyResourceResolver (ClassLoader loader) {
> currentLoader = loader;
> parentLoader = loader.getParent();
> }
>
> public URL getResource(String name){
>
> String stripped = removeLeadingSlash(name);
>
> URL result = currentLoader.getResource(stripped);
> if(result == null){
> result = parentLoader.getResource(stripped);
> }
>
> return result;
> }
>
> private String removeLeadingSlash(String name){
>
> while (name.startsWith("/")) {
> return name.substring(1);
> }
>
> return name;
> }
>
> public Class findClass(String name)
> {
> try
> {
> Class clazz = Class.forName(name, true, currentLoader);
> if(clazz == null){
> clazz = Class.forName(name, true, parentLoader);
> }
>
> return clazz;
> }
> catch (Throwable t)
> {
> throw new ApplicationRuntimeException(
> Tapestry.format("ResourceResolver.unable-to-load-class",
> name, currentLoader, t.getMessage()),
> t);
> }
> }
>
> public Class classForName(String name, Map map) throws
> ClassNotFoundException
> {
> return findClass(name);
> }
>
> public ClassLoader getClassLoader()
> {
> return currentLoader;
> }
>
> }
>
> Library file sample (external JAR):
>
> <library-specification>
> <page name="SamplePage" specification-path="SamplePage.page"/>
> .....
> <library-specification>
>
> Loader:
>
> ISpecificationSource spec = getEngine().getSpecificationSource();
> IApplicationSpecification app = getEngine().getSpecification();
>
> IResourceLocation location =
> new
> ClasspathResourceLocation(getEngine().getResourceResolver(),
> "com/project/sample.library");
>
> ILibrarySpecification ls =
> getEngine().getSpecificationSource().getLibrarySpecification(location);
> INamespace namespace = spec.getApplicationNamespace();
>
> Iterator it = ls.getPageNames().iterator();
>
> while(it.hasNext()){
> String name = (String) it.next();
> String path = ls.getPageSpecificationPath(name);
>
> try{
>
> IResourceLocation loc =
> new
> ClasspathResourceLocation(getEngine().getResourceResolver(),
> "com/project/" + path); // the .page files
> are located in the same package of the .library file
>
> IComponentSpecification component =
> getEngine().getSpecificationSource().getPageSpecification(loc);
>
> namespace.installPageSpecification(name, component);
>
> } catch(Exception e){
> logger.debug("installing exception: " + e.getMessage());
> }
> }
>
> Eduardo Lobo wrote:
>
> >
> > Hi,
> >
> > I'm making an application that needs to load war files as plugins for
> > the tapestry application to load them without making a new deploy or
> > restarting the application server
> >
> > Does anybody knows how to load pages at runtime, or another way to do
> > this?
> >
> > Thanks in advance.
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]