Пример #1
2
  /**
   * Sets the java.security.policy system property to point at the location of the security policy
   * file, which is assumed to be at "provided\rmiUtils\server.policy" (file separators adjusted to
   * match operating system). the security manager is then started. This method must be called
   * before starting the class server.
   */
  private void configSecurityManager() {
    // file.separator is "\" in Windows and "/" in Unix/Linux/Mac.
    String sep = System.getProperty("file.separator");

    System.setProperty(
        "java.security.policy", "provided" + sep + "rmiUtils" + sep + "server.policy");
    outputCmd.apply("java.security.policy: " + System.getProperty("java.security.policy"));

    // Start the security manager
    if (System.getSecurityManager() == null) {
      outputCmd.apply("Installing new Security Manager...\n");
      System.setSecurityManager(new SecurityManager());
      outputCmd.apply("Security Manager = " + System.getSecurityManager());
    }
  }
Пример #2
1
  /**
   * Sets the java.rmi.server.hostname and java.rmi.server.codebase system properties which control
   * the automatic remote dynamic class loading. This must be called before starting the class
   * server.
   *
   * @param classServerPort The port the class server will use.
   */
  private void configRMIProperties(int classServerPort) {
    // Logs all RMI activity to System.err
    System.setProperty("java.rmi.server.logCalls", "true");

    try {
      // Try to get figure out this server's IP address and save it as the
      // RMI server hostname.
      System.setProperty("java.rmi.server.hostname", getLocalAddress());

      System.setProperty(
          "java.rmi.server.codebase",
          "http://" + System.getProperty("java.rmi.server.hostname") + ":" + classServerPort + "/");
      System.setProperty(
          "java.rmi.server.useCodebaseOnly",
          "false"); // Must be false to allow remote class dynamic loading (defaults to true for JDK
                    // 1.7+)
      outputCmd.apply(
          "java.rmi.server.hostname: " + System.getProperty("java.rmi.server.hostname") + "\n",
          "java.rmi.server.codebase: " + System.getProperty("java.rmi.server.codebase") + "\n",
          "java.rmi.server.useCodebaseOnly: "
              + System.getProperty("java.rmi.server.useCodebaseOnly")
              + "\n");

    } catch (Exception e) {
      outputCmd.apply("Error getting local host address: " + e + "\n");
    }
  }
Пример #3
0
  /**
   * Start the class file server to support remote dynamic class loading. This method must be called
   * after configSecurityManager() and configRMIProperties(). If the reference to the class file
   * server, "classFileServer" is null, it is assumed that the class file server is not runnng.
   *
   * @param classServerPort the port the class file server will use.
   */
  private void startClassFileServer(int classServerPort) {
    if (null != classFileServer) stopClassFileServer();

    String userDir = System.getProperty("user.dir");
    outputCmd.apply("user.dir: " + userDir);
    try {
      classFileServer = new ClassFileServer(classServerPort, System.getProperty("user.dir"));
    } catch (java.io.IOException e) {
      outputCmd.apply("Unable to start ClassServer: " + e.getMessage());
      e.printStackTrace();
    }
  }
  private static Echo[] spawnAndTest() {

    System.err.println("\nCreate Test-->");

    Echo[] echo = new Echo[protocol.length];

    for (int i = 0; i < protocol.length; i++) {

      JavaVM serverVM =
          new JavaVM("EchoImpl", "-Djava.security.policy=" + TestParams.defaultPolicy, protocol[i]);

      System.err.println("\nusing protocol: " + (protocol[i] == "" ? "none" : protocol[i]));

      try {
        /* spawn VM for EchoServer */
        serverVM.start();

        /* lookup server */
        int tries = 12; // need enough tries for slow machine.
        echo[i] = null;
        do {
          try {
            echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT + "/EchoServer");
            break;
          } catch (NotBoundException e) {
            try {
              Thread.sleep(2000);
            } catch (Exception ignore) {
            }
            continue;
          }
        } while (--tries > 0);

        if (echo[i] == null) TestLibrary.bomb("server not bound in 12 tries", null);

        /* invoke remote method and print result*/
        System.err.println("Bound to " + echo[i]);
        byte[] data = ("Greetings, citizen " + System.getProperty("user.name") + "!").getBytes();
        byte[] result = echo[i].echoNot(data);
        for (int j = 0; j < result.length; j++) result[j] = (byte) ~result[j];
        System.err.println("Result: " + new String(result));
        echo[i].shutdown();

      } catch (Exception e) {
        TestLibrary.bomb("test failed", e);

      } finally {
        serverVM.destroy();
        try {
          Naming.unbind("//:" + REGISTRY_PORT + "/EchoServer");
        } catch (Exception e) {
          TestLibrary.bomb("unbinding EchoServer", e);
        }
      }
    }
    return echo;
  }
  private static void reactivateAndTest(Echo[] echo) {

    System.err.println("\nReactivate Test-->");

    for (int i = 0; i < echo.length; i++) {
      try {
        System.err.println("\nusing protocol: " + (protocol[i] == "" ? "none" : protocol[i]));
        byte[] data = ("Greetings, citizen " + System.getProperty("user.name") + "!").getBytes();
        byte[] result = echo[i].echoNot(data);
        for (int j = 0; j < result.length; j++) result[j] = (byte) ~result[j];
        System.err.println("Result: " + new String(result));
        echo[i].shutdown();
      } catch (Exception e) {
        TestLibrary.bomb("activating EchoServer for protocol " + protocol[i], e);
      }
    }
  }
Пример #6
0
/**
 * Sample client for the jboss container.
 *
 * @author <a href="mailto:[email protected]">Marc Fleury</a>
 * @author <a href="mailto:[email protected]">Hugo Pinto</a>
 * @version $Id: BeanUnitTestCase.java 81036 2008-11-14 13:36:39Z [email protected] $
 */
public class BeanUnitTestCase extends JBossTestCase {
  static boolean deployed = false;
  static int test = 0;
  static Date startDate = new Date();

