[jboss-cvs] JBossAS SVN: r73663 - in projects/ejb3/trunk/common/src: main/java/org/jboss/ejb3/common/registrar/spi and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun May 25 00:25:50 EDT 2008


Author: ALRubinger
Date: 2008-05-25 00:25:50 -0400 (Sun, 25 May 2008)
New Revision: 73663

Modified:
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3RegistrarTestCaseBase.java
Log:
[EJBTHREE-1379] Enhance EJB3 Registrar to allow invocation over the Object Store

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java	2008-05-24 23:16:02 UTC (rev 73662)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java	2008-05-25 04:25:50 UTC (rev 73663)
@@ -60,7 +60,7 @@
    // Constructor --------------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
 
-   public Ejb3McRegistrar(Kernel kernel)
+   public Ejb3McRegistrar(final Kernel kernel)
    {
       this.setKernel(kernel);
    }
@@ -78,7 +78,7 @@
     * @throws NotBoundException
     * @return
     */
-   public Object lookup(Object name) throws NotBoundException
+   public Object lookup(final Object name) throws NotBoundException
    {
       // Get Controller Context
       ControllerContext context = this.getKernel().getController().getInstalledContext(name);
@@ -110,7 +110,7 @@
     * @param value
     * @throws DuplicateBindException
     */
-   public void bind(Object name, Object value) throws DuplicateBindException
+   public void bind(final Object name, final Object value) throws DuplicateBindException
    {
       // Ensure there's nothing already at this location
       Object existing = null;
@@ -138,7 +138,7 @@
     * @param name
     * @param value
     */
-   public void rebind(Object name, Object value)
+   public void rebind(final Object name, final Object value)
    {
       // Initialize
       boolean alreadyBound = true;
@@ -182,7 +182,7 @@
     * @param name
     * @throws NotBoundException
     */
-   public void unbind(Object name) throws NotBoundException
+   public void unbind(final Object name) throws NotBoundException
    {
       // Ensure there is an object bound at this location
       try
@@ -210,6 +210,43 @@
       return this.getKernel();
    }
 
+   /**
+    * Invokes the specified method name on the object bound at the specified name, 
+    * returning the result
+    * 
+    * @param name
+    * @param methodName
+    * @param arguments Arguments to pass to the method
+    * @param signature String representation of fully-qualified class names of parameter types
+    * @return
+    * @throws NotBoundException If no object is bound at the specified name
+    */
+   public Object invoke(Object name, String methodName, Object[] arguments, String[] signature)
+         throws NotBoundException
+   {
+      // Ensure there is an object bound at this location
+      try
+      {
+         this.lookup(name);
+      }
+      catch (NotBoundException nbe)
+      {
+         throw new NotBoundException("Could not invoke upon object at name \"" + name + "\" as none is currently bound");
+      }
+
+      // Invoke
+      try
+      {
+         return this.getKernel().getBus().invoke(name, methodName, arguments, signature);
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Error occured in invoking method \"" + methodName
+               + "\" upon object bound at name " + name, t);
+
+      }
+   }
+
    // --------------------------------------------------------------------------------||
    // Internal Helper Methods --------------------------------------------------------||
    // --------------------------------------------------------------------------------||
@@ -217,7 +254,7 @@
    /**
     * Installs the specified value into MC at the specified name
     */
-   private void install(Object name, Object value)
+   private void install(final Object name, final Object value)
    {
       // Construct BMDB
       BeanMetaDataBuilder bmdb = BeanMetaDataBuilder.createBuilder(name.toString(), value.getClass().getName());
@@ -243,7 +280,7 @@
       return kernel;
    }
 
-   private void setKernel(Kernel kernel)
+   private void setKernel(final Kernel kernel)
    {
       this.kernel = kernel;
    }

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java	2008-05-24 23:16:02 UTC (rev 73662)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java	2008-05-25 04:25:50 UTC (rev 73663)
@@ -74,6 +74,19 @@
    void unbind(Object name) throws NotBoundException;
 
    /**
+    * Invokes the specified method name on the object bound at the specified name,
+    * returning the result
+    * 
+    * @param name
+    * @param methodName
+    * @param arguments Arguments to pass to the method
+    * @param signature String representation of fully-qualified class names of parameter types
+    * @return
+    * @throws NotBoundException If no object is bound at the specified name
+    */
+   Object invoke(Object name, String methodName, Object[] arguments, String[] signature) throws NotBoundException;
+
+   /**
     * Returns a provider implementation-specific class
     * to break contract and invoke upon vendor-specific
     * features.

Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3RegistrarTestCaseBase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3RegistrarTestCaseBase.java	2008-05-24 23:16:02 UTC (rev 73662)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3RegistrarTestCaseBase.java	2008-05-25 04:25:50 UTC (rev 73663)
@@ -131,6 +131,12 @@
 
    }
 
+   /**
+    * Tests that binding to a name already bound results in
+    * a DuplicateBindException
+    * 
+    * @throws Throwable
+    */
    @Test
    public void testRegistrarDuplicateBindFails() throws Throwable
    {
@@ -156,6 +162,12 @@
             + DuplicateBindException.class.getName());
    }
 
+   /**
+    * Tests that looking up an unbound name
+    * results in NotBoundException
+    * 
+    * @throws Throwable
+    */
    @Test
    public void testRegistrarEmptyLookupFails() throws Throwable
    {
@@ -177,7 +189,83 @@
       TestCase.fail("Attempt to lookup an unbound name should result in " + NotBoundException.class.getName());
    }
 
+   /**
+    * Tests that invocation upon a bound object succeeds
+    * 
+    * @throws Throwable
+    */
    @Test
+   public void testInvoke() throws Throwable
+   {
+
+      // Initialize new POJO
+      String bindName = "org.jboss.ejb3.TestBind" + UUID.randomUUID();
+      String oldValue = "oldValue";
+      SimplePojo pojo = new SimplePojo();
+      pojo.setProperty(oldValue);
+
+      // Bind
+      Ejb3RegistrarLocator.locateRegistrar().bind(bindName, pojo);
+
+      // Lookup
+      SimplePojo retrieved = (SimplePojo) Ejb3RegistrarLocator.locateRegistrar().lookup(bindName);
+
+      // Ensure set value is intact
+      TestCase.assertEquals(
+            "Property value set before placing in Registry was not equal to property value obtained from registry",
+            oldValue, retrieved.getProperty());
+
+      // Invoke to change property value
+      String newValue = "newValue";
+      Ejb3RegistrarLocator.locateRegistrar().invoke(bindName, "setProperty", new String[]
+      {newValue}, new String[]
+      {String.class.getName()});
+
+      // Ensure the value has changed
+      TestCase.assertEquals("Invocation did not have affect on retrived instance from Registry", newValue, retrieved
+            .getProperty());
+
+   }
+
+   /**
+    * Tests that invocation upon an unbound object fails
+    * with NotBoundException
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testInvokeOnUnboundNameFails() throws Throwable
+   {
+
+      // Initialize an unused name
+      String bindName = "org.jboss.ejb3.unused";
+
+      // Invoke to change property value
+      String newValue = "newValue";
+      try
+      {
+         Ejb3RegistrarLocator.locateRegistrar().invoke(bindName, "setProperty", new String[]
+         {newValue}, new String[]
+         {String.class.getName()});
+      }
+      // Expected
+      catch (NotBoundException nbe)
+      {
+         return;
+      }
+
+      // Should not be reached
+      TestCase.fail("Invocation on unbound name in registry should fail with " + NotBoundException.class.getName());
+
+   }
+
+   /**
+    * Tests that the Registrar implementation cannot 
+    * be re-set after it's initially bound
+    * 
+    * @throws Throwable
+    */
+   @Test
    public void testRegistrarImmutableAfterBound() throws Throwable
    {
       try




More information about the jboss-cvs-commits mailing list