|
Author: adrianc
Date: Mon Jul 12 03:28:34 2010 New Revision: 963178 URL: http://svn.apache.org/viewvc?rev=963178&view=rev Log: Set up the Jackrabbit container so it will register the local repository in JNDI. RepositoryFactory uses JNDI to get the local repository. This code is still mostly POC so it needs more work. Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/LocalRepositoryFactory.java (with props) Modified: ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java Modified: ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml?rev=963178&r1=963177&r2=963178&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml Mon Jul 12 03:28:34 2010 @@ -96,9 +96,13 @@ under the License. <!-- TODO: switch to webslinger, for per-site logging <container name="catalina-container" class="org.ofbiz.webslinger.WebslingerCatalinaContainer"> --> + + <!-- Load embedded Jackrabbit content repository. Since this container depends + upon JNDI, it must be started after the naming-container container.--> <container name="jackrabbit" class="org.ofbiz.jackrabbit.JackrabbitContainer"> <property name="repHomeDir" value="runtime/data/jackrabbit/"/> <property name="configFilePath" value="framework/jackrabbit/config/jackrabbit.xml"/> + <property name="jndiName" value="jcr/local"/> </container> <container name="catalina-container" class="org.ofbiz.catalina.container.CatalinaContainer"> Modified: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties?rev=963178&r1=963177&r2=963178&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties (original) +++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties Mon Jul 12 03:28:34 2010 @@ -21,9 +21,5 @@ # OFBiz Content Repository properties File #### -# Settings for embedded Jackrabbit repository -jackrabbit.repHomeDir=runtime/data/jackrabbit/ -jackrabbit.configFilePath=framework/jackrabbit/config/jackrabbit.xml - -# URL of external JCR-compliant repository -#jndi.repository.url=jcr-jackrabbit://jackrabbit \ No newline at end of file +# URL of JCR-compliant repository +jndi.repository.url=jcr/local \ No newline at end of file Modified: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java?rev=963178&r1=963177&r2=963178&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java Mon Jul 12 03:28:34 2010 @@ -29,6 +29,10 @@ import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.SimpleCredentials; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.naming.Reference; import org.apache.jackrabbit.core.TransientRepository; import org.ofbiz.base.container.Container; @@ -41,18 +45,18 @@ import org.ofbiz.entity.DelegatorFactory import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; -// TODO: Add support for remote and jndi based repositories? -// then use this container to register and start up an embedded instance only -// repository access for ofbiz should be provided for in a separate class - +/** + * A container for a local JCR-compliant content repository. The current + * implementation uses Apache Jackrabbit. + */ public class JackrabbitContainer implements Container { public static final String module = JackrabbitContainer.class.getName(); private static File homeDir = null; private static File jackrabbitConfigFile = null; - - private static Repository repository; + private static String jndiName; + protected static Repository repository; private static Session session; @Override @@ -61,6 +65,7 @@ public class JackrabbitContainer impleme String homeDirURL; try { homeDirURL = ContainerConfig.getPropertyValue(cc, "repHomeDir", "runtime/data/jackrabbit/"); + jndiName = ContainerConfig.getPropertyValue(cc, "jndiName", "jcr/local"); homeDir = new File(homeDirURL); URL jackrabbitConfigUrl = FlexibleLocation.resolveLocation(ContainerConfig.getPropertyValue(cc, "configFilePath", "framework/jackrabbit/config/jackrabbit.xml")); jackrabbitConfigFile = new File(jackrabbitConfigUrl.toURI()); @@ -75,7 +80,6 @@ public class JackrabbitContainer impleme @Override public boolean start() throws ContainerException { repository = new TransientRepository(jackrabbitConfigFile, homeDir); -// repository = RepositoryFactory.getRepository(); try { Delegator delegator = DelegatorFactory.getDelegator("default"); GenericValue userLogin = delegator.findOne("UserLogin", true, "userLoginId", "system"); @@ -88,11 +92,26 @@ public class JackrabbitContainer impleme } catch (GenericEntityException e) { Debug.logError(e, module); } + try { + Reference ref = new Reference(Repository.class.getName(), LocalRepositoryFactory.class.getName(), null); + Context context = new InitialContext(); + context.bind(jndiName, ref); + } catch (NamingException e) { + Debug.logError(e, module); + } + // Test JNDI bind + RepositoryFactory.getRepository(); return true; } @Override public void stop() throws ContainerException { + try { + Context context = new InitialContext(); + context.unbind(jndiName); + } catch (NamingException e) { + Debug.logError(e, module); + } if (session != null) { session.logout(); } Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/LocalRepositoryFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/LocalRepositoryFactory.java?rev=963178&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/LocalRepositoryFactory.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/LocalRepositoryFactory.java Mon Jul 12 03:28:34 2010 @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.ofbiz.jackrabbit; + +import java.util.Hashtable; + +import javax.jcr.Repository; +import javax.naming.Context; +import javax.naming.Name; +import javax.naming.Reference; +import javax.naming.spi.ObjectFactory; + +/** + * An <code>ObjectFactory</code> that returns a <code>javax.jcr.Repository</code> + * instance. + */ +public class LocalRepositoryFactory implements ObjectFactory { + + @Override + public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { + if (obj instanceof Reference) { + Reference ref = (Reference)obj; + if (ref.getClassName().equals(Repository.class.getName())) { + return JackrabbitContainer.repository; + } + } + return null; + } +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/LocalRepositoryFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/LocalRepositoryFactory.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/LocalRepositoryFactory.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java?rev=963178&r1=963177&r2=963178&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java Mon Jul 12 03:28:34 2010 @@ -18,17 +18,10 @@ *******************************************************************************/ package org.ofbiz.jackrabbit; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; - import javax.jcr.Repository; import javax.naming.InitialContext; import javax.naming.NamingException; -import org.apache.jackrabbit.core.TransientRepository; -import org.ofbiz.base.location.FlexibleLocation; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; @@ -38,14 +31,6 @@ public class RepositoryFactory { public static final String module = RepositoryFactory.class.getName(); private static final Repository repository = createRepoInstance(); - private static Repository createEmbedded() throws MalformedURLException, URISyntaxException { - String homeDirURL = UtilProperties.getPropertyValue("repository.properties", "jackrabbit.repHomeDir"); - String configFilePath = UtilProperties.getPropertyValue("repository.properties", "jackrabbit.configFilePath"); - File homeDir = new File(homeDirURL); - URL configUrl = FlexibleLocation.resolveLocation(configFilePath); - return new TransientRepository(new File(configUrl.toURI()), homeDir); - } - private static Repository createRepoInstance() { Repository result = null; try { @@ -53,13 +38,7 @@ public class RepositoryFactory { } catch (Exception e) { Debug.logError(e, module); } - if (result == null) { - try { - result = createEmbedded(); - } catch (Exception e) { - Debug.logError(e, module); - } - } + Debug.logInfo("JNDI lookup returned " + result, module); return result; } |
| Free forum by Nabble | Edit this page |
