Repository: tomee Updated Branches: refs/heads/master 26c3be0d5 -> dfb502da9
more laziness for Messages when only used for errors Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/dfb502da Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/dfb502da Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/dfb502da Branch: refs/heads/master Commit: dfb502da900ac72525e0fab006bcde51fcc1471c Parents: 26c3be0 Author: Romain Manni-Bucau <rmannibu...@apache.org> Authored: Wed Jun 17 15:56:29 2015 +0200 Committer: Romain Manni-Bucau <rmannibu...@apache.org> Committed: Wed Jun 17 15:56:29 2015 +0200 ---------------------------------------------------------------------- .../assembler/classic/AssemblerTool.java | 9 +++---- .../assembler/classic/EjbJarBuilder.java | 5 +--- .../classic/EnterpriseBeanBuilder.java | 27 +++++++++++--------- .../apache/openejb/config/AppInfoBuilder.java | 3 +-- .../org/apache/openejb/config/ConfigUtils.java | 2 -- .../openejb/config/InitEjbDeployments.java | 2 -- .../org/apache/openejb/config/ServiceUtils.java | 3 +-- .../openejb/config/rules/CheckClasses.java | 4 ++- .../openejb/config/rules/ValidationBase.java | 8 ++++-- .../apache/openejb/config/sys/JaxbOpenejb.java | 14 ++++++---- .../org/apache/openejb/util/SafeToolkit.java | 1 - 11 files changed, 40 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java index 9cd97fe..4b684b4 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java @@ -24,13 +24,13 @@ import org.apache.openejb.util.Messages; import org.apache.openejb.util.SafeToolkit; import org.apache.openejb.util.proxy.ProxyFactory; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; import javax.resource.spi.ConnectionManager; import javax.resource.spi.ManagedConnectionFactory; import javax.resource.spi.ResourceAdapter; import javax.transaction.TransactionManager; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; public class AssemblerTool { @@ -46,7 +46,6 @@ public class AssemblerTool { serviceInterfaces.put("Container", Container.class); } - protected static final Messages messages = new Messages("org.apache.openejb.util.resources"); protected static final SafeToolkit toolkit = SafeToolkit.getToolkit("AssemblerTool"); protected Properties props = new Properties(); @@ -57,7 +56,7 @@ public class AssemblerTool { protected static void checkImplementation(final Class intrfce, final Class factory, final String serviceType, final String serviceName) throws OpenEJBException { if (!intrfce.isAssignableFrom(factory)) { - throw new OpenEJBException(messages.format("init.0100", serviceType, serviceName, factory.getName(), intrfce.getName())); + throw new OpenEJBException(new Messages("org.apache.openejb.util.resources").format("init.0100", serviceType, serviceName, factory.getName(), intrfce.getName())); } } http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java index 0accb01..832e740 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java @@ -24,20 +24,17 @@ import org.apache.openejb.Injection; import org.apache.openejb.ModuleContext; import org.apache.openejb.ModuleTestContext; import org.apache.openejb.OpenEJBException; -import org.apache.openejb.util.Messages; -import javax.naming.Context; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Properties; +import javax.naming.Context; /** * @version $Revision$ $Date$ */ public class EjbJarBuilder { - protected static final Messages messages = new Messages("org.apache.openejb.util.resources"); - private final Properties props; private final AppContext context; http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java index 414d5ea..d946764 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java @@ -31,11 +31,6 @@ import org.apache.openejb.util.Index; import org.apache.openejb.util.Messages; import org.apache.openejb.util.SafeToolkit; -import javax.ejb.TimedObject; -import javax.ejb.Timer; -import javax.naming.Context; -import javax.naming.NamingException; -import javax.persistence.EntityManagerFactory; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -45,9 +40,13 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import javax.ejb.TimedObject; +import javax.ejb.Timer; +import javax.naming.Context; +import javax.naming.NamingException; +import javax.persistence.EntityManagerFactory; class EnterpriseBeanBuilder { - protected static final Messages messages = new Messages("org.apache.openejb.util.resources"); private final EnterpriseBeanInfo bean; private final BeanType ejbType; private final List<Exception> warnings = new ArrayList<Exception>(); @@ -405,21 +404,25 @@ class EnterpriseBeanBuilder { return clazz; } catch (final NoClassDefFoundError e) { if (clazz.getClassLoader() != moduleContext.getClassLoader()) { - final String message = SafeToolkit.messages.format("cl0008", className, clazz.getClassLoader(), moduleContext.getClassLoader(), e.getMessage()); - throw new OpenEJBException(AssemblerTool.messages.format(messageCode, className, bean.ejbDeploymentId, message), e); + final String message = messages().format("cl0008", className, clazz.getClassLoader(), moduleContext.getClassLoader(), e.getMessage()); + throw new OpenEJBException(messages().format(messageCode, className, bean.ejbDeploymentId, message), e); } else { - final String message = SafeToolkit.messages.format("cl0009", className, clazz.getClassLoader(), e.getMessage()); - throw new OpenEJBException(AssemblerTool.messages.format(messageCode, className, bean.ejbDeploymentId, message), e); + final String message = messages().format("cl0009", className, clazz.getClassLoader(), e.getMessage()); + throw new OpenEJBException(messages().format(messageCode, className, bean.ejbDeploymentId, message), e); } } } + private Messages messages() { // new is fine cause for errors only + return new Messages("org.apache.openejb.util.resources"); + } + private Class load(final String className, final String messageCode) throws OpenEJBException { try { return Class.forName(className, true, moduleContext.getClassLoader()); } catch (final ClassNotFoundException e) { - final String message = SafeToolkit.messages.format("cl0007", className, bean.codebase); - throw new OpenEJBException(AssemblerTool.messages.format(messageCode, className, bean.ejbDeploymentId, message)); + final String message = messages().format("cl0007", className, bean.codebase); + throw new OpenEJBException(messages().format(messageCode, className, bean.ejbDeploymentId, message)); } } } http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java index 755f017..5933362 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java @@ -108,7 +108,6 @@ import static org.apache.openejb.util.URLs.toFile; class AppInfoBuilder { private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, "org.apache.openejb.util.resources"); - private static final Messages messages = new Messages("org.apache.openejb.util.resources"); private static final boolean USE_EAR_AS_CONTEXT_ROOT_BASE = SystemInstance.get().getOptions().get("openejb.ear.use-as-webcontext-base", false); @@ -206,7 +205,7 @@ class AppInfoBuilder { } if (!containerIds.contains(d.getContainerId()) && !skipMdb(bean)) { - final String msg = messages.format("config.noContainerFound", d.getContainerId(), d.getEjbName()); + final String msg = new Messages("org.apache.openejb.util.resources").format("config.noContainerFound", d.getContainerId(), d.getEjbName()); logger.fatal(msg); throw new OpenEJBException(msg); } http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigUtils.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigUtils.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigUtils.java index 69a8947..2bc214d 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigUtils.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigUtils.java @@ -26,7 +26,6 @@ import org.apache.openejb.loader.IO; import org.apache.openejb.loader.SystemInstance; import org.apache.openejb.util.LogCategory; import org.apache.openejb.util.Logger; -import org.apache.openejb.util.Messages; import org.apache.xbean.finder.ResourceFinder; import java.io.File; @@ -36,7 +35,6 @@ import java.net.URL; public class ConfigUtils { - public static Messages messages = new Messages("org.apache.openejb.util.resources"); public static Logger logger = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources"); /** http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java b/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java index 83684c3..47c2784 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java @@ -27,7 +27,6 @@ import org.apache.openejb.jee.oejb3.OpenejbJar; import org.apache.openejb.loader.SystemInstance; import org.apache.openejb.util.LogCategory; import org.apache.openejb.util.Logger; -import org.apache.openejb.util.Messages; import org.apache.openejb.util.StringTemplate; import java.util.Collection; @@ -37,7 +36,6 @@ import java.util.Map; import java.util.Set; public class InitEjbDeployments implements DynamicDeployer { - public static Messages messages = new Messages("org.apache.openejb.util.resources"); public static Logger logger = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources"); private final StringTemplate deploymentIdTemplate; http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java index 5694392..a3ac1ba 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ServiceUtils.java @@ -62,7 +62,6 @@ public class ServiceUtils { return SystemInstance.get().getProperty("openejb.provider.default", defaultValue); } - public static Messages messages = new Messages("org.apache.openejb.util.resources"); public static Logger logger = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources"); public static ProviderManager getManager() { @@ -120,7 +119,7 @@ public class ServiceUtils { } } - throw new NoSuchProviderException(messages.format("conf.4901", id.getName(), id.getNamespace())); + throw new NoSuchProviderException(new Messages("org.apache.openejb.util.resources").format("conf.4901", id.getName(), id.getNamespace())); } public static String getServiceProviderId(final String type) throws OpenEJBException { http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java b/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java index 2a32a14..b05a35b 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java @@ -26,6 +26,7 @@ import org.apache.openejb.jee.EntityBean; import org.apache.openejb.jee.Interceptor; import org.apache.openejb.jee.RemoteBean; import org.apache.openejb.jee.SessionBean; +import org.apache.openejb.util.Messages; import org.apache.openejb.util.SafeToolkit; import org.apache.openejb.util.Strings; import org.apache.openejb.util.proxy.DynamicProxyImplFactory; @@ -419,7 +420,8 @@ public class CheckClasses extends ValidationBase { try { return Class.forName(clazz, false, cl == null ? module.getClassLoader() : cl); } catch (final ClassNotFoundException cnfe) { - throw new OpenEJBException(SafeToolkit.messages.format("cl0007", clazz, module.getJarLocation()), cnfe); + throw new OpenEJBException( + new Messages("org.apache.openejb.util.resources").format("cl0007", clazz, module.getJarLocation()), cnfe); } } } http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/config/rules/ValidationBase.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/rules/ValidationBase.java b/container/openejb-core/src/main/java/org/apache/openejb/config/rules/ValidationBase.java index 8b61e32..c37b4ca 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/rules/ValidationBase.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/rules/ValidationBase.java @@ -30,7 +30,7 @@ import org.apache.openejb.jee.MethodParams; import org.apache.openejb.jee.PersistenceType; import org.apache.openejb.util.Classes; import org.apache.openejb.util.Join; -import org.apache.openejb.util.SafeToolkit; +import org.apache.openejb.util.Messages; import java.lang.reflect.Method; @@ -150,10 +150,14 @@ public abstract class ValidationBase implements ValidationRule { try { return Classes.forName(clazz, cl); } catch (final ClassNotFoundException cnfe) { - throw new OpenEJBException(SafeToolkit.messages.format("cl0007", clazz, module.getJarLocation()), cnfe); + throw new OpenEJBException(messages().format("cl0007", clazz, module.getJarLocation()), cnfe); } } + private Messages messages() { // new is fine cause for errors only + return new Messages("org.apache.openejb.util.resources"); + } + public boolean isCmp(final EnterpriseBean b) { if (b instanceof EntityBean) { http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JaxbOpenejb.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JaxbOpenejb.java b/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JaxbOpenejb.java index 3264959..026cbaa 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JaxbOpenejb.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JaxbOpenejb.java @@ -18,11 +18,11 @@ package org.apache.openejb.config.sys; import org.apache.openejb.OpenEJBException; -import org.apache.openejb.config.ConfigUtils; import org.apache.openejb.config.SystemProperty; import org.apache.openejb.jee.JAXBContextFactory; import org.apache.openejb.loader.IO; import org.apache.openejb.util.Join; +import org.apache.openejb.util.Messages; import org.apache.openejb.util.Saxs; import org.xml.sax.Attributes; import org.xml.sax.InputSource; @@ -236,12 +236,12 @@ public abstract class JaxbOpenejb { out = IO.write(file); marshal(Openejb.class, openejb, out); } catch (final IOException e) { - throw new OpenEJBException(ConfigUtils.messages.format("conf.1040", configFile, e.getLocalizedMessage()), e); + throw new OpenEJBException(messages().format("conf.1040", configFile, e.getLocalizedMessage()), e); } catch (final MarshalException e) { if (e.getCause() instanceof IOException) { - throw new OpenEJBException(ConfigUtils.messages.format("conf.1040", configFile, e.getLocalizedMessage()), e); + throw new OpenEJBException(messages().format("conf.1040", configFile, e.getLocalizedMessage()), e); } else { - throw new OpenEJBException(ConfigUtils.messages.format("conf.1050", configFile, e.getLocalizedMessage()), e); + throw new OpenEJBException(messages().format("conf.1050", configFile, e.getLocalizedMessage()), e); } } catch (final ValidationException e) { /* TODO: Implement informative error handling here. @@ -255,7 +255,7 @@ public abstract class JaxbOpenejb { * is invalid, the MarshalException is thrown, not this one as you * would think. */ - throw new OpenEJBException(ConfigUtils.messages.format("conf.1060", configFile, e.getLocalizedMessage()), e); + throw new OpenEJBException(messages().format("conf.1060", configFile, e.getLocalizedMessage()), e); } catch (final JAXBException e) { throw new OpenEJBException(e); } finally { @@ -269,6 +269,10 @@ public abstract class JaxbOpenejb { } } + private static Messages messages() { // new is fine cause for errors only + return new Messages("org.apache.openejb.util.resources"); + } + public static final ThreadLocal<Set<String>> currentPublicId = new ThreadLocal<Set<String>>(); private static final Map<Class, JAXBContext> jaxbContexts = new HashMap<Class, JAXBContext>(); http://git-wip-us.apache.org/repos/asf/tomee/blob/dfb502da/container/openejb-core/src/main/java/org/apache/openejb/util/SafeToolkit.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/SafeToolkit.java b/container/openejb-core/src/main/java/org/apache/openejb/util/SafeToolkit.java index 7158048..c062f09 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/util/SafeToolkit.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/util/SafeToolkit.java @@ -24,7 +24,6 @@ import java.net.URLClassLoader; import java.util.HashMap; public final class SafeToolkit { - public static final Messages messages = new Messages("org.apache.openejb.util.resources"); public static final HashMap codebases = new HashMap(); public static SafeToolkit getToolkit(final String systemLocation) {