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.TorqueAbstractGroupManager;
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  /**
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 PeerGroupManager extends TorqueAbstractGroupManager implements PeerManagable
36  {
37      
38      private Boolean customPeer = false;  //  used for torque which uses per object peer classes
39      private String peerClassName;
40      transient PeerManager peerManager;
41      private static final String PEER_CLASS_NAME_KEY = "peerClassName";
42      
43      private String columnName = "GROUP_NAME";
44      
45      /**
46       * Avalon Service lifecycle method
47       */
48      @Override
49  	public void configure(Configuration conf) throws ConfigurationException
50      {
51         super.configure( conf );
52         
53          peerClassName = conf.getChild( PEER_CLASS_NAME_KEY).getValue( null );
54          if (peerClassName != null) {
55              setPeerClassName( peerClassName );
56              setCustomPeer(true);
57          } 
58      }
59      
60      @Override
61     	public Peer getPeerInstance() throws DataBackendException {
62             return getPeerManager().getPeerInstance(getPeerClassName(), TorqueTurbinePeer.class, getClassName());
63      }
64         
65         /**
66          * @return Returns the persistenceHelper.
67          */
68         @Override
69     	public PeerManager getPeerManager()
70         {
71             if (peerManager == null)
72             {
73                 peerManager = (PeerManager) resolve(PeerManager.ROLE);
74             }
75             return peerManager;
76         }
77  
78     	public String getColumnName() {
79     		return columnName;
80     	}
81  
82     	public void setColumnName(String columnName) {
83     		this.columnName = columnName;
84     	}
85      
86      @Override
87  	public Boolean getCustomPeer()
88      {
89          return customPeer;
90      }
91  
92      @Override
93  	public void setCustomPeer( Boolean customPeer )
94      {
95          this.customPeer = customPeer;
96      }
97  
98      @Override
99  	public String getPeerClassName()
100     {
101         return peerClassName;
102     }
103 
104     @Override
105 	public void setPeerClassName( String peerClassName )
106     {
107         this.peerClassName = peerClassName;
108     }
109 
110 }