001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *  http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package org.apache.directory.server.protocol.shared;
020    
021    
022    import org.apache.directory.server.core.DirectoryService;
023    import org.apache.directory.server.protocol.shared.transport.Transport;
024    import org.apache.mina.transport.socket.DatagramAcceptor;
025    import org.apache.mina.transport.socket.SocketAcceptor;
026    
027    
028    /**
029     * An abstract base class for a ProtocolService. The start/stop methods have
030     * not been implemented.
031     * 
032     * @org.apache.xbean.XBean
033     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034     * @version $Rev$, $Date$
035     */
036    public abstract class AbstractProtocolService implements ProtocolService
037    {
038        /** A flag set to indicate if the server is started or not */ 
039        private boolean started;
040        
041        /** A flag set to tell if the server is enabled or not */
042        private boolean enabled;
043        
044        /** The server ID */
045        private String serviceId;
046        
047        /** The service name */
048        private String serviceName;
049        
050        /** The service transports. We may have more than one */
051        protected Transport[] transports;
052        
053        /** directory service core where protocol data is backed */
054        private DirectoryService directoryService;
055    
056    
057        public DirectoryService getDirectoryService()
058        {
059            return directoryService;
060        }
061    
062    
063        /**
064         * @org.apache.xbean.Property hidden="true"
065         */
066        public void setDirectoryService( DirectoryService directoryService )
067        {
068            this.directoryService = directoryService;
069        }
070    
071    
072        public boolean isStarted()
073        {
074            return started;
075        }
076    
077    
078        /**
079         * @org.apache.xbean.Property hidden="true"
080         * 
081         * @param started The state of this server
082         */
083        protected void setStarted( boolean started )
084        {
085            this.started = started;
086        }
087    
088    
089        public boolean isEnabled()
090        {
091            return enabled;
092        }
093    
094    
095        /**
096         * {@inheritDoc}
097         */
098        public void setEnabled( boolean enabled )
099        {
100            this.enabled = enabled;
101        }
102    
103    
104        public String getServiceId()
105        {
106            return serviceId;
107        }
108    
109    
110        /**
111         * @org.apache.xbean.Property hidden="true"
112         */
113        public void setServiceId( String serviceId )
114        {
115            this.serviceId = serviceId;
116        }
117    
118    
119        /**
120         * @return The server name
121         */
122        public String getServiceName()
123        {
124            return serviceName;
125        }
126    
127    
128        /**
129         * @org.apache.xbean.Property hidden="true"
130         * 
131         * Set the current server's name.
132         * @param name The server name
133         */
134        public void setServiceName( String name )
135        {
136            this.serviceName = name;
137        }
138        
139        
140        /**
141         * @return the transport
142         */
143        public Transport[] getTransports()
144        {
145            return transports;
146        }
147    
148    
149        /**
150         * Set the underlying transports
151         * @param transport The transports
152         */
153        public void setTransports( Transport... transports )
154        {
155            if ( transports != null ) 
156            {
157                this.transports = new Transport[ transports.length ];
158                System.arraycopy( transports, 0, this.transports, 0, transports.length );
159                
160                for ( Transport transport:transports )
161                {
162                    if ( transport.getAcceptor() == null )
163                    {
164                        transport.init();
165                    }
166                }
167            }
168        }
169        
170        
171        /**
172         * {@inheritDoc}
173         */
174        public DatagramAcceptor getDatagramAcceptor( Transport udpTransport )
175        {
176            return (DatagramAcceptor)udpTransport.getAcceptor();
177        }
178    
179    
180        /**
181         * {@inheritDoc}
182         */
183        public SocketAcceptor getSocketAcceptor( Transport tcpTransport )
184        {
185            return (SocketAcceptor)tcpTransport.getAcceptor();
186        }
187    }