1 24 25 package org.objectweb.dream.message; 26 27 import java.io.Externalizable ; 28 import java.io.IOException ; 29 import java.io.ObjectInput ; 30 import java.io.ObjectOutput ; 31 32 import org.objectweb.dream.pool.Recyclable; 33 34 38 public class ChunkTypeImpl implements ChunkType, Recyclable, Externalizable 39 { 40 41 private Class chunkItf; 42 private Class chunkImpl; 43 44 47 public ChunkTypeImpl() 48 { 49 } 50 51 61 public ChunkTypeImpl(String itfSignature, String implSignature) 62 throws ClassNotFoundException 63 { 64 this(Class.forName(itfSignature), Class.forName(implSignature)); 65 } 66 67 77 public ChunkTypeImpl(Class chunkItf, Class chunkImpl) 78 { 79 if (!chunkItf.isInterface()) 80 { 81 throw new IllegalArgumentException (chunkItf.getName() 82 + " is not an Interface"); 83 } 84 if (!chunkItf.isAssignableFrom(chunkImpl)) 85 { 86 throw new IllegalArgumentException (chunkImpl.getName() 87 + "is not a sub class of the given interface"); 88 } 89 this.chunkItf = chunkItf; 90 this.chunkImpl = chunkImpl; 91 } 92 93 97 100 public String getChunkSignature() 101 { 102 return chunkItf.getName(); 103 } 104 105 108 public boolean isSubTypeOf(ChunkType t) 109 { 110 if (t instanceof ChunkTypeImpl) 111 { 112 return ((ChunkTypeImpl) t).getChunkItf().isAssignableFrom(chunkItf); 113 } 114 else 115 { 116 try 117 { 118 Class tChunkItf = Class.forName(t.getChunkSignature()); 119 return tChunkItf.isAssignableFrom(chunkItf); 120 } 121 catch (ClassNotFoundException e) 122 { 123 return false; 124 } 125 } 126 } 127 128 132 137 public Class getChunkItf() 138 { 139 return chunkItf; 140 } 141 142 147 public Class getChunkImpl() 148 { 149 return chunkImpl; 150 } 151 152 156 159 public void recycle() 160 { 161 chunkImpl = null; 162 chunkItf = null; 163 } 164 165 169 172 public void readExternal(ObjectInput in) throws IOException , 173 ClassNotFoundException 174 { 175 chunkImpl = Class.forName(in.readUTF()); 176 chunkItf = Class.forName(in.readUTF()); 177 } 178 179 182 public void writeExternal(ObjectOutput out) throws IOException 183 { 184 out.writeUTF(chunkImpl.getName()); 185 out.writeUTF(chunkItf.getName()); 186 } 187 } | Popular Tags |