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: package de.schlund.pfixxml.targets;
020:
021: import de.schlund.pfixxml.resources.DocrootResource;
022: import de.schlund.pfixxml.resources.FileSystemResource;
023:
024: /**
025: * Dependency referencing a target that is supplied by a target generator.
026: * The target generator is always the same the target referencing this aux
027: * dependency is using.
028: *
029: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
030: */
031: public class AuxDependencyTarget extends AbstractAuxDependency {
032: private TargetGenerator tgen;
033:
034: private String targetkey;
035:
036: private int hashCode;
037:
038: public AuxDependencyTarget(TargetGenerator tgen, String targetkey) {
039: this .type = DependencyType.TARGET;
040: this .tgen = tgen;
041: this .targetkey = targetkey;
042: this .hashCode = (tgen.getConfigPath().toString() + ":" + targetkey)
043: .hashCode();
044: }
045:
046: /**
047: * Returns the referenced target object. This might be a virtual target
048: * as well as a leaf target.
049: *
050: * @return referenced target
051: */
052: public Target getTarget() {
053: Target target = tgen.getTarget(targetkey);
054: if (target == null) {
055: target = tgen.createXMLLeafTarget(targetkey);
056: }
057: return target;
058: }
059:
060: public long getModTime() {
061: return this .getTarget().getModTime();
062: }
063:
064: public int compareTo(AuxDependency o) {
065: int comp;
066:
067: comp = super .compareTo(o);
068: if (comp != 0) {
069: return comp;
070: }
071:
072: AuxDependencyTarget a = (AuxDependencyTarget) o;
073:
074: comp = tgen.getConfigPath().compareTo(a.tgen.getConfigPath());
075: if (comp != 0) {
076: return comp;
077: }
078:
079: return targetkey.compareTo(a.targetkey);
080: }
081:
082: public boolean equals(Object obj) {
083: if (obj instanceof AuxDependencyTarget) {
084: return this .compareTo((AuxDependency) obj) == 0;
085: } else {
086: return false;
087: }
088: }
089:
090: public int hashCode() {
091: return this .hashCode;
092: }
093:
094: public String toString() {
095: String path;
096: if (tgen.getConfigPath() instanceof DocrootResource) {
097: path = ((DocrootResource) tgen.getConfigPath())
098: .getRelativePath();
099: } else if (tgen.getConfigPath() instanceof FileSystemResource) {
100: path = ((FileSystemResource) tgen.getConfigPath())
101: .getPathOnFileSystem();
102: } else {
103: path = tgen.getConfigPath().toURI().toString();
104: }
105: return "[AUX/" + getType() + " " + path + ": " + targetkey
106: + "]";
107: }
108:
109: }
|