38 |
|
|
39 |
package org.omg.IOP; |
package org.omg.IOP; |
40 |
|
|
41 |
|
import gnu.CORBA.CDR.cdrBufInput; |
42 |
|
import gnu.CORBA.CDR.cdrBufOutput; |
43 |
|
|
44 |
import org.omg.CORBA.Any; |
import org.omg.CORBA.Any; |
45 |
import org.omg.CORBA.BAD_OPERATION; |
import org.omg.CORBA.BAD_OPERATION; |
46 |
|
import org.omg.CORBA.MARSHAL; |
47 |
import org.omg.CORBA.ORB; |
import org.omg.CORBA.ORB; |
48 |
import org.omg.CORBA.StructMember; |
import org.omg.CORBA.StructMember; |
49 |
import org.omg.CORBA.TCKind; |
import org.omg.CORBA.TCKind; |
51 |
import org.omg.CORBA.portable.InputStream; |
import org.omg.CORBA.portable.InputStream; |
52 |
import org.omg.CORBA.portable.OutputStream; |
import org.omg.CORBA.portable.OutputStream; |
53 |
|
|
54 |
|
import java.io.IOException; |
55 |
|
|
56 |
/** |
/** |
57 |
* A helper operations for the structure {@link TaggedProfile}. |
* A helper operations for the structure {@link TaggedProfile}. |
58 |
* |
* |
59 |
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) |
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) |
60 |
*/ |
*/ |
61 |
public abstract class TaggedProfileHelper |
public abstract class TaggedProfileHelper |
62 |
{ |
{ |
63 |
/** |
/** |
66 |
private static TypeCode typeCode; |
private static TypeCode typeCode; |
67 |
|
|
68 |
/** |
/** |
69 |
* Create the TaggedProfile typecode (structure, |
* Create the TaggedProfile typecode (structure, named "TaggedProfile"). The |
70 |
* named "TaggedProfile"). |
* typecode states that the structure contains the following fields: tag, |
71 |
* The typecode states that the structure contains the |
* profile_data. |
|
* following fields: tag, profile_data. |
|
72 |
*/ |
*/ |
73 |
public static TypeCode type() |
public static TypeCode type() |
74 |
{ |
{ |
75 |
if (typeCode == null) |
if (typeCode == null) |
76 |
{ |
{ |
77 |
ORB orb = ORB.init(); |
ORB orb = ORB.init(); |
78 |
StructMember[] members = new StructMember[ 2 ]; |
StructMember[] members = new StructMember[2]; |
79 |
|
|
80 |
TypeCode field; |
TypeCode field; |
81 |
|
|
82 |
field = |
field = orb.create_alias_tc("IDL:omg.org/IOP/ProfileId:1.0", |
83 |
orb.create_alias_tc("IDL:omg.org/IOP/ProfileId:1.0", "ProfileId", |
"ProfileId", |
84 |
orb.get_primitive_tc(TCKind.tk_ulong) |
orb.get_primitive_tc(TCKind.tk_ulong)); |
85 |
); |
members[0] = new StructMember("tag", field, null); |
86 |
members [ 0 ] = new StructMember("tag", field, null); |
|
87 |
|
field = orb.create_sequence_tc(0, orb.get_primitive_tc(TCKind.tk_octet)); |
88 |
field = |
members[1] = new StructMember("profile_data", field, null); |
|
orb.create_sequence_tc(0, orb.get_primitive_tc(TCKind.tk_octet)); |
|
|
members [ 1 ] = new StructMember("profile_data", field, null); |
|
89 |
typeCode = orb.create_struct_tc(id(), "TaggedProfile", members); |
typeCode = orb.create_struct_tc(id(), "TaggedProfile", members); |
90 |
} |
} |
91 |
return typeCode; |
return typeCode; |
92 |
} |
} |
93 |
|
|
94 |
/** |
/** |
95 |
* Insert the TaggedProfile into the given Any. |
* Insert the TaggedProfile into the given Any. This method uses the |
96 |
* This method uses the TaggedProfileHolder. |
* TaggedProfileHolder. |
97 |
* |
* |
98 |
* @param any the Any to insert into. |
* @param any the Any to insert into. |
99 |
* @param that the TaggedProfile to insert. |
* @param that the TaggedProfile to insert. |
100 |
*/ |
*/ |
101 |
public static void insert(Any any, TaggedProfile that) |
public static void insert(Any any, TaggedProfile that) |
102 |
{ |
{ |
103 |
any.insert_Streamable(new TaggedProfileHolder(that)); |
any.insert_Streamable(new TaggedProfileHolder(that)); |
104 |
} |
} |
105 |
|
|
106 |
/** |
/** |
107 |
* Extract the TaggedProfile from given Any. |
* Extract the TaggedProfile from given Any. This method uses the |
108 |
* This method uses the TaggedProfileHolder. |
* TaggedProfileHolder. |
109 |
* |
* |
110 |
* @throws BAD_OPERATION if the passed Any does not contain TaggedProfile. |
* @throws BAD_OPERATION if the passed Any does not contain TaggedProfile. |
111 |
*/ |
*/ |
142 |
{ |
{ |
143 |
TaggedProfile value = new TaggedProfile(); |
TaggedProfile value = new TaggedProfile(); |
144 |
value.tag = input.read_long(); |
value.tag = input.read_long(); |
145 |
value.profile_data = new byte[ input.read_long() ]; |
|
146 |
for (int i0 = 0; i0 < value.profile_data.length; i0++) |
if (input instanceof cdrBufInput) |
147 |
value.profile_data [ i0 ] = input.read_octet(); |
{ |
148 |
|
// Highly probable. |
149 |
|
value.profile_data = ((cdrBufInput) input).read_sequence(); |
150 |
|
} |
151 |
|
else |
152 |
|
{ |
153 |
|
value.profile_data = new byte[input.read_long()]; |
154 |
|
for (int i0 = 0; i0 < value.profile_data.length; i0++) |
155 |
|
value.profile_data[i0] = input.read_octet(); |
156 |
|
} |
157 |
return value; |
return value; |
158 |
} |
} |
159 |
|
|
166 |
public static void write(OutputStream output, TaggedProfile value) |
public static void write(OutputStream output, TaggedProfile value) |
167 |
{ |
{ |
168 |
output.write_long(value.tag); |
output.write_long(value.tag); |
169 |
output.write_long(value.profile_data.length); |
|
170 |
for (int i0 = 0; i0 < value.profile_data.length; i0++) |
if (output instanceof cdrBufOutput) |
171 |
output.write_octet(value.profile_data [ i0 ]); |
{ |
172 |
|
// Highly probable. |
173 |
|
output.write_long(value.profile_data.length); |
174 |
|
try |
175 |
|
{ |
176 |
|
output.write(value.profile_data); |
177 |
|
} |
178 |
|
catch (IOException e) |
179 |
|
{ |
180 |
|
MARSHAL m = new MARSHAL(); |
181 |
|
m.initCause(e); |
182 |
|
throw m; |
183 |
|
} |
184 |
|
} |
185 |
|
else |
186 |
|
{ |
187 |
|
output.write_long(value.profile_data.length); |
188 |
|
for (int i0 = 0; i0 < value.profile_data.length; i0++) |
189 |
|
output.write_octet(value.profile_data[i0]); |
190 |
|
} |
191 |
} |
} |
192 |
} |
} |