Example usage for java.util Vector copyInto

List of usage examples for java.util Vector copyInto

Introduction

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

Prototype

public synchronized void copyInto(Object[] anArray) 

Source Link

Document

Copies the components of this vector into the specified array.

Usage

From source file:plugspud.PluginManager.java

/**
 * Return all plugins are of the specified class
 * /* ww w  .  j a v a2 s.  c o  m*/
 * @param pluginClass
 *            plugin class
 * 
 * @return DOCUMENT ME!
 */
public Plugin[] getPluginsOfClass(Class pluginClass) {
    Vector v = new Vector();

    for (Iterator i = plugins.iterator(); i.hasNext();) {
        PluginWrapper w = (PluginWrapper) i.next();

        if (pluginClass.isAssignableFrom(w.plugin.getClass()))
            v.addElement(w.plugin);
    }

    Plugin[] p = new Plugin[v.size()];
    v.copyInto(p);

    return p;
}

From source file:Main.java

public static String[] split(final String s, final char c, final boolean dblquotes, final int max) {
    int j = 0;//from  w w  w. j  av  a  2 s . co  m
    final Vector<String> vector = new Vector<String>();

    // add first max-1 components
    int num = 0;
    int i = 0;
    String ss = null;
    int k1;
    int k2;
    for (i = 0; num != max - 1; i = j + 1) {
        k1 = -1;
        k2 = -1;
        j = s.indexOf(c, i);
        if (dblquotes) {
            // should have k1=0
            k1 = s.indexOf('"', i);
            // quote found and before delimiter
            if (k1 >= 0 && k1 < j) {
                // next quote
                k2 = s.indexOf('"', k1 + 1);
                if (k2 >= 0) {
                    // recompute next delimiter - should have j=k2+1
                    j = s.indexOf(c, k2 + 1);
                }
            }
        }
        if (j >= 0) {
            if (dblquotes && k1 >= 0 && k2 >= 0) {
                ss = s.substring(k1 + 1, k2);
            } else {
                ss = s.substring(i, j);
            }
            vector.addElement(ss);
            num++;
        } else {
            if (dblquotes && k1 >= 0 && k2 >= 0) {
                ss = s.substring(k1 + 1, k2);
            } else {
                ss = s.substring(i);
            }
            vector.addElement(ss);
            num++;
            break;
        }
    }

    // add the max-th component
    k1 = -1;
    k2 = -1;
    if (max != 0 && j >= 0) {
        if (dblquotes) {
            k1 = s.indexOf('"', i);
            // quote found and before delimiter
            if (k1 >= 0) {
                // next quote
                k2 = s.indexOf('"', k1 + 1);
            }
        }
        if (dblquotes && k1 >= 0 && k2 >= 0) {
            ss = s.substring(k1 + 1, k2);
        } else {
            ss = s.substring(i);
        }
        vector.addElement(ss);
        num++;
    }

    // convert to array
    final String as[] = new String[num];
    vector.copyInto(as);

    // return the array
    return as;
}

From source file:org.soaplab.services.metadata.MetadataAccessorXML.java

/*********************************************************************
 * endElement()/*  w w w.jav  a 2  s .c o  m*/
 ********************************************************************/
