1 package org.sapia.magnet.domain; 2 3 import java.util.Collection ; 6 import java.util.HashMap ; 7 import java.util.Map ; 8 9 import org.apache.log4j.Logger; 12 13 import org.sapia.magnet.render.MagnetContext; 16 import org.sapia.magnet.render.RenderingException; 17 18 19 30 public class DefaultLaunchHandler extends AbstractObjectHandler implements LaunchHandlerIF { 31 32 36 37 private static final Logger _theLogger = Logger.getLogger(DefaultLaunchHandler.class); 38 39 40 public static final int DEFAULT_WAIT_TIME = 1000; 41 42 46 47 private String _theType; 48 49 50 private String _theName; 51 52 53 private String _theDefault; 54 55 56 private int _theWaitTime; 57 58 59 private Magnet _theMagnet; 60 61 62 private Map _theProfiles; 63 64 68 71 protected DefaultLaunchHandler() { 72 _theProfiles = new HashMap (); 73 _theWaitTime = DEFAULT_WAIT_TIME; 74 } 75 76 80 85 public String getType() { 86 return _theType; 87 } 88 89 94 public String getName() { 95 return _theName; 96 } 97 98 103 public String getDefault() { 104 return _theDefault; 105 } 106 107 112 public int geWaitTime() { 113 return _theWaitTime; 114 } 115 116 121 public Magnet getMagnet() { 122 return _theMagnet; 123 } 124 125 130 public Collection getProfiles() { 131 return _theProfiles.values(); 132 } 133 134 140 public Profile getProfile(String aProfileName) { 141 return (Profile) _theProfiles.get(aProfileName); 142 } 143 144 152 public Profile findProfile(String aProfileName) { 153 if (aProfileName == null) { 155 throw new IllegalArgumentException ("The profile name passed in is null"); 156 } 157 158 Profile aProfile = getProfile(aProfileName); 160 if (aProfile == null && _theDefault != null) { 161 aProfile = getProfile(_theDefault); 162 } 163 164 return aProfile; 165 } 166 167 171 176 public void setType(String aType) { 177 _theType = aType; 178 } 179 180 185 public void setName(String aName) { 186 _theName = aName; 187 } 188 189 194 public void setDefault(String aProfileName) { 195 _theDefault = aProfileName; 196 } 197 198 203 public void setWaitTime(int aWaitTime) { 204 _theWaitTime = aWaitTime; 205 } 206 207 212 public void setMagnet(Magnet aMagnet) { 213 _theMagnet = aMagnet; 214 } 215 216 221 public void addProfile(Profile aProfile) { 222 if (aProfile == null) { 223 throw new IllegalArgumentException ("The profile passed in is null"); 224 } else if (aProfile.getName() == null) { 225 throw new IllegalArgumentException ("The name of the profile passed in is null"); 226 } 227 228 _theProfiles.put(aProfile.getName(), aProfile); 229 } 230 231 236 public void execute(String aProfile) { 237 if (_theLogger.isInfoEnabled()) { 238 _theLogger.info("Executing this launch handler for the profile " + 239 aProfile + "\n\t" + toString()); 240 } 241 } 242 243 247 253 public void render(MagnetContext aContext) throws RenderingException { 254 super.renderHandlerDefs(aContext); 255 } 256 257 261 266 public String toString() { 267 StringBuffer aBuffer = new StringBuffer (super.toString()); 268 aBuffer.append("[type=").append(_theType). 269 append(" name=").append(_theName). 270 append(" default=").append(_theDefault). 271 append(" waitTime=").append(_theWaitTime). 272 append(" profiles=").append(_theProfiles.values()). 273 append("]"); 274 275 return aBuffer.toString(); 276 } 277 } 278 | Popular Tags |