Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.3-prepare 029dd395f -> ba185f5e4


Overrides & format


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a9ca7de3
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a9ca7de3
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a9ca7de3

Branch: refs/heads/tomee-1.7.3-prepare
Commit: a9ca7de3316983811c6797e32c9739d5870a2729
Parents: cac067d
Author: AndyGee <[email protected]>
Authored: Fri Nov 20 10:41:58 2015 +0100
Committer: AndyGee <[email protected]>
Committed: Fri Nov 20 10:41:58 2015 +0100

----------------------------------------------------------------------
 ...impleTransactionSynchronizationRegistry.java |   9 +
 ...ansactionSynchronizationRegistryWrapper.java |   7 +
 .../core/transaction/JtaTransactionPolicy.java  |  11 +
 .../superbiz/injection/secure/MovieTest.java    |  26 +-
 .../apache/tomee/RemoteTomEEEJBContainer.java   | 322 +++++++++----------
 5 files changed, 201 insertions(+), 174 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/a9ca7de3/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java
index 541684b..853e4cb 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java
@@ -34,6 +34,7 @@ public class SimpleTransactionSynchronizationRegistry 
implements TransactionSync
         this.transactionManager = transactionManager;
     }
 
+    @Override
     public Transaction getTransactionKey() {
         try {
             return transactionManager.getTransaction();
@@ -42,6 +43,7 @@ public class SimpleTransactionSynchronizationRegistry 
implements TransactionSync
         }
     }
 
+    @Override
     public Object getResource(final Object key) {
         final Transaction transaction = getActiveTransaction();
         final Map<Object, Object> resources = 
transactionResources.get(transaction);
@@ -51,6 +53,7 @@ public class SimpleTransactionSynchronizationRegistry 
implements TransactionSync
         return resources.get(key);
     }
 
+    @Override
     public void putResource(final Object key, final Object value) {
         final Transaction transaction = getActiveTransaction();
 
@@ -69,6 +72,7 @@ public class SimpleTransactionSynchronizationRegistry 
implements TransactionSync
         resources.put(key, value);
     }
 
+    @Override
     public int getTransactionStatus() {
         try {
             return transactionManager.getStatus();
@@ -77,6 +81,7 @@ public class SimpleTransactionSynchronizationRegistry 
implements TransactionSync
         }
     }
 
