KickJava   Java API By Example, From Geeks To Geeks.

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


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.cocoon.components.modules.input;
17
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.configuration.ConfigurationException;
20 import org.apache.avalon.framework.logger.AbstractLogEnabled;
21 import org.apache.avalon.framework.service.ServiceException;
22 import org.apache.avalon.framework.service.ServiceManager;
23 import org.apache.avalon.framework.service.Serviceable;
24 import org.apache.avalon.framework.thread.ThreadSafe;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * This simple module allows to define global parameters in a sitemap. The
31  * values are inherited from one sitemap to its sub sitemaps and can be
32  * extended there.
33  *
34  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
35  * @version CVS $Id: GlobalInputModule.java 37203 2004-08-30 14:19:06Z cziegeler $
36  */

37 public final class GlobalInputModule
38     extends AbstractLogEnabled
39     implements InputModule, Serviceable, ThreadSafe {
40
41     private ServiceManager manager;
42     
43     /**
44      * Serviceable
45      */

46     public void service(ServiceManager manager) {
47         this.manager = manager;
48     }
49     
50     /**
51      * Standard access to an attribute's value. If more than one value
52      * exists, the first is returned. If the value does not exist,
53      * null is returned. To get all values, use
54      * {@link #getAttributeValues(String, Configuration, Map)} or
55      * {@link #getAttributeNames(Configuration, Map)} and
56      * {@link #getAttribute(String, Configuration, Map)} to get them one by one.
57      * @param name a String that specifies what the caller thinks
58      * would identify an attribute. This is mainly a fallback if no
59      * modeConf is present.
60      * @param modeConf column's mode configuration from resource
61      * description. This argument is optional.
62      * @param objectModel
63      */

64     public Object JavaDoc getAttribute( String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel )
65     throws ConfigurationException {
66         SitemapVariableHolder holder = null;
67         try {
68             holder = (SitemapVariableHolder)this.manager.lookup(SitemapVariableHolder.ROLE);
69             return holder.get(name);
70         } catch (ServiceException ce) {
71             throw new ConfigurationException("Unable to lookup SitemapVariableHolder.", ce);
72         } finally {
73             this.manager.release(holder);
74         }
75     }
76
77     /**
78      * Returns an Iterator of String objects containing the names
79      * of the attributes available. If no attributes are available,
80      * the method returns an empty Iterator.
81      * @param modeConf column's mode configuration from resource
82      * description. This argument is optional.
83      * @param objectModel
84      */

85     public Iterator JavaDoc getAttributeNames( Configuration modeConf, Map JavaDoc objectModel )
86     throws ConfigurationException {
87         SitemapVariableHolder holder = null;
88         try {
89             holder = (SitemapVariableHolder)this.manager.lookup(SitemapVariableHolder.ROLE);
90             return holder.getKeys();
91         } catch (ServiceException ce) {
92             throw new ConfigurationException("Unable to lookup SitemapVariableHolder.", ce);
93         } finally {
94             this.manager.release(holder);
95         }
96     }
97
98     /**
99      * Returns an array of String objects containing all of the values
100      * the given attribute has, or null if the attribute does not
101      * exist. As an alternative,
102      * {@link #getAttributeNames(Configuration, Map)} together with
103      * {@link #getAttribute(String, Configuration, Map)} can be used to get the
104      * values one by one.
105      * @param name a String that specifies what the caller thinks
106      * would identify an attributes. This is mainly a fallback
107      * if no modeConf is present.
108      * @param modeConf column's mode configuration from resource
109      * description. This argument is optional.
110      * @param objectModel
111      */

112     public Object JavaDoc[] getAttributeValues( String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel )
113     throws ConfigurationException {
114         Object JavaDoc o = this.getAttribute(name, modeConf, objectModel);
115         if (o != null) {
116             return new Object JavaDoc[] {o};
117         }
118         return null;
119     }
120 }
121
Popular Tags