Example usage for java.util Vector addElement

List of usage examples for java.util Vector addElement

Introduction

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

Prototype

public synchronized void addElement(E obj) 

Source Link

Document

Adds the specified component to the end of this vector, increasing its size by one.

Usage

From source file:edu.umd.cfar.lamp.viper.util.StringHelp.java

/**
 * Split using a separator, but allow for the separator to occur
 * in nested parentheses without splitting.  
 *   E.g.   //from   w  ww  .  j a v  a 2s. co m
 * <pre>
 *     1, (2,3), 4
 * </pre>
 *  would split into 
 * <UL>
 *   <li> 1 </li>
 *   <li> (2,3)  (Doesn't get split, even though it has comma) </li>
 *   <li> 4 </li>
 * </ul>
 *
 * @param line The String to be seperated.
 * @param sep The seperator character, eg a comma
 * @return An array of Strings containing the seperated data.
 * @see #splitBySeparator(String line, char c)
 */
public static String[] splitBySeparatorAndParen(String line, char sep) {
    boolean withinQuotes = false;
    String newLine = new String(line);
    Vector temp = new Vector();

    int startIndex = 0;
    int nesting = 0;
    for (int i = 0; i < newLine.length(); i++) {
        char c = newLine.charAt(i);
        if (c == '"') {
            withinQuotes = !withinQuotes;
        } else if (!withinQuotes) {
            if (c == '(') {
                nesting++;
            } else if (c == ')') {
                nesting--;
            } else {
                if ((nesting == 0) && (c == sep)) {
                    String s = newLine.substring(startIndex, i);
                    temp.addElement(s);

                    startIndex = i + 1;
                }
            }
        }
    }
    String s = newLine.substring(startIndex);
    temp.addElement(s);

    String[] result = new String[temp.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = (String) temp.elementAt(i);
    }
    return (result);
}

From source file:ShowComponent.java

/**
 * This method loops through the command line arguments looking for class
 * names of components to create and property settings for those components
 * in the form name=value. This method demonstrates reflection and JavaBeans
 * introspection as they can be applied to dynamically created GUIs
 *//* w  w  w  . j  av a  2 s .c om*/
public static Vector getComponentsFromArgs(String[] args) {
    Vector components = new Vector(); // List of components to return
    Component component = null; // The current component
    PropertyDescriptor[] properties = null; // Properties of the component
    Object[] methodArgs = new Object[1]; // We'll use this below

    nextarg: // This is a labeled loop
    for (int i = 0; i < args.length; i++) { // Loop through all arguments
        // If the argument does not contain an equal sign, then it is
        // a component class name. Otherwise it is a property setting
        int equalsPos = args[i].indexOf('=');
        if (equalsPos == -1) { // Its the name of a component
            try {
                // Load the named component class
                Class componentClass = Class.forName(args[i]);
                // Instantiate it to create the component instance
                component = (Component) componentClass.newInstance();
                // Use JavaBeans to introspect the component
                // And get the list of properties it supports
                BeanInfo componentBeanInfo = Introspector.getBeanInfo(componentClass);
                properties = componentBeanInfo.getPropertyDescriptors();
            } catch (Exception e) {
                // If any step failed, print an error and exit
                System.out.println("Can't load, instantiate, " + "or introspect: " + args[i]);
                System.exit(1);
            }

            // If we succeeded, store the component in the vector
            components.addElement(component);
        } else { // The arg is a name=value property specification
            String name = args[i].substring(0, equalsPos); // property name
            String value = args[i].substring(equalsPos + 1); // property
            // value

            // If we don't have a component to set this property on, skip!
            if (component == null)
                continue nextarg;

            // Now look through the properties descriptors for this
            // component to find one with the same name.
            for (int p = 0; p < properties.length; p++) {
                if (properties[p].getName().equals(name)) {
                    // Okay, we found a property of the right name.
                    // Now get its type, and the setter method
                    Class type = properties[p].getPropertyType();
                    Method setter = properties[p].getWriteMethod();

                    // Check if property is read-only!
                    if (setter == null) {
                        System.err.println("Property " + name + " is read-only");
                        continue nextarg; // continue with next argument
                    }

                    // Try to convert the property value to the right type
                    // We support a small set of common property types here
                    // Store the converted value in an Object[] so it can
                    // be easily passed when we invoke the property setter
                    try {
                        if (type == String.class) { // no conversion needed
                            methodArgs[0] = value;
                        } else if (type == int.class) { // String to int
                            methodArgs[0] = Integer.valueOf(value);
                        } else if (type == boolean.class) { // to boolean
                            methodArgs[0] = Boolean.valueOf(value);
                        } else if (type == Color.class) { // to Color
                            methodArgs[0] = Color.decode(value);
                        } else if (type == Font.class) { // String to Font
                            methodArgs[0] = Font.decode(value);
                        } else {
                            // If we can't convert, ignore the property
                            System.err
                                    .println("Property " + name + " is of unsupported type " + type.getName());
                            continue nextarg;
                        }
                    } catch (Exception e) {
                        // If conversion failed, continue with the next arg
                        System.err.println("Can't convert  '" + value + "' to type " + type.getName()
                                + " for property " + name);
                        continue nextarg;
                    }

                    // Finally, use reflection to invoke the property
                    // setter method of the component we created, and pass
                    // in the converted property value.
                    try {
                        setter.invoke(component, methodArgs);
                    } catch (Exception e) {
                        System.err.println("Can't set property: " + name);
                    }

                    // Now go on to next command-line arg
                    continue nextarg;
                }
            }

            // If we get here, we didn't find the named property
            System.err.println("Warning: No such property: " + name);
        }
    }

    return components;
}

