001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.components.legacy;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import de.finix.contelligent.CallData;
024: import de.finix.contelligent.Component;
025: import de.finix.contelligent.ComponentContext;
026: import de.finix.contelligent.ComponentLink;
027: import de.finix.contelligent.ComponentManager;
028: import de.finix.contelligent.ComponentNotFoundException;
029: import de.finix.contelligent.ComponentPath;
030: import de.finix.contelligent.ExternalRelationSource;
031: import de.finix.contelligent.ModificationVetoException;
032: import de.finix.contelligent.logging.LoggingService;
033: import de.finix.contelligent.render.ParameterDescription;
034: import de.finix.contelligent.search.Metainfo;
035: import de.finix.contelligent.util.ThreadedMem;
036:
037: /**
038: * A <code>ComponentReference</code> holds an absolute path to another
039: * component and implements the {@link ComponentLink} interface which is treated
040: * by the component-manager in a special way:<BR>
041: * If the component-manager should return a component and recognizes that this
042: * component implements the ComponentLink interface it returns the target
043: * component of the link instead of the link-component itself if parameter
044: * followLinks is true.
045: *
046: * @see ComponentManager#getComponent
047: */
048: public class ComponentReference implements ComponentLink,
049: ExternalRelationSource {
050: final static org.apache.log4j.Logger log = LoggingService
051: .getLogger(ComponentReference.class);
052:
053: /**
054: * The path to the target component (must be absolute).
055: */
056: protected ComponentPath targetPath;
057:
058: protected ComponentContext ctx;
059:
060: public ParameterDescription[] getParameterDescription() {
061: return new ParameterDescription[] {};
062: }
063:
064: /**
065: * Implementation of {@link Component#postCreate}. This implementation
066: * doesn't do anything.
067: */
068: public void postCreate() {
069: }
070:
071: /**
072: * Implementation of {@link Component#setComponentContext}.
073: */
074: public void setComponentContext(ComponentContext ctx) {
075: this .ctx = ctx;
076: }
077:
078: /**
079: * Implementation of {@link Component#getComponentContext}.
080: */
081: public ComponentContext getComponentContext() {
082: return ctx;
083: }
084:
085: /**
086: * Implementation of {@link Component#isDynamic}. This implementation
087: * always returns false.
088: */
089: public boolean isDynamic() {
090: return false;
091: }
092:
093: /**
094: * Implementation of {@link Component#mayChangeContent}. This
095: * implementation always returns false since a link may not have any
096: * content.
097: */
098: public boolean mayChangeContent() {
099: return false;
100: }
101:
102: /**
103: * returns the path of this component as string. (without a trailing
104: * separator!)
105: */
106: final public String toString() {
107: if (ctx != null) {
108: return ctx.getPath().toString();
109: } else {
110: return "ComponentReference (name unknown)";
111: }
112: }
113:
114: public void setTargetPath(ComponentPath targetPath) {
115: if (targetPath.isRelative()) {
116: log
117: .error("'"
118: + this
119: + "':setTargetPath() - new target-path is relative!");
120: }
121: this .targetPath = targetPath;
122: }
123:
124: public ComponentPath getTargetPath() {
125: return targetPath;
126: }
127:
128: /**
129: * This is the implementation of {@link Component#putSearchMetainfo}.
130: * Overwrite that method for extension.
131: *
132: * @returns
133: */
134: public void putSearchMetainfo(Metainfo metainfo, CallData callData) {
135: }
136:
137: /**
138: * Implementation of {@link ComponentLink#getProxyInstance}.
139: *
140: * @return a <code>Component</code> value
141: * @see ComponentLink#getProxyInstance
142: */
143: public Component getProxyInstance()
144: throws ComponentNotFoundException {
145: ComponentPath path = getTargetPath(); // use getter here since classes
146: // may override this (e.g.
147: // MutableLink)
148: if (log.isDebugEnabled())
149: log.debug("'" + this
150: + "':getProxyInstance() - ... targetPath is '"
151: + path + "' ...");
152: return ctx.getCallManager().getComponent(path,
153: ThreadedMem.getCallData());
154: }
155:
156: /**
157: * Implementation of {@link ExternalRelationSource#relatedPaths(void)}.
158: * Returns a list containing the target-path of this link.
159: */
160: public java.util.List relatedPaths() {
161: List relatedPaths = new ArrayList(1);
162: relatedPaths.add(getTargetPath());
163: return relatedPaths;
164: }
165:
166: /**
167: * Implementation of {@link ExternalRelationSource#relatedPaths(List)}.
168: * Sets the target-path of this link.
169: */
170: public void relatedPaths(java.util.List newRelatedPaths)
171: throws ModificationVetoException {
172: ComponentPath oldTargetPath = getTargetPath();
173: if (newRelatedPaths.size() != 1) {
174: throw new ModificationVetoException();
175: }
176: ComponentPath newTargetPath = (ComponentPath) newRelatedPaths
177: .get(0);
178:
179: if (newTargetPath != null) {
180: if (newTargetPath.isRelative()) {
181: throw new ModificationVetoException();
182: }
183: setTargetPath(newTargetPath);
184: log
185: .debug("'"
186: + this
187: + "':updateRelationSources() - changed old target-path '"
188: + oldTargetPath + "' to '" + newTargetPath);
189: }
190: }
191:
192: }
|