KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > repository > remoterep > Model3JackrabbitRepository


1 /**
2  * VC Browser - Visualizes the content of a JSR 170 compatible repository
3  * Copyright (C) 2006 Sandro Böhme
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.visualcontent.repository.remoterep;
19
20 import java.net.MalformedURLException JavaDoc;
21 import java.rmi.NotBoundException JavaDoc;
22 import java.rmi.RemoteException JavaDoc;
23
24 import javax.jcr.Repository;
25
26 import org.visualcontent.repository.remoterep.preferences.PreferenceConstants;
27 import org.visualcontent.extensionpoints.RepositoryThrowable;
28 import org.visualcontent.extensionpoints.VCRepository;
29 import org.visualcontent.extensionpoints.VCSession;
30 import org.apache.jackrabbit.rmi.client.ClientRepositoryFactory;
31 import org.eclipse.core.runtime.CoreException;
32 import org.eclipse.core.runtime.IConfigurationElement;
33 import org.eclipse.core.runtime.IExtensionRegistry;
34 import org.eclipse.core.runtime.Platform;
35  
36
37 public class Model3JackrabbitRepository implements VCRepository {
38     private static final String JavaDoc VALID_SESSION_ID = "org.visualcontent.authentication.simplecredentials.SimpleAuthenticationService";
39
40     public Repository getRepository() throws RepositoryThrowable {
41         String JavaDoc host= Model3JackrabbitRepositoryPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_HOST); // e.g. localhost
42
String JavaDoc port=Model3JackrabbitRepositoryPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_PORT); // e.g. "1100";
43
String JavaDoc repositoryName=Model3JackrabbitRepositoryPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_REPOSITORY_NAME); // e.g. "jackrabbit.repository";
44
String JavaDoc rmiUrl = "rmi://"+host+":"+port+"/"+repositoryName;
45         ClientRepositoryFactory factory = new ClientRepositoryFactory();
46         Repository repository = null;
47         try {
48             repository = factory.getRepository(rmiUrl);
49         } catch (ClassCastException JavaDoc e) {
50             Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not connect to remote JCR-Server using the following RMI-URL: "+rmiUrl,e);
51         } catch (MalformedURLException JavaDoc e) {
52             Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not connect to remote JCR-Server using the following RMI-URL: "+rmiUrl,e);
53         } catch (RemoteException JavaDoc e) {
54             Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not connect to remote JCR-Server using the following RMI-URL: "+rmiUrl,e);
55         } catch (NotBoundException JavaDoc e) {
56             Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not connect to remote JCR-Server using the following RMI-URL: "+rmiUrl,e);
57         }
58
59         return repository;
60     }
61
62     public void releaseRepository() throws RepositoryThrowable {
63
64     }
65
66     public String JavaDoc[] getValidSessions() {
67         return new String JavaDoc[]{VALID_SESSION_ID};
68     }
69
70
71     public VCSession getCurrentVCSession() {
72         IExtensionRegistry registry = Platform.getExtensionRegistry ();
73         IConfigurationElement[] sessionConfigElements = registry.getConfigurationElementsFor("org.visualcontent.extensionpoints.VCSession");
74         VCSession session = null;
75         for (int i = 0; i < sessionConfigElements.length && session==null; i++) {
76             try {
77                 if (Model3JackrabbitRepository.VALID_SESSION_ID.equals(sessionConfigElements[i].getAttribute("id"))){
78                     session = (VCSession) sessionConfigElements[i].createExecutableExtension("class");
79                 }
80             } catch (CoreException e) {
81                 Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not create the VCSession instance.",e);
82             } catch (Throwable JavaDoc t){
83                 Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not create the VCSession instance.",t);
84             }
85         }
86         return session;
87     }
88 }
89
Popular Tags