I use a class named Init with a static method on it to get my singleton
registry.

See the attached file.



On Sun, 2006-07-23 at 01:42 +0200, Martin Strand wrote:
> Is it possible to get a reference to the current thread's Registry? This  
> old post suggests it's not possible (yet), is that correct?
> http://mail-archives.apache.org/mod_mbox/jakarta-hivemind-user/200509.mbox/[EMAIL
>  PROTECTED]
> 
> Martin
Title: Init.java
Init.java

/* 
 * Copyright (c) 2005 Altos Research LLC. All Rights Reserved. 
 */ 
package com.altosresearch; 
 
import com.altosresearch.web.AltosServlet; 
import org.apache.hivemind.ClassResolver; 
import org.apache.hivemind.ErrorHandler; 
import org.apache.hivemind.Registry; 
import org.apache.hivemind.Resource; 
import org.apache.hivemind.impl.DefaultClassResolver; 
import org.apache.hivemind.impl.RegistryBuilder; 
import org.apache.hivemind.impl.StrictErrorHandler; 
import org.apache.hivemind.impl.XmlModuleDescriptorProvider; 
import org.apache.hivemind.util.URLResource; 
import org.apache.log4j.Logger; 
 
import java.net.URL; 
import java.util.Locale; 
 
public class Init { 
 
    private static Registry sRegistry; 
    private static ClassResolver sResolver; 
    private static Logger sLogger = Logger.getLogger( Init.class ); 
 
 
    private static void addModuleIfExists( RegistryBuilder builder, String path ) { 
 
        Resource r = null; 
        try { 
            //Init.class.getResource( path ); 
            URL url = "">class.getResource( path ); 
            r = new URLResource( url ); 
            if ( r.getResourceURL() == null ) 
                return; 
 
        } catch ( Exception e ) { 
            sLogger.error( "Exception thrown loading resource for hivemind with path: " + path, e ); 
            return; 
        } 
 
        builder.addModuleDescriptorProvider( new XmlModuleDescriptorProvider( sResolver, r ) ); 
    } 
 
    public static Registry getRegistry() { 
        if ( sRegistry == null ) { 
            sRegistry = AltosServlet.getRegistry(); 
            if ( sRegistry == null ) { 
                ErrorHandler errorHandler = new StrictErrorHandler(); 
                sResolver = new DefaultClassResolver(); 
 
                RegistryBuilder builder = new RegistryBuilder( errorHandler ); 
 
                builder.addModuleDescriptorProvider( new XmlModuleDescriptorProvider( sResolver ) ); 
 
                addModuleIfExists( builder, "/hivemodule.xml" ); 
 
                sRegistry = builder.constructRegistry( Locale.getDefault() ); 
 
            } 
        } 
        return sRegistry; 
    } 
 
} 

Reply via email to