You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/02/18 15:55:21 UTC
svn commit: r628768 - in /incubator/sling/trunk/jcr: base/ base/src/
base/src/main/ base/src/main/java/ base/src/main/java/org/
base/src/main/java/org/apache/ base/src/main/java/org/apache/sling/
base/src/main/java/org/apache/sling/jcr/ base/src/main/j...
Author: bdelacretaz
Date: Mon Feb 18 06:55:19 2008
New Revision: 628768
URL: http://svn.apache.org/viewvc?rev=628768&view=rev
Log:
SLING-254 - JNDI/RMI Repository access code moved to RepositoryAccessor class in new jcr/base module
Added:
incubator/sling/trunk/jcr/base/
incubator/sling/trunk/jcr/base/pom.xml (with props)
incubator/sling/trunk/jcr/base/src/
incubator/sling/trunk/jcr/base/src/main/
incubator/sling/trunk/jcr/base/src/main/java/
incubator/sling/trunk/jcr/base/src/main/java/org/
incubator/sling/trunk/jcr/base/src/main/java/org/apache/
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/
incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java (with props)
Modified:
incubator/sling/trunk/jcr/jackrabbit-client/pom.xml
incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java
incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties
Added: incubator/sling/trunk/jcr/base/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base/pom.xml?rev=628768&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/base/pom.xml (added)
+++ incubator/sling/trunk/jcr/base/pom.xml Mon Feb 18 06:55:19 2008
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>1-incubator-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.jcr.base</artifactId>
+ <packaging>bundle</packaging>
+ <version>2.0.0-incubator-SNAPSHOT</version>
+
+ <name>Sling - JCR Base Bundle</name>
+ <description>
+ The JCR base bundle provides JCR utility classes
+ </description>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/base
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/base
+ </developerConnection>
+ <url>
+ http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base
+ </url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Category>
+ sling,jcr,jackrabbit
+ </Bundle-Category>
+ <Export-Package>
+ org.apache.sling.jcr.base.util;version=${pom.version},
+ </Export-Package>
+ <Private-Package>
+ org.apache.jackrabbit.rmi.*
+ </Private-Package>
+ <Import-Package>
+ org.apache.xml.*; resolution:=optional, *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-rmi</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: incubator/sling/trunk/jcr/base/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java?rev=628768&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java (added)
+++ incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java Mon Feb 18 06:55:19 2008
@@ -0,0 +1,99 @@
+/*
+ * 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.sling.jcr.base.util;
+
+import java.util.Hashtable;
+
+import javax.jcr.Repository;
+import javax.naming.InitialContext;
+
+import org.apache.jackrabbit.rmi.client.ClientAdapterFactory;
+import org.apache.jackrabbit.rmi.client.ClientRepositoryFactory;
+import org.apache.jackrabbit.rmi.client.LocalAdapterFactory;
+import org.apache.jackrabbit.rmi.remote.RemoteRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Access a Repository via JNDI or RMI. */
+ public class RepositoryAccessor {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ /** Prefix for RMI Repository URLs */
+ public static final String RMI_PREFIX = "rmi://";
+
+ /** First try to access the Repository via JNDI (unless jndiContext is null), and if
+ * not successful try RMI.
+ *
+ * @param repositoryName JNDI name or RMI URL (must start with "rmi://") of the Repository
+ * @param jndiContext if null, JNDI is not tried
+ * @return a Repository, or null if not found
+ */
+ public Repository getRepository(String repositoryName, Hashtable<String, Object> jndiContext) {
+
+ Repository result = null;
+
+ if(jndiContext == null) {
+ log.info("jndiContext is null, not trying JNDI");
+ } else {
+ log.debug("Trying to acquire Repository '" + repositoryName + "' via JNDI, context=" + jndiContext);
+ final ClassLoader old = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ InitialContext initialContext = new InitialContext(jndiContext);
+ Object repoObject = initialContext.lookup(repositoryName);
+ if (repoObject instanceof Repository) {
+ result = (Repository) repoObject;
+ log.info("Acquired Repository '" + repositoryName + "' via JNDI");
+
+ } else if (repoObject instanceof RemoteRepository) {
+ RemoteRepository remoteRepo = (RemoteRepository) repoObject;
+ LocalAdapterFactory laf = new ClientAdapterFactory();
+ result = laf.getRepository(remoteRepo);
+ log.info("Acquired RemoteRepository '" + repositoryName + "' via JNDI");
+ }
+
+ } catch (Throwable t) {
+ log.debug("Unable to acquire Repository '" + repositoryName + "' via JNDI, context=" + jndiContext, t);
+ } finally {
+ Thread.currentThread().setContextClassLoader(old);
+ }
+ }
+
+ if(result == null) {
+ if(repositoryName==null || !repositoryName.startsWith(RMI_PREFIX)) {
+ log.info("Repository name does not start with '" + RMI_PREFIX + "', not trying RMI");
+ } else {
+ try {
+ log.debug("Trying to acquire Repository '" + repositoryName + "' via RMI");
+ ClientRepositoryFactory crf = new ClientRepositoryFactory();
+ result = crf.getRepository(repositoryName);
+ log.info("Acquired Repository '" + repositoryName + "' via RMI");
+ } catch (Throwable t) {
+ log.debug("Unable to acquire Repository '" + repositoryName + "' via RMI", t);
+ }
+ }
+ }
+
+ if(result == null) {
+ log.info("Unable to acquire Repository '" + repositoryName + "'");
+ }
+
+ return result;
+ }
+}
Propchange: incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/jcr/base/src/main/java/org/apache/sling/jcr/base/util/RepositoryAccessor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: incubator/sling/trunk/jcr/jackrabbit-client/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-client/pom.xml?rev=628768&r1=628767&r2=628768&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-client/pom.xml (original)
+++ incubator/sling/trunk/jcr/jackrabbit-client/pom.xml Mon Feb 18 06:55:19 2008
@@ -92,6 +92,12 @@
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.base</artifactId>
+ <version>2.0.0-incubator-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.jcr.api</artifactId>
<version>2.0.0-incubator-SNAPSHOT</version>
</dependency>
Modified: incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java?rev=628768&r1=628767&r2=628768&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java (original)
+++ incubator/sling/trunk/jcr/jackrabbit-client/src/main/java/org/apache/sling/jcr/jackrabbit/client/SlingClientRepository.java Mon Feb 18 06:55:19 2008
@@ -24,14 +24,10 @@
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
-import javax.naming.InitialContext;
-import org.apache.jackrabbit.rmi.client.ClientAdapterFactory;
-import org.apache.jackrabbit.rmi.client.ClientRepositoryFactory;
-import org.apache.jackrabbit.rmi.client.LocalAdapterFactory;
-import org.apache.jackrabbit.rmi.remote.RemoteRepository;
import org.apache.sling.jcr.api.AbstractSlingRepository;
import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.base.util.RepositoryAccessor;
import org.osgi.service.log.LogService;
/**
@@ -111,36 +107,12 @@
throw new RepositoryException("Missing property 'name'");
}
- // try JNDI
- Hashtable<String, Object> jndiContext = this.fromDictionary(environment);
- ClassLoader old = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
- InitialContext initialContext = new InitialContext(jndiContext);
- Object repoObject = initialContext.lookup(repoName);
- if (repoObject instanceof Repository) {
- return (Repository) repoObject;
-
- } else if (repoObject instanceof RemoteRepository) {
- RemoteRepository remoteRepo = (RemoteRepository) repoObject;
- LocalAdapterFactory laf = new ClientAdapterFactory();
- return laf.getRepository(remoteRepo);
- }
- } catch (Throwable t) {
- this.getLog().log(LogService.LOG_INFO, "Problem checking JNDI for " + repoName, t);
- } finally {
- Thread.currentThread().setContextClassLoader(old);
+ final Hashtable<String, Object> jndiContext = this.fromDictionary(environment);
+ final Repository repo = new RepositoryAccessor().getRepository(repoName, jndiContext);
+ if(repo == null) {
+ throw new RepositoryException("Cannot acquire repository '" + repoName + "'");
}
-
- try {
- ClientRepositoryFactory crf = new ClientRepositoryFactory();
- return crf.getRepository(repoName);
- } catch (Throwable t) {
- this.getLog().log(LogService.LOG_INFO, "Problem checking RMI for " + repoName, t);
- }
-
- // finally there is no way to find a repository
- throw new RepositoryException("Cannot find repository " + repoName);
+ return repo;
}
Modified: incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=628768&r1=628767&r2=628768&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ incubator/sling/trunk/jcr/jackrabbit-client/src/main/resources/OSGI-INF/metatype/metatype.properties Mon Feb 18 06:55:19 2008
@@ -80,5 +80,5 @@
name.name = Repository Name
name.description = The name under which the repository will be looked up in \
- the JNDI or RMI. In the case of RMI, this must be a standard RMI URL of the \
- form "//host[:port]/name".
\ No newline at end of file
+ the JNDI or RMI. For RMI, this must be a standard RMI URL of the \
+ form "rmi://host[:port]/name".
\ No newline at end of file