001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.api.doctype; 017 018import java.io.Serializable; 019import java.util.Collection; 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlAnyElement; 023import javax.xml.bind.annotation.XmlElement; 024import javax.xml.bind.annotation.XmlRootElement; 025import javax.xml.bind.annotation.XmlType; 026 027import org.apache.commons.lang.StringUtils; 028import org.kuali.rice.core.api.CoreConstants; 029import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 030import org.kuali.rice.core.api.mo.ModelBuilder; 031import org.kuali.rice.kew.api.extension.ExtensionDefinition; 032import org.w3c.dom.Element; 033 034@XmlRootElement(name = DocumentTypeAttribute.Constants.ROOT_ELEMENT_NAME) 035@XmlAccessorType(XmlAccessType.NONE) 036@XmlType(name = DocumentTypeAttribute.Constants.TYPE_NAME, propOrder = { 037 DocumentTypeAttribute.Elements.ID, 038 DocumentTypeAttribute.Elements.RULE_ATTRIBUTE, 039 DocumentTypeAttribute.Elements.DOCUMENT_TYPE_ID, 040 DocumentTypeAttribute.Elements.ORDER_INDEX, 041 CoreConstants.CommonElements.FUTURE_ELEMENTS 042}) 043public final class DocumentTypeAttribute 044 extends AbstractDataTransferObject 045 implements DocumentTypeAttributeContract 046{ 047 @XmlElement(name = Elements.ID, required = false) 048 private final String id; 049 @XmlElement(name = Elements.RULE_ATTRIBUTE, required = true) 050 private final ExtensionDefinition ruleAttribute; 051 @XmlElement(name = Elements.DOCUMENT_TYPE_ID, required = true) 052 private final String documentTypeId; 053 @XmlElement(name = Elements.ORDER_INDEX, required = false) 054 private final int orderIndex; 055 056 @SuppressWarnings("unused") 057 @XmlAnyElement 058 private final Collection<Element> _futureElements = null; 059 060 /** 061 * Private constructor used only by JAXB. 062 * 063 */ 064 private DocumentTypeAttribute() { 065 this.ruleAttribute = null; 066 this.documentTypeId = null; 067 this.orderIndex = 0; 068 this.id = null; 069 } 070 071 private DocumentTypeAttribute(Builder builder) { 072 this.ruleAttribute = builder.getRuleAttribute().build(); 073 this.documentTypeId = builder.getDocumentTypeId(); 074 this.orderIndex = builder.getOrderIndex(); 075 this.id = builder.getId(); 076 } 077 078 @Override 079 public ExtensionDefinition getRuleAttribute() { 080 return this.ruleAttribute; 081 } 082 083 @Override 084 public String getDocumentTypeId() { 085 return this.documentTypeId; 086 } 087 088 @Override 089 public int getOrderIndex() { 090 return this.orderIndex; 091 } 092 093 @Override 094 public String getId() { 095 return this.id; 096 } 097 098 099 /** 100 * A builder which can be used to construct {@link DocumentTypeAttribute} instances. Enforces the constraints of the {@link DocumentTypeAttributeContract}. 101 * 102 */ 103 public final static class Builder 104 implements Serializable, ModelBuilder, DocumentTypeAttributeContract 105 { 106 107 private ExtensionDefinition.Builder ruleAttribute; 108 private String documentTypeId; 109 private int orderIndex; 110 private String id; 111 112 private Builder(String documentTypeId, ExtensionDefinition.Builder ruleAttribute) { 113 setDocumentTypeId(documentTypeId); 114 setRuleAttribute(ruleAttribute); 115 } 116 117 public static Builder create(String documentTypeId, ExtensionDefinition.Builder ruleAttribute) { 118 return new Builder(documentTypeId, ruleAttribute); 119 } 120 121 public static Builder create(DocumentTypeAttributeContract contract) { 122 if (contract == null) { 123 throw new IllegalArgumentException("contract was null"); 124 } 125 Builder builder = create(contract.getDocumentTypeId(), ExtensionDefinition.Builder.create(contract.getRuleAttribute())); 126 builder.setOrderIndex(contract.getOrderIndex()); 127 builder.setId(contract.getId()); 128 return builder; 129 } 130 131 public DocumentTypeAttribute build() { 132 return new DocumentTypeAttribute(this); 133 } 134 135 @Override 136 public ExtensionDefinition.Builder getRuleAttribute() { 137 return this.ruleAttribute; 138 } 139 140 @Override 141 public String getDocumentTypeId() { 142 return this.documentTypeId; 143 } 144 145 @Override 146 public int getOrderIndex() { 147 return this.orderIndex; 148 } 149 150 @Override 151 public String getId() { 152 return this.id; 153 } 154 155 public void setRuleAttribute(ExtensionDefinition.Builder ruleAttribute) { 156 if (ruleAttribute == null) { 157 throw new IllegalArgumentException("ruleAttribute is null"); 158 } 159 this.ruleAttribute = ruleAttribute; 160 } 161 162 public void setDocumentTypeId(String documentTypeId) { 163 if (StringUtils.isEmpty(documentTypeId)) { 164 throw new IllegalArgumentException("documentTypeId is empty"); 165 } 166 this.documentTypeId = documentTypeId; 167 } 168 169 public void setOrderIndex(int orderIndex) { 170 this.orderIndex = orderIndex; 171 } 172 173 public void setId(String id) { 174 if (StringUtils.isWhitespace(id)) { 175 throw new IllegalArgumentException("id is blank"); 176 } 177 this.id = id; 178 } 179 180 } 181 182 183 /** 184 * Defines some internal constants used on this class. 185 * 186 */ 187 static class Constants { 188 189 final static String ROOT_ELEMENT_NAME = "documentTypeAttribute"; 190 final static String TYPE_NAME = "DocumentTypeAttributeType"; 191 192 } 193 194 195 /** 196 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 197 * 198 */ 199 static class Elements { 200 201 final static String RULE_ATTRIBUTE = "ruleAttribute"; 202 final static String DOCUMENT_TYPE_ID = "documentTypeId"; 203 final static String ORDER_INDEX = "orderIndex"; 204 final static String ID = "id"; 205 206 } 207 208}