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.TorqueAbstractRoleManager;
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.util.DataBackendException;
28  /**
29   * This implementation persists to a database via Torque.
30   *
31   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
32   * @version $Id:$
33   */
34  public abstract class PeerRoleManager extends TorqueAbstractRoleManager implements PeerManagable
35  {
36      private Boolean customPeer = false;  //  used for torque which uses per object peer classes
37      
38      private String peerClassName;
39      private static final String PEER_CLASS_NAME_KEY = "peerClassName";
40      transient PeerManager peerManager;
41      
42      private String columnName = "ROLE_NAME";
43      
44      /**
45       * Avalon Service lifecycle method
46       */
47      @Override
48  	public void configure(Configuration conf) throws ConfigurationException
49      {
50         super.configure( conf );
51         
52  //       peerClassName = conf.getChild( PEER_CLASS_NAME_KEY).getValue( "org.apache.fulcrum.security.torque.om.TorqueTurbineRolePeer" );
53          peerClassName = conf.getChild( PEER_CLASS_NAME_KEY).getValue( null );
54          if (peerClassName != null) {
55              setPeerClassName( peerClassName );
56              setCustomPeer(true);
57          } 
58      }
59     
60      
61      @Override
62  	public Peer getPeerInstance() throws DataBackendException {
63          return getPeerManager().getPeerInstance(getPeerClassName(), TorqueTurbinePeer.class, getClassName());
64      }
65      
66      /**
67       * @return Returns the persistenceHelper.
68       */
69      @Override
70  	public PeerManager getPeerManager()
71      {
72          if (peerManager == null)
73          {
74              peerManager = (PeerManager) resolve(PeerManager.ROLE);
75          }
76          return peerManager;
77      }
78      
79  	public String getColumnName() {
80  		return columnName;
81  	}
82  
83  	public void setColumnName(String columnName) {
84  		this.columnName = columnName;
85  	}
86  
87      
88  	@Override
89  	public Boolean getCustomPeer()
90      {
91          return customPeer;
92      }
93  
94      @Override
95  	public void setCustomPeer( Boolean customPeer )
96      {
97          this.customPeer = customPeer;
98      }
99  
100     @Override
101 	public String getPeerClassName()
102     {
103         return peerClassName;
104     }
105 
106     @Override
107 	public void setPeerClassName( String peerClassName )
108     {
109         this.peerClassName = peerClassName;
110     }
111   
112 }