Esempio n. 1
1
  public static Hashtable findConfidence(Hashtable table) {
    Hashtable confidences = new Hashtable();
    Iterator key_iter = table.keySet().iterator();
    while (key_iter.hasNext()) {
      // System.out.println("here");
      ArrayList<Integer> combo = (ArrayList<Integer>) key_iter.next();
      // System.out.println("current combo"+combo);
      if (combo.size() >= 2) {
        ArrayList<Integer> current_combo =
            new ArrayList<Integer>(combo.subList(0, combo.size() - 1));
        ArrayList<Integer> last_combo =
            new ArrayList<Integer>(combo.subList(combo.size() - 1, combo.size()));
        /*System.out.println(combo);
        System.out.println(current_combo);
        System.out.println(last_combo);
        System.out.println(table.get(current_combo));*/

        if (table.get(current_combo) != null) {
          // System.out.println("it contains!");
          int first = (Integer) table.get(current_combo);
          int second = (Integer) table.get(combo);
          double dub_first = (double) first;
          double dub_second = (double) second;
          double combo_conf = dub_second / dub_first;
          confidences.put(combo, combo_conf);
          // System.out.println("combo:"+combo+" has the confience: "+combo_conf);
        }
      }
    }
    // System.out.println(confidences+"O");

    return confidences;
  }
  public Document getDocument(String function, Hashtable params) throws XFormsException {

    Hashtable ret = runFunc(function, params);

    if (!ret.containsKey("status")) {
      throw new XFormsException("XML-RPC return hash has no status");
    }

    String status = (String) ret.get("status");

    if (status.equals("error")) {

      if (!ret.containsKey("error")) {
        throw new XFormsException("Unknown error: cannot find XML-RPC error code");
      }

      String s = (String) ret.get("error");
      throw new XFormsException(s);
    }

    byte[] docbytes = (byte[]) ret.get("doc");

    Document doc = null;
    try {
      DocTransformer dt = new DocTransformer(docbytes);
      doc = dt.getDoc();
    } catch (Exception e) {
      throw new XFormsException(e);
    }

    return doc;
  }
