KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * PETALS: PETALS Services Platform
3  * Copyright (C) 2005 ? EBM WebSourcing
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 any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): EBM WebSourcing
21  * --------------------------------------------------------------------------
22  * $Id: NamingHelper.java,v 1.2 2005/07/22 10:24:27 alouis Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.petals.util;
27
28 import javax.naming.CompositeName JavaDoc;
29 import javax.naming.InvalidNameException JavaDoc;
30 import javax.naming.Name JavaDoc;
31 import javax.xml.namespace.QName JavaDoc;
32
33 /**
34  * Class managing mapping between String and QName
35  *
36  * @author Adrien LOUIS - EBM WebSourcing
37  *
38  */

39 public class NamingHelper {
40
41     /**
42      * @param qn
43      * @return
44      */

45     public static Name JavaDoc QNameToName(QName JavaDoc qn) {
46         return StringToName(QNameToString(qn));
47     }
48
49     public static QName JavaDoc NameToQName(Name JavaDoc n) {
50         return StringToQName(NameToString(n));
51     }
52
53     public static String JavaDoc QNameToString(QName JavaDoc qn) {
54         if (!"".equals(qn.getNamespaceURI())) {
55             return "{" + qn.getNamespaceURI() + "}" + qn.getLocalPart();
56         } else {
57             return qn.getLocalPart();
58         }
59     }
60
61     public static String JavaDoc NameToString(Name JavaDoc n) {
62         return (n != null ? n.toString() : null);
63     }
64
65     public static QName JavaDoc StringToQName(String JavaDoc s) {
66         return QName.valueOf(s);
67     }
68
69     public static Name JavaDoc StringToName(String JavaDoc s) {
70         try {
71             return new CompositeName JavaDoc(s);
72         } catch (InvalidNameException JavaDoc e) {
73             return null;
74         }
75     }
76
77 }
78
Popular Tags