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