1 /* ServiceContext.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)
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
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
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
.GIOP
;
41 import gnu
.CORBA
.CDR
.AbstractCdrInput
;
42 import gnu
.CORBA
.CDR
.AbstractCdrOutput
;
44 import org
.omg
.CORBA
.BAD_INV_ORDER
;
45 import org
.omg
.CORBA
.BAD_PARAM
;
46 import org
.omg
.CORBA
.CompletionStatus
;
47 import org
.omg
.CORBA
.portable
.IDLEntity
;
50 * Contains the ORB service data being passed.
52 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
54 public class ServiceContext
58 * Use serialVersionUID for interoperability.
60 private static final long serialVersionUID
= 1;
62 /* Standard values for the context_id. */
63 public static final int TransactionService
= 0;
66 * Defines code sets, used to encode wide and narrow characters. Required for
67 * messages with data structures, involving wide characters.
69 public static final int CodeSets
= 1;
71 public static final int ChainBypassCheck
= 2;
73 public static final int ChainBypassInfo
= 3;
75 public static final int LogicalThreadId
= 4;
77 public static final int BI_DIR_IIOP
= 5;
79 public static final int SendingContextRunTime
= 6;
81 public static final int INVOCATION_POLICIES
= 7;
83 public static final int FORWARDED_IDENTITY
= 8;
86 * Contains exception details if exception being transferred is other than
87 * System or User exception. javax.rmi uses this context to transfer arbitrary
88 * java exceptions as CORBA value types.
90 public static final int UnknownExceptionInfo
= 9;
92 public static final int RTCorbaPriority
= 10;
94 public static final int RTCorbaPriorityRange
= 11;
96 public static final int FT_GROUP_VERSION
= 12;
98 public static final int FT_REQUEST
= 13;
100 public static final int ExceptionDetailMessage
= 14;
102 public static final int SecurityAttributeService
= 15;
104 public static final int ActivityService
= 16;
107 * The context id (for instance, 0x1 for code sets context). At the moment of
108 * writing, the OMG defines 16 standard values and provides rules to register
109 * the vendor specific context ids. The range 0-4095 is reserved for the
110 * future standard OMG contexts.
112 public int context_id
;
117 public byte[] context_data
;
120 * Crete unitialised instance.
122 public ServiceContext()
127 * Create from omg context.
129 public ServiceContext(org
.omg
.IOP
.ServiceContext from
)
131 context_id
= from
.context_id
;
132 context_data
= from
.context_data
;
136 * Read the context values from the stream.
138 * @param istream a stream to read from.
140 public static ServiceContext
read(AbstractCdrInput istream
)
142 int id
= istream
.read_ulong();
146 case CodeSetServiceContext
.ID
:
148 CodeSetServiceContext codeset
= new CodeSetServiceContext();
149 codeset
.readContext(istream
);
154 ServiceContext ctx
= new ServiceContext();
156 ctx
.context_data
= istream
.read_sequence();
162 * Read a sequence of contexts from the input stream.
164 public static ServiceContext
[] readSequence(AbstractCdrInput istream
)
166 int size
= istream
.read_long();
167 ServiceContext
[] value
= new gnu
.CORBA
.GIOP
.ServiceContext
[size
];
168 for (int i
= 0; i
< value
.length
; i
++)
169 value
[i
] = read(istream
);
174 * Write the context values into the stream.
176 * @param ostream a stream to write the data to.
178 public void write(AbstractCdrOutput ostream
)
180 ostream
.write_ulong(context_id
);
181 ostream
.write_sequence(context_data
);
185 * Write the sequence of contexts into the input stream.
187 public static void writeSequence(AbstractCdrOutput ostream
, ServiceContext
[] value
)
189 ostream
.write_long(value
.length
);
190 for (int i
= 0; i
< value
.length
; i
++)
191 value
[i
].write(ostream
);
195 * Add context to the given array of contexts.
197 public static void add(org
.omg
.IOP
.ServiceContext
[] cx
,
198 org
.omg
.IOP
.ServiceContext service_context
, boolean replace
)
202 for (int i
= 0; i
< cx
.length
; i
++)
203 if (cx
[i
].context_id
== service_context
.context_id
)
209 org
.omg
.IOP
.ServiceContext
[] n
= new org
.omg
.IOP
.ServiceContext
[cx
.length
+ 1];
210 for (int i
= 0; i
< cx
.length
; i
++)
212 n
[cx
.length
] = service_context
;
218 throw new BAD_INV_ORDER("Repetetive setting of the context "
219 + service_context
.context_id
, 15, CompletionStatus
.COMPLETED_NO
);
221 cx
[exists
] = service_context
;
226 * Add context to the given array of contexts.
228 public static ServiceContext
[] add(ServiceContext
[] cx
,
229 org
.omg
.IOP
.ServiceContext service_context
, boolean replace
)
233 for (int i
= 0; i
< cx
.length
; i
++)
234 if (cx
[i
].context_id
== service_context
.context_id
)
240 ServiceContext
[] n
= new ServiceContext
[cx
.length
+ 1];
241 for (int i
= 0; i
< cx
.length
; i
++)
243 n
[cx
.length
] = new ServiceContext(service_context
);
250 throw new BAD_INV_ORDER("Repetetive setting of the context "
251 + service_context
.context_id
, 15, CompletionStatus
.COMPLETED_NO
);
253 cx
[exists
] = new ServiceContext(service_context
);
259 * Find context with the given name in the context array.
261 public static org
.omg
.IOP
.ServiceContext
findContext(int ctx_name
,
262 org
.omg
.IOP
.ServiceContext
[] cx
)
264 for (int i
= 0; i
< cx
.length
; i
++)
265 if (cx
[i
].context_id
== ctx_name
)
267 throw new BAD_PARAM("No context with id " + ctx_name
);
271 * Find context with the given name in the context array, converting into
272 * org.omg.IOP.ServiceContext.
274 public static org
.omg
.IOP
.ServiceContext
findContext(int ctx_name
,
277 for (int i
= 0; i
< cx
.length
; i
++)
278 if (cx
[i
].context_id
== ctx_name
)
279 return new org
.omg
.IOP
.ServiceContext(ctx_name
, cx
[i
].context_data
);
280 throw new BAD_PARAM("No context with id " + ctx_name
);
284 * Find context with the given name in the context array without conversions.
286 public static ServiceContext
find(int ctx_name
, ServiceContext
[] cx
)
288 for (int i
= 0; i
< cx
.length
; i
++)
289 if (cx
[i
].context_id
== ctx_name
)
295 * Return a string representation.
297 public String
toString()
299 return "ctx " + context_id
+ ", size " + context_data
.length
;