From source file:alter.vitro.vgw.service.VitroGatewayService.java

public Vector<InfoOnTrustRouting> sendTrustRoutingCoapInquiryToAllNodes() {
    Vector<InfoOnTrustRouting> retVec = new Vector<InfoOnTrustRouting>();
    if (isTrustRoutingCoapMessagingActive()) {
        logger.debug("GETTING ALL NODES FOR WHICH TO SENT TRUST ROUTING COAP MSG");
        List<CSmartDevice> alterNodeDescriptorsList = new ArrayList<CSmartDevice>();
        // TODO: connect this cachedlist with the one in ResourceAvailabilityService. Keep the disabled nodes do not overwrite them!!!
        if (ResourceAvailabilityService.getInstance().getCachedDiscoveredDevices() != null) {
            for (String smIdTmp : ResourceAvailabilityService.getInstance().getCachedDiscoveredDevices()
                    .keySet()) {/* w w  w  . j a  va2 s . c  o  m*/
                alterNodeDescriptorsList.add(
                        ResourceAvailabilityService.getInstance().getCachedDiscoveredDevices().get(smIdTmp));
            }
        } else {
            //init a new discovery
            CGateway myGateway = new CGateway();
            myGateway.setId(getAssignedGatewayUniqueIdFromReg());
            myGateway.setName("");
            myGateway.setDescription("");
            CGatewayWithSmartDevices gwWithNodeDescriptorList = myDCon.createWSIDescr(myGateway);
            logger.debug("nodeDescriptorList = {}", gwWithNodeDescriptorList.getSmartDevVec());
            alterNodeDescriptorsList = gwWithNodeDescriptorList.getSmartDevVec();
            ResourceAvailabilityService.getInstance().updateCachedNodeList(alterNodeDescriptorsList,
                    ResourceAvailabilityService.SUBSEQUENT_DISCOVERY);
        }

        Vector<String> allNodeIds = new Vector<String>();
        if (alterNodeDescriptorsList != null) {
            for (CSmartDevice cDev : alterNodeDescriptorsList) {
                logger.debug("Adding node to query for TRUST: " + cDev.getId());
                allNodeIds.addElement(cDev.getId());
            }
        }
        retVec = myDCon.findRealTimeTrustInfoOnNodes(allNodeIds,
                TrustRoutingQueryService.getPeriodBetweenCoapMsgToAnotherNode());
        logger.debug("Status of activeMQ pipes: " + (registerSOSpipe == null ? "SOS closed " : "SOS open")
                + ", Command queue: " + ((commandPipe.getProducer() == null || commandPipe.getSession() == null
                        || commandPipe.getConsumer() == null) ? " closed" : "open"));
    } else {
        logger.error("Requested to send a Routing Coap Inquiry but Service is inactive!");
    }
    return retVec;
}

From source file:edu.indiana.lib.osid.base.repository.http.Asset.java

