| 1 | |
package org.kuali.rice.krms.api.repository.rule; |
| 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.CoreConstants; |
| 18 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 19 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
| 20 | |
import org.kuali.rice.krms.api.repository.BaseAttribute; |
| 21 | |
import org.kuali.rice.krms.api.repository.BaseAttribute.Builder; |
| 22 | |
import org.kuali.rice.krms.api.repository.BaseAttribute.Elements; |
| 23 | |
import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
@XmlRootElement(name = RuleAttribute.Constants.ROOT_ELEMENT_NAME) |
| 32 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 33 | |
@XmlType(name = RuleAttribute.Constants.TYPE_NAME, propOrder = { |
| 34 | |
RuleAttribute.Elements.ID, |
| 35 | |
RuleAttribute.Elements.RULE_ID, |
| 36 | |
RuleAttribute.Elements.ATTR_DEFN_ID, |
| 37 | |
RuleAttribute.Elements.VALUE, |
| 38 | |
RuleAttribute.Elements.ATTR_DEFN, |
| 39 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 40 | |
}) |
| 41 | 0 | public final class RuleAttribute extends BaseAttribute implements RuleAttributeContract, ModelObjectComplete{ |
| 42 | |
private static final long serialVersionUID = 2988399046412505534L; |
| 43 | |
|
| 44 | |
@XmlElement(name = Elements.RULE_ID, required=true) |
| 45 | |
private String ruleId; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
private RuleAttribute() { |
| 51 | 0 | super(); |
| 52 | 0 | this.ruleId = null; |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
private RuleAttribute(Builder builder) { |
| 62 | 0 | super(builder); |
| 63 | 0 | this.ruleId = builder.getRuleId(); |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
@Override |
| 67 | |
public String getRuleId() { |
| 68 | 0 | return this.ruleId; |
| 69 | |
} |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | 0 | public static class Builder extends BaseAttribute.Builder implements RuleAttributeContract, ModelBuilder, Serializable { |
| 75 | |
private static final long serialVersionUID = -8619106871420999876L; |
| 76 | |
|
| 77 | |
private String ruleId; |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
private Builder(String id, String ruleId, String attributeDefinitionId, String value) { |
| 83 | 0 | super(id, attributeDefinitionId, value); |
| 84 | 0 | setRuleId(ruleId); |
| 85 | 0 | } |
| 86 | |
|
| 87 | |
public Builder attributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition){ |
| 88 | 0 | setAttributeDefinition(attributeDefinition); |
| 89 | 0 | return this; |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public static Builder create(String id, String ruleId, String attributeDefinitionId, String value) { |
| 103 | 0 | return new Builder(id, ruleId, attributeDefinitionId, value); |
| 104 | |
} |
| 105 | |
|
| 106 | |
public static Builder create(RuleAttributeContract contract){ |
| 107 | 0 | if (contract == null) { |
| 108 | 0 | throw new IllegalArgumentException("contract is null"); |
| 109 | |
} |
| 110 | 0 | Builder builder = new Builder(contract.getId(), |
| 111 | |
contract.getRuleId(), |
| 112 | |
contract.getAttributeDefinitionId(), |
| 113 | |
contract.getValue()) |
| 114 | |
.attributeDefinition(KrmsAttributeDefinition.Builder |
| 115 | |
.create(contract.getAttributeDefinition())); |
| 116 | 0 | return builder; |
| 117 | |
} |
| 118 | |
|
| 119 | |
public void setRuleId(String ruleId) { |
| 120 | 0 | if (StringUtils.isBlank(ruleId)) { |
| 121 | 0 | throw new IllegalArgumentException("ruleId is blank"); |
| 122 | |
} |
| 123 | 0 | this.ruleId = ruleId; |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
@Override |
| 127 | |
public String getRuleId() { |
| 128 | 0 | return ruleId; |
| 129 | |
} |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public RuleAttribute build() { |
| 138 | 0 | return new RuleAttribute(this); |
| 139 | |
} |
| 140 | |
|
| 141 | |
} |
| 142 | |
@Override |
| 143 | |
public int hashCode() { |
| 144 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 145 | |
} |
| 146 | |
|
| 147 | |
@Override |
| 148 | |
public boolean equals(Object obj) { |
| 149 | 0 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 150 | |
} |
| 151 | |
|
| 152 | |
@Override |
| 153 | |
public String toString() { |
| 154 | 0 | return ToStringBuilder.reflectionToString(this); |
| 155 | |
} |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | 0 | static class Constants { |
| 161 | |
final static String ROOT_ELEMENT_NAME = "RuleAttribute"; |
| 162 | |
final static String TYPE_NAME = "RuleAttributeType"; |
| 163 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
| 164 | |
} |
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | 0 | public static class Elements extends BaseAttribute.Elements { |
| 171 | |
final static String RULE_ID = "ruleId"; |
| 172 | |
} |
| 173 | |
} |