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    import java.io.Serializable;
019    
020    import org.apache.hivemind.util.Defense;
021    import org.apache.tapestry.IRequestCycle;
022    import org.apache.tapestry.engine.IEngineService;
023    import org.apache.tapestry.engine.ILink;
024    
025    /**
026     * Outer proxy for engine services. The inner proxy resolves the engine service name to a engine
027     * service implementation and installed it into the outer proxy as a delegate. Although HiveMind
028     * does provide a similar system of inner and outer delegates, Tapestry's engine-service:
029     * {@link org.apache.tapestry.services.impl.EngineServiceObjectProvider} object provider can
030     * cause exceptions (recurive service build) when attempting to link two services together. This
031     * extra layer of proxying resolves that issue.
032     * 
033     * @author Howard M. Lewis Ship
034     * @since 4.0
035     */
036    public class EngineServiceOuterProxy implements IEngineService, Serializable
037    {
038        private final String _serviceName;
039    
040        private IEngineService _delegate;
041    
042        public EngineServiceOuterProxy(String serviceName)
043        {
044            Defense.notNull(serviceName, "serviceName");
045    
046            _serviceName = serviceName;
047        }
048    
049        void installDelegate(IEngineService delegate)
050        {
051            _delegate = delegate;
052        }
053    
054        IEngineService getDelegate()
055        {
056            return _delegate;
057        }
058    
059        public ILink getLink(boolean post, Object parameter)
060        {
061            return _delegate.getLink(post, parameter);
062        }
063    
064        public void service(IRequestCycle cycle) throws IOException
065        {
066            _delegate.service(cycle);
067        }
068    
069        public String getName()
070        {
071            return _serviceName;
072        }
073    
074        public String toString()
075        {
076            return ImplMessages.engineServiceOuterProxyToString(_serviceName);
077        }
078    
079    }