Esempio n. 3
0
  /**
   * To retrieve the current image index that is currently animating and then updating the current
   * to the next image
   *
   * @param id
   */
  public void changeCurrIndex(Integer id) {
    // gives the animation name give the entity id
    String animation = mCurrentAnimation.get(id);
    // gets  the actual array assoc with the name
    CircularArray<Texture2> arr = mReelsNameAssoc.get(animation);

    // checks if the key is in the hash table
    if (mUpdateCurrAni.containsKey(id)) {
      int imgIndex = mUpdateCurrAni.get(id); // Retrieve the last draw's image index

      mUpdateCurrAni.remove(id); // remove it

      if (imgIndex < arr.size() - 1) { // check if the current index is still within bound

        imgIndex++; // increment the index

        mUpdateCurrAni.put(id, imgIndex); //  put next index in
      } else {

        imgIndex = 0; // when we are at the last index wrap back to the beginning
      }

    } else {
      // else is it not in the table we add with the index being 0
      mUpdateCurrAni.put(id, 0);
    }
  }
  /**
   * This method initiates and populates the hashmap reqs, with all requirements in the graph. There
   * are two types of requirements: Ordinary and Variable. All of them are fetched by calling
   * getReqTagKey for all the edges and vertexes in the graph The Ordinary requirements are directly
   * put into the reqs hashmap. The Variable requirements are used as a lookup in the list of all
   * the variable values returned by getAllVariableValues and the value matching the the Variable
   * requirement are splitted with colon and put as keys into the reqs hashmap. The value for each
   * entity in the reqs hashmap will be set to null, since no requirement are tested yet. Its never
   * needed to call this method more than once.
   */
  public void populateReqHashMap() {
    reqs = new HashMap<String, Boolean>();
    Hashtable<String, String> reqsVariables = getAllVariableValues();

    for (Edge edge : model.getEdges()) {
      String reqTag = edge.getReqTagKey();
      if (reqTag.length() == 0) continue;
      String[] tmp = reqTag.split(",");
      for (int i = 0; i < tmp.length; i++) {
        if (tmp[i].matches("[$][{].*[}]")) {
          String[] reqNames =
              reqsVariables.get(tmp[i].substring(2, tmp[i].length() - 1)).split(":");
          for (String reqVar : reqNames) this.reqs.put(reqVar, null);
        } else this.reqs.put(tmp[i], null);
      }
    }
    for (Vertex vertex : model.getVertices()) {
      String reqTag = vertex.getReqTagKey();
      if (reqTag.length() == 0) continue;
      String[] tmp = reqTag.split(",");
      for (int i = 0; i < tmp.length; i++) {
        if (tmp[i].matches("[$][{].*[}]")) {
          String savedReq = reqsVariables.get(tmp[i].substring(2, tmp[i].length() - 1));
          if (savedReq == null) continue;
          String[] reqNames = savedReq.split(":");
          for (String reqVar : reqNames) this.reqs.put(reqVar, null);
        } else this.reqs.put(tmp[i], null);
      }
    }
  }
  public void waitForLSPaddition(long lspId, long timeWait) {
    Lock lock;
    Condition lspEstablished;
    try {
      lock = lockList.get(lspId);
      if (lock == null) log.info("Lock is NULL!");
      lspEstablished = conditionList.get(lspId);
    } catch (Exception e) {
      return;
    }

    lock.lock();
    try {
      if (established == false) {
        log.info("Waiting " + timeWait + " ms  for LSP " + lspId + " to be established");
        lspEstablished.await(timeWait, TimeUnit.MILLISECONDS);
      } else {
        log.info("Inside waitForLSPaddition lockList.remove");
        // FIXME: Revisar esto
        lockList.remove(lspId);
        conditionList.remove(lspId);
      }
      log.info("LSP " + lspId + " has been established");
    } catch (InterruptedException e) {
      return;
    } finally {
      lock.unlock();
    }
  }
Esempio n. 6
0
  @Override
  public HashMap<Integer, Point> getVoisins(int refRMI) throws RemoteException {
    HashMap<Integer, Point> res = new HashMap<Integer, Point>();

    VuePersonnage courant = personnages.get(refRMI);
    VuePersonnage tempPers;

    // personnages
    for (int refVoisin : personnages.keySet()) {
      tempPers = personnages.get(refVoisin);

      if (estVoisin(courant, tempPers)) {
        res.put(refVoisin, tempPers.getPosition());
      }
    }

    VuePotion tempPot;

    // potions
    for (int refVoisin : potions.keySet()) {
      tempPot = potions.get(refVoisin);

      if (estVoisin(courant, tempPot)) {
        res.put(refVoisin, tempPot.getPosition());
      }
    }

    return res;
  }
Esempio n. 7
0
  private static String loadString(String key) {
    if (lang == null) {
      String langFile = Config.getInstance().langFileName();
      if (langFile == null) lang = new Hashtable();
      else lang = new StringLoader().hashtableLoader(langFile);
      System.out.print("Loading locale ");
      System.out.println(langFile);
      MS_XMLLANG = (String) lang.get("xmlLang");

      MS_IFACELANG = MS_XMLLANG;
      if (MS_IFACELANG == null) MS_IFACELANG = "en";

      presences = new Hashtable();
      presences.put("online", loadString("online"));
      presences.put("chat", loadString("free for chat"));
      presences.put("away", loadString("away"));
      presences.put("xa", loadString("not available"));
      presences.put("invisible", loadString("invisible"));
      presences.put("dnd", loadString("do not disturb"));
      presences.put("unavailable", loadString("offline"));
    }
    String value = (String) lang.get(key);
    // #if LOCALE_DEBUG
    if (value == null) {
      if (!lang.isEmpty()) {
        System.out.print("Can't find local string for <");
        System.err.print(key);
        System.err.println('>');
      }
    }
    // #endif
    return (value == null) ? key : value;
  }
