Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / CORBA / _PolicyImplBase.java
blob17a5f4a40e571cc733ad9e76e87ebd1e87142123
1 /* _PolicyImplBase.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package gnu.CORBA;
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;
51 /**
52 * The server side implementation base for the {@link Policy}.
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.
60 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
62 public abstract class _PolicyImplBase
63 extends ObjectImpl
64 implements Policy, InvokeHandler
66 /**
67 * Use serialVersionUID for interoperability.
69 private static final long serialVersionUID = 1;
71 /**
72 * The policy repository ids.
74 private final String[] ids;
76 /**
77 * The type of this policy.
79 private final int type;
81 /**
82 * The value of this policy. The value object is never the same
83 * for different policies.
85 private final java.lang.Object value;
87 /**
88 * The policy integer code, written in request to write
89 * the policy value.
91 private final int policyCode;
93 /**
94 * Create the new policy of the given type, having the given value.
95 * For security reasons, the method is kept package private.
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().
104 public _PolicyImplBase(int p_type, java.lang.Object p_value, int p_code,
105 String p_idl
108 type = p_type;
109 value = p_value;
110 policyCode = p_code;
111 ids = new String[] { p_idl, PolicyHelper.id() };
115 * Get the integer code of the type of this policy.
117 public final int policy_type()
119 return type;
123 * Return the list of repository ids.
125 public final String[] _ids()
127 return ids;
131 * Call the required method.
133 public final OutputStream _invoke(String method, InputStream input,
134 ResponseHandler rh
137 OutputStream output = null;
139 if (method.equals("destroy"))
141 // The "destroy" has been invoked.
142 destroy();
143 output = rh.createReply();
145 else if (method.equals("copy"))
147 // The "copy" has been invoked.
148 org.omg.CORBA.Object returns = copy();
149 output = rh.createReply();
150 output.write_Object(this);
152 else if (method.equals("policy_type"))
154 // The "policy_type" has been invoked.
155 int returns = policy_type();
156 output = rh.createReply();
157 output.write_long(returns);
159 else if (method.equals("value"))
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);
167 else
168 throw new BAD_OPERATION(method, Minor.Method,
169 CompletionStatus.COMPLETED_MAYBE);
171 return output;
175 * Get the value of this policy
177 public final java.lang.Object getValue()
179 return value;
183 * Get the integer code of this policy value.
185 public final int getCode()
187 return policyCode;
191 * Returns without action. It is a work of garbage collector
192 * to remove the unused objects.
194 public final void destroy()
199 * Returns the string representation of the given policy.
201 public final String toString()
203 return value.toString();
207 * Create a copy of this policy. The object is not mutable, so
208 * <code>this</code> can be returned.
210 * @return <code>this</code>
212 public Policy copy()
214 return this;
218 * Use the value to get a hash code.
220 public int hashCode()
222 return getValue().hashCode();
226 * Check the values for equality.
228 public boolean equals(Object x)
230 return x == null ? false : getValue().equals(x);