Example usage for java.util Vector iterator

List of usage examples for java.util Vector iterator

Introduction

In this page you can find the example usage for java.util Vector iterator.

Prototype

public synchronized Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:org.apache.velocity.runtime.resource.ResourceManagerImpl.java

/**
 * This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader. This
 * Hashtable will be passed in when initializing the the template loader.
 *///from   w w w  .java2s . c  o m
private void assembleResourceLoaderInitializers() {
    Vector resourceLoaderNames = rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER);
    StringUtils.trimStrings(resourceLoaderNames);

    for (Iterator it = resourceLoaderNames.iterator(); it.hasNext();) {

        /*
         * The loader id might look something like the following:
         *
         * file.resource.loader
         *
         * The loader id is the prefix used for all properties
         * pertaining to a particular loader.
         */
        String loaderName = (String) it.next();
        StringBuffer loaderID = new StringBuffer(loaderName);
        loaderID.append(".").append(RuntimeConstants.RESOURCE_LOADER);

        ExtendedProperties loaderConfiguration = rsvc.getConfiguration().subset(loaderID.toString());

        /*
         *  we can't really count on ExtendedProperties to give us an empty set
         */
        if (loaderConfiguration == null) {
            Logger.debug(this,
                    "ResourceManager : No configuration information found " + "for resource loader named '"
                            + loaderName + "' (id is " + loaderID + "). Skipping it...");
            continue;
        }

        /*
         *  add the loader name token to the initializer if we need it
         *  for reference later. We can't count on the user to fill
         *  in the 'name' field
         */

        loaderConfiguration.setProperty(RESOURCE_LOADER_IDENTIFIER, loaderName);

        /*
         * Add resources to the list of resource loader
         * initializers.
         */
        sourceInitializerList.add(loaderConfiguration);
    }
}

From source file:tufts.oki.dr.fedora.DR.java

private void loadFedoraObjectAssetTypes() {
    try {//  w  w w .  j  a va 2 s .  com
        Vector fedoraTypesVector = FedoraUtils.stringToVector(fedoraProperties.getProperty("fedora.types"));
        Iterator i = fedoraTypesVector.iterator();
        while (i.hasNext()) {
            createFedoraObjectAssetType((String) i.next());
        }
    } catch (Exception ex) {
        System.out.println("Unable to load fedora types" + ex);
    }
}

From source file:org.wso2.mercury.security.rampart.RampartBasedRMSecurityManager.java

public void checkProofOfPossession(SecurityToken token, MessageContext message) throws RMSecurityException {

    Vector results = null;
    if ((results = (Vector) message.getProperty(WSHandlerConstants.RECV_RESULTS)) == null) {
        throw new RMSecurityException("No Security results");
    } else {/*from   ww w  .j av  a  2s . com*/

        RampartSecurityToken storedToken = (RampartSecurityToken) token;
        WSHandlerResult wsHandlerResult = null;
        WSSecurityEngineResult wsSecurityEngineResult = null;
        for (Iterator handlerIter = results.iterator(); handlerIter.hasNext();) {
            wsHandlerResult = (WSHandlerResult) handlerIter.next();
            for (Iterator engineResultIter = wsHandlerResult.getResults().iterator(); engineResultIter
                    .hasNext();) {
                wsSecurityEngineResult = (WSSecurityEngineResult) engineResultIter.next();
                Integer actInt = (Integer) wsSecurityEngineResult.get(WSSecurityEngineResult.TAG_ACTION);
                if (WSConstants.SIGN == actInt.intValue()) {

                    Principal principal = (Principal) wsSecurityEngineResult
                            .get(WSSecurityEngineResult.TAG_PRINCIPAL);
                    if (principal instanceof WSDerivedKeyTokenPrincipal) {
                        String baseTokenId = ((WSDerivedKeyTokenPrincipal) principal).getBasetokenId();
                        try {
                            Token usedToken = this.storage.getToken(baseTokenId);
                            if (!isEqual(usedToken.getSecret(), storedToken.getToken().getSecret())) {
                                throw new RMSecurityException("Stored security token is not match with the "
                                        + " security token for this message");
                            }
                        } catch (TrustException e) {
                            throw new RMSecurityException("Can not get the security token from the storage");
                        }
                    }
                }
            }

        }
    }
}

From source file:bboss.org.apache.velocity.runtime.resource.ResourceManagerImpl.java

/**
 * This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader. This
 * Hashtable will be passed in when initializing the the template loader.
 *//* w w w  .j  a  v a 2 s .c o  m*/
