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