public void endElement(String namespaceURI, String name, String qName) {

    if (tt.is(INPUT_PATH)) {

        // 'possible_values' are always dealt with only here  because
        // we had to wait for all of them first
        currInputPropertyDef.possibleValues = new String[allowed.size()];
        allowed.copyInto(currInputPropertyDef.possibleValues);
        allowed = null;

        inputs.addElement(currInputPropertyDef);
        currInputPropertyDef = null;

    } else if (tt.is(OUTPUT_PATH)) {
        outputs.addElement(currOutputPropertyDef);
        currOutputPropertyDef = null;

    } else if (tt.is(EXT_PATH)) {
        analysis.add(optionStack.pop());

    } else if (tt.is(EVENT_PATH)) {
        event.actions = new ActionDef[actions.size()];
        actions.copyInto(event.actions);
        actions.removeAllElements();

        event.conds = new CondDef[conditions.size()];
        conditions.copyInto(event.conds);
        conditions.removeAllElements();

    } else if (tt.is(ACTION_PATH)) {
        currAction.add(optionStack.pop());
        actions.addElement(currAction);
        currAction = null;

    } else if (tt.is(PARAMETER_PATH)) {
        Vector<ParamDef> base = paramStack.pop(); // should be always with 1 element
        ParamDef baseParam = base.elementAt(0);
        params.addElement(mergeDef(baseParam, currParam));
        currParam = null;

    } else if (tt.is(STANDARD_PATH) || tt.is(RANGE_PATH)) {
        ((StdParamDef) currParam).repeat = currRepeat;
        currRepeat = null;
        ((StdParamDef) currParam).lists = new ListDef[lists.size()];
        lists.copyInto(((StdParamDef) currParam).lists);
        lists = null;

    } else if (tt.is(DATA_PATH)) {
        ((IOParamDef) currParam).repeat = currRepeat;
        currRepeat = null;
        ((StdParamDef) currParam).lists = new ListDef[lists.size()];
        lists.copyInto(((StdParamDef) currParam).lists);
        lists = null;

        // ResultDef is deprecated - therefore:
        // - copy results options to the current IOPramDef
        for (Enumeration<ResultDef> en = results.elements(); en.hasMoreElements();) {
            ResultDef rd = en.nextElement();
            currParam.options.addProperties(rd.options);
            if (rd.specialType == ResultDef.URL)
                currParam.options.put(IOParamDef.SPECIAL_TYPE, "url");
        }
        results.removeAllElements();

    } else if (tt.is(RESULT_PATH)) {
        currResult.add(optionStack.pop());
        results.addElement(currResult);
        currResult = null;

    } else if (tt.is(CHOICE_PATH) || tt.is(CHOICE_LIST_PATH)) {
        Vector<ParamDef> bools = paramStack.pop();
        ((ChoiceParamDef) currParam).bools = new ParamDef[bools.size()];
        bools.copyInto(((ChoiceParamDef) currParam).bools);

    } else if (tt.is(BASE_PARAM_PATH) || tt.is(SUB_CHOICE_PATH) || tt.is(SUB_CHOICE_LIST_PATH)) {
        Vector<ParamDef> v = paramStack.peek();
        ParamDef p = v.lastElement();

        p.conds = new CondDef[conditions.size()];
        conditions.copyInto(p.conds);
        conditions.removeAllElements();

        p.add(optionStack.pop());

    } else if (name.equals("condition")) {
        if (currCondition != null) {
            currCondition.options.addProperties(optionStack.pop());
            conditions.addElement(currCondition);
            currCondition = null;
        }

    } else if (name.equals("repeatable")) {
        if (currRepeat != null) {
            currRepeat.options.addProperties(optionStack.pop());
        }

    } else if (name.equals("list")) {
        if (currList != null) {
            currList.items = new ListItemDef[listItems.size()];
            listItems.copyInto(currList.items);
            lists.addElement(currList);
            currList = null;
            listItems = null;
        }

    } else if (name.equals("default")) {
        StringBuffer buf = pcdataStack.pop();

        // we can be inside AppLab extensions...
        if (!paramStack.empty()) {
            Vector<ParamDef> v = paramStack.peek();
            if (v.size() > 0) {
                ParamDef p = v.lastElement();
                p.dflt = new String(buf);
            }

            // ...or we are in the BSA standard part
        } else if (currInputPropertyDef != null) {
            currInputPropertyDef.defaultValue = new String(buf);
        }

    } else if (name.equals("description")) {
        StringBuffer buf = pcdataStack.pop();
        analysis.options.put(SoaplabConstants.ANALYSIS_DESCRIPTION, new String(buf));

    } else if (name.equals("allowed")) {
        StringBuffer buf = pcdataStack.pop();
        if (allowed != null)
            allowed.addElement(new String(buf));

    } else if (name.equals("prompt")) {
        StringBuffer buf = pcdataStack.pop();
        if (!paramStack.empty()) {
            Vector<ParamDef> v = paramStack.peek();
            if (v.size() > 0) {
                ParamDef p = v.lastElement();
                p.options.put(SoaplabConstants.DATA_PROMPT, new String(buf));
            }
        }

    } else if (name.equals("help")) {
        StringBuffer buf = pcdataStack.pop();
        if (!paramStack.empty()) {
            Vector<ParamDef> v = paramStack.peek();
            if (v.size() > 0) {
                ParamDef p = v.lastElement();
                p.options.put(SoaplabConstants.DATA_HELP, new String(buf));
            }
        }
    }

    tt.pop();
}

