|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
   package org.kuali.rice.kim.api.type;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import org.apache.commons.lang.StringUtils;  | 
  |  20 |     | 
   import org.apache.commons.lang.builder.EqualsBuilder;  | 
  |  21 |     | 
   import org.apache.commons.lang.builder.HashCodeBuilder;  | 
  |  22 |     | 
   import org.apache.commons.lang.builder.ToStringBuilder;  | 
  |  23 |     | 
   import org.kuali.rice.core.api.CoreConstants;  | 
  |  24 |     | 
   import org.kuali.rice.core.api.mo.ModelBuilder;  | 
  |  25 |     | 
   import org.kuali.rice.core.api.mo.ModelObjectComplete;  | 
  |  26 |     | 
   import org.w3c.dom.Element;  | 
  |  27 |     | 
     | 
  |  28 |     | 
   import javax.xml.bind.annotation.XmlAccessType;  | 
  |  29 |     | 
   import javax.xml.bind.annotation.XmlAccessorType;  | 
  |  30 |     | 
   import javax.xml.bind.annotation.XmlAnyElement;  | 
  |  31 |     | 
   import javax.xml.bind.annotation.XmlElement;  | 
  |  32 |     | 
   import javax.xml.bind.annotation.XmlRootElement;  | 
  |  33 |     | 
   import javax.xml.bind.annotation.XmlType;  | 
  |  34 |     | 
   import java.io.Serializable;  | 
  |  35 |     | 
   import java.util.ArrayList;  | 
  |  36 |     | 
   import java.util.Collection;  | 
  |  37 |     | 
   import java.util.Collections;  | 
  |  38 |     | 
   import java.util.List;  | 
  |  39 |     | 
     | 
  |  40 |     | 
     | 
  |  41 |     | 
     | 
  |  42 |     | 
     | 
  |  43 |     | 
     | 
  |  44 |     | 
     | 
  |  45 |     | 
     | 
  |  46 |     | 
     | 
  |  47 |     | 
   @XmlRootElement(name = KimType.Constants.ROOT_ELEMENT_NAME)  | 
  |  48 |     | 
   @XmlAccessorType(XmlAccessType.NONE)  | 
  |  49 |     | 
   @XmlType(name = KimType.Constants.TYPE_NAME, propOrder = { | 
  |  50 |     | 
           KimType.Elements.ID,  | 
  |  51 |     | 
           KimType.Elements.SERVICE_NAME,  | 
  |  52 |     | 
           KimType.Elements.NAMESPACE_CODE,  | 
  |  53 |     | 
           KimType.Elements.NAME,  | 
  |  54 |     | 
           KimType.Elements.ATTRIBUTE_DEFNS,  | 
  |  55 |     | 
           KimType.Elements.ACTIVE,  | 
  |  56 |     | 
           CoreConstants.CommonElements.VERSION_NUMBER,  | 
  |  57 |     | 
           CoreConstants.CommonElements.OBJECT_ID,  | 
  |  58 |     | 
           CoreConstants.CommonElements.FUTURE_ELEMENTS  | 
  |  59 |     | 
   })  | 
  |  60 |    12 |    public final class KimType implements KimTypeContract, ModelObjectComplete { | 
  |  61 |     | 
       private static final long serialVersionUID = 1L;  | 
  |  62 |     | 
     | 
  |  63 |     | 
       @XmlElement(name = KimType.Elements.ID, required = false)  | 
  |  64 |     | 
       private final String id;  | 
  |  65 |     | 
     | 
  |  66 |     | 
       @XmlElement(name = KimType.Elements.SERVICE_NAME, required = false)  | 
  |  67 |     | 
       private final String serviceName;  | 
  |  68 |     | 
     | 
  |  69 |     | 
       @XmlElement(name = KimType.Elements.NAMESPACE_CODE, required = false)  | 
  |  70 |     | 
       private final String namespaceCode;  | 
  |  71 |     | 
     | 
  |  72 |     | 
       @XmlElement(name = KimType.Elements.NAME, required = false)  | 
  |  73 |     | 
       private final String name;  | 
  |  74 |     | 
     | 
  |  75 |     | 
       @XmlElement(name = KimType.Elements.ATTRIBUTE_DEFNS, required = false)  | 
  |  76 |     | 
       private final List<KimTypeAttribute> attributeDefinitions;  | 
  |  77 |     | 
     | 
  |  78 |     | 
       @XmlElement(name = KimType.Elements.ACTIVE, required = false)  | 
  |  79 |     | 
       private final boolean active;  | 
  |  80 |     | 
     | 
  |  81 |     | 
       @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)  | 
  |  82 |     | 
       private final Long versionNumber;  | 
  |  83 |     | 
     | 
  |  84 |     | 
       @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)  | 
  |  85 |     | 
       private final String objectId;  | 
  |  86 |     | 
     | 
  |  87 |    19 |        @SuppressWarnings("unused") | 
  |  88 |     | 
       @XmlAnyElement  | 
  |  89 |     | 
       private final Collection<Element> _futureElements = null;  | 
  |  90 |     | 
     | 
  |  91 |     | 
         | 
  |  92 |     | 
     | 
  |  93 |     | 
     | 
  |  94 |    7 |        private KimType() { | 
  |  95 |    7 |            this.id = null;  | 
  |  96 |    7 |            this.serviceName = null;  | 
  |  97 |    7 |            this.namespaceCode = null;  | 
  |  98 |    7 |            this.name = null;  | 
  |  99 |    7 |            this.attributeDefinitions = Collections.<KimTypeAttribute>emptyList();  | 
  |  100 |    7 |            this.active = false;  | 
  |  101 |    7 |            this.versionNumber = Long.valueOf(1L);  | 
  |  102 |    7 |            this.objectId = null;  | 
  |  103 |    7 |        }  | 
  |  104 |     | 
     | 
  |  105 |    12 |        private KimType(Builder builder) { | 
  |  106 |    12 |            this.id = builder.getId();  | 
  |  107 |    12 |            this.serviceName = builder.getServiceName();  | 
  |  108 |    12 |            this.namespaceCode = builder.getNamespaceCode();  | 
  |  109 |    12 |            this.name = builder.getName();  | 
  |  110 |    12 |            final List<KimTypeAttribute> temp = new ArrayList<KimTypeAttribute>();  | 
  |  111 |    12 |            for (KimTypeAttribute.Builder attr : builder.getAttributeDefinitions()) { | 
  |  112 |     | 
                 | 
  |  113 |    0 |                attr.setKimTypeId(this.id);  | 
  |  114 |    0 |                temp.add(attr.build());  | 
  |  115 |     | 
           }  | 
  |  116 |    12 |            this.attributeDefinitions = Collections.unmodifiableList(temp);  | 
  |  117 |     | 
     | 
  |  118 |    12 |            this.active = builder.isActive();  | 
  |  119 |    12 |            this.versionNumber = builder.getVersionNumber();  | 
  |  120 |    12 |            this.objectId = builder.getObjectId();  | 
  |  121 |    12 |        }  | 
  |  122 |     | 
     | 
  |  123 |     | 
         | 
  |  124 |     | 
     | 
  |  125 |     | 
     | 
  |  126 |     | 
     | 
  |  127 |     | 
     | 
  |  128 |     | 
     | 
  |  129 |     | 
     | 
  |  130 |     | 
     | 
  |  131 |     | 
     | 
  |  132 |     | 
     | 
  |  133 |     | 
     | 
  |  134 |     | 
     | 
  |  135 |     | 
     | 
  |  136 |     | 
       public KimTypeAttribute getAttributeDefinitionById(String id) { | 
  |  137 |    0 |            if (StringUtils.isBlank(id)) { | 
  |  138 |    0 |                throw new IllegalArgumentException("id is blank"); | 
  |  139 |     | 
           }  | 
  |  140 |     | 
     | 
  |  141 |    0 |            if (this.attributeDefinitions != null) { | 
  |  142 |    0 |                for (KimTypeAttribute att : this.attributeDefinitions) { | 
  |  143 |    0 |                    if (att != null && att.getKimAttribute() != null  | 
  |  144 |     | 
                           && id.equals(att.getKimAttribute().getId())) { | 
  |  145 |    0 |                        return att;  | 
  |  146 |     | 
                   }  | 
  |  147 |     | 
               }  | 
  |  148 |     | 
           }  | 
  |  149 |    0 |                    return null;  | 
  |  150 |     | 
           }  | 
  |  151 |     | 
     | 
  |  152 |     | 
         | 
  |  153 |     | 
     | 
  |  154 |     | 
     | 
  |  155 |     | 
     | 
  |  156 |     | 
     | 
  |  157 |     | 
     | 
  |  158 |     | 
     | 
  |  159 |     | 
     | 
  |  160 |     | 
     | 
  |  161 |     | 
     | 
  |  162 |     | 
     | 
  |  163 |     | 
     | 
  |  164 |     | 
     | 
  |  165 |     | 
           public KimTypeAttribute getAttributeDefinitionByName(String name) { | 
  |  166 |    0 |            if (StringUtils.isBlank(name)) { | 
  |  167 |    0 |                throw new IllegalArgumentException("name is blank"); | 
  |  168 |     | 
           }  | 
  |  169 |     | 
     | 
  |  170 |    0 |            if (this.attributeDefinitions != null) { | 
  |  171 |    0 |                for (KimTypeAttribute att : this.attributeDefinitions) { | 
  |  172 |    0 |                    if (att != null && att.getKimAttribute() != null  | 
  |  173 |     | 
                           && name.equals(att.getKimAttribute().getAttributeName())) { | 
  |  174 |    0 |                        return att;  | 
  |  175 |     | 
                   }  | 
  |  176 |     | 
               }  | 
  |  177 |     | 
           }  | 
  |  178 |    0 |                    return null;  | 
  |  179 |     | 
           }  | 
  |  180 |     | 
     | 
  |  181 |     | 
       @Override  | 
  |  182 |     | 
       public String getId() { | 
  |  183 |    8 |            return id;  | 
  |  184 |     | 
       }  | 
  |  185 |     | 
     | 
  |  186 |     | 
       @Override  | 
  |  187 |     | 
       public String getServiceName() { | 
  |  188 |    5 |            return serviceName;  | 
  |  189 |     | 
       }  | 
  |  190 |     | 
     | 
  |  191 |     | 
       @Override  | 
  |  192 |     | 
       public String getNamespaceCode() { | 
  |  193 |    5 |            return namespaceCode;  | 
  |  194 |     | 
       }  | 
  |  195 |     | 
     | 
  |  196 |     | 
       @Override  | 
  |  197 |     | 
       public String getName() { | 
  |  198 |    5 |            return name;  | 
  |  199 |     | 
       }  | 
  |  200 |     | 
     | 
  |  201 |     | 
       @Override  | 
  |  202 |     | 
       public List<KimTypeAttribute> getAttributeDefinitions() { | 
  |  203 |    10 |            return attributeDefinitions;  | 
  |  204 |     | 
       }  | 
  |  205 |     | 
     | 
  |  206 |     | 
       @Override  | 
  |  207 |     | 
       public boolean isActive() { | 
  |  208 |    5 |            return active;  | 
  |  209 |     | 
       }  | 
  |  210 |     | 
     | 
  |  211 |     | 
       @Override  | 
  |  212 |     | 
       public Long getVersionNumber() { | 
  |  213 |    5 |            return versionNumber;  | 
  |  214 |     | 
       }  | 
  |  215 |     | 
     | 
  |  216 |     | 
       @Override  | 
  |  217 |     | 
       public String getObjectId() { | 
  |  218 |    5 |            return objectId;  | 
  |  219 |     | 
       }  | 
  |  220 |     | 
     | 
  |  221 |     | 
       @Override  | 
  |  222 |     | 
       public int hashCode() { | 
  |  223 |    0 |            return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);  | 
  |  224 |     | 
       }  | 
  |  225 |     | 
     | 
  |  226 |     | 
       @Override  | 
  |  227 |     | 
       public boolean equals(Object obj) { | 
  |  228 |    5 |            return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);  | 
  |  229 |     | 
       }  | 
  |  230 |     | 
     | 
  |  231 |     | 
       @Override  | 
  |  232 |     | 
       public String toString() { | 
  |  233 |    0 |            return ToStringBuilder.reflectionToString(this);  | 
  |  234 |     | 
       }  | 
  |  235 |     | 
     | 
  |  236 |     | 
         | 
  |  237 |     | 
     | 
  |  238 |     | 
     | 
  |  239 |    8 |        public static final class Builder implements KimTypeContract, ModelBuilder, Serializable { | 
  |  240 |     | 
           private String id;  | 
  |  241 |     | 
           private String serviceName;  | 
  |  242 |     | 
           private String namespaceCode;  | 
  |  243 |     | 
           private String name;  | 
  |  244 |    15 |            private List<KimTypeAttribute.Builder> attributeDefinitions = new ArrayList<KimTypeAttribute.Builder>();  | 
  |  245 |     | 
           private boolean active;  | 
  |  246 |    15 |            private Long versionNumber = 1L;  | 
  |  247 |     | 
           private String objectId;  | 
  |  248 |     | 
     | 
  |  249 |    15 |            private Builder() { | 
  |  250 |    15 |            }  | 
  |  251 |     | 
     | 
  |  252 |     | 
             | 
  |  253 |     | 
     | 
  |  254 |     | 
     | 
  |  255 |     | 
           public static Builder create() { | 
  |  256 |    9 |                return new Builder();  | 
  |  257 |     | 
           }  | 
  |  258 |     | 
     | 
  |  259 |     | 
             | 
  |  260 |     | 
     | 
  |  261 |     | 
     | 
  |  262 |     | 
           public static Builder create(KimTypeContract contract) { | 
  |  263 |    6 |                    if (contract == null) { | 
  |  264 |    0 |                            throw new IllegalArgumentException("contract was null"); | 
  |  265 |     | 
                   }  | 
  |  266 |    6 |                Builder builder = new Builder();  | 
  |  267 |    6 |                builder.setId(contract.getId());  | 
  |  268 |    6 |                builder.setServiceName(contract.getServiceName());  | 
  |  269 |    6 |                builder.setNamespaceCode(contract.getNamespaceCode());  | 
  |  270 |    6 |                builder.setName(contract.getName());  | 
  |  271 |     | 
     | 
  |  272 |    6 |                if (contract.getAttributeDefinitions() != null) { | 
  |  273 |    6 |                    final List<KimTypeAttribute.Builder> temp = new ArrayList<KimTypeAttribute.Builder>();  | 
  |  274 |    6 |                    for (KimTypeAttributeContract attr : contract.getAttributeDefinitions()) { | 
  |  275 |    0 |                        temp.add(KimTypeAttribute.Builder.create(attr));  | 
  |  276 |     | 
                   }  | 
  |  277 |     | 
     | 
  |  278 |    6 |                    builder.setAttributeDefinitions(Collections.unmodifiableList(temp));  | 
  |  279 |     | 
               }  | 
  |  280 |     | 
     | 
  |  281 |    6 |                builder.setActive(contract.isActive());  | 
  |  282 |    6 |                builder.setVersionNumber(contract.getVersionNumber());  | 
  |  283 |    6 |                builder.setObjectId(contract.getObjectId());  | 
  |  284 |    6 |                return builder;  | 
  |  285 |     | 
           }  | 
  |  286 |     | 
     | 
  |  287 |     | 
           @Override  | 
  |  288 |     | 
           public String getId() { | 
  |  289 |    12 |                return id;  | 
  |  290 |     | 
           }  | 
  |  291 |     | 
     | 
  |  292 |     | 
           public void setId(final String id) { | 
  |  293 |    12 |                this.id = id;  | 
  |  294 |    12 |            }  | 
  |  295 |     | 
     | 
  |  296 |     | 
           @Override  | 
  |  297 |     | 
           public String getServiceName() { | 
  |  298 |    12 |                return serviceName;  | 
  |  299 |     | 
           }  | 
  |  300 |     | 
     | 
  |  301 |     | 
           public void setServiceName(final String serviceName) { | 
  |  302 |    7 |                this.serviceName = serviceName;  | 
  |  303 |    7 |            }  | 
  |  304 |     | 
     | 
  |  305 |     | 
           @Override  | 
  |  306 |     | 
           public String getNamespaceCode() { | 
  |  307 |    12 |                return namespaceCode;  | 
  |  308 |     | 
           }  | 
  |  309 |     | 
     | 
  |  310 |     | 
           public void setNamespaceCode(final String namespaceCode) { | 
  |  311 |    9 |                this.namespaceCode = namespaceCode;  | 
  |  312 |    9 |            }  | 
  |  313 |     | 
     | 
  |  314 |     | 
           @Override  | 
  |  315 |     | 
           public String getName() { | 
  |  316 |    12 |                return name;  | 
  |  317 |     | 
           }  | 
  |  318 |     | 
     | 
  |  319 |     | 
           public void setName(final String name) { | 
  |  320 |    6 |                this.name = name;  | 
  |  321 |    6 |            }  | 
  |  322 |     | 
     | 
  |  323 |     | 
           @Override  | 
  |  324 |     | 
           public List<KimTypeAttribute.Builder> getAttributeDefinitions() { | 
  |  325 |    12 |                return attributeDefinitions;  | 
  |  326 |     | 
           }  | 
  |  327 |     | 
     | 
  |  328 |     | 
           public void setAttributeDefinitions(final List<KimTypeAttribute.Builder> attributeDefinitions) { | 
  |  329 |    6 |                if (attributeDefinitions == null) { | 
  |  330 |    0 |                    throw new IllegalArgumentException("attributeDefinitions is null"); | 
  |  331 |     | 
               }  | 
  |  332 |     | 
     | 
  |  333 |    6 |                this.attributeDefinitions = attributeDefinitions;  | 
  |  334 |    6 |            }  | 
  |  335 |     | 
     | 
  |  336 |     | 
           @Override  | 
  |  337 |     | 
           public boolean isActive() { | 
  |  338 |    12 |                return active;  | 
  |  339 |     | 
           }  | 
  |  340 |     | 
     | 
  |  341 |     | 
           public void setActive(final boolean active) { | 
  |  342 |    8 |                this.active = active;  | 
  |  343 |    8 |            }  | 
  |  344 |     | 
     | 
  |  345 |     | 
           @Override  | 
  |  346 |     | 
           public Long getVersionNumber() { | 
  |  347 |    12 |                return versionNumber;  | 
  |  348 |     | 
           }  | 
  |  349 |     | 
     | 
  |  350 |     | 
           public void setVersionNumber(final Long versionNumber) { | 
  |  351 |    10 |                if (versionNumber != null && versionNumber <= 0) { | 
  |  352 |    2 |                    throw new IllegalArgumentException("versionNumber is invalid"); | 
  |  353 |     | 
               }  | 
  |  354 |     | 
     | 
  |  355 |    8 |                this.versionNumber = versionNumber;  | 
  |  356 |    8 |            }  | 
  |  357 |     | 
     | 
  |  358 |     | 
           @Override  | 
  |  359 |     | 
           public String getObjectId() { | 
  |  360 |    12 |                return objectId;  | 
  |  361 |     | 
           }  | 
  |  362 |     | 
     | 
  |  363 |     | 
           public void setObjectId(final String objectId) { | 
  |  364 |    8 |                this.objectId = objectId;  | 
  |  365 |    8 |            }  | 
  |  366 |     | 
     | 
  |  367 |     | 
           @Override  | 
  |  368 |     | 
           public KimType build() { | 
  |  369 |    12 |                return new KimType(this);  | 
  |  370 |     | 
           }  | 
  |  371 |     | 
       }  | 
  |  372 |     | 
     | 
  |  373 |     | 
         | 
  |  374 |     | 
     | 
  |  375 |     | 
     | 
  |  376 |    0 |        static class Constants { | 
  |  377 |     | 
           static final String ROOT_ELEMENT_NAME = "kimType";  | 
  |  378 |     | 
           static final String TYPE_NAME = "KimTypeType";  | 
  |  379 |    1 |            static final String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; | 
  |  380 |     | 
       }  | 
  |  381 |     | 
     | 
  |  382 |     | 
         | 
  |  383 |     | 
     | 
  |  384 |     | 
     | 
  |  385 |     | 
     | 
  |  386 |    0 |        static class Elements { | 
  |  387 |     | 
           static final String ID = "id";  | 
  |  388 |     | 
           static final String SERVICE_NAME = "serviceName";  | 
  |  389 |     | 
           static final String NAMESPACE_CODE = "namespaceCode";  | 
  |  390 |     | 
           static final String NAME = "name";  | 
  |  391 |     | 
           static final String ATTRIBUTE_DEFNS = "attributeDefinitions";  | 
  |  392 |     | 
           static final String ACTIVE = "active";  | 
  |  393 |     | 
       }  | 
  |  394 |     | 
   }  |