1 18 package org.objectweb.jorm.naming.lib; 19 20 import org.objectweb.jorm.naming.api.KeyFilteredNamingContext; 21 import org.objectweb.jorm.naming.api.PBinder; 22 import org.objectweb.jorm.naming.api.PNameGetter; 23 import org.objectweb.jorm.naming.api.PName; 24 import org.objectweb.jorm.naming.api.PExceptionNaming; 25 import org.objectweb.jorm.naming.api.PNameCoder; 26 import org.objectweb.jorm.naming.api.PNameGetterConverter; 27 import org.objectweb.jorm.naming.api.PNameManager; 28 import org.objectweb.jorm.api.PException; 29 import org.objectweb.jorm.type.api.PType; 30 31 import java.util.Map ; 32 import java.util.HashMap ; 33 import java.util.Collections ; 34 import java.util.Date ; 35 import java.util.Arrays ; 36 import java.math.BigDecimal ; 37 import java.math.BigInteger ; 38 39 55 public abstract class AbstractInheritKeyFilteredPNamingContext 56 extends BasicPNamingContext 57 implements KeyFilteredNamingContext { 58 59 62 protected PType expressionType; 63 64 68 protected PNameGetterConverter pngConverter; 69 70 73 protected Map key2binder; 74 75 78 protected int codingType; 79 80 87 protected Object nullValue; 88 89 protected PName nullPName; 90 91 97 public AbstractInheritKeyFilteredPNamingContext() { 98 key2binder = new HashMap (); 99 } 100 101 public AbstractInheritKeyFilteredPNamingContext(PType expressionType, 102 int codingType) throws PException { 103 this(); 104 setExpressionType(expressionType); 105 setCodingType(codingType); 106 } 107 108 public void init() throws PException { 109 checkNullValue(); 110 } 111 112 public void setCodingType(int codingType) { 113 this.codingType = codingType; 114 if (this.codingType != PNameCoder.CTCOMPOSITE) { 115 pngConverter = new SimplePNGConverter(); 116 } else { 117 pngConverter = null; 118 } 119 } 120 121 public boolean isNull(Object png, Object ctx) throws PException { 122 return false; 123 } 124 125 128 public void exportClass(PBinder binder, Object key) throws PException { 129 synchronized(key2binder) { 130 PBinder oldbinder = (PBinder) key2binder.put(key, binder); 131 if (oldbinder != null && oldbinder != binder) { 132 key2binder.put(key, oldbinder); 133 throw new PException("Another persistent class is alread exported with the same key: " 134 + oldbinder.getBinderClassMapping().getClassName()); 135 } 136 } 137 } 138 139 public void unexportClass(Object key) throws PException { 140 synchronized(key2binder) { 141 Object oldbinder = key2binder.remove(key); 142 if (oldbinder == null) { 143 throw new PException("No persistent class to unexport with the key: " + key); 144 } 145 } 146 } 147 148 public PBinder lookup(Object key) { 149 return (PBinder) key2binder.get(key); 150 } 151 152 public Map entries() { 153 return Collections.unmodifiableMap(key2binder); 154 } 155 156 public void setExpressionType(PType type) { 157 this.expressionType = type; 158 } 159 160 public PType getExpressionType() { 161 return expressionType; 162 } 163 164 public abstract Object evaluate(Object png, Object ctx) throws PException; 165 166 167 170 public PName resolve(Object conn, PName pn) throws PException { 171 return pn; 172 } 173 174 175 178 public PName export(Object conn, Object infoitem) throws PException { 179 if (infoitem instanceof PName) { 180 return (PName) infoitem; 181 } 182 throw new PException("Operation not supported by this PNamingContext"); 183 } 184 185 public PName export(Object conn, Object infoitem, Object hints) 186 throws PException { 187 throw new PException("Operation not supported by this PNamingContext"); 188 } 189 190 public void unexport(Object conn, PName pn) throws PException { 191 throw new PException("Operation not supported by this PNamingContext"); 192 } 193 194 public void unexport(Object conn, PName pn, Object hints) throws PException { 195 throw new PException("Operation not supported by this PNamingContext"); 196 } 197 198 199 202 public boolean codingSupported(int codingtype) { 203 return codingtype == codingType || codingtype == PNameCoder.CTSTRING; 204 } 205 206 public PName decodeAbstract(Object en, Object context) 207 throws PExceptionNaming, UnsupportedOperationException { 208 Object key; 209 try { 210 if (isNull(en, context)) { 211 return nullPName; 212 } 213 key = evaluate(en, context); 214 } catch (PExceptionNaming e) { 215 throw e; 216 } catch (PException e) { 217 throw new PExceptionNaming(e); 218 } 219 PBinder binder = (PBinder) key2binder.get(key); 220 if (binder == null) { 221 throw new PExceptionNaming("No"); 222 } 223 return binder.decodeAbstract(en, context); 224 } 225 226 public PName decodeByte(byte en) throws PExceptionNaming, UnsupportedOperationException { 227 if (codingType != CTBYTE) { 228 throw new PExceptionNaming("Bad coder type: " + codingType); 229 } 230 if (((Byte ) nullValue).byteValue() == en) { 231 return getNull(); 232 } 233 Object key; 234 try { 235 key = evaluate(pngConverter.convert(en), null); 236 } catch (PExceptionNaming e) { 237 throw e; 238 } catch (PException e) { 239 throw new PExceptionNaming(e); 240 } 241 PBinder binder = (PBinder) key2binder.get(key); 242 if (binder == null) { 243 throw new PExceptionNaming("No"); 244 } 245 return binder.decodeByte(en); 246 } 247 248 public PName decodeObyte(Byte en) throws PExceptionNaming, UnsupportedOperationException { 249 if (codingType != CTOBYTE) { 250 throw new PExceptionNaming("Bad coder type: " + codingType); 251 } 252 if (nullValue == null) { 253 if (en == null) { 254 return getNull(); 255 } 256 } else if (en != null 257 && ((Byte ) nullValue).byteValue() == en.byteValue()) { 258 return getNull(); 259 } 260 Object key; 261 try { 262 key = evaluate(pngConverter.convert(en), null); 263 } catch (PExceptionNaming e) { 264 throw e; 265 } catch (PException e) { 266 throw new PExceptionNaming(e); 267 } 268 PBinder binder = (PBinder) key2binder.get(key); 269 if (binder == null) { 270 throw new PExceptionNaming("No binder associated to the key: " + key); 271 } 272 return binder.decodeObyte(en); 273 } 274 275 public PName decodeChar(char en) throws PExceptionNaming, UnsupportedOperationException { 276 if (codingType != CTCHAR) { 277 throw new PExceptionNaming("Bad coder type: " + codingType); 278 } 279 if (((Character ) nullValue).charValue() == en) { 280 return getNull(); 281 } 282 Object key; 283 try { 284 key = evaluate(pngConverter.convert(en), null); 285 } catch (PExceptionNaming e) { 286 throw e; 287 } catch (PException e) { 288 throw new PExceptionNaming(e); 289 } 290 PBinder binder = (PBinder) key2binder.get(key); 291 if (binder == null) { 292 throw new PExceptionNaming("No binder associated to the key: " + key); 293 } 294 return binder.decodeChar(en); 295 } 296 297 public PName decodeOchar(Character en) throws PExceptionNaming, UnsupportedOperationException { 298 if (codingType != CTOCHAR) { 299 throw new PExceptionNaming("Bad coder type: " + codingType); 300 } 301 if (nullValue == null) { 302 if (en == null) { 303 return getNull(); 304 } 305 } else if (en != null 306 && ((Character ) nullValue).charValue() == en.charValue()) { 307 return getNull(); 308 } 309 Object key; 310 try { 311 key = evaluate(pngConverter.convert(en), null); 312 } catch (PExceptionNaming e) { 313 throw e; 314 } catch (PException e) { 315 throw new PExceptionNaming(e); 316 } 317 PBinder binder = (PBinder) key2binder.get(key); 318 if (binder == null) { 319 throw new PExceptionNaming("No binder associated to the key: " + key); 320 } 321 return binder.decodeOchar(en); 322 } 323 324 public PName decodeInt(int en) throws PExceptionNaming, UnsupportedOperationException { 325 if (codingType != CTINT) { 326 throw new PExceptionNaming("Bad coder type: " + codingType); 327 } 328 if (((Integer ) nullValue).intValue() == en) { 329 return getNull(); 330 } 331 Object key; 332 try { 333 key = evaluate(pngConverter.convert(en), null); 334 } catch (PExceptionNaming e) { 335 throw e; 336 } catch (PException e) { 337 throw new PExceptionNaming(e); 338 } 339 PBinder binder = (PBinder) key2binder.get(key); 340 if (binder == null) { 341 throw new PExceptionNaming("No binder associated to the key: " + key); 342 } 343 return binder.decodeInt(en); 344 } 345 346 public PName decodeOint(Integer en) throws PExceptionNaming, UnsupportedOperationException { 347 if (codingType != CTOINT) { 348 throw new PExceptionNaming("Bad coder type: " + codingType); 349 } 350 if (nullValue == null) { 351 if (en == null) { 352 return getNull(); 353 } 354 } else if (en != null 355 && ((Integer ) nullValue).intValue() == en.intValue()) { 356 return getNull(); 357 } 358 Object key; 359 try { 360 key = evaluate(pngConverter.convert(en), null); 361 } catch (PExceptionNaming e) { 362 throw e; 363 } catch (PException e) { 364 throw new PExceptionNaming(e); 365 } 366 PBinder binder = (PBinder) key2binder.get(key); 367 if (binder == null) { 368 throw new PExceptionNaming("No binder associated to the key: " + key); 369 } 370 return binder.decodeOint(en); 371 } 372 373 public PName decodeLong(long en) throws PExceptionNaming, UnsupportedOperationException { 374 if (codingType != CTLONG) { 375 throw new PExceptionNaming("Bad coder type: " + codingType); 376 } 377 if (((Long ) nullValue).longValue() == en) { 378 return getNull(); 379 } 380 Object key; 381 try { 382 key = evaluate(pngConverter.convert(en), null); 383 } catch (PExceptionNaming e) { 384 throw e; 385 } catch (PException e) { 386 throw new PExceptionNaming(e); 387 } 388 PBinder binder = (PBinder) key2binder.get(key); 389 if (binder == null) { 390 throw new PExceptionNaming("No binder associated to the key: " + key); 391 } 392 return binder.decodeLong(en); 393 } 394 395 public PName decodeOlong(Long en) throws PExceptionNaming, UnsupportedOperationException { 396 if (codingType != CTOLONG) { 397 throw new PExceptionNaming("Bad coder type: " + codingType); 398 } 399 if (nullValue == null) { 400 if (en == null) { 401 return getNull(); 402 } 403 } else if (en != null 404 && ((Long ) nullValue).longValue() == en.longValue()) { 405 return getNull(); 406 } 407 Object key; 408 try { 409 key = evaluate(pngConverter.convert(en), null); 410 } catch (PExceptionNaming e) { 411 throw e; 412 } catch (PException e) { 413 throw new PExceptionNaming(e); 414 } 415 PBinder binder = (PBinder) key2binder.get(key); 416 if (binder == null) { 417 throw new PExceptionNaming("No binder associated to the key: " + key); 418 } 419 return binder.decodeOlong(en); 420 } 421 422 public PName decodeShort(short en) throws PExceptionNaming, UnsupportedOperationException { 423 if (codingType != CTSHORT) { 424 throw new PExceptionNaming("Bad coder type: " + codingType); 425 } 426 if (((Short ) nullValue).shortValue() == en) { 427 return getNull(); 428 } 429 Object key; 430 try { 431 key = evaluate(pngConverter.convert(en), null); 432 } catch (PExceptionNaming e) { 433 throw e; 434 } catch (PException e) { 435 throw new PExceptionNaming(e); 436 } 437 PBinder binder = (PBinder) key2binder.get(key); 438 if (binder == null) { 439 throw new PExceptionNaming("No binder associated to the key: " + key); 440 } 441 return binder.decodeLong(en); 442 } 443 444 public PName decodeOshort(Short en) throws PExceptionNaming, UnsupportedOperationException { 445 if (codingType != CTOSHORT) { 446 throw new PExceptionNaming("Bad coder type: " + codingType); 447 } 448 if (nullValue == null) { 449 if (en == null) { 450 return getNull(); 451 } 452 } else if (en != null 453 && ((Short ) nullValue).shortValue() == en.shortValue()) { 454 return getNull(); 455 } 456 Object key; 457 try { 458 key = evaluate(pngConverter.convert(en), null); 459 } catch (PExceptionNaming e) { 460 throw e; 461 } catch (PException e) { 462 throw new PExceptionNaming(e); 463 } 464 PBinder binder = (PBinder) key2binder.get(key); 465 if (binder == null) { 466 throw new PExceptionNaming("No binder associated to the key: " + key); 467 } 468 return binder.decodeOshort(en); 469 } 470 471 public PName decodeCharArray(char[] en) throws PExceptionNaming { 472 if (codingType != CTCHARARRAY) { 473 throw new PExceptionNaming("Bad coder type: " + codingType); 474 } 475 if (Arrays.equals((char[]) nullValue, en)) { 476 return getNull(); 477 } 478 Object key; 479 try { 480 key = evaluate(pngConverter.convert(en), null); 481 } catch (PExceptionNaming e) { 482 throw e; 483 } catch (PException e) { 484 throw new PExceptionNaming(e); 485 } 486 PBinder binder = (PBinder) key2binder.get(key); 487 if (binder == null) { 488 throw new PExceptionNaming("No binder associated to the key: " + key); 489 } 490 return binder.decodeCharArray(en); 491 } 492 493 public PName decode(byte[] en) throws PExceptionNaming { 494 if (codingType != CTBYTEARRAY) { 495 throw new PExceptionNaming("Bad coder type: " + codingType); 496 } 497 if (Arrays.equals((byte[]) nullValue, en)) { 498 return getNull(); 499 } 500 Object key; 501 try { 502 key = evaluate(pngConverter.convert(en), null); 503 } catch (PExceptionNaming e) { 504 throw e; 505 } catch (PException e) { 506 throw new PExceptionNaming(e); 507 } 508 PBinder binder = (PBinder) key2binder.get(key); 509 if (binder == null) { 510 throw new PExceptionNaming("No binder associated to the key: " + key); 511 } 512 return binder.decode(en); 513 } 514 515 public PName decodeDate(Date en) throws PExceptionNaming { 516 if (codingType != CTDATE) { 517 throw new PExceptionNaming("Bad coder type: " + codingType); 518 } 519 if (nullValue == null) { 520 if (en == null) { 521 return getNull(); 522 } 523 } else if (en != null 524 && ((Date ) nullValue).getTime() == en.getTime()) { 525 return getNull(); 526 } 527 Object key; 528 try { 529 key = evaluate(pngConverter.convert(en), null); 530 } catch (PExceptionNaming e) { 531 throw e; 532 } catch (PException e) { 533 throw new PExceptionNaming(e); 534 } 535 PBinder binder = (PBinder) key2binder.get(key); 536 if (binder == null) { 537 throw new PExceptionNaming("No binder associated to the key: " + key); 538 } 539 return binder.decodeDate(en); 540 } 541 542 public PName decodeBigInteger(BigInteger en) throws PExceptionNaming { 543 if (codingType != CTBIGINTEGER) { 544 throw new PExceptionNaming("Bad coder type: " + codingType); 545 } 546 if (nullValue == null) { 547 if (en == null) { 548 return getNull(); 549 } 550 } else if (((BigInteger ) nullValue).compareTo(en) == 0) { 551 return getNull(); 552 } 553 Object key; 554 try { 555 key = evaluate(pngConverter.convert(en), null); 556 } catch (PExceptionNaming e) { 557 throw e; 558 } catch (PException e) { 559 throw new PExceptionNaming(e); 560 } 561 PBinder binder = (PBinder) key2binder.get(key); 562 if (binder == null) { 563 throw new PExceptionNaming("No binder associated to the key: " + key); 564 } 565 return binder.decodeBigInteger(en); 566 } 567 568 public PName decodeBigDecimal(BigDecimal en) throws PExceptionNaming { 569 if (codingType != CTBIGDECIMAL) { 570 throw new PExceptionNaming("Bad coder type: " + codingType); 571 } 572 if (nullValue == null) { 573 if (en == null) { 574 return getNull(); 575 } 576 } else if (((BigDecimal ) nullValue).compareTo(en) == 0) { 577 return getNull(); 578 } 579 Object key; 580 try { 581 key = evaluate(pngConverter.convert(en), null); 582 } catch (PExceptionNaming e) { 583 throw e; 584 } catch (PException e) { 585 throw new PExceptionNaming(e); 586 } 587 PBinder binder = (PBinder) key2binder.get(key); 588 if (binder == null) { 589 throw new PExceptionNaming("No binder associated to the key: " + key); 590 } 591 return binder.decodeBigDecimal(en); 592 } 593 594 595 public PName decodeString(String en) throws PExceptionNaming { 596 597 return null; 598 } 599 600 public byte encodeByte(PName pn) throws PExceptionNaming, UnsupportedOperationException { 601 if (pn == null) { 602 throw new PExceptionNaming("Impossible to encode null"); 603 } else if (pn == nullPName || pn.isNull()) { 604 return ((Byte ) nullValue).byteValue(); 605 } else { 606 PNameManager pnm = pn.getPNameManager(); 607 if (pnm != this && pnm != null) { 608 return pn.getPNameManager().encodeByte(pn); 609 } else { 610 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 611 } 612 } 613 } 614 615 public char encodeChar(PName pn) throws PExceptionNaming, UnsupportedOperationException { 616 if (pn == null) { 617 throw new PExceptionNaming("Impossible to encode null"); 618 } else if (pn == nullPName || pn.isNull()) { 619 return ((Character ) nullValue).charValue(); 620 } else { 621 PNameManager pnm = pn.getPNameManager(); 622 if (pnm != this && pnm != null) { 623 return pn.getPNameManager().encodeChar(pn); 624 } else { 625 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 626 } 627 } 628 } 629 630 public int encodeInt(PName pn) throws PExceptionNaming, UnsupportedOperationException { 631 if (pn == null) { 632 throw new PExceptionNaming("Impossible to encode null"); 633 } else if (pn == nullPName || pn.isNull()) { 634 return ((Integer ) nullValue).intValue(); 635 } else { 636 PNameManager pnm = pn.getPNameManager(); 637 if (pnm != this && pnm != null) { 638 return pn.getPNameManager().encodeInt(pn); 639 } else { 640 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 641 } 642 } 643 } 644 645 public long encodeLong(PName pn) throws PExceptionNaming, UnsupportedOperationException { 646 if (pn == null) { 647 throw new PExceptionNaming("Impossible to encode null"); 648 } else if (pn == nullPName || pn.isNull()) { 649 return ((Long ) nullValue).longValue(); 650 } else { 651 PNameManager pnm = pn.getPNameManager(); 652 if (pnm != this && pnm != null) { 653 return pn.getPNameManager().encodeLong(pn); 654 } else { 655 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 656 } 657 } 658 } 659 660 public short encodeShort(PName pn) throws PExceptionNaming, UnsupportedOperationException { 661 if (pn == null) { 662 throw new PExceptionNaming("Impossible to encode null"); 663 } else if (pn == nullPName || pn.isNull()) { 664 return ((Short ) nullValue).shortValue(); 665 } else { 666 PNameManager pnm = pn.getPNameManager(); 667 if (pnm != this && pnm != null) { 668 return pn.getPNameManager().encodeShort(pn); 669 } else { 670 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 671 } 672 } 673 } 674 675 public Byte encodeObyte(PName pn) throws PExceptionNaming, UnsupportedOperationException { 676 if (pn == null) { 677 throw new PExceptionNaming("Impossible to encode null"); 678 } else if (pn == nullPName || pn.isNull()) { 679 return (Byte ) nullValue; 680 } else { 681 PNameManager pnm = pn.getPNameManager(); 682 if (pnm != this && pnm != null) { 683 return pn.getPNameManager().encodeObyte(pn); 684 } else { 685 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 686 } 687 } 688 } 689 690 public Character encodeOchar(PName pn) throws PExceptionNaming, UnsupportedOperationException { 691 if (pn == null) { 692 throw new PExceptionNaming("Impossible to encode null"); 693 } else if (pn == nullPName || pn.isNull()) { 694 return (Character ) nullValue; 695 } else { 696 PNameManager pnm = pn.getPNameManager(); 697 if (pnm != this && pnm != null) { 698 return pn.getPNameManager().encodeOchar(pn); 699 } else { 700 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 701 } 702 } 703 } 704 705 public Integer encodeOint(PName pn) throws PExceptionNaming, UnsupportedOperationException { 706 if (pn == null) { 707 throw new PExceptionNaming("Impossible to encode null"); 708 } else if (pn == nullPName || pn.isNull()) { 709 return (Integer ) nullValue; 710 } else { 711 PNameManager pnm = pn.getPNameManager(); 712 if (pnm != this && pnm != null) { 713 return pn.getPNameManager().encodeOint(pn); 714 } else { 715 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 716 } 717 } 718 } 719 720 public Long encodeOlong(PName pn) throws PExceptionNaming, UnsupportedOperationException { 721 if (pn == null) { 722 throw new PExceptionNaming("Impossible to encode null"); 723 } else if (pn == nullPName || pn.isNull()) { 724 return (Long ) nullValue; 725 } else { 726 PNameManager pnm = pn.getPNameManager(); 727 if (pnm != this && pnm != null) { 728 return pn.getPNameManager().encodeOlong(pn); 729 } else { 730 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 731 } 732 } 733 } 734 735 public Short encodeOshort(PName pn) throws PExceptionNaming, UnsupportedOperationException { 736 if (pn == null) { 737 throw new PExceptionNaming("Impossible to encode null"); 738 } else if (pn == nullPName || pn.isNull()) { 739 return (Short ) nullValue; 740 } else { 741 PNameManager pnm = pn.getPNameManager(); 742 if (pnm != this && pnm != null) { 743 return pn.getPNameManager().encodeOshort(pn); 744 } else { 745 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 746 } 747 } 748 } 749 750 public Date encodeDate(PName pn) throws PExceptionNaming { 751 if (pn == null) { 752 throw new PExceptionNaming("Impossible to encode null"); 753 } else if (pn == nullPName || pn.isNull()) { 754 return (Date ) nullValue; 755 } else { 756 PNameManager pnm = pn.getPNameManager(); 757 if (pnm != this && pnm != null) { 758 return pn.getPNameManager().encodeDate(pn); 759 } else { 760 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 761 } 762 } 763 } 764 765 public BigInteger encodeBigInteger(PName pn) throws PExceptionNaming { 766 if (pn == null) { 767 throw new PExceptionNaming("Impossible to encode null"); 768 } else if (pn == nullPName || pn.isNull()) { 769 return (BigInteger ) nullValue; 770 } else { 771 PNameManager pnm = pn.getPNameManager(); 772 if (pnm != this && pnm != null) { 773 return pn.getPNameManager().encodeBigInteger(pn); 774 } else { 775 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 776 } 777 } 778 } 779 780 public BigDecimal encodeBigDecimal(PName pn) throws PExceptionNaming { 781 if (pn == null) { 782 throw new PExceptionNaming("Impossible to encode null"); 783 } else if (pn == nullPName || pn.isNull()) { 784 return (BigDecimal ) nullValue; 785 } else { 786 PNameManager pnm = pn.getPNameManager(); 787 if (pnm != this && pnm != null) { 788 return pn.getPNameManager().encodeBigDecimal(pn); 789 } else { 790 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 791 } 792 } 793 } 794 795 public byte[] encode(PName pn) throws PExceptionNaming { 796 if (pn == null) { 797 throw new PExceptionNaming("Impossible to encode null"); 798 } else if (pn == nullPName || pn.isNull()) { 799 return (byte[]) nullValue; 800 } else { 801 PNameManager pnm = pn.getPNameManager(); 802 if (pnm != this && pnm != null) { 803 return pn.getPNameManager().encode(pn); 804 } else { 805 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 806 } 807 } 808 } 809 810 public char[] encodeCharArray(PName pn) throws PExceptionNaming { 811 if (pn == null) { 812 throw new PExceptionNaming("Impossible to encode null"); 813 } else if (pn == nullPName || pn.isNull()) { 814 return (char[]) nullValue; 815 } else { 816 PNameManager pnm = pn.getPNameManager(); 817 if (pnm != this && pnm != null) { 818 return pn.getPNameManager().encodeCharArray(pn); 819 } else { 820 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 821 } 822 } 823 } 824 825 public Object encodeAbstract(PName pn) throws PExceptionNaming, UnsupportedOperationException { 826 if (pn == null) { 827 throw new PExceptionNaming("Impossible to encode null"); 828 } else if (pn == nullPName || pn.isNull()) { 829 return nullPName; 830 } else { 831 PNameManager pnm = pn.getPNameManager(); 832 if (pnm != this && pnm != null) { 833 return pn.getPNameManager().encodeAbstract(pn); 834 } else { 835 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 836 } 837 } 838 } 839 840 public String encodeString(PName pn) throws PExceptionNaming { 841 if (pn == null) { 842 throw new PExceptionNaming("Impossible to encode null"); 843 } else if (pn == nullValue || pn.isNull()) { 844 return (String ) nullValue; 845 } else { 846 PNameManager pnm = pn.getPNameManager(); 847 if (pnm != this && pnm != null) { 848 return pn.getPNameManager().encodeString(pn); 849 } else { 850 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn); 851 } 852 } 853 } 854 855 public PName getNull() { 856 return nullPName; 857 } 858 859 862 public void setNullPName(Object o) throws PException { 863 if (!(o instanceof PName)) { 864 throw new PExceptionNaming("A KFPNC accepts only PName instance as parameter to define the null pname"); 865 } 866 nullPName = (PName) o; 867 } 868 869 private void checkNullValue() throws PException { 870 switch (codingType) { 871 case CTCHAR: 872 nullValue = new Character (nullPName.encodeChar()); 873 break; 874 case CTOCHAR: 875 nullValue = nullPName.encodeOchar(); 876 break; 877 case CTBYTE: 878 nullValue = new Byte (nullPName.encodeByte()); 879 break; 880 case CTOBYTE: 881 nullValue = nullPName.encodeObyte(); 882 break; 883 case CTSHORT: 884 nullValue = new Short (nullPName.encodeShort()); 885 break; 886 case CTOSHORT: 887 nullValue = nullPName.encodeOshort(); 888 break; 889 case CTINT: 890 nullValue = new Integer (nullPName.encodeInt()); 891 break; 892 case CTOINT: 893 nullValue = nullPName.encodeOint(); 894 break; 895 case CTLONG: 896 nullValue = new Long (nullPName.encodeLong()); 897 break; 898 case CTOLONG: 899 nullValue = nullPName.encodeOlong(); 900 break; 901 case CTSTRING: 902 nullValue = nullPName.encodeString(); 903 break; 904 case CTDATE: 905 nullValue = nullPName.encodeDate(); 906 break; 907 case CTBIGDECIMAL: 908 nullValue = nullPName.encodeBigDecimal(); 909 break; 910 case CTBIGINTEGER: 911 nullValue = nullPName.encodeBigInteger(); 912 break; 913 case CTBYTEARRAY: 914 nullValue = nullPName.encode(); 915 break; 916 case CTCHARARRAY: 917 nullValue = nullPName.encodeCharArray(); 918 break; 919 case CTCOMPOSITE: 920 break; 921 } 922 } 923 } 924 925 | Popular Tags |