001package org.apache.fulcrum.security.torque.peer.managers;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020import org.apache.avalon.framework.configuration.Configuration;
021import org.apache.avalon.framework.configuration.ConfigurationException;
022import org.apache.fulcrum.security.torque.TorqueAbstractRoleManager;
023import org.apache.fulcrum.security.torque.peer.Peer;
024import org.apache.fulcrum.security.torque.peer.PeerManagable;
025import org.apache.fulcrum.security.torque.peer.PeerManager;
026import org.apache.fulcrum.security.torque.peer.TorqueTurbinePeer;
027import org.apache.fulcrum.security.util.DataBackendException;
028/**
029 * This implementation persists to a database via Torque.
030 *
031 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
032 * @version $Id:$
033 */
034public abstract class PeerRoleManager extends TorqueAbstractRoleManager implements PeerManagable
035{
036    private Boolean customPeer = false;  //  used for torque which uses per object peer classes
037    
038    private String peerClassName;
039    private static final String PEER_CLASS_NAME_KEY = "peerClassName";
040    transient PeerManager peerManager;
041    
042    private String columnName = "ROLE_NAME";
043    
044    /**
045     * Avalon Service lifecycle method
046     */
047    @Override
048        public void configure(Configuration conf) throws ConfigurationException
049    {
050       super.configure( conf );
051       
052//       peerClassName = conf.getChild( PEER_CLASS_NAME_KEY).getValue( "org.apache.fulcrum.security.torque.om.TorqueTurbineRolePeer" );
053        peerClassName = conf.getChild( PEER_CLASS_NAME_KEY).getValue( null );
054        if (peerClassName != null) {
055            setPeerClassName( peerClassName );
056            setCustomPeer(true);
057        } 
058    }
059   
060    
061    @Override
062        public Peer getPeerInstance() throws DataBackendException {
063        return getPeerManager().getPeerInstance(getPeerClassName(), TorqueTurbinePeer.class, getClassName());
064    }
065    
066    /**
067     * @return Returns the persistenceHelper.
068     */
069    @Override
070        public PeerManager getPeerManager()
071    {
072        if (peerManager == null)
073        {
074            peerManager = (PeerManager) resolve(PeerManager.ROLE);
075        }
076        return peerManager;
077    }
078    
079        public String getColumnName() {
080                return columnName;
081        }
082
083        public void setColumnName(String columnName) {
084                this.columnName = columnName;
085        }
086
087    
088        @Override
089        public Boolean getCustomPeer()
090    {
091        return customPeer;
092    }
093
094    @Override
095        public void setCustomPeer( Boolean customPeer )
096    {
097        this.customPeer = customPeer;
098    }
099
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}