View Javadoc
1   package org.apache.fulcrum.security.torque.peer.managers;
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 org.apache.avalon.framework.configuration.Configuration;
21  import org.apache.avalon.framework.configuration.ConfigurationException;
22  import org.apache.fulcrum.security.torque.TorqueAbstractUserManager;
23  import org.apache.fulcrum.security.torque.peer.Peer;
24  import org.apache.fulcrum.security.torque.peer.PeerManagable;
25  import org.apache.fulcrum.security.torque.peer.PeerManager;
26  import org.apache.fulcrum.security.torque.peer.TorqueTurbinePeer;
27  import org.apache.fulcrum.security.torque.peer.TorqueTurbineUserGroupRolePeer;
28  import org.apache.fulcrum.security.util.DataBackendException;
29  /**
30   * This implementation persists to a database via Torque.
31   *
32   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
33   * @version $Id:$
34   */
35  public abstract class PeerUserManager extends TorqueAbstractUserManager implements PeerManagable
36  {
37  	/**
38       * 
39       */
40      private static final long serialVersionUID = 1L;
41  
42      /**
43  	 * if set, the generic implementation is used (by setting @link {@link #PEER_CLASS_NAME_KEY} in configuration file.
44  	 */
45      private Boolean customPeer = false;  //  used for torque which uses per object peer classes
46      
47      private String peerClassName;
48      private static final String PEER_CLASS_NAME_KEY = "peerClassName";
49      transient PeerManager peerManager;
50      
51  	private String columnName = "LOGIN_NAME";
52  	
53  	private String columnName4UserGroupRole = "USER_ID";
54  
55      private String userGroupRolePeerClassName;
56      
57      /**
58       * Avalon Service lifecycle method
59       */
60      @Override
61  	public void configure(Configuration conf) throws ConfigurationException
62      {
63         super.configure( conf );
64         
65  //        peerClassName = conf.getChild( PEER_CLASS_NAME_KEY).getValue( "org.apache.fulcrum.security.torque.om.TorqueTurbineUserPeer" );
66          peerClassName = conf.getChild( PEER_CLASS_NAME_KEY).getValue( null );
67          if (peerClassName != null) {
68              setPeerClassName( peerClassName );
69              setCustomPeer(true);
70          } 
71          
72          Configuration[]  userGroupRoleConf = conf.getChild( "userGroupRoleManager").getChildren();
73          for ( int i = 0; i < userGroupRoleConf.length; i++ )
74          {
75              Configuration configuration = userGroupRoleConf[i];
76              if ( configuration.getName().equals(PEER_CLASS_NAME_KEY) ) {
77                  userGroupRolePeerClassName = configuration.getValue( null );
78                  if (userGroupRolePeerClassName != null) {
79                      setUserGroupRolePeerClassName( userGroupRolePeerClassName );
80                      setCustomPeer(true);
81                  } 
82              }  
83          }
84          if (peerClassName != null && userGroupRolePeerClassName == null) {
85              //peerClassName.replace( "TurbineUserPeerImpl", "TurbineUserPeerImpl )
86              throw new ConfigurationException("If using peers in component configuration (xml) the element userManager expects to have a userGroupRoleManager child element with peerClassName child element.");
87          }
88  
89      }
90    
91      
92      @Override
93  	public Peer getPeerInstance() throws DataBackendException {
94          return getPeerManager().getPeerInstance(getPeerClassName(), TorqueTurbinePeer.class, getClassName());
95      }
96      
97      public Peer getUserGroupRolePeerInstance() throws DataBackendException {
98          return getPeerManager().getPeerInstance(getUserGroupRolePeerClassName(), TorqueTurbineUserGroupRolePeer.class, getClassName());
99      }
100     
101     /**
102      * @return Returns the persistenceHelper.
103      */
104     @Override
105     public PeerManager getPeerManager()
106     {
107         if (peerManager == null)
108         {
109             peerManager = (PeerManager) resolve(PeerManager.ROLE);
110         }
111         return peerManager;
112     }
113 
114 	public String getColumnName() {
115 		return columnName;
116 	}
117 
118 	public void setColumnName(String columnName) {
119 		this.columnName = columnName;
120 	}
121     
122     /**
123      * 
124      * @return if <code>true</code>, the generic implementation is used.
125      */
126     @Override
127 	public Boolean getCustomPeer()
128     {
129         return customPeer;
130     }
131 
132     @Override
133 	public void setCustomPeer( Boolean customPeer )
134     {
135         this.customPeer = customPeer;
136     }
137 
138     @Override
139 	public String getPeerClassName()
140     {
141         return peerClassName;
142     }
143 
144     @Override
145 	public void setPeerClassName( String peerClassName )
146     {
147         this.peerClassName = peerClassName;
148     }
149 
150 
151     public String getUserGroupRolePeerClassName()
152     {
153         return userGroupRolePeerClassName;
154     }
155 
156 
157     public void setUserGroupRolePeerClassName( String userGroupRolePeerClassName )
158     {
159         this.userGroupRolePeerClassName = userGroupRolePeerClassName;
160     }
161 
162 
163     public String getColumnName4UserGroupRole()
164     {
165         return columnName4UserGroupRole;
166     }
167 
168 
169     public void setColumnName4UserGroupRole( String columnName4UserGroupRole )
170     {
171         this.columnName4UserGroupRole = columnName4UserGroupRole;
172     }
173    
174     
175 }