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:org.apache.tomcat.util.net.puretls.PureTLSSocketFactory.java

private short[] getEnabledCiphers(short[] supportedCiphers) {

    short[] enabledCiphers = null;

    String attrValue = (String) attributes.get("ciphers");
    if (attrValue != null) {
        Vector vec = null;
        int fromIndex = 0;
        int index = attrValue.indexOf(',', fromIndex);
        while (index != -1) {
            String cipher = attrValue.substring(fromIndex, index).trim();
            int cipherValue = SSLPolicyInt.getCipherSuiteNumber(cipher);
            /*//  w  w  w. ja  va  2 s. c o m
             * Check to see if the requested cipher is among the supported
             * ciphers, i.e., may be enabled
             */
            if (cipherValue >= 0) {
                for (int i = 0; supportedCiphers != null && i < supportedCiphers.length; i++) {

                    if (cipherValue == supportedCiphers[i]) {
                        if (vec == null) {
                            vec = new Vector();
                        }
                        vec.addElement(new Integer(cipherValue));
                        break;
                    }
                }
            }
            fromIndex = index + 1;
            index = attrValue.indexOf(',', fromIndex);
        }

        if (vec != null) {
            int nCipher = vec.size();
            enabledCiphers = new short[nCipher];
            for (int i = 0; i < nCipher; i++) {
                Integer value = (Integer) vec.elementAt(i);
                enabledCiphers[i] = value.shortValue();
            }
        }
    }

    return enabledCiphers;

}

From source file:de.juwimm.cms.authorization.remote.AuthorizationServiceSpringImpl.java

/**
 * @see de.juwimm.cms.authorization.remote.AuthorizationServiceSpring#getUnits()
 *///w w  w. ja  va  2  s .c o  m
@Override
protected UnitValue[] handleGetUnits() throws Exception {
    Vector<UnitValue> vec = new Vector<UnitValue>();
    try {
        if (log.isDebugEnabled())
            log.debug("begin getUnits");
        UserHbm user = super.getUserHbmDao().load(AuthenticationHelper.getUserName());
        Iterator iterator = null;
        if (getUserHbmDao().isInRole(user, UserRights.SITE_ROOT, user.getActiveSite())) {
            iterator = super.getUnitHbmDao().findAll(user.getActiveSite().getSiteId()).iterator();
        } else {
            iterator = super.getUserHbmDao().getUnits4ActiveSite(user).iterator();
        }
        UnitHbm unit;
        while (iterator.hasNext()) {
            unit = (UnitHbm) iterator.next();
            UnitValue dao = getUnitHbmDao().getDao(unit);
            vec.addElement(dao);
        }
        if (log.isDebugEnabled())
            log.debug("end getUnits");
    } catch (Exception e) {
        throw new UserException(e.getMessage());
    }
    return vec.toArray(new UnitValue[0]);
}

From source file:Maze.java

/**
 * This method randomly generates the maze.
 *//*from w w w .j a v a2  s  .co m*/
private void createMaze() {
    // create an initial framework of black squares.
    for (int i = 1; i < mySquares.length - 1; i++) {
        for (int j = 1; j < mySquares[i].length - 1; j++) {
            if ((i + j) % 2 == 1) {
                mySquares[i][j] = 0;
            }
        }
    }
    // initialize the squares that can be either black or white 
    // depending on the maze.
    // first we set the value to 3 which means undecided.
    for (int i = 1; i < mySquares.length - 1; i += 2) {
        for (int j = 1; j < mySquares[i].length - 1; j += 2) {
            mySquares[i][j] = 3;
        }
    }
    // Then those squares that can be selected to be open 
    // (white) paths are given the value of 2.  
    // We randomly select the square where the tree of maze 
    // paths will begin.  The maze is generated starting from 
    // this initial square and branches out from here in all 
    // directions to fill the maze grid.  
    Vector possibleSquares = new Vector(mySquares.length * mySquares[0].length);
    int[] startSquare = new int[2];
    startSquare[0] = getRandomInt(mySquares.length / 2) * 2 + 1;
    startSquare[1] = getRandomInt(mySquares[0].length / 2) * 2 + 1;
    mySquares[startSquare[0]][startSquare[1]] = 2;
    possibleSquares.addElement(startSquare);
    // Here we loop to select squares one by one to append to 
    // the maze pathway tree.
    while (possibleSquares.size() > 0) {
        // the next square to be joined on is selected randomly.
        int chosenIndex = getRandomInt(possibleSquares.size());
        int[] chosenSquare = (int[]) possibleSquares.elementAt(chosenIndex);
        // we set the chosen square to white and then 
        // remove it from the list of possibleSquares (i.e. squares 
        // that can possibly be added to the maze), and we link 
        // the new square to the maze.
        mySquares[chosenSquare[0]][chosenSquare[1]] = 1;
        possibleSquares.removeElementAt(chosenIndex);
        link(chosenSquare, possibleSquares);
    }
    // now that the maze has been completely generated, we 
    // throw away the objects that were created during the 
    // maze creation algorithm and reclaim the memory.
    possibleSquares = null;
    System.gc();
}

