001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004    
005      This file is part of Granite Data Services.
006    
007      Granite Data Services is free software; you can redistribute it and/or modify
008      it under the terms of the GNU Library General Public License as published by
009      the Free Software Foundation; either version 2 of the License, or (at your
010      option) any later version.
011    
012      Granite Data Services is distributed in the hope that it will be useful, but
013      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014      FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015      for more details.
016    
017      You should have received a copy of the GNU Library General Public License
018      along with this library; if not, see <http://www.gnu.org/licenses/>.
019    */
020    
021    package org.granite.gravity;
022    
023    import javax.servlet.ServletContext;
024    
025    import org.granite.config.GraniteConfig;
026    import org.granite.config.flex.ServicesConfig;
027    import org.granite.context.GraniteContext;
028    import org.granite.gravity.adapters.ServiceAdapter;
029    
030    import flex.messaging.messages.AsyncMessage;
031    import flex.messaging.messages.Message;
032    
033    /**
034     * @author William DRAI
035     */
036    public class GravityProxy implements Gravity {
037    
038            private ServletContext servletContext;
039            
040            public GravityProxy(ServletContext servletContext) {
041                    this.servletContext = servletContext;
042            }
043            
044            private Gravity getGravity() {
045                    return GravityManager.getGravity(servletContext);
046            }
047    
048        ///////////////////////////////////////////////////////////////////////////
049        // Granite/Services configs access.
050    
051        public GravityConfig getGravityConfig() {
052            return getGravity().getGravityConfig();
053        }
054        public ServicesConfig getServicesConfig() {
055            return getGravity().getServicesConfig();
056        }
057        public GraniteConfig getGraniteConfig() {
058            return getGravity().getGraniteConfig();
059        }
060    
061        ///////////////////////////////////////////////////////////////////////////
062        // Properties.
063    
064            public boolean isStarted() {
065                    return getGravity().isStarted();
066            }
067    
068        ///////////////////////////////////////////////////////////////////////////
069        // Operations.
070    
071        public GraniteContext initThread() {
072            return getGravity().initThread();
073        }
074        public void releaseThread() {
075            getGravity().releaseThread();
076        }
077            
078            public ServiceAdapter getServiceAdapter(String messageType, String destinationId) {
079                    return getGravity().getServiceAdapter(messageType, destinationId);
080            }
081            
082        public void start() throws Exception {
083            getGravity().start();
084        }
085        public void reconfigure(GravityConfig gravityConfig, GraniteConfig graniteConfig) {
086            getGravity().reconfigure(gravityConfig, graniteConfig);
087        }
088        public void stop() throws Exception {
089            getGravity().stop();
090        }
091        public void stop(boolean now) throws Exception {
092            getGravity().stop(now);
093        }
094    
095        public Channel getChannel(String channelId) {
096            return getGravity().getChannel(channelId);
097        }
098        public Channel removeChannel(String channelId) {
099            return getGravity().removeChannel(channelId);
100        }
101        public boolean access(String channelId) {
102            return getGravity().access(channelId);
103        }
104        public void execute(AsyncChannelRunner runnable) {
105            getGravity().execute(runnable);
106        }
107        public boolean cancel(AsyncChannelRunner runnable) {
108            return getGravity().cancel(runnable);
109        }
110    
111        public Message handleMessage(Message message) {
112            return getGravity().handleMessage(message);
113        }
114        public Message handleMessage(Message message, boolean skipInterceptor) {
115            return getGravity().handleMessage(message, skipInterceptor);
116        }
117        public Message publishMessage(AsyncMessage message) {
118            return getGravity().publishMessage(message);
119        }
120        public Message publishMessage(Channel fromChannel, AsyncMessage message) {
121            return getGravity().publishMessage(fromChannel, message);
122        }
123    }