001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.jxp;
022:
023: import java.io.IOException;
024: import java.util.*;
025: import org.onemind.jxp.parser.AstJxpDocument;
026:
027: /**
028: * A PageSource containing multiple page sources
029: * @author TiongHiang Lee (thlee@onemindsoft.org)
030: *
031: */
032: public class MultiSourcePageSource extends JxpPageSource {
033:
034: /** the sources **/
035: private List _sources = new ArrayList();
036:
037: /**
038: * Constructor
039: */
040: public MultiSourcePageSource() {
041: }
042:
043: /**
044: * Add a new page source
045: * @param source the page source
046: */
047: public final void addPageSource(JxpPageSource source) {
048: _sources.add(source);
049: }
050:
051: /**
052: * Remove the page source
053: * @param source the source
054: */
055: public final void removePageSource(JxpPageSource source) {
056: _sources.remove(source);
057: }
058:
059: /**
060: * Get the page sources
061: * @return the sources
062: */
063: public final List getPageSources() {
064: return Collections.unmodifiableList(_sources);
065: }
066:
067: /**
068: * {@inheritDoc}
069: */
070: public final JxpPage getJxpPage(String id)
071: throws JxpPageNotFoundException {
072: for (int i = 0; i < _sources.size(); i++) {
073: JxpPageSource source = (JxpPageSource) _sources.get(i);
074: if (source.hasJxpPage(id)) {
075: return source.getJxpPage(id);
076: }
077: }
078: throw new JxpPageNotFoundException("Page " + id + " not found");
079: }
080:
081: /**
082: * {@inheritDoc}
083: */
084: public final StringBuffer getErrorSource(JxpPage page, int line,
085: int col) throws IOException {
086: return page.getSource().getErrorSource(page, line, col);
087: }
088:
089: /**
090: * {@inheritDoc}
091: */
092: public final AstJxpDocument getJxpDocument(JxpPage page)
093: throws JxpPageSourceException {
094: return page.getSource().getJxpDocument(page);
095: }
096:
097: /**
098: * {@inheritDoc}
099: */
100: public boolean hasJxpPage(String id) {
101: for (int i = 0; i < _sources.size(); i++) {
102: JxpPageSource source = (JxpPageSource) _sources.get(i);
103: if (source.hasJxpPage(id)) {
104: return true;
105: }
106: }
107: return false;
108: }
109: }
|