40 |
|
|
41 |
import org.omg.CORBA.BAD_OPERATION; |
import org.omg.CORBA.BAD_OPERATION; |
42 |
import org.omg.CORBA.CompletionStatus; |
import org.omg.CORBA.CompletionStatus; |
43 |
|
import org.omg.CORBA.Policy; |
44 |
import org.omg.CORBA.PolicyHelper; |
import org.omg.CORBA.PolicyHelper; |
|
import org.omg.CORBA.PolicyOperations; |
|
45 |
import org.omg.CORBA.portable.InputStream; |
import org.omg.CORBA.portable.InputStream; |
46 |
import org.omg.CORBA.portable.InvokeHandler; |
import org.omg.CORBA.portable.InvokeHandler; |
47 |
import org.omg.CORBA.portable.ObjectImpl; |
import org.omg.CORBA.portable.ObjectImpl; |
49 |
import org.omg.CORBA.portable.ResponseHandler; |
import org.omg.CORBA.portable.ResponseHandler; |
50 |
|
|
51 |
/** |
/** |
52 |
* The server side implementatin base for the {@link Policy}. |
* The server side implementation base for the {@link Policy}. |
53 |
* |
* |
54 |
* @specnote The java 1.4 API does not define the server side policy |
* @specnote The java 1.4 API does not define the server side policy |
55 |
* implementation base, but it defines the policy client side stub. |
* implementation base, but it defines the policy client side stub. |
61 |
*/ |
*/ |
62 |
public abstract class _PolicyImplBase |
public abstract class _PolicyImplBase |
63 |
extends ObjectImpl |
extends ObjectImpl |
64 |
implements PolicyOperations, InvokeHandler |
implements Policy, InvokeHandler |
65 |
{ |
{ |
66 |
/** |
/** |
67 |
* Use serialVersionUID for interoperability. |
* Use serialVersionUID for interoperability. |
69 |
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
70 |
|
|
71 |
/** |
/** |
72 |
* The binding interator repository ids. |
* The policy repository ids. |
73 |
*/ |
*/ |
74 |
private static String[] ids = { PolicyHelper.id() }; |
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. |
* Return the list of repository ids. |
124 |
*/ |
*/ |
125 |
public String[] _ids() |
public final String[] _ids() |
126 |
{ |
{ |
127 |
return ids; |
return ids; |
128 |
} |
} |
130 |
/** |
/** |
131 |
* Call the required method. |
* Call the required method. |
132 |
*/ |
*/ |
133 |
public OutputStream _invoke(String method, InputStream input, |
public final OutputStream _invoke(String method, InputStream input, |
134 |
ResponseHandler rh |
ResponseHandler rh |
135 |
) |
) |
136 |
{ |
{ |
137 |
OutputStream output = null; |
OutputStream output = null; |
138 |
|
|
147 |
// The "copy" has been invoked. |
// The "copy" has been invoked. |
148 |
org.omg.CORBA.Object returns = copy(); |
org.omg.CORBA.Object returns = copy(); |
149 |
output = rh.createReply(); |
output = rh.createReply(); |
150 |
output.write_Object(returns); |
output.write_Object(this); |
151 |
} |
} |
152 |
else if (method.equals("policy_type")) |
else if (method.equals("policy_type")) |
153 |
{ |
{ |
156 |
output = rh.createReply(); |
output = rh.createReply(); |
157 |
output.write_long(returns); |
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 |
else |
168 |
throw new BAD_OPERATION(method, 0, CompletionStatus.COMPLETED_MAYBE); |
throw new BAD_OPERATION(method, 0, CompletionStatus.COMPLETED_MAYBE); |
169 |
|
|
170 |
return output; |
return output; |
171 |
} |
} |
172 |
|
|
173 |
|
/** |
174 |
|
* Get the value of this policy |
175 |
|
*/ |
176 |
|
public final java.lang.Object getValue() |
177 |
|
{ |
178 |
|
return value; |
179 |
|
} |
180 |
|
|
181 |
|
/** |
182 |
|
* Get the integer code of this policy value. |
183 |
|
*/ |
184 |
|
public final int getCode() |
185 |
|
{ |
186 |
|
return policyCode; |
187 |
|
} |
188 |
|
|
189 |
|
/** |
190 |
|
* Returns without action. It is a work of garbage collector |
191 |
|
* to remove the unused objects. |
192 |
|
*/ |
193 |
|
public final void destroy() |
194 |
|
{ |
195 |
|
} |
196 |
|
|
197 |
|
/** |
198 |
|
* Returns the string representation of the given policy. |
199 |
|
*/ |
200 |
|
public final String toString() |
201 |
|
{ |
202 |
|
return value.toString(); |
203 |
|
} |
204 |
|
|
205 |
|
/** |
206 |
|
* Create a copy of this policy. The object is not mutable, so |
207 |
|
* <code>this</code> can be returned. |
208 |
|
* |
209 |
|
* @return <code>this</code> |
210 |
|
*/ |
211 |
|
public Policy copy() |
212 |
|
{ |
213 |
|
return this; |
214 |
|
} |
215 |
|
|
216 |
|
/** |
217 |
|
* Use the value to get a hash code. |
218 |
|
*/ |
219 |
|
public int hashCode() |
220 |
|
{ |
221 |
|
return getValue().hashCode(); |
222 |
|
} |
223 |
|
|
224 |
|
/** |
225 |
|
* Check the values for equality. |
226 |
|
*/ |
227 |
|
public boolean equals(Object x) |
228 |
|
{ |
229 |
|
return x == null ? false : getValue().equals(x); |
230 |
|
} |
231 |
} |
} |