summaryrefslogtreecommitdiffstats
path: root/src/com/ibm/ServerWizard2/model/Attribute.java
blob: b0eaecb64e2eaa5c30e1dc4827f8a8b0dfabfd9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.ibm.ServerWizard2.model;

import java.io.Writer;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Attribute implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	public String show = "";
	public String name = "";
	public String group = "";
	public AttributeValue value;

	public String inherited = "";
	public String desc = "";
	public String compareStr = "";
	public Boolean readable = false;
	public Boolean writeable = false;
	public Boolean readonly = false;
	public Persistency persistency = Persistency.NO_PERSISTENCY;
	public Boolean hide = false;
	private Boolean bitmask = false;
	private Boolean global = false;
	
	public enum Persistency {
		NO_PERSISTENCY, VOLATILE_ZEROED, NON_VOLATILE, VOLATILE
	};

	public Attribute() {
	}

	public Attribute(Attribute a) {
		this.name = a.name;
		this.show = a.show;
		this.desc = a.desc;
		this.group = a.group;
		this.persistency = a.persistency;
		this.readable = a.readable;
		this.writeable = a.writeable;
		this.inherited = a.inherited;
		this.hide = a.hide;
		this.bitmask = a.bitmask;
		this.global = a.global;
		
		if (a.value instanceof AttributeValueComplex) {
			this.value = new AttributeValueComplex((AttributeValueComplex)a.value);
		}
		else if(a.value instanceof AttributeValueSimple) {
			this.value = new AttributeValueSimple((AttributeValueSimple)a.value);
		}
		else if(a.value instanceof AttributeValueNative) {
			this.value = new AttributeValueNative((AttributeValueNative)a.value);
		}
		else {
			
		}
		
	}

	public AttributeValue getValue() {
		return value;
	}
	public boolean isReadable() {
		return readable;
	}
	public boolean isWriteable() {
		return writeable;
	}
	public boolean isHidden() {
		return hide;
	}

	public boolean isGlobal() {
		return this.global;
	}
	
	public String toString() {
		String rtn="Attribute: "+name+" = ";
		rtn="Attribute: "+name+" = "+value.toString()+" inherited="+this.inherited;
		return rtn;
	}

	public void setPersistence(String p) {
		if (p.equals("non-volatile")) {
			persistency = Persistency.NON_VOLATILE;
		} else if (p.equals("volatile-zeroed")) {
			persistency = Persistency.VOLATILE_ZEROED;
		} else if (p.equals("volatile")) {
			persistency = Persistency.VOLATILE;
		} else {
			throw new NullPointerException("Invalid Peristence: "+p);
		}
	}
	public String getPersistence() {
		if (persistency == Persistency.NON_VOLATILE) {
			return "non-volatile";
		} else if(persistency == Persistency.VOLATILE_ZEROED) {
			return "volatile-zeroed";
		} else if(persistency == Persistency.NO_PERSISTENCY) {
			return "";
		} else if(persistency == Persistency.VOLATILE) {
			return "volatile";
		} else { return ""; }
		
	}
	public void readModelXML(Element attribute) {
		name = SystemModel.getElement(attribute, "id");
		desc = SystemModel.getElement(attribute,"description");
		group = SystemModel.getElement(attribute,"group");
		
		String p = SystemModel.getElement(attribute,"persistency");
		if (!p.isEmpty()) { setPersistence(p); }
		
		if (SystemModel.isElementDefined(attribute,"bitmask")) {
			bitmask=true;
		}
		if (SystemModel.isElementDefined(attribute,"global")) {
			global=true;
		}

		if (SystemModel.isElementDefined(attribute,"readable")) {
			readable=true;
		}
		if (SystemModel.isElementDefined(attribute,"writeable")) {
			writeable=true;
		}
		if (name.equals("MODEL") || name.equals("TYPE") || name.equals("CLASS")) {
			hide=true;
		}
		if (SystemModel.isElementDefined(attribute,"serverwizShow")) {
			show = SystemModel.getElement(attribute, "serverwizShow");
		}
		Node simpleType = attribute.getElementsByTagName("simpleType").item(0);
		if (simpleType!=null) { 
			value = new AttributeValueSimple(this);
			value.readonly =  readonly;
			value.readXML((Element)simpleType);
		}
		Node complexType = attribute.getElementsByTagName("complexType").item(0);
		if (complexType!=null) {
			value = new AttributeValueComplex(this);
			value.readonly =  readonly;
			value.readXML((Element)complexType);
		}
		Node nativeType = attribute.getElementsByTagName("nativeType").item(0);
		if (nativeType!=null) {
			value = new AttributeValueNative(this);
			value.readonly =  readonly;
			value.readXML((Element)nativeType);
		}
	}
	public void writeBusInstanceXML(Writer out) throws Exception {
		out.write("\t\t<bus_attribute>\n");
		out.write("\t\t\t<id>"+name+"</id>\n");
		value.writeInstanceXML(out);
		out.write("\t\t</bus_attribute>\n");
	}
	public void writeInstanceXML(Writer out) throws Exception {
		out.write("\t<attribute>\n");
		out.write("\t\t<id>"+name+"</id>\n");
		value.writeInstanceXML(out);
		out.write("\t</attribute>\n");
	}

	public String compare(Object o) {
		Attribute a = (Attribute) o;
		return value.compare(a.getValue());
	}	
}
OpenPOWER on IntegriCloud