| 1 | |
package org.kuali.rice.krms.api.repository; |
| 2 | |
|
| 3 | |
import java.io.Serializable; |
| 4 | |
import java.util.Collection; |
| 5 | |
|
| 6 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 7 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 8 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 9 | |
import javax.xml.bind.annotation.XmlElement; |
| 10 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 11 | |
import javax.xml.bind.annotation.XmlType; |
| 12 | |
|
| 13 | |
import org.apache.commons.lang.StringUtils; |
| 14 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 15 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 16 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 17 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 18 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | 0 | @XmlRootElement(name = RuleAttribute.Constants.ROOT_ELEMENT_NAME, namespace = RuleAttribute.Constants.KRMSNAMESPACE) |
| 27 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 28 | |
@XmlType(name = RuleAttribute.Constants.TYPE_NAME, propOrder = { |
| 29 | |
RuleAttribute.Elements.ID, |
| 30 | |
RuleAttribute.Elements.RULE_ID, |
| 31 | |
RuleAttribute.Elements.ATTR_DEFN_ID, |
| 32 | |
RuleAttribute.Elements.VALUE, |
| 33 | |
RuleAttribute.Elements.ATTR_DEFN, |
| 34 | |
"_elements" |
| 35 | |
}) |
| 36 | 0 | public final class RuleAttribute implements RuleAttributeContract, ModelObjectComplete{ |
| 37 | |
private static final long serialVersionUID = 2988399046412505534L; |
| 38 | |
|
| 39 | |
@XmlElement(name = Elements.ID, required=true, namespace = RuleAttribute.Constants.KRMSNAMESPACE) |
| 40 | |
private String id; |
| 41 | |
@XmlElement(name = Elements.RULE_ID, required=true, namespace = RuleAttribute.Constants.KRMSNAMESPACE) |
| 42 | |
private String ruleId; |
| 43 | |
@XmlElement(name = Elements.ATTR_DEFN_ID, required=true, namespace = RuleAttribute.Constants.KRMSNAMESPACE) |
| 44 | |
private String attributeDefinitionId; |
| 45 | |
@XmlElement(name = Elements.VALUE, required=true, namespace = RuleAttribute.Constants.KRMSNAMESPACE) |
| 46 | |
private String value; |
| 47 | |
@XmlElement(name = Elements.ATTR_DEFN, required=false, namespace = RuleAttribute.Constants.KRMSNAMESPACE) |
| 48 | |
private KrmsAttributeDefinition attributeDefinition; |
| 49 | |
|
| 50 | 0 | @SuppressWarnings("unused") |
| 51 | |
@XmlAnyElement |
| 52 | |
private final Collection<org.w3c.dom.Element> _elements = null; |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | 0 | private RuleAttribute() { |
| 58 | 0 | this.id = null; |
| 59 | 0 | this.ruleId = null; |
| 60 | 0 | this.attributeDefinitionId = null; |
| 61 | 0 | this.value = null; |
| 62 | 0 | this.attributeDefinition = null; |
| 63 | 0 | } |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | 0 | private RuleAttribute(Builder builder) { |
| 72 | 0 | this.id = builder.getId(); |
| 73 | 0 | this.ruleId = builder.getRuleId(); |
| 74 | 0 | this.attributeDefinitionId = builder.getAttributeDefinitionId(); |
| 75 | 0 | this.value = builder.getValue(); |
| 76 | 0 | this.attributeDefinition = builder.getAttributeDefinition().build(); |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
@Override |
| 80 | |
public String getId() { |
| 81 | 0 | return this.id; |
| 82 | |
} |
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public String getRuleId() { |
| 86 | 0 | return this.ruleId; |
| 87 | |
} |
| 88 | |
|
| 89 | |
@Override |
| 90 | |
public String getAttributeDefinitionId() { |
| 91 | 0 | return this.attributeDefinitionId; |
| 92 | |
} |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
public String getValue() { |
| 96 | 0 | return this.value; |
| 97 | |
} |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public KrmsAttributeDefinition getAttributeDefinition() { |
| 101 | 0 | return this.attributeDefinition; |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | 0 | public static class Builder implements RuleAttributeContract, ModelBuilder, Serializable { |
| 108 | |
private static final long serialVersionUID = -8619106871420999876L; |
| 109 | |
|
| 110 | |
private String id; |
| 111 | |
private String ruleId; |
| 112 | |
private String attributeDefinitionId; |
| 113 | |
private String value; |
| 114 | |
private KrmsAttributeDefinition.Builder attributeDefinition; |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | 0 | private Builder(String id, String ruleId, String attributeDefinitionId, String value) { |
| 120 | 0 | setId(id); |
| 121 | 0 | setRuleId(ruleId); |
| 122 | 0 | setAttributeDefinitionId(attributeDefinitionId); |
| 123 | 0 | setValue(value); |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
public Builder attributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition){ |
| 127 | 0 | setAttributeDefinition(attributeDefinition); |
| 128 | 0 | return this; |
| 129 | |
} |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
public static Builder create(String id, String ruleId, String attributeDefinitionId, String value) { |
| 142 | 0 | return new Builder(id, ruleId, attributeDefinitionId, value); |
| 143 | |
} |
| 144 | |
|
| 145 | |
public static Builder create(RuleAttributeContract contract){ |
| 146 | 0 | if (contract == null) { |
| 147 | 0 | throw new IllegalArgumentException("contract is null"); |
| 148 | |
} |
| 149 | 0 | Builder builder = new Builder(contract.getId(), |
| 150 | |
contract.getRuleId(), |
| 151 | |
contract.getAttributeDefinitionId(), |
| 152 | |
contract.getValue()) |
| 153 | |
.attributeDefinition(KrmsAttributeDefinition.Builder |
| 154 | |
.create(contract.getAttributeDefinition())); |
| 155 | 0 | return builder; |
| 156 | |
} |
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
public void setId(String id) { |
| 165 | 0 | if (StringUtils.isBlank(id)) { |
| 166 | 0 | throw new IllegalArgumentException("id is blank"); |
| 167 | |
} |
| 168 | 0 | this.id = id; |
| 169 | 0 | } |
| 170 | |
|
| 171 | |
public void setRuleId(String ruleId) { |
| 172 | 0 | if (StringUtils.isBlank(ruleId)) { |
| 173 | 0 | throw new IllegalArgumentException("ruleId is blank"); |
| 174 | |
} |
| 175 | 0 | this.ruleId = ruleId; |
| 176 | 0 | } |
| 177 | |
|
| 178 | |
public void setAttributeDefinitionId(String attributeDefinitionId) { |
| 179 | 0 | if (StringUtils.isBlank(attributeDefinitionId)) { |
| 180 | 0 | throw new IllegalArgumentException("the attribute definition id is blank"); |
| 181 | |
} |
| 182 | 0 | this.attributeDefinitionId = attributeDefinitionId; |
| 183 | 0 | } |
| 184 | |
|
| 185 | |
public void setValue(String value) { |
| 186 | 0 | this.value = value; |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
public void setAttributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition) { |
| 190 | 0 | this.attributeDefinition = attributeDefinition; |
| 191 | |
|
| 192 | 0 | } |
| 193 | |
|
| 194 | |
@Override |
| 195 | |
public String getId() { |
| 196 | 0 | return id; |
| 197 | |
} |
| 198 | |
|
| 199 | |
@Override |
| 200 | |
public String getRuleId() { |
| 201 | 0 | return ruleId; |
| 202 | |
} |
| 203 | |
|
| 204 | |
@Override |
| 205 | |
public String getAttributeDefinitionId() { |
| 206 | 0 | return attributeDefinitionId; |
| 207 | |
} |
| 208 | |
|
| 209 | |
@Override |
| 210 | |
public String getValue() { |
| 211 | 0 | return value; |
| 212 | |
} |
| 213 | |
|
| 214 | |
@Override |
| 215 | |
public KrmsAttributeDefinition.Builder getAttributeDefinition() { |
| 216 | 0 | return attributeDefinition; |
| 217 | |
} |
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
@Override |
| 225 | |
public RuleAttribute build() { |
| 226 | 0 | return new RuleAttribute(this); |
| 227 | |
} |
| 228 | |
|
| 229 | |
} |
| 230 | |
@Override |
| 231 | |
public int hashCode() { |
| 232 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 233 | |
} |
| 234 | |
|
| 235 | |
@Override |
| 236 | |
public boolean equals(Object obj) { |
| 237 | 0 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 238 | |
} |
| 239 | |
|
| 240 | |
@Override |
| 241 | |
public String toString() { |
| 242 | 0 | return ToStringBuilder.reflectionToString(this); |
| 243 | |
} |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | 0 | static class Constants { |
| 249 | |
final static String KRMSNAMESPACE = "http://rice.kuali.org/schema/krms"; |
| 250 | |
final static String ROOT_ELEMENT_NAME = "RuleAttribute"; |
| 251 | |
final static String TYPE_NAME = "RuleAttributeType"; |
| 252 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { "_elements" }; |
| 253 | |
} |
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | 0 | public static class Elements { |
| 260 | |
final static String ID = "id"; |
| 261 | |
final static String RULE_ID = "ruleId"; |
| 262 | |
final static String ATTR_DEFN_ID = "attributeDefinitionId"; |
| 263 | |
final static String VALUE = "value"; |
| 264 | |
final static String ATTR_DEFN = "attributeDefinition"; |
| 265 | |
} |
| 266 | |
} |