001package votorola.s.gwt.scene.feed.ss; // Copyright 2011-2012, Christian Weilbach, Michael Allan.  Permission is hereby
002// granted, free of charge, to any person obtaining a copy of this software and associated
003// documentation files (the "Votorola Software"), to deal in the Votorola Software without
004// restriction, including without limitation the rights to use, copy, modify, merge, publish,
005// distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to
006// whom the Votorola Software is furnished to do so, subject to the following conditions: The
007// preceding copyright notice and this permission notice shall be included in all copies or
008// substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT
009// WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
010// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
011// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
012// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA
013// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
014
015import com.google.gson.stream.JsonWriter;
016import java.io.IOException;
017
018
019/** A mutable and serializeable message.
020  */
021public final class MessageJig implements votorola.s.gwt.stage.Message, SerialJig
022{
023
024
025   // - M e s s a g e  --------------------------------------------------------------------------
026
027
028    public String content() { return content; }
029
030        private String content;
031
032
033        /** Sets the content.
034          */
035        public void setContent( String s ) { content = s; }
036
037
038        private void content( final JsonWriter out ) throws IOException
039        {
040            if( content == null ) throw new NullPointerException(); // meet contract of Message
041
042            out.name( "content" ).value( content );
043            content = null;
044        }
045
046    public String location() { return location; }
047
048        private String location;
049
050
051        /** Set a url for the message.
052          */
053        public void setLocation( String s ) { location = s; }
054
055
056        private void location( final JsonWriter out ) throws IOException
057        {
058            if( location == null ) throw new IllegalArgumentException(); // meet contract of Message
059
060            out.name( "location" ).value( location );
061            location = null;
062        }
063        
064    public int id() { return id; }
065    
066        private int id = 0;
067        
068        /**
069         * Set id of the message in the db.
070         */
071        public void setId( final int _id ) {
072            id = _id;
073        }
074        
075        private void id( final JsonWriter out ) throws IOException
076        {
077            out.name("id").value( id );
078            id = 0;
079        }
080
081
082
083   // - S e r i a l - J i g --------------------------------------------------------------
084
085
086    public void serialize( final JsonWriter out ) throws IOException
087    {
088        out.beginObject();
089        id( out );
090        content( out );
091        location( out );
092        out.endObject();
093    }
094
095
096
097}