private void assembleResourceLoaderInitializers() {
    Vector resourceLoaderNames = rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER);
    StringUtils.trimStrings(resourceLoaderNames);

    for (Iterator it = resourceLoaderNames.iterator(); it.hasNext();) {

        /*
         * The loader id might look something like the following:
         *
         * file.resource.loader
         *
         * The loader id is the prefix used for all properties
         * pertaining to a particular loader.
         */
        String loaderName = (String) it.next();
        StringBuffer loaderID = new StringBuffer(loaderName);
        loaderID.append(".").append(RuntimeConstants.RESOURCE_LOADER);

        ExtendedProperties loaderConfiguration = rsvc.getConfiguration().subset(loaderID.toString());

        /*
         *  we can't really count on ExtendedProperties to give us an empty set
         */
        if (loaderConfiguration == null) {
            log.debug("ResourceManager : No configuration information found " + "for resource loader named '"
                    + loaderName + "' (id is " + loaderID + "). Skipping it...");
            continue;
        }

        /*
         *  add the loader name token to the initializer if we need it
         *  for reference later. We can't count on the user to fill
         *  in the 'name' field
         */

        loaderConfiguration.setProperty(RESOURCE_LOADER_IDENTIFIER, loaderName);

        /*
         * Add resources to the list of resource loader
         * initializers.
         */
        sourceInitializerList.add(loaderConfiguration);
    }
}

From source file:nl.nn.adapterframework.jdbc.XmlQuerySender.java

private String insertQuery(Connection connection, String correlationID, ParameterResolutionContext prc,
        String tableName, Vector columns) throws SenderException {
    try {/* w ww . j  ava 2s  .  co m*/
        String query = "INSERT INTO " + tableName + " (";
        Iterator iter = columns.iterator();
        String queryColumns = null;
        String queryValues = null;
        while (iter.hasNext()) {
            Column column = (Column) iter.next();
            if (queryColumns == null) {
                queryColumns = column.getName();
            } else {
                queryColumns = queryColumns + "," + column.getName();
            }
            if (queryValues == null) {
                queryValues = column.getQueryValue();
            } else {
                queryValues = queryValues + "," + column.getQueryValue();
            }
        }
        query = query + queryColumns + ") VALUES (" + queryValues + ")";
        return executeUpdate(connection, correlationID, tableName, query, columns);
    } catch (SenderException t) {
        throw new SenderException(getLogPrefix() + "got exception executing an INSERT SQL command", t);
    }
}

From source file:net.aepik.alasca.plugin.schemaconverter.core.SchemaConverter.java

/**
 * Retourne l'ensemble des dictionnaires possibles pour la syntaxe
 * du schma, et en fonction des syntaxes disponibles.
**//*from   ww  w . j a  v a  2s  . c o  m*/
public String[] getAvailableDictionnaries() {

    String[] result = null;
    Vector<String> resultTmp = new Vector<String>();

    // On rcupre aussi l'ensemble des dictionnaires disponibles dans le
    // traducteur. On boucle sur chaque entres de cette liste.

    String[] dictionnaries = traduc.getAvailableDictionnaries();
    for (String currentDictionnary : dictionnaries) {
        if (getAvailableSyntaxes(currentDictionnary) != null)
            resultTmp.add(currentDictionnary);
    }

    result = new String[resultTmp.size()];
    Iterator<String> it = resultTmp.iterator();
    int compteur = 0;
    while (it.hasNext()) {
        result[compteur] = it.next();
        compteur++;
    }

    return result;
}

From source file:org.apache.rampart.util.RampartUtil.java

public static Vector getContentEncryptedElements(Vector encryptedPartsElements, SOAPEnvelope envelope,
        Vector elements, Set namespaces) {

    Iterator elementsIter = elements.iterator();
    while (elementsIter.hasNext()) {
        String expression = (String) elementsIter.next();
        try {//from w  w  w.  j a  v a2s . co m
            XPath xp = new AXIOMXPath(expression);
            Iterator nsIter = namespaces.iterator();

            while (nsIter.hasNext()) {
                OMNamespace tmpNs = (OMNamespace) nsIter.next();
                xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());
            }

            List selectedNodes = xp.selectNodes(envelope);

            Iterator nodesIter = selectedNodes.iterator();

            while (nodesIter.hasNext()) {
                OMElement e = (OMElement) nodesIter.next();

                String localName = e.getLocalName();
                String namespace = e.getNamespace() != null ? e.getNamespace().getNamespaceURI() : null;

                WSEncryptionPart encryptedElem = new WSEncryptionPart(localName, namespace, "Content",
                        WSConstants.PART_TYPE_ELEMENT);

                encryptedElem.setXpath(expression);
                OMAttribute wsuId = e.getAttribute(new QName(WSConstants.WSU_NS, "Id"));

                if (wsuId != null) {
                    encryptedElem.setEncId(wsuId.getAttributeValue());
                }

                encryptedPartsElements.add(encryptedElem);

            }

        } catch (JaxenException e) {
            // This has to be changed to propagate an instance of a RampartException up
            throw new RuntimeException(e);
        }
    }

    return encryptedPartsElements;

}

