001/* ActivationDesc.java -- record with info to activate an object
002   Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
003   
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010 
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038package java.rmi.activation;
039
040import java.io.Serializable;
041import java.rmi.MarshalledObject;
042
043/**
044 * Contains the information, necessary to activate the object. This information
045 * includes:
046 * <ul>
047 * <li>the object class name</li>
048 * <li>the object group identifier</li>
049 * <li>the code location (codebase URL) that can be used to load the class
050 * remotely</li>
051 * <li>the object restart mode</li>
052 * <li>the object specific intialization information</li>
053 * </ul>
054 * 
055 * @author Audrius Meskauskas (audriusa@bioinformatics.org) (from stub) 
056 */
057public final class ActivationDesc
058    implements Serializable
059{
060  /**
061   * Use SVUID for interoperability.
062   */
063  static final long serialVersionUID = 7455834104417690957L;
064
065  /**
066   * The group id.
067   */
068  private ActivationGroupID groupid;
069
070  /**
071   * The class name.
072   */
073  private String classname;
074
075  /**
076   * The code location URL.
077   */
078  private String location;
079
080  /**
081   * The object specific intitalization data.
082   */
083  private MarshalledObject<?> data;
084
085  /**
086   * The start mode.
087   */
088  private boolean restart;
089
090  /**
091   * Create the new activation description, assuming the object group is the
092   * {@link ActivationGroup#currentGroupID()}. 
093   * 
094   * @param className the object fully qualified class name
095   * @param location the code base URL
096   * @param data the object initialization data, contained in a marshalled form
097   */
098  public ActivationDesc(String className, String location, MarshalledObject<?> data)
099      throws ActivationException
100  {
101    this(ActivationGroup.currentGroupID(), className, location, data, false);
102  }
103
104  /**
105   * Create the new activation description, assuming the object group is the
106   * {@link ActivationGroup#currentGroupID()}. 
107   * 
108   * @param className the object fully qualified class name
109   * @param location the code base URL
110   * @param data the object initialization data, contained in a marshalled form
111   * @param restart specifies reactivation mode after crash. If true, the object
112   *          is activated when activator is restarted or the activation group
113   *          is restarted. If false, the object is only activated on demand.
114   *          This flag does has no effect during the normal operation (the
115   *          object is normally activated on demand).
116   */
117  public ActivationDesc(String className, String location,
118                        MarshalledObject<?> data, boolean restart)
119      throws ActivationException
120  {
121    this(ActivationGroup.currentGroupID(), className, location, data, restart);
122  }
123
124  /**
125   * Create the new activation description. Under crash, the object will only
126   * be reactivated on demand.
127   * 
128   * @param groupID the object group id.
129   * @param className the object fully qualified class name
130   * @param location the code base URL
131   * @param data the object initialization data, contained in a marshalled form
132   */
133  public ActivationDesc(ActivationGroupID groupID, String className,
134                        String location, MarshalledObject<?> data)
135  {
136    this(groupID, className, location, data, false);
137  }
138
139  /**
140   * Create the new activation description, providing full information.
141   * 
142   * @param groupID the object group id.
143   * @param className the object fully qualified class name
144   * @param location the code base URL
145   * @param data the object initialization data, contained in a marshalled form
146   * @param restart specifies reactivation mode after crash. If true, the object
147   *          is activated when activator is restarted or the activation group
148   *          is restarted. If false, the object is only activated on demand.
149   *          This flag does has no effect during the normal operation (the
150   *          object is normally activated on demand).
151   */
152  public ActivationDesc(ActivationGroupID groupID, String className,
153                        String location, MarshalledObject<?> data, boolean restart)
154  {
155    this.groupid = groupID;
156    this.classname = className;
157    this.location = location;
158    this.data = data;
159    this.restart = restart;
160  }
161
162  public ActivationGroupID getGroupID()
163  {
164    return groupid;
165  }
166
167  /**
168   * Get the class name of the object being activated
169   * 
170   * @return the fully qualified class name of the object being activated
171   */
172  public String getClassName()
173  {
174    return classname;
175  }
176
177  /**
178   * Get the code location URL ("codebase") of the object being activated.
179   * 
180   * @return the codebase of the object being activated.
181   */
182  public String getLocation()
183  {
184    return location;
185  }
186
187  public MarshalledObject<?> getData()
188  {
189    return data;
190  }
191
192  /**
193   * Get the object reactivation strategy after crash.
194   * 
195   * @return true ir the object is activated when activator is restarted or the
196   *         activation group is restarted. False if the object is only
197   *         activated on demand. This flag does has no effect during the normal
198   *         operation (the object is normally activated on demand).
199   */
200  public boolean getRestartMode()
201  {
202    return restart;
203  }
204  
205  /**
206   * Compare this object with another activation description for equality.
207   * 
208   * @return true if all fields have the equal values, false otherwise.
209   */
210  public boolean equals(Object obj)
211  {
212    if (obj instanceof ActivationDesc)
213      {
214        ActivationDesc that = (ActivationDesc) obj;
215        return eq(groupid, that.groupid) &&
216               eq(classname, that.classname) && 
217               eq(location, that.location) && 
218               eq(data, that.data)
219               && restart == that.restart;
220      }
221    else
222      return false;
223  }
224  
225  /**
226   * Get the hash code of this object (overridden to make the returned value
227   * consistent with .equals(..).
228   */
229  public int hashCode()
230  {
231    return hash(groupid) ^ hash(classname) ^ 
232      hash(location) ^ hash(data);
233  }
234  
235  /**
236   * Get the hashcode of x or 0 if x == null.
237   */
238  static final int hash(Object x)
239  {
240    return x == null ? 0 : x.hashCode();
241  }
242  
243  /**
244   * Compare by .equals if both a and b are not null, compare directly if at
245   * least one of them is null.
246   */
247  static final boolean eq(Object a, Object b)
248  {
249    if (a == null || b == null)
250      return a == b;
251    else
252      return a.equals(b);
253  }
254}