001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    
019    package org.apache.geronimo.jetty6.handler;
020    
021    import org.mortbay.jetty.Handler;
022    import org.mortbay.jetty.HandlerContainer;
023    import org.mortbay.jetty.Server;
024    import org.mortbay.jetty.handler.AbstractHandler;
025    import org.mortbay.jetty.handler.AbstractHandlerContainer;
026    
027    /**
028     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
029     */
030    public abstract class AbstractImmutableHandler implements Handler /*extends AbstractHandlerContainer*/ {
031        protected final Handler next;
032    
033        protected AbstractImmutableHandler(Handler next) {
034            this.next = next;
035        }
036    
037        protected void doStart() throws Exception {
038            next.start();
039        }
040    
041        protected void doStop() throws Exception {
042            next.stop();
043        }
044    
045        public void setServer(Server server) {
046    //        super.setServer(server);
047            next.setServer(server);
048        }
049    
050        public Server getServer() {
051            return next.getServer();
052        }
053    
054        public void destroy() {
055            next.destroy();
056        }
057    
058        public void lifecycleCommand(LifecycleCommand lifecycleCommand) throws Exception {
059            if (next instanceof AbstractImmutableHandler) {
060                ((AbstractImmutableHandler) next).lifecycleCommand(lifecycleCommand);
061            } else {
062                lifecycleCommand.lifecycleMethod();
063            }
064        }
065    
066    
067        public void addHandler(Handler handler) {
068            if (next instanceof HandlerContainer) {
069                ((HandlerContainer) next).addHandler(handler);
070            } else {
071                throw new RuntimeException("geronimo HandlerContainers are immutable");
072            }
073        }
074    
075        /**
076         * this is basically the implementation from HandlerWrapper.
077         * @param list partial list of handlers matching byClass (may be null)
078         * @param byClass class of the handlers we want
079         * @return extended list of handlers matching byClass
080         */
081        protected Object expandChildren(Object list, Class byClass)
082        {
083    //        return expandHandler(next, list, byClass);
084            return null;
085        }
086    
087        public void start() throws Exception {
088            next.start();
089        }
090    
091        public void stop() throws Exception {
092            next.stop();
093        }
094    
095        public boolean isRunning() {
096            return next.isRunning();
097        }
098    
099        public boolean isStarted() {
100            return next.isStarted();
101        }
102    
103        public boolean isStarting() {
104            return next.isStarting();
105        }
106    
107        public boolean isStopping() {
108            return next.isStopping();
109        }
110    
111        public boolean isStopped() {
112            return next.isStopped();
113        }
114    
115        public boolean isFailed() {
116            return false;
117        }
118    }