  protected final String namingFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);

  protected final String providerURL = System.getProperty(Context.PROVIDER_URL);

  public BeanUnitTestCase(String name) {
    super(name);
  }

  public void testRealBMP() throws Exception {

    getLog().debug("");
    getLog().debug("Test Real BMP (load/passivation/...");
    getLog().debug("===================================");
    getLog().debug("");

    BMPHelperSessionHome sessionHome =
        (BMPHelperSessionHome) new InitialContext().lookup("bmp.BMPHelperSession");
    BMPHelperSession session = sessionHome.create();

    getLog().debug("looking up table:");
    if (!session.existsSimpleBeanTable()) {
      getLog().debug("table does not exist.");
      getLog().debug("create it...");
      session.createSimpleBeanTable();
      getLog().debug("done.");
    }

    SimpleBMPHome home = (SimpleBMPHome) new InitialContext().lookup("bmp.SimpleBMP");

    getLog().debug(++test + "- " + "create bean1: 1, Daniel");
    SimpleBMP b1 = home.create(1, "Daniel");
    getLog().debug("getName (): " + b1.getName());

    getLog().debug(++test + "- " + "create bean2: 2, Robert");
    b1 = home.create(2, "Robert");
    getLog().debug("getName (): " + b1.getName());

    try {
      getLog().debug(++test + "- trying to create one with same primkey: 1, Patrick");
      b1 = home.create(1, "Patrick");
      fail("Was able to create duplicate SimpleBMP");
    } catch (Exception _e) {
      getLog().debug(_e.toString());
    }

    getLog().debug(++test + "- create some more dummys:");
    for (int i = 0; i < 50; ++i) home.create(i + 3, ("Dummy " + i));

    getLog().debug(++test + "- trying to find Robert again");
    b1 = home.findByPrimaryKey(new Integer(2));
    getLog().debug("getName (): " + b1.getName());

    try {
      getLog().debug(++test + "- trying to find an not existing bean");
      b1 = home.findByPrimaryKey(new Integer(0));
      assertTrue("findByPrimaryKey(0) should fail", b1 == null);
    } catch (Exception _e) {
      getLog().debug(_e.toString());
    }

    getLog().debug(++test + "- rename Daniel to Maria: 1, Daniel");
    b1 = home.findByPrimaryKey(new Integer(1));
    getLog().debug("name old: " + b1.getName());
    b1.setName("Maria");
    assertTrue("getName == Maria", "Maria".equals(b1.getName()));

    getLog().debug(++test + "- find all beans:");
    Iterator it = home.findAll().iterator();
    while (it.hasNext()) {
      getLog().debug("found:" + ((SimpleBMP) it.next()).getName());
    }

    getLog().debug(++test + "- Now trying from within the Session bean (to be able to rollback):");
    getLog().debug(session.doTest());

    getLog().debug(++test + "- get name after rollback ");
    getLog().debug(session.doTestAfterRollback());

    getLog().debug(++test + "- removing all beans");
    it = home.findAll().iterator();
    while (it.hasNext()) ((SimpleBMP) it.next()).remove();

    getLog().debug("drop table...");
    session.dropSimpleBeanTable();
    getLog().debug("done.");
  }

  public void testStatelessBean() throws Exception {

    getLog().debug(++test + "- " + "Trying the context...");

    Context ctx = new InitialContext();
    getLog().debug("OK");

    /// *
    getLog().debug("");
    getLog().debug("Test Stateless Bean");
    getLog().debug("===================");
    getLog().debug("");
    getLog().debug(++test + "- " + "Looking up the home nextgen.StatelessSession...");
    StatelessSessionHome statelessSessionHome =
        (StatelessSessionHome) ctx.lookup("nextgen.StatelessSession");
    if (statelessSessionHome != null) getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling create on StatelessSessionHome...");
    StatelessSession statelessSession = statelessSessionHome.create();
    assertTrue("statelessSessionHome.create() != null", statelessSession != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling getEJBHome() on StatelessSession...");
    assertTrue("statelessSession.getEJBHome() != null", statelessSession.getEJBHome() != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling Business Method A on StatelessSession... ");
    statelessSession.callBusinessMethodA();
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling Business Method B on StatelessSession... ");
    getLog().debug(statelessSession.callBusinessMethodB());
    getLog().debug(++test + "- " + "Calling Business Method B(String) on StatelessSession... ");
    getLog().debug(statelessSession.callBusinessMethodB("of wisdom"));
    getLog().debug(++test + "- " + "Calling Business Method C on StatelessSession... ");
    getLog().debug(statelessSession.callBusinessMethodC());
    getLog().debug(++test + "- " + "Calling Business Method D on StatelessSession... ");
    try {
      statelessSession.callBusinessMethodD();
      fail("callBusinessMethodD, no exception was thrown");
    } catch (BusinessMethodException e) {
      getLog().debug("Caught BusinessMethodException OK");
    }
    getLog()
        .debug(++test + "- " + "Calling Business Method E (getEJBObject) on StatelessSession... ");
    getLog().debug(statelessSession.callBusinessMethodE());

    getLog().debug(++test + "- " + "Calling testClassLoading on StatelessSession... ");
    statelessSession.testClassLoading();
    getLog().debug("OK");

    getLog().debug("***Testing the various local Object class calls");
    getLog().debug(++test + "- " + "toString ... " + statelessSession.toString());

    getLog().debug(++test + "- " + "hashCode ... " + statelessSession.hashCode());

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (same object) ... "
                + statelessSession.equals(statelessSession));

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (another object) (true under same home)... "
                + statelessSession.equals(statelessSessionHome.create()));

    getLog().debug("***Testing the various local EJBObject class calls");

    getLog().debug(++test + "- " + "Get Handle ... ");
    Handle statelessHandle = statelessSession.getHandle();
    assertTrue("statelessHandle != null", statelessHandle != null);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "Serialize handle and deserialize..");
    MarshalledObject mo = new MarshalledObject(statelessHandle);
    Handle handle2 = (Handle) mo.get();
    StatelessSession statelessSession2 = (StatelessSession) handle2.getEJBObject();
    assertTrue("statelessSession2 != null", statelessSession2 != null);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "Calling businessMethodB on it...");
    getLog().debug(statelessSession2.callBusinessMethodB());
    getLog()
        .debug(
            ++test
                + "- "
                + "They should be identical..."
                + statelessSession.isIdentical(statelessSession2));
    getLog().debug("***Testing the various local EJBHome class calls");
    getLog().debug(++test + "- " + "Getting the metaData...");
    EJBMetaData statelessMetaData = statelessSessionHome.getEJBMetaData();
    assertTrue("statelessMetaData != null", statelessMetaData != null);
    getLog().debug("OK");
    getLog()
        .debug(++test + "- " + "Is stateless Session? " + statelessMetaData.isStatelessSession());
    getLog()
        .debug(
            ++test + "- " + "The remote class is " + statelessMetaData.getRemoteInterfaceClass());

    getLog().debug("");
    getLog().debug(++test + "- " + "Calling StatelessSession.remove()...");
    statelessSession.remove();
    getLog().debug("ok");
  }

  public void testStatefulBean() throws Exception {
    Context ctx = new InitialContext();

    getLog().debug("");
    getLog().debug("Test Stateful Bean");
    getLog().debug("==================");
    getLog().debug("");
    getLog().debug(++test + "- " + "Looking up the home nextgen.StatefulSession...");
    StatefulSessionHome statefulSessionHome =
        (StatefulSessionHome) ctx.lookup("nextgen.StatefulSession");
    assertTrue("statefulSessionHome!= null", statefulSessionHome != null);
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling create on StatefulSessionHome with name Marc...");
    StatefulSession statefulSession = statefulSessionHome.create("Marc");
    assertTrue("statefulSession != null", statefulSession != null);
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling getEJBHome() on StatefulSession...");
    assertTrue("statefulSession.getEJBHome() != null", statefulSession.getEJBHome() != null);
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling Business Method A on StatefulSession... ");
    getLog().debug(statefulSession.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling Business Method A (state) on StatefulSession... ");
    getLog().debug(statefulSession.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling Business Method B (EJBObject) on StatefulSession... ");
    getLog().debug(statefulSession.callBusinessMethodB());

    getLog().debug(++test + "- " + "Calling Business Method B(String) on StatefulSession... ");
    getLog().debug(statefulSession.callBusinessMethodB("of wisdom"));

    getLog().debug("***Testing the various local Object class calls");
    getLog().debug(++test + "- " + "toString ... ");
    getLog().debug(statefulSession.toString());
    getLog().debug(++test + "- " + "hashCode ... " + statefulSession.hashCode());

    getLog()
        .debug(
            ++test + "- " + "equals (same object) ... " + statefulSession.equals(statefulSession));

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (another object) (false under same home)... "
                + statefulSession.equals(statefulSessionHome.create("marc4")));

    getLog().debug("***Testing the various local EJBObject class calls");

    getLog().debug(++test + "- " + "Get Handle ... ");
    Handle statefulHandle = statefulSession.getHandle();
    assertTrue("statefulHandle != null", statefulHandle != null);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "Serialize handle and deserialize....");
    MarshalledObject mo2 = new MarshalledObject(statefulHandle);
    Handle statefulHandle2 = (Handle) mo2.get();
    StatefulSession statefulSession2 = (StatefulSession) statefulHandle2.getEJBObject();
    assertTrue("statefulSession2 != null", statefulSession2 != null);
    getLog().debug("OK");
    getLog()
        .debug(
            ++test
                + "- "
                + "Calling businessMethodB on it..."
                + statefulSession2.callBusinessMethodB());

    getLog()
        .debug(
            ++test
                + "- "
                + "They should be identical..."
                + statefulSession.isIdentical(statefulSession2));

    getLog().debug(++test + "- " + "Calling StatefulSession.remove()...");
    statefulSession.remove();
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling StatefulHome.remove(Handle) (this should fail)...");
    try {
      statefulSessionHome.remove(statefulSession2.getHandle());
      fail("statefulSessionHome.remove did not fail");
    } catch (Exception e) {
      getLog().debug("not found OK");
    }
    getLog().debug(++test + "- " + "Creating a 3rd bean and calling it...");
    StatefulSession ss3 = statefulSessionHome.create("marc3");
    getLog().debug(ss3.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling StatefulSession.remove(Handle) on a third bean...");
    Handle statefulHandle3 = ss3.getHandle();
    statefulSessionHome.remove(statefulHandle3);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "I should not be able to remove it directly...");
    try {
      ss3.remove();
      fail("ss3.remove() did not fail");
    } catch (Exception e) {
      getLog().debug("OK");
    }

    getLog().debug(++test + "- " + "Creating a 4th bean using create<METHOD> and calling it...");
    StatefulSession ss4 = statefulSessionHome.createMETHOD("marc4", "address");
    getLog().debug(ss4.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling StatefulSession.remove(Handle) on a fourth bean...");
    Handle statefulHandle4 = ss4.getHandle();
    statefulSessionHome.remove(statefulHandle4);
  }

  public void testEntityBeanCMP() throws Exception {
    Context ctx = new InitialContext();

    getLog().debug("testEntityBeanCMP");
    getLog().debug(++test + "- " + "Looking up the home nextgen.EnterpriseEntity...ok");

    EnterpriseEntityHome enterpriseEntityHome =
        (EnterpriseEntityHome) ctx.lookup("nextgen.EnterpriseEntity");
    getLog().debug(++test + "- " + "Calling find on EnterpriseEntityHome with name Marc...");
    EnterpriseEntity enterpriseEntity = null;
    try {
      enterpriseEntity = enterpriseEntityHome.findByPrimaryKey("Marc");
    } catch (Exception e) {
      getLog().debug("findByPrimaryKey(Marc) failed", e);
    }
    if (enterpriseEntity == null) {
      getLog().debug("not found OK");
      getLog().debug(++test + "- " + "Calling create on EnterpriseEntityHome with name Marc...");
      enterpriseEntity = enterpriseEntityHome.create("Marc");
    }

    if (enterpriseEntity != null)
      getLog()
          .debug(
              "ok, enterpriseEntity"
                  + enterpriseEntity
                  + ", hashCode="
                  + enterpriseEntity.hashCode());

    getLog().debug(++test + "- " + "Calling for duplicate create and DuplicateKeyException...");
    try {
      Object e = enterpriseEntityHome.create("Marc");
      getLog().debug("I Really should not make it here, e=" + e + ", hashCode=" + e.hashCode());
      throw new Exception("DuplicateKey not seen");
    } catch (DuplicateKeyException dke) {
      getLog().debug("DuplicateKeyException ok");
    }

    getLog().debug(++test + "- " + "Calling getEJBHome() on EntityCMP...");
    assertTrue("enterpriseEntity.getEJBHome() != null", enterpriseEntity.getEJBHome() != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Getting a new reference with findByPK...");
    EnterpriseEntity enterpriseEntity2 = null;
    try {
      enterpriseEntity2 = enterpriseEntityHome.findByPrimaryKey("Marc");
    } catch (Exception re) {
      getLog().debug("Exception: ", re);
    }
    assertTrue("enterpriseEntity2 != null", enterpriseEntity2 != null);
    getLog().debug("ok");
    getLog().debug(++test + "- " + "Calling Business Method A on enterpriseEntity... ");
    getLog().debug(enterpriseEntity.callBusinessMethodA());

    getLog()
        .debug(
            ++test
                + "- "
                + "Calling Business Method A (again to ejbLoad if TypeC) on enterpriseEntity... ");
    getLog().debug(enterpriseEntity.callBusinessMethodA());

    getLog()
        .debug(
            ++test
                + "- "
                + "Calling Business Method B (EJBObject from entity) on enterpriseEntity...");
    getLog().debug(enterpriseEntity.callBusinessMethodB());

    getLog().debug(++test + "- " + "Calling Business Method B(String) on EnterpriseEntity... ");
    getLog().debug(enterpriseEntity.callBusinessMethodB("of wisdom"));

    getLog().debug(++test + "- " + "Calling getOtherField (non pk) on enterpriseEntity...");
    getLog().debug("value: " + enterpriseEntity.getOtherField());

    getLog().debug(++test + "- " + "Calling setOtherField(4) on enterpriseEntity...");
    enterpriseEntity.setOtherField(4);
    getLog().debug("OK");

    getLog().debug(++test + "- " + "Calling getOtherField() on enterpriseEntity (should be 4)...");
    int value = enterpriseEntity.getOtherField();
    assertTrue("enterpriseEntity.getOtherField() == 4", value == 4);
    getLog().debug("value is " + value + ", OK");

    getLog().debug("***Testing the various local Object class calls");
    getLog().debug(++test + "- " + "toString ... " + enterpriseEntity);

    getLog().debug(++test + "- " + "hashCode ... " + enterpriseEntity.hashCode());

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (same object) ... "
                + enterpriseEntity.equals(enterpriseEntity));

    getLog()
        .debug(
            ++test
                + "- "
                + "equals (another object) (true for this case)... "
                + enterpriseEntity.equals(enterpriseEntity2));

    getLog().debug("***Testing the various local EJBObject class calls");
    getLog().debug(++test + "- " + "Get Primary Key ... " + enterpriseEntity.getPrimaryKey());

    getLog().debug(++test + "- " + "Get Handle ... ");
    Handle entityHandle = enterpriseEntity.getHandle();
    assertTrue("entityHandle != null", entityHandle != null);
    getLog().debug("OK");
    getLog().debug(++test + "- " + "Serialize handle and deserialize....");
    MarshalledObject mo3 = new MarshalledObject(entityHandle);
    Handle entityHandle3 = (Handle) mo3.get();
    EnterpriseEntity enterpriseEntity3 = (EnterpriseEntity) entityHandle3.getEJBObject();
    if (enterpriseEntity3 != null) getLog().debug("OK");
    getLog().debug(++test + "- " + "Calling businessMethodA on it...");
    getLog().debug(enterpriseEntity3.callBusinessMethodB());
    getLog()
        .debug(
            ++test
                + "- "
                + "They should be identical..."
                + enterpriseEntity.isIdentical(enterpriseEntity3));
    getLog().debug(++test + "- " + "Calling entityHome.remove(Handle)...");
    enterpriseEntityHome.remove(enterpriseEntity3.getHandle());
    getLog().debug("OK");

    getLog().debug(++test + "- " + "Calling enterpriseEntity.remove() (should fail)...");
    try {
      enterpriseEntity.remove();
      fail("enterpriseEntity.remove() did not fail");
    } catch (Exception e) {
      getLog().debug("OK");
    }

    getLog().debug(++test + "- " + "Calling EnterpriseEntity.create() for marc6...");
    EnterpriseEntity marc6 = enterpriseEntityHome.create("marc6");
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling method createEntity on enterpriseEntity... ");
    EnterpriseEntity marc2 = marc6.createEntity("marc2");
    getLog().debug("OK");

    getLog().debug(++test + "- " + "removing by PK on home (marc2)...");
    enterpriseEntityHome.remove(marc2.getPrimaryKey());
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling enterpriseEntity.remove()  (marc6)...");
    marc6.remove();
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling EnterpriseEntity.create<METHOD>() for marc7...");
    EnterpriseEntity marc7 = enterpriseEntityHome.createMETHOD("marc7");
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling enterpriseEntity.remove()  (marc7)...");
    marc7.remove();
    getLog().debug("ok");

    getLog().debug("");
    getLog().debug("");
    getLog().debug("");
  }

  public void testEntityBeanBMP() throws Exception {
    Context ctx = new InitialContext();

    getLog().debug("");
    getLog().debug("");
    getLog().debug("Test Entity Bean BMP");
    getLog().debug("====================");
    getLog().debug("");

    getLog().debug(++test + "- " + "Looking up home for nextgen.EntityBMP...");
    EntityBMPHome bmpHome = (EntityBMPHome) ctx.lookup("nextgen.EntityBMP");
    assertTrue("bmpHome != null", bmpHome != null);
    getLog().debug("ok");

    // the current test will always return

    getLog().debug(++test + "- " + "Calling create on the home...");
    EntityBMP bmpBean = bmpHome.create("Marc");
    assertTrue("bmpBean != null", bmpBean != null);
    getLog().debug("ok");

    // Let's call a business method to see the flow of server calls

    getLog().debug(++test + "- " + "Calling getEJBHome() on EntityBMP...");
    assertTrue("bmpBean.getEJBHome() != null", bmpBean.getEJBHome() != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling business methodA on BMP bean...");
    getLog().debug(bmpBean.callBusinessMethodA());
    getLog().debug(++test + "- " + "Calling business methodB (B2B) on BMP bean and it says ");
    getLog().debug(bmpBean.callBusinessMethodB());

    getLog().debug(++test + "- " + "Calling Business Method B(String) on BMP... ");
    getLog().debug(bmpBean.callBusinessMethodB("of wisdom"));

    getLog().debug(++test + "- " + "calling remove() on BMP...");
    bmpBean.remove();

    getLog().debug(++test + "- " + "calling findCollectionKeys....");
    Collection pks = bmpHome.findCollectionKeys(3);
    Iterator pkIterator = pks.iterator();
    while (pkIterator.hasNext()) {
      EntityBMP currentBean = (EntityBMP) pkIterator.next();
      getLog().debug((String) currentBean.getPrimaryKey());
    }
    getLog().debug("ok");

    getLog().debug(++test + "- " + "calling findEnumeratedKeys....");
    Enumeration pksEnumeration = bmpHome.findEnumeratedKeys(3);
    while (pksEnumeration.hasMoreElements()) {
      EntityBMP currentBean = (EntityBMP) pksEnumeration.nextElement();
      getLog().debug((String) currentBean.getPrimaryKey());
    }
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling create<METHOD> on the home...");
    bmpBean = bmpHome.createMETHOD("Marc2");
    assertTrue("bmpBean != null", bmpBean != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "calling remove() on BMP...");
    bmpBean.remove();
  }

  public void testEntityBeanPK() throws Exception {
    Context ctx = new InitialContext();

    getLog().debug("");
    getLog().debug("");
    getLog().debug("Test Entity Bean PK");
    getLog().debug("====================");
    getLog().debug("");

    getLog().debug(++test + "- " + "Looking up home for nextgen.EntityPK...");
    EntityPKHome pkHome = (EntityPKHome) ctx.lookup("nextgen.EntityPK");
    assertTrue("pkHome != null", pkHome != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling find on the home...");
    EntityPK pkBean = null;

    // Let's try to find the instance
    try {

      pkBean = pkHome.findByPrimaryKey(new AComplexPK(true, 10, 100, 1000.0, "Marc"));
    } catch (Exception e) {

      getLog().debug("not found");
      getLog().debug(++test + "- " + "Did not find the instance will create it...");
      pkBean = pkHome.create(true, 10, 100, 1000.0, "Marc");
    }

    assertTrue("pkBean != null", pkBean != null);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Retrieving other field...");
    assertTrue("pkBean.getOtherField() == 0", pkBean.getOtherField() == 0);
    getLog().debug(++test + "- " + "Setting it to 4...");
    pkBean.setOtherField(4);
    getLog().debug("ok");

    getLog().debug(++test + "- " + "Findind it again ... ");

    // Now we should be able to find it
    pkBean = pkHome.findByPrimaryKey(new AComplexPK(true, 10, 100, 1000.0, "Marc"));

    assertTrue("pkBean != null", pkBean != null);
    getLog().debug("ok");

    // check if the other field has been saved
    getLog().debug(++test + "- " + "Retrieving other field again, should be 4...");
    int newValue = pkBean.getOtherField();
    assertTrue("pkBean.getOtherField() == 4", newValue == 4);
    getLog().debug("4, ok");

    // Get a new EJBObject for this guy
    // Now we should be able to find it
    getLog().debug(++test + "- gettting a new reference ... ");
    EntityPK pkBean2 = pkHome.findByPrimaryKey(new AComplexPK(true, 10, 100, 1000.0, "Marc"));
    assertTrue("findByPrimaryKey AComplexPK", pkBean2 != null);
    getLog().debug("ok");
    getLog().debug(++test + "- Retrieving other field again, should be 4...");
    int newValue2 = pkBean2.getOtherField();
    assertTrue("Retrieving other field again, should be 4...", newValue2 == 4);

    // Now remove it
    getLog().debug(++test + "- " + "Removing the bean...");
    pkBean.remove();
    try {
      getLog().debug(++test + "- " + "I should not find it...");
      pkBean = pkHome.findByPrimaryKey(new AComplexPK(true, 10, 100, 1000.0, "Marc"));
      assertTrue("findByPrimaryKey should fail", pkBean == null);
    } catch (Exception e) {
      getLog().debug("not found, OK");
    }

    getLog().debug(++test + "- " + "Call create<METHOD> on EntityPKHome...");
    pkBean = pkHome.createMETHOD(true, 10, 100, 1000.0, "Marc");
    getLog().debug(++test + "- " + "Removing the bean...");
    pkBean.remove();
  }

  public void testTxSession() throws Exception {
    Context ctx = new InitialContext();

    getLog().debug("");
    getLog().debug("");
    getLog().debug("Test TxSession");
    getLog().debug("==============");
    getLog().debug("");

    getLog().debug(++test + "- " + "Looking up home for nextgen.TxSession...");
    TxSessionHome txHome = (TxSessionHome) ctx.lookup("nextgen.TxSession");
    if (txHome != null) getLog().debug("ok");

    getLog().debug(++test + "- " + "Calling create on the home...");
    TxSession txBean = null;

    // Let's try to create the instance
    try {

      txBean = txHome.create();
    } catch (Exception e) {

      getLog().debug("Exception: ", e);
    }

    if (txBean != null) getLog().debug("ok");

    getLog().debug(++test + "- " + "calling supports... ");
    getLog().debug(txBean.txSupports());

    getLog().debug(++test + "- " + "calling required... ");
    getLog().debug(txBean.txRequired());

    getLog().debug(++test + "- " + "calling requiresNew... ");
    getLog().debug(txBean.txRequiresNew());

    getLog().debug(++test + "- " + "calling not supported... ");
    getLog().debug(txBean.txNotSupported());

    getLog().debug(++test + "- " + "calling mandatory (should get an exception)...");
    try {
      getLog().debug(txBean.txMandatory());
    } catch (Exception e) {
      getLog().debug("got Exception, ok");
    }

    getLog().debug(++test + "- " + "calling requiredToSupports... ");
    getLog().debug(txBean.requiredToSupports());

    getLog().debug(++test + "- " + "calling requiredToNotSupported... ");
    getLog().debug(txBean.requiredToNotSupported());

    getLog().debug(++test + "- " + "calling requiredToRequiresNew... ");
    getLog().debug(txBean.requiredToRequiresNew());

    getLog().debug("ok");
  }

  public void testAllTypesBean() throws Exception {

    try {
      Context ctx = new InitialContext();

      getLog().debug("");
      getLog().debug("");
      getLog().debug("Test AllTypesBean");
      getLog().debug("=================");
      getLog().debug("");
      getLog().debug(++test + "- " + "Looking up the home AllTypes...");
      AllTypesHome allTypesHome = (AllTypesHome) ctx.lookup("AllTypes");
      if (allTypesHome != null) getLog().debug("ok");

      getLog().debug(++test + "- " + "Getting the home handle...");
      HomeHandle homeHandle = allTypesHome.getHomeHandle();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "Getting the home back from the handle...");
      EJBHome aHome = homeHandle.getEJBHome();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "Getting metadata from home...");
      EJBMetaData aMetaData = aHome.getEJBMetaData();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "Getting home from metadata...");
      aHome = aMetaData.getEJBHome();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "Calling findByPrimaryKey on AllTypesHome with name seb...");

      AllTypes allTypes = null;
      try {
        allTypes = allTypesHome.findByPrimaryKey("seb");
      } catch (Exception e) {
        getLog().debug(e.getMessage());
      }
      if (allTypes == null) {

        getLog().debug("not found OK");
        getLog().debug(++test + "- " + "Calling create on AllTypesHome with name seb...");
        allTypes = allTypesHome.create("seb");
      }

      if (allTypes != null) getLog().debug("ok");

      getLog()
          .debug(
              ++test
                  + "- "
                  + "Calling business method A an AllTypes (B2B with external ejb-ref)...");
      getLog().debug("OK, result is" + allTypes.callBusinessMethodA());

      getLog().debug("Getting all the fields");
      getLog().debug(++test + "- " + "boolean " + allTypes.getBoolean() + " Ok");
      getLog().debug(++test + "- " + "byte " + allTypes.getByte() + " Ok");
      getLog().debug(++test + "- " + "short " + allTypes.getShort() + " Ok");
      getLog().debug(++test + "- " + "int " + allTypes.getInt() + " Ok");
      getLog().debug(++test + "- " + "long " + allTypes.getLong() + " Ok");
      getLog().debug(++test + "- " + "float " + allTypes.getFloat() + " Ok");
      getLog().debug(++test + "- " + "double " + allTypes.getDouble() + " Ok");
      getLog().debug("No char test yet, bug in jdk");
      getLog().debug(++test + "- " + "String " + allTypes.getString() + " Ok");
      getLog().debug(++test + "- " + "Date " + allTypes.getDate() + " Ok");
      getLog().debug(++test + "- " + "Timestamp " + allTypes.getTimestamp() + " Ok");

      getLog().debug(++test + "- " + "MyObject ");
      MyObject obj = allTypes.getObject();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting handle of stateful...");
      Handle sfHandle = allTypes.getStateful();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting the bean back from the handle...");
      StatefulSession sfBean = (StatefulSession) sfHandle.getEJBObject();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "comparing serialized handles...");
      assertTrue(
          Arrays.equals(
              new MarshalledValue(sfHandle).toByteArray(),
              new MarshalledValue(sfBean.getHandle()).toByteArray()));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "calling business method A on stateful: ");
      getLog().debug("OK, result is " + sfBean.callBusinessMethodA());

      getLog().debug(++test + "- " + "adding the stateful bean as an object in AllTypes..");
      allTypes.addObjectToList(sfBean);
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting handle of stateless...");
      Handle slHandle = allTypes.getStateless();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting the bean back from the handle...");
      StatelessSession slBean = (StatelessSession) slHandle.getEJBObject();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "comparing serialized handles...");
      assertTrue(
          Arrays.equals(
              new MarshalledValue(slHandle).toByteArray(),
              new MarshalledValue(slBean.getHandle()).toByteArray()));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "calling business method B on stateless: ");
      getLog().debug("OK, result is " + slBean.callBusinessMethodB());

      getLog().debug(++test + "- " + "adding the stateless bean as an object in AllTypes..");
      allTypes.addObjectToList(slBean);
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting handle of entity...");
      Handle eeHandle = allTypes.getEntity();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "getting the bean back from the handle...");
      EnterpriseEntity eeBean = (EnterpriseEntity) eeHandle.getEJBObject();
      getLog().debug("OK");

      getLog().debug(++test + "- " + "comparing serialized handles...");
      assertTrue(
          Arrays.equals(
              new MarshalledValue(eeHandle).toByteArray(),
              new MarshalledValue(eeBean.getHandle()).toByteArray()));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "calling business method A on stateless: ");
      getLog().debug("OK, result is" + eeBean.callBusinessMethodA());

      getLog().debug(++test + "- " + "adding the entity bean as an object in AllTypes..");
      allTypes.addObjectToList(eeBean);
      getLog().debug("OK");

      getLog()
          .debug(
              ++test + "- " + "Getting the list of objects back (should contain the 3 beans)...");
      Collection coll = allTypes.getObjectList();
      assertEquals(coll.size(), 3);
      getLog().debug("OK");
      getLog().debug(++test + "- " + "stateful bean ");
      assertTrue(coll.contains(sfBean));
      getLog().debug("OK");
      getLog().debug(++test + "- " + "stateless bean ");
      assertTrue(coll.contains(slBean));
      getLog().debug("OK");
      getLog().debug(++test + "- " + "entity bean ");
      assertTrue(coll.contains(eeBean));
      getLog().debug("OK");

      getLog().debug("Testing automatically generated finders");

      getLog().debug(++test + "- " + "findAll()..");
      coll = allTypesHome.findAll();
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByPrimaryKey()...");
      AllTypes result = allTypesHome.findByPrimaryKey("seb");
      assertTrue(result.equals(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByABoolean()..");
      coll = allTypesHome.findByABoolean(allTypes.getBoolean());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAByte()..");
      coll = allTypesHome.findByAByte(allTypes.getByte());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAShort()..");
      coll = allTypesHome.findByAShort(allTypes.getShort());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAnInt()..");
      coll = allTypesHome.findByAnInt(allTypes.getInt());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByALong()..");
      coll = allTypesHome.findByALong(allTypes.getLong());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAFloat()..");
      coll = allTypesHome.findByAFloat(allTypes.getFloat());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByADouble()..");
      coll = allTypesHome.findByADouble(allTypes.getDouble());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug("No Char test yet, bug in jdk");

      getLog().debug(++test + "- " + "findByAString()..");
      coll = allTypesHome.findByAString(allTypes.getString());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByADate()..");
      coll = allTypesHome.findByADate(allTypes.getDate());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByATimestamp()..");
      coll = allTypesHome.findByATimestamp(allTypes.getTimestamp());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByAnObject()..");
      coll = allTypesHome.findByAnObject(allTypes.getObject());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByStatefulSession()..");
      coll =
          allTypesHome.findByStatefulSession(
              (StatefulSession) allTypes.getStateful().getEJBObject());
      getLog().debug("size=" + coll.size());
      for (Iterator i = coll.iterator(); i.hasNext(); ) {
        Object o = i.next();
        getLog().debug("o=" + o);
      }
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByStatelessSession()..");
      coll =
          allTypesHome.findByStatelessSession(
              (StatelessSession) allTypes.getStateless().getEJBObject());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByEnterpriseEntity()..");
      coll =
          allTypesHome.findByEnterpriseEntity(
              (EnterpriseEntity) allTypes.getEntity().getEJBObject());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug("Testing finders defined in jaws.xml");

      getLog().debug(++test + "- " + "findByMinInt()..");
      coll = allTypesHome.findByMinInt(0);
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

      getLog().debug(++test + "- " + "findByIntAndDouble()..");
      coll = allTypesHome.findByIntAndDouble(allTypes.getInt(), allTypes.getDouble());
      assertTrue(coll.contains(allTypes));
      getLog().debug("OK");

    } catch (Exception e) {
      getLog().debug("Exception: ", e);
      throw e;
    }
  }

  public void testBeanManagedTransactionDemarcation() throws Exception {
    Context ctx = new InitialContext();
    try {
      getLog().debug("");
      getLog().debug("");
      getLog().debug("Test Bean Managed Transaction Demarcation");
      getLog().debug("=========================================");
      getLog().debug("");
      ;

      getLog().debug(++test + "- " + "Looking up the home BMTStateful...");
      BMTStatefulHome bmtSFHome = (BMTStatefulHome) ctx.lookup("BMTStateful");

      if (bmtSFHome != null) getLog().debug("ok");

      getLog().debug(++test + "- " + "Calling create on BMTStatefulHome...");

      BMTStateful bmtSF = bmtSFHome.create();

      getLog().debug(++test + "- " + "Calling create(anything) on BMTStatefulHome...");

      bmtSFHome.create("coca");
      getLog().debug("OK");
      getLog().debug(++test + "- " + "Can the bean access its UserTransaction");
      getLog().debug(bmtSF.txExists());
      getLog().debug(++test + "- " + "Testing commit on UserTransaction");
      getLog().debug(bmtSF.txCommit());
      getLog().debug(++test + "- " + "Testing rollback on UserTransaction");
      getLog().debug(bmtSF.txRollback());
      getLog().debug(++test + "- " + "Beginning a transaction...");
      getLog().debug(bmtSF.txBegin());
      getLog().debug(++test + "- " + "Committing the transaction in another call...");
      getLog().debug(bmtSF.txEnd());
      getLog().debug(++test + "- " + "Creating a table for real db w/ tx test...");
      bmtSF.createTable();
      getLog().debug("OK, field value is:");
      getLog().debug(bmtSF.getDbField());
      getLog().debug(++test + "- " + "Updating the field in a transaction, commit...");
      bmtSF.dbCommit();
      getLog().debug("OK, field value is:");
      getLog().debug(bmtSF.getDbField());
      getLog().debug(++test + "- " + "Updating the field in a transaction, rollback...");
      bmtSF.dbRollback();
      getLog().debug("OK, field value is:");
      getLog().debug(bmtSF.getDbField());
      getLog().debug(++test + "- " + "Now dropping the table...");
      bmtSF.dropTable();
      getLog().debug("OK");
      getLog().debug(++test + "- " + "Looking up the home BMTStateful...");
      BMTStatelessHome bmtSLHome = (BMTStatelessHome) ctx.lookup("BMTStateless");
      if (bmtSLHome != null) getLog().debug("ok");
      getLog().debug(++test + "- " + "Calling create on BMTStatelessHome...");
      BMTStateless bmtSL = bmtSLHome.create();
      getLog().debug("OK");
      getLog().debug(++test + "- " + "Can the bean access its UserTransaction");
      getLog().debug(bmtSL.txExists());
      getLog().debug(++test + "- " + "Testing commit on UserTransaction");
      getLog().debug(bmtSL.txCommit());
      getLog().debug(++test + "- " + "Testing rollback on UserTransaction");
      getLog().debug(bmtSL.txRollback());
      getLog()
          .debug(
              ++test + "- " + "Beginning a transaction (container should throw an exception)...");
      try {
        getLog().debug(bmtSL.txBegin());
        fail("bmtSL.txBegin() did not fail");
      } catch (RemoteException e) {
        getLog().debug(" ... OK, exception message: " + e.getMessage());
      }

      // */
      getLog().debug("");
      getLog().debug("");
      getLog().debug("");
      getLog().debug("Test OK, " + test + " tests run, congratulations");

      Date finishDate = new Date();
      getLog()
          .debug("Tests took " + (finishDate.getTime() - startDate.getTime()) + " milliseconds");
    } catch (Exception e) {

      getLog().debug("exception: ", e);
      throw e;
    }
  }

  public static Test suite() throws Exception {
    Test t1 = getDeploySetup(BeanUnitTestCase.class, "bmp.jar");
    Test t2 = getDeploySetup(t1, "testbean.jar");
    Test t3 = getDeploySetup(t2, "testbean2.jar");
    return t3;
  }
}
  public static void main(String args[])
      throws RemoteException, InvalidTransactionException, TransactionAbortedException {
    System.setSecurityManager(new RMISecurityManager());

    String rmiPort = System.getProperty("rmiPort");
    if (rmiPort == null) {
      rmiPort = "";
    } else if (!rmiPort.equals("")) {
      rmiPort = "//:" + rmiPort + "/";
    }

    try {
      TransactionManagerImpl obj = new TransactionManagerImpl();
      Naming.rebind(rmiPort + TransactionManager.RMIName, obj);
      System.out.println("TM bound");
    } catch (Exception e) {
      System.err.println("TM not bound:" + e);
      System.exit(1);
    }

    enlistList = new HashMap<Integer, Set<ResourceManager>>();
    File f = new File(enlistFile);
    if (f.exists()) {
      try {
        ObjectInputStream fin = new ObjectInputStream(new FileInputStream(f));
        enlistList = (HashMap<Integer, Set<ResourceManager>>) fin.readObject();
        fin.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    protocolDB = new HashMap<Integer, Map<String, TwoPC_ST>>();
    File f2 = new File(protocolDBFile);
    if (f2.exists()) {
      try {
        ObjectInputStream fin2 = new ObjectInputStream(new FileInputStream(f2));
        protocolDB = (HashMap<Integer, Map<String, TwoPC_ST>>) fin2.readObject();
        fin2.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
      // recovery
      for (Integer i : protocolDB.keySet()) {
        if (i > xidCounter) {
          xidCounter = i + 1;
        }
        Map<String, TwoPC_ST> lastST = protocolDB.get(i);
        boolean re1 = true;
        for (TwoPC_ST st : lastST.values()) re1 &= (st == TwoPC_ST.Committed);
        if (re1) {
          protocolDB.remove(i);
          enlistList.remove(i);
          continue;
        }

        System.out.println("TM recovery xid: " + i + " from half commit.");
        Set<ResourceManager> commitSet = enlistList.get(i);
        boolean re2 = true;
        Set<ResourceManager> commitSet2 = new HashSet<ResourceManager>();
        for (ResourceManager r : commitSet) {
          if (r.getStatus(i) == TwoPC_ST.Prepared) {
            System.out.println("TM recovery " + i + " in " + r.getMyRMIName());
            commitSet2.add(r);
          } else if (r.getStatus(i) == TwoPC_ST.Committed) ;
          else re2 = false;
        }
        System.out.println("here 1");
        if (re2) {
          for (ResourceManager r : commitSet2) {
            r.commit(i);
          }
          protocolDB.remove(i);
          enlistList.remove(i);
        }
      }
    }
  }
Пример #8
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;
  }
Пример #9
0
public class NotActivatableServerImpl extends UnicastRemoteObject
    implements NotActivatableInterface {

  private static final String PROG_NAME = "NotActivatableServerImpl";
  private static final String SERVER_OBJECT = "NotActivatableServer";
  private static final String CLASS_NAME = "activation.NotActivatableServerImpl";

  private static final String POLICY_FILE = "policy_file";

  private static final String USER_DIR = System.getProperty("user.dir").replace('\\', '/');

  private static final String CODE_LOCATION = "file:" + USER_DIR + "/";

  private static final MarshalledObject DATA = null;
  private static ActivationDesc ACTIVATION_DESC = null;

  public NotActivatableServerImpl() throws RemoteException {}

  public void ping() throws RemoteException {}

  public void exit() throws RemoteException {
    System.exit(0);
  }

  private static void setup() {

    try {

      NotActivatableInterface rsi; // Remote server interface

      System.setSecurityManager(new RMISecurityManager());

      rsi = (NotActivatableInterface) Activatable.register(ACTIVATION_DESC);
      System.out.println("Got stub for " + SERVER_OBJECT + " implementation");

      Naming.rebind(SERVER_OBJECT, rsi);
      System.out.println("Exported " + SERVER_OBJECT + " implementation");

    } catch (Exception e) {
      System.err.println("Exception: " + e);
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {

    try {
      Properties props = new Properties();
      props.setProperty("java.security.policy", POLICY_FILE);

      ActivationGroupDesc agd = new ActivationGroupDesc(props, null);

      ActivationGroupID agid = ActivationGroup.getSystem().registerGroup(agd);

      ACTIVATION_DESC = new ActivationDesc(agid, CLASS_NAME, CODE_LOCATION, DATA, false);
    } catch (Exception e) {
      System.err.println("Exception: " + e);
      e.printStackTrace();
    }

    setup();
  }
}