View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.contract.model.test.source;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import javax.xml.bind.annotation.XmlElement;
23  import javax.xml.bind.annotation.XmlTransient;
24  
25  import org.kuali.student.contract.model.test.source.Attribute;
26  import org.kuali.student.contract.model.test.source.HasAttributes;
27  
28  @SuppressWarnings("serial")
29  @XmlTransient
30  public abstract class HasAttributesInfo implements HasAttributes, Serializable {
31  
32      @XmlElement
33      protected final List<AttributeInfo> attributes;
34  
35      protected HasAttributesInfo() {
36          attributes = null;
37      }
38  
39      protected HasAttributesInfo(HasAttributes builder) {
40          attributes = new ArrayList<AttributeInfo>();
41  
42          AttributeInfo.Builder attBuilder = new AttributeInfo.Builder();
43          for (Attribute att : builder.getAttributes()) {
44              attBuilder.setKey(att.getKey());
45              attBuilder.setValue(att.getValue());
46              attBuilder.setId(att.getId());
47              attributes.add(attBuilder.build());
48          }
49      }
50  
51      /**
52       * @return the attributes
53       */
54      @Override
55      public List<AttributeInfo> getAttributes() {
56          return attributes;
57      }
58  
59      public static class Builder implements HasAttributes {
60          private List<? extends Attribute> attributes = new ArrayList<AttributeInfo>();
61  
62          public Builder() {}
63  
64          public Builder(HasAttributes hasAtts) {
65              this.attributes = hasAtts.getAttributes();
66          }
67  
68          @Override
69          public List<? extends Attribute> getAttributes() {
70              return attributes;
71          }
72  
73          public void setAttributes(List<? extends Attribute> attributes) {
74              this.attributes = attributes;
75          }
76      }
77  }