001    /**
002     *   GRANITE DATA SERVICES
003     *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004     *
005     *   This file is part of the Granite Data Services Platform.
006     *
007     *   Granite Data Services is free software; you can redistribute it and/or
008     *   modify it under the terms of the GNU Lesser General Public
009     *   License as published by the Free Software Foundation; either
010     *   version 2.1 of the License, or (at your option) any later version.
011     *
012     *   Granite Data Services is distributed in the hope that it will be useful,
013     *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015     *   General Public License for more details.
016     *
017     *   You should have received a copy of the GNU Lesser General Public
018     *   License along with this library; if not, write to the Free Software
019     *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020     *   USA, or see <http://www.gnu.org/licenses/>.
021     */
022    package org.granite.gravity.adapters;
023    
024    import org.granite.config.flex.Destination;
025    import org.granite.gravity.Channel;
026    import org.granite.gravity.Gravity;
027    import org.granite.logging.Logger;
028    import org.granite.messaging.service.ServiceException;
029    import org.granite.util.TypeUtil;
030    import org.granite.util.XMap;
031    
032    import flex.messaging.messages.AsyncMessage;
033    import flex.messaging.messages.CommandMessage;
034    
035    /**
036     * @author William DRAI
037     */
038    public abstract class ServiceAdapter {
039    
040        private static final Logger log = Logger.getLogger(ServiceAdapter.class);
041    
042        private String id;
043        private Gravity gravity;
044        private Destination destination;
045        private Object adapterState;
046        private SecurityPolicy securityPolicy = new DefaultSecurityPolicy();
047    
048    
049        public String getId() {
050            return id;
051        }
052        public void setId(String id) {
053            this.id = id;
054        }
055    
056        public Gravity getGravity() {
057            return gravity;
058        }
059        public void setGravity(Gravity gravity) {
060            this.gravity = gravity;
061        }
062    
063        public Destination getDestination() {
064            return destination;
065        }
066        public void setDestination(Destination destination) {
067            this.destination = destination;
068        }
069    
070        public Object getAdapterState() {
071            return adapterState;
072        }
073        public void setAdapterState(Object adapterState) {
074            this.adapterState = adapterState;
075        }
076    
077        public SecurityPolicy getSecurityPolicy() {
078            return securityPolicy;
079        }
080        public void setSecurityPolicy(SecurityPolicy securityPolicy) {
081            this.securityPolicy = securityPolicy;
082        }
083    
084    
085        public void configure(XMap adapterProperties, XMap destinationProperties) throws ServiceException {
086            String securityPolicy = adapterProperties.get("security-policy");
087            if (securityPolicy != null) {
088                    try {
089                            this.securityPolicy = TypeUtil.newInstance(securityPolicy, SecurityPolicy.class);
090                    }
091                    catch (Exception e) {
092                            log.error(e, "Could not create instance of %s (using default security policy)", securityPolicy);
093                    }
094            }
095        }
096    
097        public void start() throws ServiceException {
098        }
099    
100        public void stop() throws ServiceException {
101        }
102    
103    
104        public abstract Object manage(Channel fromClient, CommandMessage message);
105    
106        public abstract Object invoke(Channel fromClient, AsyncMessage message);
107    }