Power_Impl.java

00001 package ;
00002 
00003 
00011   // import configuration classes
00012 
00013 import config.*;
00014 
00015 
00016   // import used generated classes
00017 
00018 import .PowerCrate;
00019 import .PowerCrate_Helper;
00020 import .PowerParam;
00021 import .PowerParam_Helper;
00022 
00023 
00024 class Power_Impl implements Power {
00025 
00026     // base attributes
00027 
00028   private config.Configuration p_db;
00029   private config.ConfigObject p_obj;
00030   private boolean p_was_read;
00031   private boolean p_is_valid;
00032   private String p_uid;
00033   private String p_class_name;
00034 
00035 
00036     // database class attributes
00037 
00038 
00039 
00040     // database class relationships
00041 
00042   private PowerParam[] m_defaults;
00043   private PowerCrate[] m_crates;
00044 
00045 
00046 
00047     // constructor
00048 
00049   public Power_Impl() {
00050     p_is_valid = false;
00051   }
00052 
00053   public Power_Impl(config.Configuration db, config.ConfigObject obj) {
00054     init_config_params(db, obj);
00055   }
00056 
00057   public void init_config_params(config.Configuration db, config.ConfigObject obj) {
00058     p_db = db;
00059     p_obj = obj;
00060     p_was_read = false;
00061     p_is_valid = true;
00062     p_uid = p_obj.UID();
00063     p_class_name = p_obj.class_name();
00064   }
00065 
00066   public String UID() {
00067     return p_uid;
00068   }
00069 
00070   public String class_name() {
00071     return p_class_name;
00072   }
00073 
00074   public void update(boolean set_non_valid) {
00075     if(set_non_valid == true) {
00076       p_is_valid = false;
00077     }
00078     else {
00079       p_was_read = false;
00080       p_obj.clean();
00081       init();
00082     }
00083   }
00084 
00085   public void unread() {
00086     p_was_read = false;
00087   }
00088 
00089   public boolean is_valid() {
00090     return p_is_valid;
00091   }
00092 
00093 
00094 
00095   private void init() throws config.NotFoundException, config.NotValidException, config.SystemException {
00096     if(p_was_read == true) {return;}
00097 
00098     if(p_is_valid == false) {
00099       String text = "ERROR [.Power_Impl.init()]: object " + p_uid + "@" + p_class_name + " is not valid";
00100       System.err.println(text);
00101       throw new config.NotValidException(text);
00102     }
00103 
00104     {
00105       ConfigObject[] objs = p_obj.get_objects("defaults");
00106       m_defaults = new PowerParam[objs.length];
00107       for( int i = 0; i < objs.length; i++ ) {
00108         m_defaults[i] = PowerParam_Helper.get(p_db, objs[i]);
00109       }
00110     }
00111     
00112     {
00113       ConfigObject[] objs = p_obj.get_objects("crates");
00114       m_crates = new PowerCrate[objs.length];
00115       for( int i = 0; i < objs.length; i++ ) {
00116         m_crates[i] = PowerCrate_Helper.get(p_db, objs[i]);
00117       }
00118     }
00119     
00120 
00121     p_was_read = true;
00122 
00123   }
00124 
00125   public PowerParam[] get_defaults() {
00126     if(p_was_read == false) {init();}
00127     return m_defaults;
00128   }
00129 
00130   public void set_defaults(PowerParam[] value) {
00131     p_obj.clean();
00132     config.ConfigObject[] objs = new config.ConfigObject[value.length];
00133     for(int i = 0; i < value.length; i++) {
00134       objs[i] = value[i].config_object();
00135     }
00136     p_obj.set_objects("defaults", objs);
00137   }
00138 
00139   public PowerCrate[] get_crates() {
00140     if(p_was_read == false) {init();}
00141     return m_crates;
00142   }
00143 
00144   public void set_crates(PowerCrate[] value) {
00145     p_obj.clean();
00146     config.ConfigObject[] objs = new config.ConfigObject[value.length];
00147     for(int i = 0; i < value.length; i++) {
00148       objs[i] = value[i].config_object();
00149     }
00150     p_obj.set_objects("crates", objs);
00151   }
00152 
00153   public config.ConfigObject config_object() {
00154     return p_obj;
00155   }
00156 
00157   public void print(String dx) {
00158     System.out.println(dx + "Power object:" );
00159     System.out.println(dx + "  id: \'" + UID() + "\', class name: \'" + class_name() + "\'");
00160 
00161 
00162       // print attributes
00163 
00164 
00165 
00166       // print relationships
00167 
00168     if(get_defaults().length > 0) {
00169       System.out.print(dx + "  " + get_defaults().length + " object(s) in defaults :\n");
00170       
00171       for(int i = 0; i < get_defaults().length; i++) {
00172         get_defaults()[i].print(dx.concat("    "));
00173       }
00174     }
00175     else {
00176       System.out.println(dx + "  defaults value is empty");
00177     }
00178 
00179     if(get_crates().length > 0) {
00180       System.out.print(dx + "  " + get_crates().length + " object(s) in crates :\n");
00181       
00182       for(int i = 0; i < get_crates().length; i++) {
00183         get_crates()[i].print(dx.concat("    "));
00184       }
00185     }
00186     else {
00187       System.out.println(dx + "  crates value is empty");
00188     }
00189 
00190   }
00191 
00197   public void destroy(config.Configuration db) {
00198     db.destroy(config_object());
00199   }
00200 }

Generated on Mon Feb 6 14:12:15 2006 for SCT DAQ/DCS Software - Java by  doxygen 1.4.6