001    /**
002     * Copyright (C) 2009-2011 the original author or authors.
003     * See the notice.md file distributed with this work for additional
004     * information regarding copyright ownership.
005     *
006     * Licensed under the Apache License, Version 2.0 (the "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package org.fusesource.restygwt.client;
020    
021    
022    import org.fusesource.restygwt.client.dispatcher.DefaultDispatcher;
023    
024    import com.google.gwt.core.client.GWT;
025    
026    /**
027     * Provides ability to set the default date format and service root (defaults to
028     * GWT.getModuleBaseURL()).
029     *
030     *
031     * @author <a href="http://www.acuedo.com">Dave Finch</a>
032     *
033     */
034    public class Defaults {
035    
036        public static Dispatcher dispatcher = DefaultDispatcher.INSTANCE;
037    
038        private static String serviceRoot = GWT.getModuleBaseURL();
039        private static String dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
040        private static boolean ignoreJsonNulls = false;
041        // patch TNY: timeout ms,
042        // if >-1, used in Method class to set timeout
043        private static int requestTimeout = -1;
044    
045    
046        public static String getServiceRoot() {
047            return serviceRoot;
048        }
049    
050        /**
051         * sets the URL prepended to the value of Path annotations.
052         *
053         * @param serviceRoot
054         */
055        public static void setServiceRoot(String serviceRoot) {
056            // GWT.getModuleBaseURL() is guaranteed to end with a slash, so should any custom service root
057            if (!serviceRoot.endsWith("/")) {
058                serviceRoot += "/";
059            }
060            Defaults.serviceRoot = serviceRoot;
061        }
062        
063        public static String getDateFormat() {
064            return dateFormat;
065        }
066    
067        /**
068         * Sets the format used when encoding and decoding Dates.
069         *
070         * @param dateFormat
071         */
072        public static void setDateFormat(String dateFormat) {
073            Defaults.dateFormat = dateFormat;
074        }
075    
076        /**
077         * Indicates whether or not nulls will be ignored during JSON marshalling.
078         */
079        public static boolean doesIgnoreJsonNulls() {
080            return ignoreJsonNulls;
081        }
082    
083        public static void ignoreJsonNulls() {
084            ignoreJsonNulls = true;
085        }
086    
087        public static void dontIgnoreJsonNulls() {
088            ignoreJsonNulls = false;
089        }
090    
091        public static final int getRequestTimeout() {
092            return requestTimeout;
093        }
094    
095        public static final void setRequestTimeout(int requestTimeout) {
096            Defaults.requestTimeout = requestTimeout;
097        }
098    
099        /**
100         * Sets the default dispatcher used by Method instances.
101         *
102         * @param value
103         */
104        public static void setDispatcher(Dispatcher value) {
105            dispatcher = value;
106        }
107    
108        /**
109         * Returns the default dispatcher.
110         *
111         * @return
112         */
113        public static Dispatcher getDispatcher() {
114            return dispatcher;
115        }
116    }