KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > modules > input > AbstractInputModule


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
17 package org.apache.cocoon.components.modules.input;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import org.apache.avalon.framework.activity.Disposable;
24 import org.apache.avalon.framework.configuration.Configurable;
25 import org.apache.avalon.framework.configuration.Configuration;
26 import org.apache.avalon.framework.configuration.ConfigurationException;
27 import org.apache.avalon.framework.logger.AbstractLogEnabled;
28
29 import org.apache.cocoon.util.HashMap;
30
31 /**
32  * AbstractInputModule gives you the infrastructure for easily
33  * deploying more InputModules. In order to get at the Logger, use
34  * getLogger().
35  *
36  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
37  * @version CVS $Id: AbstractInputModule.java 30932 2004-07-29 17:35:38Z vgritsenko $
38  */

39 public abstract class AbstractInputModule extends AbstractLogEnabled
40     implements InputModule, Configurable, Disposable {
41
42     /**
43      * For those modules that access only one attribute, have a
44      * fixed collection we can return an iterator for.
45      */

46     final static Vector JavaDoc returnNames;
47     static {
48         Vector JavaDoc tmp = new Vector JavaDoc();
49         tmp.add("attribute");
50         returnNames = tmp;
51     }
52
53
54
55     /**
56      * Stores (global) configuration parameters as <code>key</code> /
57      * <code>value</code> pairs.
58      */

59     protected HashMap settings = null;
60
61     /**
62      * Configures the database access helper.
63      *
64      * Takes all elements nested in component declaration and stores
65      * them as key-value pairs in <code>settings</code>. Nested
66      * configuration option are not catered for. This way global
67      * configuration options can be used.
68      *
69      * For nested configurations override this function.
70      * */

71     public void configure(Configuration conf) throws ConfigurationException {
72         Configuration[] parameters = conf.getChildren();
73         this.settings = new HashMap(parameters.length);
74         for (int i = 0; i < parameters.length; i++) {
75             String JavaDoc key = parameters[i].getName();
76             String JavaDoc val = parameters[i].getValue("");
77             this.settings.put (key, val);
78         }
79     }
80
81     /**
82      * dispose
83      */

84     public void dispose() {
85         // Purposely empty so that we don't need to implement it in every
86
// class.
87
}
88     
89     //
90
// you need to implement at least one of the following two methods
91
// since the ones below have a cyclic dependency!
92
//
93

94     /* (non-Javadoc)
95      * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
96      */

97     public Object JavaDoc getAttribute(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel) throws ConfigurationException {
98         Object JavaDoc[] result = this.getAttributeValues(name, modeConf, objectModel);
99         return (result == null ? null : result[0]);
100     }
101
102     /* (non-Javadoc)
103      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
104      */

105     public Object JavaDoc[] getAttributeValues(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
106         throws ConfigurationException {
107         Object JavaDoc result = this.getAttribute(name, modeConf, objectModel);
108         return (result == null ? null : new Object JavaDoc[] {result});
109     }
110
111
112     /* (non-Javadoc)
113      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
114      */

115     public Iterator JavaDoc getAttributeNames(Configuration modeConf, Map JavaDoc objectModel) throws ConfigurationException {
116         return AbstractInputModule.returnNames.iterator();
117     }
118 }
119
Popular Tags