Exemple #1
0
 public void removeFromFav(RoomChat rc, TombolRoomField field) {
   int n = 0;
   RoomChat tf2;
   for (n = 0; n < favRomm.size(); n++) {
     tf2 = (RoomChat) favRomm.elementAt(n);
     if (tf2.getIdRoom().equals(rc.getIdRoom())) {
       favRomm.removeElementAt(n);
       favRomm.trimToSize();
       DBStor.set_roomFav(favRomm);
       break;
     }
   }
   Favourite.delete(field);
 }
Exemple #2
0
  private static void expandComponent(
      final Node node,
      final Collection edges,
      final Collection componentNodes,
      final Collection componentEdges) {
    if (componentNodes.contains(node)) {
      // base case.  I've already expanded on node, so no need to repeat the process.
      //            LOGGER.fine("I've already expanded from " + node);
    } else {
      componentNodes.add(node);
      //            LOGGER.finer("Adding " + node + " to component");
      Vector adjacentEdges =
          findAdjacentEdges(
              node,
              edges); // yes, I know node.getEdges() should do this, but this method could be out of
      // data by the time I use this in AutoClust
      adjacentEdges.trimToSize();
      componentEdges.addAll(adjacentEdges);
      //            LOGGER.finer("Adding " + adjacentEdges + " to component");

      Iterator aeIt = adjacentEdges.iterator();
      while (aeIt.hasNext()) {
        Edge next = (Edge) aeIt.next();
        //                LOGGER.finer("looking at edge " + next);
        Node additionalNode = next.getOtherNode(node);
        //                LOGGER.finer("its other node is " + additionalNode);
        if (additionalNode == null) {
          throw new RuntimeException(
              "I tried to get the other node of this edge "
                  + next
                  + " but it doesn't have "
                  + node);
        }
        expandComponent(additionalNode, edges, componentNodes, componentEdges);
      }
      adjacentEdges.clear();
    }
  }
Exemple #3
0
  protected static synchronized void inicializa() throws Exception {

    if (listaObj == null) { // primeira utilização do gerente de objetos

      listaObj = new Vector();

      // Inicia a conexão com a base de dados
      Connection dbCon = BancoDados.abreConexao();
      Statement dbStmt = dbCon.createStatement();
      ResultSet dbRs;

      // seleciona todos objetos
      String str = "SELECT * FROM Disciplina ORDER BY Nome";
      BancoDadosLog.log(str);
      dbRs = dbStmt.executeQuery(str);

      while (dbRs.next()) {
        // Le dados da base
        String cod = dbRs.getString("cod");
        String nome = dbRs.getString("nome");
        String descricao = StringConverter.fromDataBaseNotation(dbRs.getString("descricao"));
        boolean desativada = dbRs.getBoolean("desativada");

        // Instancia o objeto
        Disciplina obj = new Disciplina(cod, nome, descricao, desativada);

        // Coloca-o na lista de objetos
        listaObj.addElement(obj);
      }

      listaObj.trimToSize();

      // Finaliza conexao
      dbStmt.close();
      dbCon.close();
    }
  }
