00001 package ;
00002
00003
00011
00012
00013 import config.*;
00014
00015
00016
00017
00018 import .Param;
00019 import .Param_Helper;
00020
00021
00022 class PowerDefaults_Impl implements PowerDefaults {
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_state;
00037
00038
00039
00040
00041 private Param[] m_param;
00042
00043
00044
00045
00046
00047 public PowerDefaults_Impl() {
00048 p_is_valid = false;
00049 }
00050
00051 public PowerDefaults_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 [.PowerDefaults_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_state = p_obj.get_string("state");
00103 m_state = (String)p_db.convert((Object)m_state, p_obj, "state");
00104
00105 {
00106 ConfigObject[] objs = p_obj.get_objects("param");
00107 m_param = new Param[objs.length];
00108 for( int i = 0; i < objs.length; i++ ) {
00109 m_param[i] = Param_Helper.get(p_db, objs[i]);
00110 }
00111 }
00112
00113
00114 p_was_read = true;
00115
00116 }
00117
00118 public String get_state() {
00119 if(p_was_read == false) {init();}
00120 return m_state;
00121 }
00122
00123 public void set_state(String value) {
00124 p_obj.clean();
00125 p_obj.set_string("state", value);
00126 }
00127
00128 public Param[] get_param() {
00129 if(p_was_read == false) {init();}
00130 return m_param;
00131 }
00132
00133 public void set_param(Param[] value) {
00134 p_obj.clean();
00135 config.ConfigObject[] objs = new config.ConfigObject[value.length];
00136 for(int i = 0; i < value.length; i++) {
00137 objs[i] = value[i].config_object();
00138 }
00139 p_obj.set_objects("param", objs);
00140 }
00141
00142 public config.ConfigObject config_object() {
00143 return p_obj;
00144 }
00145
00146 public void print(String dx) {
00147 System.out.println(dx + "PowerDefaults object:" );
00148 System.out.println(dx + " id: \'" + UID() + "\', class name: \'" + class_name() + "\'");
00149
00150
00151
00152
00153 System.out.println(dx + " state: " + get_state());
00154
00155
00156
00157
00158 if(get_param().length > 0) {
00159 System.out.print(dx + " " + get_param().length + " object(s) in param :\n");
00160
00161 for(int i = 0; i < get_param().length; i++) {
00162 get_param()[i].print(dx.concat(" "));
00163 }
00164 }
00165 else {
00166 System.out.println(dx + " param value is empty");
00167 }
00168
00169 }
00170
00176 public void destroy(config.Configuration db) {
00177 db.destroy(config_object());
00178 }
00179 }