View Javadoc
1 /* 2 * Created on Sep 28, 2003 3 * Copyright (c) 2003. All rights reserved. 4 */ 5 package portaview.server; 6 7 import java.io.File; 8 import java.net.InetAddress; 9 import java.util.Hashtable; 10 import java.util.Iterator; 11 import java.util.List; 12 import java.util.Vector; 13 14 import org.apache.xmlrpc.XmlRpcHandler; 15 16 import portaview.Log; 17 import portaview.Registry; 18 import portaview.model.Album; 19 import portaview.model.AlbumModel; 20 import portaview.model.Photo; 21 import portaview.model.PortaViewCollection; 22 import portaview.model.PortaViewModel; 23 import portaview.model.SlideSettings; 24 25 /*** 26 * Commands for the XML-RPC server. Note that the signatures of 27 * class must be compliant to the XML-RPC conversion table. 28 * 29 * @author <a href="mailto:wwlee1@uiuc.edu">William Lee</a> 30 * @version $Id: PortaViewCommands.java,v 1.9 2003/12/10 06:18:57 wlee Exp $ 31 */ 32 public class PortaViewCommands implements XmlRpcHandler 33 { 34 35 private PortaViewServer server = null; 36 37 public PortaViewCommands(PortaViewServer server) 38 { 39 this.server = server; 40 } 41 42 /*** 43 * Given a show and a sequence number return the photo struct. 44 * @param show show name 45 * @param seq sequence number 46 * @return the byte array that represents the jpeg representation of the photo. 47 */ 48 public byte[] getPhoto(String show, int seq) 49 { 50 Album a = server.getRepository().getAlbum(show); 51 Photo p = a.getPhoto(seq); 52 return p.getJpeg(); 53 } 54 55 /*** 56 * Given a show and a sequence number return the photo struct. 57 * @param show show name 58 * @param seq sequence number 59 * @return the byte array that represents the jpeg representation of the photo. 60 */ 61 public byte[] getPhotoWithName(String album, String name) 62 { 63 Album a = server.getRepository().getAlbum(album); 64 Photo p = a.getPhoto(name); 65 return p.getJpeg(); 66 } 67 68 /*** 69 * Update this portaview main displayer. This will also spawn a request to the 70 * master server in order to download the image. 71 * 72 * @param slide the hashtable contains the following key. Here is an 73 * example: 74 * <pre> 75 * struct.put(ViewerConsts.TOTAL, new Integer(3)); // total number of slides 76 * struct.put(ViewerConsts.SPEED, new Integer(5)); // speed 0 = stop, >0 = second for the next slide. 77 * struct.put(ViewerConsts.BORDER_RED, new Integer(0)); // border red 78 * struct.put(ViewerConsts.BORDER_GREEN, new Integer(255)); // border green 79 * struct.put(ViewerConsts.BORDER_BLUE, new Integer(0)); // border blue 80 * struct.put(ViewerConsts.BORDER, new Integer(2)); // border thickness 81 * </pre> 82 * @return 83 */ 84 public boolean update(Hashtable slide) 85 { 86 synchronized (this) 87 { 88 SlideSettings newSlide = new SlideSettings(slide); 89 Registry 90 .getMainApplication() 91 .getThisPortaViewModel() 92 .setSlideSettings( 93 newSlide); 94 // server.getClient().getImageFromMaster(); 95 return true; 96 } 97 } 98 99 /*** 100 * RPC call for getting the status. 101 * 102 * @return A hastable like the argument for update. 103 */ 104 public Object getStatus() 105 { 106 synchronized (this.server) 107 { 108 return ( 109 Registry 110 .getMainApplication() 111 .getThisPortaViewModel() 112 .getSlideSettings() 113 .toHashtable()); 114 } 115 } 116 117 /*** 118 * Returns a Vector of Hashtables that contains the album name and photo names 119 * The hastable contains the "name", "icon", and "photos" key. The name is of 120 * type String, the icon key contains a byte[], and the photos is a Vector of Strings. 121 * @return a Vector of albums. 122 */ 123 public Vector getAlbums() 124 { 125 Vector rtn = new Vector(); 126 Hashtable album = null; 127 Repository rep = server.getRepository(); 128 List alist = rep.listAlbums(); 129 for (Iterator iter = alist.iterator(); iter.hasNext();) 130 { 131 Album a = (Album) iter.next(); 132 rtn.add(a.toXmlRpcType()); 133 } 134 return rtn; 135 } 136 137 /*** 138 * Returns a list of albums contained in the repository. Any folder 139 * under the repository structure that contains at least 1 JPEG would be 140 * considered an album. 141 * 142 * @param rep The location of the repository. 143 * @return a List of albums 144 */ 145 private List listAlbums(File rep) 146 { 147 return null; 148 } 149 150 /*** 151 * Registers this PortaView with the master given the master's ip address. 152 * @param masterName the Master server's name 153 * @param masterIP the Master server's IP 154 * @return A struct like: name=[Name of PortaView], ip=[ip address of the current portaView] 155 * 156 */ 157 public Hashtable registerMaster(String masterName, String masterIP) 158 throws Exception 159 { 160 synchronized (this.server) 161 { 162 Hashtable rtn = new Hashtable(); 163 server.setMasterName(masterName); 164 server.setMasterIP(InetAddress.getByName(masterIP)); 165 rtn.put("name", server.getName()); 166 rtn.put("ip", server.getInetAddress().getHostAddress()); 167 return rtn; 168 } 169 } 170 171 /*** 172 * Only would be called if this PortaView is a master. This is called 173 * by the remote PortaView to register them to this master. 174 * @param portaViewName the PortaView's name. 175 * @param myIP the IP address for the PortaView. 176 * @return true if successful, false otherwise. 177 */ 178 public boolean register(String portaViewName, String myIP) 179 { 180 PortaViewCollection pv = server.getRegisteredPortaViews(); 181 synchronized (pv) 182 { 183 try 184 { 185 PortaViewModel pvm = 186 new PortaViewModel( 187 portaViewName, 188 InetAddress.getByName(myIP), 189 new AlbumModel("(No Album")); 190 pv.addPortaView(pvm); 191 return true; 192 } 193 catch (Exception e) 194 { 195 e.printStackTrace(); 196 return false; 197 } 198 } 199 } 200 201 /*** 202 * Unregister the portaview from the master's list. 203 * 204 * @param portaViewName name of the PortaView. 205 * @return true if successful, false otherwise. 206 */ 207 public boolean unregister(String portaViewName) 208 { 209 PortaViewCollection pv = server.getRegisteredPortaViews(); 210 synchronized (pv) 211 { 212 boolean removed = false; 213 for (Iterator i = pv.iterator(); i.hasNext();) 214 { 215 PortaViewModel pvm = (PortaViewModel) i.next(); 216 if (pvm.getName().equals(portaViewName)) 217 { 218 i.remove(); 219 removed = true; 220 } 221 } 222 if (removed) 223 pv.notifyChange(); 224 } 225 return true; 226 } 227 228 /*** 229 * Implements the method to dispatch the methods. This contains the 230 * lookup necessary to redirect to the right call. 231 * @see org.apache.xmlrpc.XmlRpcHandler#execute(java.lang.String, java.util.Vector) 232 */ 233 public Object execute(String method, Vector params) throws Exception 234 { 235 // This is a somewhat stupid handler, but it's sufficient for now. 236 if (method.equals("main.registerMaster")) 237 { 238 Log.debug("s: Calling registerMaster with: " + params.toString()); 239 return registerMaster( 240 (String) params.get(0), 241 (String) params.get(1)); 242 } 243 else if (method.equals("main.register")) 244 { 245 Log.debug("s: Calling register with: " + params.toString()); 246 boolean b = 247 register((String) params.get(0), (String) params.get(1)); 248 return new Boolean(b); 249 } 250 else if (method.equals("main.unregister")) 251 { 252 Log.debug("s: Calling unregister with: " + params.toString()); 253 boolean b = unregister((String) params.get(0)); 254 return new Boolean(b); 255 } 256 else if (method.equals("main.getPhoto")) 257 { 258 Log.debug("s: Calling getPhoto with: " + params.toString()); 259 return getPhoto( 260 (String) params.get(0), 261 ((Integer) params.get(1)).intValue()); 262 } 263 else if (method.equals("main.getPhotoWithName")) 264 { 265 Log.debug("s: Calling getPhotoWithName with: " + params.toString()); 266 return getPhotoWithName( 267 (String) params.get(0), 268 (String) params.get(1)); 269 } 270 else if (method.equals("main.getStatus")) 271 { 272 Log.debug("s: Calling getStatus with: " + params.toString()); 273 return getStatus(); 274 } 275 else if (method.equals("main.update")) 276 { 277 Log.debug("s: Calling update with: " + params.toString()); 278 boolean b = update((Hashtable) params.get(0)); 279 return new Boolean(b); 280 } 281 else if (method.equals("main.getAlbums")) 282 { 283 Log.debug("s: Calling getAlbums with: " + params.toString()); 284 return getAlbums(); 285 } 286 return null; 287 } 288 }

This page was automatically generated by Maven