Esempio n. 8
0
  private void verifyDb(Hashtable dataMap, int dumpIndex) throws DatabaseException {

    DatabaseConfig config = new DatabaseConfig();
    config.setReadOnly(true);
    DbInternal.setUseExistingConfig(config, true);
    Database myDb = env.openDatabase(null, dbName + dumpIndex, config);
    Cursor cursor = myDb.openCursor(null, null);
    StringDbt foundKey = new StringDbt();
    StringDbt foundData = new StringDbt();
    OperationStatus status = cursor.getFirst(foundKey, foundData, LockMode.DEFAULT);
    while (status == OperationStatus.SUCCESS) {
      String foundKeyString = foundKey.getString();
      String foundDataString = foundData.getString();
      if (dataMap.get(foundKeyString) != null) {
        assertTrue(((String) dataMap.get(foundKeyString)).equals(foundDataString));
        dataMap.remove(foundKeyString);
      } else {
        fail("didn't find key in either map (" + foundKeyString + ")");
      }
      status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT);
    }
    assertTrue(dataMap.size() == 0);
    cursor.close();
    myDb.close();
  }
  /**
   * Interface TestListener.
   *
   * <p>A Test is finished.
   */
  public void endTest(Test test) {
    // Fix for bug #5637 - if a junit.extensions.TestSetup is
    // used and throws an exception during setUp then startTest
    // would never have been called
    if (!testStarts.containsKey(test)) {
      startTest(test);
    }

    Element currentTest = null;
    if (!failedTests.containsKey(test)) {
      currentTest = doc.createElement(TESTCASE);
      currentTest.setAttribute(ATTR_NAME, JUnitVersionHelper.getTestCaseName(test));
      // a TestSuite can contain Tests from multiple classes,
      // even tests with the same name - disambiguate them.
      currentTest.setAttribute(ATTR_CLASSNAME, test.getClass().getName());
      rootElement.appendChild(currentTest);
      testElements.put(test, currentTest);
    } else {
      currentTest = (Element) testElements.get(test);
    }

    Long l = (Long) testStarts.get(test);
    currentTest.setAttribute(
        ATTR_TIME, "" + ((System.currentTimeMillis() - l.longValue()) / 1000.0));
  }
Esempio n. 10
0
  public static void main(String args[]) {
    Hashtable<String, Double> balance = new Hashtable<String, Double>();

    Enumeration<String> names;
    String str;
    double bal;

    balance.put("John Doe", 3434.34);
    balance.put("Tom Smith", 123.22);
    balance.put("Jane Baker", 1378.00);
    balance.put("Tod Hall", 99.22);
    balance.put("Ralph Smith", -19.08);

    // Show all balances in hashtable.
    names = balance.keys();
    while (names.hasMoreElements()) {
      str = names.nextElement();
      System.out.println(str + ": " + balance.get(str));
    }

    System.out.println();

    // Deposit 1,000 into John Doe's account.
    bal = balance.get("John Doe");
    balance.put("John Doe", bal + 1000);
    System.out.println("John Doe's new balance: " + balance.get("John Doe"));
  }
Esempio n. 11
0
 /**
  * Sets the thickness of the arc used to draw features.
  *
  * @param width "xxx-small", "xx-small", "x-small", "small", "medium", "large", "x-large",
  *     "xx-large", "xxx-large".
  */
 public void setFeatureThickness(String width) {
   try {
     featureThickness = ((Float) FEATURE_THICKNESSES.get(width)).floatValue();
   } catch (NullPointerException e) {
     featureThickness = ((Float) FEATURE_THICKNESSES.get("medium")).floatValue();
   }
 }
Esempio n. 12
0
 /**
  * Sets the thickness of the arc used to draw the backbone.
  *
  * @param width "xxx-small", "xx-small", "x-small", "small", "medium", "large", "x-large",
  *     "xx-large", "xxx-large".
  */
 public void setBackboneThickness(String width) {
   try {
     backboneThickness = ((Float) BACKBONE_THICKNESSES.get(width)).floatValue();
   } catch (NullPointerException e) {
     backboneThickness = ((Float) BACKBONE_THICKNESSES.get("medium")).floatValue();
   }
 }
