00001 package ;
00002
00003
00011
00012
00013 import config.*;
00014
00015
00016
00017
00018 import .PowerCard;
00019 import .PowerCard_Helper;
00020 import .PowerChannel;
00021 import .PowerChannel_Helper;
00022
00023
00024 class PowerCrate_Impl implements PowerCrate {
00025
00026
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
00037
00038 private short m_id;
00039
00040
00041
00042
00043 private PowerChannel[] m_channels;
00044 private PowerCard[] m_cards;
00045
00046
00047
00048
00049
00050 public PowerCrate_Impl() {
00051 p_is_valid = false;
00052 }
00053
00054 public PowerCrate_Impl(config.Configuration db, config.ConfigObject obj) {
00055 init_config_params(db, obj);
00056 }
00057
00058 public void init_config_params(config.Configuration db, config.ConfigObject obj) {
00059 p_db = db;
00060 p_obj = obj;
00061 p_was_read = false;
00062 p_is_valid = true;
00063 p_uid = p_obj.UID();
00064 p_class_name = p_obj.class_name();
00065 }
00066
00067 public String UID() {
00068 return p_uid;
00069 }
00070
00071 public String class_name() {
00072 return p_class_name;
00073 }
00074
00075 public void update(boolean set_non_valid) {
00076 if(set_non_valid == true) {
00077 p_is_valid = false;
00078 }
00079 else {
00080 p_was_read = false;
00081 p_obj.clean();
00082 init();
00083 }
00084 }
00085
00086 public void unread() {
00087 p_was_read = false;
00088 }
00089
00090 public boolean is_valid() {
00091 return p_is_valid;
00092 }
00093
00094
00095
00096 private void init() throws config.NotFoundException, config.NotValidException, config.SystemException {
00097 if(p_was_read == true) {return;}
00098
00099 if(p_is_valid == false) {
00100 String text = "ERROR [.PowerCrate_Impl.init()]: object " + p_uid + "@" + p_class_name + " is not valid";
00101 System.err.println(text);
00102 throw new config.NotValidException(text);
00103 }
00104
00105 m_id = p_obj.get_short("id");
00106
00107 {
00108 ConfigObject[] objs = p_obj.get_objects("channels");
00109 m_channels = new PowerChannel[objs.length];
00110 for( int i = 0; i < objs.length; i++ ) {
00111 m_channels[i] = PowerChannel_Helper.get(p_db, objs[i]);
00112 }
00113 }
00114
00115 {
00116 ConfigObject[] objs = p_obj.get_objects("cards");
00117 m_cards = new PowerCard[objs.length];
00118 for( int i = 0; i < objs.length; i++ ) {
00119 m_cards[i] = PowerCard_Helper.get(p_db, objs[i]);
00120 }
00121 }
00122
00123
00124 p_was_read = true;
00125
00126 }
00127
00128 public short get_id() {
00129 if(p_was_read == false) {init();}
00130 return m_id;
00131 }
00132
00133 public void set_id(short value) {
00134 p_obj.clean();
00135 p_obj.set_short("id", value);
00136 }
00137
00138 public PowerChannel[] get_channels() {
00139 if(p_was_read == false) {init();}
00140 return m_channels;
00141 }
00142
00143 public void set_channels(PowerChannel[] value) {
00144 p_obj.clean();
00145 config.ConfigObject[] objs = new config.ConfigObject[value.length];
00146 for(int i = 0; i < value.length; i++) {
00147 objs[i] = value[i].config_object();
00148 }
00149 p_obj.set_objects("channels", objs);
00150 }
00151
00152 public PowerCard[] get_cards() {
00153 if(p_was_read == false) {init();}
00154 return m_cards;
00155 }
00156
00157 public void set_cards(PowerCard[] value) {
00158 p_obj.clean();
00159 config.ConfigObject[] objs = new config.ConfigObject[value.length];
00160 for(int i = 0; i < value.length; i++) {
00161 objs[i] = value[i].config_object();
00162 }
00163 p_obj.set_objects("cards", objs);
00164 }
00165
00166 public config.ConfigObject config_object() {
00167 return p_obj;
00168 }
00169
00170 public void print(String dx) {
00171 System.out.println(dx + "PowerCrate object:" );
00172 System.out.println(dx + " id: \'" + UID() + "\', class name: \'" + class_name() + "\'");
00173
00174
00175
00176
00177 System.out.println(dx + " id: " + get_id());
00178
00179
00180
00181
00182 if(get_channels().length > 0) {
00183 System.out.print(dx + " " + get_channels().length + " object(s) in channels :\n");
00184
00185 for(int i = 0; i < get_channels().length; i++) {
00186 get_channels()[i].print(dx.concat(" "));
00187 }
00188 }
00189 else {
00190 System.out.println(dx + " channels value is empty");
00191 }
00192
00193 if(get_cards().length > 0) {
00194 System.out.print(dx + " " + get_cards().length + " object(s) in cards :\n");
00195
00196 for(int i = 0; i < get_cards().length; i++) {
00197 get_cards()[i].print(dx.concat(" "));
00198 }
00199 }
00200 else {
00201 System.out.println(dx + " cards value is empty");
00202 }
00203
00204 }
00205
00211 public void destroy(config.Configuration db) {
00212 db.destroy(config_object());
00213 }
00214 }