01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: *
05: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
06: * (C) 2004, Institut de Recherche pour le Développement
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Lesser General Public
10: * License as published by the Free Software Foundation; either
11: * version 2.1 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Lesser General Public License for more details.
17: */
18: package org.geotools.referencing.wkt;
19:
20: // Geotools dependencies
21: import org.geotools.util.UnsupportedImplementationException;
22:
23: /**
24: * Adapter for implementations which doesn't extends {@link Formattable}. This includes
25: * especially {@link org.geotools.referencing.operation.transform.AffineTransform2D}.
26: * This method looks for a {@code toWKT()} method using reflection.
27: *
28: * @since 2.0
29: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/wkt/Adapter.java $
30: * @version $Id: Adapter.java 20874 2006-08-07 10:00:01Z jgarnett $
31: * @author Martin Desruisseaux
32: */
33: final class Adapter extends Formattable {
34: /**
35: * The object to format as WKT.
36: */
37: private final Object object;
38:
39: /**
40: * Create an adapter for the specified object.
41: */
42: public Adapter(final Object object) {
43: this .object = object;
44: }
45:
46: /**
47: * Try to format the wrapped object as WKT. If the adapter fails to find a way to format
48: * the object as WKT, then an {@link UnsupportedImplementationException} is thrown.
49: */
50: protected String formatWKT(final Formatter formatter) {
51: if (object instanceof org.geotools.resources.Formattable) {
52: return ((org.geotools.resources.Formattable) object)
53: .formatWKT(formatter);
54: }
55: final Class classe = object.getClass();
56: final String wkt;
57: try {
58: wkt = (String) classe.getMethod("toWKT", (Class[]) null)
59: .invoke(object, (Object[]) null);
60: } catch (Exception cause) {
61: final UnsupportedImplementationException exception;
62: exception = new UnsupportedImplementationException(classe);
63: exception.initCause(cause);
64: throw exception;
65: }
66: // TODO: Not yet implemented. We should insert the WKT in the formatter
67: // as pre-formatted text, and returns {@code null}.
68: throw new UnsupportedImplementationException(classe);
69: }
70: }
|