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.tide.invocation;
023    
024    import java.util.List;
025    import java.util.Map;
026    
027    import org.granite.tide.IInvocationResult;
028    import org.granite.tide.TideMessage;
029    
030    
031    /**
032     * @author William DRAI
033     */
034    public class InvocationResult implements IInvocationResult {
035    
036        private static final long serialVersionUID = 1L;
037        
038        
039        private Object result;
040        private int scope;
041        private boolean restrict;
042        private boolean merge = true;
043        private Object[][] updates;
044        private List<ContextUpdate> results;
045        private List<ContextEvent> events;
046        private List<TideMessage> messages;
047        private Map<String, List<TideMessage>> keyedMessages;
048        
049        
050        public InvocationResult() {
051        }
052        
053        public InvocationResult(Object result) {
054            this.result = result;
055        }
056        
057        public InvocationResult(Object result, List<ContextUpdate> results) {
058            this.result = result;
059            this.results = results;
060        }
061    
062        public Object getResult() {
063            return result;
064        }
065        public void setResult(Object result) {
066            this.result = result;
067        }
068        
069        public int getScope() {
070            return scope;
071        }
072        public void setScope(int scope) {
073            this.scope = scope;
074        }
075        
076        public boolean getRestrict() {
077            return restrict;
078        }
079        public void setRestrict(boolean restrict) {
080            this.restrict = restrict;
081        }
082        
083        public boolean getMerge() {
084            return merge;
085        }
086        public void setMerge(boolean merge) {
087            this.merge = merge;
088        }
089    
090        public Object[][] getUpdates() {
091            return updates;
092        }
093        public void setUpdates(Object[][] updates) {
094            this.updates = updates;
095        }
096    
097        public List<ContextUpdate> getResults() {
098            return results;
099        }
100        public void setResults(List<ContextUpdate> results) {
101            this.results = results;
102        }
103        
104        public List<ContextEvent> getEvents() {
105            return events;
106        }
107        public void setEvents(List<ContextEvent> events) {
108            this.events = events;
109        }
110    
111        public List<TideMessage> getMessages() {
112            return messages;
113        }
114        public void setMessages(List<TideMessage> messages) {
115            this.messages = messages;
116        }
117    
118        public Map<String, List<TideMessage>> getKeyedMessages() {
119            return keyedMessages;
120        }
121        public void setKeyedMessages(Map<String, List<TideMessage>> keyedMessages) {
122            this.keyedMessages = keyedMessages;
123        }
124        
125        
126        @Override
127        public String toString() {
128            StringBuilder sb = new StringBuilder();
129            sb.append(getClass().getName()).append(" ");
130            if (scope == 1)
131                    sb.append("(SESSION) ");
132            else if (scope == 2)
133                    sb.append("(CONVERSATION) ");
134            if (restrict)
135                    sb.append("(restricted) ");
136            sb.append("{\n");
137            sb.append("\tresult: ").append(result != null ? result : "(null)");
138            if (results != null) {
139                    sb.append("\tresults: [");
140                    for (Object result : results)
141                            sb.append(result != null ? result.toString() : "(null)").append(" ");
142                    sb.append("]\n");
143            }
144            if (updates != null) {
145                    sb.append("\tupdates: [");
146                    for (Object[] update : updates)
147                            sb.append(update[0]).append(":").append(update[1]).append(" ");
148                    sb.append("]\n");
149            }
150            if (events != null) {
151                    sb.append("\tevents: [");
152                    for (ContextEvent event : events)
153                            sb.append(event).append(" ");
154                    sb.append("]\n");
155            }
156            sb.append("}");
157            return sb.toString();
158        }
159    }