From source file:org.openbravo.financial.paymentreport.erpCommon.ad_reports.PaymentReportDao.java

public static FieldProvider[] getObjectList(String objectNames) {
    Vector<Object> vector = new Vector<Object>(0);
    if (objectNames.equalsIgnoreCase("")) {
        FieldProvider objectListData[] = new FieldProvider[vector.size()];
        vector.copyInto(objectListData);

        return objectListData;
    } else {//from   w w w  .  j a v a2 s .  co  m
        String[] names = objectNames.substring(1, objectNames.length() - 1).split(", ");
        SQLReturnObject sqlRO;
        String name = null;

        for (int i = 0; i < names.length; i++) {
            sqlRO = new SQLReturnObject();
            names[i] = names[i];
            name = names[i].substring(1, names[i].length() - 1);
            sqlRO.setData("ID", name);
            sqlRO.setData("NAME", FIN_Utility.messageBD(name));
            sqlRO.setData("DESCRIPTION", "");
            vector.addElement(sqlRO);
        }

        FieldProvider objectListData[] = new FieldProvider[vector.size()];
        vector.copyInto(objectListData);

        return objectListData;
    }
}

From source file:plugspud.PluginManager.java

/**
 * Initialise the plugin manager/*from  www . j  a  va2s.c  o m*/
 * 
 * @param context
 *            context
 * 
 * @throws PluginException
 *             on any errors
 */