Esempio n. 13
0
  public synchronized void registerService(
      ConnectionPoolConfiguration config, List<TaskStub> taskList) throws RegistrationException {
    ConnectionPool pool = ConnectionPool.createFromConfiguration(config);
    for (Iterator<TaskStub> it = taskList.iterator(); it.hasNext(); ) {
      TaskStub stub = it.next();
      String name = stub.getName();

      System.out.println("registering task: " + name);

      if (registeredServices.containsKey(name)) {
        if (!registeredServices.get(name).equals(stub))
          throw new RegistrationException("TASK CONFLICT: " + name);
      } else {
        System.out.println("not found in registeredServices");
        registeredServices.put(name, stub);
      }
      if (connectionResources.containsKey(name)) {
        System.out.println("found in connectionResources");
        stub.setBalancer(connectionResources.get(name));
        connectionResources.get(name).addPool(pool);
      } else {
        LoadBalancer balancer = new RoundRobinBalancer();
        balancer.addPool(pool);
        stub.setBalancer(balancer);
        connectionResources.put(name, balancer);
      }
    }
    if (!connectionPools.contains(pool)) {
      connectionPools.add(pool);
    }
    registeredEndpoints.add(new InetSocketAddress(config.getRemoteHost(), config.getPort()));
    notifyChanged();
  }
  private void convertHashTableToArray(Hashtable hashtable) {

    String icCodesString = (String) hashtable.get("stringval1");
    String productsString = (String) hashtable.get("stringval2");

    String[] icCodesArray = null;
    if (productsString != null) {

      if (icCodesString != null) {
        icCodesArray = StringSplitter.INSTANCE.split(icCodesString, "~");
      }

      String[] productsArray = StringSplitter.INSTANCE.split(productsString, "~");

      if (productsArray != null) {
        Constant.oldProductArray = productsArray;
      }
      if (icCodesArray != null) {
        Constant.oldICCodeArray = icCodesArray;
      }

    } else {
      UiApplication.getUiApplication()
          .invokeLater(
              new Runnable() {

                public void run() {
                  Dialog.alert(
                      "Failed to Refresh Product List for Visit info, Prerequisite configuration not available on server..");
                }
              });
    }
  }
Esempio n. 15
0
  private Hashtable<Spezies, Double> calc_dmj_dp() {
    Hashtable<Spezies, Double> massenBruchHash_Zone = gg_Zone.get_speziesMassenBruecheDetail();
    Hashtable<Spezies, Double> dmj_dp = new Hashtable<Spezies, Double>();

    Enumeration<Spezies> e = massenBruchHash_Zone.keys();
    Spezies spez;

    if (loeseChemGleichgwicht == true && burns == true) {
      double delta_p = 5000;
      GasGemisch rauchgas =
          new GasGemisch(
              GG_SOLVER.get_GG_molenBrueche(p_Zone + delta_p, T_Zone, gg_Zone),
              "rauchgas_temp_" + ID);
      Hashtable<Spezies, Double> rgSpezMassenBrueche = rauchgas.get_speziesMassenBruecheDetail();

      while (e.hasMoreElements()) {
        spez = e.nextElement();
        dmj_dp.put(
            spez,
            (m_Zone * (rgSpezMassenBrueche.get(spez) - massenBruchHash_Zone.get(spez))) / delta_p);
      }

    } else {

      while (e.hasMoreElements()) {
        spez = e.nextElement();
        dmj_dp.put(spez, 0.0);
      }
    }

    return dmj_dp;
  }
