Example usage for java.util Vector elements

List of usage examples for java.util Vector elements

Introduction

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

Prototype

public Enumeration<E> elements() 

Source Link

Document

Returns an enumeration of the components of this vector.

Usage

From source file:com.krminc.phr.security.PHRRealm.java

/**
 * Returns names of all the groups in this particular realm.
 *
 * @return enumeration of group names (strings)
 *
 *//*  ww w . j  ava  2s . co  m*/
public Enumeration getGroupNames() throws BadRealmException {
    //check role cache before querying

    String query = "SELECT UNIQUE role FROM user_roles";
    ResultSet rs = null;
    Vector roles = new Vector();
    PreparedStatement st = null;
    try {
        createDS();
        conn = ds.getNonTxConnection();
        st = conn.prepareStatement(query);
        rs = st.executeQuery();
    } catch (Exception e) {
        log("Error getting roles from database");
        log(e.getMessage());
        rs = null;
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
            log(e.getMessage());
        }
        conn = null;
    }
    if (rs != null) {
        try {
            rs.beforeFirst();
            while (rs.next()) {
                roles.add(rs.getString(1));
            }
        } catch (Exception e) {
            log("Error getting roles from resultset");
            log(e.getMessage());
        } finally {
            try {
                st.close();
                rs.close();
            } catch (Exception e) {
                log(e.getMessage());
            }
        }
    }
    return roles.elements();
}

From source file:com.krminc.phr.security.PHRRealm.java

/**
 * Returns names of all the users in this particular realm.
 *
 * @return enumeration of user names//from www  .j a  v  a 2 s  .  c  o m
 *
 */
public Enumeration getUserNames() throws BadRealmException {
    String query = "SELECT username FROM user_users";
    ResultSet rs = null;
    Vector usernames = new Vector();
    PreparedStatement st = null;
    try {
        createDS();
        conn = ds.getNonTxConnection();
        st = conn.prepareStatement(query);
        rs = st.executeQuery();
    } catch (Exception e) {
        log("Error getting usernames from database");
        log(e.getMessage());
        rs = null;
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
            log(e.getMessage());
        }
        conn = null;
    }
    if (rs != null) {
        try {
            rs.beforeFirst();
            while (rs.next()) {
                usernames.add(rs.getString(1));
            }
        } catch (Exception e) {
            log("Error getting usernames from resultset");
            log(e.getMessage());
        } finally {
            try {
                st.close();
                rs.close();
            } catch (Exception e) {
                log(e.getMessage());
            }
        }
    }
    return usernames.elements();
}

From source file:org.ecoinformatics.seek.datasource.darwincore.DarwinCoreDataSource.java

/**
 * Creates a string table from the resultset records
 * //from  w  w  w . ja v a  2  s  . c o  m
 * @param aRS
 *     */
private String createTableFromResultset(String delim, ResultsetTypeRecord[] records) {
    StringBuffer tableStr = new StringBuffer();
    StringBuffer rowOfData = new StringBuffer();
    DSTableIFace tableSchema = (DSTableIFace) _resultsetSchemaDef.getTables().elementAt(0);
    Vector columns = tableSchema.getFields();

    appendHeaderRow(tableStr, columns, delim, ROWDELIM);

    for (int i = 0; i < records.length; i++) {
        rowOfData.setLength(0);

        //
        // Note: this code assumes all the columns are returned for every
        // record.
        // It also assumes they are in the same order as in the metadata.
        Enumeration colEnum = columns.elements();
        int colInx = 0;
        while (colEnum.hasMoreElements()) {
            DSTableFieldIFace colDef = (DSTableFieldIFace) colEnum.nextElement();
            ResultsetTypeRecordReturnField field = records[i].getReturnField(colInx);
            String eleStr = field.get_value();
            if (colInx > 0) {
                rowOfData.append(delim);
            }
            rowOfData.append(getValidStringValueForType(eleStr, colDef.getDataType()));
            colInx++;
        }
        tableStr.append(rowOfData);
        tableStr.append(ROWDELIM);
    }
    return tableStr.toString();
}

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

/**************************************************************************
 * Check if loaded metadata contains all necessary tags.
 **************************************************************************/
