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:jade.domain.DFDBKB.java

/**
 * Return all known subscriptions at the DF
 * @return <code>Enumeration</code> with instances of the class 
 * <code> jade.proto.SubscriptionResponder&Subscription</code>
 *///from   ww w .j  av  a  2s  .  com
public Enumeration getSubscriptions() {
    Vector subscriptions = new Vector();
    StringACLCodec codec = new StringACLCodec();
    ResultSet rs = null;

    try {
        rs = getPreparedStatements().stm_selSubscriptions.executeQuery();
        while (rs.next()) {
            String base64Str = rs.getString("aclm");
            String aclmStr = new String(Base64.decodeBase64(base64Str.getBytes("US-ASCII")), "US-ASCII");
            ACLMessage aclm = codec.decode(aclmStr.getBytes(), ACLCodec.DEFAULT_CHARSET);
            subscriptions.add(sr.createSubscription(aclm));
        }

    } catch (Exception e) {
        if (logger.isLoggable(Logger.SEVERE))
            logger.log(Logger.SEVERE, "Error retrieving subscriptions from the database", e);

    } finally {
        closeResultSet(rs);
    }
    return subscriptions.elements();
}

From source file:com.netscape.cmscore.usrgrp.UGSubsystem.java

/**
 * builds a User instance. Sets only uid for user entry retrieved
 * from LDAP server. for listing efficiency only.
 *
 * @return the User entity./*from   w w w.  ja va  2  s . co m*/
 */
protected IUser lbuildUser(LDAPEntry entry) throws EUsrGrpException {
    LDAPAttribute uid = entry.getAttribute("uid");
    if (uid == null) {
        throw new EUsrGrpException("No Attribute UID in LDAP Entry " + entry.getDN());
    }
    IUser id = createUser(this, (String) uid.getStringValues().nextElement());
    LDAPAttribute cnAttr = entry.getAttribute("cn");

    if (cnAttr != null) {
        String cn = (String) cnAttr.getStringValues().nextElement();

        if (cn != null) {
            id.setFullName(cn);
        }

    }

    LDAPAttribute certAttr = entry.getAttribute(LDAP_ATTR_USER_CERT);

    if (certAttr != null) {
        Vector<X509Certificate> certVector = new Vector<X509Certificate>();
        @SuppressWarnings("unchecked")
        Enumeration<byte[]> e = certAttr.getByteValues();

        try {
            for (; e != null && e.hasMoreElements();) {
                X509Certificate cert = new X509CertImpl(e.nextElement());

                certVector.addElement(cert);
            }
        } catch (Exception ex) {
            throw new EUsrGrpException(CMS.getUserMessage("CMS_INTERNAL_ERROR"));
        }

        if (certVector != null && certVector.size() != 0) {
            // Make an array of certs
            X509Certificate[] certArray = new X509Certificate[certVector.size()];
            Enumeration<X509Certificate> en = certVector.elements();
            int i = 0;

            while (en.hasMoreElements()) {
                certArray[i++] = en.nextElement();
            }

            id.setX509Certificates(certArray);
        }
    }

    return id;
}

From source file:com.netscape.cmscore.usrgrp.UGSubsystem.java

/**
 * builds a User instance. Set all attributes retrieved from
 * LDAP server and set them on User./*  ww  w .j  ava2s  . co m*/
 *
 * @return the User entity.
 */