Esempio n. 16
0
 static Object createObject(Class klass) {
   synchronized (emptyPool) {
     Vector emptyList = (Vector) emptyPool.get(klass);
     if (emptyList == null || emptyList.size() == 0) {
       // Create a new status
       if (verbose) {
         if (Log.isLoggable(Log.TRACE)) {
           Log.trace(TAG_LOG, "Creating new " + klass.getName());
         }
       }
       try {
         Object object = klass.newInstance();
         Vector usedList = (Vector) usedPool.get(klass);
         if (usedList == null) {
           usedList = new Vector();
           usedPool.put(klass, usedList);
         }
         usedList.addElement(object);
         return object;
       } catch (Exception e) {
         throw new IllegalArgumentException("Cannot instantiate " + klass);
       }
     } else {
       if (verbose) {
         if (Log.isLoggable(Log.TRACE)) {
           Log.trace(TAG_LOG, "Reusing existing " + klass.getName());
         }
       }
       ReusableObject obj = (ReusableObject) emptyList.elementAt(emptyList.size() - 1);
       emptyList.removeElementAt(emptyList.size() - 1);
       obj.init();
       return obj;
     }
   }
 }
Esempio n. 17
0
 /**
  * Temporary release objects. The memory is not actually released and instances are retained for
  * reuse.
  */
 public static void release() {
   if (verbose) {
     if (Log.isLoggable(Log.TRACE)) {
       Log.trace(TAG_LOG, "Releasing all objects in the pool");
     }
   }
   // Move all the used objects into the empty ones
   synchronized (emptyPool) {
     Enumeration keys = usedPool.keys();
     while (keys.hasMoreElements()) {
       Class klass = (Class) keys.nextElement();
       Vector u = (Vector) usedPool.get(klass);
       Vector e = (Vector) emptyPool.get(klass);
       for (int i = 0; i < u.size(); ++i) {
         Object o = u.elementAt(i);
         if (e == null) {
           e = new Vector();
           emptyPool.put(klass, e);
         }
         e.addElement(o);
       }
       u.removeAllElements();
     }
     // Dump stats
     dumpStats();
   }
 }
  // evaluate the current policy and calculate the current value of the policy at each state.
  private void evaluatePolicy() {
    Double deltaValue = 1.0;
    Double maxDelta = 0.0;

    // use value iteration for the current policy to determine the value of the current policy over
    // all states.
    while (deltaValue > maxDelta) {

      deltaValue = 0.0;

      Enumeration<Integer> keys = stateValues.keys();
      Integer key;
      Double oldValue, newValue;

      // iterate over all values in the stateValue table, as in Value Iteration.
      while (keys.hasMoreElements()) {
        key = keys.nextElement();
        oldValue = stateValues.get(key);
        updateValue(key); // update value
        newValue = stateValues.get(key);
        deltaValue =
            Math.max(Math.abs(oldValue - newValue), deltaValue); // track largest value change.
      }
    }
  }
  // Determine the policy that currently yields the highest value.
  private boolean updatePolicy(Integer key) {
    Game game = gameFromKey(key);
    int currentPolicy = statePolicy.get(key);

    int updatedPolicy = currentPolicy;
    Double currentValue = stateValues.get(key);
    // iterate over all possible moves, determine the best policy.
    for (int move : game.possibleMoves()) {
      Game nextTurn = game.simulateMove(move);
      Double moveValue = (double) getReward(nextTurn);

      if (nextTurn.evaluateGameState() != Consts.GameInProgress) {
        if (moveValue > currentValue) {
          currentValue = moveValue;
          updatedPolicy = move;
        }
        continue;
      }
      for (TransitionPair successor : opponent.getSuccessorStates(nextTurn)) {
        try {
          moveValue += Consts.DiscountFactor * getValue(successor.game) * successor.probability;
        } catch (InvalidMoveException e) {
          System.out.println(e.getMessage());
          e.printStackTrace();
        }
      }
      if (moveValue > currentValue) {
        currentValue = moveValue;
        updatedPolicy = move;
      }
    }
    // Update statePolicy table
    statePolicy.put(key, updatedPolicy);
    return (currentPolicy != updatedPolicy); // true if something changed.
  }
