Package org.apache.avalon.framework.service

Examples of org.apache.avalon.framework.service.ServiceManager


    public void callFunction(String className, List params, Redirector redirector) throws Exception {
        // Get the current web application context
        final WebApplicationContext webAppContext = WebAppContextUtils.getCurrentWebApplicationContext();

        // Use the current sitemap's service manager for components
        final ServiceManager sitemapManager = (ServiceManager) webAppContext.getBean(AvalonUtils.SERVICE_MANAGER_ROLE);

        AppleController app = instantiateController(className, sitemapManager);

        WebContinuation wk = null;
        if (!(app instanceof StatelessAppleController)) {
View Full Code Here


                config = createTreeProcessorConfiguration(this.servletContext);
            } catch (IOException e) {
                throw new BeanCreationException("Could not create configuration for TreeProcesoor", e);
            }

            ServiceManager serviceManager =
                (ServiceManager) this.cocoonBeanFactory.getBean(AvalonUtils.SERVICE_MANAGER_ROLE);

            // create the tree processor
            Processor processor;
            try {
View Full Code Here

            } else {
                protocol = "*";
            }
        }

        final ServiceManager m = this.getComponentLocator();

        Source source = null;
        // search for a SourceFactory implementing the protocol
        SourceFactory factory = null;
        try {
            factory = this.getSourceFactory(m, protocol);
            systemID = this.absolutize(factory, baseURI, systemID);
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Resolved to systemID : " + systemID);
            }
            source = factory.getSource(systemID, parameters);
        } catch (final ProcessingException ce) {
            // no selector available, use fallback
        } finally {
            m.release(factory);
        }

        if (null == source) {
            try {
                factory = this.getSourceFactory(m, "*");
                systemID = this.absolutize(factory, baseURI, systemID);
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Resolved to systemID : " + systemID);
                }
                source = factory.getSource(systemID, parameters);
            } catch (ProcessingException se) {
                throw new SourceException("Unable to select source factory for " + systemID, se);
            } finally {
                m.release(factory);
            }
        }

        return source;
    }
View Full Code Here

    /**
     * Get the component locator.
     */
    protected ServiceManager getComponentLocator() {
        ServiceManager l = EnvironmentHelper.getSitemapServiceManager();
        if (l == null) {
            l = this.manager;
        }
        return l;
    }
View Full Code Here

        }

        if (this.customResolver != null) {
            this.customResolver.release(source);
        } else {
            final ServiceManager m = this.getComponentLocator();

            // search for a SourceFactory implementing the protocol
            final String scheme = source.getScheme();
            SourceFactory factory = null;

            try {
                factory = this.getSourceFactory(m, scheme);
                factory.release(source);
            } catch (ProcessingException se) {
                try {
                    factory = this.getSourceFactory(m, "*");
                    factory.release(source);
                } catch (ProcessingException sse) {
                    throw new SourceFactoryNotFoundException("Unable to select source factory for " + source.getURI(), se);
                }
            } finally {
                m.release(factory);
            }
        }
    }
View Full Code Here

            if ( env == null ) {
                throw new ContextException("Unable to locate " + key + " (No environment available)");
            }
            return env.getObjectModel();
        } else if ( ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER.equals(key)) {
            final ServiceManager manager = EnvironmentHelper.getSitemapServiceManager();
            if ( manager == null ) {
                throw new ContextException("Unable to locate " + key + " (No environment available)");
            }
            return manager;
        }
View Full Code Here

        this.expression = expression;
    }

    public boolean process(XPointerContext ctx) throws SAXException, ResourceNotFoundException {
        Document document = ctx.getDocument();
        ServiceManager manager = ctx.getServiceManager();

        XPathProcessor xpathProcessor = null;
        try {
            try {
                xpathProcessor = (XPathProcessor)manager.lookup(XPathProcessor.ROLE);
            } catch (Exception e) {
                throw new SAXException("XPointerPart: error looking up XPathProcessor.", e);
            }
            NodeList nodeList = xpathProcessor.selectNodeList(document, expression, ctx);
            if (nodeList.getLength() > 0) {
                XMLConsumer consumer = ctx.getXmlConsumer();
                LocatorImpl locator = new LocatorImpl();
                locator.setSystemId(ctx.getSource().getURI());
                consumer.setDocumentLocator(locator);
                for (int i = 0; i < nodeList.getLength(); i++) {
                    DOMStreamer streamer = new DOMStreamer();
                    streamer.setNormalizeNamespaces(true);
                    streamer.setConsumer(consumer);
                    streamer.stream(nodeList.item(i));
                }
                return true;
            } else {
                if (ctx.getLogger().isDebugEnabled())
                    ctx.getLogger().debug("XPointer: expression \"" + expression + "\" gave no results.");
                return false;
            }
        } finally {
            if (xpathProcessor != null)
                manager.release(xpathProcessor);
        }
    }
