You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/07/10 08:35:07 UTC
[tomcat] branch 7.0.x updated: Align with 8.5.x
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push:
new 682e8d4 Align with 8.5.x
682e8d4 is described below
commit 682e8d434b2cd61ef7b8694196cc3adae8d20ef0
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jul 10 09:34:13 2019 +0100
Align with 8.5.x
Code clean-up. i18n improvements, fix SpotBugs warnings, spacing,
refactor to reduce duplication
---
java/org/apache/naming/factory/BeanFactory.java | 16 +-
.../naming/factory/DataSourceLinkFactory.java | 12 +-
java/org/apache/naming/factory/EjbFactory.java | 172 +++++----------------
java/org/apache/naming/factory/FactoryBase.java | 141 +++++++++++++++++
.../apache/naming/factory/LocalStrings.properties | 9 ++
.../naming/factory/LocalStrings_es.properties | 20 +++
.../naming/factory/LocalStrings_fr.properties | 28 ++++
.../naming/factory/LocalStrings_ja.properties | 28 ++++
java/org/apache/naming/factory/LookupFactory.java | 2 +-
.../apache/naming/factory/MailSessionFactory.java | 4 +-
.../apache/naming/factory/ResourceEnvFactory.java | 103 ++----------
.../org/apache/naming/factory/ResourceFactory.java | 159 ++++++-------------
.../apache/naming/factory/ResourceLinkFactory.java | 4 +-
.../org/apache/naming/factory/SendMailFactory.java | 49 +++---
.../apache/naming/factory/TransactionFactory.java | 103 ++----------
java/org/apache/naming/factory/package.html | 2 -
java/org/apache/naming/java/package.html | 2 -
17 files changed, 380 insertions(+), 474 deletions(-)
diff --git a/java/org/apache/naming/factory/BeanFactory.java b/java/org/apache/naming/factory/BeanFactory.java
index 56c97ac..ec06cd3 100644
--- a/java/org/apache/naming/factory/BeanFactory.java
+++ b/java/org/apache/naming/factory/BeanFactory.java
@@ -86,7 +86,7 @@ import org.apache.naming.ResourceRef;
* </ResourceParams>
* </pre>
*
- * @author <a href="mailto:aner at ncstech.com">Aner Perez</a>
+ * @author Aner Perez [aner at ncstech.com]
*/
public class BeanFactory
implements ObjectFactory {
@@ -145,7 +145,7 @@ public class BeanFactory
BeanInfo bi = Introspector.getBeanInfo(beanClass);
PropertyDescriptor[] pda = bi.getPropertyDescriptors();
- Object bean = beanClass.newInstance();
+ Object bean = beanClass.getConstructor().newInstance();
/* Look for properties with explicitly configured setter */
RefAddr ra = ref.get("forceString");
@@ -306,6 +306,18 @@ public class BeanFactory
NamingException ne = new NamingException(ie2.getMessage());
ne.setRootCause(ie2);
throw ne;
+ } catch (IllegalArgumentException e) {
+ NamingException ne = new NamingException(e.getMessage());
+ ne.setRootCause(e);
+ throw ne;
+ } catch (SecurityException e) {
+ NamingException ne = new NamingException(e.getMessage());
+ ne.setRootCause(e);
+ throw ne;
+ } catch (NoSuchMethodException e) {
+ NamingException ne = new NamingException(e.getMessage());
+ ne.setRootCause(e);
+ throw ne;
} catch (java.lang.reflect.InvocationTargetException ite) {
Throwable cause = ite.getCause();
if (cause instanceof ThreadDeath) {
diff --git a/java/org/apache/naming/factory/DataSourceLinkFactory.java b/java/org/apache/naming/factory/DataSourceLinkFactory.java
index 904c482..bd029fe 100644
--- a/java/org/apache/naming/factory/DataSourceLinkFactory.java
+++ b/java/org/apache/naming/factory/DataSourceLinkFactory.java
@@ -18,7 +18,6 @@
package org.apache.naming.factory;
-import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -38,7 +37,6 @@ import javax.sql.DataSource;
/**
* <p>Object factory for resource links for shared data sources.</p>
*
- * @author Filip Hanik
*/
public class DataSourceLinkFactory extends ResourceLinkFactory {
@@ -71,10 +69,10 @@ public class DataSourceLinkFactory extends ResourceLinkFactory {
protected Object wrapDataSource(Object datasource, String username, String password) throws NamingException {
try {
- Class<?> proxyClass = Proxy.getProxyClass(datasource.getClass().getClassLoader(), datasource.getClass().getInterfaces());
- Constructor<?> proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
- DataSourceHandler handler = new DataSourceHandler((DataSource)datasource, username, password);
- return proxyConstructor.newInstance(handler);
+ DataSourceHandler handler =
+ new DataSourceHandler((DataSource)datasource, username, password);
+ return Proxy.newProxyInstance(datasource.getClass().getClassLoader(),
+ datasource.getClass().getInterfaces(), handler);
}catch (Exception x) {
if (x instanceof InvocationTargetException) {
Throwable cause = x.getCause();
@@ -139,7 +137,7 @@ public class DataSourceLinkFactory extends ResourceLinkFactory {
if (iface == DataSource.class) {
return ds;
} else {
- throw new SQLException("Not a wrapper of "+iface.getName());
+ throw new SQLException(sm.getString("dataSourceLinkFactory.badWrapper", iface.getName()));
}
}
diff --git a/java/org/apache/naming/factory/EjbFactory.java b/java/org/apache/naming/factory/EjbFactory.java
index 85464d8..4f593a5 100644
--- a/java/org/apache/naming/factory/EjbFactory.java
+++ b/java/org/apache/naming/factory/EjbFactory.java
@@ -14,15 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.naming.factory;
-import java.util.Hashtable;
-
-import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.RefAddr;
import javax.naming.Reference;
@@ -35,144 +29,50 @@ import org.apache.naming.EjbRef;
*
* @author Remy Maucherat
*/
+public class EjbFactory extends FactoryBase {
-public class EjbFactory
- implements ObjectFactory {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- // -------------------------------------------------------------- Constants
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- // --------------------------------------------------------- Public Methods
-
-
- // -------------------------------------------------- ObjectFactory Methods
-
-
- /**
- * Create a new EJB instance.
- *
- * @param obj The reference object describing the DataSource
- */
@Override
- public Object getObjectInstance(Object obj, Name name, Context nameCtx,
- Hashtable<?,?> environment)
- throws Exception {
-
- if (obj instanceof EjbRef) {
- Reference ref = (Reference) obj;
+ protected boolean isReferenceTypeSupported(Object obj) {
+ return obj instanceof EjbRef;
+ }
- // If ejb-link has been specified, resolving the link using JNDI
- RefAddr linkRefAddr = ref.get(EjbRef.LINK);
- if (linkRefAddr != null) {
- // Retrieving the EJB link
- String ejbLink = linkRefAddr.getContent().toString();
- Object beanObj = (new InitialContext()).lookup(ejbLink);
- // Load home interface and checking if bean correctly
- // implements specified home interface
- /*
- String homeClassName = ref.getClassName();
- try {
- Class home = Class.forName(homeClassName);
- if (home.isInstance(beanObj)) {
- System.out.println("Bean of type "
- + beanObj.getClass().getName()
- + " implements home interface "
- + home.getName());
- } else {
- System.out.println("Bean of type "
- + beanObj.getClass().getName()
- + " doesn't implement home interface "
- + home.getName());
- throw new NamingException
- ("Bean of type " + beanObj.getClass().getName()
- + " doesn't implement home interface "
- + home.getName());
- }
- } catch (ClassNotFoundException e) {
- System.out.println("Couldn't load home interface "
- + homeClassName);
- }
- */
- return beanObj;
+ @Override
+ protected ObjectFactory getDefaultFactory(Reference ref) throws NamingException {
+
+ ObjectFactory factory;
+ String javaxEjbFactoryClassName = System.getProperty(
+ "javax.ejb.Factory", Constants.OPENEJB_EJB_FACTORY);
+ try {
+ factory = (ObjectFactory)
+ Class.forName(javaxEjbFactoryClassName).getConstructor().newInstance();
+ } catch(Throwable t) {
+ if (t instanceof NamingException) {
+ throw (NamingException) t;
}
-
- ObjectFactory factory = null;
- RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
- if (factoryRefAddr != null) {
- // Using the specified factory
- String factoryClassName =
- factoryRefAddr.getContent().toString();
- // Loading factory
- ClassLoader tcl =
- Thread.currentThread().getContextClassLoader();
- Class<?> factoryClass = null;
- if (tcl != null) {
- try {
- factoryClass = tcl.loadClass(factoryClassName);
- } catch(ClassNotFoundException e) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(e);
- throw ex;
- }
- } else {
- try {
- factoryClass = Class.forName(factoryClassName);
- } catch(ClassNotFoundException e) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(e);
- throw ex;
- }
- }
- if (factoryClass != null) {
- try {
- factory = (ObjectFactory) factoryClass.newInstance();
- } catch(Throwable t) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(t);
- throw ex;
- }
- }
- } else {
- String javaxEjbFactoryClassName =
- System.getProperty("javax.ejb.Factory",
- Constants.OPENEJB_EJB_FACTORY);
- try {
- factory = (ObjectFactory)
- Class.forName(javaxEjbFactoryClassName).newInstance();
- } catch(Throwable t) {
- if (t instanceof NamingException)
- throw (NamingException) t;
- NamingException ex = new NamingException
- ("Could not create resource factory instance");
- ex.initCause(t);
- throw ex;
- }
+ if (t instanceof ThreadDeath) {
+ throw (ThreadDeath) t;
}
-
- if (factory != null) {
- return factory.getObjectInstance
- (obj, name, nameCtx, environment);
- } else {
- throw new NamingException
- ("Cannot create resource instance");
+ if (t instanceof VirtualMachineError) {
+ throw (VirtualMachineError) t;
}
-
+ NamingException ex = new NamingException
+ ("Could not create resource factory instance");
+ ex.initCause(t);
+ throw ex;
}
+ return factory;
+ }
+ @Override
+ protected Object getLinked(Reference ref) throws NamingException {
+ // If ejb-link has been specified, resolving the link using JNDI
+ RefAddr linkRefAddr = ref.get(EjbRef.LINK);
+ if (linkRefAddr != null) {
+ // Retrieving the EJB link
+ String ejbLink = linkRefAddr.getContent().toString();
+ Object beanObj = (new InitialContext()).lookup(ejbLink);
+ return beanObj;
+ }
return null;
-
}
-
-
}
-
diff --git a/java/org/apache/naming/factory/FactoryBase.java b/java/org/apache/naming/factory/FactoryBase.java
new file mode 100644
index 0000000..a49c4b1
--- /dev/null
+++ b/java/org/apache/naming/factory/FactoryBase.java
@@ -0,0 +1,141 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.naming.factory;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+
+import org.apache.naming.StringManager;
+
+/**
+ * Abstract base class that provides common functionality required by
+ * sub-classes. This class exists primarily to reduce code duplication.
+ */
+public abstract class FactoryBase implements ObjectFactory {
+
+ private static final StringManager sm = StringManager.getManager(FactoryBase.class);
+
+ /**
+ * Creates a new object instance.
+ *
+ * @param obj The reference object describing the object to create
+ */
+ @Override
+ public final Object getObjectInstance(Object obj, Name name, Context nameCtx,
+ Hashtable<?,?> environment) throws Exception {
+
+ if (isReferenceTypeSupported(obj)) {
+ Reference ref = (Reference) obj;
+
+ Object linked = getLinked(ref);
+ if (linked != null) {
+ return linked;
+ }
+
+ ObjectFactory factory = null;
+ RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
+ if (factoryRefAddr != null) {
+ // Using the specified factory
+ String factoryClassName = factoryRefAddr.getContent().toString();
+ // Loading factory
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ Class<?> factoryClass = null;
+ try {
+ if (tcl != null) {
+ factoryClass = tcl.loadClass(factoryClassName);
+ } else {
+ factoryClass = Class.forName(factoryClassName);
+ }
+ } catch(ClassNotFoundException e) {
+ NamingException ex = new NamingException(sm.getString("factoryBase.factoryClassError"));
+ ex.initCause(e);
+ throw ex;
+ }
+ try {
+ factory = (ObjectFactory) factoryClass.getConstructor().newInstance();
+ } catch(Throwable t) {
+ if (t instanceof NamingException) {
+ throw (NamingException) t;
+ }
+ if (t instanceof ThreadDeath) {
+ throw (ThreadDeath) t;
+ }
+ if (t instanceof VirtualMachineError) {
+ throw (VirtualMachineError) t;
+ }
+ NamingException ex = new NamingException(sm.getString("factoryBase.factoryCreationError"));
+ ex.initCause(t);
+ throw ex;
+ }
+ } else {
+ // Check for a default factory
+ factory = getDefaultFactory(ref);
+ }
+
+ if (factory != null) {
+ return factory.getObjectInstance(obj, name, nameCtx, environment);
+ } else {
+ throw new NamingException(sm.getString("factoryBase.instanceCreationError"));
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Determines if this factory supports processing the provided reference
+ * object.
+ *
+ * @param obj The object to be processed
+ *
+ * @return <code>true</code> if this factory can process the object,
+ * otherwise <code>false</code>
+ */
+ protected abstract boolean isReferenceTypeSupported(Object obj);
+
+ /**
+ * If a default factory is available for the given reference type, create
+ * the default factory.
+ *
+ * @param ref The reference object to be processed
+ *
+ * @return The default factory for the given reference object or
+ * <code>null</code> if no default factory exists.
+ *
+ * @throws NamingException If the default factory cannot be created
+ */
+ protected abstract ObjectFactory getDefaultFactory(Reference ref)
+ throws NamingException;
+
+ /**
+ * If this reference is a link to another JNDI object, obtain that object.
+ *
+ * @param ref The reference object to be processed
+ *
+ * @return The linked object or <code>null</code> if linked objects are
+ * not supported by or not configured for this reference object
+ * @throws NamingException Error accessing linked object
+ */
+ protected abstract Object getLinked(Reference ref) throws NamingException;
+}
diff --git a/java/org/apache/naming/factory/LocalStrings.properties b/java/org/apache/naming/factory/LocalStrings.properties
index 628a2ac..692cef2 100644
--- a/java/org/apache/naming/factory/LocalStrings.properties
+++ b/java/org/apache/naming/factory/LocalStrings.properties
@@ -13,11 +13,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+dataSourceLinkFactory.badWrapper=Not a wrapper for type [{0}]
+
+factoryBase.factoryClassError=Could not load resource factory class
+factoryBase.factoryCreationError=Could not create resource factory instance
+factoryBase.instanceCreationError=Could not create resource instance
+
lookupFactory.circularReference=Found a circular reference involving [{0}]
lookupFactory.createFailed=Could not create instance of JNDI lookup factory class
lookupFactory.loadFailed=Could not load JNDI lookup factory class
lookupFactory.typeMismatch=The JNDI reference [{0}] was expected to be of type [{1}] but the lookup [{2}] return an object of type [{3}]
+resourceFactory.factoryCreationError=Could not create resource factory instance
+
+resourceLinkFactory.invalidGlobalContext=Caller provided invalid global context
resourceLinkFactory.nullType=The local resource link [{0}] that refers to global resource [{1}] does not specify the required attribute type
resourceLinkFactory.unknownType=The local resource link [{0}] that refers to global resource [{1}] specified the unknown type [{2}]
resourceLinkFactory.wrongType=The local resource link [{0}] that refers to global resource [{1}] was expected to return an instance of [{2}] but returned an instance of [{3}]
diff --git a/java/org/apache/naming/factory/LocalStrings_es.properties b/java/org/apache/naming/factory/LocalStrings_es.properties
new file mode 100644
index 0000000..926ef6e
--- /dev/null
+++ b/java/org/apache/naming/factory/LocalStrings_es.properties
@@ -0,0 +1,20 @@
+# 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+lookupFactory.createFailed=No se pudo crear una instancia de la clase de fábrica JNDI lookup\n
+lookupFactory.typeMismatch=La referencia JNDI [{0}] se esperaba que fuera de tipo [{1}] pero la búsqueda [{2}] devolvió un objeto tipo [{3}]
+
+resourceLinkFactory.nullType=El enlace del recurso local [{0}] que se refiere al recurso global [{1}] no especifica el atributo obligatorio "type"
+resourceLinkFactory.unknownType=El enlace del recurso local [{0}] que apunta al recurso global especificado [{1}] de tipo desconocido [{2}]\n
diff --git a/java/org/apache/naming/factory/LocalStrings_fr.properties b/java/org/apache/naming/factory/LocalStrings_fr.properties
new file mode 100644
index 0000000..18cc08f
--- /dev/null
+++ b/java/org/apache/naming/factory/LocalStrings_fr.properties
@@ -0,0 +1,28 @@
+# 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+dataSourceLinkFactory.badWrapper=Pas un enrobeur pour le type [{0}]
+
+lookupFactory.circularReference=Trouvé une référence circulaire avec [{0}]
+lookupFactory.createFailed=Echec de création de l'instance de la classe de fabrique de recherche JNDI
+lookupFactory.loadFailed=Echec de chargement de la classe de fabrique de recherche JNDI
+lookupFactory.typeMismatch=La référence JNDI [{0}] devrait être de type [{1}] mais la recherche [{2}] retourne un objet de type [{3}]
+
+resourceFactory.factoryCreationError=Impossible de créer une instance de la fabrique de ressources
+
+resourceLinkFactory.invalidGlobalContext=L'appelant a fourni un contexte global invalide
+resourceLinkFactory.nullType=Le lien local de resource [{0}] qui se réfère à la resource globale [{1}] ne spécifie pas le type d''attribut requis
+resourceLinkFactory.unknownType=Le lien local de resource [{0}] qui se réfère à la resource globale [{1}] a spécifié le type inconnu [{2}]
+resourceLinkFactory.wrongType=Le lien de ressource local [{0}] qui se réfère à la ressource globale [{1}] devait renvoyer une instance de [{2}] mais à renvoyé une instance de [{3}]
diff --git a/java/org/apache/naming/factory/LocalStrings_ja.properties b/java/org/apache/naming/factory/LocalStrings_ja.properties
new file mode 100644
index 0000000..0716753
--- /dev/null
+++ b/java/org/apache/naming/factory/LocalStrings_ja.properties
@@ -0,0 +1,28 @@
+# 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+dataSourceLinkFactory.badWrapper=クラス[{0}]のラッパーではありません。
+
+lookupFactory.circularReference=[{0}]を含む循環参照が見つかりました。
+lookupFactory.createFailed=JNDI lookup ファクトリークラスのインスタンスを作成できませんでした。
+lookupFactory.loadFailed=JNDIルックアップファクトリクラスをロードできませんでした。
+lookupFactory.typeMismatch=クラス [{1}] を期待する JNDI 参照 [{0}]に、lookup [{2}] はクラス [{3}] のオブジェクトを返却しました。
+
+resourceFactory.factoryCreationError=リソースファクトリーのインスタンスを作成できません。
+
+resourceLinkFactory.invalidGlobalContext=引数に不正な共通コンテキストが指定されました。
+resourceLinkFactory.nullType=グローバルリソース [{1}] を参照するローカルリソースリンク [{0}] に必要な属性がありません。
+resourceLinkFactory.unknownType=グローバルリソース [{1}] を参照するローカルリソースリンク [{0}] に未知のクラス [{2}] が指定されました。
+resourceLinkFactory.wrongType=グローバルリソース[{1}]を参照するローカルリソースリンク[{0}]は[{2}]のインスタンスを返すと予想されましたが、[{3}]のインスタンスを返しました。
diff --git a/java/org/apache/naming/factory/LookupFactory.java b/java/org/apache/naming/factory/LookupFactory.java
index 0a5e7b4..7f29dee 100644
--- a/java/org/apache/naming/factory/LookupFactory.java
+++ b/java/org/apache/naming/factory/LookupFactory.java
@@ -107,7 +107,7 @@ public class LookupFactory implements ObjectFactory {
}
if (factoryClass != null) {
try {
- factory = (ObjectFactory) factoryClass.newInstance();
+ factory = (ObjectFactory) factoryClass.getConstructor().newInstance();
} catch (Throwable t) {
if (t instanceof NamingException)
throw (NamingException) t;
diff --git a/java/org/apache/naming/factory/MailSessionFactory.java b/java/org/apache/naming/factory/MailSessionFactory.java
index ab32cca..fc87930 100644
--- a/java/org/apache/naming/factory/MailSessionFactory.java
+++ b/java/org/apache/naming/factory/MailSessionFactory.java
@@ -94,7 +94,7 @@ public class MailSessionFactory implements ObjectFactory {
// Return null if we cannot create an object of the requested type
final Reference ref = (Reference) refObj;
if (!ref.getClassName().equals(factoryType))
- return (null);
+ return null;
// Create a new Session inside a doPrivileged block, so that JavaMail
// can read its default properties without throwing Security
@@ -147,7 +147,7 @@ public class MailSessionFactory implements ObjectFactory {
// Create and return the new Session object
Session session = Session.getInstance(props, auth);
- return (session);
+ return session;
}
} );
diff --git a/java/org/apache/naming/factory/ResourceEnvFactory.java b/java/org/apache/naming/factory/ResourceEnvFactory.java
index 32919a4..b999c40 100644
--- a/java/org/apache/naming/factory/ResourceEnvFactory.java
+++ b/java/org/apache/naming/factory/ResourceEnvFactory.java
@@ -14,16 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.naming.factory;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
@@ -34,93 +26,22 @@ import org.apache.naming.ResourceEnvRef;
*
* @author Remy Maucherat
*/
-public class ResourceEnvFactory
- implements ObjectFactory {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- // -------------------------------------------------------------- Constants
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- // --------------------------------------------------------- Public Methods
-
+public class ResourceEnvFactory extends FactoryBase {
- // -------------------------------------------------- ObjectFactory Methods
-
-
- /**
- * Create a new Resource env instance.
- *
- * @param obj The reference object describing the DataSource
- */
@Override
- public Object getObjectInstance(Object obj, Name name, Context nameCtx,
- Hashtable<?,?> environment)
- throws Exception {
-
- if (obj instanceof ResourceEnvRef) {
- Reference ref = (Reference) obj;
- ObjectFactory factory = null;
- RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
- if (factoryRefAddr != null) {
- // Using the specified factory
- String factoryClassName =
- factoryRefAddr.getContent().toString();
- // Loading factory
- ClassLoader tcl =
- Thread.currentThread().getContextClassLoader();
- Class<?> factoryClass = null;
- if (tcl != null) {
- try {
- factoryClass = tcl.loadClass(factoryClassName);
- } catch(ClassNotFoundException e) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(e);
- throw ex;
- }
- } else {
- try {
- factoryClass = Class.forName(factoryClassName);
- } catch(ClassNotFoundException e) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(e);
- throw ex;
- }
- }
- if (factoryClass != null) {
- try {
- factory = (ObjectFactory) factoryClass.newInstance();
- } catch(Throwable t) {
- if (t instanceof NamingException)
- throw (NamingException) t;
- NamingException ex = new NamingException
- ("Could not create resource factory instance");
- ex.initCause(t);
- throw ex;
- }
- }
- }
- // Note: No defaults here
- if (factory != null) {
- return factory.getObjectInstance
- (obj, name, nameCtx, environment);
- } else {
- throw new NamingException
- ("Cannot create resource instance");
- }
- }
+ protected boolean isReferenceTypeSupported(Object obj) {
+ return obj instanceof ResourceEnvRef;
+ }
+ @Override
+ protected ObjectFactory getDefaultFactory(Reference ref) {
+ // No default factory supported.
return null;
-
}
-
+ @Override
+ protected Object getLinked(Reference ref) {
+ // Not supported
+ return null;
+ }
}
-
diff --git a/java/org/apache/naming/factory/ResourceFactory.java b/java/org/apache/naming/factory/ResourceFactory.java
index 734f3d3..a458315 100644
--- a/java/org/apache/naming/factory/ResourceFactory.java
+++ b/java/org/apache/naming/factory/ResourceFactory.java
@@ -14,142 +14,75 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.naming.factory;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.Name;
import javax.naming.NamingException;
-import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import org.apache.naming.ResourceRef;
+import org.apache.naming.StringManager;
/**
* Object factory for Resources.
*
* @author Remy Maucherat
*/
-public class ResourceFactory
- implements ObjectFactory {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- // -------------------------------------------------------------- Constants
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- // --------------------------------------------------------- Public Methods
-
+public class ResourceFactory extends FactoryBase {
- // -------------------------------------------------- ObjectFactory Methods
+ private static final StringManager sm = StringManager.getManager(ResourceFactory.class);
-
- /**
- * Crete a new DataSource instance.
- *
- * @param obj The reference object describing the DataSource
- */
@Override
- public Object getObjectInstance(Object obj, Name name, Context nameCtx,
- Hashtable<?,?> environment)
- throws Exception {
+ protected boolean isReferenceTypeSupported(Object obj) {
+ return obj instanceof ResourceRef;
+ }
- if (obj instanceof ResourceRef) {
- Reference ref = (Reference) obj;
- ObjectFactory factory = null;
- RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
- if (factoryRefAddr != null) {
- // Using the specified factory
- String factoryClassName =
- factoryRefAddr.getContent().toString();
- // Loading factory
- ClassLoader tcl =
- Thread.currentThread().getContextClassLoader();
- Class<?> factoryClass = null;
- if (tcl != null) {
- try {
- factoryClass = tcl.loadClass(factoryClassName);
- } catch(ClassNotFoundException e) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(e);
- throw ex;
- }
- } else {
- try {
- factoryClass = Class.forName(factoryClassName);
- } catch(ClassNotFoundException e) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(e);
- throw ex;
- }
+ @Override
+ protected ObjectFactory getDefaultFactory(Reference ref) throws NamingException {
+
+ ObjectFactory factory = null;
+
+ if (ref.getClassName().equals("javax.sql.DataSource")) {
+ String javaxSqlDataSourceFactoryClassName =
+ System.getProperty("javax.sql.DataSource.Factory",
+ Constants.DBCP_DATASOURCE_FACTORY);
+ try {
+ factory = (ObjectFactory) Class.forName(
+ javaxSqlDataSourceFactoryClassName).getConstructor().newInstance();
+ } catch (Exception e) {
+ NamingException ex = new NamingException(sm.getString("resourceFactory.factoryCreationError"));
+ ex.initCause(e);
+ throw ex;
+ }
+ } else if (ref.getClassName().equals("javax.mail.Session")) {
+ String javaxMailSessionFactoryClassName =
+ System.getProperty("javax.mail.Session.Factory",
+ "org.apache.naming.factory.MailSessionFactory");
+ try {
+ factory = (ObjectFactory) Class.forName(
+ javaxMailSessionFactoryClassName).getConstructor().newInstance();
+ } catch(Throwable t) {
+ if (t instanceof NamingException) {
+ throw (NamingException) t;
}
- if (factoryClass != null) {
- try {
- factory = (ObjectFactory) factoryClass.newInstance();
- } catch (Exception e) {
- if (e instanceof NamingException)
- throw (NamingException) e;
- NamingException ex = new NamingException
- ("Could not create resource factory instance");
- ex.initCause(e);
- throw ex;
- }
+ if (t instanceof ThreadDeath) {
+ throw (ThreadDeath) t;
}
- } else {
- if (ref.getClassName().equals("javax.sql.DataSource")) {
- String javaxSqlDataSourceFactoryClassName =
- System.getProperty("javax.sql.DataSource.Factory",
- Constants.DBCP_DATASOURCE_FACTORY);
- try {
- factory = (ObjectFactory)
- Class.forName(javaxSqlDataSourceFactoryClassName)
- .newInstance();
- } catch (Exception e) {
- NamingException ex = new NamingException
- ("Could not create resource factory instance");
- ex.initCause(e);
- throw ex;
- }
- } else if (ref.getClassName().equals("javax.mail.Session")) {
- String javaxMailSessionFactoryClassName =
- System.getProperty("javax.mail.Session.Factory",
- "org.apache.naming.factory.MailSessionFactory");
- try {
- factory = (ObjectFactory)
- Class.forName(javaxMailSessionFactoryClassName)
- .newInstance();
- } catch(Throwable t) {
- NamingException ex = new NamingException
- ("Could not create resource factory instance");
- ex.initCause(t);
- throw ex;
- }
+ if (t instanceof VirtualMachineError) {
+ throw (VirtualMachineError) t;
}
- }
- if (factory != null) {
- return factory.getObjectInstance
- (obj, name, nameCtx, environment);
- } else {
- throw new NamingException
- ("Cannot create resource instance");
+ NamingException ex = new NamingException(sm.getString("resourceFactory.factoryCreationError"));
+ ex.initCause(t);
+ throw ex;
}
}
- return null;
-
+ return factory;
}
-
+ @Override
+ protected Object getLinked(Reference ref) {
+ // Not supported
+ return null;
+ }
}
-
diff --git a/java/org/apache/naming/factory/ResourceLinkFactory.java b/java/org/apache/naming/factory/ResourceLinkFactory.java
index 6fe1dff..1b83fa4 100644
--- a/java/org/apache/naming/factory/ResourceLinkFactory.java
+++ b/java/org/apache/naming/factory/ResourceLinkFactory.java
@@ -40,7 +40,7 @@ public class ResourceLinkFactory implements ObjectFactory {
// ------------------------------------------------------- Static Variables
- private static final StringManager sm = StringManager.getManager(ResourceLinkFactory.class);
+ protected static final StringManager sm = StringManager.getManager(ResourceLinkFactory.class);
/**
* Global naming context.
@@ -102,7 +102,7 @@ public class ResourceLinkFactory implements ObjectFactory {
private static void validateGlobalContext(Context globalContext) {
if (ResourceLinkFactory.globalContext != null &&
ResourceLinkFactory.globalContext != globalContext) {
- throw new SecurityException("Caller provided invalid global context");
+ throw new SecurityException(sm.getString("resourceLinkFactory.invalidGlobalContext"));
}
}
diff --git a/java/org/apache/naming/factory/SendMailFactory.java b/java/org/apache/naming/factory/SendMailFactory.java
index d25621d..f8698da 100644
--- a/java/org/apache/naming/factory/SendMailFactory.java
+++ b/java/org/apache/naming/factory/SendMailFactory.java
@@ -41,33 +41,32 @@ import javax.naming.spi.ObjectFactory;
* of your server.xml configuration file.
* <p>
* Example:
- * <p>
* <pre>
* <Resource name="mail/send" auth="CONTAINER"
- * type="javax.mail.internet.MimePartDataSource"/>
- * <ResourceParams name="mail/send">
- * <parameter><name>factory</name>
- * <value>org.apache.naming.factory.SendMailFactory</value>
- * </parameter>
- * <parameter><name>mail.smtp.host</name>
- * <value>your.smtp.host</value>
- * </parameter>
- * <parameter><name>mail.smtp.user</name>
- * <value>someuser</value>
- * </parameter>
- * <parameter><name>mail.from</name>
- * <value>someuser@some.host</value>
- * </parameter>
- * <parameter><name>mail.smtp.sendpartial</name>
- * <value>true</value>
- * </parameter>
- * <parameter><name>mail.smtp.dsn.notify</name>
- * <value>FAILURE</value>
- * </parameter>
- * <parameter><name>mail.smtp.dsn.ret</name>
- * <value>FULL</value>
- * </parameter>
- * </ResourceParams>
+ * type="javax.mail.internet.MimePartDataSource"/>
+ * <ResourceParams name="mail/send">
+ * <parameter><name>factory</name>
+ * <value>org.apache.naming.factory.SendMailFactory</value>
+ * </parameter>
+ * <parameter><name>mail.smtp.host</name>
+ * <value>your.smtp.host</value>
+ * </parameter>
+ * <parameter><name>mail.smtp.user</name>
+ * <value>someuser</value>
+ * </parameter>
+ * <parameter><name>mail.from</name>
+ * <value>someuser@some.host</value>
+ * </parameter>
+ * <parameter><name>mail.smtp.sendpartial</name>
+ * <value>true</value>
+ * </parameter>
+ * <parameter><name>mail.smtp.dsn.notify</name>
+ * <value>FAILURE</value>
+ * </parameter>
+ * <parameter><name>mail.smtp.dsn.ret</name>
+ * <value>FULL</value>
+ * </parameter>
+ * </ResourceParams>
* </pre>
*
* @author Glenn Nielsen Rich Catlett
diff --git a/java/org/apache/naming/factory/TransactionFactory.java b/java/org/apache/naming/factory/TransactionFactory.java
index 5c7ecf5..e7aefb0 100644
--- a/java/org/apache/naming/factory/TransactionFactory.java
+++ b/java/org/apache/naming/factory/TransactionFactory.java
@@ -14,16 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.naming.factory;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
@@ -34,93 +26,22 @@ import org.apache.naming.TransactionRef;
*
* @author Remy Maucherat
*/
-public class TransactionFactory
- implements ObjectFactory {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- // -------------------------------------------------------------- Constants
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- // --------------------------------------------------------- Public Methods
-
+public class TransactionFactory extends FactoryBase {
- // -------------------------------------------------- ObjectFactory Methods
-
-
- /**
- * Create a new User transaction instance.
- *
- * @param obj The reference object describing the DataSource
- */
@Override
- public Object getObjectInstance(Object obj, Name name, Context nameCtx,
- Hashtable<?,?> environment)
- throws Exception {
-
- if (obj instanceof TransactionRef) {
- Reference ref = (Reference) obj;
- ObjectFactory factory = null;
- RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
- if (factoryRefAddr != null) {
- // Using the specified factory
- String factoryClassName =
- factoryRefAddr.getContent().toString();
- // Loading factory
- ClassLoader tcl =
- Thread.currentThread().getContextClassLoader();
- Class<?> factoryClass = null;
- if (tcl != null) {
- try {
- factoryClass = tcl.loadClass(factoryClassName);
- } catch(ClassNotFoundException e) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(e);
- throw ex;
- }
- } else {
- try {
- factoryClass = Class.forName(factoryClassName);
- } catch(ClassNotFoundException e) {
- NamingException ex = new NamingException
- ("Could not load resource factory class");
- ex.initCause(e);
- throw ex;
- }
- }
- if (factoryClass != null) {
- try {
- factory = (ObjectFactory) factoryClass.newInstance();
- } catch(Throwable t) {
- if (t instanceof NamingException)
- throw (NamingException) t;
- NamingException ex = new NamingException
- ("Could not create resource factory instance");
- ex.initCause(t);
- throw ex;
- }
- }
- }
- if (factory != null) {
- return factory.getObjectInstance
- (obj, name, nameCtx, environment);
- } else {
- throw new NamingException
- ("Cannot create resource instance");
- }
-
- }
+ protected boolean isReferenceTypeSupported(Object obj) {
+ return obj instanceof TransactionRef;
+ }
+ @Override
+ protected ObjectFactory getDefaultFactory(Reference ref) {
+ // No default factory supported.
return null;
-
}
-
+ @Override
+ protected Object getLinked(Reference ref) {
+ // Not supported
+ return null;
+ }
}
-
diff --git a/java/org/apache/naming/factory/package.html b/java/org/apache/naming/factory/package.html
index 5f65a4f..769d5e6 100644
--- a/java/org/apache/naming/factory/package.html
+++ b/java/org/apache/naming/factory/package.html
@@ -18,6 +18,4 @@
<p>This package contains object factories used by the naming service.</p>
-<p></p>
-
</body>
diff --git a/java/org/apache/naming/java/package.html b/java/org/apache/naming/java/package.html
index d3fcce1..2f5fe9e 100644
--- a/java/org/apache/naming/java/package.html
+++ b/java/org/apache/naming/java/package.html
@@ -18,6 +18,4 @@
<p>This package contains the URL context factory for the "java" namespace.</p>
-<p></p>
-
</body>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org