+    @Override
     public void registerInterposedSynchronization(final Synchronization 
synchronization) {
         if (synchronization == null) {
             throw new NullPointerException("synchronization is null");
@@ -91,6 +96,7 @@ public class SimpleTransactionSynchronizationRegistry 
implements TransactionSync
     }
 
 
+    @Override
     public boolean getRollbackOnly() {
         final Transaction transaction = getActiveTransaction();
         try {
@@ -100,6 +106,7 @@ public class SimpleTransactionSynchronizationRegistry 
implements TransactionSync
         }
     }
 
+    @Override
     public void setRollbackOnly() {
         final Transaction transaction = getActiveTransaction();
         try {
@@ -132,9 +139,11 @@ public class SimpleTransactionSynchronizationRegistry 
implements TransactionSync
             this.transaction = transaction;
         }
 
+        @Override
         public void beforeCompletion() {
         }
 
+        @Override
         public void afterCompletion(final int i) {
             transactionResources.remove(transaction);
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a9ca7de3/container/openejb-core/src/main/java/org/apache/openejb/core/TransactionSynchronizationRegistryWrapper.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/core/TransactionSynchronizationRegistryWrapper.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/core/TransactionSynchronizationRegistryWrapper.java
index c16b56f..ab448b2 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/core/TransactionSynchronizationRegistryWrapper.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/core/TransactionSynchronizationRegistryWrapper.java
@@ -44,30 +44,37 @@ public class TransactionSynchronizationRegistryWrapper 
implements TransactionSyn
         return registry;
     }
 
+    @Override
     public Object getResource(final Object o) {
         return getRegistry().getResource(o);
     }
 
+    @Override
     public boolean getRollbackOnly() {
         return getRegistry().getRollbackOnly();
     }
 
+    @Override
     public Object getTransactionKey() {
         return getRegistry().getTransactionKey();
     }
 
+    @Override
     public int getTransactionStatus() {
         return getRegistry().getTransactionStatus();
     }
 
+    @Override
     public void putResource(final Object o, final Object o1) {
         getRegistry().putResource(o, o1);
     }
 
+    @Override
     public void registerInterposedSynchronization(final Synchronization 
synchronization) {
         getRegistry().registerInterposedSynchronization(synchronization);
     }
 
+    @Override
     public void setRollbackOnly() {
         getRegistry().setRollbackOnly();
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a9ca7de3/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/JtaTransactionPolicy.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/JtaTransactionPolicy.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/JtaTransactionPolicy.java
index 4755037..2609991 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/JtaTransactionPolicy.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/core/transaction/JtaTransactionPolicy.java
@@ -59,12 +59,14 @@ public abstract class JtaTransactionPolicy implements 
TransactionPolicy {
         synchronizationRegistry = 
SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
     }
 
+    @Override
     public TransactionType getTransactionType() {
         return transactionType;
     }
 
     public abstract Transaction getCurrentTransaction();
 
+    @Override
     public boolean isTransactionActive() {
         final Transaction trasaction = getCurrentTransaction();
         if (trasaction == null) {
@@ -79,6 +81,7 @@ public abstract class JtaTransactionPolicy implements 
TransactionPolicy {
         }
     }
 
+    @Override
     public boolean isRollbackOnly() {
         final Transaction trasaction = getCurrentTransaction();
         if (trasaction != null) {
@@ -93,6 +96,7 @@ public abstract class JtaTransactionPolicy implements 
TransactionPolicy {
         }
     }
 
+    @Override
     public void setRollbackOnly() {
         setRollbackOnly(null);
     }
@@ -107,6 +111,7 @@ public abstract class JtaTransactionPolicy implements 
TransactionPolicy {
         }
     }
 
+    @Override
     public Object getResource(final Object key) {
         if (isTransactionActive()) {
             return synchronizationRegistry.getResource(key);
@@ -118,6 +123,7 @@ public abstract class JtaTransactionPolicy implements 
TransactionPolicy {
         return resources.get(key);
     }
 
+    @Override
     public void putResource(final Object key, final Object value) {
         if (isTransactionActive()) {
             synchronizationRegistry.putResource(key, value);
@@ -129,6 +135,7 @@ public abstract class JtaTransactionPolicy implements 
TransactionPolicy {
         resources.put(key, value);
     }
 
+    @Override
     public Object removeResource(final Object key) {
         if (isTransactionActive()) {
             final Object value = synchronizationRegistry.getResource(key);
@@ -142,13 +149,16 @@ public abstract class JtaTransactionPolicy implements 
TransactionPolicy {
         return resources.remove(key);
     }
 
+    @Override
     public void registerSynchronization(final TransactionSynchronization 
synchronization) {
         if (isTransactionActive()) {
             synchronizationRegistry.registerInterposedSynchronization(new 
Synchronization() {
+                @Override
                 public void beforeCompletion() {
                     synchronization.beforeCompletion();
                 }
 
+                @Override
                 public void afterCompletion(final int s) {
                     final TransactionSynchronization.Status status;
                     if (s == Status.STATUS_COMMITTED) {
@@ -185,6 +195,7 @@ public abstract class JtaTransactionPolicy implements 
TransactionPolicy {
         }
     }
 
+    @Override
     public void enlistResource(final XAResource xaResource) throws 
SystemException {
         final Transaction transaction = getCurrentTransaction();
         if (transaction != null) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/a9ca7de3/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
----------------------------------------------------------------------
diff --git 
a/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
 
b/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
index 0e3654b..e2d341c 100644
--- 
a/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
+++ 
b/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
@@ -38,8 +38,8 @@ public class MovieTest {
 
     private EJBContainer container;
 
-    private Context getContext(String user, String pass) throws 
NamingException {
-        Properties p = new Properties();
+    private Context getContext(final String user, final String pass) throws 
NamingException {
+        final Properties p = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY, 
"org.apache.openejb.core.LocalInitialContextFactory");
         p.setProperty("openejb.authentication.realmName", "ScriptLogin");
         p.put(Context.SECURITY_PRINCIPAL, user);
@@ -53,7 +53,7 @@ public class MovieTest {
         final ClassLoader ctxCl = 
Thread.currentThread().getContextClassLoader();
         System.setProperty("openejb.ScriptLoginModule.scriptURI", 
ctxCl.getResource("loginscript.js").toExternalForm());
 
-        Properties p = new Properties();
+        final Properties p = new Properties();
         p.put("movieDatabase", "new://Resource?type=DataSource");
         p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
         p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
@@ -76,10 +76,10 @@ public class MovieTest {
             movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
             movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
-            List<Movie> list = movies.getMovies();
+            final List<Movie> list = movies.getMovies();
             Assert.assertEquals("List.size()", 3, list.size());
 
-            for (Movie movie : list) {
+            for (final Movie movie : list) {
                 movies.deleteMovie(movie);
             }
 
@@ -98,14 +98,14 @@ public class MovieTest {
             movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
             movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
-            List<Movie> list = movies.getMovies();
+            final List<Movie> list = movies.getMovies();
             Assert.assertEquals("List.size()", 3, list.size());
 
-            for (Movie movie : list) {
+            for (final Movie movie : list) {
                 try {
                     movies.deleteMovie(movie);
                     Assert.fail("Employees should not be allowed to delete");
-                } catch (EJBAccessException e) {
+                } catch (final EJBAccessException e) {
                     // Good, Employees cannot delete things
                 }
             }
@@ -122,21 +122,21 @@ public class MovieTest {
         try {
             movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 
1992));
             Assert.fail("Unauthenticated users should not be able to add 
movies");
-        } catch (EJBAccessException e) {
+        } catch (final EJBAccessException e) {
             // Good, guests cannot add things
         }
 
         try {
             movies.deleteMovie(null);
             Assert.fail("Unauthenticated users should not be allowed to 
delete");
-        } catch (EJBAccessException e) {
+        } catch (final EJBAccessException e) {
             // Good, Unauthenticated users cannot delete things
         }
 
         try {
             // Read access should be allowed
             movies.getMovies();
-        } catch (EJBAccessException e) {
+        } catch (final EJBAccessException e) {
             Assert.fail("Read access should be allowed");
         }
     }
@@ -146,14 +146,14 @@ public class MovieTest {
         try {
             getContext("eddie", "panama");
             Assert.fail("supposed to have a login failure here");
-        } catch (javax.naming.AuthenticationException e) {
+        } catch (final javax.naming.AuthenticationException e) {
             //expected
         }
 
         try {
             getContext("jimmy", "foxylady");
             Assert.fail("supposed to have a login failure here");
-        } catch (javax.naming.AuthenticationException e) {
+        } catch (final javax.naming.AuthenticationException e) {
             //expected
         }
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a9ca7de3/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
----------------------------------------------------------------------
diff --git 
a/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
 
b/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
index 95b8a38..5d6c4b9 100644
--- 
a/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
+++ 
b/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
@@ -1,161 +1,161 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tomee;
-
-import org.apache.geronimo.osgi.locator.ProviderLocator;
-import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.assembler.Deployer;
-import org.apache.openejb.assembler.DeployerEjb;
-import org.apache.openejb.client.RemoteInitialContextFactory;
-import org.apache.openejb.config.RemoteServer;
-import org.apache.openejb.loader.IO;
-import org.apache.tomee.util.QuickServerXmlParser;
-
-import javax.ejb.EJBException;
-import javax.ejb.embeddable.EJBContainer;
-import javax.ejb.spi.EJBContainerProvider;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.validation.ValidationException;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-public class RemoteTomEEEJBContainer extends EJBContainer {
-    private static RemoteTomEEEJBContainer instance;
-    private RemoteServer container;
-    private InitialContext context;
-
-    @Override
-    public void close() {
-        instance.container.destroy();
-        instance.container = null;
-    }
-
-    @Override
-    public Context getContext() {
-        return context;
-    }
-
-    public static class Provider implements EJBContainerProvider {
-        private static final List<String> CONTAINER_NAMES = 
Arrays.asList(RemoteTomEEEJBContainer.class.getName(), "tomee-remote", 
"remote-tomee");
-
-        @Override
-        public EJBContainer createEJBContainer(final Map<?, ?> properties) {
-            final Object provider = properties.get(EJBContainer.PROVIDER);
-            int ejbContainerProviders = 1;
-            try {
-                ejbContainerProviders = 
ProviderLocator.getServices(EJBContainerProvider.class.getName(), 
EJBContainer.class, Thread.currentThread().getContextClassLoader()).size();
-            } catch (final Exception e) {
-                // no-op
-            }
-
-            if ((provider == null && ejbContainerProviders > 1)
-                    || (!RemoteTomEEEJBContainer.class.equals(provider)
-                    && !CONTAINER_NAMES.contains(String.valueOf(provider)))) {
-                return null;
-            }
-
-            if (instance != null) {
-                return instance;
-            }
-
-            final Object modules = properties.get(EJBContainer.MODULES);
-
-            System.getProperties().putAll(properties);
-            final File home = new File(System.getProperty("openejb.home", 
"doesn't exist"));
-            if (!home.exists()) {
-                throw new IllegalArgumentException("You need to set 
openejb.home");
-            }
-
-            final QuickServerXmlParser parser = QuickServerXmlParser.parse(new 
File(home, "conf/server.xml"));
-            final String remoteEjb = System.getProperty(Context.PROVIDER_URL, 
"http://"; + parser.host() + ":" + parser.http() + "/tomee/ejb");
-
-            try {
-                instance = new RemoteTomEEEJBContainer();
-                instance.container = new RemoteServer();
-                
instance.container.setPortStartup(Integer.parseInt(parser.http()));
-
-                try {
-                    instance.container.start();
-                } catch (final Exception e) {
-                    instance.container.destroy();
-                    throw e;
-                }
-
-                instance.context = new InitialContext(new Properties() {{
-                    setProperty(Context.INITIAL_CONTEXT_FACTORY, 
RemoteInitialContextFactory.class.getName());
-                    setProperty(Context.PROVIDER_URL, remoteEjb);
-                }});
-
-                final Deployer deployer = 
Deployer.class.cast(instance.context.lookup("openejb/DeployerBusinessRemote"));
-
-                if (modules instanceof File) {
-                    final File file = File.class.cast(modules);
-                    deployFile(deployer, file);
-                } else if (modules instanceof String) {
-                    final String path = String.class.cast(modules);
-                    final File file = new File(path);
-                    deployFile(deployer, file);
-                } else if (modules instanceof String[]) {
-                    for (final String path : (String[]) modules) {
-                        deployFile(deployer, new File(path));
-                    }
-                } else if (modules instanceof File[]) {
-                    for (final File file : (File[]) modules) {
-                        deployFile(deployer, file);
-                    }
-                } // else suppose already deployed
-
-                return instance;
-            } catch (final OpenEJBException e) {
-                throw new EJBException(e);
-            } catch (final MalformedURLException e) {
-                throw new EJBException(e);
-            } catch (final ValidationException ve) {
-                throw ve;
-            } catch (final Exception e) {
-                if (e instanceof EJBException) {
-                    throw (EJBException) e;
-                }
-                throw new TomEERemoteEJBContainerException("initialization 
exception", e);
-            }
-        }
-    }
-
-    private static void deployFile(final Deployer deployer, final File file) 
throws IOException, OpenEJBException {
-        if 
("true".equalsIgnoreCase(System.getProperty(DeployerEjb.OPENEJB_USE_BINARIES, 
"false"))) {
-            final Properties props = new Properties();
-            final byte[] slurpBinaries = IO.slurp(file).getBytes();
-            props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
-            props.put(DeployerEjb.OPENEJB_PATH_BINARIES, file.getName());
-            deployer.deploy(file.getAbsolutePath(), props);
-        } else {
-            deployer.deploy(file.getAbsolutePath());
-        }
-    }
-
-    protected static class TomEERemoteEJBContainerException extends 
RuntimeException {
-        protected TomEERemoteEJBContainerException(final String s, final 
Exception e) {
-            super(s, e);
-        }
-    }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee;
+
+import org.apache.geronimo.osgi.locator.ProviderLocator;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.Deployer;
+import org.apache.openejb.assembler.DeployerEjb;
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.config.RemoteServer;
+import org.apache.openejb.loader.IO;
+import org.apache.tomee.util.QuickServerXmlParser;
+
+import javax.ejb.EJBException;
+import javax.ejb.embeddable.EJBContainer;
+import javax.ejb.spi.EJBContainerProvider;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.validation.ValidationException;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class RemoteTomEEEJBContainer extends EJBContainer {
+    private static RemoteTomEEEJBContainer instance;
+    private RemoteServer container;
+    private InitialContext context;
+
+    @Override
+    public void close() {
+        instance.container.destroy();
+        instance.container = null;
+    }
+
+    @Override
+    public Context getContext() {
+        return context;
+    }
+
+    public static class Provider implements EJBContainerProvider {
+        private static final List<String> CONTAINER_NAMES = 
Arrays.asList(RemoteTomEEEJBContainer.class.getName(), "tomee-remote", 
"remote-tomee");
+
+        @Override
+        public EJBContainer createEJBContainer(final Map<?, ?> properties) {
+            final Object provider = properties.get(EJBContainer.PROVIDER);
+            int ejbContainerProviders = 1;
+            try {
+                ejbContainerProviders = 
ProviderLocator.getServices(EJBContainerProvider.class.getName(), 
EJBContainer.class, Thread.currentThread().getContextClassLoader()).size();
+            } catch (final Exception e) {
+                // no-op
+            }
+
+            if ((provider == null && ejbContainerProviders > 1)
+                    || (!RemoteTomEEEJBContainer.class.equals(provider)
+                    && !CONTAINER_NAMES.contains(String.valueOf(provider)))) {
+                return null;
+            }
+
+            if (instance != null) {
+                return instance;
+            }
+
+            final Object modules = properties.get(EJBContainer.MODULES);
+
+            System.getProperties().putAll(properties);
+            final File home = new File(System.getProperty("openejb.home", 
"doesn't exist"));
+            if (!home.exists()) {
+                throw new IllegalArgumentException("You need to set 
openejb.home");
+            }
+
+            final QuickServerXmlParser parser = QuickServerXmlParser.parse(new 
File(home, "conf/server.xml"));
+            final String remoteEjb = System.getProperty(Context.PROVIDER_URL, 
"http://"; + parser.host() + ":" + parser.http() + "/tomee/ejb");
+
+            try {
+                instance = new RemoteTomEEEJBContainer();
+                instance.container = new RemoteServer();
+                
instance.container.setPortStartup(Integer.parseInt(parser.http()));
+
+                try {
+                    instance.container.start();
+                } catch (final Exception e) {
+                    instance.container.destroy();
+                    throw e;
+                }
+
+                instance.context = new InitialContext(new Properties() {{
+                    setProperty(Context.INITIAL_CONTEXT_FACTORY, 
RemoteInitialContextFactory.class.getName());
+                    setProperty(Context.PROVIDER_URL, remoteEjb);
+                }});
+
+                final Deployer deployer = 
Deployer.class.cast(instance.context.lookup("openejb/DeployerBusinessRemote"));
+
+                if (modules instanceof File) {
+                    final File file = File.class.cast(modules);
+                    deployFile(deployer, file);
+                } else if (modules instanceof String) {
+                    final String path = String.class.cast(modules);
+                    final File file = new File(path);
+                    deployFile(deployer, file);
+                } else if (modules instanceof String[]) {
+                    for (final String path : (String[]) modules) {
+                        deployFile(deployer, new File(path));
+                    }
+                } else if (modules instanceof File[]) {
+                    for (final File file : (File[]) modules) {
+                        deployFile(deployer, file);
+                    }
+                } // else suppose already deployed
+
+                return instance;
+            } catch (final OpenEJBException e) {
+                throw new EJBException(e);
+            } catch (final MalformedURLException e) {
+                throw new EJBException(e);
+            } catch (final ValidationException ve) {
+                throw ve;
+            } catch (final Exception e) {
+                if (e instanceof EJBException) {
+                    throw (EJBException) e;
+                }
+                throw new TomEERemoteEJBContainerException("initialization 
exception", e);
+            }
+        }
+    }
+
+    private static void deployFile(final Deployer deployer, final File file) 
throws IOException, OpenEJBException {
+        if 
("true".equalsIgnoreCase(System.getProperty(DeployerEjb.OPENEJB_USE_BINARIES, 
"false"))) {
+            final Properties props = new Properties();
+            final byte[] slurpBinaries = IO.slurp(file).getBytes();
+            props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
+            props.put(DeployerEjb.OPENEJB_PATH_BINARIES, file.getName());
+            deployer.deploy(file.getAbsolutePath(), props);
+        } else {
+            deployer.deploy(file.getAbsolutePath());
+        }
+    }
+
+    protected static class TomEERemoteEJBContainerException extends 
RuntimeException {
+        protected TomEERemoteEJBContainerException(final String s, final 
Exception e) {
+            super(s, e);
+        }
+    }
+}

Reply via email to