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.portal.layout;
018:
019: import java.util.Map;
020: import java.util.Set;
021: import java.util.HashSet;
022: import java.util.Iterator;
023:
024: import org.apache.cocoon.portal.factory.impl.AbstractProducible;
025: import org.apache.cocoon.portal.pluto.om.common.ParameterImpl;
026: import org.apache.commons.collections.map.LinkedMap;
027: import org.apache.pluto.om.common.Parameter;
028:
029: /**
030: *
031: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
032: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
033: *
034: * @version CVS $Id: AbstractLayout.java 603313 2007-12-11 17:30:12Z cziegeler $
035: */
036: public abstract class AbstractLayout extends AbstractProducible
037: implements Layout, Parameters {
038:
039: protected String rendererName;
040:
041: protected Item parent;
042:
043: protected Map parameters = new LinkedMap(3);
044:
045: /* (non-Javadoc)
046: * @see org.apache.cocoon.portal.layout.Parameters#getParameters()
047: */
048: public final Map getParameters() {
049: return parameters;
050: }
051:
052: public final Set getCastorParameters() {
053: Set set = new HashSet(this .parameters.size());
054: Iterator iterator = this .parameters.entrySet().iterator();
055: Map.Entry entry;
056: while (iterator.hasNext()) {
057: entry = (Map.Entry) iterator.next();
058: ParameterImpl param = new ParameterImpl();
059: param.setName((String) entry.getKey());
060: param.setValue((String) entry.getValue());
061: set.add(param);
062: }
063: return set;
064: }
065:
066: public void addParameter(Parameter parameter) {
067: parameters.put(parameter.getName(), parameter.getValue());
068: }
069:
070: /**
071: * @see org.apache.cocoon.portal.layout.Layout#getRendererName()
072: */
073: public String getRendererName() {
074: if (this .rendererName == null) {
075: return ((LayoutDescription) this .description)
076: .getDefaultRendererName();
077: }
078: return this .rendererName;
079: }
080:
081: public void setLayoutRendererName(String value) {
082: this .rendererName = value;
083: }
084:
085: public Item getParent() {
086: return this .parent;
087: }
088:
089: public void setParent(Item item) {
090: this .parent = item;
091: }
092:
093: /* (non-Javadoc)
094: * @see org.apache.cocoon.portal.layout.Layout#getLayoutRendererName()
095: */
096: public String getLayoutRendererName() {
097: return this .rendererName;
098: }
099:
100: /* (non-Javadoc)
101: * @see java.lang.Object#clone()
102: */
103: protected Object clone() throws CloneNotSupportedException {
104: AbstractLayout clone = (AbstractLayout) super .clone();
105:
106: // we don't clone the parent; we just set it to null
107: clone.rendererName = this .rendererName;
108: clone.parameters = new LinkedMap(this .parameters);
109: clone.parent = null;
110:
111: return clone;
112: }
113:
114: /* (non-Javadoc)
115: * @see org.apache.cocoon.portal.layout.Layout#copy()
116: */
117: public Layout copy() {
118: try {
119: return (Layout) this .clone();
120: } catch (CloneNotSupportedException cnse) {
121: // ignore
122: }
123: return null;
124: }
125: }
|