Subversion Repositories XServices

Rev

Rev 66 | Blame | Last modification | View Log | Download | RSS feed

/*
 *   Copyright 2011 Brian Rosenberger (Brutex Network)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package net.brutex.xservices.ws;

import java.math.BigInteger;
import java.util.GregorianCalendar;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlElement;

import net.brutex.xservices.types.DateFormatType;
import net.brutex.xservices.types.DateTimeUnits;
import net.brutex.xservices.util.BrutexNamespaces;

import org.apache.cxf.annotations.WSDLDocumentation;
import org.apache.cxf.annotations.WSDLDocumentationCollection;

/**
 * Date and time related services.
 * @author Brian Rosenberger
 *
 */
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
@WSDLDocumentationCollection(
    {
        @WSDLDocumentation(value = BrutexNamespaces.BRUTEX_COPYRIGHT, placement = WSDLDocumentation.Placement.TOP)
    }
)
public interface DateService {
        
        public static final String SERVICE_NAME = "DateService";
        public static final String OPERATION_GETDATE = "getDate";
        public static final String OPERATION_GETTIMESTAMP = "getTimestamp";
        public static final String OPERATION_GETINTIMEZONE = "getInTimezone";
        public static final String OPERATION_FORMATDATE = "formatDate";
        public static final String OPERATION_FORMATDATEADVANCED = "formatDateAdvanced"; 
        public static final String OPERATION_PARSEDATE = "parseDate";
        public static final String OPERATION_PARSEDATEADVANCED = "parseDateAdvanced";
        public static final String OPERATION_DATETIMEDIFF = "dateTimeDiff";
        public static final String OPERATION_DATETIMEDIFF2 = "dateTimeDiff2";
        public static final String OPERATION_DATEADD = "dateAdd";
        
        public static final String PARAM_TIMEZONE = "timezone";
        public static final String PARAM_DATETIME = "datetime";
        public static final String PARAM_FORMAT = "format";
        public static final String PARAM_UNIT = "unit";
        
        /**
         * Get current date and time.
         * 
         * @param timezone Optional timezone. Defaults to server timezone.
         * @return Current date and time.
         * @throws XServicesFault 
         */
        @WebMethod(operationName=OPERATION_GETDATE)
        @WSDLDocumentation(value="Get current date and time.")
        public abstract GregorianCalendar getDate(
                        @WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
        
        /**
         * Get milliseconds since 01.01.1970.
         * 
         * @return timestamp milliseconds
         */
        @WebMethod(operationName=OPERATION_GETTIMESTAMP)
        @WSDLDocumentation(value="Get milliseconds since 01.01.1970 (Unix timestap).")
        public abstract BigInteger getTimestamp();
        
        /**
         * Display a date time with a different time zone. 
         * Changes representation only (no conversion).
         * 
         * @param cal date time.
         * @param timezone time zone
         * @return date time
         * @throws XServicesFault
         */
        @WebMethod(operationName=OPERATION_GETINTIMEZONE)
        public abstract GregorianCalendar getInTimezone(
                        @WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
                        @WebParam(name=PARAM_TIMEZONE) @XmlElement(required=true) String timezone) throws XServicesFault;
        
        /**
         * @param cal
         * @param format
         * @return formatted date/time string
         * @throws XServicesFault
         */
        @WebMethod(operationName=OPERATION_FORMATDATE)
        public abstract String formatDate(
                        @WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
                        @WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format) throws XServicesFault;
        
        @WebMethod(operationName=OPERATION_FORMATDATEADVANCED)
        public abstract String formatDateAdvanced(
                        @WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
                        @WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format) throws XServicesFault;
        
        @WebMethod(operationName=OPERATION_PARSEDATE)
        public abstract GregorianCalendar parseDate(
                        @WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
                        @WebParam(name=PARAM_FORMAT) @XmlElement(required=true) DateFormatType format,
                        @WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
        
        @WebMethod(operationName=OPERATION_PARSEDATEADVANCED)
        public abstract GregorianCalendar parseDateAdvanced(
                        @WebParam(name=PARAM_DATETIME) @XmlElement(required=true) String s,
                        @WebParam(name=PARAM_FORMAT) @XmlElement(required=true) String format,
                        @WebParam(name=PARAM_TIMEZONE) String timezone) throws XServicesFault;
        
        @WebMethod(operationName=OPERATION_DATETIMEDIFF)
        public abstract BigInteger dateTimeDiff(
                        @WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
                        @WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal) throws XServicesFault;
        
        /**
         * Fully elapsed units between two dates.
         * 4:15:10-4:15:55 in minutes = 0 and in seconds = 45
         * 
         * @param fromCal
         * @param toCal
         * @param unit
         * @return Date/time difference in unit
         * @throws XServicesFault
         */
        @WebMethod(operationName=OPERATION_DATETIMEDIFF2)
        @WSDLDocumentation(value="Get elapsed time between to dates.")
        public abstract BigInteger dateTimeDiff2(
                        @WebParam(name="fromDateTime") @XmlElement(required=true) GregorianCalendar fromCal,
                        @WebParam(name="toDateTime") @XmlElement(required=true) GregorianCalendar toCal,
                        @WebParam(name="PARAM_UNIT") DateTimeUnits unit) throws XServicesFault;
        
        /**
         * Add or substract a time span from a date.
         * 
         * @param cal
         * @param unit 
         * @return New date and time.
         * @throws XServicesFault
         */
        @WebMethod(operationName=OPERATION_DATEADD)
        @WSDLDocumentation(value="Add or substract a time span from a date.")
        public abstract GregorianCalendar dateAdd(
                        @WebParam(name=PARAM_DATETIME) @XmlElement(required=true) GregorianCalendar cal,
                        @WebParam(name="value") @XmlElement(required=true) BigInteger value,
                        @WebParam(name=PARAM_UNIT) @XmlElement(required=true) DateTimeUnits unit) throws XServicesFault;
        
}