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;
019:
020: import java.util.Iterator;
021:
022: import de.finix.contelligent.AbstractComponent;
023: import de.finix.contelligent.CallData;
024: import de.finix.contelligent.Component;
025: import de.finix.contelligent.ComponentNotFoundException;
026: import de.finix.contelligent.ComponentPathException;
027: import de.finix.contelligent.Container;
028: import de.finix.contelligent.logging.LoggingService;
029: import de.finix.contelligent.search.Metainfo;
030:
031: /**
032: * A base class defining a simple Contelligent {@link Container}.
033: */
034: public class Folder extends AbstractComponent implements Container {
035: final static org.apache.log4j.Logger log = LoggingService
036: .getLogger(Folder.class);
037:
038: public static final String METAINFO_NAME = "metainfo";
039:
040: // 'rn' property
041: public boolean getHasChildren() {
042: return (ctx.getCallManager().getSubcomponentCount(this ) > 0);
043: }
044:
045: /**
046: * changed to return iterator for large containers
047: */
048: public Iterator getSubcomponentNames() {
049: return ctx.getCallManager().getSubcomponentNames(this )
050: .iterator();
051: }
052:
053: /*
054: * public Iterator getSubcomponentNames(int startWith, int amount) { if
055: * (log.isDebugEnabled()) log.debug("getSubcomponentNames() -
056: * startWith="+startWith+" amount="+amount); ComponentManager manager =
057: * ctx.getCallManager(); return manager.getSubcomponentNames(this,
058: * startWith, amount); }
059: *
060: *
061: * public static class SubcomponentIterator implements Iterator { Container
062: * container; boolean followLinks; Iterator nameI;
063: *
064: * public SubcomponentIterator(Container container, int start, int amount,
065: * boolean followLinks) { this.container = container; this.followLinks =
066: * followLinks; nameI = container.getSubcomponentNames(start, amount); if
067: * (log.isDebugEnabled()) { log.debug("[SubcomponentIterator:<init>] -
068: * created iterator for container '"+container +"' with
069: * followLinks="+followLinks+", start="+start+", amount="+amount +" and
070: * nameIterator "+nameI); } }
071: *
072: * public boolean hasNext() { return nameI.hasNext(); }
073: *
074: * public Object next() { String subName = (String)nameI.next(); try {
075: * ComponentManager manager = ThreadedMem.getActualManager(); return
076: * manager.getSubcomponent(container, subName, ThreadedMem.getCallData(),
077: * followLinks); } catch (ComponentNotFoundException e) {
078: * log.error("[SubcomponentIterator:next()] - could not get subcomponent '"
079: * +subName+"' of container '"+container+": ",e); throw new
080: * java.util.NoSuchElementException("[SubcomponentIterator:next()] - could
081: * not get subcomponent '" +subName+"' of container '"+container+": "+e); }
082: * catch (ComponentPathException e) {
083: * log.error("[SubcomponentIterator:next()] - could not get subcomponent '"
084: * +subName+"' of container '"+container+": ",e); throw new
085: * java.util.NoSuchElementException("[SubcomponentIterator:next()] - could
086: * not get subcomponent '" +subName+"' of container '"+container+": "+e); } }
087: *
088: * public void remove() { //UnsupportedOperationException nameI.remove(); } }
089: *
090: *
091: * public Iterator subcomponents() { return subcomponents(0); }
092: *
093: * public Iterator subcomponents(boolean followLinks) { return
094: * subcomponents(0, followLinks); }
095: *
096: * public Iterator subcomponents(int start) { return new
097: * SubcomponentIterator(this, start, -1, true); // do follow links }
098: *
099: * public Iterator subcomponents(int start, boolean followLinks) { return
100: * new SubcomponentIterator(this, start, -1, followLinks); }
101: */
102:
103: /**
104: * This is the implementation of {@link Component#getSearchMetainfo}.
105: * Overwrite that method for extension.
106: *
107: * @returns
108: */
109: public void putSearchMetainfo(Metainfo metainfo, CallData callData) {
110: super .putSearchMetainfo(metainfo, callData);
111:
112: try {
113: Component metainfoComponent = callData.getActualManager()
114: .getSubcomponent(this , METAINFO_NAME, callData,
115: true);
116: if (metainfoComponent instanceof de.finix.contelligent.SearchMetainfo) {
117: metainfoComponent.putSearchMetainfo(metainfo, callData);
118: }
119: } catch (ComponentNotFoundException e) {
120: // ignore -> no metainfo available
121: } catch (ComponentPathException e) {
122: // ignore -> we define a valid path
123: }
124: }
125: }
|