Package org.apache.avalon.framework.component

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


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

    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

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

            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

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

        return this.generator;
    }

    public void addTransformer (String role, String source, Parameters param)
    throws Exception {
        ComponentSelector selector = (ComponentSelector) this.newManager.lookup(Transformer.ROLE + "Selector");
        this.transformerSelectors.add(selector);
        this.transformers.add((Transformer)selector.select(role));
        this.transformerSources.add(source);
        this.transformerParams.add(param);
    }
View Full Code Here

     * This method overrides super class' method to allow an OutputModule
     * to take care of what to do with the values.
     */
    protected void setRequestAttribute(Request request, String key, Object value) {

        ComponentSelector outputSelector = null;
        OutputModule output = null;
        String outputMode = null;
        try {
            outputSelector=(ComponentSelector) this.manager.lookup(OUTPUT_MODULE_SELECTOR);
            outputMode = (String) request.getAttribute(ATTRIBUTE_KEY);
            if (outputMode != null && outputSelector != null && outputSelector.hasComponent(outputMode)){
                output = (OutputModule) outputSelector.select(outputMode);
            }
            output.setAttribute( null, request, key, value );
        } catch (Exception e) {
                if (getLogger().isWarnEnabled())
                    getLogger()
                        .warn( "Could not select output mode "
                               + (String) outputMode
                               + ":" + e.getMessage() );
        } finally {
            if (outputSelector != null) {
                if (output != null)
                    outputSelector.release(output);
                this.manager.release(outputSelector);
            }
         }
    }
View Full Code Here

            if (conn.getAutoCommit()==false)
                conn.commit();

            // obtain output mode module and rollback output
            ComponentSelector outputSelector = null;
            OutputModule output = null;
            try {
                outputSelector=(ComponentSelector) this.manager.lookup(OUTPUT_MODULE_SELECTOR);
                if (outputMode != null && outputSelector != null && outputSelector.hasComponent(outputMode)){
                    output = (OutputModule) outputSelector.select(outputMode);
                }
                output.commit( null, request );
            } catch (Exception e) {
                if (getLogger().isWarnEnabled())
                    getLogger()
                        .warn( "Could not select output mode "
                               + (String) outputMode
                               + ":" + e.getMessage() );
            } finally {
                if (outputSelector != null) {
                    if (output != null)
                        outputSelector.release(output);
                    this.manager.release(outputSelector);
                }
            }

        } catch (Exception e) {
            if ( conn != null ) {
                try {
                    if (getLogger().isDebugEnabled())
                        getLogger().debug( "Rolling back transaction. Caused by " + e.getMessage() );
                    conn.rollback();

                    // obtain output mode module and commit output
                    ComponentSelector outputSelector = null;
                    OutputModule output = null;
                    try {
                        outputSelector=(ComponentSelector) this.manager.lookup(OUTPUT_MODULE_SELECTOR);
                        if (outputMode != null && outputSelector != null && outputSelector.hasComponent(outputMode)){
                            output = (OutputModule) outputSelector.select(outputMode);
                        }
                        output.rollback( null, request, e);
                    } catch (Exception e2) {
                        if (getLogger().isWarnEnabled())
                            getLogger()
                                .warn( "Could not select output mode "
                                       + (String) outputMode
                                       + ":" + e2.getMessage() );
                    } finally {
                        if (outputSelector != null) {
                            if (output != null)
                                outputSelector.release(output);
                            this.manager.release(outputSelector);
                        }
                    }

                } catch (SQLException se) {
View Full Code Here

        } else {
            Object[] values;
            String cname = getOutputName( tableConf, column.columnConf );
           
            // obtain input module and read values
            ComponentSelector inputSelector = null;
            InputModule input = null;
            try {
                inputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR);
                if (column.mode != null && inputSelector != null && inputSelector.hasComponent(column.mode)){
                    input = (InputModule) inputSelector.select(column.mode);
                }

                if ( column.isSet ){
                    if (getLogger().isDebugEnabled())
                        getLogger().debug( "Trying to set column " + cname +" using getAttributeValues method");
                    values = input.getAttributeValues( cname, column.modeConf, request );
                } else {
                    if (getLogger().isDebugEnabled())
                        getLogger().debug( "Trying to set column " + cname +" using getAttribute method");
                    values = new Object[1];
                    values[0] = input.getAttribute( cname, column.modeConf, request );
                }

                if ( values != null ) {
                    for ( int i = 0; i < values.length; i++ ) {
                        if (getLogger().isDebugEnabled())
                            getLogger().debug( "Setting column " + cname + " [" + i + "] " + values[i] );
                    }
                }

            } finally {
                if (inputSelector != null) {
                    if (input != null)
                        inputSelector.release(input);
                    this.manager.release(inputSelector);
                }
            }
           
            return values;
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.