public org.osid.repository.PartIterator getPartByPart(org.osid.shared.Id partStructureId)
        throws org.osid.repository.RepositoryException {
    if (partStructureId == null) {
        throw new org.osid.repository.RepositoryException(org.osid.shared.SharedException.NULL_ARGUMENT);
    }/*from  w  w  w  .j a  va2 s  . c  om*/
    try {
        java.util.Vector results = new java.util.Vector();
        for (int i = 0, size = this.recordVector.size(); i < size; i++) {
            org.osid.repository.Record record = (org.osid.repository.Record) this.recordVector.elementAt(i);
            org.osid.repository.PartIterator partIterator = record.getParts();
            while (partIterator.hasNextPart()) {
                org.osid.repository.Part part = partIterator.nextPart();
                if (part.getPartStructure().getId().isEqual(partStructureId)) {
                    results.addElement(part);
                }
            }
        }
        return new PartIterator(results);
    } catch (Throwable t) {
        _log.error(t.getMessage());
        throw new org.osid.repository.RepositoryException(org.osid.OsidException.OPERATION_FAILED);
    }
}

From source file:IteratorTest.java

protected void refreshDisplay() {
    int startIndex, nextIndex;
    Vector items = new Vector();
    String msgText = textArea.getText();
    Locale locale = (Locale) (localeButton.getSelectedItem());
    BreakIterator iterator = null;
    if (charButton.isSelected()) {
        iterator = BreakIterator.getCharacterInstance(locale);
    } else if (wordButton.isSelected()) {
        iterator = BreakIterator.getWordInstance(locale);
    } else if (lineButton.isSelected()) {
        iterator = BreakIterator.getLineInstance(locale);
    } else if (sentButton.isSelected()) {
        iterator = BreakIterator.getSentenceInstance(locale);
    }// w ww  . j  a v a  2s  .  c o  m
    iterator.setText(msgText);
    startIndex = iterator.first();
    nextIndex = iterator.next();

    while (nextIndex != BreakIterator.DONE) {
        items.addElement(msgText.substring(startIndex, nextIndex));
        startIndex = nextIndex;
        nextIndex = iterator.next();
    }
    itemList.setListData(items);
}

From source file:mypackage.State_Home.java

private Vector doCategorize(JSONArray subscriptions) throws JSONException {
    Vector out = new Vector();

    // GlobalJeS?[?B
    out.addElement(new Global("Global"));

    // ?wtB?[h????AGlobal^?[
    if (subscriptions == null) {
        return out;
    }/*from  w w  w . j  av  a  2  s  .co  m*/

    // ?wtB?[h???AGlobal^?[
    if (subscriptions.length() == 0) {
        return out;
    }

    // UncategorizedJeS?[??
    String streamid_uncategorized = "user/" + _feedlyclient.getID() + "/category/global.uncategorized";
    Category _uncategorized = new Category("Uncategorized", streamid_uncategorized, true);

    // ?wtB?[hJeS?U
    for (int i = 0; i < subscriptions.length(); i++) {
        // tB?[h?
        JSONObject feed_jsonObject = subscriptions.getJSONObject(i);
        Feed _feed = new Feed(feed_jsonObject);

        // tB?[hJeS?
        JSONArray categorys = feed_jsonObject.getJSONArray("categories");

        // JeSw???AUncategorizedJeS?[o^?B
        if (categorys.length() == 0) {
            _uncategorized.addFeed(_feed);
            continue;
        }

        // tB?[hJeSw?
        label: for (int j = 0; j < categorys.length(); j++) {
            // tB?[hJeS?
            JSONObject category = categorys.getJSONObject(j);
            String category_name = category.getString("label");
            String stream_id = category.getString("id");

            // JeS?
            for (Enumeration e = out.elements(); e.hasMoreElements();) {
                // JeS?
                Category _ctgry = (Category) e.nextElement();

                // ?vJeS???A?B
                if (_ctgry.getCategoryName().equals(category_name)) {
                    _ctgry.addFeed(_feed);
                    break label;
                }
            }

            // ?vJeS???AJeS?VK???B
            Category _new_category = new Category(category_name, stream_id, true);
            _new_category.addFeed(_feed);
            out.addElement(_new_category);
        }
    } //for

    // ?UncategorizedJeS?[?i1?tB?[h???j
    if (_uncategorized.getNumOfFeeds() != 0) {
        out.addElement(_uncategorized);
    }

    return out;
}

From source file:edu.indiana.lib.osid.base.repository.http.Asset.java

