Package org.apache.avalon.framework.component

Examples of org.apache.avalon.framework.component.ComponentSelector


        }

        // Release transformers
        int size = this.transformerSelectors.size();
        for (int i = 0; i < size; i++) {
            final ComponentSelector selector =
                (ComponentSelector)this.transformerSelectors.get(i);
            selector.release( (Component)this.transformers.get(i) );
            this.newManager.release( selector );
        }
        this.transformerSelectors.clear();
        this.transformers.clear();
        this.transformerParams.clear();
View Full Code Here


    /**
     * Obtain values from the used InputModule.
     */
    private Object[] getValues(String name) {
        Object[] values = null;
        ComponentSelector iputSelector = null;
        InputModule iput = null;
        try {
            if (this.input != null) {
                // input module is thread safe
                // thus we still have a reference to it
                values = input.getAttributeValues(name,this.inputConf,objectModel);
                if (getLogger().isDebugEnabled())
                    getLogger().debug("cached module "+this.input+" attribute "+name+" returns "+values);
            } else {
                // input was not thread safe
                // so acquire it again
                iputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR);
                if (this.inputName != null
                    && iputSelector != null
                    && iputSelector.hasComponent(this.inputName)) {
                   
                    iput = (InputModule) iputSelector.select(this.inputName);
                }
                if (iput != null) {
                    values = iput.getAttributeValues(name, this.inputConf, objectModel);
                }          
                if (getLogger().isDebugEnabled())
                    getLogger().debug("fresh module "+iput+" attribute "+name+" returns "+values);
            }
        } catch (Exception e) {
            if (getLogger().isWarnEnabled())
                getLogger().warn("A problem occurred acquiring a value from '"
                                 + this.inputName + "' for '"+name+"': " + e.getMessage());
        } finally {
            // release components if necessary
            if (iputSelector != null) {
                if (iput != null)
                    iputSelector.release(iput);
                this.manager.release(iputSelector);
            }
        }

        return values;