public void init(PluginHostContext context) throws PluginException {
    this.context = context;

    pluginMap = new HashMap<String, PluginManager.PluginWrapper>();
    plugins = new Vector<PluginWrapper>();
    startedPlugins = new Vector<PluginWrapper>();

    // Create the plugin directory if it doesn't exist
    pluginDir = context.getPluginDirectory();
    if (pluginDir == null) {
        context.log(PluginHostContext.LOG_ERROR, "No plugin directory has been provided by the plugin host.");
    } else {
        if (!pluginDir.exists() && !pluginDir.mkdirs())
            throw new PluginException("Could not create plugin directory " + pluginDir.getAbsolutePath());

        // First remove any plugins jars that are no longer required
        File removeFile = new File(pluginDir, "ros.list");
        if (removeFile.exists() && removeFile.canRead()) {
            InputStream rin = null;
            try {
                rin = new FileInputStream(removeFile);
                BufferedReader reader = new BufferedReader(new InputStreamReader(rin));
                String line = null;
                while ((line = reader.readLine()) != null) {
                    File z = new File(line);
                    context.log(PluginHostContext.LOG_INFORMATION,
                            "Deleting plugin library " + z.getAbsolutePath());
                    if (!z.delete())
                        context.log(PluginHostContext.LOG_ERROR, "Failed to delete " + z.getAbsolutePath());
                }
            } catch (IOException ioe) {
                context.log(PluginHostContext.LOG_ERROR,
                        "Failed to read remove-on-startup list file " + removeFile.getAbsolutePath());
            } finally {
                if (rin != null) {
                    try {
                        rin.close();
                    } catch (IOException ioe) {
                    }
                }
                if (!removeFile.delete()) {
                    context.log(PluginHostContext.LOG_ERROR, "Failed to remove remove-on-startup list file "
                            + removeFile.getAbsolutePath() + ". Further errors may appear.");
                }
            }
        }

        if (!pluginDir.exists() && !pluginDir.mkdirs())
            throw new PluginException("Could not create plugin directory " + pluginDir.getAbsolutePath());

        // First unzip any newly installed plugin archives
        File[] newPlugins = pluginDir.listFiles(new FileFilter() {
            public boolean accept(File f) {
                return f.getName().toLowerCase().endsWith(".tmp");
            }
        });
        for (int i = 0; i < newPlugins.length; i++) {
            try {
                unzip(newPlugins[i], pluginDir);
                if (!newPlugins[i].delete()) {
                    context.log(PluginHostContext.LOG_ERROR,
                            "New plugin archive " + newPlugins[i].getAbsolutePath() + " could not be "
                                    + "deleted. Until this file is removed, this plugin "
                                    + "will continue to be installed every time " + context.getPluginHostName()
                                    + "starts up.");
                }
            } catch (Exception e) {
                context.log(PluginHostContext.LOG_ERROR, e);
                throw new PluginException(
                        "Failed to unzip newly installed plugin " + newPlugins[i].getAbsolutePath() + ". "
                                + e.getMessage() == null ? "<null>" : e.getMessage());
            }
        }
    }

    try {

        // Create a classloader for all of the plugin jars
        Vector<URL> v = new Vector<URL>();
        if (pluginDir != null) {
            URL u = pluginDir.toURL();
            v.addElement(u);
            context.log(PluginHostContext.LOG_INFORMATION,
                    "Added Found plugin directory " + u.toExternalForm());
            findJars(pluginDir, v);
            URL[] urls = new URL[v.size()];
            v.copyInto(urls);
        }
        URL[] urls = (URL[]) v.toArray(new URL[v.size()]);
        classLoader = new URLClassLoader(urls,
                parentClassLoader == null ? getClass().getClassLoader() : parentClassLoader);
        ((URLClassLoader) classLoader).getURLs();

        // Add the standard plugins
        URL url = context.getStandardPluginsResource();
        if (url != null) {
            try {
                loadPlugins(url, classLoader, true);
            } catch (PluginException pe) {
                context.log(PluginHostContext.LOG_ERROR, pe);
            }
        } else {

            // Add the plugins
            for (Enumeration<URL> e = classLoader.getResources("plugins.properties"); e.hasMoreElements();) {
                URL resource = e.nextElement();
                context.log(PluginHostContext.LOG_DEBUG,
                        "Found plugins.properties in " + resource.toExternalForm());
                loadPlugins(resource, classLoader, false);
            }
        }

        Collections.sort(plugins);
        checkDependencies();

    } catch (Throwable t) {
        throw new PluginException("Plugin manager failed to initialise. ", t);
    }
    initialised = true;
}

From source file:com.isecpartners.gizmo.FourthIdea.java

private static String[] translateCommandline(final String toProcess) {
    if (toProcess == null || toProcess.length() == 0) {
        // no command? no string
        return new String[0];
    }//from  ww w  .  j  ava 2  s.c  o m

    // parse with a simple finite state machine

    final int normal = 0;
    final int inQuote = 1;
    final int inDoubleQuote = 2;
    int state = normal;
    StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
    Vector v = new Vector();
    StringBuffer current = new StringBuffer();
    boolean lastTokenHasBeenQuoted = false;

    while (tok.hasMoreTokens()) {
        String nextTok = tok.nextToken();
        switch (state) {
        case inQuote:
            if ("\'".equals(nextTok)) {
                lastTokenHasBeenQuoted = true;
                state = normal;
            } else {
                current.append(nextTok);
            }
            break;
        case inDoubleQuote:
            if ("\"".equals(nextTok)) {
                lastTokenHasBeenQuoted = true;
                state = normal;
            } else {
                current.append(nextTok);
            }
            break;
        default:
            if ("\'".equals(nextTok)) {
                state = inQuote;
            } else if ("\"".equals(nextTok)) {
                state = inDoubleQuote;
            } else if (" ".equals(nextTok)) {
                if (lastTokenHasBeenQuoted || current.length() != 0) {
                    v.addElement(current.toString());
                    current = new StringBuffer();
                }
            } else {
                current.append(nextTok);
            }
            lastTokenHasBeenQuoted = false;
            break;
        }
    }

    if (lastTokenHasBeenQuoted || current.length() != 0) {
        v.addElement(current.toString());
    }

    if (state == inQuote || state == inDoubleQuote) {
        throw new IllegalArgumentException("Unbalanced quotes in " + toProcess);
    }

    String[] args = new String[v.size()];
    v.copyInto(args);
    return args;
}

