View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   package org.directdemocracyportal.democracy.model.world;
6   
7   import java.util.HashSet;
8   import java.util.Set;
9   
10  import javax.persistence.CascadeType;
11  import javax.persistence.Entity;
12  import javax.persistence.FetchType;
13  import javax.persistence.OneToMany;
14  import javax.persistence.Transient;
15  
16  import org.directdemocracyportal.democracy.model.core.Role;
17  import org.hibernate.annotations.Cache;
18  import org.hibernate.annotations.CacheConcurrencyStrategy;
19  
20  /***
21   * The Class Government.
22   */
23  @Entity
24  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
25  public class Government extends Organisation
26  {
27  
28      /***
29       * The Enum GovernmentRoles.
30       */
31      public enum GovernmentRoles {
32  
33          /*** The Head_of_ state. */
34          Head_of_State
35      };
36  
37      /*** The Constant serialVersionUID. */
38      private static final long serialVersionUID = -946981671229247412L;
39  
40      /*** The Government type. */
41      private GovernmentType GovernmentType;
42  
43      /*** The elections. */
44      private Set<Election> elections = new HashSet<Election>();
45  
46      /***
47       * Instantiates a new government.
48       */
49      public Government() {
50      }
51  
52      /***
53       * Gets the government type.
54       *
55       * @return the government type
56       */
57      public GovernmentType getGovernmentType() {
58          return GovernmentType;
59      }
60  
61      /***
62       * Sets the government type.
63       *
64       * @param GovernmentType the new government type
65       */
66      public void setGovernmentType(GovernmentType GovernmentType) {
67          this.GovernmentType = GovernmentType;
68      }
69  
70      /***
71       * Gets the elections.
72       *
73       * @return the elections
74       */
75      @OneToMany(mappedBy = "government", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
76      public Set<Election> getElections() {
77          return elections;
78      }
79  
80      /***
81       * Sets the elections.
82       *
83       * @param elections the new elections
84       */
85      public void setElections(Set<Election> elections) {
86          this.elections = elections;
87      }
88  
89      /***
90       * Gets the headof state.
91       *
92       * @return the headof state
93       */
94      @Transient
95      public Person getHeadofState() {
96          for (Role role : getDefinedRoles()) {
97              if (role.getName().equals(GovernmentRoles.Head_of_State.toString())) {
98                  return (Person) role.getPlayers().iterator().next();
99              }
100         }
101         return null;
102     }
103 }