47 |
|
|
48 |
import org.omg.CORBA.BAD_PARAM; |
import org.omg.CORBA.BAD_PARAM; |
49 |
import org.omg.CORBA.CompletionStatus; |
import org.omg.CORBA.CompletionStatus; |
50 |
|
import org.omg.CORBA.MARSHAL; |
51 |
import org.omg.CORBA.ULongSeqHelper; |
import org.omg.CORBA.ULongSeqHelper; |
52 |
|
import org.omg.IOP.TAG_INTERNET_IOP; |
53 |
|
import org.omg.IOP.TAG_MULTIPLE_COMPONENTS; |
54 |
|
import org.omg.IOP.TaggedComponent; |
55 |
|
import org.omg.IOP.TaggedComponentHelper; |
56 |
|
import org.omg.IOP.TaggedProfile; |
57 |
|
import org.omg.IOP.TaggedProfileHelper; |
58 |
|
|
59 |
import java.io.ByteArrayOutputStream; |
import java.io.ByteArrayOutputStream; |
60 |
import java.io.IOException; |
import java.io.IOException; |
61 |
|
import java.util.ArrayList; |
62 |
|
|
63 |
/** |
/** |
64 |
* The implementaton of the Interoperable Object Reference (IOR). |
* The implementaton of the Interoperable Object Reference (IOR). IOR can be |
65 |
* IOR can be compared with the Internet address for a web page, |
* compared with the Internet address for a web page, it provides means to |
66 |
* it provides means to locate the CORBA service on the web. |
* locate the CORBA service on the web. IOR contains the host address, port |
67 |
* IOR contains the host address, port number, the object identifier |
* number, the object identifier (key) inside the server, the communication |
68 |
* (key) inside the server, the communication protocol version, |
* protocol version, supported charsets and so on. |
|
* supported charsets and so on. |
|
69 |
* |
* |
70 |
* Ths class provides method for encoding and |
* Ths class provides method for encoding and decoding the IOR information |
71 |
* decoding the IOR information from/to the stringified references, |
* from/to the stringified references, usually returned by |
72 |
* usually returned by {@link org.omg.CORBA.ORB#String object_to_string()}. |
* {@link org.omg.CORBA.ORB#String object_to_string()}. |
73 |
* |
* |
74 |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
75 |
* |
* |
79 |
public class IOR |
public class IOR |
80 |
{ |
{ |
81 |
/** |
/** |
82 |
* The code sets profile. |
* The code sets tagged component, normally part of the Internet profile. This |
83 |
|
* compone consists of the two componenets itself. |
84 |
*/ |
*/ |
85 |
public static class CodeSets_profile |
public static class CodeSets_profile |
86 |
{ |
{ |
87 |
|
public CodeSets_profile() |
88 |
|
{ |
89 |
|
int[] supported = CharSets_OSF.getSupportedCharSets(); |
90 |
|
|
91 |
|
narrow.native_set = CharSets_OSF.NATIVE_CHARACTER; |
92 |
|
narrow.conversion = supported; |
93 |
|
|
94 |
|
wide.native_set = CharSets_OSF.NATIVE_WIDE_CHARACTER; |
95 |
|
wide.conversion = supported; |
96 |
|
} |
97 |
|
|
98 |
/** |
/** |
99 |
* The code set component. |
* The code set component. |
100 |
*/ |
*/ |
131 |
b.append(" conversion "); |
b.append(" conversion "); |
132 |
for (int i = 0; i < conversion.length; i++) |
for (int i = 0; i < conversion.length; i++) |
133 |
{ |
{ |
134 |
b.append(name(conversion [ i ])); |
b.append(name(conversion[i])); |
135 |
b.append(' '); |
b.append(' '); |
136 |
} |
} |
137 |
} |
} |
150 |
|
|
151 |
private String name(int set) |
private String name(int set) |
152 |
{ |
{ |
153 |
return "0x" + Integer.toHexString(set) + " (" + |
return "0x" + Integer.toHexString(set) + " (" |
154 |
CharSets_OSF.getName(set) + ") "; |
+ CharSets_OSF.getName(set) + ") "; |
155 |
} |
} |
156 |
} |
} |
157 |
|
|
220 |
/** |
/** |
221 |
* The internet profile. |
* The internet profile. |
222 |
*/ |
*/ |
223 |
public static class Internet_profile |
public class Internet_profile |
224 |
{ |
{ |
225 |
/** |
/** |
226 |
* The agreed tag for the Internet profile. |
* The agreed tag for the Internet profile. |
243 |
public int port; |
public int port; |
244 |
|
|
245 |
/** |
/** |
246 |
|
* The code sets component in the internet profile of this IOR. This is not |
247 |
|
* a separate profile. |
248 |
|
*/ |
249 |
|
public CodeSets_profile CodeSets = new CodeSets_profile(); |
250 |
|
|
251 |
|
/** |
252 |
|
* Reserved for all components of this profile, this array holds the |
253 |
|
* components other than code set components. |
254 |
|
*/ |
255 |
|
ArrayList components = new ArrayList(); |
256 |
|
|
257 |
|
/** |
258 |
* Return the human readable representation. |
* Return the human readable representation. |
259 |
*/ |
*/ |
260 |
public String toString() |
public String toString() |
266 |
b.append(" (v"); |
b.append(" (v"); |
267 |
b.append(version); |
b.append(version); |
268 |
b.append(")"); |
b.append(")"); |
269 |
|
if (components.size() > 0) |
270 |
|
b.append(" " + components.size() + " extra components."); |
271 |
return b.toString(); |
return b.toString(); |
272 |
} |
} |
273 |
|
|
274 |
|
/** |
275 |
|
* Write the internet profile (except the heading tag. |
276 |
|
*/ |
277 |
|
public void write(cdrOutput out) |
278 |
|
{ |
279 |
|
try |
280 |
|
{ |
281 |
|
// Need to write the Internet profile into the separate |
282 |
|
// stream as we must know the size in advance. |
283 |
|
cdrOutput b = out.createEncapsulation(); |
284 |
|
|
285 |
|
version.write(b); |
286 |
|
b.write_string(host); |
287 |
|
|
288 |
|
b.write_ushort((short) (port & 0xFFFF)); |
289 |
|
|
290 |
|
// Write the object key. |
291 |
|
b.write_long(key.length); |
292 |
|
b.write(key); |
293 |
|
|
294 |
|
// Number of the tagged components. |
295 |
|
b.write_long(1 + components.size()); |
296 |
|
|
297 |
|
b.write_long(CodeSets_profile.TAG_CODE_SETS); |
298 |
|
CodeSets.write(b); |
299 |
|
|
300 |
|
TaggedComponent t; |
301 |
|
|
302 |
|
for (int i = 0; i < components.size(); i++) |
303 |
|
{ |
304 |
|
t = (TaggedComponent) components.get(i); |
305 |
|
TaggedComponentHelper.write(b, t); |
306 |
|
} |
307 |
|
|
308 |
|
b.close(); |
309 |
|
} |
310 |
|
catch (Exception e) |
311 |
|
{ |
312 |
|
MARSHAL m = new MARSHAL("Unable to write Internet profile."); |
313 |
|
m.initCause(e); |
314 |
|
throw m; |
315 |
|
} |
316 |
|
} |
317 |
} |
} |
318 |
|
|
319 |
/** |
/** |
320 |
* The standard minor code, indicating that the string to object |
* The standard minor code, indicating that the string to object converstio |
321 |
* converstio has failed due non specific reasons. |
* has failed due non specific reasons. |
322 |
*/ |
*/ |
323 |
public static final int FAILED = 10; |
public static final int FAILED = 10; |
324 |
|
|
325 |
/** |
/** |
|
* The code sets profile of this IOR. |
|
|
*/ |
|
|
public CodeSets_profile CodeSets = new CodeSets_profile(); |
|
|
|
|
|
/** |
|
326 |
* The internet profile of this IOR. |
* The internet profile of this IOR. |
327 |
*/ |
*/ |
328 |
public Internet_profile Internet = new Internet_profile(); |
public Internet_profile Internet = new Internet_profile(); |
333 |
public String Id; |
public String Id; |
334 |
|
|
335 |
/** |
/** |
336 |
* The additional tagged components, encapsulated in |
* The object key. |
|
* the byte arrays. They are only supported by the |
|
|
* later versions, than currently implemented. |
|
337 |
*/ |
*/ |
338 |
public byte[][] extra; |
public byte[] key; |
339 |
|
|
340 |
/** |
/** |
341 |
* The object key. |
* All tagged profiles of this IOR, except the separately defined Internet |
342 |
|
* profile. |
343 |
*/ |
*/ |
344 |
public byte[] key; |
ArrayList profiles = new ArrayList(); |
345 |
|
|
346 |
/** |
/** |
347 |
* True if the profile was encoded using the Big Endian or |
* True if the profile was encoded using the Big Endian or the encoding is not |
348 |
* the encoding is not known. |
* known. |
349 |
* |
* |
350 |
* false if it was encoded using the Little Endian. |
* false if it was encoded using the Little Endian. |
351 |
*/ |
*/ |
352 |
public boolean Big_Endian = true; |
public boolean Big_Endian = true; |
353 |
|
|
354 |
/** |
/** |
355 |
* Create an empty instance, initialising the code sets to default |
* Create an empty instance, initialising the code sets to default values. |
|
* values. |
|
356 |
*/ |
*/ |
357 |
public IOR() |
public IOR() |
358 |
{ |
{ |
|
int[] supported = CharSets_OSF.getSupportedCharSets(); |
|
|
|
|
|
CodeSets.narrow.native_set = CharSets_OSF.NATIVE_CHARACTER; |
|
|
CodeSets.narrow.conversion = supported; |
|
|
|
|
|
CodeSets.wide.native_set = CharSets_OSF.NATIVE_WIDE_CHARACTER; |
|
|
CodeSets.wide.conversion = supported; |
|
359 |
} |
} |
360 |
|
|
361 |
/** |
/** |
362 |
* Parse the provided stringifed reference. |
* Parse the provided stringifed reference. |
363 |
* |
* |
364 |
* @param stringified_reference, in the form of |
* @param stringified_reference, in the form of IOR:nnnnnn..... |
|
* IOR:nnnnnn..... |
|
365 |
* |
* |
366 |
* @return the parsed IOR |
* @return the parsed IOR |
367 |
* |
* |
370 |
* TODO corballoc and other alternative formats. |
* TODO corballoc and other alternative formats. |
371 |
*/ |
*/ |
372 |
public static IOR parse(String stringified_reference) |
public static IOR parse(String stringified_reference) |
373 |
throws BAD_PARAM |
throws BAD_PARAM |
374 |
{ |
{ |
375 |
try |
try |
376 |
{ |
{ |
377 |
if (!stringified_reference.startsWith("IOR:")) |
if (!stringified_reference.startsWith("IOR:")) |
378 |
throw new BAD_PARAM("The string refernce must start with IOR:", |
throw new BAD_PARAM("The string refernce must start with IOR:", |
379 |
FAILED, CompletionStatus.COMPLETED_NO |
FAILED, CompletionStatus.COMPLETED_NO); |
|
); |
|
380 |
|
|
381 |
IOR r = new IOR(); |
IOR r = new IOR(); |
382 |
|
|
401 |
{ |
{ |
402 |
ex.printStackTrace(); |
ex.printStackTrace(); |
403 |
throw new BAD_PARAM(ex + " while parsing " + stringified_reference, |
throw new BAD_PARAM(ex + " while parsing " + stringified_reference, |
404 |
FAILED, CompletionStatus.COMPLETED_NO |
FAILED, CompletionStatus.COMPLETED_NO); |
|
); |
|
405 |
} |
} |
406 |
} |
} |
407 |
|
|
412 |
* @throws IOException if the stream throws it. |
* @throws IOException if the stream throws it. |
413 |
*/ |
*/ |
414 |
public void _read(cdrInput c) |
public void _read(cdrInput c) |
415 |
throws IOException, BAD_PARAM |
throws IOException, BAD_PARAM |
416 |
{ |
{ |
417 |
int endian; |
int endian; |
418 |
|
|
426 |
} |
} |
427 |
|
|
428 |
/** |
/** |
429 |
* Read the IOR from the provided input stream, not reading |
* Read the IOR from the provided input stream, not reading the endian data at |
430 |
* the endian data at the beginning of the stream. The IOR is |
* the beginning of the stream. The IOR is thansferred in this form in |
|
* thansferred in this form in |
|
431 |
* {@link write_Object(org.omg.CORBA.Object)}. |
* {@link write_Object(org.omg.CORBA.Object)}. |
432 |
* |
* |
433 |
* If the stream contains a null value, the Id and Internet fields become |
* If the stream contains a null value, the Id and Internet fields become |
434 |
* equal to null. Otherwise Id contains some string (possibly |
* equal to null. Otherwise Id contains some string (possibly empty). |
|
* empty). |
|
435 |
* |
* |
436 |
* Id is checked for null in cdrInput that then returns |
* Id is checked for null in cdrInput that then returns null instead of |
437 |
* null instead of object. |
* object. |
438 |
* |
* |
439 |
* @param c a stream to read from. |
* @param c a stream to read from. |
440 |
* @throws IOException if the stream throws it. |
* @throws IOException if the stream throws it. |
441 |
*/ |
*/ |
442 |
public void _read_no_endian(cdrInput c) |
public void _read_no_endian(cdrInput c) |
443 |
throws IOException, BAD_PARAM |
throws IOException, BAD_PARAM |
444 |
{ |
{ |
445 |
Id = c.read_string(); |
Id = c.read_string(); |
446 |
|
|
465 |
Internet.host = profile.read_string(); |
Internet.host = profile.read_string(); |
466 |
Internet.port = profile.gnu_read_ushort(); |
Internet.port = profile.gnu_read_ushort(); |
467 |
|
|
468 |
int lk = profile.read_long(); |
key = profile.read_sequence(); |
|
key = new byte[ lk ]; |
|
|
profile.read(key); |
|
469 |
|
|
470 |
// Read tagged components. |
// Read tagged components. |
471 |
int n_components = 0; |
int n_components = 0; |
481 |
|
|
482 |
if (ctag == CodeSets_profile.TAG_CODE_SETS) |
if (ctag == CodeSets_profile.TAG_CODE_SETS) |
483 |
{ |
{ |
484 |
CodeSets.read(profile); |
Internet.CodeSets.read(profile); |
485 |
|
} |
486 |
|
else |
487 |
|
{ |
488 |
|
// Construct a generic component for codesets |
489 |
|
// profile. |
490 |
|
TaggedComponent pc = new TaggedComponent(); |
491 |
|
pc.tag = ctag; |
492 |
|
pc.component_data = profile.read_sequence(); |
493 |
|
Internet.components.add(pc); |
494 |
} |
} |
495 |
} |
} |
496 |
} |
} |
499 |
ex.printStackTrace(); |
ex.printStackTrace(); |
500 |
} |
} |
501 |
} |
} |
502 |
|
else |
503 |
|
{ |
504 |
|
// Construct a generic profile. |
505 |
|
TaggedProfile p = new TaggedProfile(); |
506 |
|
p.tag = tag; |
507 |
|
p.profile_data = profile.buffer.getBuffer(); |
508 |
|
|
509 |
|
profiles.add(p); |
510 |
|
} |
511 |
} |
} |
512 |
} |
} |
513 |
|
|
514 |
/** |
/** |
515 |
* Write this IOR record to the provided CDR stream. |
* Write this IOR record to the provided CDR stream. This procedure writes the |
516 |
* This procedure writes the zero (Big Endian) marker first. |
* zero (Big Endian) marker first. |
517 |
*/ |
*/ |
518 |
public void _write(cdrOutput out) |
public void _write(cdrOutput out) |
519 |
{ |
{ |
525 |
/** |
/** |
526 |
* Write a null value to the CDR output stream. |
* Write a null value to the CDR output stream. |
527 |
* |
* |
528 |
* The null value is written as defined in OMG specification |
* The null value is written as defined in OMG specification (zero length |
529 |
* (zero length string, followed by an empty set of profiles). |
* string, followed by an empty set of profiles). |
530 |
*/ |
*/ |
531 |
public static void write_null(cdrOutput out) |
public static void write_null(cdrOutput out) |
532 |
{ |
{ |
538 |
} |
} |
539 |
|
|
540 |
/** |
/** |
541 |
* Write this IOR record to the provided CDR stream. The procedure |
* Write this IOR record to the provided CDR stream. The procedure writed data |
542 |
* writed data in Big Endian, but does NOT add any endian marker |
* in Big Endian, but does NOT add any endian marker to the beginning. |
|
* to the beginning. |
|
543 |
*/ |
*/ |
544 |
public void _write_no_endian(cdrOutput out) |
public void _write_no_endian(cdrOutput out) |
545 |
{ |
{ |
546 |
try |
// Write repository id. |
547 |
{ |
out.write_string(Id); |
|
// Write repository id. |
|
|
out.write_string(Id); |
|
|
|
|
|
// Always one profile. |
|
|
out.write_long(1); |
|
|
|
|
|
// It is the Internet profile. |
|
|
out.write_long(Internet_profile.TAG_INTERNET_IOP); |
|
548 |
|
|
549 |
// Need to write the Internet profile into the separate |
out.write_long(1 + profiles.size()); |
|
// stream as we must know the size in advance. |
|
|
cdrOutput b = out.createEncapsulation(); |
|
550 |
|
|
551 |
Internet.version.write(b); |
// Write the Internet profile. |
552 |
b.write_string(Internet.host); |
out.write_long(Internet_profile.TAG_INTERNET_IOP); |
553 |
|
Internet.write(out); |
554 |
|
|
555 |
b.write_ushort((short) (Internet.port & 0xFFFF)); |
// Write other profiles. |
556 |
|
TaggedProfile tp; |
557 |
|
|
558 |
// Write the object key. |
for (int i = 0; i < profiles.size(); i++) |
|
b.write_long(key.length); |
|
|
b.write(key); |
|
|
|
|
|
// One tagged component. |
|
|
b.write_long(1); |
|
|
|
|
|
b.write_long(CodeSets_profile.TAG_CODE_SETS); |
|
|
CodeSets.write(b); |
|
|
|
|
|
b.close(); |
|
|
} |
|
|
catch (IOException ex) |
|
559 |
{ |
{ |
560 |
Unexpected.error(ex); |
tp = (TaggedProfile) profiles.get(i); |
561 |
|
TaggedProfileHelper.write(out, tp); |
562 |
} |
} |
563 |
} |
} |
564 |
|
|
579 |
|
|
580 |
for (int i = 0; i < key.length; i++) |
for (int i = 0; i < key.length; i++) |
581 |
{ |
{ |
582 |
b.append(Integer.toHexString(key [ i ] & 0xFF)); |
b.append(Integer.toHexString(key[i] & 0xFF)); |
583 |
} |
} |
584 |
|
|
585 |
b.append(" "); |
b.append(" "); |
586 |
b.append(CodeSets); |
b.append(Internet.CodeSets); |
587 |
|
|
588 |
return b.toString(); |
return b.toString(); |
589 |
} |
} |
606 |
|
|
607 |
for (int i = 0; i < binary.length; i++) |
for (int i = 0; i < binary.length; i++) |
608 |
{ |
{ |
609 |
s = Integer.toHexString(binary [ i ] & 0xFF); |
s = Integer.toHexString(binary[i] & 0xFF); |
610 |
if (s.length() == 1) |
if (s.length() == 1) |
611 |
b.append('0'); |
b.append('0'); |
612 |
b.append(s); |
b.append(s); |
614 |
|
|
615 |
return b.toString(); |
return b.toString(); |
616 |
} |
} |
617 |
|
|
618 |
|
/** |
619 |
|
* Adds a service-specific component to the IOR profile. The specified |
620 |
|
* component will be included in all profiles, present in the IOR. |
621 |
|
* |
622 |
|
* @param tagged_component a tagged component being added. |
623 |
|
*/ |
624 |
|
public void add_ior_component(TaggedComponent tagged_component) |
625 |
|
{ |
626 |
|
// Add to the Internet profile. |
627 |
|
Internet.components.add(tagged_component); |
628 |
|
|
629 |
|
// Add to others. |
630 |
|
for (int i = 0; i < profiles.size(); i++) |
631 |
|
{ |
632 |
|
TaggedProfile profile = (TaggedProfile) profiles.get(i); |
633 |
|
addComponentTo(profile, tagged_component); |
634 |
|
} |
635 |
|
} |
636 |
|
|
637 |
|
/** |
638 |
|
* Adds a service-specific component to the IOR profile. |
639 |
|
* |
640 |
|
* @param tagged_component a tagged component being added. |
641 |
|
* |
642 |
|
* @param profile_id the IOR profile to that the component must be added. The |
643 |
|
* 0 value ({@link org.omg.IOP.TAG_INTERNET_IOP#value}) adds to the Internet |
644 |
|
* profile where host and port are stored by default. |
645 |
|
*/ |
646 |
|
public void add_ior_component_to_profile(TaggedComponent tagged_component, |
647 |
|
int profile_id) |
648 |
|
{ |
649 |
|
if (profile_id == TAG_INTERNET_IOP.value) |
650 |
|
// Add to the Internet profile |
651 |
|
Internet.components.add(tagged_component); |
652 |
|
else |
653 |
|
{ |
654 |
|
// Add to others. |
655 |
|
for (int i = 0; i < profiles.size(); i++) |
656 |
|
{ |
657 |
|
TaggedProfile profile = (TaggedProfile) profiles.get(i); |
658 |
|
if (profile.tag == profile_id) |
659 |
|
addComponentTo(profile, tagged_component); |
660 |
|
} |
661 |
|
} |
662 |
|
} |
663 |
|
|
664 |
|
/** |
665 |
|
* Add given component to the given profile that is NOT an Internet profile. |
666 |
|
* |
667 |
|
* @param profile the profile, where the component should be added. |
668 |
|
* @param component the component to add. |
669 |
|
*/ |
670 |
|
private static void addComponentTo(TaggedProfile profile, |
671 |
|
TaggedComponent component) |
672 |
|
{ |
673 |
|
if (profile.tag == TAG_MULTIPLE_COMPONENTS.value) |
674 |
|
{ |
675 |
|
TaggedComponent[] present; |
676 |
|
if (profile.profile_data.length > 0) |
677 |
|
{ |
678 |
|
cdrBufInput in = new cdrBufInput(profile.profile_data); |
679 |
|
|
680 |
|
present = new TaggedComponent[in.read_long()]; |
681 |
|
|
682 |
|
for (int i = 0; i < present.length; i++) |
683 |
|
{ |
684 |
|
present[i] = TaggedComponentHelper.read(in); |
685 |
|
} |
686 |
|
} |
687 |
|
else |
688 |
|
present = new TaggedComponent[0]; |
689 |
|
|
690 |
|
cdrBufOutput out = new cdrBufOutput(profile.profile_data.length |
691 |
|
+ component.component_data.length |
692 |
|
+ 8); |
693 |
|
|
694 |
|
// Write new amount of components. |
695 |
|
out.write_long(present.length + 1); |
696 |
|
|
697 |
|
// Write other components. |
698 |
|
for (int i = 0; i < present.length; i++) |
699 |
|
TaggedComponentHelper.write(out, present[i]); |
700 |
|
|
701 |
|
// Write the passed component. |
702 |
|
TaggedComponentHelper.write(out, component); |
703 |
|
|
704 |
|
try |
705 |
|
{ |
706 |
|
out.close(); |
707 |
|
} |
708 |
|
catch (IOException e) |
709 |
|
{ |
710 |
|
throw new Unexpected(e); |
711 |
|
} |
712 |
|
profile.profile_data = out.buffer.toByteArray(); |
713 |
|
} |
714 |
|
else |
715 |
|
// The future supported tagged profiles should be added here. |
716 |
|
throw new BAD_PARAM("Unsupported profile type " + profile.tag); |
717 |
|
} |
718 |
} |
} |