Author: tdraier
Date: Mon Nov 19 12:12:53 2007
New Revision: 19214
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19214&repname=
=3Djahia
Log:
added jackrabbit factory with variables resolution for file paths
Added:
branches/JAHIA-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/org/=
apache/
branches/JAHIA-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/org/=
apache/jackrabbit/
branches/JAHIA-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/org/=
apache/jackrabbit/core/
branches/JAHIA-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/org/=
apache/jackrabbit/core/jndi/
branches/JAHIA-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/org/=
apache/jackrabbit/core/jndi/JahiaBindableRepositoryFactory.java
Added: branches/JAHIA-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/o=
rg/apache/jackrabbit/core/jndi/JahiaBindableRepositoryFactory.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/org/apache/jackrabbit/=
core/jndi/JahiaBindableRepositoryFactory.java&rev=3D19214&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/org/=
apache/jackrabbit/core/jndi/JahiaBindableRepositoryFactory.java (added)
+++ branches/JAHIA-5-0-3-DMS-JACKRABBIT-BRANCH/jackrabbit-ext/src/java/org/=
apache/jackrabbit/core/jndi/JahiaBindableRepositoryFactory.java Mon Nov 19 =
12:12:53 2007
@@ -0,0 +1,107 @@
+/*
+ * 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.jackrabbit.core.jndi;
+
+import org.apache.commons.collections.map.ReferenceMap;
+
+import javax.jcr.RepositoryException;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+/**
+ * <code>JahiaBindableRepositoryFactory</code> is an object factory that w=
hen given
+ * a reference for a <code>BindableRepository</code> object, will create an
+ * instance of the corresponding <code>BindableRepository</code>.
+ */
+public class JahiaBindableRepositoryFactory implements ObjectFactory {
+
+ /**
+ * cache using <code>java.naming.Reference</code> objects as keys and
+ * storing soft references to <code>BindableRepository</code> instances
+ */
+ private static Map cache =3D new ReferenceMap(ReferenceMap.HARD, Refer=
enceMap.SOFT);
+
+ /**
+ * empty default constructor
+ */
+ public JahiaBindableRepositoryFactory() {
+ }
+
+ /**
+ * Creates an initialized BindableRepository instance using the given
+ * configuration information and puts it in [EMAIL PROTECTED] #cache}.
+ *
+ * @param configFilePath repository configuration file path
+ * @param repHomeDir repository home directory path
+ * @return initialized repository instance
+ * @throws RepositoryException if the repository cannot be created
+ */
+ static BindableRepository createInstance(String configFilePath, String=
repHomeDir)
+ throws RepositoryException {
+ BindableRepository rep =3D BindableRepository.create(configFilePat=
h, repHomeDir);
+ cache.put(rep.getReference(), rep);
+ return rep;
+ }
+
+ //--------------------------------------------------------< ObjectFact=
ory >
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+ Hashtable environment)
+ throws Exception {
+ if (obj instanceof Reference) {
+ Reference ref =3D (Reference) obj;
+ synchronized (cache) {
+ if (cache.containsKey(ref)) {
+ return cache.get(ref);
+ } else {
+ String configFilePath =3D resolvePath((String) ref.get=
(BindableRepository.CONFIGFILEPATH_ADDRTYPE).getContent());
+ String repHomeDir =3D resolvePath((String) ref.get(Bin=
dableRepository.REPHOMEDIR_ADDRTYPE).getContent());
+ return createInstance(configFilePath, repHomeDir);
+ }
+ }
+ }
+ return null;
+ }
+
+ public String resolvePath (String path) {
+ Pattern p =3D Pattern.compile("(.*)\\$\\{(.*)\\}(.*)");
+ Matcher m =3D p.matcher(path);
+ while (m.matches()) {
+ String key =3D m.group(2);
+ String value =3D System.getProperty(key);
+ if (value =3D=3D null) {
+ value =3D System.getenv(key);
+ }
+ if (value !=3D null) {
+ path =3D m.group(1) + value + m.group(3);
+ } else {
+ path =3D m.group(1) + m.group(3);
+ }
+ m.reset();
+ m =3D p.matcher(path);
+ }
+ return path;
+ }
+}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list