Examples of ComponentSelector


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

        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

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

     */
    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

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

                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

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

    /**
     * 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

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

    /**
     * release a permanent reference to an InputModule.
     */
    protected void releaseModule(InputModule module) {
        ComponentSelector inputSelector = this.inputSelector;
        if (module != null) {
            try {
                // FIXME: Is it OK to release a module when we have released the selector before?
                if (inputSelector == null)
                    inputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR);
               
                inputSelector.release(module);
                module = null;
               
            } catch (ComponentException ce) {
                if (getLogger().isWarnEnabled())
                    getLogger().warn("Could not obtain selector for InputModules: "+ce.getMessage());
View Full Code Here

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

     */
    private Object get(int op, String attr, Map objectModel,
                         InputModule staticMod, String staticModName, Configuration staticModConf,
                         InputModule dynamicMod, String dynamicModName, Configuration dynamicModConf) {

        ComponentSelector cs = this.inputSelector;
        Object value = null;
        String name = null;
        InputModule input = null;
        Configuration conf = null;
        boolean release = false;

        try {

            if (cs == null)
                cs = (ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR);

            boolean useDynamic;
            if (dynamicMod == null && dynamicModName == null) {
                useDynamic = false;
                input = staticMod;
                name = staticModName;
                conf = staticModConf;
            } else {
                useDynamic = true;
                input = dynamicMod;
                name = dynamicModName;
                conf = dynamicModConf;
            }
       
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("MetaModule performing op "+OPNAME[op]+" on " +
                        (useDynamic?"dynamically":"statically") + " " +
                        (input==null?"created":"assigned") +
                        " module '"+name+"', using config "+dynamicModConf);
            }

            if (input == null) {
                if (cs.hasComponent(name)) {
                    release = true;
                    input = (InputModule) cs.select(name);
                } else {
                    if (getLogger().isWarnEnabled())
                        getLogger().warn("No such InputModule: "+name);
                }
            }

            switch (op) {
            case OP_GET:   
                value = input.getAttribute(attr, conf, objectModel);
                break;
            case OP_VALUES:
                value = input.getAttributeValues(attr, conf, objectModel);
                break;
            case OP_NAMES:
                value = input.getAttributeNames(conf, objectModel);
                break;
            };

            if (getLogger().isDebugEnabled())
                getLogger().debug("using "+name+" as "+input+" for "+op+" ("+attr+") and "+conf+" gives "+value);
           
        } catch (Exception e) {
            if (getLogger().isWarnEnabled())
                getLogger().warn("A problem obtaining a value from "+name+" occurred : "+e.getMessage());
        } finally {        
            if (release)
                cs.release(input);

            if (this.inputSelector == null)
                this.manager.release(cs);
        }

View Full Code Here

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

    throws ComponentException
  {
    this.manager = manager;
   
    try {
      ComponentSelector selector
        = (ComponentSelector)manager.lookup(Interpreter.ROLE);
      // Obtain the Interpreter instance for this language
      interpreter = (Interpreter)selector.select(language);
    }
    catch (Exception ex) {
      throw new ComponentException("ScriptNode: Couldn't obtain a flow "
                                   + "interpreter for " + language
                                   + ": " + ex);
View Full Code Here

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

    /**
     * Generate XML data.
     */
    public void generate() throws IOException, SAXException, ProcessingException {

        ComponentSelector principalproviders = null;
        PrincipalProvider principalprovider = null;
        try {
            principalproviders = (ComponentSelector)this.manager.lookup(PrincipalProvider.ROLE+"Selector");

            principalprovider = (PrincipalProvider)principalproviders.select(this.principalprovidername);

            Principal[] principals = principalprovider.getPrincipals(this.principalcaller);
            PrincipalGroup[] principalgroups = principalprovider.getPrincipalGroups(this.principalcaller);

            this.contentHandler.startDocument();
            this.contentHandler.startPrefixMapping("",PL_NS);

            this.contentHandler.startElement(PL_NS, LIST_ELEMENT_NAME,
                                                    LIST_ELEMENT_NAME, new AttributesImpl());

            AttributesImpl attributes;
            for(int i=0; i<principals.length; i++) {
                attributes = new AttributesImpl();
                attributes.addAttribute("", NAME_ATTR_NAME, NAME_ATTR_NAME, "CDATA", principals[i].getName());
                if (principals[i].getRole()!=null)
                    attributes.addAttribute("", ROLE_ATTR_NAME, ROLE_ATTR_NAME, "CDATA", principals[i].getRole());
                if (principals[i].getPassword()!=null)
                    attributes.addAttribute("", PASSWORD_ATTR_NAME, PASSWORD_ATTR_NAME, "CDATA", principals[i].getPassword());

                this.contentHandler.startElement(PL_NS, PRINCIPAL_ELEMENT_NAME,
                                                        PRINCIPAL_ELEMENT_NAME, attributes);
                this.contentHandler.endElement(PL_NS, PRINCIPAL_ELEMENT_NAME, PRINCIPAL_ELEMENT_NAME);
            }

            for(int i=0; i<principalgroups.length; i++) {
                attributes = new AttributesImpl();
                attributes.addAttribute("", NAME_ATTR_NAME, NAME_ATTR_NAME, "CDATA", principalgroups[i].getName());

                this.contentHandler.startElement(PL_NS, PRINCIPALGROUP_ELEMENT_NAME,
                                                        PRINCIPALGROUP_ELEMENT_NAME, attributes);

                Principal[] members = principalprovider.members(this.principalcaller, principalgroups[i]);
                for(int j=0; j<members.length; j++) {
                    attributes = new AttributesImpl();
                    attributes.addAttribute("", NAME_ATTR_NAME, NAME_ATTR_NAME, "CDATA", members[j].getName());
                    if (members[j].getRole()!=null)
                        attributes.addAttribute("", ROLE_ATTR_NAME, ROLE_ATTR_NAME, "CDATA", members[j].getRole());
                    if (members[j].getPassword()!=null)
                        attributes.addAttribute("", PASSWORD_ATTR_NAME, PASSWORD_ATTR_NAME, "CDATA",
                                                members[j].getPassword());

                    this.contentHandler.startElement(PL_NS, PRINCIPAL_ELEMENT_NAME,
                                                            PRINCIPAL_ELEMENT_NAME, attributes);
                    this.contentHandler.endElement(PL_NS, PRINCIPAL_ELEMENT_NAME, PRINCIPAL_ELEMENT_NAME);
                }

                this.contentHandler.endElement(PL_NS, PRINCIPALGROUP_ELEMENT_NAME, PRINCIPALGROUP_ELEMENT_NAME);
            }
               

            this.contentHandler.endElement(PL_NS, LIST_ELEMENT_NAME, LIST_ELEMENT_NAME);

            this.contentHandler.endPrefixMapping("");
            this.contentHandler.endDocument();

        } catch (ComponentException ce) {
            getLogger().error("Could not lookup for component.", ce);
        } finally {
            if (principalprovider!=null)
                principalproviders.release(principalprovider);
            principalprovider = null;

            if (principalproviders!=null)
                this.manager.release(principalproviders);
            principalproviders = null;
View Full Code Here

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

            for (int i = 0; i < ComponentsSelector.SELECTOR_ROLES.length; i++) {

                String role = ComponentsSelector.SELECTOR_ROLES[i];

                ComponentSelector parentSelector = null;
                try {
                    parentSelector = (ComponentSelector)this.parentManager.lookup(role);
                } catch(Exception e) {
                    // ignore and keep it null
                }
View Full Code Here

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

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

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

        ComponentSelector selector;

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

        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();
            getLogger().error(msg);
            throw new ConfigurationException(msg);
        }

        if (!selector.hasComponent(type)) {
            String msg = "Type '" + type + "' is not defined for '" + statement.getName() + "' at " +
                statement.getLocation();
            getLogger().error(msg);
            throw new ConfigurationException(msg);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.