Package org.apache.avalon.framework.component

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


     * Store a key/value pair in the output attributes. We prefix the key
     * with the name of this class to prevent potential name collisions.
     */
    protected void setOutputAttribute(Map objectModel, String outputMode, String key, Object value) {

        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.setAttribute( null, objectModel, key, value );
        } catch (Exception e) {
                if (getLogger().isWarnEnabled()) {
                    getLogger().warn("Could not select output mode "
                                     + outputMode + ":" + e.getMessage());
                }
        } finally {
            if (outputSelector != null) {
                if (output != null)
                    outputSelector.release(output);
                this.manager.release(outputSelector);
            }
         }
    }
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 +" from "+column.mode+" using getAttributeValues method");
                    values = input.getAttributeValues( cname, column.modeConf, objectModel );
                } else {
                    if (getLogger().isDebugEnabled())
                        getLogger().debug( "Trying to set column " + cname +" from "+column.mode+" using getAttribute method");
                    values = new Object[1];
                    values[0] = input.getAttribute( cname, column.modeConf, objectModel );
                }

                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

            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, objectModel );
            } catch (Exception e) {
                if (getLogger().isWarnEnabled()) {
                    getLogger().warn("Could not select output mode "
                                     + 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() );
                        e.printStackTrace();
                    }
                    conn.rollback();
                    results = null;

                    // 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, objectModel, e);
                    } catch (Exception e2) {
                        if (getLogger().isWarnEnabled()) {
                            getLogger().warn("Could not select output mode "
                                       + outputMode + ":" + e2.getMessage());
                        }
                    } finally {
                        if (outputSelector != null) {
                            if (output != null)
                                outputSelector.release(output);
                            this.manager.release(outputSelector);
                        }
                    }

                } catch (SQLException se) {
View Full Code Here

        public void remove() {}
    }

    private Connection getConnection() throws SourceException {

        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 SourceException(msg, e);
            }

            try {
                return datasource.getConnection();
            } catch(Exception e) {
                String msg = "Cannot get connection for datasource '" + this .datasourceName + "'";
                getLogger().error(msg);
                throw new SourceException(msg, e);
            }

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

    protected int setKeyAuto ( Configuration table, Column column, int currentIndex, int rowIndex,
                               Connection conn, PreparedStatement statement, Map objectModel, String outputMode, Map results )
        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, objectModel );
                    this.setColumn(objectModel, outputMode, results, table, column.columnConf, rowIndex, value, statement, currentIndex);
                    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

     */
    protected void storeKeyValue( Configuration tableConf, Column key, int rowIndex, Connection conn,
                                  Statement statement, Map objectModel, String outputMode, 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()) {
                Object value = autoincr.getPostValue( tableConf, key.columnConf, key.modeConf, conn, statement, objectModel );
                this.setOutput(objectModel, outputMode, results, tableConf, key.columnConf, rowIndex, value);
            }

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

    }
View Full Code Here

                        queryBuffer.append( ", " );
                        valueBuffer.append( ", " );
                    }
                    if ( queryData.columns[i].isKey && queryData.columns[i].isAutoIncrement ) {

                        ComponentSelector autoincrSelector = null;
                        AutoIncrementModule autoincr = null;
                        try {
                            autoincrSelector=(ComponentSelector) this.manager.lookup(DATABASE_MODULE_SELECTOR);
                            if (queryData.columns[i].mode != null && autoincrSelector != null && autoincrSelector.hasComponent(queryData.columns[i].mode)){
                                autoincr = (AutoIncrementModule) autoincrSelector.select(queryData.columns[i].mode);
                               
                                if ( autoincr.includeInQuery() ) {
                                    actualColumns++;
                                    queryBuffer.append( queryData.columns[i].columnConf.getAttribute( "name" ) );
                                    if ( autoincr.includeAsValue() ) {
                                        valueBuffer.append( "?" );
                                    } else {
                                        valueBuffer.append(
                                                           autoincr.getSubquery( table, queryData.columns[i].columnConf,
                                                                                 queryData.columns[i].modeConf ) );
                                    }
                                }
                            } else {
                                if (getLogger().isErrorEnabled())
                                    getLogger().error("Could not find mode description "
                                                      + queryData.columns[i].mode + " for column #"+i);
                                if (getLogger().isDebugEnabled()) {
                                    getLogger().debug("Column data "+queryData.columns[i]);
                                }
                                throw new ConfigurationException("Could not find mode description "+queryData.columns[i].mode+" for column "+i);
                            }
                           
                        } finally {
                            if (autoincrSelector != null) {
                                if (autoincr != null)
                                    autoincrSelector.release(autoincr);
                                this.manager.release(autoincrSelector);
                            }
                        }

                    } else {
View Full Code Here

        throws SAXException {   
           
        if ( Web3.URI.equals( uri ) && !this.error ) {
            switch ( Integer.parseInt( (String) this.tags.get( loc ))) {
                case INCLUDE_ELEM:
                    ComponentSelector r3sc = null;
                    try {
                        r3sc = (ComponentSelector)
                            this.manager.lookup ( Web3DataSource.ROLE + "Selector");
                        this.web3source = (Web3DataSource) r3sc.select( this.backend );
                        this.connection = this.web3source.getWeb3Client();
                        this.repository = (JCO.Repository) this.connection.getRepository();
                        this.functionT = this.repository.getFunctionTemplate(
                            a.getValue( Web3.INCLUDE_NAME_ATTR ) );
                        this.streamer  = (null == a.getValue( Web3.INCLUDE_CLASS_ATTR )) ?
View Full Code Here

    {
        if ( Web3.URI.equals(uri) && !this.error ) {
            switch ( Integer.parseInt( (String) this.tags.get( loc ))) {
                case INCLUDE_ELEM:
                    Web3Streamer w3s = null;
                    ComponentSelector streamerSelector = null;
                    try {
                        this.connection.execute( this.function );
                        streamerSelector =
                            (ComponentSelector)
                            this.manager.lookup( Web3Streamer.ROLE + "Selector" );
                        w3s = (Web3Streamer) streamerSelector.select( this.streamer );
                        w3s.stream( this.function,  super.contentHandler );
                    }
                    catch (Exception x) {
                        this.attributes.clear();
                        super.contentHandler.startElement(uri, Web3.ABAP_EXCEPTION_ELEM,
                            Web3.ABAP_EXCEPTION_ELEM, this.attributes);
                        super.contentHandler.characters(x.getMessage ().toCharArray(),
                            0, x.getMessage ().length());
                        super.contentHandler.endElement(uri, Web3.ABAP_EXCEPTION_ELEM,
                            Web3.ABAP_EXCEPTION_ELEM);                   
                        getLogger().error(x.getMessage(), x);
                    }
                    finally {
                        this.web3source.releaseWeb3Client( this.connection );
                        if ( null != streamerSelector ) {
                            streamerSelector.release( w3s );
                        }
                        manager.release( streamerSelector );
                    }
                    this.connection = null;
                    this.repository = null;
View Full Code Here

     *
     */
    public InputStream getInputStream()
    throws IOException {

        ComponentSelector serializerSelector = null;
        Serializer serializer = null;
        try {

            serializerSelector = (ComponentSelector) this.manager.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 (ComponentException cme) {
            throw new CascadingIOException("could not lookup pipeline components", cme);
        } catch (Exception e) {
            throw new CascadingIOException("Exception during processing of " + this.getURI(), e);
        } finally {
            if (serializer != null) serializerSelector.release(serializer);
            if (serializerSelector != null) this.manager.release(serializerSelector);
        }
    }
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.