From source file:ccas.BaseExportView.java

/**
 * @see org.displaytag.export.TextExportView#doExport(java.io.Writer)
 *//*from w w w. ja v  a2  s. c  o  m*/
public void doExport(Writer out) throws IOException//, JspException
{
    /*
     if (log.isDebugEnabled())
     {
    log.debug(getClass().getName());
     }
    */
    final String DOCUMENT_START = getDocumentStart();
    final String DOCUMENT_END = getDocumentEnd();
    final String ROW_START = getRowStart();
    final String ROW_END = getRowEnd();
    final String CELL_START = getCellStart();
    final String CELL_END = getCellEnd();
    final boolean ALWAYS_APPEND_CELL_END = getAlwaysAppendCellEnd();
    final boolean ALWAYS_APPEND_ROW_END = getAlwaysAppendRowEnd();

    // document start
    write(out, DOCUMENT_START);

    //        if (this.header)
    {
        write(out, doHeaders());
    }

    // get the correct iterator (full or partial list according to the exportFull field)
    Iterator rowIterator = vecBody.iterator();//this.model.getRowIterator(this.exportFull);

    // iterator on rows
    while (rowIterator.hasNext()) {
        Vector row = (Vector) rowIterator.next();
        /*
                    if (this.model.getTableDecorator() != null)
                    {
                
        String stringStartRow = this.model.getTableDecorator().startRow();
        write(out, stringStartRow);
                    }
        */
        // iterator on columns
        Iterator columnIterator = row.iterator();//row.getColumnIterator(this.model.getHeaderCellList());

        write(out, ROW_START);

        while (columnIterator.hasNext()) {
            // Column column = columnIterator.nextColumn();
            String column = (String) columnIterator.next();

            // Get the value to be displayed for the column
            String value = escapeColumnValue(column);//(column.getValue(this.decorated));

            write(out, CELL_START);

            write(out, value);

            if (ALWAYS_APPEND_CELL_END || columnIterator.hasNext()) {
                write(out, CELL_END);
            }

        }
        if (ALWAYS_APPEND_ROW_END || rowIterator.hasNext()) {
            write(out, ROW_END);
        }
    }

    // document end
    write(out, DOCUMENT_END);

}

From source file:nl.nn.adapterframework.jdbc.XmlQuerySender.java

private String updateQuery(Connection connection, String correlationID, String tableName, Vector columns,
        String where) throws SenderException {
    try {/*from   w  w  w. jav a  2 s .  c o  m*/
        String query = "UPDATE " + tableName + " SET ";
        Iterator iter = columns.iterator();
        String querySet = null;
        while (iter.hasNext()) {
            Column column = (Column) iter.next();
            if (querySet == null) {
                querySet = column.getName();
            } else {
                querySet = querySet + "," + column.getName();
            }
            querySet = querySet + "=" + column.getQueryValue();
        }
        query = query + querySet;
        if (where != null) {
            query = query + " WHERE " + where;
        }
        return executeUpdate(connection, correlationID, tableName, query, columns);
    } catch (SenderException t) {
        throw new SenderException(getLogPrefix() + "got exception executing an UPDATE SQL command", t);
    }
}

From source file:org.kepler.job.JobManager.java

/**
 * Submit a job, called from Job.submit(); boolean <i>overwrite</i>
 * indicates whether old files that exist on the same directory should be
 * removed before staging new files. As long jobIDs are not really unique,
 * this is worth to be true. <i>options</i> can be a special options string
 * for the actual jobmanager./*  w  w  w  .java 2s.com*/
 * 
 * @return: jobID as String if submission is successful (it is submitted and
 *          real jobID of the submitted job can be retrieved) real jobID can
 *          be found in job.status.jobID, but you do not need actually on
 *          error throws JobException
 */

