Package org.apache.avalon.framework.context

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


     * A method addContext(DefaultContext context) is called here to enable subclasses
     * to put additional objects into the context programmatically.
     */
    final private Context setupContext( final Configuration conf )
    throws Exception {
        final DefaultContext context = new DefaultContext();
        final Configuration[] confs = conf.getChildren( "entry" );
        for (int i = 0; i < confs.length; i++) {
            final String key = confs[i].getAttribute("name");
            final String value = confs[i].getAttribute("value", null);
            if (value == null) {
                String clazz = confs[i].getAttribute("class");
                Object obj = getClass().getClassLoader().loadClass(clazz).newInstance();
                context.put(key, obj);
                if (getLogger().isInfoEnabled()) {
                    getLogger().info("ContainerTestCase: added an instance of class " + clazz + " to context entry " + key);
                }
            } else {
                context.put(key, value);
                if (getLogger().isInfoEnabled()) {
                    getLogger().info("ContainerTestCase: added value \"" + value + "\" to context entry " + key);
                }
            }
        }
View Full Code Here


        final Logger logger = new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""));

        final LogKitLoggerManager logKitLoggerManager = new LogKitLoggerManager(defaultHierarchy);
        logKitLoggerManager.enableLogging(logger);

        final DefaultContext subcontext = new DefaultContext();
        subcontext.put(Constants.CONTEXT_WORK_DIR, workDir);
        subcontext.put("portlet-context", this.portletContext);
        if (this.portletContextPath == null) {
            File logSCDir = new File(this.workDir, "log");
            logSCDir.mkdirs();
            if (getLogger().isWarnEnabled()) {
                getLogger().warn("Setting context-root for LogKit to " + logSCDir);
            }
            subcontext.put("context-root", logSCDir.toString());
        } else {
            subcontext.put("context-root", this.portletContextPath);
        }

        try {
            logKitLoggerManager.contextualize(subcontext);
View Full Code Here

                    getInterpreterID(), this);
            if (getLogger().isDebugEnabled())
                getLogger().debug("Instantiated a stateful apple, continuationid = " + wk.getId());
        }

        DefaultContext appleContext = new DefaultContext(avalonContext);
        if (wk != null) {
        appleContext.put("continuation-id", wk.getId());
        }
       
        LifecycleHelper.setupComponent( app, getLogger(), appleContext,
                                        this.serviceManager, new WrapperComponentManager(this.serviceManager)
                                        null, null, true);
View Full Code Here

        final LoggerManager loggerManager =
                newLoggerManager(loggerManagerClass, defaultHierarchy);
        ContainerUtil.enableLogging(loggerManager, logger);

        final DefaultContext subcontext = new DefaultContext(this.appContext);
        subcontext.put("portlet-context", this.portletContext);
        if (this.portletContextPath == null) {
            File logSCDir = new File(this.workDir, "log");
            logSCDir.mkdirs();
            if (getLogger().isWarnEnabled()) {
                getLogger().warn("Setting context-root for LogKit to " + logSCDir);
            }
            subcontext.put("context-root", logSCDir.toString());
        } else {
            subcontext.put("context-root", this.portletContextPath);
        }

        try {
            ContainerUtil.contextualize(loggerManager, subcontext);
            this.loggerManager = loggerManager;
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

    }

    public void testAddContext()
        throws Exception
    {
        final DefaultContext context = new DefaultContext();
        context.put( "key1", "value1" );
        assertTrue( "value1".equals( context.get( "key1" ) ) );
        context.put( "key1", "" );
        assertTrue( "".equals( context.get( "key1" ) ) );

        context.put( "key1", "value1" );
        context.makeReadOnly();

        try
        {
            context.put( "key1", "" );
            throw new AssertionFailedError( "You are not allowed to change a value after it has been made read only" );
        }
        catch ( IllegalStateException ise )
        {
            assertTrue( "Value is null", "value1".equals( context.get( "key1" ) ) );
        }
    }
View Full Code Here

    }

    public void testResolveableObject()
        throws ContextException
    {
        final DefaultContext context = new DefaultContext();
        context.put( "key1", new ResolvableString() );
        context.put( "test", "Cool Test" );
        context.makeReadOnly();

        final Context newContext = (Context) context;
        assertTrue( "Cool Test".equals( newContext.get( "test" ) ) );
        assertTrue( ! "This is a ${test}.".equals( newContext.get( "key1" ) ) );
        assertTrue( "This is a Cool Test.".equals( newContext.get( "key1" ) ) );
View Full Code Here

    }

    public void testCascadingContext()
         throws ContextException
    {
        final DefaultContext parent = new DefaultContext();
        parent.put( "test", "ok test" );
        parent.makeReadOnly();
        final DefaultContext child = new DefaultContext( parent );
        child.put( "check", new ResolvableString("This is an ${test}.") );
        child.makeReadOnly();
        final Context context = (Context) child;

        assertTrue ( "ok test".equals( context.get( "test" ) ) );
        assertTrue ( ! "This is an ${test}.".equals( context.get( "check" ) ) );
        assertTrue ( "This is an ok test.".equals( context.get( "check" ) ) );
View Full Code Here

    }
   
    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

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.