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.dispatcher;
020    
021    import java.util.logging.Logger;
022    
023    import org.fusesource.restygwt.client.Dispatcher;
024    import org.fusesource.restygwt.client.Method;
025    import org.fusesource.restygwt.client.callback.CallbackFactory;
026    import org.fusesource.restygwt.client.callback.FilterawareRequestCallback;
027    
028    import com.google.gwt.http.client.RequestBuilder;
029    import com.google.gwt.http.client.RequestCallback;
030    import com.google.gwt.logging.client.LogConfiguration;
031    
032    public class DefaultDispatcherFilter implements DispatcherFilter {
033    
034        /**
035         * where to get a callback from. gives us the ability to use
036         * customized {@link FilterawareRequestCallback}
037         */
038        private CallbackFactory callbackFactory;
039    
040        /**
041         * the one and only constructor
042         * @param cf
043         */
044        public DefaultDispatcherFilter(final CallbackFactory cf) {
045            this.callbackFactory = cf;
046        }
047    
048        /**
049         * main filter method for a dispatcherfilter.
050         *
051         * @return continue filtering or not
052         */
053        public boolean filter(final Method method, final RequestBuilder builder) {
054            if (LogConfiguration.loggingIsEnabled()) {
055                Logger.getLogger(Dispatcher.class.getName()).info(
056                        "Sending http request: " + builder.getHTTPMethod() + " "
057                                + builder.getUrl());
058            }
059    
060            builder.setCallback(callbackFactory.createCallback(method));
061            return true;
062        }
063    }