From source file:com.verisign.epp.codec.gen.EPPUtil.java

/**
 * Decode a <code>Vector</code> of <code>String</code>'s by XML namespace
 * and tag name, from an XML Element. The children elements of
 * <code>aElement</code> will be searched for the specified <code>aNS</code>
 * namespace URI and the specified <code>aTagName</code>. Each XML element
 * found will be decoded and added to the returned <code>Vector</code>.
 * Empty child elements, will result in empty string ("") return
 * <code>Vector</code> elements.
 * /*  ww  w. j av  a  2 s.co m*/
 * @param aElement
 *            XML Element to scan. For example, the element could be
 *            &ltdomain:update&gt
 * @param aNS
 *            XML namespace of the elements. For example, for domain element
 *            this is "urn:iana:xmlns:domain".
 * @param aTagName
 *            Tag name of the element including an optional namespace
 *            prefix. For example, the tag name for the domain name servers
 *            is "domain:server".
 * @return <code>Vector</code> of <code>String</code> elements representing
 *         the text nodes of the found XML elements.
 * @exception EPPDecodeException
 *                Error decoding <code>aElement</code>.
 */
public static <X> Vector<X> decodeVector(Element aElement, String aNS, String aTagName)
        throws EPPDecodeException {
    Vector retVal = new Vector();

    Vector theChildren = EPPUtil.getElementsByTagNameNS(aElement, aNS, aTagName);

    for (int i = 0; i < theChildren.size(); i++) {
        Element currChild = (Element) theChildren.elementAt(i);

        Text currVal = (Text) currChild.getFirstChild();

        // Element has text?
        if (currVal != null) {
            retVal.addElement(currVal.getNodeValue());
        } else { // No text in element.
            retVal.addElement("");
        }
    }

    return retVal;
}

From source file:alice.tuprolog.lib.OOLibrary.java

private static Constructor<?> lookupConstructor(Class<?> target, Class<?>[] argClasses, Object[] argValues)
        throws NoSuchMethodException {
    // first try for exact match
    try {/*from  w  ww .j  a  v a  2  s  .c om*/
        return target.getConstructor(argClasses);
    } catch (NoSuchMethodException e) {
        if (argClasses.length == 0) { // if no args & no exact match, out of
            // luck
            return null;
        }
    }

    // go the more complicated route
    Constructor<?>[] constructors = target.getConstructors();
    Vector<Constructor<?>> goodConstructors = new Vector<>();
    for (int i = 0; i != constructors.length; i++) {
        if (matchClasses(constructors[i].getParameterTypes(), argClasses))
            goodConstructors.addElement(constructors[i]);
    }
    switch (goodConstructors.size()) {
    case 0:
        // no constructors have been found checking for assignability
        // and (int -> long) conversion. One last chance:
        // looking for compatible methods considering also
        // type conversions:
        // double --> float
        // (the first found is used - no most specific
        // method algorithm is applied )

        for (int i = 0; i != constructors.length; i++) {
            Class<?>[] types = constructors[i].getParameterTypes();
            Object[] val = matchClasses(types, argClasses, argValues);
            if (val != null) {
                // found a method compatible
                // after type conversions
                for (int j = 0; j < types.length; j++) {
                    argClasses[j] = types[j];
                    argValues[j] = val[j];
                }
                return constructors[i];
            }
        }

        return null;
    case 1:
        return goodConstructors.firstElement();
    default:
        return mostSpecificConstructor(goodConstructors);
    }
}

