-
Notifications
You must be signed in to change notification settings - Fork 22
/
RepositoryId.java
1054 lines (882 loc) · 38.2 KB
/
RepositoryId.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998-1999 IBM Corp. All rights reserved.
* Copyright (c) 2019-2020 Payara Services Ltd.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License v2.0
* w/Classpath exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause OR GPL-2.0 WITH
* Classpath-exception-2.0
*/
package com.sun.corba.ee.impl.util;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.Hashtable;
import java.util.IdentityHashMap;
import java.io.IOException;
import java.lang.reflect.Method;
// Imports for using codebase URL to load class
import java.net.MalformedURLException;
import com.sun.corba.ee.impl.io.ObjectStreamClass;
import com.sun.corba.ee.impl.javax.rmi.CORBA.Util;
import com.sun.corba.ee.impl.misc.ClassInfoCache ;
import org.glassfish.pfl.basic.concurrent.SoftCache;
public class RepositoryId {
// Legal IDL Identifier characters (1 = legal). Note
// that '.' (2E) is marked as legal even though it is
// not legal in IDL. This allows us to treat a fully
// qualified Java name with '.' package separators
// uniformly, and is safe because that is the only
// legal use of '.' in a Java name.
public static final byte[] IDL_IDENTIFIER_CHARS = {
// 0 1 2 3 4 5 6 7 8 9 a b c d e f
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 10-1f
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,1,0, // 20-2f
1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0, // 30-3f
0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 40-4f
1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, // 50-5f
0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 60-6f
1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0, // 70-7f
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 80-8f
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 90-9f
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // a0-af
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // b0-bf
1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // c0-cf
0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // d0-df
1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // e0-ef
0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // f0-ff
};
private static final long serialVersionUID = 123456789L;
private static final String defaultServerURL = JDKBridge.getLocalCodebase() ;
private static final boolean useCodebaseOnly = JDKBridge.useCodebaseOnly() ;
private static final Map<Class<?>, String> classToRepStr = new WeakHashMap<>();
private static final Map<Class<?>, String> classIDLToRepStr = new WeakHashMap<>();
private static final Map<Class<?>, String> classSeqToRepStr = new WeakHashMap<>();
private static final Map<String, byte[]> repStrToByteArray = new IdentityHashMap<>();
private static final Map<String, Class<?>> repStrToClass = new SoftCache<>();
private String repId = null;
private boolean isSupportedFormat = true;
private String typeString = null;
private String versionString = null;
private boolean isSequence = false;
private boolean isRMIValueType = false;
private boolean isIDLType = false;
private String completeClassName = null;
private String unqualifiedName = null;
private String definedInId = null;
private Class clazz = null;
private String suid = null, actualSuid = null;
private long suidLong = ObjectStreamClass.kDefaultUID, actualSuidLong =
ObjectStreamClass.kDefaultUID;
// Repository ID fragments
private static final String kSequenceKeyword = "seq";
private static final String kValuePrefix = "RMI:";
private static final String kIDLPrefix = "IDL:";
private static final String kIDLNamePrefix = "omg.org/";
private static final String kIDLClassnamePrefix = "org.omg.";
private static final String kSequencePrefix = "[";
private static final String kCORBAPrefix = "CORBA/";
private static final String kArrayPrefix = kValuePrefix
+ kSequencePrefix + kCORBAPrefix;
private static final int kValuePrefixLength = kValuePrefix.length();
private static final int kIDLPrefixLength = kIDLPrefix.length();
private static final int kSequencePrefixLength = kSequencePrefix.length();
private static final String kInterfaceHashCode = ":0000000000000000";
private static final String kInterfaceOnlyHashStr = "0000000000000000";
private static final String kExternalizableHashStr = "0000000000000001";
// Value tag utility methods and constants
public static final int kInitialValueTag= 0x7fffff00;
public static final int kNoTypeInfo = 0;
public static final int kSingleRepTypeInfo = 0x02;
public static final int kPartialListTypeInfo = 0x06;
public static final int kChunkedMask = 0x08;
public static final int kPreComputed_StandardRMIUnchunked =
RepositoryId.computeValueTag(false,
RepositoryId.kSingleRepTypeInfo, false);
public static final int kPreComputed_CodeBaseRMIUnchunked =
RepositoryId.computeValueTag(true,
RepositoryId.kSingleRepTypeInfo, false);
public static final int kPreComputed_StandardRMIChunked =
RepositoryId.computeValueTag(false,
RepositoryId.kSingleRepTypeInfo, true);
public static final int kPreComputed_CodeBaseRMIChunked =
RepositoryId.computeValueTag(true,
RepositoryId.kSingleRepTypeInfo, true);
public static final int kPreComputed_StandardRMIUnchunked_NoRep =
RepositoryId.computeValueTag(false, RepositoryId.kNoTypeInfo, false);
public static final int kPreComputed_CodeBaseRMIUnchunked_NoRep =
RepositoryId.computeValueTag(true, RepositoryId.kNoTypeInfo, false);
public static final int kPreComputed_StandardRMIChunked_NoRep =
RepositoryId.computeValueTag(false, RepositoryId.kNoTypeInfo, true);
public static final int kPreComputed_CodeBaseRMIChunked_NoRep =
RepositoryId.computeValueTag(true, RepositoryId.kNoTypeInfo, true);
// Public, well known repository IDs
// _REVISIT_ : A table structure with a good search routine for all of this
// would be more efficient and easier to maintain...
// String
public static final String kWStringValueVersion = "1.0";
public static final String kWStringValueHash = ":"+kWStringValueVersion;
public static final String kWStringStubValue = "WStringValue";
public static final String kWStringTypeStr = "omg.org/CORBA/"
+ kWStringStubValue;
public static final String kWStringValueRepID = kIDLPrefix
+ kWStringTypeStr + kWStringValueHash;
// Any
public static final String kAnyRepID = kIDLPrefix + "omg.org/CORBA/Any";
// Class
public static final String kClassDescValueHash = ":"
+ Long.toHexString(
ObjectStreamClass.getActualSerialVersionUID(
javax.rmi.CORBA.ClassDesc.class)).toUpperCase()
+ ":"
+ Long.toHexString(
ObjectStreamClass.getSerialVersionUID(
javax.rmi.CORBA.ClassDesc.class)).toUpperCase();
public static final String kClassDescStubValue = "ClassDesc";
public static final String kClassDescTypeStr =
"javax.rmi.CORBA."+kClassDescStubValue;
public static final String kClassDescValueRepID =
kValuePrefix + kClassDescTypeStr + kClassDescValueHash;
// Object
public static final String kObjectValueHash = ":1.0";
public static final String kObjectStubValue = "Object";
// Sequence
public static final String kSequenceValueHash = ":1.0";
public static final String kPrimitiveSequenceValueHash = ":0000000000000000";
// Serializable
public static final String kSerializableValueHash = ":1.0";
public static final String kSerializableStubValue = "Serializable";
// Externalizable
public static final String kExternalizableValueHash = ":1.0";
public static final String kExternalizableStubValue = "Externalizable";
// Remote (The empty string is used for java.rmi.Remote)
public static final String kRemoteValueHash = "";
public static final String kRemoteStubValue = "";
public static final String kRemoteTypeStr = "";
public static final String kRemoteValueRepID = "";
public static final Hashtable<String, StringBuffer> kSpecialArrayTypeStrings = new Hashtable<>();
static {
kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName()));
kSpecialArrayTypeStrings.put("javax.rmi.CORBA.ClassDesc", new StringBuffer(java.lang.Class.class.getName()));
kSpecialArrayTypeStrings.put("CORBA.Object", new StringBuffer(java.rmi.Remote.class.getName()));
}
public static final Hashtable<Class<?>, String> kSpecialCasesRepIDs = new Hashtable<>();
static {
kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID);
kSpecialCasesRepIDs.put(java.lang.Class.class, kClassDescValueRepID);
kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID);
}
public static final Hashtable<Class<?>, String> kSpecialCasesStubValues = new Hashtable<>();
static {
kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue);
kSpecialCasesStubValues.put(java.lang.Class.class, kClassDescStubValue);
kSpecialCasesStubValues.put(java.lang.Object.class, kObjectStubValue);
kSpecialCasesStubValues.put(java.io.Serializable.class, kSerializableStubValue);
kSpecialCasesStubValues.put(java.io.Externalizable.class, kExternalizableStubValue);
kSpecialCasesStubValues.put(java.rmi.Remote.class, kRemoteStubValue);
}
public static final Hashtable<Class<?>, String> kSpecialCasesVersions = new Hashtable<>();
static {
kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash);
kSpecialCasesVersions.put(java.lang.Class.class, kClassDescValueHash);
kSpecialCasesVersions.put(java.lang.Object.class, kObjectValueHash);
kSpecialCasesVersions.put(java.io.Serializable.class, kSerializableValueHash);
kSpecialCasesVersions.put(java.io.Externalizable.class, kExternalizableValueHash);
kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash);
}
public static final Hashtable<String, Class<?>> kSpecialCasesClasses = new Hashtable<>();
static {
kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class);
kSpecialCasesClasses.put(kClassDescTypeStr, java.lang.Class.class);
kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class);
kSpecialCasesClasses.put("org.omg.CORBA.WStringValue", java.lang.String.class);
kSpecialCasesClasses.put("javax.rmi.CORBA.ClassDesc", java.lang.Class.class);
// 6793820: need to handle classes of primitive types!
kSpecialCasesClasses.put( "boolean", boolean.class ) ;
kSpecialCasesClasses.put( "byte", byte.class ) ;
kSpecialCasesClasses.put( "char", char.class ) ;
kSpecialCasesClasses.put( "short", short.class ) ;
kSpecialCasesClasses.put( "int", int.class ) ;
kSpecialCasesClasses.put( "long", long.class ) ;
kSpecialCasesClasses.put( "float", float.class ) ;
kSpecialCasesClasses.put( "double", double.class ) ;
}
public static final Hashtable<Class<?>, String> kSpecialCasesArrayPrefix = new Hashtable<>();
static {
kSpecialCasesArrayPrefix.put( java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
kSpecialCasesArrayPrefix.put( java.lang.Class.class, kValuePrefix + kSequencePrefix + "javax/rmi/CORBA/");
kSpecialCasesArrayPrefix.put( java.lang.Object.class, kValuePrefix + kSequencePrefix + "java/lang/");
kSpecialCasesArrayPrefix.put( java.io.Serializable.class, kValuePrefix + kSequencePrefix + "java/io/");
kSpecialCasesArrayPrefix.put( java.io.Externalizable.class, kValuePrefix + kSequencePrefix + "java/io/");
kSpecialCasesArrayPrefix.put( java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
}
public static final Hashtable<String, String> kSpecialPrimitives = new Hashtable<>();
static {
kSpecialPrimitives.put("int","long");
kSpecialPrimitives.put("long","longlong");
kSpecialPrimitives.put("byte","octet");
}
/**
* Used to convert ascii to hex.
*/
private static final byte ASCII_HEX[] = {
(byte)'0',
(byte)'1',
(byte)'2',
(byte)'3',
(byte)'4',
(byte)'5',
(byte)'6',
(byte)'7',
(byte)'8',
(byte)'9',
(byte)'A',
(byte)'B',
(byte)'C',
(byte)'D',
(byte)'E',
(byte)'F',
};
// bug fix for 4328952; to eliminate possibility of overriding this
// in a subclass.
public static final RepositoryIdCache cache = new RepositoryIdCache();
// Interface Rep ID Strings
public static final String kjava_rmi_Remote = createForAnyType(java.rmi.Remote.class);
public static final String korg_omg_CORBA_Object = createForAnyType(org.omg.CORBA.Object.class);
// To create a RepositoryID, use code similar to the following:
// RepositoryId.cache.getId( id );
RepositoryId(){}
RepositoryId(String aRepId){
init(aRepId);
}
RepositoryId init(String aRepId) {
this.repId = aRepId;
// Special case for remote
if (aRepId.length() == 0) {
clazz = java.rmi.Remote.class;
typeString = "";
isRMIValueType = true;
suid = kInterfaceOnlyHashStr;
return this;
} else if (aRepId.equals(kWStringValueRepID)) {
clazz = java.lang.String.class;
typeString = kWStringTypeStr;
isIDLType = true;
// fix where Attempting to obtain a FullValueDescription
// for an RMI value type with a String field causes an exception.
completeClassName = "java.lang.String";
versionString = kWStringValueVersion;
return this;
} else {
String repId = convertFromISOLatin1(aRepId);
int firstIndex = repId.indexOf(':') ;
if (firstIndex == -1)
throw new IllegalArgumentException(
"RepositoryId must have the form <type>:<body>" ) ;
int secondIndex = repId.indexOf( ':', firstIndex + 1 ) ;
if (secondIndex == -1)
versionString = "" ;
else
versionString = repId.substring(secondIndex) ;
if (repId.startsWith(kIDLPrefix)) {
typeString =
repId.substring(kIDLPrefixLength,
repId.indexOf(':', kIDLPrefixLength));
isIDLType = true;
if (typeString.startsWith(kIDLNamePrefix))
completeClassName = kIDLClassnamePrefix +
typeString.substring(
kIDLNamePrefix.length()).replace('/','.');
else
completeClassName = typeString.replace('/','.');
} else if (repId.startsWith(kValuePrefix)) {
typeString =
repId.substring(kValuePrefixLength,
repId.indexOf(':', kValuePrefixLength));
isRMIValueType = true;
if (versionString.indexOf('.') == -1) {
actualSuid = versionString.substring(1);
suid = actualSuid; // default if not explicitly specified
if (actualSuid.indexOf(':') != -1){
// we have a declared hash also
int pos = actualSuid.indexOf(':')+1;
// actualSuid = suid.substring(pos);
// suid = suid.substring(0, pos-1);
suid = actualSuid.substring(pos);
actualSuid = actualSuid.substring(0, pos-1);
}
} else {
// _REVISIT_ : Special case version failure ?
}
} else {
isSupportedFormat = false;
typeString = "" ;
}
if (typeString.startsWith(kSequencePrefix)) {
isSequence = true;
}
return this;
}
}
public final String getUnqualifiedName() {
if (unqualifiedName == null){
String className = getClassName();
int index = className.lastIndexOf('.');
if (index == -1){
unqualifiedName = className;
definedInId = "IDL::1.0";
}
else {
unqualifiedName = className.substring(index);
definedInId = "IDL:"
+ className.substring(0, index).replace('.','/') + ":1.0";
}
}
return unqualifiedName;
}
public final String getDefinedInId() {
if (definedInId == null){
getUnqualifiedName();
}
return definedInId;
}
public final String getTypeString() {
return typeString;
}
public final String getVersionString() {
return versionString;
}
public final String getSerialVersionUID() {
return suid;
}
public final String getActualSerialVersionUID() {
return actualSuid;
}
public final long getSerialVersionUIDAsLong() {
return suidLong;
}
public final long getActualSerialVersionUIDAsLong() {
return actualSuidLong;
}
public final boolean isRMIValueType() {
return isRMIValueType;
}
public final boolean isIDLType() {
return isIDLType;
}
public final String getRepositoryId() {
return repId;
}
public static byte[] getByteArray(String repStr) {
synchronized (repStrToByteArray){
return repStrToByteArray.get(repStr);
}
}
public static void setByteArray(String repStr, byte[] repStrBytes) {
synchronized (repStrToByteArray){
repStrToByteArray.put(repStr, repStrBytes);
}
}
public final boolean isSequence() {
return isSequence;
}
public final boolean isSupportedFormat() {
return isSupportedFormat;
}
// This method will return the classname from the typestring OR
// if the classname turns out to be a special class "pseudo" name,
// then the matching real classname is returned.
public final String getClassName() {
if (isRMIValueType)
return typeString;
else if (isIDLType)
return completeClassName;
else
return null;
}
// This method calls getClazzFromType() and falls back to the repStrToClass
// cache if no class was found. It's used where any class matching the
// given repid is an acceptable result.
public final Class<?> getAnyClassFromType() throws ClassNotFoundException {
try {
return getClassFromType();
} catch (ClassNotFoundException cnfe) {
Class<?> clz = repStrToClass.get(repId);
if (clz != null)
return clz;
else
throw cnfe;
}
}
public final Class<?> getClassFromType() throws ClassNotFoundException {
if (clazz != null)
return clazz;
Class<?> specialCase = (Class)kSpecialCasesClasses.get(getClassName());
if (specialCase != null) {
clazz = specialCase;
return specialCase;
} else {
try {
return Util.getInstance().loadClass(getClassName(),
null, null);
} catch(ClassNotFoundException cnfe) {
if (defaultServerURL != null) {
try {
return getClassFromType(defaultServerURL);
} catch(MalformedURLException mue){
throw cnfe;
}
} else {
throw cnfe;
}
}
}
}
public final Class<?> getClassFromType(Class<?> expectedType, String codebase)
throws ClassNotFoundException {
if (clazz != null)
return clazz;
Class<?> specialCase = (Class)kSpecialCasesClasses.get(getClassName());
if (specialCase != null){
clazz = specialCase;
return specialCase;
} else {
ClassLoader expectedTypeClassLoader =
(expectedType == null ? null : expectedType.getClassLoader());
return Utility.loadClassOfType(getClassName(),
codebase,
expectedTypeClassLoader,
expectedType,
expectedTypeClassLoader);
}
}
public final Class<?> getClassFromType(String url)
throws ClassNotFoundException, MalformedURLException {
// 6793820: check special cases BEFORE going to ClassLoader.
if (clazz != null)
return clazz;
Class<?> specialCase = (Class)kSpecialCasesClasses.get(getClassName());
if (specialCase != null) {
clazz = specialCase;
return specialCase;
} else {
return Util.getInstance().loadClass(getClassName(), url, null);
}
}
@Override
public final String toString() {
return repId;
}
/**
* Checks to see if the FullValueDescription should be retrieved.
* @param clazz The type to get description for
* @param repositoryID The repository ID
* @return If full description should be retrieved
* @throws IOException If suids do not match or if the repositoryID
* is not an RMIValueType.
*/
public static boolean useFullValueDescription(Class clazz,
String repositoryID) throws IOException{
return useFullValueDescription( clazz, ClassInfoCache.get( clazz ),
repositoryID ) ;
}
/**
* Checks to see if the FullValueDescription should be retrieved.
* @param clazz The type to get description for
* @param cinfo The ClassInfo for the type.
* @param repositoryID The repository ID
* @return If full description should be retrieved
* @exception IOException If suids do not match or if the repositoryID
* is not an RMIValueType.
*/
public static boolean useFullValueDescription(Class<?> clazz,
ClassInfoCache.ClassInfo cinfo,
String repositoryID) throws IOException{
String clazzRepIDStr = createForAnyType(clazz, cinfo );
if (clazzRepIDStr.equals(repositoryID))
return false;
RepositoryId targetRepid;
RepositoryId clazzRepid;
synchronized(cache) {
// to avoid race condition where multiple threads could be
// accessing this method, and their access to the cache may
// be interleaved giving unexpected results
targetRepid = cache.getId(repositoryID);
clazzRepid = cache.getId(clazzRepIDStr);
}
if ((targetRepid.isRMIValueType()) && (clazzRepid.isRMIValueType())){
if (!targetRepid.getSerialVersionUID()
.equals(clazzRepid.getSerialVersionUID())) {
String mssg =
"Mismatched serialization UIDs : Source (Rep. ID"
+ clazzRepid + ") = "
+ clazzRepid.getSerialVersionUID()
+ " whereas Target (Rep. ID " + repositoryID
+ ") = " + targetRepid.getSerialVersionUID();
throw new IOException(mssg);
} else {
return true;
}
} else {
throw new IOException(
"The repository ID is not of an RMI value type (Expected ID = "
+ clazzRepIDStr + "; Received ID = " + repositoryID +")");
}
}
private static String createHashString(Class<?> clazz) {
ClassInfoCache.ClassInfo cinfo = ClassInfoCache.get( clazz ) ;
if (cinfo.isInterface() || !cinfo.isASerializable(clazz))
return kInterfaceHashCode;
long actualLong = ObjectStreamClass.getActualSerialVersionUID(clazz);
String hash = null;
if (actualLong == 0)
hash = kInterfaceOnlyHashStr;
else if (actualLong == 1)
hash = kExternalizableHashStr;
else
hash = Long.toHexString(actualLong).toUpperCase();
while(hash.length() < 16) {
hash = "0" + hash;
}
long declaredLong = ObjectStreamClass.getSerialVersionUID(clazz);
String declared = null;
if (declaredLong == 0)
declared = kInterfaceOnlyHashStr;
else if (declaredLong == 1)
declared = kExternalizableHashStr;
else
declared = Long.toHexString(declaredLong).toUpperCase();
while (declared.length() < 16) {
declared = "0" + declared;
}
hash = hash + ":" + declared;
return ":" + hash;
}
/**
* Creates a repository ID for a sequence. This is for expert users only as
* this method assumes the object passed is an array. If passed an object
* that is not an array, it will produce a rep id for a sequence of zero
* length. This would be an error.
* @param ser The Java object to create a repository ID for
* @return Created repository ID
**/
public static String createSequenceRepID(java.lang.Object ser){
return createSequenceRepID(ser.getClass());
}
/**
* Creates a repository ID for a sequence. This is for expert users only as
* this method assumes the object passed is an array. If passed an object
* that is not an array, it will produce a malformed rep id.
* @param clazz The Java class to create a repository ID for
* @return Created repository ID
**/
public static String createSequenceRepID(Class<?> clazz){
synchronized (classSeqToRepStr) {
String repid = classSeqToRepStr.get(clazz);
if (repid != null)
return repid;
Class<?> originalClazz = clazz;
Class<?> type = null;
int numOfDims = 0;
while ((type = clazz.getComponentType()) != null) {
numOfDims++;
clazz = type;
}
if (clazz.isPrimitive()) {
repid = kValuePrefix + originalClazz.getName()
+ kPrimitiveSequenceValueHash;
} else {
StringBuilder buf = new StringBuilder();
buf.append(kValuePrefix);
while(numOfDims-- > 0) {
buf.append("[");
}
buf.append("L");
buf.append(convertToISOLatin1(clazz.getName()));
buf.append(";");
buf.append(createHashString(clazz));
repid = buf.toString();
}
classSeqToRepStr.put(originalClazz,repid);
return repid;
}
}
public static String createForSpecialCase(java.lang.Class<?> clazz){
return createForSpecialCase( clazz, ClassInfoCache.get( clazz ) ) ;
}
public static String createForSpecialCase(java.lang.Class<?> clazz,
ClassInfoCache.ClassInfo cinfo ){
if (cinfo.isArray()) {
return createSequenceRepID(clazz);
} else {
if (clazz == String.class)
return kWStringValueRepID ;
if (clazz == Class.class)
return kClassDescValueRepID ;
if (clazz == java.rmi.Remote.class)
return kRemoteValueRepID ;
return null ;
}
}
public static String createForSpecialCase(java.io.Serializable ser){
Class<?> clazz = ser.getClass();
if (ClassInfoCache.get(clazz).isArray()) {
return createSequenceRepID(ser);
} else {
return createForSpecialCase(clazz);
}
}
/**
* Creates a repository ID for a normal Java Type.
* @param ser The Java object to create a repository ID for
* @return Created repository ID
* @exception com.sun.corba.ee.impl.io.TypeMismatchException if
* ser implements the org.omg.CORBA.portable.IDLEntity interface
* which indicates it is an IDL Value type.
**/
public static String createForJavaType(java.io.Serializable ser)
throws com.sun.corba.ee.impl.io.TypeMismatchException
{
synchronized (classToRepStr) {
String repid = createForSpecialCase(ser);
if (repid != null)
return repid;
Class<?> clazz = ser.getClass();
repid = classToRepStr.get(clazz);
if (repid != null)
return repid;
repid = kValuePrefix + convertToISOLatin1(clazz.getName()) +
createHashString(clazz);
classToRepStr.put(clazz, repid);
repStrToClass.put(repid, clazz);
return repid;
}
}
public static String createForJavaType(Class<?> clz)
throws com.sun.corba.ee.impl.io.TypeMismatchException
{
return createForJavaType( clz, ClassInfoCache.get( clz ) ) ;
}
/**
* Creates a repository ID for a normal Java Type.
* @param clz The Java class to create a repository ID for
* @param cinfo ClassInfo; may be null
* @return Created repository ID
* @exception com.sun.corba.ee.impl.io.TypeMismatchException if
* ser implements the * org.omg.CORBA.portable.IDLEntity interface
* which indicates it is an IDL Value type.
**/
public static String createForJavaType(Class<?> clz, ClassInfoCache.ClassInfo cinfo )
throws com.sun.corba.ee.impl.io.TypeMismatchException
{
synchronized (classToRepStr){
String repid = createForSpecialCase(clz,cinfo);
if (repid != null)
return repid;
repid = classToRepStr.get(clz);
if (repid != null)
return repid;
repid = kValuePrefix + convertToISOLatin1(clz.getName()) +
createHashString(clz);
classToRepStr.put(clz, repid);
repStrToClass.put(repid, clz);
return repid;
}
}
/**
* Creates a repository ID for an IDL Java Type.
* @param ser The IDL Value object to create a repository ID for
* @param major The major version number
* @param minor The minor version number
* @return Created repository ID
* @exception com.sun.corba.ee.impl.io.TypeMismatchException if ser does not implement the
* org.omg.CORBA.portable.IDLEntity interface which indicates it is an IDL Value type.
**/
public static String createForIDLType(Class<?> ser, int major, int minor)
throws com.sun.corba.ee.impl.io.TypeMismatchException
{
synchronized (classIDLToRepStr){
String repid = classIDLToRepStr.get(ser);
if (repid != null)
return repid;
repid = kIDLPrefix
+ convertToISOLatin1(ser.getName()).replace('.','/')
+ ":" + major + "." + minor;
classIDLToRepStr.put(ser, repid);
return repid;
}
}
private static String getIdFromHelper(Class<?> clazz){
try {
Class<?> helperClazz =
Utility.loadClassForClass(clazz.getName()+"Helper",
null, clazz.getClassLoader(), clazz, clazz.getClassLoader());
Method idMethod = helperClazz.getDeclaredMethod("id");
return (String)idMethod.invoke(null);
} catch (java.lang.ClassNotFoundException | java.lang.NoSuchMethodException
| java.lang.reflect.InvocationTargetException | java.lang.IllegalAccessException cnfe) {
throw new org.omg.CORBA.MARSHAL(cnfe.toString());
}
}
public static String createForAnyType(Class<?> type ) {
return createForAnyType( type, ClassInfoCache.get( type ) ) ;
}
/**
* Createa a repository ID for the type if it is either a java type
* or an IDL type.
* @param type The type to create rep. id for
* @param cinfo The ClassInfo for the type (pre-computed elsewhere to save time)
* @return The rep. id.
**/
public static String createForAnyType(Class<?> type, ClassInfoCache.ClassInfo cinfo) {
try{
// We may re-compute the repo id more than once, but that's OK, because
// it's always the same.
String result = cinfo.getRepositoryId() ;
if (result == null) {
if (cinfo.isArray()) {
result = createSequenceRepID(type);
} else if (cinfo.isAIDLEntity(type)) {
try{
result = getIdFromHelper(type);
} catch(Throwable t) {
return createForIDLType(type, 1, 0);
}
} else
result = createForJavaType(type, cinfo );
cinfo.setRepositoryId( result ) ;
}
return result ;
} catch(com.sun.corba.ee.impl.io.TypeMismatchException e){
return null;
}
}
public static boolean isAbstractBase(Class<?> clazz) {
ClassInfoCache.ClassInfo cinfo = ClassInfoCache.get( clazz ) ;
return cinfo.isInterface() && cinfo.isAIDLEntity(clazz)
&& !cinfo.isAValueBase(clazz) && !cinfo.isACORBAObject(clazz) ;
}
public static boolean isAnyRequired(Class clazz) {
return ((clazz == java.lang.Object.class) ||
(clazz == java.io.Serializable.class) ||
(clazz == java.io.Externalizable.class));
}
public static long fromHex(String hexNumber) {
if (hexNumber.startsWith("0x")) {
return Long.valueOf(hexNumber.substring(2), 16);
}
return Long.valueOf(hexNumber, 16);
}
/**
* Convert strings with illegal IDL identifier characters.
* <p>
* Section 5.5.7 of OBV spec.
* @param name String to convert
* @return Converted String
*/
public static String convertToISOLatin1 (String name) {
int length = name.length();
if (length == 0) {
return name;
}
StringBuilder buffer = null;
for (int i = 0; i < length; i++) {
char c = name.charAt(i);
if (c > 255 || IDL_IDENTIFIER_CHARS[c] == 0) {
// We gotta convert. Have we already started?
if (buffer == null) {
// No, so get set up...
buffer = new StringBuilder(name.substring(0,i));
}
// Convert the character into the IDL escape syntax...
buffer.append("\\U")
.append((char)ASCII_HEX[(c & 0xF000) >>> 12])
.append((char)ASCII_HEX[(c & 0x0F00) >>> 8])
.append((char)ASCII_HEX[(c & 0x00F0) >>> 4])
.append((char)ASCII_HEX[(c & 0x000F)]);
} else {
if (buffer != null) {
buffer.append(c);
}
}
}
if (buffer != null) {
name = buffer.toString();
}
return name;
}
/**
* Convert strings with ISO Latin 1 escape sequences back to original
* strings.
* <p>
* Section 5.5.7 of OBV spec.
*/
private static String convertFromISOLatin1 (String name) {
int index = -1;
StringBuilder buf = new StringBuilder(name);
while ((index = buf.toString().indexOf("\\U")) != -1){
String str = "0000" + buf.toString().substring(index+2, index+6);
// Convert Hexadecimal
byte[] buffer = new byte[(str.length() - 4) / 2];
for (int i=4, j=0; i < str.length(); i +=2, j++) {
buffer[j] =
(byte)((Utility.hexOf(str.charAt(i)) << 4) & 0xF0);
buffer[j] |=
(byte)((Utility.hexOf(str.charAt(i+1)) << 0) & 0x0F);
}
buf = new StringBuilder(delete(buf.toString(), index, index+6));
buf.insert(index, (char)buffer[1]);
}
return buf.toString();
}