Esempio n. 20
0
  static void dumpToFile(
      String name1,
      String name2,
      OutputStream ostream,
      Hashtable<String, PkgEntry> tbl1,
      Hashtable<String, PkgEntry> tbl2) {

    List<String> keyList = new ArrayList<String>();
    for (String x : Collections.list(tbl1.keys())) {
      keyList.add(x);
    }
    Collections.sort(keyList);
    PrintWriter pw = null;
    pw = new PrintWriter(new OutputStreamWriter(ostream));
    pw.printf("\t%s\t%s\n", name1, name2);
    long sum1 = 0L;
    long sum2 = 0L;
    for (String x : keyList) {
      pw.printf("%s\t%s\t%s\n", x, tbl1.get(x).getSize() / 1024, tbl2.get(x).getSize() / 1024);
      sum1 += tbl1.get(x).getSize();
      sum2 += tbl2.get(x).getSize();
    }
    pw.printf("Total\t%s\t%s\n", sum1 / 1024, sum2 / 1024);
    pw.flush();
  }
Esempio n. 21
0
 private int getId(Object key) {
   if (strToInt.get(key) != null) {
     //                return ((Integer)strToInt.get(key)).intValue();
     return ((FeatureImpl) strToInt.get(key)).index();
   }
   return -1;
 }
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (uneHashtable.get(unEtat) != null) {
     g.setColor((Color) uneHashtable.get(unEtat));
     g.fillRect(100, 20, 40, 40);
   }
 }
Esempio n. 23
0
  @Override
  public boolean ramassePotion(int refRMI, int refPotion) throws RemoteException {
    boolean res = false;

    VuePersonnage vuePersonnage = personnages.get(refRMI);
    VuePotion vuePotion = potions.get(refPotion);

    if (vuePersonnage.isActionExecutee()) {
      // si une action a deja ete executee
      logActionDejaExecutee(refRMI);

    } else {
      // sinon, on tente de jouer l'interaction
      int distance =
          Calculs.distanceChebyshev(vuePersonnage.getPosition(), vuePotion.getPosition());

      // on teste la distance entre le personnage et la potion
      if (distance <= Constantes.DISTANCE_MIN_INTERACTION) {
        new Ramassage(this, vuePersonnage, vuePotion).interagit();
        personnages.get(refRMI).executeAction();

        res = true;
      } else {
        logger.warning(
            Constantes.nomClasse(this),
            nomRaccourciClient(refRMI)
                + " a tente d'interagir avec "
                + vuePotion.getElement().getNom()
                + ", alors qu'il est trop eloigne !\nDistance = "
                + distance);
      }
    }

    return res;
  }
Esempio n. 24
0
  /**
   * Find an element in the list.
   *
   * <p>This is a little more complex than the simple lookup since it might be that we are indexing
   * with a class and the list contains interfaces.
   *
   * <p>Since the hashtable lookup is a lot faster than the linear search we add the result of the
   * linear search to the hashtable so that the next time we need not do it.
   *
   * @return Checklist or null if noone exist.
   * @param cls the class to lookup.
   */
  private static Checklist lookupChecklist(Class cls) {
    if (lists.contains(cls)) {
      return (Checklist) lists.get(cls);
    }

    // Now lets search
    Enumeration enumeration = lists.keys();

    while (enumeration.hasMoreElements()) {
      Object clazz = enumeration.nextElement();

      Class[] intfs = cls.getInterfaces();
      for (int i = 0; i < intfs.length; i++) {
        if (intfs[i].equals(clazz)) {
          // We found it!
          Checklist chlist = (Checklist) lists.get(clazz);

          // Enter the class to speed up the next search.
          lists.put(cls, chlist);
          return chlist;
        }
      }
    }

    return null;
  }
 protected void makeSpines(LinkedList<StackSorterTriple> triples) {
   System.out.println("makeSpines");
   spines = new LinkedList<SpineRepresentation>();
   ListIterator<StackSorterTriple> li = triples.listIterator();
   while (li.hasNext()) {
     StackSorterTriple triple = li.next();
     Hashtable<String, Serializable> hash = triple.getItemInfo();
     if (hash != null) {
       String itemS = (String) hash.get("item");
       if (itemS != null) {
         Integer itemAkt = Integer.parseInt(itemS);
         boolean isSpecial = itemAkt.equals(item);
         System.out.println(itemAkt);
         // SpineRepresentationImpl spine=new
         // SpineRepresentationImpl(new
         // BibliographicStatusSorterImpl(itemAkt,(String)hash.get("ibarcode"),(String)hash.get("status"),(String)hash.get("collection")),isSpecial,false);
         SpineRepresentationImpl spine =
             new SpineRepresentationImpl(
                 new BibliographicStatusSorterImpl(
                     Integer.parseInt((String) hash.get("bib")),
                     (String) hash.get("ibarcode"),
                     (String) hash.get("status"),
                     (String) hash.get("collection")),
                 isSpecial,
                 false);
         spines.add(spine);
       } else {
         System.out.println("SpineGetterSorterImp.makeSpines: item null.");
       }
     } else {
       System.out.println("SpineGetterSorterImp.makeSpines: hash null.");
     }
   }
 }