protected String submit(Job job, boolean overwrite, String options) throws JobException {

    // first, get the submit file
    String submitFilePath = job.getSubmitFile(); // predefined submitfile?
    if (submitFilePath == null) { // no, create it now for the specific job
        // manager
        submitFilePath = new String(job.getLocalWorkdirPath() + File.separator + "submitcmd." + job.getJobID());
        jobSupport.createSubmitFile(submitFilePath, job);
        job.setSubmitFile(submitFilePath, true);
    }

    // the submitfile will be in current working dir of job, so we have to
    // get the name of the submitfile without path
    File sf = new File(submitFilePath);
    String submitFileName = sf.getName();

    // job manager specific submission command
    String commandStr = jobSupport.getSubmitCmd(job.getWorkdirPath() + "/" + submitFileName, options, job);

    //System.out.println("submit command is: " + commandStr);

    String cdCmd = "cd " + job.getWorkdirPath() + "; ";
    int exitCode = 0;

    if (commandStr == null || commandStr.trim().equals("")) {
        throw new JobException("Supporter class could not give back meaningful command to submit your job");
    }

    // stage the files before submission
    try {
        // delete the remote working directory if asked by the submitter
        if (overwrite)
            execObject.deleteFile(job.getWorkdirPath(), true, false);

        execObject.createDir(job.getWorkdirPath(), true);

        boolean cpLocalBinScript = false;
        boolean cpRemoteBinScript = false;
        boolean binPathSpecified = false;
        String binFileName = job.getBinFile();
        File binFile = null;
        //if binFile exists check where it should be staged.
        if (binFileName != null) {
            binFile = new File(binFileName);
            if (managerBinPath != null && !(managerBinPath.trim().equals("")))
                binPathSpecified = true;
            else if (job.isBinFileLocal()) {
                cpLocalBinScript = true;
            } else {
                cpRemoteBinScript = true;
            }
        }

        //If bin path is specified stage bin file to binpath
        if (binPathSpecified) {
            if (job.isBinFileLocal()) {
                execObject.copyTo(binFile, managerBinPath, false);
            } else {
                StringBuffer cmd = new StringBuffer("cp ");
                cmd.append(binFileName);
                cmd.append(" ");
                cmd.append(managerBinPath);
                ByteArrayOutputStream commandStdout = new ByteArrayOutputStream();
                ByteArrayOutputStream commandStderr = new ByteArrayOutputStream();
                exitCode = _exec(new String(cmd), commandStdout, commandStderr);
                if (exitCode != 0) {
                    throw new JobException("Error at copying remote bin file into specified bin path."
                            + "\nStdout:\n" + commandStdout + "\nStderr:\n" + commandStderr);
                }
            }

            //format bin file if it was copied from mac or windows
            Vector<File> vector = new Vector<File>();
            vector.add(binFile);
            formatFiles(managerBinPath, vector);
        }

        // stage local files/directories to the remote working directory
        // while also stripping end of line meta-characters from each file
        // if the file comes from mac or windows
        Vector<File> files = job.getLocalFiles();
        if (cpLocalBinScript) {
            //add bin file to the list of files to be copied to workingdir
            files.add(binFile);
        }
        execObject.copyTo(files, job.getWorkdirPath(), true);

        //Now try to change the format of the copied files
        //if the copy was from Windows or Mac
        formatFiles(job.getWorkdirPath(), files);

        // copy already remote files/directories to the working directory
        Vector<String> rfiles = job.getRemoteFiles();
        if (rfiles.size() > 0) {
            StringBuffer cmd = new StringBuffer("cp -r ");
            Iterator<String> it = rfiles.iterator();
            while (it.hasNext()) {
                cmd = cmd.append((String) it.next());
                cmd = cmd.append(" ");
            }
            if (cpRemoteBinScript) {
                //add bin file to the list of files to be copied to workingdir
                cmd = cmd.append(binFileName);
                cmd = cmd.append(" ");
            }
            cmd = cmd.append(job.getWorkdirPath());

            if (isDebugging)
                log.debug("Remote file copy command: " + cmd);

            ByteArrayOutputStream commandStdout = new ByteArrayOutputStream();
            ByteArrayOutputStream commandStderr = new ByteArrayOutputStream();
            exitCode = _exec(new String(cmd), commandStdout, commandStderr);
            if (exitCode != 0) {
                //if the error is because same file, do not throw exception.
                String[] stdErrArray = commandStderr.toString().split("\n");
                boolean throwE = false;
                for (int index = 0; index < stdErrArray.length; index++) {
                    if (!stdErrArray[index].trim().endsWith("are the same file")) {
                        throwE = true;
                        break;
                    }
                }
                if (throwE)
                    throw new JobException("Error at copying remote files into the job directory."
                            + "\nStdout:\n" + commandStdout + "\nStderr:\n" + commandStderr);
            }
        }

    } catch (ExecException e) {
        throw new JobException("Jobmanager.submit: Error at staging files to " + user + "@" + host + "\n" + e);
    }

    // we have to enter the workdir before submitting the job
    commandStr = new String(cdCmd + commandStr);

    // submit the job finally
    ByteArrayOutputStream commandStdout = new ByteArrayOutputStream();
    ByteArrayOutputStream commandStderr = new ByteArrayOutputStream();

    exitCode = _exec(commandStr, commandStdout, commandStderr);

    if (exitCode != 0) {
        throw new JobException("Error at job submission." + "\nCommand:" + commandStr + "\nStdout:\n"
                + commandStdout + "\nStderr:\n" + commandStderr);
    }

    // parse the output for real jobID
    // This method can throw JobException as well!
    String jobID = jobSupport.parseSubmitOutput(commandStdout.toString(), commandStderr.toString());

    return jobID;
}