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;
009: * version 2.1 of the License.
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.openoffice;
017:
018: // OpenOffice dependencies
019: import com.sun.star.lang.XSingleServiceFactory;
020: import com.sun.star.lang.XMultiServiceFactory;
021: import com.sun.star.comp.loader.FactoryHelper;
022: import com.sun.star.registry.XRegistryKey;
023: import com.sun.star.beans.XPropertySet;
024:
025: // Geotools dependencies
026: import org.geotools.nature.Calendar;
027: import org.geotools.nature.SeaWater;
028: import org.geotools.nature.SunRelativePosition;
029:
030: /**
031: * Exports methods from the {@link org.geotools.nature} package as
032: * <A HREF="http://www.openoffice.org">OpenOffice</A> add-ins.
033: *
034: * @since 2.2
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/openoffice/src/main/java/org/geotools/openoffice/Nature.java $
036: * @version $Id: Nature.java 20771 2006-07-31 12:52:44Z jgarnett $
037: * @author Martin Desruisseaux
038: */
039: public final class Nature extends Formulas implements XNature {
040: /**
041: * The name for the registration of this component.<BR>
042: * <strong>NOTE:</strong> OpenOffice expects a field with exactly that name; do not rename!
043: */
044: private static final String __serviceName = "org.geotools.openoffice.Nature";
045:
046: /**
047: * The name of the provided service.
048: */
049: private static final String ADDIN_SERVICE = "com.sun.star.sheet.AddIn";
050:
051: /**
052: * The number of milliseconds in a day. Divide by this quantity for conversions from
053: * milliseconds to days.
054: */
055: private static final double DAY_TO_MILLIS = 24.0 * 60 * 60 * 1000;
056:
057: /**
058: * The calculator for sun relative position. Will be created only when first needed.
059: */
060: private transient SunRelativePosition calculator;
061:
062: /**
063: * Constructs a default implementation of {@code XNature} interface.
064: */
065: public Nature() {
066: setTimeZone("GMT");
067: methods
068: .put(
069: "getNoonTime",
070: new MethodInfo(
071: "Nature",
072: "NOON.TIME",
073: "Returns the noon time (in GMT) when the Sun reach its highest point.",
074: new String[] {
075: "xOptions",
076: "Provided by OpenOffice.",
077: "latitude",
078: "The latitude of observation point, in degrees.",
079: "longitude",
080: "The longitude of observation point, in degrees.",
081: "time", "The observation date." }));
082: methods
083: .put(
084: "getElevation",
085: new MethodInfo(
086: "Nature",
087: "SUN.ELEVATION",
088: "Returns the Sun's elevation angle in degrees.",
089: new String[] {
090: "xOptions",
091: "Provided by OpenOffice.",
092: "latitude",
093: "The latitude of observation point, in degrees.",
094: "longitude",
095: "The longitude of observation point, in degrees.",
096: "time",
097: "The observation date and time, in GMT." }));
098: methods
099: .put(
100: "getAzimuth",
101: new MethodInfo(
102: "Nature",
103: "SUN.AZIMUTH",
104: "Returns the Sun's azimuth in degrees.",
105: new String[] {
106: "xOptions",
107: "Provided by OpenOffice.",
108: "latitude",
109: "The latitude of observation point, in degrees.",
110: "longitude",
111: "The longitude of observation point, in degrees.",
112: "time",
113: "The observation date and time, in GMT." }));
114: methods.put("getTropicalYearLength", new MethodInfo("Nature",
115: "TROPICAL.YEAR.LENGTH",
116: "Returns the tropical year length in days.",
117: new String[] { "xOptions", "Provided by OpenOffice.",
118: "time", "A date that contains the year." }));
119: methods.put("getSynodicMonthLength", new MethodInfo("Nature",
120: "SYNODIC.MONTH.LENGTH",
121: "Returns the synodic month length in days.",
122: new String[] { "xOptions", "Provided by OpenOffice.",
123: "time", "A date that contains the month." }));
124: methods
125: .put(
126: "getSeaWaterDensity",
127: new MethodInfo(
128: "Nature",
129: "SEAWATER.DENSITY",
130: "Computes sea water density (kg/m³) as a function of salinity, temperature and pressure.",
131: new String[] { "xOptions",
132: "Provided by OpenOffice.",
133: "salinity", "Salinity PSS-78.",
134: "temperature",
135: "Temperature ITS-68.",
136: "pressure",
137: "Pressure in decibars, not including atmospheric pressure." }));
138: methods
139: .put(
140: "getSeaWaterMeltingPoint",
141: new MethodInfo(
142: "Nature",
143: "SEAWATER.MELTING.POINT",
144: "Computes the sea water fusion temperature (melting point) as a function of salinity and pressure.",
145: new String[] { "xOptions",
146: "Provided by OpenOffice.",
147: "salinity", "Salinity PSS-78.",
148: "pressure",
149: "Pressure in decibars, not including atmospheric pressure." }));
150: methods
151: .put(
152: "getSeaWaterSoundVelocity",
153: new MethodInfo(
154: "Nature",
155: "SEAWATER.SOUND.VELOCITY",
156: "Computes the sound velocity in sea water as a function of salinity, temperature and pressure.",
157: new String[] { "xOptions",
158: "Provided by OpenOffice.",
159: "salinity", "Salinity PSS-78.",
160: "temperature",
161: "Temperature ITS-68.",
162: "pressure",
163: "Pressure in decibars, not including atmospheric pressure." }));
164: methods
165: .put(
166: "getSeaWaterSaturationO2",
167: new MethodInfo(
168: "Nature",
169: "SEAWATER.OXYGEN.SATURATION",
170: "Computes the saturation in disolved oxygen (µmol/kg) as a function of salinity and temperature.",
171: new String[] { "xOptions",
172: "Provided by OpenOffice.",
173: "salinity", "Salinity PSS-78.",
174: "temperature",
175: "Temperature ITS-68." }));
176: }
177:
178: /**
179: * Returns a factory for creating the service.
180: * This method is called by the {@code com.sun.star.comp.loader.JavaLoader}; do not rename!
181: *
182: * @param implementation The name of the implementation for which a service is desired.
183: * @param factories The service manager to be used if needed.
184: * @param registry The registry key
185: * @return A factory for creating the component.
186: */
187: public static XSingleServiceFactory __getServiceFactory(
188: final String implementation,
189: final XMultiServiceFactory factories,
190: final XRegistryKey registry) {
191: if (implementation.equals(Nature.class.getName())) {
192: return FactoryHelper.getServiceFactory(Nature.class,
193: __serviceName, factories, registry);
194: }
195: return null;
196: }
197:
198: /**
199: * Writes the service information into the given registry key.
200: * This method is called by the {@code com.sun.star.comp.loader.JavaLoader}; do not rename!
201: *
202: * @param registry The registry key.
203: * @return {@code true} if the operation succeeded.
204: */
205: public static boolean __writeRegistryServiceInfo(
206: final XRegistryKey registry) {
207: final String classname = Nature.class.getName();
208: return FactoryHelper.writeRegistryServiceInfo(classname,
209: __serviceName, registry)
210: && FactoryHelper.writeRegistryServiceInfo(classname,
211: ADDIN_SERVICE, registry);
212: }
213:
214: /**
215: * The service name that can be used to create such an object by a factory.
216: */
217: public String getServiceName() {
218: return __serviceName;
219: }
220:
221: /**
222: * Provides the supported service names of the implementation, including also
223: * indirect service names.
224: *
225: * @return Sequence of service names that are supported.
226: */
227: public String[] getSupportedServiceNames() {
228: return new String[] { ADDIN_SERVICE, __serviceName };
229: }
230:
231: /**
232: * Tests whether the specified service is supported, i.e. implemented by the implementation.
233: *
234: * @param name Name of service to be tested.
235: * @return {@code true} if the service is supported, {@code false} otherwise.
236: */
237: public boolean supportsService(final String name) {
238: return name.equals(ADDIN_SERVICE) || name.equals(__serviceName);
239: }
240:
241: /**
242: * Returns informations about sur relative position for the specified coordinates.
243: *
244: * @param xOptions Provided by OpenOffice.
245: * @param latitude The latitude of observation point, in degrees.
246: * @param longitude The longitude of observation point, in degrees.
247: * @param time The observation date and time, in GMT.
248: */
249: private SunRelativePosition getSunRelativePosition(
250: final XPropertySet xOptions, final double latitude,
251: final double longitude, final double time) {
252: if (calculator == null) {
253: calculator = new SunRelativePosition(Double.NaN);
254: }
255: calculator.setCoordinate(longitude, latitude);
256: calculator.setDate(toDate(xOptions, time));
257: return calculator;
258: }
259:
260: /**
261: * {@inheritDoc}
262: */
263: public double getNoonTime(final XPropertySet xOptions,
264: final double latitude, final double longitude,
265: final double time) {
266: return getSunRelativePosition(xOptions, latitude, longitude,
267: time).getNoonTime()
268: / DAY_TO_MILLIS;
269: }
270:
271: /**
272: * {@inheritDoc}
273: */
274: public double getElevation(final XPropertySet xOptions,
275: final double latitude, final double longitude,
276: final double time) {
277: return getSunRelativePosition(xOptions, latitude, longitude,
278: time).getElevation();
279: }
280:
281: /**
282: * {@inheritDoc}
283: */
284: public double getAzimuth(final XPropertySet xOptions,
285: final double latitude, final double longitude,
286: final double time) {
287: return getSunRelativePosition(xOptions, latitude, longitude,
288: time).getAzimuth();
289: }
290:
291: /**
292: * {@inheritDoc}
293: */
294: public double getTropicalYearLength(final XPropertySet xOptions,
295: final double time) {
296: return Calendar.tropicalYearLength(toDate(xOptions, time));
297: }
298:
299: /**
300: * {@inheritDoc}
301: */
302: public double getSynodicMonthLength(final XPropertySet xOptions,
303: final double time) {
304: return Calendar.synodicMonthLength(toDate(xOptions, time));
305: }
306:
307: /**
308: * {@inheritDoc}
309: */
310: public double getSeaWaterDensity(final XPropertySet xOptions,
311: final double salinity, final double temperature,
312: final double pressure) {
313: return SeaWater.density(salinity, temperature, pressure);
314: }
315:
316: /**
317: * {@inheritDoc}
318: */
319: public double getSeaWaterMeltingPoint(final XPropertySet xOptions,
320: final double salinity, final double pressure) {
321: return SeaWater.fusionTemperature(salinity, pressure);
322: }
323:
324: /**
325: * {@inheritDoc}
326: */
327: public double getSeaWaterSoundVelocity(final XPropertySet xOptions,
328: final double salinity, final double temperature,
329: final double pressure) {
330: return SeaWater.soundVelocity(salinity, temperature, pressure);
331: }
332:
333: /**
334: * {@inheritDoc}
335: */
336: public double getSeaWaterSaturationO2(final XPropertySet xOptions,
337: final double salinity, final double temperature) {
338: return SeaWater.saturationO2(salinity, temperature);
339: }
340: }
|