KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > jcr > tck > RepositoryStartupServlet


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.jcr.tck;
18
19 import java.util.Hashtable JavaDoc;
20
21 import javax.jcr.Repository;
22 import javax.naming.Context JavaDoc;
23 import javax.naming.InitialContext JavaDoc;
24 import javax.naming.NamingException JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.http.HttpServlet JavaDoc;
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 /**
36  * Setup Repository for access via JNDI by TCK Web Application
37  *
38  * @author David Caruana
39  */

40 public class RepositoryStartupServlet extends HttpServlet JavaDoc
41 {
42     private static final long serialVersionUID = -4763518135895358778L;
43
44     private static InitialContext JavaDoc jndiContext;
45     
46     private final static String JavaDoc repositoryName = "Alfresco.Repository";
47
48     
49     /**
50      * Initializes the servlet
51      *
52      * @throws ServletException
53      */

54     public void init()
55         throws ServletException JavaDoc
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 JavaDoc<String JavaDoc, String JavaDoc> env = new Hashtable JavaDoc<String JavaDoc, String JavaDoc>();
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 JavaDoc(env);
69             jndiContext.bind(repositoryName, (Repository)repository);
70         }
71         catch (NamingException JavaDoc e)
72         {
73             throw new ServletException JavaDoc(e);
74         }
75     }
76
77     /**
78      * Destroy the servlet
79      */

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 JavaDoc e)
91             {
92                 // Note: Itentionally ignore...
93
}
94         }
95     }
96
97
98 }
99
Popular Tags