public org.osid.repository.PartIterator getPartsByPartStructure(org.osid.shared.Id partStructureId)
        throws org.osid.repository.RepositoryException {
    if (partStructureId == null) {
        throw new org.osid.repository.RepositoryException(org.osid.shared.SharedException.NULL_ARGUMENT);
    }// w ww.j a va  2  s . c  o m
    try {
        java.util.Vector results = new java.util.Vector();
        org.osid.repository.RecordIterator recordIterator = getRecords();
        while (recordIterator.hasNextRecord()) {
            org.osid.repository.Record record = recordIterator.nextRecord();
            org.osid.repository.PartIterator partIterator = record.getParts();
            while (partIterator.hasNextPart()) {
                org.osid.repository.Part part = partIterator.nextPart();
                if (part.getPartStructure().getId().isEqual(partStructureId)) {
                    results.addElement(part);
                }
            }
        }
        return new PartIterator(results);
    } catch (Throwable t) {
        _log.error(t.getMessage());
        throw new org.osid.repository.RepositoryException(org.osid.OsidException.OPERATION_FAILED);
    }
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.fileprofile.FileProfileMainHandler.java

/**
 * Get the request params and set them in the FileProfile.
 *//*from w ww  .  j a  va 2 s  .c o m*/
private void setRequestParams(HttpServletRequest p_request, FileProfile p_fp) {
    p_fp.setName(p_request.getParameter("fpName"));
    String filterInfo = p_request.getParameter("filterInfo");
    if (filterInfo != null) {
        String[] filterInfoArray = filterInfo.split(",");
        long filterId = Long.parseLong(filterInfoArray[0]);
        p_fp.setFilterId(filterId);
        if (filterInfoArray.length == 2) {
            String filterTableName = filterInfoArray[1];
            p_fp.setFilterTableName(filterTableName);
        } else
            p_fp.setFilterTableName(null);
    }
    String qaFilterInfo = p_request.getParameter("qaFilterInfo");
    if (qaFilterInfo != null) {
        long qaFilterId = Long.parseLong(qaFilterInfo);
        p_fp.setQaFilter(QAFilterManager.getQAFilterById(qaFilterId));
    }

    // for bug GBS-2590, by fan
    char[] xmlEncodeChar = { '<', '>', '&', '"' };
    String desc = XmlFilterHelper.encodeSpecifiedEntities(p_request.getParameter("desc"), xmlEncodeChar);
    p_fp.setDescription(desc);

    p_fp.setCompanyId(Long.parseLong(CompanyThreadLocal.getInstance().getValue()));
    // p_fp.setSupportSid(p_request.getParameter("supportSid") != null);
    // p_fp.setUnicodeEscape(p_request.getParameter("unicodeEscape") !=
    // null);
    // p_fp.setHeaderTranslate(p_request.getParameter("headerTranslate") !=
    // null);
    p_fp.setL10nProfileId(Long.parseLong(p_request.getParameter("locProfileId")));
    p_fp.setScriptOnImport(p_request.getParameter("scriptOnImport"));
    p_fp.setScriptOnExport(p_request.getParameter("scriptOnExport"));
    String formatInfo = p_request.getParameter("formatInfo");
    int idx = formatInfo.indexOf(",");
    formatInfo = formatInfo.substring(0, idx);
    p_fp.setKnownFormatTypeId(Long.parseLong(formatInfo));
    p_fp.setCodeSet(p_request.getParameter("codeSet"));

    // String rule = p_request.getParameter("rule");
    // if (rule != null && !rule.startsWith("-1"))
    // {
    // p_fp.setXmlRuleFileId(Long.parseLong(rule));
    // }
    // else
    // {
    // p_fp.setXmlRuleFileId(0);
    // }

    KnownFormatTypeImpl knownFormat = HibernateUtil.get(KnownFormatTypeImpl.class, Long.parseLong(formatInfo));
    if (knownFormat != null && !KnownFormatType.XML.equals(knownFormat.getName())) {
        p_fp.setXmlDtd(null);
    } else {
        String dtdIds = p_request.getParameter("dtdIds");
        if (dtdIds != null && !"-1".equals(dtdIds)) {
            p_fp.setXmlDtd(HibernateUtil.get(XmlDtdImpl.class, Long.parseLong(dtdIds)));
        } else {
            p_fp.setXmlDtd(null);
        }
    }

    if ("0".equals(p_request.getParameter("extGroup"))) {
        Vector extensionIds = new Vector();
        String ids = p_request.getParameter("extensions");
        StringTokenizer tok = new StringTokenizer(ids, ",");
        while (tok.hasMoreTokens()) {
            extensionIds.addElement(new Long(tok.nextToken()));
        }
        p_fp.setFileExtensionIds(extensionIds);
    } else {
        p_fp.setFileExtensionIds(null);
    }

    // default export (primary vs. secondary target files)
    if ("1".equals(p_request.getParameter("exportFiles"))) {
        p_fp.byDefaultExportStf(false);
    } else {
        p_fp.byDefaultExportStf(true);
    }

    // String jsFilter = p_request.getParameter("jsFilter");
    // if (jsFilter == null || jsFilter.trim().length() == 0)
    // {
    // jsFilter = null;
    // }
    // p_fp.setJsFilterRegex(jsFilter);

    String terminologyApproval = p_request.getParameter("terminologyRadio");
    if (terminologyApproval != null) {
        p_fp.setTerminologyApproval(Integer.parseInt(terminologyApproval));
    }

    String BOMType = p_request.getParameter("bomType");
    p_fp.setBOMType(Integer.parseInt(BOMType));

    String xlfSourceAsUnTranslatedTarget = p_request.getParameter("xlfSrcAsTargetRadio");
    if (xlfSourceAsUnTranslatedTarget != null) {
        p_fp.setXlfSourceAsUnTranslatedTarget(Integer.parseInt(xlfSourceAsUnTranslatedTarget));
    }

    /**
     * String referenceFPId = p_request.getParameter("xlfFp"); if
     * (referenceFPId == null || referenceFPId == "-1")
     * p_fp.setReferenceFP(0); else
     * p_fp.setReferenceFP(Long.parseLong(referenceFPId));
     */
}

From source file:com.sun.grizzly.http.jk.server.JkMain.java

private void preProcessProperties() {
    Enumeration keys = props.keys();
    Vector v = new Vector();

    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        Object newName = replacements.get(key);
        if (newName != null) {
            v.addElement(key);
        }/*from   w  w w. ja va2 s.  c  o  m*/
    }
    keys = v.elements();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        Object propValue = props.getProperty(key);
        String replacement = (String) replacements.get(key);
        props.put(replacement, propValue);
        if (LoggerUtils.getLogger().isLoggable(Level.FINEST)) {
            LoggerUtils.getLogger().log(Level.FINEST,
                    "Substituting " + key + " " + replacement + " " + propValue);
        }
    }
}