From source file:com.jada.content.template.TemplateEngine.java

public MenuInfo[] getMenu(String menuSetName) throws Exception {
    boolean customerSession = ContentLookupDispatchAction.isCustomerSession(request);
    Vector<?> vector = api.getMenu(menuSetName, customerSession);
    MenuInfo menuInfo[] = new MenuInfo[vector.size()];
    vector.copyInto(menuInfo);
    return menuInfo;
}

From source file:com.adito.boot.Util.java

/**
 * Split a string into an array taking into account delimiters, quotes and
 * escapes/*from w w  w .j av  a  2 s. co m*/
 * 
 * @param str string to split
 * @param delim delimiter
 * @param quote quote character
 * @param escape escape character
 * @return array
 */

public static String[] splitString(String str, char delim, char quote, char escape) {
    Vector v = new Vector();
    StringBuffer str1 = new StringBuffer();
    char ch = ' ';
    boolean inQuote = false;
    boolean escaped = false;

    for (int i = 0; i < str.length(); i++) {
        ch = str.charAt(i);

        if ((escape != -1) && (ch == escape) && !escaped) {
            escaped = true;
        } else {
            if ((quote != -1) && (ch == quote) && !escaped) {
                inQuote = !inQuote;
            } else if (!inQuote && (ch == delim && !escaped)) {
                v.addElement(str1.toString());
                str1.setLength(0);
            } else {
                str1.append(ch);
            }
            if (escaped) {
                escaped = false;
            }
        }
    }

    if (str.length() > 0) {
        v.addElement(str1.toString());

    }
    String[] array;
    array = new String[v.size()];
    v.copyInto(array);

    return array;
}

From source file:org.hyperic.util.file.match.MatcherScanner.java