View Full Code Here

    {
        Redirector redirector = new SitemapRedirector(this.environment);
        SourceResolver resolver = (SourceResolver)this.environment.getObjectModel()
            .get(OBJECT_SOURCE_RESOLVER);
        ComponentManager sitemapManager = CocoonComponentManager.getSitemapComponentManager();
        ComponentSelector actionSelector
            = (ComponentSelector)sitemapManager.lookup(Action.ROLE + "Selector");
        Action action = (Action)actionSelector.select(type);
        Map result = null;
        try {
            result = action.act(redirector,
                                resolver,
                                this.environment.getObjectModel(),
                                source,
                                jsobjectToParameters(parameters));
        } finally {
            actionSelector.release(action);
        }

        // what should be done with the redirector ??
        // ignore it or call sendPage with it?
        return (result!=null? new ScriptableMap(result) : null);
View Full Code Here

        throws Exception
    {
        // since no new components can be declared on sitemap we could
        // very well use the 'other' one here. Anyway, since it's there...
        ComponentManager sitemapManager = CocoonComponentManager.getSitemapComponentManager();
        ComponentSelector inputSelector = (ComponentSelector)sitemapManager
            .lookup(InputModule.ROLE + "Selector");
        InputModule input = (InputModule) inputSelector.select(type);
        Object result = null;
        try {
            result = input.getAttribute(attribute, null,
                                        this.environment.getObjectModel());
        } finally {
            inputSelector.release(input);
        }
        return result;
    }
View Full Code Here

        throws Exception
    {
        // since no new components can be declared on sitemap we could
        // very well use the 'other' one here. Anyway, since it's there...
        ComponentManager sitemapManager = CocoonComponentManager.getSitemapComponentManager();
        ComponentSelector outputSelector = (ComponentSelector)sitemapManager
            .lookup(OutputModule.ROLE + "Selector");
        OutputModule output = (OutputModule) outputSelector.select(type);
        try {
            output.setAttribute(null, this.environment.getObjectModel(), attribute,
                                jsobjectToObject(value));
        }
        finally {
            outputSelector.release(output);
        }
    }
View Full Code Here

        throws Exception
    {
        // since no new components can be declared on sitemap we could
        // very well use the 'other' one here. Anyway, since it's there...
        ComponentManager sitemapManager = CocoonComponentManager.getSitemapComponentManager();
        ComponentSelector outputSelector = (ComponentSelector)sitemapManager
            .lookup(OutputModule.ROLE + "Selector");
        OutputModule output = (OutputModule) outputSelector.select(type);
        try {
            output.commit(null, this.environment.getObjectModel());
        } finally {
            outputSelector.release(output);
        }
    }
View Full Code Here

        throws Exception
    {
        // since no new components can be declared on sitemap we could
        // very well use the 'other' one here. Anyway, since it's there...
        ComponentManager sitemapManager = CocoonComponentManager.getSitemapComponentManager();
        ComponentSelector outputSelector = (ComponentSelector)sitemapManager
            .lookup(OutputModule.ROLE + "Selector");
        OutputModule output = (OutputModule) outputSelector.select(type);
        try {
            output.rollback(null, this.environment.getObjectModel(), null);
        } finally {
            outputSelector.release(output);
        }
    }
View Full Code Here

     */
    public String getTypeForStatement(Configuration statement, String role) throws ConfigurationException {

        String type = statement.getAttribute("type", null);

        ComponentSelector selector = null;

        try {
            try {
                selector = (ComponentSelector)this.manager.lookup(role);
            } catch(ComponentException ce) {
                String msg = "Cannot get component selector for '" + statement.getName() + "' at " +
                    statement.getLocation();
                throw new ConfigurationException(msg, ce);
            }

            if (type == null && selector instanceof ExtendedComponentSelector) {
                type = ((ExtendedComponentSelector)selector).getDefaultHint();
            }

            if (type == null) {
                String msg = "No default type exists for '" + statement.getName() + "' at " +
                    statement.getLocation();
                throw new ConfigurationException(msg);
            }

            if (!selector.hasComponent(type)) {
                String msg = "Type '" + type + "' is not defined for '" + statement.getName() + "' at " +
                    statement.getLocation();
                throw new ConfigurationException(msg);
            }
        } finally {
View Full Code Here

                frag.normalize();

                if ( null != serializerName) {
          ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();

                  ComponentSelector selector = null;
                  Serializer serializer = null;
                  OutputStream oStream = null;
                  try {
                       selector = (ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
                       serializer = (Serializer)selector.select(serializerName);
                       oStream = ws.getOutputStream();
                       serializer.setOutputStream(oStream);
                         serializer.startDocument();
                       DOMStreamer streamer = new DOMStreamer(serializer);
                       streamer.stream(frag);
                         serializer.endDocument();
                  } catch (ComponentException e) {
                    throw new ProcessingException("Unable to lookup serializer.", e);
          } finally {
                      if (oStream != null) {
                          oStream.flush();
                          try {
                              oStream.close();
                          } catch (Exception ignore) {
                            }
                        }
            if ( selector != null ) {
              selector.release( serializer );
              manager.release( selector );
            }
                  }
                } else {
                  final String content = XMLUtils.serializeNode(frag,
                                             XMLUtils.defaultSerializeToXMLFormat(false));
                  OutputStream oStream = ws.getOutputStream();
 
                  oStream.write(content.getBytes());
                  oStream.flush();
                  oStream.close();
                }
            } else {
              String content;
        if ( null != serializerName) {
          ComponentManager  manager = CocoonComponentManager.getSitemapComponentManager();
                   
                    ComponentSelector selector = null;
                    Serializer serializer = null;
                    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
                    try {
                        selector = (ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
                        serializer = (Serializer)selector.select(serializerName);
                        serializer.setOutputStream(oStream);
                        serializer.startDocument();
                        DOMStreamer streamer = new DOMStreamer(serializer);
                        streamer.stream(frag);
                        serializer.endDocument();
          } catch (ComponentException e) {
            throw new ProcessingException("Unable to lookup serializer.", e);
                    } finally {
                        if (oStream != null) {
                            oStream.flush();
                            try {
                                oStream.close();
                            } catch (Exception ignore) {
                            }
                        }
            if ( selector != null ) {
              selector.release( serializer );
              manager.release( selector );
            }
                    }
          content = oStream.toString();
        } else {
View Full Code Here

    /**
     * Obtain a permanent reference to an InputModule.
     */
    protected InputModule obtainModule(String type) {
        ComponentSelector inputSelector = this.inputSelector;
        InputModule module = null;
        try {
            if (inputSelector == null)
                inputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR);

            if (inputSelector.hasComponent(type)){
               
                if (type != null && inputSelector.hasComponent(type))
                    module = (InputModule) inputSelector.select(type);
               
                if (!(module instanceof ThreadSafe) ) {
                    inputSelector.release(module);
                    module = null;
                }
            }
            if (type != null && module == null)
                if (getLogger().isWarnEnabled())
                    getLogger().warn("A problem occurred setting up '" + type
                                     +"': Selector is "+(inputSelector!=null?"not ":"")
                                     +"null, Component is "
                                     +(inputSelector!=null && inputSelector.hasComponent(type)?"known":"unknown"));
           
        } catch (ComponentException ce) {
            if (getLogger().isWarnEnabled())
                getLogger().warn("Could not obtain selector for InputModules: "+ce.getMessage());
        } finally {
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.component.ComponentSelector

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.