public void checkMetadata() throws SoaplabException {

    Vector<String> errors = new Vector<String>();

    if (analysis == null) {
        errors.addElement("No 'analysis' tag found.");
    } else {/*  w  w  w.j  a v a2  s. c o m*/
        if (analysis.type == null)
            errors.addElement("An analysis must have a type defined.");
        if (analysis.category == null)
            errors.addElement("An analysis must have a category defined.");
        if (analysis.appName == null)
            errors.addElement("An analysis must have a name defined.");
    }

    if (event == null) {
        errors.addElement("No 'event' tag found.");
    } else {
        if (event.actions == null || event.actions.length == 0)
            errors.addElement("An event must have at least one action.");
    }

    // any errors found?
    if (errors.size() > 0) {
        StringBuilder buf = new StringBuilder();
        for (Enumeration en = errors.elements(); en.hasMoreElements();)
            buf.append("\n\t" + (String) en.nextElement());
        throw new SoaplabException("Errors in XML input:" + buf.toString());
    }
}

From source file:com.krminc.phr.security.PHRRealm.java

/**
 * Returns enumeration of groups that a particular user belongs to.
 *
 *@exception NoSuchUserException//from  w  w w .  j  ava 2  s.  c o  m
 */
public Enumeration getGroupNames(String user) throws NoSuchUserException {
    //check user cache before querying?

    String query = "SELECT DISTINCT role FROM user_roles WHERE username = ?";
    ResultSet rs = null;
    Vector roles = new Vector();
    PreparedStatement st = null;
    try {
        createDS();
        conn = ds.getNonTxConnection();
        st = conn.prepareStatement(query);
        st.setString(1, user);
        rs = st.executeQuery();
    } catch (Exception e) {
        log("Error getting roles from database");
        log(e.getMessage());
        rs = null;
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
            log(e.getMessage());
        }
        conn = null;
    }
    if (rs != null) {
        try {
            rs.beforeFirst();
            while (rs.next()) {
                roles.add(rs.getString(1));
            }
        } catch (Exception e) {
            log("Error getting roles from resultset");
            log(e.getMessage());
        } finally {
            try {
                st.close();
                rs.close();
            } catch (Exception e) {
                log(e.getMessage());
            }
        }
    } else {
        throw new NoSuchUserException("User not available.");
    }
    return roles.elements();
}

From source file:org.atricore.idbus.kernel.common.support.osgi.OsgiBundlespaceClassLoader.java

@Override
protected Enumeration<URL> findResources(String name) throws IOException {

    //        if (logger.isTraceEnabled())
    //            logger.trace("findResources (by name) " + name);

    Vector<URL> resources = new Vector<URL>();
    Map<Bundle, OsgiBundleClassLoader> bundleClassLoaders = getBundleClassLoaders();
    for (Bundle bundle : getBundles()) {

        if (canLoadResources(bundle)) {

            //                if (logger.isTraceEnabled())
            //                    logger.trace("findResources (by name) " + name + " in bundle " + bundle.getSymbolicName());

            try {
                Enumeration<URL> bundleResources = bundleClassLoaders.get(bundle).getResources(name);

                if (bundleResources != null && bundleResources.hasMoreElements()) {
                    while (bundleResources.hasMoreElements()) {

                        URL u = bundleResources.nextElement();

                        //                            if (logger.isTraceEnabled())
                        //                                logger.trace("findResources (by name) " + name + " found in bundle " +
                        //                                        bundle.getSymbolicName() +
                        //                                        "(" + bundle.getBundleId() + ")" +
                        //                                        u);

                        resources.add(u);
                    }/*from w ww  . ja  va2s.  c  o m*/
                }
            } catch (Throwable ex) {
                /// Catch any other exceptions which could be thrown by a bundle loading a resource.
            }
        }
    }

    if (resources.size() > 0) {
        return resources.elements();
    } else {
        if (getSupportingClassLoader() != null) {

            //                if (logger.isTraceEnabled())
            //                    logger.trace("findResources (by name) " + name + ", looking in supporting classloaders");

            return getSupportingClassLoader().getResources(name);
        } else {
            return new Vector<URL>().elements();
        }
    }
}

From source file:com.izforge.izpack.panels.shortcut.ShortcutPanelLogic.java

