KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > util > PetalsExtensionsUtil


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$
20  * -------------------------------------------------------------------------
21  */

22
23 package org.objectweb.petals.component.common.util;
24
25 import java.net.URI JavaDoc;
26 import java.net.URISyntaxException JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.petals.tools.jbicommon.descriptor.Extensions;
30 import org.objectweb.petals.tools.jbicommon.descriptor.PetalsExtension;
31
32 /**
33  *
34  * @author ofabre
35  *
36  */

37 public final class PetalsExtensionsUtil {
38
39     /**
40      * Key node names
41      */

42     public static final String JavaDoc ADDRESS = "address";
43
44     public static final String JavaDoc WSDL_LOCATION = "wsdl";
45
46     /**
47      * Namespace of the extension elements in the jbi descriptor file
48      */

49     private static final String JavaDoc KEY_VALUE_NS = "http://petals.objectweb.org/extensions/key-value/";
50
51     private PetalsExtensionsUtil() {
52
53     }
54
55     /**
56      * Extract a value from the key value map extension
57      *
58      * @param extensions
59      * the {@link Extensions} element containing Petals key value
60      * extension
61      * @param key
62      * the targeted key
63      * @return the {@link String} value for the given key or null
64      */

65     @SuppressWarnings JavaDoc("unchecked")
66     public static String JavaDoc extractValueFromKeyValueExtension(
67         Extensions extensions, String JavaDoc key) {
68         String JavaDoc value = null;
69         if (extensions != null) {
70             try {
71                 URI JavaDoc uri = new URI JavaDoc(KEY_VALUE_NS);
72                 PetalsExtension petalsExtension = extensions
73                     .getPetalsExtensions().get(uri);
74                 if (petalsExtension != null) {
75                     Map JavaDoc<String JavaDoc, String JavaDoc> keyValue = (Map JavaDoc<String JavaDoc, String JavaDoc>) petalsExtension
76                         .getExtensionObject();
77                     value = keyValue.get(key);
78                 }
79             } catch (URISyntaxException JavaDoc e) {
80                 // This exception should not be raised.
81
// If this exception is raised, fix the value of KEY_VALUE_NS.
82
e.printStackTrace();
83             }
84         }
85
86         return value;
87     }
88
89     /**
90      * Test if the key is present in the extensions.
91      *
92      * @param extensions
93      * the {@link Extensions} element containing Petals key value
94      * extension
95      * @param key
96      * the targeted key
97      *
98      * @return true if the key is present (Implies that the extensions are not
99      * null), false otherwise.
100      */

101     public static boolean hasKeyValueExtension(Extensions extensions, String JavaDoc key) {
102         return (extractValueFromKeyValueExtension(extensions, key) != null);
103     }
104
105 }
106
Popular Tags