| 1 | |
package org.kuali.rice.krms.api.repository; |
| 2 | |
|
| 3 | |
import java.io.Serializable; |
| 4 | |
import java.util.ArrayList; |
| 5 | |
import java.util.Arrays; |
| 6 | |
import java.util.Collection; |
| 7 | |
import java.util.Collections; |
| 8 | |
import java.util.List; |
| 9 | |
|
| 10 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 11 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 12 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 13 | |
import javax.xml.bind.annotation.XmlElement; |
| 14 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 15 | |
import javax.xml.bind.annotation.XmlType; |
| 16 | |
|
| 17 | |
import org.apache.commons.lang.StringUtils; |
| 18 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 19 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 20 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 21 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 22 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
@XmlRootElement(name = Action.Constants.ROOT_ELEMENT_NAME, namespace = Action.Constants.KRMSNAMESPACE) |
| 32 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 33 | |
@XmlType(name = Action.Constants.TYPE_NAME, propOrder = { |
| 34 | |
Action.Elements.ID, |
| 35 | |
Action.Elements.NAME, |
| 36 | |
Action.Elements.NAMESPACE, |
| 37 | |
Action.Elements.DESC, |
| 38 | |
Action.Elements.TYPE_ID, |
| 39 | |
Action.Elements.ATTRIBUTES, |
| 40 | |
"_elements" |
| 41 | |
}) |
| 42 | 0 | public final class Action implements ActionContract, ModelObjectComplete{ |
| 43 | |
private static final long serialVersionUID = 2783959459503209577L; |
| 44 | |
|
| 45 | |
@XmlElement(name = Elements.ID, required=true, namespace = Action.Constants.KRMSNAMESPACE) |
| 46 | |
private String actionId; |
| 47 | |
@XmlElement(name = Elements.NAME, required=true, namespace = Action.Constants.KRMSNAMESPACE) |
| 48 | |
private String name; |
| 49 | |
@XmlElement(name = Elements.NAMESPACE, required=true, namespace = Action.Constants.KRMSNAMESPACE) |
| 50 | |
private String namespace; |
| 51 | |
@XmlElement(name = Elements.DESC, required=true, namespace = Action.Constants.KRMSNAMESPACE) |
| 52 | |
private String description; |
| 53 | |
@XmlElement(name = Elements.TYPE_ID, required=true, namespace = Action.Constants.KRMSNAMESPACE) |
| 54 | |
private String typeId; |
| 55 | |
@XmlElement(name = Elements.ATTRIBUTES, required=false, namespace = Action.Constants.KRMSNAMESPACE) |
| 56 | |
private List<ActionAttribute> attributes; |
| 57 | |
|
| 58 | 0 | @SuppressWarnings("unused") |
| 59 | |
@XmlAnyElement |
| 60 | |
private final Collection<org.w3c.dom.Element> _elements = null; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | 0 | private Action() { |
| 68 | 0 | this.actionId = null; |
| 69 | 0 | this.name = null; |
| 70 | 0 | this.namespace = null; |
| 71 | 0 | this.description = null; |
| 72 | 0 | this.typeId = null; |
| 73 | 0 | this.attributes = null; |
| 74 | 0 | } |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | 0 | private Action(Builder builder) { |
| 83 | 0 | this.actionId = builder.getActionId(); |
| 84 | 0 | this.name = builder.getName(); |
| 85 | 0 | this.namespace = builder.getNamespace(); |
| 86 | 0 | this.description = builder.getDescription(); |
| 87 | 0 | this.typeId = builder.getTypeId(); |
| 88 | 0 | List<ActionAttribute> attrList = new ArrayList<ActionAttribute>(); |
| 89 | 0 | for (ActionAttribute.Builder b : builder.attributes){ |
| 90 | 0 | attrList.add(b.build()); |
| 91 | |
} |
| 92 | 0 | this.attributes = Collections.unmodifiableList(attrList); |
| 93 | 0 | } |
| 94 | |
|
| 95 | |
@Override |
| 96 | |
public String getActionId() { |
| 97 | 0 | return this.actionId; |
| 98 | |
} |
| 99 | |
|
| 100 | |
@Override |
| 101 | |
public String getName() { |
| 102 | 0 | return this.name; |
| 103 | |
} |
| 104 | |
|
| 105 | |
@Override |
| 106 | |
public String getNamespace() { |
| 107 | 0 | return this.namespace; |
| 108 | |
} |
| 109 | |
|
| 110 | |
@Override |
| 111 | |
public String getDescription() { |
| 112 | 0 | return this.description; |
| 113 | |
} |
| 114 | |
|
| 115 | |
@Override |
| 116 | |
public String getTypeId() { |
| 117 | 0 | return this.typeId; |
| 118 | |
} |
| 119 | |
|
| 120 | |
@Override |
| 121 | |
public List<ActionAttribute> getAttributes() { |
| 122 | 0 | return this.attributes; |
| 123 | |
} |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | 0 | public static class Builder implements ActionContract, ModelBuilder, Serializable { |
| 129 | |
|
| 130 | |
private String actionId; |
| 131 | |
private String name; |
| 132 | |
private String namespace; |
| 133 | |
private String description; |
| 134 | |
private String typeId; |
| 135 | |
private List<ActionAttribute.Builder> attributes; |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | 0 | private Builder(String actionId, String name, String namespace, String typeId) { |
| 141 | 0 | setActionId(actionId); |
| 142 | 0 | setName(name); |
| 143 | 0 | setNamespace(namespace); |
| 144 | 0 | setTypeId(typeId); |
| 145 | 0 | } |
| 146 | |
|
| 147 | |
public Builder description (String description){ |
| 148 | 0 | setDescription(description); |
| 149 | 0 | return this; |
| 150 | |
} |
| 151 | |
public Builder attributes (List<ActionAttribute.Builder> attributes){ |
| 152 | 0 | setAttributes(attributes); |
| 153 | 0 | return this; |
| 154 | |
} |
| 155 | |
|
| 156 | |
public static Builder create(String actionId, String name, String namespace, String typeId){ |
| 157 | 0 | return new Builder(actionId, name, namespace, typeId); |
| 158 | |
} |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
public static Builder create(ActionContract contract) { |
| 166 | 0 | if (contract == null) { |
| 167 | 0 | throw new IllegalArgumentException("contract is null"); |
| 168 | |
} |
| 169 | 0 | List <ActionAttribute.Builder> attrBuilderList = new ArrayList<ActionAttribute.Builder>(); |
| 170 | 0 | if (contract.getAttributes() != null){ |
| 171 | 0 | for (ActionAttributeContract attrContract : contract.getAttributes()){ |
| 172 | 0 | ActionAttribute.Builder myBuilder = ActionAttribute.Builder.create(attrContract); |
| 173 | 0 | attrBuilderList.add(myBuilder); |
| 174 | 0 | } |
| 175 | |
} |
| 176 | 0 | Builder builder = new Builder(contract.getActionId(), contract.getName(), |
| 177 | |
contract.getNamespace(), contract.getTypeId()) |
| 178 | |
.description(contract.getDescription()) |
| 179 | |
.attributes(attrBuilderList); |
| 180 | 0 | return builder; |
| 181 | |
} |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
public void setActionId(String actionId) { |
| 191 | 0 | if (StringUtils.isBlank(actionId)) { |
| 192 | 0 | throw new IllegalArgumentException("actionId is blank"); |
| 193 | |
} |
| 194 | 0 | this.actionId = actionId; |
| 195 | 0 | } |
| 196 | |
|
| 197 | |
|
| 198 | |
public void setName(String name) { |
| 199 | 0 | if (StringUtils.isBlank(name)) { |
| 200 | 0 | throw new IllegalArgumentException("name is blank"); |
| 201 | |
} |
| 202 | 0 | this.name = name; |
| 203 | 0 | } |
| 204 | |
|
| 205 | |
|
| 206 | |
public void setNamespace(String namespace) { |
| 207 | 0 | if (StringUtils.isBlank(namespace)) { |
| 208 | 0 | throw new IllegalArgumentException("namespace is blank"); |
| 209 | |
} |
| 210 | 0 | this.namespace = namespace; |
| 211 | 0 | } |
| 212 | |
|
| 213 | |
|
| 214 | |
public void setDescription(String desc) { |
| 215 | 0 | this.description = desc; |
| 216 | 0 | } |
| 217 | |
|
| 218 | |
public void setTypeId(String typeId) { |
| 219 | 0 | if (StringUtils.isBlank(typeId)) { |
| 220 | 0 | throw new IllegalArgumentException("KRMS type id is blank"); |
| 221 | |
} |
| 222 | 0 | this.typeId = typeId; |
| 223 | 0 | } |
| 224 | |
|
| 225 | |
public void setAttributes(List<ActionAttribute.Builder> attributes){ |
| 226 | 0 | if (attributes == null){ |
| 227 | 0 | this.attributes = Collections.unmodifiableList(new ArrayList<ActionAttribute.Builder>()); |
| 228 | 0 | return; |
| 229 | |
} |
| 230 | 0 | this.attributes = Collections.unmodifiableList(attributes); |
| 231 | 0 | } |
| 232 | |
|
| 233 | |
@Override |
| 234 | |
public String getActionId() { |
| 235 | 0 | return actionId; |
| 236 | |
} |
| 237 | |
|
| 238 | |
@Override |
| 239 | |
public String getName() { |
| 240 | 0 | return name; |
| 241 | |
} |
| 242 | |
|
| 243 | |
@Override |
| 244 | |
public String getNamespace() { |
| 245 | 0 | return namespace; |
| 246 | |
} |
| 247 | |
|
| 248 | |
@Override |
| 249 | |
public String getDescription() { |
| 250 | 0 | return description; |
| 251 | |
} |
| 252 | |
|
| 253 | |
@Override |
| 254 | |
public String getTypeId() { |
| 255 | 0 | return typeId; |
| 256 | |
} |
| 257 | |
|
| 258 | |
@Override |
| 259 | |
public List<ActionAttribute.Builder> getAttributes() { |
| 260 | 0 | return attributes; |
| 261 | |
} |
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
@Override |
| 269 | |
public Action build() { |
| 270 | 0 | return new Action(this); |
| 271 | |
} |
| 272 | |
|
| 273 | |
} |
| 274 | |
@Override |
| 275 | |
public int hashCode() { |
| 276 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 277 | |
} |
| 278 | |
|
| 279 | |
@Override |
| 280 | |
public boolean equals(Object obj) { |
| 281 | 0 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 282 | |
} |
| 283 | |
|
| 284 | |
@Override |
| 285 | |
public String toString() { |
| 286 | 0 | return ToStringBuilder.reflectionToString(this); |
| 287 | |
} |
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | 0 | static class Constants { |
| 293 | |
final static String KRMSNAMESPACE = "http://rice.kuali.org/schema/krms"; |
| 294 | |
final static String ROOT_ELEMENT_NAME = "Action"; |
| 295 | |
final static String TYPE_NAME = "ActionType"; |
| 296 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { "_elements" }; |
| 297 | |
} |
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | 0 | public static class Elements { |
| 304 | |
final static String ID = "actionId"; |
| 305 | |
final static String NAME = "name"; |
| 306 | |
final static String NAMESPACE = "namespace"; |
| 307 | |
final static String DESC = "description"; |
| 308 | |
final static String TYPE_ID = "typeId"; |
| 309 | |
final static String ATTRIBUTES = "attribute"; |
| 310 | |
} |
| 311 | |
|
| 312 | |
} |