Subversion Repositories XServices

Rev

Rev 70 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 70 Rev 71
1
/*
1
/*
2
 *   Copyright 2011 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2011 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
17
package net.brutex.xservices.ws;
17
package net.brutex.xservices.ws;
18
 
18
 
19
import java.math.BigInteger;
19
import java.math.BigInteger;
20
import java.util.GregorianCalendar;
20
import java.util.GregorianCalendar;
21
 
21
 
22
import javax.jws.WebMethod;
22
import javax.jws.WebMethod;
23
import javax.jws.WebParam;
23
import javax.jws.WebParam;
24
import javax.jws.WebService;
24
import javax.jws.WebService;
25
import javax.xml.bind.annotation.XmlElement;
25
import javax.xml.bind.annotation.XmlElement;
26
 
26
 
27
import net.brutex.xservices.types.DateFormatType;
27
import net.brutex.xservices.types.DateFormatType;
28
import net.brutex.xservices.types.DateTimeUnits;
28
import net.brutex.xservices.types.DateTimeUnits;
29
import net.brutex.xservices.util.BrutexNamespaces;
29
import net.brutex.xservices.util.BrutexNamespaces;
30
 
30
 
31
import org.apache.cxf.annotations.WSDLDocumentation;
31
import org.apache.cxf.annotations.WSDLDocumentation;
32
import org.apache.cxf.annotations.WSDLDocumentationCollection;
32
import org.apache.cxf.annotations.WSDLDocumentationCollection;
33
 
33
 
34
/**
34
/**
35
 * Date and time related services.
35
 * Date and time related services.
36
 * @author Brian Rosenberger
36
 * @author Brian Rosenberger
37
 *
37
 *
38
 */
38
 */
