1 package org.apache.fulcrum.security.torque.security.turbine;
2 /*
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 */
20 import java.util.HashSet;
21 import java.util.Set;
22
23 import org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole;
24 import org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRoleEntity;
25 import org.apache.fulcrum.security.torque.security.TorqueAbstractSecurityEntity;
26 import org.apache.fulcrum.security.util.DataBackendException;
27 /**
28 * This abstract class provides the SecurityInterface to the managers.
29 *
30 * Additional Torque contract
31 *
32 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
33 * @version $Id:$
34 */
35 public abstract class TorqueAbstractTurbineTurbineSecurityEntity extends TorqueAbstractSecurityEntity
36 implements TurbineUserGroupRoleEntity // not in group and role but already in TurbineUser interface
37 {
38 /** Serial version */
39 private static final long serialVersionUID = -6230312046016785990L;
40
41 /** a cache of user_group_role objects */
42 private Set<? extends TurbineUserGroupRole> userGroupRoleSet = null;
43
44 /* (non-Javadoc)
45 * @see org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRoleEntity#addUserGroupRole(org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole)
46 */
47 public void addUserGroupRole(TurbineUserGroupRole userGroupRole) throws DataBackendException
48 {
49 getUserGroupRoleSet().add(userGroupRole);
50 }
51
52 /**
53 * @param user_group_role u/g/r to add
54 * @param isLazilyLoaded <code>true</code> for lazy loading
55 * @throws DataBackendException if the database backend is not found
56 */
57 public void addUserGroupRole( TurbineUserGroupRole user_group_role, boolean isLazilyLoaded ) throws DataBackendException {
58 if (isLazilyLoaded)
59 {
60 getDefaultUserGroupRoleSet().add( user_group_role );
61 }
62 else
63 {
64 getUserGroupRoleSet().add( user_group_role );
65 }
66 }
67
68 /**
69 * @return get default u/g/r set
70 * @throws DataBackendException if the database backend is not found
71 */
72 @SuppressWarnings("unchecked")
73 private <T extends TurbineUserGroupRole> Set<T> getDefaultUserGroupRoleSet() throws DataBackendException
74 {
75 if (userGroupRoleSet == null)
76 {
77 userGroupRoleSet = new HashSet<TurbineUserGroupRole>();
78 }
79
80 return (Set<T>) userGroupRoleSet;
81 }
82
83 /* (non-Javadoc)
84 * @see org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRoleEntity#getUserGroupRoleSet()
85 * @throws DataBackendException if loaded lazily
86 */
87 public <T extends TurbineUserGroupRole> Set<T> getUserGroupRoleSet() throws DataBackendException
88 {
89 return getDefaultUserGroupRoleSet();
90 }
91
92 /* (non-Javadoc)
93 * @see org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRoleEntity#removeUserGroupRole(org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole)
94 */
95 public void removeUserGroupRole(TurbineUserGroupRole userGroupRole) throws DataBackendException
96 {
97 getUserGroupRoleSet().remove(userGroupRole);
98 }
99
100 /**
101 * @param user_group_role u/g/r to remove
102 * @param isLazilyLoaded <code>true</code> for lazy loading
103 * @throws DataBackendException if the database backend is not found
104 */
105 public void removeUserGroupRole( TurbineUserGroupRole user_group_role, boolean isLazilyLoaded ) throws DataBackendException {
106 if (isLazilyLoaded)
107 {
108 getDefaultUserGroupRoleSet().remove( user_group_role );
109 }
110 else
111 {
112 getUserGroupRoleSet().remove( user_group_role );
113 }
114 }
115
116 /* (non-Javadoc)
117 * @see org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRoleEntity#setUserGroupRoleSet(java.util.Set)
118 */
119 public <T extends TurbineUserGroupRole> void setUserGroupRoleSet(Set<T> userGroupRoleSet)
120 {
121 if (userGroupRoleSet != null)
122 {
123 this.userGroupRoleSet = userGroupRoleSet;
124 }
125 else
126 {
127 this.userGroupRoleSet = new HashSet<TurbineUserGroupRole>();
128 }
129 }
130
131 }