/**
 * Creates all shortcuts based on the information in shortcuts.
 *//*from ww w .  j a  v a2 s  .  c o m*/
private void createShortcuts(List<ShortcutData> shortcuts) {
    if (!createShortcuts) {
        return;
    }
    String groupName;

    List<String> startMenuShortcuts = new ArrayList<String>();
    for (ShortcutData data : shortcuts) {
        try {
            groupName = this.groupName + data.subgroup;
            shortcut.setUserType(userType);
            shortcut.setLinkName(data.name);
            shortcut.setLinkType(data.type);
            shortcut.setArguments(data.commandLine);
            shortcut.setDescription(data.description);
            shortcut.setIconLocation(data.iconFile, data.iconIndex);

            shortcut.setShowCommand(data.initialState);
            shortcut.setTargetPath(data.target);
            shortcut.setWorkingDirectory(data.workingDirectory);
            shortcut.setEncoding(data.deskTopEntryLinux_Encoding);
            shortcut.setMimetype(data.deskTopEntryLinux_MimeType);
            shortcut.setRunAsAdministrator(data.runAsAdministrator);

            shortcut.setTerminal(data.deskTopEntryLinux_Terminal);
            shortcut.setTerminalOptions(data.deskTopEntryLinux_TerminalOptions);
            shortcut.setType(data.deskTopEntryLinux_Type);
            shortcut.setKdeSubstUID(data.deskTopEntryLinux_X_KDE_SubstituteUID);
            shortcut.setKdeUserName(data.deskTopEntryLinux_X_KDE_UserName);
            shortcut.setURL(data.deskTopEntryLinux_URL);
            shortcut.setTryExec(data.TryExec);
            shortcut.setCategories(data.Categories);
            shortcut.setCreateForAll(data.createForAll);
            shortcut.setUninstaller(uninstallData);

            if (data.addToGroup) {
                shortcut.setProgramGroup(groupName);
            } else {
                shortcut.setProgramGroup("");
            }

            shortcut.save();

            if (data.type == Shortcut.APPLICATIONS || data.addToGroup) {
                if (shortcut instanceof com.izforge.izpack.util.os.Unix_Shortcut) {
                    com.izforge.izpack.util.os.Unix_Shortcut unixcut = (com.izforge.izpack.util.os.Unix_Shortcut) shortcut;
                    String f = unixcut.getWrittenFileName();
                    if (f != null) {
                        startMenuShortcuts.add(f);
                    }
                }
            }

            // add the file and directory name to the file list
            String fileName = shortcut.getFileName();
            files.add(0, fileName);

            File file = new File(fileName);
            File base = new File(shortcut.getBasePath());
            Vector<File> intermediates = new Vector<File>();

            execFiles.add(new ExecutableFile(fileName, ExecutableFile.UNINSTALL, ExecutableFile.IGNORE,
                    new ArrayList<OsModel>(), false));
            files.add(fileName);

            while ((file = file.getParentFile()) != null) {
                if (file.equals(base)) {
                    break;
                }
                intermediates.add(file);
            }

            if (file != null) {
                Enumeration<File> filesEnum = intermediates.elements();

                while (filesEnum.hasMoreElements()) {
                    files.add(0, filesEnum.nextElement().toString());
                }
            }
        } catch (Exception ignored) {
        }
    }
    if (OsVersion.IS_UNIX) {
        writeXDGMenuFile(startMenuShortcuts, this.groupName, programGroupIconFile, programGroupComment);
    }
    shortcut.execPostAction();

    try {
        if (execFiles != null) {
            //
            // TODO: Hi Guys,
            // TODO The following commented lines sometimes produces an uncatchable
            // nullpointer Exception!
            // TODO evaluate for what reason the files should exec.
            // TODO if there is a serious explanation, why to do that,
            // TODO the code must be more robust
            //FileExecutor executor = new FileExecutor(execFiles);
            // evaluate executor.executeFiles( ExecutableFile.NEVER, null );
        }
    } catch (NullPointerException nep) {
        nep.printStackTrace();
    } catch (RuntimeException cannot) {
        cannot.printStackTrace();
    }
    shortcut.cleanUp();
}

From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java

/**
 * Anhand des Alias des Gertes die Tauchgangsliste fllen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //  ww  w .  j  ava2s  . c om
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 02.07.2012
 * @param deviceAlias
 */
