KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > magnet > domain > Launcher


1 package org.sapia.magnet.domain;
2
3 // Import of Sapia's utility classes
4
// ---------------------------------
5
import org.sapia.util.xml.confix.ObjectWrapperIF;
6
7 // Import of Sapia's magnet classes
8
// --------------------------------
9
import org.sapia.magnet.render.AbstractRenderable;
10 import org.sapia.magnet.render.MagnetContext;
11 import org.sapia.magnet.render.RenderingException;
12
13
14 /**
15  *
16  *
17  * @author Jean-Cedric Desrochers
18  *
19  * <dl>
20  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
21  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
22  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
23  * </dl>
24  */

25 public class Launcher extends AbstractRenderable implements ObjectWrapperIF {
26
27   /////////////////////////////////////////////////////////////////////////////////////////
28
///////////////////////////////// INSTANCE ATTRIBUTES /////////////////////////////////
29
/////////////////////////////////////////////////////////////////////////////////////////
30

31   /** The type of this launcher. */
32   private String JavaDoc _theType;
33
34   /** The wrapped object of this launcher. */
35   private LaunchHandlerIF _theLaunchHandler;
36
37   /////////////////////////////////////////////////////////////////////////////////////////
38
//////////////////////////////////// CONSTRUCTORS /////////////////////////////////////
39
/////////////////////////////////////////////////////////////////////////////////////////
40

41   /**
42    * Creates a new Launcher instance.
43    */

44   public Launcher() {
45   }
46
47   /////////////////////////////////////////////////////////////////////////////////////////
48
////////////////////////////////// ACCESSOR METHODS ///////////////////////////////////
49
/////////////////////////////////////////////////////////////////////////////////////////
50

51   /**
52    * Returns the type of this launcher.
53    *
54    * @return The type of this launcher.
55    */

56   public String JavaDoc getType() {
57     return _theType;
58   }
59
60   /**
61    * Returns the wrapped launcher of this launcher.
62    *
63    * @return The wrapped launcher of this launcher.
64    */

65   public LaunchHandlerIF getLaunchHandler() {
66     if (_theLaunchHandler == null) {
67       throw new IllegalStateException JavaDoc("The laucher type is not define");
68     }
69
70     return _theLaunchHandler;
71   }
72
73   /////////////////////////////////////////////////////////////////////////////////////////
74
/////////////////////////////////// MUTATOR METHODS ///////////////////////////////////
75
/////////////////////////////////////////////////////////////////////////////////////////
76

77   /**
78    * Changes the type of this launcher for the value passed in.
79    *
80    * @param aType The new type.
81    * @exception IllegalArgumentException If the launcher type passed in
82    * is not recognized by the launcher.
83    */

84   public void setType(String JavaDoc aType) {
85     try {
86       _theType = aType;
87       _theLaunchHandler = HandlerFactory.getInstance().createLaunchHandler(aType);
88       _theLaunchHandler.setType(aType);
89     } catch (ObjectCreationException oce) {
90       throw new IllegalArgumentException JavaDoc("Unable to assign the launcher type - " + oce.getMessage());
91     }
92   }
93
94   /////////////////////////////////////////////////////////////////////////////////////////
95
/////////////////////////////////// HELPER METHODS ////////////////////////////////////
96
/////////////////////////////////////////////////////////////////////////////////////////
97

98   /**
99    * Executes this launch handler for the passed in profile.
100    *
101    * @param aProfile The profile to execute.
102    */

103   public void execute(String JavaDoc aProfile) {
104     _theLaunchHandler.execute(aProfile);
105   }
106
107   /////////////////////////////////////////////////////////////////////////////////////////
108
////////////////////////////////// OVERRIDEN METHODS //////////////////////////////////
109
/////////////////////////////////////////////////////////////////////////////////////////
110

111   /**
112    * Renders this objects to the magnet context passed in.
113    *
114    * @param aContext The magnet context to use.
115    * @exception RenderingException If an error occurs while rendering this object.
116    */

117   public void render(MagnetContext aContext) throws RenderingException {
118     if (_theLaunchHandler == null) {
119       throw new RenderingException("Unable to render the laucher - the laucher type is not define");
120     }
121     
122     _theLaunchHandler.render(aContext);
123   }
124
125   /**
126    * Returns a string representation of this launcher.
127    *
128    * @return A string representation of this launcher.
129    */

130   public String JavaDoc toString() {
131     StringBuffer JavaDoc aBuffer = new StringBuffer JavaDoc(super.toString());
132     aBuffer.append("[type=").append(_theType).
133             append(" launchHandler=").append(_theLaunchHandler).
134             append("]");
135
136     return aBuffer.toString();
137   }
138
139   /////////////////////////////////////////////////////////////////////////////////////////
140
/////////////////////////////// INTERACE IMPLEMENTATION ///////////////////////////////
141
/////////////////////////////////////////////////////////////////////////////////////////
142

143   /**
144    * Returns the object encapsulated by this wrapper.
145    *
146    * @return The object encapsulated by this wrapper.
147    */

148   public Object JavaDoc getWrappedObject(){
149     if (_theLaunchHandler == null) {
150       return this;
151     } else {
152       return _theLaunchHandler;
153     }
154   }
155 }
156
Popular Tags