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.TorqueAbstractGroupManager;
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/**
030 * This implementation persists to a database via Torque.
031 *
032 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
033 * @version $Id:$
034 */
035public abstract class PeerGroupManager extends TorqueAbstractGroupManager implements PeerManagable
036{
037    
038    private Boolean customPeer = false;  //  used for torque which uses per object peer classes
039    private String peerClassName;
040    transient PeerManager peerManager;
041    private static final String PEER_CLASS_NAME_KEY = "peerClassName";
042    
043    private String columnName = "GROUP_NAME";
044    
045    /**
046     * Avalon Service lifecycle method
047     */
048    @Override
049        public void configure(Configuration conf) throws ConfigurationException
050    {
051       super.configure( conf );
052       
053        peerClassName = conf.getChild( PEER_CLASS_NAME_KEY).getValue( null );
054        if (peerClassName != null) {
055            setPeerClassName( peerClassName );
056            setCustomPeer(true);
057        } 
058    }
059    
060    @Override
061        public Peer getPeerInstance() throws DataBackendException {
062           return getPeerManager().getPeerInstance(getPeerClassName(), TorqueTurbinePeer.class, getClassName());
063    }
064       
065       /**
066        * @return Returns the persistenceHelper.
067        */
068       @Override
069        public PeerManager getPeerManager()
070       {
071           if (peerManager == null)
072           {
073               peerManager = (PeerManager) resolve(PeerManager.ROLE);
074           }
075           return peerManager;
076       }
077
078        public String getColumnName() {
079                return columnName;
080        }
081
082        public void setColumnName(String columnName) {
083                this.columnName = columnName;
084        }
085    
086    @Override
087        public Boolean getCustomPeer()
088    {
089        return customPeer;
090    }
091
092    @Override
093        public void setCustomPeer( Boolean customPeer )
094    {
095        this.customPeer = customPeer;
096    }
097
098    @Override
099        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}