KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > jcr > JNDIRepository


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

16 package org.apache.cocoon.jcr;
17
18 import javax.jcr.Repository;
19 import javax.naming.InitialContext JavaDoc;
20 import javax.naming.NamingException JavaDoc;
21
22 import org.apache.avalon.framework.configuration.Configuration;
23 import org.apache.avalon.framework.configuration.ConfigurationException;
24
25 /**
26  * @version $Id: JNDIRepository.java 240335 2005-08-26 20:26:24Z vgritsenko $
27  */

28 public class JNDIRepository extends AbstractRepository {
29
30     public void configure(Configuration config) throws ConfigurationException {
31         super.configure(config);
32
33         Configuration rsrcConfig = config.getChild("jndi-resource");
34         String JavaDoc name = rsrcConfig.getAttribute("name");
35
36         InitialContext JavaDoc ctx = null;
37         try {
38             ctx = new InitialContext JavaDoc();
39             this.delegate = (Repository) ctx.lookup(name);
40         } catch (NamingException JavaDoc e) {
41             throw new ConfigurationException("Cannot lookup JNDI entry '" + name + "'", e);
42         } finally {
43             if (ctx != null) {
44                 try {
45                     ctx.close();
46                 } catch (NamingException JavaDoc ignored) {
47                     // Ignored
48
}
49             }
50         }
51     }
52
53 }
54
Popular Tags