001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE 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
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixxml.targets;
021:
022: import java.util.Iterator;
023: import java.util.TreeMap;
024: import java.util.TreeSet;
025:
026: /**
027: * PageTargetTree.java
028: *
029: *
030: * Created: Fri Jul 20 13:38:09 2001
031: *
032: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
033: *
034: *
035: */
036:
037: public class PageTargetTree {
038: TreeMap<PageInfo, Target> toplevels = new TreeMap<PageInfo, Target>();
039: TreeMap<String, TreeSet<PageInfo>> pageinfos = new TreeMap<String, TreeSet<PageInfo>>();
040:
041: protected void addEntry(PageInfo pageinfo, Target target) {
042: synchronized (toplevels) {
043: if (toplevels.get(pageinfo) == null) {
044: toplevels.put(pageinfo, target);
045: String name = pageinfo.getName();
046: if (pageinfos.get(name) == null) {
047: pageinfos.put(name, new TreeSet<PageInfo>());
048: }
049: TreeSet<PageInfo> pinfos = pageinfos.get(name);
050: pinfos.add(pageinfo);
051: } else {
052: throw new RuntimeException(
053: "Can't have another top-level target '"
054: + target.getTargetKey()
055: + "' for the same page '"
056: + pageinfo.getName() + "' variant: '"
057: + pageinfo.getVariant() + "'");
058: }
059: }
060: }
061:
062: public TreeSet<PageInfo> getPageInfoForPageName(String name) {
063: synchronized (pageinfos) {
064: return pageinfos.get(name);
065: }
066: }
067:
068: public TreeSet<PageInfo> getPageInfos() {
069: synchronized (toplevels) {
070: return new TreeSet<PageInfo>(toplevels.keySet());
071: }
072: }
073:
074: public TreeSet<Target> getToplevelTargets() {
075: synchronized (toplevels) {
076: return new TreeSet<Target>(toplevels.values());
077: }
078: }
079:
080: public Target getTargetForPageInfo(PageInfo pinfo) {
081: synchronized (toplevels) {
082: return toplevels.get(pinfo);
083: }
084: }
085:
086: public void initTargets() {
087: synchronized (toplevels) {
088: for (Iterator<PageInfo> i = toplevels.keySet().iterator(); i
089: .hasNext();) {
090: PageInfo pageinfo = i.next();
091: Target top = toplevels.get(pageinfo);
092: addPageInfoToTarget(pageinfo, top);
093: }
094: }
095: }
096:
097: private void addPageInfoToTarget(PageInfo page, Target target) {
098: ((TargetImpl) target).addPageInfo(page);
099: Target xmlsource = target.getXMLSource();
100: if (xmlsource != null) {
101: addPageInfoToTarget(page, xmlsource);
102: }
103:
104: Target xslsource = target.getXSLSource();
105: if (xslsource != null) {
106: addPageInfoToTarget(page, xslsource);
107: }
108: }
109:
110: }// PageTargetTree
|