KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > util > JNDIUtil


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: JNDIUtil.java 16:03:11 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.util;
23
24 import javax.naming.Context JavaDoc;
25 import javax.naming.NameClassPair JavaDoc;
26 import javax.naming.NamingEnumeration JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28
29 /**
30  * This utility class is used to help us to manage JNDI directories
31  *
32  * @author ddesjardins - eBMWebsourcing
33  */

34 public final class JNDIUtil {
35
36     private JNDIUtil() {
37
38     }
39
40     /**
41      * Check if a name is bound is a specific context
42      *
43      * @param parentContext
44      * parent context where to list the content of the child context
45      * @param childContextName
46      * name of the child context, the context in we want to look for
47      * the binding name
48      * @param name
49      * binding name
50      * @return
51      */

52     public static boolean isBound(Context JavaDoc parentContext,
53         String JavaDoc childContextName, String JavaDoc name) {
54         boolean test = false;
55         try {
56             NamingEnumeration JavaDoc<NameClassPair JavaDoc> namingEnumeration = parentContext
57                 .list(childContextName);
58             while (namingEnumeration.hasMoreElements()) {
59                 NameClassPair JavaDoc classPair = (NameClassPair JavaDoc) namingEnumeration
60                     .next();
61                 if (classPair.getName().equals(name)) {
62                     return true;
63                 }
64             }
65         } catch (NamingException JavaDoc e) {
66             return false;
67         }
68         return test;
69     }
70 }
71
Popular Tags