001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.modules.input;
018:
019: import org.apache.avalon.framework.configuration.Configuration;
020: import org.apache.avalon.framework.configuration.ConfigurationException;
021: import org.apache.avalon.framework.logger.AbstractLogEnabled;
022: import org.apache.avalon.framework.service.ServiceException;
023: import org.apache.avalon.framework.service.ServiceManager;
024: import org.apache.avalon.framework.service.Serviceable;
025: import org.apache.avalon.framework.thread.ThreadSafe;
026:
027: import java.util.Iterator;
028: import java.util.Map;
029:
030: /**
031: * This simple module allows to define global parameters in a sitemap. The
032: * values are inherited from one sitemap to its sub sitemaps and can be
033: * extended there.
034: *
035: * @deprecated This module will be replaced by a better version in 2.2.
036: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
037: * @version $Id: GlobalInputModule.java 433543 2006-08-22 06:22:54Z crossley $
038: */
039: public final class GlobalInputModule extends AbstractLogEnabled
040: implements InputModule, Serviceable, ThreadSafe {
041:
042: private ServiceManager manager;
043:
044: /**
045: * Serviceable
046: */
047: public void service(ServiceManager manager) {
048: this .manager = manager;
049: }
050:
051: /**
052: * Standard access to an attribute's value. If more than one value
053: * exists, the first is returned. If the value does not exist,
054: * null is returned. To get all values, use
055: * {@link #getAttributeValues(String, Configuration, Map)} or
056: * {@link #getAttributeNames(Configuration, Map)} and
057: * {@link #getAttribute(String, Configuration, Map)} to get them one by one.
058: * @param name a String that specifies what the caller thinks
059: * would identify an attribute. This is mainly a fallback if no
060: * modeConf is present.
061: * @param modeConf column's mode configuration from resource
062: * description. This argument is optional.
063: * @param objectModel
064: */
065: public Object getAttribute(String name, Configuration modeConf,
066: Map objectModel) throws ConfigurationException {
067: SitemapVariableHolder holder = null;
068: try {
069: holder = (SitemapVariableHolder) this .manager
070: .lookup(SitemapVariableHolder.ROLE);
071: return holder.get(name);
072: } catch (ServiceException ce) {
073: throw new ConfigurationException(
074: "Unable to lookup SitemapVariableHolder.", ce);
075: } finally {
076: this .manager.release(holder);
077: }
078: }
079:
080: /**
081: * Returns an Iterator of String objects containing the names
082: * of the attributes available. If no attributes are available,
083: * the method returns an empty Iterator.
084: * @param modeConf column's mode configuration from resource
085: * description. This argument is optional.
086: * @param objectModel
087: */
088: public Iterator getAttributeNames(Configuration modeConf,
089: Map objectModel) throws ConfigurationException {
090: SitemapVariableHolder holder = null;
091: try {
092: holder = (SitemapVariableHolder) this .manager
093: .lookup(SitemapVariableHolder.ROLE);
094: return holder.getKeys();
095: } catch (ServiceException ce) {
096: throw new ConfigurationException(
097: "Unable to lookup SitemapVariableHolder.", ce);
098: } finally {
099: this .manager.release(holder);
100: }
101: }
102:
103: /**
104: * Returns an array of String objects containing all of the values
105: * the given attribute has, or null if the attribute does not
106: * exist. As an alternative,
107: * {@link #getAttributeNames(Configuration, Map)} together with
108: * {@link #getAttribute(String, Configuration, Map)} can be used to get the
109: * values one by one.
110: * @param name a String that specifies what the caller thinks
111: * would identify an attributes. This is mainly a fallback
112: * if no modeConf is present.
113: * @param modeConf column's mode configuration from resource
114: * description. This argument is optional.
115: * @param objectModel
116: */
117: public Object[] getAttributeValues(String name,
118: Configuration modeConf, Map objectModel)
119: throws ConfigurationException {
120: Object o = this .getAttribute(name, modeConf, objectModel);
121: if (o != null) {
122: return new Object[] { o };
123: }
124: return null;
125: }
126: }
|