1 18 package org.objectweb.jorm.naming.lib; 19 20 import org.objectweb.jorm.naming.api.PName; 21 import org.objectweb.jorm.naming.api.PBinder; 22 import org.objectweb.jorm.naming.api.PNameCoder; 23 import org.objectweb.jorm.naming.api.FilteredPNamingContext; 24 import org.objectweb.jorm.naming.api.PNameGetterConverter; 25 import org.objectweb.jorm.naming.api.PExceptionNaming; 26 import org.objectweb.jorm.api.PException; 27 28 import java.util.Date ; 29 import java.util.Arrays ; 30 import java.math.BigInteger ; 31 import java.math.BigDecimal ; 32 33 97 public abstract class AbstractInheritFilteredPNamingContext 98 extends BasicPNamingContext 99 implements FilteredPNamingContext { 100 101 105 private FilteredPNamingContext[] fpncs = new FilteredPNamingContext[0]; 106 107 111 protected PBinder binder; 112 113 116 protected int codingType; 117 118 121 private PName nullPName; 122 123 protected PNameGetterConverter converter; 124 125 public AbstractInheritFilteredPNamingContext() { 126 } 127 128 public AbstractInheritFilteredPNamingContext(int codingType) { 129 this.codingType = codingType; 130 } 131 132 public AbstractInheritFilteredPNamingContext(int codingType, PNameGetterConverter converter) { 133 this.codingType = codingType; 134 this.converter = converter; 135 } 136 137 public PBinder getBinder() { 138 return binder; 139 } 140 141 public void setBinder(PBinder binder) { 142 this.binder = binder; 143 } 144 145 public void setCodingType(int codingType) { 146 this.codingType = codingType; 147 } 148 149 public PNameGetterConverter getConverter() { 150 return converter; 151 } 152 153 public void setConverter(PNameGetterConverter converter) { 154 this.converter = converter; 155 } 156 157 public synchronized void bindSubFPNC(FilteredPNamingContext fpnc) { 158 FilteredPNamingContext[] newfpncs = new FilteredPNamingContext[fpncs.length + 1]; 159 System.arraycopy(fpncs, 0, newfpncs, 0, fpncs.length); 160 newfpncs[fpncs.length] = fpnc; 161 fpncs = newfpncs; 162 } 163 164 public synchronized void unbindSubFPNC(FilteredPNamingContext fpnc) { 165 int j = Arrays.binarySearch(fpncs, fpnc); 166 if (j == -1) { 167 return; 169 } 170 FilteredPNamingContext[] newfpncs = new FilteredPNamingContext[fpncs.length - 1]; 171 if (j > 0) { 172 System.arraycopy(fpncs, 0, newfpncs, 0, j); 174 } 175 if (j < newfpncs.length) { 176 System.arraycopy(fpncs, j + 1, newfpncs, j, fpncs.length - j); 178 } 179 fpncs = newfpncs; 180 } 181 182 public boolean codingSupported(int codingtype) { 183 return codingtype == codingType || codingtype == PNameCoder.CTSTRING; 184 } 185 186 public PName getNull() { 187 return nullPName; 188 } 189 190 public void setNullPName(Object o) throws PException { 191 nullPName = (PName) o; 192 } 193 194 public PName resolve(Object conn, PName pn) throws PException { 195 int i = fpncs.length - 1; 196 switch (codingType) { 197 case CTCOMPOSITE: { 198 Object o = pn.encodeAbstract(); 199 while(i>=0 && !fpncs[i].match(o)) { 200 i--; 201 } 202 if (i>=0) { 203 return fpncs[i].decodeAbstract(o, null); 204 } else if (binder != null) { 205 return binder.decodeAbstract(o, null); 206 } else { 207 return pn; 208 } 209 } 210 case CTCHAR:{ 211 char o = pn.encodeChar(); 212 while(i>=0 && !fpncs[i].match(o)) { 213 i--; 214 } 215 if (i>=0) { 216 return fpncs[i].decodeChar(o); 217 } else if (binder != null) { 218 return binder.decodeChar(o); 219 } else { 220 return pn; 221 } 222 } 223 224 case CTOCHAR: { 225 Character o = pn.encodeOchar(); 226 while(i>=0 && !fpncs[i].match(o)) { 227 i--; 228 } 229 if (i>=0) { 230 return fpncs[i].decodeOchar(o); 231 } else if (binder != null) { 232 return binder.decodeOchar(o); 233 } else { 234 return pn; 235 } 236 } 237 238 case CTBYTE: { 239 byte o = pn.encodeByte(); 240 while(i>=0 && !fpncs[i].match(o)) { 241 i--; 242 } 243 if (i>=0) { 244 return fpncs[i].decodeByte(o); 245 } else if (binder != null) { 246 return binder.decodeByte(o); 247 } else { 248 return pn; 249 } 250 } 251 252 case CTOBYTE: { 253 Byte o = pn.encodeObyte(); 254 while(i>=0 && !fpncs[i].match(o)) { 255 i--; 256 } 257 if (i>=0) { 258 return fpncs[i].decodeObyte(o); 259 } else if (binder != null) { 260 return binder.decodeObyte(o); 261 } else { 262 return pn; 263 } 264 } 265 266 case CTSHORT: { 267 short o = pn.encodeShort(); 268 while(i>=0 && !fpncs[i].match(o)) { 269 i--; 270 } 271 if (i>=0) { 272 return fpncs[i].decodeShort(o); 273 } else if (binder != null) { 274 return binder.decodeShort(o); 275 } else { 276 return pn; 277 } 278 } 279 280 case CTOSHORT: { 281 Short o = pn.encodeOshort(); 282 while(i>=0 && !fpncs[i].match(o)) { 283 i--; 284 } 285 if (i>=0) { 286 return fpncs[i].decodeOshort(o); 287 } else if (binder != null) { 288 return binder.decodeOshort(o); 289 } else { 290 return pn; 291 } 292 } 293 294 case CTINT: { 295 int o = pn.encodeInt(); 296 while(i>=0 && !fpncs[i].match(o)) { 297 i--; 298 } 299 if (i>=0) { 300 return fpncs[i].decodeInt(o); 301 } else if (binder != null) { 302 return binder.decodeInt(o); 303 } else { 304 return pn; 305 } 306 } 307 308 case CTOINT: { 309 Integer o = pn.encodeOint(); 310 while(i>=0 && !fpncs[i].match(o)) { 311 i--; 312 } 313 if (i>=0) { 314 return fpncs[i].decodeOint(o); 315 } else if (binder != null) { 316 return binder.decodeOint(o); 317 } else { 318 return pn; 319 } 320 } 321 322 case CTLONG: { 323 long o = pn.encodeLong(); 324 while(i>=0 && !fpncs[i].match(o)) { 325 i--; 326 } 327 if (i>=0) { 328 return fpncs[i].decodeLong(o); 329 } else if (binder != null) { 330 return binder.decodeLong(o); 331 } else { 332 return pn; 333 } 334 } 335 336 case CTOLONG: { 337 Long o = pn.encodeOlong(); 338 while(i>=0 && !fpncs[i].match(o)) { 339 i--; 340 } 341 if (i>=0) { 342 return fpncs[i].decodeOlong(o); 343 } else if (binder != null) { 344 return binder.decodeOlong(o); 345 } else { 346 return pn; 347 } 348 } 349 350 case CTSTRING: { 351 String o = pn.encodeString(); 352 while(i>=0 && !fpncs[i].match(o)) { 353 i--; 354 } 355 if (i>=0) { 356 return fpncs[i].decodeString(o); 357 } else if (binder != null) { 358 return binder.decodeString(o); 359 } else { 360 return pn; 361 } 362 } 363 364 case CTBYTEARRAY: { 365 byte[] o = pn.encode(); 366 while(i>=0 && !fpncs[i].match(o)) { 367 i--; 368 } 369 if (i>=0) { 370 return fpncs[i].decode(o); 371 } else if (binder != null) { 372 return binder.decode(o); 373 } else { 374 return pn; 375 } 376 } 377 378 case CTCHARARRAY: { 379 char[] o = pn.encodeCharArray(); 380 while(i>=0 && !fpncs[i].match(o)) { 381 i--; 382 } 383 if (i>=0) { 384 return fpncs[i].decodeCharArray(o); 385 } else if (binder != null) { 386 return binder.decodeCharArray(o); 387 } else { 388 return pn; 389 } 390 } 391 392 case CTDATE: { 393 Date o = pn.encodeDate(); 394 while(i>=0 && !fpncs[i].match(o)) { 395 i--; 396 } 397 if (i>=0) { 398 return fpncs[i].decodeDate(o); 399 } else if (binder != null) { 400 return binder.decodeDate(o); 401 } else { 402 return pn; 403 } 404 } 405 406 case CTBIGDECIMAL: { 407 BigDecimal o = pn.encodeBigDecimal(); 408 while(i>=0 && !fpncs[i].match(o)) { 409 i--; 410 } 411 if (i>=0) { 412 return fpncs[i].decodeBigDecimal(o); 413 } else if (binder != null) { 414 return binder.decodeBigDecimal(o); 415 } else { 416 return pn; 417 } 418 } 419 420 case CTBIGINTEGER: { 421 BigInteger o = pn.encodeBigInteger(); 422 while(i>=0 && !fpncs[i].match(o)) { 423 i--; 424 } 425 if (i>=0) { 426 return fpncs[i].decodeBigInteger(o); 427 } else if (binder != null) { 428 return binder.decodeBigInteger(o); 429 } else { 430 return pn; 431 } 432 } 433 434 default: 435 return getNull(); 436 } 437 } 438 439 public PName export(Object conn, Object infoitem) throws PException { 440 return export(conn, infoitem, null); 441 } 442 443 public PName export(Object conn, Object infoitem, Object hints) 444 throws PException { 445 if (infoitem instanceof PName) { 446 return (PName) infoitem; 447 } else { 448 return decodeAbstract(infoitem, hints); 449 } 450 } 451 452 public void unexport(Object conn, PName pn) throws PException { 453 } 455 456 public void unexport(Object conn, PName pn, Object hints) throws PException { 457 } 459 460 public String encodeString(PName pn) throws PExceptionNaming { 461 throw new UnsupportedOperationException ("String coding not supported"); 462 } 463 } 464 | Popular Tags |