Exemple #4
0
  public boolean loadData(Integer id) {
    try {
      Vector params = new Vector(1);
      params.add(id);
      rows = (Vector) xmlClient.execute("DateiHandler.getDateien", params);
      rows.trimToSize();
      Iterator it = rows.iterator();
      while (it.hasNext()) {
        Vector row = (Vector) it.next();
        String thumb = (String) row.elementAt(0);
        if (thumb != null) {
          ImageIcon i = new ImageIcon(Base64.decode(thumb.getBytes()));
          row.setElementAt(i, 0);
        }
      }
      logger.debug("DateiTableModel filled with " + getRowCount() + " records.");
      this.id_obj = id;
      return true;

    } catch (XmlRpcException e) {
      MsgBox.error(e.getMessage());
      return false;
    }
  }
 /**
  * This method generates the web page based on the contents of the request packet.
  *
  * <p>This method will be overwritten to enable various actions to take place as the information
  * is uploaded.
  *
  * <p>For the result of File requests, write the contents to a file.
  *
  * <p>I am having a problem with the loading of binary files.
  *
  * @param thisPage Information on this HTTP request
  * @throws IOException if io errors
  */
 protected void processor(ThisPage thisPage) throws IOException {
   Enumeration<String> keys = thisPage.getPartNames();
   HttpServletRequest req = thisPage.getRequest();
   ServletConfig config = thisPage.getConfig();
   String targetDirectory = config.getInitParameter("directory");
   GenericPrinter output = thisPage.getPrinter();
   output.println("<html><head>");
   output.println("<title>Dummy Upload Program</title>");
   output.println("</head><body>");
   output.println("<p>It is assumed that the processor method of the ");
   output.println("bradleyross.library.servlets.UploadServlet class will ");
   output.println("be overridden to provide the desired function.  This ");
   output.println("sample version is designed for testing the applications ");
   output.println("and to allow demonstration of the capabilities.</p>");
   output.println("<p>Target directory for upload tests is " + targetDirectory + "</p>");
   output.println("<h2>Headers</h2>");
   output.println("<table border=\"1\">");
   Enumeration<?> list1 = req.getHeaderNames();
   while (list1.hasMoreElements()) {
     String name = (String) list1.nextElement();
     Enumeration<?> list2 = req.getHeaders(name);
     while (list2.hasMoreElements()) {
       String value = (String) list2.nextElement();
       output.println("<tr><td>" + name + "</td><td>" + value + "</td></tr>");
     }
   }
   output.println("</table>");
   output.println("<h2>Parts of form</h2>");
   output.println("<p>The following are the parts of the multipart form</p>");
   output.println("<ul>");
   while (keys.hasMoreElements()) {
     String name = keys.nextElement();
     String mime = thisPage.getElement(name).getMime();
     String fileName = thisPage.getElement(name).getFilename();
     String encoding = thisPage.getElement(name).getTransferEncoding();
     output.println("<li><p>" + name + "</p>");
     if (fileName == null) {
       output.println("<p>Filename not specified</p>");
     } else {
       output.println("<p>Filename is " + fileName + "</p>");
     }
     if (mime == null) {
       output.println("<p>Content type not specified</p>");
       mime = new String();
     } else {
       output.println("<p>Content-type: " + mime + "</p>");
     }
     if (encoding == null) {
       output.println("<p>Transfer encoding not specified</p>");
     } else {
       output.println("<p>Content-transfer-encoding: " + encoding + "</p>");
     }
     if (mime.toUpperCase().startsWith("TEXT")) {
       output.println(
           "<p>" + StringHelpers.escapeHTML(thisPage.getElement(name).toString()) + "</p></li>");
     }
     output.println(
         "<p>Size of contents: " + Integer.toString(thisPage.getElement(name).getContentsSize()));
     if (fileName != null && targetDirectory != null) {
       try {
         boolean validEntry = true;
         File outputFile = null;
         if (targetDirectory.length() == 0 || fileName.length() == 0) {
           validEntry = false;
         }
         if (validEntry) {
           outputFile = new File(targetDirectory, fileName);
           output.println(
               "<p>Name of file is "
                   + StringHelpers.escapeHTML(outputFile.getCanonicalPath())
                   + "</p>");
         }
         if (!validEntry) {;
         } else if (outputFile == null) {
           output.println("<p>Unable to open output file</p>");
         } else {
           FileOutputStream outputStream = new FileOutputStream(outputFile);
           byte transfer[] = thisPage.getElement(name).getContents();
           if (transfer == null) {
             output.println("<p>Unable to get file contents</p>");
           } else {
             outputStream.write(thisPage.getElement(name).getContents());
           }
           outputStream.close();
         }
       } catch (IOException e) {
         output.println("<p>Error while writing file</p>");
         output.println(
             StringHelpers.escapeHTML(
                 "<p>" + e.getClass().getName() + " " + e.getMessage() + "</p>"));
       }
     } else {;
     }
   }
   output.println("</ul>");
   output.println("<h2>Messages</h2>");
   output.println(
       "<p>These messages are normally printed only if an error occurs during the processing ");
   output.println(
       "of the HTTP transaction.  They are included here to test the behavior of the servlet.</p><ol>");
   Vector<String> messages = thisPage.getMessageList();
   messages.trimToSize();
   for (int i = 0; i < messages.size(); i++) {
     output.println("<li><p>" + StringHelpers.escapeHTML(messages.elementAt(i)) + "</p></li>");
   }
   output.println("</ol>");
   output.println("</body></html>");
   thisPage.sendContents();
 }
  // Submit the specified request, and fetch list attributes reply(s).
  // The returned Vector contains IFSListAttrsRep objects.
  Vector listAttributes(IFSListAttrsReq req) throws IOException, AS400SecurityException {
    // Assume connect() has already been done.

    errorRC_ = 0;
    Vector replys = new Vector(256);
    ClientAccessDataStream ds = null;
    try {
      ds = (ClientAccessDataStream) server_.sendAndReceive(req);
    } catch (ConnectionDroppedException e) {
      Trace.log(Trace.ERROR, "Byte stream server connection lost.");
      connectionDropped(e);
    } catch (InterruptedException e) {
      Trace.log(Trace.ERROR, "Interrupted");
      throw new InterruptedIOException(e.getMessage());
    }

    // @A1A
    int rc = -1; // @A1A

    boolean done = false;
    do {
      if (ds instanceof IFSListAttrsRep) {
        replys.addElement(ds);
      } else if (ds instanceof IFSReturnCodeRep) {
        // If the return code is NO_MORE_FILES then all files
        // that match the specification have been returned.
        rc = ((IFSReturnCodeRep) ds).getReturnCode();

        if (rc != IFSReturnCodeRep.SUCCESS
            && // @D4A
            rc != IFSReturnCodeRep.NO_MORE_FILES
            && rc != IFSReturnCodeRep.FILE_NOT_FOUND
            && rc != IFSReturnCodeRep.PATH_NOT_FOUND) {
          throwSecurityExceptionIfAccessDenied(path_, rc); // check for "access denied"
          Trace.log(
              Trace.ERROR,
              "Error getting file attributes for file "
                  + path_
                  + ": "
                  + "IFSReturnCodeRep return code",
              descriptionForReturnCode(rc));
          throw new ExtendedIOException(path_, rc);
        }

      } else {
        // Unknown data stream.
        Trace.log(Trace.ERROR, "Unknown reply data stream", ds.data_); // @A9C
        throw new InternalErrorException(
            Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
      }

      // Fetch the next reply if not already done.
      done = ((IFSDataStream) ds).isEndOfChain();
      if (!done) {
        try {
          ds = (ClientAccessDataStream) server_.receive(req.getCorrelation());
        } catch (ConnectionDroppedException e) {
          Trace.log(Trace.ERROR, "Byte stream server connection lost.");
          connectionDropped(e);
        } catch (InterruptedException e) {
          Trace.log(Trace.ERROR, "Interrupted");
          throw new InterruptedIOException(e.getMessage());
        }
      }
    } while (!done);

    // @A1A
    if (rc == IFSReturnCodeRep.PATH_NOT_FOUND) { // @A1A
      // If the directory or file does not exist, then return NULL.
      errorRC_ = rc;
      replys = null; // @A1A
    } // @A1A
    else { // @A1A
      // Set the vector capacity to the current size.
      replys.trimToSize();
    } // @A1A

    return replys;
  }
Exemple #7
0
 private ValuesEnumeration(Enumeration e) {
   while (e.hasMoreElements()) {
     v.add(e.nextElement());
   }
   v.trimToSize();
 }
 /**
  * Trims the capacity of this list to be the list's current size.
  *
  * @see Vector#trimToSize()
  */
 public void trimToSize() {
   delegate.trimToSize();
 }
  /** Runs a test on the hsqldb lists */
  public void testLists() {

    HsqlArrayList arrayList = new HsqlArrayList();
    HsqlLinkedList linkedList = new HsqlLinkedList();
    Vector vector = new Vector();
    Vector listCommandsCalled = new Vector(NUMBER_OF_ITERATIONS_PER_RUN);
    Integer tempInt = null;
    int tempCommandCode;
    int tempPosition;
    boolean arrayListException = false;
    boolean linkedListException = false;
    boolean vectorException = false;
    Object arrayListObject = null;
    Object linkedListObject = null;
    Object vectorObject = null;

    for (int i = 0; i < getRandomInt(3, 12); i++) { // prime the contents with a couple items
      tempInt = getRandomInteger();

      arrayList.add(tempInt);
      linkedList.add(tempInt);
      vector.addElement(tempInt);
      listCommandsCalled.addElement("Add");
    }

    compareLists(arrayList, linkedList, vector);

    for (int j = 0; j < NUMBER_OF_ITERATIONS_PER_RUN; j++) {
      tempCommandCode = getRandomInt(0, 15); // 0 and 8 are ignored or used for a special op

      switch (tempCommandCode) {
        case ADD:
          tempInt = getRandomInteger();

          listCommandsCalled.addElement("Add");
          arrayList.add(tempInt);
          linkedList.add(tempInt);
          vector.addElement(tempInt);
          break;

        case ADD_AT:
          tempInt = getRandomInteger();
          tempPosition = getRandomInt(0, vector.size());

          listCommandsCalled.addElement("Add at " + tempPosition);

          try {
            arrayList.add(tempPosition, tempInt);
          } catch (Exception ex) {
            arrayListException = true;
          }

          try {
            linkedList.add(tempPosition, tempInt);
          } catch (Exception ex) {
            linkedListException = true;
          }

          try {
            vector.insertElementAt(tempInt, tempPosition);
          } catch (Exception ex) {
            vectorException = true;
          }
          break;

        case GET:
          tempPosition = getRandomInt(0, vector.size() - 1);

          listCommandsCalled.addElement("Get " + tempPosition);

          try {
            arrayListObject = arrayList.get(tempPosition);
          } catch (Exception ex) {
            arrayListException = true;
          }

          try {
            linkedListObject = linkedList.get(tempPosition);
          } catch (Exception ex) {
            linkedListException = true;
          }

          try {
            vectorObject = vector.elementAt(tempPosition);
          } catch (Exception ex) {
            vectorException = true;
          }
          break;

        case REMOVE:
          tempPosition = getRandomInt(0, vector.size() - 1);

          listCommandsCalled.addElement("Remove " + tempPosition);

          try {
            arrayListObject = arrayList.remove(tempPosition);
          } catch (Exception ex) {
            arrayListException = true;
          }

          try {
            linkedListObject = linkedList.remove(tempPosition);
          } catch (Exception ex) {
            linkedListException = true;
          }

          try {
            vectorObject = vector.elementAt(tempPosition);

            vector.removeElementAt(tempPosition);
          } catch (Exception ex) {
            vectorException = true;
          }
          break;

        case SET:
          tempInt = getRandomInteger();
          tempPosition = getRandomInt(0, vector.size() - 1);

          listCommandsCalled.addElement("Set " + tempPosition);

          try {
            arrayList.set(tempPosition, tempInt);
          } catch (Exception ex) {
            arrayListException = true;
          }

          try {
            linkedList.set(tempPosition, tempInt);
          } catch (Exception ex) {
            linkedListException = true;
          }

          try {
            vector.setElementAt(tempInt, tempPosition);
          } catch (Exception ex) {
            vectorException = true;
          }
          break;

        case OPTIMIZE:
          listCommandsCalled.addElement("Optimize");
          arrayList.trim();
          vector.trimToSize();
          break;

        case REMOVE_ALL:
          if (getRandomInt(0, 5) == 4) { // to limit the frequency of this call
            listCommandsCalled.addElement("Remove all");

            if (vector.size() == 0) {
              break;
            }

            for (int k = arrayList.size() - 1; k >= 0; k--) {
              arrayList.remove(k);
              linkedList.remove(k);
            }

            vector.removeAllElements();
          }
          break;

        default:
      }

      if (arrayListException || linkedListException || vectorException) {

        // if an exception is thrown in vector but not one of the lists or vice versa
        if (!(arrayListException && linkedListException && vectorException)) {
          if (!(arrayListException && vectorException)) {
            System.out.println("Exception descrepancy with vector and arraylist");
          } else if (!(linkedListException && vectorException)) {
            System.out.println("Exception descrepancy with vector and linkedlist");
          } else {
            System.out.println("Error in TestDataStructures");
          }

          this.printListCommandsCalled(listCommandsCalled);
          fail("test failed");

          // System.exit(0);
        }

        return;
      }

      if (!objectEquals(linkedListObject, arrayListObject, vectorObject)) {
        System.out.println("Objects returned inconsistent");
        this.printListCommandsCalled(listCommandsCalled);
        fail("test failed");

        // System.exit(0);
      }

      compareLists(arrayList, linkedList, vector);
    }
  }