From source file:fsi_admin.JAwsS3Conn.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String ERROR = null, codErr = null;

    try {//from w  ww .  j av a  2  s  .c  o  m
        Properties parametros = new Properties();
        Vector archivos = new Vector();
        DiskFileUpload fu = new DiskFileUpload();
        List items = fu.parseRequest(request);
        Iterator iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (item.isFormField())
                parametros.put(item.getFieldName(), item.getString());
            else
                archivos.addElement(item);
        }

        if (parametros.getProperty("SERVER") == null || parametros.getProperty("DATABASE") == null
                || parametros.getProperty("USER") == null || parametros.getProperty("PASSWORD") == null
                || parametros.getProperty("ACTION") == null) {
            System.out.println("No recibi parametros de conexin antes del archivo");
            ERROR = "ERROR: El servidor no recibi todos los parametros de conexion (SERVER,DATABASE,USER,PASSWORD,ACTION) antes del archivo";
            codErr = "3";
            ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                    parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                    parametros.getProperty("PASSWORD"), request, ERROR, 3);
        }

        //Hasta aqui se han enviado todos los parametros ninguno nulo
        if (ERROR == null) {
            StringBuffer msj = new StringBuffer(), S3BUKT = new StringBuffer(), S3USR = new StringBuffer(),
                    S3PASS = new StringBuffer();
            MutableBoolean COBRAR = new MutableBoolean(false);
            MutableDouble COSTO = new MutableDouble(0.0), SALDO = new MutableDouble(0.0);
            // Primero obtiene info del S3
            if (!obtenInfoAWSS3(request.getRemoteAddr(), request.getRemoteHost(),
                    parametros.getProperty("SERVER"), parametros.getProperty("DATABASE"),
                    parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), S3BUKT, S3USR, S3PASS,
                    msj, COSTO, SALDO, COBRAR)) {
                System.out.println("El usuario y contrasea de servicio estan mal");
                ERROR = msj.toString();
                codErr = "2";
                ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                        parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                        parametros.getProperty("PASSWORD"), request, ERROR, 2);

            } else {
                AWSCredentials credentials = new BasicAWSCredentials(S3USR.toString(), S3PASS.toString());
                AmazonS3 s3 = new AmazonS3Client(credentials);
                Region usWest2 = Region.getRegion(Regions.US_WEST_2);
                s3.setRegion(usWest2);
                //System.out.println("AwsConn:" + parametros.getProperty("NOMBRE") + ":parametros.getProperty(NOMBRE)");
                String nombre = parametros.getProperty("SERVER") + parametros.getProperty("DATABASE")
                        + parametros.getProperty("ID_MODULO") + parametros.getProperty("OBJIDS")
                        + parametros.getProperty("IDSEP") + parametros.getProperty("NOMBRE");
                //System.out.println("AwsConn_Nombre:" + nombre + ":nombre");

                if (parametros.getProperty("ACTION").equals("SUBIR")) {
                    Double TOTBITES = new Double(Double.parseDouble(parametros.getProperty("TOTBITES")));
                    Double TAMBITES = new Double(Double.parseDouble(parametros.getProperty("TAMBITES")));

                    if (COBRAR.booleanValue() && SALDO
                            .doubleValue() < (COSTO.doubleValue() * (((TOTBITES + TAMBITES) / 1024) / 1024))) {
                        System.out
                                .println("El servicio S3 de subida tiene un costo que no alcanza en el saldo");
                        ERROR = "El servicio S3 de subida tiene un costo que no alcanza en el saldo";
                        codErr = "2";
                        ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                parametros.getProperty("PASSWORD"), request, ERROR, 2);
                    } else {
                        if (!subirArchivo(msj, s3, S3BUKT.toString(), nombre, archivos)) {
                            System.out.println("No se permiti subir el archivo al s3");
                            ERROR = msj.toString();
                            codErr = "3";
                            ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                    parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                    parametros.getProperty("PASSWORD"), request, ERROR, 3);
                        } else {
                            ingresarRegistroExitoso(parametros.getProperty("SERVER"),
                                    parametros.getProperty("DATABASE"), parametros.getProperty("ID_MODULO"),
                                    parametros.getProperty("OBJIDS"), parametros.getProperty("IDSEP"),
                                    parametros.getProperty("NOMBRE"), parametros.getProperty("TAMBITES"));
                        }
                    }

                } else if (parametros.getProperty("ACTION").equals("ELIMINAR")) {
                    Double TOTBITES = new Double(Double.parseDouble(parametros.getProperty("TOTBITES")));

                    if (COBRAR.booleanValue()
                            && SALDO.doubleValue() < (COSTO.doubleValue() * ((TOTBITES / 1024) / 1024))) {
                        System.out
                                .println("El servicio S3 de borrado tiene un costo que no alcanza en el saldo");
                        ERROR = "El servicio S3 de borrado tiene un costo que no alcanza en el saldo";
                        codErr = "2";
                        ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                parametros.getProperty("PASSWORD"), request, ERROR, 2);
                    } else {
                        if (!eliminarArchivo(msj, s3, S3BUKT.toString(), nombre)) {
                            System.out.println("No se permiti eliminar el archivo del s3");
                            ERROR = msj.toString();
                            codErr = "3";
                            ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                    parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                    parametros.getProperty("PASSWORD"), request, ERROR, 3);
                        } else {
                            eliminarRegistroExitoso(parametros.getProperty("SERVER"),
                                    parametros.getProperty("DATABASE"), parametros.getProperty("ID_MODULO"),
                                    parametros.getProperty("OBJIDS"), parametros.getProperty("IDSEP"),
                                    parametros.getProperty("NOMBRE"));
                        }
                    }
                } else if (parametros.getProperty("ACTION").equals("DESCARGAR")) {
                    Double TOTBITES = new Double(Double.parseDouble(parametros.getProperty("TOTBITES")));
                    //System.out.println("COBRAR: " + COBRAR.booleanValue() + " SALDO: " + SALDO.doubleValue() + " COSTO: " + COSTO.doubleValue() + " TOTBITES: " + TOTBITES + " TOTMB: " + ((TOTBITES / 1024) / 1024) + " RES: " + (COSTO.doubleValue() * ((TOTBITES / 1024) / 1024)));
                    if (COBRAR.booleanValue()
                            && SALDO.doubleValue() < (COSTO.doubleValue() * ((TOTBITES / 1024) / 1024))) {
                        System.out.println(
                                "El servicio S3 de descarga tiene un costo que no alcanza en el saldo");
                        ERROR = "El servicio S3 de descarga tiene un costo que no alcanza en el saldo";
                        codErr = "2";
                        ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                parametros.getProperty("PASSWORD"), request, ERROR, 2);
                    } else {
                        if (!descargarArchivo(response, msj, s3, S3BUKT.toString(), nombre,
                                parametros.getProperty("NOMBRE"))) {
                            System.out.println("No se permiti descargar el archivo del s3");
                            ERROR = msj.toString();
                            codErr = "3";
                            ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                    parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                    parametros.getProperty("PASSWORD"), request, ERROR, 3);
                        } else
                            return;
                    }
                }

                if (ERROR == null) {
                    //Devuelve la respuesta al cliente
                    Element S3 = new Element("S3");
                    S3.setAttribute("Archivo", nombre);
                    S3.setAttribute("MsjError", "");
                    Document Reporte = new Document(S3);

                    Format format = Format.getPrettyFormat();
                    format.setEncoding("utf-8");
                    format.setTextMode(TextMode.NORMALIZE);
                    XMLOutputter xmlOutputter = new XMLOutputter(format);
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    xmlOutputter.output(Reporte, out);

                    byte[] data = out.toByteArray();
                    ByteArrayInputStream istream = new ByteArrayInputStream(data);

                    String destino = "Archivo.xml";
                    JBajarArchivo fd = new JBajarArchivo();
                    fd.doDownload(response, getServletConfig().getServletContext(), istream, "text/xml",
                            data.length, destino);

                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        ERROR = "ERROR DE EXCEPCION EN SERVIDOR AWS S3: " + e.getMessage();
    }

    //Genera el archivo XML de error para ser devuelto al Servidor
    if (ERROR != null) {
        Element SIGN_ERROR = new Element("SIGN_ERROR");
        SIGN_ERROR.setAttribute("CodError", codErr);
        SIGN_ERROR.setAttribute("MsjError", ERROR);
        Document Reporte = new Document(SIGN_ERROR);

        Format format = Format.getPrettyFormat();
        format.setEncoding("utf-8");
        format.setTextMode(TextMode.NORMALIZE);
        XMLOutputter xmlOutputter = new XMLOutputter(format);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        xmlOutputter.output(Reporte, out);

        byte[] data = out.toByteArray();
        ByteArrayInputStream istream = new ByteArrayInputStream(data);

        String destino = "SIGN_ERROR.xml";
        JBajarArchivo fd = new JBajarArchivo();
        fd.doDownload(response, getServletConfig().getServletContext(), istream, "text/xml", data.length,
                destino);

    }

}