protected IUser buildUser(LDAPEntry entry) throws EUsrGrpException {
    LDAPAttribute uid = entry.getAttribute("uid");
    if (uid == null) {
        throw new EUsrGrpException("No Attribute UID in LDAP Entry " + entry.getDN());
    }
    IUser id = createUser(this, (String) uid.getStringValues().nextElement());
    LDAPAttribute cnAttr = entry.getAttribute("cn");

    if (cnAttr != null) {
        String cn = (String) cnAttr.getStringValues().nextElement();

        if (cn != null) {
            id.setFullName(cn);
        }
    }

    String userdn = entry.getDN();

    if (userdn != null) {
        id.setUserDN(userdn);
    } else { // the impossible
        log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_USRGRP_BUILD_USER", userdn));

        throw new EUsrGrpException(CMS.getUserMessage("CMS_INTERNAL_ERROR"));
    }

    /*
     LDAPAttribute certdnAttr = entry.getAttribute(LDAP_ATTR_CERTDN);
     if (certdnAttr != null) {
     String cdn = (String)certdnAttr.getStringValues().nextElement();
     if (cdn != null) {
     id.setCertDN(cdn);
     }
     }
     */
    LDAPAttribute mailAttr = entry.getAttribute("mail");

    if (mailAttr != null) {
        @SuppressWarnings("unchecked")
        Enumeration<String> en = mailAttr.getStringValues();

        if (en != null && en.hasMoreElements()) {
            String mail = en.nextElement();

            if (mail != null) {
                id.setEmail(mail);
            }
        }
    }
    if (id.getEmail() == null) {
        id.setEmail(""); // safety net
    }

    LDAPAttribute pwdAttr = entry.getAttribute("userpassword");

    if (pwdAttr != null) {
        String pwd = (String) pwdAttr.getStringValues().nextElement();

        if (pwd != null) {
            id.setPassword(pwd);
        }
    }
    LDAPAttribute phoneAttr = entry.getAttribute("telephonenumber");

    if (phoneAttr != null) {
        @SuppressWarnings("unchecked")
        Enumeration<String> en = phoneAttr.getStringValues();

        if (en != null && en.hasMoreElements()) {
            String phone = en.nextElement();

            if (phone != null) {
                id.setPhone(phone);
            }
        }
    }
    if (id.getPhone() == null) {
        id.setPhone(""); // safety net
    }

    LDAPAttribute userTypeAttr = entry.getAttribute("usertype");

    if (userTypeAttr == null)
        id.setUserType("");
    else {
        @SuppressWarnings("unchecked")
        Enumeration<String> en = userTypeAttr.getStringValues();

        if (en != null && en.hasMoreElements()) {
            String userType = en.nextElement();

            if ((userType != null) && (!userType.equals("undefined")))
                id.setUserType(userType);
            else
                id.setUserType("");

        }
    }

    LDAPAttribute userStateAttr = entry.getAttribute("userstate");

    if (userStateAttr == null)
        id.setState("");
    else {
        @SuppressWarnings("unchecked")
        Enumeration<String> en = userStateAttr.getStringValues();

        if (en != null && en.hasMoreElements()) {
            String userState = en.nextElement();

            if (userState != null)
                id.setState(userState);
            else
                id.setState("");

        }
    }

    LDAPAttribute certAttr = entry.getAttribute(LDAP_ATTR_USER_CERT);

    if (certAttr != null) {
        Vector<X509Certificate> certVector = new Vector<X509Certificate>();
        @SuppressWarnings("unchecked")
        Enumeration<byte[]> e = certAttr.getByteValues();

        try {
            for (; e != null && e.hasMoreElements();) {
                X509Certificate cert = new X509CertImpl(e.nextElement());
                certVector.addElement(cert);
            }
        } catch (Exception ex) {
            throw new EUsrGrpException(CMS.getUserMessage("CMS_INTERNAL_ERROR"));
        }

        if (certVector != null && certVector.size() != 0) {
            // Make an array of certs
            X509Certificate[] certArray = new X509Certificate[certVector.size()];
            Enumeration<X509Certificate> en = certVector.elements();
            int i = 0;

            while (en.hasMoreElements()) {
                certArray[i++] = en.nextElement();
            }

            id.setX509Certificates(certArray);
        }
    }

    LDAPAttribute profileAttr = entry.getAttribute(LDAP_ATTR_PROFILE_ID);
    if (profileAttr != null) {
        @SuppressWarnings("unchecked")
        Enumeration<String> profiles = profileAttr.getStringValues();
        id.setTpsProfiles(Collections.list(profiles));
    }

    return id;
}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Updates the <code>identificationCount</code> attribute of the
 * <code>AntennaReadPoint</code> objects according to the given
 * observations./* www .j  ava  2  s.  c  om*/
 *
 * @param observations
 *            The observations
 */
private void updateAntennaReadPointIdentificationCount(Vector<Observation> observations) {
    Enumeration observationIter = observations.elements();
    while (observationIter.hasMoreElements()) {
        Observation curObservation = (Observation) observationIter.nextElement();
        ReadPoint curReadPoint = (ReadPoint) readPoints.get(curObservation.getReadPointName());
        String[] ids = curObservation.getIds();
        if (curReadPoint instanceof AntennaReadPoint) {
            AntennaReadPoint curAntReadPoint = (AntennaReadPoint) curReadPoint;
            for (int tagIndex = 0; tagIndex < ids.length; tagIndex++) {
                curAntReadPoint.increaseIdentificationCount();
            }
        }
    }
}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Returns <code>true</code> iff this source supports write operations,
 * <code>false</code> otherwise.
 *
 * @return <code>true</code> iff this source supports write operations,
 *         <code>false</code> otherwise
 * @throws ReaderProtocolException/*from  ww  w . j  a va2s. c  om*/
 */
public boolean supportsWriteOperations() throws ReaderProtocolException {
    Vector closure = getReaderAndReadPoints();
    Enumeration readerIterator = closure.elements();
    HardwareAbstraction curHardwareAbstraction;
    while (readerIterator.hasMoreElements()) {
        curHardwareAbstraction = ((ReaderAndReadPoints) readerIterator.nextElement()).getReader();
        if (curHardwareAbstraction.supportsWriteBytes() || curHardwareAbstraction.supportsWriteId()) {
            return true;
        }
    }
    return false;
}

From source file:GUI.MainWindow.java

