Showing the changes to java/pkg (1423 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1 @@ | ||
| 1 | +All the *.java files here belong to OpenJDK version 1.7, see http://openjdk.java.net/ | |
| @@ -0,0 +1,338 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | + | |
| 5 | +implement AwtColor; | |
| 6 | + | |
| 7 | +include "jni.m"; | |
| 8 | + jni : JNI; | |
| 9 | + ClassModule, | |
| 10 | + JString, | |
| 11 | + JArray, | |
| 12 | + JArrayI, | |
| 13 | + JArrayC, | |
| 14 | + JArrayB, | |
| 15 | + JArrayS, | |
| 16 | + JArrayJ, | |
| 17 | + JArrayF, | |
| 18 | + JArrayD, | |
| 19 | + JArrayZ, | |
| 20 | + JArrayJObject, | |
| 21 | + JArrayJClass, | |
| 22 | + JArrayJString, | |
| 23 | + JClass, | |
| 24 | + JThread, | |
| 25 | + Value, | |
| 26 | + sys, | |
| 27 | + FALSE, | |
| 28 | + JObject : import jni; | |
| 29 | + | |
| 30 | + draw: Draw; | |
| 31 | + Context, Display, Image: import draw; | |
| 32 | + | |
| 33 | +include "java/lang/ClassLoader_L.m"; | |
| 34 | +include "awt_Color.m"; | |
| 35 | + | |
| 36 | +ctxt : ref Context; | |
| 37 | +systemcolors_file := "/java/lib/systemcolor.properties"; | |
| 38 | + | |
| 39 | +rgbvmap := array[3*256] of { | |
| 40 | + byte 255,byte 255,byte 255, byte 255,byte 255,byte 170, | |
| 41 | + byte 255,byte 255,byte 85, byte 255,byte 255,byte 0, | |
| 42 | + byte 255,byte 170,byte 255, byte 255,byte 170,byte 170, | |
| 43 | + byte 255,byte 170,byte 85, byte 255,byte 170,byte 0, | |
| 44 | + byte 255,byte 85,byte 255, byte 255,byte 85,byte 170, | |
| 45 | + byte 255,byte 85,byte 85, byte 255,byte 85,byte 0, | |
| 46 | + byte 255,byte 0,byte 255, byte 255,byte 0,byte 170, | |
| 47 | + byte 255,byte 0,byte 85, byte 255,byte 0,byte 0, | |
| 48 | + byte 238,byte 0,byte 0, byte 238,byte 238,byte 238, | |
| 49 | + byte 238,byte 238,byte 158, byte 238,byte 238,byte 79, | |
| 50 | + byte 238,byte 238,byte 0, byte 238,byte 158,byte 238, | |
| 51 | + byte 238,byte 158,byte 158, byte 238,byte 158,byte 79, | |
| 52 | + byte 238,byte 158,byte 0, byte 238,byte 79,byte 238, | |
| 53 | + byte 238,byte 79,byte 158, byte 238,byte 79,byte 79, | |
| 54 | + byte 238,byte 79,byte 0, byte 238,byte 0,byte 238, | |
| 55 | + byte 238,byte 0,byte 158, byte 238,byte 0,byte 79, | |
| 56 | + byte 221,byte 0,byte 73, byte 221,byte 0,byte 0, | |
| 57 | + byte 221,byte 221,byte 221, byte 221,byte 221,byte 147, | |
| 58 | + byte 221,byte 221,byte 73, byte 221,byte 221,byte 0, | |
| 59 | + byte 221,byte 147,byte 221, byte 221,byte 147,byte 147, | |
| 60 | + byte 221,byte 147,byte 73, byte 221,byte 147,byte 0, | |
| 61 | + byte 221,byte 73,byte 221, byte 221,byte 73,byte 147, | |
| 62 | + byte 221,byte 73,byte 73, byte 221,byte 73,byte 0, | |
| 63 | + byte 221,byte 0,byte 221, byte 221,byte 0,byte 147, | |
| 64 | + byte 204,byte 0,byte 136, byte 204,byte 0,byte 68, | |
| 65 | + byte 204,byte 0,byte 0, byte 204,byte 204,byte 204, | |
| 66 | + byte 204,byte 204,byte 136, byte 204,byte 204,byte 68, | |
| 67 | + byte 204,byte 204,byte 0, byte 204,byte 136,byte 204, | |
| 68 | + byte 204,byte 136,byte 136, byte 204,byte 136,byte 68, | |
| 69 | + byte 204,byte 136,byte 0, byte 204,byte 68,byte 204, | |
| 70 | + byte 204,byte 68,byte 136, byte 204,byte 68,byte 68, | |
| 71 | + byte 204,byte 68,byte 0, byte 204,byte 0,byte 204, | |
| 72 | + byte 170,byte 255,byte 170, byte 170,byte 255,byte 85, | |
| 73 | + byte 170,byte 255,byte 0, byte 170,byte 170,byte 255, | |
| 74 | + byte 187,byte 187,byte 187, byte 187,byte 187,byte 93, | |
| 75 | + byte 187,byte 187,byte 0, byte 170,byte 85,byte 255, | |
| 76 | + byte 187,byte 93,byte 187, byte 187,byte 93,byte 93, | |
| 77 | + byte 187,byte 93,byte 0, byte 170,byte 0,byte 255, | |
| 78 | + byte 187,byte 0,byte 187, byte 187,byte 0,byte 93, | |
| 79 | + byte 187,byte 0,byte 0, byte 170,byte 255,byte 255, | |
| 80 | + byte 158,byte 238,byte 238, byte 158,byte 238,byte 158, | |
| 81 | + byte 158,byte 238,byte 79, byte 158,byte 238,byte 0, | |
| 82 | + byte 158,byte 158,byte 238, byte 170,byte 170,byte 170, | |
| 83 | + byte 170,byte 170,byte 85, byte 170,byte 170,byte 0, | |
| 84 | + byte 158,byte 79,byte 238, byte 170,byte 85,byte 170, | |
| 85 | + byte 170,byte 85,byte 85, byte 170,byte 85,byte 0, | |
| 86 | + byte 158,byte 0,byte 238, byte 170,byte 0,byte 170, | |
| 87 | + byte 170,byte 0,byte 85, byte 170,byte 0,byte 0, | |
| 88 | + byte 153,byte 0,byte 0, byte 147,byte 221,byte 221, | |
| 89 | + byte 147,byte 221,byte 147, byte 147,byte 221,byte 73, | |
| 90 | + byte 147,byte 221,byte 0, byte 147,byte 147,byte 221, | |
| 91 | + byte 153,byte 153,byte 153, byte 153,byte 153,byte 76, | |
| 92 | + byte 153,byte 153,byte 0, byte 147,byte 73,byte 221, | |
| 93 | + byte 153,byte 76,byte 153, byte 153,byte 76,byte 76, | |
| 94 | + byte 153,byte 76,byte 0, byte 147,byte 0,byte 221, | |
| 95 | + byte 153,byte 0,byte 153, byte 153,byte 0,byte 76, | |
| 96 | + byte 136,byte 0,byte 68, byte 136,byte 0,byte 0, | |
| 97 | + byte 136,byte 204,byte 204, byte 136,byte 204,byte 136, | |
| 98 | + byte 136,byte 204,byte 68, byte 136,byte 204,byte 0, | |
| 99 | + byte 136,byte 136,byte 204, byte 136,byte 136,byte 136, | |
| 100 | + byte 136,byte 136,byte 68, byte 136,byte 136,byte 0, | |
| 101 | + byte 136,byte 68,byte 204, byte 136,byte 68,byte 136, | |
| 102 | + byte 136,byte 68,byte 68, byte 136,byte 68,byte 0, | |
| 103 | + byte 136,byte 0,byte 204, byte 136,byte 0,byte 136, | |
| 104 | + byte 85,byte 255,byte 85, byte 85,byte 255,byte 0, | |
| 105 | + byte 85,byte 170,byte 255, byte 93,byte 187,byte 187, | |
| 106 | + byte 93,byte 187,byte 93, byte 93,byte 187,byte 0, | |
| 107 | + byte 85,byte 85,byte 255, byte 93,byte 93,byte 187, | |
| 108 | + byte 119,byte 119,byte 119, byte 119,byte 119,byte 0, | |
| 109 | + byte 85,byte 0,byte 255, byte 93,byte 0,byte 187, | |
| 110 | + byte 119,byte 0,byte 119, byte 119,byte 0,byte 0, | |
| 111 | + byte 85,byte 255,byte 255, byte 85,byte 255,byte 170, | |
| 112 | + byte 79,byte 238,byte 158, byte 79,byte 238,byte 79, | |
| 113 | + byte 79,byte 238,byte 0, byte 79,byte 158,byte 238, | |
| 114 | + byte 85,byte 170,byte 170, byte 85,byte 170,byte 85, | |
| 115 | + byte 85,byte 170,byte 0, byte 79,byte 79,byte 238, | |
| 116 | + byte 85,byte 85,byte 170, byte 102,byte 102,byte 102, | |
| 117 | + byte 102,byte 102,byte 0, byte 79,byte 0,byte 238, | |
| 118 | + byte 85,byte 0,byte 170, byte 102,byte 0,byte 102, | |
| 119 | + byte 102,byte 0,byte 0, byte 79,byte 238,byte 238, | |
| 120 | + byte 73,byte 221,byte 221, byte 73,byte 221,byte 147, | |
| 121 | + byte 73,byte 221,byte 73, byte 73,byte 221,byte 0, | |
| 122 | + byte 73,byte 147,byte 221, byte 76,byte 153,byte 153, | |
| 123 | + byte 76,byte 153,byte 76, byte 76,byte 153,byte 0, | |
| 124 | + byte 73,byte 73,byte 221, byte 76,byte 76,byte 153, | |
| 125 | + byte 85,byte 85,byte 85, byte 85,byte 85,byte 0, | |
| 126 | + byte 73,byte 0,byte 221, byte 76,byte 0,byte 153, | |
| 127 | + byte 85,byte 0,byte 85, byte 85,byte 0,byte 0, | |
| 128 | + byte 68,byte 0,byte 0, byte 68,byte 204,byte 204, | |
| 129 | + byte 68,byte 204,byte 136, byte 68,byte 204,byte 68, | |
| 130 | + byte 68,byte 204,byte 0, byte 68,byte 136,byte 204, | |
| 131 | + byte 68,byte 136,byte 136, byte 68,byte 136,byte 68, | |
| 132 | + byte 68,byte 136,byte 0, byte 68,byte 68,byte 204, | |
| 133 | + byte 68,byte 68,byte 136, byte 68,byte 68,byte 68, | |
| 134 | + byte 68,byte 68,byte 0, byte 68,byte 0,byte 204, | |
| 135 | + byte 68,byte 0,byte 136, byte 68,byte 0,byte 68, | |
| 136 | + byte 0,byte 255,byte 0, byte 0,byte 170,byte 255, | |
| 137 | + byte 0,byte 187,byte 187, byte 0,byte 187,byte 93, | |
| 138 | + byte 0,byte 187,byte 0, byte 0,byte 85,byte 255, | |
| 139 | + byte 0,byte 93,byte 187, byte 0,byte 119,byte 119, | |
| 140 | + byte 0,byte 119,byte 0, byte 0,byte 0,byte 255, | |
| 141 | + byte 0,byte 0,byte 187, byte 0,byte 0,byte 119, | |
| 142 | + byte 51,byte 51,byte 51, byte 0,byte 255,byte 255, | |
| 143 | + byte 0,byte 255,byte 170, byte 0,byte 255,byte 85, | |
| 144 | + byte 0,byte 238,byte 79, byte 0,byte 238,byte 0, | |
| 145 | + byte 0,byte 158,byte 238, byte 0,byte 170,byte 170, | |
| 146 | + byte 0,byte 170,byte 85, byte 0,byte 170,byte 0, | |
| 147 | + byte 0,byte 79,byte 238, byte 0,byte 85,byte 170, | |
| 148 | + byte 0,byte 102,byte 102, byte 0,byte 102,byte 0, | |
| 149 | + byte 0,byte 0,byte 238, byte 0,byte 0,byte 170, | |
| 150 | + byte 0,byte 0,byte 102, byte 34,byte 34,byte 34, | |
| 151 | + byte 0,byte 238,byte 238, byte 0,byte 238,byte 158, | |
| 152 | + byte 0,byte 221,byte 147, byte 0,byte 221,byte 73, | |
| 153 | + byte 0,byte 221,byte 0, byte 0,byte 147,byte 221, | |
| 154 | + byte 0,byte 153,byte 153, byte 0,byte 153,byte 76, | |
| 155 | + byte 0,byte 153,byte 0, byte 0,byte 73,byte 221, | |
| 156 | + byte 0,byte 76,byte 153, byte 0,byte 85,byte 85, | |
| 157 | + byte 0,byte 85,byte 0, byte 0,byte 0,byte 221, | |
| 158 | + byte 0,byte 0,byte 153, byte 0,byte 0,byte 85, | |
| 159 | + byte 17,byte 17,byte 17, byte 0,byte 221,byte 221, | |
| 160 | + byte 0,byte 204,byte 204, byte 0,byte 204,byte 136, | |
| 161 | + byte 0,byte 204,byte 68, byte 0,byte 204,byte 0, | |
| 162 | + byte 0,byte 136,byte 204, byte 0,byte 136,byte 136, | |
| 163 | + byte 0,byte 136,byte 68, byte 0,byte 136,byte 0, | |
| 164 | + byte 0,byte 68,byte 204, byte 0,byte 68,byte 136, | |
| 165 | + byte 0,byte 68,byte 68, byte 0,byte 68,byte 0, | |
| 166 | + byte 0,byte 0,byte 204, byte 0,byte 0,byte 136, | |
| 167 | + byte 0,byte 0,byte 68, byte 0,byte 0,byte 0, | |
| 168 | +}; | |
| 169 | + | |
| 170 | +modinit(jni_p : JNI) | |
| 171 | +{ | |
| 172 | + if (ctxt != nil) | |
| 173 | + return; | |
| 174 | + | |
| 175 | + jni = jni_p; | |
| 176 | + sys = jni->sys; | |
| 177 | + ctxt = jni->getContext(); | |
| 178 | + if (ctxt == nil) | |
| 179 | + jni->ThrowException("java.awt.AWTError", "can't get Draw Context"); | |
| 180 | + draw = load Draw Draw->PATH; | |
| 181 | + | |
| 182 | +} | |
| 183 | + | |
| 184 | +getColor(jni_p: JNI, c: JObject) : ref Image | |
| 185 | +{ | |
| 186 | + modinit(jni_p); | |
| 187 | + | |
| 188 | + cm_index := getColorIndex(jni_p, c); | |
| 189 | + # (red, green, blue) := ctxt.display.cmap2rgb(cm_index); | |
| 190 | + # sys->print("Inferno color: red=%d, green=%d, blue=%d\n", red, green, blue); | |
| 191 | + col := ctxt.display.color(cm_index); | |
| 192 | + return col; | |
| 193 | +} | |
| 194 | + | |
| 195 | +getColorIndex(jni_p: JNI, c: JObject) : int | |
| 196 | +{ | |
| 197 | + modinit(jni_p); | |
| 198 | + | |
| 199 | + if (c == nil) { | |
| 200 | + sys->print("getColorIndex: null Color object\n"); | |
| 201 | + return 0; | |
| 202 | + } | |
| 203 | + | |
| 204 | + val := jni->GetObjField( c, "pData", "I" ); | |
| 205 | + if ( val == nil ) | |
| 206 | + sys->print( "getColorIndex: Couldn't get pData field from color object.\n" ); | |
| 207 | + else { | |
| 208 | + pdata := val.Int(); | |
| 209 | + if (pdata != 0) { | |
| 210 | + # sys->print("Using pData. pData = %d\n", pdata); | |
| 211 | + return pdata - 1; | |
| 212 | + } | |
| 213 | + } | |
| 214 | + | |
| 215 | + (ret, err) := jni->CallMethod(c, "getRGB", "()I", nil); | |
| 216 | + if (err != jni->OK) | |
| 217 | + jni->FatalError("awt_Color couldn't get RGB values of color"); | |
| 218 | + | |
| 219 | + rgb := ret.Int(); | |
| 220 | + r := (rgb >> 16) & 255; | |
| 221 | + g := (rgb >> 8) & 255; | |
| 222 | + b := (rgb >> 0) & 255; | |
| 223 | + cm_index := ctxt.display.rgb2cmap(r,g,b); | |
| 224 | + # sys->print( "rgb: %d\n", rgb); | |
| 225 | + # sys->print( "red: %d; green: %d; blue %d\n", r, g, b); | |
| 226 | + # sys->print("Color map index is %d.\n", cm_index); | |
| 227 | + | |
| 228 | + # sys->print("Setting pData to %d\n", cm_index+1); | |
| 229 | + val = ref Value.TInt(cm_index+1); | |
| 230 | + err = jni->SetObjField( c, "pData", val ); | |
| 231 | + if (err != jni->OK) | |
| 232 | + sys->print("getColorIndex: Couldn't set Color pData field\n"); | |
| 233 | + | |
| 234 | + return cm_index; | |
| 235 | +} | |
| 236 | + | |
| 237 | +makeColorModel(jni_p: JNI, bits: int) : JObject | |
| 238 | +{ | |
| 239 | + modinit(jni_p); | |
| 240 | + | |
| 241 | + cast := jni->CastMod(); | |
| 242 | + jbary := jni->MkAByte(rgbvmap); | |
| 243 | + arraylen := len jbary.ary; | |
| 244 | + # sys->print("makeColorModel: Array length is %d.\n", arraylen); | |
| 245 | + | |
| 246 | + args := array[5] of ref Value; | |
| 247 | + args[0] = ref Value.TInt(bits); | |
| 248 | + args[1] = ref Value.TInt(256); | |
| 249 | + args[2] = ref Value.TObject(cast->FromJArray(cast->ByteToJArray(jbary))); | |
| 250 | + args[3] = ref Value.TInt(0); | |
| 251 | + args[4] = ref Value.TBoolean(jni->FALSE); | |
| 252 | + | |
| 253 | + cl_data := jni->FindClass("java/awt/image/IndexColorModel"); | |
| 254 | + if (cl_data == nil) | |
| 255 | + jni->FatalError("awt_Color couldn't load java/awt/image/IndexColorModel"); | |
| 256 | + jobj := jni->AllocObject(cl_data); | |
| 257 | + (ret, err) := jni->CallMethod(jobj, "<init>", "(II[BIZ)V", args); | |
| 258 | + | |
| 259 | + if (err != jni->OK) | |
| 260 | + jni->FatalError("awt_Color couldn't create IndexColorModel"); | |
| 261 | + | |
| 262 | + system_flag := ref Value.TInt(1); | |
| 263 | + err = jni->SetObjField( jobj, "pData", system_flag ); | |
| 264 | + if (err != jni->OK) | |
| 265 | + sys->print("makeColorModel: Couldn't set ColorModel pData field to 1\n"); | |
| 266 | + | |
| 267 | + return jobj; | |
| 268 | +} | |
| 269 | + | |
| 270 | + | |
| 271 | +loadSystemColors(jni_p: JNI, systemColors: JArrayI) | |
| 272 | +{ | |
| 273 | + val : ref Value; | |
| 274 | + | |
| 275 | + modinit(jni_p); | |
| 276 | + | |
| 277 | + cl := jni->GetClassObject(jni->FindClass("java/awt/SystemColor")); | |
| 278 | + if (cl == nil) | |
| 279 | + jni->FatalError("iToolkit_L couldn't load java/awt/SystemColor"); | |
| 280 | + val = jni->GetStaticField( cl.class, "NUM_COLORS", "I" ); | |
| 281 | + if ( val == nil ) { | |
| 282 | + sys->print( "loadSystemColors: Couldn't get NUM_COLORS field from SystemColor class.\n" ); | |
| 283 | + return; | |
| 284 | + } | |
| 285 | + | |
| 286 | + num_colors := val.Int(); | |
| 287 | + # sys->print("Using GetStaticField: NUM_COLORS = %d\n", num_colors); | |
| 288 | + | |
| 289 | + lines := readfile(systemcolors_file); | |
| 290 | + if (lines == nil) { | |
| 291 | + sys->print( "loadSystemColors: Couldn't read %s\n", systemcolors_file); | |
| 292 | + return; | |
| 293 | + } | |
| 294 | + for(; lines != nil; lines = tl lines) { | |
| 295 | + line := hd lines; | |
| 296 | + (n, l) := sys->tokenize(line, " \t="); | |
| 297 | + if (n < 2 || line[0] == '#') | |
| 298 | + continue; | |
| 299 | + key := hd l; | |
| 300 | + line = hd tl l; | |
| 301 | + (n, l) = sys->tokenize(line, ";"); | |
| 302 | + if (n != 3) | |
| 303 | + continue; | |
| 304 | + r := int hd l; | |
| 305 | + g := int hd tl l; | |
| 306 | + b := int hd tl tl l; | |
| 307 | + # sys->print(" key = %s: r = %d; g = %d; b = %d\n", key, r, g, b); | |
| 308 | + val = jni->GetStaticField( cl.class, key, "I" ); | |
| 309 | + if ( val == nil ) | |
| 310 | + continue; | |
| 311 | + index := val.Int(); | |
| 312 | + color := (255 << 24) | ((r & 255) << 16) | ((g & 255) << 8) | ((b & 255) << 0); | |
| 313 | + systemColors.ary[index] = color; | |
| 314 | + } | |
| 315 | + | |
| 316 | + return; | |
| 317 | +} | |
| 318 | + | |
| 319 | + | |
| 320 | +# read a file and return its lines as a list of strings | |
| 321 | +readfile(filename: string) : list of string | |
| 322 | +{ | |
| 323 | + fd := sys->open(filename, sys->OREAD); | |
| 324 | + if(fd != nil) { | |
| 325 | + (n, dir) := sys->fstat(fd); | |
| 326 | + if(n < 0) | |
| 327 | + return nil; # shouldn't happen | |
| 328 | + buf := array[dir.length] of byte; | |
| 329 | + n = sys->read(fd, buf, dir.length); | |
| 330 | + if(n == dir.length) { | |
| 331 | + (nil, linelist) := sys->tokenize(string buf[0:n], "\r\n"); | |
| 332 | + return linelist; | |
| 333 | + } | |
| 334 | + } | |
| 335 | + return nil; | |
| 336 | +} | |
| 337 | + | |
| 338 | + | |
| @@ -0,0 +1,13 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | + | |
| 5 | +AwtColor : module | |
| 6 | +{ | |
| 7 | + PATH : con "/dis/java/inferno/awt/awt_Color.dis"; | |
| 8 | + | |
| 9 | + getColor : fn(jni: JNI, c: JObject) : ref Image; | |
| 10 | + getColorIndex : fn(jni: JNI, c: JObject) : int; | |
| 11 | + makeColorModel : fn(jni: JNI, bits: int) : JObject; | |
| 12 | + loadSystemColors : fn(jni: JNI, systemColors: JArrayI); | |
| 13 | +}; | |
| @@ -0,0 +1,250 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | + | |
| 5 | +implement FrameManager; | |
| 6 | + | |
| 7 | +include "sys.m"; | |
| 8 | + sys: Sys; | |
| 9 | + | |
| 10 | +include "string.m"; | |
| 11 | + str: String; | |
| 12 | + | |
| 13 | +include "draw.m"; | |
| 14 | + draw: Draw; | |
| 15 | + Context, Display, Point, Rect, Image, Screen: import draw; | |
| 16 | + | |
| 17 | +include "tk.m"; | |
| 18 | + tk: Tk; | |
| 19 | + Toplevel: import tk; | |
| 20 | + | |
| 21 | +include "wmlib.m"; | |
| 22 | + wmlib: Wmlib; | |
| 23 | + | |
| 24 | +include "awt_Frame.m"; | |
| 25 | + | |
| 26 | +screen: ref Screen; | |
| 27 | +display: ref Display; | |
| 28 | +ones: ref Image; | |
| 29 | +white: ref Image; | |
| 30 | +nochan: chan of string; | |
| 31 | +tHeight : int; | |
| 32 | +bWidth: int; | |
| 33 | + | |
| 34 | +win_cfg := array[] of { | |
| 35 | + "canvas .c -height 306 -width 406", | |
| 36 | + "pack .c -side bottom -fill both -expand 1", | |
| 37 | +# ".c configure -side bottom -fill both -expand 1", | |
| 38 | + "pack propagate . 0", | |
| 39 | +}; | |
| 40 | + | |
| 41 | +win_bind := array[] of { | |
| 42 | + "bind # <Motion> {send butt m %b %X %Y}", | |
| 43 | + "bind # <Leave> {send butt Leave}", | |
| 44 | +# "bind # <ButtonPress> {focus #; send foc focus; send butt p %b %X %Y}", | |
| 45 | + "bind # <ButtonPress> {focus #; send butt p %b %X %Y}", | |
| 46 | + "bind # <ButtonRelease> {send butt r %b %X %Y}", | |
| 47 | + "bind # <Double-Button> {send butt d %b %X %Y}", | |
| 48 | + "bind # <Enter> {send butt Enter}", | |
| 49 | + "bind # <KeyPress> {send key %K}", | |
| 50 | +# "bind . <FocusIn> {send foc focus}", | |
| 51 | +# "bind .Wm_t <Button-1> +{focus #; send foc focus}", | |
| 52 | + "bind .Wm_t <Button-1> +{focus #}", | |
| 53 | +# "bind .Wm_t.title <Button-1> +{focus #; send foc focus}", | |
| 54 | + "bind .Wm_t.title <Button-1> +{focus #}", | |
| 55 | +}; | |
| 56 | + | |
| 57 | +modinit(ctxt: ref Context) | |
| 58 | +{ | |
| 59 | + if (sys != nil) | |
| 60 | + return; | |
| 61 | + | |
| 62 | + sys = load Sys Sys->PATH; | |
| 63 | + str = load String String->PATH; | |
| 64 | + draw = load Draw Draw->PATH; | |
| 65 | + tk = load Tk Tk->PATH; | |
| 66 | + wmlib = load Wmlib Wmlib->PATH; | |
| 67 | + nochan = chan of string; | |
| 68 | + | |
| 69 | + display = ctxt.display; | |
| 70 | + screen = ctxt.screen; | |
| 71 | + ones = display.ones; | |
| 72 | + white = display.color(Draw->White); | |
| 73 | + | |
| 74 | + wmlib->init(); | |
| 75 | +} | |
| 76 | +showwin(cv : ref Canvas) | |
| 77 | +{ | |
| 78 | + tk->cmd(cv.top, "pack " + cv.canvas); | |
| 79 | +} | |
| 80 | +makewin(ctxt: ref Context, title: string, x, y, width, height: int): ref Canvas | |
| 81 | +{ | |
| 82 | + modinit(ctxt); | |
| 83 | + where := "-x " + string x + " -y " + string y; | |
| 84 | + (t, menu) := wmlib->titlebar(screen, where, title, Wmlib->Appl); | |
| 85 | + | |
| 86 | +# calculate topInset and boardwidth | |
| 87 | + bWidth = int tk->cmd(t, ". cget -bd"); | |
| 88 | + tHeight = int tk->cmd(t, ". cget -height"); | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + if (width > 0 && height > 0) | |
| 93 | + win_cfg[0] = "canvas .c -height " + string (height - tHeight - bWidth) + | |
| 94 | + " -width " + string (width - 2*bWidth); | |
| 95 | + | |
| 96 | +# win_cfg[0] = "canvas .c -height " + string height + " -width " + string width; | |
| 97 | + | |
| 98 | + wmlib->tkcmds(t, win_cfg); | |
| 99 | + return alloccanvas(t, ctxt, ".c", menu); | |
| 100 | +} | |
| 101 | + | |
| 102 | +resizewin(cv: ref Canvas, x, y, width, height : int) | |
| 103 | +{ | |
| 104 | +} | |
| 105 | + | |
| 106 | +alloccanvas(t: ref Toplevel, ctxt: ref Draw->Context, canvas: string, menu: chan of string): ref Canvas | |
| 107 | +{ | |
| 108 | + cmd := chan of string; | |
| 109 | + tk->namechan(t, cmd, "cmd"); | |
| 110 | + butt := chan of string; | |
| 111 | + tk->namechan(t, butt, "butt"); | |
| 112 | +# mouse := chan of string; | |
| 113 | +# tk->namechan(t, mouse, "mouse"); | |
| 114 | + | |
| 115 | + key := chan of string; | |
| 116 | + tk->namechan(t, key, "key"); | |
| 117 | + | |
| 118 | + foc := chan of string; | |
| 119 | + tk->namechan(t, foc, "foc"); | |
| 120 | + | |
| 121 | + tk->cmd(t, "bind . <Configure> {send cmd resize}"); | |
| 122 | + tk->cmd(t, "bind . <Map> {send cmd map}"); | |
| 123 | + | |
| 124 | + for (i := 0; i < len win_bind; i++) | |
| 125 | + tk->cmd(t, expand(win_bind[i], canvas)); | |
| 126 | + | |
| 127 | + tk->cmd(t, "update"); | |
| 128 | + | |
| 129 | + c := ref Canvas; | |
| 130 | + display = ctxt.display; | |
| 131 | + c.image = display.image; | |
| 132 | + c.rect = canvposn(t, canvas); | |
| 133 | + c.buf = display.newimage(c.image.r, c.image.ldepth , 0, Draw->White); | |
| 134 | + c.events = chan of ref Event; | |
| 135 | + c.top = t; | |
| 136 | + c.ctxt = ctxt; | |
| 137 | + c.canvas = canvas; | |
| 138 | + c.pid = sys->pctl(0, nil); | |
| 139 | + | |
| 140 | +# calculate topInset and boardwidth | |
| 141 | + y1 := int tk->cmd(t, ". cget -acty") + int tk->cmd(t, ".dy get"); | |
| 142 | + y2 := int tk->cmd(t, ".c cget -acty") + int tk->cmd(t, ".dy get"); | |
| 143 | + | |
| 144 | +# tHeight = int tk->cmd(t, ".Wm_t cget -actheight"); | |
| 145 | + tHeight = y2 - y1; | |
| 146 | + bWidth = int tk->cmd(t, ". cget -bd"); | |
| 147 | + | |
| 148 | + paint(c, c_canvposn(t, canvas)); | |
| 149 | + spawn handler(c, menu, cmd, butt, key, foc); | |
| 150 | + return c; | |
| 151 | +} | |
| 152 | + | |
| 153 | +hidewin(c: ref Canvas) | |
| 154 | +{ | |
| 155 | + tk->cmd(c.top, "pack forget " + c.canvas); | |
| 156 | +} | |
| 157 | + | |
| 158 | +handler(c: ref Canvas, menu, cmd, butt, key, foc: chan of string) | |
| 159 | +{ | |
| 160 | + detail: string; | |
| 161 | + t := c.top; | |
| 162 | + if (menu == nil) | |
| 163 | + menu = nochan; | |
| 164 | + for (;;) alt { | |
| 165 | + detail = <- menu => | |
| 166 | + case detail { | |
| 167 | + "exit" => | |
| 168 | + c.events <- = ref Event(Event.Shutdown, nil); | |
| 169 | + "task" => | |
| 170 | + c.events <- = ref Event(Event.Icon, nil); | |
| 171 | +# "move" => | |
| 172 | +# sys->print("===== moving \n"); | |
| 173 | + * => | |
| 174 | + ; | |
| 175 | + } | |
| 176 | + wmlib->titlectl(c.top, detail); | |
| 177 | + | |
| 178 | + detail = <- cmd => | |
| 179 | + (n, word) := sys->tokenize(detail, " "); | |
| 180 | + case hd word { | |
| 181 | + "resize" or "map" => | |
| 182 | + c.rect = canvposn(t, c.canvas); | |
| 183 | + paint(c, c_canvposn(t, c.canvas)); | |
| 184 | + e := Event.Resize; | |
| 185 | + if (hd word == "map") { | |
| 186 | + e = Event.DeIcon; | |
| 187 | + tk->cmd(t, "focus " + c.canvas); | |
| 188 | + } | |
| 189 | + c.events <- = ref Event(e, nil); | |
| 190 | + * => | |
| 191 | + ; | |
| 192 | + } | |
| 193 | + detail = <- butt => | |
| 194 | + | |
| 195 | + c.events <- = ref Event(Event.Button, detail); | |
| 196 | + detail = <- key => | |
| 197 | + c.events <- = ref Event(Event.Key, detail); | |
| 198 | +# detail = <- foc => | |
| 199 | +# c.events <- = ref Event(Event.Focus, detail); | |
| 200 | + | |
| 201 | + } | |
| 202 | +} | |
| 203 | + | |
| 204 | +expand(cmd, canvas: string): string | |
| 205 | +{ | |
| 206 | + s: string; | |
| 207 | + for (;;) { | |
| 208 | + (l, r) := str->splitl(cmd, "#"); | |
| 209 | + s = s + l; | |
| 210 | + if (r == nil) | |
| 211 | + return s; | |
| 212 | + s = s + canvas; | |
| 213 | + cmd = r[1:]; | |
| 214 | + } | |
| 215 | +} | |
| 216 | + | |
| 217 | +paint(c: ref Canvas, r: Rect) | |
| 218 | +{ | |
| 219 | + c.image.draw(r, white, ones, (0, 0)); | |
| 220 | +} | |
| 221 | + | |
| 222 | +c_canvposn(t: ref Toplevel, c: string): Rect | |
| 223 | +{ | |
| 224 | + r: Rect; | |
| 225 | + | |
| 226 | + r.min.x = int tk->cmd(t, c + " cget -actx") + int tk->cmd(t, ".dx get"); | |
| 227 | + r.min.y = int tk->cmd(t, c + " cget -acty") + int tk->cmd(t, ".dy get"); | |
| 228 | + r.max.x = r.min.x + int tk->cmd(t, c + " cget -actwidth") + int tk->cmd(t, ".dw get"); | |
| 229 | + r.max.y = r.min.y + int tk->cmd(t, c + " cget -actheight") + int tk->cmd(t, ".dh get"); | |
| 230 | + return r; | |
| 231 | +} | |
| 232 | +canvposn(t: ref Toplevel, c: string): Rect | |
| 233 | +{ | |
| 234 | + r: Rect; | |
| 235 | + | |
| 236 | + r.min.x = int tk->cmd(t, ". cget -actx") + int tk->cmd(t, ".dx get"); | |
| 237 | + r.min.y = int tk->cmd(t, ". cget -acty") + int tk->cmd(t, ".dy get"); | |
| 238 | + r.max.x = r.min.x + int tk->cmd(t, ". cget -actwidth") + int tk->cmd(t, ".dw get"); | |
| 239 | + r.max.y = r.min.y + int tk->cmd(t, ". cget -actheight") + int tk->cmd(t, ".dh get"); | |
| 240 | + return r; | |
| 241 | +} | |
| 242 | +getInsets(): (int, int) | |
| 243 | +{ | |
| 244 | + return (bWidth, tHeight); | |
| 245 | +} | |
| 246 | + | |
| 247 | +mapCanvas(dimg : ref Image, wimg : ref Image) | |
| 248 | +{ | |
| 249 | + dimg.draw(dimg.r, wimg, ones, dimg.r.min); | |
| 250 | +} | |
| @@ -0,0 +1,46 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | + | |
| 5 | +FrameManager: module | |
| 6 | +{ | |
| 7 | + PATH: con "/dis/java/inferno/awt/awt_Frame.dis"; | |
| 8 | + | |
| 9 | + Event: adt | |
| 10 | + { | |
| 11 | + event: int; | |
| 12 | + detail: string; | |
| 13 | + | |
| 14 | + Button, Key, | |
| 15 | + Icon, DeIcon, | |
| 16 | + Resize, Shutdown, Focus | |
| 17 | + : con iota; | |
| 18 | + }; | |
| 19 | + | |
| 20 | + Attr: adt | |
| 21 | + { | |
| 22 | + origin: Draw->Point; | |
| 23 | + dims: Draw->Point; | |
| 24 | + }; | |
| 25 | + | |
| 26 | + Canvas: adt | |
| 27 | + { | |
| 28 | + # interface | |
| 29 | + image: ref Draw->Image; | |
| 30 | + buf: ref Draw->Image; | |
| 31 | + rect: Draw->Rect; | |
| 32 | + events: chan of ref Event; | |
| 33 | + attr: ref Attr; | |
| 34 | + # implementation | |
| 35 | + ctxt : ref Draw->Context; | |
| 36 | + top: ref Tk->Toplevel; | |
| 37 | + canvas: string; | |
| 38 | + pid: int; | |
| 39 | + }; | |
| 40 | + | |
| 41 | + makewin: fn(ctxt: ref Draw->Context, title: string, x, y, width, height: int): ref Canvas; | |
| 42 | + resizewin: fn(cv: ref Canvas, x, y, width, height : int); | |
| 43 | + hidewin: fn(c: ref Canvas); | |
| 44 | + getInsets: fn(): (int, int); | |
| 45 | + mapCanvas : fn(dimg : ref Draw->Image, wimg : ref Draw->Image); | |
| 46 | +}; | |
| @@ -0,0 +1,209 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | +implement AwtGraphics; | |
| 5 | + | |
| 6 | +include "sys.m"; | |
| 7 | + sys : Sys; | |
| 8 | + | |
| 9 | +include "draw.m"; | |
| 10 | + draw: Draw; | |
| 11 | + Screen, Display, Rect, Font, Point, Image: import draw; | |
| 12 | + | |
| 13 | +include "math.m"; | |
| 14 | + math: Math; | |
| 15 | + Pi, atan, tan: import math; | |
| 16 | + | |
| 17 | +disp : ref Display; | |
| 18 | +wimg, dimg, white, ones, icolor : ref Image; | |
| 19 | + | |
| 20 | +include "awt_Graphics.m"; | |
| 21 | + | |
| 22 | +init(img : ref Image, bufimg : ref Image){ | |
| 23 | + sys = load Sys Sys->PATH; | |
| 24 | + draw = load Draw Draw->PATH; | |
| 25 | + math = load Math Math->PATH; | |
| 26 | + dimg = img; | |
| 27 | + wimg = bufimg; | |
| 28 | + disp = wimg.display; | |
| 29 | + ones = disp.ones; | |
| 30 | + icolor = disp.color(Draw->White); | |
| 31 | + white = disp.color(Draw->White); | |
| 32 | +} | |
| 33 | + | |
| 34 | +undoClip() | |
| 35 | +{ | |
| 36 | + wimg.clipr = wimg.r; | |
| 37 | +} | |
| 38 | + | |
| 39 | +dispose() | |
| 40 | +{ | |
| 41 | + dimg = nil; | |
| 42 | + wimg = nil; | |
| 43 | +} | |
| 44 | +setForeground(p0, p1, p2 : int) | |
| 45 | +{ | |
| 46 | + icolor = disp.rgb(p0, p1, p2); | |
| 47 | +} | |
| 48 | + | |
| 49 | +changeClip(p0, p1, p2, p3 : int) | |
| 50 | +{ | |
| 51 | +# sys->print("=== Change Cliping Area\n"); | |
| 52 | + wimg.clipr = ((p0, p1), (p0 + p2 - 1, p1 + p3 -1)); | |
| 53 | +} | |
| 54 | + | |
| 55 | +clearRect( p0 : int,p1 : int,p2 : int,p3 : int) | |
| 56 | +{ | |
| 57 | + r := ((p0, p1), (p0 + p2 - 1, p1 + p3 - 1)); | |
| 58 | + wimg.draw(r, white, ones, (0, 0)); | |
| 59 | +} | |
| 60 | + | |
| 61 | +fillRect(ply: array of Point) | |
| 62 | +{ | |
| 63 | + wimg.fillpoly(ply, 1, icolor, ply[0]); | |
| 64 | +} | |
| 65 | + | |
| 66 | +drawRect(ply: array of Point) | |
| 67 | +{ | |
| 68 | + wimg.poly(ply, 0, 0, 0, icolor, ply[0]); | |
| 69 | +} | |
| 70 | + | |
| 71 | +drawStringWidth(txt : string, sp : Point, font : ref Font) : int | |
| 72 | +{ | |
| 73 | + ep := wimg.text(sp, icolor, sp, font, txt); | |
| 74 | + return(ep.x-sp.x); | |
| 75 | + | |
| 76 | +} | |
| 77 | + | |
| 78 | +drawLine(sp, ep : Point) | |
| 79 | +{ | |
| 80 | + wimg.line(sp, ep, 0, 0, 0, icolor, sp); | |
| 81 | +} | |
| 82 | + | |
| 83 | +genDraw(r : Rect, data : array of byte) | |
| 84 | +{ | |
| 85 | + wimg.writepixels(r, data); | |
| 86 | +} | |
| 87 | + | |
| 88 | +copyArea(rect0, rect1 : Draw->Rect, data : array of byte) | |
| 89 | +{ | |
| 90 | + wimg.readpixels(rect0, data); | |
| 91 | + wimg.writepixels(rect1, data); | |
| 92 | +} | |
| 93 | + | |
| 94 | +drawRoundRect(p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int) | |
| 95 | +{ | |
| 96 | +} | |
| 97 | + | |
| 98 | +fillRoundRect(p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int) | |
| 99 | +{ | |
| 100 | +} | |
| 101 | + | |
| 102 | +drawPolygon(ply : array of Point) | |
| 103 | +{ | |
| 104 | + wimg.poly(ply, 0, 0, 0, icolor, icolor.r.min); | |
| 105 | +} | |
| 106 | + | |
| 107 | +drawPolyline(ply : array of Point) | |
| 108 | +{ | |
| 109 | + wimg.poly(ply, 0, 0, 0, icolor, icolor.r.min); | |
| 110 | +} | |
| 111 | + | |
| 112 | +fillPolygon(ply : array of Point) | |
| 113 | +{ | |
| 114 | + wimg.fillpoly(ply, 1, icolor, icolor.r.min); | |
| 115 | +} | |
| 116 | + | |
| 117 | +drawOval(p : Point, p2 : int,p3 : int) | |
| 118 | +{ | |
| 119 | + p.x += p2 / 2; | |
| 120 | + p.y += p3 / 2; | |
| 121 | + wimg.ellipse(p, p2/2, p3/2, 0, icolor, p); | |
| 122 | +} | |
| 123 | + | |
| 124 | +fillOval(p: Point, p2 : int,p3 : int) | |
| 125 | +{ | |
| 126 | + p.x += p2 / 2; | |
| 127 | + p.y += p3 / 2; | |
| 128 | + wimg.fillellipse(p, p2/2, p3/2, icolor, p); | |
| 129 | +} | |
| 130 | + | |
| 131 | +drawArc(p : Point, p2 : int,p3 : int,p4 : int,p5 : int) | |
| 132 | +{ | |
| 133 | + p.x += p2 / 2; | |
| 134 | + p.y += p3 / 2; | |
| 135 | + (p4, p5) = adjustArcAngles(p2, p3, p4, p5); | |
| 136 | + wimg.arc(p, p2/2, p3/2, 0, icolor, p, p4, p5); | |
| 137 | +} | |
| 138 | + | |
| 139 | +fillArc(p : Point, p2 : int,p3 : int,p4 : int,p5 : int) | |
| 140 | +{ | |
| 141 | + p.x += p2 / 2; | |
| 142 | + p.y += p3 / 2; | |
| 143 | + (p4, p5) = adjustArcAngles(p2, p3, p4, p5); | |
| 144 | + wimg.fillarc(p, p2/2, p3/2, icolor, p, p4, p5); | |
| 145 | +} | |
| 146 | + | |
| 147 | +adjustArcAngles(w, h, start, arc: int): (int, int) | |
| 148 | +{ | |
| 149 | + laps, end: int; | |
| 150 | + | |
| 151 | + if (arc >= 360 || arc <= -360) { | |
| 152 | + start = 0; | |
| 153 | + arc = 360; | |
| 154 | + } else | |
| 155 | + start = start % 360; | |
| 156 | + | |
| 157 | + if (w != h && arc != 0 && arc != 360) { | |
| 158 | + laps = (start + arc) / 360; | |
| 159 | + end = (start + arc) % 360; | |
| 160 | + start = skewAngle(w, h, start); | |
| 161 | + end = skewAngle(w, h, end); | |
| 162 | + arc = end - start + (laps * 360); | |
| 163 | + } | |
| 164 | + return (start, arc); | |
| 165 | +} | |
| 166 | + | |
| 167 | +skewAngle(width, height, angle: int): int | |
| 168 | +{ | |
| 169 | + if (width == 0 || height == 0) | |
| 170 | + return angle; | |
| 171 | + | |
| 172 | + normAngle := real angle * (2.0 * Pi) / 360.0; | |
| 173 | + | |
| 174 | + w := real width; | |
| 175 | + h := real height; | |
| 176 | + skewedAngle := h/w * tan(normAngle); | |
| 177 | + skewedAngle = atan(skewedAngle); | |
| 178 | + | |
| 179 | + if (normAngle > 1.5 * Pi) | |
| 180 | + skewedAngle += 2.0 * Pi; | |
| 181 | + else if (normAngle > 0.5 * Pi) | |
| 182 | + skewedAngle += Pi; | |
| 183 | + else if (normAngle < -1.5 * Pi) | |
| 184 | + skewedAngle -= 2.0 * Pi; | |
| 185 | + else if (normAngle < -0.5 * Pi) | |
| 186 | + skewedAngle -= Pi; | |
| 187 | + | |
| 188 | + skewedAngle = skewedAngle * 360.0 / (2.0 * Pi); | |
| 189 | + return int skewedAngle; | |
| 190 | +} | |
| 191 | + | |
| 192 | +sendToDisplay(r : Draw->Rect) | |
| 193 | +{ | |
| 194 | +# if (dimg == nil) | |
| 195 | +# sys->print("on screen image is nil\n"); | |
| 196 | +# else | |
| 197 | + if (dimg != nil) | |
| 198 | + { | |
| 199 | + wimg.clipr=r; | |
| 200 | + dimg.draw(r, wimg, ones, r.min); | |
| 201 | +# dimg.draw(dimg.r, wimg, ones, dimg.r.min); | |
| 202 | + } | |
| 203 | +} | |
| 204 | + | |
| 205 | +getDC(img: ref Draw->Image, bufimg : ref Draw->Image) | |
| 206 | +{ | |
| 207 | + dimg = img; | |
| 208 | +} | |
| 209 | + | |
| @@ -0,0 +1,43 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | +AwtGraphics : module | |
| 5 | +{ | |
| 6 | + PATH : con "/dis/java/inferno/awt/awt_Graphics.dis"; | |
| 7 | + | |
| 8 | + init : fn(img : ref Draw->Image, bufimg: ref Draw->Image); | |
| 9 | + | |
| 10 | + dispose : fn(); | |
| 11 | + setForeground : fn(r, g, b : int); | |
| 12 | + changeClip : fn(p0, p1, p2, p3 : int); | |
| 13 | + | |
| 14 | +# removeClip : fn(); | |
| 15 | + clearRect : fn( p0 : int,p1 : int,p2 : int,p3 : int); | |
| 16 | + | |
| 17 | + fillRect : fn(ply: array of Draw->Point); | |
| 18 | + drawRect : fn(ply: array of Draw->Point); | |
| 19 | + | |
| 20 | + drawStringWidth: fn(txt : string, sp : Draw->Point, font : ref Draw->Font) : int; | |
| 21 | + drawLine : fn(sp, ep : Draw->Point); | |
| 22 | + | |
| 23 | + genDraw : fn(r : Draw->Rect, img : array of byte); | |
| 24 | + | |
| 25 | + copyArea : fn(rect0, rect1 : Draw->Rect, data : array of byte); | |
| 26 | + | |
| 27 | + drawRoundRect: fn(p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int); | |
| 28 | + | |
| 29 | + fillRoundRect: fn(p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int); | |
| 30 | + | |
| 31 | + drawPolygon : fn(ply : array of Draw->Point); | |
| 32 | + drawPolyline: fn(ply : array of Draw->Point); | |
| 33 | + fillPolygon : fn(ply : array of Draw->Point); | |
| 34 | + drawOval : fn(p : Draw->Point, p2 : int,p3 : int); | |
| 35 | + | |
| 36 | + fillOval : fn(p: Draw->Point, p2 : int,p3 : int); | |
| 37 | + | |
| 38 | + drawArc : fn(p : Draw->Point, p2 : int,p3 : int,p4 : int,p5 : int); | |
| 39 | + | |
| 40 | + fillArc : fn(p : Draw->Point, p2 : int,p3 : int,p4 : int,p5 : int); | |
| 41 | + sendToDisplay : fn(r : Draw->Rect); | |
| 42 | + getDC : fn(img: ref Draw->Image, bufimg : ref Draw->Image); | |
| 43 | +}; | |
| @@ -0,0 +1,36 @@ | ||
| 1 | +AwtImage : module | |
| 2 | +{ | |
| 3 | + PATH : con "/dis/java/inferno/awt/awt_Image.dis"; | |
| 4 | + | |
| 5 | + # | |
| 6 | + # Inferno rep of manifest constants defined in | |
| 7 | + # java.awt.image.ImageObserver (hope they don't change | |
| 8 | + # in javaland). | |
| 9 | + ImO_WIDTH: con 1; | |
| 10 | + ImO_HEIGHT: con 2; | |
| 11 | + ImO_PROPERTIES: con 4; | |
| 12 | + ImO_SOMEBITS: con 8; | |
| 13 | + ImO_FRAMEBITS: con 16; | |
| 14 | + ImO_ALLBITS: con 32; | |
| 15 | + ImO_ERROR: con 64; | |
| 16 | + ImO_ABORT: con 128; | |
| 17 | + | |
| 18 | + # | |
| 19 | + # Inferno rep of pixel delivery hints from | |
| 20 | + # java.awt.image.ImageConsumer. | |
| 21 | + # | |
| 22 | + ImC_RANDOMPIXELORDER: con 1; | |
| 23 | + ImC_TOPDOWNLEFTRIGHT: con 2; | |
| 24 | + ImC_COMPLETESCANLINES: con 4; | |
| 25 | + ImC_SINGLEPASS: con 8; | |
| 26 | + ImC_SINGLEFRAME: con 16; | |
| 27 | + | |
| 28 | + # | |
| 29 | + # Inferno rep of imageComplete status bits | |
| 30 | + # java.awt.image.ImageConsumer. | |
| 31 | + # | |
| 32 | + ImC_IMAGEERROR: con 1; | |
| 33 | + ImC_SINGLFRAMEDONE: con 2; | |
| 34 | + ImC_STATICIMAGEDONE: con 3; | |
| 35 | + ImC_IMAGEABORTED: con 4; | |
| 36 | +}; | |
| @@ -0,0 +1,117 @@ | ||
| 1 | +/* | |
| 2 | + * | |
| 3 | + * Adapted from MDrawingSurfaceInfo.java version - 1.3 96/12/20 | |
| 4 | + * | |
| 5 | + */ | |
| 6 | + | |
| 7 | +package inferno.awt; | |
| 8 | + | |
| 9 | +import sun.awt.DrawingSurfaceInfo; | |
| 10 | +import sun.awt.PhysicalDrawingSurface; | |
| 11 | +import sun.awt.image.ImageRepresentation; | |
| 12 | +import java.awt.Rectangle; | |
| 13 | +import java.awt.Shape; | |
| 14 | +import java.awt.image.ColorModel; | |
| 15 | +import java.awt.peer.ComponentPeer; // eventually inferno.awt.iComponentPeer ?? | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * The iDrawingSurfaceInfo object provides direct access for rendering | |
| 19 | + * on Components maintained by the Inferno iToolkit. | |
| 20 | + * | |
| 21 | + */ | |
| 22 | + | |
| 23 | +public class iDrawingSurfaceInfo | |
| 24 | + implements DrawingSurfaceInfo, PhysicalDrawingSurface /* , iDrawingSurface */ | |
| 25 | +{ | |
| 26 | + int state; | |
| 27 | + int w, h; | |
| 28 | + ComponentPeer peer = null; // eventually an iComponentPeer | |
| 29 | + ImageRepresentation imgrep; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Construct a new iDrawingSurfaceInfo for the specified peer. | |
| 33 | + */ | |
| 34 | + /* To date Inferno doesn't need this constructor from | |
| 35 | + MDrawingSurfaceInfo if it does, we'll need an | |
| 36 | + inferno.awt.iComponentPeer | |
| 37 | + iDrawingSurfaceInfo(iComponentPeer peer) { | |
| 38 | + this.peer = peer; | |
| 39 | + } | |
| 40 | + */ | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Construct a new iDrawingSurfaceInfo for the specified offscreen image. | |
| 44 | + */ | |
| 45 | + iDrawingSurfaceInfo(ImageRepresentation imgrep) { | |
| 46 | + this.imgrep = imgrep; | |
| 47 | + } | |
| 48 | + | |
| 49 | + // implementation of lock from sun.awt.DrawingSurfaceInfo interface | |
| 50 | + public native int lock(); | |
| 51 | + | |
| 52 | + // implementation of unlock from sun.awt.DrawingSurfaceInfo interface | |
| 53 | + public native void unlock(); | |
| 54 | + | |
| 55 | + // implementation of getBounds from sun.awt.DrawingSurfaceInfo interface | |
| 56 | + public Rectangle getBounds() { | |
| 57 | + Rectangle r; | |
| 58 | + // comment out to keep compiler happy, eventually may | |
| 59 | + // need this code ? - jfs | |
| 60 | + /* | |
| 61 | + if (peer != null) { | |
| 62 | + r = peer.target.getBounds(); | |
| 63 | + r.setLocation(0, 0); | |
| 64 | + } else { | |
| 65 | + r = new Rectangle(0, 0, imgrep.width, imgrep.height); | |
| 66 | + } | |
| 67 | + return r; | |
| 68 | + */ | |
| 69 | + return (r = new Rectangle(0, 0, imgrep.width, imgrep.height)); | |
| 70 | + } | |
| 71 | + | |
| 72 | + // implementation of getSurface from sun.awt.DrawingSurfaceInfo interface | |
| 73 | + public PhysicalDrawingSurface getSurface() { | |
| 74 | + return this; | |
| 75 | + } | |
| 76 | + | |
| 77 | + // implementation of getClip from sun.awt.DrawingSurfaceInfo interface | |
| 78 | + public Shape getClip() { | |
| 79 | + return getBounds(); | |
| 80 | + } | |
| 81 | + | |
| 82 | + public ColorModel getColorModel() { | |
| 83 | + return iToolkit.getStaticColorModel(); | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Returns a an Object pointer to the rendered $Draw->Image | |
| 88 | + * represented by this object. | |
| 89 | + */ | |
| 90 | + final native Object getDrawable(); | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * Return the depth (log2 of pixel width) of the | |
| 94 | + * $Draw->Image represented by this object. | |
| 95 | + */ | |
| 96 | + final native int getDepth(); | |
| 97 | + | |
| 98 | + /* | |
| 99 | + for future reference: | |
| 100 | + X11DrawingSurfaceInfo implements X11DrawingSurface: | |
| 101 | + public native int getDisplay(); | |
| 102 | + public native int getDrawable(); | |
| 103 | + public native int getDepth(); | |
| 104 | + public native int getVisualID(); | |
| 105 | + public native int getColormapID(); | |
| 106 | + public ColorModel getColorModel(); | |
| 107 | + | |
| 108 | + and WDrawingSurfaceInfo implements WDrawingSurface: | |
| 109 | + public native int getHWnd(); | |
| 110 | + public native int getHBitmap(); | |
| 111 | + public native int getPBits(); | |
| 112 | + public native int getHDC(); | |
| 113 | + public native int getDepth(); | |
| 114 | + public native int getHPalette(); | |
| 115 | + | |
| 116 | + */ | |
| 117 | +} | |
| @@ -0,0 +1,56 @@ | ||
| 1 | +implement iDrawingSurfaceInfo_L; | |
| 2 | + | |
| 3 | +# javal v1.5 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | + | |
| 27 | +include "iDrawingSurfaceInfo_L.m"; | |
| 28 | + | |
| 29 | +#>> extra post includes here | |
| 30 | + | |
| 31 | +#<< | |
| 32 | + | |
| 33 | +init( jni_p : JNI ) | |
| 34 | +{ | |
| 35 | + # save java native inteface mod instance | |
| 36 | + jni = jni_p; | |
| 37 | + #>>extra initialization here | |
| 38 | + #<< | |
| 39 | +} | |
| 40 | + | |
| 41 | +lock_I( this : ref iDrawingSurfaceInfo_obj) : int | |
| 42 | +{#>> | |
| 43 | +}#<< | |
| 44 | + | |
| 45 | +unlock_V( this : ref iDrawingSurfaceInfo_obj) | |
| 46 | +{#>> | |
| 47 | +}#<< | |
| 48 | + | |
| 49 | +getDrawable_rObject( this : ref iDrawingSurfaceInfo_obj) : JObject | |
| 50 | +{#>> | |
| 51 | +}#<< | |
| 52 | + | |
| 53 | +getDepth_I( this : ref iDrawingSurfaceInfo_obj) : int | |
| 54 | +{#>> | |
| 55 | +}#<< | |
| 56 | + | |
| @@ -0,0 +1,21 @@ | ||
| 1 | +# javal v1.5 generated file: edit with care | |
| 2 | + | |
| 3 | +iDrawingSurfaceInfo_L : module | |
| 4 | +{ | |
| 5 | + iDrawingSurfaceInfo_obj : adt | |
| 6 | + { | |
| 7 | + cl_mod : ClassModule; | |
| 8 | + state : int; | |
| 9 | + w : int; | |
| 10 | + h : int; | |
| 11 | + peer : JObject; | |
| 12 | + imgrep : JObject; | |
| 13 | + }; | |
| 14 | + | |
| 15 | + init : fn( jni_p : JNI ); | |
| 16 | + lock_I : fn( this : ref iDrawingSurfaceInfo_obj) : int; | |
| 17 | + unlock_V : fn( this : ref iDrawingSurfaceInfo_obj); | |
| 18 | + getDrawable_rObject : fn( this : ref iDrawingSurfaceInfo_obj) : JObject; | |
| 19 | + getDepth_I : fn( this : ref iDrawingSurfaceInfo_obj) : int; | |
| 20 | + | |
| 21 | +}; | |
| @@ -0,0 +1,266 @@ | ||
| 1 | +/* | |
| 2 | + * %W% - %E% | |
| 3 | + */ | |
| 4 | + | |
| 5 | + /* | |
| 6 | + The only font metrics that Inferno provides are height, the distance | |
| 7 | + in pixels between baselines of lines of text rendered in a particular | |
| 8 | + font, and ascent, the distance from the top of the bounding box to the | |
| 9 | + baseline. So there really isn't much vertical information to provide. | |
| 10 | + In particular there's no leading, and descent information. | |
| 11 | + | |
| 12 | + To do better than this will require, putting max bounds, leading, and | |
| 13 | + descent information in the Inferno subfont files, and augmenting $Draw | |
| 14 | + built-in module to make this information visible to Limbo programs. | |
| 15 | + */ | |
| 16 | + | |
| 17 | +/* | |
| 18 | + * | |
| 19 | + */ | |
| 20 | + | |
| 21 | +package inferno.awt; | |
| 22 | + | |
| 23 | +import java.awt.*; | |
| 24 | +import java.util.Hashtable; | |
| 25 | +import java.lang.IllegalArgumentException; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * A font metrics object for a font. | |
| 29 | + * | |
| 30 | + */ | |
| 31 | +public class iFontMetrics extends FontMetrics { | |
| 32 | + | |
| 33 | + private static final boolean debug = false; | |
| 34 | + | |
| 35 | + int widths[]; | |
| 36 | + int ascent; | |
| 37 | + int descent; | |
| 38 | + int leading; | |
| 39 | + int height; | |
| 40 | + int maxAscent; | |
| 41 | + int maxDescent; | |
| 42 | + int maxHeight; | |
| 43 | + | |
| 44 | + /* | |
| 45 | + maxAdvance can't be readily determined without | |
| 46 | + parsing the Inferno font file and calling | |
| 47 | + Draw->(Draw->Font).width() for every char mapped by | |
| 48 | + that Inferno Font. An alternate fudging strategy is to | |
| 49 | + set it to the max width of any char in the first 256 | |
| 50 | + (getWidths()) characters. | |
| 51 | + */ | |
| 52 | + int maxAdvance = -1; | |
| 53 | + | |
| 54 | + private boolean needWidths = true; | |
| 55 | + | |
| 56 | + // rather than ask our Font for it's peer everytime we want it. We'll | |
| 57 | + // ask once at construction time, as a small optimization. | |
| 58 | + | |
| 59 | + private iFontPeer ifontpeer; | |
| 60 | + | |
| 61 | + public iFontMetrics(Font font) { | |
| 62 | + super(font); | |
| 63 | + // Some vertical font metrics (height, and ascent) are (conveniently) | |
| 64 | + // already available in the iFontPeer of a constructed Font. | |
| 65 | + if (font == null) { | |
| 66 | + throw new IllegalArgumentException("font"); | |
| 67 | + } | |
| 68 | + ifontpeer = (iFontPeer)font.getPeer(); // our Inferno peer | |
| 69 | + height = ifontpeer.iHeight; | |
| 70 | + ascent = ifontpeer.iAscent; | |
| 71 | + | |
| 72 | + // fudge a pixel for leading if the difference between height | |
| 73 | + // and ascent permits, done by iFontPeer() like so | |
| 74 | + // leading = ((height - ascent) > 2) ? 1 : 0; | |
| 75 | + leading = ifontpeer.fLeading; | |
| 76 | + descent = height - ascent - leading; | |
| 77 | + | |
| 78 | + // There's no information regarding the following available to Limbo, | |
| 79 | + // or even in the Inferno subfont files, so fudge 'em. | |
| 80 | + maxHeight = height; | |
| 81 | + maxAscent = ascent; | |
| 82 | + maxDescent = descent; | |
| 83 | + | |
| 84 | + // widths and maybe maxAdvance is evaluated lazily as needed. | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Get leading | |
| 89 | + */ | |
| 90 | + public int getLeading() { | |
| 91 | + return leading; | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Get ascent. | |
| 96 | + */ | |
| 97 | + public int getAscent() { | |
| 98 | + return ascent; | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Get descent | |
| 103 | + */ | |
| 104 | + public int getDescent() { | |
| 105 | + return descent; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Get height | |
| 110 | + */ | |
| 111 | + public int getHeight() { | |
| 112 | + return height; | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * Get maxAscent | |
| 117 | + */ | |
| 118 | + public int getMaxAscent() { | |
| 119 | + return maxAscent; | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Get maxDescent | |
| 124 | + */ | |
| 125 | + public int getMaxDescent() { | |
| 126 | + return maxDescent; | |
| 127 | + } | |
| 128 | + | |
| 129 | + /** | |
| 130 | + * Get maxAdvance | |
| 131 | + */ | |
| 132 | + public int getMaxAdvance() { | |
| 133 | + if (needWidths) { | |
| 134 | + initWidths(); | |
| 135 | + } | |
| 136 | + return maxAdvance; | |
| 137 | + } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Returns the advance width of the sprcified character in this Font. | |
| 141 | + */ | |
| 142 | + public int charWidth(char ch) { | |
| 143 | + if (ch < 256) { // chars are zero extended upon promotin to ints | |
| 144 | + if (needWidths) { | |
| 145 | + initWidths(); | |
| 146 | + } | |
| 147 | + return widths[ch & 0xFF]; | |
| 148 | + } else { | |
| 149 | + char data[] = { ch }; | |
| 150 | + return charsWidth(data, 0, 1); | |
| 151 | + } | |
| 152 | + } | |
| 153 | + | |
| 154 | + | |
| 155 | + /** | |
| 156 | + * Return the advance widh of the specified chars in this Font | |
| 157 | + */ | |
| 158 | + public int charsWidth(char data[], int off, int len) { | |
| 159 | + int w = 0; | |
| 160 | + int tlen = len; | |
| 161 | + int toff = off; | |
| 162 | + boolean tooBig = false; | |
| 163 | + if (data == null || off < 0) { | |
| 164 | + throw new IllegalArgumentException(); | |
| 165 | + } | |
| 166 | + while(len-- > 0) { | |
| 167 | + if (data[off] >= 256) { | |
| 168 | + tooBig = true; | |
| 169 | + break; | |
| 170 | + } | |
| 171 | + if (needWidths) { | |
| 172 | + initWidths(); | |
| 173 | + } | |
| 174 | + w += widths[data[off++]]; | |
| 175 | + } | |
| 176 | + if (tooBig) { | |
| 177 | + if (debug) { | |
| 178 | + System.out.println("iFontMetrics.charsWidth - tooBig"); | |
| 179 | + } | |
| 180 | + w = stringWidth(new String(data, off, len)); | |
| 181 | + } | |
| 182 | + return w; | |
| 183 | + } | |
| 184 | + | |
| 185 | + | |
| 186 | + /** | |
| 187 | + * Return the width of the specified string in this Font. | |
| 188 | + * | |
| 189 | + * Why not bust up the string into a char[] and try for the optimization | |
| 190 | + * of charsWidth if all elemment values are less than 256? -jfs? | |
| 191 | + */ | |
| 192 | + public int stringWidth(String str) { | |
| 193 | + if (str == null) { | |
| 194 | + throw new IllegalArgumentException(); | |
| 195 | + } | |
| 196 | + return iStringWidth(str); | |
| 197 | + } | |
| 198 | + | |
| 199 | + public int bytesWidth(byte[] data, int off, int len) { | |
| 200 | + // check args here? | |
| 201 | + if (data == null || off < 0 || len < 0) { | |
| 202 | + throw new IllegalArgumentException(); | |
| 203 | + } | |
| 204 | + byte[] ndata = new byte[len]; | |
| 205 | + System.arraycopy(data, off, ndata, 0, len); | |
| 206 | + return iBytesWidth(ndata); | |
| 207 | + } | |
| 208 | + | |
| 209 | + // Compute width of string in this font. | |
| 210 | + private native int iStringWidth(String str); | |
| 211 | + | |
| 212 | + // translate bytes from UTF-8 encoding into a Unicode Limbo string, | |
| 213 | + // compute the advance width of the string in this Font and return | |
| 214 | + // the advance in pixels. | |
| 215 | + private native int iBytesWidth(byte data[]); | |
| 216 | + | |
| 217 | + // get advance widths of the first 256 characters of this font. | |
| 218 | + private synchronized void initWidths() { | |
| 219 | + widths = new int[256]; | |
| 220 | + maxAdvance = iInitWidths(widths); | |
| 221 | + if (debug) { | |
| 222 | + System.out.println("iFontMetrics.initWidths(): maxAdvance=" + maxAdvance); | |
| 223 | + } | |
| 224 | + needWidths = false; | |
| 225 | + } | |
| 226 | + | |
| 227 | + // populates widths with the advance width of the first 256 chars | |
| 228 | + // in this font, returns the width of the widest character. | |
| 229 | + private native int iInitWidths(int widths[]); | |
| 230 | + | |
| 231 | + /** | |
| 232 | + * Get the widths of the first 256 characters in the font. | |
| 233 | + */ | |
| 234 | + public int[] getWidths() { | |
| 235 | + if (needWidths) { | |
| 236 | + initWidths(); | |
| 237 | + } | |
| 238 | + return widths; | |
| 239 | + } | |
| 240 | + | |
| 241 | + static Hashtable table = new Hashtable(); | |
| 242 | + | |
| 243 | + static synchronized FontMetrics getFontMetrics(Font font) { | |
| 244 | + if (font == null) { | |
| 245 | + throw new NullPointerException("FontMetrics.getFontMetrics()"); | |
| 246 | + } | |
| 247 | + FontMetrics fm = (FontMetrics)table.get(font); | |
| 248 | + if (fm == null) { | |
| 249 | + table.put(font, fm = new iFontMetrics(font)); | |
| 250 | + } | |
| 251 | + return fm; | |
| 252 | + } | |
| 253 | + | |
| 254 | + /** | |
| 255 | + Returns a representation of this <code>FontMetric</code> | |
| 256 | + object's values as a string. | |
| 257 | + @return a string representation of this font metric. | |
| 258 | + */ | |
| 259 | + public String toString() { | |
| 260 | + return getClass().getName() + "[font=" + getFont() + "ascent=" + | |
| 261 | + getAscent() + ", descent=" + getDescent() + ", leading=" + | |
| 262 | + getLeading() + ", height=" + getHeight() + ", maxAdvance=" + | |
| 263 | + maxAdvance + ", font.getPeer()=" + font.getPeer().toString() + | |
| 264 | + " ]" ; | |
| 265 | + } | |
| 266 | +} | |
| @@ -0,0 +1,123 @@ | ||
| 1 | +implement iFontMetrics_L; | |
| 2 | + | |
| 3 | +# javal v1.5 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | +# | |
| 27 | +# %W% - %E% | |
| 28 | +# | |
| 29 | + | |
| 30 | +Value: import jni; | |
| 31 | +sys : import jni; # std inferno Sys modoule | |
| 32 | +# str : import jni; # std inferno String module | |
| 33 | +# jldr : import jni; # primary java class loader, JavaClassLoader | |
| 34 | + | |
| 35 | +# draw.m is included by something included by jni.m | |
| 36 | +draw : Draw; | |
| 37 | +Font : import Draw; | |
| 38 | + | |
| 39 | +include "iFontPeer_L.m"; | |
| 40 | +ifontpeerm : iFontPeer_L; | |
| 41 | +iFontPeer_obj : import ifontpeerm; | |
| 42 | +#<< | |
| 43 | + | |
| 44 | +include "iFontMetrics_L.m"; | |
| 45 | + | |
| 46 | +#>> extra post includes here | |
| 47 | + | |
| 48 | +cast : Cast; | |
| 49 | +ctxt : ref Draw->Context; # for ref to Display | |
| 50 | + | |
| 51 | +#<< | |
| 52 | + | |
| 53 | +init( jni_p : JNI ) | |
| 54 | +{ | |
| 55 | + # save java native inteface mod instance | |
| 56 | + jni = jni_p; | |
| 57 | + #>>extra initialization here | |
| 58 | + | |
| 59 | + sys = jni->sys; | |
| 60 | + | |
| 61 | + # should not I share draw with at least the rest of the AWT | |
| 62 | + # graphics world ? | |
| 63 | + draw = load Draw Draw->PATH; | |
| 64 | + | |
| 65 | + #ifontpeerm = load iFontPeer_L iFontPeer_L->PATH; | |
| 66 | + | |
| 67 | + ctxt = jni->getContext(); | |
| 68 | + if (ctxt == nil) { | |
| 69 | + # Eventually the print can be removed, throwing the | |
| 70 | + # Exception will suffice. | |
| 71 | + sys->print("iFontMetrics_L.init: ctxt == nil, can't get Draw Context!\n"); | |
| 72 | + jni->ThrowException("java.awt.AWTError", "can't get Draw Context"); | |
| 73 | + } | |
| 74 | +#<< | |
| 75 | +} | |
| 76 | + | |
| 77 | +iStringWidth_rString_I( this : ref iFontMetrics_obj, p0 : JString) : int | |
| 78 | +{#>> | |
| 79 | + | |
| 80 | + # sys->print("iFontMetrics_L: fontref=%#x\n", p0); | |
| 81 | + return (draw->(this.ifontpeer.iFontRef).width(p0.str)); | |
| 82 | + #return (draw->(this.iFontRef).width(p0.str)); | |
| 83 | +}#<< | |
| 84 | + | |
| 85 | +iBytesWidth_aB_I( this : ref iFontMetrics_obj, p0 : JArrayB) : int | |
| 86 | +{#>> | |
| 87 | + # convert to string performing UT8 to Unicode translation | |
| 88 | + cdata := string p0.ary; | |
| 89 | + return (draw->(this.ifontpeer.iFontRef).width(cdata)); | |
| 90 | +}#<< | |
| 91 | + | |
| 92 | +iInitWidths_aI_I( this : ref iFontMetrics_obj, p0 : JArrayI) : int | |
| 93 | +{#>> | |
| 94 | + # p0 is widths[256] in java land | |
| 95 | + maxw := 0; # maximum width | |
| 96 | + cs : string; | |
| 97 | + n := len p0.ary; | |
| 98 | + cw : int; # width of current char | |
| 99 | + cb := array[1] of byte; | |
| 100 | + | |
| 101 | + for (i := 0; i < n; i++) { | |
| 102 | + cb[0] = byte i; # cast i to string | |
| 103 | + cs = string cb; | |
| 104 | + | |
| 105 | + cw = (draw->(this.ifontpeer.iFontRef).width(cs)); | |
| 106 | + | |
| 107 | + if (maxw < cw) { | |
| 108 | + maxw = cw; | |
| 109 | + } | |
| 110 | + | |
| 111 | + p0.ary[i] = cw; | |
| 112 | + } | |
| 113 | + return maxw; | |
| 114 | +}#<< | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| @@ -0,0 +1,27 @@ | ||
| 1 | +# javal v1.5 generated file: edit with care | |
| 2 | + | |
| 3 | +iFontMetrics_L : module | |
| 4 | +{ | |
| 5 | + iFontMetrics_obj : adt | |
| 6 | + { | |
| 7 | + cl_mod : ClassModule; | |
| 8 | + font : JObject; | |
| 9 | + widths : JArrayI; | |
| 10 | + ascent : int; | |
| 11 | + descent : int; | |
| 12 | + leading : int; | |
| 13 | + height : int; | |
| 14 | + maxAscent : int; | |
| 15 | + maxDescent : int; | |
| 16 | + maxHeight : int; | |
| 17 | + maxAdvance : int; | |
| 18 | + needWidths : byte; | |
| 19 | + ifontpeer : ref iFontPeer_obj; # javal generates JObject; | |
| 20 | + }; | |
| 21 | + | |
| 22 | + init : fn( jni_p : JNI ); | |
| 23 | + iStringWidth_rString_I : fn( this : ref iFontMetrics_obj, p0 : JString) : int; | |
| 24 | + iBytesWidth_aB_I : fn( this : ref iFontMetrics_obj, p0 : JArrayB) : int; | |
| 25 | + iInitWidths_aI_I : fn( this : ref iFontMetrics_obj, p0 : JArrayI) : int; | |
| 26 | + | |
| 27 | +}; | |
| @@ -0,0 +1,276 @@ | ||
| 1 | +/* | |
| 2 | + * %W% - %E% | |
| 3 | + */ | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Inferno's Font peer | |
| 7 | + * | |
| 8 | + */ | |
| 9 | + | |
| 10 | + /* | |
| 11 | + * If you're not using xemacs to view this file, you may find it's indentation | |
| 12 | + * more ledgible if you set your tabstops to four spaces. | |
| 13 | + */ | |
| 14 | +package inferno.awt; | |
| 15 | + | |
| 16 | +import java.io.FileNotFoundException; | |
| 17 | +import java.awt.Font; | |
| 18 | +import java.util.Properties; | |
| 19 | +import java.util.Hashtable; | |
| 20 | +import java.util.Vector; | |
| 21 | +import java.io.File; | |
| 22 | +import java.io.InputStream; | |
| 23 | +import java.io.FileInputStream; | |
| 24 | +import java.io.BufferedInputStream; | |
| 25 | +import java.util.StringTokenizer; | |
| 26 | + | |
| 27 | +public class iFontPeer implements java.awt.peer.FontPeer { | |
| 28 | + | |
| 29 | + // a default Inferno pathname to a font | |
| 30 | + // "/fonts/lucidasans/latin1.7.font" is a popular default font | |
| 31 | + private final static String defifpathname = "*default*"; | |
| 32 | + | |
| 33 | + /* | |
| 34 | + An object to hold a Limbo reference of type ref Draw->Font | |
| 35 | + the handle to Inferno platform font capabilities. | |
| 36 | + Inferno JNI access as this.iFontRef. | |
| 37 | + Pertinent size metrics are kept here in the peer for quicker | |
| 38 | + text rendering. | |
| 39 | + */ | |
| 40 | + Object iFontRef; | |
| 41 | + int iAscent = -1; // Inferno font's ascent value | |
| 42 | + int iHeight = -1; // Inferno font's height value | |
| 43 | + int fLeading = -1; // a fudged value for leading (none in Inferno fonts) | |
| 44 | + String iName = ""; // Inferno font's name (should match ifpathname) | |
| 45 | + | |
| 46 | + private static Properties fprops; | |
| 47 | + static { | |
| 48 | + // Find property file | |
| 49 | + String jhome = System.getProperty("java.home"); | |
| 50 | + if (jhome == null){ | |
| 51 | + throw new Error("java.home property not set"); | |
| 52 | + } | |
| 53 | + // trace("jhome=" + jhome); | |
| 54 | + | |
| 55 | + String language = System.getProperty("user.language", "en"); | |
| 56 | + String region = System.getProperty("user.region"); | |
| 57 | + | |
| 58 | + // trace("language=" + language); | |
| 59 | + // trace("region=" + region); | |
| 60 | + // trace("File.separator=" + File.separator); | |
| 61 | + | |
| 62 | + try { | |
| 63 | + File f = null; | |
| 64 | + if (region != null) { | |
| 65 | + f = new File(jhome + File.separator + | |
| 66 | + "lib" + File.separator + | |
| 67 | + "font.properties." + language + "_" + | |
| 68 | + region); | |
| 69 | + } | |
| 70 | + | |
| 71 | + if (f == null || !f.canRead()) { | |
| 72 | + f = new File(jhome + File.separator + | |
| 73 | + "lib" + File.separator + "font.properties." + | |
| 74 | + language); | |
| 75 | + if (!f.canRead()) { | |
| 76 | + f = new File(jhome + File.separator + | |
| 77 | + "lib" + File.separator + "font.properties"); | |
| 78 | + if (!f.canRead()){ | |
| 79 | + throw new Exception(); | |
| 80 | + } | |
| 81 | + } | |
| 82 | + } | |
| 83 | + | |
| 84 | + fprops = new Properties(); | |
| 85 | + | |
| 86 | + // Load property file | |
| 87 | + // trace("trying to load props at path " + f.getPath()); | |
| 88 | + InputStream in = | |
| 89 | + new BufferedInputStream(new FileInputStream(f.getPath())); | |
| 90 | + fprops.load(in); | |
| 91 | + in.close(); | |
| 92 | + } catch (Exception e){ | |
| 93 | + System.out.println("iFontPeer: can't load font.properties"); | |
| 94 | + System.out.println("exception: " + e.getMessage()); | |
| 95 | + e.printStackTrace(); | |
| 96 | + } // end try | |
| 97 | + } // end static | |
| 98 | + | |
| 99 | + | |
| 100 | + // The do-nothing constructor | |
| 101 | + public iFontPeer(String name, int style) { | |
| 102 | + // Don't do anything with name and style, they're implementation | |
| 103 | + // artifacts from a different (better?) world of scalable | |
| 104 | + // platform fonts where size is a final argument to platform | |
| 105 | + // dependant rendering libraries, but Inferno's are static bitmaps. | |
| 106 | + // | |
| 107 | + // a better (more general) signatures for this constructor would | |
| 108 | + // have been FontPeer(Font font) or | |
| 109 | + // FontPeer(String name,int style,int size) | |
| 110 | + // but alas, Sun's API hasn't been quite general enough in that regard. | |
| 111 | + } | |
| 112 | + | |
| 113 | + // Native method to actually create font in Inferno Display and | |
| 114 | + // populate this object with reference to Draw->Font and some | |
| 115 | + // font metrics. | |
| 116 | + private native void initFontPeer(String ifpathname) throws FileNotFoundException; | |
| 117 | + | |
| 118 | + // | |
| 119 | + // initializeFontPeer is called by java.awt.Font.java so this | |
| 120 | + // method must, regretably, have public scope. | |
| 121 | + // | |
| 122 | + public String initializeFontPeer(String name, int style, int size) | |
| 123 | + { | |
| 124 | + String ifpn = ""; // pathname to Inferno font | |
| 125 | + // trace("iFontPeer.initializeFontPeer(): name=" + name +" ,style=" | |
| 126 | + // + style + ", size=" + size); | |
| 127 | + | |
| 128 | + boolean triedDefault = false; | |
| 129 | + ifpn = mapifpath(name, style, size); | |
| 130 | + if (ifpn == null) { | |
| 131 | + ifpn = defifpathname; | |
| 132 | + } | |
| 133 | + | |
| 134 | + retry: | |
| 135 | + try { | |
| 136 | + initFontPeer(ifpn); // sets iName, iAscent, iHeight, and fLeading | |
| 137 | + } catch (FileNotFoundException e) { | |
| 138 | + // case: properties maps to a file but font file doesn't | |
| 139 | + // exist | |
| 140 | + if (!triedDefault) { | |
| 141 | + triedDefault = true; | |
| 142 | + ifpn = defifpathname; | |
| 143 | + // trace("initializeFontPeer: trying default"); | |
| 144 | + break retry; | |
| 145 | + } | |
| 146 | + } | |
| 147 | + | |
| 148 | + if (debug) { | |
| 149 | + trace("iFontPeer.initializeFontPeer():"); | |
| 150 | + trace(" iName=" + iName); | |
| 151 | + trace(" iAscent=" + iAscent + " iHeight=" + iHeight); | |
| 152 | + } | |
| 153 | + return ifpn; | |
| 154 | + } | |
| 155 | + | |
| 156 | + // | |
| 157 | + // map a Java font triple into the full pathname of an Inferno | |
| 158 | + // font description file. | |
| 159 | + // | |
| 160 | + private static String mapifpath(String name, int style, int size) { | |
| 161 | + | |
| 162 | + if (fprops == null) { | |
| 163 | + return defifpathname; | |
| 164 | + } | |
| 165 | + | |
| 166 | + String aName = name.toLowerCase(); | |
| 167 | + String aStyle = styleStr(style); | |
| 168 | + String aSize = String.valueOf(size); | |
| 169 | + | |
| 170 | + //trace("mapifpath(" + aName + ", " + aStyle + ", " + aSize + ")"); | |
| 171 | + String aStr = aName + "." + aStyle + "." + aSize; | |
| 172 | + int idx; | |
| 173 | + | |
| 174 | + // perform face name substitution | |
| 175 | + String rStr = fprops.getProperty("alias." + aName); | |
| 176 | + if (rStr != null && rStr.indexOf('.') < 0) { | |
| 177 | + aName = rStr; | |
| 178 | + } | |
| 179 | + //trace("gp1 rStr=" +rStr+ " aName=" +aName+ " aStyle=" +aStyle+ | |
| 180 | + // " aSize=" + aSize); | |
| 181 | + | |
| 182 | + // perform style substitution on result of above | |
| 183 | + rStr = fprops.getProperty("alias." + aName + "." + aStyle); | |
| 184 | + if (rStr != null) { | |
| 185 | + idx = rStr.indexOf('.'); | |
| 186 | + if (idx > 0 && rStr.lastIndexOf('.') == idx && | |
| 187 | + (idx+1 < rStr.length())) | |
| 188 | + { | |
| 189 | + aName = rStr.substring(0,idx); | |
| 190 | + aStyle = rStr.substring(idx+1); | |
| 191 | + } | |
| 192 | + } | |
| 193 | + //trace("gp2 rStr=" +rStr+ " aName=" +aName+ " aStyle=" +aStyle+ | |
| 194 | + // " aSize=" + aSize); | |
| 195 | + | |
| 196 | + | |
| 197 | + // Now see if there's a complete alias for this "font+style+size" | |
| 198 | + rStr = fprops.getProperty("alias." + aName + "." + aStyle + | |
| 199 | + "." + aSize); | |
| 200 | + if (rStr != null) { | |
| 201 | + StringTokenizer st = new StringTokenizer(rStr,".",false); | |
| 202 | + if (st.countTokens() == 3) { | |
| 203 | + aName = st.nextToken(); | |
| 204 | + aStyle = st.nextToken(); | |
| 205 | + aSize = st.nextToken(); | |
| 206 | + } | |
| 207 | + } | |
| 208 | + //trace("gp3 rStr=" +rStr+ " aName=" +aName+ " aStyle=" +aStyle+ | |
| 209 | + // " aSize=" + aSize); | |
| 210 | + | |
| 211 | + | |
| 212 | + // after these substitutions, see if the font string has | |
| 213 | + // a match, applying the followin heuristic. | |
| 214 | + // if stlye isn't "plain", adjust size +-2, if no match | |
| 215 | + // change style to "plain" and proceed per style is "plain" | |
| 216 | + // if style is "plain" adjust size +-4 if need be. | |
| 217 | + // | |
| 218 | + | |
| 219 | + while(true) { | |
| 220 | + int nsize; | |
| 221 | + boolean up = true; | |
| 222 | + int range = (style != Font.PLAIN) ? 2 : 4; | |
| 223 | + | |
| 224 | + for (int i = 0; i <= range;) { | |
| 225 | + nsize = Math.abs(size + ((up) ? i : -i)); | |
| 226 | + // trace("nsize=" + nsize); | |
| 227 | + aSize = String.valueOf(nsize); | |
| 228 | + rStr = fprops.getProperty(aName +"."+ aStyle + "." + aSize); | |
| 229 | + if (rStr != null) { | |
| 230 | + //trace("***mapifpath: got it!"); | |
| 231 | + break; | |
| 232 | + } | |
| 233 | + if (!up) { | |
| 234 | + i++; | |
| 235 | + } | |
| 236 | + up = (!up); | |
| 237 | + } | |
| 238 | + if (rStr == null) { | |
| 239 | + if (style != Font.PLAIN) { // retry with plain style | |
| 240 | + style = Font.PLAIN; | |
| 241 | + aStyle = styleStr(style); | |
| 242 | + //trace("***mapifpath: retry w/plain font!, nsize=" + nsize); | |
| 243 | + continue; | |
| 244 | + } | |
| 245 | + rStr = defifpathname; // no Match, returns default | |
| 246 | + } | |
| 247 | + break; | |
| 248 | + } | |
| 249 | + trace ("mapifpath: gp4 aName=" +aName+ " aStyle=" +aStyle+ | |
| 250 | + " aSize=" + aSize + " rStr=" + rStr); | |
| 251 | + return(rStr); | |
| 252 | + } | |
| 253 | + | |
| 254 | + /* | |
| 255 | + * return String representation of style | |
| 256 | + */ | |
| 257 | + private static String styleStr(int num){ | |
| 258 | + switch(num){ | |
| 259 | + case Font.BOLD: | |
| 260 | + return "bold"; | |
| 261 | + case Font.ITALIC: | |
| 262 | + return "italic"; | |
| 263 | + case Font.ITALIC+Font.BOLD: | |
| 264 | + return "bolditalic"; | |
| 265 | + default: | |
| 266 | + return "plain"; | |
| 267 | + } | |
| 268 | + } | |
| 269 | + | |
| 270 | + private static final boolean debug = false; | |
| 271 | + private static void trace(String arg) { | |
| 272 | + if (debug) { | |
| 273 | + System.out.println(arg); | |
| 274 | + } | |
| 275 | + } | |
| 276 | +} | |
| @@ -0,0 +1,115 @@ | ||
| 1 | +implement iFontPeer_L; | |
| 2 | + | |
| 3 | +# javal v1.5 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | + | |
| 27 | +# | |
| 28 | +# %W% - %E% | |
| 29 | +# | |
| 30 | + | |
| 31 | +Value : import jni; | |
| 32 | +sys : import jni; # std inferno Sys modoule | |
| 33 | +str : import jni; # std inferno String module | |
| 34 | +# jldr : import jni; # primary java class loader, JavaClassLoader | |
| 35 | + | |
| 36 | +# draw.m is included by something included by jni.m | |
| 37 | +draw : Draw; | |
| 38 | +Font : import Draw; | |
| 39 | + | |
| 40 | +#<< | |
| 41 | + | |
| 42 | +include "iFontPeer_L.m"; | |
| 43 | + | |
| 44 | +#>> extra post includes here | |
| 45 | + | |
| 46 | +cast : Cast; | |
| 47 | +ctxt : ref Draw->Context; # for ref to Display | |
| 48 | + | |
| 49 | +#<< | |
| 50 | + | |
| 51 | +init( jni_p : JNI ) | |
| 52 | +{ | |
| 53 | + # save java native inteface mod instance | |
| 54 | + jni = jni_p; | |
| 55 | + #>>extra initialization here | |
| 56 | + | |
| 57 | + sys = jni->sys; | |
| 58 | + | |
| 59 | + # should not I share draw with at least the rest of the AWT | |
| 60 | + # graphics world ? | |
| 61 | + draw = load Draw Draw->PATH; | |
| 62 | + # sys->print("iFontPeer_L: draw=%x\n",draw); | |
| 63 | + | |
| 64 | + # Why is getting Cast module handle from jni different | |
| 65 | + # than getting Sys, Math, and String modules handles from jni? | |
| 66 | + # cast = jni->CastMod(); | |
| 67 | + ctxt = jni->getContext(); | |
| 68 | + if (ctxt == nil) { | |
| 69 | + # Eventually the print can be removed, throwing the | |
| 70 | + # Exception will suffice. | |
| 71 | + sys->print("iFontPeer_L.init: ctxt == nil, can't get Draw Context!\n"); | |
| 72 | + jni->ThrowException("java.awt.AWTError", "can't get Draw Context"); | |
| 73 | + } | |
| 74 | + #<< | |
| 75 | +} | |
| 76 | + | |
| 77 | +initFontPeer_rString_V( this : ref iFontPeer_obj, p0 : JString) | |
| 78 | +{#>> | |
| 79 | + | |
| 80 | + ifp := p0.str; | |
| 81 | + #sys->print("initFontPeer_V: this.ifpathname=%s\n",ifp); | |
| 82 | + | |
| 83 | + this.iFontRef = draw->Font.open(ctxt.display, ifp); | |
| 84 | + fontref := this.iFontRef; | |
| 85 | + | |
| 86 | + if (nil == fontref) { | |
| 87 | + sys->print("iFontPeer_L: can't open font %s - %r\n",ifp); | |
| 88 | + jni->ThrowException("java.io.FileNotFoundException", ifp); | |
| 89 | + } | |
| 90 | + | |
| 91 | + # sys->print("iFontPeer_L: this=%#x\n",this); | |
| 92 | + # sys->print("iFontPeer_L: this.iFontRef=%#x, draw=%#x\n",this.iFontRef, draw); | |
| 93 | + | |
| 94 | + | |
| 95 | + # make native Font information visible in javaland | |
| 96 | + | |
| 97 | + #this.iName.str = fontref.name; | |
| 98 | + this.iName = jni->NewString(fontref.name); | |
| 99 | + | |
| 100 | + this.iAscent = fontref.ascent; | |
| 101 | + this.iHeight = fontref.height; | |
| 102 | + | |
| 103 | + | |
| 104 | + ## if there is some height to spare, fudge a pixel of leading | |
| 105 | + # if ((fontref.height - fontref.ascent) > 2) { | |
| 106 | + # this.fLeading = 1; | |
| 107 | + # } | |
| 108 | + this.fLeading = 0; | |
| 109 | + | |
| 110 | + # sys->print("this.iFontRef=%x\n",this.iFontRef); | |
| 111 | + # sys->print("this.iAscent=%x\n",this.iAscent); | |
| 112 | + # sys->print("this.iHeight=%x\n",this.iHeight); | |
| 113 | + # sys->print("this.fLeading=%x\n",this.fLeading); | |
| 114 | +}#<< | |
| 115 | + | |
| @@ -0,0 +1,20 @@ | ||
| 1 | +# javal v1.5 generated file: edit with care | |
| 2 | + | |
| 3 | +iFontPeer_L : module | |
| 4 | +{ | |
| 5 | + PATH : con "/dis/java/inferno/awt/iFontPeer_L.dis"; | |
| 6 | + | |
| 7 | + iFontPeer_obj : adt | |
| 8 | + { | |
| 9 | + cl_mod : ClassModule; | |
| 10 | + iFontRef : ref Font; # javal generates JObject; | |
| 11 | + iAscent : int; | |
| 12 | + iHeight : int; | |
| 13 | + fLeading : int; | |
| 14 | + iName : JString; | |
| 15 | + }; | |
| 16 | + | |
| 17 | + init : fn( jni_p : JNI ); | |
| 18 | + initFontPeer_rString_V : fn( this : ref iFontPeer_obj, p0 : JString); | |
| 19 | + | |
| 20 | +}; | |
| @@ -0,0 +1,527 @@ | ||
| 1 | +package inferno.awt; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.awt.event.*; | |
| 5 | +import java.awt.peer.*; | |
| 6 | +import java.awt.image.ImageProducer; | |
| 7 | +import java.awt.image.ImageObserver; | |
| 8 | +import java.awt.image.ColorModel; | |
| 9 | +import java.awt.image.DirectColorModel; | |
| 10 | +import java.util.*; | |
| 11 | +import inferno.awt.iGraphics; | |
| 12 | + | |
| 13 | +public class iFramePeer implements FramePeer, DoubleBufferingPeer { | |
| 14 | + private Object pCanvas; // Set inside create() used by natives | |
| 15 | + | |
| 16 | + // set inside create(), used by natives, to avoid some clutter in | |
| 17 | + // escaping the Limbo type system. | |
| 18 | + private Object thisAsJObject; | |
| 19 | + | |
| 20 | + private Frame target; | |
| 21 | + | |
| 22 | + private int leftInset=0; // How much canvas is inset from frame | |
| 23 | + private int rightInset=0; | |
| 24 | + private int topInset=0; | |
| 25 | + private int bottomInset=0; | |
| 26 | + private int left; // x position of left of frame | |
| 27 | + private int top; // y position of top of frame | |
| 28 | + | |
| 29 | + private Point oldMousePoint; | |
| 30 | + private boolean buttonState[]; | |
| 31 | + | |
| 32 | + private int resizable = 1; | |
| 33 | + | |
| 34 | + public iFramePeer(Frame target) { | |
| 35 | + this.target = target; | |
| 36 | + oldMousePoint=new Point(-1,-1); | |
| 37 | + buttonState=new boolean[3]; | |
| 38 | + for (int i=0;i<3;i++) buttonState[i]=false; //up | |
| 39 | + // create(this); | |
| 40 | + if (target.getTitle() != null) { | |
| 41 | + setTitle(target.getTitle()); | |
| 42 | + } | |
| 43 | + Font f = target.getFont(); | |
| 44 | + if (f == null) { | |
| 45 | + f = new Font("Dialog", Font.PLAIN, 12); | |
| 46 | + target.setFont(f); | |
| 47 | + setFont(f); | |
| 48 | + } | |
| 49 | + Color c = target.getBackground(); | |
| 50 | + if (c == null) { | |
| 51 | + c = SystemColor.window; | |
| 52 | + target.setBackground(c); | |
| 53 | + setBackground(c); | |
| 54 | + } | |
| 55 | + c = target.getForeground(); | |
| 56 | + if (c == null) { | |
| 57 | + target.setForeground(Color.black); | |
| 58 | + setForeground(Color.black); | |
| 59 | + } | |
| 60 | + if (!target.isResizable()) | |
| 61 | + this.resizable = 0; | |
| 62 | + | |
| 63 | + create(this); | |
| 64 | + | |
| 65 | + } | |
| 66 | + | |
| 67 | + /* implementation of java.awt.peer.DoubleBufferingPeer */ | |
| 68 | + public boolean isDoubleBuffered() { | |
| 69 | + return true; | |
| 70 | + } | |
| 71 | + | |
| 72 | + private native Object getRefImage(); // Returns dev/draw image of canvas | |
| 73 | + | |
| 74 | + private native Object getRefOffScreenImage(); // Returns off-screen buffer image | |
| 75 | + | |
| 76 | + private native void pReshape(int x, int y, int width, int height); | |
| 77 | + | |
| 78 | + private native void pHide(); // Hide frame | |
| 79 | + | |
| 80 | + private native void pShow(iFramePeer fp); // Show frame | |
| 81 | + | |
| 82 | + private native int getXYLoc(int coord); // get x or y value of the global position | |
| 83 | + | |
| 84 | + // Create frame putting canvas in pcanvas | |
| 85 | + private native void create(iFramePeer me); | |
| 86 | + | |
| 87 | + public native void pDispose(); // Destroy frame | |
| 88 | + public native void setCursor(int cursorType); // Set cursor | |
| 89 | + public native void setTitle(String title); // Set title of frame | |
| 90 | + public native void toFront(); // Move frame to front | |
| 91 | + public native void toBack(); // Move frame to back | |
| 92 | + | |
| 93 | + | |
| 94 | + /* New 1.1 API */ | |
| 95 | + public Point getLocationOnScreen() // Return position on screen | |
| 96 | + { | |
| 97 | + Point p = new Point(); | |
| 98 | + p.x = getXYLoc(0); | |
| 99 | + p.y = getXYLoc(1); | |
| 100 | + return p; | |
| 101 | + } | |
| 102 | + | |
| 103 | + public void recalculate() | |
| 104 | + { | |
| 105 | + MenuBar mb=target.getMenuBar(); | |
| 106 | + if (mb!=null) | |
| 107 | + { | |
| 108 | + iMenuBarPeer ip=(iMenuBarPeer)mb.getPeer(); | |
| 109 | + | |
| 110 | + if (ip!=null) | |
| 111 | + { | |
| 112 | + ip.recalculate(); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + public void setCursor(Cursor c) | |
| 118 | + { | |
| 119 | + if (c!=null) | |
| 120 | + setCursor(c.getType()); | |
| 121 | + } | |
| 122 | + | |
| 123 | + public void setResizable(boolean resizable) | |
| 124 | + { | |
| 125 | + System.out.println("java: setResizable() get called" + resizable); | |
| 126 | + if(!resizable) | |
| 127 | + this.resizable = 0; | |
| 128 | + } | |
| 129 | + | |
| 130 | + public void setMenuBar(MenuBar mb) | |
| 131 | + { | |
| 132 | + recalculate(); | |
| 133 | + } | |
| 134 | + | |
| 135 | + public void setIconImage(Image im) | |
| 136 | + { | |
| 137 | + } | |
| 138 | + | |
| 139 | + public Insets getInsets() | |
| 140 | + { | |
| 141 | + Insets i=new Insets(topInset,leftInset,bottomInset,rightInset); | |
| 142 | + | |
| 143 | + MenuBar mb=target.getMenuBar(); | |
| 144 | + | |
| 145 | + if (mb!=null) | |
| 146 | + { | |
| 147 | + iMenuBarPeer peer=(iMenuBarPeer)mb.getPeer(); | |
| 148 | + | |
| 149 | + if (peer!=null) | |
| 150 | + { | |
| 151 | + i=(Insets)i.clone(); //Get new copy | |
| 152 | + | |
| 153 | + i.top+=peer.getHeight(); | |
| 154 | + } | |
| 155 | + | |
| 156 | + } | |
| 157 | + | |
| 158 | + return i; | |
| 159 | + } | |
| 160 | + | |
| 161 | + public Insets insets() | |
| 162 | + { | |
| 163 | + return getInsets(); | |
| 164 | + } | |
| 165 | + | |
| 166 | + public void endValidate() | |
| 167 | + { | |
| 168 | + | |
| 169 | + } | |
| 170 | + | |
| 171 | + public void beginValidate() | |
| 172 | + { | |
| 173 | + | |
| 174 | + } | |
| 175 | + | |
| 176 | + public void setBounds(int x, int y, int width, int height) { | |
| 177 | + pReshape(x, y, width, height); | |
| 178 | + } | |
| 179 | + | |
| 180 | + public void reshape(int x, int y, int width, int height) { | |
| 181 | + pReshape(x, y, width, height); | |
| 182 | + } | |
| 183 | + | |
| 184 | + | |
| 185 | + public void dispose() | |
| 186 | + { | |
| 187 | + pDispose(); | |
| 188 | + pCanvas=null; | |
| 189 | + } | |
| 190 | + | |
| 191 | + public void disable() | |
| 192 | + { | |
| 193 | + setEnabled(false); | |
| 194 | + } | |
| 195 | + | |
| 196 | + public void enable() | |
| 197 | + { | |
| 198 | + setEnabled(false); | |
| 199 | + } | |
| 200 | + | |
| 201 | + public void setEnabled(boolean b) | |
| 202 | + { | |
| 203 | + | |
| 204 | + } | |
| 205 | + | |
| 206 | + public void hide() | |
| 207 | + { | |
| 208 | + setVisible(false); | |
| 209 | + } | |
| 210 | + | |
| 211 | + public void show() | |
| 212 | + { | |
| 213 | + setVisible(true); | |
| 214 | + } | |
| 215 | + | |
| 216 | + public void setVisible(boolean b) | |
| 217 | + { | |
| 218 | + if (b) | |
| 219 | + pShow(this); | |
| 220 | + else | |
| 221 | + pHide(); | |
| 222 | + } | |
| 223 | + | |
| 224 | + public Dimension getMinimumSize() { | |
| 225 | + return target.getSize(); | |
| 226 | + } | |
| 227 | + | |
| 228 | + public Dimension getPreferredSize() { | |
| 229 | + return getMinimumSize(); | |
| 230 | + } | |
| 231 | + | |
| 232 | + public Dimension minimumSize() { | |
| 233 | + return getMinimumSize(); | |
| 234 | + } | |
| 235 | + | |
| 236 | + public Dimension preferredSize() { | |
| 237 | + return getPreferredSize(); | |
| 238 | + } | |
| 239 | + | |
| 240 | + | |
| 241 | + public int checkImage(Image img, int w, int h, ImageObserver o) { | |
| 242 | + return 0; | |
| 243 | + } | |
| 244 | + | |
| 245 | + public FontMetrics getFontMetrics(Font font) { | |
| 246 | + return iFontMetrics.getFontMetrics(font); | |
| 247 | + } | |
| 248 | + | |
| 249 | + public boolean prepareImage(Image img, int w, int h, ImageObserver o) { | |
| 250 | + return false; | |
| 251 | + } | |
| 252 | + | |
| 253 | + | |
| 254 | + public Image createImage(ImageProducer producer) { | |
| 255 | + return null/*new Win32Image(producer)*/; | |
| 256 | + } | |
| 257 | + public Image createImage(int width, int height) { | |
| 258 | + return null/*new Win32Image(target, width, height)*/; | |
| 259 | + } | |
| 260 | + | |
| 261 | + public boolean isFocusTraversable() { | |
| 262 | + return false; | |
| 263 | + } | |
| 264 | + | |
| 265 | + public void requestFocus() | |
| 266 | + { | |
| 267 | + } | |
| 268 | + | |
| 269 | + public void nextFocus() | |
| 270 | + { | |
| 271 | + } | |
| 272 | + | |
| 273 | + public void setFont(Font f) | |
| 274 | + { | |
| 275 | + | |
| 276 | + } | |
| 277 | + | |
| 278 | + public Font getFont() | |
| 279 | + { | |
| 280 | + return null; | |
| 281 | + } | |
| 282 | + | |
| 283 | + public void setBackground(Color c) | |
| 284 | + { | |
| 285 | + | |
| 286 | + } | |
| 287 | + | |
| 288 | + public void setForeground(Color c) | |
| 289 | + { | |
| 290 | + | |
| 291 | + } | |
| 292 | + | |
| 293 | + public Graphics getGraphics() | |
| 294 | + { | |
| 295 | + if (pCanvas==null) { | |
| 296 | + System.out.println("iFramePeer.getGraphics(): pCanvas == null!"); // jfs - remove | |
| 297 | + return null; | |
| 298 | + } | |
| 299 | + Rectangle bounds = target.getBounds(); | |
| 300 | + Rectangle clip = new Rectangle(bounds.x+leftInset, | |
| 301 | + bounds.y+topInset, | |
| 302 | + bounds.width-leftInset-rightInset, | |
| 303 | + bounds.height-topInset-bottomInset); | |
| 304 | + Graphics g=new iGraphics(getRefImage(),getRefOffScreenImage(), clip, target); | |
| 305 | + g.translate(bounds.x,bounds.y); // bounds have already been set - lg | |
| 306 | + return g; | |
| 307 | + } | |
| 308 | + | |
| 309 | + public java.awt.Toolkit getToolkit() { | |
| 310 | + return Toolkit.getDefaultToolkit(); | |
| 311 | + } | |
| 312 | + | |
| 313 | + public ColorModel getColorModel() { | |
| 314 | + return iToolkit.getStaticColorModel(); | |
| 315 | + } | |
| 316 | + | |
| 317 | + public void handleEvent(AWTEvent e) | |
| 318 | + { | |
| 319 | + | |
| 320 | + } | |
| 321 | + | |
| 322 | + public void print(Graphics g) | |
| 323 | + { | |
| 324 | + } | |
| 325 | + | |
| 326 | + public void paint(Graphics g) | |
| 327 | + { | |
| 328 | + g.setColor(target.getForeground()); | |
| 329 | + g.setFont(target.getFont()); | |
| 330 | + MenuBar mb=target.getMenuBar(); | |
| 331 | + if (mb!=null) | |
| 332 | + { | |
| 333 | + iMenuBarPeer ip=(iMenuBarPeer)mb.getPeer(); | |
| 334 | + | |
| 335 | + if (ip!=null) | |
| 336 | + { | |
| 337 | + ip.paint(g); | |
| 338 | + } | |
| 339 | + } | |
| 340 | + target.paint(g); | |
| 341 | + } | |
| 342 | + | |
| 343 | + | |
| 344 | + public void repaint(long tm, int x, int y, int width, int height) { | |
| 345 | + | |
| 346 | + iToolkit.postEvent(new PaintEvent((Component)target, PaintEvent.UPDATE, | |
| 347 | + new Rectangle(x, y, width, height))); | |
| 348 | + | |
| 349 | + } | |
| 350 | + | |
| 351 | + private void handleKeyEvents(int ch) | |
| 352 | + { | |
| 353 | + char keyChar = (char)ch; | |
| 354 | + boolean control = ch >= 0 && ch <= 31; | |
| 355 | + boolean lowercase = ch >= (int)'a' && ch <= (int)'z'; | |
| 356 | + boolean uppercase = ch >= (int)'A' && ch <= (int)'Z'; | |
| 357 | + int modifiers = control?InputEvent.CTRL_MASK: | |
| 358 | + uppercase?InputEvent.SHIFT_MASK:0; | |
| 359 | + int keyCode = control?ch+64:lowercase?ch-32:ch; | |
| 360 | + | |
| 361 | + // constructing a Date is slow, System.currentTimeMillis(), | |
| 362 | + // is faster, but it's implementation opens #c/time and | |
| 363 | + // converts a string to a big. Fastest still and probably | |
| 364 | + // with sufficient resolution would be natively time stamping | |
| 365 | + // events with sys->millisec(). -jfs | |
| 366 | + //// Date d = new Date(); | |
| 367 | + //// long when = d.getTime(); | |
| 368 | + long when = System.currentTimeMillis(); | |
| 369 | + | |
| 370 | + | |
| 371 | + iToolkit.postEvent(new KeyEvent(target,KeyEvent.KEY_PRESSED, | |
| 372 | + when,modifiers,keyCode,keyChar)); | |
| 373 | + | |
| 374 | + // synthesize events that we don't get from /dev/keyboard via | |
| 375 | + // Inferno's Tk (this is some fast typist!) | |
| 376 | + /* | |
| 377 | + iToolkit.postEvent(new KeyEvent(target,KeyEvent.KEY_TYPED, | |
| 378 | + when+1,modifiers,keyCode,keyChar)); | |
| 379 | + iToolkit.postEvent(new KeyEvent(target,KeyEvent.KEY_RELEASED, | |
| 380 | + when+2,modifiers,keyCode,keyChar)); | |
| 381 | + */ | |
| 382 | + } | |
| 383 | + | |
| 384 | + private void handleMouseEvents(int m,int button,int x,int y) | |
| 385 | + { | |
| 386 | + char mode=(char)m; | |
| 387 | + // System.out.println("Mouse event "+mode+" "+button+" "+x+" "+y); | |
| 388 | + switch(mode) | |
| 389 | + { | |
| 390 | +case 'd': | |
| 391 | +case 'r': | |
| 392 | +case 'm': | |
| 393 | +case 'p': | |
| 394 | + Rectangle bounds = target.getBounds(); | |
| 395 | + int xx=x-bounds.x-leftInset; | |
| 396 | + int yy=y-bounds.y; // -topInset; | |
| 397 | + | |
| 398 | + Point mousePoint=new Point(xx,yy); | |
| 399 | + long when = System.currentTimeMillis(); | |
| 400 | + int modifier; | |
| 401 | + | |
| 402 | + switch(button) | |
| 403 | + { | |
| 404 | +case 1: | |
| 405 | + modifier=InputEvent.BUTTON1_MASK; | |
| 406 | + break; | |
| 407 | + | |
| 408 | +case 2: | |
| 409 | + modifier=InputEvent.BUTTON2_MASK; | |
| 410 | + break; | |
| 411 | + | |
| 412 | +case 3: | |
| 413 | + modifier=InputEvent.BUTTON3_MASK; | |
| 414 | + break; | |
| 415 | + | |
| 416 | +default: | |
| 417 | + modifier=0; | |
| 418 | + } | |
| 419 | + | |
| 420 | + switch(mode) | |
| 421 | + { | |
| 422 | +case 'p': // Pressed | |
| 423 | +case 'd': // Double click | |
| 424 | + { | |
| 425 | + if (button>0 && button<=3 && buttonState[button-1]==false) | |
| 426 | + { | |
| 427 | + oldMousePoint=mousePoint; | |
| 428 | + buttonState[button-1]=true; | |
| 429 | + iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_PRESSED, | |
| 430 | + when,modifier,xx,yy,1,false)); | |
| 431 | + | |
| 432 | + } | |
| 433 | + break; | |
| 434 | + } | |
| 435 | +case 'r': // Released | |
| 436 | + { | |
| 437 | + if (button>0 && button<=3 && buttonState[button-1]==true) | |
| 438 | + { | |
| 439 | + buttonState[button-1]=false; | |
| 440 | + iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_RELEASED, | |
| 441 | + when,modifier,xx,yy,1,false)); | |
| 442 | + if (mousePoint.equals(oldMousePoint)) | |
| 443 | + { | |
| 444 | + iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_CLICKED, | |
| 445 | + when,modifier,xx,yy,1,button==2)); | |
| 446 | + } | |
| 447 | + } | |
| 448 | + break; | |
| 449 | + } | |
| 450 | +case 'm': // Moved | |
| 451 | + { | |
| 452 | + modifier=0; | |
| 453 | + if (buttonState[0]) modifier|=InputEvent.BUTTON1_MASK; | |
| 454 | + if (buttonState[1]) modifier|=InputEvent.BUTTON2_MASK; | |
| 455 | + if (buttonState[2]) modifier|=InputEvent.BUTTON3_MASK; | |
| 456 | + iToolkit.postEvent(new MouseEvent(target, | |
| 457 | + modifier==0?MouseEvent.MOUSE_MOVED:MouseEvent.MOUSE_DRAGGED, | |
| 458 | + when,modifier,xx,yy,1,false)); | |
| 459 | + | |
| 460 | + break; | |
| 461 | + } | |
| 462 | +default: | |
| 463 | + // System.out.println("focusEvent:" + mouseString); | |
| 464 | + } | |
| 465 | + break; | |
| 466 | + } | |
| 467 | + | |
| 468 | + // System.out.println("mouseString "+mouseString); | |
| 469 | + } | |
| 470 | + | |
| 471 | + private void moveSize(int x, int y, int width, int height) | |
| 472 | + { | |
| 473 | + Rectangle old = target.getBounds(); | |
| 474 | + Rectangle n = new Rectangle(x, y, width, height); | |
| 475 | + if (!n.equals(old)){ | |
| 476 | + target.setBounds(x, y, width, height); | |
| 477 | + target.validate(); | |
| 478 | + target.repaint(); | |
| 479 | + } | |
| 480 | + } | |
| 481 | + | |
| 482 | + private void paintTarget(int x, int y, int width, int height) | |
| 483 | + { | |
| 484 | + target.setBounds(x, y, width, height); | |
| 485 | + target.validate(); | |
| 486 | + target.repaint(); | |
| 487 | + } | |
| 488 | + | |
| 489 | + // | |
| 490 | + // Callbacks from native for Window Events | |
| 491 | + // | |
| 492 | + private void handleActivated() { | |
| 493 | + iToolkit.postEvent(new WindowEvent(target, | |
| 494 | + WindowEvent.WINDOW_ACTIVATED)); | |
| 495 | + iToolkit.postEvent(new FocusEvent(target, | |
| 496 | + FocusEvent.FOCUS_GAINED, false)); | |
| 497 | + } | |
| 498 | + private void handleDeactivated() { | |
| 499 | + iToolkit.postEvent(new WindowEvent(target, | |
| 500 | + WindowEvent.WINDOW_DEACTIVATED)); | |
| 501 | + iToolkit.postEvent(new FocusEvent(target, | |
| 502 | + FocusEvent.FOCUS_LOST, true)); | |
| 503 | + } | |
| 504 | + private void handleClosing() { | |
| 505 | + //System.out.println("iFramePeer.handleClosing():"); | |
| 506 | + // Java Frame can then call System.exit() to shutdown the VM | |
| 507 | + // if it so desires | |
| 508 | + iToolkit.postEvent(new WindowEvent(target, | |
| 509 | + WindowEvent.WINDOW_CLOSING)); | |
| 510 | + } | |
| 511 | + private void handleIconified() { | |
| 512 | + //System.out.println("iFramePeer.handleIconified():"); | |
| 513 | + iToolkit.postEvent(new WindowEvent(target, | |
| 514 | + WindowEvent.WINDOW_ICONIFIED)); | |
| 515 | + | |
| 516 | + } | |
| 517 | + private void handleDeIconified() { | |
| 518 | + // System.out.println("iFramePeer.handleDeiconified():"); | |
| 519 | + iToolkit.postEvent(new WindowEvent(target, | |
| 520 | + WindowEvent.WINDOW_DEICONIFIED)); | |
| 521 | + | |
| 522 | + // may need to make Cursors visible as well??? - jfs | |
| 523 | + // target.repaint(); | |
| 524 | + } | |
| 525 | +} | |
| 526 | + | |
| 527 | + | |
| @@ -0,0 +1,588 @@ | ||
| 1 | +implement iFramePeer_L; | |
| 2 | + | |
| 3 | +# javal v1.5 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | + | |
| 27 | + cast : Cast; | |
| 28 | + | |
| 29 | + sys : Sys; | |
| 30 | + | |
| 31 | + draw: Draw; | |
| 32 | + Context, Screen, Display, Rect, Font, Point, Image: import draw; | |
| 33 | + | |
| 34 | +include "tk.m"; | |
| 35 | + tk: Tk; | |
| 36 | + Toplevel: import tk; | |
| 37 | + | |
| 38 | +include "wmlib.m"; | |
| 39 | + wmlib: Wmlib; | |
| 40 | + | |
| 41 | +include "awt_Color.m"; | |
| 42 | + awt : AwtColor; | |
| 43 | + | |
| 44 | +#<< | |
| 45 | + | |
| 46 | +include "iFramePeer_L.m"; | |
| 47 | + | |
| 48 | +#>> extra post includes here | |
| 49 | + str : String; | |
| 50 | + Value : import jni; | |
| 51 | + ctxt : ref Draw->Context; | |
| 52 | + title : string; | |
| 53 | + | |
| 54 | + # channel for receiving Tk events and "reallyExit" from dispose(). | |
| 55 | + cmdchan: chan of string; | |
| 56 | + | |
| 57 | + # | |
| 58 | + # the following was included from awt_Frame.b and sees varying | |
| 59 | + # degrees of use. | |
| 60 | + # | |
| 61 | + | |
| 62 | + screen: ref Screen; | |
| 63 | + display: ref Display; | |
| 64 | + ones: ref Image; | |
| 65 | + white: ref Image; | |
| 66 | + nochan: chan of string; | |
| 67 | + tHeight : int; | |
| 68 | + bWidth: int; | |
| 69 | + last_x, last_y : int; | |
| 70 | + | |
| 71 | + Event: adt | |
| 72 | + { | |
| 73 | + event: int; | |
| 74 | + detail: string; | |
| 75 | + | |
| 76 | + Button, Key, | |
| 77 | + Icon, DeIcon, | |
| 78 | + Resize, Shutdown | |
| 79 | + : con iota; | |
| 80 | + }; | |
| 81 | + | |
| 82 | + Attr: adt | |
| 83 | + { | |
| 84 | + origin: Draw->Point; | |
| 85 | + dims: Draw->Point; | |
| 86 | + }; | |
| 87 | + | |
| 88 | + Canvas: adt | |
| 89 | + { | |
| 90 | + # interface | |
| 91 | + image: ref Draw->Image; | |
| 92 | + buf: ref Draw->Image; | |
| 93 | + rect: Draw->Rect; | |
| 94 | + events: chan of ref Event; | |
| 95 | + attr: ref Attr; | |
| 96 | + # implementation | |
| 97 | + ctxt : ref Draw->Context; | |
| 98 | + top: ref Tk->Toplevel; | |
| 99 | + canvas: string; | |
| 100 | + pid: int; | |
| 101 | + }; | |
| 102 | + # end of historical inclusions from awt_Frame.b | |
| 103 | +#<< | |
| 104 | +init( jni_p : JNI ) | |
| 105 | +{ | |
| 106 | + # save java native inteface mod instance | |
| 107 | + jni = jni_p; | |
| 108 | + #>>extra initialization here | |
| 109 | + | |
| 110 | + sys = jni->sys; | |
| 111 | + | |
| 112 | + str = load String String->PATH; | |
| 113 | + awt = load AwtColor AwtColor->PATH; | |
| 114 | + cast = jni->CastMod(); | |
| 115 | + | |
| 116 | + # draw and tk are module refs that JNI may someday provide, saving a | |
| 117 | + # Limbo load operation for every FramePeer construction | |
| 118 | + draw = load Draw Draw->PATH; | |
| 119 | + tk = load Tk Tk->PATH; | |
| 120 | + wmlib = load Wmlib Wmlib->PATH; | |
| 121 | + | |
| 122 | + ctxt = jni->getContext(); | |
| 123 | + title = "Untitled"; | |
| 124 | + | |
| 125 | + nochan = chan of string; | |
| 126 | + screen = ctxt.screen; | |
| 127 | + last_x = last_y = -10; | |
| 128 | + wmlib->init(); | |
| 129 | + #<< | |
| 130 | +} | |
| 131 | + | |
| 132 | +getRefImage_rObject( this : ref iFramePeer_obj) : ref Draw->Image | |
| 133 | +{#>> | |
| 134 | + return this.pCanvas.image; | |
| 135 | +}#<< | |
| 136 | + | |
| 137 | +getRefOffScreenImage_rObject(this :ref iFramePeer_obj) : ref Draw->Image | |
| 138 | +{#>> | |
| 139 | + return this.pCanvas.buf; | |
| 140 | +}#<< | |
| 141 | + | |
| 142 | +pReshape_I_I_I_I_V( this : ref iFramePeer_obj, p0 : int,p1 : int,p2 : int,p3 : int) | |
| 143 | +{#>> | |
| 144 | + strcmd := ". configure -x " + string p0 + " -y " + string p1 + | |
| 145 | + " -width " + string p2 + " -height " + string p3; | |
| 146 | + | |
| 147 | + tk->cmd(this.pCanvas.top, strcmd); | |
| 148 | + tk->cmd(this.pCanvas.top, "update"); | |
| 149 | +}#<< | |
| 150 | + | |
| 151 | +pHide_V( this : ref iFramePeer_obj) | |
| 152 | +{#>> | |
| 153 | + # Explicit filtering of input (mouse and keyboard) events shouldn't | |
| 154 | + # be needed if Tk is doing it's job wrt "map" and "unmap". | |
| 155 | + tk->cmd(this.pCanvas.top, ". unmap"); | |
| 156 | + this.pCanvas.image = nil; | |
| 157 | +}#<< | |
| 158 | + | |
| 159 | +pShow_riFramePeer_V( this : ref iFramePeer_obj, p0 : JObject) | |
| 160 | +{#>> | |
| 161 | + # Window.show() has already produced a WINDOW_OPENED event | |
| 162 | + # Tk\'s " . map" will result in a WINDOW_ACTIVATE event when it | |
| 163 | + # directs focus to the newly mapped frame. | |
| 164 | + | |
| 165 | + tk->cmd(this.pCanvas.top, ". map"); | |
| 166 | +# spawn doEvent(this, p0); | |
| 167 | +}#<< | |
| 168 | + | |
| 169 | +getXYLoc_I_I( this : ref iFramePeer_obj,p0 : int) : int | |
| 170 | +{#>> | |
| 171 | + if (p0 == 0) | |
| 172 | + return this.pCanvas.rect.min.x; | |
| 173 | + else | |
| 174 | + return this.pCanvas.rect.min.y; | |
| 175 | +}#<< | |
| 176 | + | |
| 177 | +create_riFramePeer_V( this : ref iFramePeer_obj, p0 : JObject) | |
| 178 | +{#>> | |
| 179 | + # make's for easy punning around the Limbo type system. | |
| 180 | + # two refs to same object: "this" and "thisAsJObject". | |
| 181 | + this.thisAsJObject = p0; | |
| 182 | + | |
| 183 | + t := jni->GetObjField(this.target, "title", "Ljava/lang/String;"); | |
| 184 | + | |
| 185 | + if (t == nil) | |
| 186 | + sys->print("Cannot get title\n"); | |
| 187 | + else{ | |
| 188 | + sobj := t.Object(); | |
| 189 | + c := jni->CastMod(); | |
| 190 | + js := cast->ToJString(sobj); | |
| 191 | + title = js.str; | |
| 192 | + } | |
| 193 | + | |
| 194 | + xval := jni->GetObjField(this.target, "x", "I"); | |
| 195 | + yval := jni->GetObjField(this.target, "y", "I"); | |
| 196 | + wval := jni->GetObjField(this.target, "width", "I"); | |
| 197 | + hval := jni->GetObjField(this.target, "height", "I"); | |
| 198 | + | |
| 199 | + | |
| 200 | + x := xval.Int(); | |
| 201 | + y := yval.Int(); | |
| 202 | + w := wval.Int(); | |
| 203 | + h := hval.Int(); | |
| 204 | + | |
| 205 | + makewin(ctxt, title, x, y, w, h, this, p0); | |
| 206 | + | |
| 207 | + this.topInset = tHeight + bWidth + bWidth; | |
| 208 | + this.leftInset = bWidth; | |
| 209 | + this.rightInset = bWidth; | |
| 210 | + this.bottomInset = bWidth; | |
| 211 | + this.left = this.pCanvas.rect.min.x; | |
| 212 | + this.top = this.pCanvas.rect.min.y; | |
| 213 | + | |
| 214 | + tk->cmd(this.pCanvas.top, ". unmap"); | |
| 215 | + this.pCanvas.image = nil; | |
| 216 | +}#<< | |
| 217 | + | |
| 218 | +pDispose_V( this : ref iFramePeer_obj) | |
| 219 | +{#>> | |
| 220 | + # sys->print("iFramePeer_L.pDispose_V(): entered on pid=%d\n", sys->pctl(0,nil)); | |
| 221 | + | |
| 222 | + # request evenhandler's suicide, and sync until done | |
| 223 | + cmdchan <- = "reallyExit"; | |
| 224 | + | |
| 225 | + this.pCanvas = nil; | |
| 226 | +}#<< | |
| 227 | + | |
| 228 | +setCursor_I_V( this : ref iFramePeer_obj, p0 : int) | |
| 229 | +{#>> | |
| 230 | +}#<< | |
| 231 | + | |
| 232 | + | |
| 233 | +setTitle_rString_V( this : ref iFramePeer_obj, p0 : JString) | |
| 234 | +{#>> | |
| 235 | + title = p0.str; | |
| 236 | + if (wmlib != nil && this.pCanvas != nil && this.pCanvas.top != nil && | |
| 237 | + title != nil) | |
| 238 | + { | |
| 239 | + | |
| 240 | + # sys->print("iFramePeer_L.b.setTitle(): %s\n", title); | |
| 241 | + | |
| 242 | + # A change of title string to an iconfied Frmae will only be seen | |
| 243 | + # after deiconification, as Inferno's wm provides no mechanism | |
| 244 | + # to change the value displayed on the "taskbar" once a window's | |
| 245 | + # been iconified, contrary to the commentary in appl/lib/wmlib.b | |
| 246 | + wmlib->taskbar(this.pCanvas.top, title); | |
| 247 | + } | |
| 248 | +}#<< | |
| 249 | + | |
| 250 | +toFront_V( this : ref iFramePeer_obj) | |
| 251 | +{#>> | |
| 252 | + this.pCanvas.image.top(); | |
| 253 | +}#<< | |
| 254 | + | |
| 255 | +toBack_V( this : ref iFramePeer_obj) | |
| 256 | +{#>> | |
| 257 | + this.pCanvas.image.bottom(); | |
| 258 | +}#<< | |
| 259 | + | |
| 260 | +#>> | |
| 261 | +doEvent(i : ref iFramePeer_obj, job : JObject) | |
| 262 | +{ | |
| 263 | +# cc := i.pCanvas; | |
| 264 | + for (;;) { | |
| 265 | + e := <- i.pCanvas.events; | |
| 266 | + case e.event { | |
| 267 | + Event.Shutdown => | |
| 268 | + exit; | |
| 269 | + * => | |
| 270 | + ; | |
| 271 | + } | |
| 272 | + } | |
| 273 | +} | |
| 274 | + | |
| 275 | +javapainttarget(j : JObject, r : Draw->Rect) | |
| 276 | +{ | |
| 277 | + args := array[4] of ref Value; | |
| 278 | + args[0] = ref Value.TInt(r.min.x); | |
| 279 | + args[1] = ref Value.TInt(r.min.y); | |
| 280 | + args[2] = ref Value.TInt(r.max.x - r.min.x + 1); | |
| 281 | + args[3] = ref Value.TInt(r.max.y - r.min.y + 1); | |
| 282 | + (val, err) := jni->CallMethod(j, "paintTarget", "(IIII)V", args); | |
| 283 | + if (err != jni->OK){ | |
| 284 | + sys->print( "CallMethod Error %d: paintTarget\n",err); | |
| 285 | + } | |
| 286 | +} | |
| 287 | + | |
| 288 | +javamvsz(j : JObject, r : Draw->Rect) | |
| 289 | +{ | |
| 290 | + args := array[4] of ref Value; | |
| 291 | + args[0] = ref Value.TInt(r.min.x); | |
| 292 | + args[1] = ref Value.TInt(r.min.y); | |
| 293 | + args[2] = ref Value.TInt(r.max.x - r.min.x + 1); | |
| 294 | + args[3] = ref Value.TInt(r.max.y - r.min.y + 1); | |
| 295 | + (val, err) := jni->CallMethod(j, "moveSize", "(IIII)V", args); | |
| 296 | + if (err != jni->OK){ | |
| 297 | + sys->print( "CallMethod Error %d: moveSize\n",err); | |
| 298 | + } | |
| 299 | +} | |
| 300 | +#<< | |
| 301 | + | |
| 302 | + | |
| 303 | +#>> | |
| 304 | +win_cfg := array[] of { | |
| 305 | + "canvas .c -height 6 -width 6", | |
| 306 | + "pack .c -side bottom -fill both -expand 1", | |
| 307 | + "pack propagate . 0", | |
| 308 | +}; | |
| 309 | + | |
| 310 | +win_bind := array[] of { | |
| 311 | + "bind . <Configure> {send cmd configure}", | |
| 312 | + "bind . <Map> {send cmd map}", | |
| 313 | + "bind . <FocusIn> +{send cmd focusIn}", | |
| 314 | + "bind . <FocusOut> +{send cmd focusOut}", | |
| 315 | + "bind # <Motion> {send butt m %b %X %Y}", | |
| 316 | + "bind # <Leave> {send butt Leave}", | |
| 317 | + "bind # <ButtonPress> {focus #;send butt p %b %X %Y}", | |
| 318 | + "bind # <ButtonRelease> {send butt r %b %X %Y}", | |
| 319 | + "bind # <Double-Button> {send butt d %b %X %Y}", | |
| 320 | + "bind # <Enter> {send butt Enter}", | |
| 321 | + "bind # <KeyPress> {send key %K}", | |
| 322 | + "bind .Wm_t <Button-1> +{send butt p %b %x %y}", | |
| 323 | + "bind .Wm_t.title <Button-1> +{send butt p %b %x %y}", | |
| 324 | + "bind .Wm_t <Button-1> +{focus #}", | |
| 325 | + "bind .Wm_t.title <Button-1> +{focus #}", | |
| 326 | + | |
| 327 | + # Optional button 2 input focus to frame. Deviates from | |
| 328 | + # current (crippled IMHO) wmlib practice. Benefit is keyboard | |
| 329 | + # focus without raising frame to top. - jfs | |
| 330 | + "bind .Wm_t <Button-2> +{focus #}", | |
| 331 | + "bind .Wm_t.title <Button-2> +{focus #}", | |
| 332 | +}; | |
| 333 | + | |
| 334 | +modinit(ctxt: ref Context) | |
| 335 | +{ | |
| 336 | + draw = load Draw Draw->PATH; | |
| 337 | + tk = load Tk Tk->PATH; | |
| 338 | + wmlib = load Wmlib Wmlib->PATH; | |
| 339 | + | |
| 340 | + nochan = chan of string; | |
| 341 | + | |
| 342 | + screen = ctxt.screen; | |
| 343 | + last_x = last_y = -10; | |
| 344 | + | |
| 345 | + wmlib->init(); | |
| 346 | +} | |
| 347 | + | |
| 348 | +makewin(ctxt: ref Context, title: string, x, y, width, height: int, this: ref iFramePeer_obj, job: JObject) | |
| 349 | +{ | |
| 350 | +# modinit(ctxt); | |
| 351 | + t : ref Toplevel; | |
| 352 | + menu : chan of string; | |
| 353 | + where := "-x " + string x + " -y " + string y; | |
| 354 | + if (this.resizable == 1) | |
| 355 | + (t, menu) = wmlib->titlebar(screen, where, title, Wmlib->Appl); | |
| 356 | + else | |
| 357 | + (t, menu) = wmlib->titlebar(screen, where, title, Wmlib->Hide); | |
| 358 | + | |
| 359 | +# calculate topInset and boardwidth | |
| 360 | + bWidth = int tk->cmd(t, ". cget -bd"); | |
| 361 | + tHeight = int tk->cmd(t, ". cget -height"); | |
| 362 | + | |
| 363 | + if (width > 0 && height > 0) | |
| 364 | + win_cfg[0] = "canvas .c -height " + string (height - tHeight -bWidth -bWidth) + " -width " + string (width); | |
| 365 | +# win_cfg[0] = "canvas .c -height " + string (height - tHeight) + " -width " + string width; | |
| 366 | + | |
| 367 | + wmlib->tkcmds(t, win_cfg); | |
| 368 | + | |
| 369 | + ones = t.image.display.ones; | |
| 370 | + white = t.image.display.color(Draw->White); | |
| 371 | + alloccanvas(t, ctxt, ".c", menu, this, job); | |
| 372 | +} | |
| 373 | + | |
| 374 | +alloccanvas(t: ref Toplevel, ctxt: ref Draw->Context, canvas: string, menu: chan of string, this :ref iFramePeer_obj, job: JObject) | |
| 375 | +{ | |
| 376 | + cmdchan = chan of string; | |
| 377 | + tk->namechan(t, cmdchan, "cmd"); | |
| 378 | + butt := chan of string; | |
| 379 | + tk->namechan(t, butt, "butt"); | |
| 380 | + | |
| 381 | + key := chan of string; | |
| 382 | + tk->namechan(t, key, "key"); | |
| 383 | + | |
| 384 | +# tk->cmd(t, "bind . <Configure> {send cmd resize}"); | |
| 385 | +# tk->cmd(t, "bind . <Map> {send cmd map}"); | |
| 386 | + | |
| 387 | + for (i := 0; i < len win_bind; i++) | |
| 388 | + tk->cmd(t, expand(win_bind[i], canvas)); | |
| 389 | + | |
| 390 | + tk->cmd(t, "update"); | |
| 391 | + | |
| 392 | + c := ref Canvas; | |
| 393 | + this.pCanvas = c; | |
| 394 | + c = nil; | |
| 395 | + | |
| 396 | + bg := Draw->White; | |
| 397 | + jcol := jni->GetObjField(this.target, "background", "Ljava/awt/Color;"); | |
| 398 | + if (jcol == nil) { | |
| 399 | + sys->print("iFramePeer_L: Cannot get background color\n"); | |
| 400 | + } else { | |
| 401 | + color := jcol.Object(); | |
| 402 | + bg = awt->getColorIndex(jni, color); | |
| 403 | + } | |
| 404 | + | |
| 405 | + this.pCanvas.image = t.image; | |
| 406 | + display = t.image.display; | |
| 407 | + this.pCanvas.rect = canvposn(t, canvas); | |
| 408 | + this.pCanvas.buf = ctxt.display.newimage(ctxt.display.image.r, | |
| 409 | + this.pCanvas.image.ldepth , 0, bg); | |
| 410 | + this.pCanvas.events = nil; # not currently used | |
| 411 | + this.pCanvas.top = t; | |
| 412 | + this.pCanvas.ctxt = ctxt; | |
| 413 | + this.pCanvas.canvas = canvas; | |
| 414 | + this.pCanvas.pid = sys->pctl(0, nil); | |
| 415 | + | |
| 416 | + spawn handler(menu, cmdchan, butt, key, this, job); | |
| 417 | +} | |
| 418 | + | |
| 419 | +handler(menu, cmd, butt, key : chan of string, this : ref iFramePeer_obj, job: JObject) | |
| 420 | +{ | |
| 421 | + detail: string; | |
| 422 | + iconified := 0; | |
| 423 | + toplvl := this.pCanvas.top; | |
| 424 | + | |
| 425 | + if (menu == nil) | |
| 426 | + menu = nochan; | |
| 427 | + for (;;) alt { | |
| 428 | + detail = <- menu => | |
| 429 | + case detail { | |
| 430 | + "exit" => | |
| 431 | +# this.pCanvas.events <- = ref Event(Event.Shutdown, nil); | |
| 432 | + # 'X' button in titlebar is passed to Java code | |
| 433 | + # as a WINDOW_CLOSING event. | |
| 434 | + doFclosing(this.thisAsJObject); | |
| 435 | + | |
| 436 | + "task" => | |
| 437 | + iconified = 1; | |
| 438 | + this.pCanvas.image = nil; | |
| 439 | + doFiconified(job); | |
| 440 | + | |
| 441 | + # synthesize a WINDOW_DEACTIVATED event, the TK "FocusOut" | |
| 442 | + # event doesn't arrive until after this window has been | |
| 443 | + # selected and deiconified from the toolbar. | |
| 444 | + doFdeactivated(this.thisAsJObject); | |
| 445 | + wmlib->titlectl(toplvl, detail); # shrink it | |
| 446 | + | |
| 447 | + * => # default wmlib actions for move, size, ok, help | |
| 448 | + wmlib->titlectl(toplvl, detail); | |
| 449 | + } | |
| 450 | +# wmlib->titlectl(this.pCanvas.top, detail); | |
| 451 | + | |
| 452 | + detail = <- cmd => | |
| 453 | + (n, word) := sys->tokenize(detail, " "); | |
| 454 | + case hd word { | |
| 455 | + "configure" or "map" => | |
| 456 | + this.pCanvas.image = this.pCanvas.top.image; | |
| 457 | + this.pCanvas.rect = canvposn(toplvl, this.pCanvas.canvas); | |
| 458 | +# e := Event.Resize; | |
| 459 | + if (hd word == "map") { | |
| 460 | + # if being mapped after an iconfication | |
| 461 | + if (iconified) { | |
| 462 | + iconified = 0; | |
| 463 | + doFdeIconified(this.thisAsJObject); | |
| 464 | + } | |
| 465 | +# sys->print("mapped\n"); | |
| 466 | + tk->cmd(toplvl, "focus " + this.pCanvas.canvas); | |
| 467 | +# deIconify(job); | |
| 468 | + r := this.pCanvas.rect; | |
| 469 | + javapainttarget(job, r); | |
| 470 | + } | |
| 471 | + else{ | |
| 472 | + r := this.pCanvas.rect; | |
| 473 | + javamvsz(job, r); | |
| 474 | + } | |
| 475 | + | |
| 476 | + # receiving or losing window's keyboard focus should | |
| 477 | + # generate frame activation events upto Javaland | |
| 478 | + "focusIn" => | |
| 479 | + doFactivated(this.thisAsJObject); | |
| 480 | + "focusOut" => | |
| 481 | + # ignore loss-of-Tk-focus events that result from | |
| 482 | + # iconification. | |
| 483 | + if (! iconified) { | |
| 484 | + doFdeactivated(this.thisAsJObject); | |
| 485 | + } | |
| 486 | + # sent by dispose() to terminate this event handling thread | |
| 487 | + "reallyExit" => | |
| 488 | + sys->print("iFrame_Peer_L.handler(): suicide\n"); | |
| 489 | + exit; | |
| 490 | + * => | |
| 491 | + sys->print("iFrame_Peer_L.handler(): unknown event - %s\n", | |
| 492 | + detail); | |
| 493 | + } | |
| 494 | + | |
| 495 | + detail = <- butt => | |
| 496 | + doMouseEvent(job, detail); | |
| 497 | + detail = <- key => | |
| 498 | + doKeyEvent(job, detail); | |
| 499 | + } | |
| 500 | +} | |
| 501 | + | |
| 502 | +expand(cmd, canvas: string): string | |
| 503 | +{ | |
| 504 | + s: string; | |
| 505 | + for (;;) { | |
| 506 | + (l, r) := str->splitl(cmd, "#"); | |
| 507 | + s = s + l; | |
| 508 | + if (r == nil) | |
| 509 | + return s; | |
| 510 | + s = s + canvas; | |
| 511 | + cmd = r[1:]; | |
| 512 | + } | |
| 513 | +} | |
| 514 | + | |
| 515 | +canvposn(t: ref Toplevel, c: string): Rect | |
| 516 | +{ | |
| 517 | + r: Rect; | |
| 518 | + | |
| 519 | + r.min.x = int tk->cmd(t, ". cget -actx"); | |
| 520 | + r.min.y = int tk->cmd(t, ". cget -acty"); | |
| 521 | + r.max.x = r.min.x - 1 + int tk->cmd(t, ". cget -actwidth"); | |
| 522 | + r.max.y = r.min.y - 1 + int tk->cmd(t, ". cget -actheight"); | |
| 523 | + return r; | |
| 524 | +} | |
| 525 | + | |
| 526 | +doFactivated(job : JObject) { | |
| 527 | + (val, err) := jni->CallMethod(job, "handleActivated", "()V", nil); | |
| 528 | + if (err != jni->OK) | |
| 529 | + sys->print( "CallMethod Error %d: handleActivated\n",err); | |
| 530 | + | |
| 531 | +} | |
| 532 | + | |
| 533 | +doFdeactivated(job : JObject) { | |
| 534 | + (val, err) := jni->CallMethod(job, "handleDeactivated", "()V", nil); | |
| 535 | + if (err != jni->OK) | |
| 536 | + sys->print( "CallMethod Error %d: handleDeactivated\n",err); | |
| 537 | + | |
| 538 | +} | |
| 539 | + | |
| 540 | +doFclosing(job : JObject) { | |
| 541 | + (val, err) := jni->CallMethod(job, "handleClosing", "()V", nil); | |
| 542 | + if (err != jni->OK) | |
| 543 | + sys->print( "CallMethod Error %d: handleClosingt\n",err); | |
| 544 | + | |
| 545 | +} | |
| 546 | + | |
| 547 | +doFiconified(job : JObject) { | |
| 548 | + (val, err) := jni->CallMethod(job, "handleIconified", "()V", nil); | |
| 549 | + if (err != jni->OK) | |
| 550 | + sys->print( "CallMethod Error %d: handleIconified\n",err); | |
| 551 | +} | |
| 552 | + | |
| 553 | +doFdeIconified(job : JObject) { | |
| 554 | + (val, err) := jni->CallMethod(job, "handleDeIconified", "()V", nil); | |
| 555 | + if (err != jni->OK) | |
| 556 | + sys->print( "CallMethod Error %d: handleDeIconified\n",err); | |
| 557 | +} | |
| 558 | +doKeyEvent(job : JObject, detail : string) { | |
| 559 | + (kchar, st) := str->toint(detail, 16); | |
| 560 | + args := array[1] of ref Value; | |
| 561 | + args[0] = ref Value.TInt(kchar); | |
| 562 | + (val, err) := jni->CallMethod(job, "handleKeyEvents", "(I)V", args); | |
| 563 | + if (err != jni->OK){ | |
| 564 | + sys->print( "CallMethod Error %d: handleKeyEvents\n",err); | |
| 565 | + } | |
| 566 | +} | |
| 567 | + | |
| 568 | +doMouseEvent(job : JObject, detail : string) { | |
| 569 | + (n,toks) := sys->tokenize(detail," "); | |
| 570 | + if (n != 4) return; | |
| 571 | + mode := array of byte hd toks; | |
| 572 | + toks = tl toks; | |
| 573 | + button:=int hd toks; | |
| 574 | + toks = tl toks; | |
| 575 | + x:=int hd toks; | |
| 576 | + toks = tl toks; | |
| 577 | + y:=int hd toks; | |
| 578 | + args := array[4] of ref Value; | |
| 579 | + args[0] = ref Value.TInt(int mode[0]); | |
| 580 | + args[1] = ref Value.TInt(button); | |
| 581 | + args[2] = ref Value.TInt(x); | |
| 582 | + args[3] = ref Value.TInt(y); | |
| 583 | + (val, err) := jni->CallMethod(job, "handleMouseEvents", "(IIII)V", args); | |
| 584 | + if (err != jni->OK){ | |
| 585 | + sys->print( "CallMethod Error %d: handleMouseEvents\n",err); | |
| 586 | + } | |
| 587 | +} | |
| 588 | +#<< | |
| @@ -0,0 +1,36 @@ | ||
| 1 | +# javal v1.5 generated file: edit with care | |
| 2 | + | |
| 3 | +iFramePeer_L : module | |
| 4 | +{ | |
| 5 | + iFramePeer_obj : adt | |
| 6 | + { | |
| 7 | + cl_mod : ClassModule; | |
| 8 | + pCanvas : ref Canvas; #JObject; | |
| 9 | + thisAsJObject : JObject; | |
| 10 | + target : JObject; | |
| 11 | + leftInset : int; | |
| 12 | + rightInset : int; | |
| 13 | + topInset : int; | |
| 14 | + bottomInset : int; | |
| 15 | + left : int; | |
| 16 | + top : int; | |
| 17 | + buttonState : JArrayZ; | |
| 18 | + oldMousePoint : JObject; | |
| 19 | + resizable : int; | |
| 20 | + }; | |
| 21 | + | |
| 22 | + init : fn( jni_p : JNI ); | |
| 23 | + getRefImage_rObject : fn( this : ref iFramePeer_obj) : ref Draw->Image; | |
| 24 | + getRefOffScreenImage_rObject : fn(this :ref iFramePeer_obj) : ref Draw->Image; | |
| 25 | + pReshape_I_I_I_I_V : fn( this : ref iFramePeer_obj, p0 : int,p1 : int,p2 : int,p3 : int); | |
| 26 | + pHide_V : fn( this : ref iFramePeer_obj); | |
| 27 | + pShow_riFramePeer_V : fn( this : ref iFramePeer_obj, p0 : JObject); | |
| 28 | + getXYLoc_I_I : fn( this : ref iFramePeer_obj, p0 : int) : int; | |
| 29 | + create_riFramePeer_V : fn( this : ref iFramePeer_obj, p0 : JObject); | |
| 30 | + pDispose_V : fn( this : ref iFramePeer_obj); | |
| 31 | + setCursor_I_V : fn( this : ref iFramePeer_obj, p0 : int); | |
| 32 | + setTitle_rString_V : fn( this : ref iFramePeer_obj, p0 : JString); | |
| 33 | + toFront_V : fn( this : ref iFramePeer_obj); | |
| 34 | + toBack_V : fn( this : ref iFramePeer_obj); | |
| 35 | + | |
| 36 | +}; | |
| @@ -0,0 +1,606 @@ | ||
| 1 | +package inferno.awt; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.awt.peer.*; | |
| 5 | +import java.io.*; | |
| 6 | +import java.util.*; | |
| 7 | +import java.awt.image.ImageObserver; | |
| 8 | +import inferno.awt.iFontPeer; | |
| 9 | + | |
| 10 | +//import sun.awt.image.OffScreenImageSource; | |
| 11 | +//import sun.awt.image.ImageRepresentation; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * iGraphics is an object that encapsulates a graphics context for a | |
| 15 | + * particular canvas. | |
| 16 | + * | |
| 17 | + * @version 1.18 18 Mar 1996 | |
| 18 | + */ | |
| 19 | + | |
| 20 | +public class iGraphics extends Graphics { | |
| 21 | + // Object pcanvas; | |
| 22 | + Object refImage; | |
| 23 | + Object refOffScreenImage; | |
| 24 | + Component target; | |
| 25 | + Color foreground; | |
| 26 | + Font font; | |
| 27 | + private iFontPeer ifontpeer; | |
| 28 | + int originX; | |
| 29 | + int originY; | |
| 30 | + Rectangle clipRect; | |
| 31 | + Rectangle initialClipRect; | |
| 32 | + boolean dirty; | |
| 33 | + | |
| 34 | + //private native void imageCreate(ImageRepresentation ir); | |
| 35 | + private native void pSetForeground(int r, int g, int b); | |
| 36 | + | |
| 37 | + private Image image; | |
| 38 | + | |
| 39 | + private Object awt; // Pointer to awt object | |
| 40 | + | |
| 41 | + private native void createGraphics(); | |
| 42 | + | |
| 43 | + public iGraphics(Object refImage, Object refOffScreenImage, Rectangle initialClipRect, Component target) | |
| 44 | + { | |
| 45 | + this.refImage = refImage; | |
| 46 | + this.refOffScreenImage = refOffScreenImage; | |
| 47 | + this.initialClipRect = new Rectangle(initialClipRect); | |
| 48 | + this.clipRect = new Rectangle(initialClipRect); | |
| 49 | + this.target = target; | |
| 50 | + this.font = target.getFont(); | |
| 51 | + if (font != null) { | |
| 52 | + this.ifontpeer = (iFontPeer)font.getPeer(); | |
| 53 | + } | |
| 54 | + dirty = false; | |
| 55 | + createGraphics(); | |
| 56 | + } | |
| 57 | + | |
| 58 | +// a dummy constructor for testing | |
| 59 | + public iGraphics(Object im) { | |
| 60 | + } | |
| 61 | + | |
| 62 | + | |
| 63 | + public iGraphics(Image image) { | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * Create a new iGraphics Object based on this one. | |
| 68 | + */ | |
| 69 | + public Graphics create() { | |
| 70 | + iGraphics g = new iGraphics(refImage, refOffScreenImage, initialClipRect, target); | |
| 71 | + g.foreground = foreground; | |
| 72 | + g.font = font; | |
| 73 | + g.ifontpeer = ifontpeer; | |
| 74 | + g.originX = originX; | |
| 75 | + g.originY = originY; | |
| 76 | + g.image = image; | |
| 77 | + //g.clipRect = clipRect; | |
| 78 | + //g.initialClipRect = initialClipRect; | |
| 79 | + return g; | |
| 80 | + } | |
| 81 | + | |
| 82 | + private void checkDirty() | |
| 83 | + { | |
| 84 | + if (dirty) | |
| 85 | + { | |
| 86 | + dirty = false; | |
| 87 | + copyOffscreenImage(clipRect.x,clipRect.y,clipRect.width,clipRect.height); | |
| 88 | + } | |
| 89 | + | |
| 90 | + } | |
| 91 | + | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * Translate | |
| 95 | + */ | |
| 96 | + public void translate(int x, int y) { | |
| 97 | + originX += x; | |
| 98 | + originY += y; | |
| 99 | + clipRect.translate(-x,-y); | |
| 100 | + initialClipRect.translate(-x,-y); | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * Disposes of this iGraphics context. It cannot be used after being | |
| 105 | + * disposed. | |
| 106 | + */ | |
| 107 | + private native void pDispose(); | |
| 108 | + | |
| 109 | + public void dispose() | |
| 110 | + { | |
| 111 | + checkDirty(); | |
| 112 | + pDispose(); | |
| 113 | + } | |
| 114 | + | |
| 115 | + public void setFont(Font font) { | |
| 116 | + if ((font != null) && (this.font != font)) { | |
| 117 | + synchronized (this.font) { | |
| 118 | + this.font = font; | |
| 119 | + ifontpeer = (iFontPeer)font.getPeer(); | |
| 120 | + } | |
| 121 | + } | |
| 122 | + } | |
| 123 | + public Font getFont() { | |
| 124 | + return this.font; | |
| 125 | + } | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * Gets font metrics for the given font. | |
| 129 | + */ | |
| 130 | + public FontMetrics getFontMetrics(Font font) { | |
| 131 | + return iFontMetrics.getFontMetrics(font); | |
| 132 | + } | |
| 133 | + | |
| 134 | + | |
| 135 | + private void ourSetForeground() | |
| 136 | + { | |
| 137 | + pSetForeground(foreground.getRed(), foreground.getGreen(), foreground.getBlue()); | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * Sets the foreground color. | |
| 142 | + */ | |
| 143 | + public void setColor(Color c) { | |
| 144 | + if ((c != null) && (c != foreground)) { | |
| 145 | + foreground = c; | |
| 146 | + pSetForeground(c.getRed(), c.getGreen(), c.getBlue()); | |
| 147 | + } | |
| 148 | + } | |
| 149 | + public Color getColor() { | |
| 150 | + return foreground; | |
| 151 | + } | |
| 152 | + | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Sets the paint mode to overwrite the destination with the | |
| 156 | + * current color. This is the default paint mode. | |
| 157 | + */ | |
| 158 | + public native void setPaintMode(); | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Sets the paint mode to alternate between the current color | |
| 162 | + * and the given color. | |
| 163 | + */ | |
| 164 | + public native void setXORMode(Color c1); | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * Gets the current clipping area | |
| 168 | + */ | |
| 169 | + public Rectangle getClipBounds() | |
| 170 | + { | |
| 171 | + return new Rectangle(clipRect); | |
| 172 | + } | |
| 173 | + | |
| 174 | + private native void changeClip(int X, int Y, int W, int H, boolean set); | |
| 175 | + | |
| 176 | + private void removeClip() | |
| 177 | + { | |
| 178 | + checkDirty(); | |
| 179 | + clipRect = new Rectangle(initialClipRect); | |
| 180 | + } | |
| 181 | + | |
| 182 | + private void ourSetClip() | |
| 183 | + { | |
| 184 | + dirty = true; | |
| 185 | + changeClip(clipRect.x,clipRect.y,clipRect.width,clipRect.height,true); | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** Crops the clipping rectangle for this iGraphics context. */ | |
| 189 | + public void clipRect(int X, int Y, int W, int H) { | |
| 190 | + checkDirty(); | |
| 191 | + clipRect = clipRect.intersection(new Rectangle(X,Y,W,H)); // test lg | |
| 192 | + // System.out.println("java == intersection: "+ clipRect); | |
| 193 | + //changeClip(X, Y, W, H, false); | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** Sets the clipping rectangle for this iGraphics context. */ | |
| 197 | + public void setClip(int X, int Y, int W, int H) { | |
| 198 | + checkDirty(); | |
| 199 | + clipRect = new Rectangle(X,Y,W,H); | |
| 200 | + //changeClip(X, Y, W, H, true); | |
| 201 | + } | |
| 202 | + | |
| 203 | + /** Returns a Shape object representing the clip. */ | |
| 204 | + public Shape getClip() { | |
| 205 | + return getClipBounds(); | |
| 206 | + } | |
| 207 | + | |
| 208 | + /** Sets the clip to a Shape (only Rectangle allowed). */ | |
| 209 | + public void setClip(Shape clip) { | |
| 210 | + if (clip == null) { | |
| 211 | + removeClip(); | |
| 212 | + } else if (clip instanceof Rectangle) { | |
| 213 | + Rectangle r = (Rectangle) clip; | |
| 214 | + checkDirty(); | |
| 215 | + clipRect = new Rectangle(r); | |
| 216 | + //changeClip(r.x, r.y, r.width, r.height, true); | |
| 217 | + } else { | |
| 218 | + throw new IllegalArgumentException("setClip(Shape) only supports Rectangle objects"); | |
| 219 | + } | |
| 220 | + } | |
| 221 | + | |
| 222 | + /** Clears the rectangle indicated by x,y,w,h. */ | |
| 223 | + private native void pClearRect(int x, int y, int w, int h); | |
| 224 | + | |
| 225 | + public void clearRect(int x, int y, int w, int h) | |
| 226 | + { | |
| 227 | + ourSetClip(); | |
| 228 | + pClearRect(x,y,w,h); | |
| 229 | + } | |
| 230 | + | |
| 231 | + /** Fills the given rectangle with the foreground color. */ | |
| 232 | + private native void pFillRect(int X, int Y, int W, int H); | |
| 233 | + | |
| 234 | + public void fillRect(int X, int Y, int W, int H) | |
| 235 | + { | |
| 236 | + ourSetClip(); | |
| 237 | + pFillRect(X,Y,W,H); | |
| 238 | + } | |
| 239 | + | |
| 240 | + /** Draws the given rectangle. */ | |
| 241 | + private native void pDrawRect(int X, int Y, int W, int H); | |
| 242 | + | |
| 243 | + public void drawRect(int X, int Y, int W, int H) | |
| 244 | + { | |
| 245 | + ourSetClip(); | |
| 246 | + pDrawRect(X,Y,W,H); | |
| 247 | + } | |
| 248 | + | |
| 249 | + | |
| 250 | + /** Draws the given string. */ | |
| 251 | + public void drawString(String str, int x, int y) { | |
| 252 | + drawStringWidth(str, x, y); | |
| 253 | + } | |
| 254 | + | |
| 255 | + /** Draws the given character array. */ | |
| 256 | + public void drawChars(char data[], int offset, int length, int x, int y) { | |
| 257 | + String str = new String(data, offset, length); | |
| 258 | + drawStringWidth(str, x, y); | |
| 259 | + // drawCharsWidth(data, offset, length, x, y); | |
| 260 | + } | |
| 261 | + | |
| 262 | + /** Draws the given byte array. */ | |
| 263 | + public void drawBytes(byte data[], int offset, int length, int x, int y) { | |
| 264 | + String str = new String(data, offset, length); | |
| 265 | + drawStringWidth(str, x, y); | |
| 266 | + // drawBytesWidth(data, offset, length, x, y); | |
| 267 | + } | |
| 268 | + | |
| 269 | + /** Draws the given string and returns the length of the drawn | |
| 270 | + string in pixels. If font is not set then returns -1. */ | |
| 271 | + private native int pDrawStringWidth(String str, int x, int y); | |
| 272 | + | |
| 273 | + private int drawStringWidth(String str, int x, int y) | |
| 274 | + { | |
| 275 | + int r; | |
| 276 | + ourSetClip(); | |
| 277 | + if (ifontpeer == null) { | |
| 278 | + return 0; | |
| 279 | + } | |
| 280 | + r = pDrawStringWidth(str, x, y - ifontpeer.iAscent - ifontpeer.fLeading); | |
| 281 | + // System.out.println("Length of string "+r); | |
| 282 | + return r; | |
| 283 | + } | |
| 284 | + | |
| 285 | + /** Draws the given character array and return the width in | |
| 286 | + pixels. If font is not set then returns -1. */ | |
| 287 | +// public native int drawCharsWidth(char data[], int offset, int length, | |
| 288 | +// int x, int y); | |
| 289 | + | |
| 290 | + /** Draws the given character array and return the width in | |
| 291 | + pixels. If font is not set then returns -1. */ | |
| 292 | +// public native int drawBytesWidth(byte data[], int offset, int length, | |
| 293 | +// int x, int y); | |
| 294 | + | |
| 295 | + /** Draws the given line. */ | |
| 296 | + private native void pDrawLine(int x1, int y1, int x2, int y2); | |
| 297 | + | |
| 298 | + public void drawLine(int x1, int y1, int x2, int y2) { | |
| 299 | + ourSetClip(); | |
| 300 | + pDrawLine(x1, y1, x2, y2); | |
| 301 | + } | |
| 302 | + | |
| 303 | + /** | |
| 304 | + * Draws an image at x,y in nonblocking mode with a callback object. | |
| 305 | + */ | |
| 306 | + public boolean drawImage(Image img, int x, int y, ImageObserver observer) { | |
| 307 | + // We need to get the bits. | |
| 308 | + if ( img == null ) | |
| 309 | + return false; | |
| 310 | + java.awt.image.ImageProducer ip = img.getSource(); | |
| 311 | + java.awt.image.ImageConsumer ic = new iImageConsumer(this, img, x, y); | |
| 312 | + ip.startProduction(ic); | |
| 313 | + ip.removeConsumer(ic); | |
| 314 | + /*WImage wImg = (WImage) img; | |
| 315 | + if (wImg.hasError()) { | |
| 316 | + if (observer != null) { | |
| 317 | + observer.imageUpdate(img, | |
| 318 | + ImageObserver.ERROR|ImageObserver.ABORT, | |
| 319 | + -1, -1, -1, -1); | |
| 320 | + } | |
| 321 | + return false; | |
| 322 | + } | |
| 323 | + ImageRepresentation ir = wImg.getImageRep(); | |
| 324 | + return ir.drawImage(this, x, y, null, observer); | |
| 325 | + */ | |
| 326 | + return false; | |
| 327 | + } | |
| 328 | + | |
| 329 | + /** | |
| 330 | + * Draws an image scaled to x,y,w,h in nonblocking mode with a | |
| 331 | + * callback object. | |
| 332 | + */ | |
| 333 | + public boolean drawImage(Image img, int x, int y, int width, int height, | |
| 334 | + ImageObserver observer) { | |
| 335 | + /*if (width == 0 || height == 0) { | |
| 336 | + return true; | |
| 337 | + } | |
| 338 | + WImage wImg = (WImage) img; | |
| 339 | + if (wImg.hasError()) { | |
| 340 | + if (observer != null) { | |
| 341 | + observer.imageUpdate(img, | |
| 342 | + ImageObserver.ERROR|ImageObserver.ABORT, | |
| 343 | + -1, -1, -1, -1); | |
| 344 | + } | |
| 345 | + return false; | |
| 346 | + } | |
| 347 | + ImageRepresentation ir = wImg.getImageRep(); | |
| 348 | + return ir.drawScaledImage(this, x, y, width, height, null, observer); | |
| 349 | + */ | |
| 350 | + return false; | |
| 351 | + } | |
| 352 | + | |
| 353 | + /** | |
| 354 | + * Draws an image at x,y in nonblocking mode with a solid background | |
| 355 | + * color and a callback object. | |
| 356 | + */ | |
| 357 | + public boolean drawImage(Image img, int x, int y, Color bg, | |
| 358 | + ImageObserver observer) { | |
| 359 | + /*WImage wImg = (WImage) img; | |
| 360 | + if (wImg.hasError()) { | |
| 361 | + if (observer != null) { | |
| 362 | + observer.imageUpdate(img, | |
| 363 | + ImageObserver.ERROR|ImageObserver.ABORT, | |
| 364 | + -1, -1, -1, -1); | |
| 365 | + } | |
| 366 | + return false; | |
| 367 | + } | |
| 368 | + ImageRepresentation ir = wImg.getImageRep(); | |
| 369 | + return ir.drawImage(this, x, y, bg, observer); | |
| 370 | + */ | |
| 371 | + return false; | |
| 372 | + } | |
| 373 | + | |
| 374 | + /** | |
| 375 | + * Draws an image scaled to x,y,w,h in nonblocking mode with a | |
| 376 | + * solid background color and a callback object. | |
| 377 | + */ | |
| 378 | + public boolean drawImage(Image img, int x, int y, int width, int height, | |
| 379 | + Color bg, ImageObserver observer) { | |
| 380 | + /*if (width == 0 || height == 0) { | |
| 381 | + return true; | |
| 382 | + } | |
| 383 | + WImage wImg = (WImage) img; | |
| 384 | + if (wImg.hasError()) { | |
| 385 | + if (observer != null) { | |
| 386 | + observer.imageUpdate(img, | |
| 387 | + ImageObserver.ERROR|ImageObserver.ABORT, | |
| 388 | + -1, -1, -1, -1); | |
| 389 | + } | |
| 390 | + return false; | |
| 391 | + } | |
| 392 | + ImageRepresentation ir = wImg.getImageRep(); | |
| 393 | + return ir.drawScaledImage(this, x, y, width, height, bg, observer); | |
| 394 | + */ | |
| 395 | + return false; | |
| 396 | + } | |
| 397 | + | |
| 398 | + /** | |
| 399 | + * Draws a subrectangle of an image scaled to a destination rectangle | |
| 400 | + * in nonblocking mode with a callback object. | |
| 401 | + */ | |
| 402 | + public boolean drawImage(Image img, | |
| 403 | + int dx1, int dy1, int dx2, int dy2, | |
| 404 | + int sx1, int sy1, int sx2, int sy2, | |
| 405 | + ImageObserver observer) { | |
| 406 | + /*if (dx1 == dx2 || dy1 == dy2) { | |
| 407 | + return true; | |
| 408 | + } | |
| 409 | + WImage wImg = (WImage) img; | |
| 410 | + if (wImg.hasError()) { | |
| 411 | + if (observer != null) { | |
| 412 | + observer.imageUpdate(img, | |
| 413 | + ImageObserver.ERROR|ImageObserver.ABORT, | |
| 414 | + -1, -1, -1, -1); | |
| 415 | + } | |
| 416 | + return false; | |
| 417 | + } | |
| 418 | + ImageRepresentation ir = wImg.getImageRep(); | |
| 419 | + return ir.drawStretchImage(this, | |
| 420 | + dx1, dy1, dx2, dy2, | |
| 421 | + sx1, sy1, sx2, sy2, | |
| 422 | + null, observer); | |
| 423 | + */ | |
| 424 | + return false; | |
| 425 | + } | |
| 426 | + | |
| 427 | + /** | |
| 428 | + * Draws a subrectangle of an image scaled to a destination rectangle in | |
| 429 | + * nonblocking mode with a solid background color and a callback object. | |
| 430 | + */ | |
| 431 | + public boolean drawImage(Image img, | |
| 432 | + int dx1, int dy1, int dx2, int dy2, | |
| 433 | + int sx1, int sy1, int sx2, int sy2, | |
| 434 | + Color bgcolor, ImageObserver observer) { | |
| 435 | + /*if (dx1 == dx2 || dy1 == dy2) { | |
| 436 | + return true; | |
| 437 | + } | |
| 438 | + WImage wImg = (WImage) img; | |
| 439 | + if (wImg.hasError()) { | |
| 440 | + if (observer != null) { | |
| 441 | + observer.imageUpdate(img, | |
| 442 | + ImageObserver.ERROR|ImageObserver.ABORT, | |
| 443 | + -1, -1, -1, -1); | |
| 444 | + } | |
| 445 | + return false; | |
| 446 | + } | |
| 447 | + ImageRepresentation ir = wImg.getImageRep(); | |
| 448 | + return ir.drawStretchImage(this, | |
| 449 | + dx1, dy1, dx2, dy2, | |
| 450 | + sx1, sy1, sx2, sy2, | |
| 451 | + bgcolor, observer); | |
| 452 | + */ | |
| 453 | + return false; | |
| 454 | + } | |
| 455 | + | |
| 456 | + /** | |
| 457 | + * Actually draws the image on the Inferno display in a blocking mode. | |
| 458 | + */ | |
| 459 | + private native void pGenDraw(int x, int y, int w, int h, byte pixels[]); | |
| 460 | + | |
| 461 | + protected void drawImage(int x, int y, int w, int h, byte pixels[]) { | |
| 462 | + ourSetClip(); | |
| 463 | + //ourSetForeground(); | |
| 464 | + pGenDraw(x, y, w, h, pixels); | |
| 465 | + return; | |
| 466 | + } | |
| 467 | + | |
| 468 | + /** | |
| 469 | + * Copies an area of the canvas that this graphics context paints to. | |
| 470 | + * @param X the x-coordinate of the source. | |
| 471 | + * @param Y the y-coordinate of the source. | |
| 472 | + * @param W the width. | |
| 473 | + * @param H the height. | |
| 474 | + * @param dx the x-coordinate of the destination. | |
| 475 | + * @param dy the y-coordinate of the destination. | |
| 476 | + */ | |
| 477 | + public native void copyArea(int X, int Y, int W, int H, int dx, int dy); | |
| 478 | + | |
| 479 | + | |
| 480 | + /** Draws a rounded rectangle. */ | |
| 481 | + private native void pDrawRoundRect(int x, int y, int w, int h, | |
| 482 | + int arcWidth, int arcHeight); | |
| 483 | + | |
| 484 | + public void drawRoundRect(int x, int y, int w, int h, | |
| 485 | + int arcWidth, int arcHeight) | |
| 486 | + { | |
| 487 | + ourSetClip(); | |
| 488 | + pDrawRoundRect(x,y,w,h,arcWidth,arcHeight); | |
| 489 | + } | |
| 490 | + | |
| 491 | + /** Draws a filled rounded rectangle. */ | |
| 492 | + private native void pFillRoundRect(int x, int y, int w, int h, | |
| 493 | + int arcWidth, int arcHeight); | |
| 494 | + | |
| 495 | + public void fillRoundRect(int x, int y, int w, int h, | |
| 496 | + int arcWidth, int arcHeight) | |
| 497 | + { | |
| 498 | + ourSetClip(); | |
| 499 | + pFillRoundRect(x,y,w,h,arcWidth,arcHeight); | |
| 500 | + } | |
| 501 | + | |
| 502 | + /** Draws a polygon defined by an array of x points and y points */ | |
| 503 | + private native void pDrawPolygon(int xPoints[], int yPoints[], int nPoints); | |
| 504 | + | |
| 505 | + public void drawPolygon(int xPoints[], int yPoints[], int nPoints) | |
| 506 | + { | |
| 507 | + ourSetClip(); | |
| 508 | + pDrawPolygon(xPoints,yPoints,nPoints); | |
| 509 | + } | |
| 510 | + | |
| 511 | + /** Draws a polygon defined by an array of x points and y points */ | |
| 512 | + private native void pDrawPolyline(int xPoints[], int yPoints[], int nPoints); | |
| 513 | + | |
| 514 | + public void drawPolyline(int xPoints[], int yPoints[], int nPoints) | |
| 515 | + { | |
| 516 | + ourSetClip(); | |
| 517 | + pDrawPolyline(xPoints,yPoints,nPoints); | |
| 518 | + } | |
| 519 | + | |
| 520 | + /** Fills a polygon with the current fill mask */ | |
| 521 | + private native void pFillPolygon(int xPoints[], int yPoints[], int nPoints); | |
| 522 | + | |
| 523 | + public void fillPolygon(int xPoints[], int yPoints[], int nPoints) | |
| 524 | + { | |
| 525 | + ourSetClip(); | |
| 526 | + pFillPolygon(xPoints,yPoints,nPoints); | |
| 527 | + } | |
| 528 | + | |
| 529 | + /** Draws an oval to fit in the given rectangle */ | |
| 530 | + private native void pDrawOval(int x, int y, int w, int h); | |
| 531 | + | |
| 532 | + public void drawOval(int x, int y, int w, int h) | |
| 533 | + { | |
| 534 | + ourSetClip(); | |
| 535 | + pDrawOval(x,y,w,h); | |
| 536 | + } | |
| 537 | + | |
| 538 | + /** Fills an oval to fit in the given rectangle */ | |
| 539 | + private native void pFillOval(int x, int y, int w, int h); | |
| 540 | + | |
| 541 | + public void fillOval(int x, int y, int w, int h) | |
| 542 | + { | |
| 543 | + ourSetClip(); | |
| 544 | + pFillOval(x,y,w,h); | |
| 545 | + } | |
| 546 | + | |
| 547 | + /** | |
| 548 | + * Draws an arc bounded by the given rectangle from startAngle to | |
| 549 | + * endAngle. 0 degrees is a vertical line straight up from the | |
| 550 | + * center of the rectangle. Positive angles indicate clockwise | |
| 551 | + * rotations, negative angle are counter-clockwise. | |
| 552 | + */ | |
| 553 | + private native void pDrawArc(int x, int y, int w, int h, | |
| 554 | + int startAngle, | |
| 555 | + int endAngle); | |
| 556 | + | |
| 557 | + public void drawArc(int x, int y, int w, int h, | |
| 558 | + int startAngle, | |
| 559 | + int endAngle) | |
| 560 | + { | |
| 561 | + ourSetClip(); | |
| 562 | + pDrawArc(x,y,w,h,startAngle,endAngle); | |
| 563 | + } | |
| 564 | + | |
| 565 | + /** fills an arc. arguments are the same as drawArc. */ | |
| 566 | + private native void pFillArc(int x, int y, int w, int h, | |
| 567 | + int startAngle, | |
| 568 | + int endAngle); | |
| 569 | + | |
| 570 | + public void fillArc(int x, int y, int w, int h, | |
| 571 | + int startAngle, | |
| 572 | + int endAngle) | |
| 573 | + { | |
| 574 | + ourSetClip(); | |
| 575 | + pFillArc(x,y,w,h,startAngle,endAngle); | |
| 576 | + } | |
| 577 | + | |
| 578 | + | |
| 579 | + public String toString() { | |
| 580 | + return (getClass().getName() + "[" + originX + "," + originY + | |
| 581 | + "[font=" + getFont() + "], color=" + getColor() + "]"); | |
| 582 | + } | |
| 583 | + | |
| 584 | + // Print a peer using this graphics object. | |
| 585 | + void print(ComponentPeer peer) | |
| 586 | + { | |
| 587 | + } | |
| 588 | + | |
| 589 | + /* Outline the given region. */ | |
| 590 | + //public native void drawRegion(Region r); | |
| 591 | + | |
| 592 | + /* Fill the given region. */ | |
| 593 | + //public native void fillRegion(Region r); | |
| 594 | + | |
| 595 | + /** Terminates a PrintJob and releases resources */ | |
| 596 | + public void close(PrintJob pj) | |
| 597 | + { | |
| 598 | + } | |
| 599 | + | |
| 600 | + private native void copyOffscreenImage(int X, int Y, int W, int H); | |
| 601 | + | |
| 602 | +} | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| @@ -0,0 +1,245 @@ | ||
| 1 | +implement iGraphics_L; | |
| 2 | + | |
| 3 | +include "jni.m"; | |
| 4 | + jni : JNI; | |
| 5 | + ClassModule, | |
| 6 | + JString, | |
| 7 | + JArray, | |
| 8 | + JArrayI, | |
| 9 | + JArrayC, | |
| 10 | + JArrayB, | |
| 11 | + JArrayS, | |
| 12 | + JArrayJ, | |
| 13 | + JArrayF, | |
| 14 | + JArrayD, | |
| 15 | + JArrayZ, | |
| 16 | + JArrayJObject, | |
| 17 | + JArrayJClass, | |
| 18 | + JArrayJString, | |
| 19 | + JClass, | |
| 20 | + JThread, | |
| 21 | + JObject : import jni; | |
| 22 | + | |
| 23 | +#>> extra pre includes here | |
| 24 | +# | |
| 25 | +# %W% - %E% | |
| 26 | +# | |
| 27 | + sys : Sys; | |
| 28 | + draw: Draw; | |
| 29 | + Point, Font: import draw; | |
| 30 | +include "awt_Graphics.m"; | |
| 31 | + | |
| 32 | +include "iFontPeer_L.m"; | |
| 33 | + ifontpeerm: iFontPeer_L; | |
| 34 | + iFontPeer_obj : import ifontpeerm; | |
| 35 | + | |
| 36 | +#<< | |
| 37 | + | |
| 38 | +include "iGraphics_L.m"; | |
| 39 | + | |
| 40 | +#>> extra post includes here | |
| 41 | + | |
| 42 | +#<< | |
| 43 | + | |
| 44 | +init( jni_p : JNI ) | |
| 45 | +{ | |
| 46 | + # save java native inteface mod instance | |
| 47 | + jni = jni_p; | |
| 48 | + #>>extra initialization here | |
| 49 | + sys = jni->sys; | |
| 50 | + | |
| 51 | + #<< | |
| 52 | +} | |
| 53 | + | |
| 54 | + | |
| 55 | +pSetForeground_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int) | |
| 56 | +{#>> | |
| 57 | + this.awt->setForeground(p0, p1, p2); | |
| 58 | +}#<< | |
| 59 | + | |
| 60 | +createGraphics_V( this : ref iGraphics_obj) | |
| 61 | +{#>> | |
| 62 | + this.awt = load AwtGraphics AwtGraphics->PATH;; | |
| 63 | + if (this.awt == nil) { | |
| 64 | + sys->print("could not load %s: %r\n", AwtGraphics->PATH); | |
| 65 | + return; | |
| 66 | + } | |
| 67 | + this.awt->init(this.refImage, this.refOffScreenImage); | |
| 68 | +}#<< | |
| 69 | + | |
| 70 | +pDispose_V( this : ref iGraphics_obj) | |
| 71 | +{#>> | |
| 72 | +}#<< | |
| 73 | + | |
| 74 | +setPaintMode_V( this : ref iGraphics_obj) | |
| 75 | +{#>> | |
| 76 | +}#<< | |
| 77 | + | |
| 78 | +setXORMode_rColor_V( this : ref iGraphics_obj, p0 : JObject) | |
| 79 | +{#>> | |
| 80 | +}#<< | |
| 81 | + | |
| 82 | +changeClip_I_I_I_I_Z_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int) | |
| 83 | +{#>> | |
| 84 | + this.awt->changeClip(p0 + this.originX, p1 + this.originY, p2, p3); | |
| 85 | +}#<< | |
| 86 | + | |
| 87 | +pClearRect_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int) | |
| 88 | +{#>> | |
| 89 | + this.awt->clearRect(p0 + this.originX, p1 + this.originY, p2, p3); | |
| 90 | +}#<< | |
| 91 | + | |
| 92 | +pFillRect_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int) | |
| 93 | +{#>> | |
| 94 | + | |
| 95 | + tp := (p0, p1); | |
| 96 | + p := dp(this, tp); | |
| 97 | + | |
| 98 | + ply := array [5] of {p, (p.x + p2 - 1, p.y), (p.x + p2 - 1, p.y + p3 - 1), | |
| 99 | + (p.x, p.y + p3 - 1), p}; | |
| 100 | + this.awt->fillRect(ply); | |
| 101 | +}#<< | |
| 102 | + | |
| 103 | +pDrawRect_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int) | |
| 104 | +{#>> | |
| 105 | + tp := (p0, p1); | |
| 106 | + p := dp(this, tp); | |
| 107 | + | |
| 108 | + ply := array [5] of {p, (p.x + p2 - 1, p.y), (p.x + p2 - 1, p.y + p3 - 1), | |
| 109 | + (p.x, p.y + p3 - 1), p}; | |
| 110 | + this.awt->drawRect(ply); | |
| 111 | +}#<< | |
| 112 | + | |
| 113 | +pDrawStringWidth_rString_I_I_I( this : ref iGraphics_obj, p0 : JString,p1 : int,p2 : int) : int | |
| 114 | +{#>> | |
| 115 | + str : string; | |
| 116 | + sp : Point; | |
| 117 | + sp.x = p1; | |
| 118 | + sp.y = p2; | |
| 119 | + | |
| 120 | + str = p0.str; | |
| 121 | + sp = dp(this, sp); | |
| 122 | + return this.awt->drawStringWidth(str, sp, this.ifontpeer.iFontRef ); | |
| 123 | +}#<< | |
| 124 | + | |
| 125 | +pDrawLine_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int) | |
| 126 | +{#>> | |
| 127 | + sp, ep : Point; | |
| 128 | + sp.x = this.originX + p0; | |
| 129 | + sp.y = this.originY + p1; | |
| 130 | + ep.x = this.originX + p2; | |
| 131 | + ep.y = this.originY + p3; | |
| 132 | + this.awt->drawLine(sp, ep); | |
| 133 | +}#<< | |
| 134 | + | |
| 135 | +pGenDraw_I_I_I_I_aB_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int, p4 : JArrayB) | |
| 136 | +{#>> | |
| 137 | + p0 += this.originX; | |
| 138 | + p1 += this.originY; | |
| 139 | + r := Draw->Rect((p0,p1),(p0+p2,p1+p3)); | |
| 140 | + this.awt->genDraw(r, p4.ary); | |
| 141 | +}#<< | |
| 142 | + | |
| 143 | +copyArea_I_I_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int) | |
| 144 | +{#>> | |
| 145 | + data := array [(p2 - p0 + 1) * (p3 - p1 + 1)] of byte; | |
| 146 | + rect0, rect1 : Draw->Rect; | |
| 147 | + rect0.min = (p0, p1); | |
| 148 | + rect0.max = (p2, p3); | |
| 149 | + rect1.min = (p0 + p4, p1 + p5); | |
| 150 | + rect1.max = (p2 + p4, p3 + p5); | |
| 151 | + this.awt->copyArea(rect0, rect1, data); | |
| 152 | +}#<< | |
| 153 | + | |
| 154 | +pDrawRoundRect_I_I_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int) | |
| 155 | +{#>> | |
| 156 | +}#<< | |
| 157 | + | |
| 158 | +pFillRoundRect_I_I_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int) | |
| 159 | +{#>> | |
| 160 | +}#<< | |
| 161 | + | |
| 162 | +pDrawPolygon_aI_aI_I_V( this : ref iGraphics_obj, p0 : JArrayI,p1 : JArrayI,p2 : int) | |
| 163 | +{#>> | |
| 164 | + ply := array [p2 + 1] of Point; | |
| 165 | + for (i := 0; i < p2; i++){ | |
| 166 | + ply[i].x = p0.ary[i] + this.originX; | |
| 167 | + ply[i].y = p1.ary[i] + this.originY; | |
| 168 | + } | |
| 169 | + ply[p2].x = ply[0].x; | |
| 170 | + ply[p2].y = ply[0].y; | |
| 171 | + this.awt->drawPolygon(ply); | |
| 172 | +}#<< | |
| 173 | + | |
| 174 | +pDrawPolyline_aI_aI_I_V( this : ref iGraphics_obj, p0 : JArrayI,p1 : JArrayI,p2 : int) | |
| 175 | +{#>> | |
| 176 | + ply := array [p2] of Point; | |
| 177 | + for (i := 0; i < p2; i++){ | |
| 178 | + ply[i].x = p0.ary[i] + this.originX; | |
| 179 | + ply[i].y = p1.ary[i] + this.originY; | |
| 180 | + } | |
| 181 | + this.awt->drawPolygon(ply); | |
| 182 | +}#<< | |
| 183 | + | |
| 184 | +pFillPolygon_aI_aI_I_V( this : ref iGraphics_obj, p0 : JArrayI,p1 : JArrayI,p2 : int) | |
| 185 | +{#>> | |
| 186 | + ply := array [p2 + 1] of Point; | |
| 187 | + for (i := 0; i < p2; i++){ | |
| 188 | + ply[i].x = p0.ary[i] + this.originX; | |
| 189 | + ply[i].y = p1.ary[i] + this.originY; | |
| 190 | + } | |
| 191 | + ply[p2].x = ply[0].x; | |
| 192 | + ply[p2].y = ply[0].y; | |
| 193 | + this.awt->fillPolygon(ply); | |
| 194 | +}#<< | |
| 195 | + | |
| 196 | +pDrawOval_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int) | |
| 197 | +{#>> | |
| 198 | + tp := (p0, p1); | |
| 199 | + p := dp(this, tp); | |
| 200 | + this.awt->drawOval(p, p2, p3); | |
| 201 | +}#<< | |
| 202 | + | |
| 203 | +pFillOval_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int) | |
| 204 | +{#>> | |
| 205 | + tp := (p0, p1); | |
| 206 | + p := dp(this, tp); | |
| 207 | + | |
| 208 | + this.awt->fillOval(p, p2, p3); | |
| 209 | +}#<< | |
| 210 | + | |
| 211 | +pDrawArc_I_I_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int) | |
| 212 | +{#>> | |
| 213 | + | |
| 214 | + tp := (p0, p1); | |
| 215 | + p := dp(this, tp); | |
| 216 | + this.awt->drawArc(p, p2, p3, p4, p5); | |
| 217 | +}#<< | |
| 218 | + | |
| 219 | +pFillArc_I_I_I_I_I_I_V( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int) | |
| 220 | +{#>> | |
| 221 | + tp := (p0, p1); | |
| 222 | + p := dp(this, tp); | |
| 223 | + this.awt->fillArc(p, p2, p3, p4, p5); | |
| 224 | +}#<< | |
| 225 | + | |
| 226 | +copyOffscreenImage_I_I_I_I_V( this : ref iGraphics_obj, p0 : int, p1: int, p2: int, p3: int) | |
| 227 | +{#>> | |
| 228 | + this.awt->getDC(this.refImage, this.refOffScreenImage); | |
| 229 | + this.awt->sendToDisplay(((p0+this.originX,p1+this.originY), | |
| 230 | + (p0+this.originX+p2-1,p1+this.originY+p3-1))); | |
| 231 | +}#<< | |
| 232 | + | |
| 233 | + | |
| 234 | +#>> | |
| 235 | + | |
| 236 | +# duplicates a point and translates into this graphic's region | |
| 237 | +dp(this : ref iGraphics_obj, p : Point) :Point | |
| 238 | +{ | |
| 239 | + pt := p; | |
| 240 | + pt.x += this.originX; | |
| 241 | + pt.y += this.originY; | |
| 242 | + return pt; | |
| 243 | +} | |
| 244 | + | |
| 245 | +#<< | |
| @@ -0,0 +1,50 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | +# generated file edit with care | |
| 5 | + | |
| 6 | +iGraphics_L : module | |
| 7 | +{ | |
| 8 | + iGraphics_obj : adt | |
| 9 | + { | |
| 10 | + cl_mod : ClassModule; | |
| 11 | + refImage : ref Draw->Image; | |
| 12 | + refOffScreenImage : ref Draw->Image; | |
| 13 | + target : JObject; | |
| 14 | + foreground : JObject; | |
| 15 | + font : JObject; | |
| 16 | + ifontpeer : ref iFontPeer_obj; | |
| 17 | + originX : int; | |
| 18 | + originY : int; | |
| 19 | + clipRect : JObject; | |
| 20 | + initialClipRect : JObject; | |
| 21 | + dirty : int; | |
| 22 | + image : JObject; | |
| 23 | + awt : AwtGraphics; | |
| 24 | + }; | |
| 25 | + | |
| 26 | + init : fn( jni_p : JNI ); | |
| 27 | + pSetForeground_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int); | |
| 28 | + createGraphics_V : fn( this : ref iGraphics_obj); | |
| 29 | + pDispose_V : fn( this : ref iGraphics_obj); | |
| 30 | + setPaintMode_V : fn( this : ref iGraphics_obj); | |
| 31 | + setXORMode_rColor_V : fn( this : ref iGraphics_obj, p0 : JObject); | |
| 32 | + changeClip_I_I_I_I_Z_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int); | |
| 33 | + pClearRect_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int); | |
| 34 | + pFillRect_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int); | |
| 35 | + pDrawRect_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int); | |
| 36 | + pDrawStringWidth_rString_I_I_I : fn( this : ref iGraphics_obj, p0 : JString,p1 : int,p2 : int) : int; | |
| 37 | + pDrawLine_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int); | |
| 38 | + pGenDraw_I_I_I_I_aB_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : JArrayB); | |
| 39 | + copyArea_I_I_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int); | |
| 40 | + pDrawRoundRect_I_I_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int); | |
| 41 | + pFillRoundRect_I_I_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int); | |
| 42 | + pDrawPolygon_aI_aI_I_V : fn( this : ref iGraphics_obj, p0 : JArrayI,p1 : JArrayI,p2 : int); | |
| 43 | + pDrawPolyline_aI_aI_I_V : fn( this : ref iGraphics_obj, p0 : JArrayI,p1 : JArrayI,p2 : int); | |
| 44 | + pFillPolygon_aI_aI_I_V : fn( this : ref iGraphics_obj, p0 : JArrayI,p1 : JArrayI,p2 : int); | |
| 45 | + pDrawOval_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int); | |
| 46 | + pFillOval_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int); | |
| 47 | + pDrawArc_I_I_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int); | |
| 48 | + pFillArc_I_I_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int); | |
| 49 | + copyOffscreenImage_I_I_I_I_V : fn( this : ref iGraphics_obj, p0 : int, p1: int, p2: int, p3: int); | |
| 50 | +}; | |
| @@ -0,0 +1,51 @@ | ||
| 1 | +/* | |
| 2 | + * | |
| 3 | + * %W% - %E% | |
| 4 | + * | |
| 5 | + * Adapted from SunSoft's X11Image.java 1.7 97/02/24 | |
| 6 | + */ | |
| 7 | +package inferno.awt; | |
| 8 | + | |
| 9 | +import java.awt.Component; | |
| 10 | +import java.awt.Graphics; | |
| 11 | +import java.awt.image.ImageProducer; | |
| 12 | + | |
| 13 | +import sun.awt.image.ImageRepresentation; | |
| 14 | + | |
| 15 | +class iImage extends sun.awt.image.Image { | |
| 16 | + /** | |
| 17 | + * Construct an image for offscreen rendering to be used with a | |
| 18 | + * given Component. | |
| 19 | + */ | |
| 20 | + public iImage(Component c, int w, int h) { | |
| 21 | + super(c, w, h); | |
| 22 | + } | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * Construct an image from an ImageProducer object. | |
| 26 | + */ | |
| 27 | + public iImage(ImageProducer producer) { | |
| 28 | + super(producer); | |
| 29 | + } | |
| 30 | + | |
| 31 | + public Graphics getGraphics() { | |
| 32 | + throw new IllegalAccessError("getGraphics() only valid for images created with createImage(w, h)"); | |
| 33 | + } | |
| 34 | + | |
| 35 | + protected ImageRepresentation makeImageRep() { | |
| 36 | + // make Inferno ImageRepresentation - jfs | |
| 37 | + //return new ImageRepresentation(this, -1, -1, 0); | |
| 38 | + return new iImageRepresentation(this, -1, -1, 0); | |
| 39 | + } | |
| 40 | + | |
| 41 | + protected ImageRepresentation getImageRep() { | |
| 42 | + return super.getImageRep(); | |
| 43 | + } | |
| 44 | + | |
| 45 | + // overridden strictly for tracing and debugging. - jfs | |
| 46 | + protected void initGraphics(Graphics g) { | |
| 47 | + System.out.println("iImage.initGraphics() this=" + this + | |
| 48 | + "\n g=" + g); | |
| 49 | + super.initGraphics(g); | |
| 50 | + } | |
| 51 | +} | |
Empty file added.
| @@ -0,0 +1,91 @@ | ||
| 1 | +/* | |
| 2 | + * | |
| 3 | + */ | |
| 4 | + | |
| 5 | +package inferno.awt; | |
| 6 | + | |
| 7 | +import java.awt.Color; | |
| 8 | +import java.awt.Graphics; | |
| 9 | +//import java.awt.AWTException; | |
| 10 | +//import java.awt.Rectangle; | |
| 11 | +import java.awt.image.ColorModel; | |
| 12 | +import java.awt.image.ImageConsumer; | |
| 13 | +import java.awt.image.ImageObserver; | |
| 14 | +import sun.awt.image.ImageWatched; | |
| 15 | +import sun.awt.image.Image; | |
| 16 | +//import sun.awt.AWTFinalizeable; | |
| 17 | +//import sun.awt.AWTFinalizer; | |
| 18 | +//import java.util.Hashtable; | |
| 19 | + | |
| 20 | +/* | |
| 21 | + * This implementation the implementation class for Sun's | |
| 22 | + * sun.awt.image.ImageRepresentation. | |
| 23 | + * - jfs | |
| 24 | + */ | |
| 25 | +public class iImageRepresentation extends sun.awt.image.ImageRepresentation | |
| 26 | +{ | |
| 27 | + /* ref Draw->Image, used by native code */ | |
| 28 | + Object piImage; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Create an ImageRepresentation for the given Image scaled | |
| 32 | + * to the given width and height and dithered or converted to | |
| 33 | + * a ColorModel appropriate for the given image tag. | |
| 34 | + */ | |
| 35 | + //public iImageRepresentation(Image im, int w, int h, int t) { | |
| 36 | + public iImageRepresentation(iImage im, int w, int h, int t) { | |
| 37 | + super(im, w, h, t); | |
| 38 | + System.out.println("iImageRep.iImagRep(): w=" + w + " h=" + h + | |
| 39 | + "t=" + t + "im=" + im); | |
| 40 | + } | |
| 41 | + /** | |
| 42 | + * Initialize this ImageRepresentation object to act as the | |
| 43 | + * destination drawable for this OffScreen Image. | |
| 44 | + */ | |
| 45 | + protected native void offscreenInit(Color bg); | |
| 46 | + | |
| 47 | + /* make Inferno's own ImageRepresentation - jfs | |
| 48 | + private native boolean setBytePixels(int x, int y, int w, int h, | |
| 49 | + ColorModel model, | |
| 50 | + byte pix[], int off, int scansize); | |
| 51 | + */ | |
| 52 | + protected native boolean setBytePixels(int x, int y, int w, int h, | |
| 53 | + ColorModel model, | |
| 54 | + byte pix[], int off, int scansize); | |
| 55 | + | |
| 56 | + /* make Inferno's own ImageRepresentation - jfs | |
| 57 | + private native boolean setIntPixels(int x, int y, int w, int h, | |
| 58 | + ColorModel model, | |
| 59 | + int pix[], int off, int scansize); | |
| 60 | + */ | |
| 61 | + protected native boolean setIntPixels(int x, int y, int w, int h, | |
| 62 | + ColorModel model, | |
| 63 | + int pix[], int off, int scansize); | |
| 64 | + | |
| 65 | + /* make Inferno's own ImageRepresentation - jfs | |
| 66 | + private native boolean finish(boolean force); | |
| 67 | + */ | |
| 68 | + protected native boolean finish(boolean force); | |
| 69 | + | |
| 70 | + /* make Inferno's own ImageRepresentation - jfs | |
| 71 | + native synchronized void imageDraw(Graphics g, int x, int y, Color c); | |
| 72 | + | |
| 73 | + */ | |
| 74 | + native protected synchronized void imageDraw(Graphics g, int x, int y, Color c); | |
| 75 | + | |
| 76 | + /* make Inferno's own ImageRepresentation - jfs | |
| 77 | + native synchronized void imageStretch(Graphics g, | |
| 78 | + int dx1, int dy1, int dx2, int dy2, | |
| 79 | + int sx1, int sy1, int sx2, int sy2, | |
| 80 | + Color c); | |
| 81 | + */ | |
| 82 | + native protected synchronized void imageStretch(Graphics g, | |
| 83 | + int dx1, int dy1, int dx2, int dy2, | |
| 84 | + int sx1, int sy1, int sx2, int sy2, | |
| 85 | + Color c); | |
| 86 | + | |
| 87 | + /* make Inferno's own ImageRepresentation - jfs | |
| 88 | + private native void disposeImage(); | |
| 89 | + */ | |
| 90 | + protected native void disposeImage(); | |
| 91 | +} | |
| @@ -0,0 +1,152 @@ | ||
| 1 | +implement iImageRepresentation_L; | |
| 2 | + | |
| 3 | +# javal v1.5 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | + | |
| 27 | +#<< | |
| 28 | + | |
| 29 | +include "iImageRepresentation_L.m"; | |
| 30 | + | |
| 31 | +#>> extra post includes here | |
| 32 | + sys : import jni; # std Inferno Sys module | |
| 33 | + str : import jni; # std Inferno String module | |
| 34 | + | |
| 35 | + FALSE : import jni; | |
| 36 | + TRUE : import jni; | |
| 37 | + | |
| 38 | + # draw.m in included by something included by jni.m | |
| 39 | + draw : Draw; | |
| 40 | + Context, Screen, Display, Rect, Point, Image : import draw; | |
| 41 | + ctxt: ref Context; | |
| 42 | + | |
| 43 | +include "awt_Image.m"; | |
| 44 | + | |
| 45 | + awtIm : AwtImage; | |
| 46 | + | |
| 47 | + # Some constants that aggregate status state. | |
| 48 | + IM_SIZEINFO: con (awtIm->ImO_WIDTH | awtIm->ImO_HEIGHT); | |
| 49 | + IM_DRAWINFO: con (awtIm->ImO_WIDTH | awtIm->ImO_HEIGHT | | |
| 50 | + awtIm->ImO_SOMEBITS); | |
| 51 | + IM_FULLDRAWINFO: con (awtIm->ImO_FRAMEBITS | awtIm->ImO_ALLBITS); | |
| 52 | + IM_OFFSCREENINFO: con (awtIm->ImO_WIDTH | awtIm->ImO_HEIGHT | | |
| 53 | + awtIm->ImO_SOMEBITS | awtIm->ImO_ALLBITS); | |
| 54 | + | |
| 55 | + # Some constants that aggregate hints state | |
| 56 | + HINT_OFFSCREENSEND: con (awtIm->ImC_TOPDOWNLEFTRIGHT | | |
| 57 | + awtIm->ImC_COMPLETESCANLINES | | |
| 58 | + awtIm->ImC_SINGLEPASS); | |
| 59 | + | |
| 60 | +include "awt_Color.m"; | |
| 61 | + awtColor : AwtColor; | |
| 62 | + | |
| 63 | +#<< | |
| 64 | + | |
| 65 | +init( jni_p : JNI ) | |
| 66 | +{ | |
| 67 | + # save java native inteface mod instance | |
| 68 | + jni = jni_p; | |
| 69 | + #>>extra initialization here | |
| 70 | + sys = jni->sys; | |
| 71 | + draw = load Draw Draw->PATH; | |
| 72 | + if (draw == nil) { | |
| 73 | + jni->InitError(sys->sprint( | |
| 74 | + "inferno.awt.iImageRepresentation: could not load %s: %r", | |
| 75 | + Draw->PATH)); | |
| 76 | + } | |
| 77 | + awtColor = load AwtColor AwtColor->PATH; | |
| 78 | + if (awtColor == nil) { | |
| 79 | + jni->InitError(sys->sprint( | |
| 80 | + "inferno.awt.iImageRepresentation: could not load %s: %r", | |
| 81 | + AwtColor->PATH)); | |
| 82 | + } | |
| 83 | + ctxt = jni->getContext(); | |
| 84 | + #<< | |
| 85 | +} | |
| 86 | + | |
| 87 | +offscreenInit_rColor_V( this : ref iImageRepresentation_obj, p0 : JObject) | |
| 88 | +{#>> | |
| 89 | + # Type(p0) is java.awt.Color | |
| 90 | + # bgcolorim := ctxt.display.color(Draw->White); # default | |
| 91 | + bgcoloridx := Draw->White; | |
| 92 | + if (p0 == nil) { | |
| 93 | + sys->print("iImageRepresentation_L.offscreenInit(): p0 == nil!\n"); | |
| 94 | + } else { | |
| 95 | + # get the colormap index for this Java Color | |
| 96 | + bgcoloridx = awtColor->getColorIndex(jni, p0); | |
| 97 | + } | |
| 98 | + bgcoloridx = Draw->White; # for testing... - jfs | |
| 99 | + if (this.width <= 0 || this.height <=0) { | |
| 100 | + jni->ThrowException("java.lang.IllegalArgumentException", "offscreen w and h < 0"); | |
| 101 | + } | |
| 102 | + # create an Inferno Image for double buffer store. | |
| 103 | + ldeep := ctxt.display.image.ldepth; | |
| 104 | + this.piImage = ctxt.display.newimage(Draw->Rect( | |
| 105 | + (0,0),(this.width,this.height)), | |
| 106 | + ldeep, 0, bgcoloridx); | |
| 107 | + sys->print("iImageRepresentation_L.offscreenInit(): - this=%x, piImage=%x!\n", | |
| 108 | + this, this.piImage); | |
| 109 | +}#<< | |
| 110 | + | |
| 111 | +setBytePixels_I_I_I_I_rColorModel_aB_I_I_Z( this : ref iImageRepresentation_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : JObject,p5 : JArrayB,p6 : int,p7 : int) : int | |
| 112 | +{#>> | |
| 113 | + # not yet implemented, so keep the type system happy by returning | |
| 114 | + # FALSE as nothing was done | |
| 115 | + sys->print("iImageRepresentation_L.setBytePixels(): - NYI!\n"); | |
| 116 | + return(FALSE); | |
| 117 | +}#<< | |
| 118 | + | |
| 119 | +setIntPixels_I_I_I_I_rColorModel_aI_I_I_Z( this : ref iImageRepresentation_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : JObject,p5 : JArrayI,p6 : int,p7 : int) : int | |
| 120 | +{#>> | |
| 121 | + # not yet implemented, so keep the type system happy by returning | |
| 122 | + # FALSE as nothing was done | |
| 123 | + sys->print("iImageRepresentation_L.setIntPixels(): - NYI!\n"); | |
| 124 | + return(FALSE); | |
| 125 | +}#<< | |
| 126 | + | |
| 127 | +finish_Z_Z( this : ref iImageRepresentation_obj, p0 : int) : int | |
| 128 | +{#>> | |
| 129 | + # not yet implemented, so just return false so the calling code | |
| 130 | + # wont try a resend in TopDownLeftRight order... | |
| 131 | + sys->print("iImageRepresentation_L.finish(): - NYI!\n"); | |
| 132 | + return(FALSE); | |
| 133 | +}#<< | |
| 134 | + | |
| 135 | +imageDraw_rGraphics_I_I_rColor_V( this : ref iImageRepresentation_obj, p0 : JObject,p1 : int,p2 : int,p3 : JObject) | |
| 136 | +{#>> | |
| 137 | + sys->print("iImageRepresentation_L.imageDraw(): - NYI!\n"); | |
| 138 | +}#<< | |
| 139 | + | |
| 140 | +imageStretch_rGraphics_I_I_I_I_I_I_I_I_rColor_V( this : ref iImageRepresentation_obj, p0 : JObject,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int,p6 : int,p7 : int,p8 : int,p9 : JObject) | |
| 141 | +{#>> | |
| 142 | + sys->print("iImageRepresentation_L.imageStretch(): - NYI!\n"); | |
| 143 | +}#<< | |
| 144 | + | |
| 145 | +disposeImage_V( this : ref iImageRepresentation_obj) | |
| 146 | +{#>> | |
| 147 | + this.piImage = nil; | |
| 148 | + sys->print("iImageRepresentation_L.disposeImage(): - NYI!\n"); | |
| 149 | +}#<< | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| @@ -0,0 +1,36 @@ | ||
| 1 | +# javal v1.5 generated file: edit with care | |
| 2 | + | |
| 3 | +iImageRepresentation_L : module | |
| 4 | +{ | |
| 5 | + iImageRepresentation_obj : adt | |
| 6 | + { | |
| 7 | + cl_mod : ClassModule; | |
| 8 | + watchers : JObject; # type java.lang.Vector; | |
| 9 | + pData : int; | |
| 10 | + src : JObject; # type sun.awt.image.InputStreamImageSource | |
| 11 | + image : JObject; # type sun.awt.image.Image | |
| 12 | + tag : int; | |
| 13 | + srcW : int; | |
| 14 | + srcH : int; | |
| 15 | + width : int; | |
| 16 | + height : int; | |
| 17 | + hints : int; | |
| 18 | + availinfo : int; | |
| 19 | + offscreen : byte; | |
| 20 | + newbits : JObject; # type java.awt.Rectangle | |
| 21 | + consuming : byte; | |
| 22 | + numWaiters : int; | |
| 23 | + finalnext : JObject; # type sun.awt.AWTFinalizeable | |
| 24 | + piImage : ref Draw->Image; | |
| 25 | + }; | |
| 26 | + | |
| 27 | + init : fn( jni_p : JNI ); | |
| 28 | + offscreenInit_rColor_V : fn( this : ref iImageRepresentation_obj, p0 : JObject); | |
| 29 | + setBytePixels_I_I_I_I_rColorModel_aB_I_I_Z : fn( this : ref iImageRepresentation_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : JObject,p5 : JArrayB,p6 : int,p7 : int) : int; | |
| 30 | + setIntPixels_I_I_I_I_rColorModel_aI_I_I_Z : fn( this : ref iImageRepresentation_obj, p0 : int,p1 : int,p2 : int,p3 : int,p4 : JObject,p5 : JArrayI,p6 : int,p7 : int) : int; | |
| 31 | + finish_Z_Z : fn( this : ref iImageRepresentation_obj, p0 : int) : int; | |
| 32 | + imageDraw_rGraphics_I_I_rColor_V : fn( this : ref iImageRepresentation_obj, p0 : JObject,p1 : int,p2 : int,p3 : JObject); | |
| 33 | + imageStretch_rGraphics_I_I_I_I_I_I_I_I_rColor_V : fn( this : ref iImageRepresentation_obj, p0 : JObject,p1 : int,p2 : int,p3 : int,p4 : int,p5 : int,p6 : int,p7 : int,p8 : int,p9 : JObject); | |
| 34 | + disposeImage_V : fn( this : ref iImageRepresentation_obj); | |
| 35 | + | |
| 36 | +}; | |
| @@ -0,0 +1,180 @@ | ||
| 1 | +implement iImage_L; | |
| 2 | + | |
| 3 | +# javal v1.5 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | + | |
| 27 | +# | |
| 28 | +# %W% - %E% | |
| 29 | +# | |
| 30 | + | |
| 31 | +#<< | |
| 32 | + | |
| 33 | +include "iImage_L.m"; | |
| 34 | + | |
| 35 | +#>> extra post includes here | |
| 36 | + | |
| 37 | +draw : Draw; | |
| 38 | + | |
| 39 | +#include "image2enc.m"; | |
| 40 | +# image2enc : Image2enc; | |
| 41 | + | |
| 42 | +include "imagefile.m"; | |
| 43 | + readimg : RImagefile; | |
| 44 | + imageremap : Imageremap; | |
| 45 | + | |
| 46 | +include "bufio.m"; | |
| 47 | + B :Bufio; | |
| 48 | + | |
| 49 | +#<< | |
| 50 | + | |
| 51 | +init( jni_p : JNI ) | |
| 52 | +{ | |
| 53 | + # save java native inteface mod instance | |
| 54 | + jni = jni_p; | |
| 55 | + #>>extra initialization here | |
| 56 | + #<< | |
| 57 | +} | |
| 58 | + | |
| 59 | +getImage_V( this : ref iImage_obj) | |
| 60 | +{#>> | |
| 61 | + # Open a file descriptor from which we can read a picture. | |
| 62 | + # | |
| 63 | + file : string; | |
| 64 | + fd : ref Sys->FD; | |
| 65 | + if ( this.file != nil ) { | |
| 66 | + file = this.file.str; | |
| 67 | + fd = jni->sys->open(file, Sys->OREAD); | |
| 68 | + if ( fd == nil ) | |
| 69 | + jni->ThrowException("java/io/IOException", jni->sys->sprint("%r")); | |
| 70 | + } | |
| 71 | + else if ( this.url != nil ) { # Try to open a network connection | |
| 72 | + # file = some component of the URL | |
| 73 | + return; # later. | |
| 74 | + } | |
| 75 | + else | |
| 76 | + return; | |
| 77 | + | |
| 78 | + B = load Bufio Bufio->PATH; | |
| 79 | + if ( B == nil ) | |
| 80 | + return; | |
| 81 | + | |
| 82 | + iobuf := B->fopen(fd, Bufio->OREAD); | |
| 83 | + if ( (imagetype := guesstype(file)) == nil ) | |
| 84 | + return; | |
| 85 | + | |
| 86 | + imgarr : array of byte; | |
| 87 | + (this.width, this.height, imgarr) = convert_img(iobuf, imagetype); | |
| 88 | + this.imgbytes = jni->MkAByte(imgarr); | |
| 89 | +}#<< | |
| 90 | + | |
| 91 | +# | |
| 92 | +# Guess the file type from the suffix | |
| 93 | +# | |
| 94 | +guesstype(name : string) : string | |
| 95 | +{ | |
| 96 | + imagetype : string; | |
| 97 | + (nil, suffix) := jni->str->splitr(name, "."); | |
| 98 | + case suffix { | |
| 99 | + "gif" => imagetype = "IMAGE/GIF"; | |
| 100 | + "pic" => imagetype = "IMAGE/PICT"; | |
| 101 | + "jpg" or "jpeg" => imagetype = "IMAGE/JPEG"; | |
| 102 | + "bit" or "mask" => imagetype = "IMAGE/X-INFERNO-BIT"; | |
| 103 | + "xbm" or "xbmp" => imagetype = "IMAGE/X-XBITMAP"; | |
| 104 | + } | |
| 105 | + return imagetype; | |
| 106 | +} | |
| 107 | + | |
| 108 | +# | |
| 109 | +# Convert the image into the Inferno bit format | |
| 110 | +# Return image height, width and the image(array of bytes) | |
| 111 | +# Uses readgif.b/readjpg.b/readxbitmap.b/readpic.b and image2enc.b | |
| 112 | +# | |
| 113 | +convert_img(fd : ref Bufio->Iobuf, imagetype: string): (int, int, array of byte) | |
| 114 | +{ | |
| 115 | + # Initialization | |
| 116 | + | |
| 117 | + case imagetype { | |
| 118 | + "IMAGE/GIF" => readimg = load RImagefile RImagefile->READGIFPATH; | |
| 119 | + "IMAGE/JPEG" => readimg = load RImagefile RImagefile->READJPGPATH; | |
| 120 | + "IMAGE/X-XBITMAP" => readimg = load RImagefile RImagefile->READXBMPATH; | |
| 121 | + "IMAGE/X-PICT" => readimg = load RImagefile RImagefile->READPICPATH; | |
| 122 | + "IMAGE/X-INFERNO-BIT" => # What to do here? | |
| 123 | + * => return(-1,-1,nil); | |
| 124 | + } | |
| 125 | + | |
| 126 | + if ( readimg == nil ) | |
| 127 | + return(-1,-1,nil); | |
| 128 | + | |
| 129 | + readimg->init(B); | |
| 130 | + rawimg : ref RImagefile->Rawimage; | |
| 131 | + | |
| 132 | + # Read image [gif/jpg/xbm/pic] | |
| 133 | + err_readimg: string; | |
| 134 | + (rawimg, err_readimg) = readimg->read(fd); | |
| 135 | + readimg = nil; # memory control | |
| 136 | + | |
| 137 | + # Error check | |
| 138 | + if (err_readimg != "" ) { | |
| 139 | + return(-1,-1,nil); | |
| 140 | + } | |
| 141 | + | |
| 142 | + # Image2enc | |
| 143 | +# image2enc = load Image2enc Image2enc->PATH; | |
| 144 | +# if ( image2enc == nil ) | |
| 145 | +# return (-1, -1, nil); | |
| 146 | +# (data, mask, err_enc) := image2enc->image2enc(rawimg, 1); | |
| 147 | + | |
| 148 | + # Error check | |
| 149 | +# if (err_enc != "" ) { | |
| 150 | +# return(-1,-1,nil); | |
| 151 | +# } | |
| 152 | + | |
| 153 | + # Masking | |
| 154 | +# if (mask != nil) { | |
| 155 | +# newdata := array[len data + len mask] of byte; | |
| 156 | +# newdata[0:] = data[0:]; | |
| 157 | +# newdata[len data:] = mask[0:]; | |
| 158 | +# data = newdata; | |
| 159 | +# } | |
| 160 | + | |
| 161 | + # Make Inferno image | |
| 162 | + imageremap = load Imageremap Imageremap->PATH; | |
| 163 | + draw = load Draw Draw->PATH; | |
| 164 | + Image, Context : import draw; | |
| 165 | + if ( imageremap == nil || draw == nil ) | |
| 166 | + return (-1, -1, nil); | |
| 167 | + (img, err_remap) := imageremap->remap(rawimg, jni->getContext().display, 0); | |
| 168 | + if ( img == nil ) | |
| 169 | + return (-1, -1, nil); | |
| 170 | + | |
| 171 | + # Determine image size | |
| 172 | + wd := (rawimg.r.max.x - rawimg.r.min.x); | |
| 173 | + ht := (rawimg.r.max.y - rawimg.r.min.y); | |
| 174 | + | |
| 175 | + data := array[wd*ht] of byte; # what if depth != 3 ? | |
| 176 | + img.readpixels(img.r, data); | |
| 177 | + | |
| 178 | + # Return width, height and image | |
| 179 | + return(wd, ht, data); | |
| 180 | +} | |
| @@ -0,0 +1,26 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | + | |
| 5 | +# javal v1.5 generated file: edit with care | |
| 6 | + | |
| 7 | +iImage_L : module | |
| 8 | +{ | |
| 9 | + iImage_obj : adt | |
| 10 | + { | |
| 11 | + cl_mod : ClassModule; | |
| 12 | + width : int; | |
| 13 | + height : int; | |
| 14 | + file : JString; | |
| 15 | + url : JObject; | |
| 16 | + imgbytes : JArrayB; | |
| 17 | + properties : JObject; | |
| 18 | + q : JObject; | |
| 19 | + consumers : JObject; | |
| 20 | + fd : ref Sys->FD; | |
| 21 | + }; | |
| 22 | + | |
| 23 | + init : fn( jni_p : JNI ); | |
| 24 | + getImage_V : fn( this : ref iImage_obj); | |
| 25 | + | |
| 26 | +}; | |
| @@ -0,0 +1,906 @@ | ||
| 1 | +package inferno.awt; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.awt.event.*; | |
| 5 | +import java.awt.peer.*; | |
| 6 | + | |
| 7 | +public class iMenuBarPeer implements | |
| 8 | +MenuBarPeer,MouseListener,MouseMotionListener,zMenuParent { | |
| 9 | + MenuBar target; | |
| 10 | + int height; | |
| 11 | + zMenuBarObject selectedMenuObject; | |
| 12 | + zMenuBarObject menuObjects[]; | |
| 13 | + int menuObjectCount; | |
| 14 | + Window child; | |
| 15 | + | |
| 16 | + public void closeChild(Window w) | |
| 17 | + { | |
| 18 | + // Called from child via zMenuParent interface to | |
| 19 | + // close itself down. Since Window may take some time to | |
| 20 | + // close down, check to see if we are still the child window | |
| 21 | + // not the previous window | |
| 22 | + if (child!=null && child==w) | |
| 23 | + { | |
| 24 | + | |
| 25 | + child.setVisible(false); // Hide Window | |
| 26 | + child.dispose(); // Destroy window | |
| 27 | + child=null; // Lose reference to Window | |
| 28 | + if (selectedMenuObject!=null) | |
| 29 | + { | |
| 30 | + // If menu item selected, display not selected | |
| 31 | + Frame frm=(Frame)target.getParent(); | |
| 32 | + Graphics g=frm.getGraphics(); | |
| 33 | + selectedMenuObject.paint(g,0); | |
| 34 | + g.dispose(); | |
| 35 | + } | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + public void closeEverything() | |
| 40 | + { | |
| 41 | + // Close our child | |
| 42 | + closeChild(child); | |
| 43 | + } | |
| 44 | + | |
| 45 | + void create(Frame f) | |
| 46 | + { | |
| 47 | + // Calculate sizes | |
| 48 | + recalculate(); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public iMenuBarPeer(MenuBar target) { | |
| 52 | + Frame frm=(Frame)target.getParent(); | |
| 53 | + frm.addMouseListener(this); | |
| 54 | + frm.addMouseMotionListener(this); | |
| 55 | + this.target = target; | |
| 56 | + create(frm); | |
| 57 | + } | |
| 58 | + | |
| 59 | + // Required by MenuBarPeer interface but not used | |
| 60 | + public void dispose() | |
| 61 | + { | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void addMenu(Menu m) { | |
| 65 | + // Calculate sizes | |
| 66 | + recalculate(); | |
| 67 | + } | |
| 68 | + | |
| 69 | + public void delMenu(int index) { | |
| 70 | + // Calculate sizes | |
| 71 | + recalculate(); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public void addHelpMenu(Menu m) { | |
| 75 | + // Calculate sizes | |
| 76 | + recalculate(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + // Calculate height of menubar | |
| 80 | + public int getHeight() | |
| 81 | + { | |
| 82 | + height=0; | |
| 83 | + | |
| 84 | + if (target!=null) | |
| 85 | + { | |
| 86 | + Frame frm=(Frame)target.getParent(); | |
| 87 | + for (int i=target.getMenuCount()-1;i>=0;--i) | |
| 88 | + { | |
| 89 | + Menu m=target.getMenu(i); | |
| 90 | + Font f=m.getFont(); | |
| 91 | + FontMetrics fm=frm.getFontMetrics(f); | |
| 92 | + | |
| 93 | + height=Math.max(height,fm.getHeight()+2); | |
| 94 | + } | |
| 95 | + } | |
| 96 | + return height; | |
| 97 | + } | |
| 98 | + | |
| 99 | + public void recalculate() | |
| 100 | + { | |
| 101 | + // Create all the objects | |
| 102 | + if (target!=null) | |
| 103 | + { | |
| 104 | + Frame frm=(Frame)target.getParent(); | |
| 105 | + Rectangle d=frm.getBounds(); | |
| 106 | + Insets is=frm.getInsets(); | |
| 107 | + Menu hm=target.getHelpMenu(); | |
| 108 | + | |
| 109 | + selectedMenuObject=null; | |
| 110 | + menuObjects=null; | |
| 111 | + menuObjectCount=target.getMenuCount(); | |
| 112 | + if (menuObjectCount!=0) | |
| 113 | + { | |
| 114 | + int x=is.left; | |
| 115 | + int y=is.top-height; | |
| 116 | + menuObjects=new zMenuBarObject[menuObjectCount]; | |
| 117 | + | |
| 118 | + | |
| 119 | + for (int i=0;i<menuObjectCount;i++) | |
| 120 | + { | |
| 121 | + int w,xx; | |
| 122 | + Menu m=target.getMenu(i); | |
| 123 | + Font f=m.getFont(); | |
| 124 | + if (f==null) | |
| 125 | + { | |
| 126 | + w=0; | |
| 127 | + xx=0; | |
| 128 | + } | |
| 129 | + else | |
| 130 | + { | |
| 131 | + FontMetrics fm=frm.getFontMetrics(f); | |
| 132 | + w=fm.stringWidth(" "+m.getLabel()+" ")+2; | |
| 133 | + | |
| 134 | + if (m==hm) | |
| 135 | + { | |
| 136 | + xx=d.width-is.right-w; | |
| 137 | + } | |
| 138 | + else | |
| 139 | + { | |
| 140 | + xx=x; | |
| 141 | + x+=w; | |
| 142 | + } | |
| 143 | + | |
| 144 | + } | |
| 145 | + menuObjects[i]=new zMenuBarObject(m,new Rectangle(xx,y,w,height)); | |
| 146 | + | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + } | |
| 151 | + } | |
| 152 | + | |
| 153 | + // Not the Component paint but similar | |
| 154 | + // called from Frame.paint | |
| 155 | + public void paint(Graphics gg) | |
| 156 | + { | |
| 157 | + Frame frm=(Frame)target.getParent(); | |
| 158 | + Insets is=frm.getInsets(); | |
| 159 | + Rectangle d=frm.getBounds(); | |
| 160 | + int y=is.top-height; | |
| 161 | + int x=is.left; | |
| 162 | + int w=d.width-is.left-is.right; | |
| 163 | + int h=height; | |
| 164 | + Graphics g=gg.create(); | |
| 165 | + | |
| 166 | + // Display the menu objects | |
| 167 | + g.setClip(x,y,w,h); | |
| 168 | + g.setColor(SystemColor.menu); | |
| 169 | + g.fillRect(x,y,w,h); | |
| 170 | + | |
| 171 | + for (int i=0;i<menuObjectCount;i++) | |
| 172 | + menuObjects[i].paint(g); | |
| 173 | + | |
| 174 | + | |
| 175 | + g.dispose(); | |
| 176 | + } | |
| 177 | + | |
| 178 | + public void mouseExited(MouseEvent e) | |
| 179 | + { | |
| 180 | + // Deselect if mouse exits window | |
| 181 | + // (Almost certainly never called by inferno) | |
| 182 | + if (selectedMenuObject!=null) | |
| 183 | + { | |
| 184 | + Frame frm=(Frame)target.getParent(); | |
| 185 | + Graphics g=frm.getGraphics(); | |
| 186 | + selectedMenuObject.paint(g,0); | |
| 187 | + selectedMenuObject=null; | |
| 188 | + g.dispose(); | |
| 189 | + } | |
| 190 | + } | |
| 191 | + | |
| 192 | + // Required by listener interface but not used | |
| 193 | + public void mouseEntered(MouseEvent e) | |
| 194 | + { | |
| 195 | + } | |
| 196 | + | |
| 197 | + // Required by listener interface but not used | |
| 198 | + public void mouseClicked(MouseEvent e) | |
| 199 | + { | |
| 200 | + } | |
| 201 | + | |
| 202 | + public void mousePressed(MouseEvent e) | |
| 203 | + { | |
| 204 | + // If within an object (selectMenuObject set by mouseMove) | |
| 205 | + if (selectedMenuObject!=null && selectedMenuObject.area.contains(e.getPoint())) | |
| 206 | + { | |
| 207 | + Frame frm=(Frame)target.getParent(); | |
| 208 | + Graphics g=frm.getGraphics(); | |
| 209 | + selectedMenuObject.paint(g,-1); | |
| 210 | + g.dispose(); | |
| 211 | + | |
| 212 | + Menu menu=selectedMenuObject.menu; | |
| 213 | + if(menu != null){ | |
| 214 | + Rectangle md=selectedMenuObject.area; | |
| 215 | + Rectangle fd=frm.getBounds(); | |
| 216 | + int xoff=md.x; | |
| 217 | + int yoff=md.y+md.height; | |
| 218 | + | |
| 219 | + closeChild(child); | |
| 220 | + child=new zMenuWindow(frm,this,menu,xoff,yoff); | |
| 221 | + child.pack(); | |
| 222 | + child.setVisible(true); | |
| 223 | + } | |
| 224 | + } | |
| 225 | + else | |
| 226 | + { | |
| 227 | + // Close child window (if any) | |
| 228 | + if (child != null) | |
| 229 | + closeChild(child); | |
| 230 | + // Display deselected | |
| 231 | + if(selectedMenuObject != null){ | |
| 232 | + Frame frm=(Frame)target.getParent(); | |
| 233 | + Graphics g=frm.getGraphics(); | |
| 234 | + selectedMenuObject.paint(g,0); | |
| 235 | + g.dispose(); | |
| 236 | + } | |
| 237 | + } | |
| 238 | + } | |
| 239 | + | |
| 240 | + // Require by listener interface but not used | |
| 241 | + public void mouseReleased(MouseEvent e) | |
| 242 | + { | |
| 243 | + } | |
| 244 | + | |
| 245 | + public void mouseMoved(MouseEvent e) | |
| 246 | + { | |
| 247 | + // Track the mouse movement over the menuObjects | |
| 248 | + // setting selectedMenuObject as appropriate | |
| 249 | + if (selectedMenuObject==null || | |
| 250 | + !selectedMenuObject.area.contains(e.getPoint())) | |
| 251 | + { | |
| 252 | + Frame frm=(Frame)target.getParent(); | |
| 253 | + Graphics g=frm.getGraphics(); | |
| 254 | + // if (selectedMenuObject!=null && child==null) | |
| 255 | + if (selectedMenuObject!=null) | |
| 256 | + { | |
| 257 | + selectedMenuObject.paint(g,0); | |
| 258 | + selectedMenuObject=null; | |
| 259 | + } | |
| 260 | + | |
| 261 | + for (int i=0;i<menuObjectCount;i++) | |
| 262 | + if (menuObjects[i].area.contains(e.getPoint())) | |
| 263 | + { | |
| 264 | + if (selectedMenuObject!=null) | |
| 265 | + { | |
| 266 | + selectedMenuObject.paint(g,0); | |
| 267 | + selectedMenuObject=null; | |
| 268 | + } | |
| 269 | + if (menuObjects[i].menu.isEnabled()) | |
| 270 | + { | |
| 271 | + int mode=1; | |
| 272 | + selectedMenuObject=menuObjects[i]; | |
| 273 | + if (child!=null) | |
| 274 | + { | |
| 275 | + Menu menu=selectedMenuObject.menu; | |
| 276 | + Rectangle md=selectedMenuObject.area; | |
| 277 | + Rectangle fd=frm.getBounds(); | |
| 278 | + int xoff=md.x; | |
| 279 | + int yoff=md.y+md.height; | |
| 280 | + | |
| 281 | + Window newChild=new zMenuWindow(frm,this,menu,xoff,yoff); | |
| 282 | + newChild.pack(); | |
| 283 | + newChild.setVisible(true); | |
| 284 | + closeChild(child); | |
| 285 | + child=newChild; | |
| 286 | + mode=-1; | |
| 287 | + } | |
| 288 | + | |
| 289 | + selectedMenuObject.paint(g,mode); | |
| 290 | + } | |
| 291 | + break; | |
| 292 | + } | |
| 293 | + | |
| 294 | + g.dispose(); | |
| 295 | + } | |
| 296 | + } | |
| 297 | + | |
| 298 | + // Require by listener interface but not used | |
| 299 | + public void mouseDragged(MouseEvent e) | |
| 300 | + { | |
| 301 | + } | |
| 302 | + | |
| 303 | + | |
| 304 | +} | |
| 305 | + | |
| 306 | +// This is the object corresponding to the menu items | |
| 307 | +// on the menubar | |
| 308 | +class zMenuBarObject { | |
| 309 | + Menu menu; | |
| 310 | + Rectangle area; | |
| 311 | + int mode; | |
| 312 | + | |
| 313 | + public zMenuBarObject(Menu menu,Rectangle area) | |
| 314 | + { | |
| 315 | + this.menu=menu; | |
| 316 | + this.area=area; | |
| 317 | + this.mode=0; | |
| 318 | + } | |
| 319 | + | |
| 320 | + public void paint(Graphics g,int mode) | |
| 321 | + { | |
| 322 | + this.mode=mode; | |
| 323 | + paint(g); | |
| 324 | + } | |
| 325 | + | |
| 326 | + // Not the component paint but similar | |
| 327 | + // displays the menu item | |
| 328 | + public void paint(Graphics g) | |
| 329 | + { | |
| 330 | + Font f=menu.getFont(); | |
| 331 | + FontMetrics fm=g.getFontMetrics(f); | |
| 332 | + | |
| 333 | + g.setColor(SystemColor.menu); | |
| 334 | + | |
| 335 | + if (mode!=0) | |
| 336 | + Misc.fill3DRect(area,mode>0,g); | |
| 337 | + else | |
| 338 | + g.fillRect(area.x,area.y,area.width,area.height); | |
| 339 | + | |
| 340 | + g.translate(-mode,-mode); | |
| 341 | + | |
| 342 | + g.setFont(f); | |
| 343 | + if (menu.isEnabled()) | |
| 344 | + { | |
| 345 | + g.setColor(SystemColor.menuText); | |
| 346 | + g.drawString(" "+menu.getLabel(),area.x+1,area.y+fm.getAscent()+1); | |
| 347 | + } | |
| 348 | + else | |
| 349 | + { | |
| 350 | + Misc.drawDisabledString(" "+menu.getLabel(),area.x+1,area.y+fm.getAscent()+1,g); | |
| 351 | + | |
| 352 | + } | |
| 353 | + | |
| 354 | + g.translate(+mode,+mode); | |
| 355 | + | |
| 356 | + } | |
| 357 | + | |
| 358 | +} | |
| 359 | + | |
| 360 | +// This the window containing the dropdown menus | |
| 361 | +// the painting is done by zMenuDisplay | |
| 362 | +// zMenuDisplay returns its size and the Window sizes itself | |
| 363 | +// accordingly | |
| 364 | + | |
| 365 | +class zMenuWindow extends Window implements ComponentListener,zMenuParent{ | |
| 366 | + zMenuDisplay menudisplay; | |
| 367 | + zMenuParent ancestor; | |
| 368 | + int xoffset,yoffset; | |
| 369 | + | |
| 370 | + public zMenuWindow(Frame f,zMenuParent ancestor,Menu menu,int xoffset,int yoffset) | |
| 371 | +{ | |
| 372 | + super(f); | |
| 373 | + this.xoffset=xoffset; | |
| 374 | + this.yoffset=yoffset; | |
| 375 | + this.ancestor=ancestor; | |
| 376 | + Point p=f.getLocation(); | |
| 377 | + p.translate(this.xoffset,this.yoffset); | |
| 378 | + setLocation(p); | |
| 379 | + f.addComponentListener(this); | |
| 380 | + this.menudisplay=new zMenuDisplay(menu); | |
| 381 | + add(this.menudisplay,BorderLayout.CENTER); | |
| 382 | + } | |
| 383 | + | |
| 384 | + public void closeChild(Window w) | |
| 385 | + { | |
| 386 | + if (menudisplay!=null) | |
| 387 | + { | |
| 388 | + if (!menudisplay.gotFocus() && ancestor!=null) | |
| 389 | + ancestor.closeChild(this); | |
| 390 | + else | |
| 391 | + menudisplay.closeChild(w); | |
| 392 | + } | |
| 393 | + } | |
| 394 | + | |
| 395 | + public void closeEverything() | |
| 396 | +{ | |
| 397 | + if (ancestor!=null) | |
| 398 | + ancestor.closeEverything(); | |
| 399 | +} | |
| 400 | + | |
| 401 | + public boolean gotFocus() | |
| 402 | + { | |
| 403 | + if (menudisplay==null) | |
| 404 | + return false; | |
| 405 | + else | |
| 406 | + return menudisplay.gotFocus(); | |
| 407 | + | |
| 408 | + } | |
| 409 | + | |
| 410 | + public void componentHidden(ComponentEvent e) | |
| 411 | + { | |
| 412 | + | |
| 413 | + } | |
| 414 | + | |
| 415 | + public void componentMoved(ComponentEvent e) | |
| 416 | + { | |
| 417 | + Point p=e.getComponent().getLocation(); | |
| 418 | + p.translate(xoffset,yoffset); | |
| 419 | + setLocation(p); | |
| 420 | + } | |
| 421 | + | |
| 422 | + public void componentResized(ComponentEvent e) | |
| 423 | + { | |
| 424 | + | |
| 425 | + } | |
| 426 | + | |
| 427 | + public void componentShown(ComponentEvent e) | |
| 428 | + { | |
| 429 | + | |
| 430 | + } | |
| 431 | + | |
| 432 | + public void dispose() | |
| 433 | + { | |
| 434 | + if (menudisplay!=null) | |
| 435 | + { | |
| 436 | + menudisplay.closeChild(this); | |
| 437 | + } | |
| 438 | + super.dispose(); | |
| 439 | + } | |
| 440 | + | |
| 441 | +} | |
| 442 | + | |
| 443 | +// This is the display part of the zMenuWindow | |
| 444 | +// it covers the whole window | |
| 445 | + | |
| 446 | +class zMenuDisplay extends Canvas implements | |
| 447 | +MouseListener,MouseMotionListener, | |
| 448 | +FocusListener{ | |
| 449 | + zMenuObject menuObjects[]; | |
| 450 | + zMenuObject selectedMenuObject; | |
| 451 | + zMenuWindow child; | |
| 452 | + int menuObjectCount; | |
| 453 | + Dimension pSize; | |
| 454 | + boolean focus; | |
| 455 | + Menu menu; | |
| 456 | + static Color highlight = SystemColor.controlHighlight; | |
| 457 | + static Color light = SystemColor.controlLtHighlight; | |
| 458 | + static Color medium = SystemColor.controlShadow; | |
| 459 | + static Color dark = SystemColor.controlDkShadow; | |
| 460 | + | |
| 461 | + | |
| 462 | + static final int TickBoxSize=13; | |
| 463 | + | |
| 464 | + static final int TickLabelGap=4; | |
| 465 | + | |
| 466 | + static final int SeparatorHeight=6; | |
| 467 | + | |
| 468 | + | |
| 469 | + public zMenuDisplay(Menu menu) | |
| 470 | + | |
| 471 | + { | |
| 472 | + super(); | |
| 473 | + setMenu(menu); | |
| 474 | + addMouseListener(this); | |
| 475 | + addMouseMotionListener(this); | |
| 476 | + addFocusListener(this); | |
| 477 | + } | |
| 478 | + | |
| 479 | + public boolean isFocusTraversable() { | |
| 480 | + return false; | |
| 481 | + } | |
| 482 | + | |
| 483 | + | |
| 484 | + void setMenu(Menu menu) | |
| 485 | + | |
| 486 | + { | |
| 487 | + | |
| 488 | + int maxwidth=0; | |
| 489 | + | |
| 490 | + int yy=4; | |
| 491 | + | |
| 492 | + int xx=4; | |
| 493 | + | |
| 494 | + this.menu=menu; | |
| 495 | + | |
| 496 | + | |
| 497 | + menuObjectCount=menu.getItemCount(); | |
| 498 | + | |
| 499 | + | |
| 500 | + selectedMenuObject=null; | |
| 501 | + | |
| 502 | + | |
| 503 | + if (menuObjectCount==0) | |
| 504 | + | |
| 505 | + menuObjects=null; | |
| 506 | + | |
| 507 | + else | |
| 508 | + | |
| 509 | + { | |
| 510 | + | |
| 511 | + menuObjects=new zMenuObject[menuObjectCount]; | |
| 512 | + | |
| 513 | + | |
| 514 | + boolean submenu=false; | |
| 515 | + | |
| 516 | + for (int i=0;i<menuObjectCount;i++) | |
| 517 | + | |
| 518 | + { | |
| 519 | + | |
| 520 | + MenuItem mi=menu.getItem(i); | |
| 521 | + | |
| 522 | + String label=mi.getLabel(); | |
| 523 | + if (!submenu && mi instanceof Menu) submenu=true; | |
| 524 | + | |
| 525 | + | |
| 526 | + if (!label.equals("-")) | |
| 527 | + | |
| 528 | + { | |
| 529 | + | |
| 530 | + Font f=mi.getFont(); | |
| 531 | + | |
| 532 | + FontMetrics fm=getFontMetrics(f); | |
| 533 | + | |
| 534 | + | |
| 535 | + maxwidth=Math.max(maxwidth,TickBoxSize+TickLabelGap+fm.stringWidth(label)); | |
| 536 | + | |
| 537 | + | |
| 538 | + } | |
| 539 | + | |
| 540 | + | |
| 541 | + } | |
| 542 | + | |
| 543 | + maxwidth+=2; // For outside lines | |
| 544 | + | |
| 545 | + if (submenu) maxwidth+=8; | |
| 546 | + | |
| 547 | + for (int i=0;i<menuObjectCount;i++) | |
| 548 | + { | |
| 549 | + | |
| 550 | + MenuItem mi=menu.getItem(i); | |
| 551 | + | |
| 552 | + String label=mi.getLabel(); | |
| 553 | + int h; | |
| 554 | + | |
| 555 | + | |
| 556 | + if (label.equals("-")) | |
| 557 | + { | |
| 558 | + h=SeparatorHeight; // Height | |
| 559 | + | |
| 560 | + menuObjects[i]=new zMenuSeparator(new Rectangle(xx,yy,maxwidth,h)); | |
| 561 | + | |
| 562 | + } | |
| 563 | + else | |
| 564 | + { | |
| 565 | + Font f=mi.getFont(); | |
| 566 | + FontMetrics fm=getFontMetrics(f); | |
| 567 | + h=Math.max(fm.getHeight(),TickBoxSize)+4; //Height | |
| 568 | + | |
| 569 | + menuObjects[i]=new zMenuText(mi,new Rectangle(xx,yy,maxwidth,h)); | |
| 570 | + | |
| 571 | + } | |
| 572 | + | |
| 573 | + yy+=h; | |
| 574 | + | |
| 575 | + | |
| 576 | + } | |
| 577 | + | |
| 578 | + | |
| 579 | + } | |
| 580 | + | |
| 581 | + pSize=new Dimension(xx+maxwidth+4,yy+4); | |
| 582 | + | |
| 583 | + } | |
| 584 | + | |
| 585 | + | |
| 586 | + public Dimension getPreferredSize() | |
| 587 | + | |
| 588 | + { | |
| 589 | + | |
| 590 | + return pSize; | |
| 591 | + | |
| 592 | + } | |
| 593 | + | |
| 594 | + | |
| 595 | + public void paint(Graphics g) | |
| 596 | + { | |
| 597 | + Dimension d=getSize(); | |
| 598 | + | |
| 599 | + g.setColor(SystemColor.menu); | |
| 600 | + | |
| 601 | + Misc.Draw3DArea(0,0,d.width,d.height,g); | |
| 602 | + | |
| 603 | + for (int i=0;i<menuObjectCount;i++) | |
| 604 | + menuObjects[i].paint(g,0); | |
| 605 | + | |
| 606 | + } | |
| 607 | + | |
| 608 | + void closeChild() | |
| 609 | + { | |
| 610 | + closeChild(child); | |
| 611 | + } | |
| 612 | + | |
| 613 | + void closeChild(Window w) | |
| 614 | + { | |
| 615 | + if (w!=null && w == child) | |
| 616 | + { | |
| 617 | + w.setVisible(false); | |
| 618 | + w.dispose(); | |
| 619 | + w=null; | |
| 620 | + } | |
| 621 | + if (child!=null) | |
| 622 | + { | |
| 623 | + child.setVisible(false); | |
| 624 | + child.dispose(); | |
| 625 | + child = null; | |
| 626 | + } | |
| 627 | + } | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + // Required by listener interface but not used | |
| 632 | + public void mouseClicked(MouseEvent e) | |
| 633 | + { | |
| 634 | + } | |
| 635 | + | |
| 636 | + // Required by listener interface but not used | |
| 637 | + public void mouseEntered(MouseEvent e) | |
| 638 | + { | |
| 639 | + } | |
| 640 | + | |
| 641 | + // Required by listener interface but not used | |
| 642 | + public void mouseExited(MouseEvent e) | |
| 643 | + { | |
| 644 | + } | |
| 645 | + | |
| 646 | + // Required by listener interface but not used | |
| 647 | + public void mousePressed(MouseEvent e) | |
| 648 | + { | |
| 649 | + } | |
| 650 | + | |
| 651 | + public void mouseReleased(MouseEvent e) | |
| 652 | + { | |
| 653 | + if (selectedMenuObject!=null && selectedMenuObject instanceof zMenuText) | |
| 654 | + { | |
| 655 | + MenuItem menuItem=((zMenuText)selectedMenuObject).item; | |
| 656 | + if (menuItem.isEnabled() && !(menuItem instanceof Menu)) | |
| 657 | + { | |
| 658 | + String actionCommand=menuItem.getActionCommand(); | |
| 659 | + iToolkit.postEvent(new ActionEvent(menuItem, ActionEvent.ACTION_PERFORMED, | |
| 660 | + actionCommand)); | |
| 661 | + zMenuWindow w=(zMenuWindow)getParent(); | |
| 662 | + Frame f=(Frame)w.getParent(); | |
| 663 | + f.requestFocus(); | |
| 664 | + w.closeEverything(); | |
| 665 | + } | |
| 666 | + } | |
| 667 | + } | |
| 668 | + | |
| 669 | + public void mouseMoved(MouseEvent e) | |
| 670 | + { | |
| 671 | + if (!focus) | |
| 672 | + { | |
| 673 | + focus=true; | |
| 674 | + requestFocus(); | |
| 675 | + } | |
| 676 | + | |
| 677 | + if (selectedMenuObject==null || | |
| 678 | + !selectedMenuObject.area.contains(e.getPoint())) | |
| 679 | + { | |
| 680 | + Graphics g=getGraphics(); | |
| 681 | + if (selectedMenuObject!=null) | |
| 682 | + { | |
| 683 | + selectedMenuObject.paint(g,0); | |
| 684 | + selectedMenuObject=null; | |
| 685 | + closeChild(child); | |
| 686 | + } | |
| 687 | + for (int i=0;i<menuObjectCount;i++) | |
| 688 | + if (menuObjects[i].area.contains(e.getPoint())) | |
| 689 | + { | |
| 690 | + int mode=1; | |
| 691 | + | |
| 692 | + selectedMenuObject=menuObjects[i]; | |
| 693 | + if (selectedMenuObject instanceof zMenuText) | |
| 694 | + { | |
| 695 | + zMenuText mo=(zMenuText)selectedMenuObject; | |
| 696 | + | |
| 697 | + if (mo.item.isEnabled()) | |
| 698 | + { | |
| 699 | + zMenuWindow w=(zMenuWindow)getParent(); | |
| 700 | + Frame f=(Frame)w.getParent(); | |
| 701 | + | |
| 702 | + if (mo.item instanceof Menu) | |
| 703 | + { | |
| 704 | + int xx=w.xoffset+mo.area.x+mo.area.width; | |
| 705 | + int yy=w.yoffset+mo.area.y; | |
| 706 | + Menu menu=(Menu)mo.item; | |
| 707 | + | |
| 708 | + mode=-1; | |
| 709 | + | |
| 710 | + zMenuWindow newChild=new zMenuWindow(f,w,menu,xx,yy); | |
| 711 | + newChild.pack(); | |
| 712 | + newChild.setVisible(true); | |
| 713 | + closeChild(child); | |
| 714 | + child=newChild; | |
| 715 | + } | |
| 716 | + } | |
| 717 | + selectedMenuObject.paint(g,mode); | |
| 718 | + } | |
| 719 | + break; | |
| 720 | + } | |
| 721 | + | |
| 722 | + g.dispose(); | |
| 723 | + } | |
| 724 | + } | |
| 725 | + | |
| 726 | + public void mouseDragged(MouseEvent e) | |
| 727 | + { | |
| 728 | + mouseMoved(e); | |
| 729 | + } | |
| 730 | + | |
| 731 | + public boolean gotFocus() | |
| 732 | + { | |
| 733 | + if (focus) | |
| 734 | + return true; | |
| 735 | + else | |
| 736 | + if (child==null) | |
| 737 | + return false; | |
| 738 | + else | |
| 739 | + return child.gotFocus(); | |
| 740 | + | |
| 741 | + } | |
| 742 | + | |
| 743 | + public void focusLost(FocusEvent e) | |
| 744 | + { | |
| 745 | + focus=false; | |
| 746 | + if (!gotFocus()) | |
| 747 | + { | |
| 748 | + zMenuWindow m=(zMenuWindow)getParent(); | |
| 749 | + if (m.ancestor!=null) m.ancestor.closeChild(m); | |
| 750 | + } | |
| 751 | + } | |
| 752 | + | |
| 753 | + public void focusGained(FocusEvent e) | |
| 754 | + { | |
| 755 | + focus=true; | |
| 756 | + | |
| 757 | + } | |
| 758 | + | |
| 759 | +} | |
| 760 | + | |
| 761 | +// base class for the menuObjects | |
| 762 | + | |
| 763 | +abstract class zMenuObject { | |
| 764 | + Rectangle area; | |
| 765 | + | |
| 766 | + public zMenuObject() | |
| 767 | + { | |
| 768 | + } | |
| 769 | + | |
| 770 | + public zMenuObject(Rectangle area) | |
| 771 | + { | |
| 772 | + this.area=area; | |
| 773 | + } | |
| 774 | + | |
| 775 | + public abstract void paint(Graphics g,int mode); | |
| 776 | + | |
| 777 | +} | |
| 778 | + | |
| 779 | +// Standard item item class | |
| 780 | + | |
| 781 | +class zMenuText extends zMenuObject { | |
| 782 | + MenuItem item; | |
| 783 | + | |
| 784 | +public zMenuText(MenuItem item,Rectangle area) | |
| 785 | +{ | |
| 786 | + super(area); | |
| 787 | + this.item=item; | |
| 788 | +} | |
| 789 | + | |
| 790 | + | |
| 791 | +void drawArrow(Graphics g,int x,int y) | |
| 792 | +{ | |
| 793 | + for (int i=0;i<4;i++) | |
| 794 | + { | |
| 795 | + g.drawLine(x,y+i,x+3-i,y+i); | |
| 796 | + if (i!=0) | |
| 797 | + g.drawLine(x,y-i,x+3-i,y-i); | |
| 798 | + } | |
| 799 | +} | |
| 800 | + | |
| 801 | +public void paint(Graphics g,int mode) | |
| 802 | +{ | |
| 803 | + Font f=item.getFont(); | |
| 804 | + FontMetrics fm=g.getFontMetrics(f); | |
| 805 | + int fa=fm.getAscent(); | |
| 806 | + boolean enabled=item.isEnabled(); | |
| 807 | + boolean submenu=item instanceof Menu; | |
| 808 | + boolean checked=(item instanceof CheckboxMenuItem? | |
| 809 | + ((CheckboxMenuItem)item).getState():false); | |
| 810 | + String s=item.getLabel(); | |
| 811 | + int xx=area.x; | |
| 812 | + int yy=area.y; | |
| 813 | + | |
| 814 | + g.setFont(f); | |
| 815 | + if (enabled) | |
| 816 | + { | |
| 817 | + g.setColor(SystemColor.menu); | |
| 818 | + if (mode!=0) | |
| 819 | + Misc.fill3DRect(area,mode>0,g); | |
| 820 | + else | |
| 821 | + g.fillRect(xx,yy,area.width,area.height); | |
| 822 | + | |
| 823 | + xx+=2; | |
| 824 | + yy+=2; | |
| 825 | + g.setColor(SystemColor.menuText); | |
| 826 | + g.translate(-mode,-mode); | |
| 827 | + if (checked) Misc.drawTick(g,xx,yy,zMenuDisplay.TickBoxSize); | |
| 828 | + | |
| 829 | +g.drawString(s,zMenuDisplay.TickBoxSize+zMenuDisplay.TickLabelGap+xx,yy+fa); | |
| 830 | + if (submenu) | |
| 831 | + drawArrow(g,area.x+area.width-6,area.y+area.height/2); | |
| 832 | + g.translate(+mode,+mode); | |
| 833 | + } | |
| 834 | + else | |
| 835 | + { | |
| 836 | + xx+=2; | |
| 837 | + yy+=2; | |
| 838 | + if (checked) | |
| 839 | + { | |
| 840 | + g.setColor(SystemColor.controlLtHighlight); | |
| 841 | + Misc.drawTick(g,xx+1,yy+1,zMenuDisplay.TickBoxSize); | |
| 842 | + g.setColor(SystemColor.controlShadow); | |
| 843 | + Misc.drawTick(g,xx,yy,zMenuDisplay.TickBoxSize); | |
| 844 | + } | |
| 845 | + | |
| 846 | +Misc.drawDisabledString(s,zMenuDisplay.TickBoxSize+zMenuDisplay.TickLabelGap+xx,yy+fa,g); | |
| 847 | + if (submenu) | |
| 848 | + { | |
| 849 | + g.setColor(SystemColor.controlLtHighlight); | |
| 850 | + drawArrow(g,area.x+area.width-6+1,area.y+area.height/2+1); | |
| 851 | + g.setColor(SystemColor.controlShadow); | |
| 852 | + drawArrow(g,area.x+area.width-6,area.y+area.height/2); | |
| 853 | + } | |
| 854 | + } | |
| 855 | + | |
| 856 | + | |
| 857 | +} | |
| 858 | + | |
| 859 | +} | |
| 860 | + | |
| 861 | +// separator bar | |
| 862 | + | |
| 863 | +class zMenuSeparator extends zMenuObject { | |
| 864 | + | |
| 865 | +public zMenuSeparator(Rectangle area) | |
| 866 | +{ | |
| 867 | + super(area); | |
| 868 | +} | |
| 869 | + | |
| 870 | +public void paint(Graphics g,int mode) | |
| 871 | +{ | |
| 872 | + int y=area.y+zMenuDisplay.SeparatorHeight/2-1; | |
| 873 | + | |
| 874 | + g.setColor(zMenuDisplay.medium); | |
| 875 | + g.drawLine(area.x,y,area.x+area.width,y); | |
| 876 | + | |
| 877 | + y+=1; | |
| 878 | + | |
| 879 | + g.setColor(zMenuDisplay.light); | |
| 880 | + g.drawLine(area.x,y,area.x+area.width,y); | |
| 881 | + | |
| 882 | + | |
| 883 | +} | |
| 884 | + | |
| 885 | +} | |
| 886 | + | |
| 887 | +// The interface to look backwards to parent to close ourselves | |
| 888 | + | |
| 889 | +interface zMenuParent { | |
| 890 | + | |
| 891 | + | |
| 892 | + // Called by child (or parent) to close and delete itself | |
| 893 | + public void closeChild(Window W); | |
| 894 | + | |
| 895 | + // Close all the windows back to the menubar | |
| 896 | + public void closeEverything(); | |
| 897 | + | |
| 898 | +} | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| @@ -0,0 +1,33 @@ | ||
| 1 | +/* | |
| 2 | + * %W% - %E% | |
| 3 | + * | |
| 4 | + * Adapted from SunSoft's X11OffScreenImage.java 1.2 97/02/23 | |
| 5 | + */ | |
| 6 | + | |
| 7 | +package inferno.awt; | |
| 8 | + | |
| 9 | +import java.awt.Component; | |
| 10 | +import java.awt.Graphics; | |
| 11 | +import sun.awt.DrawingSurface; | |
| 12 | +import sun.awt.DrawingSurfaceInfo; | |
| 13 | + | |
| 14 | +class iOffScreenImage extends iImage implements DrawingSurface { | |
| 15 | + /** | |
| 16 | + * Construct an image for offscreen rendering to be used with a | |
| 17 | + * given Component. | |
| 18 | + */ | |
| 19 | + public iOffScreenImage(Component c, int w, int h) { | |
| 20 | + super(c, w, h); | |
| 21 | + } | |
| 22 | + | |
| 23 | + public Graphics getGraphics() { | |
| 24 | + Graphics g = new iGraphics(this); | |
| 25 | + initGraphics(g); | |
| 26 | + return g; | |
| 27 | + } | |
| 28 | + | |
| 29 | + // implementation of sun.awt.DrawingSurface's getDrawingSurfaceInfo() | |
| 30 | + public DrawingSurfaceInfo getDrawingSurfaceInfo() { | |
| 31 | + return new iDrawingSurfaceInfo(getImageRep()); | |
| 32 | + } | |
| 33 | +} | |
| @@ -0,0 +1,652 @@ | ||
| 1 | +package inferno.awt; | |
| 2 | + | |
| 3 | +import java.awt.*; | |
| 4 | +import java.applet.*; | |
| 5 | +import java.awt.event.*; | |
| 6 | +import java.awt.peer.*; | |
| 7 | +import inferno.awt.*; | |
| 8 | + | |
| 9 | +public class iPopupMenuPeer implements PopupMenuPeer,zPopupMenuParent { | |
| 10 | + PopupMenu target; | |
| 11 | + Window child; | |
| 12 | + | |
| 13 | + public void show(Event e) | |
| 14 | + { | |
| 15 | + Object o=e.target; | |
| 16 | + | |
| 17 | + if (o instanceof Component) | |
| 18 | + { | |
| 19 | + Component c=(Component)o; | |
| 20 | + Point pc=c.getLocationOnScreen(); | |
| 21 | + Container p; | |
| 22 | + | |
| 23 | + if (c instanceof Container) | |
| 24 | + p=(Container)c; | |
| 25 | + else | |
| 26 | + p=c.getParent(); | |
| 27 | + | |
| 28 | + if (p!=null) | |
| 29 | + { | |
| 30 | + Window w=null; | |
| 31 | + | |
| 32 | + while (true) | |
| 33 | + { | |
| 34 | + if (p instanceof Frame) | |
| 35 | + { | |
| 36 | + Frame f=(Frame)p; | |
| 37 | + | |
| 38 | + Point pf=f.getLocationOnScreen(); | |
| 39 | + | |
| 40 | + closeChild(child); | |
| 41 | + | |
| 42 | + child=new zPopupMenu(f,this,target,pc.x+e.x-pf.x,pc.y+e.y-pf.y); | |
| 43 | + child.pack(); | |
| 44 | + child.setVisible(true); | |
| 45 | + | |
| 46 | + break; | |
| 47 | + } | |
| 48 | + else | |
| 49 | + if (p instanceof Applet) | |
| 50 | + { | |
| 51 | + Applet a=(Applet)p; | |
| 52 | + | |
| 53 | + break; | |
| 54 | + } | |
| 55 | + | |
| 56 | + p=p.getParent(); | |
| 57 | + | |
| 58 | + if (p==null) break; | |
| 59 | + } | |
| 60 | + | |
| 61 | + | |
| 62 | + } | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + } | |
| 67 | + | |
| 68 | + | |
| 69 | + } | |
| 70 | + | |
| 71 | + public void delItem(int item) | |
| 72 | + { | |
| 73 | + | |
| 74 | + } | |
| 75 | + | |
| 76 | + | |
| 77 | + public void addItem(MenuItem item) | |
| 78 | + { | |
| 79 | + | |
| 80 | + } | |
| 81 | + | |
| 82 | + public void addSeparator() | |
| 83 | + { | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void disable() | |
| 87 | + { | |
| 88 | + | |
| 89 | + } | |
| 90 | + | |
| 91 | + public void enable() | |
| 92 | + { | |
| 93 | + | |
| 94 | + } | |
| 95 | + | |
| 96 | + public void setEnabled(boolean state) | |
| 97 | + { | |
| 98 | + | |
| 99 | + } | |
| 100 | + | |
| 101 | + public void setLabel(String label) | |
| 102 | + { | |
| 103 | + | |
| 104 | + } | |
| 105 | + | |
| 106 | + | |
| 107 | + public void closeChild(Window w) | |
| 108 | + { | |
| 109 | + if (child!=null && child==w) | |
| 110 | + { | |
| 111 | + child.setVisible(false); | |
| 112 | + child.dispose(); | |
| 113 | + child=null; | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + public void closeEverything() | |
| 118 | + { | |
| 119 | + closeChild(child); | |
| 120 | + } | |
| 121 | + | |
| 122 | + public iPopupMenuPeer(PopupMenu target) { | |
| 123 | + this.target = target; | |
| 124 | + } | |
| 125 | + | |
| 126 | + public void dispose() | |
| 127 | + { | |
| 128 | + } | |
| 129 | + | |
| 130 | +} | |
| 131 | + | |
| 132 | +class zPopupMenu extends Window implements ComponentListener,zPopupMenuParent{ | |
| 133 | + zPopupMenuDisplay menudisplay; | |
| 134 | + zPopupMenuParent ancestor; | |
| 135 | + int xoffset,yoffset; | |
| 136 | + | |
| 137 | + public zPopupMenu(Frame f,zPopupMenuParent ancestor,Menu menu,int xoffset,int yoffset) | |
| 138 | +{ | |
| 139 | + super(f); | |
| 140 | + this.xoffset=xoffset; | |
| 141 | + this.yoffset=yoffset; | |
| 142 | + this.ancestor=ancestor; | |
| 143 | + Point p=f.getLocation(); | |
| 144 | + p.translate(this.xoffset,this.yoffset); | |
| 145 | + setLocation(p); | |
| 146 | + f.addComponentListener(this); | |
| 147 | + this.menudisplay=new zPopupMenuDisplay(menu); | |
| 148 | + add(this.menudisplay,BorderLayout.CENTER); | |
| 149 | + //System.out.println("zPopupMenu Called: " + this); | |
| 150 | + } | |
| 151 | + | |
| 152 | + public void closeChild(Window w) | |
| 153 | + { | |
| 154 | + if (menudisplay!=null) | |
| 155 | + { | |
| 156 | + if (!menudisplay.gotFocus() && ancestor!=null) | |
| 157 | + ancestor.closeChild(this); | |
| 158 | + else | |
| 159 | + menudisplay.closeChild(w); | |
| 160 | + } | |
| 161 | + } | |
| 162 | + | |
| 163 | + public void closeEverything() | |
| 164 | +{ | |
| 165 | + if (ancestor!=null) | |
| 166 | + ancestor.closeEverything(); | |
| 167 | +} | |
| 168 | + | |
| 169 | + public boolean gotFocus() | |
| 170 | + { | |
| 171 | + if (menudisplay==null) | |
| 172 | + return false; | |
| 173 | + else | |
| 174 | + return menudisplay.gotFocus(); | |
| 175 | + | |
| 176 | + } | |
| 177 | + | |
| 178 | + public void componentHidden(ComponentEvent e) | |
| 179 | + { | |
| 180 | + | |
| 181 | + } | |
| 182 | + | |
| 183 | + public void componentMoved(ComponentEvent e) | |
| 184 | + { | |
| 185 | + Point p=e.getComponent().getLocation(); | |
| 186 | + p.translate(xoffset,yoffset); | |
| 187 | + setLocation(p); | |
| 188 | + } | |
| 189 | + | |
| 190 | + public void componentResized(ComponentEvent e) | |
| 191 | + { | |
| 192 | + | |
| 193 | + } | |
| 194 | + | |
| 195 | + public void componentShown(ComponentEvent e) | |
| 196 | + { | |
| 197 | + | |
| 198 | + } | |
| 199 | + | |
| 200 | + public void dispose() | |
| 201 | + { | |
| 202 | + if (menudisplay!=null) | |
| 203 | + { | |
| 204 | + menudisplay.closeChild(this); | |
| 205 | + } | |
| 206 | + super.dispose(); | |
| 207 | + } | |
| 208 | + | |
| 209 | +} | |
| 210 | + | |
| 211 | +class zPopupMenuDisplay extends Canvas implements | |
| 212 | +MouseListener,MouseMotionListener, | |
| 213 | +FocusListener{ | |
| 214 | + zPopupMenuObject menuObjects[]; | |
| 215 | + zPopupMenuObject selectedMenuObject; | |
| 216 | + zPopupMenu child; | |
| 217 | + int menuObjectCount; | |
| 218 | + Dimension pSize; | |
| 219 | + boolean focus; | |
| 220 | + Menu menu; | |
| 221 | + static Color highlight = SystemColor.controlHighlight; | |
| 222 | + static Color light = SystemColor.controlLtHighlight; | |
| 223 | + static Color medium = SystemColor.controlShadow; | |
| 224 | + static Color dark = SystemColor.controlDkShadow; | |
| 225 | + | |
| 226 | + | |
| 227 | + static final int TickBoxSize=13; | |
| 228 | + | |
| 229 | + static final int TickLabelGap=4; | |
| 230 | + | |
| 231 | + static final int SeparatorHeight=6; | |
| 232 | + | |
| 233 | + | |
| 234 | + public zPopupMenuDisplay(Menu menu) | |
| 235 | + | |
| 236 | + { | |
| 237 | + super(); | |
| 238 | + setMenu(menu); | |
| 239 | + addMouseListener(this); | |
| 240 | + addMouseMotionListener(this); | |
| 241 | + /*addKeyListener(this);*/ | |
| 242 | + addFocusListener(this); | |
| 243 | + | |
| 244 | + } | |
| 245 | + | |
| 246 | + public boolean isFocusTraversable() { | |
| 247 | + return false; | |
| 248 | + } | |
| 249 | + | |
| 250 | + | |
| 251 | + void setMenu(Menu menu) | |
| 252 | + | |
| 253 | + { | |
| 254 | + | |
| 255 | + int maxwidth=0; | |
| 256 | + | |
| 257 | + int yy=4; | |
| 258 | + | |
| 259 | + int xx=4; | |
| 260 | + | |
| 261 | + this.menu=menu; | |
| 262 | + | |
| 263 | + | |
| 264 | + menuObjectCount=menu.getItemCount(); | |
| 265 | + | |
| 266 | + | |
| 267 | + selectedMenuObject=null; | |
| 268 | + | |
| 269 | + | |
| 270 | + if (menuObjectCount==0) | |
| 271 | + | |
| 272 | + menuObjects=null; | |
| 273 | + | |
| 274 | + else | |
| 275 | + | |
| 276 | + { | |
| 277 | + | |
| 278 | + menuObjects=new zPopupMenuObject[menuObjectCount]; | |
| 279 | + | |
| 280 | + | |
| 281 | + boolean submenu=false; | |
| 282 | + | |
| 283 | + for (int i=0;i<menuObjectCount;i++) | |
| 284 | + | |
| 285 | + { | |
| 286 | + | |
| 287 | + MenuItem mi=menu.getItem(i); | |
| 288 | + | |
| 289 | + String label=mi.getLabel(); | |
| 290 | + if (!submenu && mi instanceof Menu) submenu=true; | |
| 291 | + | |
| 292 | + | |
| 293 | + if (!label.equals("-")) | |
| 294 | + | |
| 295 | + { | |
| 296 | + | |
| 297 | + Font f=mi.getFont(); | |
| 298 | + | |
| 299 | + FontMetrics fm=getFontMetrics(f); | |
| 300 | + | |
| 301 | + | |
| 302 | +maxwidth=Math.max(maxwidth,TickBoxSize+TickLabelGap+fm.stringWidth(label)); | |
| 303 | + | |
| 304 | + | |
| 305 | + } | |
| 306 | + | |
| 307 | + | |
| 308 | + } | |
| 309 | + | |
| 310 | + maxwidth+=2; // For outside lines | |
| 311 | + | |
| 312 | + if (submenu) maxwidth+=8; | |
| 313 | + | |
| 314 | + for (int i=0;i<menuObjectCount;i++) | |
| 315 | + { | |
| 316 | + | |
| 317 | + MenuItem mi=menu.getItem(i); | |
| 318 | + | |
| 319 | + String label=mi.getLabel(); | |
| 320 | + int h; | |
| 321 | + | |
| 322 | + | |
| 323 | + if (label.equals("-")) | |
| 324 | + { | |
| 325 | + h=SeparatorHeight; // Height | |
| 326 | + | |
| 327 | + menuObjects[i]=new zPopupMenuSeparator(new Rectangle(xx,yy,maxwidth,h)); | |
| 328 | + | |
| 329 | + } | |
| 330 | + else | |
| 331 | + { | |
| 332 | + Font f=mi.getFont(); | |
| 333 | + FontMetrics fm=getFontMetrics(f); | |
| 334 | + h=Math.max(fm.getHeight(),TickBoxSize)+4; //Height | |
| 335 | + | |
| 336 | + menuObjects[i]=new zPopupMenuText(mi,new Rectangle(xx,yy,maxwidth,h)); | |
| 337 | + | |
| 338 | + } | |
| 339 | + | |
| 340 | + yy+=h; | |
| 341 | + | |
| 342 | + | |
| 343 | + } | |
| 344 | + | |
| 345 | + | |
| 346 | + } | |
| 347 | + | |
| 348 | + pSize=new Dimension(xx+maxwidth+4,yy+4); | |
| 349 | + | |
| 350 | + } | |
| 351 | + | |
| 352 | + | |
| 353 | + public Dimension getPreferredSize() | |
| 354 | + | |
| 355 | + { | |
| 356 | + | |
| 357 | + return pSize; | |
| 358 | + | |
| 359 | + } | |
| 360 | + | |
| 361 | + | |
| 362 | + public void paint(Graphics g) | |
| 363 | + { | |
| 364 | + Dimension d=getSize(); | |
| 365 | + | |
| 366 | + g.setColor(SystemColor.menu); | |
| 367 | + | |
| 368 | + Misc.Draw3DArea(0,0,d.width,d.height,g); | |
| 369 | + | |
| 370 | + for (int i=0;i<menuObjectCount;i++) | |
| 371 | + menuObjects[i].paint(g,0); | |
| 372 | + | |
| 373 | + } | |
| 374 | + | |
| 375 | + void closeChild() | |
| 376 | + { | |
| 377 | + closeChild(child); | |
| 378 | + } | |
| 379 | + | |
| 380 | + void closeChild(Window w) | |
| 381 | + { | |
| 382 | + if (child!=null && child==w) | |
| 383 | + { | |
| 384 | + child.setVisible(false); | |
| 385 | + child.dispose(); | |
| 386 | + child=null; | |
| 387 | + } | |
| 388 | + } | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + public void mouseClicked(MouseEvent e) | |
| 394 | + { | |
| 395 | + } | |
| 396 | + | |
| 397 | + public void mouseEntered(MouseEvent e) | |
| 398 | + { | |
| 399 | + } | |
| 400 | + | |
| 401 | + public void mouseExited(MouseEvent e) | |
| 402 | + { | |
| 403 | + } | |
| 404 | + | |
| 405 | + public void mousePressed(MouseEvent e) | |
| 406 | + { | |
| 407 | + } | |
| 408 | + | |
| 409 | + public void mouseReleased(MouseEvent e) | |
| 410 | + { | |
| 411 | + if (selectedMenuObject!=null && selectedMenuObject instanceof zPopupMenuText) | |
| 412 | + { | |
| 413 | + MenuItem menuItem=((zPopupMenuText)selectedMenuObject).item; | |
| 414 | + if (menuItem.isEnabled() && !(menuItem instanceof Menu)) | |
| 415 | + { | |
| 416 | + String actionCommand=menuItem.getActionCommand(); | |
| 417 | + iToolkit.postEvent(new ActionEvent(menuItem, ActionEvent.ACTION_PERFORMED, | |
| 418 | + actionCommand)); | |
| 419 | + zPopupMenu w=(zPopupMenu)getParent(); | |
| 420 | + Frame f=(Frame)w.getParent(); | |
| 421 | + f.requestFocus(); | |
| 422 | + w.closeEverything(); | |
| 423 | + } | |
| 424 | + } | |
| 425 | + } | |
| 426 | + | |
| 427 | + public void mouseMoved(MouseEvent e) | |
| 428 | + { | |
| 429 | + if (!focus) | |
| 430 | + { | |
| 431 | + focus=true; | |
| 432 | + requestFocus(); | |
| 433 | + } | |
| 434 | + | |
| 435 | + if (selectedMenuObject==null || | |
| 436 | + !selectedMenuObject.area.contains(e.getPoint())) | |
| 437 | + { | |
| 438 | + Graphics g=getGraphics(); | |
| 439 | + if (selectedMenuObject!=null) | |
| 440 | + { | |
| 441 | + selectedMenuObject.paint(g,0); | |
| 442 | + selectedMenuObject=null; | |
| 443 | + closeChild(child); | |
| 444 | + } | |
| 445 | + for (int i=0;i<menuObjectCount;i++) | |
| 446 | + if (menuObjects[i].area.contains(e.getPoint())) | |
| 447 | + { | |
| 448 | + int mode=1; | |
| 449 | + | |
| 450 | + selectedMenuObject=menuObjects[i]; | |
| 451 | + if (selectedMenuObject instanceof zPopupMenuText) | |
| 452 | + { | |
| 453 | + zPopupMenuText mo=(zPopupMenuText)selectedMenuObject; | |
| 454 | + | |
| 455 | + if (mo.item.isEnabled()) | |
| 456 | + { | |
| 457 | + zPopupMenu w=(zPopupMenu)getParent(); | |
| 458 | + Frame f=(Frame)w.getParent(); | |
| 459 | + | |
| 460 | + if (mo.item instanceof Menu) | |
| 461 | + { | |
| 462 | + int xx=w.xoffset+mo.area.x+mo.area.width; | |
| 463 | + int yy=w.yoffset+mo.area.y; | |
| 464 | + Menu menu=(Menu)mo.item; | |
| 465 | + | |
| 466 | + mode=-1; | |
| 467 | + | |
| 468 | + zPopupMenu newChild=new zPopupMenu(f,w,menu,xx,yy); | |
| 469 | + newChild.pack(); | |
| 470 | + newChild.setVisible(true); | |
| 471 | + closeChild(child); | |
| 472 | + child=newChild; | |
| 473 | + | |
| 474 | + } | |
| 475 | + } | |
| 476 | + selectedMenuObject.paint(g,mode); | |
| 477 | + } | |
| 478 | + break; | |
| 479 | + } | |
| 480 | + | |
| 481 | + g.dispose(); | |
| 482 | + } | |
| 483 | + } | |
| 484 | + | |
| 485 | + public void mouseDragged(MouseEvent e) | |
| 486 | + { | |
| 487 | + mouseMoved(e); | |
| 488 | + } | |
| 489 | + | |
| 490 | + public boolean gotFocus() | |
| 491 | + { | |
| 492 | + if (focus) | |
| 493 | + return true; | |
| 494 | + else | |
| 495 | + if (child==null) | |
| 496 | + return false; | |
| 497 | + else | |
| 498 | + return child.gotFocus(); | |
| 499 | + | |
| 500 | + } | |
| 501 | + | |
| 502 | + public void focusLost(FocusEvent e) | |
| 503 | + { | |
| 504 | + focus=false; | |
| 505 | + if (!gotFocus()) | |
| 506 | + { | |
| 507 | + zPopupMenu m=(zPopupMenu)getParent(); | |
| 508 | + if (m.ancestor!=null) m.ancestor.closeChild(m); | |
| 509 | + } | |
| 510 | + } | |
| 511 | + | |
| 512 | + public void focusGained(FocusEvent e) | |
| 513 | + { | |
| 514 | + focus=true; | |
| 515 | + | |
| 516 | + } | |
| 517 | + | |
| 518 | +} | |
| 519 | + | |
| 520 | +abstract class zPopupMenuObject { | |
| 521 | + Rectangle area; | |
| 522 | + | |
| 523 | + public zPopupMenuObject() | |
| 524 | + { | |
| 525 | + } | |
| 526 | + | |
| 527 | + public zPopupMenuObject(Rectangle area) | |
| 528 | + { | |
| 529 | + this.area=area; | |
| 530 | + } | |
| 531 | + | |
| 532 | + public abstract void paint(Graphics g,int mode); | |
| 533 | + | |
| 534 | +} | |
| 535 | + | |
| 536 | +class zPopupMenuText extends zPopupMenuObject { | |
| 537 | + MenuItem item; | |
| 538 | + | |
| 539 | +public zPopupMenuText(MenuItem item,Rectangle area) | |
| 540 | +{ | |
| 541 | + super(area); | |
| 542 | + this.item=item; | |
| 543 | +} | |
| 544 | + | |
| 545 | + | |
| 546 | +void drawArrow(Graphics g,int x,int y) | |
| 547 | +{ | |
| 548 | + for (int i=0;i<4;i++) | |
| 549 | + { | |
| 550 | + g.drawLine(x,y+i,x+3-i,y+i); | |
| 551 | + if (i!=0) | |
| 552 | + g.drawLine(x,y-i,x+3-i,y-i); | |
| 553 | + } | |
| 554 | +} | |
| 555 | + | |
| 556 | +public void paint(Graphics g,int mode) | |
| 557 | +{ | |
| 558 | + Font f=item.getFont(); | |
| 559 | + FontMetrics fm=g.getFontMetrics(f); | |
| 560 | + int fa=fm.getAscent(); | |
| 561 | + boolean enabled=item.isEnabled(); | |
| 562 | + boolean submenu=item instanceof Menu; | |
| 563 | + boolean checked=(item instanceof CheckboxMenuItem? | |
| 564 | + ((CheckboxMenuItem)item).getState():false); | |
| 565 | + String s=item.getLabel(); | |
| 566 | + int xx=area.x; | |
| 567 | + int yy=area.y; | |
| 568 | + | |
| 569 | + g.setFont(f); | |
| 570 | + if (enabled) | |
| 571 | + { | |
| 572 | + g.setColor(SystemColor.menu); | |
| 573 | + if (mode!=0) | |
| 574 | + Misc.fill3DRect(area,mode>0,g); | |
| 575 | + else | |
| 576 | + g.fillRect(xx,yy,area.width,area.height); | |
| 577 | + | |
| 578 | + xx+=2; | |
| 579 | + yy+=2; | |
| 580 | + g.setColor(SystemColor.menuText); | |
| 581 | + g.translate(-mode,-mode); | |
| 582 | + if (checked) Misc.drawTick(g,xx,yy,zPopupMenuDisplay.TickBoxSize); | |
| 583 | + | |
| 584 | +g.drawString(s,zPopupMenuDisplay.TickBoxSize+zPopupMenuDisplay.TickLabelGap+xx,yy+fa); | |
| 585 | + if (submenu) | |
| 586 | + drawArrow(g,area.x+area.width-6,area.y+area.height/2); | |
| 587 | + g.translate(+mode,+mode); | |
| 588 | + } | |
| 589 | + else | |
| 590 | + { | |
| 591 | + xx+=2; | |
| 592 | + yy+=2; | |
| 593 | + if (checked) | |
| 594 | + { | |
| 595 | + g.setColor(SystemColor.controlLtHighlight); | |
| 596 | + Misc.drawTick(g,xx+1,yy+1,zPopupMenuDisplay.TickBoxSize); | |
| 597 | + g.setColor(SystemColor.controlShadow); | |
| 598 | + Misc.drawTick(g,xx,yy,zPopupMenuDisplay.TickBoxSize); | |
| 599 | + } | |
| 600 | + | |
| 601 | + | |
| 602 | +Misc.drawDisabledString(s,zPopupMenuDisplay.TickBoxSize+zPopupMenuDisplay.TickLabelGap+xx,yy+fa,g); | |
| 603 | + if (submenu) | |
| 604 | + { | |
| 605 | + g.setColor(SystemColor.controlLtHighlight); | |
| 606 | + drawArrow(g,area.x+area.width-6+1,area.y+area.height/2+1); | |
| 607 | + g.setColor(SystemColor.controlShadow); | |
| 608 | + drawArrow(g,area.x+area.width-6,area.y+area.height/2); | |
| 609 | + } | |
| 610 | + } | |
| 611 | + | |
| 612 | + | |
| 613 | +} | |
| 614 | + | |
| 615 | +} | |
| 616 | + | |
| 617 | +class zPopupMenuSeparator extends zPopupMenuObject { | |
| 618 | + | |
| 619 | +public zPopupMenuSeparator(Rectangle area) | |
| 620 | +{ | |
| 621 | + super(area); | |
| 622 | +} | |
| 623 | + | |
| 624 | +public void paint(Graphics g,int mode) | |
| 625 | +{ | |
| 626 | + int y=area.y+zPopupMenuDisplay.SeparatorHeight/2-1; | |
| 627 | + | |
| 628 | + g.setColor(zPopupMenuDisplay.medium); | |
| 629 | + g.drawLine(area.x,y,area.x+area.width,y); | |
| 630 | + | |
| 631 | + y+=1; | |
| 632 | + | |
| 633 | + g.setColor(zPopupMenuDisplay.light); | |
| 634 | + g.drawLine(area.x,y,area.x+area.width,y); | |
| 635 | + | |
| 636 | + | |
| 637 | +} | |
| 638 | + | |
| 639 | +} | |
| 640 | + | |
| 641 | +interface zPopupMenuParent { | |
| 642 | + | |
| 643 | + public void closeChild(Window W); | |
| 644 | + | |
| 645 | + public void closeEverything(); | |
| 646 | + | |
| 647 | +} | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| @@ -0,0 +1,303 @@ | ||
| 1 | +/* | |
| 2 | + * %W% - %E% | |
| 3 | + */ | |
| 4 | + | |
| 5 | +package inferno.awt; | |
| 6 | + | |
| 7 | +import java.util.Hashtable; | |
| 8 | +import java.awt.*; | |
| 9 | +import java.awt.Toolkit; | |
| 10 | +import java.awt.image.*; | |
| 11 | +import java.awt.peer.*; | |
| 12 | +import java.awt.event.MouseEvent; | |
| 13 | +import java.awt.datatransfer.Clipboard; | |
| 14 | +import java.io.*; | |
| 15 | +import java.net.URL; | |
| 16 | +import java.util.Properties; | |
| 17 | +import sun.awt.image.*; | |
| 18 | + | |
| 19 | +public class iToolkit extends Toolkit { | |
| 20 | + | |
| 21 | + // System clipboard. | |
| 22 | + Clipboard clipboard; | |
| 23 | + | |
| 24 | + // the system EventQueue | |
| 25 | + protected static EventQueue theEventQueue; | |
| 26 | + | |
| 27 | + public iToolkit() { | |
| 28 | + | |
| 29 | + String eqName = Toolkit.getProperty("AWT.EventQueueClass", | |
| 30 | + "java.awt.EventQueue"); | |
| 31 | + try { | |
| 32 | + theEventQueue = (EventQueue)Class.forName(eqName).newInstance(); | |
| 33 | + } catch (Exception e) { | |
| 34 | + System.err.println("Failed loading " + eqName + ": " + e); | |
| 35 | + theEventQueue = new EventQueue(); | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + protected EventQueue getSystemEventQueueImpl() { | |
| 40 | + return theEventQueue; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public Clipboard getSystemClipboard() { | |
| 44 | + SecurityManager security = System.getSecurityManager(); | |
| 45 | + if (security != null) { | |
| 46 | + security.checkSystemClipboardAccess(); | |
| 47 | + } | |
| 48 | + if (clipboard == null) { | |
| 49 | + //clipboard = new WClipboard(); | |
| 50 | + } | |
| 51 | + return clipboard; | |
| 52 | + } | |
| 53 | + | |
| 54 | + | |
| 55 | + static public void postEvent(AWTEvent event) | |
| 56 | + { | |
| 57 | + // System.out.println("PeekEvent = "+theEventQueue.peekEvent()); | |
| 58 | + theEventQueue.postEvent(event); | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void beep() | |
| 62 | + { | |
| 63 | + | |
| 64 | + } | |
| 65 | + | |
| 66 | + public PrintJob getPrintJob(Frame frame, String doctitle, Properties props) | |
| 67 | + { | |
| 68 | + return null; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public java.awt.Image createImage(byte[] data, int offset, int length) { | |
| 72 | + return createImage(new ByteArrayImageSource(data, offset, length)); | |
| 73 | + } | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + public java.awt.Image createImage(ImageProducer producer) { | |
| 78 | + return null/*new WImage(producer)*/; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public int checkImage(java.awt.Image img, int w, int h, ImageObserver o) { | |
| 82 | + return 0/*checkScrImage(img, w, h, o)*/; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public boolean prepareImage(java.awt.Image img, int w, int h, ImageObserver o) { | |
| 86 | + return false/*prepareScrImage(img, w, h, o)*/; | |
| 87 | + } | |
| 88 | + | |
| 89 | + public java.awt.Image getImage(String filename) { | |
| 90 | + return null/*getImageFromHash(this, filename)*/; | |
| 91 | + } | |
| 92 | + | |
| 93 | + public java.awt.Image getImage(URL url) { | |
| 94 | + return null/*getImageFromHash(this, url)*/; | |
| 95 | + } | |
| 96 | + | |
| 97 | + public void sync() | |
| 98 | + { | |
| 99 | + } | |
| 100 | + | |
| 101 | + public FontMetrics getFontMetrics(Font font) { | |
| 102 | + return iFontMetrics.getFontMetrics(font); | |
| 103 | + } | |
| 104 | + | |
| 105 | + public String[] getFontList() { | |
| 106 | + // REMIND: "Helvetica", "TimesRoman", "Courier" and "ZapfDingbats" | |
| 107 | + // will go awy from this list. | |
| 108 | + String list[] = {"Dialog", "SansSerif", "Serif", "Monospaced", | |
| 109 | + "Helvetica", "TimesRoman", "Courier", | |
| 110 | + "DialogInput", "ZapfDingbats"}; | |
| 111 | + return list; | |
| 112 | + } | |
| 113 | + | |
| 114 | + | |
| 115 | + static native ColorModel makeColorModel(); | |
| 116 | + static ColorModel screenmodel; | |
| 117 | + | |
| 118 | + static ColorModel getStaticColorModel() { | |
| 119 | + if (screenmodel == null) { | |
| 120 | + screenmodel = makeColorModel(); | |
| 121 | + } | |
| 122 | + return screenmodel; | |
| 123 | + } | |
| 124 | + | |
| 125 | + public ColorModel getColorModel() { | |
| 126 | + return getStaticColorModel(); | |
| 127 | + } | |
| 128 | + // nwk+ | |
| 129 | + public native void loadSystemColors(int[] systemColors); | |
| 130 | + // -nwk | |
| 131 | + | |
| 132 | + public Dimension getScreenSize() { | |
| 133 | + return new Dimension(getScreenWidth(), getScreenHeight()); | |
| 134 | + } | |
| 135 | + | |
| 136 | + public int getScreenResolution() | |
| 137 | + { | |
| 138 | + return 96; | |
| 139 | + } | |
| 140 | + | |
| 141 | + protected int getScreenWidth() | |
| 142 | + { | |
| 143 | + return 640; | |
| 144 | + } | |
| 145 | + | |
| 146 | + protected int getScreenHeight() | |
| 147 | + { | |
| 148 | + return 480; | |
| 149 | + } | |
| 150 | + | |
| 151 | + public FontPeer getFontPeer(String name, int style) { | |
| 152 | + return new inferno.awt.iFontPeer(name, style); | |
| 153 | + } | |
| 154 | + | |
| 155 | + /* | |
| 156 | + * Create peer objects. | |
| 157 | + */ | |
| 158 | + | |
| 159 | + public ButtonPeer createButton(Button target) { | |
| 160 | + ButtonPeer peer = null; | |
| 161 | + //ButtonPeer peer = new WButtonPeer(target); | |
| 162 | + //peerMap.put(target, peer); | |
| 163 | + return peer; | |
| 164 | + } | |
| 165 | + | |
| 166 | + public TextFieldPeer createTextField(TextField target) { | |
| 167 | + TextFieldPeer peer = null; | |
| 168 | + //TextFieldPeer peer = new WTextFieldPeer(target); | |
| 169 | + //peerMap.put(target, peer); | |
| 170 | + return peer; | |
| 171 | + } | |
| 172 | + | |
| 173 | + public LabelPeer createLabel(Label target) { | |
| 174 | + LabelPeer peer = null; | |
| 175 | + //LabelPeer peer = new WLabelPeer(target); | |
| 176 | + //peerMap.put(target, peer); | |
| 177 | + return peer; | |
| 178 | + } | |
| 179 | + | |
| 180 | + public ListPeer createList(List target) { | |
| 181 | + ListPeer peer = null; | |
| 182 | + //ListPeer peer = new WListPeer(target); | |
| 183 | + //peerMap.put(target, peer); | |
| 184 | + return peer; | |
| 185 | + } | |
| 186 | + | |
| 187 | + public CheckboxPeer createCheckbox(Checkbox target) { | |
| 188 | + CheckboxPeer peer = null; | |
| 189 | + //CheckboxPeer peer = new WCheckboxPeer(target); | |
| 190 | + //peerMap.put(target, peer); | |
| 191 | + return peer; | |
| 192 | + } | |
| 193 | + | |
| 194 | + public ScrollbarPeer createScrollbar(Scrollbar target) { | |
| 195 | + ScrollbarPeer peer = null; | |
| 196 | + //ScrollbarPeer peer = new WScrollbarPeer(target); | |
| 197 | + //peerMap.put(target, peer); | |
| 198 | + return peer; | |
| 199 | + } | |
| 200 | + | |
| 201 | + public ScrollPanePeer createScrollPane(ScrollPane target) { | |
| 202 | + ScrollPanePeer peer = null; | |
| 203 | + //ScrollPanePeer peer = new WScrollPanePeer(target); | |
| 204 | + //peerMap.put(target, peer); | |
| 205 | + return peer; | |
| 206 | + } | |
| 207 | + | |
| 208 | + public TextAreaPeer createTextArea(TextArea target) { | |
| 209 | + TextAreaPeer peer = null; | |
| 210 | + //TextAreaPeer peer = new WTextAreaPeer(target); | |
| 211 | + //peerMap.put(target, peer); | |
| 212 | + return peer; | |
| 213 | + } | |
| 214 | + | |
| 215 | + public ChoicePeer createChoice(Choice target) { | |
| 216 | + ChoicePeer peer = null; | |
| 217 | + //ChoicePeer peer = new WChoicePeer(target); | |
| 218 | + //peerMap.put(target, peer); | |
| 219 | + return peer; | |
| 220 | + } | |
| 221 | + | |
| 222 | + public FramePeer createFrame(Frame target) { | |
| 223 | +// FramePeer peer = null; | |
| 224 | + FramePeer peer = new iFramePeer(target); | |
| 225 | + //peerMap.put(target, peer); | |
| 226 | + return peer; | |
| 227 | + } | |
| 228 | + | |
| 229 | + public CanvasPeer createCanvas(Canvas target) { | |
| 230 | + CanvasPeer peer = null; | |
| 231 | + //CanvasPeer peer = new WCanvasPeer(target); | |
| 232 | + //peerMap.put(target, peer); | |
| 233 | + return peer; | |
| 234 | + } | |
| 235 | + | |
| 236 | + public PanelPeer createPanel(Panel target) { | |
| 237 | + PanelPeer peer = null; | |
| 238 | + //PanelPeer peer = new WPanelPeer(target); | |
| 239 | + //peerMap.put(target, peer); | |
| 240 | + return peer; | |
| 241 | + } | |
| 242 | + | |
| 243 | + public WindowPeer createWindow(Window target) { | |
| 244 | + // WindowPeer peer = null; | |
| 245 | + WindowPeer peer = new iWindowPeer(target); | |
| 246 | + //peerMap.put(target, peer); | |
| 247 | + return peer; | |
| 248 | + } | |
| 249 | + | |
| 250 | + public DialogPeer createDialog(Dialog target) { | |
| 251 | + DialogPeer peer = null; | |
| 252 | + //DialogPeer peer = new WDialogPeer(target); | |
| 253 | + //peerMap.put(target, peer); | |
| 254 | + return peer; | |
| 255 | + } | |
| 256 | + | |
| 257 | + public FileDialogPeer createFileDialog(FileDialog target) { | |
| 258 | + FileDialogPeer peer = null; | |
| 259 | + //FileDialogPeer peer = new WFileDialogPeer(target); | |
| 260 | + //peerMap.put(target, peer); | |
| 261 | + return peer; | |
| 262 | + } | |
| 263 | + | |
| 264 | + public MenuBarPeer createMenuBar(MenuBar target) { | |
| 265 | + MenuBarPeer peer = new iMenuBarPeer(target); | |
| 266 | + //peerMap.put(target, peer); | |
| 267 | + return peer; | |
| 268 | +// return null; | |
| 269 | + } | |
| 270 | + | |
| 271 | + public MenuPeer createMenu(Menu target) { | |
| 272 | + MenuPeer peer = null; | |
| 273 | + //MenuPeer peer = new WMenuPeer(target); | |
| 274 | + //peerMap.put(target, peer); | |
| 275 | + return peer; | |
| 276 | + } | |
| 277 | + | |
| 278 | + public PopupMenuPeer createPopupMenu(PopupMenu target) { | |
| 279 | + //PopupMenuPeer peer = null; | |
| 280 | + PopupMenuPeer peer = new iPopupMenuPeer(target); | |
| 281 | + //peerMap.put(target, peer); | |
| 282 | + return peer; | |
| 283 | + } | |
| 284 | + | |
| 285 | + public MenuItemPeer createMenuItem(MenuItem target) { | |
| 286 | + MenuItemPeer peer = null; | |
| 287 | + //MenuItemPeer peer = new WMenuItemPeer(target); | |
| 288 | + //peerMap.put(target, peer); | |
| 289 | + return peer; | |
| 290 | + } | |
| 291 | + | |
| 292 | + public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) { | |
| 293 | + CheckboxMenuItemPeer peer = null; | |
| 294 | + //CheckboxMenuItemPeer peer = new WCheckboxMenuItemPeer(target); | |
| 295 | + //peerMap.put(target, peer); | |
| 296 | + return peer; | |
| 297 | + } | |
| 298 | + | |
| 299 | + | |
| 300 | +} | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| @@ -0,0 +1,85 @@ | ||
| 1 | +implement iToolkit_L; | |
| 2 | + | |
| 3 | +# javal v1.5 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | + | |
| 27 | +# | |
| 28 | +# %W% - %E% | |
| 29 | +# | |
| 30 | + draw: Draw; | |
| 31 | + Context, Display, Image: import draw; | |
| 32 | + | |
| 33 | +include "java/lang/ClassLoader_L.m"; | |
| 34 | +include "awt_Color.m"; | |
| 35 | + awt : AwtColor; | |
| 36 | + | |
| 37 | +sys : import jni; | |
| 38 | +ctxt : ref Context; | |
| 39 | + | |
| 40 | +#<< | |
| 41 | + | |
| 42 | +include "iToolkit_L.m"; | |
| 43 | + | |
| 44 | +#>> extra post includes here | |
| 45 | + | |
| 46 | +#<< | |
| 47 | + | |
| 48 | +init( jni_p : JNI ) | |
| 49 | +{ | |
| 50 | + # save java native inteface mod instance | |
| 51 | + jni = jni_p; | |
| 52 | + #>>extra initialization here | |
| 53 | + sys = jni->sys; | |
| 54 | + ctxt = jni->getContext(); | |
| 55 | + awt = load AwtColor AwtColor->PATH; | |
| 56 | + if (awt == nil) { | |
| 57 | + sys->print("could not load %s: %r\n", AwtColor->PATH); | |
| 58 | + return; | |
| 59 | + } | |
| 60 | + #<< | |
| 61 | +} | |
| 62 | + | |
| 63 | +makeColorModel_rColorModel( this : ref iToolkit_obj ) : JObject | |
| 64 | +{#>> | |
| 65 | + if (ctxt == nil) { | |
| 66 | + sys->print("iToolkit_L: Can't makeColorModel - nil context\n"); | |
| 67 | + return nil; | |
| 68 | + } | |
| 69 | + | |
| 70 | + junk := this; | |
| 71 | + ldepth := ctxt.display.image.ldepth; | |
| 72 | + bits := 1<<ldepth; | |
| 73 | + jobj := awt->makeColorModel(jni, bits); | |
| 74 | + return jobj; | |
| 75 | +}#<< | |
| 76 | + | |
| 77 | +## nwk+ | |
| 78 | +loadSystemColors_aI_V( this : ref iToolkit_obj, p0 : JArrayI) | |
| 79 | +{#>> | |
| 80 | + junk := this; | |
| 81 | + | |
| 82 | + awt->loadSystemColors(jni, p0); | |
| 83 | + return; | |
| 84 | +}#<< | |
| 85 | +## -nwk | |
| @@ -0,0 +1,19 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | + | |
| 5 | +# javal v1.5 generated file: edit with care | |
| 6 | + | |
| 7 | +iToolkit_L : module | |
| 8 | +{ | |
| 9 | + iToolkit_obj : adt | |
| 10 | + { | |
| 11 | + cl_mod : ClassModule; | |
| 12 | + clipboard : JObject; | |
| 13 | + }; | |
| 14 | + | |
| 15 | + init : fn( jni_p : JNI ); | |
| 16 | + makeColorModel_rColorModel : fn( this : ref iToolkit_obj ) : JObject; | |
| 17 | + loadSystemColors_aI_V : fn( this : ref iToolkit_obj, p0 : JArrayI); | |
| 18 | + | |
| 19 | +}; | |
| @@ -0,0 +1,411 @@ | ||
| 1 | +/* | |
| 2 | + * %W% - %E% | |
| 3 | + */ | |
| 4 | + | |
| 5 | +package inferno.awt; | |
| 6 | + | |
| 7 | +import java.awt.*; | |
| 8 | +import java.awt.event.*; | |
| 9 | +import java.awt.peer.*; | |
| 10 | +import java.awt.image.ImageProducer; | |
| 11 | +import java.awt.image.ImageObserver; | |
| 12 | +import java.awt.image.ColorModel; | |
| 13 | +import java.awt.image.DirectColorModel; | |
| 14 | +import java.util.*; | |
| 15 | +import inferno.awt.iGraphics; | |
| 16 | + | |
| 17 | +public class iWindowPeer implements WindowPeer, DoubleBufferingPeer { | |
| 18 | + Object pCanvas; // Set inside create() | |
| 19 | + Window target; | |
| 20 | + int leftInset=0; // How much canvas is inset from window | |
| 21 | + int rightInset=0; | |
| 22 | + int topInset=0; | |
| 23 | + int bottomInset=0; | |
| 24 | + int left; // x position of left of window | |
| 25 | + int top; // y position of top of window | |
| 26 | + | |
| 27 | + private Point oldMousePoint; | |
| 28 | + private boolean buttonState[]; | |
| 29 | + | |
| 30 | + public iWindowPeer(Window target) { | |
| 31 | + this.target = target; | |
| 32 | + oldMousePoint=new Point(-1,-1); | |
| 33 | + buttonState=new boolean[3]; | |
| 34 | + for (int i=0;i<3;i++) buttonState[i]=false; //up | |
| 35 | + create(this); | |
| 36 | + Font f = target.getFont(); | |
| 37 | + if (f == null) { | |
| 38 | + f = new Font("Dialog", Font.PLAIN, 12); | |
| 39 | + target.setFont(f); | |
| 40 | + setFont(f); | |
| 41 | + } | |
| 42 | + Color c = target.getBackground(); | |
| 43 | + if (c == null) { | |
| 44 | + c = SystemColor.window; | |
| 45 | + target.setBackground(c); | |
| 46 | + setBackground(c); | |
| 47 | + } | |
| 48 | + c = target.getForeground(); | |
| 49 | + if (c == null) { | |
| 50 | + target.setForeground(Color.black); | |
| 51 | + setForeground(Color.black); | |
| 52 | + } | |
| 53 | + | |
| 54 | + } | |
| 55 | + | |
| 56 | + /* implementation of java.awt.peer.DoubleBufferingPeer */ | |
| 57 | + public boolean isDoubleBuffered() { | |
| 58 | + return true; | |
| 59 | + } | |
| 60 | + | |
| 61 | + native Object getRefImage(); // Returns $Draw->Image of canvas | |
| 62 | + native Object getRefOffScreenImage(); // Returns off-screen buffer image | |
| 63 | + | |
| 64 | + native void pReshape(int x, int y, int width, int height); | |
| 65 | + | |
| 66 | + native void pHide(); // Hide window | |
| 67 | + | |
| 68 | + native void pShow(iWindowPeer fp); // Show window | |
| 69 | + | |
| 70 | + native int getXYLoc(int coord); // get x or y value of the global position | |
| 71 | + | |
| 72 | + public native void create(iWindowPeer fp); // Create window putting canvas in pcanvas | |
| 73 | + | |
| 74 | + public native void pDispose(); // Destroy window | |
| 75 | + | |
| 76 | + public native void setCursor(int cursorType); // Set cursor | |
| 77 | + | |
| 78 | + | |
| 79 | + /* New 1.1 API */ | |
| 80 | + public Point getLocationOnScreen() // Return position on screen | |
| 81 | + { | |
| 82 | + Point p = new Point(); | |
| 83 | + p.x = getXYLoc(0); | |
| 84 | + p.y = getXYLoc(1); | |
| 85 | + return p; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public void setCursor(Cursor c) | |
| 89 | + { | |
| 90 | + if (c!=null) | |
| 91 | + setCursor(c.getType()); | |
| 92 | + } | |
| 93 | + | |
| 94 | + public native void toFront(); // Move window to front | |
| 95 | + | |
| 96 | + public native void toBack(); // Move window to back | |
| 97 | + | |
| 98 | + public Insets getInsets() | |
| 99 | + { | |
| 100 | + Insets i=new Insets(topInset,leftInset,bottomInset,rightInset); | |
| 101 | + return i; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public Insets insets() | |
| 105 | + { | |
| 106 | + return getInsets(); | |
| 107 | + } | |
| 108 | + | |
| 109 | + public void endValidate() | |
| 110 | + { | |
| 111 | + | |
| 112 | + } | |
| 113 | + | |
| 114 | + public void beginValidate() | |
| 115 | + { | |
| 116 | + | |
| 117 | + } | |
| 118 | + | |
| 119 | + public void setBounds(int x, int y, int width, int height) { | |
| 120 | + pReshape(x, y, width, height); | |
| 121 | + } | |
| 122 | + | |
| 123 | + public void reshape(int x, int y, int width, int height) { | |
| 124 | + pReshape(x, y, width, height); | |
| 125 | + } | |
| 126 | + | |
| 127 | + | |
| 128 | + public void dispose() | |
| 129 | + { | |
| 130 | + pDispose(); | |
| 131 | + pCanvas=null; | |
| 132 | + } | |
| 133 | + | |
| 134 | + public void disable() | |
| 135 | + { | |
| 136 | + setEnabled(false); | |
| 137 | + } | |
| 138 | + | |
| 139 | + public void enable() | |
| 140 | + { | |
| 141 | + setEnabled(false); | |
| 142 | + } | |
| 143 | + | |
| 144 | + public void setEnabled(boolean b) | |
| 145 | + { | |
| 146 | + | |
| 147 | + } | |
| 148 | + | |
| 149 | + public void hide() | |
| 150 | + { | |
| 151 | + setVisible(false); | |
| 152 | + } | |
| 153 | + | |
| 154 | + public void show() | |
| 155 | + { | |
| 156 | + setVisible(true); | |
| 157 | + } | |
| 158 | + | |
| 159 | + public void setVisible(boolean b) | |
| 160 | + { | |
| 161 | + if (b) | |
| 162 | + pShow(this); | |
| 163 | + else | |
| 164 | + pHide(); | |
| 165 | + } | |
| 166 | + | |
| 167 | + public Dimension getMinimumSize() { | |
| 168 | + return target.getSize(); | |
| 169 | + } | |
| 170 | + | |
| 171 | + public Dimension getPreferredSize() { | |
| 172 | + return getMinimumSize(); | |
| 173 | + } | |
| 174 | + | |
| 175 | + public Dimension minimumSize() { | |
| 176 | + return getMinimumSize(); | |
| 177 | + } | |
| 178 | + | |
| 179 | + public Dimension preferredSize() { | |
| 180 | + return getPreferredSize(); | |
| 181 | + } | |
| 182 | + | |
| 183 | + | |
| 184 | + public int checkImage(Image img, int w, int h, ImageObserver o) { | |
| 185 | + return 0; | |
| 186 | + } | |
| 187 | + | |
| 188 | + public FontMetrics getFontMetrics(Font font) { | |
| 189 | + return iFontMetrics.getFontMetrics(font); | |
| 190 | + } | |
| 191 | + | |
| 192 | + public boolean prepareImage(Image img, int w, int h, ImageObserver o) { | |
| 193 | + return false; | |
| 194 | + } | |
| 195 | + | |
| 196 | + | |
| 197 | + public Image createImage(ImageProducer producer) { | |
| 198 | + return null/*new Win32Image(producer)*/; | |
| 199 | + } | |
| 200 | + public Image createImage(int width, int height) { | |
| 201 | + return null/*new Win32Image(target, width, height)*/; | |
| 202 | + } | |
| 203 | + | |
| 204 | + public boolean isFocusTraversable() { | |
| 205 | + return false; | |
| 206 | + } | |
| 207 | + | |
| 208 | + public void requestFocus() | |
| 209 | + { | |
| 210 | + } | |
| 211 | + | |
| 212 | + public void nextFocus() | |
| 213 | + { | |
| 214 | + } | |
| 215 | + | |
| 216 | + public void setFont(Font f) | |
| 217 | + { | |
| 218 | + | |
| 219 | + } | |
| 220 | + | |
| 221 | + public Font getFont() | |
| 222 | + { | |
| 223 | + return null; | |
| 224 | + } | |
| 225 | + | |
| 226 | + public void setBackground(Color c) | |
| 227 | + { | |
| 228 | + | |
| 229 | + } | |
| 230 | + | |
| 231 | + public void setForeground(Color c) | |
| 232 | + { | |
| 233 | + | |
| 234 | + } | |
| 235 | + | |
| 236 | + public Graphics getGraphics() | |
| 237 | + { | |
| 238 | + if (pCanvas == null) { | |
| 239 | + System.out.println("iWindowPeer:getGraphics()s: pCanvas == null, continuing!"); // jfs -remove | |
| 240 | + return null; | |
| 241 | + } | |
| 242 | + Rectangle bounds = target.getBounds(); | |
| 243 | + Rectangle clip = new Rectangle(bounds.x+leftInset, | |
| 244 | + bounds.y+topInset, | |
| 245 | + bounds.width-leftInset-rightInset, | |
| 246 | + bounds.height-topInset-bottomInset); | |
| 247 | + Graphics g=new iGraphics(getRefImage(),getRefOffScreenImage(), clip, | |
| 248 | +target); | |
| 249 | + g.translate(bounds.x,bounds.y); | |
| 250 | + return g; | |
| 251 | + } | |
| 252 | + | |
| 253 | + public java.awt.Toolkit getToolkit() { | |
| 254 | + // XXX: bogus | |
| 255 | + return Toolkit.getDefaultToolkit(); | |
| 256 | + } | |
| 257 | + | |
| 258 | + public ColorModel getColorModel() { | |
| 259 | + return iToolkit.getStaticColorModel(); | |
| 260 | + } | |
| 261 | + | |
| 262 | + public void handleEvent(AWTEvent e) | |
| 263 | + { | |
| 264 | + | |
| 265 | + } | |
| 266 | + | |
| 267 | + public void print(Graphics g) | |
| 268 | + { | |
| 269 | + } | |
| 270 | + | |
| 271 | + public void paint(Graphics g) | |
| 272 | + { | |
| 273 | + g.setColor(target.getForeground()); | |
| 274 | + g.setFont(target.getFont()); | |
| 275 | + target.paint(g); | |
| 276 | + } | |
| 277 | + | |
| 278 | + | |
| 279 | + public void repaint(long tm, int x, int y, int width, int height) { | |
| 280 | + iToolkit.postEvent(new PaintEvent((Component)target, PaintEvent.UPDATE, | |
| 281 | + new Rectangle(x, y, width, height))); | |
| 282 | + | |
| 283 | + } | |
| 284 | + | |
| 285 | + public void handleKeyEvents(int ch) | |
| 286 | + { | |
| 287 | + char keyChar = (char)ch; | |
| 288 | + boolean control = ch >= 0 && ch <= 31; | |
| 289 | + boolean lowercase = ch >= (int)'a' && ch <= (int)'z'; | |
| 290 | + boolean uppercase = ch >= (int)'A' && ch <= (int)'Z'; | |
| 291 | + int modifiers = control?InputEvent.CTRL_MASK: | |
| 292 | + uppercase?InputEvent.SHIFT_MASK:0; | |
| 293 | + int keyCode = control?ch+64:lowercase?ch-32:ch; | |
| 294 | + Date d = new Date(); | |
| 295 | + long when = d.getTime(); | |
| 296 | + | |
| 297 | + iToolkit.postEvent(new KeyEvent(target,KeyEvent.KEY_PRESSED, | |
| 298 | + when,modifiers,keyCode,keyChar)); | |
| 299 | + | |
| 300 | + } | |
| 301 | + | |
| 302 | +private void handleMouseEvents(int m,int button,int x,int y) | |
| 303 | +{ | |
| 304 | + char mode=(char)m; | |
| 305 | + // System.out.println("Mouse event "+mode+" "+button+" "+x+" "+y); | |
| 306 | + switch(mode) | |
| 307 | + { | |
| 308 | + case 'd': | |
| 309 | + case 'r': | |
| 310 | + case 'm': | |
| 311 | + case 'p': | |
| 312 | + Rectangle bounds = target.getBounds(); | |
| 313 | + int xx=x-bounds.x-leftInset; | |
| 314 | + int yy=y-bounds.y; // -topInset; | |
| 315 | + | |
| 316 | + Point mousePoint=new Point(xx,yy); | |
| 317 | + //Date d = new Date(); | |
| 318 | + //long when = d.getTime(); | |
| 319 | + long when=0; | |
| 320 | + int modifier; | |
| 321 | + | |
| 322 | + switch(button) | |
| 323 | + { | |
| 324 | + case 1: | |
| 325 | + modifier=InputEvent.BUTTON1_MASK; | |
| 326 | + break; | |
| 327 | + | |
| 328 | + case 2: | |
| 329 | + modifier=InputEvent.BUTTON2_MASK; | |
| 330 | + break; | |
| 331 | + | |
| 332 | + case 3: | |
| 333 | + modifier=InputEvent.BUTTON3_MASK; | |
| 334 | + break; | |
| 335 | + | |
| 336 | + default: | |
| 337 | + modifier=0; | |
| 338 | + } | |
| 339 | + | |
| 340 | + switch(mode) | |
| 341 | + { | |
| 342 | + case 'p': // Pressed | |
| 343 | + case 'd': // Double click | |
| 344 | + { | |
| 345 | + if (button>0 && button<=3 && buttonState[button-1]==false) | |
| 346 | + { | |
| 347 | + oldMousePoint=mousePoint; | |
| 348 | + buttonState[button-1]=true; | |
| 349 | + iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_PRESSED, | |
| 350 | + when,modifier,xx,yy,1,false)); | |
| 351 | + | |
| 352 | + } | |
| 353 | + break; | |
| 354 | + } | |
| 355 | + case 'r': // Released | |
| 356 | + { | |
| 357 | + if (button>0 && button<=3 && buttonState[button-1]==true) | |
| 358 | + { | |
| 359 | + buttonState[button-1]=false; | |
| 360 | + iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_RELEASED, | |
| 361 | + when,modifier,xx,yy,1,false)); | |
| 362 | + if (mousePoint.equals(oldMousePoint)) | |
| 363 | + { | |
| 364 | + iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_CLICKED, | |
| 365 | + when,modifier,xx,yy,1,button==2)); | |
| 366 | + } | |
| 367 | + } | |
| 368 | + break; | |
| 369 | + } | |
| 370 | + case 'm': // Moved | |
| 371 | + { | |
| 372 | + modifier=0; | |
| 373 | + if (buttonState[0]) modifier|=InputEvent.BUTTON1_MASK; | |
| 374 | + if (buttonState[1]) modifier|=InputEvent.BUTTON2_MASK; | |
| 375 | + if (buttonState[2]) modifier|=InputEvent.BUTTON3_MASK; | |
| 376 | + iToolkit.postEvent(new MouseEvent(target, | |
| 377 | + modifier==0?MouseEvent.MOUSE_MOVED:MouseEvent.MOUSE_DRAGGED, | |
| 378 | + when,modifier,xx,yy,1,false)); | |
| 379 | + | |
| 380 | + break; | |
| 381 | + } | |
| 382 | + default: | |
| 383 | + // System.out.println("MouseString: " + mouseString); | |
| 384 | + } | |
| 385 | + break; | |
| 386 | + } | |
| 387 | +} | |
| 388 | + | |
| 389 | + private void movesize(int x, int y, int width, int height) | |
| 390 | + { | |
| 391 | + Rectangle old = target.getBounds(); | |
| 392 | + Rectangle n = new Rectangle(x, y, width, height); | |
| 393 | + if (!n.equals(old)){ | |
| 394 | + target.setBounds(x, y, width, height); | |
| 395 | + target.repaint(); | |
| 396 | + } | |
| 397 | + } | |
| 398 | + | |
| 399 | + public void handleFocusGained() | |
| 400 | + { | |
| 401 | + | |
| 402 | + } | |
| 403 | +} | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| @@ -0,0 +1,377 @@ | ||
| 1 | +implement iWindowPeer_L; | |
| 2 | + | |
| 3 | +include "jni.m"; | |
| 4 | + jni : JNI; | |
| 5 | + ClassModule, | |
| 6 | + JString, | |
| 7 | + JArray, | |
| 8 | + JArrayI, | |
| 9 | + JArrayC, | |
| 10 | + JArrayB, | |
| 11 | + JArrayS, | |
| 12 | + JArrayJ, | |
| 13 | + JArrayF, | |
| 14 | + JArrayD, | |
| 15 | + JArrayZ, | |
| 16 | + JArrayJObject, | |
| 17 | + JArrayJClass, | |
| 18 | + JArrayJString, | |
| 19 | + JClass, | |
| 20 | + JObject : import jni; | |
| 21 | + | |
| 22 | +#>> extra pre includes here | |
| 23 | +# | |
| 24 | +# %W% - %E% | |
| 25 | +# | |
| 26 | + cast : Cast; | |
| 27 | + sys : Sys; | |
| 28 | + draw: Draw; | |
| 29 | + Context, Screen, Display, Rect, Font, Point, Image: import draw; | |
| 30 | + | |
| 31 | +include "tk.m"; | |
| 32 | + tk: Tk; | |
| 33 | + Toplevel: import tk; | |
| 34 | + | |
| 35 | +include "wmlib.m"; | |
| 36 | + wmlib: Wmlib; | |
| 37 | + | |
| 38 | +include "awt_Color.m"; | |
| 39 | + awt : AwtColor; | |
| 40 | +#<< | |
| 41 | + | |
| 42 | +include "iWindowPeer_L.m"; | |
| 43 | + | |
| 44 | +#>> extra post includes here | |
| 45 | + str : String; | |
| 46 | + Value : import jni; | |
| 47 | + ctxt : ref Draw->Context; | |
| 48 | + cvm : ref Canvas; | |
| 49 | +#<< | |
| 50 | + | |
| 51 | +init( jni_p : JNI ) | |
| 52 | +{ | |
| 53 | + # save java native inteface mod instance | |
| 54 | + jni = jni_p; | |
| 55 | + #>>extra initialization here | |
| 56 | + sys = jni->sys; | |
| 57 | + str = load String String->PATH; | |
| 58 | + awt = load AwtColor AwtColor->PATH; | |
| 59 | + cast = jni->CastMod(); | |
| 60 | + ctxt = jni->getContext(); | |
| 61 | + #<< | |
| 62 | +} | |
| 63 | + | |
| 64 | +getRefImage_rObject( this : ref iWindowPeer_obj) : ref Draw->Image | |
| 65 | +{#>> | |
| 66 | + return this.pCanvas.image; | |
| 67 | +}#<< | |
| 68 | + | |
| 69 | +getRefOffScreenImage_rObject( this : ref iWindowPeer_obj) : ref Draw->Image | |
| 70 | +{#>> | |
| 71 | + return this.pCanvas.buf; | |
| 72 | +}#<< | |
| 73 | + | |
| 74 | +pReshape_I_I_I_I_V( this : ref iWindowPeer_obj, p0 : int,p1 : int,p2 : int,p3 : int) | |
| 75 | +{#>> | |
| 76 | + strcmd := ". configure -x " + | |
| 77 | + string p0 + " -y " + string p1 + " -width " + string p2 + " -height " + string p3; | |
| 78 | + | |
| 79 | + tk->cmd(this.pCanvas.top, strcmd); | |
| 80 | + tk->cmd(this.pCanvas.top, "update"); | |
| 81 | + this.pCanvas.image = this.pCanvas.top.image; | |
| 82 | +}#<< | |
| 83 | + | |
| 84 | +pHide_V( this : ref iWindowPeer_obj) | |
| 85 | +{#>> | |
| 86 | + tk->cmd(this.pCanvas.top, ". unmap"); | |
| 87 | + this.pCanvas.image = nil; | |
| 88 | +}#<< | |
| 89 | + | |
| 90 | +pShow_riWindowPeer_V( this : ref iWindowPeer_obj, p0: JObject) | |
| 91 | +{#>> | |
| 92 | + tk->cmd(this.pCanvas.top, ". map"); | |
| 93 | +return; | |
| 94 | + args := array[0] of ref Value; | |
| 95 | + (val, err) := jni->CallMethod(this.target, "repaint", "()V", args); | |
| 96 | + if (err != jni->OK){ | |
| 97 | + sys->print( "CallMethod Error %d: repaint\n",err); | |
| 98 | + } | |
| 99 | +}#<< | |
| 100 | + | |
| 101 | +getXYLoc_I_I( this : ref iWindowPeer_obj, p0 : int) : int | |
| 102 | +{#>> | |
| 103 | + if (p0 == 0) | |
| 104 | + return cvm.rect.min.x; | |
| 105 | + else | |
| 106 | + return cvm.rect.min.y; | |
| 107 | +}#<< | |
| 108 | + | |
| 109 | +create_riWindowPeer_V( this : ref iWindowPeer_obj, p0 : JObject) | |
| 110 | +{#>> | |
| 111 | + xval := jni->GetObjField(this.target, "x", "I"); | |
| 112 | + yval := jni->GetObjField(this.target, "y", "I"); | |
| 113 | + wval := jni->GetObjField(this.target, "width", "I"); | |
| 114 | + hval := jni->GetObjField(this.target, "height", "I"); | |
| 115 | + | |
| 116 | + x := xval.Int(); | |
| 117 | + y := yval.Int(); | |
| 118 | + w := wval.Int(); | |
| 119 | + h := hval.Int(); | |
| 120 | + | |
| 121 | + makewin(ctxt, x, y, w, h, this, p0); | |
| 122 | + | |
| 123 | + this.topInset = 0; | |
| 124 | + this.leftInset = 0; | |
| 125 | + this.rightInset = 0; | |
| 126 | + this.bottomInset = 0; | |
| 127 | + this.left = this.pCanvas.rect.min.x; | |
| 128 | + this.top = this.pCanvas.rect.min.y; | |
| 129 | + | |
| 130 | + tk->cmd(this.pCanvas.top, ". unmap"); | |
| 131 | + this.pCanvas.image = nil; | |
| 132 | + | |
| 133 | +}#<< | |
| 134 | + | |
| 135 | +pDispose_V( this : ref iWindowPeer_obj) | |
| 136 | +{#>> | |
| 137 | + this.pCanvas.jtd <- = "Die!"; | |
| 138 | + | |
| 139 | + this.pCanvas.top = nil; | |
| 140 | + this.pCanvas.image = nil; | |
| 141 | + this.pCanvas.buf = nil; | |
| 142 | + this.pCanvas = nil; | |
| 143 | +}#<< | |
| 144 | + | |
| 145 | +setCursor_I_V( this : ref iWindowPeer_obj, p0 : int) | |
| 146 | +{#>> | |
| 147 | +}#<< | |
| 148 | + | |
| 149 | +toFront_V( this : ref iWindowPeer_obj) | |
| 150 | +{#>> | |
| 151 | + this.pCanvas.image.top(); | |
| 152 | +}#<< | |
| 153 | + | |
| 154 | +toBack_V( this : ref iWindowPeer_obj) | |
| 155 | +{#>> | |
| 156 | + this.pCanvas.image.bottom(); | |
| 157 | +}#<< | |
| 158 | + | |
| 159 | +#>> | |
| 160 | +screen: ref Screen; | |
| 161 | +display: ref Display; | |
| 162 | +ones: ref Image; | |
| 163 | +white: ref Image; | |
| 164 | + | |
| 165 | + Event: adt | |
| 166 | + { | |
| 167 | + event: int; | |
| 168 | + detail: string; | |
| 169 | + | |
| 170 | + Button, Key, | |
| 171 | + Icon, DeIcon, | |
| 172 | + Resize, Shutdown | |
| 173 | + : con iota; | |
| 174 | + }; | |
| 175 | + | |
| 176 | + Attr: adt | |
| 177 | + { | |
| 178 | + origin: Draw->Point; | |
| 179 | + dims: Draw->Point; | |
| 180 | + }; | |
| 181 | + | |
| 182 | + Canvas: adt | |
| 183 | + { | |
| 184 | + # interface | |
| 185 | + image: ref Draw->Image; | |
| 186 | + buf: ref Draw->Image; | |
| 187 | + rect: Draw->Rect; | |
| 188 | + events: chan of ref Event; | |
| 189 | + attr: ref Attr; | |
| 190 | + jtd : chan of string; | |
| 191 | + # implementation | |
| 192 | + ctxt : ref Draw->Context; | |
| 193 | + top: ref Tk->Toplevel; | |
| 194 | + canvas: string; | |
| 195 | + pid: int; | |
| 196 | + }; | |
| 197 | +#<< | |
| 198 | + | |
| 199 | +#>> | |
| 200 | +win_cfg := array[] of { | |
| 201 | + "canvas .w -height 2 -width 2", | |
| 202 | + "pack .w -side bottom -fill both -expand 1", | |
| 203 | + "pack propagate . 0", | |
| 204 | +}; | |
| 205 | + | |
| 206 | +win_bind := array[] of { | |
| 207 | + "bind # <Motion> {send butt m %b %X %Y}", | |
| 208 | +# "bind # <Leave> {send butt Leave}", | |
| 209 | + "bind # <ButtonPress> {focus #;send butt p %b %X %Y}", | |
| 210 | + "bind # <ButtonRelease> {send butt r %b %X %Y}", | |
| 211 | + "bind # <Double-Button> {send butt d %b %X %Y}", | |
| 212 | +# "bind # <Enter> {send butt Enter}", | |
| 213 | + "bind # <KeyPress> {send key %K}", | |
| 214 | +# "bind . <FocusIn> {send foc focus}", | |
| 215 | +}; | |
| 216 | + | |
| 217 | +modinit(ctxt: ref Context) | |
| 218 | +{ | |
| 219 | + draw = load Draw Draw->PATH; | |
| 220 | + tk = load Tk Tk->PATH; | |
| 221 | + wmlib = load Wmlib Wmlib->PATH; | |
| 222 | + | |
| 223 | + screen = ctxt.screen; | |
| 224 | + wmlib->init(); | |
| 225 | +} | |
| 226 | + | |
| 227 | +makewin(ctxt: ref Context, x, y, width, height: int, this: ref iWindowPeer_obj, job: JObject) | |
| 228 | +{ | |
| 229 | + modinit(ctxt); | |
| 230 | + where := "-x " + string x + " -y " + string y; | |
| 231 | + t := tk->toplevel(screen, "-borderwidth 0 -relief raised "+where); | |
| 232 | +# (t, menu) := wmlib->titlebar(screen, where, title, Wmlib->Appl); | |
| 233 | + | |
| 234 | + if (width > 0 && height > 0) | |
| 235 | + win_cfg[0] = "canvas .w -height " + string height + " -width " + string width; | |
| 236 | + | |
| 237 | + wmlib->tkcmds(t, win_cfg); | |
| 238 | + ones = t.image.display.ones; | |
| 239 | + white = t.image.display.color(Draw->White); | |
| 240 | + alloccanvas(t, ctxt, ".w", this, job); | |
| 241 | +} | |
| 242 | + | |
| 243 | +alloccanvas(t: ref Toplevel, ctxt: ref Draw->Context, canvas: string, this :ref iWindowPeer_obj, job: JObject) | |
| 244 | +{ | |
| 245 | + cmd := chan of string; | |
| 246 | + tk->namechan(t, cmd, "cmd"); | |
| 247 | + butt := chan of string; | |
| 248 | + tk->namechan(t, butt, "butt"); | |
| 249 | + | |
| 250 | + key := chan of string; | |
| 251 | + tk->namechan(t, key, "key"); | |
| 252 | + | |
| 253 | + tk->cmd(t, "bind . <Configure> {send cmd resize}"); | |
| 254 | + tk->cmd(t, "bind . <Map> {send cmd map}"); | |
| 255 | + | |
| 256 | + for (i := 0; i < len win_bind; i++) | |
| 257 | + tk->cmd(t, expand(win_bind[i], canvas)); | |
| 258 | + | |
| 259 | + tk->cmd(t, "update"); | |
| 260 | + | |
| 261 | + c := ref Canvas; | |
| 262 | + this.pCanvas = c; | |
| 263 | + c = nil; | |
| 264 | + | |
| 265 | + bg := Draw->White; | |
| 266 | + jcol := jni->GetObjField(this.target, "background", "Ljava/awt/Color;"); | |
| 267 | + if (jcol == nil) { | |
| 268 | + sys->print("Cannot get background color\n"); | |
| 269 | + } else { | |
| 270 | + color := jcol.Object(); | |
| 271 | + bg = awt->getColorIndex(jni, color); | |
| 272 | + } | |
| 273 | + | |
| 274 | + this.pCanvas.image = t.image; | |
| 275 | + display = t.image.display; | |
| 276 | + this.pCanvas.rect = canvposn(t, canvas); | |
| 277 | + this.pCanvas.buf = ctxt.display.newimage(ctxt.display.image.r, | |
| 278 | + this.pCanvas.image.ldepth , 0, bg); | |
| 279 | + this.pCanvas.events = chan of ref Event; | |
| 280 | + this.pCanvas.top = t; | |
| 281 | + this.pCanvas.ctxt = ctxt; | |
| 282 | + this.pCanvas.canvas = canvas; | |
| 283 | + this.pCanvas.pid = sys->pctl(0, nil); | |
| 284 | + | |
| 285 | + spawn handler(cmd, butt, key, this, job); | |
| 286 | +} | |
| 287 | + | |
| 288 | +handler(cmd, butt, key : chan of string, this : ref iWindowPeer_obj, job: JObject) | |
| 289 | +{ | |
| 290 | + | |
| 291 | + detail: string; | |
| 292 | + | |
| 293 | + jtd := chan of string; | |
| 294 | + this.pCanvas.jtd = jtd; | |
| 295 | + | |
| 296 | + for (;;) alt { | |
| 297 | + detail = <- this.pCanvas.jtd => | |
| 298 | + return; | |
| 299 | + detail = <- cmd => | |
| 300 | + (n, word) := sys->tokenize(detail, " "); | |
| 301 | + case hd word { | |
| 302 | + "map" => | |
| 303 | + this.pCanvas.image = this.pCanvas.top.image; | |
| 304 | + handleRepaint(this); | |
| 305 | + | |
| 306 | + * => | |
| 307 | + ; | |
| 308 | + } | |
| 309 | + | |
| 310 | + detail = <- butt => | |
| 311 | + doMouseEvent(job, detail); | |
| 312 | + detail = <- key => | |
| 313 | + (kchar, st) := str->toint(detail, 16); | |
| 314 | + args := array[1] of ref Value; | |
| 315 | + args[0] = ref Value.TInt(kchar); | |
| 316 | + (val, err) := jni->CallMethod(job, "handleKeyEvents", "(I)V", args); | |
| 317 | + if (err != jni->OK){ | |
| 318 | + sys->print( "CallMethod Error %d: handleKeyEvents\n",err); | |
| 319 | + } | |
| 320 | + } | |
| 321 | +} | |
| 322 | +expand(cmd, canvas: string): string | |
| 323 | +{ | |
| 324 | + s: string; | |
| 325 | + for (;;) { | |
| 326 | + (l, r) := str->splitl(cmd, "#"); | |
| 327 | + s = s + l; | |
| 328 | + if (r == nil) | |
| 329 | + return s; | |
| 330 | + s = s + canvas; | |
| 331 | + cmd = r[1:]; | |
| 332 | + } | |
| 333 | +} | |
| 334 | + | |
| 335 | +canvposn(t: ref Toplevel, c: string): Rect | |
| 336 | +{ | |
| 337 | + r: Rect; | |
| 338 | + | |
| 339 | + r.min.x = int tk->cmd(t, ". cget -actx") + int tk->cmd(t, ".dx get"); | |
| 340 | + r.min.y = int tk->cmd(t, ". cget -acty") + int tk->cmd(t, ".dy get"); | |
| 341 | + r.max.x = r.min.x + int tk->cmd(t, ". cget -actwidth") + int tk->cmd(t, ".dw get"); | |
| 342 | + r.max.y = r.min.y + int tk->cmd(t, ". cget -actheight") + int tk->cmd(t, ".dh get"); | |
| 343 | + return r; | |
| 344 | +} | |
| 345 | + | |
| 346 | +doMouseEvent(job: JObject, detail : string) | |
| 347 | +{ | |
| 348 | + (n,toks) := sys->tokenize(detail," "); | |
| 349 | + if (n != 4) return; | |
| 350 | + mode := array of byte hd toks; | |
| 351 | + toks = tl toks; | |
| 352 | + button:=int hd toks; | |
| 353 | + toks = tl toks; | |
| 354 | + x:=int hd toks; | |
| 355 | + toks = tl toks; | |
| 356 | + y:=int hd toks; | |
| 357 | + args := array[4] of ref Value; | |
| 358 | + args[0] = ref Value.TInt(int mode[0]); | |
| 359 | + args[1] = ref Value.TInt(button); | |
| 360 | + args[2] = ref Value.TInt(x); | |
| 361 | + args[3] = ref Value.TInt(y); | |
| 362 | + (val, err) := jni->CallMethod(job, "handleMouseEvents", "(IIII)V", args); | |
| 363 | + if (err != jni->OK){ | |
| 364 | + sys->print( "CallMethod Error %d: handleMouseEvents\n",err); | |
| 365 | + } | |
| 366 | +} | |
| 367 | + | |
| 368 | +handleRepaint(this : ref iWindowPeer_obj) | |
| 369 | +{ | |
| 370 | + args := array[0] of ref Value; | |
| 371 | + (val, err) := jni->CallMethod(this.target, "repaint", "()V", args); | |
| 372 | + if (err != jni->OK){ | |
| 373 | + sys->print( "CallMethod Error %d: repaint\n",err); | |
| 374 | + } | |
| 375 | +} | |
| 376 | +#<< | |
| 377 | + | |
| @@ -0,0 +1,36 @@ | ||
| 1 | +# | |
| 2 | +# %W% - %E% | |
| 3 | +# | |
| 4 | +# generated file edit with care | |
| 5 | + | |
| 6 | +iWindowPeer_L : module | |
| 7 | +{ | |
| 8 | + iWindowPeer_obj : adt | |
| 9 | + { | |
| 10 | + cl_mod : ClassModule; | |
| 11 | + pCanvas : ref Canvas; | |
| 12 | + target : JObject; | |
| 13 | + leftInset : int; | |
| 14 | + rightInset : int; | |
| 15 | + topInset : int; | |
| 16 | + bottomInset : int; | |
| 17 | + left : int; | |
| 18 | + top : int; | |
| 19 | + oldMousePoint : JObject; | |
| 20 | + buttonState : JArrayZ; | |
| 21 | + }; | |
| 22 | + | |
| 23 | + init : fn( jni_p : JNI ); | |
| 24 | + getRefImage_rObject : fn( this : ref iWindowPeer_obj) : ref Draw->Image; | |
| 25 | + getRefOffScreenImage_rObject : fn( this : ref iWindowPeer_obj) : ref Draw->Image; | |
| 26 | + pReshape_I_I_I_I_V : fn( this : ref iWindowPeer_obj, p0 : int,p1 : int,p2 : int,p3 : int); | |
| 27 | + pHide_V : fn( this : ref iWindowPeer_obj); | |
| 28 | + pShow_riWindowPeer_V : fn( this : ref iWindowPeer_obj, p0 : JObject); | |
| 29 | + getXYLoc_I_I : fn( this : ref iWindowPeer_obj, p0 : int) : int; | |
| 30 | + create_riWindowPeer_V : fn( this : ref iWindowPeer_obj, p0 : JObject); | |
| 31 | + pDispose_V : fn( this : ref iWindowPeer_obj); | |
| 32 | + setCursor_I_V : fn( this : ref iWindowPeer_obj, p0 : int); | |
| 33 | + toFront_V : fn( this : ref iWindowPeer_obj); | |
| 34 | + toBack_V : fn( this : ref iWindowPeer_obj); | |
| 35 | + | |
| 36 | +}; | |
| @@ -0,0 +1,126 @@ | ||
| 1 | +<../../../../mkconfig | |
| 2 | + | |
| 3 | +TARG=\ | |
| 4 | + iDrawingSurfaceInfo.dis\ | |
| 5 | + iFontMetrics.dis\ | |
| 6 | + iFontPeer.dis\ | |
| 7 | + iFramePeer.dis\ | |
| 8 | + iGraphics.dis\ | |
| 9 | + iImage.dis\ | |
| 10 | + iImageConsumer.dis\ | |
| 11 | + iImageRepresentation.dis\ | |
| 12 | + iMenuBarPeer.dis\ | |
| 13 | + iOffScreenImage.dis\ | |
| 14 | + iPopupMenuPeer.dis\ | |
| 15 | + iToolkit.dis\ | |
| 16 | + iWindowPeer.dis\ | |
| 17 | + zMenuWindow.dis\ | |
| 18 | + zMenuDisplay.dis\ | |
| 19 | + zMenuBarObject.dis\ | |
| 20 | + zMenuObject.dis\ | |
| 21 | + zMenuParent.dis\ | |
| 22 | + zMenuSeparator.dis\ | |
| 23 | + zMenuText.dis\ | |
| 24 | + zPopupMenu.dis\ | |
| 25 | + zPopupMenuDisplay.dis\ | |
| 26 | + zPopupMenuObject.dis\ | |
| 27 | + zPopupMenuParent.dis\ | |
| 28 | + zPopupMenuSeparator.dis\ | |
| 29 | + zPopupMenuText.dis\ | |
| 30 | +# Limbo code\ | |
| 31 | + awt_Color.dis\ | |
| 32 | + awt_Frame.dis\ | |
| 33 | + awt_Graphics.dis\ | |
| 34 | +# broken\ | |
| 35 | +# iDrawingSurfaceInfo_L.dis\ | |
| 36 | + iFontMetrics_L.dis\ | |
| 37 | + iFontPeer_L.dis\ | |
| 38 | + iFramePeer_L.dis\ | |
| 39 | + iGraphics_L.dis\ | |
| 40 | + iImageRepresentation_L.dis\ | |
| 41 | + iImage_L.dis\ | |
| 42 | + iToolkit_L.dis\ | |
| 43 | + iWindowPeer_L.dis\ | |
| 44 | + | |
| 45 | +MODULES=\ | |
| 46 | + $ROOT/java/module/classloader.m\ | |
| 47 | + $ROOT/java/module/jni.m\ | |
| 48 | + $ROOT/java/module/cast.m\ | |
| 49 | + awt_Color.m\ | |
| 50 | + awt_Frame.m\ | |
| 51 | + awt_Graphics.m\ | |
| 52 | + awt_Image.m\ | |
| 53 | + iDrawingSurfaceInfo_L.m\ | |
| 54 | + iFontMetrics_L.m\ | |
| 55 | + iFontPeer_L.m\ | |
| 56 | + iFramePeer_L.m\ | |
| 57 | + iGraphics_L.m\ | |
| 58 | + iImageRepresentation_L.m\ | |
| 59 | + iImage_L.m\ | |
| 60 | + iToolkit_L.m\ | |
| 61 | + iWindowPeer_L.m\ | |
| 62 | + | |
| 63 | +SYSMODULES=\ | |
| 64 | + draw.m\ | |
| 65 | + hash.m\ | |
| 66 | + keyring.m\ | |
| 67 | + loader.m\ | |
| 68 | + math.m\ | |
| 69 | + string.m\ | |
| 70 | + sys.m\ | |
| 71 | + | |
| 72 | +DISBIN=$ROOT/java/dis/java/inferno/awt | |
| 73 | + | |
| 74 | +<$ROOT/mkfiles/mkjava | |
| 75 | + | |
| 76 | +LIMBOINCL=\ | |
| 77 | + $LIMBOINCL\ | |
| 78 | + -I$ROOT/java/pkg\ | |
| 79 | + | |
| 80 | +awt_Color.dis: awt_Color.b | |
| 81 | + limbo $LIMBOINCL -gw awt_Color.b | |
| 82 | + | |
| 83 | +awt_Frame.dis: awt_Frame.b | |
| 84 | + limbo $LIMBOINCL -gw awt_Frame.b | |
| 85 | + | |
| 86 | +awt_Graphics.dis: awt_Graphics.b | |
| 87 | + limbo $LIMBOINCL -gw awt_Graphics.b | |
| 88 | + | |
| 89 | +zMenuWindow.dis: iMenuBarPeer.class | |
| 90 | + j2d zMenuWindow.class | |
| 91 | + | |
| 92 | +zMenuDisplay.dis: iMenuBarPeer.class | |
| 93 | + j2d zMenuDisplay.class | |
| 94 | + | |
| 95 | +zMenuBarObject.dis: iMenuBarPeer.class | |
| 96 | + j2d zMenuBarObject.class | |
| 97 | + | |
| 98 | +zMenuObject.dis: iMenuBarPeer.class | |
| 99 | + j2d zMenuObject.class | |
| 100 | + | |
| 101 | +zMenuParent.dis: iMenuBarPeer.class | |
| 102 | + j2d zMenuParent.class | |
| 103 | + | |
| 104 | +zMenuSeparator.dis: iMenuBarPeer.class | |
| 105 | + j2d zMenuSeparator.class | |
| 106 | + | |
| 107 | +zMenuText.dis: iMenuBarPeer.class | |
| 108 | + j2d zMenuText.class | |
| 109 | + | |
| 110 | +zPopupMenu.dis: iPopupMenuPeer.class | |
| 111 | + j2d zPopupMenu.class | |
| 112 | + | |
| 113 | +zPopupMenuDisplay.dis: iPopupMenuPeer.class | |
| 114 | + j2d zPopupMenuDisplay.class | |
| 115 | + | |
| 116 | +zPopupMenuObject.dis: iPopupMenuPeer.class | |
| 117 | + j2d zPopupMenuObject.class | |
| 118 | + | |
| 119 | +zPopupMenuParent.dis: iPopupMenuPeer.class | |
| 120 | + j2d zPopupMenuParent.class | |
| 121 | + | |
| 122 | +zPopupMenuSeparator.dis: iPopupMenuPeer.class | |
| 123 | + j2d zPopupMenuSeparator.class | |
| 124 | + | |
| 125 | +zPopupMenuText.dis: iPopupMenuPeer.class | |
| 126 | + j2d zPopupMenuText.class | |
| @@ -0,0 +1,7 @@ | ||
| 1 | +<../../../mkconfig | |
| 2 | + | |
| 3 | +DIRS=\ | |
| 4 | + oracle\ | |
| 5 | + sun\ | |
| 6 | + | |
| 7 | +<$ROOT/mkfiles/mksubdirs | |
| @@ -0,0 +1,6 @@ | ||
| 1 | +<../../../../mkconfig | |
| 2 | + | |
| 3 | +DIRS=\ | |
| 4 | + net\ | |
| 5 | + | |
| 6 | +<$ROOT/mkfiles/mksubdirs | |
| @@ -0,0 +1,201 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.oracle.net; | |
| 27 | + | |
| 28 | +import java.net.Socket; | |
| 29 | +import java.net.ServerSocket; | |
| 30 | +import java.net.SocketImpl; | |
| 31 | +import java.net.SocketImplFactory; | |
| 32 | +import java.net.SocketException; | |
| 33 | +import java.nio.channels.SocketChannel; | |
| 34 | +import java.nio.channels.ServerSocketChannel; | |
| 35 | +import java.io.IOException; | |
| 36 | +import java.io.FileDescriptor; | |
| 37 | +import java.security.AccessController; | |
| 38 | +import java.security.PrivilegedAction; | |
| 39 | +import java.lang.reflect.Constructor; | |
| 40 | +import java.lang.reflect.AccessibleObject; | |
| 41 | +import java.lang.reflect.InvocationTargetException; | |
| 42 | + | |
| 43 | +import sun.net.sdp.SdpSupport; | |
| 44 | + | |
| 45 | +/** | |
| 46 | + * This class consists exclusively of static methods that Sockets or Channels to | |
| 47 | + * sockets that support the InfiniBand Sockets Direct Protocol (SDP). | |
| 48 | + */ | |
| 49 | + | |
| 50 | +public final class Sdp { | |
| 51 | + private Sdp() { } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * The package-privage ServerSocket(SocketImpl) constructor | |
| 55 | + */ | |
| 56 | + private static final Constructor<ServerSocket> serverSocketCtor; | |
| 57 | + static { | |
| 58 | + try { | |
| 59 | + serverSocketCtor = (Constructor<ServerSocket>) | |
| 60 | + ServerSocket.class.getDeclaredConstructor(SocketImpl.class); | |
| 61 | + setAccessible(serverSocketCtor); | |
| 62 | + } catch (NoSuchMethodException e) { | |
| 63 | + throw new AssertionError(e); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * The package-private SdpSocketImpl() constructor | |
| 69 | + */ | |
| 70 | + private static final Constructor<SocketImpl> socketImplCtor; | |
| 71 | + static { | |
| 72 | + try { | |
| 73 | + Class<?> cl = Class.forName("java.net.SdpSocketImpl", true, null); | |
| 74 | + socketImplCtor = (Constructor<SocketImpl>)cl.getDeclaredConstructor(); | |
| 75 | + setAccessible(socketImplCtor); | |
| 76 | + } catch (ClassNotFoundException e) { | |
| 77 | + throw new AssertionError(e); | |
| 78 | + } catch (NoSuchMethodException e) { | |
| 79 | + throw new AssertionError(e); | |
| 80 | + } | |
| 81 | + } | |
| 82 | + | |
| 83 | + private static void setAccessible(final AccessibleObject o) { | |
| 84 | + AccessController.doPrivileged(new PrivilegedAction<Void>() { | |
| 85 | + public Void run() { | |
| 86 | + o.setAccessible(true); | |
| 87 | + return null; | |
| 88 | + } | |
| 89 | + }); | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * SDP enabled Socket. | |
| 94 | + */ | |
| 95 | + private static class SdpSocket extends Socket { | |
| 96 | + SdpSocket(SocketImpl impl) throws SocketException { | |
| 97 | + super(impl); | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Creates a SDP enabled SocketImpl | |
| 103 | + */ | |
| 104 | + private static SocketImpl createSocketImpl() { | |
| 105 | + try { | |
| 106 | + return socketImplCtor.newInstance(); | |
| 107 | + } catch (InstantiationException x) { | |
| 108 | + throw new AssertionError(x); | |
| 109 | + } catch (IllegalAccessException x) { | |
| 110 | + throw new AssertionError(x); | |
| 111 | + } catch (InvocationTargetException x) { | |
| 112 | + throw new AssertionError(x); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * Creates an unconnected and unbound SDP socket. The {@code Socket} is | |
| 118 | + * associated with a {@link java.net.SocketImpl} of the system-default type. | |
| 119 | + * | |
| 120 | + * @return a new Socket | |
| 121 | + * | |
| 122 | + * @throws UnsupportedOperationException | |
| 123 | + * If SDP is not supported | |
| 124 | + * @throws IOException | |
| 125 | + * If an I/O error occurs | |
| 126 | + */ | |
| 127 | + public static Socket openSocket() throws IOException { | |
| 128 | + SocketImpl impl = createSocketImpl(); | |
| 129 | + return new SdpSocket(impl); | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * Creates an unbound SDP server socket. The {@code ServerSocket} is | |
| 134 | + * associated with a {@link java.net.SocketImpl} of the system-default type. | |
| 135 | + * | |
| 136 | + * @return a new ServerSocket | |
| 137 | + * | |
| 138 | + * @throws UnsupportedOperationException | |
| 139 | + * If SDP is not supported | |
| 140 | + * @throws IOException | |
| 141 | + * If an I/O error occurs | |
| 142 | + */ | |
| 143 | + public static ServerSocket openServerSocket() throws IOException { | |
| 144 | + // create ServerSocket via package-private constructor | |
| 145 | + SocketImpl impl = createSocketImpl(); | |
| 146 | + try { | |
| 147 | + return serverSocketCtor.newInstance(impl); | |
| 148 | + } catch (IllegalAccessException x) { | |
| 149 | + throw new AssertionError(x); | |
| 150 | + } catch (InstantiationException x) { | |
| 151 | + throw new AssertionError(x); | |
| 152 | + } catch (InvocationTargetException x) { | |
| 153 | + Throwable cause = x.getCause(); | |
| 154 | + if (cause instanceof IOException) | |
| 155 | + throw (IOException)cause; | |
| 156 | + if (cause instanceof RuntimeException) | |
| 157 | + throw (RuntimeException)cause; | |
| 158 | + throw new RuntimeException(x); | |
| 159 | + } | |
| 160 | + } | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * Opens a socket channel to a SDP socket. | |
| 164 | + * | |
| 165 | + * <p> The channel will be associated with the system-wide default | |
| 166 | + * {@link java.nio.channels.spi.SelectorProvider SelectorProvider}. | |
| 167 | + * | |
| 168 | + * @return a new SocketChannel | |
| 169 | + * | |
| 170 | + * @throws UnsupportedOperationException | |
| 171 | + * If SDP is not supported or not supported by the default selector | |
| 172 | + * provider | |
| 173 | + * @throws IOException | |
| 174 | + * If an I/O error occurs. | |
| 175 | + */ | |
| 176 | + public static SocketChannel openSocketChannel() throws IOException { | |
| 177 | + FileDescriptor fd = SdpSupport.createSocket(); | |
| 178 | + return sun.nio.ch.Secrets.newSocketChannel(fd); | |
| 179 | + } | |
| 180 | + | |
| 181 | + /** | |
| 182 | + * Opens a socket channel to a SDP socket. | |
| 183 | + * | |
| 184 | + * <p> The channel will be associated with the system-wide default | |
| 185 | + * {@link java.nio.channels.spi.SelectorProvider SelectorProvider}. | |
| 186 | + * | |
| 187 | + * @return a new ServerSocketChannel | |
| 188 | + * | |
| 189 | + * @throws UnsupportedOperationException | |
| 190 | + * If SDP is not supported or not supported by the default selector | |
| 191 | + * provider | |
| 192 | + * @throws IOException | |
| 193 | + * If an I/O error occurs | |
| 194 | + */ | |
| 195 | + public static ServerSocketChannel openServerSocketChannel() | |
| 196 | + throws IOException | |
| 197 | + { | |
| 198 | + FileDescriptor fd = SdpSupport.createSocket(); | |
| 199 | + return sun.nio.ch.Secrets.newServerSocketChannel(fd); | |
| 200 | + } | |
| 201 | +} | |
| @@ -0,0 +1,8 @@ | ||
| 1 | +<../../../../../mkconfig | |
| 2 | + | |
| 3 | +TARG=\ | |
| 4 | + Sdp.dis\ | |
| 5 | + | |
| 6 | +DISBIN=$ROOT/java/dis/java/java/com/oracle/net | |
| 7 | + | |
| 8 | +<$ROOT/mkfiles/mkjava | |
| @@ -0,0 +1,6 @@ | ||
| 1 | +<../../../../../../mkconfig | |
| 2 | + | |
| 3 | +DIRS=\ | |
| 4 | + resources\ | |
| 5 | + | |
| 6 | +<$ROOT/mkfiles/mksubdirs | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=alert | |
| 17 | +awtcomponent=AWT component | |
| 18 | +checkbox=check box | |
| 19 | +colorchooser=color chooser | |
| 20 | +columnheader=column header | |
| 21 | +combobox=combo box | |
| 22 | +canvas=canvas | |
| 23 | +desktopicon=desktop icon | |
| 24 | +desktoppane=desktop pane | |
| 25 | +dialog=dialog | |
| 26 | +directorypane=directory pane | |
| 27 | +glasspane=glass pane | |
| 28 | +filechooser=file chooser | |
| 29 | +filler=filler | |
| 30 | +frame=frame | |
| 31 | +internalframe=internal frame | |
| 32 | +label=label | |
| 33 | +layeredpane=layered pane | |
| 34 | +list=list | |
| 35 | +listitem=list item | |
| 36 | +menubar=menu bar | |
| 37 | +menu=menu | |
| 38 | +menuitem=menu item | |
| 39 | +optionpane=option pane | |
| 40 | +pagetab=page tab | |
| 41 | +pagetablist=page tab list | |
| 42 | +panel=panel | |
| 43 | +passwordtext=password text | |
| 44 | +popupmenu=popup menu | |
| 45 | +progressbar=progress bar | |
| 46 | +pushbutton=push button | |
| 47 | +radiobutton=radio button | |
| 48 | +rootpane=root pane | |
| 49 | +rowheader=row header | |
| 50 | +scrollbar=scroll bar | |
| 51 | +scrollpane=scroll pane | |
| 52 | +separator=separator | |
| 53 | +slider=slider | |
| 54 | +splitpane=split pane | |
| 55 | +swingcomponent=swing component | |
| 56 | +table=table | |
| 57 | +text=text | |
| 58 | +tree=tree | |
| 59 | +togglebutton=toggle button | |
| 60 | +toolbar=tool bar | |
| 61 | +tooltip=tool tip | |
| 62 | +unknown=unknown | |
| 63 | +viewport=viewport | |
| 64 | +window=window | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=label for | |
| 69 | +labeledBy=labeled by | |
| 70 | +memberOf=member of | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=active | |
| 77 | +armed=armed | |
| 78 | +busy=busy | |
| 79 | +checked=checked | |
| 80 | +collapsed=collapsed | |
| 81 | +editable=editable | |
| 82 | +expandable=expandable | |
| 83 | +expanded=expanded | |
| 84 | +enabled=enabled | |
| 85 | +focusable=focusable | |
| 86 | +focused=focused | |
| 87 | +iconified=iconified | |
| 88 | +modal=modal | |
| 89 | +multiline=multiple line | |
| 90 | +multiselectable=multiselectable | |
| 91 | +opaque=opaque | |
| 92 | +pressed=pressed | |
| 93 | +resizable=resizable | |
| 94 | +selectable=selectable | |
| 95 | +selected=selected | |
| 96 | +showing=showing | |
| 97 | +singleline=single line | |
| 98 | +transient=transient | |
| 99 | +visible=visible | |
| 100 | +vertical=vertical | |
| 101 | +horizontal=horizontal | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expand=toggle expand | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=flows to | |
| 113 | +flowsFrom=flows from | |
| 114 | +subwindowOf=subwindow of | |
| 115 | +parentWindowOf=parent window of | |
| 116 | +embeds=embeds | |
| 117 | +embeddedBy=embedded by | |
| 118 | +childNodeOf=child node of | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=header | |
| 124 | +footer=footer | |
| 125 | +paragraph=paragraph | |
| 126 | +ruler=ruler | |
| 127 | +editbar=editbar | |
| 128 | +progressMonitor=progress monitor | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=manages descendants | |
| 134 | +indeterminate=indeterminate | |
| 135 | +truncated=truncated | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=HTML container | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=Alert | |
| 17 | +awtcomponent=AWT-Komponente | |
| 18 | +checkbox=Kontrollk\u00E4stchen | |
| 19 | +colorchooser=Farbauswahl | |
| 20 | +columnheader=Spalten-Header | |
| 21 | +combobox=Kombinationsfeld | |
| 22 | +canvas=Leinwand | |
| 23 | +desktopicon=Desktopsymbol | |
| 24 | +desktoppane=Desktopbereich | |
| 25 | +dialog=Dialogfeld | |
| 26 | +directorypane=Verzeichnisbereich | |
| 27 | +glasspane=Glass Pane | |
| 28 | +filechooser=Dateiauswahl | |
| 29 | +filler=F\u00FCllbereich | |
| 30 | +frame=Rahmen | |
| 31 | +internalframe=Innerer Rahmen | |
| 32 | +label=Label | |
| 33 | +layeredpane=Layered Pane | |
| 34 | +list=Liste | |
| 35 | +listitem=Listenelement | |
| 36 | +menubar=Men\u00FCleiste | |
| 37 | +menu=Men\u00FC | |
| 38 | +menuitem=Men\u00FCpunkt | |
| 39 | +optionpane=Optionsbereich | |
| 40 | +pagetab=Registerkarte | |
| 41 | +pagetablist=Registerkartenliste | |
| 42 | +panel=Bereich | |
| 43 | +passwordtext=Kennworttext | |
| 44 | +popupmenu=Popup-Men\u00FC | |
| 45 | +progressbar=Fortschrittsbalken | |
| 46 | +pushbutton=Schaltfl\u00E4che | |
| 47 | +radiobutton=Optionsfeld | |
| 48 | +rootpane=Root-Bereich | |
| 49 | +rowheader=Zeilen-Header | |
| 50 | +scrollbar=Bildlaufleiste | |
| 51 | +scrollpane=Bildlaufbereich | |
| 52 | +separator=Trennzeichen | |
| 53 | +slider=Schieberegler | |
| 54 | +splitpane=Split Pane | |
| 55 | +swingcomponent=Swing-Komponente | |
| 56 | +table=Tabelle | |
| 57 | +text=Text | |
| 58 | +tree=Baumstruktur | |
| 59 | +togglebutton=Umschaltfl\u00E4che | |
| 60 | +toolbar=Symbolleiste | |
| 61 | +tooltip=QuickInfo | |
| 62 | +unknown=Unbekannt | |
| 63 | +viewport=Viewport | |
| 64 | +window=Fenster | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=Label f\u00FCr | |
| 69 | +labeledBy=beschriftet von | |
| 70 | +memberOf=Mitglied von | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=aktiv | |
| 77 | +armed=aktiviert | |
| 78 | +busy=ausgelastet | |
| 79 | +checked=markiert | |
| 80 | +collapsed=ausgeblendet | |
| 81 | +editable=bearbeitbar | |
| 82 | +expandable=erweiterbar | |
| 83 | +expanded=eingeblendet | |
| 84 | +enabled=aktiviert | |
| 85 | +focusable=fokussierbar | |
| 86 | +focused=fokussiert | |
| 87 | +iconified=minimiert | |
| 88 | +modal=modal | |
| 89 | +multiline=mehrzeilig | |
| 90 | +multiselectable=mehrfach ausw\u00E4hlbar | |
| 91 | +opaque=nicht transparent | |
| 92 | +pressed=gedr\u00FCckt | |
| 93 | +resizable=skalierbar | |
| 94 | +selectable=w\u00E4hlbar | |
| 95 | +selected=ausgew\u00E4hlt | |
| 96 | +showing=angezeigt | |
| 97 | +singleline=einzeilig | |
| 98 | +transient=transient | |
| 99 | +visible=sichtbar | |
| 100 | +vertical=vertikal | |
| 101 | +horizontal=horizontal | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expand=ein-/ausblenden | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=flie\u00DFt zu | |
| 113 | +flowsFrom=flie\u00DFt von | |
| 114 | +subwindowOf=Unterfenster von | |
| 115 | +parentWindowOf=\u00FCbergeordnetes Fenster von | |
| 116 | +embeds=bettet ein | |
| 117 | +embeddedBy=eingebettet in | |
| 118 | +childNodeOf=untergeordneter Knoten von | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=Header | |
| 124 | +footer=Footer | |
| 125 | +paragraph=Absatz | |
| 126 | +ruler=Lineal | |
| 127 | +editbar=Bearbeitungsleiste | |
| 128 | +progressMonitor=Fortschrittsmonitor | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=verwaltet untergeordnete Objekte | |
| 134 | +indeterminate=unbestimmt | |
| 135 | +truncated=abgeschnitten | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=HTML-Container | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,142 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=alert | |
| 17 | +awtcomponent=AWT component | |
| 18 | +checkbox=check box | |
| 19 | +colorchooser=color chooser | |
| 20 | +columnheader=column header | |
| 21 | +combobox=combo box | |
| 22 | +canvas=canvas | |
| 23 | +desktopicon=desktop icon | |
| 24 | +desktoppane=desktop pane | |
| 25 | +dialog=dialog | |
| 26 | +directorypane=directory pane | |
| 27 | +glasspane=glass pane | |
| 28 | +filechooser=file chooser | |
| 29 | +filler=filler | |
| 30 | +frame=frame | |
| 31 | +internalframe=internal frame | |
| 32 | +label=label | |
| 33 | +layeredpane=layered pane | |
| 34 | +list=list | |
| 35 | +listitem=list item | |
| 36 | +menubar=menu bar | |
| 37 | +menu=menu | |
| 38 | +menuitem=menu item | |
| 39 | +optionpane=option pane | |
| 40 | +pagetab=page tab | |
| 41 | +pagetablist=page tab list | |
| 42 | +panel=panel | |
| 43 | +passwordtext=password text | |
| 44 | +popupmenu=popup menu | |
| 45 | +progressbar=progress bar | |
| 46 | +pushbutton=push button | |
| 47 | +radiobutton=radio button | |
| 48 | +rootpane=root pane | |
| 49 | +rowheader=row header | |
| 50 | +scrollbar=scroll bar | |
| 51 | +scrollpane=scroll pane | |
| 52 | +separator=separator | |
| 53 | +slider=slider | |
| 54 | +splitpane=split pane | |
| 55 | +swingcomponent=swing component | |
| 56 | +table=table | |
| 57 | +text=text | |
| 58 | +tree=tree | |
| 59 | +togglebutton=toggle button | |
| 60 | +toolbar=tool bar | |
| 61 | +tooltip=tool tip | |
| 62 | +unknown=unknown | |
| 63 | +viewport=viewport | |
| 64 | +window=window | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=label for | |
| 69 | +labeledBy=labeled by | |
| 70 | +memberOf=member of | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=active | |
| 77 | +armed=armed | |
| 78 | +busy=busy | |
| 79 | +checked=checked | |
| 80 | +collapsed=collapsed | |
| 81 | +editable=editable | |
| 82 | +expandable=expandable | |
| 83 | +expanded=expanded | |
| 84 | +enabled=enabled | |
| 85 | +focusable=focusable | |
| 86 | +focused=focused | |
| 87 | +iconified=iconified | |
| 88 | +modal=modal | |
| 89 | +multiline=multiple line | |
| 90 | +multiselectable=multiselectable | |
| 91 | +opaque=opaque | |
| 92 | +pressed=pressed | |
| 93 | +resizable=resizable | |
| 94 | +selectable=selectable | |
| 95 | +selected=selected | |
| 96 | +showing=showing | |
| 97 | +singleline=single line | |
| 98 | +transient=transient | |
| 99 | +visible=visible | |
| 100 | +vertical=vertical | |
| 101 | +horizontal=horizontal | |
| 102 | + | |
| 103 | +# new relations, roles and states for J2SE 1.5.0 | |
| 104 | + | |
| 105 | +# | |
| 106 | +# accessible relations | |
| 107 | +# | |
| 108 | +flowsTo=flows to | |
| 109 | +flowsFrom=flows from | |
| 110 | +subwindowOf=subwindow of | |
| 111 | +parentWindowOf=parent window of | |
| 112 | +embeds=embeds | |
| 113 | +embeddedBy=embedded by | |
| 114 | +childNodeOf=child node of | |
| 115 | + | |
| 116 | +# | |
| 117 | +# accessible roles | |
| 118 | +# | |
| 119 | +header=header | |
| 120 | +footer=footer | |
| 121 | +paragraph=paragraph | |
| 122 | +ruler=ruler | |
| 123 | +editbar=editbar | |
| 124 | +progressMonitor=progress monitor | |
| 125 | + | |
| 126 | +# | |
| 127 | +# accessible states | |
| 128 | +# | |
| 129 | +managesDescendants=manages descendants | |
| 130 | +indeterminate=indeterminate | |
| 131 | +truncated=truncated | |
| 132 | + | |
| 133 | +# new for J2SE 1.6.0 | |
| 134 | + | |
| 135 | +# | |
| 136 | +# accessible roles | |
| 137 | +# | |
| 138 | +htmlcontainer=HTML container | |
| 139 | + | |
| 140 | +# | |
| 141 | +# END OF MATERIAL TO LOCALIZE | |
| 142 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=alerta | |
| 17 | +awtcomponent=componente AWT | |
| 18 | +checkbox=casilla de control | |
| 19 | +colorchooser=selector de color | |
| 20 | +columnheader=cabecera de columna | |
| 21 | +combobox=cuadro combinado | |
| 22 | +canvas=lienzo | |
| 23 | +desktopicon=icono de escritorio | |
| 24 | +desktoppane=panel de escritorio | |
| 25 | +dialog=cuadro de di\u00E1logo | |
| 26 | +directorypane=panel de directorio | |
| 27 | +glasspane=panel de cristal | |
| 28 | +filechooser=selector de archivos | |
| 29 | +filler=rellenador | |
| 30 | +frame=marco | |
| 31 | +internalframe=marco interno | |
| 32 | +label=etiqueta | |
| 33 | +layeredpane=panel en capas | |
| 34 | +list=lista | |
| 35 | +listitem=elemento de lista | |
| 36 | +menubar=barra de men\u00FAs | |
| 37 | +menu=men\u00FA | |
| 38 | +menuitem=elemento de men\u00FA | |
| 39 | +optionpane=panel de opciones | |
| 40 | +pagetab=separador de p\u00E1gina | |
| 41 | +pagetablist=lista de separadores de p\u00E1gina | |
| 42 | +panel=panel | |
| 43 | +passwordtext=texto de contrase\u00F1a | |
| 44 | +popupmenu=men\u00FA emergente | |
| 45 | +progressbar=barra de progreso | |
| 46 | +pushbutton=bot\u00F3n | |
| 47 | +radiobutton=bot\u00F3n de radio | |
| 48 | +rootpane=panel ra\u00EDz | |
| 49 | +rowheader=cabecera de filas | |
| 50 | +scrollbar=barra de desplazamiento | |
| 51 | +scrollpane=panel de desplazamiento | |
| 52 | +separator=separador | |
| 53 | +slider=deslizador | |
| 54 | +splitpane=panel de divisi\u00F3n | |
| 55 | +swingcomponent=componente swing | |
| 56 | +table=tabla | |
| 57 | +text=texto | |
| 58 | +tree=\u00E1rbol | |
| 59 | +togglebutton=bot\u00F3n conmutador | |
| 60 | +toolbar=barra de herramientas | |
| 61 | +tooltip=ayuda de burbuja | |
| 62 | +unknown=desconocido | |
| 63 | +viewport=viewport | |
| 64 | +window=ventana | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=etiqueta para | |
| 69 | +labeledBy=etiquetado por | |
| 70 | +memberOf=miembro de | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=activo | |
| 77 | +armed=armado | |
| 78 | +busy=ocupado | |
| 79 | +checked=activado | |
| 80 | +collapsed=reducido | |
| 81 | +editable=editable | |
| 82 | +expandable=ampliable | |
| 83 | +expanded=ampliado | |
| 84 | +enabled=activado | |
| 85 | +focusable=enfocable | |
| 86 | +focused=enfocado | |
| 87 | +iconified=convertido en icono | |
| 88 | +modal=modal | |
| 89 | +multiline=l\u00EDnea m\u00FAltiple | |
| 90 | +multiselectable=multiseleccionable | |
| 91 | +opaque=opaco | |
| 92 | +pressed=pulsado | |
| 93 | +resizable=redimensionable | |
| 94 | +selectable=seleccionable | |
| 95 | +selected=seleccionado | |
| 96 | +showing=mostrando | |
| 97 | +singleline=l\u00EDnea \u00FAnica | |
| 98 | +transient=transitorio | |
| 99 | +visible=visible | |
| 100 | +vertical=vertical | |
| 101 | +horizontal=horizontal | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expand=activar/desactivar ampliaci\u00F3n | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=llega a | |
| 113 | +flowsFrom=procede de | |
| 114 | +subwindowOf=ventana subordinada de | |
| 115 | +parentWindowOf=ventana principal de | |
| 116 | +embeds=embebe | |
| 117 | +embeddedBy=embebido por | |
| 118 | +childNodeOf=nodo secundario de | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=cabecera | |
| 124 | +footer=pie | |
| 125 | +paragraph=p\u00E1rrafo | |
| 126 | +ruler=regla | |
| 127 | +editbar=barra de edici\u00F3n | |
| 128 | +progressMonitor=monitor de progreso | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=gestiona descendientes | |
| 134 | +indeterminate=indeterminada | |
| 135 | +truncated=truncado | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=Contenedor HTML | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=alerte | |
| 17 | +awtcomponent=composant AWT | |
| 18 | +checkbox=case \u00E0 cocher | |
| 19 | +colorchooser=s\u00E9lecteur de couleurs | |
| 20 | +columnheader=en-t\u00EAte de colonne | |
| 21 | +combobox=liste d\u00E9roulante | |
| 22 | +canvas=canevas | |
| 23 | +desktopicon=ic\u00F4ne de bureau | |
| 24 | +desktoppane=panneau de bureau | |
| 25 | +dialog=bo\u00EEte de dialogue | |
| 26 | +directorypane=panneau de r\u00E9pertoires | |
| 27 | +glasspane=panneau de grossissement | |
| 28 | +filechooser=s\u00E9lecteur de fichiers | |
| 29 | +filler=\u00E9l\u00E9ment de remplissage | |
| 30 | +frame=cadre | |
| 31 | +internalframe=cadre interne | |
| 32 | +label=libell\u00E9 | |
| 33 | +layeredpane=panneau superpos\u00E9 | |
| 34 | +list=liste | |
| 35 | +listitem=\u00E9l\u00E9ment de liste | |
| 36 | +menubar=barre de menus | |
| 37 | +menu=menu | |
| 38 | +menuitem=option de menu | |
| 39 | +optionpane=panneau d'options | |
| 40 | +pagetab=onglet de page | |
| 41 | +pagetablist=liste d'onglets de page | |
| 42 | +panel=panneau | |
| 43 | +passwordtext=texte de mot de passe | |
| 44 | +popupmenu=menu contextuel | |
| 45 | +progressbar=barre de progression | |
| 46 | +pushbutton=bouton | |
| 47 | +radiobutton=bouton radio | |
| 48 | +rootpane=panneau racine | |
| 49 | +rowheader=en-t\u00EAte de ligne | |
| 50 | +scrollbar=barre de d\u00E9filement | |
| 51 | +scrollpane=panneau de d\u00E9filement | |
| 52 | +separator=s\u00E9parateur | |
| 53 | +slider=curseur | |
| 54 | +splitpane=panneau divis\u00E9 | |
| 55 | +swingcomponent=composant Swing | |
| 56 | +table=tableau | |
| 57 | +text=texte | |
| 58 | +tree=arborescence | |
| 59 | +togglebutton=bouton de basculement | |
| 60 | +toolbar=barre d'outils | |
| 61 | +tooltip=info-bulle | |
| 62 | +unknown=inconnu | |
| 63 | +viewport=lucarne | |
| 64 | +window=fen\u00EAtre | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=libell\u00E9 de | |
| 69 | +labeledBy=libell\u00E9 par | |
| 70 | +memberOf=membre de | |
| 71 | +controlledBy=contr\u00F4l\u00E9 par | |
| 72 | +controllerFor=contr\u00F4leur pour | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=actif | |
| 77 | +armed=arm\u00E9 | |
| 78 | +busy=occup\u00E9 | |
| 79 | +checked=coch\u00E9 | |
| 80 | +collapsed=r\u00E9duit | |
| 81 | +editable=modifiable | |
| 82 | +expandable=extensible | |
| 83 | +expanded=d\u00E9velopp\u00E9 | |
| 84 | +enabled=activ\u00E9 | |
| 85 | +focusable=zone d'entr\u00E9e possible | |
| 86 | +focused=avec zone d'entr\u00E9e | |
| 87 | +iconified=r\u00E9duit \u00E0 une ic\u00F4ne | |
| 88 | +modal=modal | |
| 89 | +multiline=ligne multiple | |
| 90 | +multiselectable=multis\u00E9lectionnable | |
| 91 | +opaque=opaque | |
| 92 | +pressed=enfonc\u00E9 | |
| 93 | +resizable=redimensionnable | |
| 94 | +selectable=s\u00E9lectionnable | |
| 95 | +selected=s\u00E9lectionn\u00E9 | |
| 96 | +showing=montrant | |
| 97 | +singleline=ligne unique | |
| 98 | +transient=non persistant | |
| 99 | +visible=visible | |
| 100 | +vertical=vertical | |
| 101 | +horizontal=horizontal | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expand=basculer le d\u00E9veloppement | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=flux vers | |
| 113 | +flowsFrom=flux depuis | |
| 114 | +subwindowOf=sous-fen\u00EAtre de | |
| 115 | +parentWindowOf=fen\u00EAtre parente de | |
| 116 | +embeds=incorpore | |
| 117 | +embeddedBy=incorpor\u00E9 par | |
| 118 | +childNodeOf=noeud enfant de | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=en-t\u00EAte | |
| 124 | +footer=pied de page | |
| 125 | +paragraph=paragraphe | |
| 126 | +ruler=r\u00E8gle | |
| 127 | +editbar=barre d'\u00E9dition | |
| 128 | +progressMonitor=contr\u00F4le de la progression | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=g\u00E8re les descendants | |
| 134 | +indeterminate=ind\u00E9termin\u00E9 | |
| 135 | +truncated=tronqu\u00E9 | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=conteneur HTML | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=avviso | |
| 17 | +awtcomponent=componente AWT | |
| 18 | +checkbox=casella di controllo | |
| 19 | +colorchooser=selezione colori | |
| 20 | +columnheader=intestazione colonna | |
| 21 | +combobox=casella combinata | |
| 22 | +canvas=sfondo | |
| 23 | +desktopicon=icona desktop | |
| 24 | +desktoppane=riquadro desktop | |
| 25 | +dialog=finestra di dialogo | |
| 26 | +directorypane=riquadro directory | |
| 27 | +glasspane=riquadro trasparente | |
| 28 | +filechooser=selezione file | |
| 29 | +filler=utilit\u00E0 riempimento | |
| 30 | +frame=cornice | |
| 31 | +internalframe=cornice interna | |
| 32 | +label=etichetta | |
| 33 | +layeredpane=riquadro a livelli | |
| 34 | +list=lista | |
| 35 | +listitem=voce lista | |
| 36 | +menubar=barra dei menu | |
| 37 | +menu=menu | |
| 38 | +menuitem=voce di menu | |
| 39 | +optionpane=riquadro opzioni | |
| 40 | +pagetab=scheda pagina | |
| 41 | +pagetablist=lista schede pagina | |
| 42 | +panel=pannello | |
| 43 | +passwordtext=testo della password | |
| 44 | +popupmenu=menu popup | |
| 45 | +progressbar=barra di avanzamento | |
| 46 | +pushbutton=pulsante | |
| 47 | +radiobutton=pulsante di scelta | |
| 48 | +rootpane=riquadro root | |
| 49 | +rowheader=intestazione di riga | |
| 50 | +scrollbar=barra di scorrimento | |
| 51 | +scrollpane=riquadro scorrimento | |
| 52 | +separator=separatore | |
| 53 | +slider=dispositivo di scorrimento | |
| 54 | +splitpane=riquadro doppio | |
| 55 | +swingcomponent=componente swing | |
| 56 | +table=tabella | |
| 57 | +text=testo | |
| 58 | +tree=albero | |
| 59 | +togglebutton=interruttore | |
| 60 | +toolbar=barra degli strumenti | |
| 61 | +tooltip=descrizione comandi | |
| 62 | +unknown=sconosciuto | |
| 63 | +viewport=viewport | |
| 64 | +window=finestra | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=etichetta per | |
| 69 | +labeledBy=etichetta di | |
| 70 | +memberOf=membro di | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=attivo | |
| 77 | +armed=abilitato | |
| 78 | +busy=occupato | |
| 79 | +checked=verificato | |
| 80 | +collapsed=compresso | |
| 81 | +editable=modificabile | |
| 82 | +expandable=espandibile | |
| 83 | +expanded=espanso | |
| 84 | +enabled=abilitato | |
| 85 | +focusable=attivabile in primo piano | |
| 86 | +focused=in primo piano | |
| 87 | +iconified=ridotto a icona | |
| 88 | +modal=modale | |
| 89 | +multiline=a righe multiple | |
| 90 | +multiselectable=multi-selezionabile | |
| 91 | +opaque=nascosto | |
| 92 | +pressed=premuto | |
| 93 | +resizable=ridimensionabile | |
| 94 | +selectable=selezionabile | |
| 95 | +selected=selezionato | |
| 96 | +showing=visualizzato | |
| 97 | +singleline=a riga singola | |
| 98 | +transient=transitorio | |
| 99 | +visible=visibile | |
| 100 | +vertical=verticale | |
| 101 | +horizontal=orizzontale | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expand=abilita/disabilita espansione | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=va verso | |
| 113 | +flowsFrom=proviene da | |
| 114 | +subwindowOf=sottofinestra di | |
| 115 | +parentWindowOf=finestra di livello superiore di | |
| 116 | +embeds=incorpora | |
| 117 | +embeddedBy=incorporato da | |
| 118 | +childNodeOf=nodo figlio di | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=intestazione | |
| 124 | +footer=pi\u00E8 di pagina | |
| 125 | +paragraph=paragrafo | |
| 126 | +ruler=righello | |
| 127 | +editbar=barra di modifica | |
| 128 | +progressMonitor=stato avanzamento | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=gestisce i discendenti | |
| 134 | +indeterminate=indeterminato | |
| 135 | +truncated=troncato | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=Contenitore HTML | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=\u30A2\u30E9\u30FC\u30C8 | |
| 17 | +awtcomponent=AWT\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8 | |
| 18 | +checkbox=\u30C1\u30A7\u30C3\u30AF\u30FB\u30DC\u30C3\u30AF\u30B9 | |
| 19 | +colorchooser=\u30AB\u30E9\u30FC\u30FB\u30C1\u30E5\u30FC\u30B6 | |
| 20 | +columnheader=\u5217\u30D8\u30C3\u30C0\u30FC | |
| 21 | +combobox=\u30B3\u30F3\u30DC\u30FB\u30DC\u30C3\u30AF\u30B9 | |
| 22 | +canvas=\u30AD\u30E3\u30F3\u30D0\u30B9 | |
| 23 | +desktopicon=\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u30FB\u30A2\u30A4\u30B3\u30F3 | |
| 24 | +desktoppane=\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u533A\u753B | |
| 25 | +dialog=\u30C0\u30A4\u30A2\u30ED\u30B0 | |
| 26 | +directorypane=\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u533A\u753B | |
| 27 | +glasspane=\u30AC\u30E9\u30B9\u533A\u753B | |
| 28 | +filechooser=\u30D5\u30A1\u30A4\u30EB\u30FB\u30C1\u30E5\u30FC\u30B6 | |
| 29 | +filler=\u30D5\u30A3\u30E9\u30FC | |
| 30 | +frame=\u30D5\u30EC\u30FC\u30E0 | |
| 31 | +internalframe=\u5185\u90E8\u30D5\u30EC\u30FC\u30E0 | |
| 32 | +label=\u30E9\u30D9\u30EB | |
| 33 | +layeredpane=\u968E\u5C64\u5316\u3055\u308C\u305F\u533A\u753B | |
| 34 | +list=\u30EA\u30B9\u30C8 | |
| 35 | +listitem=\u30EA\u30B9\u30C8\u9805\u76EE | |
| 36 | +menubar=\u30E1\u30CB\u30E5\u30FC\u30FB\u30D0\u30FC | |
| 37 | +menu=\u30E1\u30CB\u30E5\u30FC | |
| 38 | +menuitem=\u30E1\u30CB\u30E5\u30FC\u9805\u76EE | |
| 39 | +optionpane=\u30AA\u30D7\u30B7\u30E7\u30F3\u533A\u753B | |
| 40 | +pagetab=\u30DA\u30FC\u30B8\u30FB\u30BF\u30D6 | |
| 41 | +pagetablist=\u30DA\u30FC\u30B8\u30FB\u30BF\u30D6\u30FB\u30EA\u30B9\u30C8 | |
| 42 | +panel=\u30D1\u30CD\u30EB | |
| 43 | +passwordtext=\u30D1\u30B9\u30EF\u30FC\u30C9\u30FB\u30C6\u30AD\u30B9\u30C8 | |
| 44 | +popupmenu=\u30DD\u30C3\u30D7\u30A2\u30C3\u30D7\u30FB\u30E1\u30CB\u30E5\u30FC | |
| 45 | +progressbar=\u9032\u6357\u30D0\u30FC | |
| 46 | +pushbutton=\u30D7\u30C3\u30B7\u30E5\u30FB\u30DC\u30BF\u30F3 | |
| 47 | +radiobutton=\u30E9\u30B8\u30AA\u30FB\u30DC\u30BF\u30F3 | |
| 48 | +rootpane=\u30EB\u30FC\u30C8\u533A\u753B | |
| 49 | +rowheader=\u884C\u30D8\u30C3\u30C0\u30FC | |
| 50 | +scrollbar=\u30B9\u30AF\u30ED\u30FC\u30EB\u30FB\u30D0\u30FC | |
| 51 | +scrollpane=\u30B9\u30AF\u30ED\u30FC\u30EB\u533A\u753B | |
| 52 | +separator=\u30BB\u30D1\u30EC\u30FC\u30BF | |
| 53 | +slider=\u30B9\u30E9\u30A4\u30C0 | |
| 54 | +splitpane=\u5206\u5272\u533A\u753B | |
| 55 | +swingcomponent=Swing\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8 | |
| 56 | +table=\u8868 | |
| 57 | +text=\u30C6\u30AD\u30B9\u30C8 | |
| 58 | +tree=\u30C4\u30EA\u30FC | |
| 59 | +togglebutton=\u30C8\u30B0\u30EB\u30FB\u30DC\u30BF\u30F3 | |
| 60 | +toolbar=\u30C4\u30FC\u30EB\u30D0\u30FC | |
| 61 | +tooltip=\u30C4\u30FC\u30EB\u30C1\u30C3\u30D7 | |
| 62 | +unknown=\u4E0D\u660E | |
| 63 | +viewport=\u30D3\u30E5\u30FC\u30DD\u30FC\u30C8 | |
| 64 | +window=\u30A6\u30A3\u30F3\u30C9\u30A6 | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=label for | |
| 69 | +labeledBy=labeled by | |
| 70 | +memberOf=member of | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=\u30A2\u30AF\u30C6\u30A3\u30D6 | |
| 77 | +armed=\u4F5C\u52D5\u6E96\u5099\u5B8C\u4E86 | |
| 78 | +busy=\u30D3\u30B8\u30FC | |
| 79 | +checked=\u30C1\u30A7\u30C3\u30AF | |
| 80 | +collapsed=\u77ED\u7E2E | |
| 81 | +editable=\u7DE8\u96C6\u53EF\u80FD | |
| 82 | +expandable=\u5C55\u958B\u53EF\u80FD | |
| 83 | +expanded=\u5C55\u958B | |
| 84 | +enabled=\u6709\u52B9 | |
| 85 | +focusable=\u30D5\u30A9\u30FC\u30AB\u30B9\u53EF\u80FD | |
| 86 | +focused=\u30D5\u30A9\u30FC\u30AB\u30B9 | |
| 87 | +iconified=\u30A2\u30A4\u30B3\u30F3\u5316 | |
| 88 | +modal=\u30E2\u30FC\u30C0\u30EB | |
| 89 | +multiline=\u8907\u6570\u884C | |
| 90 | +multiselectable=\u8907\u6570\u9078\u629E\u53EF\u80FD | |
| 91 | +opaque=\u4E0D\u900F\u660E | |
| 92 | +pressed=\u62BC\u4E0B | |
| 93 | +resizable=\u30B5\u30A4\u30BA\u5909\u66F4\u53EF\u80FD | |
| 94 | +selectable=\u9078\u629E\u53EF\u80FD | |
| 95 | +selected=\u9078\u629E | |
| 96 | +showing=\u8868\u793A | |
| 97 | +singleline=\u5358\u4E00\u884C | |
| 98 | +transient=\u4E00\u6642 | |
| 99 | +visible=\u53EF\u8996 | |
| 100 | +vertical=\u5782\u76F4 | |
| 101 | +horizontal=\u6C34\u5E73 | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expand=\u30C8\u30B0\u30EB\u5C55\u958B | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=flows to | |
| 113 | +flowsFrom=flows from | |
| 114 | +subwindowOf=subwindow of | |
| 115 | +parentWindowOf=parent window of | |
| 116 | +embeds=\u57CB\u8FBC\u307F | |
| 117 | +embeddedBy=embedded by | |
| 118 | +childNodeOf=child node of | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=\u30D8\u30C3\u30C0\u30FC | |
| 124 | +footer=\u30D5\u30C3\u30BF\u30FC | |
| 125 | +paragraph=\u6BB5\u843D | |
| 126 | +ruler=\u30EB\u30FC\u30E9\u30FC | |
| 127 | +editbar=\u7DE8\u96C6\u30D0\u30FC | |
| 128 | +progressMonitor=\u9032\u6357\u30E2\u30CB\u30BF\u30FC | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=\u5B50\u5B6B\u3092\u7BA1\u7406 | |
| 134 | +indeterminate=\u4E0D\u78BA\u5B9A | |
| 135 | +truncated=\u4E0D\u5B8C\u5168 | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=HTML\u30B3\u30F3\u30C6\u30CA | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=\uACBD\uBCF4 | |
| 17 | +awtcomponent=AWT \uAD6C\uC131 \uC694\uC18C | |
| 18 | +checkbox=\uCCB4\uD06C \uBC15\uC2A4 | |
| 19 | +colorchooser=\uC0C9\uC0C1 \uC120\uD0DD\uAE30 | |
| 20 | +columnheader=\uC5F4 \uBA38\uB9AC\uAE00 | |
| 21 | +combobox=\uCF64\uBCF4 \uC0C1\uC790 | |
| 22 | +canvas=\uCE94\uBC84\uC2A4 | |
| 23 | +desktopicon=\uBC14\uD0D5 \uD654\uBA74 \uC544\uC774\uCF58 | |
| 24 | +desktoppane=\uBC14\uD0D5 \uD654\uBA74 \uCC3D | |
| 25 | +dialog=\uB300\uD654\uC0C1\uC790 | |
| 26 | +directorypane=\uB514\uB809\uD1A0\uB9AC \uCC3D | |
| 27 | +glasspane=\uAE00\uB798\uC2A4 \uCC3D | |
| 28 | +filechooser=\uD30C\uC77C \uC120\uD0DD\uAE30 | |
| 29 | +filler=\uD544\uB7EC | |
| 30 | +frame=\uD504\uB808\uC784 | |
| 31 | +internalframe=\uB0B4\uBD80 \uD504\uB808\uC784 | |
| 32 | +label=\uB808\uC774\uBE14 | |
| 33 | +layeredpane=\uACC4\uCE35\uC801 \uCC3D | |
| 34 | +list=\uBAA9\uB85D | |
| 35 | +listitem=\uBAA9\uB85D \uD56D\uBAA9 | |
| 36 | +menubar=\uBA54\uB274 \uD45C\uC2DC\uC904 | |
| 37 | +menu=\uBA54\uB274 | |
| 38 | +menuitem=\uBA54\uB274 \uD56D\uBAA9 | |
| 39 | +optionpane=\uC635\uC158 \uCC3D | |
| 40 | +pagetab=\uD398\uC774\uC9C0 \uD0ED | |
| 41 | +pagetablist=\uD398\uC774\uC9C0 \uD0ED \uBAA9\uB85D | |
| 42 | +panel=\uD328\uB110 | |
| 43 | +passwordtext=\uBE44\uBC00\uBC88\uD638 \uD14D\uC2A4\uD2B8 | |
| 44 | +popupmenu=\uD31D\uC5C5 \uBA54\uB274 | |
| 45 | +progressbar=\uC9C4\uD589 \uB9C9\uB300 | |
| 46 | +pushbutton=\uB204\uB984 \uB2E8\uCD94 | |
| 47 | +radiobutton=\uB77C\uB514\uC624 \uB2E8\uCD94 | |
| 48 | +rootpane=\uB8E8\uD2B8 \uCC3D | |
| 49 | +rowheader=\uD589 \uBA38\uB9AC\uAE00 | |
| 50 | +scrollbar=\uC2A4\uD06C\uB864 \uB9C9\uB300 | |
| 51 | +scrollpane=\uC2A4\uD06C\uB864 \uCC3D | |
| 52 | +separator=\uAD6C\uBD84 \uAE30\uD638 | |
| 53 | +slider=\uC2AC\uB77C\uC774\uB354 | |
| 54 | +splitpane=\uBD84\uD560 \uCC3D | |
| 55 | +swingcomponent=\uD68C\uC804 \uAD6C\uC131 \uC694\uC18C | |
| 56 | +table=\uD14C\uC774\uBE14 | |
| 57 | +text=\uD14D\uC2A4\uD2B8 | |
| 58 | +tree=\uD2B8\uB9AC | |
| 59 | +togglebutton=\uD1A0\uAE00 \uB2E8\uCD94 | |
| 60 | +toolbar=\uB3C4\uAD6C \uBAA8\uC74C | |
| 61 | +tooltip=\uB3C4\uAD6C \uC124\uBA85 | |
| 62 | +unknown=\uC54C \uC218 \uC5C6\uC74C | |
| 63 | +viewport=\uBDF0\uD3EC\uD2B8 | |
| 64 | +window=\uCC3D | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=\uB808\uC774\uBE14 \uB300\uC0C1 | |
| 69 | +labeledBy=\uB808\uC774\uBE14 \uC9C0\uC815\uC790 | |
| 70 | +memberOf=\uC18C\uC18D \uADF8\uB8F9 | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=\uD65C\uC131 | |
| 77 | +armed=\uD06C\uAE30 | |
| 78 | +busy=\uC0AC\uC6A9 \uC911 | |
| 79 | +checked=\uC120\uD0DD\uB428 | |
| 80 | +collapsed=\uCD95\uC18C\uB428 | |
| 81 | +editable=\uD3B8\uC9D1 \uAC00\uB2A5 | |
| 82 | +expandable=\uD655\uC7A5 \uAC00\uB2A5 | |
| 83 | +expanded=\uD655\uC7A5\uB428 | |
| 84 | +enabled=\uC0AC\uC6A9 | |
| 85 | +focusable=\uD3EC\uCEE4\uC2A4 \uAC00\uB2A5 | |
| 86 | +focused=\uD3EC\uCEE4\uC2A4\uB428 | |
| 87 | +iconified=\uC544\uC774\uCF58\uD654\uB428 | |
| 88 | +modal=\uBAA8\uB2EC | |
| 89 | +multiline=\uBCF5\uC218 \uD589 | |
| 90 | +multiselectable=\uB2E4\uC911 \uC120\uD0DD \uAC00\uB2A5 | |
| 91 | +opaque=\uBD88\uD22C\uBA85 | |
| 92 | +pressed=\uB204\uB984 | |
| 93 | +resizable=\uD06C\uAE30 \uC870\uC815 \uAC00\uB2A5 | |
| 94 | +selectable=\uC120\uD0DD \uAC00\uB2A5 | |
| 95 | +selected=\uC120\uD0DD\uB428 | |
| 96 | +showing=\uD45C\uC2DC | |
| 97 | +singleline=\uD55C \uC904 | |
| 98 | +transient=\uC77C\uC2DC | |
| 99 | +visible=\uD45C\uC2DC \uAC00\uB2A5 | |
| 100 | +vertical=\uC138\uB85C | |
| 101 | +horizontal=\uAC00\uB85C | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle \uD655\uC7A5=\uD1A0\uAE00 \uD655\uC7A5 | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=\uD750\uB984 \uB300\uC0C1 | |
| 113 | +flowsFrom=\uD750\uB984 \uCD9C\uCC98 | |
| 114 | +subwindowOf=\uD558\uC704 \uCC3D | |
| 115 | +parentWindowOf=\uC0C1\uC704 \uCC3D | |
| 116 | +embeds=\uD3EC\uD568 | |
| 117 | +embeddedBy=\uD3EC\uD568 \uC8FC\uCCB4 | |
| 118 | +childNodeOf=\uD558\uC704 \uB178\uB4DC | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=\uBA38\uB9AC\uAE00 | |
| 124 | +footer=\uBC14\uB2E5\uAE00 | |
| 125 | +paragraph=\uB2E8\uB77D | |
| 126 | +ruler=\uB208\uAE08\uC790 | |
| 127 | +editbar=\uD3B8\uC9D1 \uB3C4\uAD6C | |
| 128 | +progressMonitor=\uC9C4\uD589 \uBAA8\uB2C8\uD130 | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=\uC885\uC18D \uD56D\uBAA9 \uAD00\uB9AC | |
| 134 | +indeterminate=\uD655\uC815\uB418\uC9C0 \uC54A\uC74C | |
| 135 | +truncated=\uC798\uB9BC | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=HTML \uCEE8\uD14C\uC774\uB108 | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=alerta | |
| 17 | +awtcomponent=componente AWT | |
| 18 | +checkbox=caixa de sele\u00E7\u00E3o | |
| 19 | +colorchooser=seletor de cores | |
| 20 | +columnheader=cabe\u00E7alho da coluna | |
| 21 | +combobox=caixa de combina\u00E7\u00E3o | |
| 22 | +canvas=tela | |
| 23 | +desktopicon=\u00EDcone da \u00E1rea de trabalho | |
| 24 | +desktoppane=painel da \u00E1rea de trabalho | |
| 25 | +dialog=caixa de di\u00E1logo | |
| 26 | +directorypane=painel do diret\u00F3rio | |
| 27 | +glasspane=painel transparente | |
| 28 | +filechooser=seletor de arquivos | |
| 29 | +filler=preenchedor | |
| 30 | +frame=quadro | |
| 31 | +internalframe=quadro interno | |
| 32 | +label=r\u00F3tulo | |
| 33 | +layeredpane=painel em camadas | |
| 34 | +list=lista | |
| 35 | +listitem=item da lista | |
| 36 | +menubar=barra de menus | |
| 37 | +menu=menu | |
| 38 | +menuitem=item do menu | |
| 39 | +optionpane=painel de op\u00E7\u00F5es | |
| 40 | +pagetab=guia da p\u00E1gina | |
| 41 | +pagetablist=lista de guias da p\u00E1gina | |
| 42 | +panel=painel | |
| 43 | +passwordtext=texto da senha | |
| 44 | +popupmenu=menu pop-up | |
| 45 | +progressbar=barra de progresso | |
| 46 | +pushbutton=bot\u00E3o de a\u00E7\u00E3o | |
| 47 | +radiobutton=bot\u00E3o de op\u00E7\u00E3o | |
| 48 | +rootpane=painel base | |
| 49 | +rowheader=cabe\u00E7alho da linha | |
| 50 | +scrollbar=barra de rolagem | |
| 51 | +scrollpane=painel de rolagem | |
| 52 | +separator=separador | |
| 53 | +slider=controle deslizante | |
| 54 | +splitpane=painel dividido | |
| 55 | +swingcomponent=componente swing | |
| 56 | +table=tabela | |
| 57 | +text=texto | |
| 58 | +tree=\u00E1rvore | |
| 59 | +togglebutton=bot\u00E3o de altern\u00E2ncia | |
| 60 | +toolbar=barra de ferramentas | |
| 61 | +tooltip=dica de ferramenta | |
| 62 | +unknown=desconhecido | |
| 63 | +viewport=janela de visualiza\u00E7\u00E3o | |
| 64 | +window=janela | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=r\u00F3tulo de | |
| 69 | +labeledBy=rotulado por | |
| 70 | +memberOf=membro de | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=ativo | |
| 77 | +armed=armado | |
| 78 | +busy=ocupado | |
| 79 | +checked=selecionado | |
| 80 | +collapsed=recolhido | |
| 81 | +editable=edit\u00E1vel | |
| 82 | +expandable=expans\u00EDvel | |
| 83 | +expanded=expandido | |
| 84 | +enabled=ativado | |
| 85 | +focusable=focaliz\u00E1vel | |
| 86 | +focused=focalizado | |
| 87 | +iconified=iconizado | |
| 88 | +modal=modal | |
| 89 | +multiline=v\u00E1rias linhas | |
| 90 | +multiselectable=m\u00FAltipla escolha | |
| 91 | +opaque=opaco | |
| 92 | +pressed=pressionado | |
| 93 | +resizable=redimension\u00E1vel | |
| 94 | +selectable=selecion\u00E1vel | |
| 95 | +selected=selecionado | |
| 96 | +showing=mostrando | |
| 97 | +singleline=linha \u00FAnica | |
| 98 | +transient=transit\u00F3rio | |
| 99 | +visible=vis\u00EDvel | |
| 100 | +vertical=vertical | |
| 101 | +horizontal=horizontal | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expandir=alternar expans\u00E3o | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=fluxos para | |
| 113 | +flowsFrom=fluxos de | |
| 114 | +subwindowOf=subjanela de | |
| 115 | +parentWindowOf=janela pai de | |
| 116 | +embeds=integra | |
| 117 | +embeddedBy=integrado por | |
| 118 | +childNodeOf=n\u00F3 filho de | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=cabe\u00E7alho | |
| 124 | +footer=rodap\u00E9 | |
| 125 | +paragraph=par\u00E1grafo | |
| 126 | +ruler=r\u00E9gua | |
| 127 | +editbar=barra de edi\u00E7\u00E3o | |
| 128 | +progressMonitor=monitor de progresso | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=gerencia descendentes | |
| 134 | +indeterminate=indeterminado | |
| 135 | +truncated=truncado | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=Container de HTML | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=avisering | |
| 17 | +awtcomponent=AWT-komponent | |
| 18 | +checkbox=kryssruta | |
| 19 | +colorchooser=f\u00E4rgv\u00E4ljare | |
| 20 | +columnheader=kolumnrubrik | |
| 21 | +combobox=kombinationsruta | |
| 22 | +canvas=rityta | |
| 23 | +desktopicon=skrivbordsikon | |
| 24 | +desktoppane=skrivbordsruta | |
| 25 | +dialog=dialogruta | |
| 26 | +directorypane=katalogruta | |
| 27 | +glasspane=glasruta | |
| 28 | +filechooser=filv\u00E4ljare | |
| 29 | +filler=utfyllnad | |
| 30 | +frame=ram | |
| 31 | +internalframe=intern ram | |
| 32 | +label=etikett | |
| 33 | +layeredpane=staplad ruta | |
| 34 | +list=lista | |
| 35 | +listitem=listobjekt | |
| 36 | +menubar=menyrad | |
| 37 | +menu=meny | |
| 38 | +menuitem=menyalternativ | |
| 39 | +optionpane=alternativruta | |
| 40 | +pagetab=sidflik | |
| 41 | +pagetablist=sidflikslista | |
| 42 | +panel=panel | |
| 43 | +passwordtext=l\u00F6senordstext | |
| 44 | +popupmenu=snabbmeny | |
| 45 | +progressbar=statusrad | |
| 46 | +pushbutton=knapp | |
| 47 | +radiobutton=alternativknapp | |
| 48 | +rootpane=grundruta | |
| 49 | +rowheader=radrubrik | |
| 50 | +scrollbar=rullningslist | |
| 51 | +scrollpane=rullningsruta | |
| 52 | +separator=avskiljare | |
| 53 | +slider=skjutreglage | |
| 54 | +splitpane=delad ruta | |
| 55 | +swingcomponent=swing-komponent | |
| 56 | +table=tabell | |
| 57 | +text=text | |
| 58 | +tree=tr\u00E4d | |
| 59 | +togglebutton=v\u00E4xlingsknapp | |
| 60 | +toolbar=verktygsrad | |
| 61 | +tooltip=knappbeskrivning | |
| 62 | +unknown=ok\u00E4nd | |
| 63 | +viewport=vyport | |
| 64 | +window=f\u00F6nster | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=etikett f\u00F6r | |
| 69 | +labeledBy=etikett av | |
| 70 | +memberOf=medlem i | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=aktiv | |
| 77 | +armed=redo | |
| 78 | +busy=upptagen | |
| 79 | +checked=markerad | |
| 80 | +collapsed=komprimerad | |
| 81 | +editable=redigerbar | |
| 82 | +expandable=ut\u00F6kningsbar | |
| 83 | +expanded=ut\u00F6kad | |
| 84 | +enabled=aktiverad | |
| 85 | +focusable=fokuseringsbar | |
| 86 | +focused=fokuserad | |
| 87 | +iconified=minimerad | |
| 88 | +modal=modal | |
| 89 | +multiline=flera rader | |
| 90 | +multiselectable=flerval | |
| 91 | +opaque=t\u00E4ckande | |
| 92 | +pressed=nedtryckt | |
| 93 | +resizable=storleks\u00E4ndringsbar | |
| 94 | +selectable=valbar | |
| 95 | +selected=vald | |
| 96 | +showing=visas | |
| 97 | +singleline=en rad | |
| 98 | +transient=tillf\u00E4llig | |
| 99 | +visible=synlig | |
| 100 | +vertical=vertikal | |
| 101 | +horizontal=horisontell | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle ut\u00F6ka=v\u00E4xla ut\u00F6ka | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=fl\u00F6dar till | |
| 113 | +flowsFrom=fl\u00F6dar fr\u00E5n | |
| 114 | +subwindowOf=delf\u00F6nster av | |
| 115 | +parentWindowOf=\u00F6verordnat f\u00F6nster f\u00F6r | |
| 116 | +embeds=b\u00E4ddar in | |
| 117 | +embeddedBy=b\u00E4ddas in av | |
| 118 | +childNodeOf=underordnad nod f\u00F6r | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=sidhuvud | |
| 124 | +footer=sidfot | |
| 125 | +paragraph=stycke | |
| 126 | +ruler=linjal | |
| 127 | +editbar=redigeringslist | |
| 128 | +progressMonitor=f\u00F6rlopps\u00F6vervakare | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=hanterar underordnade | |
| 134 | +indeterminate=obest\u00E4mt | |
| 135 | +truncated=kapad | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=HTML-container | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=\u9884\u8B66 | |
| 17 | +awtcomponent=AWT \u7EC4\u4EF6 | |
| 18 | +checkbox=\u590D\u9009\u6846 | |
| 19 | +colorchooser=\u989C\u8272\u9009\u62E9\u5668 | |
| 20 | +columnheader=\u5217\u6807\u9898 | |
| 21 | +combobox=\u7EC4\u5408\u6846 | |
| 22 | +canvas=\u753B\u5E03 | |
| 23 | +desktopicon=\u684C\u9762\u56FE\u6807 | |
| 24 | +desktoppane=\u684C\u9762\u7A97\u683C | |
| 25 | +dialog=\u5BF9\u8BDD | |
| 26 | +directorypane=\u76EE\u5F55\u7A97\u683C | |
| 27 | +glasspane=\u73BB\u7483\u7A97\u683C | |
| 28 | +filechooser=\u6587\u4EF6\u9009\u62E9\u5668 | |
| 29 | +filler=\u6F0F\u6597 | |
| 30 | +frame=\u5E27 | |
| 31 | +internalframe=\u5185\u90E8\u5E27 | |
| 32 | +label=\u6807\u7B7E | |
| 33 | +layeredpane=\u5206\u5C42\u7A97\u683C | |
| 34 | +list=\u5217\u8868 | |
| 35 | +listitem=\u5217\u8868\u9879 | |
| 36 | +menubar=\u83DC\u5355\u680F | |
| 37 | +menu=\u83DC\u5355 | |
| 38 | +menuitem=\u83DC\u5355\u9879 | |
| 39 | +optionpane=\u9009\u9879\u7A97\u683C | |
| 40 | +pagetab=\u9875\u6807\u7B7E | |
| 41 | +pagetablist=\u9875\u6807\u7B7E\u5217\u8868 | |
| 42 | +panel=\u9762\u677F | |
| 43 | +passwordtext=\u53E3\u4EE4\u6587\u672C | |
| 44 | +popupmenu=\u5F39\u51FA\u5F0F\u83DC\u5355 | |
| 45 | +progressbar=\u8FDB\u5EA6\u680F | |
| 46 | +pushbutton=\u6309\u94AE | |
| 47 | +radiobutton=\u5355\u9009\u6309\u94AE | |
| 48 | +rootpane=\u6839\u7A97\u683C | |
| 49 | +rowheader=\u884C\u6807\u9898 | |
| 50 | +scrollbar=\u6EDA\u52A8\u6761 | |
| 51 | +scrollpane=\u6EDA\u52A8\u7A97\u683C | |
| 52 | +separator=\u5206\u9694\u6761 | |
| 53 | +slider=\u6ED1\u5757 | |
| 54 | +splitpane=\u62C6\u5206\u7A97\u683C | |
| 55 | +swingcomponent=\u65CB\u8F6C\u7EC4\u4EF6 | |
| 56 | +table=\u8868 | |
| 57 | +text=\u6587\u672C | |
| 58 | +tree=\u6811 | |
| 59 | +togglebutton=\u5207\u6362\u6309\u94AE | |
| 60 | +toolbar=\u5DE5\u5177\u680F | |
| 61 | +tooltip=\u5DE5\u5177\u63D0\u793A | |
| 62 | +unknown=\u672A\u77E5 | |
| 63 | +viewport=\u89C6\u7A97 | |
| 64 | +window=\u7A97\u53E3 | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=\u6807\u7B7E\u5C5E\u4E8E | |
| 69 | +labeledBy=\u6807\u7B7E\u5236\u4F5C\u8005 | |
| 70 | +memberOf=\u5C5E\u4E8E | |
| 71 | +controlledBy=controlledBy | |
| 72 | +controllerFor=controllerFor | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=\u6D3B\u52A8 | |
| 77 | +armed=\u5F85\u547D | |
| 78 | +busy=\u5FD9 | |
| 79 | +checked=\u5DF2\u9009\u4E2D | |
| 80 | +collapsed=\u5DF2\u6536\u7F29 | |
| 81 | +editable=\u53EF\u7F16\u8F91 | |
| 82 | +expandable=\u53EF\u5C55\u5F00 | |
| 83 | +expanded=\u5DF2\u5C55\u5F00 | |
| 84 | +enabled=\u542F\u7528 | |
| 85 | +focusable=\u53EF\u96C6\u4E2D | |
| 86 | +focused=\u5DF2\u96C6\u4E2D | |
| 87 | +iconified=\u56FE\u6807\u5F0F | |
| 88 | +modal=\u6A21\u6001 | |
| 89 | +multiline=\u591A\u884C | |
| 90 | +multiselectable=\u591A\u9009\u62E9 | |
| 91 | +opaque=\u4E0D\u900F\u660E | |
| 92 | +pressed=\u5DF2\u6309\u4E0B | |
| 93 | +resizable=\u53EF\u8C03\u6574\u5927\u5C0F | |
| 94 | +selectable=\u53EF\u9009\u62E9 | |
| 95 | +selected=\u6240\u9009 | |
| 96 | +showing=\u6B63\u5728\u663E\u793A | |
| 97 | +singleline=\u5355\u884C | |
| 98 | +transient=\u77AC\u65F6 | |
| 99 | +visible=\u53EF\u89C1 | |
| 100 | +vertical=\u5782\u76F4 | |
| 101 | +horizontal=\u6C34\u5E73 | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expand=\u5207\u6362\u5C55\u5F00 | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=\u6D41\u5411 | |
| 113 | +flowsFrom=\u6D41\u81EA | |
| 114 | +subwindowOf=\u5B50\u7A97\u53E3 | |
| 115 | +parentWindowOf=\u7236\u7A97\u53E3 | |
| 116 | +embeds=\u5D4C\u5165\u9879 | |
| 117 | +embeddedBy=\u5D4C\u5165\u8005 | |
| 118 | +childNodeOf=\u5B50\u8282\u70B9 | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=\u9875\u7709 | |
| 124 | +footer=\u9875\u811A | |
| 125 | +paragraph=\u6BB5\u843D | |
| 126 | +ruler=\u6807\u5C3A | |
| 127 | +editbar=\u7F16\u8F91\u680F | |
| 128 | +progressMonitor=\u8FDB\u5EA6\u76D1\u89C6\u5668 | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=\u7BA1\u7406\u5B50\u9879 | |
| 134 | +indeterminate=\u4E0D\u786E\u5B9A | |
| 135 | +truncated=\u5DF2\u622A\u65AD | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=HTML \u5BB9\u5668 | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,146 @@ | ||
| 1 | +# | |
| 2 | +# This properties file is used to create a PropertyResourceBundle | |
| 3 | +# It contains Locale specific strings used be the Accessibility package. | |
| 4 | +# | |
| 5 | +# When this file is read in, the strings are put into the | |
| 6 | +# defaults table. This is an implementation detail of the current | |
| 7 | +# workings of Accessibility. DO NOT DEPEND ON THIS. | |
| 8 | +# This may change in future versions of Accessibility as we improve | |
| 9 | +# localization support. | |
| 10 | +# | |
| 11 | +# @author Lynn Monsanto | |
| 12 | + | |
| 13 | +# | |
| 14 | +# accessible roles | |
| 15 | +# | |
| 16 | +alert=\u8B66\u793A | |
| 17 | +awtcomponent=AWT \u5143\u4EF6 | |
| 18 | +checkbox=\u6838\u53D6\u65B9\u584A | |
| 19 | +colorchooser=\u8272\u5F69\u9078\u64C7\u5668 | |
| 20 | +columnheader=\u76F4\u6B04\u6A19\u984C | |
| 21 | +combobox=\u4E0B\u62C9\u5F0F\u6E05\u55AE\u65B9\u584A | |
| 22 | +canvas=\u756B\u5E03 | |
| 23 | +desktopicon=\u684C\u9762\u5716\u793A | |
| 24 | +desktoppane=\u684C\u9762\u7A97\u683C | |
| 25 | +dialog=\u5C0D\u8A71\u65B9\u584A | |
| 26 | +directorypane=\u76EE\u9304\u7A97\u683C | |
| 27 | +glasspane=\u6AA2\u8996\u7A97\u683C | |
| 28 | +filechooser=\u6A94\u6848\u9078\u64C7\u5668 | |
| 29 | +filler=\u586B\u5145\u7269 | |
| 30 | +frame=\u6846\u67B6 | |
| 31 | +internalframe=\u5167\u90E8\u6846\u67B6 | |
| 32 | +label=\u6A19\u7C64 | |
| 33 | +layeredpane=\u5206\u5C64\u7A97\u683C | |
| 34 | +list=\u6E05\u55AE | |
| 35 | +listitem=\u6E05\u55AE\u9805\u76EE | |
| 36 | +menubar=\u529F\u80FD\u8868\u5217 | |
| 37 | +menu=\u529F\u80FD\u8868 | |
| 38 | +menuitem=\u529F\u80FD\u8868\u9805\u76EE | |
| 39 | +optionpane=\u9078\u9805\u7A97\u683C | |
| 40 | +pagetab=\u9801\u9762\u9801\u7C64 | |
| 41 | +pagetablist=\u9801\u9762\u9801\u7C64\u6E05\u55AE | |
| 42 | +panel=\u9762\u677F | |
| 43 | +passwordtext=\u5BC6\u78BC\u6587\u5B57 | |
| 44 | +popupmenu=\u5373\u73FE\u5F0F\u529F\u80FD\u8868 | |
| 45 | +progressbar=\u9032\u5EA6\u5217 | |
| 46 | +pushbutton=\u4E0B\u58D3\u6309\u9215 | |
| 47 | +radiobutton=\u55AE\u9078\u9215 | |
| 48 | +rootpane=root \u7A97\u683C | |
| 49 | +rowheader=\u5217\u6A19\u984C | |
| 50 | +scrollbar=\u6372\u8EF8 | |
| 51 | +scrollpane=\u6372\u52D5\u7A97\u683C | |
| 52 | +separator=\u5206\u9694\u5143 | |
| 53 | +slider=\u6ED1\u52D5\u8EF8 | |
| 54 | +splitpane=\u5206\u5272\u7A97\u683C | |
| 55 | +swingcomponent=Swing \u5143\u4EF6 | |
| 56 | +table=\u8868\u683C | |
| 57 | +text=\u6587\u5B57 | |
| 58 | +tree=\u6A39\u72C0\u7D50\u69CB | |
| 59 | +togglebutton=\u5207\u63DB\u6309\u9215 | |
| 60 | +toolbar=\u5DE5\u5177\u5217 | |
| 61 | +tooltip=\u5DE5\u5177\u63D0\u793A | |
| 62 | +unknown=\u4E0D\u660E\u7684 | |
| 63 | +viewport=\u6AA2\u8996\u5340 | |
| 64 | +window=\u8996\u7A97 | |
| 65 | +# | |
| 66 | +# accessible relations | |
| 67 | +# | |
| 68 | +labelFor=\u6A19\u793A\u5C0D\u8C61 | |
| 69 | +labeledBy=\u6A19\u793A\u8005 | |
| 70 | +memberOf=\u6240\u5C6C\u6210\u54E1 | |
| 71 | +controlledBy=\u63A7\u5236\u8005 | |
| 72 | +controllerFor=\u63A7\u5236\u5C0D\u8C61 | |
| 73 | +# | |
| 74 | +# accessible states | |
| 75 | +# | |
| 76 | +active=\u4F5C\u7528\u4E2D | |
| 77 | +armed=\u5DF2\u914D\u5099 | |
| 78 | +busy=\u5FD9\u788C\u4E2D | |
| 79 | +checked=\u5DF2\u6838\u9078 | |
| 80 | +collapsed=\u5DF2\u6536\u7E2E | |
| 81 | +editable=\u53EF\u7DE8\u8F2F | |
| 82 | +expandable=\u53EF\u64F4\u5C55 | |
| 83 | +expanded=\u5DF2\u64F4\u5C55 | |
| 84 | +enabled=\u5DF2\u555F\u7528 | |
| 85 | +focusable=\u53EF\u805A\u7126 | |
| 86 | +focused=\u5DF2\u805A\u7126 | |
| 87 | +iconified=\u5DF2\u5716\u793A\u5316 | |
| 88 | +modal=\u6A21\u614B | |
| 89 | +multiline=\u591A\u884C | |
| 90 | +multiselectable=\u53EF\u591A\u91CD\u9078\u53D6 | |
| 91 | +opaque=\u4E0D\u900F\u660E | |
| 92 | +pressed=\u5DF2\u6309\u4E0B | |
| 93 | +resizable=\u53EF\u8ABF\u6574\u5927\u5C0F | |
| 94 | +selectable=\u53EF\u9078\u53D6 | |
| 95 | +selected=\u5DF2\u9078\u53D6 | |
| 96 | +showing=\u986F\u793A | |
| 97 | +singleline=\u55AE\u884C | |
| 98 | +transient=\u66AB\u6642\u7684 | |
| 99 | +visible=\u53EF\u898B\u7684 | |
| 100 | +vertical=\u5782\u76F4 | |
| 101 | +horizontal=\u6C34\u5E73 | |
| 102 | +# | |
| 103 | +# accessible actions | |
| 104 | +# | |
| 105 | +toggle expand=\u5207\u63DB\u64F4\u5C55 | |
| 106 | + | |
| 107 | +# new relations, roles and states for J2SE 1.5.0 | |
| 108 | + | |
| 109 | +# | |
| 110 | +# accessible relations | |
| 111 | +# | |
| 112 | +flowsTo=\u6D41\u52D5\u81F3 | |
| 113 | +flowsFrom=\u6D41\u52D5\u81EA | |
| 114 | +subwindowOf=\u5B50\u8996\u7A97 | |
| 115 | +parentWindowOf=\u7236\u7CFB\u8996\u7A97 | |
| 116 | +embeds=\u5167\u5D4C | |
| 117 | +embeddedBy=\u5167\u5D4C\u8005 | |
| 118 | +childNodeOf=\u5B50\u7BC0\u9EDE | |
| 119 | + | |
| 120 | +# | |
| 121 | +# accessible roles | |
| 122 | +# | |
| 123 | +header=\u9801\u9996 | |
| 124 | +footer=\u9801\u5C3E | |
| 125 | +paragraph=\u6BB5\u843D | |
| 126 | +ruler=\u5C3A\u898F | |
| 127 | +editbar=\u7DE8\u8F2F\u5217 | |
| 128 | +progressMonitor=\u9032\u5EA6\u76E3\u8996\u5668 | |
| 129 | + | |
| 130 | +# | |
| 131 | +# accessible states | |
| 132 | +# | |
| 133 | +managesDescendants=\u7BA1\u7406\u5B50\u4EE3 | |
| 134 | +indeterminate=\u4E0D\u78BA\u5B9A | |
| 135 | +truncated=\u5DF2\u622A\u65B7 | |
| 136 | + | |
| 137 | +# new for J2SE 1.6.0 | |
| 138 | + | |
| 139 | +# | |
| 140 | +# accessible roles | |
| 141 | +# | |
| 142 | +htmlcontainer=HTML \u5BB9\u5668 | |
| 143 | + | |
| 144 | +# | |
| 145 | +# END OF MATERIAL TO LOCALIZE | |
| 146 | +# | |
| @@ -0,0 +1,2 @@ | ||
| 1 | +<../../../../../../../mkconfig | |
| 2 | + | |
| @@ -0,0 +1,6 @@ | ||
| 1 | +<../../../../../mkconfig | |
| 2 | + | |
| 3 | +DIRS=\ | |
| 4 | + internal\ | |
| 5 | + | |
| 6 | +<$ROOT/mkfiles/mksubdirs | |
Binary file not shown.
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,462 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.awt; | |
| 27 | + | |
| 28 | +import java.awt.*; | |
| 29 | + | |
| 30 | +import sun.awt.AWTAccessor; | |
| 31 | +import sun.awt.SunToolkit; | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * A collection of utility methods for AWT. | |
| 35 | + * | |
| 36 | + * The functionality provided by the static methods of the class includes: | |
| 37 | + * <ul> | |
| 38 | + * <li>Setting shapes on top-level windows | |
| 39 | + * <li>Setting a constant alpha value for each pixel of a top-level window | |
| 40 | + * <li>Making a window non-opaque, after that it paints only explicitly | |
| 41 | + * painted pixels on the screen, with arbitrary alpha values for every pixel. | |
| 42 | + * <li>Setting a 'mixing-cutout' shape for a component. | |
| 43 | + * </ul> | |
| 44 | + * <p> | |
| 45 | + * A "top-level window" is an instance of the {@code Window} class (or its | |
| 46 | + * descendant, such as {@code JFrame}). | |
| 47 | + * <p> | |
| 48 | + * Some of the mentioned features may not be supported by the native platform. | |
| 49 | + * To determine whether a particular feature is supported, the user must use | |
| 50 | + * the {@code isTranslucencySupported()} method of the class passing a desired | |
| 51 | + * translucency kind (a member of the {@code Translucency} enum) as an | |
| 52 | + * argument. | |
| 53 | + * <p> | |
| 54 | + * The per-pixel alpha feature also requires the user to create her/his | |
| 55 | + * windows using a translucency-capable graphics configuration. | |
| 56 | + * The {@code isTranslucencyCapable()} method must | |
| 57 | + * be used to verify whether any given GraphicsConfiguration supports | |
| 58 | + * the trasnlcency effects. | |
| 59 | + * <p> | |
| 60 | + * <b>WARNING</b>: This class is an implementation detail and only meant | |
| 61 | + * for limited use outside of the core platform. This API may change | |
| 62 | + * drastically between update release, and it may even be | |
| 63 | + * removed or be moved in some other package(s)/class(es). | |
| 64 | + */ | |
| 65 | +public final class AWTUtilities { | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * The AWTUtilities class should not be instantiated | |
| 69 | + */ | |
| 70 | + private AWTUtilities() { | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** Kinds of translucency supported by the underlying system. | |
| 74 | + * @see #isTranslucencySupported | |
| 75 | + */ | |
| 76 | + public static enum Translucency { | |
| 77 | + /** | |
| 78 | + * Represents support in the underlying system for windows each pixel | |
| 79 | + * of which is guaranteed to be either completely opaque, with | |
| 80 | + * an alpha value of 1.0, or completely transparent, with an alpha | |
| 81 | + * value of 0.0. | |
| 82 | + */ | |
| 83 | + PERPIXEL_TRANSPARENT, | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Represents support in the underlying system for windows all of | |
| 87 | + * the pixels of which have the same alpha value between or including | |
| 88 | + * 0.0 and 1.0. | |
| 89 | + */ | |
| 90 | + TRANSLUCENT, | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * Represents support in the underlying system for windows that | |
| 94 | + * contain or might contain pixels with arbitrary alpha values | |
| 95 | + * between and including 0.0 and 1.0. | |
| 96 | + */ | |
| 97 | + PERPIXEL_TRANSLUCENT; | |
| 98 | + } | |
| 99 | + | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Returns whether the given level of translucency is supported by | |
| 103 | + * the underlying system. | |
| 104 | + * | |
| 105 | + * Note that this method may sometimes return the value | |
| 106 | + * indicating that the particular level is supported, but | |
| 107 | + * the native windowing system may still not support the | |
| 108 | + * given level of translucency (due to the bugs in | |
| 109 | + * the windowing system). | |
| 110 | + * | |
| 111 | + * @param translucencyKind a kind of translucency support | |
| 112 | + * (either PERPIXEL_TRANSPARENT, | |
| 113 | + * TRANSLUCENT, or PERPIXEL_TRANSLUCENT) | |
| 114 | + * @return whether the given translucency kind is supported | |
| 115 | + */ | |
| 116 | + public static boolean isTranslucencySupported(Translucency translucencyKind) { | |
| 117 | + switch (translucencyKind) { | |
| 118 | + case PERPIXEL_TRANSPARENT: | |
| 119 | + return isWindowShapingSupported(); | |
| 120 | + case TRANSLUCENT: | |
| 121 | + return isWindowOpacitySupported(); | |
| 122 | + case PERPIXEL_TRANSLUCENT: | |
| 123 | + return isWindowTranslucencySupported(); | |
| 124 | + } | |
| 125 | + return false; | |
| 126 | + } | |
| 127 | + | |
| 128 | + | |
| 129 | + /** | |
| 130 | + * Returns whether the windowing system supports changing the opacity | |
| 131 | + * value of top-level windows. | |
| 132 | + * Note that this method may sometimes return true, but the native | |
| 133 | + * windowing system may still not support the concept of | |
| 134 | + * translucency (due to the bugs in the windowing system). | |
| 135 | + */ | |
| 136 | + private static boolean isWindowOpacitySupported() { | |
| 137 | + Toolkit curToolkit = Toolkit.getDefaultToolkit(); | |
| 138 | + if (!(curToolkit instanceof SunToolkit)) { | |
| 139 | + return false; | |
| 140 | + } | |
| 141 | + return ((SunToolkit)curToolkit).isWindowOpacitySupported(); | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Set the opacity of the window. The opacity is at the range [0..1]. | |
| 146 | + * Note that setting the opacity level of 0 may or may not disable | |
| 147 | + * the mouse event handling on this window. This is | |
| 148 | + * a platform-dependent behavior. | |
| 149 | + * | |
| 150 | + * In order for this method to enable the translucency effect, | |
| 151 | + * the isTranslucencySupported() method should indicate that the | |
| 152 | + * TRANSLUCENT level of translucency is supported. | |
| 153 | + * | |
| 154 | + * <p>Also note that the window must not be in the full-screen mode | |
| 155 | + * when setting the opacity value < 1.0f. Otherwise | |
| 156 | + * the IllegalArgumentException is thrown. | |
| 157 | + * | |
| 158 | + * @param window the window to set the opacity level to | |
| 159 | + * @param opacity the opacity level to set to the window | |
| 160 | + * @throws NullPointerException if the window argument is null | |
| 161 | + * @throws IllegalArgumentException if the opacity is out of | |
| 162 | + * the range [0..1] | |
| 163 | + * @throws IllegalArgumentException if the window is in full screen mode, | |
| 164 | + * and the opacity is less than 1.0f | |
| 165 | + * @throws UnsupportedOperationException if the TRANSLUCENT translucency | |
| 166 | + * kind is not supported | |
| 167 | + */ | |
| 168 | + public static void setWindowOpacity(Window window, float opacity) { | |
| 169 | + if (window == null) { | |
| 170 | + throw new NullPointerException( | |
| 171 | + "The window argument should not be null."); | |
| 172 | + } | |
| 173 | + | |
| 174 | + AWTAccessor.getWindowAccessor().setOpacity(window, opacity); | |
| 175 | + } | |
| 176 | + | |
| 177 | + /** | |
| 178 | + * Get the opacity of the window. If the opacity has not | |
| 179 | + * yet being set, this method returns 1.0. | |
| 180 | + * | |
| 181 | + * @param window the window to get the opacity level from | |
| 182 | + * @throws NullPointerException if the window argument is null | |
| 183 | + */ | |
| 184 | + public static float getWindowOpacity(Window window) { | |
| 185 | + if (window == null) { | |
| 186 | + throw new NullPointerException( | |
| 187 | + "The window argument should not be null."); | |
| 188 | + } | |
| 189 | + | |
| 190 | + return AWTAccessor.getWindowAccessor().getOpacity(window); | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** | |
| 194 | + * Returns whether the windowing system supports changing the shape | |
| 195 | + * of top-level windows. | |
| 196 | + * Note that this method may sometimes return true, but the native | |
| 197 | + * windowing system may still not support the concept of | |
| 198 | + * shaping (due to the bugs in the windowing system). | |
| 199 | + */ | |
| 200 | + public static boolean isWindowShapingSupported() { | |
| 201 | + Toolkit curToolkit = Toolkit.getDefaultToolkit(); | |
| 202 | + if (!(curToolkit instanceof SunToolkit)) { | |
| 203 | + return false; | |
| 204 | + } | |
| 205 | + return ((SunToolkit)curToolkit).isWindowShapingSupported(); | |
| 206 | + } | |
| 207 | + | |
| 208 | + /** | |
| 209 | + * Returns an object that implements the Shape interface and represents | |
| 210 | + * the shape previously set with the call to the setWindowShape() method. | |
| 211 | + * If no shape has been set yet, or the shape has been reset to null, | |
| 212 | + * this method returns null. | |
| 213 | + * | |
| 214 | + * @param window the window to get the shape from | |
| 215 | + * @return the current shape of the window | |
| 216 | + * @throws NullPointerException if the window argument is null | |
| 217 | + */ | |
| 218 | + public static Shape getWindowShape(Window window) { | |
| 219 | + if (window == null) { | |
| 220 | + throw new NullPointerException( | |
| 221 | + "The window argument should not be null."); | |
| 222 | + } | |
| 223 | + return AWTAccessor.getWindowAccessor().getShape(window); | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * Sets a shape for the given window. | |
| 228 | + * If the shape argument is null, this methods restores | |
| 229 | + * the default shape making the window rectangular. | |
| 230 | + * <p>Note that in order to set a shape, the window must be undecorated. | |
| 231 | + * If the window is decorated, this method ignores the {@code shape} | |
| 232 | + * argument and resets the shape to null. | |
| 233 | + * <p>Also note that the window must not be in the full-screen mode | |
| 234 | + * when setting a non-null shape. Otherwise the IllegalArgumentException | |
| 235 | + * is thrown. | |
| 236 | + * <p>Depending on the platform, the method may return without | |
| 237 | + * effecting the shape of the window if the window has a non-null warning | |
| 238 | + * string ({@link Window#getWarningString()}). In this case the passed | |
| 239 | + * shape object is ignored. | |
| 240 | + * | |
| 241 | + * @param window the window to set the shape to | |
| 242 | + * @param shape the shape to set to the window | |
| 243 | + * @throws NullPointerException if the window argument is null | |
| 244 | + * @throws IllegalArgumentException if the window is in full screen mode, | |
| 245 | + * and the shape is not null | |
| 246 | + * @throws UnsupportedOperationException if the PERPIXEL_TRANSPARENT | |
| 247 | + * translucency kind is not supported | |
| 248 | + */ | |
| 249 | + public static void setWindowShape(Window window, Shape shape) { | |
| 250 | + if (window == null) { | |
| 251 | + throw new NullPointerException( | |
| 252 | + "The window argument should not be null."); | |
| 253 | + } | |
| 254 | + AWTAccessor.getWindowAccessor().setShape(window, shape); | |
| 255 | + } | |
| 256 | + | |
| 257 | + private static boolean isWindowTranslucencySupported() { | |
| 258 | + /* | |
| 259 | + * Per-pixel alpha is supported if all the conditions are TRUE: | |
| 260 | + * 1. The toolkit is a sort of SunToolkit | |
| 261 | + * 2. The toolkit supports translucency in general | |
| 262 | + * (isWindowTranslucencySupported()) | |
| 263 | + * 3. There's at least one translucency-capable | |
| 264 | + * GraphicsConfiguration | |
| 265 | + */ | |
| 266 | + | |
| 267 | + Toolkit curToolkit = Toolkit.getDefaultToolkit(); | |
| 268 | + if (!(curToolkit instanceof SunToolkit)) { | |
| 269 | + return false; | |
| 270 | + } | |
| 271 | + | |
| 272 | + if (!((SunToolkit)curToolkit).isWindowTranslucencySupported()) { | |
| 273 | + return false; | |
| 274 | + } | |
| 275 | + | |
| 276 | + GraphicsEnvironment env = | |
| 277 | + GraphicsEnvironment.getLocalGraphicsEnvironment(); | |
| 278 | + | |
| 279 | + // If the default GC supports translucency return true. | |
| 280 | + // It is important to optimize the verification this way, | |
| 281 | + // see CR 6661196 for more details. | |
| 282 | + if (isTranslucencyCapable(env.getDefaultScreenDevice() | |
| 283 | + .getDefaultConfiguration())) | |
| 284 | + { | |
| 285 | + return true; | |
| 286 | + } | |
| 287 | + | |
| 288 | + // ... otherwise iterate through all the GCs. | |
| 289 | + GraphicsDevice[] devices = env.getScreenDevices(); | |
| 290 | + | |
| 291 | + for (int i = 0; i < devices.length; i++) { | |
| 292 | + GraphicsConfiguration[] configs = devices[i].getConfigurations(); | |
| 293 | + for (int j = 0; j < configs.length; j++) { | |
| 294 | + if (isTranslucencyCapable(configs[j])) { | |
| 295 | + return true; | |
| 296 | + } | |
| 297 | + } | |
| 298 | + } | |
| 299 | + | |
| 300 | + return false; | |
| 301 | + } | |
| 302 | + | |
| 303 | + /** | |
| 304 | + * Enables the per-pixel alpha support for the given window. | |
| 305 | + * Once the window becomes non-opaque (the isOpaque is set to false), | |
| 306 | + * the drawing sub-system is starting to respect the alpha value of each | |
| 307 | + * separate pixel. If a pixel gets painted with alpha color component | |
| 308 | + * equal to zero, it becomes visually transparent, if the alpha of the | |
| 309 | + * pixel is equal to 255, the pixel is fully opaque. Interim values | |
| 310 | + * of the alpha color component make the pixel semi-transparent (i.e. | |
| 311 | + * translucent). | |
| 312 | + * <p>Note that in order for the window to support the per-pixel alpha | |
| 313 | + * mode, the window must be created using the GraphicsConfiguration | |
| 314 | + * for which the {@link #isTranslucencyCapable} | |
| 315 | + * method returns true. | |
| 316 | + * <p>Also note that some native systems enable the per-pixel translucency | |
| 317 | + * mode for any window created using the translucency-compatible | |
| 318 | + * graphics configuration. However, it is highly recommended to always | |
| 319 | + * invoke the setWindowOpaque() method for these windows, at least for | |
| 320 | + * the sake of cross-platform compatibility reasons. | |
| 321 | + * <p>Also note that the window must not be in the full-screen mode | |
| 322 | + * when making it non-opaque. Otherwise the IllegalArgumentException | |
| 323 | + * is thrown. | |
| 324 | + * <p>If the window is a {@code Frame} or a {@code Dialog}, the window must | |
| 325 | + * be undecorated prior to enabling the per-pixel translucency effect (see | |
| 326 | + * {@link Frame#setUndecorated()} and/or {@link Dialog#setUndecorated()}). | |
| 327 | + * If the window becomes decorated through a subsequent call to the | |
| 328 | + * corresponding {@code setUndecorated()} method, the per-pixel | |
| 329 | + * translucency effect will be disabled and the opaque property reset to | |
| 330 | + * {@code true}. | |
| 331 | + * <p>Depending on the platform, the method may return without | |
| 332 | + * effecting the opaque property of the window if the window has a non-null | |
| 333 | + * warning string ({@link Window#getWarningString()}). In this case | |
| 334 | + * the passed 'isOpaque' value is ignored. | |
| 335 | + * | |
| 336 | + * @param window the window to set the shape to | |
| 337 | + * @param isOpaque whether the window must be opaque (true), | |
| 338 | + * or translucent (false) | |
| 339 | + * @throws NullPointerException if the window argument is null | |
| 340 | + * @throws IllegalArgumentException if the window uses | |
| 341 | + * a GraphicsConfiguration for which the | |
| 342 | + * {@code isTranslucencyCapable()} | |
| 343 | + * method returns false | |
| 344 | + * @throws IllegalArgumentException if the window is in full screen mode, | |
| 345 | + * and the isOpaque is false | |
| 346 | + * @throws IllegalArgumentException if the window is decorated and the | |
| 347 | + * isOpaque argument is {@code false}. | |
| 348 | + * @throws UnsupportedOperationException if the PERPIXEL_TRANSLUCENT | |
| 349 | + * translucency kind is not supported | |
| 350 | + */ | |
| 351 | + public static void setWindowOpaque(Window window, boolean isOpaque) { | |
| 352 | + if (window == null) { | |
| 353 | + throw new NullPointerException( | |
| 354 | + "The window argument should not be null."); | |
| 355 | + } | |
| 356 | + if (!isOpaque && !isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT)) { | |
| 357 | + throw new UnsupportedOperationException( | |
| 358 | + "The PERPIXEL_TRANSLUCENT translucency kind is not supported"); | |
| 359 | + } | |
| 360 | + AWTAccessor.getWindowAccessor().setOpaque(window, isOpaque); | |
| 361 | + } | |
| 362 | + | |
| 363 | + /** | |
| 364 | + * Returns whether the window is opaque or translucent. | |
| 365 | + * | |
| 366 | + * @param window the window to set the shape to | |
| 367 | + * @return whether the window is currently opaque (true) | |
| 368 | + * or translucent (false) | |
| 369 | + * @throws NullPointerException if the window argument is null | |
| 370 | + */ | |
| 371 | + public static boolean isWindowOpaque(Window window) { | |
| 372 | + if (window == null) { | |
| 373 | + throw new NullPointerException( | |
| 374 | + "The window argument should not be null."); | |
| 375 | + } | |
| 376 | + | |
| 377 | + return window.isOpaque(); | |
| 378 | + } | |
| 379 | + | |
| 380 | + /** | |
| 381 | + * Verifies whether a given GraphicsConfiguration supports | |
| 382 | + * the PERPIXEL_TRANSLUCENT kind of translucency. | |
| 383 | + * All windows that are intended to be used with the {@link #setWindowOpaque} | |
| 384 | + * method must be created using a GraphicsConfiguration for which this method | |
| 385 | + * returns true. | |
| 386 | + * <p>Note that some native systems enable the per-pixel translucency | |
| 387 | + * mode for any window created using a translucency-capable | |
| 388 | + * graphics configuration. However, it is highly recommended to always | |
| 389 | + * invoke the setWindowOpaque() method for these windows, at least | |
| 390 | + * for the sake of cross-platform compatibility reasons. | |
| 391 | + * | |
| 392 | + * @param gc GraphicsConfiguration | |
| 393 | + * @throws NullPointerException if the gc argument is null | |
| 394 | + * @return whether the given GraphicsConfiguration supports | |
| 395 | + * the translucency effects. | |
| 396 | + */ | |
| 397 | + public static boolean isTranslucencyCapable(GraphicsConfiguration gc) { | |
| 398 | + if (gc == null) { | |
| 399 | + throw new NullPointerException("The gc argument should not be null"); | |
| 400 | + } | |
| 401 | + /* | |
| 402 | + return gc.isTranslucencyCapable(); | |
| 403 | + */ | |
| 404 | + Toolkit curToolkit = Toolkit.getDefaultToolkit(); | |
| 405 | + if (!(curToolkit instanceof SunToolkit)) { | |
| 406 | + return false; | |
| 407 | + } | |
| 408 | + return ((SunToolkit)curToolkit).isTranslucencyCapable(gc); | |
| 409 | + } | |
| 410 | + | |
| 411 | + /** | |
| 412 | + * Sets a 'mixing-cutout' shape for the given component. | |
| 413 | + * | |
| 414 | + * By default a lightweight component is treated as an opaque rectangle for | |
| 415 | + * the purposes of the Heavyweight/Lightweight Components Mixing feature. | |
| 416 | + * This method enables developers to set an arbitrary shape to be cut out | |
| 417 | + * from heavyweight components positioned underneath the lightweight | |
| 418 | + * component in the z-order. | |
| 419 | + * <p> | |
| 420 | + * The {@code shape} argument may have the following values: | |
| 421 | + * <ul> | |
| 422 | + * <li>{@code null} - reverts the default cutout shape (the rectangle equal | |
| 423 | + * to the component's {@code getBounds()}) | |
| 424 | + * <li><i>empty-shape</i> - does not cut out anything from heavyweight | |
| 425 | + * components. This makes the given lightweight component effectively | |
| 426 | + * transparent. Note that descendants of the lightweight component still | |
| 427 | + * affect the shapes of heavyweight components. An example of an | |
| 428 | + * <i>empty-shape</i> is {@code new Rectangle()}. | |
| 429 | + * <li><i>non-empty-shape</i> - the given shape will be cut out from | |
| 430 | + * heavyweight components. | |
| 431 | + * </ul> | |
| 432 | + * <p> | |
| 433 | + * The most common example when the 'mixing-cutout' shape is needed is a | |
| 434 | + * glass pane component. The {@link JRootPane#setGlassPane()} method | |
| 435 | + * automatically sets the <i>empty-shape</i> as the 'mixing-cutout' shape | |
| 436 | + * for the given glass pane component. If a developer needs some other | |
| 437 | + * 'mixing-cutout' shape for the glass pane (which is rare), this must be | |
| 438 | + * changed manually after installing the glass pane to the root pane. | |
| 439 | + * <p> | |
| 440 | + * Note that the 'mixing-cutout' shape neither affects painting, nor the | |
| 441 | + * mouse events handling for the given component. It is used exclusively | |
| 442 | + * for the purposes of the Heavyweight/Lightweight Components Mixing | |
| 443 | + * feature. | |
| 444 | + * | |
| 445 | + * @param component the component that needs non-default | |
| 446 | + * 'mixing-cutout' shape | |
| 447 | + * @param shape the new 'mixing-cutout' shape | |
| 448 | + * @throws NullPointerException if the component argument is {@code null} | |
| 449 | + */ | |
| 450 | + public static void setComponentMixingCutoutShape(Component component, | |
| 451 | + Shape shape) | |
| 452 | + { | |
| 453 | + if (component == null) { | |
| 454 | + throw new NullPointerException( | |
| 455 | + "The component argument should not be null."); | |
| 456 | + } | |
| 457 | + | |
| 458 | + AWTAccessor.getComponentAccessor().setMixingCutoutShape(component, | |
| 459 | + shape); | |
| 460 | + } | |
| 461 | +} | |
| 462 | + | |
| @@ -0,0 +1,169 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.awt; | |
| 27 | + | |
| 28 | +import java.awt.*; | |
| 29 | +import java.awt.geom.*; | |
| 30 | + | |
| 31 | +import sun.awt.AWTAccessor; | |
| 32 | + | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Security Warning control interface. | |
| 36 | + * | |
| 37 | + * This class provides a couple of methods that help a developer relocate | |
| 38 | + * the AWT security warning to an appropriate position relative to the current | |
| 39 | + * window size. A "top-level window" is an instance of the {@code Window} | |
| 40 | + * class (or its descendant, such as {@code JFrame}). The security warning | |
| 41 | + * is applied to all windows created by an untrusted code. All such windows | |
| 42 | + * have a non-null "warning string" (see {@link Window#getWarningString()}). | |
| 43 | + * <p> | |
| 44 | + * <b>WARNING</b>: This class is an implementation detail and only meant | |
| 45 | + * for limited use outside of the core platform. This API may change | |
| 46 | + * drastically between update release, and it may even be | |
| 47 | + * removed or be moved to some other packages or classes. | |
| 48 | + */ | |
| 49 | +public final class SecurityWarning { | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * The SecurityWarning class should not be instantiated | |
| 53 | + */ | |
| 54 | + private SecurityWarning() { | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Gets the size of the security warning. | |
| 59 | + * | |
| 60 | + * The returned value is not valid until the peer has been created. Before | |
| 61 | + * invoking this method a developer must call the {@link Window#pack()}, | |
| 62 | + * {@link Window#setVisible()}, or some other method that creates the peer. | |
| 63 | + * | |
| 64 | + * @param window the window to get the security warning size for | |
| 65 | + * | |
| 66 | + * @throws NullPointerException if the window argument is null | |
| 67 | + * @throws IllegalArgumentException if the window is trusted (i.e. | |
| 68 | + * the {@code getWarningString()} returns null) | |
| 69 | + */ | |
| 70 | + public static Dimension getSize(Window window) { | |
| 71 | + if (window == null) { | |
| 72 | + throw new NullPointerException( | |
| 73 | + "The window argument should not be null."); | |
| 74 | + } | |
| 75 | + if (window.getWarningString() == null) { | |
| 76 | + throw new IllegalArgumentException( | |
| 77 | + "The window must have a non-null warning string."); | |
| 78 | + } | |
| 79 | + // We don't check for a non-null peer since it may be destroyed | |
| 80 | + // after assigning a valid value to the security warning size. | |
| 81 | + | |
| 82 | + return AWTAccessor.getWindowAccessor().getSecurityWarningSize(window); | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Sets the position of the security warning. | |
| 87 | + * <p> | |
| 88 | + * The {@code alignmentX} and {@code alignmentY} arguments specify the | |
| 89 | + * origin of the coordinate system used to calculate the position of the | |
| 90 | + * security warning. The values must be in the range [0.0f...1.0f]. The | |
| 91 | + * {@code 0.0f} value represents the left (top) edge of the rectangular | |
| 92 | + * bounds of the window. The {@code 1.0f} value represents the right | |
| 93 | + * (bottom) edge of the bounds. Whenever the size of the window changes, | |
| 94 | + * the origin of the coordinate system gets relocated accordingly. For | |
| 95 | + * convenience a developer may use the {@code Component.*_ALIGNMENT} | |
| 96 | + * constants to pass predefined values for these arguments. | |
| 97 | + * <p> | |
| 98 | + * The {@code point} argument specifies the location of the security | |
| 99 | + * warning in the coordinate system described above. If both {@code x} and | |
| 100 | + * {@code y} coordinates of the point are equal to zero, the warning will | |
| 101 | + * be located right in the origin of the coordinate system. On the other | |
| 102 | + * hand, if both {@code alignmentX} and {@code alignmentY} are equal to | |
| 103 | + * zero (i.e. the origin of the coordinate system is placed at the top-left | |
| 104 | + * corner of the window), then the {@code point} argument represents the | |
| 105 | + * absolute location of the security warning relative to the location of | |
| 106 | + * the window. The "absolute" in this case means that the position of the | |
| 107 | + * security warning is not effected by resizing of the window. | |
| 108 | + * <p> | |
| 109 | + * Note that the security warning managment code guarantees that: | |
| 110 | + * <ul> | |
| 111 | + * <li>The security warning cannot be located farther than two pixels from | |
| 112 | + * the rectangular bounds of the window (see {@link Window#getBounds}), and | |
| 113 | + * <li>The security warning is always visible on the screen. | |
| 114 | + * </ul> | |
| 115 | + * If either of the conditions is violated, the calculated position of the | |
| 116 | + * security warning is adjusted by the system to meet both these | |
| 117 | + * conditions. | |
| 118 | + * <p> | |
| 119 | + * The default position of the security warning is in the upper-right | |
| 120 | + * corner of the window, two pixels to the right from the right edge. This | |
| 121 | + * corresponds to the following arguments passed to this method: | |
| 122 | + * <ul> | |
| 123 | + * <li>{@code alignmentX = Component.RIGHT_ALIGNMENT} | |
| 124 | + * <li>{@code alignmentY = Component.TOP_ALIGNMENT} | |
| 125 | + * <li>{@code point = (2, 0)} | |
| 126 | + * </ul> | |
| 127 | + * | |
| 128 | + * @param window the window to set the position of the security warning for | |
| 129 | + * @param alignmentX the horizontal origin of the coordinate system | |
| 130 | + * @param alignmentY the vertical origin of the coordinate system | |
| 131 | + * @param point the position of the security warning in the specified | |
| 132 | + * coordinate system | |
| 133 | + * | |
| 134 | + * @throws NullPointerException if the window argument is null | |
| 135 | + * @throws NullPointerException if the point argument is null | |
| 136 | + * @throws IllegalArgumentException if the window is trusted (i.e. | |
| 137 | + * the {@code getWarningString()} returns null | |
| 138 | + * @throws IllegalArgumentException if the alignmentX or alignmentY | |
| 139 | + * arguments are not within the range [0.0f ... 1.0f] | |
| 140 | + */ | |
| 141 | + public static void setPosition(Window window, Point2D point, | |
| 142 | + float alignmentX, float alignmentY) | |
| 143 | + { | |
| 144 | + if (window == null) { | |
| 145 | + throw new NullPointerException( | |
| 146 | + "The window argument should not be null."); | |
| 147 | + } | |
| 148 | + if (window.getWarningString() == null) { | |
| 149 | + throw new IllegalArgumentException( | |
| 150 | + "The window must have a non-null warning string."); | |
| 151 | + } | |
| 152 | + if (point == null) { | |
| 153 | + throw new NullPointerException( | |
| 154 | + "The point argument must not be null"); | |
| 155 | + } | |
| 156 | + if (alignmentX < 0.0f || alignmentX > 1.0f) { | |
| 157 | + throw new IllegalArgumentException( | |
| 158 | + "alignmentX must be in the range [0.0f ... 1.0f]."); | |
| 159 | + } | |
| 160 | + if (alignmentY < 0.0f || alignmentY > 1.0f) { | |
| 161 | + throw new IllegalArgumentException( | |
| 162 | + "alignmentY must be in the range [0.0f ... 1.0f]."); | |
| 163 | + } | |
| 164 | + | |
| 165 | + AWTAccessor.getWindowAccessor().setSecurityWarningPosition(window, | |
| 166 | + point, alignmentX, alignmentY); | |
| 167 | + } | |
| 168 | +} | |
| 169 | + | |
| @@ -0,0 +1,9 @@ | ||
| 1 | +<../../../../../mkconfig | |
| 2 | + | |
| 3 | +TARG=\ | |
| 4 | + AWTUtilities.dis\ | |
| 5 | + SecurityWarning.dis\ | |
| 6 | + | |
| 7 | +DISBIN=$ROOT/java/dis/java/java/com/sun/awt | |
| 8 | + | |
| 9 | +<$ROOT/mkfiles/mkjava | |
Binary file not shown.
| @@ -0,0 +1,410 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans; | |
| 26 | + | |
| 27 | +import java.lang.reflect.Array; | |
| 28 | +import java.lang.reflect.GenericArrayType; | |
| 29 | +import java.lang.reflect.ParameterizedType; | |
| 30 | +import java.lang.reflect.Type; | |
| 31 | +import java.lang.reflect.TypeVariable; | |
| 32 | +import java.lang.reflect.WildcardType; | |
| 33 | +import java.util.HashMap; | |
| 34 | +import java.util.Map; | |
| 35 | + | |
| 36 | +import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl; | |
| 37 | +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; | |
| 38 | + | |
| 39 | +/** | |
| 40 | + * This is utility class to resolve types. | |
| 41 | + * | |
| 42 | + * @since 1.7 | |
| 43 | + * | |
| 44 | + * @author Eamonn McManus | |
| 45 | + * @author Sergey Malenkov | |
| 46 | + */ | |
| 47 | +public final class TypeResolver { | |
| 48 | + /** | |
| 49 | + * Replaces the given {@code type} in an inherited method | |
| 50 | + * with the actual type it has in the given {@code inClass}. | |
| 51 | + * | |
| 52 | + * <p>Although type parameters are not inherited by subclasses in the Java | |
| 53 | + * language, they <em>are</em> effectively inherited when using reflection. | |
| 54 | + * For example, if you declare an interface like this...</p> | |
| 55 | + * | |
| 56 | + * <pre> | |
| 57 | + * public interface StringToIntMap extends Map<String,Integer> {} | |
| 58 | + * </pre> | |
| 59 | + * | |
| 60 | + * <p>...then StringToIntMap.class.getMethods() will show that it has methods | |
| 61 | + * like put(K,V) even though StringToIntMap has no type parameters. The K | |
| 62 | + * and V variables are the ones declared by Map, so | |
| 63 | + * {@link TypeVariable#getGenericDeclaration()} will return Map.class.</p> | |
| 64 | + * | |
| 65 | + * <p>The purpose of this method is to take a Type from a possibly-inherited | |
| 66 | + * method and replace it with the correct Type for the inheriting class. | |
| 67 | + * So given parameters of K and StringToIntMap.class in the above example, | |
| 68 | + * this method will return String.</p> | |
| 69 | + * | |
| 70 | + * @param inClass the base class used to resolve | |
| 71 | + * @param type the type to resolve | |
| 72 | + * @return a resolved type | |
| 73 | + * | |
| 74 | + * @see #getActualType(Class) | |
| 75 | + * @see #resolve(Type,Type) | |
| 76 | + */ | |
| 77 | + public static Type resolveInClass(Class<?> inClass, Type type) { | |
| 78 | + return resolve(getActualType(inClass), type); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Replaces all {@code types} in the given array | |
| 83 | + * with the actual types they have in the given {@code inClass}. | |
| 84 | + * | |
| 85 | + * @param inClass the base class used to resolve | |
| 86 | + * @param types the array of types to resolve | |
| 87 | + * @return an array of resolved types | |
| 88 | + * | |
| 89 | + * @see #getActualType(Class) | |
| 90 | + * @see #resolve(Type,Type[]) | |
| 91 | + */ | |
| 92 | + public static Type[] resolveInClass(Class<?> inClass, Type[] types) { | |
| 93 | + return resolve(getActualType(inClass), types); | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * Replaces type variables of the given {@code formal} type | |
| 98 | + * with the types they stand for in the given {@code actual} type. | |
| 99 | + * | |
| 100 | + * <p>A ParameterizedType is a class with type parameters, and the values | |
| 101 | + * of those parameters. For example, Map<K,V> is a generic class, and | |
| 102 | + * a corresponding ParameterizedType might look like | |
| 103 | + * Map<K=String,V=Integer>. Given such a ParameterizedType, this method | |
| 104 | + * will replace K with String, or List<K> with List<String;, or | |
| 105 | + * List<? super K> with List<? super String>.</p> | |
| 106 | + * | |
| 107 | + * <p>The {@code actual} argument to this method can also be a Class. | |
| 108 | + * In this case, either it is equivalent to a ParameterizedType with | |
| 109 | + * no parameters (for example, Integer.class), or it is equivalent to | |
| 110 | + * a "raw" ParameterizedType (for example, Map.class). In the latter | |
| 111 | + * case, every type parameter declared or inherited by the class is replaced | |
| 112 | + * by its "erasure". For a type parameter declared as <T>, the erasure | |
| 113 | + * is Object. For a type parameter declared as <T extends Number>, | |
| 114 | + * the erasure is Number.</p> | |
| 115 | + * | |
| 116 | + * <p>Although type parameters are not inherited by subclasses in the Java | |
| 117 | + * language, they <em>are</em> effectively inherited when using reflection. | |
| 118 | + * For example, if you declare an interface like this...</p> | |
| 119 | + * | |
| 120 | + * <pre> | |
| 121 | + * public interface StringToIntMap extends Map<String,Integer> {} | |
| 122 | + * </pre> | |
| 123 | + * | |
| 124 | + * <p>...then StringToIntMap.class.getMethods() will show that it has methods | |
| 125 | + * like put(K,V) even though StringToIntMap has no type parameters. The K | |
| 126 | + * and V variables are the ones declared by Map, so | |
| 127 | + * {@link TypeVariable#getGenericDeclaration()} will return {@link Map Map.class}.</p> | |
| 128 | + * | |
| 129 | + * <p>For this reason, this method replaces inherited type parameters too. | |
| 130 | + * Therefore if this method is called with {@code actual} being | |
| 131 | + * StringToIntMap.class and {@code formal} being the K from Map, | |
| 132 | + * it will return {@link String String.class}.</p> | |
| 133 | + * | |
| 134 | + * <p>In the case where {@code actual} is a "raw" ParameterizedType, the | |
| 135 | + * inherited type parameters will also be replaced by their erasures. | |
| 136 | + * The erasure of a Class is the Class itself, so a "raw" subinterface of | |
| 137 | + * StringToIntMap will still show the K from Map as String.class. But | |
| 138 | + * in a case like this... | |
| 139 | + * | |
| 140 | + * <pre> | |
| 141 | + * public interface StringToIntListMap extends Map<String,List<Integer>> {} | |
| 142 | + * public interface RawStringToIntListMap extends StringToIntListMap {} | |
| 143 | + * </pre> | |
| 144 | + * | |
| 145 | + * <p>...the V inherited from Map will show up as List<Integer> in | |
| 146 | + * StringToIntListMap, but as plain List in RawStringToIntListMap.</p> | |
| 147 | + * | |
| 148 | + * @param actual the type that supplies bindings for type variables | |
| 149 | + * @param formal the type where occurrences of the variables | |
| 150 | + * in {@code actual} will be replaced by the corresponding bound values | |
| 151 | + * @return a resolved type | |
| 152 | + * | |
| 153 | + * @see #TypeResolver(Type) | |
| 154 | + * @see #resolve(Type) | |
| 155 | + */ | |
| 156 | + public static Type resolve(Type actual, Type formal) { | |
| 157 | + return new TypeResolver(actual).resolve(formal); | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Replaces type variables of all formal types in the given array | |
| 162 | + * with the types they stand for in the given {@code actual} type. | |
| 163 | + * | |
| 164 | + * @param actual the type that supplies bindings for type variables | |
| 165 | + * @param formals the array of types to resolve | |
| 166 | + * @return an array of resolved types | |
| 167 | + * | |
| 168 | + * @see #TypeResolver(Type) | |
| 169 | + * @see #resolve(Type[]) | |
| 170 | + */ | |
| 171 | + public static Type[] resolve(Type actual, Type[] formals) { | |
| 172 | + return new TypeResolver(actual).resolve(formals); | |
| 173 | + } | |
| 174 | + | |
| 175 | + /** | |
| 176 | + * Converts the given {@code type} to the corresponding class. | |
| 177 | + * This method implements the concept of type erasure, | |
| 178 | + * that is described in section 4.6 of | |
| 179 | + * <cite>The Java™ Language Specification</cite>. | |
| 180 | + * | |
| 181 | + * @param type the array of types to convert | |
| 182 | + * @return a corresponding class | |
| 183 | + */ | |
| 184 | + public static Class<?> erase(Type type) { | |
| 185 | + if (type instanceof Class) { | |
| 186 | + return (Class<?>) type; | |
| 187 | + } | |
| 188 | + if (type instanceof ParameterizedType) { | |
| 189 | + ParameterizedType pt = (ParameterizedType) type; | |
| 190 | + return (Class<?>) pt.getRawType(); | |
| 191 | + } | |
| 192 | + if (type instanceof TypeVariable) { | |
| 193 | + TypeVariable tv = (TypeVariable)type; | |
| 194 | + Type[] bounds = tv.getBounds(); | |
| 195 | + return (0 < bounds.length) | |
| 196 | + ? erase(bounds[0]) | |
| 197 | + : Object.class; | |
| 198 | + } | |
| 199 | + if (type instanceof WildcardType) { | |
| 200 | + WildcardType wt = (WildcardType)type; | |
| 201 | + Type[] bounds = wt.getUpperBounds(); | |
| 202 | + return (0 < bounds.length) | |
| 203 | + ? erase(bounds[0]) | |
| 204 | + : Object.class; | |
| 205 | + } | |
| 206 | + if (type instanceof GenericArrayType) { | |
| 207 | + GenericArrayType gat = (GenericArrayType)type; | |
| 208 | + return Array.newInstance(erase(gat.getGenericComponentType()), 0).getClass(); | |
| 209 | + } | |
| 210 | + throw new IllegalArgumentException("Unknown Type kind: " + type.getClass()); | |
| 211 | + } | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * Converts all {@code types} in the given array | |
| 215 | + * to the corresponding classes. | |
| 216 | + * | |
| 217 | + * @param types the array of types to convert | |
| 218 | + * @return an array of corresponding classes | |
| 219 | + * | |
| 220 | + * @see #erase(Type) | |
| 221 | + */ | |
| 222 | + public static Class[] erase(Type[] types) { | |
| 223 | + int length = types.length; | |
| 224 | + Class[] classes = new Class[length]; | |
| 225 | + for (int i = 0; i < length; i++) { | |
| 226 | + classes[i] = TypeResolver.erase(types[i]); | |
| 227 | + } | |
| 228 | + return classes; | |
| 229 | + } | |
| 230 | + | |
| 231 | + | |
| 232 | + private final Map<TypeVariable<?>, Type> map | |
| 233 | + = new HashMap<TypeVariable<?>, Type>(); | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * Constructs the type resolver for the given actual type. | |
| 237 | + * | |
| 238 | + * @param actual the type that supplies bindings for type variables | |
| 239 | + * | |
| 240 | + * @see #prepare(Type) | |
| 241 | + */ | |
| 242 | + private TypeResolver(Type actual) { | |
| 243 | + prepare(actual); | |
| 244 | + } | |
| 245 | + | |
| 246 | + /** | |
| 247 | + * Fills the map from type parameters | |
| 248 | + * to types as seen by the given {@code type}. | |
| 249 | + * The method is recursive because the {@code type} | |
| 250 | + * inherits mappings from its parent classes and interfaces. | |
| 251 | + * The {@code type} can be either a {@link Class Class} | |
| 252 | + * or a {@link ParameterizedType ParameterizedType}. | |
| 253 | + * If it is a {@link Class Class}, it is either equivalent | |
| 254 | + * to a {@link ParameterizedType ParameterizedType} with no parameters, | |
| 255 | + * or it represents the erasure of a {@link ParameterizedType ParameterizedType}. | |
| 256 | + * | |
| 257 | + * @param type the next type in the hierarchy | |
| 258 | + */ | |
| 259 | + private void prepare(Type type) { | |
| 260 | + Class<?> raw = (Class<?>)((type instanceof Class<?>) | |
| 261 | + ? type | |
| 262 | + : ((ParameterizedType)type).getRawType()); | |
| 263 | + | |
| 264 | + TypeVariable<?>[] formals = raw.getTypeParameters(); | |
| 265 | + | |
| 266 | + Type[] actuals = (type instanceof Class<?>) | |
| 267 | + ? formals | |
| 268 | + : ((ParameterizedType)type).getActualTypeArguments(); | |
| 269 | + | |
| 270 | + assert formals.length == actuals.length; | |
| 271 | + for (int i = 0; i < formals.length; i++) { | |
| 272 | + this.map.put(formals[i], actuals[i]); | |
| 273 | + } | |
| 274 | + Type gSuperclass = raw.getGenericSuperclass(); | |
| 275 | + if (gSuperclass != null) { | |
| 276 | + prepare(gSuperclass); | |
| 277 | + } | |
| 278 | + for (Type gInterface : raw.getGenericInterfaces()) { | |
| 279 | + prepare(gInterface); | |
| 280 | + } | |
| 281 | + // If type is the raw version of a parameterized class, we type-erase | |
| 282 | + // all of its type variables, including inherited ones. | |
| 283 | + if (type instanceof Class<?> && formals.length > 0) { | |
| 284 | + for (Map.Entry<TypeVariable<?>, Type> entry : this.map.entrySet()) { | |
| 285 | + entry.setValue(erase(entry.getValue())); | |
| 286 | + } | |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + /** | |
| 291 | + * Replaces the given {@code formal} type | |
| 292 | + * with the type it stand for in this type resolver. | |
| 293 | + * | |
| 294 | + * @param formal the array of types to resolve | |
| 295 | + * @return a resolved type | |
| 296 | + */ | |
| 297 | + private Type resolve(Type formal) { | |
| 298 | + if (formal instanceof Class) { | |
| 299 | + return formal; | |
| 300 | + } | |
| 301 | + if (formal instanceof GenericArrayType) { | |
| 302 | + Type comp = ((GenericArrayType)formal).getGenericComponentType(); | |
| 303 | + comp = resolve(comp); | |
| 304 | + return (comp instanceof Class) | |
| 305 | + ? Array.newInstance((Class<?>)comp, 0).getClass() | |
| 306 | + : GenericArrayTypeImpl.make(comp); | |
| 307 | + } | |
| 308 | + if (formal instanceof ParameterizedType) { | |
| 309 | + ParameterizedType fpt = (ParameterizedType)formal; | |
| 310 | + Type[] actuals = resolve(fpt.getActualTypeArguments()); | |
| 311 | + return ParameterizedTypeImpl.make( | |
| 312 | + (Class<?>)fpt.getRawType(), actuals, fpt.getOwnerType()); | |
| 313 | + } | |
| 314 | + if (formal instanceof WildcardType) { | |
| 315 | + WildcardType fwt = (WildcardType)formal; | |
| 316 | + Type[] upper = resolve(fwt.getUpperBounds()); | |
| 317 | + Type[] lower = resolve(fwt.getLowerBounds()); | |
| 318 | + return new WildcardTypeImpl(upper, lower); | |
| 319 | + } | |
| 320 | + if (!(formal instanceof TypeVariable)) { | |
| 321 | + throw new IllegalArgumentException("Bad Type kind: " + formal.getClass()); | |
| 322 | + } | |
| 323 | + Type actual = this.map.get((TypeVariable) formal); | |
| 324 | + if (actual == null || actual.equals(formal)) { | |
| 325 | + return formal; | |
| 326 | + } | |
| 327 | + actual = fixGenericArray(actual); | |
| 328 | + return resolve(actual); | |
| 329 | + // A variable can be bound to another variable that is itself bound | |
| 330 | + // to something. For example, given: | |
| 331 | + // class Super<T> {...} | |
| 332 | + // class Mid<X> extends Super<T> {...} | |
| 333 | + // class Sub extends Mid<String> | |
| 334 | + // the variable T is bound to X, which is in turn bound to String. | |
| 335 | + // So if we have to resolve T, we need the tail recursion here. | |
| 336 | + } | |
| 337 | + | |
| 338 | + /** | |
| 339 | + * Replaces all formal types in the given array | |
| 340 | + * with the types they stand for in this type resolver. | |
| 341 | + * | |
| 342 | + * @param formals the array of types to resolve | |
| 343 | + * @return an array of resolved types | |
| 344 | + * | |
| 345 | + * @see #resolve(Type) | |
| 346 | + */ | |
| 347 | + private Type[] resolve(Type[] formals) { | |
| 348 | + int length = formals.length; | |
| 349 | + Type[] actuals = new Type[length]; | |
| 350 | + for (int i = 0; i < length; i++) { | |
| 351 | + actuals[i] = resolve(formals[i]); | |
| 352 | + } | |
| 353 | + return actuals; | |
| 354 | + } | |
| 355 | + | |
| 356 | + /** | |
| 357 | + * Replaces a {@link GenericArrayType GenericArrayType} | |
| 358 | + * with plain array class where it is possible. | |
| 359 | + * Bug <a href="http://bugs.sun.com/view_bug.do?bug_id=5041784">5041784</a> | |
| 360 | + * is that arrays of non-generic type sometimes show up | |
| 361 | + * as {@link GenericArrayType GenericArrayType} when using reflection. | |
| 362 | + * For example, a {@code String[]} might show up | |
| 363 | + * as a {@link GenericArrayType GenericArrayType} | |
| 364 | + * where {@link GenericArrayType#getGenericComponentType getGenericComponentType} | |
| 365 | + * is {@code String.class}. This violates the specification, | |
| 366 | + * which says that {@link GenericArrayType GenericArrayType} | |
| 367 | + * is used when the component type is a type variable or parameterized type. | |
| 368 | + * We fit the specification here. | |
| 369 | + * | |
| 370 | + * @param type the type to fix | |
| 371 | + * @return a corresponding type for the generic array type, | |
| 372 | + * or the same type as {@code type} | |
| 373 | + */ | |
| 374 | + private static Type fixGenericArray(Type type) { | |
| 375 | + if (type instanceof GenericArrayType) { | |
| 376 | + Type comp = ((GenericArrayType)type).getGenericComponentType(); | |
| 377 | + comp = fixGenericArray(comp); | |
| 378 | + if (comp instanceof Class) { | |
| 379 | + return Array.newInstance((Class<?>)comp, 0).getClass(); | |
| 380 | + } | |
| 381 | + } | |
| 382 | + return type; | |
| 383 | + } | |
| 384 | + | |
| 385 | + /** | |
| 386 | + * Replaces a {@link Class Class} with type parameters | |
| 387 | + * with a {@link ParameterizedType ParameterizedType} | |
| 388 | + * where every parameter is bound to itself. | |
| 389 | + * When calling {@link #resolveInClass} in the context of {@code inClass}, | |
| 390 | + * we can't just pass {@code inClass} as the {@code actual} parameter, | |
| 391 | + * because if {@code inClass} has type parameters | |
| 392 | + * that would be interpreted as accessing the raw type, | |
| 393 | + * so we would get unwanted erasure. | |
| 394 | + * This is why we bind each parameter to itself. | |
| 395 | + * If {@code inClass} does have type parameters and has methods | |
| 396 | + * where those parameters appear in the return type or argument types, | |
| 397 | + * we will correctly leave those types alone. | |
| 398 | + * | |
| 399 | + * @param inClass the base class used to resolve | |
| 400 | + * @return a parameterized type for the class, | |
| 401 | + * or the same class as {@code inClass} | |
| 402 | + */ | |
| 403 | + private static Type getActualType(Class<?> inClass) { | |
| 404 | + Type[] params = inClass.getTypeParameters(); | |
| 405 | + return (params.length == 0) | |
| 406 | + ? inClass | |
| 407 | + : ParameterizedTypeImpl.make( | |
| 408 | + inClass, params, inClass.getEnclosingClass()); | |
| 409 | + } | |
| 410 | +} | |
Binary file not shown.
| @@ -0,0 +1,91 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans; | |
| 26 | + | |
| 27 | +import java.lang.ref.Reference; | |
| 28 | +import java.lang.ref.WeakReference; | |
| 29 | + | |
| 30 | +import java.util.Map; | |
| 31 | +import java.util.WeakHashMap; | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * A hashtable-based cache with weak keys and weak values. | |
| 35 | + * An entry in the map will be automatically removed | |
| 36 | + * when its key is no longer in the ordinary use. | |
| 37 | + * A value will be automatically removed as well | |
| 38 | + * when it is no longer in the ordinary use. | |
| 39 | + * | |
| 40 | + * @since 1.7 | |
| 41 | + * | |
| 42 | + * @author Sergey A. Malenkov | |
| 43 | + */ | |
| 44 | +public final class WeakCache<K, V> { | |
| 45 | + private final Map<K, Reference<V>> map = new WeakHashMap<K, Reference<V>>(); | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Returns a value to which the specified {@code key} is mapped, | |
| 49 | + * or {@code null} if this map contains no mapping for the {@code key}. | |
| 50 | + * | |
| 51 | + * @param key the key whose associated value is returned | |
| 52 | + * @return a value to which the specified {@code key} is mapped | |
| 53 | + */ | |
| 54 | + public V get(K key) { | |
| 55 | + Reference<V> reference = this.map.get(key); | |
| 56 | + if (reference == null) { | |
| 57 | + return null; | |
| 58 | + } | |
| 59 | + V value = reference.get(); | |
| 60 | + if (value == null) { | |
| 61 | + this.map.remove(key); | |
| 62 | + } | |
| 63 | + return value; | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * Associates the specified {@code value} with the specified {@code key}. | |
| 68 | + * Removes the mapping for the specified {@code key} from this cache | |
| 69 | + * if it is present and the specified {@code value} is {@code null}. | |
| 70 | + * If the cache previously contained a mapping for the {@code key}, | |
| 71 | + * the old value is replaced by the specified {@code value}. | |
| 72 | + * | |
| 73 | + * @param key the key with which the specified value is associated | |
| 74 | + * @param value the value to be associated with the specified key | |
| 75 | + */ | |
| 76 | + public void put(K key, V value) { | |
| 77 | + if (value != null) { | |
| 78 | + this.map.put(key, new WeakReference<V>(value)); | |
| 79 | + } | |
| 80 | + else { | |
| 81 | + this.map.remove(key); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Removes all of the mappings from this cache. | |
| 87 | + */ | |
| 88 | + public void clear() { | |
| 89 | + this.map.clear(); | |
| 90 | + } | |
| 91 | +} | |
Binary file not shown.
| @@ -0,0 +1,161 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans; | |
| 26 | + | |
| 27 | +import java.lang.reflect.Type; | |
| 28 | +import java.lang.reflect.WildcardType; | |
| 29 | +import java.util.Arrays; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * This class implements {@link WildcardType WildcardType} compatibly with the JDK's | |
| 33 | + * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}. | |
| 34 | + * Unfortunately we can't use the JDK's | |
| 35 | + * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl} here as we do for | |
| 36 | + * {@link sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl ParameterizedTypeImpl} and | |
| 37 | + * {@link sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl GenericArrayTypeImpl}, | |
| 38 | + * because {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}'s | |
| 39 | + * constructor takes parameters representing intermediate structures obtained during class-file parsing. | |
| 40 | + * We could reconstruct versions of those structures but it would be more trouble than it's worth. | |
| 41 | + * | |
| 42 | + * @since 1.7 | |
| 43 | + * | |
| 44 | + * @author Eamonn McManus | |
| 45 | + * @author Sergey Malenkov | |
| 46 | + */ | |
| 47 | +final class WildcardTypeImpl implements WildcardType { | |
| 48 | + private final Type[] upperBounds; | |
| 49 | + private final Type[] lowerBounds; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Creates a wildcard type with the requested bounds. | |
| 53 | + * Note that the array arguments are not cloned | |
| 54 | + * because instances of this class are never constructed | |
| 55 | + * from outside the containing package. | |
| 56 | + * | |
| 57 | + * @param upperBounds the array of types representing | |
| 58 | + * the upper bound(s) of this type variable | |
| 59 | + * @param lowerBounds the array of types representing | |
| 60 | + * the lower bound(s) of this type variable | |
| 61 | + */ | |
| 62 | + WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) { | |
| 63 | + this.upperBounds = upperBounds; | |
| 64 | + this.lowerBounds = lowerBounds; | |
| 65 | + } | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * Returns an array of {@link Type Type} objects | |
| 69 | + * representing the upper bound(s) of this type variable. | |
| 70 | + * Note that if no upper bound is explicitly declared, | |
| 71 | + * the upper bound is {@link Object Object}. | |
| 72 | + * | |
| 73 | + * @return an array of types representing | |
| 74 | + * the upper bound(s) of this type variable | |
| 75 | + */ | |
| 76 | + public Type[] getUpperBounds() { | |
| 77 | + return this.upperBounds.clone(); | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * Returns an array of {@link Type Type} objects | |
| 82 | + * representing the lower bound(s) of this type variable. | |
| 83 | + * Note that if no lower bound is explicitly declared, | |
| 84 | + * the lower bound is the type of {@code null}. | |
| 85 | + * In this case, a zero length array is returned. | |
| 86 | + * | |
| 87 | + * @return an array of types representing | |
| 88 | + * the lower bound(s) of this type variable | |
| 89 | + */ | |
| 90 | + public Type[] getLowerBounds() { | |
| 91 | + return this.lowerBounds.clone(); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Indicates whether some other object is "equal to" this one. | |
| 96 | + * It is implemented compatibly with the JDK's | |
| 97 | + * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}. | |
| 98 | + * | |
| 99 | + * @param object the reference object with which to compare | |
| 100 | + * @return {@code true} if this object is the same as the object argument; | |
| 101 | + * {@code false} otherwise | |
| 102 | + * @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#equals | |
| 103 | + */ | |
| 104 | + @Override | |
| 105 | + public boolean equals(Object object) { | |
| 106 | + if (object instanceof WildcardType) { | |
| 107 | + WildcardType type = (WildcardType) object; | |
| 108 | + return Arrays.equals(this.upperBounds, type.getUpperBounds()) | |
| 109 | + && Arrays.equals(this.lowerBounds, type.getLowerBounds()); | |
| 110 | + } | |
| 111 | + return false; | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Returns a hash code value for the object. | |
| 116 | + * It is implemented compatibly with the JDK's | |
| 117 | + * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}. | |
| 118 | + * | |
| 119 | + * @return a hash code value for this object | |
| 120 | + * @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#hashCode | |
| 121 | + */ | |
| 122 | + @Override | |
| 123 | + public int hashCode() { | |
| 124 | + return Arrays.hashCode(this.upperBounds) | |
| 125 | + ^ Arrays.hashCode(this.lowerBounds); | |
| 126 | + } | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * Returns a string representation of the object. | |
| 130 | + * It is implemented compatibly with the JDK's | |
| 131 | + * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}. | |
| 132 | + * | |
| 133 | + * @return a string representation of the object | |
| 134 | + * @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#toString | |
| 135 | + */ | |
| 136 | + @Override | |
| 137 | + public String toString() { | |
| 138 | + StringBuilder sb; | |
| 139 | + Type[] bounds; | |
| 140 | + if (this.lowerBounds.length == 0) { | |
| 141 | + if (this.upperBounds.length == 0 || Object.class == this.upperBounds[0]) { | |
| 142 | + return "?"; | |
| 143 | + } | |
| 144 | + bounds = this.upperBounds; | |
| 145 | + sb = new StringBuilder("? extends "); | |
| 146 | + } | |
| 147 | + else { | |
| 148 | + bounds = this.lowerBounds; | |
| 149 | + sb = new StringBuilder("? super "); | |
| 150 | + } | |
| 151 | + for (int i = 0; i < bounds.length; i++) { | |
| 152 | + if (i > 0) { | |
| 153 | + sb.append(" & "); | |
| 154 | + } | |
| 155 | + sb.append((bounds[i] instanceof Class) | |
| 156 | + ? ((Class) bounds[i]).getName() | |
| 157 | + : bounds[i].toString()); | |
| 158 | + } | |
| 159 | + return sb.toString(); | |
| 160 | + } | |
| 161 | +} | |
Binary file not shown.
| @@ -0,0 +1,105 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This is base class that simplifies access to entities (fields or properties). | |
| 29 | + * The {@code name} attribute specifies the name of the accessible entity. | |
| 30 | + * The element defines getter if it contains no argument | |
| 31 | + * or setter if it contains one argument. | |
| 32 | + * | |
| 33 | + * @since 1.7 | |
| 34 | + * | |
| 35 | + * @author Sergey A. Malenkov | |
| 36 | + */ | |
| 37 | +abstract class AccessorElementHandler extends ElementHandler { | |
| 38 | + private String name; | |
| 39 | + private ValueObject value; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * Parses attributes of the element. | |
| 43 | + * The following atributes are supported: | |
| 44 | + * <dl> | |
| 45 | + * <dt>name | |
| 46 | + * <dd>the name of the accessible entity | |
| 47 | + * <dt>id | |
| 48 | + * <dd>the identifier of the variable that is intended to store the result | |
| 49 | + * </dl> | |
| 50 | + * | |
| 51 | + * @param name the attribute name | |
| 52 | + * @param value the attribute value | |
| 53 | + */ | |
| 54 | + @Override | |
| 55 | + public void addAttribute(String name, String value) { | |
| 56 | + if (name.equals("name")) { // NON-NLS: the attribute name | |
| 57 | + this.name = value; | |
| 58 | + } else { | |
| 59 | + super.addAttribute(name, value); | |
| 60 | + } | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Adds the argument that is used to set the value of this element. | |
| 65 | + * | |
| 66 | + * @param argument the value of the element that contained in this one | |
| 67 | + */ | |
| 68 | + @Override | |
| 69 | + protected final void addArgument(Object argument) { | |
| 70 | + if (this.value != null) { | |
| 71 | + throw new IllegalStateException("Could not add argument to evaluated element"); | |
| 72 | + } | |
| 73 | + setValue(this.name, argument); | |
| 74 | + this.value = ValueObjectImpl.VOID; | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Returns the value of this element. | |
| 79 | + * | |
| 80 | + * @return the value of this element | |
| 81 | + */ | |
| 82 | + @Override | |
| 83 | + protected final ValueObject getValueObject() { | |
| 84 | + if (this.value == null) { | |
| 85 | + this.value = ValueObjectImpl.create(getValue(this.name)); | |
| 86 | + } | |
| 87 | + return this.value; | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Returns the value of the entity with specified {@code name}. | |
| 92 | + * | |
| 93 | + * @param name the name of the accessible entity | |
| 94 | + * @return the value of the specified entity | |
| 95 | + */ | |
| 96 | + protected abstract Object getValue(String name); | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * Sets the new value for the entity with specified {@code name}. | |
| 100 | + * | |
| 101 | + * @param name the name of the accessible entity | |
| 102 | + * @param value the new value for the specified entity | |
| 103 | + */ | |
| 104 | + protected abstract void setValue(String name, Object value); | |
| 105 | +} | |
Binary file not shown.
| @@ -0,0 +1,133 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +import java.lang.reflect.Array; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * This class is intended to handle <array> element, | |
| 31 | + * that is used to array creation. | |
| 32 | + * The {@code length} attribute specifies the length of the array. | |
| 33 | + * The {@code class} attribute specifies the elements type. | |
| 34 | + * The {@link Object} type is used by default. | |
| 35 | + * For example:<pre> | |
| 36 | + * <array length="10"/></pre> | |
| 37 | + * is equivalent to {@code new Component[10]} in Java code. | |
| 38 | + * The {@code set} and {@code get} methods, | |
| 39 | + * as defined in the {@link java.util.List} interface, | |
| 40 | + * can be used as if they could be applied to array instances. | |
| 41 | + * The {@code index} attribute can thus be used with arrays. | |
| 42 | + * For example:<pre> | |
| 43 | + * <array length="3" class="java.lang.String"> | |
| 44 | + * <void index="1"> | |
| 45 | + * <string>Hello, world</string> | |
| 46 | + * </void> | |
| 47 | + * </array></pre> | |
| 48 | + * is equivalent to the following Java code:<pre> | |
| 49 | + * String[] s = new String[3]; | |
| 50 | + * s[1] = "Hello, world";</pre> | |
| 51 | + * It is possible to omit the {@code length} attribute and | |
| 52 | + * specify the values directly, without using {@code void} tags. | |
| 53 | + * The length of the array is equal to the number of values specified. | |
| 54 | + * For example:<pre> | |
| 55 | + * <array id="array" class="int"> | |
| 56 | + * <int>123</int> | |
| 57 | + * <int>456</int> | |
| 58 | + * </array></pre> | |
| 59 | + * is equivalent to {@code int[] array = {123, 456}} in Java code. | |
| 60 | + * <p>The following atributes are supported: | |
| 61 | + * <dl> | |
| 62 | + * <dt>length | |
| 63 | + * <dd>the array length | |
| 64 | + * <dt>class | |
| 65 | + * <dd>the type of object for instantiation | |
| 66 | + * <dt>id | |
| 67 | + * <dd>the identifier of the variable that is intended to store the result | |
| 68 | + * </dl> | |
| 69 | + * | |
| 70 | + * @since 1.7 | |
| 71 | + * | |
| 72 | + * @author Sergey A. Malenkov | |
| 73 | + */ | |
| 74 | +final class ArrayElementHandler extends NewElementHandler { | |
| 75 | + private Integer length; | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Parses attributes of the element. | |
| 79 | + * The following atributes are supported: | |
| 80 | + * <dl> | |
| 81 | + * <dt>length | |
| 82 | + * <dd>the array length | |
| 83 | + * <dt>class | |
| 84 | + * <dd>the type of object for instantiation | |
| 85 | + * <dt>id | |
| 86 | + * <dd>the identifier of the variable that is intended to store the result | |
| 87 | + * </dl> | |
| 88 | + * | |
| 89 | + * @param name the attribute name | |
| 90 | + * @param value the attribute value | |
| 91 | + */ | |
| 92 | + @Override | |
| 93 | + public void addAttribute(String name, String value) { | |
| 94 | + if (name.equals("length")) { // NON-NLS: the attribute name | |
| 95 | + this.length = Integer.valueOf(value); | |
| 96 | + } else { | |
| 97 | + super.addAttribute(name, value); | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Calculates the value of this element | |
| 103 | + * if the lentgh attribute is set. | |
| 104 | + */ | |
| 105 | + @Override | |
| 106 | + public void startElement() { | |
| 107 | + if (this.length != null) { | |
| 108 | + getValueObject(); | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * Creates an instance of the array. | |
| 114 | + * | |
| 115 | + * @param type the base class | |
| 116 | + * @param args the array of arguments | |
| 117 | + * @return the value of this element | |
| 118 | + */ | |
| 119 | + @Override | |
| 120 | + protected ValueObject getValueObject(Class<?> type, Object[] args) { | |
| 121 | + if (type == null) { | |
| 122 | + type = Object.class; | |
| 123 | + } | |
| 124 | + if (this.length != null) { | |
| 125 | + return ValueObjectImpl.create(Array.newInstance(type, this.length)); | |
| 126 | + } | |
| 127 | + Object array = Array.newInstance(type, args.length); | |
| 128 | + for (int i = 0; i < args.length; i++) { | |
| 129 | + Array.set(array, i, args[i]); | |
| 130 | + } | |
| 131 | + return ValueObjectImpl.create(array); | |
| 132 | + } | |
| 133 | +} | |
Binary file not shown.
| @@ -0,0 +1,69 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <boolean> element. | |
| 29 | + * This element specifies {@code boolean} values. | |
| 30 | + * The class {@link Boolean} is used as wrapper for these values. | |
| 31 | + * The result value is created from text of the body of this element. | |
| 32 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 33 | + * For example:<pre> | |
| 34 | + * <boolean>true</boolean></pre> | |
| 35 | + * is shortcut to<pre> | |
| 36 | + * <method name="valueOf" class="java.lang.Boolean"> | |
| 37 | + * <string>true</string> | |
| 38 | + * </method></pre> | |
| 39 | + * which is equivalent to {@code Boolean.valueOf("true")} in Java code. | |
| 40 | + * <p>The following atribute is supported: | |
| 41 | + * <dl> | |
| 42 | + * <dt>id | |
| 43 | + * <dd>the identifier of the variable that is intended to store the result | |
| 44 | + * </dl> | |
| 45 | + * | |
| 46 | + * @since 1.7 | |
| 47 | + * | |
| 48 | + * @author Sergey A. Malenkov | |
| 49 | + */ | |
| 50 | +final class BooleanElementHandler extends StringElementHandler { | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Creates {@code boolean} value from | |
| 54 | + * the text of the body of this element. | |
| 55 | + * | |
| 56 | + * @param argument the text of the body | |
| 57 | + * @return evaluated {@code boolean} value | |
| 58 | + */ | |
| 59 | + @Override | |
| 60 | + public Object getValue(String argument) { | |
| 61 | + if (Boolean.TRUE.toString().equalsIgnoreCase(argument)) { | |
| 62 | + return Boolean.TRUE; | |
| 63 | + } | |
| 64 | + if (Boolean.FALSE.toString().equalsIgnoreCase(argument)) { | |
| 65 | + return Boolean.FALSE; | |
| 66 | + } | |
| 67 | + throw new IllegalArgumentException("Unsupported boolean argument: " + argument); | |
| 68 | + } | |
| 69 | +} | |
Binary file not shown.
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <byte> element. | |
| 29 | + * This element specifies {@code byte} values. | |
| 30 | + * The class {@link Byte} is used as wrapper for these values. | |
| 31 | + * The result value is created from text of the body of this element. | |
| 32 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 33 | + * For example:<pre> | |
| 34 | + * <byte>127</byte></pre> | |
| 35 | + * is shortcut to<pre> | |
| 36 | + * <method name="decode" class="java.lang.Byte"> | |
| 37 | + * <string>127</string> | |
| 38 | + * </method></pre> | |
| 39 | + * which is equivalent to {@code Byte.decode("127")} in Java code. | |
| 40 | + * <p>The following atribute is supported: | |
| 41 | + * <dl> | |
| 42 | + * <dt>id | |
| 43 | + * <dd>the identifier of the variable that is intended to store the result | |
| 44 | + * </dl> | |
| 45 | + * | |
| 46 | + * @since 1.7 | |
| 47 | + * | |
| 48 | + * @author Sergey A. Malenkov | |
| 49 | + */ | |
| 50 | +final class ByteElementHandler extends StringElementHandler { | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Creates {@code byte} value from | |
| 54 | + * the text of the body of this element. | |
| 55 | + * | |
| 56 | + * @param argument the text of the body | |
| 57 | + * @return evaluated {@code byte} value | |
| 58 | + */ | |
| 59 | + @Override | |
| 60 | + public Object getValue(String argument) { | |
| 61 | + return Byte.decode(argument); | |
| 62 | + } | |
| 63 | +} | |
Binary file not shown.
| @@ -0,0 +1,92 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <char> element. | |
| 29 | + * This element specifies {@code char} values. | |
| 30 | + * The class {@link Character} is used as wrapper for these values. | |
| 31 | + * The result value is created from text of the body of this element. | |
| 32 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 33 | + * For example:<pre> | |
| 34 | + * <char>X</char></pre> | |
| 35 | + * which is equivalent to {@code Character.valueOf('X')} in Java code. | |
| 36 | + * <p>The following atributes are supported: | |
| 37 | + * <dl> | |
| 38 | + * <dt>code | |
| 39 | + * <dd>this attribute specifies character code | |
| 40 | + * <dt>id | |
| 41 | + * <dd>the identifier of the variable that is intended to store the result | |
| 42 | + * </dl> | |
| 43 | + * The {@code code} attribute can be used for characters | |
| 44 | + * that are illegal in XML document, for example:<pre> | |
| 45 | + * <char code="0"/></pre> | |
| 46 | + * | |
| 47 | + * @since 1.7 | |
| 48 | + * | |
| 49 | + * @author Sergey A. Malenkov | |
| 50 | + */ | |
| 51 | +final class CharElementHandler extends StringElementHandler { | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Parses attributes of the element. | |
| 55 | + * The following atributes are supported: | |
| 56 | + * <dl> | |
| 57 | + * <dt>code | |
| 58 | + * <dd>this attribute specifies character code | |
| 59 | + * <dt>id | |
| 60 | + * <dd>the identifier of the variable that is intended to store the result | |
| 61 | + * </dl> | |
| 62 | + * | |
| 63 | + * @param name the attribute name | |
| 64 | + * @param value the attribute value | |
| 65 | + */ | |
| 66 | + @Override | |
| 67 | + public void addAttribute(String name, String value) { | |
| 68 | + if (name.equals("code")) { // NON-NLS: the attribute name | |
| 69 | + int code = Integer.decode(value); | |
| 70 | + for (char ch : Character.toChars(code)) { | |
| 71 | + addCharacter(ch); | |
| 72 | + } | |
| 73 | + } else { | |
| 74 | + super.addAttribute(name, value); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Creates {@code char} value from | |
| 80 | + * the text of the body of this element. | |
| 81 | + * | |
| 82 | + * @param argument the text of the body | |
| 83 | + * @return evaluated {@code char} value | |
| 84 | + */ | |
| 85 | + @Override | |
| 86 | + public Object getValue(String argument) { | |
| 87 | + if (argument.length() != 1) { | |
| 88 | + throw new IllegalArgumentException("Wrong characters count"); | |
| 89 | + } | |
| 90 | + return Character.valueOf(argument.charAt(0)); | |
| 91 | + } | |
| 92 | +} | |
Binary file not shown.
| @@ -0,0 +1,62 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <class> element. | |
| 29 | + * This element specifies {@link Class} values. | |
| 30 | + * The result value is created from text of the body of this element. | |
| 31 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 32 | + * For example:<pre> | |
| 33 | + * <class>java.lang.Class</class></pre> | |
| 34 | + * is shortcut to<pre> | |
| 35 | + * <method name="forName" class="java.lang.Class"> | |
| 36 | + * <string>java.lang.Class</string> | |
| 37 | + * </method></pre> | |
| 38 | + * which is equivalent to {@code Class.forName("java.lang.Class")} in Java code. | |
| 39 | + * <p>The following atribute is supported: | |
| 40 | + * <dl> | |
| 41 | + * <dt>id | |
| 42 | + * <dd>the identifier of the variable that is intended to store the result | |
| 43 | + * </dl> | |
| 44 | + * | |
| 45 | + * @since 1.7 | |
| 46 | + * | |
| 47 | + * @author Sergey A. Malenkov | |
| 48 | + */ | |
| 49 | +final class ClassElementHandler extends StringElementHandler { | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Creates class by the name from | |
| 53 | + * the text of the body of this element. | |
| 54 | + * | |
| 55 | + * @param argument the text of the body | |
| 56 | + * @return evaluated {@code Class} value | |
| 57 | + */ | |
| 58 | + @Override | |
| 59 | + public Object getValue(String argument) { | |
| 60 | + return getOwner().findClass(argument); | |
| 61 | + } | |
| 62 | +} | |
Binary file not shown.
| @@ -0,0 +1,389 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +import com.sun.beans.finder.ClassFinder; | |
| 28 | + | |
| 29 | +import java.beans.ExceptionListener; | |
| 30 | + | |
| 31 | +import java.io.IOException; | |
| 32 | + | |
| 33 | +import java.lang.ref.Reference; | |
| 34 | +import java.lang.ref.WeakReference; | |
| 35 | + | |
| 36 | +import java.util.ArrayList; | |
| 37 | +import java.util.HashMap; | |
| 38 | +import java.util.List; | |
| 39 | +import java.util.Map; | |
| 40 | + | |
| 41 | +import javax.xml.parsers.ParserConfigurationException; | |
| 42 | +import javax.xml.parsers.SAXParserFactory; | |
| 43 | + | |
| 44 | +import org.xml.sax.Attributes; | |
| 45 | +import org.xml.sax.InputSource; | |
| 46 | +import org.xml.sax.SAXException; | |
| 47 | +import org.xml.sax.helpers.DefaultHandler; | |
| 48 | + | |
| 49 | +/** | |
| 50 | + * The main class to parse JavaBeans XML archive. | |
| 51 | + * | |
| 52 | + * @since 1.7 | |
| 53 | + * | |
| 54 | + * @author Sergey A. Malenkov | |
| 55 | + * | |
| 56 | + * @see ElementHandler | |
| 57 | + */ | |
| 58 | +public final class DocumentHandler extends DefaultHandler { | |
| 59 | + private final Map<String, Class<? extends ElementHandler>> handlers = new HashMap<String, Class<? extends ElementHandler>>(); | |
| 60 | + | |
| 61 | + private final Map<String, Object> environment = new HashMap<String, Object>(); | |
| 62 | + | |
| 63 | + private final List<Object> objects = new ArrayList<Object>(); | |
| 64 | + | |
| 65 | + private Reference<ClassLoader> loader; | |
| 66 | + private ExceptionListener listener; | |
| 67 | + private Object owner; | |
| 68 | + | |
| 69 | + private ElementHandler handler; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Creates new instance of document handler. | |
| 73 | + */ | |
| 74 | + public DocumentHandler() { | |
| 75 | + setElementHandler("java", JavaElementHandler.class); // NON-NLS: the element name | |
| 76 | + setElementHandler("null", NullElementHandler.class); // NON-NLS: the element name | |
| 77 | + setElementHandler("array", ArrayElementHandler.class); // NON-NLS: the element name | |
| 78 | + setElementHandler("class", ClassElementHandler.class); // NON-NLS: the element name | |
| 79 | + setElementHandler("string", StringElementHandler.class); // NON-NLS: the element name | |
| 80 | + setElementHandler("object", ObjectElementHandler.class); // NON-NLS: the element name | |
| 81 | + | |
| 82 | + setElementHandler("void", VoidElementHandler.class); // NON-NLS: the element name | |
| 83 | + setElementHandler("char", CharElementHandler.class); // NON-NLS: the element name | |
| 84 | + setElementHandler("byte", ByteElementHandler.class); // NON-NLS: the element name | |
| 85 | + setElementHandler("short", ShortElementHandler.class); // NON-NLS: the element name | |
| 86 | + setElementHandler("int", IntElementHandler.class); // NON-NLS: the element name | |
| 87 | + setElementHandler("long", LongElementHandler.class); // NON-NLS: the element name | |
| 88 | + setElementHandler("float", FloatElementHandler.class); // NON-NLS: the element name | |
| 89 | + setElementHandler("double", DoubleElementHandler.class); // NON-NLS: the element name | |
| 90 | + setElementHandler("boolean", BooleanElementHandler.class); // NON-NLS: the element name | |
| 91 | + | |
| 92 | + // some handlers for new elements | |
| 93 | + setElementHandler("new", NewElementHandler.class); // NON-NLS: the element name | |
| 94 | + setElementHandler("var", VarElementHandler.class); // NON-NLS: the element name | |
| 95 | + setElementHandler("true", TrueElementHandler.class); // NON-NLS: the element name | |
| 96 | + setElementHandler("false", FalseElementHandler.class); // NON-NLS: the element name | |
| 97 | + setElementHandler("field", FieldElementHandler.class); // NON-NLS: the element name | |
| 98 | + setElementHandler("method", MethodElementHandler.class); // NON-NLS: the element name | |
| 99 | + setElementHandler("property", PropertyElementHandler.class); // NON-NLS: the element name | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Returns the class loader used to instantiate objects. | |
| 104 | + * If the class loader has not been explicitly set | |
| 105 | + * then {@code null} is returned. | |
| 106 | + * | |
| 107 | + * @return the class loader used to instantiate objects | |
| 108 | + */ | |
| 109 | + public ClassLoader getClassLoader() { | |
| 110 | + return (this.loader != null) | |
| 111 | + ? this.loader.get() | |
| 112 | + : null; | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * Sets the class loader used to instantiate objects. | |
| 117 | + * If the class loader is not set | |
| 118 | + * then default class loader will be used. | |
| 119 | + * | |
| 120 | + * @param loader a classloader to use | |
| 121 | + */ | |
| 122 | + public void setClassLoader(ClassLoader loader) { | |
| 123 | + this.loader = new WeakReference<ClassLoader>(loader); | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * Returns the exception listener for parsing. | |
| 128 | + * The exception listener is notified | |
| 129 | + * when handler catches recoverable exceptions. | |
| 130 | + * If the exception listener has not been explicitly set | |
| 131 | + * then default exception listener is returned. | |
| 132 | + * | |
| 133 | + * @return the exception listener for parsing | |
| 134 | + */ | |
| 135 | + public ExceptionListener getExceptionListener() { | |
| 136 | + return this.listener; | |
| 137 | + } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Sets the exception listener for parsing. | |
| 141 | + * The exception listener is notified | |
| 142 | + * when handler catches recoverable exceptions. | |
| 143 | + * | |
| 144 | + * @param listener the exception listener for parsing | |
| 145 | + */ | |
| 146 | + public void setExceptionListener(ExceptionListener listener) { | |
| 147 | + this.listener = listener; | |
| 148 | + } | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * Returns the owner of this document handler. | |
| 152 | + * | |
| 153 | + * @return the owner of this document handler | |
| 154 | + */ | |
| 155 | + public Object getOwner() { | |
| 156 | + return this.owner; | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * Sets the owner of this document handler. | |
| 161 | + * | |
| 162 | + * @param owner the owner of this document handler | |
| 163 | + */ | |
| 164 | + public void setOwner(Object owner) { | |
| 165 | + this.owner = owner; | |
| 166 | + } | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * Returns the handler for the element with specified name. | |
| 170 | + * | |
| 171 | + * @param name the name of the element | |
| 172 | + * @return the corresponding element handler | |
| 173 | + */ | |
| 174 | + public Class<? extends ElementHandler> getElementHandler(String name) { | |
| 175 | + Class<? extends ElementHandler> type = this.handlers.get(name); | |
| 176 | + if (type == null) { | |
| 177 | + throw new IllegalArgumentException("Unsupported element: " + name); | |
| 178 | + } | |
| 179 | + return type; | |
| 180 | + } | |
| 181 | + | |
| 182 | + /** | |
| 183 | + * Sets the handler for the element with specified name. | |
| 184 | + * | |
| 185 | + * @param name the name of the element | |
| 186 | + * @param handler the corresponding element handler | |
| 187 | + */ | |
| 188 | + public void setElementHandler(String name, Class<? extends ElementHandler> handler) { | |
| 189 | + this.handlers.put(name, handler); | |
| 190 | + } | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * Indicates whether the variable with specified identifier is defined. | |
| 194 | + * | |
| 195 | + * @param id the identifier | |
| 196 | + * @return @{code true} if the variable is defined; | |
| 197 | + * @{code false} otherwise | |
| 198 | + */ | |
| 199 | + public boolean hasVariable(String id) { | |
| 200 | + return this.environment.containsKey(id); | |
| 201 | + } | |
| 202 | + | |
| 203 | + /** | |
| 204 | + * Returns the value of the variable with specified identifier. | |
| 205 | + * | |
| 206 | + * @param id the identifier | |
| 207 | + * @return the value of the variable | |
| 208 | + */ | |
| 209 | + public Object getVariable(String id) { | |
| 210 | + if (!this.environment.containsKey(id)) { | |
| 211 | + throw new IllegalArgumentException("Unbound variable: " + id); | |
| 212 | + } | |
| 213 | + return this.environment.get(id); | |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * Sets new value of the variable with specified identifier. | |
| 218 | + * | |
| 219 | + * @param id the identifier | |
| 220 | + * @param value new value of the variable | |
| 221 | + */ | |
| 222 | + public void setVariable(String id, Object value) { | |
| 223 | + this.environment.put(id, value); | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * Returns the array of readed objects. | |
| 228 | + * | |
| 229 | + * @return the array of readed objects | |
| 230 | + */ | |
| 231 | + public Object[] getObjects() { | |
| 232 | + return this.objects.toArray(); | |
| 233 | + } | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * Adds the object to the list of readed objects. | |
| 237 | + * | |
| 238 | + * @param object the object that is readed from XML document | |
| 239 | + */ | |
| 240 | + void addObject(Object object) { | |
| 241 | + this.objects.add(object); | |
| 242 | + } | |
| 243 | + | |
| 244 | + /** | |
| 245 | + * Prepares this handler to read objects from XML document. | |
| 246 | + */ | |
| 247 | + @Override | |
| 248 | + public void startDocument() { | |
| 249 | + this.objects.clear(); | |
| 250 | + this.handler = null; | |
| 251 | + } | |
| 252 | + | |
| 253 | + /** | |
| 254 | + * Parses opening tag of XML element | |
| 255 | + * using corresponding element handler. | |
| 256 | + * | |
| 257 | + * @param uri the namespace URI, or the empty string | |
| 258 | + * if the element has no namespace URI or | |
| 259 | + * if namespace processing is not being performed | |
| 260 | + * @param localName the local name (without prefix), or the empty string | |
| 261 | + * if namespace processing is not being performed | |
| 262 | + * @param qName the qualified name (with prefix), or the empty string | |
| 263 | + * if qualified names are not available | |
| 264 | + * @param attributes the attributes attached to the element | |
| 265 | + */ | |
| 266 | + @Override | |
| 267 | + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { | |
| 268 | + ElementHandler parent = this.handler; | |
| 269 | + try { | |
| 270 | + this.handler = getElementHandler(qName).newInstance(); | |
| 271 | + this.handler.setOwner(this); | |
| 272 | + this.handler.setParent(parent); | |
| 273 | + } | |
| 274 | + catch (Exception exception) { | |
| 275 | + throw new SAXException(exception); | |
| 276 | + } | |
| 277 | + for (int i = 0; i < attributes.getLength(); i++) | |
| 278 | + try { | |
| 279 | + String name = attributes.getQName(i); | |
| 280 | + String value = attributes.getValue(i); | |
| 281 | + this.handler.addAttribute(name, value); | |
| 282 | + } | |
| 283 | + catch (RuntimeException exception) { | |
| 284 | + handleException(exception); | |
| 285 | + } | |
| 286 | + | |
| 287 | + this.handler.startElement(); | |
| 288 | + } | |
| 289 | + | |
| 290 | + /** | |
| 291 | + * Parses closing tag of XML element | |
| 292 | + * using corresponding element handler. | |
| 293 | + * | |
| 294 | + * @param uri the namespace URI, or the empty string | |
| 295 | + * if the element has no namespace URI or | |
| 296 | + * if namespace processing is not being performed | |
| 297 | + * @param localName the local name (without prefix), or the empty string | |
| 298 | + * if namespace processing is not being performed | |
| 299 | + * @param qName the qualified name (with prefix), or the empty string | |
| 300 | + * if qualified names are not available | |
| 301 | + */ | |
| 302 | + @Override | |
| 303 | + public void endElement(String uri, String localName, String qName) { | |
| 304 | + try { | |
| 305 | + this.handler.endElement(); | |
| 306 | + } | |
| 307 | + catch (RuntimeException exception) { | |
| 308 | + handleException(exception); | |
| 309 | + } | |
| 310 | + finally { | |
| 311 | + this.handler = this.handler.getParent(); | |
| 312 | + } | |
| 313 | + } | |
| 314 | + | |
| 315 | + /** | |
| 316 | + * Parses character data inside XML element. | |
| 317 | + * | |
| 318 | + * @param chars the array of characters | |
| 319 | + * @param start the start position in the character array | |
| 320 | + * @param length the number of characters to use | |
| 321 | + */ | |
| 322 | + @Override | |
| 323 | + public void characters(char[] chars, int start, int length) { | |
| 324 | + if (this.handler != null) { | |
| 325 | + try { | |
| 326 | + while (0 < length--) { | |
| 327 | + this.handler.addCharacter(chars[start++]); | |
| 328 | + } | |
| 329 | + } | |
| 330 | + catch (RuntimeException exception) { | |
| 331 | + handleException(exception); | |
| 332 | + } | |
| 333 | + } | |
| 334 | + } | |
| 335 | + | |
| 336 | + /** | |
| 337 | + * Handles an exception using current exception listener. | |
| 338 | + * | |
| 339 | + * @param exception an exception to handle | |
| 340 | + * @see #setExceptionListener | |
| 341 | + */ | |
| 342 | + public void handleException(Exception exception) { | |
| 343 | + if (this.listener == null) { | |
| 344 | + throw new IllegalStateException(exception); | |
| 345 | + } | |
| 346 | + this.listener.exceptionThrown(exception); | |
| 347 | + } | |
| 348 | + | |
| 349 | + /** | |
| 350 | + * Starts parsing of the specified input source. | |
| 351 | + * | |
| 352 | + * @param input the input source to parse | |
| 353 | + */ | |
| 354 | + public void parse(InputSource input) { | |
| 355 | + try { | |
| 356 | + SAXParserFactory.newInstance().newSAXParser().parse(input, this); | |
| 357 | + } | |
| 358 | + catch (ParserConfigurationException exception) { | |
| 359 | + handleException(exception); | |
| 360 | + } | |
| 361 | + catch (SAXException wrapper) { | |
| 362 | + Exception exception = wrapper.getException(); | |
| 363 | + if (exception == null) { | |
| 364 | + exception = wrapper; | |
| 365 | + } | |
| 366 | + handleException(exception); | |
| 367 | + } | |
| 368 | + catch (IOException exception) { | |
| 369 | + handleException(exception); | |
| 370 | + } | |
| 371 | + } | |
| 372 | + | |
| 373 | + /** | |
| 374 | + * Resolves class by name using current class loader. | |
| 375 | + * This method handles exception using current exception listener. | |
| 376 | + * | |
| 377 | + * @param name the name of the class | |
| 378 | + * @return the object that represents the class | |
| 379 | + */ | |
| 380 | + public Class<?> findClass(String name) { | |
| 381 | + try { | |
| 382 | + return ClassFinder.resolveClass(name, getClassLoader()); | |
| 383 | + } | |
| 384 | + catch (ClassNotFoundException exception) { | |
| 385 | + handleException(exception); | |
| 386 | + return null; | |
| 387 | + } | |
| 388 | + } | |
| 389 | +} | |
Binary file not shown.
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <double> element. | |
| 29 | + * This element specifies {@code double} values. | |
| 30 | + * The class {@link Double} is used as wrapper for these values. | |
| 31 | + * The result value is created from text of the body of this element. | |
| 32 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 33 | + * For example:<pre> | |
| 34 | + * <double>1.23e45</double></pre> | |
| 35 | + * is shortcut to<pre> | |
| 36 | + * <method name="valueOf" class="java.lang.Double"> | |
| 37 | + * <string>1.23e45</string> | |
| 38 | + * </method></pre> | |
| 39 | + * which is equivalent to {@code Double.valueOf("1.23e45")} in Java code. | |
| 40 | + * <p>The following atribute is supported: | |
| 41 | + * <dl> | |
| 42 | + * <dt>id | |
| 43 | + * <dd>the identifier of the variable that is intended to store the result | |
| 44 | + * </dl> | |
| 45 | + * | |
| 46 | + * @since 1.7 | |
| 47 | + * | |
| 48 | + * @author Sergey A. Malenkov | |
| 49 | + */ | |
| 50 | +final class DoubleElementHandler extends StringElementHandler { | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Creates {@code double} value from | |
| 54 | + * the text of the body of this element. | |
| 55 | + * | |
| 56 | + * @param argument the text of the body | |
| 57 | + * @return evaluated {@code double} value | |
| 58 | + */ | |
| 59 | + @Override | |
| 60 | + public Object getValue(String argument) { | |
| 61 | + return Double.valueOf(argument); | |
| 62 | + } | |
| 63 | +} | |
Binary file not shown.
| @@ -0,0 +1,224 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * The base class for element handlers. | |
| 29 | + * | |
| 30 | + * @since 1.7 | |
| 31 | + * | |
| 32 | + * @author Sergey A. Malenkov | |
| 33 | + * | |
| 34 | + * @see DocumentHandler | |
| 35 | + */ | |
| 36 | +public abstract class ElementHandler { | |
| 37 | + private DocumentHandler owner; | |
| 38 | + private ElementHandler parent; | |
| 39 | + | |
| 40 | + private String id; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Returns the document handler that creates this element handler. | |
| 44 | + * | |
| 45 | + * @return the owner document handler | |
| 46 | + */ | |
| 47 | + public final DocumentHandler getOwner() { | |
| 48 | + return this.owner; | |
| 49 | + } | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Sets the document handler that creates this element handler. | |
| 53 | + * The owner document handler should be set after instantiation. | |
| 54 | + * Such approach is used to simplify the extensibility. | |
| 55 | + * | |
| 56 | + * @param owner the owner document handler | |
| 57 | + * @see DocumentHandler#startElement | |
| 58 | + */ | |
| 59 | + final void setOwner(DocumentHandler owner) { | |
| 60 | + if (owner == null) { | |
| 61 | + throw new IllegalArgumentException("Every element should have owner"); | |
| 62 | + } | |
| 63 | + this.owner = owner; | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * Returns the element handler that contains this one. | |
| 68 | + * | |
| 69 | + * @return the parent element handler | |
| 70 | + */ | |
| 71 | + public final ElementHandler getParent() { | |
| 72 | + return this.parent; | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Sets the element handler that contains this one. | |
| 77 | + * The parent element handler should be set after instantiation. | |
| 78 | + * Such approach is used to simplify the extensibility. | |
| 79 | + * | |
| 80 | + * @param parent the parent element handler | |
| 81 | + * @see DocumentHandler#startElement | |
| 82 | + */ | |
| 83 | + final void setParent(ElementHandler parent) { | |
| 84 | + this.parent = parent; | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Returns the value of the variable with specified identifier. | |
| 89 | + * | |
| 90 | + * @param id the identifier | |
| 91 | + * @return the value of the variable | |
| 92 | + */ | |
| 93 | + protected final Object getVariable(String id) { | |
| 94 | + if (id.equals(this.id)) { | |
| 95 | + ValueObject value = getValueObject(); | |
| 96 | + if (value.isVoid()) { | |
| 97 | + throw new IllegalStateException("The element does not return value"); | |
| 98 | + } | |
| 99 | + return value.getValue(); | |
| 100 | + } | |
| 101 | + return (this.parent != null) | |
| 102 | + ? this.parent.getVariable(id) | |
| 103 | + : this.owner.getVariable(id); | |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * Returns the value of the parent element. | |
| 108 | + * | |
| 109 | + * @return the value of the parent element | |
| 110 | + */ | |
| 111 | + protected Object getContextBean() { | |
| 112 | + if (this.parent != null) { | |
| 113 | + ValueObject value = this.parent.getValueObject(); | |
| 114 | + if (!value.isVoid()) { | |
| 115 | + return value.getValue(); | |
| 116 | + } | |
| 117 | + throw new IllegalStateException("The outer element does not return value"); | |
| 118 | + } else { | |
| 119 | + Object value = this.owner.getOwner(); | |
| 120 | + if (value != null) { | |
| 121 | + return value; | |
| 122 | + } | |
| 123 | + throw new IllegalStateException("The topmost element does not have context"); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * Parses attributes of the element. | |
| 129 | + * By default, the following atribute is supported: | |
| 130 | + * <dl> | |
| 131 | + * <dt>id | |
| 132 | + * <dd>the identifier of the variable that is intended to store the result | |
| 133 | + * </dl> | |
| 134 | + * | |
| 135 | + * @param name the attribute name | |
| 136 | + * @param value the attribute value | |
| 137 | + */ | |
| 138 | + public void addAttribute(String name, String value) { | |
| 139 | + if (name.equals("id")) { // NON-NLS: the attribute name | |
| 140 | + this.id = value; | |
| 141 | + } else { | |
| 142 | + throw new IllegalArgumentException("Unsupported attribute: " + name); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * This method is called before parsing of the element's body. | |
| 148 | + * All attributes are parsed at this point. | |
| 149 | + * By default, do nothing. | |
| 150 | + */ | |
| 151 | + public void startElement() { | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * This method is called after parsing of the element's body. | |
| 156 | + * By default, it calculates the value of this element. | |
| 157 | + * The following tasks are executing for any non-void value: | |
| 158 | + * <ol> | |
| 159 | + * <li>If the {@code id} attribute is set | |
| 160 | + * the value of the variable with the specified identifier | |
| 161 | + * is set to the value of this element.</li> | |
| 162 | + * <li>This element is used as an argument of parent element if it is possible.</li> | |
| 163 | + * </ol> | |
| 164 | + * | |
| 165 | + * @see #isArgument | |
| 166 | + */ | |
| 167 | + public void endElement() { | |
| 168 | + // do nothing if no value returned | |
| 169 | + ValueObject value = getValueObject(); | |
| 170 | + if (!value.isVoid()) { | |
| 171 | + if (this.id != null) { | |
| 172 | + this.owner.setVariable(this.id, value.getValue()); | |
| 173 | + } | |
| 174 | + if (isArgument()) { | |
| 175 | + if (this.parent != null) { | |
| 176 | + this.parent.addArgument(value.getValue()); | |
| 177 | + } else { | |
| 178 | + this.owner.addObject(value.getValue()); | |
| 179 | + } | |
| 180 | + } | |
| 181 | + } | |
| 182 | + } | |
| 183 | + | |
| 184 | + /** | |
| 185 | + * Adds the character that contained in this element. | |
| 186 | + * By default, only whitespaces are acceptable. | |
| 187 | + * | |
| 188 | + * @param ch the character | |
| 189 | + */ | |
| 190 | + public void addCharacter(char ch) { | |
| 191 | + if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) { | |
| 192 | + throw new IllegalStateException("Illegal character with code " + (int) ch); | |
| 193 | + } | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * Adds the argument that is used to calculate the value of this element. | |
| 198 | + * By default, no arguments are acceptable. | |
| 199 | + * | |
| 200 | + * @param argument the value of the element that contained in this one | |
| 201 | + */ | |
| 202 | + protected void addArgument(Object argument) { | |
| 203 | + throw new IllegalStateException("Could not add argument to simple element"); | |
| 204 | + } | |
| 205 | + | |
| 206 | + /** | |
| 207 | + * Tests whether the value of this element can be used | |
| 208 | + * as an argument of the element that contained in this one. | |
| 209 | + * | |
| 210 | + * @return {@code true} if the value of this element can be used | |
| 211 | + * as an argument of the element that contained in this one, | |
| 212 | + * {@code false} otherwise | |
| 213 | + */ | |
| 214 | + protected boolean isArgument() { | |
| 215 | + return this.id == null; | |
| 216 | + } | |
| 217 | + | |
| 218 | + /** | |
| 219 | + * Returns the value of this element. | |
| 220 | + * | |
| 221 | + * @return the value of this element | |
| 222 | + */ | |
| 223 | + protected abstract ValueObject getValueObject(); | |
| 224 | +} | |
Binary file not shown.
| @@ -0,0 +1,56 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <false> element. | |
| 29 | + * This element specifies {@code false} value. | |
| 30 | + * It should not contain body or inner elements. | |
| 31 | + * For example:<pre> | |
| 32 | + * <false/></pre> | |
| 33 | + * is equivalent to {@code false} in Java code. | |
| 34 | + * <p>The following atribute is supported: | |
| 35 | + * <dl> | |
| 36 | + * <dt>id | |
| 37 | + * <dd>the identifier of the variable that is intended to store the result | |
| 38 | + * </dl> | |
| 39 | + * | |
| 40 | + * @since 1.7 | |
| 41 | + * | |
| 42 | + * @author Sergey A. Malenkov | |
| 43 | + */ | |
| 44 | +final class FalseElementHandler extends NullElementHandler { | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Returns {@code Boolean.FALSE} | |
| 48 | + * as a value of <false> element. | |
| 49 | + * | |
| 50 | + * @return {@code Boolean.FALSE} by default | |
| 51 | + */ | |
| 52 | + @Override | |
| 53 | + public Object getValue() { | |
| 54 | + return Boolean.FALSE; | |
| 55 | + } | |
| 56 | +} | |
Binary file not shown.
| @@ -0,0 +1,189 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +import com.sun.beans.finder.FieldFinder; | |
| 28 | + | |
| 29 | +import java.lang.reflect.Field; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * This class is intended to handle <field> element. | |
| 33 | + * This element simplifies access to the fields. | |
| 34 | + * If the {@code class} attribute is specified | |
| 35 | + * this element accesses static field of specified class. | |
| 36 | + * This element defines getter if it contains no argument. | |
| 37 | + * It returns the value of the field in this case. | |
| 38 | + * For example:<pre> | |
| 39 | + * <field name="TYPE" class="java.lang.Long"/></pre> | |
| 40 | + * is equivalent to {@code Long.TYPE} in Java code. | |
| 41 | + * This element defines setter if it contains one argument. | |
| 42 | + * It does not return the value of the field in this case. | |
| 43 | + * For example:<pre> | |
| 44 | + * <field name="id"><int>0</int></field></pre> | |
| 45 | + * is equivalent to {@code id = 0} in Java code. | |
| 46 | + * <p>The following atributes are supported: | |
| 47 | + * <dl> | |
| 48 | + * <dt>name | |
| 49 | + * <dd>the field name | |
| 50 | + * <dt>class | |
| 51 | + * <dd>the type is used for static fields only | |
| 52 | + * <dt>id | |
| 53 | + * <dd>the identifier of the variable that is intended to store the result | |
| 54 | + * </dl> | |
| 55 | + * | |
| 56 | + * @since 1.7 | |
| 57 | + * | |
| 58 | + * @author Sergey A. Malenkov | |
| 59 | + */ | |
| 60 | +final class FieldElementHandler extends AccessorElementHandler { | |
| 61 | + private Class<?> type; | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Parses attributes of the element. | |
| 65 | + * The following atributes are supported: | |
| 66 | + * <dl> | |
| 67 | + * <dt>name | |
| 68 | + * <dd>the field name | |
| 69 | + * <dt>class | |
| 70 | + * <dd>the type is used for static fields only | |
| 71 | + * <dt>id | |
| 72 | + * <dd>the identifier of the variable that is intended to store the result | |
| 73 | + * </dl> | |
| 74 | + * | |
| 75 | + * @param name the attribute name | |
| 76 | + * @param value the attribute value | |
| 77 | + */ | |
| 78 | + @Override | |
| 79 | + public void addAttribute(String name, String value) { | |
| 80 | + if (name.equals("class")) { // NON-NLS: the attribute name | |
| 81 | + this.type = getOwner().findClass(value); | |
| 82 | + } else { | |
| 83 | + super.addAttribute(name, value); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Tests whether the value of this element can be used | |
| 89 | + * as an argument of the element that contained in this one. | |
| 90 | + * | |
| 91 | + * @return {@code true} if the value of this element should be used | |
| 92 | + * as an argument of the element that contained in this one, | |
| 93 | + * {@code false} otherwise | |
| 94 | + */ | |
| 95 | + @Override | |
| 96 | + protected boolean isArgument() { | |
| 97 | + return super.isArgument() && (this.type != null); // only static accessor can be used an argument | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Returns the context of the field. | |
| 102 | + * The context of the static field is the class object. | |
| 103 | + * The context of the non-static field is the value of the parent element. | |
| 104 | + * | |
| 105 | + * @return the context of the field | |
| 106 | + */ | |
| 107 | + @Override | |
| 108 | + protected Object getContextBean() { | |
| 109 | + return (this.type != null) | |
| 110 | + ? this.type | |
| 111 | + : super.getContextBean(); | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Returns the value of the field with specified {@code name}. | |
| 116 | + * | |
| 117 | + * @param name the name of the field | |
| 118 | + * @return the value of the specified field | |
| 119 | + */ | |
| 120 | + @Override | |
| 121 | + protected Object getValue(String name) { | |
| 122 | + try { | |
| 123 | + return getFieldValue(getContextBean(), name); | |
| 124 | + } | |
| 125 | + catch (Exception exception) { | |
| 126 | + getOwner().handleException(exception); | |
| 127 | + } | |
| 128 | + return null; | |
| 129 | + } | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * Sets the new value for the field with specified {@code name}. | |
| 133 | + * | |
| 134 | + * @param name the name of the field | |
| 135 | + * @param value the new value for the specified field | |
| 136 | + */ | |
| 137 | + @Override | |
| 138 | + protected void setValue(String name, Object value) { | |
| 139 | + try { | |
| 140 | + setFieldValue(getContextBean(), name, value); | |
| 141 | + } | |
| 142 | + catch (Exception exception) { | |
| 143 | + getOwner().handleException(exception); | |
| 144 | + } | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * Performs the search of the field with specified {@code name} | |
| 149 | + * in specified context and returns its value. | |
| 150 | + * | |
| 151 | + * @param bean the context bean that contains field | |
| 152 | + * @param name the name of the field | |
| 153 | + * @return the value of the field | |
| 154 | + * @throws IllegalAccessException if the field is not accesible | |
| 155 | + * @throws NoSuchFieldException if the field is not found | |
| 156 | + */ | |
| 157 | + static Object getFieldValue(Object bean, String name) throws IllegalAccessException, NoSuchFieldException { | |
| 158 | + return findField(bean, name).get(bean); | |
| 159 | + } | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * Performs the search of the field with specified {@code name} | |
| 163 | + * in specified context and updates its value. | |
| 164 | + * | |
| 165 | + * @param bean the context bean that contains field | |
| 166 | + * @param name the name of the field | |
| 167 | + * @param value the new value for the field | |
| 168 | + * @throws IllegalAccessException if the field is not accesible | |
| 169 | + * @throws NoSuchFieldException if the field is not found | |
| 170 | + */ | |
| 171 | + private static void setFieldValue(Object bean, String name, Object value) throws IllegalAccessException, NoSuchFieldException { | |
| 172 | + findField(bean, name).set(bean, value); | |
| 173 | + } | |
| 174 | + | |
| 175 | + /** | |
| 176 | + * Performs the search of the field | |
| 177 | + * with specified {@code name} in specified context. | |
| 178 | + * | |
| 179 | + * @param bean the context bean that contains field | |
| 180 | + * @param name the name of the field | |
| 181 | + * @return field object that represents found field | |
| 182 | + * @throws NoSuchFieldException if the field is not found | |
| 183 | + */ | |
| 184 | + private static Field findField(Object bean, String name) throws NoSuchFieldException { | |
| 185 | + return (bean instanceof Class<?>) | |
| 186 | + ? FieldFinder.findStaticField((Class<?>) bean, name) | |
| 187 | + : FieldFinder.findField(bean.getClass(), name); | |
| 188 | + } | |
| 189 | +} | |
Binary file not shown.
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <float> element. | |
| 29 | + * This element specifies {@code float} values. | |
| 30 | + * The class {@link Float} is used as wrapper for these values. | |
| 31 | + * The result value is created from text of the body of this element. | |
| 32 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 33 | + * For example:<pre> | |
| 34 | + * <float>-1.23</float></pre> | |
| 35 | + * is shortcut to<pre> | |
| 36 | + * <method name="valueOf" class="java.lang.Float"> | |
| 37 | + * <string>-1.23</string> | |
| 38 | + * </method></pre> | |
| 39 | + * which is equivalent to {@code Float.valueOf("-1.23")} in Java code. | |
| 40 | + * <p>The following atribute is supported: | |
| 41 | + * <dl> | |
| 42 | + * <dt>id | |
| 43 | + * <dd>the identifier of the variable that is intended to store the result | |
| 44 | + * </dl> | |
| 45 | + * | |
| 46 | + * @since 1.7 | |
| 47 | + * | |
| 48 | + * @author Sergey A. Malenkov | |
| 49 | + */ | |
| 50 | +final class FloatElementHandler extends StringElementHandler { | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Creates {@code float} value from | |
| 54 | + * the text of the body of this element. | |
| 55 | + * | |
| 56 | + * @param argument the text of the body | |
| 57 | + * @return evaluated {@code float} value | |
| 58 | + */ | |
| 59 | + @Override | |
| 60 | + public Object getValue(String argument) { | |
| 61 | + return Float.valueOf(argument); | |
| 62 | + } | |
| 63 | +} | |
Binary file not shown.
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <int> element. | |
| 29 | + * This element specifies {@code int} values. | |
| 30 | + * The class {@link Integer} is used as wrapper for these values. | |
| 31 | + * The result value is created from text of the body of this element. | |
| 32 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 33 | + * For example:<pre> | |
| 34 | + * <int>-1</int></pre> | |
| 35 | + * is shortcut to<pre> | |
| 36 | + * <method name="decode" class="java.lang.Integer"> | |
| 37 | + * <string>-1</string> | |
| 38 | + * </method></pre> | |
| 39 | + * which is equivalent to {@code Integer.decode("-1")} in Java code. | |
| 40 | + * <p>The following atribute is supported: | |
| 41 | + * <dl> | |
| 42 | + * <dt>id | |
| 43 | + * <dd>the identifier of the variable that is intended to store the result | |
| 44 | + * </dl> | |
| 45 | + * | |
| 46 | + * @since 1.7 | |
| 47 | + * | |
| 48 | + * @author Sergey A. Malenkov | |
| 49 | + */ | |
| 50 | +final class IntElementHandler extends StringElementHandler { | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Creates {@code int} value from | |
| 54 | + * the text of the body of this element. | |
| 55 | + * | |
| 56 | + * @param argument the text of the body | |
| 57 | + * @return evaluated {@code int} value | |
| 58 | + */ | |
| 59 | + @Override | |
| 60 | + public Object getValue(String argument) { | |
| 61 | + return Integer.decode(argument); | |
| 62 | + } | |
| 63 | +} | |
Binary file not shown.
| @@ -0,0 +1,151 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +import java.beans.XMLDecoder; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * This class is intended to handle <java> element. | |
| 31 | + * Each element that appears in the body of this element | |
| 32 | + * is evaluated in the context of the decoder itself. | |
| 33 | + * Typically this outer context is used to retrieve the owner of the decoder, | |
| 34 | + * which can be set before reading the archive. | |
| 35 | + * <p>The following atributes are supported: | |
| 36 | + * <dl> | |
| 37 | + * <dt>version | |
| 38 | + * <dd>the Java version (not supported) | |
| 39 | + * <dt>class | |
| 40 | + * <dd>the type of preferable parser (not supported) | |
| 41 | + * <dt>id | |
| 42 | + * <dd>the identifier of the variable that is intended to store the result | |
| 43 | + * </dl> | |
| 44 | + * | |
| 45 | + * @see DocumentHandler#getOwner | |
| 46 | + * @see DocumentHandler#setOwner | |
| 47 | + * @since 1.7 | |
| 48 | + * | |
| 49 | + * @author Sergey A. Malenkov | |
| 50 | + */ | |
| 51 | +final class JavaElementHandler extends ElementHandler { | |
| 52 | + private Class<?> type; | |
| 53 | + private ValueObject value; | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Parses attributes of the element. | |
| 57 | + * The following atributes are supported: | |
| 58 | + * <dl> | |
| 59 | + * <dt>version | |
| 60 | + * <dd>the Java version (not supported) | |
| 61 | + * <dt>class | |
| 62 | + * <dd>the type of preferable parser (not supported) | |
| 63 | + * <dt>id | |
| 64 | + * <dd>the identifier of the variable that is intended to store the result | |
| 65 | + * </dl> | |
| 66 | + * | |
| 67 | + * @param name the attribute name | |
| 68 | + * @param value the attribute value | |
| 69 | + */ | |
| 70 | + @Override | |
| 71 | + public void addAttribute(String name, String value) { | |
| 72 | + if (name.equals("version")) { // NON-NLS: the attribute name | |
| 73 | + // unsupported attribute | |
| 74 | + } else if (name.equals("class")) { // NON-NLS: the attribute name | |
| 75 | + // check class for owner | |
| 76 | + this.type = getOwner().findClass(value); | |
| 77 | + } else { | |
| 78 | + super.addAttribute(name, value); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Adds the argument to the list of readed objects. | |
| 84 | + * | |
| 85 | + * @param argument the value of the element that contained in this one | |
| 86 | + */ | |
| 87 | + @Override | |
| 88 | + protected void addArgument(Object argument) { | |
| 89 | + getOwner().addObject(argument); | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * Tests whether the value of this element can be used | |
| 94 | + * as an argument of the element that contained in this one. | |
| 95 | + * | |
| 96 | + * @return {@code true} if the value of this element should be used | |
| 97 | + * as an argument of the element that contained in this one, | |
| 98 | + * {@code false} otherwise | |
| 99 | + */ | |
| 100 | + @Override | |
| 101 | + protected boolean isArgument() { | |
| 102 | + return false; // do not use owner as object | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Returns the value of this element. | |
| 107 | + * | |
| 108 | + * @return the value of this element | |
| 109 | + */ | |
| 110 | + @Override | |
| 111 | + protected ValueObject getValueObject() { | |
| 112 | + if (this.value == null) { | |
| 113 | + this.value = ValueObjectImpl.create(getValue()); | |
| 114 | + } | |
| 115 | + return this.value; | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Returns the owner of the owner document handler | |
| 120 | + * as a value of <java> element. | |
| 121 | + * | |
| 122 | + * @return the owner of the owner document handler | |
| 123 | + */ | |
| 124 | + private Object getValue() { | |
| 125 | + Object owner = getOwner().getOwner(); | |
| 126 | + if ((this.type == null) || isValid(owner)) { | |
| 127 | + return owner; | |
| 128 | + } | |
| 129 | + if (owner instanceof XMLDecoder) { | |
| 130 | + XMLDecoder decoder = (XMLDecoder) owner; | |
| 131 | + owner = decoder.getOwner(); | |
| 132 | + if (isValid(owner)) { | |
| 133 | + return owner; | |
| 134 | + } | |
| 135 | + } | |
| 136 | + throw new IllegalStateException("Unexpected owner class: " + owner.getClass().getName()); | |
| 137 | + } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Validates the owner of the <java> element. | |
| 141 | + * The owner is valid if it is {@code null} or an instance | |
| 142 | + * of the class specified by the {@code class} attribute. | |
| 143 | + * | |
| 144 | + * @param owner the owner of the <java> element | |
| 145 | + * @return {@code true} if the {@code owner} is valid; | |
| 146 | + * {@code false} otherwise | |
| 147 | + */ | |
| 148 | + private boolean isValid(Object owner) { | |
| 149 | + return (owner == null) || this.type.isInstance(owner); | |
| 150 | + } | |
| 151 | +} | |
Binary file not shown.
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <long> element. | |
| 29 | + * This element specifies {@code long} values. | |
| 30 | + * The class {@link Long} is used as wrapper for these values. | |
| 31 | + * The result value is created from text of the body of this element. | |
| 32 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 33 | + * For example:<pre> | |
| 34 | + * <long>0xFFFF</long></pre> | |
| 35 | + * is shortcut to<pre> | |
| 36 | + * <method name="decode" class="java.lang.Long"> | |
| 37 | + * <string>0xFFFF</string> | |
| 38 | + * </method></pre> | |
| 39 | + * which is equivalent to {@code Long.decode("0xFFFF")} in Java code. | |
| 40 | + * <p>The following atribute is supported: | |
| 41 | + * <dl> | |
| 42 | + * <dt>id | |
| 43 | + * <dd>the identifier of the variable that is intended to store the result | |
| 44 | + * </dl> | |
| 45 | + * | |
| 46 | + * @since 1.7 | |
| 47 | + * | |
| 48 | + * @author Sergey A. Malenkov | |
| 49 | + */ | |
| 50 | +final class LongElementHandler extends StringElementHandler { | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Creates {@code long} value from | |
| 54 | + * the text of the body of this element. | |
| 55 | + * | |
| 56 | + * @param argument the text of the body | |
| 57 | + * @return evaluated {@code long} value | |
| 58 | + */ | |
| 59 | + @Override | |
| 60 | + public Object getValue(String argument) { | |
| 61 | + return Long.decode(argument); | |
| 62 | + } | |
| 63 | +} | |
Binary file not shown.
| @@ -0,0 +1,109 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +import com.sun.beans.finder.MethodFinder; | |
| 28 | + | |
| 29 | +import java.lang.reflect.Method; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * This class is intended to handle <method> element. | |
| 33 | + * It describes invocation of the method. | |
| 34 | + * The {@code name} attribute denotes | |
| 35 | + * the name of the method to invoke. | |
| 36 | + * If the {@code class} attribute is specified | |
| 37 | + * this element invokes static method of specified class. | |
| 38 | + * The inner elements specifies the arguments of the method. | |
| 39 | + * For example:<pre> | |
| 40 | + * <method name="valueOf" class="java.lang.Long"> | |
| 41 | + * <string>10</string> | |
| 42 | + * </method></pre> | |
| 43 | + * is equivalent to {@code Long.valueOf("10")} in Java code. | |
| 44 | + * <p>The following atributes are supported: | |
| 45 | + * <dl> | |
| 46 | + * <dt>name | |
| 47 | + * <dd>the method name | |
| 48 | + * <dt>class | |
| 49 | + * <dd>the type of object for instantiation | |
| 50 | + * <dt>id | |
| 51 | + * <dd>the identifier of the variable that is intended to store the result | |
| 52 | + * </dl> | |
| 53 | + * | |
| 54 | + * @since 1.7 | |
| 55 | + * | |
| 56 | + * @author Sergey A. Malenkov | |
| 57 | + */ | |
| 58 | +final class MethodElementHandler extends NewElementHandler { | |
| 59 | + private String name; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Parses attributes of the element. | |
| 63 | + * The following atributes are supported: | |
| 64 | + * <dl> | |
| 65 | + * <dt>name | |
| 66 | + * <dd>the method name | |
| 67 | + * <dt>class | |
| 68 | + * <dd>the type of object for instantiation | |
| 69 | + * <dt>id | |
| 70 | + * <dd>the identifier of the variable that is intended to store the result | |
| 71 | + * </dl> | |
| 72 | + * | |
| 73 | + * @param name the attribute name | |
| 74 | + * @param value the attribute value | |
| 75 | + */ | |
| 76 | + @Override | |
| 77 | + public void addAttribute(String name, String value) { | |
| 78 | + if (name.equals("name")) { // NON-NLS: the attribute name | |
| 79 | + this.name = value; | |
| 80 | + } else { | |
| 81 | + super.addAttribute(name, value); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Returns the result of method execution. | |
| 87 | + * | |
| 88 | + * @param type the base class | |
| 89 | + * @param args the array of arguments | |
| 90 | + * @return the value of this element | |
| 91 | + * @throws Exception if calculation is failed | |
| 92 | + */ | |
| 93 | + @Override | |
| 94 | + protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception { | |
| 95 | + Object bean = getContextBean(); | |
| 96 | + Class<?>[] types = getArgumentTypes(args); | |
| 97 | + Method method = (type != null) | |
| 98 | + ? MethodFinder.findStaticMethod(type, this.name, types) | |
| 99 | + : MethodFinder.findMethod(bean.getClass(), this.name, types); | |
| 100 | + | |
| 101 | + if (method.isVarArgs()) { | |
| 102 | + args = getArguments(args, method.getParameterTypes()); | |
| 103 | + } | |
| 104 | + Object value = method.invoke(bean, args); | |
| 105 | + return method.getReturnType().equals(void.class) | |
| 106 | + ? ValueObjectImpl.VOID | |
| 107 | + : ValueObjectImpl.create(value); | |
| 108 | + } | |
| 109 | +} | |
Binary file not shown.
| @@ -0,0 +1,205 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +import com.sun.beans.finder.ConstructorFinder; | |
| 28 | + | |
| 29 | +import java.lang.reflect.Array; | |
| 30 | +import java.lang.reflect.Constructor; | |
| 31 | + | |
| 32 | +import java.util.ArrayList; | |
| 33 | +import java.util.List; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * This class is intended to handle <new> element. | |
| 37 | + * It describes instantiation of the object. | |
| 38 | + * The {@code class} attribute denotes | |
| 39 | + * the name of the class to instantiate. | |
| 40 | + * The inner elements specifies the arguments of the constructor. | |
| 41 | + * For example:<pre> | |
| 42 | + * <new class="java.lang.Long"> | |
| 43 | + * <string>10</string> | |
| 44 | + * </new></pre> | |
| 45 | + * is equivalent to {@code new Long("10")} in Java code. | |
| 46 | + * <p>The following atributes are supported: | |
| 47 | + * <dl> | |
| 48 | + * <dt>class | |
| 49 | + * <dd>the type of object for instantiation | |
| 50 | + * <dt>id | |
| 51 | + * <dd>the identifier of the variable that is intended to store the result | |
| 52 | + * </dl> | |
| 53 | + * | |
| 54 | + * @since 1.7 | |
| 55 | + * | |
| 56 | + * @author Sergey A. Malenkov | |
| 57 | + */ | |
| 58 | +class NewElementHandler extends ElementHandler { | |
| 59 | + private List<Object> arguments = new ArrayList<Object>(); | |
| 60 | + private ValueObject value = ValueObjectImpl.VOID; | |
| 61 | + | |
| 62 | + private Class<?> type; | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Parses attributes of the element. | |
| 66 | + * The following atributes are supported: | |
| 67 | + * <dl> | |
| 68 | + * <dt>class | |
| 69 | + * <dd>the type of object for instantiation | |
| 70 | + * <dt>id | |
| 71 | + * <dd>the identifier of the variable that is intended to store the result | |
| 72 | + * </dl> | |
| 73 | + * | |
| 74 | + * @param name the attribute name | |
| 75 | + * @param value the attribute value | |
| 76 | + */ | |
| 77 | + @Override | |
| 78 | + public void addAttribute(String name, String value) { | |
| 79 | + if (name.equals("class")) { // NON-NLS: the attribute name | |
| 80 | + this.type = getOwner().findClass(value); | |
| 81 | + } else { | |
| 82 | + super.addAttribute(name, value); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Adds the argument to the list of arguments | |
| 88 | + * that is used to calculate the value of this element. | |
| 89 | + * | |
| 90 | + * @param argument the value of the element that contained in this one | |
| 91 | + */ | |
| 92 | + @Override | |
| 93 | + protected final void addArgument(Object argument) { | |
| 94 | + if (this.arguments == null) { | |
| 95 | + throw new IllegalStateException("Could not add argument to evaluated element"); | |
| 96 | + } | |
| 97 | + this.arguments.add(argument); | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Returns the context of the method. | |
| 102 | + * The context of the static method is the class object. | |
| 103 | + * The context of the non-static method is the value of the parent element. | |
| 104 | + * | |
| 105 | + * @return the context of the method | |
| 106 | + */ | |
| 107 | + @Override | |
| 108 | + protected final Object getContextBean() { | |
| 109 | + return (this.type != null) | |
| 110 | + ? this.type | |
| 111 | + : super.getContextBean(); | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Returns the value of this element. | |
| 116 | + * | |
| 117 | + * @return the value of this element | |
| 118 | + */ | |
| 119 | + @Override | |
| 120 | + protected final ValueObject getValueObject() { | |
| 121 | + if (this.arguments != null) { | |
| 122 | + try { | |
| 123 | + this.value = getValueObject(this.type, this.arguments.toArray()); | |
| 124 | + } | |
| 125 | + catch (Exception exception) { | |
| 126 | + getOwner().handleException(exception); | |
| 127 | + } | |
| 128 | + finally { | |
| 129 | + this.arguments = null; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + return this.value; | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Calculates the value of this element | |
| 137 | + * using the base class and the array of arguments. | |
| 138 | + * By default, it creates an instance of the base class. | |
| 139 | + * This method should be overridden in those handlers | |
| 140 | + * that extend behavior of this element. | |
| 141 | + * | |
| 142 | + * @param type the base class | |
| 143 | + * @param args the array of arguments | |
| 144 | + * @return the value of this element | |
| 145 | + * @throws Exception if calculation is failed | |
| 146 | + */ | |
| 147 | + ValueObject getValueObject(Class<?> type, Object[] args) throws Exception { | |
| 148 | + if (type == null) { | |
| 149 | + throw new IllegalArgumentException("Class name is not set"); | |
| 150 | + } | |
| 151 | + Class<?>[] types = getArgumentTypes(args); | |
| 152 | + Constructor<?> constructor = ConstructorFinder.findConstructor(type, types); | |
| 153 | + if (constructor.isVarArgs()) { | |
| 154 | + args = getArguments(args, constructor.getParameterTypes()); | |
| 155 | + } | |
| 156 | + return ValueObjectImpl.create(constructor.newInstance(args)); | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * Converts the array of arguments to the array of corresponding classes. | |
| 161 | + * If argument is {@code null} the class is {@code null} too. | |
| 162 | + * | |
| 163 | + * @param arguments the array of arguments | |
| 164 | + * @return the array of corresponding classes | |
| 165 | + */ | |
| 166 | + static Class<?>[] getArgumentTypes(Object[] arguments) { | |
| 167 | + Class<?>[] types = new Class<?>[arguments.length]; | |
| 168 | + for (int i = 0; i < arguments.length; i++) { | |
| 169 | + if (arguments[i] != null) { | |
| 170 | + types[i] = arguments[i].getClass(); | |
| 171 | + } | |
| 172 | + } | |
| 173 | + return types; | |
| 174 | + } | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Resolves variable arguments. | |
| 178 | + * | |
| 179 | + * @param arguments the array of arguments | |
| 180 | + * @param types the array of parameter types | |
| 181 | + * @return the resolved array of arguments | |
| 182 | + */ | |
| 183 | + static Object[] getArguments(Object[] arguments, Class<?>[] types) { | |
| 184 | + int index = types.length - 1; | |
| 185 | + if (types.length == arguments.length) { | |
| 186 | + Object argument = arguments[index]; | |
| 187 | + if (argument == null) { | |
| 188 | + return arguments; | |
| 189 | + } | |
| 190 | + Class<?> type = types[index]; | |
| 191 | + if (type.isAssignableFrom(argument.getClass())) { | |
| 192 | + return arguments; | |
| 193 | + } | |
| 194 | + } | |
| 195 | + int length = arguments.length - index; | |
| 196 | + Class<?> type = types[index].getComponentType(); | |
| 197 | + Object array = Array.newInstance(type, length); | |
| 198 | + System.arraycopy(arguments, index, array, 0, length); | |
| 199 | + | |
| 200 | + Object[] args = new Object[types.length]; | |
| 201 | + System.arraycopy(arguments, 0, args, 0, index); | |
| 202 | + args[index] = array; | |
| 203 | + return args; | |
| 204 | + } | |
| 205 | +} | |
Binary file not shown.
| @@ -0,0 +1,76 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <null> element. | |
| 29 | + * This element specifies {@code null} value. | |
| 30 | + * It should not contain body or inner elements. | |
| 31 | + * For example:<pre> | |
| 32 | + * <null/></pre> | |
| 33 | + * is equivalent to {@code null} in Java code. | |
| 34 | + * <p>The following atribute is supported: | |
| 35 | + * <dl> | |
| 36 | + * <dt>id | |
| 37 | + * <dd>the identifier of the variable that is intended to store the result | |
| 38 | + * </dl> | |
| 39 | + * | |
| 40 | + * @since 1.7 | |
| 41 | + * | |
| 42 | + * @author Sergey A. Malenkov | |
| 43 | + */ | |
| 44 | +class NullElementHandler extends ElementHandler implements ValueObject { | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Returns the value of this element. | |
| 48 | + * | |
| 49 | + * @return the value of this element | |
| 50 | + */ | |
| 51 | + @Override | |
| 52 | + protected final ValueObject getValueObject() { | |
| 53 | + return this; | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Returns {@code null} | |
| 58 | + * as a value of <null> element. | |
| 59 | + * This method should be overridden in those handlers | |
| 60 | + * that extend behavior of this element. | |
| 61 | + * | |
| 62 | + * @return {@code null} by default | |
| 63 | + */ | |
| 64 | + public Object getValue() { | |
| 65 | + return null; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Returns {@code void} state of this value object. | |
| 70 | + * | |
| 71 | + * @return {@code false} always | |
| 72 | + */ | |
| 73 | + public final boolean isVoid() { | |
| 74 | + return false; | |
| 75 | + } | |
| 76 | +} | |
Binary file not shown.
| @@ -0,0 +1,168 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +import java.beans.Expression; | |
| 28 | + | |
| 29 | +import static java.util.Locale.ENGLISH; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * This class is intended to handle <object> element. | |
| 33 | + * This element looks like <void> element, | |
| 34 | + * but its value is always used as an argument for element | |
| 35 | + * that contains this one. | |
| 36 | + * <p>The following atributes are supported: | |
| 37 | + * <dl> | |
| 38 | + * <dt>class | |
| 39 | + * <dd>the type is used for static methods and fields | |
| 40 | + * <dt>method | |
| 41 | + * <dd>the method name | |
| 42 | + * <dt>property | |
| 43 | + * <dd>the property name | |
| 44 | + * <dt>index | |
| 45 | + * <dd>the property index | |
| 46 | + * <dt>field | |
| 47 | + * <dd>the field name | |
| 48 | + * <dt>idref | |
| 49 | + * <dd>the identifier to refer to the variable | |
| 50 | + * <dt>id | |
| 51 | + * <dd>the identifier of the variable that is intended to store the result | |
| 52 | + * </dl> | |
| 53 | + * | |
| 54 | + * @since 1.7 | |
| 55 | + * | |
| 56 | + * @author Sergey A. Malenkov | |
| 57 | + */ | |
| 58 | +class ObjectElementHandler extends NewElementHandler { | |
| 59 | + private String idref; | |
| 60 | + private String field; | |
| 61 | + private Integer index; | |
| 62 | + private String property; | |
| 63 | + private String method; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Parses attributes of the element. | |
| 67 | + * The following atributes are supported: | |
| 68 | + * <dl> | |
| 69 | + * <dt>class | |
| 70 | + * <dd>the type is used for static methods and fields | |
| 71 | + * <dt>method | |
| 72 | + * <dd>the method name | |
| 73 | + * <dt>property | |
| 74 | + * <dd>the property name | |
| 75 | + * <dt>index | |
| 76 | + * <dd>the property index | |
| 77 | + * <dt>field | |
| 78 | + * <dd>the field name | |
| 79 | + * <dt>idref | |
| 80 | + * <dd>the identifier to refer to the variable | |
| 81 | + * <dt>id | |
| 82 | + * <dd>the identifier of the variable that is intended to store the result | |
| 83 | + * </dl> | |
| 84 | + * | |
| 85 | + * @param name the attribute name | |
| 86 | + * @param value the attribute value | |
| 87 | + */ | |
| 88 | + @Override | |
| 89 | + public final void addAttribute(String name, String value) { | |
| 90 | + if (name.equals("idref")) { // NON-NLS: the attribute name | |
| 91 | + this.idref = value; | |
| 92 | + } else if (name.equals("field")) { // NON-NLS: the attribute name | |
| 93 | + this.field = value; | |
| 94 | + } else if (name.equals("index")) { // NON-NLS: the attribute name | |
| 95 | + this.index = Integer.valueOf(value); | |
| 96 | + addArgument(this.index); // hack for compatibility | |
| 97 | + } else if (name.equals("property")) { // NON-NLS: the attribute name | |
| 98 | + this.property = value; | |
| 99 | + } else if (name.equals("method")) { // NON-NLS: the attribute name | |
| 100 | + this.method = value; | |
| 101 | + } else { | |
| 102 | + super.addAttribute(name, value); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * Calculates the value of this element | |
| 108 | + * if the field attribute or the idref attribute is set. | |
| 109 | + */ | |
| 110 | + @Override | |
| 111 | + public final void startElement() { | |
| 112 | + if ((this.field != null) || (this.idref != null)) { | |
| 113 | + getValueObject(); | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + /** | |
| 118 | + * Tests whether the value of this element can be used | |
| 119 | + * as an argument of the element that contained in this one. | |
| 120 | + * | |
| 121 | + * @return {@code true} if the value of this element can be used | |
| 122 | + * as an argument of the element that contained in this one, | |
| 123 | + * {@code false} otherwise | |
| 124 | + */ | |
| 125 | + @Override | |
| 126 | + protected boolean isArgument() { | |
| 127 | + return true; // hack for compatibility | |
| 128 | + } | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * Creates the value of this element. | |
| 132 | + * | |
| 133 | + * @param type the base class | |
| 134 | + * @param args the array of arguments | |
| 135 | + * @return the value of this element | |
| 136 | + * @throws Exception if calculation is failed | |
| 137 | + */ | |
| 138 | + @Override | |
| 139 | + protected final ValueObject getValueObject(Class<?> type, Object[] args) throws Exception { | |
| 140 | + if (this.field != null) { | |
| 141 | + return ValueObjectImpl.create(FieldElementHandler.getFieldValue(getContextBean(), this.field)); | |
| 142 | + } | |
| 143 | + if (this.idref != null) { | |
| 144 | + return ValueObjectImpl.create(getVariable(this.idref)); | |
| 145 | + } | |
| 146 | + Object bean = getContextBean(); | |
| 147 | + String name; | |
| 148 | + if (this.index != null) { | |
| 149 | + name = (args.length == 2) | |
| 150 | + ? PropertyElementHandler.SETTER | |
| 151 | + : PropertyElementHandler.GETTER; | |
| 152 | + } else if (this.property != null) { | |
| 153 | + name = (args.length == 1) | |
| 154 | + ? PropertyElementHandler.SETTER | |
| 155 | + : PropertyElementHandler.GETTER; | |
| 156 | + | |
| 157 | + if (0 < this.property.length()) { | |
| 158 | + name += this.property.substring(0, 1).toUpperCase(ENGLISH) + this.property.substring(1); | |
| 159 | + } | |
| 160 | + } else { | |
| 161 | + name = (this.method != null) && (0 < this.method.length()) | |
| 162 | + ? this.method | |
| 163 | + : "new"; // NON-NLS: the constructor marker | |
| 164 | + } | |
| 165 | + Expression expression = new Expression(bean, name, args); | |
| 166 | + return ValueObjectImpl.create(expression.getValue()); | |
| 167 | + } | |
| 168 | +} | |
Binary file not shown.
| @@ -0,0 +1,287 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +import com.sun.beans.finder.MethodFinder; | |
| 28 | + | |
| 29 | +import java.beans.IndexedPropertyDescriptor; | |
| 30 | +import java.beans.IntrospectionException; | |
| 31 | +import java.beans.Introspector; | |
| 32 | +import java.beans.PropertyDescriptor; | |
| 33 | + | |
| 34 | +import java.lang.reflect.Array; | |
| 35 | +import java.lang.reflect.InvocationTargetException; | |
| 36 | +import java.lang.reflect.Method; | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * This class is intended to handle <property> element. | |
| 40 | + * This element simplifies access to the properties. | |
| 41 | + * If the {@code index} attribute is specified | |
| 42 | + * this element uses additional {@code int} parameter. | |
| 43 | + * If the {@code name} attribute is not specified | |
| 44 | + * this element uses method "get" as getter | |
| 45 | + * and method "set" as setter. | |
| 46 | + * This element defines getter if it contains no argument. | |
| 47 | + * It returns the value of the property in this case. | |
| 48 | + * For example:<pre> | |
| 49 | + * <property name="object" index="10"/></pre> | |
| 50 | + * is shortcut to<pre> | |
| 51 | + * <method name="getObject"> | |
| 52 | + * <int>10</int> | |
| 53 | + * </method></pre> | |
| 54 | + * which is equivalent to {@code getObject(10)} in Java code. | |
| 55 | + * This element defines setter if it contains one argument. | |
| 56 | + * It does not return the value of the property in this case. | |
| 57 | + * For example:<pre> | |
| 58 | + * <property><int>0</int></property></pre> | |
| 59 | + * is shortcut to<pre> | |
| 60 | + * <method name="set"> | |
| 61 | + * <int>0</int> | |
| 62 | + * </method></pre> | |
| 63 | + * which is equivalent to {@code set(0)} in Java code. | |
| 64 | + * <p>The following atributes are supported: | |
| 65 | + * <dl> | |
| 66 | + * <dt>name | |
| 67 | + * <dd>the property name | |
| 68 | + * <dt>index | |
| 69 | + * <dd>the property index | |
| 70 | + * <dt>id | |
| 71 | + * <dd>the identifier of the variable that is intended to store the result | |
| 72 | + * </dl> | |
| 73 | + * | |
| 74 | + * @since 1.7 | |
| 75 | + * | |
| 76 | + * @author Sergey A. Malenkov | |
| 77 | + */ | |
| 78 | +final class PropertyElementHandler extends AccessorElementHandler { | |
| 79 | + static final String GETTER = "get"; // NON-NLS: the getter prefix | |
| 80 | + static final String SETTER = "set"; // NON-NLS: the setter prefix | |
| 81 | + | |
| 82 | + private Integer index; | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Parses attributes of the element. | |
| 86 | + * The following atributes are supported: | |
| 87 | + * <dl> | |
| 88 | + * <dt>name | |
| 89 | + * <dd>the property name | |
| 90 | + * <dt>index | |
| 91 | + * <dd>the property index | |
| 92 | + * <dt>id | |
| 93 | + * <dd>the identifier of the variable that is intended to store the result | |
| 94 | + * </dl> | |
| 95 | + * | |
| 96 | + * @param name the attribute name | |
| 97 | + * @param value the attribute value | |
| 98 | + */ | |
| 99 | + @Override | |
| 100 | + public void addAttribute(String name, String value) { | |
| 101 | + if (name.equals("index")) { // NON-NLS: the attribute name | |
| 102 | + this.index = Integer.valueOf(value); | |
| 103 | + } else { | |
| 104 | + super.addAttribute(name, value); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Tests whether the value of this element can be used | |
| 110 | + * as an argument of the element that contained in this one. | |
| 111 | + * | |
| 112 | + * @return {@code true} if the value of this element should be used | |
| 113 | + * as an argument of the element that contained in this one, | |
| 114 | + * {@code false} otherwise | |
| 115 | + */ | |
| 116 | + @Override | |
| 117 | + protected boolean isArgument() { | |
| 118 | + return false; // non-static accessor cannot be used an argument | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * Returns the value of the property with specified {@code name}. | |
| 123 | + * | |
| 124 | + * @param name the name of the property | |
| 125 | + * @return the value of the specified property | |
| 126 | + */ | |
| 127 | + @Override | |
| 128 | + protected Object getValue(String name) { | |
| 129 | + try { | |
| 130 | + return getPropertyValue(getContextBean(), name, this.index); | |
| 131 | + } | |
| 132 | + catch (Exception exception) { | |
| 133 | + getOwner().handleException(exception); | |
| 134 | + } | |
| 135 | + return null; | |
| 136 | + } | |
| 137 | + | |
| 138 | + /** | |
| 139 | + * Sets the new value for the property with specified {@code name}. | |
| 140 | + * | |
| 141 | + * @param name the name of the property | |
| 142 | + * @param value the new value for the specified property | |
| 143 | + */ | |
| 144 | + @Override | |
| 145 | + protected void setValue(String name, Object value) { | |
| 146 | + try { | |
| 147 | + setPropertyValue(getContextBean(), name, this.index, value); | |
| 148 | + } | |
| 149 | + catch (Exception exception) { | |
| 150 | + getOwner().handleException(exception); | |
| 151 | + } | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Performs the search of the getter for the property | |
| 156 | + * with specified {@code name} in specified class | |
| 157 | + * and returns value of the property. | |
| 158 | + * | |
| 159 | + * @param bean the context bean that contains property | |
| 160 | + * @param name the name of the property | |
| 161 | + * @param index the index of the indexed property | |
| 162 | + * @return the value of the property | |
| 163 | + * @throws IllegalAccessException if the property is not accesible | |
| 164 | + * @throws IntrospectionException if the bean introspection is failed | |
| 165 | + * @throws InvocationTargetException if the getter cannot be invoked | |
| 166 | + * @throws NoSuchMethodException if the getter is not found | |
| 167 | + */ | |
| 168 | + private static Object getPropertyValue(Object bean, String name, Integer index) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException { | |
| 169 | + Class<?> type = bean.getClass(); | |
| 170 | + if (index == null) { | |
| 171 | + return findGetter(type, name).invoke(bean); | |
| 172 | + } else if (type.isArray() && (name == null)) { | |
| 173 | + return Array.get(bean, index); | |
| 174 | + } else { | |
| 175 | + return findGetter(type, name, int.class).invoke(bean, index); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * Performs the search of the setter for the property | |
| 181 | + * with specified {@code name} in specified class | |
| 182 | + * and updates value of the property. | |
| 183 | + * | |
| 184 | + * @param bean the context bean that contains property | |
| 185 | + * @param name the name of the property | |
| 186 | + * @param index the index of the indexed property | |
| 187 | + * @param value the new value for the property | |
| 188 | + * @throws IllegalAccessException if the property is not accesible | |
| 189 | + * @throws IntrospectionException if the bean introspection is failed | |
| 190 | + * @throws InvocationTargetException if the setter cannot be invoked | |
| 191 | + * @throws NoSuchMethodException if the setter is not found | |
| 192 | + */ | |
| 193 | + private static void setPropertyValue(Object bean, String name, Integer index, Object value) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException { | |
| 194 | + Class<?> type = bean.getClass(); | |
| 195 | + Class<?> param = (value != null) | |
| 196 | + ? value.getClass() | |
| 197 | + : null; | |
| 198 | + | |
| 199 | + if (index == null) { | |
| 200 | + findSetter(type, name, param).invoke(bean, value); | |
| 201 | + } else if (type.isArray() && (name == null)) { | |
| 202 | + Array.set(bean, index, value); | |
| 203 | + } else { | |
| 204 | + findSetter(type, name, int.class, param).invoke(bean, index, value); | |
| 205 | + } | |
| 206 | + } | |
| 207 | + | |
| 208 | + /** | |
| 209 | + * Performs the search of the getter for the property | |
| 210 | + * with specified {@code name} in specified class. | |
| 211 | + * | |
| 212 | + * @param type the class that contains method | |
| 213 | + * @param name the name of the property | |
| 214 | + * @param args the method arguments | |
| 215 | + * @return method object that represents found getter | |
| 216 | + * @throws IntrospectionException if the bean introspection is failed | |
| 217 | + * @throws NoSuchMethodException if method is not found | |
| 218 | + */ | |
| 219 | + private static Method findGetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException { | |
| 220 | + if (name == null) { | |
| 221 | + return MethodFinder.findInstanceMethod(type, GETTER, args); | |
| 222 | + } | |
| 223 | + PropertyDescriptor pd = getProperty(type, name); | |
| 224 | + if (args.length == 0) { | |
| 225 | + Method method = pd.getReadMethod(); | |
| 226 | + if (method != null) { | |
| 227 | + return method; | |
| 228 | + } | |
| 229 | + } else if (pd instanceof IndexedPropertyDescriptor) { | |
| 230 | + IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; | |
| 231 | + Method method = ipd.getIndexedReadMethod(); | |
| 232 | + if (method != null) { | |
| 233 | + return method; | |
| 234 | + } | |
| 235 | + } | |
| 236 | + throw new IntrospectionException("Could not find getter for the " + name + " property"); | |
| 237 | + } | |
| 238 | + | |
| 239 | + /** | |
| 240 | + * Performs the search of the setter for the property | |
| 241 | + * with specified {@code name} in specified class. | |
| 242 | + * | |
| 243 | + * @param type the class that contains method | |
| 244 | + * @param name the name of the property | |
| 245 | + * @param args the method arguments | |
| 246 | + * @return method object that represents found setter | |
| 247 | + * @throws IntrospectionException if the bean introspection is failed | |
| 248 | + * @throws NoSuchMethodException if method is not found | |
| 249 | + */ | |
| 250 | + private static Method findSetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException { | |
| 251 | + if (name == null) { | |
| 252 | + return MethodFinder.findInstanceMethod(type, SETTER, args); | |
| 253 | + } | |
| 254 | + PropertyDescriptor pd = getProperty(type, name); | |
| 255 | + if (args.length == 1) { | |
| 256 | + Method method = pd.getWriteMethod(); | |
| 257 | + if (method != null) { | |
| 258 | + return method; | |
| 259 | + } | |
| 260 | + } else if (pd instanceof IndexedPropertyDescriptor) { | |
| 261 | + IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; | |
| 262 | + Method method = ipd.getIndexedWriteMethod(); | |
| 263 | + if (method != null) { | |
| 264 | + return method; | |
| 265 | + } | |
| 266 | + } | |
| 267 | + throw new IntrospectionException("Could not find setter for the " + name + " property"); | |
| 268 | + } | |
| 269 | + | |
| 270 | + /** | |
| 271 | + * Performs the search of the descriptor for the property | |
| 272 | + * with specified {@code name} in specified class. | |
| 273 | + * | |
| 274 | + * @param type the class to introspect | |
| 275 | + * @param name the property name | |
| 276 | + * @return descriptor for the named property | |
| 277 | + * @throws IntrospectionException if property descriptor is not found | |
| 278 | + */ | |
| 279 | + private static PropertyDescriptor getProperty(Class<?> type, String name) throws IntrospectionException { | |
| 280 | + for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) { | |
| 281 | + if (name.equals(pd.getName())) { | |
| 282 | + return pd; | |
| 283 | + } | |
| 284 | + } | |
| 285 | + throw new IntrospectionException("Could not find the " + name + " property descriptor"); | |
| 286 | + } | |
| 287 | +} | |
Binary file not shown.
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <short> element. | |
| 29 | + * This element specifies {@code short} values. | |
| 30 | + * The class {@link Short} is used as wrapper for these values. | |
| 31 | + * The result value is created from text of the body of this element. | |
| 32 | + * The body parsing is described in the class {@link StringElementHandler}. | |
| 33 | + * For example:<pre> | |
| 34 | + * <short>200</short></pre> | |
| 35 | + * is shortcut to<pre> | |
| 36 | + * <method name="decode" class="java.lang.Short"> | |
| 37 | + * <string>200</string> | |
| 38 | + * </method></pre> | |
| 39 | + * which is equivalent to {@code Short.decode("200")} in Java code. | |
| 40 | + * <p>The following atribute is supported: | |
| 41 | + * <dl> | |
| 42 | + * <dt>id | |
| 43 | + * <dd>the identifier of the variable that is intended to store the result | |
| 44 | + * </dl> | |
| 45 | + * | |
| 46 | + * @since 1.7 | |
| 47 | + * | |
| 48 | + * @author Sergey A. Malenkov | |
| 49 | + */ | |
| 50 | +final class ShortElementHandler extends StringElementHandler { | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Creates {@code short} value from | |
| 54 | + * the text of the body of this element. | |
| 55 | + * | |
| 56 | + * @param argument the text of the body | |
| 57 | + * @return evaluated {@code short} value | |
| 58 | + */ | |
| 59 | + @Override | |
| 60 | + public Object getValue(String argument) { | |
| 61 | + return Short.decode(argument); | |
| 62 | + } | |
| 63 | +} | |
Binary file not shown.
| @@ -0,0 +1,116 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <string> element. | |
| 29 | + * This element specifies {@link String} values. | |
| 30 | + * The result value is created from text of the body of this element. | |
| 31 | + * For example:<pre> | |
| 32 | + * <string>description</string></pre> | |
| 33 | + * is equivalent to {@code "description"} in Java code. | |
| 34 | + * The value of inner element is calculated | |
| 35 | + * before adding to the string using {@link String#valueOf(Object)}. | |
| 36 | + * Note that all characters are used including whitespaces (' ', '\t', '\n', '\r'). | |
| 37 | + * So the value of the element<pre> | |
| 38 | + * <string><true></string></pre> | |
| 39 | + * is not equal to the value of the element<pre> | |
| 40 | + * <string> | |
| 41 | + * <true> | |
| 42 | + * </string></pre> | |
| 43 | + * <p>The following atribute is supported: | |
| 44 | + * <dl> | |
| 45 | + * <dt>id | |
| 46 | + * <dd>the identifier of the variable that is intended to store the result | |
| 47 | + * </dl> | |
| 48 | + * | |
| 49 | + * @since 1.7 | |
| 50 | + * | |
| 51 | + * @author Sergey A. Malenkov | |
| 52 | + */ | |
| 53 | +public class StringElementHandler extends ElementHandler { | |
| 54 | + private StringBuilder sb = new StringBuilder(); | |
| 55 | + private ValueObject value = ValueObjectImpl.NULL; | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Adds the character that contained in this element. | |
| 59 | + * | |
| 60 | + * @param ch the character | |
| 61 | + */ | |
| 62 | + @Override | |
| 63 | + public final void addCharacter(char ch) { | |
| 64 | + if (this.sb == null) { | |
| 65 | + throw new IllegalStateException("Could not add chararcter to evaluated string element"); | |
| 66 | + } | |
| 67 | + this.sb.append(ch); | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * Adds the string value of the argument to the string value of this element. | |
| 72 | + * | |
| 73 | + * @param argument the value of the element that contained in this one | |
| 74 | + */ | |
| 75 | + @Override | |
| 76 | + protected final void addArgument(Object argument) { | |
| 77 | + if (this.sb == null) { | |
| 78 | + throw new IllegalStateException("Could not add argument to evaluated string element"); | |
| 79 | + } | |
| 80 | + this.sb.append(argument); | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Returns the value of this element. | |
| 85 | + * | |
| 86 | + * @return the value of this element | |
| 87 | + */ | |
| 88 | + @Override | |
| 89 | + protected final ValueObject getValueObject() { | |
| 90 | + if (this.sb != null) { | |
| 91 | + try { | |
| 92 | + this.value = ValueObjectImpl.create(getValue(this.sb.toString())); | |
| 93 | + } | |
| 94 | + catch (RuntimeException exception) { | |
| 95 | + getOwner().handleException(exception); | |
| 96 | + } | |
| 97 | + finally { | |
| 98 | + this.sb = null; | |
| 99 | + } | |
| 100 | + } | |
| 101 | + return this.value; | |
| 102 | + } | |
| 103 | + | |
| 104 | + /** | |
| 105 | + * Returns the text of the body of this element. | |
| 106 | + * This method evaluates value from text of the body, | |
| 107 | + * and should be overridden in those handlers | |
| 108 | + * that extend behavior of this element. | |
| 109 | + * | |
| 110 | + * @param argument the text of the body | |
| 111 | + * @return evaluated value | |
| 112 | + */ | |
| 113 | + protected Object getValue(String argument) { | |
| 114 | + return argument; | |
| 115 | + } | |
| 116 | +} | |
Binary file not shown.
| @@ -0,0 +1,56 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <true> element. | |
| 29 | + * This element specifies {@code true} value. | |
| 30 | + * It should not contain body or inner elements. | |
| 31 | + * For example:<pre> | |
| 32 | + * <true/></pre> | |
| 33 | + * is equivalent to {@code true} in Java code. | |
| 34 | + * <p>The following atribute is supported: | |
| 35 | + * <dl> | |
| 36 | + * <dt>id | |
| 37 | + * <dd>the identifier of the variable that is intended to store the result | |
| 38 | + * </dl> | |
| 39 | + * | |
| 40 | + * @since 1.7 | |
| 41 | + * | |
| 42 | + * @author Sergey A. Malenkov | |
| 43 | + */ | |
| 44 | +final class TrueElementHandler extends NullElementHandler { | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Returns {@code Boolean.TRUE} | |
| 48 | + * as a value of <true> element. | |
| 49 | + * | |
| 50 | + * @return {@code Boolean.TRUE} by default | |
| 51 | + */ | |
| 52 | + @Override | |
| 53 | + public Object getValue() { | |
| 54 | + return Boolean.TRUE; | |
| 55 | + } | |
| 56 | +} | |
Binary file not shown.
| @@ -0,0 +1,50 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This interface represents the result of method execution. | |
| 29 | + * | |
| 30 | + * @since 1.7 | |
| 31 | + * | |
| 32 | + * @author Sergey A. Malenkov | |
| 33 | + */ | |
| 34 | +public interface ValueObject { | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Returns the result of method execution. | |
| 38 | + * | |
| 39 | + * @return the result of method execution | |
| 40 | + */ | |
| 41 | + Object getValue(); | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Returns {@code void} state of this value object. | |
| 45 | + * | |
| 46 | + * @return {@code true} if value can be ignored, | |
| 47 | + * {@code false} otherwise | |
| 48 | + */ | |
| 49 | + boolean isVoid(); | |
| 50 | +} | |
Binary file not shown.
| @@ -0,0 +1,88 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This utility class provides {@code static} method | |
| 29 | + * to create the object that contains the result of method execution. | |
| 30 | + * | |
| 31 | + * @since 1.7 | |
| 32 | + * | |
| 33 | + * @author Sergey A. Malenkov | |
| 34 | + */ | |
| 35 | +final class ValueObjectImpl implements ValueObject { | |
| 36 | + static final ValueObject NULL = new ValueObjectImpl(null); | |
| 37 | + static final ValueObject VOID = new ValueObjectImpl(); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Returns the object that describes returning value. | |
| 41 | + * | |
| 42 | + * @param value the result of method execution | |
| 43 | + * @return the object that describes value | |
| 44 | + */ | |
| 45 | + static ValueObject create(Object value) { | |
| 46 | + return (value != null) | |
| 47 | + ? new ValueObjectImpl(value) | |
| 48 | + : NULL; | |
| 49 | + } | |
| 50 | + | |
| 51 | + private Object value; | |
| 52 | + private boolean isVoid; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Creates the object that describes returning void value. | |
| 56 | + */ | |
| 57 | + private ValueObjectImpl() { | |
| 58 | + this.isVoid = true; | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Creates the object that describes returning non-void value. | |
| 63 | + * | |
| 64 | + * @param value the result of method execution | |
| 65 | + */ | |
| 66 | + private ValueObjectImpl(Object value) { | |
| 67 | + this.value = value; | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * Returns the result of method execution. | |
| 72 | + * | |
| 73 | + * @return the result of method execution | |
| 74 | + */ | |
| 75 | + public Object getValue() { | |
| 76 | + return this.value; | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Returns {@code void} state of this value object. | |
| 81 | + * | |
| 82 | + * @return {@code true} if value should be ignored, | |
| 83 | + * {@code false} otherwise | |
| 84 | + */ | |
| 85 | + public boolean isVoid() { | |
| 86 | + return this.isVoid; | |
| 87 | + } | |
| 88 | +} | |
Binary file not shown.
| @@ -0,0 +1,82 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <var> element. | |
| 29 | + * This element retrieves the value of specified variable. | |
| 30 | + * For example:<pre> | |
| 31 | + * <var id="id1" idref="id2"/></pre> | |
| 32 | + * is equivalent to {@code id1 = id2} in Java code. | |
| 33 | + * <p>The following atributes are supported: | |
| 34 | + * <dl> | |
| 35 | + * <dt>idref | |
| 36 | + * <dd>the identifier to refer to the variable | |
| 37 | + * <dt>id | |
| 38 | + * <dd>the identifier of the variable that is intended to store the result | |
| 39 | + * </dl> | |
| 40 | + * | |
| 41 | + * @since 1.7 | |
| 42 | + * | |
| 43 | + * @author Sergey A. Malenkov | |
| 44 | + */ | |
| 45 | +final class VarElementHandler extends ElementHandler { | |
| 46 | + private ValueObject value; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Parses attributes of the element. | |
| 50 | + * The following atributes are supported: | |
| 51 | + * <dl> | |
| 52 | + * <dt>idref | |
| 53 | + * <dd>the identifier to refer to the variable | |
| 54 | + * <dt>id | |
| 55 | + * <dd>the identifier of the variable that is intended to store the result | |
| 56 | + * </dl> | |
| 57 | + * | |
| 58 | + * @param name the attribute name | |
| 59 | + * @param value the attribute value | |
| 60 | + */ | |
| 61 | + @Override | |
| 62 | + public void addAttribute(String name, String value) { | |
| 63 | + if (name.equals("idref")) { // NON-NLS: the attribute name | |
| 64 | + this.value = ValueObjectImpl.create(getVariable(value)); | |
| 65 | + } else { | |
| 66 | + super.addAttribute(name, value); | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * Returns the value of this element. | |
| 72 | + * | |
| 73 | + * @return the value of this element | |
| 74 | + */ | |
| 75 | + @Override | |
| 76 | + protected ValueObject getValueObject() { | |
| 77 | + if (this.value == null) { | |
| 78 | + throw new IllegalArgumentException("Variable name is not set"); | |
| 79 | + } | |
| 80 | + return this.value; | |
| 81 | + } | |
| 82 | +} | |
Binary file not shown.
| @@ -0,0 +1,68 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.decoder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is intended to handle <void> element. | |
| 29 | + * This element looks like <object> element, | |
| 30 | + * but its value is not used as an argument for element | |
| 31 | + * that contains this one. | |
| 32 | + * <p>The following atributes are supported: | |
| 33 | + * <dl> | |
| 34 | + * <dt>class | |
| 35 | + * <dd>the type is used for static methods and fields | |
| 36 | + * <dt>method | |
| 37 | + * <dd>the method name | |
| 38 | + * <dt>property | |
| 39 | + * <dd>the property name | |
| 40 | + * <dt>index | |
| 41 | + * <dd>the property index | |
| 42 | + * <dt>field | |
| 43 | + * <dd>the field name | |
| 44 | + * <dt>idref | |
| 45 | + * <dd>the identifier to refer to the variable | |
| 46 | + * <dt>id | |
| 47 | + * <dd>the identifier of the variable that is intended to store the result | |
| 48 | + * </dl> | |
| 49 | + * | |
| 50 | + * @since 1.7 | |
| 51 | + * | |
| 52 | + * @author Sergey A. Malenkov | |
| 53 | + */ | |
| 54 | +final class VoidElementHandler extends ObjectElementHandler { | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Tests whether the value of this element can be used | |
| 58 | + * as an argument of the element that contained in this one. | |
| 59 | + * | |
| 60 | + * @return {@code true} if the value of this element should be used | |
| 61 | + * as an argument of the element that contained in this one, | |
| 62 | + * {@code false} otherwise | |
| 63 | + */ | |
| 64 | + @Override | |
| 65 | + protected boolean isArgument() { | |
| 66 | + return false; // hack for compatibility | |
| 67 | + } | |
| 68 | +} | |
| @@ -0,0 +1,34 @@ | ||
| 1 | +<../../../../../../mkconfig | |
| 2 | + | |
| 3 | +TARG=\ | |
| 4 | + AccessorElementHandler.dis\ | |
| 5 | + ArrayElementHandler.dis\ | |
| 6 | + BooleanElementHandler.dis\ | |
| 7 | + ByteElementHandler.dis\ | |
| 8 | + CharElementHandler.dis\ | |
| 9 | + ClassElementHandler.dis\ | |
| 10 | + DocumentHandler.dis\ | |
| 11 | + DoubleElementHandler.dis\ | |
| 12 | + ElementHandler.dis\ | |
| 13 | + FalseElementHandler.dis\ | |
| 14 | + FieldElementHandler.dis\ | |
| 15 | + FloatElementHandler.dis\ | |
| 16 | + IntElementHandler.dis\ | |
| 17 | + JavaElementHandler.dis\ | |
| 18 | + LongElementHandler.dis\ | |
| 19 | + MethodElementHandler.dis\ | |
| 20 | + NewElementHandler.dis\ | |
| 21 | + NullElementHandler.dis\ | |
| 22 | + ObjectElementHandler.dis\ | |
| 23 | + PropertyElementHandler.dis\ | |
| 24 | + ShortElementHandler.dis\ | |
| 25 | + StringElementHandler.dis\ | |
| 26 | + TrueElementHandler.dis\ | |
| 27 | + ValueObject.dis\ | |
| 28 | + ValueObjectImpl.dis\ | |
| 29 | + VarElementHandler.dis\ | |
| 30 | + VoidElementHandler.dis\ | |
| 31 | + | |
| 32 | +DISBIN=$ROOT/java/dis/java/java/com/sun/beans/decoder | |
| 33 | + | |
| 34 | +<$ROOT/mkfiles/mkjava | |
Binary file not shown.
| @@ -0,0 +1,213 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import java.util.HashMap; | |
| 28 | +import java.util.Map; | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * This abstract class provides functionality | |
| 32 | + * to find a public method or constructor | |
| 33 | + * with specified parameter types. | |
| 34 | + * It supports a variable number of parameters. | |
| 35 | + * | |
| 36 | + * @since 1.7 | |
| 37 | + * | |
| 38 | + * @author Sergey A. Malenkov | |
| 39 | + */ | |
| 40 | +abstract class AbstractFinder<T> { | |
| 41 | + private final Class<?>[] args; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Creates finder for array of classes of arguments. | |
| 45 | + * If a particular element of array equals {@code null}, | |
| 46 | + * than the appropriate pair of classes | |
| 47 | + * does not take into consideration. | |
| 48 | + * | |
| 49 | + * @param args array of classes of arguments | |
| 50 | + */ | |
| 51 | + protected AbstractFinder(Class<?>[] args) { | |
| 52 | + this.args = args; | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Returns an array of {@code Class} objects | |
| 57 | + * that represent the formal parameter types of the method | |
| 58 | + * Returns an empty array if the method takes no parameters. | |
| 59 | + * | |
| 60 | + * @param method the object that represents method | |
| 61 | + * @return the parameter types of the method | |
| 62 | + */ | |
| 63 | + protected abstract Class<?>[] getParameters(T method); | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Returns {@code true} if and only if the method | |
| 67 | + * was declared to take a variable number of arguments. | |
| 68 | + * | |
| 69 | + * @param method the object that represents method | |
| 70 | + * @return {@code true} if the method was declared | |
| 71 | + * to take a variable number of arguments; | |
| 72 | + * {@code false} otherwise | |
| 73 | + */ | |
| 74 | + protected abstract boolean isVarArgs(T method); | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * Checks validness of the method. | |
| 78 | + * At least the valid method should be public. | |
| 79 | + * | |
| 80 | + * @param method the object that represents method | |
| 81 | + * @return {@code true} if the method is valid, | |
| 82 | + * {@code false} otherwise | |
| 83 | + */ | |
| 84 | + protected abstract boolean isValid(T method); | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Performs a search in the {@code methods} array. | |
| 88 | + * The one method is selected from the array of the valid methods. | |
| 89 | + * The list of parameters of the selected method shows | |
| 90 | + * the best correlation with the list of arguments | |
| 91 | + * specified at class initialization. | |
| 92 | + * If more than one method is both accessible and applicable | |
| 93 | + * to a method invocation, it is necessary to choose one | |
| 94 | + * to provide the descriptor for the run-time method dispatch. | |
| 95 | + * The most specific method should be chosen. | |
| 96 | + * | |
| 97 | + * @param methods the array of methods to search within | |
| 98 | + * @return the object that represents found method | |
| 99 | + * @throws NoSuchMethodException if no method was found or several | |
| 100 | + * methods meet the search criteria | |
| 101 | + * @see #isAssignable | |
| 102 | + */ | |
| 103 | + final T find(T[] methods) throws NoSuchMethodException { | |
| 104 | + Map<T, Class<?>[]> map = new HashMap<T, Class<?>[]>(); | |
| 105 | + | |
| 106 | + T oldMethod = null; | |
| 107 | + Class<?>[] oldParams = null; | |
| 108 | + boolean ambiguous = false; | |
| 109 | + | |
| 110 | + for (T newMethod : methods) { | |
| 111 | + if (isValid(newMethod)) { | |
| 112 | + Class<?>[] newParams = getParameters(newMethod); | |
| 113 | + if (newParams.length == this.args.length) { | |
| 114 | + PrimitiveWrapperMap.replacePrimitivesWithWrappers(newParams); | |
| 115 | + if (isAssignable(newParams, this.args)) { | |
| 116 | + if (oldMethod == null) { | |
| 117 | + oldMethod = newMethod; | |
| 118 | + oldParams = newParams; | |
| 119 | + } else { | |
| 120 | + boolean useNew = isAssignable(oldParams, newParams); | |
| 121 | + boolean useOld = isAssignable(newParams, oldParams); | |
| 122 | + | |
| 123 | + if (useOld == useNew) { | |
| 124 | + ambiguous = true; | |
| 125 | + } else if (useNew) { | |
| 126 | + oldMethod = newMethod; | |
| 127 | + oldParams = newParams; | |
| 128 | + ambiguous = false; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + } | |
| 132 | + } | |
| 133 | + if (isVarArgs(newMethod)) { | |
| 134 | + int length = newParams.length - 1; | |
| 135 | + if (length <= this.args.length) { | |
| 136 | + Class<?>[] array = new Class<?>[this.args.length]; | |
| 137 | + System.arraycopy(newParams, 0, array, 0, length); | |
| 138 | + if (length < this.args.length) { | |
| 139 | + Class<?> type = newParams[length].getComponentType(); | |
| 140 | + if (type.isPrimitive()) { | |
| 141 | + type = PrimitiveWrapperMap.getType(type.getName()); | |
| 142 | + } | |
| 143 | + for (int i = length; i < this.args.length; i++) { | |
| 144 | + array[i] = type; | |
| 145 | + } | |
| 146 | + } | |
| 147 | + map.put(newMethod, array); | |
| 148 | + } | |
| 149 | + } | |
| 150 | + } | |
| 151 | + } | |
| 152 | + for (T newMethod : methods) { | |
| 153 | + Class<?>[] newParams = map.get(newMethod); | |
| 154 | + if (newParams != null) { | |
| 155 | + if (isAssignable(newParams, this.args)) { | |
| 156 | + if (oldMethod == null) { | |
| 157 | + oldMethod = newMethod; | |
| 158 | + oldParams = newParams; | |
| 159 | + } else { | |
| 160 | + boolean useNew = isAssignable(oldParams, newParams); | |
| 161 | + boolean useOld = isAssignable(newParams, oldParams); | |
| 162 | + | |
| 163 | + if (useOld == useNew) { | |
| 164 | + if (oldParams == map.get(oldMethod)) { | |
| 165 | + ambiguous = true; | |
| 166 | + } | |
| 167 | + } else if (useNew) { | |
| 168 | + oldMethod = newMethod; | |
| 169 | + oldParams = newParams; | |
| 170 | + ambiguous = false; | |
| 171 | + } | |
| 172 | + } | |
| 173 | + } | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + if (ambiguous) { | |
| 178 | + throw new NoSuchMethodException("Ambiguous methods are found"); | |
| 179 | + } | |
| 180 | + if (oldMethod == null) { | |
| 181 | + throw new NoSuchMethodException("Method is not found"); | |
| 182 | + } | |
| 183 | + return oldMethod; | |
| 184 | + } | |
| 185 | + | |
| 186 | + /** | |
| 187 | + * Determines if every class in {@code min} array is either the same as, | |
| 188 | + * or is a superclass of, the corresponding class in {@code max} array. | |
| 189 | + * The length of every array must equal the number of arguments. | |
| 190 | + * This comparison is performed in the {@link #find} method | |
| 191 | + * before the first call of the isAssignable method. | |
| 192 | + * If an argument equals {@code null} | |
| 193 | + * the appropriate pair of classes does not take into consideration. | |
| 194 | + * | |
| 195 | + * @param min the array of classes to be checked | |
| 196 | + * @param max the array of classes that is used to check | |
| 197 | + * @return {@code true} if all classes in {@code min} array | |
| 198 | + * are assignable from corresponding classes in {@code max} array, | |
| 199 | + * {@code false} otherwise | |
| 200 | + * | |
| 201 | + * @see Class#isAssignableFrom | |
| 202 | + */ | |
| 203 | + private boolean isAssignable(Class<?>[] min, Class<?>[] max) { | |
| 204 | + for (int i = 0; i < this.args.length; i++) { | |
| 205 | + if (null != this.args[i]) { | |
| 206 | + if (!min[i].isAssignableFrom(max[i])) { | |
| 207 | + return false; | |
| 208 | + } | |
| 209 | + } | |
| 210 | + } | |
| 211 | + return true; | |
| 212 | + } | |
| 213 | +} | |
Binary file not shown.
| @@ -0,0 +1,98 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import java.beans.BeanDescriptor; | |
| 28 | +import java.beans.BeanInfo; | |
| 29 | +import java.beans.MethodDescriptor; | |
| 30 | +import java.beans.PropertyDescriptor; | |
| 31 | +import java.lang.reflect.Method; | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * This is utility class that provides functionality | |
| 35 | + * to find a {@link BeanInfo} for a JavaBean specified by its type. | |
| 36 | + * | |
| 37 | + * @since 1.7 | |
| 38 | + * | |
| 39 | + * @author Sergey A. Malenkov | |
| 40 | + */ | |
| 41 | +public final class BeanInfoFinder | |
| 42 | + extends InstanceFinder<BeanInfo> { | |
| 43 | + | |
| 44 | + private static final String DEFAULT = "sun.beans.infos"; | |
| 45 | + | |
| 46 | + public BeanInfoFinder() { | |
| 47 | + super(BeanInfo.class, true, "BeanInfo", DEFAULT); | |
| 48 | + } | |
| 49 | + | |
| 50 | + private static boolean isValid(Class<?> type, Method method) { | |
| 51 | + return (method != null) && method.getDeclaringClass().isAssignableFrom(type); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + protected BeanInfo instantiate(Class<?> type, String prefix, String name) { | |
| 56 | + // this optimization will only use the BeanInfo search path | |
| 57 | + // if is has changed from the original | |
| 58 | + // or trying to get the ComponentBeanInfo | |
| 59 | + BeanInfo info = !DEFAULT.equals(prefix) || "ComponentBeanInfo".equals(name) | |
| 60 | + ? super.instantiate(type, prefix, name) | |
| 61 | + : null; | |
| 62 | + | |
| 63 | + if (info != null) { | |
| 64 | + // make sure that the returned BeanInfo matches the class | |
| 65 | + BeanDescriptor bd = info.getBeanDescriptor(); | |
| 66 | + if (bd != null) { | |
| 67 | + if (type.equals(bd.getBeanClass())) { | |
| 68 | + return info; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + else { | |
| 72 | + PropertyDescriptor[] pds = info.getPropertyDescriptors(); | |
| 73 | + if (pds != null) { | |
| 74 | + for (PropertyDescriptor pd : pds) { | |
| 75 | + Method method = pd.getReadMethod(); | |
| 76 | + if (method == null) { | |
| 77 | + method = pd.getWriteMethod(); | |
| 78 | + } | |
| 79 | + if (isValid(type, method)) { | |
| 80 | + return info; | |
| 81 | + } | |
| 82 | + } | |
| 83 | + } | |
| 84 | + else { | |
| 85 | + MethodDescriptor[] mds = info.getMethodDescriptors(); | |
| 86 | + if (mds != null) { | |
| 87 | + for (MethodDescriptor md : mds) { | |
| 88 | + if (isValid(type, md.getMethod())) { | |
| 89 | + return info; | |
| 90 | + } | |
| 91 | + } | |
| 92 | + } | |
| 93 | + } | |
| 94 | + } | |
| 95 | + } | |
| 96 | + return null; | |
| 97 | + } | |
| 98 | +} | |
Binary file not shown.
| @@ -0,0 +1,176 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This is utility class that provides {@code static} methods | |
| 29 | + * to find a class with the specified name using the specified class loader. | |
| 30 | + * | |
| 31 | + * @since 1.7 | |
| 32 | + * | |
| 33 | + * @author Sergey A. Malenkov | |
| 34 | + */ | |
| 35 | +public final class ClassFinder { | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Returns the {@code Class} object associated | |
| 39 | + * with the class or interface with the given string name, | |
| 40 | + * using the default class loader. | |
| 41 | + * <p> | |
| 42 | + * The {@code name} can denote an array class | |
| 43 | + * (see {@link Class#getName} for details). | |
| 44 | + * | |
| 45 | + * @param name fully qualified name of the desired class | |
| 46 | + * @return class object representing the desired class | |
| 47 | + * | |
| 48 | + * @throws ClassNotFoundException if the class cannot be located | |
| 49 | + * by the specified class loader | |
| 50 | + * | |
| 51 | + * @see Class#forName(String) | |
| 52 | + * @see Class#forName(String,boolean,ClassLoader) | |
| 53 | + * @see ClassLoader#getSystemClassLoader() | |
| 54 | + * @see Thread#getContextClassLoader() | |
| 55 | + */ | |
| 56 | + public static Class<?> findClass(String name) throws ClassNotFoundException { | |
| 57 | + try { | |
| 58 | + ClassLoader loader = Thread.currentThread().getContextClassLoader(); | |
| 59 | + if (loader == null) { | |
| 60 | + // can be null in IE (see 6204697) | |
| 61 | + loader = ClassLoader.getSystemClassLoader(); | |
| 62 | + } | |
| 63 | + if (loader != null) { | |
| 64 | + return Class.forName(name, false, loader); | |
| 65 | + } | |
| 66 | + | |
| 67 | + } catch (ClassNotFoundException exception) { | |
| 68 | + // use current class loader instead | |
| 69 | + } catch (SecurityException exception) { | |
| 70 | + // use current class loader instead | |
| 71 | + } | |
| 72 | + return Class.forName(name); | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Returns the {@code Class} object associated with | |
| 77 | + * the class or interface with the given string name, | |
| 78 | + * using the given class loader. | |
| 79 | + * <p> | |
| 80 | + * The {@code name} can denote an array class | |
| 81 | + * (see {@link Class#getName} for details). | |
| 82 | + * <p> | |
| 83 | + * If the parameter {@code loader} is null, | |
| 84 | + * the class is loaded through the default class loader. | |
| 85 | + * | |
| 86 | + * @param name fully qualified name of the desired class | |
| 87 | + * @param loader class loader from which the class must be loaded | |
| 88 | + * @return class object representing the desired class | |
| 89 | + * | |
| 90 | + * @throws ClassNotFoundException if the class cannot be located | |
| 91 | + * by the specified class loader | |
| 92 | + * | |
| 93 | + * @see #findClass(String,ClassLoader) | |
| 94 | + * @see Class#forName(String,boolean,ClassLoader) | |
| 95 | + */ | |
| 96 | + public static Class<?> findClass(String name, ClassLoader loader) throws ClassNotFoundException { | |
| 97 | + if (loader != null) { | |
| 98 | + try { | |
| 99 | + return Class.forName(name, false, loader); | |
| 100 | + } catch (ClassNotFoundException exception) { | |
| 101 | + // use default class loader instead | |
| 102 | + } catch (SecurityException exception) { | |
| 103 | + // use default class loader instead | |
| 104 | + } | |
| 105 | + } | |
| 106 | + return findClass(name); | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Returns the {@code Class} object associated | |
| 111 | + * with the class or interface with the given string name, | |
| 112 | + * using the default class loader. | |
| 113 | + * <p> | |
| 114 | + * The {@code name} can denote an array class | |
| 115 | + * (see {@link Class#getName} for details). | |
| 116 | + * <p> | |
| 117 | + * This method can be used to obtain | |
| 118 | + * any of the {@code Class} objects | |
| 119 | + * representing {@code void} or primitive Java types: | |
| 120 | + * {@code char}, {@code byte}, {@code short}, | |
| 121 | + * {@code int}, {@code long}, {@code float}, | |
| 122 | + * {@code double} and {@code boolean}. | |
| 123 | + * | |
| 124 | + * @param name fully qualified name of the desired class | |
| 125 | + * @return class object representing the desired class | |
| 126 | + * | |
| 127 | + * @throws ClassNotFoundException if the class cannot be located | |
| 128 | + * by the specified class loader | |
| 129 | + * | |
| 130 | + * @see #resolveClass(String,ClassLoader) | |
| 131 | + */ | |
| 132 | + public static Class<?> resolveClass(String name) throws ClassNotFoundException { | |
| 133 | + return resolveClass(name, null); | |
| 134 | + } | |
| 135 | + | |
| 136 | + /** | |
| 137 | + * Returns the {@code Class} object associated with | |
| 138 | + * the class or interface with the given string name, | |
| 139 | + * using the given class loader. | |
| 140 | + * <p> | |
| 141 | + * The {@code name} can denote an array class | |
| 142 | + * (see {@link Class#getName} for details). | |
| 143 | + * <p> | |
| 144 | + * If the parameter {@code loader} is null, | |
| 145 | + * the class is loaded through the default class loader. | |
| 146 | + * <p> | |
| 147 | + * This method can be used to obtain | |
| 148 | + * any of the {@code Class} objects | |
| 149 | + * representing {@code void} or primitive Java types: | |
| 150 | + * {@code char}, {@code byte}, {@code short}, | |
| 151 | + * {@code int}, {@code long}, {@code float}, | |
| 152 | + * {@code double} and {@code boolean}. | |
| 153 | + * | |
| 154 | + * @param name fully qualified name of the desired class | |
| 155 | + * @param loader class loader from which the class must be loaded | |
| 156 | + * @return class object representing the desired class | |
| 157 | + * | |
| 158 | + * @throws ClassNotFoundException if the class cannot be located | |
| 159 | + * by the specified class loader | |
| 160 | + * | |
| 161 | + * @see #findClass(String,ClassLoader) | |
| 162 | + * @see PrimitiveTypeMap#getType(String) | |
| 163 | + */ | |
| 164 | + public static Class<?> resolveClass(String name, ClassLoader loader) throws ClassNotFoundException { | |
| 165 | + Class<?> type = PrimitiveTypeMap.getType(name); | |
| 166 | + return (type == null) | |
| 167 | + ? findClass(name, loader) | |
| 168 | + : type; | |
| 169 | + } | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * Disable instantiation. | |
| 173 | + */ | |
| 174 | + private ClassFinder() { | |
| 175 | + } | |
| 176 | +} | |
Binary file not shown.
| @@ -0,0 +1,127 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import com.sun.beans.WeakCache; | |
| 28 | + | |
| 29 | +import java.lang.reflect.Constructor; | |
| 30 | +import java.lang.reflect.Modifier; | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * This utility class provides {@code static} methods | |
| 34 | + * to find a public constructor with specified parameter types | |
| 35 | + * in specified class. | |
| 36 | + * | |
| 37 | + * @since 1.7 | |
| 38 | + * | |
| 39 | + * @author Sergey A. Malenkov | |
| 40 | + */ | |
| 41 | +public final class ConstructorFinder extends AbstractFinder<Constructor<?>> { | |
| 42 | + private static final WeakCache<Signature, Constructor<?>> CACHE = new WeakCache<Signature, Constructor<?>>(); | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Finds public constructor | |
| 46 | + * that is declared in public class. | |
| 47 | + * | |
| 48 | + * @param type the class that can have constructor | |
| 49 | + * @param args parameter types that is used to find constructor | |
| 50 | + * @return object that represents found constructor | |
| 51 | + * @throws NoSuchMethodException if constructor could not be found | |
| 52 | + * or some constructors are found | |
| 53 | + */ | |
| 54 | + public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) throws NoSuchMethodException { | |
| 55 | + if (type.isPrimitive()) { | |
| 56 | + throw new NoSuchMethodException("Primitive wrapper does not contain constructors"); | |
| 57 | + } | |
| 58 | + if (type.isInterface()) { | |
| 59 | + throw new NoSuchMethodException("Interface does not contain constructors"); | |
| 60 | + } | |
| 61 | + if (Modifier.isAbstract(type.getModifiers())) { | |
| 62 | + throw new NoSuchMethodException("Abstract class cannot be instantiated"); | |
| 63 | + } | |
| 64 | + if (!Modifier.isPublic(type.getModifiers())) { | |
| 65 | + throw new NoSuchMethodException("Class is not accessible"); | |
| 66 | + } | |
| 67 | + PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); | |
| 68 | + Signature signature = new Signature(type, args); | |
| 69 | + | |
| 70 | + Constructor<?> constructor = CACHE.get(signature); | |
| 71 | + if (constructor != null) { | |
| 72 | + return constructor; | |
| 73 | + } | |
| 74 | + constructor = new ConstructorFinder(args).find(type.getConstructors()); | |
| 75 | + CACHE.put(signature, constructor); | |
| 76 | + return constructor; | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Creates constructor finder with specified array of parameter types. | |
| 81 | + * | |
| 82 | + * @param args the array of parameter types | |
| 83 | + */ | |
| 84 | + private ConstructorFinder(Class<?>[] args) { | |
| 85 | + super(args); | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Returns an array of {@code Class} objects | |
| 90 | + * that represent the formal parameter types of the constructor | |
| 91 | + * Returns an empty array if the constructor takes no parameters. | |
| 92 | + * | |
| 93 | + * @param constructor the object that represents constructor | |
| 94 | + * @return the parameter types of the constructor | |
| 95 | + */ | |
| 96 | + @Override | |
| 97 | + protected Class<?>[] getParameters(Constructor<?> constructor) { | |
| 98 | + return constructor.getParameterTypes(); | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Returns {@code true} if and only if the constructor | |
| 103 | + * was declared to take a variable number of arguments. | |
| 104 | + * | |
| 105 | + * @param constructor the object that represents constructor | |
| 106 | + * @return {@code true} if the constructor was declared | |
| 107 | + * to take a variable number of arguments; | |
| 108 | + * {@code false} otherwise | |
| 109 | + */ | |
| 110 | + @Override | |
| 111 | + protected boolean isVarArgs(Constructor<?> constructor) { | |
| 112 | + return constructor.isVarArgs(); | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * Checks validness of the constructor. | |
| 117 | + * The valid constructor should be public. | |
| 118 | + * | |
| 119 | + * @param constructor the object that represents constructor | |
| 120 | + * @return {@code true} if the constructor is valid, | |
| 121 | + * {@code false} otherwise | |
| 122 | + */ | |
| 123 | + @Override | |
| 124 | + protected boolean isValid(Constructor<?> constructor) { | |
| 125 | + return Modifier.isPublic(constructor.getModifiers()); | |
| 126 | + } | |
| 127 | +} | |
Binary file not shown.
| @@ -0,0 +1,106 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import java.lang.reflect.Field; | |
| 28 | +import java.lang.reflect.Modifier; | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * This utility class provides {@code static} methods | |
| 32 | + * to find a public field with specified name | |
| 33 | + * in specified class. | |
| 34 | + * | |
| 35 | + * @since 1.7 | |
| 36 | + * | |
| 37 | + * @author Sergey A. Malenkov | |
| 38 | + */ | |
| 39 | +public final class FieldFinder { | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * Finds public field (static or non-static) | |
| 43 | + * that is declared in public class. | |
| 44 | + * | |
| 45 | + * @param type the class that can have field | |
| 46 | + * @param name the name of field to find | |
| 47 | + * @return object that represents found field | |
| 48 | + * @throws NoSuchFieldException if field is not found | |
| 49 | + * @see Class#getField | |
| 50 | + */ | |
| 51 | + public static Field findField(Class<?> type, String name) throws NoSuchFieldException { | |
| 52 | + if (name == null) { | |
| 53 | + throw new IllegalArgumentException("Field name is not set"); | |
| 54 | + } | |
| 55 | + Field field = type.getField(name); | |
| 56 | + if (!Modifier.isPublic(field.getModifiers())) { | |
| 57 | + throw new NoSuchFieldException("Field '" + name + "' is not public"); | |
| 58 | + } | |
| 59 | + if (!Modifier.isPublic(field.getDeclaringClass().getModifiers())) { | |
| 60 | + throw new NoSuchFieldException("Field '" + name + "' is not accessible"); | |
| 61 | + } | |
| 62 | + return field; | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Finds public non-static field | |
| 67 | + * that is declared in public class. | |
| 68 | + * | |
| 69 | + * @param type the class that can have field | |
| 70 | + * @param name the name of field to find | |
| 71 | + * @return object that represents found field | |
| 72 | + * @throws NoSuchFieldException if field is not found | |
| 73 | + * @see Class#getField | |
| 74 | + */ | |
| 75 | + public static Field findInstanceField(Class<?> type, String name) throws NoSuchFieldException { | |
| 76 | + Field field = findField(type, name); | |
| 77 | + if (Modifier.isStatic(field.getModifiers())) { | |
| 78 | + throw new NoSuchFieldException("Field '" + name + "' is static"); | |
| 79 | + } | |
| 80 | + return field; | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Finds public static field | |
| 85 | + * that is declared in public class. | |
| 86 | + * | |
| 87 | + * @param type the class that can have field | |
| 88 | + * @param name the name of field to find | |
| 89 | + * @return object that represents found field | |
| 90 | + * @throws NoSuchFieldException if field is not found | |
| 91 | + * @see Class#getField | |
| 92 | + */ | |
| 93 | + public static Field findStaticField(Class<?> type, String name) throws NoSuchFieldException { | |
| 94 | + Field field = findField(type, name); | |
| 95 | + if (!Modifier.isStatic(field.getModifiers())) { | |
| 96 | + throw new NoSuchFieldException("Field '" + name + "' is not static"); | |
| 97 | + } | |
| 98 | + return field; | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Disable instantiation. | |
| 103 | + */ | |
| 104 | + private FieldFinder() { | |
| 105 | + } | |
| 106 | +} | |
Binary file not shown.
| @@ -0,0 +1,109 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This is utility class that provides basic functionality | |
| 29 | + * to find an auxiliary class for a JavaBean specified by its type. | |
| 30 | + * | |
| 31 | + * @since 1.7 | |
| 32 | + * | |
| 33 | + * @author Sergey A. Malenkov | |
| 34 | + */ | |
| 35 | +class InstanceFinder<T> { | |
| 36 | + | |
| 37 | + private static final String[] EMPTY = { }; | |
| 38 | + | |
| 39 | + private final Class<? extends T> type; | |
| 40 | + private final boolean allow; | |
| 41 | + private final String suffix; | |
| 42 | + private volatile String[] packages; | |
| 43 | + | |
| 44 | + InstanceFinder(Class<? extends T> type, boolean allow, String suffix, String... packages) { | |
| 45 | + this.type = type; | |
| 46 | + this.allow = allow; | |
| 47 | + this.suffix = suffix; | |
| 48 | + this.packages = packages.clone(); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public String[] getPackages() { | |
| 52 | + return this.packages.clone(); | |
| 53 | + } | |
| 54 | + | |
| 55 | + public void setPackages(String... packages) { | |
| 56 | + this.packages = (packages != null) && (packages.length > 0) | |
| 57 | + ? packages.clone() | |
| 58 | + : EMPTY; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public T find(Class<?> type) { | |
| 62 | + if (type == null) { | |
| 63 | + return null; | |
| 64 | + } | |
| 65 | + String name = type.getName() + this.suffix; | |
| 66 | + T object = instantiate(type, name); | |
| 67 | + if (object != null) { | |
| 68 | + return object; | |
| 69 | + } | |
| 70 | + if (this.allow) { | |
| 71 | + object = instantiate(type, null); | |
| 72 | + if (object != null) { | |
| 73 | + return object; | |
| 74 | + } | |
| 75 | + } | |
| 76 | + int index = name.lastIndexOf('.') + 1; | |
| 77 | + if (index > 0) { | |
| 78 | + name = name.substring(index); | |
| 79 | + } | |
| 80 | + for (String prefix : this.packages) { | |
| 81 | + object = instantiate(type, prefix, name); | |
| 82 | + if (object != null) { | |
| 83 | + return object; | |
| 84 | + } | |
| 85 | + } | |
| 86 | + return null; | |
| 87 | + } | |
| 88 | + | |
| 89 | + protected T instantiate(Class<?> type, String name) { | |
| 90 | + if (type != null) { | |
| 91 | + try { | |
| 92 | + if (name != null) { | |
| 93 | + type = ClassFinder.findClass(name, type.getClassLoader()); | |
| 94 | + } | |
| 95 | + if (this.type.isAssignableFrom(type)) { | |
| 96 | + return (T) type.newInstance(); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + catch (Exception exception) { | |
| 100 | + // ignore any exceptions | |
| 101 | + } | |
| 102 | + } | |
| 103 | + return null; | |
| 104 | + } | |
| 105 | + | |
| 106 | + protected T instantiate(Class<?> type, String prefix, String name) { | |
| 107 | + return instantiate(type, prefix + '.' + name); | |
| 108 | + } | |
| 109 | +} | |
Binary file not shown.
| @@ -0,0 +1,231 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import com.sun.beans.TypeResolver; | |
| 28 | +import com.sun.beans.WeakCache; | |
| 29 | + | |
| 30 | +import java.lang.reflect.Method; | |
| 31 | +import java.lang.reflect.Modifier; | |
| 32 | +import java.lang.reflect.ParameterizedType; | |
| 33 | +import java.lang.reflect.Type; | |
| 34 | +import java.util.Arrays; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * This utility class provides {@code static} methods | |
| 38 | + * to find a public method with specified name and parameter types | |
| 39 | + * in specified class. | |
| 40 | + * | |
| 41 | + * @since 1.7 | |
| 42 | + * | |
| 43 | + * @author Sergey A. Malenkov | |
| 44 | + */ | |
| 45 | +public final class MethodFinder extends AbstractFinder<Method> { | |
| 46 | + private static final WeakCache<Signature, Method> CACHE = new WeakCache<Signature, Method>(); | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Finds public method (static or non-static) | |
| 50 | + * that is accessible from public class. | |
| 51 | + * | |
| 52 | + * @param type the class that can have method | |
| 53 | + * @param name the name of method to find | |
| 54 | + * @param args parameter types that is used to find method | |
| 55 | + * @return object that represents found method | |
| 56 | + * @throws NoSuchMethodException if method could not be found | |
| 57 | + * or some methods are found | |
| 58 | + */ | |
| 59 | + public static Method findMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException { | |
| 60 | + if (name == null) { | |
| 61 | + throw new IllegalArgumentException("Method name is not set"); | |
| 62 | + } | |
| 63 | + PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); | |
| 64 | + Signature signature = new Signature(type, name, args); | |
| 65 | + | |
| 66 | + Method method = CACHE.get(signature); | |
| 67 | + if (method != null) { | |
| 68 | + return method; | |
| 69 | + } | |
| 70 | + method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods())); | |
| 71 | + CACHE.put(signature, method); | |
| 72 | + return method; | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Finds public non-static method | |
| 77 | + * that is accessible from public class. | |
| 78 | + * | |
| 79 | + * @param type the class that can have method | |
| 80 | + * @param name the name of method to find | |
| 81 | + * @param args parameter types that is used to find method | |
| 82 | + * @return object that represents found method | |
| 83 | + * @throws NoSuchMethodException if method could not be found | |
| 84 | + * or some methods are found | |
| 85 | + */ | |
| 86 | + public static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) throws NoSuchMethodException { | |
| 87 | + Method method = findMethod(type, name, args); | |
| 88 | + if (Modifier.isStatic(method.getModifiers())) { | |
| 89 | + throw new NoSuchMethodException("Method '" + name + "' is static"); | |
| 90 | + } | |
| 91 | + return method; | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Finds public static method | |
| 96 | + * that is accessible from public class. | |
| 97 | + * | |
| 98 | + * @param type the class that can have method | |
| 99 | + * @param name the name of method to find | |
| 100 | + * @param args parameter types that is used to find method | |
| 101 | + * @return object that represents found method | |
| 102 | + * @throws NoSuchMethodException if method could not be found | |
| 103 | + * or some methods are found | |
| 104 | + */ | |
| 105 | + public static Method findStaticMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException { | |
| 106 | + Method method = findMethod(type, name, args); | |
| 107 | + if (!Modifier.isStatic(method.getModifiers())) { | |
| 108 | + throw new NoSuchMethodException("Method '" + name + "' is not static"); | |
| 109 | + } | |
| 110 | + return method; | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Finds method that is accessible from public class or interface through class hierarchy. | |
| 115 | + * | |
| 116 | + * @param method object that represents found method | |
| 117 | + * @return object that represents accessible method | |
| 118 | + * @throws NoSuchMethodException if method is not accessible or is not found | |
| 119 | + * in specified superclass or interface | |
| 120 | + */ | |
| 121 | + public static Method findAccessibleMethod(Method method) throws NoSuchMethodException { | |
| 122 | + Class<?> type = method.getDeclaringClass(); | |
| 123 | + if (Modifier.isPublic(type.getModifiers())) { | |
| 124 | + return method; | |
| 125 | + } | |
| 126 | + if (Modifier.isStatic(method.getModifiers())) { | |
| 127 | + throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible"); | |
| 128 | + } | |
| 129 | + for (Type generic : type.getGenericInterfaces()) { | |
| 130 | + try { | |
| 131 | + return findAccessibleMethod(method, generic); | |
| 132 | + } | |
| 133 | + catch (NoSuchMethodException exception) { | |
| 134 | + // try to find in superclass or another interface | |
| 135 | + } | |
| 136 | + } | |
| 137 | + return findAccessibleMethod(method, type.getGenericSuperclass()); | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * Finds method that accessible from specified class. | |
| 142 | + * | |
| 143 | + * @param method object that represents found method | |
| 144 | + * @param generic generic type that is used to find accessible method | |
| 145 | + * @return object that represents accessible method | |
| 146 | + * @throws NoSuchMethodException if method is not accessible or is not found | |
| 147 | + * in specified superclass or interface | |
| 148 | + */ | |
| 149 | + private static Method findAccessibleMethod(Method method, Type generic) throws NoSuchMethodException { | |
| 150 | + String name = method.getName(); | |
| 151 | + Class<?>[] params = method.getParameterTypes(); | |
| 152 | + if (generic instanceof Class) { | |
| 153 | + Class<?> type = (Class<?>) generic; | |
| 154 | + return findAccessibleMethod(type.getMethod(name, params)); | |
| 155 | + } | |
| 156 | + if (generic instanceof ParameterizedType) { | |
| 157 | + ParameterizedType pt = (ParameterizedType) generic; | |
| 158 | + Class<?> type = (Class<?>) pt.getRawType(); | |
| 159 | + for (Method m : type.getMethods()) { | |
| 160 | + if (m.getName().equals(name)) { | |
| 161 | + Class<?>[] pts = m.getParameterTypes(); | |
| 162 | + if (pts.length == params.length) { | |
| 163 | + if (Arrays.equals(params, pts)) { | |
| 164 | + return findAccessibleMethod(m); | |
| 165 | + } | |
| 166 | + Type[] gpts = m.getGenericParameterTypes(); | |
| 167 | + if (Arrays.equals(params, TypeResolver.erase(TypeResolver.resolve(pt, gpts)))) { | |
| 168 | + return findAccessibleMethod(m); | |
| 169 | + } | |
| 170 | + } | |
| 171 | + } | |
| 172 | + } | |
| 173 | + } | |
| 174 | + throw new NoSuchMethodException("Method '" + name + "' is not accessible"); | |
| 175 | + } | |
| 176 | + | |
| 177 | + | |
| 178 | + private final String name; | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * Creates method finder with specified array of parameter types. | |
| 182 | + * | |
| 183 | + * @param name the name of method to find | |
| 184 | + * @param args the array of parameter types | |
| 185 | + */ | |
| 186 | + private MethodFinder(String name, Class<?>[] args) { | |
| 187 | + super(args); | |
| 188 | + this.name = name; | |
| 189 | + } | |
| 190 | + | |
| 191 | + /** | |
| 192 | + * Returns an array of {@code Class} objects | |
| 193 | + * that represent the formal parameter types of the method | |
| 194 | + * Returns an empty array if the method takes no parameters. | |
| 195 | + * | |
| 196 | + * @param method the object that represents method | |
| 197 | + * @return the parameter types of the method | |
| 198 | + */ | |
| 199 | + @Override | |
| 200 | + protected Class<?>[] getParameters(Method method) { | |
| 201 | + return method.getParameterTypes(); | |
| 202 | + } | |
| 203 | + | |
| 204 | + /** | |
| 205 | + * Returns {@code true} if and only if the method | |
| 206 | + * was declared to take a variable number of arguments. | |
| 207 | + * | |
| 208 | + * @param method the object that represents method | |
| 209 | + * @return {@code true} if the method was declared | |
| 210 | + * to take a variable number of arguments; | |
| 211 | + * {@code false} otherwise | |
| 212 | + */ | |
| 213 | + @Override | |
| 214 | + protected boolean isVarArgs(Method method) { | |
| 215 | + return method.isVarArgs(); | |
| 216 | + } | |
| 217 | + | |
| 218 | + /** | |
| 219 | + * Checks validness of the method. | |
| 220 | + * The valid method should be public and | |
| 221 | + * should have the specified name. | |
| 222 | + * | |
| 223 | + * @param method the object that represents method | |
| 224 | + * @return {@code true} if the method is valid, | |
| 225 | + * {@code false} otherwise | |
| 226 | + */ | |
| 227 | + @Override | |
| 228 | + protected boolean isValid(Method method) { | |
| 229 | + return Modifier.isPublic(method.getModifiers()) && method.getName().equals(this.name); | |
| 230 | + } | |
| 231 | +} | |
Binary file not shown.
| @@ -0,0 +1,68 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import java.beans.PersistenceDelegate; | |
| 28 | +import java.util.HashMap; | |
| 29 | +import java.util.Map; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * This is utility class that provides functionality | |
| 33 | + * to find a {@link PersistenceDelegate} for a JavaBean specified by its type. | |
| 34 | + * | |
| 35 | + * @since 1.7 | |
| 36 | + * | |
| 37 | + * @author Sergey A. Malenkov | |
| 38 | + */ | |
| 39 | +public final class PersistenceDelegateFinder | |
| 40 | + extends InstanceFinder<PersistenceDelegate> { | |
| 41 | + | |
| 42 | + private final Map<Class<?>, PersistenceDelegate> registry; | |
| 43 | + | |
| 44 | + public PersistenceDelegateFinder() { | |
| 45 | + super(PersistenceDelegate.class, true, "PersistenceDelegate"); | |
| 46 | + this.registry = new HashMap<Class<?>, PersistenceDelegate>(); | |
| 47 | + } | |
| 48 | + | |
| 49 | + public void register(Class<?> type, PersistenceDelegate delegate) { | |
| 50 | + synchronized (this.registry) { | |
| 51 | + if (delegate != null) { | |
| 52 | + this.registry.put(type, delegate); | |
| 53 | + } | |
| 54 | + else { | |
| 55 | + this.registry.remove(type); | |
| 56 | + } | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 60 | + @Override | |
| 61 | + public PersistenceDelegate find(Class<?> type) { | |
| 62 | + PersistenceDelegate delegate; | |
| 63 | + synchronized (this.registry) { | |
| 64 | + delegate = this.registry.get(type); | |
| 65 | + } | |
| 66 | + return (delegate != null) ? delegate : super.find(type); | |
| 67 | + } | |
| 68 | +} | |
Binary file not shown.
| @@ -0,0 +1,70 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import java.util.HashMap; | |
| 28 | +import java.util.Map; | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * This utility class associates | |
| 32 | + * name of primitive type with appropriate class. | |
| 33 | + * | |
| 34 | + * @since 1.7 | |
| 35 | + * | |
| 36 | + * @author Sergey A. Malenkov | |
| 37 | + */ | |
| 38 | +final class PrimitiveTypeMap { | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Returns primitive type class by its name. | |
| 42 | + * | |
| 43 | + * @param name the name of primitive type | |
| 44 | + * @return found primitive type class, | |
| 45 | + * or {@code null} if not found | |
| 46 | + */ | |
| 47 | + static Class<?> getType(String name) { | |
| 48 | + return map.get(name); | |
| 49 | + } | |
| 50 | + | |
| 51 | + private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9); | |
| 52 | + | |
| 53 | + static { | |
| 54 | + map.put(boolean.class.getName(), boolean.class); | |
| 55 | + map.put(char.class.getName(), char.class); | |
| 56 | + map.put(byte.class.getName(), byte.class); | |
| 57 | + map.put(short.class.getName(), short.class); | |
| 58 | + map.put(int.class.getName(), int.class); | |
| 59 | + map.put(long.class.getName(), long.class); | |
| 60 | + map.put(float.class.getName(), float.class); | |
| 61 | + map.put(double.class.getName(), double.class); | |
| 62 | + map.put(void.class.getName(), void.class); | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Disable instantiation. | |
| 67 | + */ | |
| 68 | + private PrimitiveTypeMap() { | |
| 69 | + } | |
| 70 | +} | |
Binary file not shown.
| @@ -0,0 +1,86 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import java.util.HashMap; | |
| 28 | +import java.util.Map; | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * This utility class associates | |
| 32 | + * name of primitive type with appropriate wrapper. | |
| 33 | + * | |
| 34 | + * @since 1.7 | |
| 35 | + * | |
| 36 | + * @author Sergey A. Malenkov | |
| 37 | + */ | |
| 38 | +public final class PrimitiveWrapperMap { | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Replaces all primitive types in specified array with wrappers. | |
| 42 | + * | |
| 43 | + * @param types array of classes where all primitive types | |
| 44 | + * will be replaced by appropriate wrappers | |
| 45 | + */ | |
| 46 | + static void replacePrimitivesWithWrappers(Class<?>[] types) { | |
| 47 | + for (int i = 0; i < types.length; i++) { | |
| 48 | + if (types[i] != null) { | |
| 49 | + if (types[i].isPrimitive()) { | |
| 50 | + types[i] = getType(types[i].getName()); | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Returns wrapper for primitive type by its name. | |
| 58 | + * | |
| 59 | + * @param name the name of primitive type | |
| 60 | + * @return found wrapper for primitive type, | |
| 61 | + * or {@code null} if not found | |
| 62 | + */ | |
| 63 | + public static Class<?> getType(String name) { | |
| 64 | + return map.get(name); | |
| 65 | + } | |
| 66 | + | |
| 67 | + private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9); | |
| 68 | + | |
| 69 | + static { | |
| 70 | + map.put(Boolean.TYPE.getName(), Boolean.class); | |
| 71 | + map.put(Character.TYPE.getName(), Character.class); | |
| 72 | + map.put(Byte.TYPE.getName(), Byte.class); | |
| 73 | + map.put(Short.TYPE.getName(), Short.class); | |
| 74 | + map.put(Integer.TYPE.getName(), Integer.class); | |
| 75 | + map.put(Long.TYPE.getName(), Long.class); | |
| 76 | + map.put(Float.TYPE.getName(), Float.class); | |
| 77 | + map.put(Double.TYPE.getName(), Double.class); | |
| 78 | + map.put(Void.TYPE.getName(), Void.class); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Disable instantiation. | |
| 83 | + */ | |
| 84 | + private PrimitiveWrapperMap() { | |
| 85 | + } | |
| 86 | +} | |
Binary file not shown.
| @@ -0,0 +1,87 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +import com.sun.beans.WeakCache; | |
| 28 | + | |
| 29 | +import java.beans.PropertyEditor; | |
| 30 | + | |
| 31 | +import sun.beans.editors.BooleanEditor; | |
| 32 | +import sun.beans.editors.ByteEditor; | |
| 33 | +import sun.beans.editors.DoubleEditor; | |
| 34 | +import sun.beans.editors.EnumEditor; | |
| 35 | +import sun.beans.editors.FloatEditor; | |
| 36 | +import sun.beans.editors.IntegerEditor; | |
| 37 | +import sun.beans.editors.LongEditor; | |
| 38 | +import sun.beans.editors.ShortEditor; | |
| 39 | + | |
| 40 | +/** | |
| 41 | + * This is utility class that provides functionality | |
| 42 | + * to find a {@link PropertyEditor} for a JavaBean specified by its type. | |
| 43 | + * | |
| 44 | + * @since 1.7 | |
| 45 | + * | |
| 46 | + * @author Sergey A. Malenkov | |
| 47 | + */ | |
| 48 | +public final class PropertyEditorFinder | |
| 49 | + extends InstanceFinder<PropertyEditor> { | |
| 50 | + | |
| 51 | + private final WeakCache<Class<?>, Class<?>> registry; | |
| 52 | + | |
| 53 | + public PropertyEditorFinder() { | |
| 54 | + super(PropertyEditor.class, false, "Editor", "sun.beans.editors"); | |
| 55 | + | |
| 56 | + this.registry = new WeakCache<Class<?>, Class<?>>(); | |
| 57 | + this.registry.put(Byte.TYPE, ByteEditor.class); | |
| 58 | + this.registry.put(Short.TYPE, ShortEditor.class); | |
| 59 | + this.registry.put(Integer.TYPE, IntegerEditor.class); | |
| 60 | + this.registry.put(Long.TYPE, LongEditor.class); | |
| 61 | + this.registry.put(Boolean.TYPE, BooleanEditor.class); | |
| 62 | + this.registry.put(Float.TYPE, FloatEditor.class); | |
| 63 | + this.registry.put(Double.TYPE, DoubleEditor.class); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void register(Class<?> type, Class<?> editor) { | |
| 67 | + synchronized (this.registry) { | |
| 68 | + this.registry.put(type, editor); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public PropertyEditor find(Class<?> type) { | |
| 74 | + Class<?> predefined; | |
| 75 | + synchronized (this.registry) { | |
| 76 | + predefined = this.registry.get(type); | |
| 77 | + } | |
| 78 | + PropertyEditor editor = instantiate(predefined, null); | |
| 79 | + if (editor == null) { | |
| 80 | + editor = super.find(type); | |
| 81 | + if ((editor == null) && (null != type.getEnumConstants())) { | |
| 82 | + editor = new EnumEditor(type); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + return editor; | |
| 86 | + } | |
| 87 | +} | |
Binary file not shown.
| @@ -0,0 +1,169 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.beans.finder; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * This class is designed to be a key of a cache | |
| 29 | + * of constructors or methods. | |
| 30 | + * | |
| 31 | + * @since 1.7 | |
| 32 | + * | |
| 33 | + * @author Sergey A. Malenkov | |
| 34 | + */ | |
| 35 | +final class Signature { | |
| 36 | + private final Class<?> type; | |
| 37 | + private final String name; | |
| 38 | + private final Class<?>[] args; | |
| 39 | + | |
| 40 | + private volatile int code; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Constructs signature for constructor. | |
| 44 | + * | |
| 45 | + * @param type the class that contains constructor | |
| 46 | + * @param args the types of constructor's parameters | |
| 47 | + */ | |
| 48 | + Signature(Class<?> type, Class<?>[] args) { | |
| 49 | + this(type, null, args); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Constructs signature for method. | |
| 54 | + * | |
| 55 | + * @param type the class that contains method | |
| 56 | + * @param name the name of the method | |
| 57 | + * @param args the types of method's parameters | |
| 58 | + */ | |
| 59 | + Signature(Class<?> type, String name, Class<?>[] args) { | |
| 60 | + this.type = type; | |
| 61 | + this.name = name; | |
| 62 | + this.args = args; | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Indicates whether some other object is "equal to" this one. | |
| 67 | + * | |
| 68 | + * @param object the reference object with which to compare | |
| 69 | + * @return {@code true} if this object is the same as the | |
| 70 | + * {@code object} argument, {@code false} otherwise | |
| 71 | + * @see #hashCode() | |
| 72 | + */ | |
| 73 | + @Override | |
| 74 | + public boolean equals(Object object) { | |
| 75 | + if (this == object) { | |
| 76 | + return true; | |
| 77 | + } | |
| 78 | + if (object instanceof Signature) { | |
| 79 | + Signature signature = (Signature) object; | |
| 80 | + return isEqual(signature.type, this.type) | |
| 81 | + && isEqual(signature.name, this.name) | |
| 82 | + && isEqual(signature.args, this.args); | |
| 83 | + } | |
| 84 | + return false; | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Indicates whether some object is "equal to" another one. | |
| 89 | + * This method supports {@code null} values. | |
| 90 | + * | |
| 91 | + * @param obj1 the first reference object that will compared | |
| 92 | + * @param obj2 the second reference object that will compared | |
| 93 | + * @return {@code true} if first object is the same as the second object, | |
| 94 | + * {@code false} otherwise | |
| 95 | + */ | |
| 96 | + private static boolean isEqual(Object obj1, Object obj2) { | |
| 97 | + return (obj1 == null) | |
| 98 | + ? obj2 == null | |
| 99 | + : obj1.equals(obj2); | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Indicates whether some array is "equal to" another one. | |
| 104 | + * This method supports {@code null} values. | |
| 105 | + * | |
| 106 | + * @param args1 the first reference array that will compared | |
| 107 | + * @param args2 the second reference array that will compared | |
| 108 | + * @return {@code true} if first array is the same as the second array, | |
| 109 | + * {@code false} otherwise | |
| 110 | + */ | |
| 111 | + private static boolean isEqual(Class<?>[] args1, Class<?>[] args2) { | |
| 112 | + if ((args1 == null) || (args2 == null)) { | |
| 113 | + return args1 == args2; | |
| 114 | + } | |
| 115 | + if (args1.length != args2.length) { | |
| 116 | + return false; | |
| 117 | + } | |
| 118 | + for (int i = 0; i < args1.length; i++) { | |
| 119 | + if (!isEqual(args1[i], args2[i])) { | |
| 120 | + return false; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + return true; | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * Returns a hash code value for the object. | |
| 128 | + * This method is supported for the benefit of hashtables | |
| 129 | + * such as {@link java.util.HashMap} or {@link java.util.HashSet}. | |
| 130 | + * Hash code computed using algorithm | |
| 131 | + * suggested in Effective Java, Item 8. | |
| 132 | + * | |
| 133 | + * @return a hash code value for this object | |
| 134 | + * @see #equals(Object) | |
| 135 | + */ | |
| 136 | + @Override | |
| 137 | + public int hashCode() { | |
| 138 | + if (this.code == 0) { | |
| 139 | + int code = 17; | |
| 140 | + code = addHashCode(code, this.type); | |
| 141 | + code = addHashCode(code, this.name); | |
| 142 | + | |
| 143 | + if (this.args != null) { | |
| 144 | + for (Class<?> arg : this.args) { | |
| 145 | + code = addHashCode(code, arg); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + this.code = code; | |
| 149 | + } | |
| 150 | + return this.code; | |
| 151 | + } | |
| 152 | + | |
| 153 | + /** | |
| 154 | + * Adds hash code value if specified object. | |
| 155 | + * This is a part of the algorithm | |
| 156 | + * suggested in Effective Java, Item 8. | |
| 157 | + * | |
| 158 | + * @param code current hash code value | |
| 159 | + * @param object object that updates hash code value | |
| 160 | + * @return updated hash code value | |
| 161 | + * @see #hashCode() | |
| 162 | + */ | |
| 163 | + private static int addHashCode(int code, Object object) { | |
| 164 | + code *= 37; | |
| 165 | + return (object != null) | |
| 166 | + ? code + object.hashCode() | |
| 167 | + : code; | |
| 168 | + } | |
| 169 | +} | |
| @@ -0,0 +1,19 @@ | ||
| 1 | +<../../../../../../mkconfig | |
| 2 | + | |
| 3 | +TARG=\ | |
| 4 | + AbstractFinder.dis\ | |
| 5 | + BeanInfoFinder.dis\ | |
| 6 | + ClassFinder.dis\ | |
| 7 | + ConstructorFinder.dis\ | |
| 8 | + FieldFinder.dis\ | |
| 9 | + InstanceFinder.dis\ | |
| 10 | + MethodFinder.dis\ | |
| 11 | + PersistenceDelegateFinder.dis\ | |
| 12 | + PrimitiveTypeMap.dis\ | |
| 13 | + PrimitiveWrapperMap.dis\ | |
| 14 | + PropertyEditorFinder.dis\ | |
| 15 | + Signature.dis\ | |
| 16 | + | |
| 17 | +DISBIN=$ROOT/java/dis/java/java/com/sun/beans/finder | |
| 18 | + | |
| 19 | +<$ROOT/mkfiles/mkjava | |
| @@ -0,0 +1,15 @@ | ||
| 1 | +<../../../../../mkconfig | |
| 2 | + | |
| 3 | +DIRS=\ | |
| 4 | + decoder\ | |
| 5 | + finder\ | |
| 6 | + | |
| 7 | +TARG=\ | |
| 8 | + TypeResolver.dis\ | |
| 9 | + WeakCache.dis\ | |
| 10 | + WildcardTypeImpl.dis\ | |
| 11 | + | |
| 12 | +DISBIN=$ROOT/java/dis/java/java/com/sun/beans | |
| 13 | + | |
| 14 | +<$ROOT/mkfiles/mkjava | |
| 15 | +<$ROOT/mkfiles/mksubdirs | |
| @@ -0,0 +1,6 @@ | ||
| 1 | +<../../../../../mkconfig | |
| 2 | + | |
| 3 | +DIRS=\ | |
| 4 | + provider\ | |
| 5 | + | |
| 6 | +<$ROOT/mkfiles/mksubdirs | |
| @@ -0,0 +1,427 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.security.*; | |
| 29 | +import java.security.spec.*; | |
| 30 | +import javax.crypto.*; | |
| 31 | +import javax.crypto.spec.*; | |
| 32 | +import javax.crypto.BadPaddingException; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * This class implements the AES algorithm in its various modes | |
| 36 | + * (<code>ECB</code>, <code>CFB</code>, <code>OFB</code>, <code>CBC</code>, | |
| 37 | + * <code>PCBC</code>) and padding schemes (<code>PKCS5Padding</code>, | |
| 38 | + * <code>NoPadding</code>, <code>ISO10126Padding</code>). | |
| 39 | + * | |
| 40 | + * @author Valerie Peng | |
| 41 | + * | |
| 42 | + * | |
| 43 | + * @see AESCrypt | |
| 44 | + * @see CipherBlockChaining | |
| 45 | + * @see ElectronicCodeBook | |
| 46 | + * @see CipherFeedback | |
| 47 | + * @see OutputFeedback | |
| 48 | + */ | |
| 49 | + | |
| 50 | +public final class AESCipher extends CipherSpi { | |
| 51 | + /* | |
| 52 | + * internal CipherCore object which does the real work. | |
| 53 | + */ | |
| 54 | + private CipherCore core = null; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Creates an instance of AES cipher with default ECB mode and | |
| 58 | + * PKCS5Padding. | |
| 59 | + */ | |
| 60 | + public AESCipher() { | |
| 61 | + core = new CipherCore(new AESCrypt(), AESConstants.AES_BLOCK_SIZE); | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Sets the mode of this cipher. | |
| 66 | + * | |
| 67 | + * @param mode the cipher mode | |
| 68 | + * | |
| 69 | + * @exception NoSuchAlgorithmException if the requested cipher mode does | |
| 70 | + * not exist | |
| 71 | + */ | |
| 72 | + protected void engineSetMode(String mode) | |
| 73 | + throws NoSuchAlgorithmException { | |
| 74 | + core.setMode(mode); | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Sets the padding mechanism of this cipher. | |
| 79 | + * | |
| 80 | + * @param padding the padding mechanism | |
| 81 | + * | |
| 82 | + * @exception NoSuchPaddingException if the requested padding mechanism | |
| 83 | + * does not exist | |
| 84 | + */ | |
| 85 | + protected void engineSetPadding(String paddingScheme) | |
| 86 | + throws NoSuchPaddingException { | |
| 87 | + core.setPadding(paddingScheme); | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Returns the block size (in bytes). | |
| 92 | + * | |
| 93 | + * @return the block size (in bytes), or 0 if the underlying algorithm is | |
| 94 | + * not a block cipher | |
| 95 | + */ | |
| 96 | + protected int engineGetBlockSize() { | |
| 97 | + return AESConstants.AES_BLOCK_SIZE; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Returns the length in bytes that an output buffer would need to be in | |
| 102 | + * order to hold the result of the next <code>update</code> or | |
| 103 | + * <code>doFinal</code> operation, given the input length | |
| 104 | + * <code>inputLen</code> (in bytes). | |
| 105 | + * | |
| 106 | + * <p>This call takes into account any unprocessed (buffered) data from a | |
| 107 | + * previous <code>update</code> call, and padding. | |
| 108 | + * | |
| 109 | + * <p>The actual output length of the next <code>update</code> or | |
| 110 | + * <code>doFinal</code> call may be smaller than the length returned by | |
| 111 | + * this method. | |
| 112 | + * | |
| 113 | + * @param inputLen the input length (in bytes) | |
| 114 | + * | |
| 115 | + * @return the required output buffer size (in bytes) | |
| 116 | + */ | |
| 117 | + protected int engineGetOutputSize(int inputLen) { | |
| 118 | + return core.getOutputSize(inputLen); | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * Returns the initialization vector (IV) in a new buffer. | |
| 123 | + * | |
| 124 | + * <p>This is useful in the case where a random IV has been created | |
| 125 | + * (see <a href = "#init">init</a>), | |
| 126 | + * or in the context of password-based encryption or | |
| 127 | + * decryption, where the IV is derived from a user-provided password. | |
| 128 | + * | |
| 129 | + * @return the initialization vector in a new buffer, or null if the | |
| 130 | + * underlying algorithm does not use an IV, or if the IV has not yet | |
| 131 | + * been set. | |
| 132 | + */ | |
| 133 | + protected byte[] engineGetIV() { | |
| 134 | + return core.getIV(); | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * Returns the parameters used with this cipher. | |
| 139 | + * | |
| 140 | + * <p>The returned parameters may be the same that were used to initialize | |
| 141 | + * this cipher, or may contain the default set of parameters or a set of | |
| 142 | + * randomly generated parameters used by the underlying cipher | |
| 143 | + * implementation (provided that the underlying cipher implementation | |
| 144 | + * uses a default set of parameters or creates new parameters if it needs | |
| 145 | + * parameters but was not initialized with any). | |
| 146 | + * | |
| 147 | + * @return the parameters used with this cipher, or null if this cipher | |
| 148 | + * does not use any parameters. | |
| 149 | + */ | |
| 150 | + protected AlgorithmParameters engineGetParameters() { | |
| 151 | + return core.getParameters("AES"); | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Initializes this cipher with a key and a source of randomness. | |
| 156 | + * | |
| 157 | + * <p>The cipher is initialized for one of the following four operations: | |
| 158 | + * encryption, decryption, key wrapping or key unwrapping, depending on | |
| 159 | + * the value of <code>opmode</code>. | |
| 160 | + * | |
| 161 | + * <p>If this cipher requires an initialization vector (IV), it will get | |
| 162 | + * it from <code>random</code>. | |
| 163 | + * This behaviour should only be used in encryption or key wrapping | |
| 164 | + * mode, however. | |
| 165 | + * When initializing a cipher that requires an IV for decryption or | |
| 166 | + * key unwrapping, the IV | |
| 167 | + * (same IV that was used for encryption or key wrapping) must be provided | |
| 168 | + * explicitly as a | |
| 169 | + * parameter, in order to get the correct result. | |
| 170 | + * | |
| 171 | + * <p>This method also cleans existing buffer and other related state | |
| 172 | + * information. | |
| 173 | + * | |
| 174 | + * @param opmode the operation mode of this cipher (this is one of | |
| 175 | + * the following: | |
| 176 | + * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>, | |
| 177 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) | |
| 178 | + * @param key the secret key | |
| 179 | + * @param random the source of randomness | |
| 180 | + * | |
| 181 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 182 | + * initializing this cipher | |
| 183 | + */ | |
| 184 | + protected void engineInit(int opmode, Key key, SecureRandom random) | |
| 185 | + throws InvalidKeyException { | |
| 186 | + core.init(opmode, key, random); | |
| 187 | + } | |
| 188 | + | |
| 189 | + /** | |
| 190 | + * Initializes this cipher with a key, a set of | |
| 191 | + * algorithm parameters, and a source of randomness. | |
| 192 | + * | |
| 193 | + * <p>The cipher is initialized for one of the following four operations: | |
| 194 | + * encryption, decryption, key wrapping or key unwrapping, depending on | |
| 195 | + * the value of <code>opmode</code>. | |
| 196 | + * | |
| 197 | + * <p>If this cipher (including its underlying feedback or padding scheme) | |
| 198 | + * requires any random bytes, it will get them from <code>random</code>. | |
| 199 | + * | |
| 200 | + * @param opmode the operation mode of this cipher (this is one of | |
| 201 | + * the following: | |
| 202 | + * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>, | |
| 203 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) | |
| 204 | + * @param key the encryption key | |
| 205 | + * @param params the algorithm parameters | |
| 206 | + * @param random the source of randomness | |
| 207 | + * | |
| 208 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 209 | + * initializing this cipher | |
| 210 | + * @exception InvalidAlgorithmParameterException if the given algorithm | |
| 211 | + * parameters are inappropriate for this cipher | |
| 212 | + */ | |
| 213 | + protected void engineInit(int opmode, Key key, | |
| 214 | + AlgorithmParameterSpec params, | |
| 215 | + SecureRandom random) | |
| 216 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 217 | + core.init(opmode, key, params, random); | |
| 218 | + } | |
| 219 | + | |
| 220 | + protected void engineInit(int opmode, Key key, | |
| 221 | + AlgorithmParameters params, | |
| 222 | + SecureRandom random) | |
| 223 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 224 | + core.init(opmode, key, params, random); | |
| 225 | + } | |
| 226 | + | |
| 227 | + /** | |
| 228 | + * Continues a multiple-part encryption or decryption operation | |
| 229 | + * (depending on how this cipher was initialized), processing another data | |
| 230 | + * part. | |
| 231 | + * | |
| 232 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 233 | + * buffer, starting at <code>inputOffset</code>, are processed, and the | |
| 234 | + * result is stored in a new buffer. | |
| 235 | + * | |
| 236 | + * @param input the input buffer | |
| 237 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 238 | + * starts | |
| 239 | + * @param inputLen the input length | |
| 240 | + * | |
| 241 | + * @return the new buffer with the result | |
| 242 | + * | |
| 243 | + * @exception IllegalStateException if this cipher is in a wrong state | |
| 244 | + * (e.g., has not been initialized) | |
| 245 | + */ | |
| 246 | + protected byte[] engineUpdate(byte[] input, int inputOffset, | |
| 247 | + int inputLen) { | |
| 248 | + return core.update(input, inputOffset, inputLen); | |
| 249 | + } | |
| 250 | + | |
| 251 | + /** | |
| 252 | + * Continues a multiple-part encryption or decryption operation | |
| 253 | + * (depending on how this cipher was initialized), processing another data | |
| 254 | + * part. | |
| 255 | + * | |
| 256 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 257 | + * buffer, starting at <code>inputOffset</code>, are processed, and the | |
| 258 | + * result is stored in the <code>output</code> buffer, starting at | |
| 259 | + * <code>outputOffset</code>. | |
| 260 | + * | |
| 261 | + * @param input the input buffer | |
| 262 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 263 | + * starts | |
| 264 | + * @param inputLen the input length | |
| 265 | + * @param output the buffer for the result | |
| 266 | + * @param outputOffset the offset in <code>output</code> where the result | |
| 267 | + * is stored | |
| 268 | + * | |
| 269 | + * @return the number of bytes stored in <code>output</code> | |
| 270 | + * | |
| 271 | + * @exception ShortBufferException if the given output buffer is too small | |
| 272 | + * to hold the result | |
| 273 | + */ | |
| 274 | + protected int engineUpdate(byte[] input, int inputOffset, int inputLen, | |
| 275 | + byte[] output, int outputOffset) | |
| 276 | + throws ShortBufferException { | |
| 277 | + return core.update(input, inputOffset, inputLen, output, | |
| 278 | + outputOffset); | |
| 279 | + } | |
| 280 | + | |
| 281 | + /** | |
| 282 | + * Encrypts or decrypts data in a single-part operation, | |
| 283 | + * or finishes a multiple-part operation. | |
| 284 | + * The data is encrypted or decrypted, depending on how this cipher was | |
| 285 | + * initialized. | |
| 286 | + * | |
| 287 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 288 | + * buffer, starting at <code>inputOffset</code>, and any input bytes that | |
| 289 | + * may have been buffered during a previous <code>update</code> operation, | |
| 290 | + * are processed, with padding (if requested) being applied. | |
| 291 | + * The result is stored in a new buffer. | |
| 292 | + * | |
| 293 | + * <p>The cipher is reset to its initial state (uninitialized) after this | |
| 294 | + * call. | |
| 295 | + * | |
| 296 | + * @param input the input buffer | |
| 297 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 298 | + * starts | |
| 299 | + * @param inputLen the input length | |
| 300 | + * | |
| 301 | + * @return the new buffer with the result | |
| 302 | + * | |
| 303 | + * @exception IllegalBlockSizeException if this cipher is a block cipher, | |
| 304 | + * no padding has been requested (only in encryption mode), and the total | |
| 305 | + * input length of the data processed by this cipher is not a multiple of | |
| 306 | + * block size | |
| 307 | + * @exception BadPaddingException if this cipher is in decryption mode, | |
| 308 | + * and (un)padding has been requested, but the decrypted data is not | |
| 309 | + * bounded by the appropriate padding bytes | |
| 310 | + */ | |
| 311 | + protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) | |
| 312 | + throws IllegalBlockSizeException, BadPaddingException { | |
| 313 | + return core.doFinal(input, inputOffset, inputLen); | |
| 314 | + } | |
| 315 | + | |
| 316 | + /** | |
| 317 | + * Encrypts or decrypts data in a single-part operation, | |
| 318 | + * or finishes a multiple-part operation. | |
| 319 | + * The data is encrypted or decrypted, depending on how this cipher was | |
| 320 | + * initialized. | |
| 321 | + * | |
| 322 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 323 | + * buffer, starting at <code>inputOffset</code>, and any input bytes that | |
| 324 | + * may have been buffered during a previous <code>update</code> operation, | |
| 325 | + * are processed, with padding (if requested) being applied. | |
| 326 | + * The result is stored in the <code>output</code> buffer, starting at | |
| 327 | + * <code>outputOffset</code>. | |
| 328 | + * | |
| 329 | + * <p>The cipher is reset to its initial state (uninitialized) after this | |
| 330 | + * call. | |
| 331 | + * | |
| 332 | + * @param input the input buffer | |
| 333 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 334 | + * starts | |
| 335 | + * @param inputLen the input length | |
| 336 | + * @param output the buffer for the result | |
| 337 | + * @param outputOffset the offset in <code>output</code> where the result | |
| 338 | + * is stored | |
| 339 | + * | |
| 340 | + * @return the number of bytes stored in <code>output</code> | |
| 341 | + * | |
| 342 | + * @exception IllegalBlockSizeException if this cipher is a block cipher, | |
| 343 | + * no padding has been requested (only in encryption mode), and the total | |
| 344 | + * input length of the data processed by this cipher is not a multiple of | |
| 345 | + * block size | |
| 346 | + * @exception ShortBufferException if the given output buffer is too small | |
| 347 | + * to hold the result | |
| 348 | + * @exception BadPaddingException if this cipher is in decryption mode, | |
| 349 | + * and (un)padding has been requested, but the decrypted data is not | |
| 350 | + * bounded by the appropriate padding bytes | |
| 351 | + */ | |
| 352 | + protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, | |
| 353 | + byte[] output, int outputOffset) | |
| 354 | + throws IllegalBlockSizeException, ShortBufferException, | |
| 355 | + BadPaddingException { | |
| 356 | + return core.doFinal(input, inputOffset, inputLen, output, | |
| 357 | + outputOffset); | |
| 358 | + } | |
| 359 | + | |
| 360 | + /** | |
| 361 | + * Returns the key size of the given key object. | |
| 362 | + * | |
| 363 | + * @param key the key object. | |
| 364 | + * | |
| 365 | + * @return the key size of the given key object. | |
| 366 | + * | |
| 367 | + * @exception InvalidKeyException if <code>key</code> is invalid. | |
| 368 | + */ | |
| 369 | + protected int engineGetKeySize(Key key) throws InvalidKeyException { | |
| 370 | + byte[] encoded = key.getEncoded(); | |
| 371 | + if (!AESCrypt.isKeySizeValid(encoded.length)) { | |
| 372 | + throw new InvalidKeyException("Invalid AES key length: " + | |
| 373 | + encoded.length + " bytes"); | |
| 374 | + } | |
| 375 | + return encoded.length * 8; | |
| 376 | + } | |
| 377 | + | |
| 378 | + /** | |
| 379 | + * Wrap a key. | |
| 380 | + * | |
| 381 | + * @param key the key to be wrapped. | |
| 382 | + * | |
| 383 | + * @return the wrapped key. | |
| 384 | + * | |
| 385 | + * @exception IllegalBlockSizeException if this cipher is a block | |
| 386 | + * cipher, no padding has been requested, and the length of the | |
| 387 | + * encoding of the key to be wrapped is not a | |
| 388 | + * multiple of the block size. | |
| 389 | + * | |
| 390 | + * @exception InvalidKeyException if it is impossible or unsafe to | |
| 391 | + * wrap the key with this cipher (e.g., a hardware protected key is | |
| 392 | + * being passed to a software only cipher). | |
| 393 | + */ | |
| 394 | + protected byte[] engineWrap(Key key) | |
| 395 | + throws IllegalBlockSizeException, InvalidKeyException { | |
| 396 | + return core.wrap(key); | |
| 397 | + } | |
| 398 | + | |
| 399 | + /** | |
| 400 | + * Unwrap a previously wrapped key. | |
| 401 | + * | |
| 402 | + * @param wrappedKey the key to be unwrapped. | |
| 403 | + * | |
| 404 | + * @param wrappedKeyAlgorithm the algorithm the wrapped key is for. | |
| 405 | + * | |
| 406 | + * @param wrappedKeyType the type of the wrapped key. | |
| 407 | + * This is one of <code>Cipher.SECRET_KEY</code>, | |
| 408 | + * <code>Cipher.PRIVATE_KEY</code>, or <code>Cipher.PUBLIC_KEY</code>. | |
| 409 | + * | |
| 410 | + * @return the unwrapped key. | |
| 411 | + * | |
| 412 | + * @exception NoSuchAlgorithmException if no installed providers | |
| 413 | + * can create keys of type <code>wrappedKeyType</code> for the | |
| 414 | + * <code>wrappedKeyAlgorithm</code>. | |
| 415 | + * | |
| 416 | + * @exception InvalidKeyException if <code>wrappedKey</code> does not | |
| 417 | + * represent a wrapped key of type <code>wrappedKeyType</code> for | |
| 418 | + * the <code>wrappedKeyAlgorithm</code>. | |
| 419 | + */ | |
| 420 | + protected Key engineUnwrap(byte[] wrappedKey, | |
| 421 | + String wrappedKeyAlgorithm, | |
| 422 | + int wrappedKeyType) | |
| 423 | + throws InvalidKeyException, NoSuchAlgorithmException { | |
| 424 | + return core.unwrap(wrappedKey, wrappedKeyAlgorithm, | |
| 425 | + wrappedKeyType); | |
| 426 | + } | |
| 427 | +} | |
| @@ -0,0 +1,46 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * This class defines the constants used by the AES implementation. | |
| 30 | + * | |
| 31 | + * @author Valerie Peng | |
| 32 | + * | |
| 33 | + * | |
| 34 | + * @see AESCipher | |
| 35 | + */ | |
| 36 | + | |
| 37 | +interface AESConstants { | |
| 38 | + | |
| 39 | + // AES block size in bytes. | |
| 40 | + int AES_BLOCK_SIZE = 16; | |
| 41 | + | |
| 42 | + // Valid AES key sizes in bytes. | |
| 43 | + // NOTE: The values need to be listed in an *increasing* order | |
| 44 | + // since DHKeyAgreement depends on this fact. | |
| 45 | + int[] AES_KEYSIZES = { 16, 24, 32 }; | |
| 46 | +} | |
| @@ -0,0 +1,659 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +/* $Id: Rijndael.java,v 1.6 2000/02/10 01:31:41 gelderen Exp $ | |
| 27 | + * | |
| 28 | + * Copyright (C) 1995-2000 The Cryptix Foundation Limited. | |
| 29 | + * All rights reserved. | |
| 30 | + * | |
| 31 | + * Use, modification, copying and distribution of this softwareas is subject | |
| 32 | + * the terms and conditions of the Cryptix General Licence. You should have | |
| 33 | + * received a copy of the Cryptix General Licence along with this library; | |
| 34 | + * if not, you can download a copy from http://www.cryptix.org/ . | |
| 35 | + */ | |
| 36 | + | |
| 37 | +package com.sun.crypto.provider; | |
| 38 | + | |
| 39 | +import java.security.InvalidKeyException; | |
| 40 | + | |
| 41 | +/** | |
| 42 | + * Rijndael --pronounced Reindaal-- is a symmetric cipher with a 128-bit | |
| 43 | + * block size and variable key-size (128-, 192- and 256-bit). | |
| 44 | + * <p> | |
| 45 | + * Rijndael was designed by <a href="mailto:rijmen@esat.kuleuven.ac.be">Vincent | |
| 46 | + * Rijmen</a> and <a href="mailto:Joan.Daemen@village.uunet.be">Joan Daemen</a>. | |
| 47 | + */ | |
| 48 | +final class AESCrypt extends SymmetricCipher implements AESConstants | |
| 49 | +{ | |
| 50 | + private boolean ROUNDS_12 = false; | |
| 51 | + private boolean ROUNDS_14 = false; | |
| 52 | + | |
| 53 | + /** Session and Sub keys */ | |
| 54 | + private Object[] sessionK = null; | |
| 55 | + private int[] K = null; | |
| 56 | + | |
| 57 | + /** (ROUNDS-1) * 4 */ | |
| 58 | + private int limit = 0; | |
| 59 | + | |
| 60 | + AESCrypt() { | |
| 61 | + // empty | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Returns this cipher's block size. | |
| 66 | + * | |
| 67 | + * @return this cipher's block size | |
| 68 | + */ | |
| 69 | + int getBlockSize() { | |
| 70 | + return AES_BLOCK_SIZE; | |
| 71 | + } | |
| 72 | + | |
| 73 | + void init(boolean decrypting, String algorithm, byte[] key) | |
| 74 | + throws InvalidKeyException { | |
| 75 | + if (!algorithm.equalsIgnoreCase("AES") | |
| 76 | + && !algorithm.equalsIgnoreCase("Rijndael")) { | |
| 77 | + throw new InvalidKeyException | |
| 78 | + ("Wrong algorithm: AES or Rijndael required"); | |
| 79 | + } | |
| 80 | + if (!isKeySizeValid(key.length)) { | |
| 81 | + throw new InvalidKeyException("Invalid AES key length: " + | |
| 82 | + key.length + " bytes"); | |
| 83 | + } | |
| 84 | + | |
| 85 | + // generate session key and reset sub key. | |
| 86 | + sessionK = makeKey(key); | |
| 87 | + setSubKey(decrypting); | |
| 88 | + } | |
| 89 | + | |
| 90 | + private void setSubKey(boolean decrypting) { | |
| 91 | + int[][] Kd = (int[][]) sessionK[decrypting ? 1 : 0]; | |
| 92 | + int rounds = Kd.length; | |
| 93 | + this.K = new int[rounds*4]; | |
| 94 | + for(int i=0; i<rounds; i++) { | |
| 95 | + for(int j=0; j<4; j++) { | |
| 96 | + K[i*4 + j] = Kd[i][j]; | |
| 97 | + } | |
| 98 | + } | |
| 99 | + | |
| 100 | + if (decrypting) { | |
| 101 | + int j0 = K[K.length-4]; | |
| 102 | + int j1 = K[K.length-3]; | |
| 103 | + int j2 = K[K.length-2]; | |
| 104 | + int j3 = K[K.length-1]; | |
| 105 | + | |
| 106 | + for (int i=this.K.length-1; i>3; i--) { | |
| 107 | + this.K[i] = this.K[i-4]; | |
| 108 | + } | |
| 109 | + K[0] = j0; | |
| 110 | + K[1] = j1; | |
| 111 | + K[2] = j2; | |
| 112 | + K[3] = j3; | |
| 113 | + } | |
| 114 | + | |
| 115 | + ROUNDS_12 = (rounds>=13); | |
| 116 | + ROUNDS_14 = (rounds==15); | |
| 117 | + | |
| 118 | + rounds--; | |
| 119 | + limit=rounds*4; | |
| 120 | + } | |
| 121 | + | |
| 122 | + private static int[] | |
| 123 | + alog = new int[256], | |
| 124 | + log = new int[256]; | |
| 125 | + | |
| 126 | + private static final byte[] | |
| 127 | + S = new byte[256], | |
| 128 | + Si = new byte[256]; | |
| 129 | + | |
| 130 | + private static final int[] | |
| 131 | + T1 = new int[256], | |
| 132 | + T2 = new int[256], | |
| 133 | + T3 = new int[256], | |
| 134 | + T4 = new int[256], | |
| 135 | + T5 = new int[256], | |
| 136 | + T6 = new int[256], | |
| 137 | + T7 = new int[256], | |
| 138 | + T8 = new int[256]; | |
| 139 | + | |
| 140 | + private static final int[] | |
| 141 | + U1 = new int[256], | |
| 142 | + U2 = new int[256], | |
| 143 | + U3 = new int[256], | |
| 144 | + U4 = new int[256]; | |
| 145 | + | |
| 146 | + private static final byte[] rcon = new byte[30]; | |
| 147 | + | |
| 148 | + | |
| 149 | + // Static code - to intialise S-boxes and T-boxes | |
| 150 | + static | |
| 151 | + { | |
| 152 | + int ROOT = 0x11B; | |
| 153 | + int i, j = 0; | |
| 154 | + | |
| 155 | + // | |
| 156 | + // produce log and alog tables, needed for multiplying in the | |
| 157 | + // field GF(2^m) (generator = 3) | |
| 158 | + // | |
| 159 | + alog[0] = 1; | |
| 160 | + for (i = 1; i < 256; i++) | |
| 161 | + { | |
| 162 | + j = (alog[i-1] << 1) ^ alog[i-1]; | |
| 163 | + if ((j & 0x100) != 0) { | |
| 164 | + j ^= ROOT; | |
| 165 | + } | |
| 166 | + alog[i] = j; | |
| 167 | + } | |
| 168 | + for (i = 1; i < 255; i++) { | |
| 169 | + log[alog[i]] = i; | |
| 170 | + } | |
| 171 | + byte[][] A = new byte[][] | |
| 172 | + { | |
| 173 | + {1, 1, 1, 1, 1, 0, 0, 0}, | |
| 174 | + {0, 1, 1, 1, 1, 1, 0, 0}, | |
| 175 | + {0, 0, 1, 1, 1, 1, 1, 0}, | |
| 176 | + {0, 0, 0, 1, 1, 1, 1, 1}, | |
| 177 | + {1, 0, 0, 0, 1, 1, 1, 1}, | |
| 178 | + {1, 1, 0, 0, 0, 1, 1, 1}, | |
| 179 | + {1, 1, 1, 0, 0, 0, 1, 1}, | |
| 180 | + {1, 1, 1, 1, 0, 0, 0, 1} | |
| 181 | + }; | |
| 182 | + byte[] B = new byte[] { 0, 1, 1, 0, 0, 0, 1, 1}; | |
| 183 | + | |
| 184 | + // | |
| 185 | + // substitution box based on F^{-1}(x) | |
| 186 | + // | |
| 187 | + int t; | |
| 188 | + byte[][] box = new byte[256][8]; | |
| 189 | + box[1][7] = 1; | |
| 190 | + for (i = 2; i < 256; i++) { | |
| 191 | + j = alog[255 - log[i]]; | |
| 192 | + for (t = 0; t < 8; t++) { | |
| 193 | + box[i][t] = (byte)((j >>> (7 - t)) & 0x01); | |
| 194 | + } | |
| 195 | + } | |
| 196 | + // | |
| 197 | + // affine transform: box[i] <- B + A*box[i] | |
| 198 | + // | |
| 199 | + byte[][] cox = new byte[256][8]; | |
| 200 | + for (i = 0; i < 256; i++) { | |
| 201 | + for (t = 0; t < 8; t++) { | |
| 202 | + cox[i][t] = B[t]; | |
| 203 | + for (j = 0; j < 8; j++) { | |
| 204 | + cox[i][t] ^= A[t][j] * box[i][j]; | |
| 205 | + } | |
| 206 | + } | |
| 207 | + } | |
| 208 | + // | |
| 209 | + // S-boxes and inverse S-boxes | |
| 210 | + // | |
| 211 | + for (i = 0; i < 256; i++) { | |
| 212 | + S[i] = (byte)(cox[i][0] << 7); | |
| 213 | + for (t = 1; t < 8; t++) { | |
| 214 | + S[i] ^= cox[i][t] << (7-t); | |
| 215 | + } | |
| 216 | + Si[S[i] & 0xFF] = (byte) i; | |
| 217 | + } | |
| 218 | + // | |
| 219 | + // T-boxes | |
| 220 | + // | |
| 221 | + byte[][] G = new byte[][] { | |
| 222 | + {2, 1, 1, 3}, | |
| 223 | + {3, 2, 1, 1}, | |
| 224 | + {1, 3, 2, 1}, | |
| 225 | + {1, 1, 3, 2} | |
| 226 | + }; | |
| 227 | + byte[][] AA = new byte[4][8]; | |
| 228 | + for (i = 0; i < 4; i++) { | |
| 229 | + for (j = 0; j < 4; j++) AA[i][j] = G[i][j]; | |
| 230 | + AA[i][i+4] = 1; | |
| 231 | + } | |
| 232 | + byte pivot, tmp; | |
| 233 | + byte[][] iG = new byte[4][4]; | |
| 234 | + for (i = 0; i < 4; i++) { | |
| 235 | + pivot = AA[i][i]; | |
| 236 | + if (pivot == 0) { | |
| 237 | + t = i + 1; | |
| 238 | + while ((AA[t][i] == 0) && (t < 4)) { | |
| 239 | + t++; | |
| 240 | + } | |
| 241 | + if (t == 4) { | |
| 242 | + throw new RuntimeException("G matrix is not invertible"); | |
| 243 | + } | |
| 244 | + else { | |
| 245 | + for (j = 0; j < 8; j++) { | |
| 246 | + tmp = AA[i][j]; | |
| 247 | + AA[i][j] = AA[t][j]; | |
| 248 | + AA[t][j] = (byte) tmp; | |
| 249 | + } | |
| 250 | + pivot = AA[i][i]; | |
| 251 | + } | |
| 252 | + } | |
| 253 | + for (j = 0; j < 8; j++) { | |
| 254 | + if (AA[i][j] != 0) { | |
| 255 | + AA[i][j] = (byte) | |
| 256 | + alog[(255 + log[AA[i][j] & 0xFF] - log[pivot & 0xFF]) | |
| 257 | + % 255]; | |
| 258 | + } | |
| 259 | + } | |
| 260 | + for (t = 0; t < 4; t++) { | |
| 261 | + if (i != t) { | |
| 262 | + for (j = i+1; j < 8; j++) { | |
| 263 | + AA[t][j] ^= mul(AA[i][j], AA[t][i]); | |
| 264 | + } | |
| 265 | + AA[t][i] = 0; | |
| 266 | + } | |
| 267 | + } | |
| 268 | + } | |
| 269 | + for (i = 0; i < 4; i++) { | |
| 270 | + for (j = 0; j < 4; j++) { | |
| 271 | + iG[i][j] = AA[i][j + 4]; | |
| 272 | + } | |
| 273 | + } | |
| 274 | + | |
| 275 | + int s; | |
| 276 | + for (t = 0; t < 256; t++) { | |
| 277 | + s = S[t]; | |
| 278 | + T1[t] = mul4(s, G[0]); | |
| 279 | + T2[t] = mul4(s, G[1]); | |
| 280 | + T3[t] = mul4(s, G[2]); | |
| 281 | + T4[t] = mul4(s, G[3]); | |
| 282 | + | |
| 283 | + s = Si[t]; | |
| 284 | + T5[t] = mul4(s, iG[0]); | |
| 285 | + T6[t] = mul4(s, iG[1]); | |
| 286 | + T7[t] = mul4(s, iG[2]); | |
| 287 | + T8[t] = mul4(s, iG[3]); | |
| 288 | + | |
| 289 | + U1[t] = mul4(t, iG[0]); | |
| 290 | + U2[t] = mul4(t, iG[1]); | |
| 291 | + U3[t] = mul4(t, iG[2]); | |
| 292 | + U4[t] = mul4(t, iG[3]); | |
| 293 | + } | |
| 294 | + // | |
| 295 | + // round constants | |
| 296 | + // | |
| 297 | + rcon[0] = 1; | |
| 298 | + int r = 1; | |
| 299 | + for (t = 1; t < 30; t++) { | |
| 300 | + r = mul(2, r); | |
| 301 | + rcon[t] = (byte) r; | |
| 302 | + } | |
| 303 | + log = null; | |
| 304 | + alog = null; | |
| 305 | + } | |
| 306 | + | |
| 307 | + // multiply two elements of GF(2^m) | |
| 308 | + private static final int mul (int a, int b) { | |
| 309 | + return (a != 0 && b != 0) ? | |
| 310 | + alog[(log[a & 0xFF] + log[b & 0xFF]) % 255] : | |
| 311 | + 0; | |
| 312 | + } | |
| 313 | + | |
| 314 | + // convenience method used in generating Transposition boxes | |
| 315 | + private static final int mul4 (int a, byte[] b) { | |
| 316 | + if (a == 0) return 0; | |
| 317 | + a = log[a & 0xFF]; | |
| 318 | + int a0 = (b[0] != 0) ? alog[(a + log[b[0] & 0xFF]) % 255] & 0xFF : 0; | |
| 319 | + int a1 = (b[1] != 0) ? alog[(a + log[b[1] & 0xFF]) % 255] & 0xFF : 0; | |
| 320 | + int a2 = (b[2] != 0) ? alog[(a + log[b[2] & 0xFF]) % 255] & 0xFF : 0; | |
| 321 | + int a3 = (b[3] != 0) ? alog[(a + log[b[3] & 0xFF]) % 255] & 0xFF : 0; | |
| 322 | + return a0 << 24 | a1 << 16 | a2 << 8 | a3; | |
| 323 | + } | |
| 324 | + | |
| 325 | + // check if the specified length (in bytes) is a valid keysize for AES | |
| 326 | + static final boolean isKeySizeValid(int len) { | |
| 327 | + for (int i = 0; i < AES_KEYSIZES.length; i++) { | |
| 328 | + if (len == AES_KEYSIZES[i]) { | |
| 329 | + return true; | |
| 330 | + } | |
| 331 | + } | |
| 332 | + return false; | |
| 333 | + } | |
| 334 | + | |
| 335 | + /** | |
| 336 | + * Encrypt exactly one block of plaintext. | |
| 337 | + */ | |
| 338 | + void encryptBlock(byte[] in, int inOffset, | |
| 339 | + byte[] out, int outOffset) | |
| 340 | + { | |
| 341 | + int keyOffset = 0; | |
| 342 | + int t0 = ((in[inOffset++] ) << 24 | | |
| 343 | + (in[inOffset++] & 0xFF) << 16 | | |
| 344 | + (in[inOffset++] & 0xFF) << 8 | | |
| 345 | + (in[inOffset++] & 0xFF) ) ^ K[keyOffset++]; | |
| 346 | + int t1 = ((in[inOffset++] ) << 24 | | |
| 347 | + (in[inOffset++] & 0xFF) << 16 | | |
| 348 | + (in[inOffset++] & 0xFF) << 8 | | |
| 349 | + (in[inOffset++] & 0xFF) ) ^ K[keyOffset++]; | |
| 350 | + int t2 = ((in[inOffset++] ) << 24 | | |
| 351 | + (in[inOffset++] & 0xFF) << 16 | | |
| 352 | + (in[inOffset++] & 0xFF) << 8 | | |
| 353 | + (in[inOffset++] & 0xFF) ) ^ K[keyOffset++]; | |
| 354 | + int t3 = ((in[inOffset++] ) << 24 | | |
| 355 | + (in[inOffset++] & 0xFF) << 16 | | |
| 356 | + (in[inOffset++] & 0xFF) << 8 | | |
| 357 | + (in[inOffset++] & 0xFF) ) ^ K[keyOffset++]; | |
| 358 | + | |
| 359 | + // apply round transforms | |
| 360 | + while( keyOffset < limit ) | |
| 361 | + { | |
| 362 | + int a0, a1, a2; | |
| 363 | + a0 = T1[(t0 >>> 24) ] ^ | |
| 364 | + T2[(t1 >>> 16) & 0xFF] ^ | |
| 365 | + T3[(t2 >>> 8) & 0xFF] ^ | |
| 366 | + T4[(t3 ) & 0xFF] ^ K[keyOffset++]; | |
| 367 | + a1 = T1[(t1 >>> 24) ] ^ | |
| 368 | + T2[(t2 >>> 16) & 0xFF] ^ | |
| 369 | + T3[(t3 >>> 8) & 0xFF] ^ | |
| 370 | + T4[(t0 ) & 0xFF] ^ K[keyOffset++]; | |
| 371 | + a2 = T1[(t2 >>> 24) ] ^ | |
| 372 | + T2[(t3 >>> 16) & 0xFF] ^ | |
| 373 | + T3[(t0 >>> 8) & 0xFF] ^ | |
| 374 | + T4[(t1 ) & 0xFF] ^ K[keyOffset++]; | |
| 375 | + t3 = T1[(t3 >>> 24) ] ^ | |
| 376 | + T2[(t0 >>> 16) & 0xFF] ^ | |
| 377 | + T3[(t1 >>> 8) & 0xFF] ^ | |
| 378 | + T4[(t2 ) & 0xFF] ^ K[keyOffset++]; | |
| 379 | + t0 = a0; t1 = a1; t2 = a2; | |
| 380 | + } | |
| 381 | + | |
| 382 | + // last round is special | |
| 383 | + int tt = K[keyOffset++]; | |
| 384 | + out[outOffset++] = (byte)(S[(t0 >>> 24) ] ^ (tt >>> 24)); | |
| 385 | + out[outOffset++] = (byte)(S[(t1 >>> 16) & 0xFF] ^ (tt >>> 16)); | |
| 386 | + out[outOffset++] = (byte)(S[(t2 >>> 8) & 0xFF] ^ (tt >>> 8)); | |
| 387 | + out[outOffset++] = (byte)(S[(t3 ) & 0xFF] ^ (tt )); | |
| 388 | + tt = K[keyOffset++]; | |
| 389 | + out[outOffset++] = (byte)(S[(t1 >>> 24) ] ^ (tt >>> 24)); | |
| 390 | + out[outOffset++] = (byte)(S[(t2 >>> 16) & 0xFF] ^ (tt >>> 16)); | |
| 391 | + out[outOffset++] = (byte)(S[(t3 >>> 8) & 0xFF] ^ (tt >>> 8)); | |
| 392 | + out[outOffset++] = (byte)(S[(t0 ) & 0xFF] ^ (tt )); | |
| 393 | + tt = K[keyOffset++]; | |
| 394 | + out[outOffset++] = (byte)(S[(t2 >>> 24) ] ^ (tt >>> 24)); | |
| 395 | + out[outOffset++] = (byte)(S[(t3 >>> 16) & 0xFF] ^ (tt >>> 16)); | |
| 396 | + out[outOffset++] = (byte)(S[(t0 >>> 8) & 0xFF] ^ (tt >>> 8)); | |
| 397 | + out[outOffset++] = (byte)(S[(t1 ) & 0xFF] ^ (tt )); | |
| 398 | + tt = K[keyOffset++]; | |
| 399 | + out[outOffset++] = (byte)(S[(t3 >>> 24) ] ^ (tt >>> 24)); | |
| 400 | + out[outOffset++] = (byte)(S[(t0 >>> 16) & 0xFF] ^ (tt >>> 16)); | |
| 401 | + out[outOffset++] = (byte)(S[(t1 >>> 8) & 0xFF] ^ (tt >>> 8)); | |
| 402 | + out[outOffset ] = (byte)(S[(t2 ) & 0xFF] ^ (tt )); | |
| 403 | + } | |
| 404 | + | |
| 405 | + | |
| 406 | + /** | |
| 407 | + * Decrypt exactly one block of plaintext. | |
| 408 | + */ | |
| 409 | + void decryptBlock(byte[] in, int inOffset, | |
| 410 | + byte[] out, int outOffset) | |
| 411 | + { | |
| 412 | + int keyOffset = 4; | |
| 413 | + int t0 = ((in[inOffset++] ) << 24 | | |
| 414 | + (in[inOffset++] & 0xFF) << 16 | | |
| 415 | + (in[inOffset++] & 0xFF) << 8 | | |
| 416 | + (in[inOffset++] & 0xFF) ) ^ K[keyOffset++]; | |
| 417 | + int t1 = ((in[inOffset++] ) << 24 | | |
| 418 | + (in[inOffset++] & 0xFF) << 16 | | |
| 419 | + (in[inOffset++] & 0xFF) << 8 | | |
| 420 | + (in[inOffset++] & 0xFF) ) ^ K[keyOffset++]; | |
| 421 | + int t2 = ((in[inOffset++] ) << 24 | | |
| 422 | + (in[inOffset++] & 0xFF) << 16 | | |
| 423 | + (in[inOffset++] & 0xFF) << 8 | | |
| 424 | + (in[inOffset++] & 0xFF) ) ^ K[keyOffset++]; | |
| 425 | + int t3 = ((in[inOffset++] ) << 24 | | |
| 426 | + (in[inOffset++] & 0xFF) << 16 | | |
| 427 | + (in[inOffset++] & 0xFF) << 8 | | |
| 428 | + (in[inOffset ] & 0xFF) ) ^ K[keyOffset++]; | |
| 429 | + | |
| 430 | + int a0, a1, a2; | |
| 431 | + if(ROUNDS_12) | |
| 432 | + { | |
| 433 | + a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 434 | + T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++]; | |
| 435 | + a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^ | |
| 436 | + T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++]; | |
| 437 | + a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^ | |
| 438 | + T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 439 | + t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^ | |
| 440 | + T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++]; | |
| 441 | + t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 442 | + T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++]; | |
| 443 | + t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^ | |
| 444 | + T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++]; | |
| 445 | + t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^ | |
| 446 | + T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 447 | + t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^ | |
| 448 | + T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++]; | |
| 449 | + | |
| 450 | + if(ROUNDS_14) | |
| 451 | + { | |
| 452 | + a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 453 | + T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++]; | |
| 454 | + a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^ | |
| 455 | + T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++]; | |
| 456 | + a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^ | |
| 457 | + T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 458 | + t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^ | |
| 459 | + T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++]; | |
| 460 | + t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 461 | + T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++]; | |
| 462 | + t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^ | |
| 463 | + T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++]; | |
| 464 | + t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^ | |
| 465 | + T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 466 | + t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^ | |
| 467 | + T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++]; | |
| 468 | + } | |
| 469 | + } | |
| 470 | + a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 471 | + T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++]; | |
| 472 | + a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^ | |
| 473 | + T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++]; | |
| 474 | + a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^ | |
| 475 | + T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 476 | + t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^ | |
| 477 | + T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++]; | |
| 478 | + t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 479 | + T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++]; | |
| 480 | + t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^ | |
| 481 | + T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++]; | |
| 482 | + t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^ | |
| 483 | + T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 484 | + t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^ | |
| 485 | + T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++]; | |
| 486 | + a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 487 | + T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++]; | |
| 488 | + a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^ | |
| 489 | + T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++]; | |
| 490 | + a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^ | |
| 491 | + T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 492 | + t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^ | |
| 493 | + T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++]; | |
| 494 | + t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 495 | + T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++]; | |
| 496 | + t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^ | |
| 497 | + T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++]; | |
| 498 | + t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^ | |
| 499 | + T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 500 | + t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^ | |
| 501 | + T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++]; | |
| 502 | + a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 503 | + T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++]; | |
| 504 | + a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^ | |
| 505 | + T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++]; | |
| 506 | + a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^ | |
| 507 | + T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 508 | + t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^ | |
| 509 | + T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++]; | |
| 510 | + t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 511 | + T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++]; | |
| 512 | + t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^ | |
| 513 | + T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++]; | |
| 514 | + t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^ | |
| 515 | + T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 516 | + t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^ | |
| 517 | + T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++]; | |
| 518 | + a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 519 | + T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++]; | |
| 520 | + a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^ | |
| 521 | + T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++]; | |
| 522 | + a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^ | |
| 523 | + T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 524 | + t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^ | |
| 525 | + T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++]; | |
| 526 | + t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 527 | + T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++]; | |
| 528 | + t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^ | |
| 529 | + T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++]; | |
| 530 | + t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^ | |
| 531 | + T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 532 | + t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^ | |
| 533 | + T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++]; | |
| 534 | + a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^ | |
| 535 | + T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++]; | |
| 536 | + a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^ | |
| 537 | + T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++]; | |
| 538 | + a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^ | |
| 539 | + T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++]; | |
| 540 | + t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^ | |
| 541 | + T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++]; | |
| 542 | + | |
| 543 | + t1 = K[0]; | |
| 544 | + out[outOffset++] = (byte)(Si[(a0 >>> 24) ] ^ (t1 >>> 24)); | |
| 545 | + out[outOffset++] = (byte)(Si[(t3 >>> 16) & 0xFF] ^ (t1 >>> 16)); | |
| 546 | + out[outOffset++] = (byte)(Si[(a2 >>> 8) & 0xFF] ^ (t1 >>> 8)); | |
| 547 | + out[outOffset++] = (byte)(Si[(a1 ) & 0xFF] ^ (t1 )); | |
| 548 | + t1 = K[1]; | |
| 549 | + out[outOffset++] = (byte)(Si[(a1 >>> 24) ] ^ (t1 >>> 24)); | |
| 550 | + out[outOffset++] = (byte)(Si[(a0 >>> 16) & 0xFF] ^ (t1 >>> 16)); | |
| 551 | + out[outOffset++] = (byte)(Si[(t3 >>> 8) & 0xFF] ^ (t1 >>> 8)); | |
| 552 | + out[outOffset++] = (byte)(Si[(a2 ) & 0xFF] ^ (t1 )); | |
| 553 | + t1 = K[2]; | |
| 554 | + out[outOffset++] = (byte)(Si[(a2 >>> 24) ] ^ (t1 >>> 24)); | |
| 555 | + out[outOffset++] = (byte)(Si[(a1 >>> 16) & 0xFF] ^ (t1 >>> 16)); | |
| 556 | + out[outOffset++] = (byte)(Si[(a0 >>> 8) & 0xFF] ^ (t1 >>> 8)); | |
| 557 | + out[outOffset++] = (byte)(Si[(t3 ) & 0xFF] ^ (t1 )); | |
| 558 | + t1 = K[3]; | |
| 559 | + out[outOffset++] = (byte)(Si[(t3 >>> 24) ] ^ (t1 >>> 24)); | |
| 560 | + out[outOffset++] = (byte)(Si[(a2 >>> 16) & 0xFF] ^ (t1 >>> 16)); | |
| 561 | + out[outOffset++] = (byte)(Si[(a1 >>> 8) & 0xFF] ^ (t1 >>> 8)); | |
| 562 | + out[outOffset ] = (byte)(Si[(a0 ) & 0xFF] ^ (t1 )); | |
| 563 | + } | |
| 564 | + | |
| 565 | + | |
| 566 | + /** | |
| 567 | + * Expand a user-supplied key material into a session key. | |
| 568 | + * | |
| 569 | + * @param key The 128/192/256-bit user-key to use. | |
| 570 | + * @exception InvalidKeyException If the key is invalid. | |
| 571 | + */ | |
| 572 | + private static Object[] makeKey(byte[] k) throws InvalidKeyException { | |
| 573 | + if (k == null) { | |
| 574 | + throw new InvalidKeyException("Empty key"); | |
| 575 | + } | |
| 576 | + if (!isKeySizeValid(k.length)) { | |
| 577 | + throw new InvalidKeyException("Invalid AES key length: " + | |
| 578 | + k.length + " bytes"); | |
| 579 | + } | |
| 580 | + int ROUNDS = getRounds(k.length); | |
| 581 | + int ROUND_KEY_COUNT = (ROUNDS + 1) * 4; | |
| 582 | + | |
| 583 | + int BC = 4; | |
| 584 | + int[][] Ke = new int[ROUNDS + 1][4]; // encryption round keys | |
| 585 | + int[][] Kd = new int[ROUNDS + 1][4]; // decryption round keys | |
| 586 | + | |
| 587 | + int KC = k.length/4; // keylen in 32-bit elements | |
| 588 | + | |
| 589 | + int[] tk = new int[KC]; | |
| 590 | + int i, j; | |
| 591 | + | |
| 592 | + // copy user material bytes into temporary ints | |
| 593 | + for (i = 0, j = 0; i < KC; i++, j+=4) { | |
| 594 | + tk[i] = (k[j] ) << 24 | | |
| 595 | + (k[j+1] & 0xFF) << 16 | | |
| 596 | + (k[j+2] & 0xFF) << 8 | | |
| 597 | + (k[j+3] & 0xFF); | |
| 598 | + } | |
| 599 | + | |
| 600 | + // copy values into round key arrays | |
| 601 | + int t = 0; | |
| 602 | + for (j = 0; (j < KC) && (t < ROUND_KEY_COUNT); j++, t++) { | |
| 603 | + Ke[t / 4][t % 4] = tk[j]; | |
| 604 | + Kd[ROUNDS - (t / 4)][t % 4] = tk[j]; | |
| 605 | + } | |
| 606 | + int tt, rconpointer = 0; | |
| 607 | + while (t < ROUND_KEY_COUNT) { | |
| 608 | + // extrapolate using phi (the round key evolution function) | |
| 609 | + tt = tk[KC - 1]; | |
| 610 | + tk[0] ^= (S[(tt >>> 16) & 0xFF] ) << 24 ^ | |
| 611 | + (S[(tt >>> 8) & 0xFF] & 0xFF) << 16 ^ | |
| 612 | + (S[(tt ) & 0xFF] & 0xFF) << 8 ^ | |
| 613 | + (S[(tt >>> 24) ] & 0xFF) ^ | |
| 614 | + (rcon[rconpointer++] ) << 24; | |
| 615 | + if (KC != 8) | |
| 616 | + for (i = 1, j = 0; i < KC; i++, j++) tk[i] ^= tk[j]; | |
| 617 | + else { | |
| 618 | + for (i = 1, j = 0; i < KC / 2; i++, j++) tk[i] ^= tk[j]; | |
| 619 | + tt = tk[KC / 2 - 1]; | |
| 620 | + tk[KC / 2] ^= (S[(tt ) & 0xFF] & 0xFF) ^ | |
| 621 | + (S[(tt >>> 8) & 0xFF] & 0xFF) << 8 ^ | |
| 622 | + (S[(tt >>> 16) & 0xFF] & 0xFF) << 16 ^ | |
| 623 | + (S[(tt >>> 24) ] ) << 24; | |
| 624 | + for (j = KC / 2, i = j + 1; i < KC; i++, j++) tk[i] ^= tk[j]; | |
| 625 | + } | |
| 626 | + // copy values into round key arrays | |
| 627 | + for (j = 0; (j < KC) && (t < ROUND_KEY_COUNT); j++, t++) { | |
| 628 | + Ke[t / 4][t % 4] = tk[j]; | |
| 629 | + Kd[ROUNDS - (t / 4)][t % 4] = tk[j]; | |
| 630 | + } | |
| 631 | + } | |
| 632 | + for (int r = 1; r < ROUNDS; r++) { | |
| 633 | + // inverse MixColumn where needed | |
| 634 | + for (j = 0; j < BC; j++) { | |
| 635 | + tt = Kd[r][j]; | |
| 636 | + Kd[r][j] = U1[(tt >>> 24) & 0xFF] ^ | |
| 637 | + U2[(tt >>> 16) & 0xFF] ^ | |
| 638 | + U3[(tt >>> 8) & 0xFF] ^ | |
| 639 | + U4[ tt & 0xFF]; | |
| 640 | + } | |
| 641 | + } | |
| 642 | + // assemble the encryption (Ke) and decryption (Kd) round keys into | |
| 643 | + // one sessionKey object | |
| 644 | + Object[] result = new Object[] {Ke, Kd}; | |
| 645 | + return result; | |
| 646 | + } | |
| 647 | + | |
| 648 | + | |
| 649 | + /** | |
| 650 | + * Return The number of rounds for a given Rijndael keysize. | |
| 651 | + * | |
| 652 | + * @param keySize The size of the user key material in bytes. | |
| 653 | + * MUST be one of (16, 24, 32). | |
| 654 | + * @return The number of rounds. | |
| 655 | + */ | |
| 656 | + private static int getRounds(int keySize) { | |
| 657 | + return (keySize >> 2) + 6; | |
| 658 | + } | |
| 659 | +} | |
| @@ -0,0 +1,117 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.security.SecureRandom; | |
| 29 | +import java.security.InvalidParameterException; | |
| 30 | +import java.security.InvalidAlgorithmParameterException; | |
| 31 | +import java.security.InvalidKeyException; | |
| 32 | +import java.security.spec.AlgorithmParameterSpec; | |
| 33 | +import javax.crypto.KeyGeneratorSpi; | |
| 34 | +import javax.crypto.SecretKey; | |
| 35 | +import javax.crypto.spec.SecretKeySpec; | |
| 36 | + | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * This class generates a AES key. | |
| 40 | + * | |
| 41 | + * @author Valerie Peng | |
| 42 | + * | |
| 43 | + */ | |
| 44 | + | |
| 45 | +public final class AESKeyGenerator extends KeyGeneratorSpi { | |
| 46 | + | |
| 47 | + private SecureRandom random = null; | |
| 48 | + private int keySize = 16; // default keysize (in number of bytes) | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Empty constructor. | |
| 52 | + */ | |
| 53 | + public AESKeyGenerator() { | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Initializes this key generator. | |
| 58 | + * | |
| 59 | + * @param random the source of randomness for this generator | |
| 60 | + */ | |
| 61 | + protected void engineInit(SecureRandom random) { | |
| 62 | + this.random = random; | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Initializes this key generator with the specified parameter | |
| 67 | + * set and a user-provided source of randomness. | |
| 68 | + * | |
| 69 | + * @param params the key generation parameters | |
| 70 | + * @param random the source of randomness for this key generator | |
| 71 | + * | |
| 72 | + * @exception InvalidAlgorithmParameterException if <code>params</code> is | |
| 73 | + * inappropriate for this key generator | |
| 74 | + */ | |
| 75 | + protected void engineInit(AlgorithmParameterSpec params, | |
| 76 | + SecureRandom random) | |
| 77 | + throws InvalidAlgorithmParameterException { | |
| 78 | + throw new InvalidAlgorithmParameterException | |
| 79 | + ("AES key generation does not take any parameters"); | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Initializes this key generator for a certain keysize, using the given | |
| 84 | + * source of randomness. | |
| 85 | + * | |
| 86 | + * @param keysize the keysize. This is an algorithm-specific | |
| 87 | + * metric specified in number of bits. | |
| 88 | + * @param random the source of randomness for this key generator | |
| 89 | + */ | |
| 90 | + protected void engineInit(int keysize, SecureRandom random) { | |
| 91 | + if (((keysize % 8) != 0) || | |
| 92 | + (!AESCrypt.isKeySizeValid(keysize/8))) { | |
| 93 | + throw new InvalidParameterException | |
| 94 | + ("Wrong keysize: must be equal to 128, 192 or 256"); | |
| 95 | + } | |
| 96 | + this.keySize = keysize/8; | |
| 97 | + this.engineInit(random); | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Generates the AES key. | |
| 102 | + * | |
| 103 | + * @return the new AES key | |
| 104 | + */ | |
| 105 | + protected SecretKey engineGenerateKey() { | |
| 106 | + SecretKeySpec aesKey = null; | |
| 107 | + | |
| 108 | + if (this.random == null) { | |
| 109 | + this.random = SunJCE.RANDOM; | |
| 110 | + } | |
| 111 | + | |
| 112 | + byte[] keyBytes = new byte[keySize]; | |
| 113 | + this.random.nextBytes(keyBytes); | |
| 114 | + aesKey = new SecretKeySpec(keyBytes, "AES"); | |
| 115 | + return aesKey; | |
| 116 | + } | |
| 117 | +} | |
| @@ -0,0 +1,87 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.util.*; | |
| 29 | +import java.io.*; | |
| 30 | +import sun.security.util.*; | |
| 31 | +import java.security.AlgorithmParametersSpi; | |
| 32 | +import java.security.spec.AlgorithmParameterSpec; | |
| 33 | +import java.security.spec.InvalidParameterSpecException; | |
| 34 | +import javax.crypto.spec.IvParameterSpec; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * This class implements the parameter (IV) used with the AES algorithm | |
| 38 | + * in feedback-mode. IV is defined in the standards as follows: | |
| 39 | + * | |
| 40 | + * <pre> | |
| 41 | + * IV ::= OCTET STRING -- 16 octets | |
| 42 | + * </pre> | |
| 43 | + * | |
| 44 | + * @author Valerie Peng | |
| 45 | + * | |
| 46 | + */ | |
| 47 | +public final class AESParameters extends AlgorithmParametersSpi { | |
| 48 | + | |
| 49 | + private BlockCipherParamsCore core; | |
| 50 | + | |
| 51 | + public AESParameters() { | |
| 52 | + core = new BlockCipherParamsCore(AESConstants.AES_BLOCK_SIZE); | |
| 53 | + } | |
| 54 | + | |
| 55 | + protected void engineInit(AlgorithmParameterSpec paramSpec) | |
| 56 | + throws InvalidParameterSpecException { | |
| 57 | + core.init(paramSpec); | |
| 58 | + } | |
| 59 | + | |
| 60 | + protected void engineInit(byte[] encoded) | |
| 61 | + throws IOException { | |
| 62 | + core.init(encoded); | |
| 63 | + } | |
| 64 | + | |
| 65 | + protected void engineInit(byte[] encoded, String decodingMethod) | |
| 66 | + throws IOException { | |
| 67 | + core.init(encoded, decodingMethod); | |
| 68 | + } | |
| 69 | + | |
| 70 | + protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) | |
| 71 | + throws InvalidParameterSpecException { | |
| 72 | + return core.getParameterSpec(paramSpec); | |
| 73 | + } | |
| 74 | + | |
| 75 | + protected byte[] engineGetEncoded() throws IOException { | |
| 76 | + return core.getEncoded(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + protected byte[] engineGetEncoded(String encodingMethod) | |
| 80 | + throws IOException { | |
| 81 | + return core.getEncoded(); | |
| 82 | + } | |
| 83 | + | |
| 84 | + protected String engineToString() { | |
| 85 | + return core.toString(); | |
| 86 | + } | |
| 87 | +} | |
| @@ -0,0 +1,483 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.util.Arrays; | |
| 29 | +import java.security.*; | |
| 30 | +import java.security.spec.*; | |
| 31 | +import javax.crypto.*; | |
| 32 | +import javax.crypto.spec.*; | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * This class implements the AES KeyWrap algorithm as defined | |
| 36 | + * in <a href=http://www.w3.org/TR/xmlenc-core/#sec-Alg-SymmetricKeyWrap> | |
| 37 | + * "XML Encryption Syntax and Processing" section 5.6.3 "AES Key Wrap". | |
| 38 | + * Note: only <code>ECB</code> mode and <code>NoPadding</code> padding | |
| 39 | + * can be used for this algorithm. | |
| 40 | + * | |
| 41 | + * @author Valerie Peng | |
| 42 | + * | |
| 43 | + * | |
| 44 | + * @see AESCipher | |
| 45 | + */ | |
| 46 | +public final class AESWrapCipher extends CipherSpi { | |
| 47 | + | |
| 48 | + private static final byte[] IV = { | |
| 49 | + (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, | |
| 50 | + (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6 | |
| 51 | + }; | |
| 52 | + | |
| 53 | + private static final int blksize = AESConstants.AES_BLOCK_SIZE; | |
| 54 | + | |
| 55 | + /* | |
| 56 | + * internal cipher object which does the real work. | |
| 57 | + */ | |
| 58 | + private AESCrypt cipher; | |
| 59 | + | |
| 60 | + /* | |
| 61 | + * are we encrypting or decrypting? | |
| 62 | + */ | |
| 63 | + private boolean decrypting = false; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Creates an instance of AES KeyWrap cipher with default | |
| 67 | + * mode, i.e. "ECB" and padding scheme, i.e. "NoPadding". | |
| 68 | + */ | |
| 69 | + public AESWrapCipher() { | |
| 70 | + cipher = new AESCrypt(); | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Sets the mode of this cipher. Only "ECB" mode is accepted for this | |
| 75 | + * cipher. | |
| 76 | + * | |
| 77 | + * @param mode the cipher mode | |
| 78 | + * | |
| 79 | + * @exception NoSuchAlgorithmException if the requested cipher mode | |
| 80 | + * is not "ECB". | |
| 81 | + */ | |
| 82 | + protected void engineSetMode(String mode) | |
| 83 | + throws NoSuchAlgorithmException { | |
| 84 | + if (!mode.equalsIgnoreCase("ECB")) { | |
| 85 | + throw new NoSuchAlgorithmException(mode + " cannot be used"); | |
| 86 | + } | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Sets the padding mechanism of this cipher. Only "NoPadding" schmem | |
| 91 | + * is accepted for this cipher. | |
| 92 | + * | |
| 93 | + * @param padding the padding mechanism | |
| 94 | + * | |
| 95 | + * @exception NoSuchPaddingException if the requested padding mechanism | |
| 96 | + * is not "NoPadding". | |
| 97 | + */ | |
| 98 | + protected void engineSetPadding(String padding) | |
| 99 | + throws NoSuchPaddingException { | |
| 100 | + if (!padding.equalsIgnoreCase("NoPadding")) { | |
| 101 | + throw new NoSuchPaddingException(padding + " cannot be used"); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Returns the block size (in bytes). i.e. 16 bytes. | |
| 107 | + * | |
| 108 | + * @return the block size (in bytes), i.e. 16 bytes. | |
| 109 | + */ | |
| 110 | + protected int engineGetBlockSize() { | |
| 111 | + return blksize; | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Returns the length in bytes that an output buffer would need to be | |
| 116 | + * given the input length <code>inputLen</code> (in bytes). | |
| 117 | + * | |
| 118 | + * <p>The actual output length of the next <code>update</code> or | |
| 119 | + * <code>doFinal</code> call may be smaller than the length returned | |
| 120 | + * by this method. | |
| 121 | + * | |
| 122 | + * @param inputLen the input length (in bytes) | |
| 123 | + * | |
| 124 | + * @return the required output buffer size (in bytes) | |
| 125 | + */ | |
| 126 | + protected int engineGetOutputSize(int inputLen) { | |
| 127 | + // can only return an upper-limit if not initialized yet. | |
| 128 | + int result = 0; | |
| 129 | + if (decrypting) { | |
| 130 | + result = inputLen - 8; | |
| 131 | + } else { | |
| 132 | + result = inputLen + 8; | |
| 133 | + } | |
| 134 | + return (result < 0? 0:result); | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * Returns the initialization vector (IV) which is null for this cipher. | |
| 139 | + * | |
| 140 | + * @return null for this cipher. | |
| 141 | + */ | |
| 142 | + protected byte[] engineGetIV() { | |
| 143 | + return null; | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Initializes this cipher with a key and a source of randomness. | |
| 148 | + * | |
| 149 | + * <p>The cipher only supports the following two operation modes:<b> | |
| 150 | + * Cipher.WRAP_MODE, and <b> | |
| 151 | + * Cipher.UNWRAP_MODE. | |
| 152 | + * <p>For modes other than the above two, UnsupportedOperationException | |
| 153 | + * will be thrown. | |
| 154 | + * | |
| 155 | + * @param opmode the operation mode of this cipher. Only | |
| 156 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) are accepted. | |
| 157 | + * @param key the secret key. | |
| 158 | + * @param random the source of randomness. | |
| 159 | + * | |
| 160 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 161 | + * initializing this cipher. | |
| 162 | + */ | |
| 163 | + protected void engineInit(int opmode, Key key, SecureRandom random) | |
| 164 | + throws InvalidKeyException { | |
| 165 | + if (opmode == Cipher.WRAP_MODE) { | |
| 166 | + decrypting = false; | |
| 167 | + } else if (opmode == Cipher.UNWRAP_MODE) { | |
| 168 | + decrypting = true; | |
| 169 | + } else { | |
| 170 | + throw new UnsupportedOperationException("This cipher can " + | |
| 171 | + "only be used for key wrapping and unwrapping"); | |
| 172 | + } | |
| 173 | + cipher.init(decrypting, key.getAlgorithm(), key.getEncoded()); | |
| 174 | + } | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Initializes this cipher with a key, a set of algorithm parameters, | |
| 178 | + * and a source of randomness. | |
| 179 | + * | |
| 180 | + * <p>The cipher only supports the following two operation modes:<b> | |
| 181 | + * Cipher.WRAP_MODE, and <b> | |
| 182 | + * Cipher.UNWRAP_MODE. | |
| 183 | + * <p>For modes other than the above two, UnsupportedOperationException | |
| 184 | + * will be thrown. | |
| 185 | + * | |
| 186 | + * @param opmode the operation mode of this cipher. Only | |
| 187 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) are accepted. | |
| 188 | + * @param key the secret key. | |
| 189 | + * @param params the algorithm parameters; must be null for this cipher. | |
| 190 | + * @param random the source of randomness. | |
| 191 | + * | |
| 192 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 193 | + * initializing this cipher | |
| 194 | + * @exception InvalidAlgorithmParameterException if the given algorithm | |
| 195 | + * parameters is not null. | |
| 196 | + */ | |
| 197 | + protected void engineInit(int opmode, Key key, | |
| 198 | + AlgorithmParameterSpec params, | |
| 199 | + SecureRandom random) | |
| 200 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 201 | + if (params != null) { | |
| 202 | + throw new InvalidAlgorithmParameterException("This cipher " + | |
| 203 | + "does not accept any parameters"); | |
| 204 | + } | |
| 205 | + engineInit(opmode, key, random); | |
| 206 | + } | |
| 207 | + | |
| 208 | + /** | |
| 209 | + * Initializes this cipher with a key, a set of algorithm parameters, | |
| 210 | + * and a source of randomness. | |
| 211 | + * | |
| 212 | + * <p>The cipher only supports the following two operation modes:<b> | |
| 213 | + * Cipher.WRAP_MODE, and <b> | |
| 214 | + * Cipher.UNWRAP_MODE. | |
| 215 | + * <p>For modes other than the above two, UnsupportedOperationException | |
| 216 | + * will be thrown. | |
| 217 | + * | |
| 218 | + * @param opmode the operation mode of this cipher. Only | |
| 219 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) are accepted. | |
| 220 | + * @param key the secret key. | |
| 221 | + * @param params the algorithm parameters; must be null for this cipher. | |
| 222 | + * @param random the source of randomness. | |
| 223 | + * | |
| 224 | + * @exception InvalidKeyException if the given key is inappropriate. | |
| 225 | + * @exception InvalidAlgorithmParameterException if the given algorithm | |
| 226 | + * parameters is not null. | |
| 227 | + */ | |
| 228 | + protected void engineInit(int opmode, Key key, | |
| 229 | + AlgorithmParameters params, | |
| 230 | + SecureRandom random) | |
| 231 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 232 | + if (params != null) { | |
| 233 | + throw new InvalidAlgorithmParameterException("This cipher " + | |
| 234 | + "does not accept any parameters"); | |
| 235 | + } | |
| 236 | + engineInit(opmode, key, random); | |
| 237 | + } | |
| 238 | + | |
| 239 | + /** | |
| 240 | + * This operation is not supported by this cipher. | |
| 241 | + * Since it's impossible to initialize this cipher given the | |
| 242 | + * current Cipher.engineInit(...) implementation, | |
| 243 | + * IllegalStateException will always be thrown upon invocation. | |
| 244 | + * | |
| 245 | + * @param in the input buffer. | |
| 246 | + * @param inOffset the offset in <code>in</code> where the input | |
| 247 | + * starts. | |
| 248 | + * @param inLen the input length. | |
| 249 | + * | |
| 250 | + * @return n/a. | |
| 251 | + * | |
| 252 | + * @exception IllegalStateException upon invocation of this method. | |
| 253 | + */ | |
| 254 | + protected byte[] engineUpdate(byte[] in, int inOffset, int inLen) { | |
| 255 | + throw new IllegalStateException("Cipher has not been initialized"); | |
| 256 | + } | |
| 257 | + | |
| 258 | + /** | |
| 259 | + * This operation is not supported by this cipher. | |
| 260 | + * Since it's impossible to initialize this cipher given the | |
| 261 | + * current Cipher.engineInit(...) implementation, | |
| 262 | + * IllegalStateException will always be thrown upon invocation. | |
| 263 | + * | |
| 264 | + * @param in the input buffer. | |
| 265 | + * @param inOffset the offset in <code>in</code> where the input | |
| 266 | + * starts. | |
| 267 | + * @param inLen the input length. | |
| 268 | + * @param out the buffer for the result. | |
| 269 | + * @param outOffset the offset in <code>out</code> where the result | |
| 270 | + * is stored. | |
| 271 | + * | |
| 272 | + * @return n/a. | |
| 273 | + * | |
| 274 | + * @exception IllegalStateException upon invocation of this method. | |
| 275 | + */ | |
| 276 | + protected int engineUpdate(byte[] in, int inOffset, int inLen, | |
| 277 | + byte[] out, int outOffset) | |
| 278 | + throws ShortBufferException { | |
| 279 | + throw new IllegalStateException("Cipher has not been initialized"); | |
| 280 | + } | |
| 281 | + | |
| 282 | + /** | |
| 283 | + * This operation is not supported by this cipher. | |
| 284 | + * Since it's impossible to initialize this cipher given the | |
| 285 | + * current Cipher.engineInit(...) implementation, | |
| 286 | + * IllegalStateException will always be thrown upon invocation. | |
| 287 | + * | |
| 288 | + * @param in the input buffer | |
| 289 | + * @param inOffset the offset in <code>in</code> where the input | |
| 290 | + * starts | |
| 291 | + * @param inLen the input length. | |
| 292 | + * | |
| 293 | + * @return n/a. | |
| 294 | + * | |
| 295 | + * @exception IllegalStateException upon invocation of this method. | |
| 296 | + */ | |
| 297 | + protected byte[] engineDoFinal(byte[] input, int inputOffset, | |
| 298 | + int inputLen) | |
| 299 | + throws IllegalBlockSizeException, BadPaddingException { | |
| 300 | + throw new IllegalStateException("Cipher has not been initialized"); | |
| 301 | + } | |
| 302 | + | |
| 303 | + /** | |
| 304 | + * This operation is not supported by this cipher. | |
| 305 | + * Since it's impossible to initialize this cipher given the | |
| 306 | + * current Cipher.engineInit(...) implementation, | |
| 307 | + * IllegalStateException will always be thrown upon invocation. | |
| 308 | + * | |
| 309 | + * @param in the input buffer. | |
| 310 | + * @param inOffset the offset in <code>in</code> where the input | |
| 311 | + * starts. | |
| 312 | + * @param inLen the input length. | |
| 313 | + * @param out the buffer for the result. | |
| 314 | + * @param outOffset the ofset in <code>out</code> where the result | |
| 315 | + * is stored. | |
| 316 | + * | |
| 317 | + * @return n/a. | |
| 318 | + * | |
| 319 | + * @exception IllegalStateException upon invocation of this method. | |
| 320 | + */ | |
| 321 | + protected int engineDoFinal(byte[] in, int inOffset, int inLen, | |
| 322 | + byte[] out, int outOffset) | |
| 323 | + throws IllegalBlockSizeException, ShortBufferException, | |
| 324 | + BadPaddingException { | |
| 325 | + throw new IllegalStateException("Cipher has not been initialized"); | |
| 326 | + } | |
| 327 | + | |
| 328 | + /** | |
| 329 | + * Returns the parameters used with this cipher which is always null | |
| 330 | + * for this cipher. | |
| 331 | + * | |
| 332 | + * @return null since this cipher does not use any parameters. | |
| 333 | + */ | |
| 334 | + protected AlgorithmParameters engineGetParameters() { | |
| 335 | + return null; | |
| 336 | + } | |
| 337 | + | |
| 338 | + /** | |
| 339 | + * Returns the key size of the given key object in number of bits. | |
| 340 | + * | |
| 341 | + * @param key the key object. | |
| 342 | + * | |
| 343 | + * @return the "effective" key size of the given key object. | |
| 344 | + * | |
| 345 | + * @exception InvalidKeyException if <code>key</code> is invalid. | |
| 346 | + */ | |
| 347 | + protected int engineGetKeySize(Key key) throws InvalidKeyException { | |
| 348 | + byte[] encoded = key.getEncoded(); | |
| 349 | + if (!AESCrypt.isKeySizeValid(encoded.length)) { | |
| 350 | + throw new InvalidKeyException("Invalid key length: " + | |
| 351 | + encoded.length + " bytes"); | |
| 352 | + } | |
| 353 | + return encoded.length * 8; | |
| 354 | + } | |
| 355 | + | |
| 356 | + /** | |
| 357 | + * Wrap a key. | |
| 358 | + * | |
| 359 | + * @param key the key to be wrapped. | |
| 360 | + * | |
| 361 | + * @return the wrapped key. | |
| 362 | + * | |
| 363 | + * @exception IllegalBlockSizeException if this cipher is a block | |
| 364 | + * cipher, no padding has been requested, and the length of the | |
| 365 | + * encoding of the key to be wrapped is not a | |
| 366 | + * multiple of the block size. | |
| 367 | + * | |
| 368 | + * @exception InvalidKeyException if it is impossible or unsafe to | |
| 369 | + * wrap the key with this cipher (e.g., a hardware protected key is | |
| 370 | + * being passed to a software only cipher). | |
| 371 | + */ | |
| 372 | + protected byte[] engineWrap(Key key) | |
| 373 | + throws IllegalBlockSizeException, InvalidKeyException { | |
| 374 | + byte[] keyVal = key.getEncoded(); | |
| 375 | + if ((keyVal == null) || (keyVal.length == 0)) { | |
| 376 | + throw new InvalidKeyException("Cannot get an encoding of " + | |
| 377 | + "the key to be wrapped"); | |
| 378 | + } | |
| 379 | + byte[] out = new byte[keyVal.length + 8]; | |
| 380 | + | |
| 381 | + if (keyVal.length == 8) { | |
| 382 | + System.arraycopy(IV, 0, out, 0, IV.length); | |
| 383 | + System.arraycopy(keyVal, 0, out, IV.length, 8); | |
| 384 | + cipher.encryptBlock(out, 0, out, 0); | |
| 385 | + } else { | |
| 386 | + if (keyVal.length % 8 != 0) { | |
| 387 | + throw new IllegalBlockSizeException("length of the " + | |
| 388 | + "to be wrapped key should be multiples of 8 bytes"); | |
| 389 | + } | |
| 390 | + System.arraycopy(IV, 0, out, 0, IV.length); | |
| 391 | + System.arraycopy(keyVal, 0, out, IV.length, keyVal.length); | |
| 392 | + int N = keyVal.length/8; | |
| 393 | + byte[] buffer = new byte[blksize]; | |
| 394 | + for (int j = 0; j < 6; j++) { | |
| 395 | + for (int i = 1; i <= N; i++) { | |
| 396 | + int T = i + j*N; | |
| 397 | + System.arraycopy(out, 0, buffer, 0, IV.length); | |
| 398 | + System.arraycopy(out, i*8, buffer, IV.length, 8); | |
| 399 | + cipher.encryptBlock(buffer, 0, buffer, 0); | |
| 400 | + for (int k = 1; T != 0; k++) { | |
| 401 | + byte v = (byte) T; | |
| 402 | + buffer[IV.length - k] ^= v; | |
| 403 | + T >>>= 8; | |
| 404 | + } | |
| 405 | + System.arraycopy(buffer, 0, out, 0, IV.length); | |
| 406 | + System.arraycopy(buffer, 8, out, 8*i, 8); | |
| 407 | + } | |
| 408 | + } | |
| 409 | + } | |
| 410 | + return out; | |
| 411 | + } | |
| 412 | + | |
| 413 | + /** | |
| 414 | + * Unwrap a previously wrapped key. | |
| 415 | + * | |
| 416 | + * @param wrappedKey the key to be unwrapped. | |
| 417 | + * | |
| 418 | + * @param wrappedKeyAlgorithm the algorithm the wrapped key is for. | |
| 419 | + * | |
| 420 | + * @param wrappedKeyType the type of the wrapped key. | |
| 421 | + * This is one of <code>Cipher.SECRET_KEY</code>, | |
| 422 | + * <code>Cipher.PRIVATE_KEY</code>, or <code>Cipher.PUBLIC_KEY</code>. | |
| 423 | + * | |
| 424 | + * @return the unwrapped key. | |
| 425 | + * | |
| 426 | + * @exception NoSuchAlgorithmException if no installed providers | |
| 427 | + * can create keys of type <code>wrappedKeyType</code> for the | |
| 428 | + * <code>wrappedKeyAlgorithm</code>. | |
| 429 | + * | |
| 430 | + * @exception InvalidKeyException if <code>wrappedKey</code> does not | |
| 431 | + * represent a wrapped key of type <code>wrappedKeyType</code> for | |
| 432 | + * the <code>wrappedKeyAlgorithm</code>. | |
| 433 | + */ | |
| 434 | + protected Key engineUnwrap(byte[] wrappedKey, | |
| 435 | + String wrappedKeyAlgorithm, | |
| 436 | + int wrappedKeyType) | |
| 437 | + throws InvalidKeyException, NoSuchAlgorithmException { | |
| 438 | + int wrappedKeyLen = wrappedKey.length; | |
| 439 | + // ensure the wrappedKey length is multiples of 8 bytes and non-zero | |
| 440 | + if (wrappedKeyLen == 0) { | |
| 441 | + throw new InvalidKeyException("The wrapped key is empty"); | |
| 442 | + } | |
| 443 | + if (wrappedKeyLen % 8 != 0) { | |
| 444 | + throw new InvalidKeyException | |
| 445 | + ("The wrapped key has invalid key length"); | |
| 446 | + } | |
| 447 | + byte[] out = new byte[wrappedKeyLen - 8]; | |
| 448 | + byte[] buffer = new byte[blksize]; | |
| 449 | + if (wrappedKeyLen == 16) { | |
| 450 | + cipher.decryptBlock(wrappedKey, 0, buffer, 0); | |
| 451 | + for (int i = 0; i < IV.length; i++) { | |
| 452 | + if (IV[i] != buffer[i]) { | |
| 453 | + throw new InvalidKeyException("Integrity check failed"); | |
| 454 | + } | |
| 455 | + } | |
| 456 | + System.arraycopy(buffer, IV.length, out, 0, out.length); | |
| 457 | + } else { | |
| 458 | + System.arraycopy(wrappedKey, 0, buffer, 0, IV.length); | |
| 459 | + System.arraycopy(wrappedKey, IV.length, out, 0, out.length); | |
| 460 | + int N = out.length/8; | |
| 461 | + for (int j = 5; j >= 0; j--) { | |
| 462 | + for (int i = N; i > 0; i--) { | |
| 463 | + int T = i + j*N; | |
| 464 | + System.arraycopy(out, 8*(i-1), buffer, IV.length, 8); | |
| 465 | + for (int k = 1; T != 0; k++) { | |
| 466 | + byte v = (byte) T; | |
| 467 | + buffer[IV.length - k] ^= v; | |
| 468 | + T >>>= 8; | |
| 469 | + } | |
| 470 | + cipher.decryptBlock(buffer, 0, buffer, 0); | |
| 471 | + System.arraycopy(buffer, IV.length, out, 8*(i-1), 8); | |
| 472 | + } | |
| 473 | + } | |
| 474 | + for (int i = 0; i < IV.length; i++) { | |
| 475 | + if (IV[i] != buffer[i]) { | |
| 476 | + throw new InvalidKeyException("Integrity check failed"); | |
| 477 | + } | |
| 478 | + } | |
| 479 | + } | |
| 480 | + return ConstructKeys.constructKey(out, wrappedKeyAlgorithm, | |
| 481 | + wrappedKeyType); | |
| 482 | + } | |
| 483 | +} | |
| @@ -0,0 +1,263 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.security.*; | |
| 29 | +import java.security.spec.AlgorithmParameterSpec; | |
| 30 | + | |
| 31 | +import javax.crypto.*; | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * Implementation of the ARCFOUR cipher, an algorithm apparently compatible | |
| 35 | + * with RSA Security's RC4(tm) cipher. The description of this algorithm was | |
| 36 | + * taken from Bruce Schneier's book Applied Cryptography, 2nd ed., | |
| 37 | + * section 17.1. | |
| 38 | + * | |
| 39 | + * We support keys from 40 to 1024 bits. ARCFOUR would allow for keys shorter | |
| 40 | + * than 40 bits, but that is too insecure for us to permit. | |
| 41 | + * | |
| 42 | + * Note that we subclass CipherSpi directly and do not use the CipherCore | |
| 43 | + * framework. That was designed to simplify implementation of block ciphers | |
| 44 | + * and does not offer any advantages for stream ciphers such as ARCFOUR. | |
| 45 | + * | |
| 46 | + * @since 1.5 | |
| 47 | + * @author Andreas Sterbenz | |
| 48 | + */ | |
| 49 | +public final class ARCFOURCipher extends CipherSpi { | |
| 50 | + | |
| 51 | + // state array S, 256 entries. The entries are 8-bit, but we use an int[] | |
| 52 | + // because int arithmetic is much faster than in Java than bytes. | |
| 53 | + private final int[] S; | |
| 54 | + | |
| 55 | + // state indices i and j. Called is and js to avoid collision with | |
| 56 | + // local variables. 'is' is set to -1 after a call to doFinal() | |
| 57 | + private int is, js; | |
| 58 | + | |
| 59 | + // the bytes of the last key used (if any) | |
| 60 | + // we need this to re-initialize after a call to doFinal() | |
| 61 | + private byte[] lastKey; | |
| 62 | + | |
| 63 | + // called by the JCE framework | |
| 64 | + public ARCFOURCipher() { | |
| 65 | + S = new int[256]; | |
| 66 | + } | |
| 67 | + | |
| 68 | + // core key setup code. initializes S, is, and js | |
| 69 | + // assumes key is non-null and between 40 and 1024 bit | |
| 70 | + private void init(byte[] key) { | |
| 71 | + // initialize S[i] to i | |
| 72 | + for (int i = 0; i < 256; i++) { | |
| 73 | + S[i] = i; | |
| 74 | + } | |
| 75 | + | |
| 76 | + // we avoid expanding key to 256 bytes and instead keep a separate | |
| 77 | + // counter ki = i mod key.length. | |
| 78 | + for (int i = 0, j = 0, ki = 0; i < 256; i++) { | |
| 79 | + int Si = S[i]; | |
| 80 | + j = (j + Si + key[ki]) & 0xff; | |
| 81 | + S[i] = S[j]; | |
| 82 | + S[j] = Si; | |
| 83 | + ki++; | |
| 84 | + if (ki == key.length) { | |
| 85 | + ki = 0; | |
| 86 | + } | |
| 87 | + } | |
| 88 | + | |
| 89 | + // set indices to 0 | |
| 90 | + is = 0; | |
| 91 | + js = 0; | |
| 92 | + } | |
| 93 | + | |
| 94 | + // core crypt code. OFB style, so works for both encryption and decryption | |
| 95 | + private void crypt(byte[] in, int inOfs, int inLen, byte[] out, | |
| 96 | + int outOfs) { | |
| 97 | + if (is < 0) { | |
| 98 | + // doFinal() was called, need to reset the cipher to initial state | |
| 99 | + init(lastKey); | |
| 100 | + } | |
| 101 | + while (inLen-- > 0) { | |
| 102 | + is = (is + 1) & 0xff; | |
| 103 | + int Si = S[is]; | |
| 104 | + js = (js + Si) & 0xff; | |
| 105 | + int Sj = S[js]; | |
| 106 | + S[is] = Sj; | |
| 107 | + S[js] = Si; | |
| 108 | + out[outOfs++] = (byte)(in[inOfs++] ^ S[(Si + Sj) & 0xff]); | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 112 | + // Modes do not make sense with stream ciphers, but allow ECB | |
| 113 | + // see JCE spec. | |
| 114 | + protected void engineSetMode(String mode) throws NoSuchAlgorithmException { | |
| 115 | + if (mode.equalsIgnoreCase("ECB") == false) { | |
| 116 | + throw new NoSuchAlgorithmException("Unsupported mode " + mode); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + | |
| 120 | + // Padding does not make sense with stream ciphers, but allow NoPadding | |
| 121 | + // see JCE spec. | |
| 122 | + protected void engineSetPadding(String padding) | |
| 123 | + throws NoSuchPaddingException { | |
| 124 | + if (padding.equalsIgnoreCase("NoPadding") == false) { | |
| 125 | + throw new NoSuchPaddingException("Padding must be NoPadding"); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + | |
| 129 | + // Return 0 to indicate stream cipher | |
| 130 | + // see JCE spec. | |
| 131 | + protected int engineGetBlockSize() { | |
| 132 | + return 0; | |
| 133 | + } | |
| 134 | + | |
| 135 | + // output length is always the same as input length | |
| 136 | + // see JCE spec | |
| 137 | + protected int engineGetOutputSize(int inputLen) { | |
| 138 | + return inputLen; | |
| 139 | + } | |
| 140 | + | |
| 141 | + // no IV, return null | |
| 142 | + // see JCE spec | |
| 143 | + protected byte[] engineGetIV() { | |
| 144 | + return null; | |
| 145 | + } | |
| 146 | + | |
| 147 | + // no parameters | |
| 148 | + // see JCE spec | |
| 149 | + protected AlgorithmParameters engineGetParameters() { | |
| 150 | + return null; | |
| 151 | + } | |
| 152 | + | |
| 153 | + // see JCE spec | |
| 154 | + protected void engineInit(int opmode, Key key, SecureRandom random) | |
| 155 | + throws InvalidKeyException { | |
| 156 | + init(opmode, key); | |
| 157 | + } | |
| 158 | + | |
| 159 | + // see JCE spec | |
| 160 | + protected void engineInit(int opmode, Key key, | |
| 161 | + AlgorithmParameterSpec params, SecureRandom random) | |
| 162 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 163 | + if (params != null) { | |
| 164 | + throw new InvalidAlgorithmParameterException | |
| 165 | + ("Parameters not supported"); | |
| 166 | + } | |
| 167 | + init(opmode, key); | |
| 168 | + } | |
| 169 | + | |
| 170 | + // see JCE spec | |
| 171 | + protected void engineInit(int opmode, Key key, | |
| 172 | + AlgorithmParameters params, SecureRandom random) | |
| 173 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 174 | + if (params != null) { | |
| 175 | + throw new InvalidAlgorithmParameterException | |
| 176 | + ("Parameters not supported"); | |
| 177 | + } | |
| 178 | + init(opmode, key); | |
| 179 | + } | |
| 180 | + | |
| 181 | + // init method. Check opmode and key, then call init(byte[]). | |
| 182 | + private void init(int opmode, Key key) throws InvalidKeyException { | |
| 183 | + if ((opmode < Cipher.ENCRYPT_MODE) || (opmode > Cipher.UNWRAP_MODE)) { | |
| 184 | + throw new InvalidKeyException("Unknown opmode: " + opmode); | |
| 185 | + } | |
| 186 | + lastKey = getEncodedKey(key); | |
| 187 | + init(lastKey); | |
| 188 | + } | |
| 189 | + | |
| 190 | + // return the encoding of key if key is a valid ARCFOUR key. | |
| 191 | + // otherwise, throw an InvalidKeyException | |
| 192 | + private static byte[] getEncodedKey(Key key) throws InvalidKeyException { | |
| 193 | + String keyAlg = key.getAlgorithm(); | |
| 194 | + if (!keyAlg.equals("RC4") && !keyAlg.equals("ARCFOUR")) { | |
| 195 | + throw new InvalidKeyException("Not an ARCFOUR key: " + keyAlg); | |
| 196 | + } | |
| 197 | + if ("RAW".equals(key.getFormat()) == false) { | |
| 198 | + throw new InvalidKeyException("Key encoding format must be RAW"); | |
| 199 | + } | |
| 200 | + byte[] encodedKey = key.getEncoded(); | |
| 201 | + if ((encodedKey.length < 5) || (encodedKey.length > 128)) { | |
| 202 | + throw new InvalidKeyException | |
| 203 | + ("Key length must be between 40 and 1024 bit"); | |
| 204 | + } | |
| 205 | + return encodedKey; | |
| 206 | + } | |
| 207 | + | |
| 208 | + // see JCE spec | |
| 209 | + protected byte[] engineUpdate(byte[] in, int inOfs, int inLen) { | |
| 210 | + byte[] out = new byte[inLen]; | |
| 211 | + crypt(in, inOfs, inLen, out, 0); | |
| 212 | + return out; | |
| 213 | + } | |
| 214 | + | |
| 215 | + // see JCE spec | |
| 216 | + protected int engineUpdate(byte[] in, int inOfs, int inLen, | |
| 217 | + byte[] out, int outOfs) throws ShortBufferException { | |
| 218 | + if (out.length - outOfs < inLen) { | |
| 219 | + throw new ShortBufferException("Output buffer too small"); | |
| 220 | + } | |
| 221 | + crypt(in, inOfs, inLen, out, outOfs); | |
| 222 | + return inLen; | |
| 223 | + } | |
| 224 | + | |
| 225 | + // see JCE spec | |
| 226 | + protected byte[] engineDoFinal(byte[] in, int inOfs, int inLen) { | |
| 227 | + byte[] out = engineUpdate(in, inOfs, inLen); | |
| 228 | + is = -1; | |
| 229 | + return out; | |
| 230 | + } | |
| 231 | + | |
| 232 | + // see JCE spec | |
| 233 | + protected int engineDoFinal(byte[] in, int inOfs, int inLen, | |
| 234 | + byte[] out, int outOfs) throws ShortBufferException { | |
| 235 | + int outLen = engineUpdate(in, inOfs, inLen, out, outOfs); | |
| 236 | + is = -1; | |
| 237 | + return outLen; | |
| 238 | + } | |
| 239 | + | |
| 240 | + // see JCE spec | |
| 241 | + protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, | |
| 242 | + InvalidKeyException { | |
| 243 | + byte[] encoded = key.getEncoded(); | |
| 244 | + if ((encoded == null) || (encoded.length == 0)) { | |
| 245 | + throw new InvalidKeyException("Could not obtain encoded key"); | |
| 246 | + } | |
| 247 | + return engineDoFinal(encoded, 0, encoded.length); | |
| 248 | + } | |
| 249 | + | |
| 250 | + // see JCE spec | |
| 251 | + protected Key engineUnwrap(byte[] wrappedKey, String algorithm, | |
| 252 | + int type) throws InvalidKeyException, NoSuchAlgorithmException { | |
| 253 | + byte[] encoded = engineDoFinal(wrappedKey, 0, wrappedKey.length); | |
| 254 | + return ConstructKeys.constructKey(encoded, algorithm, type); | |
| 255 | + } | |
| 256 | + | |
| 257 | + // see JCE spec | |
| 258 | + protected int engineGetKeySize(Key key) throws InvalidKeyException { | |
| 259 | + byte[] encodedKey = getEncodedKey(key); | |
| 260 | + return encodedKey.length << 3; | |
| 261 | + } | |
| 262 | + | |
| 263 | +} | |
| @@ -0,0 +1,127 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.util.*; | |
| 29 | +import java.io.*; | |
| 30 | +import sun.security.util.*; | |
| 31 | +import sun.misc.HexDumpEncoder; | |
| 32 | +import java.security.spec.AlgorithmParameterSpec; | |
| 33 | +import java.security.spec.InvalidParameterSpecException; | |
| 34 | +import javax.crypto.spec.IvParameterSpec; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * This class implements the parameter (IV) used with Block Ciphers | |
| 38 | + * in feedback-mode. IV is defined in the standards as follows: | |
| 39 | + * | |
| 40 | + * <pre> | |
| 41 | + * IV ::= OCTET STRING -- length depends on the block size of the | |
| 42 | + * block ciphers | |
| 43 | + * </pre> | |
| 44 | + * | |
| 45 | + * @author Valerie Peng | |
| 46 | + * | |
| 47 | + */ | |
| 48 | +final class BlockCipherParamsCore { | |
| 49 | + private int block_size = 0; | |
| 50 | + private byte[] iv = null; | |
| 51 | + | |
| 52 | + BlockCipherParamsCore(int blksize) { | |
| 53 | + block_size = blksize; | |
| 54 | + } | |
| 55 | + | |
| 56 | + void init(AlgorithmParameterSpec paramSpec) | |
| 57 | + throws InvalidParameterSpecException { | |
| 58 | + if (!(paramSpec instanceof IvParameterSpec)) { | |
| 59 | + throw new InvalidParameterSpecException | |
| 60 | + ("Inappropriate parameter specification"); | |
| 61 | + } | |
| 62 | + byte[] tmpIv = ((IvParameterSpec)paramSpec).getIV(); | |
| 63 | + if (tmpIv.length != block_size) { | |
| 64 | + throw new InvalidParameterSpecException("IV not " + | |
| 65 | + block_size + " bytes long"); | |
| 66 | + } | |
| 67 | + iv = (byte[]) tmpIv.clone(); | |
| 68 | + } | |
| 69 | + | |
| 70 | + void init(byte[] encoded) throws IOException { | |
| 71 | + DerInputStream der = new DerInputStream(encoded); | |
| 72 | + | |
| 73 | + byte[] tmpIv = der.getOctetString(); | |
| 74 | + if (der.available() != 0) { | |
| 75 | + throw new IOException("IV parsing error: extra data"); | |
| 76 | + } | |
| 77 | + if (tmpIv.length != block_size) { | |
| 78 | + throw new IOException("IV not " + block_size + | |
| 79 | + " bytes long"); | |
| 80 | + } | |
| 81 | + iv = tmpIv; | |
| 82 | + } | |
| 83 | + | |
| 84 | + void init(byte[] encoded, String decodingMethod) | |
| 85 | + throws IOException { | |
| 86 | + if ((decodingMethod != null) && | |
| 87 | + (!decodingMethod.equalsIgnoreCase("ASN.1"))) { | |
| 88 | + throw new IllegalArgumentException("Only support ASN.1 format"); | |
| 89 | + } | |
| 90 | + init(encoded); | |
| 91 | + } | |
| 92 | + | |
| 93 | + AlgorithmParameterSpec getParameterSpec(Class paramSpec) | |
| 94 | + throws InvalidParameterSpecException | |
| 95 | + { | |
| 96 | + if (IvParameterSpec.class.isAssignableFrom(paramSpec)) { | |
| 97 | + return new IvParameterSpec(this.iv); | |
| 98 | + } else { | |
| 99 | + throw new InvalidParameterSpecException | |
| 100 | + ("Inappropriate parameter specification"); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + byte[] getEncoded() throws IOException { | |
| 105 | + DerOutputStream out = new DerOutputStream(); | |
| 106 | + out.putOctetString(this.iv); | |
| 107 | + return out.toByteArray(); | |
| 108 | + } | |
| 109 | + | |
| 110 | + byte[] getEncoded(String encodingMethod) | |
| 111 | + throws IOException { | |
| 112 | + return getEncoded(); | |
| 113 | + } | |
| 114 | + | |
| 115 | + /* | |
| 116 | + * Returns a formatted string describing the parameters. | |
| 117 | + */ | |
| 118 | + public String toString() { | |
| 119 | + String LINE_SEP = System.getProperty("line.separator"); | |
| 120 | + | |
| 121 | + String ivString = LINE_SEP + " iv:" + LINE_SEP + "["; | |
| 122 | + HexDumpEncoder encoder = new HexDumpEncoder(); | |
| 123 | + ivString += encoder.encodeBuffer(this.iv); | |
| 124 | + ivString += "]" + LINE_SEP; | |
| 125 | + return ivString; | |
| 126 | + } | |
| 127 | +} | |
| @@ -0,0 +1,428 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.security.*; | |
| 29 | +import java.security.spec.*; | |
| 30 | +import sun.security.util.*; | |
| 31 | +import javax.crypto.*; | |
| 32 | +import javax.crypto.spec.*; | |
| 33 | +import javax.crypto.BadPaddingException; | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * This class implements the Blowfish algorithm in its various modes | |
| 37 | + * (<code>ECB</code>, <code>CFB</code>, <code>OFB</code>, <code>CBC</code>, | |
| 38 | + * <code>PCBC</code>) and padding schemes (<code>PKCS5Padding</code>, | |
| 39 | + * <code>NoPadding</code>, <code>ISO10126Padding</code>). | |
| 40 | + * | |
| 41 | + * <p> Blowfish is a 64-bit block cipher with a variable-length key. | |
| 42 | + * | |
| 43 | + * @author Jan Luehe | |
| 44 | + * | |
| 45 | + * | |
| 46 | + * @see BlowfishCrypt | |
| 47 | + * @see CipherBlockChaining | |
| 48 | + * @see ElectronicCodeBook | |
| 49 | + * @see CipherFeedback | |
| 50 | + * @see OutputFeedback | |
| 51 | + */ | |
| 52 | + | |
| 53 | +public final class BlowfishCipher extends CipherSpi { | |
| 54 | + | |
| 55 | + /* | |
| 56 | + * internal CipherCore object which does the real work. | |
| 57 | + */ | |
| 58 | + private CipherCore core = null; | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * Creates an instance of Blowfish cipher with default ECB mode and | |
| 62 | + * PKCS5Padding. | |
| 63 | + */ | |
| 64 | + public BlowfishCipher() { | |
| 65 | + core = new CipherCore(new BlowfishCrypt(), | |
| 66 | + BlowfishConstants.BLOWFISH_BLOCK_SIZE); | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Sets the mode of this cipher. | |
| 71 | + * | |
| 72 | + * @param mode the cipher mode | |
| 73 | + * | |
| 74 | + * @exception NoSuchAlgorithmException if the requested cipher mode does | |
| 75 | + * not exist | |
| 76 | + */ | |
| 77 | + protected void engineSetMode(String mode) | |
| 78 | + throws NoSuchAlgorithmException { | |
| 79 | + core.setMode(mode); | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Sets the padding mechanism of this cipher. | |
| 84 | + * | |
| 85 | + * @param padding the padding mechanism | |
| 86 | + * | |
| 87 | + * @exception NoSuchPaddingException if the requested padding mechanism | |
| 88 | + * does not exist | |
| 89 | + */ | |
| 90 | + protected void engineSetPadding(String paddingScheme) | |
| 91 | + throws NoSuchPaddingException { | |
| 92 | + core.setPadding(paddingScheme); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Returns the block size (in bytes). | |
| 97 | + * | |
| 98 | + * @return the block size (in bytes), or 0 if the underlying algorithm is | |
| 99 | + * not a block cipher | |
| 100 | + */ | |
| 101 | + protected int engineGetBlockSize() { | |
| 102 | + return BlowfishConstants.BLOWFISH_BLOCK_SIZE; | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Returns the length in bytes that an output buffer would need to be in | |
| 107 | + * order to hold the result of the next <code>update</code> or | |
| 108 | + * <code>doFinal</code> operation, given the input length | |
| 109 | + * <code>inputLen</code> (in bytes). | |
| 110 | + * | |
| 111 | + * <p>This call takes into account any unprocessed (buffered) data from a | |
| 112 | + * previous <code>update</code> call, and padding. | |
| 113 | + * | |
| 114 | + * <p>The actual output length of the next <code>update</code> or | |
| 115 | + * <code>doFinal</code> call may be smaller than the length returned by | |
| 116 | + * this method. | |
| 117 | + * | |
| 118 | + * @param inputLen the input length (in bytes) | |
| 119 | + * | |
| 120 | + * @return the required output buffer size (in bytes) | |
| 121 | + */ | |
| 122 | + protected int engineGetOutputSize(int inputLen) { | |
| 123 | + return core.getOutputSize(inputLen); | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * Returns the initialization vector (IV) in a new buffer. | |
| 128 | + * | |
| 129 | + * <p>This is useful in the case where a random IV has been created | |
| 130 | + * (see <a href = "#init">init</a>), | |
| 131 | + * or in the context of password-based encryption or | |
| 132 | + * decryption, where the IV is derived from a user-supplied password. | |
| 133 | + * | |
| 134 | + * @return the initialization vector in a new buffer, or null if the | |
| 135 | + * underlying algorithm does not use an IV, or if the IV has not yet | |
| 136 | + * been set. | |
| 137 | + */ | |
| 138 | + protected byte[] engineGetIV() { | |
| 139 | + return core.getIV(); | |
| 140 | + } | |
| 141 | + | |
| 142 | + /** | |
| 143 | + * Returns the parameters used with this cipher. | |
| 144 | + * | |
| 145 | + * <p>The returned parameters may be the same that were used to initialize | |
| 146 | + * this cipher, or may contain the default set of parameters or a set of | |
| 147 | + * randomly generated parameters used by the underlying cipher | |
| 148 | + * implementation (provided that the underlying cipher implementation | |
| 149 | + * uses a default set of parameters or creates new parameters if it needs | |
| 150 | + * parameters but was not initialized with any). | |
| 151 | + * | |
| 152 | + * @return the parameters used with this cipher, or null if this cipher | |
| 153 | + * does not use any parameters. | |
| 154 | + */ | |
| 155 | + protected AlgorithmParameters engineGetParameters() { | |
| 156 | + return core.getParameters("Blowfish"); | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * Initializes this cipher with a key and a source of randomness. | |
| 161 | + * | |
| 162 | + * <p>The cipher is initialized for one of the following four operations: | |
| 163 | + * encryption, decryption, key wrapping or key unwrapping, depending on | |
| 164 | + * the value of <code>opmode</code>. | |
| 165 | + * | |
| 166 | + * <p>If this cipher requires an initialization vector (IV), it will get | |
| 167 | + * it from <code>random</code>. | |
| 168 | + * This behaviour should only be used in encryption or key wrapping | |
| 169 | + * mode, however. | |
| 170 | + * When initializing a cipher that requires an IV for decryption or | |
| 171 | + * key unwrapping, the IV | |
| 172 | + * (same IV that was used for encryption or key wrapping) must be provided | |
| 173 | + * explicitly as a | |
| 174 | + * parameter, in order to get the correct result. | |
| 175 | + * | |
| 176 | + * <p>This method also cleans existing buffer and other related state | |
| 177 | + * information. | |
| 178 | + * | |
| 179 | + * @param opmode the operation mode of this cipher (this is one of | |
| 180 | + * the following: | |
| 181 | + * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>, | |
| 182 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) | |
| 183 | + * @param key the secret key | |
| 184 | + * @param random the source of randomness | |
| 185 | + * | |
| 186 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 187 | + * initializing this cipher | |
| 188 | + */ | |
| 189 | + protected void engineInit(int opmode, Key key, SecureRandom random) | |
| 190 | + throws InvalidKeyException { | |
| 191 | + core.init(opmode, key, random); | |
| 192 | + } | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * Initializes this cipher with a key, a set of | |
| 196 | + * algorithm parameters, and a source of randomness. | |
| 197 | + * | |
| 198 | + * <p>The cipher is initialized for one of the following four operations: | |
| 199 | + * encryption, decryption, key wrapping or key unwrapping, depending on | |
| 200 | + * the value of <code>opmode</code>. | |
| 201 | + * | |
| 202 | + * <p>If this cipher (including its underlying feedback or padding scheme) | |
| 203 | + * requires any random bytes, it will get them from <code>random</code>. | |
| 204 | + * | |
| 205 | + * @param opmode the operation mode of this cipher (this is one of | |
| 206 | + * the following: | |
| 207 | + * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>, | |
| 208 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) | |
| 209 | + * @param key the encryption key | |
| 210 | + * @param params the algorithm parameters | |
| 211 | + * @param random the source of randomness | |
| 212 | + * | |
| 213 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 214 | + * initializing this cipher | |
| 215 | + * @exception InvalidAlgorithmParameterException if the given algorithm | |
| 216 | + * parameters are inappropriate for this cipher | |
| 217 | + */ | |
| 218 | + protected void engineInit(int opmode, Key key, | |
| 219 | + AlgorithmParameterSpec params, | |
| 220 | + SecureRandom random) | |
| 221 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 222 | + core.init(opmode, key, params, random); | |
| 223 | + } | |
| 224 | + | |
| 225 | + protected void engineInit(int opmode, Key key, | |
| 226 | + AlgorithmParameters params, | |
| 227 | + SecureRandom random) | |
| 228 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 229 | + core.init(opmode, key, params, random); | |
| 230 | + } | |
| 231 | + | |
| 232 | + /** | |
| 233 | + * Continues a multiple-part encryption or decryption operation | |
| 234 | + * (depending on how this cipher was initialized), processing another data | |
| 235 | + * part. | |
| 236 | + * | |
| 237 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 238 | + * buffer, starting at <code>inputOffset</code>, are processed, and the | |
| 239 | + * result is stored in a new buffer. | |
| 240 | + * | |
| 241 | + * @param input the input buffer | |
| 242 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 243 | + * starts | |
| 244 | + * @param inputLen the input length | |
| 245 | + * | |
| 246 | + * @return the new buffer with the result | |
| 247 | + * | |
| 248 | + * @exception IllegalStateException if this cipher is in a wrong state | |
| 249 | + * (e.g., has not been initialized) | |
| 250 | + */ | |
| 251 | + protected byte[] engineUpdate(byte[] input, int inputOffset, | |
| 252 | + int inputLen) { | |
| 253 | + return core.update(input, inputOffset, inputLen); | |
| 254 | + } | |
| 255 | + | |
| 256 | + /** | |
| 257 | + * Continues a multiple-part encryption or decryption operation | |
| 258 | + * (depending on how this cipher was initialized), processing another data | |
| 259 | + * part. | |
| 260 | + * | |
| 261 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 262 | + * buffer, starting at <code>inputOffset</code>, are processed, and the | |
| 263 | + * result is stored in the <code>output</code> buffer, starting at | |
| 264 | + * <code>outputOffset</code>. | |
| 265 | + * | |
| 266 | + * @param input the input buffer | |
| 267 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 268 | + * starts | |
| 269 | + * @param inputLen the input length | |
| 270 | + * @param output the buffer for the result | |
| 271 | + * @param outputOffset the offset in <code>output</code> where the result | |
| 272 | + * is stored | |
| 273 | + * | |
| 274 | + * @return the number of bytes stored in <code>output</code> | |
| 275 | + * | |
| 276 | + * @exception ShortBufferException if the given output buffer is too small | |
| 277 | + * to hold the result | |
| 278 | + */ | |
| 279 | + protected int engineUpdate(byte[] input, int inputOffset, int inputLen, | |
| 280 | + byte[] output, int outputOffset) | |
| 281 | + throws ShortBufferException { | |
| 282 | + return core.update(input, inputOffset, inputLen, output, | |
| 283 | + outputOffset); | |
| 284 | + } | |
| 285 | + | |
| 286 | + /** | |
| 287 | + * Encrypts or decrypts data in a single-part operation, | |
| 288 | + * or finishes a multiple-part operation. | |
| 289 | + * The data is encrypted or decrypted, depending on how this cipher was | |
| 290 | + * initialized. | |
| 291 | + * | |
| 292 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 293 | + * buffer, starting at <code>inputOffset</code>, and any input bytes that | |
| 294 | + * may have been buffered during a previous <code>update</code> operation, | |
| 295 | + * are processed, with padding (if requested) being applied. | |
| 296 | + * The result is stored in a new buffer. | |
| 297 | + * | |
| 298 | + * <p>The cipher is reset to its initial state (uninitialized) after this | |
| 299 | + * call. | |
| 300 | + * | |
| 301 | + * @param input the input buffer | |
| 302 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 303 | + * starts | |
| 304 | + * @param inputLen the input length | |
| 305 | + * | |
| 306 | + * @return the new buffer with the result | |
| 307 | + * | |
| 308 | + * @exception IllegalBlockSizeException if this cipher is a block cipher, | |
| 309 | + * no padding has been requested (only in encryption mode), and the total | |
| 310 | + * input length of the data processed by this cipher is not a multiple of | |
| 311 | + * block size | |
| 312 | + * @exception BadPaddingException if this cipher is in decryption mode, | |
| 313 | + * and (un)padding has been requested, but the decrypted data is not | |
| 314 | + * bounded by the appropriate padding bytes | |
| 315 | + */ | |
| 316 | + protected byte[] engineDoFinal(byte[] input, int inputOffset, | |
| 317 | + int inputLen) | |
| 318 | + throws IllegalBlockSizeException, BadPaddingException { | |
| 319 | + return core.doFinal(input, inputOffset, inputLen); | |
| 320 | + } | |
| 321 | + | |
| 322 | + /** | |
| 323 | + * Encrypts or decrypts data in a single-part operation, | |
| 324 | + * or finishes a multiple-part operation. | |
| 325 | + * The data is encrypted or decrypted, depending on how this cipher was | |
| 326 | + * initialized. | |
| 327 | + * | |
| 328 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 329 | + * buffer, starting at <code>inputOffset</code>, and any input bytes that | |
| 330 | + * may have been buffered during a previous <code>update</code> operation, | |
| 331 | + * are processed, with padding (if requested) being applied. | |
| 332 | + * The result is stored in the <code>output</code> buffer, starting at | |
| 333 | + * <code>outputOffset</code>. | |
| 334 | + * | |
| 335 | + * <p>The cipher is reset to its initial state (uninitialized) after this | |
| 336 | + * call. | |
| 337 | + * | |
| 338 | + * @param input the input buffer | |
| 339 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 340 | + * starts | |
| 341 | + * @param inputLen the input length | |
| 342 | + * @param output the buffer for the result | |
| 343 | + * @param outputOffset the offset in <code>output</code> where the result | |
| 344 | + * is stored | |
| 345 | + * | |
| 346 | + * @return the number of bytes stored in <code>output</code> | |
| 347 | + * | |
| 348 | + * @exception IllegalBlockSizeException if this cipher is a block cipher, | |
| 349 | + * no padding has been requested (only in encryption mode), and the total | |
| 350 | + * input length of the data processed by this cipher is not a multiple of | |
| 351 | + * block size | |
| 352 | + * @exception ShortBufferException if the given output buffer is too small | |
| 353 | + * to hold the result | |
| 354 | + * @exception BadPaddingException if this cipher is in decryption mode, | |
| 355 | + * and (un)padding has been requested, but the decrypted data is not | |
| 356 | + * bounded by the appropriate padding bytes | |
| 357 | + */ | |
| 358 | + protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, | |
| 359 | + byte[] output, int outputOffset) | |
| 360 | + throws IllegalBlockSizeException, ShortBufferException, | |
| 361 | + BadPaddingException { | |
| 362 | + return core.doFinal(input, inputOffset, inputLen, output, | |
| 363 | + outputOffset); | |
| 364 | + } | |
| 365 | + | |
| 366 | + /** | |
| 367 | + * Returns the key size of the given key object. | |
| 368 | + * | |
| 369 | + * @param key the key object. | |
| 370 | + * | |
| 371 | + * @return the key size of the given key object. | |
| 372 | + * | |
| 373 | + * @exception InvalidKeyException if <code>key</code> is invalid. | |
| 374 | + */ | |
| 375 | + protected int engineGetKeySize(Key key) throws InvalidKeyException { | |
| 376 | + return (key.getEncoded().length * 8); | |
| 377 | + } | |
| 378 | + | |
| 379 | + /** | |
| 380 | + * Wrap a key. | |
| 381 | + * | |
| 382 | + * @param key the key to be wrapped. | |
| 383 | + * | |
| 384 | + * @return the wrapped key. | |
| 385 | + * | |
| 386 | + * @exception IllegalBlockSizeException if this cipher is a block | |
| 387 | + * cipher, no padding has been requested, and the length of the | |
| 388 | + * encoding of the key to be wrapped is not a | |
| 389 | + * multiple of the block size. | |
| 390 | + * | |
| 391 | + * @exception InvalidKeyException if it is impossible or unsafe to | |
| 392 | + * wrap the key with this cipher (e.g., a hardware protected key is | |
| 393 | + * being passed to a software only cipher). | |
| 394 | + */ | |
| 395 | + protected byte[] engineWrap(Key key) | |
| 396 | + throws IllegalBlockSizeException, InvalidKeyException { | |
| 397 | + return core.wrap(key); | |
| 398 | + } | |
| 399 | + | |
| 400 | + /** | |
| 401 | + * Unwrap a previously wrapped key. | |
| 402 | + * | |
| 403 | + * @param wrappedKey the key to be unwrapped. | |
| 404 | + * | |
| 405 | + * @param wrappedKeyAlgorithm the algorithm the wrapped key is for. | |
| 406 | + * | |
| 407 | + * @param wrappedKeyType the type of the wrapped key. | |
| 408 | + * This is one of <code>Cipher.SECRET_KEY</code>, | |
| 409 | + * <code>Cipher.PRIVATE_KEY</code>, or <code>Cipher.PUBLIC_KEY</code>. | |
| 410 | + * | |
| 411 | + * @return the unwrapped key. | |
| 412 | + * | |
| 413 | + * @exception NoSuchAlgorithmException if no installed providers | |
| 414 | + * can create keys of type <code>wrappedKeyType</code> for the | |
| 415 | + * <code>wrappedKeyAlgorithm</code>. | |
| 416 | + * | |
| 417 | + * @exception InvalidKeyException if <code>wrappedKey</code> does not | |
| 418 | + * represent a wrapped key of type <code>wrappedKeyType</code> for | |
| 419 | + * the <code>wrappedKeyAlgorithm</code>. | |
| 420 | + */ | |
| 421 | + protected Key engineUnwrap(byte[] wrappedKey, | |
| 422 | + String wrappedKeyAlgorithm, | |
| 423 | + int wrappedKeyType) | |
| 424 | + throws InvalidKeyException, NoSuchAlgorithmException { | |
| 425 | + return core.unwrap(wrappedKey, wrappedKeyAlgorithm, | |
| 426 | + wrappedKeyType); | |
| 427 | + } | |
| 428 | +} | |
| @@ -0,0 +1,41 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * This class defines the constants used by the Blowfish algorithm | |
| 30 | + * implementation. | |
| 31 | + * | |
| 32 | + * @author Jan Luehe | |
| 33 | + * | |
| 34 | + * @see BlowfishCipher | |
| 35 | + * @see BlowfishCrypt | |
| 36 | + */ | |
| 37 | + | |
| 38 | +interface BlowfishConstants { | |
| 39 | + int BLOWFISH_BLOCK_SIZE = 8; // number of bytes | |
| 40 | + int BLOWFISH_MAX_KEYSIZE = 56; // number of bytes | |
| 41 | +} | |
| @@ -0,0 +1,558 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.security.InvalidKeyException; | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * This is the internal Blowfish class responsible for encryption and | |
| 32 | + * decryption of a byte array of size <code>BLOWFISH_BLOCK_SIZE</code>. | |
| 33 | + * | |
| 34 | + * @author Jan Luehe | |
| 35 | + * @author David Brownell | |
| 36 | + * | |
| 37 | + * @see BlowfishCipher | |
| 38 | + */ | |
| 39 | + | |
| 40 | +final class BlowfishCrypt extends SymmetricCipher | |
| 41 | + implements BlowfishConstants { | |
| 42 | + | |
| 43 | + /* | |
| 44 | + * Are we encrypting or decrypting? | |
| 45 | + */ | |
| 46 | + private boolean decrypting = false; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Gets this cipher's block size. | |
| 50 | + * | |
| 51 | + * @return this cipher's block size | |
| 52 | + */ | |
| 53 | + int getBlockSize() { | |
| 54 | + return BLOWFISH_BLOCK_SIZE; | |
| 55 | + } | |
| 56 | + | |
| 57 | + void init(boolean decrypting, String algorithm, byte[] rawKey) | |
| 58 | + throws InvalidKeyException { | |
| 59 | + this.decrypting = decrypting; | |
| 60 | + if (!algorithm.equalsIgnoreCase("Blowfish")) { | |
| 61 | + throw new InvalidKeyException("Wrong algorithm: Blowfish required"); | |
| 62 | + } | |
| 63 | + if (rawKey.length > BLOWFISH_MAX_KEYSIZE) { | |
| 64 | + throw new InvalidKeyException("Key too long (> 448 bits)"); | |
| 65 | + } | |
| 66 | + // Step 1: Init P and then S arrays from pi bytes | |
| 67 | + int i, j, count; | |
| 68 | + | |
| 69 | + System.arraycopy(pi, 0, p, 0, 18); | |
| 70 | + System.arraycopy(pi, 18, s0, 0, 256); | |
| 71 | + System.arraycopy(pi, 18 + 256, s1, 0, 256); | |
| 72 | + System.arraycopy(pi, 18 + 512, s2, 0, 256); | |
| 73 | + System.arraycopy(pi, 18 + 768, s3, 0, 256); | |
| 74 | + | |
| 75 | + // Step 2: XOR all parts of P with key data | |
| 76 | + int tmp = 0; | |
| 77 | + int nLen = rawKey.length; | |
| 78 | + int nKeyPos = 0; | |
| 79 | + for (i = 0; i < 18; i++) { | |
| 80 | + for (j = 0; j < 4; j++) { | |
| 81 | + tmp <<= 8; | |
| 82 | + tmp |= 0x0ff & rawKey[nKeyPos]; | |
| 83 | + if (++nKeyPos == nLen) nKeyPos = 0; | |
| 84 | + } | |
| 85 | + p[i] ^= tmp; | |
| 86 | + } | |
| 87 | + | |
| 88 | + // Steps 3-7: Replace all P, S values with computed values | |
| 89 | + int[] data = new int[2]; | |
| 90 | + | |
| 91 | + for (i = 0; i < 18; i+=2) { | |
| 92 | + encryptBlock(data); | |
| 93 | + p[i] = data[0]; | |
| 94 | + p[i+1] = data[1]; | |
| 95 | + } | |
| 96 | + | |
| 97 | + for (j = 0; j < 256; j+=2) { | |
| 98 | + encryptBlock(data); | |
| 99 | + s0[j] = data[0]; | |
| 100 | + s0[j+1] = data[1]; | |
| 101 | + } | |
| 102 | + for (j = 0; j < 256; j+=2) { | |
| 103 | + encryptBlock(data); | |
| 104 | + s1[j] = data[0]; | |
| 105 | + s1[j+1] = data[1]; | |
| 106 | + } | |
| 107 | + for (j = 0; j < 256; j+=2) { | |
| 108 | + encryptBlock(data); | |
| 109 | + s2[j] = data[0]; | |
| 110 | + s2[j+1] = data[1]; | |
| 111 | + } | |
| 112 | + for (j = 0; j < 256; j+=2) { | |
| 113 | + encryptBlock(data); | |
| 114 | + s3[j] = data[0]; | |
| 115 | + s3[j+1] = data[1]; | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 120 | + * Performs encryption operation. | |
| 121 | + * | |
| 122 | + * <p>The input plain text <code>plain</code>, starting at | |
| 123 | + * <code>plainOffset</code> and ending at | |
| 124 | + * <code>(plainOffset + len - 1)</code>, is encrypted. | |
| 125 | + * The result is stored in <code>cipher</code>, starting at | |
| 126 | + * <code>cipherOffset</code>. | |
| 127 | + * | |
| 128 | + * <p>The subclass that implements Cipher should ensure that | |
| 129 | + * <code>init</code> has been called before this method is called. | |
| 130 | + * | |
| 131 | + * @param plain the buffer with the input data to be encrypted | |
| 132 | + * @param plainOffset the offset in <code>plain</code> | |
| 133 | + * @param plainLen the length of the input data | |
| 134 | + * @param cipher the buffer for the result | |
| 135 | + * @param cipherOffset the offset in <code>cipher</code> | |
| 136 | + */ | |
| 137 | + void encryptBlock(byte[] plain, int plainOffset, | |
| 138 | + byte[] cipher, int cipherOffset) | |
| 139 | + { | |
| 140 | + cipherBlock(plain, plainOffset, cipher, cipherOffset); | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Performs decryption operation. | |
| 145 | + * | |
| 146 | + * <p>The input cipher text <code>cipher</code>, starting at | |
| 147 | + * <code>cipherOffset</code> and ending at | |
| 148 | + * <code>(cipherOffset + len - 1)</code>, is decrypted. | |
| 149 | + * The result is stored in <code>plain</code>, starting at | |
| 150 | + * <code>plainOffset</code>. | |
| 151 | + * | |
| 152 | + * <p>The subclass that implements Cipher should ensure that | |
| 153 | + * <code>init</code> has been called before this method is called. | |
| 154 | + * | |
| 155 | + * @param cipher the buffer with the input data to be decrypted | |
| 156 | + * @param cipherOffset the offset in <code>cipherOffset</code> | |
| 157 | + * @param cipherLen the length of the input data | |
| 158 | + * @param plain the buffer for the result | |
| 159 | + * @param plainOffset the offset in <code>plain</code> | |
| 160 | + */ | |
| 161 | + void decryptBlock(byte[] cipher, int cipherOffset, | |
| 162 | + byte[] plain, int plainOffset) | |
| 163 | + { | |
| 164 | + cipherBlock(cipher, cipherOffset, plain, plainOffset); | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * Encrypts, or decrypts, the blocks of data passed in. | |
| 169 | + */ | |
| 170 | + private void cipherBlock(byte[] in, int inOffset, | |
| 171 | + byte[] out, int outOffset) { | |
| 172 | + temp[0] = ((in[inOffset ] ) << 24) | | |
| 173 | + ((in[inOffset + 1] & 0xff) << 16) | | |
| 174 | + ((in[inOffset + 2] & 0xff) << 8) | | |
| 175 | + ((in[inOffset + 3] & 0xff) ); | |
| 176 | + | |
| 177 | + temp[1] = ((in[inOffset + 4] ) << 24) | | |
| 178 | + ((in[inOffset + 5] & 0xff) << 16) | | |
| 179 | + ((in[inOffset + 6] & 0xff) << 8) | | |
| 180 | + ((in[inOffset + 7] & 0xff) ); | |
| 181 | + | |
| 182 | + if (decrypting) { | |
| 183 | + decryptBlock(temp); | |
| 184 | + } else { | |
| 185 | + encryptBlock(temp); | |
| 186 | + } | |
| 187 | + | |
| 188 | + int t = temp[0]; | |
| 189 | + out[outOffset ] = (byte)(t >> 24); | |
| 190 | + out[outOffset + 1] = (byte)(t >> 16); | |
| 191 | + out[outOffset + 2] = (byte)(t >> 8); | |
| 192 | + out[outOffset + 3] = (byte)(t ); | |
| 193 | + | |
| 194 | + t = temp[1]; | |
| 195 | + out[outOffset + 4] = (byte)(t >> 24); | |
| 196 | + out[outOffset + 5] = (byte)(t >> 16); | |
| 197 | + out[outOffset + 6] = (byte)(t >> 8); | |
| 198 | + out[outOffset + 7] = (byte)(t ); | |
| 199 | + } | |
| 200 | + | |
| 201 | + /** | |
| 202 | + * Encrypts a single block, in place. | |
| 203 | + */ | |
| 204 | + private void encryptBlock(int[] value) { | |
| 205 | + int left = value[0]; | |
| 206 | + int right = value[1]; | |
| 207 | + | |
| 208 | + left ^= p[0]; | |
| 209 | + | |
| 210 | + right ^= F(left) ^ p[1]; | |
| 211 | + left ^= F(right) ^ p[2]; | |
| 212 | + right ^= F(left) ^ p[3]; | |
| 213 | + left ^= F(right) ^ p[4]; | |
| 214 | + | |
| 215 | + right ^= F(left) ^ p[5]; | |
| 216 | + left ^= F(right) ^ p[6]; | |
| 217 | + right ^= F(left) ^ p[7]; | |
| 218 | + left ^= F(right) ^ p[8]; | |
| 219 | + | |
| 220 | + right ^= F(left) ^ p[9]; | |
| 221 | + left ^= F(right) ^ p[10]; | |
| 222 | + right ^= F(left) ^ p[11]; | |
| 223 | + left ^= F(right) ^ p[12]; | |
| 224 | + | |
| 225 | + right ^= F(left) ^ p[13]; | |
| 226 | + left ^= F(right) ^ p[14]; | |
| 227 | + right ^= F(left) ^ p[15]; | |
| 228 | + left ^= F(right) ^ p[16]; | |
| 229 | + | |
| 230 | + right ^= p[17]; | |
| 231 | + | |
| 232 | + value[0] = right; | |
| 233 | + value[1] = left; | |
| 234 | + } | |
| 235 | + | |
| 236 | + /** | |
| 237 | + * Decrypts a single block, in place. | |
| 238 | + */ | |
| 239 | + private void decryptBlock(int[] value) { | |
| 240 | + int left = value[1]; | |
| 241 | + int right = value[0]; | |
| 242 | + | |
| 243 | + right ^= p[17]; | |
| 244 | + | |
| 245 | + left ^= p[16] ^ F(right); | |
| 246 | + right ^= p[15] ^ F(left); | |
| 247 | + left ^= p[14] ^ F(right); | |
| 248 | + right ^= p[13] ^ F(left); | |
| 249 | + | |
| 250 | + left ^= p[12] ^ F(right); | |
| 251 | + right ^= p[11] ^ F(left); | |
| 252 | + left ^= p[10] ^ F(right); | |
| 253 | + right ^= p[9] ^ F(left); | |
| 254 | + | |
| 255 | + left ^= p[8] ^ F(right); | |
| 256 | + right ^= p[7] ^ F(left); | |
| 257 | + left ^= p[6] ^ F(right); | |
| 258 | + right ^= p[5] ^ F(left); | |
| 259 | + | |
| 260 | + left ^= p[4] ^ F(right); | |
| 261 | + right ^= p[3] ^ F(left); | |
| 262 | + left ^= p[2] ^ F(right); | |
| 263 | + right ^= p[1] ^ F(left); | |
| 264 | + | |
| 265 | + left ^= p[0]; | |
| 266 | + | |
| 267 | + value[0] = left; | |
| 268 | + value[1] = right; | |
| 269 | + } | |
| 270 | + | |
| 271 | + /** | |
| 272 | + * Calculates the S-Box function F(). | |
| 273 | + * | |
| 274 | + * This gets used "rounds" times on each encryption/decryption. | |
| 275 | + */ | |
| 276 | + private int F(int v) { | |
| 277 | + return (( s0[ v >>> 24 ] | |
| 278 | + + s1[(v >> 16) & 0xff]) | |
| 279 | + ^ s2[(v >> 8) & 0xff]) | |
| 280 | + + s3[ v & 0xff]; | |
| 281 | + } | |
| 282 | + | |
| 283 | + private final int[] p = new int[18]; // subkeys | |
| 284 | + private final int[] s0 = new int[256]; // s-boxes | |
| 285 | + private final int[] s1 = new int[256]; | |
| 286 | + private final int[] s2 = new int[256]; | |
| 287 | + private final int[] s3 = new int[256]; | |
| 288 | + private final int[] temp = new int[2]; // to avoid encrypt/decrypt mallocs | |
| 289 | + | |
| 290 | + // many digits of pi, for initializing p and s | |
| 291 | + private static final int[] pi = { | |
| 292 | + | |
| 293 | + // p [rounds + 2] | |
| 294 | + 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, | |
| 295 | + 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, | |
| 296 | + 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, | |
| 297 | + 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, | |
| 298 | + 0x9216d5d9, 0x8979fb1b, | |
| 299 | + | |
| 300 | + // s [4][256] | |
| 301 | + 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, | |
| 302 | + 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, | |
| 303 | + 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, | |
| 304 | + 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, | |
| 305 | + 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, | |
| 306 | + 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, | |
| 307 | + 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, | |
| 308 | + 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, | |
| 309 | + 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, | |
| 310 | + 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, | |
| 311 | + 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, | |
| 312 | + 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, | |
| 313 | + 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, | |
| 314 | + 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, | |
| 315 | + 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, | |
| 316 | + 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, | |
| 317 | + 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, | |
| 318 | + 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, | |
| 319 | + 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, | |
| 320 | + 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, | |
| 321 | + 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, | |
| 322 | + 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, | |
| 323 | + 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, | |
| 324 | + 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, | |
| 325 | + 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, | |
| 326 | + 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, | |
| 327 | + 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, | |
| 328 | + 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, | |
| 329 | + 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, | |
| 330 | + 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, | |
| 331 | + 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, | |
| 332 | + 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, | |
| 333 | + 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, | |
| 334 | + 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, | |
| 335 | + 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, | |
| 336 | + 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, | |
| 337 | + 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, | |
| 338 | + 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, | |
| 339 | + 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, | |
| 340 | + 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, | |
| 341 | + 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, | |
| 342 | + 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, | |
| 343 | + 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, | |
| 344 | + 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, | |
| 345 | + 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, | |
| 346 | + 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, | |
| 347 | + 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, | |
| 348 | + 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, | |
| 349 | + 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, | |
| 350 | + 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, | |
| 351 | + 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, | |
| 352 | + 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, | |
| 353 | + 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, | |
| 354 | + 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, | |
| 355 | + 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, | |
| 356 | + 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, | |
| 357 | + 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, | |
| 358 | + 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, | |
| 359 | + 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, | |
| 360 | + 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, | |
| 361 | + 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, | |
| 362 | + 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, | |
| 363 | + 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, | |
| 364 | + 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a, | |
| 365 | + 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, | |
| 366 | + 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, | |
| 367 | + 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, | |
| 368 | + 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, | |
| 369 | + 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, | |
| 370 | + 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, | |
| 371 | + 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, | |
| 372 | + 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, | |
| 373 | + 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, | |
| 374 | + 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, | |
| 375 | + 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, | |
| 376 | + 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, | |
| 377 | + 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, | |
| 378 | + 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, | |
| 379 | + 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, | |
| 380 | + 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, | |
| 381 | + 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, | |
| 382 | + 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, | |
| 383 | + 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, | |
| 384 | + 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, | |
| 385 | + 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, | |
| 386 | + 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, | |
| 387 | + 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, | |
| 388 | + 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, | |
| 389 | + 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, | |
| 390 | + 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, | |
| 391 | + 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, | |
| 392 | + 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, | |
| 393 | + 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, | |
| 394 | + 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, | |
| 395 | + 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, | |
| 396 | + 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, | |
| 397 | + 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, | |
| 398 | + 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, | |
| 399 | + 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, | |
| 400 | + 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, | |
| 401 | + 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, | |
| 402 | + 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, | |
| 403 | + 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, | |
| 404 | + 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, | |
| 405 | + 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, | |
| 406 | + 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, | |
| 407 | + 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, | |
| 408 | + 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, | |
| 409 | + 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, | |
| 410 | + 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, | |
| 411 | + 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, | |
| 412 | + 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, | |
| 413 | + 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, | |
| 414 | + 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, | |
| 415 | + 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, | |
| 416 | + 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, | |
| 417 | + 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, | |
| 418 | + 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, | |
| 419 | + 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, | |
| 420 | + 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, | |
| 421 | + 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, | |
| 422 | + 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, | |
| 423 | + 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, | |
| 424 | + 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, | |
| 425 | + 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, | |
| 426 | + 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, | |
| 427 | + 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, | |
| 428 | + 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7, | |
| 429 | + 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, | |
| 430 | + 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, | |
| 431 | + 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, | |
| 432 | + 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, | |
| 433 | + 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, | |
| 434 | + 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, | |
| 435 | + 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, | |
| 436 | + 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, | |
| 437 | + 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, | |
| 438 | + 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, | |
| 439 | + 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, | |
| 440 | + 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, | |
| 441 | + 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, | |
| 442 | + 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, | |
| 443 | + 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, | |
| 444 | + 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, | |
| 445 | + 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, | |
| 446 | + 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, | |
| 447 | + 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, | |
| 448 | + 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, | |
| 449 | + 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, | |
| 450 | + 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, | |
| 451 | + 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, | |
| 452 | + 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, | |
| 453 | + 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, | |
| 454 | + 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, | |
| 455 | + 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, | |
| 456 | + 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, | |
| 457 | + 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, | |
| 458 | + 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, | |
| 459 | + 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, | |
| 460 | + 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, | |
| 461 | + 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, | |
| 462 | + 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, | |
| 463 | + 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, | |
| 464 | + 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, | |
| 465 | + 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, | |
| 466 | + 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, | |
| 467 | + 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, | |
| 468 | + 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, | |
| 469 | + 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, | |
| 470 | + 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, | |
| 471 | + 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, | |
| 472 | + 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, | |
| 473 | + 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, | |
| 474 | + 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, | |
| 475 | + 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, | |
| 476 | + 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, | |
| 477 | + 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, | |
| 478 | + 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, | |
| 479 | + 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, | |
| 480 | + 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, | |
| 481 | + 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, | |
| 482 | + 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, | |
| 483 | + 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, | |
| 484 | + 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, | |
| 485 | + 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, | |
| 486 | + 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, | |
| 487 | + 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, | |
| 488 | + 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, | |
| 489 | + 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, | |
| 490 | + 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, | |
| 491 | + 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, | |
| 492 | + 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0, | |
| 493 | + 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, | |
| 494 | + 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, | |
| 495 | + 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, | |
| 496 | + 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, | |
| 497 | + 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, | |
| 498 | + 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, | |
| 499 | + 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, | |
| 500 | + 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, | |
| 501 | + 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, | |
| 502 | + 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, | |
| 503 | + 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, | |
| 504 | + 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, | |
| 505 | + 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, | |
| 506 | + 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, | |
| 507 | + 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, | |
| 508 | + 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, | |
| 509 | + 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, | |
| 510 | + 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, | |
| 511 | + 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, | |
| 512 | + 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, | |
| 513 | + 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, | |
| 514 | + 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, | |
| 515 | + 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, | |
| 516 | + 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, | |
| 517 | + 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, | |
| 518 | + 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, | |
| 519 | + 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, | |
| 520 | + 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, | |
| 521 | + 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, | |
| 522 | + 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, | |
| 523 | + 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, | |
| 524 | + 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, | |
| 525 | + 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, | |
| 526 | + 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, | |
| 527 | + 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, | |
| 528 | + 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, | |
| 529 | + 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, | |
| 530 | + 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, | |
| 531 | + 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, | |
| 532 | + 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, | |
| 533 | + 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, | |
| 534 | + 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, | |
| 535 | + 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, | |
| 536 | + 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, | |
| 537 | + 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, | |
| 538 | + 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, | |
| 539 | + 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, | |
| 540 | + 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, | |
| 541 | + 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, | |
| 542 | + 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, | |
| 543 | + 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, | |
| 544 | + 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, | |
| 545 | + 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, | |
| 546 | + 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, | |
| 547 | + 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, | |
| 548 | + 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, | |
| 549 | + 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, | |
| 550 | + 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, | |
| 551 | + 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, | |
| 552 | + 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, | |
| 553 | + 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, | |
| 554 | + 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, | |
| 555 | + 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, | |
| 556 | + 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6, | |
| 557 | + }; | |
| 558 | +} | |
| @@ -0,0 +1,115 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.security.SecureRandom; | |
| 29 | +import java.security.InvalidParameterException; | |
| 30 | +import java.security.InvalidAlgorithmParameterException; | |
| 31 | +import java.security.spec.AlgorithmParameterSpec; | |
| 32 | +import javax.crypto.KeyGeneratorSpi; | |
| 33 | +import javax.crypto.SecretKey; | |
| 34 | +import javax.crypto.spec.SecretKeySpec; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * This class generates a secret key for use with the Blowfish algorithm. | |
| 38 | + * | |
| 39 | + * @author Jan Luehe | |
| 40 | + * | |
| 41 | + */ | |
| 42 | + | |
| 43 | +public final class BlowfishKeyGenerator extends KeyGeneratorSpi { | |
| 44 | + | |
| 45 | + private SecureRandom random = null; | |
| 46 | + private int keysize = 16; // default keysize (in number of bytes) | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Empty constructor | |
| 50 | + */ | |
| 51 | + public BlowfishKeyGenerator() { | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Initializes this key generator. | |
| 56 | + * | |
| 57 | + * @param random the source of randomness for this generator | |
| 58 | + */ | |
| 59 | + protected void engineInit(SecureRandom random) { | |
| 60 | + this.random = random; | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Initializes this key generator with the specified parameter | |
| 65 | + * set and a user-provided source of randomness. | |
| 66 | + * | |
| 67 | + * @param params the key generation parameters | |
| 68 | + * @param random the source of randomness for this key generator | |
| 69 | + * | |
| 70 | + * @exception InvalidAlgorithmParameterException if <code>params</code> is | |
| 71 | + * inappropriate for this key generator | |
| 72 | + */ | |
| 73 | + protected void engineInit(AlgorithmParameterSpec params, | |
| 74 | + SecureRandom random) | |
| 75 | + throws InvalidAlgorithmParameterException | |
| 76 | + { | |
| 77 | + throw new InvalidAlgorithmParameterException | |
| 78 | + ("Blowfish key generation does not take any parameters"); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Initializes this key generator for a certain keysize, using the given | |
| 83 | + * source of randomness. | |
| 84 | + * | |
| 85 | + * @param keysize the keysize. This is an algorithm-specific | |
| 86 | + * metric specified in number of bits. | |
| 87 | + * @param random the source of randomness for this key generator | |
| 88 | + */ | |
| 89 | + protected void engineInit(int keysize, SecureRandom random) { | |
| 90 | + if (((keysize % 8) != 0) || (keysize < 32) || (keysize > 448)) { | |
| 91 | + throw new InvalidParameterException("Keysize must be " | |
| 92 | + + "multiple of 8, and can " | |
| 93 | + + "only range from 32 to 448 " | |
| 94 | + + "(inclusive)"); | |
| 95 | + } | |
| 96 | + this.keysize = keysize / 8; | |
| 97 | + this.engineInit(random); | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Generates a Blowfish key. | |
| 102 | + * | |
| 103 | + * @return the new Blowfish key | |
| 104 | + */ | |
| 105 | + protected SecretKey engineGenerateKey() { | |
| 106 | + if (this.random == null) { | |
| 107 | + this.random = SunJCE.RANDOM; | |
| 108 | + } | |
| 109 | + | |
| 110 | + byte[] keyBytes = new byte[this.keysize]; | |
| 111 | + this.random.nextBytes(keyBytes); | |
| 112 | + | |
| 113 | + return new SecretKeySpec(keyBytes, "Blowfish"); | |
| 114 | + } | |
| 115 | +} | |
| @@ -0,0 +1,88 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.util.*; | |
| 29 | +import java.io.*; | |
| 30 | +import sun.security.util.*; | |
| 31 | +import java.security.AlgorithmParametersSpi; | |
| 32 | +import java.security.spec.AlgorithmParameterSpec; | |
| 33 | +import java.security.spec.InvalidParameterSpecException; | |
| 34 | +import javax.crypto.spec.IvParameterSpec; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * This class implements the parameter (IV) used with the Blowfish algorithm in | |
| 38 | + * feedback-mode. IV is defined in the standards as follows: | |
| 39 | + * | |
| 40 | + * <pre> | |
| 41 | + * IV ::= OCTET STRING -- 8 octets | |
| 42 | + * </pre> | |
| 43 | + * | |
| 44 | + * @author Jan Luehe | |
| 45 | + * | |
| 46 | + */ | |
| 47 | + | |
| 48 | +public final class BlowfishParameters extends AlgorithmParametersSpi { | |
| 49 | + | |
| 50 | + private BlockCipherParamsCore core; | |
| 51 | + | |
| 52 | + public BlowfishParameters() { | |
| 53 | + core = new BlockCipherParamsCore | |
| 54 | + (BlowfishConstants.BLOWFISH_BLOCK_SIZE); | |
| 55 | + } | |
| 56 | + protected void engineInit(AlgorithmParameterSpec paramSpec) | |
| 57 | + throws InvalidParameterSpecException { | |
| 58 | + core.init(paramSpec); | |
| 59 | + } | |
| 60 | + | |
| 61 | + protected void engineInit(byte[] encoded) | |
| 62 | + throws IOException { | |
| 63 | + core.init(encoded); | |
| 64 | + } | |
| 65 | + | |
| 66 | + protected void engineInit(byte[] encoded, String decodingMethod) | |
| 67 | + throws IOException { | |
| 68 | + core.init(encoded, decodingMethod); | |
| 69 | + } | |
| 70 | + | |
| 71 | + protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) | |
| 72 | + throws InvalidParameterSpecException { | |
| 73 | + return core.getParameterSpec(paramSpec); | |
| 74 | + } | |
| 75 | + | |
| 76 | + protected byte[] engineGetEncoded() throws IOException { | |
| 77 | + return core.getEncoded(); | |
| 78 | + } | |
| 79 | + | |
| 80 | + protected byte[] engineGetEncoded(String encodingMethod) | |
| 81 | + throws IOException { | |
| 82 | + return core.getEncoded(); | |
| 83 | + } | |
| 84 | + | |
| 85 | + protected String engineToString() { | |
| 86 | + return core.toString(); | |
| 87 | + } | |
| 88 | +} | |
| @@ -0,0 +1,212 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.security.InvalidKeyException; | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * This class represents ciphers in cipher block chaining (CBC) mode. | |
| 32 | + * | |
| 33 | + * <p>This mode is implemented independently of a particular cipher. | |
| 34 | + * Ciphers to which this mode should apply (e.g., DES) must be | |
| 35 | + * <i>plugged-in</i> using the constructor. | |
| 36 | + * | |
| 37 | + * <p>NOTE: This class does not deal with buffering or padding. | |
| 38 | + * | |
| 39 | + * @author Gigi Ankeny | |
| 40 | + */ | |
| 41 | + | |
| 42 | +class CipherBlockChaining extends FeedbackCipher { | |
| 43 | + | |
| 44 | + /* | |
| 45 | + * random bytes that are initialized with iv | |
| 46 | + */ | |
| 47 | + protected byte[] r; | |
| 48 | + | |
| 49 | + /* | |
| 50 | + * output buffer | |
| 51 | + */ | |
| 52 | + private byte[] k; | |
| 53 | + | |
| 54 | + // variables for save/restore calls | |
| 55 | + private byte[] rSave = null; | |
| 56 | + | |
| 57 | + CipherBlockChaining(SymmetricCipher embeddedCipher) { | |
| 58 | + super(embeddedCipher); | |
| 59 | + k = new byte[blockSize]; | |
| 60 | + r = new byte[blockSize]; | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Gets the name of this feedback mode. | |
| 65 | + * | |
| 66 | + * @return the string <code>CBC</code> | |
| 67 | + */ | |
| 68 | + String getFeedback() { | |
| 69 | + return "CBC"; | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Initializes the cipher in the specified mode with the given key | |
| 74 | + * and iv. | |
| 75 | + * | |
| 76 | + * @param decrypting flag indicating encryption or decryption | |
| 77 | + * @param algorithm the algorithm name | |
| 78 | + * @param key the key | |
| 79 | + * @param iv the iv | |
| 80 | + * | |
| 81 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 82 | + * initializing this cipher | |
| 83 | + */ | |
| 84 | + void init(boolean decrypting, String algorithm, byte[] key, byte[] iv) | |
| 85 | + throws InvalidKeyException { | |
| 86 | + if ((key == null) || (iv == null) || (iv.length != blockSize)) { | |
| 87 | + throw new InvalidKeyException("Internal error"); | |
| 88 | + } | |
| 89 | + this.iv = iv; | |
| 90 | + reset(); | |
| 91 | + embeddedCipher.init(decrypting, algorithm, key); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Resets the iv to its original value. | |
| 96 | + * This is used when doFinal is called in the Cipher class, so that the | |
| 97 | + * cipher can be reused (with its original iv). | |
| 98 | + */ | |
| 99 | + void reset() { | |
| 100 | + System.arraycopy(iv, 0, r, 0, blockSize); | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * Save the current content of this cipher. | |
| 105 | + */ | |
| 106 | + void save() { | |
| 107 | + if (rSave == null) { | |
| 108 | + rSave = new byte[blockSize]; | |
| 109 | + } | |
| 110 | + System.arraycopy(r, 0, rSave, 0, blockSize); | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Restores the content of this cipher to the previous saved one. | |
| 115 | + */ | |
| 116 | + void restore() { | |
| 117 | + System.arraycopy(rSave, 0, r, 0, blockSize); | |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * Performs encryption operation. | |
| 122 | + * | |
| 123 | + * <p>The input plain text <code>plain</code>, starting at | |
| 124 | + * <code>plainOffset</code> and ending at | |
| 125 | + * <code>(plainOffset + len - 1)</code>, is encrypted. | |
| 126 | + * The result is stored in <code>cipher</code>, starting at | |
| 127 | + * <code>cipherOffset</code>. | |
| 128 | + * | |
| 129 | + * <p>It is the application's responsibility to make sure that | |
| 130 | + * <code>plainLen</code> is a multiple of the embedded cipher's block size, | |
| 131 | + * as any excess bytes are ignored. | |
| 132 | + * | |
| 133 | + * @param plain the buffer with the input data to be encrypted | |
| 134 | + * @param plainOffset the offset in <code>plain</code> | |
| 135 | + * @param plainLen the length of the input data | |
| 136 | + * @param cipher the buffer for the result | |
| 137 | + * @param cipherOffset the offset in <code>cipher</code> | |
| 138 | + */ | |
| 139 | + void encrypt(byte[] plain, int plainOffset, int plainLen, | |
| 140 | + byte[] cipher, int cipherOffset) | |
| 141 | + { | |
| 142 | + int i; | |
| 143 | + int endIndex = plainOffset + plainLen; | |
| 144 | + | |
| 145 | + for (; plainOffset < endIndex; | |
| 146 | + plainOffset+=blockSize, cipherOffset += blockSize) { | |
| 147 | + for (i=0; i<blockSize; i++) { | |
| 148 | + k[i] = (byte)(plain[i+plainOffset] ^ r[i]); | |
| 149 | + } | |
| 150 | + embeddedCipher.encryptBlock(k, 0, cipher, cipherOffset); | |
| 151 | + System.arraycopy(cipher, cipherOffset, r, 0, blockSize); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + | |
| 155 | + /** | |
| 156 | + * Performs decryption operation. | |
| 157 | + * | |
| 158 | + * <p>The input cipher text <code>cipher</code>, starting at | |
| 159 | + * <code>cipherOffset</code> and ending at | |
| 160 | + * <code>(cipherOffset + len - 1)</code>, is decrypted. | |
| 161 | + * The result is stored in <code>plain</code>, starting at | |
| 162 | + * <code>plainOffset</code>. | |
| 163 | + * | |
| 164 | + * <p>It is the application's responsibility to make sure that | |
| 165 | + * <code>cipherLen</code> is a multiple of the embedded cipher's block | |
| 166 | + * size, as any excess bytes are ignored. | |
| 167 | + * | |
| 168 | + * <p>It is also the application's responsibility to make sure that | |
| 169 | + * <code>init</code> has been called before this method is called. | |
| 170 | + * (This check is omitted here, to avoid double checking.) | |
| 171 | + * | |
| 172 | + * @param cipher the buffer with the input data to be decrypted | |
| 173 | + * @param cipherOffset the offset in <code>cipherOffset</code> | |
| 174 | + * @param cipherLen the length of the input data | |
| 175 | + * @param plain the buffer for the result | |
| 176 | + * @param plainOffset the offset in <code>plain</code> | |
| 177 | + * | |
| 178 | + * @exception IllegalBlockSizeException if input data whose length does | |
| 179 | + * not correspond to the embedded cipher's block size is passed to the | |
| 180 | + * embedded cipher | |
| 181 | + */ | |
| 182 | + void decrypt(byte[] cipher, int cipherOffset, int cipherLen, | |
| 183 | + byte[] plain, int plainOffset) | |
| 184 | + { | |
| 185 | + int i; | |
| 186 | + byte[] cipherOrig=null; | |
| 187 | + int endIndex = cipherOffset + cipherLen; | |
| 188 | + | |
| 189 | + if (cipher==plain && (cipherOffset >= plainOffset) | |
| 190 | + && ((cipherOffset - plainOffset) < blockSize)) { | |
| 191 | + // Save the original ciphertext blocks, so they can be | |
| 192 | + // stored in the feedback register "r". | |
| 193 | + // This is necessary because in this constellation, a | |
| 194 | + // ciphertext block (or parts of it) will be overridden by | |
| 195 | + // the plaintext result. | |
| 196 | + cipherOrig = (byte[])cipher.clone(); | |
| 197 | + } | |
| 198 | + | |
| 199 | + for (; cipherOffset < endIndex; | |
| 200 | + cipherOffset += blockSize, plainOffset += blockSize) { | |
| 201 | + embeddedCipher.decryptBlock(cipher, cipherOffset, k, 0); | |
| 202 | + for (i = 0; i < blockSize; i++) { | |
| 203 | + plain[i+plainOffset] = (byte)(k[i] ^ r[i]); | |
| 204 | + } | |
| 205 | + if (cipherOrig==null) { | |
| 206 | + System.arraycopy(cipher, cipherOffset, r, 0, blockSize); | |
| 207 | + } else { | |
| 208 | + System.arraycopy(cipherOrig, cipherOffset, r, 0, blockSize); | |
| 209 | + } | |
| 210 | + } | |
| 211 | + } | |
| 212 | +} | |
| @@ -0,0 +1,943 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.crypto.provider; | |
| 27 | + | |
| 28 | +import java.util.Locale; | |
| 29 | + | |
| 30 | +import java.security.*; | |
| 31 | +import java.security.spec.*; | |
| 32 | +import javax.crypto.*; | |
| 33 | +import javax.crypto.spec.*; | |
| 34 | +import javax.crypto.BadPaddingException; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * This class represents the symmetric algorithms in its various modes | |
| 38 | + * (<code>ECB</code>, <code>CFB</code>, <code>OFB</code>, <code>CBC</code>, | |
| 39 | + * <code>PCBC</code>, <code>CTR</code>, and <code>CTS</code>) and | |
| 40 | + * padding schemes (<code>PKCS5Padding</code>, <code>NoPadding</code>, | |
| 41 | + * <code>ISO10126Padding</code>). | |
| 42 | + * | |
| 43 | + * @author Gigi Ankeny | |
| 44 | + * @author Jan Luehe | |
| 45 | + * @see ElectronicCodeBook | |
| 46 | + * @see CipherFeedback | |
| 47 | + * @see OutputFeedback | |
| 48 | + * @see CipherBlockChaining | |
| 49 | + * @see PCBC | |
| 50 | + * @see CounterMode | |
| 51 | + * @see CipherTextStealing | |
| 52 | + */ | |
| 53 | + | |
| 54 | +final class CipherCore { | |
| 55 | + | |
| 56 | + /* | |
| 57 | + * internal buffer | |
| 58 | + */ | |
| 59 | + private byte[] buffer = null; | |
| 60 | + | |
| 61 | + /* | |
| 62 | + * internal buffer | |
| 63 | + */ | |
| 64 | + private int blockSize = 0; | |
| 65 | + | |
| 66 | + /* | |
| 67 | + * unit size (number of input bytes that can be processed at a time) | |
| 68 | + */ | |
| 69 | + private int unitBytes = 0; | |
| 70 | + | |
| 71 | + /* | |
| 72 | + * index of the content size left in the buffer | |
| 73 | + */ | |
| 74 | + private int buffered = 0; | |
| 75 | + | |
| 76 | + /* | |
| 77 | + * minimum number of bytes in the buffer required for | |
| 78 | + * FeedbackCipher.encryptFinal()/decryptFinal() call. | |
| 79 | + * update() must buffer this many bytes before before starting | |
| 80 | + * to encrypt/decrypt data. | |
| 81 | + * currently, only CTS mode has a non-zero value due to its special | |
| 82 | + * handling on the last two blocks (the last one may be incomplete). | |
| 83 | + */ | |
| 84 | + private int minBytes = 0; | |
| 85 | + | |
| 86 | + /* | |
| 87 | + * number of bytes needed to make the total input length a multiple | |
| 88 | + * of the blocksize (this is used in feedback mode, when the number of | |
| 89 | + * input bytes that are processed at a time is different from the block | |
| 90 | + * size) | |
| 91 | + */ | |
| 92 | + private int diffBlocksize = 0; | |
| 93 | + | |
| 94 | + /* | |
| 95 | + * padding class | |
| 96 | + */ | |
| 97 | + private Padding padding = null; | |
| 98 | + | |
| 99 | + /* | |
| 100 | + * internal cipher engine | |
| 101 | + */ | |
| 102 | + private FeedbackCipher cipher = null; | |
| 103 | + | |
| 104 | + /* | |
| 105 | + * the cipher mode | |
| 106 | + */ | |
| 107 | + private int cipherMode = ECB_MODE; | |
| 108 | + | |
| 109 | + /* | |
| 110 | + * are we encrypting or decrypting? | |
| 111 | + */ | |
| 112 | + private boolean decrypting = false; | |
| 113 | + | |
| 114 | + /* | |
| 115 | + * Block Mode constants | |
| 116 | + */ | |
| 117 | + private static final int ECB_MODE = 0; | |
| 118 | + private static final int CBC_MODE = 1; | |
| 119 | + private static final int CFB_MODE = 2; | |
| 120 | + private static final int OFB_MODE = 3; | |
| 121 | + private static final int PCBC_MODE = 4; | |
| 122 | + private static final int CTR_MODE = 5; | |
| 123 | + private static final int CTS_MODE = 6; | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * Creates an instance of CipherCore with default ECB mode and | |
| 127 | + * PKCS5Padding. | |
| 128 | + */ | |
| 129 | + CipherCore(SymmetricCipher impl, int blkSize) { | |
| 130 | + blockSize = blkSize; | |
| 131 | + unitBytes = blkSize; | |
| 132 | + diffBlocksize = blkSize; | |
| 133 | + | |
| 134 | + /* | |
| 135 | + * The buffer should be usable for all cipher mode and padding | |
| 136 | + * schemes. Thus, it has to be at least (blockSize+1) for CTS. | |
| 137 | + * In decryption mode, it also hold the possible padding block. | |
| 138 | + */ | |
| 139 | + buffer = new byte[blockSize*2]; | |
| 140 | + | |
| 141 | + // set mode and padding | |
| 142 | + cipher = new ElectronicCodeBook(impl); | |
| 143 | + padding = new PKCS5Padding(blockSize); | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Sets the mode of this cipher. | |
| 148 | + * | |
| 149 | + * @param mode the cipher mode | |
| 150 | + * | |
| 151 | + * @exception NoSuchAlgorithmException if the requested cipher mode does | |
| 152 | + * not exist | |
| 153 | + */ | |
| 154 | + void setMode(String mode) throws NoSuchAlgorithmException { | |
| 155 | + if (mode == null) | |
| 156 | + throw new NoSuchAlgorithmException("null mode"); | |
| 157 | + | |
| 158 | + String modeUpperCase = mode.toUpperCase(Locale.ENGLISH); | |
| 159 | + | |
| 160 | + if (modeUpperCase.equals("ECB")) { | |
| 161 | + return; | |
| 162 | + } | |
| 163 | + | |
| 164 | + SymmetricCipher rawImpl = cipher.getEmbeddedCipher(); | |
| 165 | + if (modeUpperCase.equals("CBC")) { | |
| 166 | + cipherMode = CBC_MODE; | |
| 167 | + cipher = new CipherBlockChaining(rawImpl); | |
| 168 | + } | |
| 169 | + else if (modeUpperCase.equals("CTS")) { | |
| 170 | + cipherMode = CTS_MODE; | |
| 171 | + cipher = new CipherTextStealing(rawImpl); | |
| 172 | + minBytes = blockSize+1; | |
| 173 | + padding = null; | |
| 174 | + } | |
| 175 | + else if (modeUpperCase.equals("CTR")) { | |
| 176 | + cipherMode = CTR_MODE; | |
| 177 | + cipher = new CounterMode(rawImpl); | |
| 178 | + unitBytes = 1; | |
| 179 | + padding = null; | |
| 180 | + } | |
| 181 | + else if (modeUpperCase.startsWith("CFB")) { | |
| 182 | + cipherMode = CFB_MODE; | |
| 183 | + unitBytes = getNumOfUnit(mode, "CFB".length(), blockSize); | |
| 184 | + cipher = new CipherFeedback(rawImpl, unitBytes); | |
| 185 | + } | |
| 186 | + else if (modeUpperCase.startsWith("OFB")) { | |
| 187 | + cipherMode = OFB_MODE; | |
| 188 | + unitBytes = getNumOfUnit(mode, "OFB".length(), blockSize); | |
| 189 | + cipher = new OutputFeedback(rawImpl, unitBytes); | |
| 190 | + } | |
| 191 | + else if (modeUpperCase.equals("PCBC")) { | |
| 192 | + cipherMode = PCBC_MODE; | |
| 193 | + cipher = new PCBC(rawImpl); | |
| 194 | + } | |
| 195 | + else { | |
| 196 | + throw new NoSuchAlgorithmException("Cipher mode: " + mode | |
| 197 | + + " not found"); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + | |
| 201 | + private static int getNumOfUnit(String mode, int offset, int blockSize) | |
| 202 | + throws NoSuchAlgorithmException { | |
| 203 | + int result = blockSize; // use blockSize as default value | |
| 204 | + if (mode.length() > offset) { | |
| 205 | + int numInt; | |
| 206 | + try { | |
| 207 | + Integer num = Integer.valueOf(mode.substring(offset)); | |
| 208 | + numInt = num.intValue(); | |
| 209 | + result = numInt >> 3; | |
| 210 | + } catch (NumberFormatException e) { | |
| 211 | + throw new NoSuchAlgorithmException | |
| 212 | + ("Algorithm mode: " + mode + " not implemented"); | |
| 213 | + } | |
| 214 | + if ((numInt % 8 != 0) || (result > blockSize)) { | |
| 215 | + throw new NoSuchAlgorithmException | |
| 216 | + ("Invalid algorithm mode: " + mode); | |
| 217 | + } | |
| 218 | + } | |
| 219 | + return result; | |
| 220 | + } | |
| 221 | + | |
| 222 | + /** | |
| 223 | + * Sets the padding mechanism of this cipher. | |
| 224 | + * | |
| 225 | + * @param padding the padding mechanism | |
| 226 | + * | |
| 227 | + * @exception NoSuchPaddingException if the requested padding mechanism | |
| 228 | + * does not exist | |
| 229 | + */ | |
| 230 | + void setPadding(String paddingScheme) | |
| 231 | + throws NoSuchPaddingException | |
| 232 | + { | |
| 233 | + if (paddingScheme == null) { | |
| 234 | + throw new NoSuchPaddingException("null padding"); | |
| 235 | + } | |
| 236 | + if (paddingScheme.equalsIgnoreCase("NoPadding")) { | |
| 237 | + padding = null; | |
| 238 | + } else if (paddingScheme.equalsIgnoreCase("ISO10126Padding")) { | |
| 239 | + padding = new ISO10126Padding(blockSize); | |
| 240 | + } else if (!paddingScheme.equalsIgnoreCase("PKCS5Padding")) { | |
| 241 | + throw new NoSuchPaddingException("Padding: " + paddingScheme | |
| 242 | + + " not implemented"); | |
| 243 | + } | |
| 244 | + if ((padding != null) && | |
| 245 | + ((cipherMode == CTR_MODE) || (cipherMode == CTS_MODE))) { | |
| 246 | + padding = null; | |
| 247 | + throw new NoSuchPaddingException | |
| 248 | + ((cipherMode == CTR_MODE? "CTR":"CTS") + | |
| 249 | + " mode must be used with NoPadding"); | |
| 250 | + } | |
| 251 | + } | |
| 252 | + | |
| 253 | + /** | |
| 254 | + * Returns the length in bytes that an output buffer would need to be in | |
| 255 | + * order to hold the result of the next <code>update</code> or | |
| 256 | + * <code>doFinal</code> operation, given the input length | |
| 257 | + * <code>inputLen</code> (in bytes). | |
| 258 | + * | |
| 259 | + * <p>This call takes into account any unprocessed (buffered) data from a | |
| 260 | + * previous <code>update</code> call, and padding. | |
| 261 | + * | |
| 262 | + * <p>The actual output length of the next <code>update</code> or | |
| 263 | + * <code>doFinal</code> call may be smaller than the length returned by | |
| 264 | + * this method. | |
| 265 | + * | |
| 266 | + * @param inputLen the input length (in bytes) | |
| 267 | + * | |
| 268 | + * @return the required output buffer size (in bytes) | |
| 269 | + */ | |
| 270 | + int getOutputSize(int inputLen) { | |
| 271 | + int totalLen = buffered + inputLen; | |
| 272 | + | |
| 273 | + if (padding == null) | |
| 274 | + return totalLen; | |
| 275 | + | |
| 276 | + if (decrypting) | |
| 277 | + return totalLen; | |
| 278 | + | |
| 279 | + if (unitBytes != blockSize) { | |
| 280 | + if (totalLen < diffBlocksize) | |
| 281 | + return diffBlocksize; | |
| 282 | + else | |
| 283 | + return (totalLen + blockSize - | |
| 284 | + ((totalLen - diffBlocksize) % blockSize)); | |
| 285 | + } else { | |
| 286 | + return totalLen + padding.padLength(totalLen); | |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + /** | |
| 291 | + * Returns the initialization vector (IV) in a new buffer. | |
| 292 | + * | |
| 293 | + * <p>This is useful in the case where a random IV has been created | |
| 294 | + * (see <a href = "#init">init</a>), | |
| 295 | + * or in the context of password-based encryption or | |
| 296 | + * decryption, where the IV is derived from a user-provided password. | |
| 297 | + * | |
| 298 | + * @return the initialization vector in a new buffer, or null if the | |
| 299 | + * underlying algorithm does not use an IV, or if the IV has not yet | |
| 300 | + * been set. | |
| 301 | + */ | |
| 302 | + byte[] getIV() { | |
| 303 | + byte[] iv = cipher.getIV(); | |
| 304 | + return (iv == null) ? null : (byte[])iv.clone(); | |
| 305 | + } | |
| 306 | + | |
| 307 | + /** | |
| 308 | + * Returns the parameters used with this cipher. | |
| 309 | + * | |
| 310 | + * <p>The returned parameters may be the same that were used to initialize | |
| 311 | + * this cipher, or may contain the default set of parameters or a set of | |
| 312 | + * randomly generated parameters used by the underlying cipher | |
| 313 | + * implementation (provided that the underlying cipher implementation | |
| 314 | + * uses a default set of parameters or creates new parameters if it needs | |
| 315 | + * parameters but was not initialized with any). | |
| 316 | + * | |
| 317 | + * @return the parameters used with this cipher, or null if this cipher | |
| 318 | + * does not use any parameters. | |
| 319 | + */ | |
| 320 | + AlgorithmParameters getParameters(String algName) { | |
| 321 | + AlgorithmParameters params = null; | |
| 322 | + if (cipherMode == ECB_MODE) return null; | |
| 323 | + byte[] iv = getIV(); | |
| 324 | + if (iv != null) { | |
| 325 | + AlgorithmParameterSpec ivSpec; | |
| 326 | + if (algName.equals("RC2")) { | |
| 327 | + RC2Crypt rawImpl = (RC2Crypt) cipher.getEmbeddedCipher(); | |
| 328 | + ivSpec = new RC2ParameterSpec(rawImpl.getEffectiveKeyBits(), | |
| 329 | + iv); | |
| 330 | + } else { | |
| 331 | + ivSpec = new IvParameterSpec(iv); | |
| 332 | + } | |
| 333 | + try { | |
| 334 | + params = AlgorithmParameters.getInstance(algName, "SunJCE"); | |
| 335 | + } catch (NoSuchAlgorithmException nsae) { | |
| 336 | + // should never happen | |
| 337 | + throw new RuntimeException("Cannot find " + algName + | |
| 338 | + " AlgorithmParameters implementation in SunJCE provider"); | |
| 339 | + } catch (NoSuchProviderException nspe) { | |
| 340 | + // should never happen | |
| 341 | + throw new RuntimeException("Cannot find SunJCE provider"); | |
| 342 | + } | |
| 343 | + try { | |
| 344 | + params.init(ivSpec); | |
| 345 | + } catch (InvalidParameterSpecException ipse) { | |
| 346 | + // should never happen | |
| 347 | + throw new RuntimeException("IvParameterSpec not supported"); | |
| 348 | + } | |
| 349 | + } | |
| 350 | + return params; | |
| 351 | + } | |
| 352 | + | |
| 353 | + /** | |
| 354 | + * Initializes this cipher with a key and a source of randomness. | |
| 355 | + * | |
| 356 | + * <p>The cipher is initialized for one of the following four operations: | |
| 357 | + * encryption, decryption, key wrapping or key unwrapping, depending on | |
| 358 | + * the value of <code>opmode</code>. | |
| 359 | + * | |
| 360 | + * <p>If this cipher requires an initialization vector (IV), it will get | |
| 361 | + * it from <code>random</code>. | |
| 362 | + * This behaviour should only be used in encryption or key wrapping | |
| 363 | + * mode, however. | |
| 364 | + * When initializing a cipher that requires an IV for decryption or | |
| 365 | + * key unwrapping, the IV | |
| 366 | + * (same IV that was used for encryption or key wrapping) must be provided | |
| 367 | + * explicitly as a | |
| 368 | + * parameter, in order to get the correct result. | |
| 369 | + * | |
| 370 | + * <p>This method also cleans existing buffer and other related state | |
| 371 | + * information. | |
| 372 | + * | |
| 373 | + * @param opmode the operation mode of this cipher (this is one of | |
| 374 | + * the following: | |
| 375 | + * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>, | |
| 376 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) | |
| 377 | + * @param key the secret key | |
| 378 | + * @param random the source of randomness | |
| 379 | + * | |
| 380 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 381 | + * initializing this cipher | |
| 382 | + */ | |
| 383 | + void init(int opmode, Key key, SecureRandom random) | |
| 384 | + throws InvalidKeyException { | |
| 385 | + try { | |
| 386 | + init(opmode, key, (AlgorithmParameterSpec)null, random); | |
| 387 | + } catch (InvalidAlgorithmParameterException e) { | |
| 388 | + throw new InvalidKeyException(e.getMessage()); | |
| 389 | + } | |
| 390 | + } | |
| 391 | + | |
| 392 | + /** | |
| 393 | + * Initializes this cipher with a key, a set of | |
| 394 | + * algorithm parameters, and a source of randomness. | |
| 395 | + * | |
| 396 | + * <p>The cipher is initialized for one of the following four operations: | |
| 397 | + * encryption, decryption, key wrapping or key unwrapping, depending on | |
| 398 | + * the value of <code>opmode</code>. | |
| 399 | + * | |
| 400 | + * <p>If this cipher (including its underlying feedback or padding scheme) | |
| 401 | + * requires any random bytes, it will get them from <code>random</code>. | |
| 402 | + * | |
| 403 | + * @param opmode the operation mode of this cipher (this is one of | |
| 404 | + * the following: | |
| 405 | + * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>, | |
| 406 | + * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) | |
| 407 | + * @param key the encryption key | |
| 408 | + * @param params the algorithm parameters | |
| 409 | + * @param random the source of randomness | |
| 410 | + * | |
| 411 | + * @exception InvalidKeyException if the given key is inappropriate for | |
| 412 | + * initializing this cipher | |
| 413 | + * @exception InvalidAlgorithmParameterException if the given algorithm | |
| 414 | + * parameters are inappropriate for this cipher | |
| 415 | + */ | |
| 416 | + void init(int opmode, Key key, AlgorithmParameterSpec params, | |
| 417 | + SecureRandom random) | |
| 418 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 419 | + decrypting = (opmode == Cipher.DECRYPT_MODE) | |
| 420 | + || (opmode == Cipher.UNWRAP_MODE); | |
| 421 | + | |
| 422 | + byte[] keyBytes = getKeyBytes(key); | |
| 423 | + | |
| 424 | + byte[] ivBytes; | |
| 425 | + if (params == null) { | |
| 426 | + ivBytes = null; | |
| 427 | + } else if (params instanceof IvParameterSpec) { | |
| 428 | + ivBytes = ((IvParameterSpec)params).getIV(); | |
| 429 | + if ((ivBytes == null) || (ivBytes.length != blockSize)) { | |
| 430 | + throw new InvalidAlgorithmParameterException | |
| 431 | + ("Wrong IV length: must be " + blockSize + | |
| 432 | + " bytes long"); | |
| 433 | + } | |
| 434 | + } else if (params instanceof RC2ParameterSpec) { | |
| 435 | + ivBytes = ((RC2ParameterSpec)params).getIV(); | |
| 436 | + if ((ivBytes != null) && (ivBytes.length != blockSize)) { | |
| 437 | + throw new InvalidAlgorithmParameterException | |
| 438 | + ("Wrong IV length: must be " + blockSize + | |
| 439 | + " bytes long"); | |
| 440 | + } | |
| 441 | + } else { | |
| 442 | + throw new InvalidAlgorithmParameterException("Wrong parameter " | |
| 443 | + + "type: IV " | |
| 444 | + + "expected"); | |
| 445 | + } | |
| 446 | + | |
| 447 | + if (cipherMode == ECB_MODE) { | |
| 448 | + if (ivBytes != null) { | |
| 449 | + throw new InvalidAlgorithmParameterException | |
| 450 | + ("ECB mode cannot use IV"); | |
| 451 | + } | |
| 452 | + } else if (ivBytes == null) { | |
| 453 | + if (decrypting) { | |
| 454 | + throw new InvalidAlgorithmParameterException("Parameters " | |
| 455 | + + "missing"); | |
| 456 | + } | |
| 457 | + if (random == null) { | |
| 458 | + random = SunJCE.RANDOM; | |
| 459 | + } | |
| 460 | + ivBytes = new byte[blockSize]; | |
| 461 | + random.nextBytes(ivBytes); | |
| 462 | + } | |
| 463 | + | |
| 464 | + buffered = 0; | |
| 465 | + diffBlocksize = blockSize; | |
| 466 | + | |
| 467 | + String algorithm = key.getAlgorithm(); | |
| 468 | + | |
| 469 | + cipher.init(decrypting, algorithm, keyBytes, ivBytes); | |
| 470 | + } | |
| 471 | + | |
| 472 | + void init(int opmode, Key key, AlgorithmParameters params, | |
| 473 | + SecureRandom random) | |
| 474 | + throws InvalidKeyException, InvalidAlgorithmParameterException { | |
| 475 | + IvParameterSpec ivSpec = null; | |
| 476 | + if (params != null) { | |
| 477 | + try { | |
| 478 | + ivSpec = (IvParameterSpec)params.getParameterSpec | |
| 479 | + (IvParameterSpec.class); | |
| 480 | + } catch (InvalidParameterSpecException ipse) { | |
| 481 | + throw new InvalidAlgorithmParameterException("Wrong parameter " | |
| 482 | + + "type: IV " | |
| 483 | + + "expected"); | |
| 484 | + } | |
| 485 | + } | |
| 486 | + init(opmode, key, ivSpec, random); | |
| 487 | + } | |
| 488 | + | |
| 489 | + /** | |
| 490 | + * Return the key bytes of the specified key. Throw an InvalidKeyException | |
| 491 | + * if the key is not usable. | |
| 492 | + */ | |
| 493 | + static byte[] getKeyBytes(Key key) throws InvalidKeyException { | |
| 494 | + if (key == null) { | |
| 495 | + throw new InvalidKeyException("No key given"); | |
| 496 | + } | |
| 497 | + // note: key.getFormat() may return null | |
| 498 | + if (!"RAW".equalsIgnoreCase(key.getFormat())) { | |
| 499 | + throw new InvalidKeyException("Wrong format: RAW bytes needed"); | |
| 500 | + } | |
| 501 | + byte[] keyBytes = key.getEncoded(); | |
| 502 | + if (keyBytes == null) { | |
| 503 | + throw new InvalidKeyException("RAW key bytes missing"); | |
| 504 | + } | |
| 505 | + return keyBytes; | |
| 506 | + } | |
| 507 | + | |
| 508 | + /** | |
| 509 | + * Continues a multiple-part encryption or decryption operation | |
| 510 | + * (depending on how this cipher was initialized), processing another data | |
| 511 | + * part. | |
| 512 | + * | |
| 513 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 514 | + * buffer, starting at <code>inputOffset</code>, are processed, and the | |
| 515 | + * result is stored in a new buffer. | |
| 516 | + * | |
| 517 | + * @param input the input buffer | |
| 518 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 519 | + * starts | |
| 520 | + * @param inputLen the input length | |
| 521 | + * | |
| 522 | + * @return the new buffer with the result | |
| 523 | + * | |
| 524 | + * @exception IllegalStateException if this cipher is in a wrong state | |
| 525 | + * (e.g., has not been initialized) | |
| 526 | + */ | |
| 527 | + byte[] update(byte[] input, int inputOffset, int inputLen) { | |
| 528 | + byte[] output = null; | |
| 529 | + byte[] out = null; | |
| 530 | + try { | |
| 531 | + output = new byte[getOutputSize(inputLen)]; | |
| 532 | + int len = update(input, inputOffset, inputLen, output, | |
| 533 | + 0); | |
| 534 | + if (len == output.length) { | |
| 535 | + out = output; | |
| 536 | + } else { | |
| 537 | + out = new byte[len]; | |
| 538 | + System.arraycopy(output, 0, out, 0, len); | |
| 539 | + } | |
| 540 | + } catch (ShortBufferException e) { | |
| 541 | + // never thrown | |
| 542 | + } | |
| 543 | + return out; | |
| 544 | + } | |
| 545 | + | |
| 546 | + /** | |
| 547 | + * Continues a multiple-part encryption or decryption operation | |
| 548 | + * (depending on how this cipher was initialized), processing another data | |
| 549 | + * part. | |
| 550 | + * | |
| 551 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 552 | + * buffer, starting at <code>inputOffset</code>, are processed, and the | |
| 553 | + * result is stored in the <code>output</code> buffer, starting at | |
| 554 | + * <code>outputOffset</code>. | |
| 555 | + * | |
| 556 | + * @param input the input buffer | |
| 557 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 558 | + * starts | |
| 559 | + * @param inputLen the input length | |
| 560 | + * @param output the buffer for the result | |
| 561 | + * @param outputOffset the offset in <code>output</code> where the result | |
| 562 | + * is stored | |
| 563 | + * | |
| 564 | + * @return the number of bytes stored in <code>output</code> | |
| 565 | + * | |
| 566 | + * @exception ShortBufferException if the given output buffer is too small | |
| 567 | + * to hold the result | |
| 568 | + */ | |
| 569 | + int update(byte[] input, int inputOffset, int inputLen, byte[] output, | |
| 570 | + int outputOffset) throws ShortBufferException { | |
| 571 | + // figure out how much can be sent to crypto function | |
| 572 | + int len = buffered + inputLen - minBytes; | |
| 573 | + if (padding != null && decrypting) { | |
| 574 | + // do not include the padding bytes when decrypting | |
| 575 | + len -= blockSize; | |
| 576 | + } | |
| 577 | + // do not count the trailing bytes which do not make up a unit | |
| 578 | + len = (len > 0 ? (len - (len%unitBytes)) : 0); | |
| 579 | + | |
| 580 | + // check output buffer capacity | |
| 581 | + if ((output == null) || ((output.length - outputOffset) < len)) { | |
| 582 | + throw new ShortBufferException("Output buffer must be " | |
| 583 | + + "(at least) " + len | |
| 584 | + + " bytes long"); | |
| 585 | + } | |
| 586 | + if (len != 0) { | |
| 587 | + // there is some work to do | |
| 588 | + byte[] in = new byte[len]; | |
| 589 | + | |
| 590 | + int inputConsumed = len - buffered; | |
| 591 | + int bufferedConsumed = buffered; | |
| 592 | + if (inputConsumed < 0) { | |
| 593 | + inputConsumed = 0; | |
| 594 | + bufferedConsumed = len; | |
| 595 | + } | |
| 596 | + | |
| 597 | + if (buffered != 0) { | |
| 598 | + System.arraycopy(buffer, 0, in, 0, bufferedConsumed); | |
| 599 | + } | |
| 600 | + if (inputConsumed > 0) { | |
| 601 | + System.arraycopy(input, inputOffset, in, | |
| 602 | + bufferedConsumed, inputConsumed); | |
| 603 | + } | |
| 604 | + | |
| 605 | + if (decrypting) { | |
| 606 | + cipher.decrypt(in, 0, len, output, outputOffset); | |
| 607 | + } else { | |
| 608 | + cipher.encrypt(in, 0, len, output, outputOffset); | |
| 609 | + } | |
| 610 | + | |
| 611 | + // Let's keep track of how many bytes are needed to make | |
| 612 | + // the total input length a multiple of blocksize when | |
| 613 | + // padding is applied | |
| 614 | + if (unitBytes != blockSize) { | |
| 615 | + if (len < diffBlocksize) | |
| 616 | + diffBlocksize -= len; | |
| 617 | + else | |
| 618 | + diffBlocksize = blockSize - | |
| 619 | + ((len - diffBlocksize) % blockSize); | |
| 620 | + } | |
| 621 | + | |
| 622 | + inputLen -= inputConsumed; | |
| 623 | + inputOffset += inputConsumed; | |
| 624 | + outputOffset += len; | |
| 625 | + buffered -= bufferedConsumed; | |
| 626 | + if (buffered > 0) { | |
| 627 | + System.arraycopy(buffer, bufferedConsumed, buffer, 0, | |
| 628 | + buffered); | |
| 629 | + } | |
| 630 | + } | |
| 631 | + // left over again | |
| 632 | + if (inputLen > 0) { | |
| 633 | + System.arraycopy(input, inputOffset, buffer, buffered, | |
| 634 | + inputLen); | |
| 635 | + } | |
| 636 | + buffered += inputLen; | |
| 637 | + return len; | |
| 638 | + } | |
| 639 | + | |
| 640 | + /** | |
| 641 | + * Encrypts or decrypts data in a single-part operation, | |
| 642 | + * or finishes a multiple-part operation. | |
| 643 | + * The data is encrypted or decrypted, depending on how this cipher was | |
| 644 | + * initialized. | |
| 645 | + * | |
| 646 | + * <p>The first <code>inputLen</code> bytes in the <code>input</code> | |
| 647 | + * buffer, starting at <code>inputOffset</code>, and any input bytes that | |
| 648 | + * may have been buffered during a previous <code>update</code> operation, | |
| 649 | + * are processed, with padding (if requested) being applied. | |
| 650 | + * The result is stored in a new buffer. | |
| 651 | + * | |
| 652 | + * <p>The cipher is reset to its initial state (uninitialized) after this | |
| 653 | + * call. | |
| 654 | + * | |
| 655 | + * @param input the input buffer | |
| 656 | + * @param inputOffset the offset in <code>input</code> where the input | |
| 657 | + * starts | |
| 658 | + * @param inputLen the input length | |
| 659 | + * | |
| 660 | + * @return the new buffer with the result | |
| 661 | + * | |
| 662 | + * @exception IllegalBlockSizeException if this cipher is a block cipher, | |
| 663 | + * no padding has been requested (only in encryption mode), and the total | |
| 664 | + * input length of the data processed by this cipher is not a multiple of | |
| 665 | + * block size | |
| 666 | + * @exception BadPaddingException if this cipher is in decryption mode, | |
| 667 | + * and (un)padding has been requested, but the decrypted data is not | |
| 668 | + * bounded by the appropriate padding bytes | |
| 669 | + */ | |
| 670 | + byte[] doFinal(byte[] input, int inputOffset, int inputLen) | |
| 671 | + throws IllegalBlockSizeException, BadPaddingException { | |
| 672 | + byte[] output = null; | |
| 673 | + byte[] out = null; | |
| 674 | + try { | |
| 675 | + output = new byte[getOutputSize(inputLen)]; | |
| 676 | + int len = doFinal(input, inputOffset, inputLen, output, 0); | |
| 677 | + if (len < output.length) { | |
| 678 | + out = new byte[len]; | |
| 679 | + if (len != 0) | |
| 680 | + System.arraycopy(output, 0, out, 0, len); | |
| 681 | + } else { | |
262 more lines aren’t shown here.
This diff is large: its 273 lines aren’t shown here.
This diff is large: its 216 lines aren’t shown here.
This diff is large: its 262 lines aren’t shown here.
This diff is large: its 192 lines aren’t shown here.
This diff is large: its 211 lines aren’t shown here.
This diff is large: its 429 lines aren’t shown here.
This diff is large: its 40 lines aren’t shown here.
This diff is large: its 1146 lines aren’t shown here.
This diff is large: its 162 lines aren’t shown here.
This diff is large: its 165 lines aren’t shown here.
This diff is large: its 148 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 427 lines aren’t shown here.
This diff is large: its 169 lines aren’t shown here.
This diff is large: its 163 lines aren’t shown here.
This diff is large: its 162 lines aren’t shown here.
This diff is large: its 146 lines aren’t shown here.
This diff is large: its 88 lines aren’t shown here.
This diff is large: its 568 lines aren’t shown here.
This diff is large: its 413 lines aren’t shown here.
This diff is large: its 237 lines aren’t shown here.
This diff is large: its 187 lines aren’t shown here.
This diff is large: its 172 lines aren’t shown here.
This diff is large: its 145 lines aren’t shown here.
This diff is large: its 353 lines aren’t shown here.
This diff is large: its 332 lines aren’t shown here.
This diff is large: its 161 lines aren’t shown here.
This diff is large: its 131 lines aren’t shown here.
This diff is large: its 200 lines aren’t shown here.
This diff is large: its 349 lines aren’t shown here.
This diff is large: its 134 lines aren’t shown here.
This diff is large: its 110 lines aren’t shown here.
This diff is large: its 204 lines aren’t shown here.
This diff is large: its 134 lines aren’t shown here.
This diff is large: its 110 lines aren’t shown here.
This diff is large: its 124 lines aren’t shown here.
This diff is large: its 904 lines aren’t shown here.
This diff is large: its 222 lines aren’t shown here.
This diff is large: its 411 lines aren’t shown here.
This diff is large: its 260 lines aren’t shown here.
This diff is large: its 230 lines aren’t shown here.
This diff is large: its 542 lines aren’t shown here.
This diff is large: its 155 lines aren’t shown here.
This diff is large: its 204 lines aren’t shown here.
This diff is large: its 144 lines aren’t shown here.
This diff is large: its 430 lines aren’t shown here.
This diff is large: its 436 lines aren’t shown here.
This diff is large: its 155 lines aren’t shown here.
This diff is large: its 283 lines aren’t shown here.
This diff is large: its 199 lines aren’t shown here.
This diff is large: its 522 lines aren’t shown here.
This diff is large: its 129 lines aren’t shown here.
This diff is large: its 85 lines aren’t shown here.
This diff is large: its 91 lines aren’t shown here.
This diff is large: its 152 lines aren’t shown here.
This diff is large: its 321 lines aren’t shown here.
This diff is large: its 230 lines aren’t shown here.
This diff is large: its 445 lines aren’t shown here.
This diff is large: its 265 lines aren’t shown here.
This diff is large: its 457 lines aren’t shown here.
This diff is large: its 103 lines aren’t shown here.
This diff is large: its 278 lines aren’t shown here.
This diff is large: its 176 lines aren’t shown here.
This diff is large: its 369 lines aren’t shown here.
This diff is large: its 86 lines aren’t shown here.
This diff is large: its 65 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 103 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 7 lines aren’t shown here.
This diff is large: its 7 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
Binary file not shown.
This diff is large: its 54 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1822 lines aren’t shown here.
Binary file not shown.
This diff is large: its 95 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1533 lines aren’t shown here.
Binary file not shown.
This diff is large: its 107 lines aren’t shown here.
Binary file not shown.
This diff is large: its 308 lines aren’t shown here.
This diff is large: its 209 lines aren’t shown here.
This diff is large: its 70 lines aren’t shown here.
This diff is large: its 16 lines aren’t shown here.
Binary file not shown.
This diff is large: its 124 lines aren’t shown here.
Binary file not shown.
This diff is large: its 137 lines aren’t shown here.
Binary file not shown.
This diff is large: its 34 lines aren’t shown here.
Binary file not shown.
This diff is large: its 63 lines aren’t shown here.
Binary file not shown.
This diff is large: its 1168 lines aren’t shown here.
Binary file not shown.
This diff is large: its 50 lines aren’t shown here.
Binary file not shown.
This diff is large: its 147 lines aren’t shown here.
Binary file not shown.
This diff is large: its 219 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 487 lines aren’t shown here.
Binary file not shown.
This diff is large: its 217 lines aren’t shown here.
Binary file not shown.
This diff is large: its 500 lines aren’t shown here.
This diff is large: its 211 lines aren’t shown here.
Binary file not shown.
This diff is large: its 80 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 21 lines aren’t shown here.
Binary file not shown.
This diff is large: its 447 lines aren’t shown here.
This diff is large: its 172 lines aren’t shown here.
This diff is large: its 105 lines aren’t shown here.
Binary file not shown.
This diff is large: its 1029 lines aren’t shown here.
Binary file not shown.
This diff is large: its 100 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 1318 lines aren’t shown here.
Binary file not shown.
This diff is large: its 105 lines aren’t shown here.
Binary file not shown.
This diff is large: its 318 lines aren’t shown here.
Binary file not shown.
This diff is large: its 321 lines aren’t shown here.
This diff is large: its 107 lines aren’t shown here.
This diff is large: its 72 lines aren’t shown here.
Binary file not shown.
This diff is large: its 403 lines aren’t shown here.
Binary file not shown.
This diff is large: its 268 lines aren’t shown here.
This diff is large: its 21 lines aren’t shown here.
Binary file not shown.
This diff is large: its 137 lines aren’t shown here.
Binary file not shown.
This diff is large: its 134 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 261 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 310 lines aren’t shown here.
Binary file not shown.
This diff is large: its 84 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1565 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 372 lines aren’t shown here.
Binary file not shown.
This diff is large: its 255 lines aren’t shown here.
This diff is large: its 367 lines aren’t shown here.
This diff is large: its 144 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1676 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
Binary file not shown.
This diff is large: its 89 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 1810 lines aren’t shown here.
This diff is large: its 83 lines aren’t shown here.
Binary file not shown.
This diff is large: its 99 lines aren’t shown here.
Binary file not shown.
This diff is large: its 2417 lines aren’t shown here.
This diff is large: its 158 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
Binary file not shown.
This diff is large: its 225 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 285 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 242 lines aren’t shown here.
This diff is large: its 32 lines aren’t shown here.
This diff is large: its 12 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1593 lines aren’t shown here.
Binary file not shown.
This diff is large: its 104 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 1172 lines aren’t shown here.
Binary file not shown.
This diff is large: its 127 lines aren’t shown here.
Binary file not shown.
This diff is large: its 2047 lines aren’t shown here.
This diff is large: its 501 lines aren’t shown here.
This diff is large: its 220 lines aren’t shown here.
Binary file not shown.
This diff is large: its 193 lines aren’t shown here.
This diff is large: its 16 lines aren’t shown here.
Binary file not shown.
This diff is large: its 323 lines aren’t shown here.
Binary file not shown.
This diff is large: its 131 lines aren’t shown here.
Binary file not shown.
This diff is large: its 316 lines aren’t shown here.
Binary file not shown.
This diff is large: its 94 lines aren’t shown here.
Binary file not shown.
This diff is large: its 135 lines aren’t shown here.
This diff is large: its 71 lines aren’t shown here.
This diff is large: its 14 lines aren’t shown here.
Binary file not shown.
This diff is large: its 64 lines aren’t shown here.
Binary file not shown.
This diff is large: its 65 lines aren’t shown here.
Binary file not shown.
This diff is large: its 78 lines aren’t shown here.
Binary file not shown.
This diff is large: its 77 lines aren’t shown here.
Binary file not shown.
This diff is large: its 66 lines aren’t shown here.
Binary file not shown.
This diff is large: its 67 lines aren’t shown here.
This diff is large: its 14 lines aren’t shown here.
Binary file not shown.
This diff is large: its 55 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 135 lines aren’t shown here.
Binary file not shown.
This diff is large: its 73 lines aren’t shown here.
This diff is large: its 11 lines aren’t shown here.
This diff is large: its 71 lines aren’t shown here.
This diff is large: its 98 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 39 lines aren’t shown here.
This diff is large: its 90 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 43 lines aren’t shown here.
This diff is large: its 104 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 90 lines aren’t shown here.
This diff is large: its 14 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 37 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 37 lines aren’t shown here.
This diff is large: its 11 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 34 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 221 lines aren’t shown here.
This diff is large: its 14 lines aren’t shown here.
This diff is large: its 1304 lines aren’t shown here.
This diff is large: its 168 lines aren’t shown here.
This diff is large: its 119 lines aren’t shown here.
This diff is large: its 636 lines aren’t shown here.
This diff is large: its 1399 lines aren’t shown here.
This diff is large: its 145 lines aren’t shown here.
This diff is large: its 352 lines aren’t shown here.
This diff is large: its 1740 lines aren’t shown here.
This diff is large: its 1498 lines aren’t shown here.
This diff is large: its 43 lines aren’t shown here.
This diff is large: its 1142 lines aren’t shown here.
This diff is large: its 183 lines aren’t shown here.
This diff is large: its 2156 lines aren’t shown here.
This diff is large: its 234 lines aren’t shown here.
This diff is large: its 832 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 3 lines aren’t shown here.
This diff is large: its 28 lines aren’t shown here.
This diff is large: its 84 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 85 lines aren’t shown here.
This diff is large: its 85 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 85 lines aren’t shown here.
This diff is large: its 85 lines aren’t shown here.
This diff is large: its 179 lines aren’t shown here.
This diff is large: its 3 lines aren’t shown here.
This diff is large: its 7 lines aren’t shown here.
This diff is large: its 7 lines aren’t shown here.
This diff is large: its 7 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 735 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 151 lines aren’t shown here.
This diff is large: its 108 lines aren’t shown here.
This diff is large: its 91 lines aren’t shown here.
This diff is large: its 362 lines aren’t shown here.
This diff is large: its 366 lines aren’t shown here.
This diff is large: its 268 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 847 lines aren’t shown here.
This diff is large: its 477 lines aren’t shown here.
This diff is large: its 461 lines aren’t shown here.
This diff is large: its 375 lines aren’t shown here.
This diff is large: its 224 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 1284 lines aren’t shown here.
This diff is large: its 70 lines aren’t shown here.
This diff is large: its 110 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 44 lines aren’t shown here.
This diff is large: its 152 lines aren’t shown here.
This diff is large: its 115 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 67 lines aren’t shown here.
This diff is large: its 115 lines aren’t shown here.
This diff is large: its 59 lines aren’t shown here.
This diff is large: its 114 lines aren’t shown here.
This diff is large: its 105 lines aren’t shown here.
This diff is large: its 212 lines aren’t shown here.
This diff is large: its 109 lines aren’t shown here.
This diff is large: its 144 lines aren’t shown here.
This diff is large: its 60 lines aren’t shown here.
This diff is large: its 160 lines aren’t shown here.
This diff is large: its 296 lines aren’t shown here.
This diff is large: its 67 lines aren’t shown here.
This diff is large: its 307 lines aren’t shown here.
This diff is large: its 71 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 176 lines aren’t shown here.
This diff is large: its 126 lines aren’t shown here.
This diff is large: its 114 lines aren’t shown here.
This diff is large: its 167 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 3 lines aren’t shown here.
This diff is large: its 56 lines aren’t shown here.
This diff is large: its 3 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 34 lines aren’t shown here.
This diff is large: its 34 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 429 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 286 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 566 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 337 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 321 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 105 lines aren’t shown here.
This diff is large: its 96 lines aren’t shown here.
Binary file not shown.
This diff is large: its 45 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 566 lines aren’t shown here.
This diff is large: its 99 lines aren’t shown here.
This diff is large: its 104 lines aren’t shown here.
This diff is large: its 72 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 1310 lines aren’t shown here.
Binary file not shown.
This diff is large: its 212 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 904 lines aren’t shown here.
This diff is large: its 560 lines aren’t shown here.
This diff is large: its 135 lines aren’t shown here.
This diff is large: its 113 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 2621 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 187 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 178 lines aren’t shown here.
Binary file not shown.
This diff is large: its 47 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 296 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 70 lines aren’t shown here.
This diff is large: its 95 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 225 lines aren’t shown here.
This diff is large: its 96 lines aren’t shown here.
This diff is large: its 401 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 104 lines aren’t shown here.
This diff is large: its 131 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 185 lines aren’t shown here.
This diff is large: its 480 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 36 lines aren’t shown here.
This diff is large: its 235 lines aren’t shown here.
This diff is large: its 104 lines aren’t shown here.
This diff is large: its 73 lines aren’t shown here.
This diff is large: its 68 lines aren’t shown here.
This diff is large: its 228 lines aren’t shown here.
This diff is large: its 246 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 176 lines aren’t shown here.
This diff is large: its 68 lines aren’t shown here.
This diff is large: its 237 lines aren’t shown here.
This diff is large: its 182 lines aren’t shown here.
This diff is large: its 125 lines aren’t shown here.
This diff is large: its 100 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 235 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 752 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 3 lines aren’t shown here.
This diff is large: its 65 lines aren’t shown here.
This diff is large: its 3 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 7 lines aren’t shown here.
Binary file not shown.
This diff is large: its 299 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1623 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 2683 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 495 lines aren’t shown here.
Binary file not shown.
This diff is large: its 258 lines aren’t shown here.
Binary file not shown.
This diff is large: its 400 lines aren’t shown here.
Binary file not shown.
This diff is large: its 908 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1490 lines aren’t shown here.
Binary file not shown.
This diff is large: its 44 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1219 lines aren’t shown here.
Binary file not shown.
This diff is large: its 437 lines aren’t shown here.
This diff is large: its 726 lines aren’t shown here.
This diff is large: its 132 lines aren’t shown here.
Binary file not shown.
This diff is large: its 175 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 547 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 819 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 665 lines aren’t shown here.
Binary file not shown.
This diff is large: its 323 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1323 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 2205 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1620 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 643 lines aren’t shown here.
Binary file not shown.
This diff is large: its 501 lines aren’t shown here.
Binary file not shown.
This diff is large: its 339 lines aren’t shown here.
Binary file not shown.
This diff is large: its 98 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 282 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 345 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 105 lines aren’t shown here.
This diff is large: its 7 lines aren’t shown here.
This diff is large: its 46 lines aren’t shown here.
This diff is large: its 108 lines aren’t shown here.
This diff is large: its 210 lines aren’t shown here.
This diff is large: its 97 lines aren’t shown here.
This diff is large: its 40 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 57 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 94 lines aren’t shown here.
This diff is large: its 88 lines aren’t shown here.
This diff is large: its 46 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 373 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 136 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
This diff is large: its 46 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 82 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
This diff is large: its 44 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 114 lines aren’t shown here.
This diff is large: its 154 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 262 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 430 lines aren’t shown here.
This diff is large: its 77 lines aren’t shown here.
This diff is large: its 74 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 44 lines aren’t shown here.
This diff is large: its 445 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 42 lines aren’t shown here.
This diff is large: its 124 lines aren’t shown here.
This diff is large: its 831 lines aren’t shown here.
This diff is large: its 40 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 240 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 102 lines aren’t shown here.
This diff is large: its 474 lines aren’t shown here.
This diff is large: its 150 lines aren’t shown here.
This diff is large: its 130 lines aren’t shown here.
This diff is large: its 44 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 44 lines aren’t shown here.
This diff is large: its 182 lines aren’t shown here.
This diff is large: its 864 lines aren’t shown here.
This diff is large: its 431 lines aren’t shown here.
This diff is large: its 40 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 70 lines aren’t shown here.
This diff is large: its 286 lines aren’t shown here.
This diff is large: its 80 lines aren’t shown here.
This diff is large: its 75 lines aren’t shown here.
This diff is large: its 118 lines aren’t shown here.
This diff is large: its 53 lines aren’t shown here.
This diff is large: its 78 lines aren’t shown here.
This diff is large: its 56 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 44 lines aren’t shown here.
This diff is large: its 68 lines aren’t shown here.
This diff is large: its 201 lines aren’t shown here.
This diff is large: its 378 lines aren’t shown here.
This diff is large: its 11 lines aren’t shown here.
This diff is large: its 36 lines aren’t shown here.
This diff is large: its 3 lines aren’t shown here.
This diff is large: its 40 lines aren’t shown here.
This diff is large: its 42 lines aren’t shown here.
This diff is large: its 53 lines aren’t shown here.
This diff is large: its 74 lines aren’t shown here.
This diff is large: its 53 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 172 lines aren’t shown here.
This diff is large: its 95 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
This diff is large: its 74 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 66 lines aren’t shown here.
This diff is large: its 68 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 57 lines aren’t shown here.
This diff is large: its 64 lines aren’t shown here.
This diff is large: its 73 lines aren’t shown here.
This diff is large: its 57 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
This diff is large: its 68 lines aren’t shown here.
This diff is large: its 32 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 80 lines aren’t shown here.
This diff is large: its 51 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 88 lines aren’t shown here.
This diff is large: its 125 lines aren’t shown here.
This diff is large: its 77 lines aren’t shown here.
This diff is large: its 46 lines aren’t shown here.
This diff is large: its 211 lines aren’t shown here.
This diff is large: its 545 lines aren’t shown here.
This diff is large: its 156 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 117 lines aren’t shown here.
This diff is large: its 120 lines aren’t shown here.
This diff is large: its 60 lines aren’t shown here.
This diff is large: its 117 lines aren’t shown here.
This diff is large: its 117 lines aren’t shown here.
This diff is large: its 116 lines aren’t shown here.
This diff is large: its 116 lines aren’t shown here.
This diff is large: its 136 lines aren’t shown here.
This diff is large: its 59 lines aren’t shown here.
This diff is large: its 59 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 121 lines aren’t shown here.
This diff is large: its 29 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
Binary file not shown.
This diff is large: its 233 lines aren’t shown here.
Binary file not shown.
This diff is large: its 98 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 34 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 2065 lines aren’t shown here.
Binary file not shown.
This diff is large: its 131 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 37 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 305 lines aren’t shown here.
Binary file not shown.
This diff is large: its 229 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 1493 lines aren’t shown here.
Binary file not shown.
This diff is large: its 68 lines aren’t shown here.
Binary file not shown.
This diff is large: its 78 lines aren’t shown here.
Binary file not shown.
This diff is large: its 47 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 779 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 1498 lines aren’t shown here.
This diff is large: its 115 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 271 lines aren’t shown here.
Binary file not shown.
This diff is large: its 719 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 470 lines aren’t shown here.
Binary file not shown.
This diff is large: its 322 lines aren’t shown here.
Binary file not shown.
This diff is large: its 275 lines aren’t shown here.
Binary file not shown.
This diff is large: its 366 lines aren’t shown here.
Binary file not shown.
This diff is large: its 189 lines aren’t shown here.
Binary file not shown.
This diff is large: its 211 lines aren’t shown here.
Binary file not shown.
This diff is large: its 125 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 176 lines aren’t shown here.
Binary file not shown.
This diff is large: its 179 lines aren’t shown here.
Binary file not shown.
This diff is large: its 71 lines aren’t shown here.
Binary file not shown.
This diff is large: its 123 lines aren’t shown here.
Binary file not shown.
This diff is large: its 69 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 281 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 679 lines aren’t shown here.
Binary file not shown.
This diff is large: its 65 lines aren’t shown here.
Binary file not shown.
This diff is large: its 193 lines aren’t shown here.
Binary file not shown.
This diff is large: its 96 lines aren’t shown here.
Binary file not shown.
This diff is large: its 91 lines aren’t shown here.
Binary file not shown.
This diff is large: its 242 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 138 lines aren’t shown here.
This diff is large: its 39 lines aren’t shown here.
This diff is large: its 34 lines aren’t shown here.
This diff is large: its 11 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 839 lines aren’t shown here.
Binary file not shown.
This diff is large: its 103 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 253 lines aren’t shown here.
Binary file not shown.
This diff is large: its 107 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 911 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 189 lines aren’t shown here.
Binary file not shown.
This diff is large: its 111 lines aren’t shown here.
Binary file not shown.
This diff is large: its 73 lines aren’t shown here.
Binary file not shown.
This diff is large: its 41 lines aren’t shown here.
Binary file not shown.
This diff is large: its 104 lines aren’t shown here.
Binary file not shown.
This diff is large: its 60 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 233 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 495 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 22 lines aren’t shown here.
This diff is large: its 38 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 120 lines aren’t shown here.
This diff is large: its 242 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 12 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
Binary file not shown.
This diff is large: its 571 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 347 lines aren’t shown here.
Binary file not shown.
This diff is large: its 107 lines aren’t shown here.
Binary file not shown.
This diff is large: its 666 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 545 lines aren’t shown here.
Binary file not shown.
This diff is large: its 111 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
This diff is large: its 149 lines aren’t shown here.
This diff is large: its 15 lines aren’t shown here.
Binary file not shown.
This diff is large: its 122 lines aren’t shown here.
Binary file not shown.
This diff is large: its 56 lines aren’t shown here.
Binary file not shown.
This diff is large: its 247 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 809 lines aren’t shown here.
Binary file not shown.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 13 lines aren’t shown here.
This diff is large: its 758 lines aren’t shown here.
This diff is large: its 478 lines aren’t shown here.
This diff is large: its 64 lines aren’t shown here.
This diff is large: its 309 lines aren’t shown here.
This diff is large: its 220 lines aren’t shown here.
This diff is large: its 24 lines aren’t shown here.
This diff is large: its 403 lines aren’t shown here.
This diff is large: its 264 lines aren’t shown here.
This diff is large: its 288 lines aren’t shown here.
This diff is large: its 143 lines aren’t shown here.
This diff is large: its 182 lines aren’t shown here.
This diff is large: its 65 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 59 lines aren’t shown here.
This diff is large: its 54 lines aren’t shown here.
This diff is large: its 54 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 63 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 64 lines aren’t shown here.
This diff is large: its 64 lines aren’t shown here.
This diff is large: its 42 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 59 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 62 lines aren’t shown here.
This diff is large: its 53 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 54 lines aren’t shown here.
This diff is large: its 51 lines aren’t shown here.
This diff is large: its 150 lines aren’t shown here.
This diff is large: its 267 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 138 lines aren’t shown here.
This diff is large: its 39 lines aren’t shown here.
This diff is large: its 218 lines aren’t shown here.
This diff is large: its 1286 lines aren’t shown here.
This diff is large: its 949 lines aren’t shown here.
This diff is large: its 381 lines aren’t shown here.
This diff is large: its 112 lines aren’t shown here.
This diff is large: its 1515 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 90 lines aren’t shown here.
This diff is large: its 149 lines aren’t shown here.
This diff is large: its 30 lines aren’t shown here.
This diff is large: its 156 lines aren’t shown here.
This diff is large: its 487 lines aren’t shown here.
This diff is large: its 108 lines aren’t shown here.
This diff is large: its 161 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 129 lines aren’t shown here.
This diff is large: its 171 lines aren’t shown here.
This diff is large: its 40 lines aren’t shown here.
This diff is large: its 39 lines aren’t shown here.
This diff is large: its 100 lines aren’t shown here.
This diff is large: its 215 lines aren’t shown here.
This diff is large: its 71 lines aren’t shown here.
This diff is large: its 59 lines aren’t shown here.
This diff is large: its 490 lines aren’t shown here.
This diff is large: its 118 lines aren’t shown here.
This diff is large: its 100 lines aren’t shown here.
This diff is large: its 283 lines aren’t shown here.
This diff is large: its 218 lines aren’t shown here.
This diff is large: its 363 lines aren’t shown here.
This diff is large: its 477 lines aren’t shown here.
This diff is large: its 184 lines aren’t shown here.
This diff is large: its 101 lines aren’t shown here.
This diff is large: its 77 lines aren’t shown here.
This diff is large: its 125 lines aren’t shown here.
This diff is large: its 120 lines aren’t shown here.
This diff is large: its 59 lines aren’t shown here.
This diff is large: its 95 lines aren’t shown here.
This diff is large: its 132 lines aren’t shown here.
This diff is large: its 110 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 94 lines aren’t shown here.
This diff is large: its 111 lines aren’t shown here.
This diff is large: its 105 lines aren’t shown here.
This diff is large: its 96 lines aren’t shown here.
This diff is large: its 68 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
This diff is large: its 147 lines aren’t shown here.
This diff is large: its 279 lines aren’t shown here.
This diff is large: its 194 lines aren’t shown here.
This diff is large: its 83 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 43 lines aren’t shown here.
This diff is large: its 43 lines aren’t shown here.
This diff is large: its 46 lines aren’t shown here.
This diff is large: its 46 lines aren’t shown here.
This diff is large: its 43 lines aren’t shown here.
This diff is large: its 126 lines aren’t shown here.
This diff is large: its 99 lines aren’t shown here.
This diff is large: its 512 lines aren’t shown here.
This diff is large: its 97 lines aren’t shown here.
This diff is large: its 327 lines aren’t shown here.
This diff is large: its 98 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 207 lines aren’t shown here.
This diff is large: its 133 lines aren’t shown here.
This diff is large: its 574 lines aren’t shown here.
This diff is large: its 191 lines aren’t shown here.
This diff is large: its 1027 lines aren’t shown here.
This diff is large: its 758 lines aren’t shown here.
This diff is large: its 317 lines aren’t shown here.
This diff is large: its 195 lines aren’t shown here.
This diff is large: its 520 lines aren’t shown here.
This diff is large: its 156 lines aren’t shown here.
This diff is large: its 415 lines aren’t shown here.
This diff is large: its 562 lines aren’t shown here.
This diff is large: its 176 lines aren’t shown here.
This diff is large: its 243 lines aren’t shown here.
This diff is large: its 210 lines aren’t shown here.
This diff is large: its 2571 lines aren’t shown here.
This diff is large: its 1072 lines aren’t shown here.
This diff is large: its 120 lines aren’t shown here.
This diff is large: its 265 lines aren’t shown here.
This diff is large: its 77 lines aren’t shown here.
This diff is large: its 92 lines aren’t shown here.
This diff is large: its 142 lines aren’t shown here.
This diff is large: its 572 lines aren’t shown here.
This diff is large: its 125 lines aren’t shown here.
This diff is large: its 33 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 134 lines aren’t shown here.
This diff is large: its 78 lines aren’t shown here.
This diff is large: its 1376 lines aren’t shown here.
This diff is large: its 172 lines aren’t shown here.
This diff is large: its 2660 lines aren’t shown here.
This diff is large: its 701 lines aren’t shown here.
This diff is large: its 81 lines aren’t shown here.
This diff is large: its 270 lines aren’t shown here.
This diff is large: its 1153 lines aren’t shown here.
This diff is large: its 346 lines aren’t shown here.
This diff is large: its 273 lines aren’t shown here.
This diff is large: its 631 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 246 lines aren’t shown here.
This diff is large: its 179 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 93 lines aren’t shown here.
This diff is large: its 77 lines aren’t shown here.
This diff is large: its 51 lines aren’t shown here.
This diff is large: its 425 lines aren’t shown here.
This diff is large: its 165 lines aren’t shown here.
This diff is large: its 123 lines aren’t shown here.
This diff is large: its 137 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 36 lines aren’t shown here.
This diff is large: its 148 lines aren’t shown here.
This diff is large: its 163 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 177 lines aren’t shown here.
This diff is large: its 179 lines aren’t shown here.
This diff is large: its 74 lines aren’t shown here.
This diff is large: its 126 lines aren’t shown here.
This diff is large: its 25 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 70 lines aren’t shown here.
This diff is large: its 93 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 68 lines aren’t shown here.
This diff is large: its 58 lines aren’t shown here.
This diff is large: its 247 lines aren’t shown here.
This diff is large: its 11 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 237 lines aren’t shown here.
This diff is large: its 1161 lines aren’t shown here.
This diff is large: its 52 lines aren’t shown here.
This diff is large: its 501 lines aren’t shown here.
This diff is large: its 129 lines aren’t shown here.
This diff is large: its 243 lines aren’t shown here.
This diff is large: its 224 lines aren’t shown here.
This diff is large: its 71 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 5 lines aren’t shown here.
This diff is large: its 17 lines aren’t shown here.
This diff is large: its 700 lines aren’t shown here.
This diff is large: its 1069 lines aren’t shown here.
This diff is large: its 260 lines aren’t shown here.
This diff is large: its 609 lines aren’t shown here.
This diff is large: its 56 lines aren’t shown here.
This diff is large: its 120 lines aren’t shown here.
This diff is large: its 127 lines aren’t shown here.
This diff is large: its 157 lines aren’t shown here.
This diff is large: its 193 lines aren’t shown here.
This diff is large: its 590 lines aren’t shown here.
This diff is large: its 141 lines aren’t shown here.
This diff is large: its 206 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
Binary file not shown.
This diff is large: its 119 lines aren’t shown here.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This diff is large: its 108 lines aren’t shown here.
Binary file not shown.
This diff is larger than a page shows: the files after these aren’t listed. Clone the repository to see all of it.