Search in sources :

Example 1 with Iterator

use of java.util.Iterator in project camel by apache.

the class PGPDataFormatTest method readSecretKey.

static PGPSecretKey readSecretKey() throws Exception {
    InputStream input = new ByteArrayInputStream(getSecKeyRing());
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input), new BcKeyFingerprintCalculator());
    @SuppressWarnings("rawtypes") Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext()) {
        PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();
        @SuppressWarnings("rawtypes") Iterator keyIter = keyRing.getSecretKeys();
        while (keyIter.hasNext()) {
            PGPSecretKey key = (PGPSecretKey) keyIter.next();
            if (key.isSigningKey()) {
                return key;
            }
        }
    }
    throw new IllegalArgumentException("Can't find signing key in key ring.");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PGPSecretKey(org.bouncycastle.openpgp.PGPSecretKey) Iterator(java.util.Iterator) PGPSecretKeyRingCollection(org.bouncycastle.openpgp.PGPSecretKeyRingCollection) BcKeyFingerprintCalculator(org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator) PGPSecretKeyRing(org.bouncycastle.openpgp.PGPSecretKeyRing)

Example 2 with Iterator

use of java.util.Iterator in project camel by apache.

the class ElsqlProducer method process.

@Override
public void process(final Exchange exchange) throws Exception {
    final Object data = exchange.getIn().getBody();
    final SqlParameterSource param = new ElsqlSqlMapSource(exchange, data);
    final String sql = elSql.getSql(elSqlName, new SpringSqlParams(param));
    LOG.debug("ElsqlProducer @{} using sql: {}", elSqlName, sql);
    // special for processing stream list (batch not supported)
    final SqlOutputType outputType = getEndpoint().getOutputType();
    if (outputType == SqlOutputType.StreamList) {
        processStreamList(exchange, sql, param);
        return;
    }
    log.trace("jdbcTemplate.execute: {}", sql);
    jdbcTemplate.execute(sql, param, new PreparedStatementCallback<Object>() {

        @Override
        public Object doInPreparedStatement(final PreparedStatement ps) throws SQLException, DataAccessException {
            ResultSet rs = null;
            try {
                boolean isResultSet = false;
                final int expected = ps.getParameterMetaData().getParameterCount();
                if (expected > 0 && batch) {
                    final String sqlForDefaultPreparedStamentStrategy = sql.replaceAll(":", ":\\?");
                    final String preparedQuery = sqlPrepareStatementStrategy.prepareQuery(sqlForDefaultPreparedStamentStrategy, getEndpoint().isAllowNamedParameters(), exchange);
                    final Iterator<?> iterator = exchange.getIn().getBody(Iterator.class);
                    while (iterator != null && iterator.hasNext()) {
                        final Object value = iterator.next();
                        final Iterator<?> i = sqlPrepareStatementStrategy.createPopulateIterator(sqlForDefaultPreparedStamentStrategy, preparedQuery, expected, exchange, value);
                        sqlPrepareStatementStrategy.populateStatement(ps, i, expected);
                        ps.addBatch();
                    }
                }
                // execute the prepared statement and populate the outgoing message
                if (batch) {
                    final int[] updateCounts = ps.executeBatch();
                    int total = 0;
                    for (final int count : updateCounts) {
                        total += count;
                    }
                    exchange.getIn().setHeader(SqlConstants.SQL_UPDATE_COUNT, total);
                } else {
                    isResultSet = ps.execute();
                    if (isResultSet) {
                        rs = ps.getResultSet();
                        // preserve headers first, so we can override the SQL_ROW_COUNT header
                        exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
                        final SqlOutputType outputType = getEndpoint().getOutputType();
                        log.trace("Got result list from query: {}, outputType={}", rs, outputType);
                        if (outputType == SqlOutputType.SelectList) {
                            final List<?> data = getEndpoint().queryForList(rs, true);
                            // for noop=true we still want to enrich with the row count header
                            if (getEndpoint().isNoop()) {
                                exchange.getOut().setBody(exchange.getIn().getBody());
                            } else if (getEndpoint().getOutputHeader() != null) {
                                exchange.getOut().setBody(exchange.getIn().getBody());
                                exchange.getOut().setHeader(getEndpoint().getOutputHeader(), data);
                            } else {
                                exchange.getOut().setBody(data);
                            }
                            exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT, data.size());
                        } else if (outputType == SqlOutputType.SelectOne) {
                            final Object data = getEndpoint().queryForObject(rs);
                            if (data != null) {
                                // for noop=true we still want to enrich with the row count header
                                if (getEndpoint().isNoop()) {
                                    exchange.getOut().setBody(exchange.getIn().getBody());
                                } else if (getEndpoint().getOutputHeader() != null) {
                                    exchange.getOut().setBody(exchange.getIn().getBody());
                                    exchange.getOut().setHeader(getEndpoint().getOutputHeader(), data);
                                } else {
                                    exchange.getOut().setBody(data);
                                }
                                exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT, 1);
                            } else {
                                if (getEndpoint().isNoop()) {
                                    exchange.getOut().setBody(exchange.getIn().getBody());
                                } else if (getEndpoint().getOutputHeader() != null) {
                                    exchange.getOut().setBody(exchange.getIn().getBody());
                                }
                                exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT, 0);
                            }
                        } else {
                            throw new IllegalArgumentException("Invalid outputType=" + outputType);
                        }
                    } else {
                        // if we are here, there isResultSet is false. This can happen only if we are doing an update operation or there is no result.
                        // we can simply add the updateCount in this case.
                        exchange.getOut().setHeader(SqlConstants.SQL_UPDATE_COUNT, ps.getUpdateCount());
                    }
                }
            } finally {
                closeResultSet(rs);
            }
            return null;
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) SqlOutputType(org.apache.camel.component.sql.SqlOutputType) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) ResultSet(java.sql.ResultSet) JdbcUtils.closeResultSet(org.springframework.jdbc.support.JdbcUtils.closeResultSet) Iterator(java.util.Iterator) ResultSetIterator(org.apache.camel.component.sql.ResultSetIterator) List(java.util.List) DataAccessException(org.springframework.dao.DataAccessException) SpringSqlParams(com.opengamma.elsql.SpringSqlParams)