private void handleCVELookup(File save_file) {

    final File sf = save_file;
    // Best to do this as a background task it'll take time
    Runnable r = new Runnable() {
        public void run() {
            HashSet cves = new HashSet();
            // Find all selected vulns in the tree.
            TreePath[] paths = VulnTree.getSelectionPaths();
            for (int i = 0; i < paths.length; i++) {
                // Loop through them and merge all CVEs into the cves HashSet
                TreePath path = paths[i];
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object obj = node.getUserObject();
                if (obj instanceof Vulnerability) {
                    Vulnerability vuln = (Vulnerability) obj;
                    // add these references to the HashSet
                    cves.addAll(vuln.getCVEReferences());
                }/*from   ww  w  .j ava2 s .  c o  m*/
            }

            // Get the answers from our local CSV file
            CVEUtils cveu = new CVEUtils();
            Vector answers = cveu.getCVEs(cves);

            try {
                String[] headerrow = { "CVE ID", "Risk Score", "Summary" };
                // Write header column to file
                writeCSVLine(sf, headerrow);
                // Now get all the details and make a CSV for the user.
                Enumeration enums = answers.elements();
                while (enums.hasMoreElements()) {
                    CVE c = (CVE) enums.nextElement();
                    System.out.println(c.getCveId() + ":" + c.getRiskScore());
                    writeCSVLine(sf, c.toStringArray());
                }

                // Open file in user's default programme
                Desktop.getDesktop().open(sf);

            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
            }
        }
    };

    new Thread(r).start();
}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Removes the specified ReadPoints from the list of ReadPoints currently
 * associated with this source.//from   w w w .j av a 2 s .  co  m
 * @param readPointList
 *           The list of readpoints
 */
public void removeReadPoints(final ReadPoint[] readPointList) {

    Vector readPoints = readerDevice.getVector(readPointList);

    Enumeration iterator = readPoints.elements();
    ReadPoint cur;

    while (iterator.hasMoreElements()) {
        cur = (ReadPoint) iterator.nextElement();
        this.readPoints.remove(cur.getName());
    }
}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Adds the specified ReadPoints to the list of readpoints currently
 * associated with this source. If some of the ReadPoints to be added are
 * already associated with this source, only the not yet associated
 * ReadPoints will be added.// ww w .j a v  a2 s .  co  m
 * @param readPointList
 *           The list of readpoints
 */
public void addReadPoints(final ReadPoint[] readPointList) {

    Vector readPoints = readerDevice.getVector(readPointList);

    Enumeration iterator = readPoints.elements();
    ReadPoint cur;

    while (iterator.hasMoreElements()) {
        cur = (ReadPoint) iterator.nextElement();
        if (!this.readPoints.containsKey(cur.getName())) {
            this.readPoints.put(cur.getName(), cur);
        }
    }

}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Remove a list of tag selectors.//from ww w  .  j  a v  a  2 s.c  o m
 * @param tagSelectorList
 *           The list of tag selectors
 */
public void removeTagSelectors(final TagSelector[] tagSelectorList) {

    Vector tagSelectors = readerDevice.getVector(tagSelectorList);

    Enumeration iterator = tagSelectors.elements();
    TagSelector cur;

    while (iterator.hasMoreElements()) {
        cur = (TagSelector) iterator.nextElement();
        this.tagSelectors.remove(cur.getName());
    }
}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Remove a list of read triggers./*from w  ww . j  a  v a  2 s .  c  o  m*/
 * @param triggerList
 *           The list of read triggers
 */
public void removeReadTriggers(final Trigger[] triggerList) {

    Vector triggers = readerDevice.getVector(triggerList);

    Enumeration iterator = triggers.elements();
    Trigger cur;

    while (iterator.hasMoreElements()) {
        cur = (Trigger) iterator.nextElement();

        if (readTriggers.containsKey(cur.getName())) {
            if (cur.getType().equals(TriggerType.CONTINUOUS)) {
                // continuous trigger
                continuousThread.stop();
                continuousThread = null;
            } else if (cur.getType().equals(TriggerType.TIMER)) {
                // timer trigger
                if (timerThreads.containsKey(cur.getName())) {
                    Timer t = (Timer) timerThreads.get(cur.getName());
                    t.cancel();
                    timerThreads.remove(cur.getName());
                }
            } else if (cur.getType().equals(TriggerType.IO_EDGE)) {
                // io edge trigger
                // get port
                final int num = 6;
                String port = cur.getValue().substring(cur.getValue().indexOf(';') + num,
                        cur.getValue().lastIndexOf(';'));
                if (readerDevice.getEdgeTriggers().containsKey(port)) {
                    IOEdgeTriggerPortManager manager = (IOEdgeTriggerPortManager) readerDevice.getEdgeTriggers()
                            .get(port);
                    manager.removeListener(cur, this.getName());
                    if (manager.getNumberOfTriggers() <= 0) {
                        manager.stop();
                    }
                }
            } else if (cur.getType().equals(TriggerType.IO_VALUE)) {
                // io value trigger
                // get port
                final int num = 5;
                String port = cur.getValue().substring(num, cur.getValue().indexOf(';'));
                if (readerDevice.getValueTriggers().containsKey(port)) {
                    IOValueTriggerPortManager manager = (IOValueTriggerPortManager) readerDevice
                            .getValueTriggers().get(port);
                    manager.removeListener(cur, this.getName());
                    if (manager.getNumberOfTriggers() <= 0) {
                        manager.stop();
                    }
                }
            }

            this.readTriggers.remove(cur.getName());
        }
    }

}