KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jxpath > MapDynamicPropertyHandler


1 /*
2  * Copyright 1999-2004 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.commons.jxpath;
17
18 import java.util.Iterator JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 /**
23  * Implements the DynamicPropertyHandler interface for java.util.Map.
24  *
25  * @author Dmitri Plotnikov
26  * @version $Revision: 1.7 $ $Date: 2004/03/02 01:03:14 $
27  */

28 public class MapDynamicPropertyHandler implements DynamicPropertyHandler {
29
30     private static final String JavaDoc[] STRING_ARRAY = new String JavaDoc[0];
31
32     /**
33      * Returns string representations of all keys in the map.
34      */

35     public String JavaDoc[] getPropertyNames(Object JavaDoc object) {
36         Map JavaDoc map = (Map JavaDoc) object;
37         Set JavaDoc set = map.keySet();
38         String JavaDoc names[] = new String JavaDoc[set.size()];
39         Iterator JavaDoc it = set.iterator();
40         for (int i = 0; i < names.length; i++) {
41             names[i] = String.valueOf(it.next());
42         }
43         return names;
44     }
45
46     /**
47      * Returns the value for the specified key.
48      */

49     public Object JavaDoc getProperty(Object JavaDoc object, String JavaDoc propertyName) {
50         return ((Map JavaDoc) object).get(propertyName);
51     }
52
53     /**
54      * Sets the specified key value.
55      */

56     public void setProperty(Object JavaDoc object, String JavaDoc propertyName, Object JavaDoc value) {
57         ((Map JavaDoc) object).put(propertyName, value);
58     }
59 }
Popular Tags