[portal-commits] JBoss Portal SVN: r5979 - in trunk: common/src/main/org/jboss/portal/common/util and 1 other directory.
portal-commits at lists.jboss.org
portal-commits at lists.jboss.org
Wed Jan 10 11:03:20 EST 2007
Author: julien at jboss.com
Date: 2007-01-10 11:03:11 -0500 (Wed, 10 Jan 2007)
New Revision: 5979
Modified:
trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java
trunk/common/src/main/org/jboss/portal/common/util/JNDI.java
Log:
- make JCRCMS uses JNDI binding utility
- added javadoc to JNDI binding utility
Modified: trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2007-01-10 15:47:37 UTC (rev 5978)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2007-01-10 16:03:11 UTC (rev 5979)
@@ -25,7 +25,6 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.jboss.cache.Version;
-import org.jboss.naming.NonSerializableFactory;
import org.jboss.portal.cms.CMS;
import org.jboss.portal.cms.CMSException;
import org.jboss.portal.cms.CMSMimeMappings;
@@ -47,6 +46,7 @@
import org.jboss.portal.common.net.URLVisitor;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
+import org.jboss.portal.common.util.JNDI;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.UserModule;
import org.jboss.portal.identity.IdentityServiceController;
@@ -65,7 +65,6 @@
import javax.jcr.Session;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import javax.naming.CompositeName;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
@@ -106,6 +105,8 @@
private String jndiName;
+ private JNDI.Binding jndiBinding;
+
private InvocationHandler handler = new InvocationHandler()
{
public Object invoke(Invocation invocation) throws Exception, InvocationException
@@ -271,7 +272,8 @@
{
if (this.jndiName != null)
{
- NonSerializableFactory.rebind(new CompositeName(this.jndiName), this, true);
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
}
//check the version of jbosscache being run
@@ -298,17 +300,11 @@
/** Shuts down the repo and unregisters it */
public void stopService()
{
- try
- {
- if (this.jndiName != null)
- {
- NonSerializableFactory.unbind(this.jndiName);
- }
- }
- catch(Exception e)
- {
- log.error(this, e);
- }
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
log.info("Stopping JCR CMS");
stopJCR();
// removeInterceptors();
Modified: trunk/common/src/main/org/jboss/portal/common/util/JNDI.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/JNDI.java 2007-01-10 15:47:37 UTC (rev 5978)
+++ trunk/common/src/main/org/jboss/portal/common/util/JNDI.java 2007-01-10 16:03:11 UTC (rev 5979)
@@ -26,14 +26,49 @@
import javax.naming.CompositeName;
import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
/**
+ * Various JNDI stuff.
+ *
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision$
*/
public class JNDI
{
+ /**
+ * Encapsulate JNDI binding operation into one single class, hidding non usefull JNDI complexity.
+ * It has been designed to fit with service life cycle.
+ *
+ * <code>
+ *
+ * private String jndiName;
+ * private JNDI.Binding jndiBinding;
+ *
+ * public void startService() throws Exception
+ * {
+ * ...
+ * if (this.jndiName != null)
+ * {
+ * jndiBinding = new JNDI.Binding(jndiName, this);
+ * jndiBinding.bind();
+ * }
+ * ...
+ * }
+ *
+ * public void stopService() throws Exception
+ * {
+ * ...
+ * if (jndiBinding != null)
+ * {
+ * jndiBinding.unbind();
+ * jndiBinding = null;
+ * }
+ * ...
+ * }
+ * </code>
+ */
public static class Binding
{
@@ -60,12 +95,20 @@
this.o = o;
}
- public void bind() throws Exception
+ /**
+ * Attempt to perform binding.
+ *
+ * @throws NamingException on failure
+ */
+ public void bind() throws NamingException
{
NonSerializableFactory.rebind(new CompositeName(jndiName), o, true);
unbindJNDIName = jndiName;
}
+ /**
+ * Unbinds in a safe manner.
+ */
public void unbind()
{
if (unbindJNDIName != null)
More information about the portal-commits
mailing list