39
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
39
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
40
@WSDLDocumentationCollection(
40
@WSDLDocumentationCollection(
41
    {
41
    {
42
    	@WSDLDocumentation(value = BrutexNamespaces.BRUTEX_COPYRIGHT, placement = WSDLDocumentation.Placement.TOP)
42
    	@WSDLDocumentation(value = BrutexNamespaces.BRUTEX_COPYRIGHT, placement = WSDLDocumentation.Placement.TOP)
43
    }
43
    }
44
)
44
)
45
public interface DateService {
45
public interface DateService {
46
	
46
	
47
	public static final String SERVICE_NAME = "DateService";
47
	public static final String SERVICE_NAME = "DateService";
48
	final String OPERATION_GETDATE = "getDate";
48
	final String OPERATION_GETDATE = "getDate";
49
	final String OPERATION_GETTIMESTAMP = "getTimestamp";
49
	final String OPERATION_GETTIMESTAMP = "getTimestamp";
-
 
50
	final String OPERATION_GETTIMESTAMP2 = "getTimestamp2";
50
	final String OPERATION_GETINTIMEZONE = "getInTimezone";
51
	final String OPERATION_GETINTIMEZONE = "getInTimezone";
51
	final String OPERATION_FORMATDATE = "formatDate";
52
	final String OPERATION_FORMATDATE = "formatDate";
52
	final String OPERATION_FORMATDATEADVANCED = "formatDateAdvanced";	
53
	final String OPERATION_FORMATDATEADVANCED = "formatDateAdvanced";	
53
	final String OPERATION_PARSEDATE = "parseDate";
54
	final String OPERATION_PARSEDATE = "parseDate";
54
	final String OPERATION_PARSEDATEADVANCED = "parseDateAdvanced";
55
	final String OPERATION_PARSEDATEADVANCED = "parseDateAdvanced";
55
	final String OPERATION_DATETIMEDIFF = "dateTimeDiff";
56
	final String OPERATION_DATETIMEDIFF = "dateTimeDiff";
56
	final String OPERATION_DATETIMEDIFF2 = "dateTimeDiff2";
57
	final String OPERATION_DATETIMEDIFF2 = "dateTimeDiff2";
57
	final String OPERATION_DATEADD = "dateAdd";
58
	final String OPERATION_DATEADD = "dateAdd";
58
	
59
	
59
	final String PARAM_TIMEZONE = "timezone";
60
	final String PARAM_TIMEZONE = "timezone";
60
	final String PARAM_DATETIME = "datetime";
61
	final String PARAM_DATETIME = "datetime";
61
	final String PARAM_FORMAT = "format";
62
	final String PARAM_FORMAT = "format";
62
	final String PARAM_UNIT = "unit";
63
	final String PARAM_UNIT = "unit";
63
	
64
	
64
	/**
65
	/**
65
	 * Get current date and time.
66
	 * Get current date and time.
66
	 * 
67
	 * 
67
	 * @param timezone Optional timezone. Defaults to server timezone.
68
	 * @param timezone Optional timezone. Defaults to server timezone.
68
	 * @return Current date and time.
69
	 * @return Current date and time.
69
	 * @throws XServicesFault 
70
	 * @throws XServicesFault 
70
	 */
71
	 */
71
	@WebMethod(operationName=OPERATION_GETDATE)
72
	@WebMethod(operationName=OPERATION_GETDATE)
72
	@WSDLDocumentation(value="Get current date and time.")
73
	@WSDLDocumentation(value="Get current date and time.")
73
	public abstract GregorianCalendar getDate(
74
	public abstract GregorianCalendar getDate(
74
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
75
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
75
	
76
	
76
	/**
77
	/**
77
	 * Get milliseconds since 01.01.1970.
78
	 * Get milliseconds since 01.01.1970.
78
	 * 
79
	 * 
79
	 * @return timestamp milliseconds
80
	 * @return timestamp milliseconds
80
	 */
81
	 */
81
	@WebMethod(operationName=OPERATION_GETTIMESTAMP)
82
	@WebMethod(operationName=OPERATION_GETTIMESTAMP)
82
	@WSDLDocumentation(value="Get milliseconds since 01.01.1970 (Unix timestap).")
83
	@WSDLDocumentation(value="Get milliseconds since 01.01.1970 (Unix timestap).")
83
	public abstract BigInteger getTimestamp();
84
	public abstract BigInteger getTimestamp();
-
 
85
 
-
 
86
	/**
-
 
87
	 * Get seconds since 01.01.1970.
-
 
88
	 * 
-
 
89
	 * @return timestamp seconds
-
 
90
	 */
-
 
91
	@WebMethod(operationName=OPERATION_GETTIMESTAMP2)
-
 
92
	@WSDLDocumentation(value="Get seconds since 01.01.1970 (Unix timestap).")
-
 
93
	public abstract BigInteger getTimestamp2();
84
	
94
	
85
	/**
95
	/**
86
	 * Display a date time with a different time zone. 
96
	 * Display a date time with a different time zone. 
87
	 * Changes representation only (no conversion).
97
	 * Changes representation only (no conversion).
88
	 * 
98
	 * 
89
	 * @param cal date time.
99
	 * @param cal date time.
90
	 * @param timezone time zone
100
	 * @param timezone time zone
91
	 * @return date time
101
	 * @return date time
92
	 * @throws XServicesFault
102
	 * @throws XServicesFault
93
	 */
103
	 */
94
	@WebMethod(operationName=OPERATION_GETINTIMEZONE)
104
	@WebMethod(operationName=OPERATION_GETINTIMEZONE)
95
	public abstract GregorianCalendar getInTimezone(
105
	public abstract GregorianCalendar getInTimezone(
96
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
106
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
97
			@WebParam(name=PARAM_TIMEZONE) @XmlElement(required=true) String timezone) throws XServicesFault;
107
			@WebParam(name=PARAM_TIMEZONE) @XmlElement(required=true) String timezone) throws XServicesFault;
98
	
108
	
99
	/**
109
	/**
100
	 * Formats a date with pre-defined patterns.
110
	 * Formats a date with pre-defined patterns.
101
	 * 
111
	 * 
102
	 * @param cal date time to be formatted
112
	 * @param cal date time to be formatted
103
	 * @param format Pattern to be used for date formating
113
	 * @param format Pattern to be used for date formating
104
	 * @return formatted date/time string
114
	 * @return formatted date/time string
105
	 * @throws XServicesFault
115
	 * @throws XServicesFault
106
	 */
116
	 */
107
	@WebMethod(operationName=OPERATION_FORMATDATE)
117
	@WebMethod(operationName=OPERATION_FORMATDATE)
108
	public abstract String formatDate(
118
	public abstract String formatDate(
109
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
119
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
110
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format) throws XServicesFault;
120
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format) throws XServicesFault;
111
	
121
	
112
	/**
122
	/**
113
	 * Formats a date with a free form pattern.
123
	 * Formats a date with a free form pattern.
114
	 * Uses SimpleDateFormat patterns
124
	 * Uses SimpleDateFormat patterns
115
	 * The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):
125
	 * The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):
116
 
126
 
117
    Letter	Date or Time Component	Presentation	Examples
127
    Letter	Date or Time Component	Presentation	Examples
118
    G	Era designator	Text	AD
128
    G	Era designator	Text	AD
119
    y	Year	Year	1996; 96
129
    y	Year	Year	1996; 96
120
    M	Month in year	Month	July; Jul; 07
130
    M	Month in year	Month	July; Jul; 07
121
    w	Week in year	Number	27
131
    w	Week in year	Number	27
122
    W	Week in month	Number	2
132
    W	Week in month	Number	2
123
    D	Day in year	Number	189
133
    D	Day in year	Number	189
124
    d	Day in month	Number	10
134
    d	Day in month	Number	10
125
    F	Day of week in month	Number	2
135
    F	Day of week in month	Number	2
126
    E	Day in week	Text	Tuesday; Tue
136
    E	Day in week	Text	Tuesday; Tue
127
    a	Am/pm marker	Text	PM
137
    a	Am/pm marker	Text	PM
128
    H	Hour in day (0-23)	Number	0
138
    H	Hour in day (0-23)	Number	0
129
    k	Hour in day (1-24)	Number	24
139
    k	Hour in day (1-24)	Number	24
130
    K	Hour in am/pm (0-11)	Number	0
140
    K	Hour in am/pm (0-11)	Number	0
131
    h	Hour in am/pm (1-12)	Number	12
141
    h	Hour in am/pm (1-12)	Number	12
132
    m	Minute in hour	Number	30
142
    m	Minute in hour	Number	30
133
    s	Second in minute	Number	55
143
    s	Second in minute	Number	55
134
    S	Millisecond	Number	978
144
    S	Millisecond	Number	978
135
    z	Time zone	General time zone	Pacific Standard Time; PST; GMT-08:00
145
    z	Time zone	General time zone	Pacific Standard Time; PST; GMT-08:00
136
    Z	Time zone	RFC 822 time zone	-0800
146
    Z	Time zone	RFC 822 time zone	-0800
137
	 * @param cal Date time to be formatted
147
	 * @param cal Date time to be formatted
138
	 * @param format Format string
148
	 * @param format Format string
139
	 * @return Date time formatted according to format string
149
	 * @return Date time formatted according to format string
140
	 * @throws XServicesFault
150
	 * @throws XServicesFault
141
	 */
151
	 */
142
	@WebMethod(operationName=OPERATION_FORMATDATEADVANCED)
152
	@WebMethod(operationName=OPERATION_FORMATDATEADVANCED)
143
	public abstract String formatDateAdvanced(
153
	public abstract String formatDateAdvanced(
144
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
154
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
145
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format) throws XServicesFault;
155
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format) throws XServicesFault;
146
	
156
	
147
	/**
157
	/**
148
	 * Converts a string into date using pre-defined date formats.
158
	 * Converts a string into date using pre-defined date formats.
149
	 * 
159
	 * 
150
	 * @param s Date/ time as string
160
	 * @param s Date/ time as string
151
	 * @param format date format
161
	 * @param format date format
152
	 * @param timezone timezone
162
	 * @param timezone timezone
153
	 * @return XML Date
163
	 * @return XML Date
154
	 * @throws XServicesFault
164
	 * @throws XServicesFault
155
	 */
165
	 */
156
	@WebMethod(operationName=OPERATION_PARSEDATE)
166
	@WebMethod(operationName=OPERATION_PARSEDATE)
157
	public abstract GregorianCalendar parseDate(
167
	public abstract GregorianCalendar parseDate(
158
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
168
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
159
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format,
169
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format,
160
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
170
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
161
	
171
	
162
	/**
172
	/**
163
	 * Converts a string into date using any format.
173
	 * Converts a string into date using any format.
164
	 * @param s date/ time as string
174
	 * @param s date/ time as string
165
	 * @param format date format
175
	 * @param format date format
166
	 * @param timezone timezone
176
	 * @param timezone timezone
167
	 * @return XML Date
177
	 * @return XML Date
168
	 * @throws XServicesFault
178
	 * @throws XServicesFault
169
	 */
179
	 */
170
	@WebMethod(operationName=OPERATION_PARSEDATEADVANCED)
180
	@WebMethod(operationName=OPERATION_PARSEDATEADVANCED)
171
	public abstract GregorianCalendar parseDateAdvanced(
181
	public abstract GregorianCalendar parseDateAdvanced(
172
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
182
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
173
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format,
183
			@WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format,
174
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
184
			@WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
175
	
185
	
176
	/**
186
	/**
177
	 * Calculate elapsed time between two dates.
187
	 * Calculate elapsed time between two dates.
178
	 * @param fromCal First date.
188
	 * @param fromCal First date.
179
	 * @param toCal Second date.
189
	 * @param toCal Second date.
180
	 * @return Elapsed time in milliseconds
190
	 * @return Elapsed time in milliseconds
181
	 * @throws XServicesFault
191
	 * @throws XServicesFault
182
	 */
192
	 */
183
	@WebMethod(operationName=OPERATION_DATETIMEDIFF)
193
	@WebMethod(operationName=OPERATION_DATETIMEDIFF)
184
	public abstract BigInteger dateTimeDiff(
194
	public abstract BigInteger dateTimeDiff(
185
			@WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
195
			@WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
186
			@WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal) throws XServicesFault;
196
			@WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal) throws XServicesFault;
187
	
197
	
188
	/**
198
	/**
189
	 * Fully elapsed units between two dates.
199
	 * Fully elapsed units between two dates.
190
	 * 4:15:10-4:15:55 in minutes = 0 and in seconds = 45
200
	 * 4:15:10-4:15:55 in minutes = 0 and in seconds = 45
191
	 * 
201
	 * 
192
	 * @param fromCal
202
	 * @param fromCal
193
	 * @param toCal
203
	 * @param toCal
194
	 * @param unit
204
	 * @param unit
195
	 * @return Date/time difference in unit
205
	 * @return Date/time difference in unit
196
	 * @throws XServicesFault
206
	 * @throws XServicesFault
197
	 */
207
	 */
198
	@WebMethod(operationName=OPERATION_DATETIMEDIFF2)
208
	@WebMethod(operationName=OPERATION_DATETIMEDIFF2)
199
	@WSDLDocumentation(value="Get elapsed time between to dates.")
209
	@WSDLDocumentation(value="Get elapsed time between to dates.")
200
	public abstract BigInteger dateTimeDiff2(
210
	public abstract BigInteger dateTimeDiff2(
201
			@WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
211
			@WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
202
			@WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal,
212
			@WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal,
203
			@WebParam(name="PARAM_UNIT") DateTimeUnits unit) throws XServicesFault;
213
			@WebParam(name="PARAM_UNIT") DateTimeUnits unit) throws XServicesFault;
204
	
214
	
205
	/**
215
	/**
206
	 * Add or subtract a time span from a date.
216
	 * Add or subtract a time span from a date.
207
	 * 
217
	 * 
208
	 * @param cal The initial date.
218
	 * @param cal The initial date.
209
	 * @param value The amount to add.
219
	 * @param value The amount to add.
210
	 * @param unit The unit the amount is defined in.
220
	 * @param unit The unit the amount is defined in.
211
	 * @return New date and time.
221
	 * @return New date and time.
212
	 * @throws XServicesFault
222
	 * @throws XServicesFault
213
	 * 
223
	 * 
214
	 */
224
	 */
215
	@WebMethod(operationName=OPERATION_DATEADD)
225
	@WebMethod(operationName=OPERATION_DATEADD)
216
	@WSDLDocumentation(value="Add or substract a time span from a date.")
226
	@WSDLDocumentation(value="Add or substract a time span from a date.")
217
	public abstract GregorianCalendar dateAdd(
227
	public abstract GregorianCalendar dateAdd(
218
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
228
			@WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
219
			@WebParam(name="value") @XmlElement(required=true) BigInteger value,
229
			@WebParam(name="value") @XmlElement(required=true) BigInteger value,
220
			@WebParam(name=PARAM_UNIT) @XmlElement(required=true) DateTimeUnits unit) throws XServicesFault;
230
			@WebParam(name=PARAM_UNIT) @XmlElement(required=true) DateTimeUnits unit) throws XServicesFault;
221
	
231
	
222
}
232
}