View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2    		
3    		// --- IMPORTS FROM /messages/settings/javasettings/javaimport BEGIN
4   			import java.util.*;import javax.vecmath.*;import cz.cuni.amis.pogamut.base.communication.messages.*;import cz.cuni.amis.pogamut.base.communication.worldview.*;import cz.cuni.amis.pogamut.base.communication.worldview.event.*;import cz.cuni.amis.pogamut.base.communication.worldview.object.*;import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;import cz.cuni.amis.pogamut.base.communication.translator.event.*;import cz.cuni.amis.pogamut.multi.communication.translator.event.*;import cz.cuni.amis.pogamut.base3d.worldview.object.*;import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.*;import cz.cuni.amis.pogamut.ut2004.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;import cz.cuni.amis.utils.exception.*;import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;import cz.cuni.amis.utils.SafeEquals;import cz.cuni.amis.pogamut.base.agent.*;import cz.cuni.amis.pogamut.multi.agent.*;import cz.cuni.amis.pogamut.multi.communication.worldview.property.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.property.*;import cz.cuni.amis.utils.token.*;import cz.cuni.amis.utils.*;
5   		// --- IMPORTS FROM /messages/settings/javasettings/javaimport END
6   		
7   		
8   		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] BEGIN
9   				
10  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] END
11  		
12  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the shared part of the GameBots2004 message ALIVE.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Alive message are for confirmation, that
25  		the connection is still working. They are sent periodically with
26  		usual period of one second (this can change depending on the
27  		configuration of ControlServer)
28  	
29           */
30   	public class AliveMessageSharedImpl 
31    						extends
32    						AliveMessageShared
33  	    {
34   	
35      
36      	
37      	public AliveMessageSharedImpl(AliveMessageSharedImpl source) {
38  			
39  		}
40  		
41  		public AliveMessageSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
42  			this.Id = (UnrealId)objectId;
43  			NullCheck.check(this.Id, "objectId");
44  		
45  			if (properties.size() != 0) {
46  				throw new PogamutException("Not enough properties passed to the constructor.", AliveMessageSharedImpl.class);
47  			}
48  		
49  			//we have to do some checking in this one to know that we get all properties required
50  			for ( ISharedProperty property : properties ) {
51  				PropertyId pId = property.getPropertyId();
52  				if ( !objectId.equals( property.getObjectId() )) {
53  					//properties for different objects
54  					throw new PogamutException("Trying to create a AliveMessageSharedImpl with different WorldObjectId properties : " + 
55  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
56  				}
57  				if (!AliveMessageShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
58  				// property that does not belong here
59  				throw new PogamutException("Trying to create a AliveMessageSharedImpl with invalid property (invalid property token): " + 
60  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
61  				}
62  				propertyMap.put(property.getPropertyId(), property);
63  				
64  				
65  			}
66  		}
67      
68  						
69  						private UnrealId Id = cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AliveMessage.AliveMessageId;
70  						
71  						public UnrealId getId() {
72  							return Id;
73  						}
74  					
75     				
76     				@Override
77     				public void setSimTime(long SimTime) {
78  					super.setSimTime(SimTime);
79  				}
80     			
81  	    				@Override
82  	    				public 
83  	    				AliveMessageSharedImpl clone() {
84  	    					return new 
85  	    					AliveMessageSharedImpl(this);
86  	    				}
87  	    				
88  	    				
89  		
90  		
91  		
92  		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
93  			0
94  		);
95  		
96  		@Override
97  		public ISharedProperty getProperty(PropertyId id) {
98  			return propertyMap.get(id);
99  		}
100 
101 		@Override
102 		public Map<PropertyId, ISharedProperty> getProperties() {
103 			return propertyMap;
104 		}
105 	
106 		
107 		
108     	
109     	
110     	public static class AliveMessageSharedUpdate
111      implements ISharedWorldObjectUpdatedEvent
112 		{
113 	
114 			private AliveMessageShared object;
115 			private long time;
116 			private ITeamId teamId;
117 			
118 			public AliveMessageSharedUpdate
119     (AliveMessageShared data, long time, ITeamId teamId)
120 			{
121 				this.object = data;
122 				this.time = time;
123 				this.teamId = teamId;
124 			}
125 			
126 			/**
127 			 * Simulation time in MILLI SECONDS !!!
128 			 */
129 			@Override
130 			public long getSimTime() {
131 				return this.time;
132 			}
133 	
134 			@Override
135 			public WorldObjectId getId() {
136 				return object.getId();
137 			}
138 	
139 			@Override
140 			public ITeamId getTeamId() {
141 				return teamId;
142 			}
143 			
144 			@Override
145 			public Class getCompositeObjectClass()
146 			{
147 				return object.getCompositeClass();
148 			}
149 	
150 			@Override
151 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
152 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
153 				
154 				for ( ISharedProperty property : object.getProperties().values() )
155 				{
156 					if ( property != null)
157 					{
158 						events.push( property.createUpdateEvent(time, teamId) );
159 					}
160 				}
161 				return events;
162 			}
163 			
164 		}
165 	
166     
167  		
168  	    public String toString() {
169             return
170             	super.toString() + "[" +
171             	
172 				"]";           		
173         }
174  	
175  		
176  		public String toHtmlString() {
177  			return super.toString() + "[<br/>" +
178             	
179 				"<br/>]";     
180 		}
181  	
182  		
183  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
184         	
185 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
186 		
187 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
188 	        
189 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
190  	
191 		}
192