1 7 8 package com.sun.corba.se.spi.ior.iiop ; 9 10 import com.sun.corba.se.spi.ior.IOR ; 11 import com.sun.corba.se.spi.ior.iiop.IIOPProfile; 12 import com.sun.corba.se.spi.orb.ORB; 13 import com.sun.corba.se.spi.orb.ORBVersion; 14 import com.sun.corba.se.spi.orb.ORBVersionFactory; 15 16 import com.sun.corba.se.impl.orbutil.ORBUtility; 17 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; 18 19 public class GIOPVersion { 20 21 23 public static final GIOPVersion V1_0 = new GIOPVersion((byte)1, (byte)0); 24 public static final GIOPVersion V1_1 = new GIOPVersion((byte)1, (byte)1); 25 public static final GIOPVersion V1_2 = new GIOPVersion((byte)1, (byte)2); 26 public static final GIOPVersion V1_3 = new GIOPVersion((byte)1, (byte)3); 27 28 public static final GIOPVersion V13_XX = 31 new GIOPVersion((byte)13, (byte)Message.JAVA_ENC_VERSION); 32 33 public static final GIOPVersion DEFAULT_VERSION = V1_2; 34 35 public static final int VERSION_1_0 = 0x0100; 36 public static final int VERSION_1_1 = 0x0101; 37 public static final int VERSION_1_2 = 0x0102; 38 public static final int VERSION_1_3 = 0x0103; 39 public static final int VERSION_13_XX = 40 ((0x0D << 8) & 0x0000FF00) | Message.JAVA_ENC_VERSION; 41 42 44 private byte major = (byte) 0; 45 private byte minor = (byte) 0; 46 47 49 public GIOPVersion() {} 50 51 public GIOPVersion(byte majorB, byte minorB) { 52 this.major = majorB; 53 this.minor = minorB; 54 } 55 56 public GIOPVersion(int major, int minor) { 57 this.major = (byte)major; 58 this.minor = (byte)minor; 59 } 60 61 63 public byte getMajor() { 64 return this.major; 65 } 66 67 public byte getMinor() { 68 return this.minor; 69 } 70 71 73 public boolean equals(GIOPVersion gv){ 74 return gv.major == this.major && gv.minor == this.minor ; 75 } 76 77 public boolean equals(Object obj) { 78 if (obj != null && (obj instanceof GIOPVersion)) 79 return equals((GIOPVersion)obj); 80 else 81 return false; 82 } 83 84 public int hashCode() 85 { 86 return 37*major + minor ; 87 } 88 89 public boolean lessThan(GIOPVersion gv) { 90 if (this.major < gv.major) { 91 return true; 92 } else if (this.major == gv.major) { 93 if (this.minor < gv.minor) { 94 return true; 95 } 96 } 97 98 return false; 99 } 100 101 public int intValue() 102 { 103 return (major << 8 | minor); 104 } 105 106 public String toString() 107 { 108 return major + "." + minor; 109 } 110 111 public static GIOPVersion getInstance(byte major, byte minor) 112 { 113 switch(((major << 8) | minor)) { 114 case VERSION_1_0: 115 return GIOPVersion.V1_0; 116 case VERSION_1_1: 117 return GIOPVersion.V1_1; 118 case VERSION_1_2: 119 return GIOPVersion.V1_2; 120 case VERSION_1_3: 121 return GIOPVersion.V1_3; 122 case VERSION_13_XX: 123 return GIOPVersion.V13_XX; 124 default: 125 return new GIOPVersion(major, minor); 126 } 127 } 128 129 public static GIOPVersion parseVersion(String s) 130 { 131 int dotIdx = s.indexOf('.'); 132 133 if (dotIdx < 1 || dotIdx == s.length() - 1) 134 throw new NumberFormatException ("GIOP major, minor, and decimal point required: " + s); 135 136 int major = Integer.parseInt(s.substring(0, dotIdx)); 137 int minor = Integer.parseInt(s.substring(dotIdx + 1, s.length())); 138 139 return GIOPVersion.getInstance((byte)major, (byte)minor); 140 } 141 142 148 public static GIOPVersion chooseRequestVersion(ORB orb, IOR ior ) { 149 150 GIOPVersion orbVersion = orb.getORBData().getGIOPVersion(); 151 IIOPProfile prof = ior.getProfile() ; 152 GIOPVersion profVersion = prof.getGIOPVersion(); 153 154 156 ORBVersion targetOrbVersion = prof.getORBVersion(); 157 if (!(targetOrbVersion.equals(ORBVersionFactory.getFOREIGN())) && 158 targetOrbVersion.lessThan(ORBVersionFactory.getNEWER())) { 159 return V1_0; 162 } 163 164 166 byte prof_major = profVersion.getMajor(); 167 byte prof_minor = profVersion.getMinor(); 168 169 byte orb_major = orbVersion.getMajor(); 170 byte orb_minor = orbVersion.getMinor(); 171 172 if (orb_major < prof_major) { 173 return orbVersion; 174 } else if (orb_major > prof_major) { 175 return profVersion; 176 } else { if (orb_minor <= prof_minor) { 178 return orbVersion; 179 } else { 180 return profVersion; 181 } 182 } 183 } 184 185 public boolean supportsIORIIOPProfileComponents() 186 { 187 return getMinor() > 0 || getMajor() > 1; 188 } 189 190 192 public void read(org.omg.CORBA.portable.InputStream istream) { 193 this.major = istream.read_octet(); 194 this.minor = istream.read_octet(); 195 } 196 197 public void write(org.omg.CORBA.portable.OutputStream ostream) { 198 ostream.write_octet(this.major); 199 ostream.write_octet(this.minor); 200 } 201 } 202 | Popular Tags |