From source file:com.verisign.epp.codec.gen.EPPUtil.java

/**
 * Decode a <code>Vector</code> of <code>EPPCodecComponent</code>'s, by XML
 * namespace and tag name, from an XML Element. The children elements of
 * <code>aElement</code> will be searched for the specified <code>aNS</code>
 * namespace URI and the specified <code>aTagName</code>. Each XML element
 * found will result in the instantiation of <code>aClass</code>, which will
 * decode the associated XML element and added to the returned
 * <code>Vector</code>.//www . j  a  va 2  s  .  c o m
 * 
 * @param aElement
 *            XML Element to scan. For example, the element could be
 *            &ltdomain:add&gt
 * @param aNS
 *            XML namespace of the elements. For example, for domain element
 *            this is "urn:iana:xmlns:domain".
 * @param aTagName
 *            Tag name of the element including an optional namespace
 *            prefix. For example, the tag name for the contact elements of
 *            &gtdomain:add&gt is "domain:contact".
 * @param aClass
 *            Class to instantiate for each found XML element. This must be
 *            a class that implements <code>EPPCodecComponent</code>
 * @return <code>Vector</code> of <code>EPPCodecComponent</code> elements
 *         representing the found XML elements.
 * @exception EPPDecodeException
 *                Error decoding <code>aElement</code>.
 */