Example 3 with Iterator

use of java.util.Iterator in project antlrworks by antlr.

the class XJMainMenuBar method buildWindowMenu_.

private void buildWindowMenu_() {
    Iterator iterator = XJApplication.shared().getWindows().iterator();
    int count = 0;
    while (iterator.hasNext()) {
        XJWindow window = (XJWindow) iterator.next();
        if (window.shouldAppearsInWindowMenu()) {
            XJMenuItemCheck item = buildMenuItemCheck(window.getTitle(), count < 10 ? KeyEvent.VK_0 + count : -1, MI_WINDOW + count);
            item.setSelected(window.isActive());
            menuWindow.addItem(item);
            count++;
        }
    }
    if (count == 0) {
        XJMenuItem item = new XJMenuItem(XJLocalizable.getXJString("NoWindows"), MI_NO_WINDOW, null);
        item.setEnabled(false);
        menuWindow.addItem(item);
    }
}
Also used : XJWindow(org.antlr.xjlib.appkit.frame.XJWindow) Iterator(java.util.Iterator)

Example 4 with Iterator

use of java.util.Iterator in project camel by apache.

the class ExpressionBuilder method skipFirstExpression.

/**
     * Returns an expression that skips the first element
     */
public static Expression skipFirstExpression(final Expression expression) {
    return new ExpressionAdapter() {

        public Object evaluate(Exchange exchange) {
            Object value = expression.evaluate(exchange, Object.class);
            Iterator it = exchange.getContext().getTypeConverter().tryConvertTo(Iterator.class, exchange, value);
            if (it != null) {
                // skip first
                it.next();
                return it;
            } else {
                return value;
            }
        }

        @Override
        public String toString() {
            return "skipFirst(" + expression + ")";
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) XMLTokenExpressionIterator(org.apache.camel.support.XMLTokenExpressionIterator) GroupTokenIterator(org.apache.camel.util.GroupTokenIterator) TokenXMLExpressionIterator(org.apache.camel.support.TokenXMLExpressionIterator) TokenPairExpressionIterator(org.apache.camel.support.TokenPairExpressionIterator) Iterator(java.util.Iterator) SkipIterator(org.apache.camel.util.SkipIterator) GroupIterator(org.apache.camel.util.GroupIterator) ExpressionAdapter(org.apache.camel.support.ExpressionAdapter)

Example 5 with Iterator

use of java.util.Iterator in project camel by apache.

the class UnmarshalProcessor method process.

public boolean process(Exchange exchange, AsyncCallback callback) {
    ObjectHelper.notNull(dataFormat, "dataFormat");
    InputStream stream = null;
    Object result = null;
    try {
        stream = exchange.getIn().getMandatoryBody(InputStream.class);
        // lets setup the out message before we invoke the dataFormat so that it can mutate it if necessary
        Message out = exchange.getOut();
        out.copyFrom(exchange.getIn());
        result = dataFormat.unmarshal(exchange, stream);
        if (result instanceof Exchange) {
            if (result != exchange) {
                // it's not allowed to return another exchange other than the one provided to dataFormat
                throw new RuntimeCamelException("The returned exchange " + result + " is not the same as " + exchange + " provided to the DataFormat");
            }
        } else if (result instanceof Message) {
            // the dataformat has probably set headers, attachments, etc. so let's use it as the outbound payload
            exchange.setOut((Message) result);
        } else {
            out.setBody(result);
        }
    } catch (Throwable e) {
        // remove OUT message, as an exception occurred
        exchange.setOut(null);
        exchange.setException(e);
    } finally {
        // The Iterator will close the stream itself
        if (!(result instanceof Iterator)) {
            IOHelper.close(stream, "input stream");
        }
    }
    callback.done(true);
    return true;
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) InputStream(java.io.InputStream) Iterator(java.util.Iterator) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Aggregations

Iterator (java.util.Iterator)7939 ArrayList (java.util.ArrayList)2053 Set (java.util.Set)1744 HashMap (java.util.HashMap)1678 HashSet (java.util.HashSet)1526 Map (java.util.Map)1486 List (java.util.List)1463 Test (org.junit.Test)576 IOException (java.io.IOException)465 Collection (java.util.Collection)320 Region (org.apache.geode.cache.Region)240 SSOException (com.iplanet.sso.SSOException)227 LinkedList (java.util.LinkedList)196 File (java.io.File)187 TreeSet (java.util.TreeSet)187 SMSException (com.sun.identity.sm.SMSException)169 LinkedHashMap (java.util.LinkedHashMap)146 IdRepoException (com.sun.identity.idm.IdRepoException)133 NoSuchElementException (java.util.NoSuchElementException)130 Session (org.hibernate.Session)126