Package org.apache.avalon.framework.context

Examples of org.apache.avalon.framework.context.DefaultContext


    }
   
    public void testHiddenItems()
        throws ContextException
    {
        final DefaultContext parent = new DefaultContext();
        parent.put( "test", "test" );
        parent.makeReadOnly();
        final DefaultContext child = new DefaultContext( parent );
        child.put( "check", "check" );
        final Context context = (Context) child;
       
        assertTrue ( "check".equals( context.get( "check" ) ) );
        assertTrue ( "test".equals( context.get( "test" ) ) );
               
        child.hide( "test" );
        try
        {
            context.get( "test" );
            fail( "The item \"test\" was hidden in the child context, but could still be retrieved via get()." );
        }
        catch (ContextException ce)
        {
            // Supposed to be thrown.
        }
       
        child.makeReadOnly();
       
        try
        {
            child.hide( "test" );
            fail( "hide() did not throw an exception, even though the context is supposed to be read-only." );
        }
        catch (IllegalStateException ise)
        {
            // Supposed to be thrown.
View Full Code Here


   
    public void testEquals()
        throws Exception
    {
        // Different set of parents.
        DefaultContext p1 = new DefaultContext();
        p1.put( "test", "CoolTest" );
        DefaultContext p2 = new DefaultContext();
        p2.put( "test", "Cool Test" );
       
        DefaultContext c1 = new DefaultContext( p1 );
        DefaultContext c2 = new DefaultContext( p1 );
        DefaultContext c3 = new DefaultContext( p1 );
        DefaultContext c4 = new DefaultContext( p1 );
        DefaultContext c5 = new DefaultContext( p2 );
       
        c1.put( "test", "Cool Test" );
        c2.put( "test", "Cool Test" );
        c3.put( "test", "Cool Test" );
        c3.put( "test2", "Cool Test" );
        c4.put( "test", "Cool Test" );
        c4.makeReadOnly();
        c5.put( "test", "Cool Test" );
       
        assertEquals( "Identical", c1, c2 );
        assertTrue( "ContextData", ! c1.equals( c3 ) );
        assertTrue( "ReadOnly", ! c1.equals( c4 ) );
        assertTrue( "Parent", ! c1.equals( c5 ) );
View Full Code Here

    public void testHashcode()
        throws Exception
    {
        // Different set of parents.
        DefaultContext p1 = new DefaultContext();
        p1.put( "test", "CoolTest" );
        DefaultContext p2 = new DefaultContext();
        p2.put( "test", "Cool Test" );
       
        DefaultContext c1 = new DefaultContext( p1 );
        DefaultContext c2 = new DefaultContext( p1 );
        DefaultContext c3 = new DefaultContext( p1 );
        DefaultContext c4 = new DefaultContext( p1 );
        DefaultContext c5 = new DefaultContext( p2 );
       
        c1.put( "test", "Cool Test" );
        c2.put( "test", "Cool Test" );
        c3.put( "test", "Cool Test" );
        c3.put( "test2", "Cool Test" );
        c4.put( "test", "Cool Test" );
        c4.makeReadOnly();
        c5.put( "test", "Cool Test" );
       
        assertEquals( "Identical", c1.hashCode(), c2.hashCode() );
        assertTrue( "ContextData", c1.hashCode() != c3.hashCode() );
        assertTrue( "ReadOnly", c1.hashCode() != c4.hashCode() );
        assertTrue( "Parent", c1.hashCode() != c5.hashCode() );
    }
View Full Code Here

       
        try {
            String projectHome = ForrestConfUtils.getProjectHome();

            if(!projectHome.startsWith(ForrestConfUtils.defaultHome)){
                DefaultContext newContext = new DefaultContext(context);
                newContext.put("context-root", ForrestConfUtils.getProjectWebappHome());
                currentContext = newContext;
            }
        } catch (Exception e) {
            throw new ContextException("Error getting forrest.home java property.",e);
        }
View Full Code Here

        manager = new ExcaliburComponentManager();

        manager.setLoggerManager(lm);
        manager.enableLogging(logger);

        DefaultContext context = new DefaultContext();
        String realPath = Turbine.getRealPath("/");

        context.put(AvalonComponentService.COMPONENT_APP_ROOT, realPath);
        System.setProperty("applicationRoot", realPath);

        log.debug("Application Root is " + realPath);

        manager.contextualize(context);
View Full Code Here

            // Setup the application context with context-dir and work-dir that
            // can be used in logkit.xconf
            this.context = getDir(this.contextDir, "context");
            this.work = getDir(workDir, "working");
            DefaultContext appContext = new DefaultContext();
            appContext.put(Constants.CONTEXT_WORK_DIR, work);

            this.logManager = new LogKitLoggerManager(hierarchy);
            this.logManager.enableLogging(log);

            if (this.logKit != null) {
                final FileInputStream fis = new FileInputStream(logKit);
                final DefaultConfigurationBuilder builder =
                    new DefaultConfigurationBuilder();
                final Configuration logKitConf = builder.build(fis);
                final DefaultContext subcontext = new DefaultContext(appContext);
                subcontext.put("context-root", this.contextDir);
                subcontext.put("context-work", this.workDir);
                this.logManager.contextualize(subcontext);
                this.logManager.configure(logKitConf);
                if (logger != null) {
                    log = this.logManager.getLoggerForCategory(logger);
                } else {
View Full Code Here

            ( new LogTarget[]
            {new StreamTarget( System.out, new PatternFormatter( pattern ) )} );
        logger.setPriority( Priority.INFO );

        m_manager.enableLogging( new LogKitLogger( logger ) );
        m_manager.contextualize( new DefaultContext() );
        m_manager.configure( new DefaultConfiguration( "", "" ) );

        m_logger = new LogKitLogger( logger );
    }
View Full Code Here

        throws Exception
    {
        FullLifecycleComponent component = new FullLifecycleComponent();

        component.enableLogging( new NullLogger() );
        component.contextualize( new DefaultContext() );
        component.service( new DefaultServiceManager() );
        component.configure( new DefaultConfiguration( "", "" ) );
        component.parameterize( new Parameters() );
        component.initialize();
        component.start();
View Full Code Here

    {
        FullLifecycleComponent component = new FullLifecycleComponent();

        try
        {
            component.contextualize( new DefaultContext() );
        }
        catch( Exception e )
        {
            return;
        }
View Full Code Here

        throws Exception
    {
        FullLifecycleComponent component = new FullLifecycleComponent();

        component.enableLogging( new NullLogger() );
        component.contextualize( new DefaultContext() );
        try
        {
            component.initialize();
            component.parameterize( new Parameters() );
        }
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.context.DefaultContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.