Examples of ComponentSelector


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

        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

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

     * 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

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

            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

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

        } 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

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

     */
    protected void storeKeyValue( Configuration tableConf, Column key, int rowIndex, Connection conn,
                                  Statement statement, Request request, Map results )
        throws SQLException, ConfigurationException, ComponentException {
       
        ComponentSelector autoincrSelector = null;
        AutoIncrementModule autoincr = null;
        try {
            autoincrSelector=(ComponentSelector) this.manager.lookup(DATABASE_MODULE_SELECTOR);
            if (key.mode != null && autoincrSelector != null && autoincrSelector.hasComponent(key.mode)){
                autoincr = (AutoIncrementModule) autoincrSelector.select(key.mode);
            }

            if (!autoincr.includeAsValue()) {
                String keyname = getOutputName( tableConf, key.columnConf, rowIndex );
                Object value = autoincr.getPostValue( tableConf, key.columnConf, key.modeConf, conn, statement, request );
                if (getLogger().isDebugEnabled())
                    getLogger().debug( "Retrieving autoincrement for " + keyname + "as " + value );
                setRequestAttribute( request, keyname, value );
                results.put( keyname, String.valueOf( value ) );
            }

        } finally {
            if (autoincrSelector != null) {
                if (autoincr != null)
                    autoincrSelector.release(autoincr);
                this.manager.release(autoincrSelector);
            }
         }
       
    }
View Full Code Here

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

        throws ConfigurationException, SQLException, ComponentException, Exception {

        int columnCount = 0;

       
        ComponentSelector autoincrSelector = null;
        AutoIncrementModule autoincr = null;
        try {
            autoincrSelector=(ComponentSelector) this.manager.lookup(DATABASE_MODULE_SELECTOR);
            if (column.mode != null && autoincrSelector != null && autoincrSelector.hasComponent(column.mode)){
                autoincr = (AutoIncrementModule) autoincrSelector.select(column.mode);
            }

            if ( autoincr.includeInQuery() ) {
                if ( autoincr.includeAsValue() ) {
                    Object value = autoincr.getPreValue( table, column.columnConf, column.modeConf, conn, request );
                    String keyname = this.getOutputName( table, column.columnConf, rowIndex );
                    if (getLogger().isDebugEnabled())
                        getLogger().debug( "Setting key " + keyname + " to " + value );
                    statement.setObject( currentIndex, value );
                    setRequestAttribute( request, keyname, value );
                    results.put( keyname, String.valueOf( value ) );
                    columnCount = 1;
                }
            } else {
                if (getLogger().isDebugEnabled())
                    getLogger().debug( "Automatically setting key" );
            }

        } finally {
            if (autoincrSelector != null) {
                if (autoincr != null)
                    autoincrSelector.release(autoincr);
                this.manager.release(autoincrSelector);
            }
         }

        return columnCount;
View Full Code Here

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

        }
    }
   
    private Connection getConnection() throws ProcessingException {

        ComponentSelector selector = null;
        DataSourceComponent datasource = null;

        try {
            try {
                selector = (ComponentSelector)this.manager.lookup(DataSourceComponent.ROLE + "Selector");
                   
                datasource = (DataSourceComponent)selector.select(this.datasourceName);
   
            } catch(Exception e) {
                String msg = "Cannot get datasource '" + this.datasourceName + "'";
                getLogger().error(msg);
                throw new ProcessingException(msg, e);
            }
           
            try {
                return datasource.getConnection();
            } catch(Exception e) {
                String msg = "Cannot get connection for datasource '" + this .datasourceName + "'";
                getLogger().error(msg);
                throw new ProcessingException(msg, e);
            }

        } finally {
            if (datasource != null) {
                selector.release(datasource);
            }
        }
    }
View Full Code Here

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

                                      + "' from '" + inputName + "': " + e.getMessage());
            }
        } else {
            // input was not thread safe
            // so acquire it again
            ComponentSelector iputSelector = null;
            InputModule iput = null;
            try {
                // obtain input module
                iputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR);
                if (inputName != null && iputSelector != null && iputSelector.hasComponent(inputName)){
                    iput = (InputModule) iputSelector.select(inputName);
                }
                if (iput != null) {
                    result = iput.getAttribute(paramName, this.inputConf, ObjectModelHelper.getRequest(objectModel));
                }
            } catch (Exception e) {
                if (getLogger().isWarnEnabled())
                    getLogger().warn("A problem occurred acquiring Parameter '" + paramName
                                     + "' from '" + inputName + "': " + e.getMessage());
            } finally {
                // release components
                if (iputSelector != null) {
                    if (iput != null)
                        iputSelector.release(iput);
                    this.manager.release(iputSelector);
                }
            }
        }
View Full Code Here

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

                getLogger().warn("No input module given. FAILING");
            return null;
        }

        InputModule input = null;
        ComponentSelector inputSelector = null;
        Object result = null;

        // one could test whether the input module is ThreadSafe and
        // keep a reference for that instance. Then one would need
        // to implement Disposable in order to release it at EOL
        // That would probably speed up things a lot. Especially, since
        // matchers are invoked very often.
        // Perhaps a CachingWildcardMatcher ?

        try {
            // obtain input module
            inputSelector=(ComponentSelector) this.manager.lookup(INPUT_MODULE_SELECTOR);
            if (inputName != null && inputSelector != null && inputSelector.hasComponent(inputName)){
                input = (InputModule) inputSelector.select(inputName);
            }
            if (input != null) {
                result = input.getAttribute(paramName, this.inputConf,
                                                     ObjectModelHelper.getRequest(objectModel));
            }
        } catch (Exception e) {
            if (getLogger().isWarnEnabled())
                getLogger().warn("A problem occurred acquiring Parameter '" + paramName
                                 + "' from '" + inputName + "': " + e.getMessage());
        } finally {
            // release components
            if (inputSelector != null) {
                if (input != null)
                    inputSelector.release(input);
                this.manager.release(inputSelector);
            }
        }

        if (getLogger().isDebugEnabled())
View Full Code Here

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

            String local_serializer = a.getValue("",SWT_SERIALIZER_ATTRIBUTE);
            if (local_serializer != null) this.serializer_name = local_serializer;
            if (this.serializer_name != null) {
              // Lookup the Serializer
              this.message = "that Serializer does not exist";
              ComponentSelector selector = (ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
              this.ch = (Serializer)selector.select(this.serializer_name);
              this.message = "Could not open the source for writing";
              this.os = this.wsource.getOutputStream();
              this.message = "could not write the file";
              ((Serializer)this.ch).setOutputStream(this.os);                  // Is there a way to avoid this casting?
              this.isSerializer = true;
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.