Source for gnu.CORBA._PolicyImplBase

   1: /* _PolicyImplBase.java --
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package gnu.CORBA;
  40: 
  41: import org.omg.CORBA.BAD_OPERATION;
  42: import org.omg.CORBA.CompletionStatus;
  43: import org.omg.CORBA.Policy;
  44: import org.omg.CORBA.PolicyHelper;
  45: import org.omg.CORBA.portable.InputStream;
  46: import org.omg.CORBA.portable.InvokeHandler;
  47: import org.omg.CORBA.portable.ObjectImpl;
  48: import org.omg.CORBA.portable.OutputStream;
  49: import org.omg.CORBA.portable.ResponseHandler;
  50: 
  51: /**
  52:  * The server side implementation base for the {@link Policy}.
  53:  *
  54:  * @specnote The java 1.4 API does not define the server side policy
  55:  * implementation base, but it defines the policy client side stub.
  56:  * As these two classes always work together, and even no separate testing is
  57:  * possible, the required implementation base is provided in gnu.CORBA
  58:  * namespace. Sun will probably include they base in the future java APIs.
  59:  *
  60:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  61:  */
  62: public abstract class _PolicyImplBase
  63:   extends ObjectImpl
  64:   implements Policy, InvokeHandler
  65: {
  66:   /**
  67:    * Use serialVersionUID for interoperability.
  68:    */
  69:   private static final long serialVersionUID = 1;
  70: 
  71:   /**
  72:    * The policy repository ids.
  73:    */
  74:   private final String[] ids;
  75: 
  76:   /**
  77:    * The type of this policy.
  78:    */
  79:   private final int type;
  80: 
  81:   /**
  82:    * The value of this policy. The value object is never the same
  83:    * for different policies.
  84:    */
  85:   private final java.lang.Object value;
  86: 
  87:   /**
  88:    * The policy integer code, written in request to write
  89:    * the policy value.
  90:    */
  91:   private final int policyCode;
  92: 
  93:   /**
  94:    * Create the new policy of the given type, having the given value.
  95:    * For security reasons, the method is kept package private.
  96:    *
  97:    * @param p_type the type of this policy.
  98:    * @param p_value the value of this policy.
  99:    * @param p_code the integer code of this policy.
 100:    * @param p_idl the policy IDL type string. The {@link #_ids()}
 101:    * will return array, first line being this string and another
 102:    * being PolicyHelper.id().
 103:    */
 104:   public _PolicyImplBase(int p_type, java.lang.Object p_value, int p_code,
 105:                          String p_idl
 106:                         )
 107:   {
 108:     type = p_type;
 109:     value = p_value;
 110:     policyCode = p_code;
 111:     ids = new String[] { p_idl, PolicyHelper.id() };
 112:   }
 113: 
 114:   /**
 115:    * Get the integer code of the type of this policy.
 116:    */
 117:   public final int policy_type()
 118:   {
 119:     return type;
 120:   }
 121: 
 122:   /**
 123:    * Return the list of repository ids.
 124:    */
 125:   public final String[] _ids()
 126:   {
 127:     return ids;
 128:   }
 129: 
 130:   /**
 131:    * Call the required method.
 132:    */
 133:   public final OutputStream _invoke(String method, InputStream input,
 134:                                     ResponseHandler rh
 135:                                    )
 136:   {
 137:     OutputStream output = null;
 138: 
 139:     if (method.equals("destroy"))
 140:       {
 141:         // The "destroy" has been invoked.
 142:         destroy();
 143:         output = rh.createReply();
 144:       }
 145:     else if (method.equals("copy"))
 146:       {
 147:         // The "copy" has been invoked.
 148:         org.omg.CORBA.Object returns = copy();
 149:         output = rh.createReply();
 150:         output.write_Object(this);
 151:       }
 152:     else if (method.equals("policy_type"))
 153:       {
 154:         // The "policy_type" has been invoked.
 155:         int returns = policy_type();
 156:         output = rh.createReply();
 157:         output.write_long(returns);
 158:       }
 159:     else if (method.equals("value"))
 160:       {
 161:         // The "value" can be invoked on the children types
 162:         // and must return an integer, representing the policy value
 163:         // (CORBA enumeration).
 164:         output = rh.createReply();
 165:         output.write_long(policyCode);
 166:       }
 167:     else
 168:       throw new BAD_OPERATION(method, Minor.Method,
 169:         CompletionStatus.COMPLETED_MAYBE);
 170: 
 171:     return output;
 172:   }
 173: 
 174:   /**
 175:    * Get the value of this policy
 176:    */
 177:   public final java.lang.Object getValue()
 178:   {
 179:     return value;
 180:   }
 181: 
 182:   /**
 183:    * Get the integer code of this policy value.
 184:    */
 185:   public final int getCode()
 186:   {
 187:     return policyCode;
 188:   }
 189: 
 190:   /**
 191:    * Returns without action. It is a work of garbage collector
 192:    * to remove the unused objects.
 193:    */
 194:   public final void destroy()
 195:   {
 196:   }
 197: 
 198:   /**
 199:    * Returns the string representation of the given policy.
 200:    */
 201:   public final String toString()
 202:   {
 203:     return value.toString();
 204:   }
 205: 
 206:   /**
 207:    * Create a copy of this policy. The object is not mutable, so
 208:    * <code>this</code> can be returned.
 209:    *
 210:    * @return <code>this</code>
 211:    */
 212:   public Policy copy()
 213:   {
 214:     return this;
 215:   }
 216: 
 217:   /**
 218:    * Use the value to get a hash code.
 219:    */
 220:   public int hashCode()
 221:   {
 222:     return getValue().hashCode();
 223:   }
 224: 
 225:   /**
 226:    * Check the values for equality.
 227:    */
 228:   public boolean equals(Object x)
 229:   {
 230:     return x == null ? false : getValue().equals(x);
 231:   }
 232: }