Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 17553 invoked from network); 4 Aug 2007 11:25:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Aug 2007 11:25:04 -0000 Received: (qmail 42380 invoked by uid 500); 4 Aug 2007 11:25:04 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 42354 invoked by uid 500); 4 Aug 2007 11:25:04 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 42344 invoked by uid 99); 4 Aug 2007 11:25:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Aug 2007 04:25:03 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Aug 2007 11:24:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6DF4F1A981A; Sat, 4 Aug 2007 04:24:35 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r562695 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: RepositoryImpl.java config/RepositoryConfig.java Date: Sat, 04 Aug 2007 11:24:34 -0000 To: commits@jackrabbit.apache.org From: reschke@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070804112435.6DF4F1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: reschke Date: Sat Aug 4 04:24:32 2007 New Revision: 562695 URL: http://svn.apache.org/viewvc?view=rev&rev=562695 Log: JCR-1009: make JCR2SPI's RepositoryImpl referenceable in case if the underlying RepositoryConfig instance itself is referenceable. Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/RepositoryImpl.java jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/config/RepositoryConfig.java Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/RepositoryImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/RepositoryImpl.java?view=diff&rev=562695&r1=562694&r2=562695 ============================================================================== --- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/RepositoryImpl.java (original) +++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/RepositoryImpl.java Sat Aug 4 04:24:32 2007 @@ -16,30 +16,42 @@ */ package org.apache.jackrabbit.jcr2spi; -import org.apache.jackrabbit.jcr2spi.config.RepositoryConfig; -import org.apache.jackrabbit.spi.SessionInfo; -import org.apache.jackrabbit.spi.XASessionInfo; -import org.slf4j.LoggerFactory; -import org.slf4j.Logger; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Map; -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import javax.jcr.Credentials; import javax.jcr.LoginException; import javax.jcr.NoSuchWorkspaceException; -import java.util.Map; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.naming.Context; +import javax.naming.Name; +import javax.naming.NamingException; +import javax.naming.RefAddr; +import javax.naming.Reference; +import javax.naming.Referenceable; +import javax.naming.StringRefAddr; +import javax.naming.spi.ObjectFactory; + +import org.apache.jackrabbit.jcr2spi.config.RepositoryConfig; +import org.apache.jackrabbit.spi.SessionInfo; +import org.apache.jackrabbit.spi.XASessionInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * RepositoryImpl... */ -public class RepositoryImpl implements Repository { +public class RepositoryImpl implements Repository, Referenceable { private static Logger log = LoggerFactory.getLogger(RepositoryImpl.class); // configuration of the repository private final RepositoryConfig config; private final Map descriptors; + private Reference reference = null; private RepositoryImpl(RepositoryConfig config) throws RepositoryException { this.config = config; @@ -103,5 +115,108 @@ */ public Session login() throws LoginException, NoSuchWorkspaceException, RepositoryException { return login(null, null); + } + + //---------------------------------------------------------< Rereferencable >--- + + /** + * @see Referenceable#getReference() + */ + public Reference getReference() throws NamingException { + if (config instanceof Referenceable) { + Referenceable confref = (Referenceable)config; + if (reference == null) { + reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null); + // carry over all addresses from referenceable config + for (Enumeration en = confref.getReference().getAll(); en.hasMoreElements(); ) { + reference.add((RefAddr)(en.nextElement())); + } + + // also add the information required by factory class + reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName())); + reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName())); + } + + return reference; + } + else { + throw new javax.naming.OperationNotSupportedException("Contained RepositoryConfig needs to implement javax.naming.Referenceable"); + } + } + + /** + * Implementation of {@link ObjectFactory} for repository instances. + *

+ * Works by creating a {@link Reference} to a {@link RepositoryConfig} + * instance based on the information obtained from the {@link RepositoryImpl}'s + * {@link Reference}. + *

+ * Address Types: + *

+ *
{@link #RCF} + *
Class name for {@link ObjectFactory} creating instances of {@link RepositoryConfig}
+ *
{@link #RCC} + *
Class name for {@link RepositoryConfig} instances
+ *
+ *

+ * All other types are copied over verbatim to the new {@link Reference} + */ + public static class Factory implements ObjectFactory { + + public static final String RCF = RepositoryImpl.class.getName() + ".factory"; + public static final String RCC = RepositoryImpl.class.getName() + ".class"; + + public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { + + Object res = null; + if (obj instanceof Reference) { + Reference ref = (Reference)obj; + String classname = ref.getClassName(); + + if (RepositoryImpl.class.getName().equals(classname)) { + + RefAddr rfac = ref.get(RCF); + if (rfac == null || !(rfac instanceof StringRefAddr)) { + throw new Exception("Address type " + RCF + " missing or of wrong class: " + rfac); + } + String configFactoryClassName = (String)((StringRefAddr)rfac).getContent(); + + RefAddr rclas = ref.get(RCC); + if (rclas == null || !(rclas instanceof StringRefAddr)) { + throw new Exception("Address type " + RCC + " missing or of wrong class: " + rclas); + } + String repositoryConfigClassName = (String)((StringRefAddr)rclas).getContent(); + + Object rof = Class.forName(configFactoryClassName).newInstance(); + + if (! (rof instanceof ObjectFactory)) { + throw new Exception(rof + " must implement ObjectFactory"); + } + + ObjectFactory of = (ObjectFactory)rof; + Reference newref = new Reference(repositoryConfigClassName, + configFactoryClassName, null); + + // carry over all arguments except our own + for (Enumeration en = ref.getAll(); en.hasMoreElements(); ){ + RefAddr ra = (RefAddr)en.nextElement(); + String type = ra.getType(); + if (! RCF.equals(type) && ! RCC.equals(type)) { + newref.add(ra); + } + } + + Object config = of.getObjectInstance(newref, name, nameCtx, environment); + if (! (config instanceof RepositoryConfig)) { + throw new Exception(config + " must implement RepositoryConfig"); + } + return RepositoryImpl.create((RepositoryConfig)config); + } + else { + throw new Exception("Unexpected class: " + classname); + } + } + return res; + } } } Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/config/RepositoryConfig.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/config/RepositoryConfig.java?view=diff&rev=562695&r1=562694&r2=562695 ============================================================================== --- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/config/RepositoryConfig.java (original) +++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/config/RepositoryConfig.java Sat Aug 4 04:24:32 2007 @@ -22,7 +22,12 @@ import javax.jcr.ValueFactory; /** - * RepositoryConfig... + * This class bundles the information required by JCR2SPI to + * bootstrap an SPI implementation. + *

+ * Instances of this class should implement + * {@link javax.naming.Referenceable} in order to make JCR2SPI's + * {@link javax.jcr.Repository} itself referenceable. */ public interface RepositoryConfig {