Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ObjectManagerIS.java

00001 package Sct.IS;
00002 import Sct.*;
00003 import java.io.IOException;
00004 import java.io.InvalidClassException;
00005 
00006 public class ObjectManagerIS extends AbstractObjectManager {
00007     private static ObjectManagerIS instance;
00008     static {
00009         instance = new ObjectManagerIS();
00010     }
00011     
00012     protected ObjectManagerIS() {}
00013     
00014     public static ObjectManagerIS getInstance() {
00015         return instance;
00016     }
00017     
00018     
00019     public Serializable readObject(String uniqueID, String className) throws IOException{
00020         ISObject o = new ISObject(className);
00021         NameIS name = new NameIS(className, uniqueID);
00022         is.Repository r = SctNames.getISRepository();
00023         try {
00024             r.getValue(name.getName(),  o);
00025         } catch (RuntimeException re) {
00026             IOException e = new IOException("IS Exception trying to read " + name.getName());
00027             e.initCause(re);
00028             throw e;
00029         }
00030         
00031         return o.s;
00032     }
00033     
00034     public Name writeObject(Serializable object) throws IOException{
00035         ISObject o = new ISObject(object);
00036         is.Repository r = SctNames.getISRepository();
00037         NameIS name = new NameIS(object);
00038         try {
00039             r.insert(name.getName(),  o);
00040         } catch (RuntimeException re) {
00041             IOException e = new IOException("IS Exception trying to write " + name.getName());
00042             e.initCause(re);
00043             throw e;
00044         }
00045         return name;
00046     }
00047     
00048     public Serializable readObject(String name) throws IOException{
00049         is.Repository r = SctNames.getISRepository();
00050                 
00051         try {
00052             NameIS nameIS = new NameIS(name);
00053             ISObject o = new ISObject(nameIS.getClassName());        
00054             r.getValue(name, o);            
00055             return o.s;
00056             
00057         } catch (IllegalArgumentException iae) {
00058             is.AnyInfo any = new is.AnyInfo();            
00059             try {
00060                 r.getValue(name, any);
00061                 return new AnyInfoAdapter(any);
00062             } catch (RuntimeException re) {
00063                 IOException e = new IOException("IS Exception trying to read " + name);
00064                 e.initCause(re);
00065                 throw e;
00066             }            
00067         } catch (RuntimeException re) {
00068             IOException e = new IOException("IS Exception trying to read " + name);
00069             e.initCause(re);
00070             throw e;
00071         }
00072                 
00073     }    
00074     
00075     
00076     protected class ISObject extends is.Info {
00077         protected boolean bInConstructor = true;
00078         Serializable s;
00079         
00083         ISObject(Serializable s) {
00084             super(s.getClassName());
00085             this.s = s;
00086             bInConstructor = false;            
00087         }
00088         
00092         ISObject(String typename) {
00093             super(typename);
00094             bInConstructor = false;            
00095         }
00096                 
00097         public void publishGuts(is.Ostream out) {
00098             if (bInConstructor) return;
00099             super.publishGuts(out);
00100             try {
00101                 OStreamIS outIS = new OStreamIS(out);
00102                 writeClassName(outIS, s.getClassName());
00103                 s.write(outIS,  ObjectManagerIS.getInstance());
00104             } catch (IOException e) {
00105                 e.printStackTrace();
00106                 return;
00107             }
00108         }
00109         public void refreshGuts(is.Istream in) {
00110             super.refreshGuts(in);
00112             try {
00113                 IStreamIS inIS = new IStreamIS(in);
00114                 s = (Serializable)ObjectManagerIS.getInstance().createObject(inIS, readClassName(inIS));
00115             } catch (InvalidClassException e) {                
00116                 IllegalArgumentException ie = new IllegalArgumentException();
00117                 ie.initCause(e);
00118                 throw ie;
00119             } catch (Exception e) {
00120                 e.printStackTrace();
00121                 return;
00122             }
00123         }
00124     }
00125 }

Generated on Thu Jul 15 09:55:46 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5