001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.factory;
017:
018: // J2SE dependencies
019: import java.util.Map;
020: import java.util.Collections;
021:
022: // JUnit dependencies
023: import junit.framework.Assert;
024:
025: /**
026: * An internal dummy factory for testing factory dependencies.
027: * It doesn't matter if this factory is registered or not. We
028: * just need a {@code InternalFactory.class} value different
029: * than {@code DummyFactory.class}.
030: *
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/factory/DummyFactory.java $
032: * @version $Id: DummyFactory.java 25262 2007-04-23 21:11:16Z desruisseaux $
033: * @author Martin Desruisseaux
034: */
035: interface InternalFactory extends Factory {
036: }
037:
038: /**
039: * Dummy factory interface for {@link FactoryRegistryTest}.
040: *
041: * @version $Id: DummyFactory.java 25262 2007-04-23 21:11:16Z desruisseaux $
042: * @author Martin Desruisseaux
043: */
044: public interface DummyFactory extends InternalFactory {
045: /**
046: * A hint key for a {@code DummyFactory} instance.
047: */
048: Hints.Key DUMMY_FACTORY = new Hints.ClassKey(DummyFactory.class
049: .getName());
050:
051: /**
052: * A hint key for a {@code DummyFactory2} instance.
053: */
054: Hints.Key INTERNAL_FACTORY = new Hints.ClassKey(
055: InternalFactory.class.getName());
056:
057: /**
058: * Dummy factory implementation #1.
059: * This factory doesn't use any other factory.
060: */
061: final class Example1 implements DummyFactory {
062: public String toString() {
063: return "#1";
064: }
065:
066: public Map getImplementationHints() {
067: return Collections.singletonMap(Hints.KEY_INTERPOLATION,
068: Hints.VALUE_INTERPOLATION_BILINEAR);
069: }
070: }
071:
072: /**
073: * Dummy factory implementation #2.
074: * This factory uses factory #1.
075: */
076: final class Example2 implements DummyFactory {
077: public String toString() {
078: return "#2";
079: }
080:
081: public Map getImplementationHints() {
082: return Collections.singletonMap(INTERNAL_FACTORY,
083: new Example1());
084: }
085: }
086:
087: /**
088: * Dummy factory implementation #3.
089: * This factory uses factory #2, which uses itself factory #1.
090: */
091: final class Example3 implements DummyFactory {
092: public String toString() {
093: return "#3";
094: }
095:
096: public Map getImplementationHints() {
097: return Collections.singletonMap(INTERNAL_FACTORY,
098: new Example2());
099: }
100: }
101:
102: /**
103: * Dummy factory implementation #4.
104: * {@link FactoryRegistryTest} will not register this factory in same time than other ones.
105: */
106: final class Example4 implements DummyFactory {
107: public String toString() {
108: return "#4";
109: }
110:
111: public Map getImplementationHints() {
112: return Collections.singletonMap(Hints.KEY_INTERPOLATION,
113: Hints.VALUE_INTERPOLATION_BICUBIC);
114: }
115: }
116:
117: /**
118: * Dummy factory implementation #5.
119: * {@link FactoryRegistryTest} will not register this factory in same time than other ones.
120: * This factory is the only one to accept hints.
121: */
122: final class Example5 implements DummyFactory {
123: private Object value = Hints.VALUE_INTERPOLATION_BILINEAR;
124:
125: public Example5() {
126: Assert
127: .fail("The constructor with Hints argument should have been used.");
128: }
129:
130: public Example5(Hints hints) {
131: if (hints != null
132: && hints.containsKey(Hints.KEY_INTERPOLATION)) {
133: value = hints.get(Hints.KEY_INTERPOLATION);
134: }
135: }
136:
137: public String toString() {
138: return "#5";
139: }
140:
141: public Map getImplementationHints() {
142: return Collections.singletonMap(Hints.KEY_INTERPOLATION,
143: value);
144: }
145: }
146: }
|