Esempio n. 26
0
  public void executeLast(Hashtable _tagLibrary, Hashtable _beanLibrary) {
    try {
      Boolean included =
          (Boolean)
              (((report_element_base) _beanLibrary.get("SYSTEM:" + iConst.iHORT_SYSTEM_Included))
                  .getContent());
      if (included != null && included.booleanValue() == true) {
      } else {
        document =
            (document)
                (((report_element_base) _beanLibrary.get("SYSTEM:" + iConst.iHORT_SYSTEM_Document))
                    .getContent());
        java.util.Vector vector =
            ((java.util.Vector)
                (((report_element_base) _beanLibrary.get("SYSTEM:" + iConst.iHORT_SYSTEM_Canvas))
                    .getContent()));
        vector.remove(vector.lastElement());
        if (_tagLibrary.get(getName() + ":" + getID()) == null)
          _tagLibrary.remove(getName() + ":" + getID() + "_ids_" + this.motore.hashCode());
        else _tagLibrary.remove(getName() + ":" + getID());

        ((DataOutputStream)
                (((report_element_base) _beanLibrary.get("SYSTEM:" + iConst.iHORT_SYSTEM_Writer))
                    .getContent()))
            .writeBytes(document._content + document._comment + document._footer);
      }
    } catch (Exception e) {
      setError(e, iStub.log_ERROR);
    }
  }
Esempio n. 27
0
  /**
   * Generates the localized key for the given password and engine id for the privacy protocol
   * specified by the supplied OID.
   *
   * @param privProtocolID an <code>OID</code> identifying the privacy protocol the key should be
   *     created for.
   * @param authProtocolID an <code>OID</code> identifying the authentication protocol to use.
   * @param passwordString the authentication pass phrase.
   * @param engineID the engine ID of the authoritative engine.
   * @return the localized privacy key.
   */
  public byte[] passwordToKey(
      OID privProtocolID, OID authProtocolID, OctetString passwordString, byte[] engineID) {

    AuthenticationProtocol authProtocol = authProtocols.get(authProtocolID);
    if (authProtocol == null) {
      return null;
    }
    PrivacyProtocol privProtocol = privProtocols.get(privProtocolID);
    if (privProtocol == null) {
      return null;
    }
    byte[] key = authProtocol.passwordToKey(passwordString, engineID);

    if (key == null) {
      return null;
    }
    if (key.length >= privProtocol.getMinKeyLength()) {
      if (key.length > privProtocol.getMaxKeyLength()) {
        // truncate key
        byte[] truncatedKey = new byte[privProtocol.getMaxKeyLength()];
        System.arraycopy(key, 0, truncatedKey, 0, privProtocol.getMaxKeyLength());
        return truncatedKey;
      }
      return key;
    }
    // extend key if necessary
    byte[] extKey = privProtocol.extendShortKey(key, passwordString, engineID, authProtocol);
    return extKey;
  }
