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.pfixcore.editor2.core.spring;
020:
021: import java.util.Collections;
022: import java.util.HashMap;
023: import java.util.Map;
024: import java.util.WeakHashMap;
025:
026: import de.schlund.pfixcore.editor2.core.dom.Project;
027: import de.schlund.pfixcore.editor2.core.dom.Target;
028: import de.schlund.pfixcore.editor2.core.spring.internal.TargetAuxDepImpl;
029: import de.schlund.pfixcore.editor2.core.spring.internal.TargetPfixImpl;
030: import de.schlund.pfixxml.targets.AuxDependency;
031: import de.schlund.pfixxml.targets.AuxDependencyFile;
032:
033: /**
034: * Implementation of TargetFactoryService
035: *
036: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
037: */
038: public class TargetFactoryServiceImpl implements TargetFactoryService {
039: private Map<de.schlund.pfixxml.targets.Target, Target> cachePfixTarget;
040:
041: private Map<AuxDependency, Target> cacheAuxDepTarget;
042:
043: private ProjectFactoryService projectfactory;
044:
045: private VariantFactoryService variantfactory;
046:
047: private TargetFactoryService targetfactory;
048:
049: private ThemeFactoryService themefactory;
050:
051: private IncludeFactoryService includefactory;
052:
053: private ImageFactoryService imagefactory;
054:
055: private FileSystemService filesystem;
056:
057: private PathResolverService pathresolver;
058:
059: public void setProjectFactoryService(
060: ProjectFactoryService projectfactory) {
061: this .projectfactory = projectfactory;
062: }
063:
064: public void setThemeFactoryService(ThemeFactoryService themefactory) {
065: this .themefactory = themefactory;
066: }
067:
068: public void setVariantFactoryService(
069: VariantFactoryService variantfactory) {
070: this .variantfactory = variantfactory;
071: }
072:
073: public void setIncludeFactoryService(
074: IncludeFactoryService includefactory) {
075: this .includefactory = includefactory;
076: }
077:
078: public void setImageFactoryService(ImageFactoryService imagefactory) {
079: this .imagefactory = imagefactory;
080: }
081:
082: public void setPathResolverService(PathResolverService pathresolver) {
083: this .pathresolver = pathresolver;
084: }
085:
086: public void setFileSystemService(FileSystemService filesystem) {
087: this .filesystem = filesystem;
088: }
089:
090: public void setTargetFactoryService(
091: TargetFactoryService targetfactory) {
092: this .targetfactory = targetfactory;
093: }
094:
095: public TargetFactoryServiceImpl() {
096: this .cachePfixTarget = new WeakHashMap<de.schlund.pfixxml.targets.Target, Target>();
097: this .cacheAuxDepTarget = Collections
098: .synchronizedMap(new HashMap<AuxDependency, Target>());
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see de.schlund.pfixcore.editor2.core.spring.TargetFactoryService#createTarget(de.schlund.pfixxml.targets.Target,
105: * de.schlund.pfixcore.editor2.core.dom.Project)
106: */
107: public Target getTargetFromPustefixTarget(
108: de.schlund.pfixxml.targets.Target pfixTarget,
109: Project project) {
110: if (pfixTarget == null) {
111: return null;
112: }
113: synchronized (this .cachePfixTarget) {
114: if (!this .cachePfixTarget.containsKey(pfixTarget)) {
115: this .cachePfixTarget.put(pfixTarget,
116: new TargetPfixImpl(targetfactory,
117: projectfactory, variantfactory,
118: includefactory, themefactory,
119: imagefactory, pathresolver, filesystem,
120: pfixTarget, project));
121: }
122: return (Target) this .cachePfixTarget.get(pfixTarget);
123: }
124: }
125:
126: /*
127: * (non-Javadoc)
128: *
129: * @see de.schlund.pfixcore.editor2.core.spring.TargetFactoryService#createTarget(de.schlund.pfixxml.targets.AuxDependency)
130: */
131: public Target getLeafTargetFromPustefixAuxDependency(
132: AuxDependencyFile auxdep) {
133: // TODO Make sure Target object is unique within the whole installation
134: if (this .cacheAuxDepTarget.containsKey(auxdep)) {
135: return (Target) this .cacheAuxDepTarget.get(auxdep);
136: }
137: synchronized (this .cacheAuxDepTarget) {
138: if (!this .cacheAuxDepTarget.containsKey(auxdep)) {
139: this .cacheAuxDepTarget.put(auxdep,
140: new TargetAuxDepImpl(this .projectfactory,
141: this .variantfactory, this .pathresolver,
142: this .filesystem, auxdep));
143: }
144: }
145: return (Target) this.cacheAuxDepTarget.get(auxdep);
146: }
147:
148: }
|