KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > magnet > domain > java > Codebase


1 package org.sapia.magnet.domain.java;
2
3 // Import of Sun's JDK classes
4
// ---------------------------
5
import java.util.Iterator JavaDoc;
6
7 // Import of Sapia's magnet classes
8
// --------------------------------
9
import org.sapia.magnet.domain.Path;
10 import org.sapia.magnet.domain.Resource;
11 import org.sapia.magnet.render.MagnetContext;
12 import org.sapia.magnet.render.RenderingException;
13
14
15 /**
16  *
17  *
18  * @author Jean-Cedric Desrochers
19  *
20  * <dl>
21  * <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>
22  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
23  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
24  * </dl>
25  */

26 public class Codebase extends Classpath {
27
28   /////////////////////////////////////////////////////////////////////////////////////////
29
///////////////////////////////// INSTANCE ATTRIBUTES /////////////////////////////////
30
/////////////////////////////////////////////////////////////////////////////////////////
31

32   /** The name of the profile associated to this codebase. */
33   private String JavaDoc _theProfileName;
34
35   /////////////////////////////////////////////////////////////////////////////////////////
36
//////////////////////////////////// CONSTRUCTORS /////////////////////////////////////
37
/////////////////////////////////////////////////////////////////////////////////////////
38

39   /**
40    * Creates a new Codebase instance.
41    */

42   public Codebase() {
43   }
44
45   /////////////////////////////////////////////////////////////////////////////////////////
46
////////////////////////////////// ACCESSOR METHODS ///////////////////////////////////
47
/////////////////////////////////////////////////////////////////////////////////////////
48

49   /**
50    * Returns the name of the associated profile of this codebase.
51    *
52    * @return The name of the associated profile of this codebase.
53    */

54   public String JavaDoc getProfile() {
55     return _theProfileName;
56   }
57
58   /////////////////////////////////////////////////////////////////////////////////////////
59
/////////////////////////////////// MUTATOR METHODS ///////////////////////////////////
60
/////////////////////////////////////////////////////////////////////////////////////////
61

62   /**
63    * Changes the profile name of this codebase.
64    *
65    * @param aProfileName The new profile name.
66    */

67   public void setProfile(String JavaDoc aProfileName) {
68     _theProfileName = aProfileName;
69   }
70
71   /////////////////////////////////////////////////////////////////////////////////////////
72
////////////////////////////////// OVERRIDEN METHODS //////////////////////////////////
73
/////////////////////////////////////////////////////////////////////////////////////////
74

75   /**
76    * Renders this objects to the magnet context passed in.
77    *
78    * @param aContext The magnet context to use.
79    * @exception RenderingException If an error occurs while rendering this object.
80    */

81   public void render(MagnetContext aContext) throws RenderingException {
82     if (_theProfileName == null ||
83         (aContext.getProfile() != null && _theProfileName.equals(aContext.getProfile()))) {
84       try {
85         super.render(aContext);
86   
87         StringBuffer JavaDoc aBuffer = new StringBuffer JavaDoc();
88         if (System.getProperty("java.rmi.server.codebase") != null) {
89           aBuffer.append(System.getProperty("java.rmi.server.codebase")).append(" ");
90         }
91
92         for (Iterator JavaDoc somePaths = getPaths().iterator(); somePaths.hasNext(); ) {
93           Path aPath = (Path) somePaths.next();
94           for (Iterator JavaDoc it = aPath.getSelectedResources().iterator(); it.hasNext(); ) {
95             Resource aResource = (Resource) it.next();
96             aBuffer.append(aResource.getURL()).append(" ");
97           }
98         }
99   
100         System.setProperty("java.rmi.server.codebase", aBuffer.toString());
101       } catch (RenderingException re) {
102         StringBuffer JavaDoc aBuffer = new StringBuffer JavaDoc("Unable to render the codebase of the");
103         if (_theProfileName == null) {
104           aBuffer.append(" default profile");
105         } else {
106           aBuffer.append(" profile ").append(_theProfileName);
107         }
108                   
109         throw new RenderingException(aBuffer.toString(), re);
110       }
111     }
112   }
113
114   /**
115    * Returns a string representation of this codebase.
116    *
117    * @return A string representation of this codebase.
118    */

119   public String JavaDoc toString() {
120     StringBuffer JavaDoc aBuffer = new StringBuffer JavaDoc(super.toString());
121     aBuffer.append("[profile=").append(_theProfileName).
122             append("]");
123
124     return aBuffer.toString();
125   }
126 }
127
128
Popular Tags