Esempio n. 28
0
  /**
   * 判断相等
   *
   * @param params0
   * @param params1
   * @return
   */
  public static boolean equals(Hashtable params0, Hashtable params1) {
    // 相等,包括均为空
    if (params0 == null && params1 == null) {
      return true;
    }
    // 非空
    if (params0 == null || params1 == null) {
      return false;
    }

    if (params0.size() != params1.size()) {
      return false;
    }
    // 键和值相等
    for (Enumeration e = params0.keys(); e.hasMoreElements(); ) {
      String key0 = (String) e.nextElement();
      String val0 = (String) params0.get(key0);

      if (params1.containsKey(key0)) {
        String val1 = (String) params1.get(key0);
        if (!val0.equals(val1)) {
          return false;
        }
      } else {
        return false;
      }
    }
    return true;
  }
  /**
   * Checks to see if this <tt>PermissionCollection</tt> implies the given permission.
   *
   * @param permission the <tt>Permission</tt> object to check against
   * @return true if the given permission is implied by this <tt>PermissionCollection</tt>, false
   *     otherwise.
   */
  public boolean implies(Permission permission) {
    if (!(permission instanceof UserAdminPermission)) {
      return (false);
    }

    UserAdminPermission uap = (UserAdminPermission) permission;
    UserAdminPermission x;

    int desired = uap.getMask();
    int effective = 0;

    // Short circuit if the "*" Permission was added.
    // desired can only be ACTION_NONE when name is "admin".
    if (all_allowed && desired != UserAdminPermission.ACTION_NONE) {
      x = (UserAdminPermission) permissions.get("*");
      if (x != null) {
        effective |= x.getMask();
        if ((effective & desired) == desired) {
          return (true);
        }
      }
    }

    // strategy:
    // Check for full match first. Then work our way up the
    // name looking for matches on a.b.*
    String name = uap.getName();

    x = (UserAdminPermission) permissions.get(name);

    if (x != null) {
      // we have a direct hit!
      effective |= x.getMask();
      if ((effective & desired) == desired) {
        return (true);
      }
    }

    // work our way up the tree...
    int last;

    int offset = name.length() - 1;

    while ((last = name.lastIndexOf(".", offset)) != -1) {
      name = name.substring(0, last + 1) + "*";
      x = (UserAdminPermission) permissions.get(name);

      if (x != null) {
        effective |= x.getMask();
        if ((effective & desired) == desired) {
          return (true);
        }
      }
      offset = last - 1;
    }

    // we don't have to check for "*" as it was already checked
    // at the top (all_allowed), so we just return false
    return (false);
  }
Esempio n. 30
0
 public TreeNode getChildAt(int index) {
   if (acceptor.acceptsMetadata() && index >= entry.getMetadataCount()) {
     SelectableEntry childEntry =
         getEntry().getChildAt(index - entry.getMetadataCount(), acceptor);
     SelectableEntryNode node = (SelectableEntryNode) childrenNodeTable.get(childEntry.getID());
     if (node == null) {
       node = new SelectableEntryNode(childEntry, this, acceptor, model);
       childrenNodeTable.put(childEntry.getID(), node);
     }
     return node;
   } else if (acceptor.acceptsMetadata()) {
     Metadata metadata = entry.getMetadata(index);
     MetadataNode node = (MetadataNode) metadataNodeTable.get(metadata.getID());
     if (node == null) {
       node = new MetadataNode(this, metadata, model);
       metadataNodeTable.put(metadata.getID(), node);
     }
     return node;
   } else {
     SelectableEntry childEntry = getEntry().getChildAt(index, acceptor);
     SelectableEntryNode node = (SelectableEntryNode) childrenNodeTable.get(childEntry.getID());
     if (node == null) {
       node = new SelectableEntryNode(childEntry, this, acceptor, model);
       childrenNodeTable.put(childEntry.getID(), node);
     }
     return node;
   }
 }