Esempio n. 1
0
  public String toString() {
    String s = "[" + helper_type + ";";
    for (Enumeration e = seq.elements(); e.hasMoreElements(); ) {
      try {
        Class c = (Class) e.nextElement();
        s += c.getName() + ",";
      } catch (NoSuchElementException ee) {
        s += "???" + ",";
      }
    }

    return s + "]";
  }
Esempio n. 2
0
 private static void checkStub(Remote stub, Class<? extends Remote> stubClass) {
   // Check remote stub is from the expected class.
   //
   if (stub.getClass() != stubClass) {
     if (!Proxy.isProxyClass(stub.getClass())) {
       throw new SecurityException("Expecting a " + stubClass.getName() + " stub!");
     } else {
       InvocationHandler handler = Proxy.getInvocationHandler(stub);
       if (handler.getClass() != RemoteObjectInvocationHandler.class) {
         throw new SecurityException(
             "Expecting a dynamic proxy instance with a "
                 + RemoteObjectInvocationHandler.class.getName()
                 + " invocation handler!");
       } else {
         stub = (Remote) handler;
       }
     }
   }
   // Check RemoteRef in stub is from the expected class
   // "sun.rmi.server.UnicastRef2".
   //
   RemoteRef ref = ((RemoteObject) stub).getRef();
   if (ref.getClass() != UnicastRef2.class) {
     throw new SecurityException(
         "Expecting a " + UnicastRef2.class.getName() + " remote reference in stub!");
   }
   // Check RMIClientSocketFactory in stub is from the expected class
   // "javax.rmi.ssl.SslRMIClientSocketFactory".
   //
   LiveRef liveRef = ((UnicastRef2) ref).getLiveRef();
   RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
   if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) {
     throw new SecurityException(
         "Expecting a "
             + SslRMIClientSocketFactory.class.getName()
             + " RMI client socket factory in stub!");
   }
 }
Esempio n. 3
0
  /**
   * Contact a belief network context, get the helper list, and search the list to see if there's a
   * helper which matches the type sequence specified. If there's more than one helper which
   * matches, find the ``best fit.''
   *
   * <p>The class and count scores of the best-fitting helper class are written into
   * <tt>max_class_score[0]</tt> and <tt>max_count_score[0]</tt>, respectively.
   */
  public static Class find_helper_class0(
      Vector seq, String helper_type, int[] max_class_score, int[] max_count_score)
      throws ClassNotFoundException {
    long t0 = System.currentTimeMillis();
    if (bnc != null) // make sure the reference is still alive
    try {
        bnc.get_name();
      } catch (RemoteException e) {
        bnc = null;
      }

    if (bnc == null) // need to locate a context
    {
      String cb = System.getProperty("java.rmi.server.codebase", "http://localhost");
      long tt0 = System.currentTimeMillis();
      try {
        bnc = BeliefNetworkContext.locate_context(new URL(cb).getHost());
      } catch (Exception e) {
        throw new ClassNotFoundException("nested: " + e);
      }
    }

    String[] helperlist;
    try {
      helperlist = bnc.get_helper_names(helper_type);
    } catch (RemoteException e) {
      throw new ClassNotFoundException("bnc.get_helper_names failed");
    }

    int[] class_score1 = new int[1], count_score1 = new int[1];
    max_class_score[0] = -1;
    max_count_score[0] = -1;
    Class cmax_score = null;

    for (int i = 0; i < helperlist.length; i++) {
      try {
        Class c = RMIClassLoader.loadClass(helperlist[i]);
        SeqTriple[] sm = (SeqTriple[]) invoke_description(c);
        if (sm == null) continue; // apparently not a helper class
        if (MatchClassPattern.matches(sm, seq, class_score1, count_score1)) {
          if (class_score1[0] > max_class_score[0]
              || (class_score1[0] == max_class_score[0] && count_score1[0] > max_count_score[0])) {
            cmax_score = c;
            max_class_score[0] = class_score1[0];
            max_count_score[0] = count_score1[0];
          }
        }
      } catch (Exception e2) {
        System.err.println("PiHelperLoader: attempt to load " + helperlist[i] + " failed; " + e2);
      }
    }

    if (cmax_score == null) {
      System.err.println("find_helper_class0: failed; helper list:");
      for (int i = 0; i < helperlist.length; i++) System.err.println("\t" + helperlist[i]);

      String s = "";
      for (Enumeration e = seq.elements(); e.hasMoreElements(); ) {
        try {
          Class c = (Class) e.nextElement();
          s += c.getName() + ",";
        } catch (NoSuchElementException ee) {
          s += "???" + ",";
        }
      }

      throw new ClassNotFoundException("no " + helper_type + " helper for sequence [" + s + "]");
    }

    // FOR NOW IGNORE THE POSSIBILITY OF TWO OR MORE MATCHES !!!
    return cmax_score;
  }