00001
00065 package com.arcle.rmt.j2se.model.domimpl.rqml;
00066
00067 import java.util.Map;
00068 import java.util.Hashtable;
00069 import org.w3c.dom.Element;
00070 import com.arcle.rmt.rqml.*;
00071 import com.arcle.rmt.j2se.model.domimpl.*;
00072
00078 public class RQMLFirstClassImpl extends RQMLSecondClassImpl
00079 implements RQMLFirstClass {
00080
00087 public RQMLFirstClassImpl(Element elem, RQMLSecondClassFactory fac) {
00088 super(elem, fac);
00089 }
00090
00091 public Name getName() {
00092 RQMLSecondClass child = getFirstChild("name");
00093 return (Name) child;
00094 }
00095
00096 public int getPriority() {
00097 return getThreeLevelAttribute("priority");
00098 }
00099
00100 public int getDifficulty() {
00101 return getThreeLevelAttribute("difficulty");
00102 }
00103
00104
00105 public synchronized int getStatus() {
00106 Integer statusValue = (Integer) statusIndexes.get(getAttribute("status"));
00107 if (statusValue == null) {
00108 return STATUS_PROPOSED;
00109 }
00110 return statusValue.intValue();
00111 }
00112
00113
00114 public int getStability() {
00115 return getThreeLevelAttribute("stability");
00116 }
00117
00118
00119 public String getVersion() {
00120 return getAttribute("version");
00121 }
00122
00123
00124 public Description getDescription() {
00125 return (Description) getFirstChild("description");
00126 }
00127
00128
00129 public Rationale getRationale() {
00130 return (Rationale) getFirstChild("rationale");
00131 }
00132
00133 public void setName(Name NAME) {
00134 throw new UnsupportedOperationException("Not implemented yet");
00135 }
00136
00137 public void setDescription(Description DESC) {
00138 throw new UnsupportedOperationException("Not implemented yet");
00139 }
00140
00141 public void setRationale(Rationale RATIONALE) {
00142 throw new UnsupportedOperationException("Not implemented yet");
00143 }
00144
00145
00146 public void setPriority(int p) {
00147 if (PRIORITY_LOW <= p && p <= PRIORITY_HIGH) {
00148 setThreeLevelAttribute("priority", p);
00149 }
00150 }
00151
00152
00153 public void setDifficulty(int d) {
00154 if (DIFFICULTY_LOW <= d && d <= DIFFICULTY_HIGH) {
00155 setThreeLevelAttribute("difficulty", d);
00156 }
00157 }
00158
00159 public synchronized void setStatus(int STATUS) {
00160 String statusValue = (String) statusStrings.get(new Integer(STATUS));
00161 if (statusValue == null) {
00162 throw new IllegalArgumentException("Illegal status attribute value: " + STATUS);
00163 }
00164
00165 setAttribute("status", statusValue);
00166 }
00167
00168
00169 public void setVersion(String VERSION) {
00170 setAttribute("version", VERSION);
00171 }
00172
00173
00174 public void setStability(int s) {
00175 if (STABILITY_LOW <= s && s <= STABILITY_HIGH) {
00176 setThreeLevelAttribute("stability", s);
00177 }
00178 }
00179
00180 protected int getIntAttribute(String name) {
00181 try {
00182 return Integer.parseInt(getAttribute(name));
00183 } catch(NumberFormatException e) {
00184 return 0;
00185 }
00186 }
00187
00196 private synchronized int getThreeLevelAttribute(String name) {
00197 String value = getAttribute(name);
00198 if (value.length() == 0) {
00199 return 0;
00200 }
00201 Integer iVal = (Integer) threeLevelIndexes.get(value);
00202 if (iVal == null) {
00203 throw new IllegalArgumentException("Illegal attribute value of: "
00204 + name);
00205 }
00206 return iVal.intValue();
00207 }
00208
00217 private synchronized void setThreeLevelAttribute(String name, int value) {
00218 String str = (String) threeLevelStrings.get(new Integer(value));
00219 if (str == null) {
00220 throw new IllegalArgumentException("Illegal index: " + value
00221 + " for attribute: " + name);
00222 }
00223 setAttribute(name, str);
00224 }
00225
00229 private static final Map threeLevelIndexes;
00230
00234 private static final Map threeLevelStrings;
00235
00236 private static final Map statusIndexes;
00237
00238 private static final Map statusStrings;
00239
00243 static {
00244
00245 threeLevelIndexes = new Hashtable(3, 1);
00246 threeLevelStrings = new Hashtable(3, 1);
00247 statusIndexes = new Hashtable(4, 1);
00248 statusStrings = new Hashtable(4, 1);
00249
00250 Integer low = new Integer(PRIORITY_LOW);
00251 Integer normal = new Integer(PRIORITY_NORMAL);
00252 Integer high = new Integer(PRIORITY_HIGH);
00253
00254 threeLevelStrings.put(low, "low");
00255 threeLevelStrings.put(normal, "normal");
00256 threeLevelStrings.put(high, "high");
00257
00258 threeLevelIndexes.put("low", low);
00259 threeLevelIndexes.put("normal", normal);
00260 threeLevelIndexes.put("high", high);
00261
00262 Integer proposed = new Integer(STATUS_PROPOSED);
00263 Integer approved = new Integer(STATUS_APPROVED);
00264 Integer incorporated = new Integer(STATUS_INCORPORATED);
00265 Integer validated = new Integer(STATUS_VALIDATED);
00266
00267 statusStrings.put(proposed, "proposed");
00268 statusStrings.put(approved, "approved");
00269 statusStrings.put(incorporated, "incorporated");
00270 statusStrings.put(validated, "validated");
00271
00272 statusIndexes.put("proposed", proposed);
00273 statusIndexes.put("approved", approved);
00274 statusIndexes.put("incorporated", incorporated);
00275 statusIndexes.put("validated", validated);
00276 }
00277 }