Package org.apache.avalon.framework.service

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


        if ( connection == null ) {
            throw new RuntimeException("Connection configuration is missing for " + this.getClass().getName() + "." +
                    " Have a look at the iBatis sqlMapConfig and check the 'connection' property for the data source.");
        }
        // get the component manager
        final ServiceManager manager = EnvironmentHelper.getSitemapServiceManager();
        if ( manager == null ) {
            throw new RuntimeException("Cocoon sitemap service manager is not available for " + this.getClass().getName() + "." +
            " Make sure that you're initializing iBatis during an active request and not on startup.");           
        }
        try {
            this.datasource = (DataSourceComponent)manager.lookup(DataSourceComponent.ROLE + '/' + connection);
        } catch (ServiceException e) {
            throw new CascadingRuntimeException("Unable to lookup data source with name " + connection + "." +
                    " Check the cocoon.xconf and the iBatis sqlMapConfig.", e);               
        }
    }
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

     *
     * @throws Exception when there is an error.
     */
    protected void initializeServiceManager() throws Exception
    {
        final ServiceManager parent = (ServiceManager) get( m_rootContext, SERVICE_MANAGER, null );
        final DefaultServiceManager manager = new EAServiceManager( parent, getLogger().getChildLogger("compat") );

        /**
         * If there is a parent ServiceManager, we need to see if it has a SourceResolver,
         * and if not, make sure that one is available to fortress
         */

        if ( parent == null || !parent.hasService( SourceResolver.ROLE ) )
        {
            manager.put( SourceResolver.ROLE, m_defaultSourceResolver );
        }

        Object lem = get( m_rootContext, LifecycleExtensionManager.ROLE, null);
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

        throws Exception
    {
        final String key = Role3.ROLE;
        final String type = "PerThread";

        final ServiceManager serviceManager = getServiceManager();
        final BaseRole object1 = (BaseRole) serviceManager.lookup( key );
        final BaseRole object2 = (BaseRole) serviceManager.lookup( key );

        assertEquals( type + " 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 );

                    assertTrue( type + " object IDs (1 vs 3)", object1.getID() != object3.getID() );
                    assertTrue( type + " object IDs (2 vs 4)", object2.getID() != object4.getID() );
                    assertEquals( type + " object IDs (3 vs 4)", object3.getID(), object4.getID() );
                }
View Full Code Here

        throws Exception
    {
        final String key = Role4.ROLE;
        final String type = "Factory";

        final ServiceManager serviceManager = getServiceManager();
        final BaseRole object1 = (BaseRole) serviceManager.lookup( key );
        final BaseRole object2 = (BaseRole) serviceManager.lookup( key );

        assertTrue( type + " 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 );

                    assertTrue( type + " object IDs (1 vs 3)", object1.getID() != object3.getID() );
                    assertTrue( type + " object IDs (2 vs 4)", object2.getID() != object4.getID() );
                    assertTrue( type + " object IDs (3 vs 4)", object3.getID() != object4.getID() );
                }
View Full Code Here

    }

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

        serviceManager.release( object1 );
        serviceManager.release( object2 );
        serviceManager.release( object3 );
    }
View Full Code Here

        final ContainerManager cm = new DefaultContainerManager( config.getContext() );
        ContainerUtil.initialize( cm );

        final DefaultContainer container = (DefaultContainer) cm.getContainer();
        final ServiceManager serviceManager = container.getServiceManager();
        return serviceManager;
    }
View Full Code Here

            DocumentFragment domTemplate = null;

            String src = DomHelper.getAttribute(bindingElm, "src", null);
            if (src != null) {
                ServiceManager manager = assistant.getServiceManager();
                SourceResolver sourceResolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
                Source source = null;
                try {
                    source = sourceResolver.resolveURI(src);
                    Document document = SourceUtil.toDOM(source);
                    Element element = document.getDocumentElement();

                    String xpath = DomHelper.getAttribute(bindingElm, "xpath", null);
                    if (xpath != null) {
                        XPathProcessor xpathProcessor = (XPathProcessor)manager.lookup(XPathProcessor.ROLE);
                        try {
                            Node node = xpathProcessor.selectSingleNode(document, xpath);
                            if (node == null)
                                throw new BindingException("XPath expression \"" + xpath + "\" didn't return a result.");
                            if (!(node instanceof Element))
                                throw new BindingException("XPath expression \"" + xpath + "\" did not return an element node.");
                            element = (Element)node;
                        } finally {
                            manager.release(xpathProcessor);
                        }
                    }
                    domTemplate = document.createDocumentFragment();
                    domTemplate.appendChild(element);
                } finally {
                    if (source != null) {
                        sourceResolver.release(source);
                    }
                    manager.release(sourceResolver);
                }
            } else if(bindingElm.hasChildNodes()) {
                // FIXME: using the binding's document prevents it to be garbage collected.
                //        --> create a new Document and use doc.importNode();
                domTemplate = bindingElm.getOwnerDocument().createDocumentFragment();
View Full Code Here

  /**
   * @see org.apache.excalibur.source.Source#getInputStream()
   */
  public InputStream getInputStream() throws IOException, SourceNotFoundException {
        try {
            ServiceManager sitemapManager = (ServiceManager) this.context.get(ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER);
            ServiceSelector serializerSelector = null;
            Serializer serializer = null;
            try {
                serializerSelector = (ServiceSelector) sitemapManager.lookup(Serializer.ROLE+"Selector");
                serializer = (Serializer) serializerSelector.select("xml");
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                serializer.setOutputStream(os);
                this.toSAX(serializer);
                return new ByteArrayInputStream(os.toByteArray());
            } catch (SAXException se) {
                throw new CascadingIOException("Unable to stream content.", se);
            } catch (ServiceException ce) {
                throw new CascadingIOException("Unable to get components for serializing.", ce);
            } finally {
                if ( serializer != null ) {
                    serializerSelector.release(serializer);
                }
                sitemapManager.release(serializerSelector);
            }
        } catch (ContextException ce) {
            throw new CascadingIOException("Unable to get service manager.", ce);
        }
  }
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.