001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.services.impl;
016    
017    import java.io.IOException;
018    
019    import org.apache.hivemind.util.Defense;
020    import org.apache.tapestry.IRequestCycle;
021    import org.apache.tapestry.engine.IEngineService;
022    import org.apache.tapestry.engine.ILink;
023    
024    /**
025     * Inner proxy that actually resolves the engine service using the
026     * {@link org.apache.tapestry.services.impl.EngineServiceSource}, then replaces itself in the outer
027     * proxy.
028     * 
029     * @author Howard M. Lewis Ship
030     * @since 4.0
031     * @see org.apache.tapestry.services.impl.EngineServiceOuterProxy
032     */
033    public class EngineServiceInnerProxy implements IEngineService
034    {
035        private final String _serviceName;
036    
037        private final EngineServiceOuterProxy _outerProxy;
038    
039        private final EngineServiceSource _source;
040    
041        public EngineServiceInnerProxy(String serviceName, EngineServiceOuterProxy outerProxy,
042                EngineServiceSource source)
043        {
044            Defense.notNull(serviceName, "serviceName");
045            Defense.notNull(outerProxy, "outerProxy");
046            Defense.notNull(source, "source");
047    
048            _serviceName = serviceName;
049            _outerProxy = outerProxy;
050            _source = source;
051        }
052    
053        public String toString()
054        {
055            return ImplMessages.engineServiceInnerProxyToString(_serviceName);
056        }
057    
058        private IEngineService resolve()
059        {
060            IEngineService service = _source.resolveEngineService(_serviceName);
061    
062            _outerProxy.installDelegate(service);
063    
064            return service;
065        }
066    
067        public synchronized ILink getLink(IRequestCycle cycle, boolean post, Object parameter)
068        {
069            return resolve().getLink(cycle, false, parameter);
070        }
071    
072        public synchronized void service(IRequestCycle cycle) throws IOException
073        {
074            resolve().service(cycle);
075        }
076    
077        public String getName()
078        {
079            return _serviceName;
080        }
081    
082    }