From source file:org.apache.axis.handlers.soap.MustUnderstandChecker.java

public void invoke(MessageContext msgContext) throws AxisFault {
    // Do SOAP semantics here
    if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("semanticCheck00"));
    }//from   w w  w  . j  a  va 2 s .  c o m

    Message msg = msgContext.getCurrentMessage();
    if (msg == null)
        return; // nothing to do if there's no message

    SOAPEnvelope env = msg.getSOAPEnvelope();
    Vector headers = null;
    if (service != null) {
        ArrayList acts = service.getActors();
        headers = env.getHeadersByActor(acts);
    } else {
        headers = env.getHeaders();
    }

    // 1. Check mustUnderstands
    Vector misunderstoodHeaders = null;
    Enumeration enumeration = headers.elements();
    while (enumeration.hasMoreElements()) {
        SOAPHeaderElement header = (SOAPHeaderElement) enumeration.nextElement();

        // Ignore header, if it is a parameter to the operation 
        if (msgContext != null && msgContext.getOperation() != null) {
            OperationDesc oper = msgContext.getOperation();
            if (oper.getParamByQName(header.getQName()) != null) {
                continue;
            }
        }
        if (header.getMustUnderstand() && !header.isProcessed()) {
            if (misunderstoodHeaders == null)
                misunderstoodHeaders = new Vector();
            misunderstoodHeaders.addElement(header);
        }
    }
    SOAPConstants soapConstants = msgContext.getSOAPConstants();
    // !!! we should indicate SOAP1.2 compliance via the
    // MessageContext, not a boolean here....

    if (misunderstoodHeaders != null) {
        AxisFault fault = new AxisFault(soapConstants.getMustunderstandFaultQName(), null, null, null, null,
                null);
        StringBuffer whatWasMissUnderstood = new StringBuffer(256);

        enumeration = misunderstoodHeaders.elements();
        while (enumeration.hasMoreElements()) {
            SOAPHeaderElement badHeader = (SOAPHeaderElement) enumeration.nextElement();
            QName badQName = new QName(badHeader.getNamespaceURI(), badHeader.getName());
            if (whatWasMissUnderstood.length() != 0)
                whatWasMissUnderstood.append(", ");
            whatWasMissUnderstood.append(badQName.toString());
            // !!! If SOAP 1.2, insert misunderstood fault headers here
            if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                SOAPHeaderElement newHeader = new SOAPHeaderElement(Constants.URI_SOAP12_ENV,
                        Constants.ELEM_NOTUNDERSTOOD);
                newHeader.addAttribute(null, Constants.ATTR_QNAME, badQName);
                fault.addHeader(newHeader);
            }
        }
        fault.setFaultString(Messages.getMessage("noUnderstand00", whatWasMissUnderstood.toString()));
        throw fault;
    }
}