public String getAttribute(String attrib) { if (reqAttribs.containsKey(attrib)) { return reqAttribs.get(attrib); } else if (optAttribs.containsKey(attrib)) { return optAttribs.get(attrib); } return null; }
public boolean setAttribute(String name, String value) { if (reqAttribs.containsKey(name)) { reqAttribs.put(name, value); return true; } else if (optAttribs.containsKey(name)) { optAttribs.put(name, value); return true; } return false; }
public String generateXMLString() { String s = ""; s += "<!--" + this.comments + "-->\n"; s += "<" + this.getName() + " "; Set<String> keys = reqAttribs.keySet(); for (String k : keys) { String value = reqAttribs.get(k); if (value != null && !value.isEmpty()) s += k + "=\"" + value + "\" "; } boolean hasElements = this.elements != null && !this.elements.isEmpty(); if (hasElements) { s += ">\n"; s += this.elements; s += "\n</" + this.getName() + ">\n"; } else s += "/>\n"; return s; }
public Operator(OperatorTemplate opTemplate) { HashMap<String, Attribute> templateAttributes = opTemplate.getAttributes(); reqAttribs = new HashMap<String, String>(); optAttribs = new HashMap<String, String>(); name = opTemplate.getName(); // Sort out the required and optional attributes Iterator<Map.Entry<String, Attribute>> it = templateAttributes.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Attribute> entry = it.next(); // Sort out the attributes into required and optionals if (entry.getValue().required == Attribute.REQUIRED_REQUIRED) { reqAttribs.put(entry.getKey(), null); } else if (entry.getValue().required == Attribute.REQUIRED_OPTIONAL) { optAttribs.put(entry.getKey(), null); } } }
public HashMap<String, String> getAttributes() { HashMap<String, String> allAttribs = new HashMap<String, String>(); allAttribs.putAll(reqAttribs); allAttribs.putAll(optAttribs); return allAttribs; }