protected void scandir(File dir, String vpath, int depth) {

    // This is just here to ensure that our scanning doesn't spin-up
    // the CPU.  We sleep briefly every few directories to give other
    // processes a chance to run.
    pause();//from  ww w.  j a  v  a 2 s  .c  om

    if (depth > maxDepth && maxDepth != -1) {
        if (log != null) {
            //log.info("scandir: Skipping dir " + dir.getAbsolutePath() 
            //         + " and all subdirs because they are below our "
            //         + "maxDepth of " + maxDepth);
        }
        return;

    } else {
        checkInterrupted();
        if (isExcluded(dir.getAbsolutePath())) {
            //log.info("scandir: Skipping: " + dir.getAbsolutePath() 
            //         + " because it is explicitly excluded from scan.");
            return;
        }
    }

    if (!dir.canRead()) {
        errors.add(new MatcherException(
                "Don't have permissions to read " + "directory: " + dir.getAbsolutePath()));
        return;
    }
    String[] newfiles = dir.list();

    if (newfiles == null) {
        /*
         * two reasons are mentioned in the API docs for File.list
         * (1) dir is not a directory. This is impossible as
         *     we wouldn't get here in this case.
         * (2) an IO error occurred (why doesn't it throw an exception
         *     then???)
         */
        errors.add(new MatcherException("IO error scanning directory " + dir.getAbsolutePath()));
        return;
    }

    // log.debug("scandir: Scanning: " + dir.getAbsolutePath());

    // Tell someone how our scan is progressing...
    if (progressCB != null)
        progressCB.notifyScanDir(dir);

    if (!myFollowSymlinks) {
        Vector noLinks = new Vector();
        for (int i = 0; i < newfiles.length; i++) {
            checkInterrupted();
            try {
                if (myFileUtils.isSymbolicLink(dir, newfiles[i])) {
                    String name = vpath + newfiles[i];
                    File file = new File(dir, newfiles[i]);
                    if (file.isDirectory()) {
                        dirsExcluded.addElement(name);
                    } else {
                        filesExcluded.addElement(name);
                    }
                } else {
                    noLinks.addElement(newfiles[i]);
                }
            } catch (IOException ioe) {
                String msg = "IOException caught while checking " + "for links, couldn't get canonical path!";
                // will be caught and redirected to Ant's logging system
                errors.add(new MatcherException(msg, ioe));
            }
        }
        newfiles = new String[noLinks.size()];
        noLinks.copyInto(newfiles);
    }

    for (int i = 0; i < newfiles.length; i++) {
        checkInterrupted();
        pause();
        String name = vpath + newfiles[i];
        File file = new File(dir, newfiles[i]);
        if (file.isDirectory()) {
            if (isIncluded(name)) {
                if (!isExcluded(name)) {
                    // log.info("scandir: checking isSelected(" + name + "," + file.getAbsolutePath() + ")");
                    if (isSelected(name, file)) {
                        continue;
                    } else {
                        if (/*fast &&*/ couldHoldIncluded(name)) {
                            scandir(file, name + File.separator, depth + 1);
                        }
                    }

                } else {
                    if (/*fast &&*/ couldHoldIncluded(name)) {
                        scandir(file, name + File.separator, depth + 1);
                    }
                }
            } else {
                if (/*fast &&*/ couldHoldIncluded(name)) {
                    scandir(file, name + File.separator, depth + 1);
                }
            }
            // if (!fast) {
            //     scandir(file, name + File.separator, fast);
            // }
        } else if (file.isFile()) {
            if (isIncluded(name)) {
                if (!isExcluded(name)) {
                    if (isSelected(name, file)) {
                        continue;
                    } else {
                        // everythingIncluded = false;
                        // filesDeselected.addElement(name);
                    }
                } else {
                    // everythingIncluded = false;
                    // filesExcluded.addElement(name);
                }
            } else {
                // everythingIncluded = false;
                // filesNotIncluded.addElement(name);
            }
        }
    }
}

From source file:org.openadaptor.auxil.connector.ftp.SunFTPConnection.java

/**
 * Retrieves a list of file names on the remote server that match the supplied pattern. We use the nameList() call on
 * the FTP client which returns a string of the format: <p/>
 * //from ww  w. j  a va 2  s .  c om
 * <blockquote>
 * 
 * <pre>
 *       -rw-r--r--   1 restrict restrict      3787 Nov 10 06:07 Georgina.html
 * </pre>
 * 
 * </blockquote>
 * 
 * We strip out all the dross up to the filename. This will fail if the output from the list call changes!
 * 
 * @param filePattern -
 *          the pattern the match file names against
 * 
 * @return array of the file names or null if none found
 * 
 * @throws ConnectionException -
 *           if there was an communications error
 */
public String[] fileList(String filePattern) {
    Vector v = new Vector();

    checkLoggedIn();

    try {
        TelnetInputStream in = _ftpClient.nameList(filePattern);

        BufferedReader rdr = new BufferedReader(new InputStreamReader(in));
        String fileName;

        while ((fileName = rdr.readLine()) != null) {
            // list returns file details in the following format:
            // -rw-r--r-- 1 restrict restrict 3787 Nov 10 06:07 Georgina.html
            // we have to strip out the extra details and leave the filename
            fileName = fileName.substring(fileName.lastIndexOf(" ") + 1);
            v.add(fileName);
        }
    } catch (Exception e) {
        close();
        throw new ConnectionException("Error retrieving file list: " + e.getMessage(), this);
    }

    // no files - well return null then
    if (v.size() == 0)
        return null;

    // take the list of file names and convert them into an array
    String[] s = new String[v.size()];
    v.copyInto(s);

    return s;
}