public static Vector decodeCompVector(Element aElement, String aNS, String aTagName, Class aClass)
        throws EPPDecodeException {
    Vector retVal = new Vector();

    try {
        Vector theChildren = EPPUtil.getElementsByTagNameNS(aElement, aNS, aTagName);

        // For each element
        for (int i = 0; i < theChildren.size(); i++) {
            EPPCodecComponent currComp = (EPPCodecComponent) aClass.newInstance();

            currComp.decode((Element) theChildren.elementAt(i));

            retVal.addElement(currComp);
        }

        // end for each element
    } catch (IllegalAccessException e) {
        throw new EPPDecodeException("EPPUtil.decodeCompVector(), IllegalAccessException: " + e);
    } catch (InstantiationException e) {
        throw new EPPDecodeException("EPPUtil.decodeCompVector(), InstantiationException: " + e);
    }

    return retVal;
}

From source file:Animator.java

/**
 * Parse the IMAGES parameter. It looks like 1|2|3|4|5, etc., where each
 * number (item) names a source image.//w  ww . ja v a  2s  .  c om
 * 
 * @return a Vector of (URL) image file names.
 */
Vector parseImages(String attr) throws MalformedURLException {
    Vector result = new Vector(10);
    for (int i = 0; i < attr.length();) {
        int next = attr.indexOf('|', i);
        if (next == -1)
            next = attr.length();
        String file = attr.substring(i, next);
        result.addElement(new URL(imageSource, "T" + file + ".gif"));
        i = next + 1;
    }
    return result;
}

From source file:alice.tuprolog.lib.OOLibrary.java

private static Method lookupMethod(Class<?> target, String name, Class<?>[] argClasses, Object[] argValues)
        throws NoSuchMethodException {
    // first try for exact match
    try {/*from ww  w  .  j  a  v a 2 s . c o m*/
        Method m = target.getMethod(name, argClasses);
        return m;
    } catch (NoSuchMethodException e) {
        if (argClasses.length == 0) { // if no args & no exact match, out of
            // luck
            return null;
        }
    }

    // go the more complicated route
    Method[] methods = target.getMethods();
    Vector<Method> goodMethods = new Vector<>();
    for (int i = 0; i != methods.length; i++) {
        if (name.equals(methods[i].getName()) && matchClasses(methods[i].getParameterTypes(), argClasses))
            goodMethods.addElement(methods[i]);
    }
    switch (goodMethods.size()) {
    case 0:
        // no methods have been found checking for assignability
        // and (int -> long) conversion. One last chance:
        // looking for compatible methods considering also
        // type conversions:
        // double --> float
        // (the first found is used - no most specific
        // method algorithm is applied )

        for (int i = 0; i != methods.length; i++) {
            if (name.equals(methods[i].getName())) {
                Class<?>[] types = methods[i].getParameterTypes();
                Object[] val = matchClasses(types, argClasses, argValues);
                if (val != null) {
                    // found a method compatible
                    // after type conversions
                    for (int j = 0; j < types.length; j++) {
                        argClasses[j] = types[j];
                        argValues[j] = val[j];
                    }
                    return methods[i];
                }
            }
        }

        return null;
    case 1:
        return goodMethods.firstElement();
    default:
        return mostSpecificMethod(goodMethods);
    }
}

From source file:Animator.java

/**
 * Stuff a range of image names into a Vector.
 * /*from  w w w  .  j  av  a2  s.c o m*/
 * @return a Vector of image URLs.
 */
Vector prepareImageRange(int startImage, int endImage, String pattern) throws MalformedURLException {
    Vector result = new Vector(Math.abs(endImage - startImage) + 1);
    if (pattern == null) {
        pattern = "T%N.gif";
    }
    if (startImage > endImage) {
        for (int i = startImage; i >= endImage; i--) {
            result.addElement(new URL(imageSource, doSubst(pattern, i)));
        }
    } else {
        for (int i = startImage; i <= endImage; i++) {
            result.addElement(new URL(imageSource, doSubst(pattern, i)));
        }
    }
    return result;
}