View Full Code Here

    public void testContextManager() throws Exception
    {
        final Context managerContext = m_manager.getContainerManagerContext();
        assertNotNull( managerContext );

        final ServiceManager serviceManager = (ServiceManager) managerContext.get( SERVICE_MANAGER );
        assertNotNull( serviceManager );

        final InstrumentManager instrumentManager =
                (InstrumentManager) serviceManager.lookup( InstrumentManager.ROLE );
        assertNotNull( instrumentManager );
        assertSame( m_instrManager, instrumentManager );
    }
View Full Code Here

        m_componentManagerCreator = new ExcaliburComponentManagerCreator( null,
            new File( "../conf/logkit.xml" ), new File( "../conf/roles.xml" ),
            new File( "../conf/components.xml" ), new File( "../conf/instrument.xml" ) );

        // Get a reference to the service manager
        ServiceManager serviceManager = m_componentManagerCreator.getServiceManager();

        // Get a reference to the example component.
        ExampleInstrumentable instrumentable =
            (ExampleInstrumentable)serviceManager.lookup( ExampleInstrumentable.ROLE );
        try
        {
            boolean quit = false;
            while( !quit )
            {
                System.out.println( "Enter the number of times that exampleAction should be "
                                    + "called, or 'q' to quit." );
                BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
                System.out.print( " : " );
                String cntStr = in.readLine();

                // Can get a null if CTRL-C is hit.
                if( ( cntStr == null ) || ( cntStr.equalsIgnoreCase( "q" ) ) )
                {
                    quit = true;
                }
                else if( ( cntStr.equalsIgnoreCase( "gc" ) ) )
                {
                    System.gc();
                }
                else
                {
                    try
                    {
                        int concurrent = 100;
                        CyclicBarrier barrier = new CyclicBarrier( concurrent );
                        int cnt = Integer.parseInt( cntStr );
                        int average = Math.max( cnt / concurrent, 1 );

                        while( cnt > 0 )
                        {
                            Thread t = new Thread( new ActionRunner( instrumentable,
                                                                     Math.min( average, cnt ),
                                                                     barrier ) );
                            t.start();

                            if( cnt > 0 )
                            {
                                cnt -= average;
                            }

                            if( cnt < 0 )
                            {
                                cnt = 0;
                            }
                        }
                    }
                    catch( NumberFormatException e )
                    {
                    }
                }
            }
        }
        finally
        {
            // Release the component
            serviceManager.release( instrumentable );
            instrumentable = null;

            // Dispose of the ComponentManagerCreator.  It will dispose all
            //  of its own components, including the ComponentManager
            m_componentManagerCreator.dispose();
View Full Code Here

    }

    public void testThreadsafe()
        throws Exception
    {
        final ServiceManager serviceManager = getServiceManager();
        final String key = Role1.ROLE;
        final BaseRole object1 = (BaseRole) serviceManager.lookup( key );
        final BaseRole object2 = (BaseRole) serviceManager.lookup( key );

        assertSame( "Threadsafe objects (1 vs 2)", object1, object2 );
        assertEquals( "Threadsafe object IDs (1 vs 2)", object1.getID(), object2.getID() );

        final Thread thread = new Thread()
        {
            public void run()
            {
                try
                {
                    final BaseRole object3 = (BaseRole) serviceManager.lookup( key );
                    final BaseRole object4 = (BaseRole) serviceManager.lookup( key );

                    assertSame( "Threadsafe objects (1 vs 3)", object1, object3 );
                    assertEquals( "Threadsafe object IDs (1 vs 3)", object1.getID(), object3.getID() );
                    assertSame( "Threadsafe objects (2 vs 4)", object2, object4 );
                    assertEquals( "Threadsafe object IDs (2 vs 4)", object2.getID(), object4.getID() );
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.service.ServiceManager

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.