Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.timesupport / org.gvsig.timesupport.lib / org.gvsig.timesupport.lib.impl / src / main / java / org / gvsig / timesupport / impl / TimeSupportDefaultImplLibrary.java @ 44136

History | View | Annotate | Download (9.27 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.timesupport.impl;
23

    
24
import org.gvsig.timesupport.AbsoluteInstantType;
25
import org.gvsig.timesupport.AbsoluteIntervalType;
26
import org.gvsig.timesupport.Chronology;
27
import org.gvsig.timesupport.DataTypes;
28
import org.gvsig.timesupport.TimeSupportLibrary;
29
import org.gvsig.timesupport.TimeSupportLocator;
30
import org.gvsig.timesupport.TimeSupportManager;
31
import org.gvsig.timesupport.impl.coercion.CoerceToDate;
32
import org.gvsig.timesupport.impl.coercion.CoerceToInstant;
33
import org.gvsig.timesupport.impl.coercion.CoerceToInterval;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.dataTypes.DataTypesManager;
36
import org.gvsig.tools.library.AbstractLibrary;
37
import org.gvsig.tools.library.LibraryException;
38

    
39
/**
40
 * Library for default implementation initialization and configuration.
41
 * 
42
 * @author gvSIG team
43
 * @version $Id$
44
 */
45
public class TimeSupportDefaultImplLibrary extends AbstractLibrary {
46

    
47
    @Override
48
    public void doRegistration() {
49
        registerAsImplementationOf(TimeSupportLibrary.class);
50
    }
51
    
52
    @Override
53
    protected void doInitialize() throws LibraryException {
54
        TimeSupportLocator.registerManager(DefaultTimeSupportManager.class);
55
    }
56

    
57
    @Override
58
    protected void doPostInitialize() throws LibraryException {
59
        //Register the types
60
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
61
        dataTypesManager.setCoercion(DataTypes.INSTANT, new CoerceToInstant());
62
        dataTypesManager.setCoercion(DataTypes.INTERVAL, new CoerceToInterval());
63
        dataTypesManager.addCoercion(DataTypes.DATE, new CoerceToDate());
64
        
65
        TimeSupportManager timeSupportManager = TimeSupportLocator.getManager();
66
        
67
        //register AbsoluteInstantType 
68
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.ERA, org.joda.time.DateTimeFieldType.era()));
69
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.YEAR_OF_ERA, org.joda.time.DateTimeFieldType.yearOfEra()));
70
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.CENTURY_OF_ERA, org.joda.time.DateTimeFieldType.centuryOfEra()));
71
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.YEAR_OF_CENTURY, org.joda.time.DateTimeFieldType.yearOfCentury()));
72
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.YEAR, org.joda.time.DateTimeFieldType.year()));
73
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.DAY_OF_YEAR, org.joda.time.DateTimeFieldType.dayOfYear()));
74
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MONTH_OF_YEAR, org.joda.time.DateTimeFieldType.monthOfYear()));
75
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.DAY_OF_MONTH, org.joda.time.DateTimeFieldType.dayOfMonth()));
76
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.WEEKYEAR_OF_CENTURY, org.joda.time.DateTimeFieldType.weekyearOfCentury()));
77
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.WEEKYEAR, org.joda.time.DateTimeFieldType.weekyear()));
78
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.WEEK_OF_WEEKYEAR, org.joda.time.DateTimeFieldType.weekOfWeekyear()));
79
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.DAY_OF_WEEK, org.joda.time.DateTimeFieldType.dayOfWeek()));
80
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.HALFDAY_OF_DAY, org.joda.time.DateTimeFieldType.halfdayOfDay()));
81
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.HOUR_OF_HALFDAY, org.joda.time.DateTimeFieldType.hourOfHalfday()));
82
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.CLOCKHOUR_OF_HALFDAY, org.joda.time.DateTimeFieldType.clockhourOfHalfday()));
83
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.CLOCKHOUR_OF_DAY, org.joda.time.DateTimeFieldType.clockhourOfDay()));
84
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.HOUR_OF_DAY, org.joda.time.DateTimeFieldType.hourOfDay()));
85
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MINUTE_OF_DAY, org.joda.time.DateTimeFieldType.minuteOfDay()));
86
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MINUTE_OF_HOUR, org.joda.time.DateTimeFieldType.minuteOfHour()));
87
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.SECOND_OF_DAY, org.joda.time.DateTimeFieldType.secondOfDay()));
88
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.SECOND_OF_MINUTE, org.joda.time.DateTimeFieldType.secondOfMinute()));
89
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MILLIS_OF_DAY, org.joda.time.DateTimeFieldType.millisOfDay()));
90
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MILLIS_OF_SECOND, org.joda.time.DateTimeFieldType.millisOfSecond()));
91
       
92
        //Register period types
93
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.YEARS, org.joda.time.PeriodType.years()));
94
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.MONTHS, org.joda.time.PeriodType.months()));
95
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.WEEKS, org.joda.time.PeriodType.weeks()));
96
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.DAYS, org.joda.time.PeriodType.days()));
97
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.HOURS, org.joda.time.PeriodType.hours()));
98
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.MINUTES, org.joda.time.PeriodType.minutes()));
99
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.SECONDS, org.joda.time.PeriodType.seconds()));
100
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.MILLIS, org.joda.time.PeriodType.millis()));
101
                              
102
        //register Chronologies
103
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.BUDDHIST, org.joda.time.chrono.BuddhistChronology.getInstance()));
104
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.COPTIC, org.joda.time.chrono.CopticChronology.getInstance()));
105
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.GJ, org.joda.time.chrono.GJChronology.getInstance()));
106
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.GREGORIAN, org.joda.time.chrono.GregorianChronology.getInstance()));
107
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.ISO, org.joda.time.chrono.ISOChronology.getInstance()));
108
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.JULIAN, org.joda.time.chrono.JulianChronology.getInstance()));
109
        
110
        //Sets the default chronology
111
        timeSupportManager.setDefaultChronology(Chronology.GREGORIAN);     
112
        
113
        //Add some string patterns to parse relative instants
114
        timeSupportManager.addRelativeInstantPattern("yyyy:MM:dd HH:mm:ss");
115
        timeSupportManager.addRelativeInstantPattern("yyyy:MM:dd");
116
        timeSupportManager.addRelativeInstantPattern("yyyy/MM/dd HH:mm:ss");
117
        timeSupportManager.addRelativeInstantPattern("yyyy/MM/dd");
118
        timeSupportManager.addRelativeInstantPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
119
        timeSupportManager.addRelativeInstantPattern("yyyy-MM-dd HH:mm:ss"); 
120
        timeSupportManager.addRelativeInstantPattern("yyyy-MM-dd");   
121
    }
122

    
123
}