@SuppressWarnings("unchecked")
private void fillDiveComboBox(String cDevice) {
    String device;
    DateTime dateTime;
    long javaTime;
    //
    device = cDevice;
    if (device != null) {
        lg.debug("search dive list for device <" + device + ">...");
        releaseGraph();
        // Eine Liste der Dives lesen
        lg.debug("read dive list for device from DB...");
        Vector<String[]> entrys = databaseUtil.getDiveListForDeviceLog(device);
        if (entrys.size() < 1) {
            lg.info("no dives for device <" + cDevice + "/" + databaseUtil.getAliasForNameConn(device)
                    + "> found in DB.");
            clearDiveComboBox();
            return;
        }
        //
        // Objekt fr das Modell erstellen
        Vector<String[]> diveEntrys = new Vector<String[]>();
        // die erfragten details zurechtrcken
        // Felder sind:
        // H_DIVEID,
        // H_H_DIVENUMBERONSPX
        // H_STARTTIME,
        for (Enumeration<String[]> enu = entrys.elements(); enu.hasMoreElements();) {
            String[] origSet = enu.nextElement();
            // zusammenbauen fuer Anzeige
            String[] elem = new String[3];
            // SPX-DiveNumber etwas einrcken, fr vierstellige Anzeige
            elem[0] = origSet[0];
            elem[1] = String.format("%4s", origSet[1]);
            // Die UTC-Zeit als ASCII/UNIX wieder zu der originalen Zeit fr Java zusammenbauen
            try {
                javaTime = Long.parseLong(origSet[2]) * 1000;
                dateTime = new DateTime(javaTime);
                elem[2] = dateTime.toString(LangStrings.getString("MainCommGUI.timeFormatterString"));
            } catch (NumberFormatException ex) {
                lg.error("Number format exception (value=<" + origSet[1] + ">: <" + ex.getLocalizedMessage()
                        + ">");
                elem[1] = "error";
            }
            diveEntrys.add(elem);
        }
        // aufrumen
        entrys.clear();
        entrys = null;
        // die box initialisieren
        LogListComboBoxModel listBoxModel = new LogListComboBoxModel(diveEntrys);
        diveSelectComboBox.setModel(listBoxModel);
        if (diveEntrys.size() > 0) {
            diveSelectComboBox.setSelectedIndex(0);
        }
    } else {
        lg.debug("no device found....");
    }
}

From source file:org.openflexo.foundation.ie.IEWOComponent.java

/**
 * Return a Vector of all ComponentInstance objects involved in the definition of that component
 * /*from ww w . j  a  va 2 s .c  o  m*/
 * @return a newly created Vector of ComponentInstance objects
 */
public Vector<ComponentInstance> getAllComponentInstances() {
    Vector allIEObjects = getAllEmbeddedIEObjects();
    Vector<ComponentInstance> returned = new Vector<ComponentInstance>();
    for (FlexoResource r : getFlexoResource().getDependentResources()) {
        if (r instanceof FlexoComponentResource) {
            for (ComponentInstance ci : ((FlexoComponentResource) r).getComponentDefinition()
                    .getComponentInstances()) {
                if (ci.getXMLResourceData() == this) {

                }
            }
        }
    }
    for (Enumeration en = allIEObjects.elements(); en.hasMoreElements();) {
        IEObject next = (IEObject) en.nextElement();
        if (next instanceof ComponentInstance) {
            returned.add((ComponentInstance) next);
        }
    }
    return returned;
}

From source file:org.agnitas.beans.impl.MailingImpl.java

@Override
public List<String> cleanupDynTags(Vector<String> keep) {
    Vector<String> remove = new Vector<String>();
    String tmp = null;//from   ww  w . j  av  a 2 s .c  o  m

    // first find keys which should be removed
    Iterator<String> it = this.dynTags.keySet().iterator();
    while (it.hasNext()) {
        tmp = it.next();
        if (!keep.contains(tmp)) {
            remove.add(tmp);
        }
    }

    // now remove them!
    Enumeration<String> e = remove.elements();
    while (e.hasMoreElements()) {
        dynTags.remove(e.nextElement());
    }

    return remove;
}