KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > faceless > pdf > PeeredObject


1 package org.faceless.pdf;
2
3 import java.util.WeakHashMap JavaDoc;
4 import java.lang.ref.*;
5
6 abstract class PeeredObject
7 {
8     private static final WeakHashMap JavaDoc map = new WeakHashMap JavaDoc();
9
10     PeeredObject() {}
11
12     abstract Object JavaDoc getPeer();
13
14     static final Object JavaDoc getPeer(Object JavaDoc newobject)
15     {
16     if (newobject==null) return null;
17         Object JavaDoc oldobject = map.get(newobject);
18         if (oldobject!=null) {
19             return ((Reference)oldobject).get();
20         } else {
21         if (newobject instanceof org.faceless.pdf2.PDFPage) {
22             oldobject=new PDFPage((org.faceless.pdf2.PDFPage)newobject);
23         } else if (newobject instanceof org.faceless.pdf2.PDFAction) {
24             oldobject=new PDFAction((org.faceless.pdf2.PDFAction)newobject);
25         } else if (newobject instanceof org.faceless.pdf2.PDFAnnotation) {
26             oldobject=new PDFAnnotation((org.faceless.pdf2.PDFAnnotation)newobject);
27         } else if (newobject instanceof org.faceless.pdf2.PDFFont) {
28             oldobject=new PDFFont((org.faceless.pdf2.PDFFont)newobject);
29         } else if (newobject instanceof org.faceless.pdf2.PDFStyle) {
30             oldobject=new PDFStyle((org.faceless.pdf2.PDFStyle)newobject);
31         } else if (newobject instanceof org.faceless.pdf2.PDFImage) {
32             oldobject=new PDFImage((org.faceless.pdf2.PDFImage)newobject);
33         } else if (newobject instanceof org.faceless.pdf2.PDFPattern) {
34             oldobject=new ColorPattern((org.faceless.pdf2.PDFPattern)newobject);
35         } else if (newobject instanceof org.faceless.pdf2.PDFBookmark) {
36             oldobject=new PDFBookmark((org.faceless.pdf2.PDFBookmark)newobject);
37         } else if (newobject instanceof org.faceless.pdf2.FormButton) {
38             oldobject=new FormButton((org.faceless.pdf2.FormButton)newobject);
39         } else if (newobject instanceof org.faceless.pdf2.FormText) {
40             oldobject=new FormText((org.faceless.pdf2.FormText)newobject);
41         } else if (newobject instanceof org.faceless.pdf2.FormRadioButton) {
42             oldobject=new FormRadioButton((org.faceless.pdf2.FormRadioButton)newobject);
43         } else if (newobject instanceof org.faceless.pdf2.FormCheckbox) {
44             oldobject=new FormCheckbox((org.faceless.pdf2.FormCheckbox)newobject);
45         } else if (newobject instanceof org.faceless.pdf2.FormSignature) {
46             oldobject=new FormSignature((org.faceless.pdf2.FormSignature)newobject);
47         } else if (newobject instanceof org.faceless.pdf2.FormChoice) {
48             oldobject=new FormChoice((org.faceless.pdf2.FormChoice)newobject);
49         } else if (newobject instanceof org.faceless.pdf2.Form) {
50             oldobject=new Form((org.faceless.pdf2.Form)newobject);
51         } else if (newobject instanceof org.faceless.pdf2.PDFSound) {
52             oldobject=new PDFSound((org.faceless.pdf2.PDFSound)newobject);
53         } else if (newobject instanceof org.faceless.pdf2.LayoutBox.Text) {
54             oldobject=new LayoutBox.Text((org.faceless.pdf2.LayoutBox.Text)newobject);
55         } else if (newobject instanceof org.faceless.pdf2.LayoutBox.Box) {
56             oldobject=new LayoutBox.Box((org.faceless.pdf2.LayoutBox.Box)newobject);
57         } else if (newobject instanceof org.faceless.pdf2.LayoutBox) {
58             oldobject=new LayoutBox((org.faceless.pdf2.LayoutBox)newobject);
59         } else {
60             throw new Error JavaDoc("Unknown peer class "+newobject.getClass());
61         }
62         map.put(newobject, new WeakReference(oldobject));
63     }
64     return oldobject;
65     }
66
67     public String JavaDoc toString()
68     {
69         return getPeer().toString();
70     }
71 }
72
Popular Tags