1 17 package org.alfresco.jcr.tck; 18 19 import java.util.Hashtable ; 20 21 import javax.jcr.Repository; 22 import javax.naming.Context ; 23 import javax.naming.InitialContext ; 24 import javax.naming.NamingException ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServlet ; 27 28 import org.alfresco.jcr.repository.RepositoryFactory; 29 import org.alfresco.jcr.repository.RepositoryImpl; 30 import org.alfresco.jcr.test.TestData; 31 import org.springframework.web.context.WebApplicationContext; 32 import org.springframework.web.context.support.WebApplicationContextUtils; 33 34 35 40 public class RepositoryStartupServlet extends HttpServlet 41 { 42 private static final long serialVersionUID = -4763518135895358778L; 43 44 private static InitialContext jndiContext; 45 46 private final static String repositoryName = "Alfresco.Repository"; 47 48 49 54 public void init() 55 throws ServletException 56 { 57 super.init(); 58 59 WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); 60 RepositoryImpl repository = (RepositoryImpl)context.getBean(RepositoryFactory.REPOSITORY_BEAN); 61 repository.setDefaultWorkspace(TestData.TEST_WORKSPACE); 62 63 try 64 { 65 Hashtable <String , String > env = new Hashtable <String , String >(); 66 env.put(Context.PROVIDER_URL, "http://www.alfresco.org"); 67 env.put(Context.INITIAL_CONTEXT_FACTORY, "com.day.crx.jndi.provider.MemoryInitialContextFactory"); 68 jndiContext = new InitialContext (env); 69 jndiContext.bind(repositoryName, (Repository)repository); 70 } 71 catch (NamingException e) 72 { 73 throw new ServletException (e); 74 } 75 } 76 77 80 public void destroy() 81 { 82 super.destroy(); 83 84 if (jndiContext != null) 85 { 86 try 87 { 88 jndiContext.unbind(repositoryName); 89 } 90 catch (NamingException e) 91 { 92 } 94 } 95 } 96 97 98 } 99 | Popular Tags |