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