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.adapters;
022
023 import org.granite.config.flex.Destination;
024 import org.granite.gravity.Channel;
025 import org.granite.gravity.Gravity;
026 import org.granite.messaging.service.ServiceException;
027 import org.granite.util.XMap;
028
029 import flex.messaging.messages.AsyncMessage;
030 import flex.messaging.messages.CommandMessage;
031 import flex.messaging.messages.Message;
032
033 /**
034 * @author William DRAI
035 */
036 public abstract class ServiceAdapter {
037
038 private String id;
039 private Gravity gravity;
040 private Destination destination;
041 private Object adapterState;
042 private SecurityPolicy securityPolicy = new DefaultPolicy();
043
044
045 public String getId() {
046 return id;
047 }
048 public void setId(String id) {
049 this.id = id;
050 }
051
052 public Gravity getGravity() {
053 return gravity;
054 }
055 public void setGravity(Gravity gravity) {
056 this.gravity = gravity;
057 }
058
059 public Destination getDestination() {
060 return destination;
061 }
062 public void setDestination(Destination destination) {
063 this.destination = destination;
064 }
065
066 public Object getAdapterState() {
067 return adapterState;
068 }
069 public void setAdapterState(Object adapterState) {
070 this.adapterState = adapterState;
071 }
072
073 public SecurityPolicy getSecurityPolicy() {
074 return securityPolicy;
075 }
076 public void setSecurityPolicy(SecurityPolicy securityPolicy) {
077 this.securityPolicy = securityPolicy;
078 }
079
080
081 public void configure(XMap adapterProperties, XMap destinationProperties) throws ServiceException {
082 }
083
084 public void start() throws ServiceException {
085 }
086
087 public void stop() throws ServiceException {
088 }
089
090
091 public abstract Object manage(Channel fromClient, CommandMessage message);
092
093 public abstract Object invoke(Channel fromClient, AsyncMessage message);
094
095
096 private static class DefaultPolicy implements SecurityPolicy {
097
098 public boolean canCreate(Channel client, String channel, Message message) {
099 return client != null;
100 }
101
102 public boolean canSubscribe(Channel client, String channel, Message message) {
103 return client != null;
104 }
105
106 public boolean canPublish(Channel client, String channel, Message message) {
107 return client != null;
108 }
109 }
110 }