1 5 package com.tc.objectserver.managedobject; 6 7 import com.tc.exception.TCRuntimeException; 8 import com.tc.object.ObjectID; 9 import com.tc.object.dna.api.DNA; 10 import com.tc.object.dna.api.DNACursor; 11 import com.tc.object.dna.api.DNAWriter; 12 import com.tc.object.dna.api.LiteralAction; 13 import com.tc.object.dna.impl.ClassInstance; 14 import com.tc.object.dna.impl.ClassLoaderInstance; 15 import com.tc.object.dna.impl.UTF8ByteDataHolder; 16 import com.tc.object.loaders.Namespace; 17 import com.tc.objectserver.mgmt.ManagedObjectFacade; 18 import com.tc.objectserver.mgmt.PhysicalManagedObjectFacade; 19 import com.tc.text.PrettyPrintable; 20 import com.tc.text.PrettyPrinter; 21 import com.tc.util.Assert; 22 23 import java.io.IOException ; 24 import java.io.ObjectInput ; 25 import java.io.ObjectOutput ; 26 import java.io.PrintWriter ; 27 import java.io.StringWriter ; 28 import java.util.Collections ; 29 import java.util.HashMap ; 30 import java.util.Map ; 31 import java.util.Set ; 32 33 public class LiteralTypesManagedObjectState extends AbstractManagedObjectState implements PrettyPrintable { 34 private Object references; 35 36 LiteralTypesManagedObjectState() { 37 super(); 38 } 39 40 public int hashCode() { 41 throw new TCRuntimeException("Don't hash me!"); 42 } 43 44 public void apply(ObjectID objectID, DNACursor cursor, BackReferences includeIDs) throws IOException { 45 final int actionCount = cursor.getActionCount(); 46 if (actionCount != 1) { 47 throw new AssertionError ("Invalid action count: " + actionCount + "\nThis object is " + toString() + "\nDNA is " 50 + cursor.toString() + "\nApply object ID: " + objectID); 51 } 52 53 cursor.next(); 54 LiteralAction a = (LiteralAction) cursor.getAction(); 55 references = a.getObject(); 58 } 59 60 public void dehydrate(ObjectID objectID, DNAWriter writer) { 61 writer.addLiteralValue(references); 62 } 63 64 public String toString() { 65 StringWriter writer = new StringWriter (); 67 PrintWriter pWriter = new PrintWriter (writer); 68 new PrettyPrinter(pWriter).visit(this); 69 return writer.getBuffer().toString(); 70 } 71 72 public PrettyPrinter prettyPrint(PrettyPrinter out) { 73 PrettyPrinter rv = out; 74 out = out.print(getClass().getName()).duplicateAndIndent().println(); 75 out.indent().print("references: " + references).println(); 76 out.indent().print("listener: " + getListener()).println(); 77 return rv; 78 } 79 80 public ManagedObjectFacade createFacade(ObjectID objectID, String className, int limit) { 81 83 Map dataCopy = new HashMap (); 84 dataCopy.put(className, references); 85 86 return new PhysicalManagedObjectFacade(objectID, ObjectID.NULL_ID, className, dataCopy, false, DNA.NULL_ARRAY_SIZE, 87 false); 88 } 89 90 public Set getObjectReferences() { 91 return Collections.EMPTY_SET; 92 } 93 94 public void addObjectReferencesTo(ManagedObjectTraverser traverser) { 95 } 97 98 public byte getType() { 99 return LITERAL_TYPE; 100 } 101 102 public void writeTo(ObjectOutput o) throws IOException { 103 o.writeObject(references); 104 } 105 106 static LiteralTypesManagedObjectState readFrom(ObjectInput in) throws IOException , ClassNotFoundException { 107 LiteralTypesManagedObjectState lmos = new LiteralTypesManagedObjectState(); 108 lmos.references = in.readObject(); 109 return lmos; 110 } 111 112 protected boolean basicEquals(AbstractManagedObjectState o) { 113 LiteralTypesManagedObjectState lmos = (LiteralTypesManagedObjectState) o; 114 return references.equals(lmos.references); 115 } 116 117 public String getClassName() { 118 Assert.assertNotNull(references); 119 120 if (references instanceof ClassInstance) { 121 return "java.lang.Class"; 122 } else if (references instanceof ClassLoaderInstance) { 123 return "java.lang.ClassLoader"; 124 } else if (references instanceof UTF8ByteDataHolder) { return "java.lang.String"; } 125 126 return references.getClass().getName(); 127 } 128 129 public String getLoaderDescription() { 130 return Namespace.getStandardBootstrapLoaderName(); 131 } 132 133 } 134 | Popular Tags |