1 18 package org.visualcontent.repository.remoterep; 19 20 import java.net.MalformedURLException ; 21 import java.rmi.NotBoundException ; 22 import java.rmi.RemoteException ; 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 VALID_SESSION_ID = "org.visualcontent.authentication.simplecredentials.SimpleAuthenticationService"; 39 40 public Repository getRepository() throws RepositoryThrowable { 41 String host= Model3JackrabbitRepositoryPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_HOST); String port=Model3JackrabbitRepositoryPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_PORT); String repositoryName=Model3JackrabbitRepositoryPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_REPOSITORY_NAME); String rmiUrl = "rmi://"+host+":"+port+"/"+repositoryName; 45 ClientRepositoryFactory factory = new ClientRepositoryFactory(); 46 Repository repository = null; 47 try { 48 repository = factory.getRepository(rmiUrl); 49 } catch (ClassCastException e) { 50 Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not connect to remote JCR-Server using the following RMI-URL: "+rmiUrl,e); 51 } catch (MalformedURLException e) { 52 Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not connect to remote JCR-Server using the following RMI-URL: "+rmiUrl,e); 53 } catch (RemoteException e) { 54 Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not connect to remote JCR-Server using the following RMI-URL: "+rmiUrl,e); 55 } catch (NotBoundException 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 [] getValidSessions() { 67 return new String []{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 t){ 83 Model3JackrabbitRepositoryPlugin.getDefault().showError("Could not create the VCSession instance.",t); 84 } 85 } 86 return session; 87 } 88 } 89 | Popular Tags |