001 package org.maltparser.core.flow.spec;
002
003 import java.util.HashMap;
004
005 import org.maltparser.core.exception.MaltChainedException;
006 import org.maltparser.core.flow.FlowChartManager;
007 import org.maltparser.core.flow.item.ChartItem;
008 import org.w3c.dom.Attr;
009 import org.w3c.dom.Element;
010 import org.w3c.dom.NamedNodeMap;
011 /**
012 *
013 *
014 * @author Johan Hall
015 */
016 public class ChartItemSpecification {
017 private String chartItemName;
018 private Class<? extends ChartItem> chartItemClass;
019 private HashMap<String,String> attributes;
020
021 public ChartItemSpecification() {
022 this(null,null);
023 }
024
025 public ChartItemSpecification(String chartItemName, Class<? extends ChartItem> chartItemClass) {
026 setChartItemName(chartItemName);
027 setChartItemClass(chartItemClass);
028 attributes = new HashMap<String,String>(3);
029 }
030
031 public String getChartItemName() {
032 return chartItemName;
033 }
034
035 public void setChartItemName(String chartItemName) {
036 this.chartItemName = chartItemName;
037 }
038
039 public Class<? extends ChartItem> getChartItemClass() {
040 return chartItemClass;
041 }
042
043 public void setChartItemClass(Class<? extends ChartItem> chartItemClass) {
044 this.chartItemClass = chartItemClass;
045 }
046
047 public HashMap<String, String> getChartItemAttributes() {
048 return attributes;
049 }
050
051 public String getChartItemAttribute(String key) {
052 return attributes.get(key);
053 }
054
055 public void addChartItemAttribute(String key, String value) {
056 attributes.put(key, value);
057 }
058
059 public void removeChartItemAttribute(String key) {
060 attributes.remove(key);
061 }
062
063 public void read(Element chartItemSpec, FlowChartManager flowCharts) throws MaltChainedException {
064 chartItemName = chartItemSpec.getAttribute("item");
065 chartItemClass = flowCharts.getFlowChartSystem().getChartElement(chartItemName).getChartItemClass();
066
067 NamedNodeMap attrs = chartItemSpec.getAttributes();
068 for(int i = 0 ; i < attrs.getLength() ; i++) {
069 Attr attribute = (Attr)attrs.item(i);
070 addChartItemAttribute(attribute.getName(),attribute.getValue());
071 }
072 }
073
074 public int hashCode() {
075 final int prime = 31;
076 int result = 1;
077 result = prime * result + ((chartItemName == null) ? 0 : chartItemName.hashCode());
078 result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
079 result = prime * result + ((chartItemClass == null) ? 0 : chartItemClass.hashCode());
080 return result;
081 }
082
083 public boolean equals(Object obj) {
084 if (this == obj)
085 return true;
086 if (obj == null)
087 return false;
088 if (getClass() != obj.getClass())
089 return false;
090 ChartItemSpecification other = (ChartItemSpecification) obj;
091 if (chartItemName == null) {
092 if (other.chartItemName != null)
093 return false;
094 } else if (!chartItemName.equals(other.chartItemName))
095 return false;
096
097 if (attributes == null) {
098 if (other.attributes != null)
099 return false;
100 } else if (!attributes.equals(other.attributes))
101 return false;
102
103 if (chartItemClass == null) {
104 if (other.chartItemClass != null)
105 return false;
106 } else if (!chartItemClass.equals(other.chartItemClass))
107 return false;
108
109 return true;
110 }
111
112 public String toString() {
113 StringBuilder sb = new StringBuilder();
114 sb.append(chartItemName);sb.append(' ');
115 for (String key : attributes.keySet()) {
116 sb.append(key);sb.append('=');sb.append(attributes.get(key));sb.append(' ');
117 }
118 return sb.toString();
119 }
120
121 }