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
039 /**
040 * generated.
041 */
042 private static final long serialVersionUID = 2050789495671401625L;
043
044 private final String _serviceName;
045
046 private IEngineService _delegate;
047
048 public EngineServiceOuterProxy(String serviceName)
049 {
050 Defense.notNull(serviceName, "serviceName");
051
052 _serviceName = serviceName;
053 }
054
055 void installDelegate(IEngineService delegate)
056 {
057 _delegate = delegate;
058 }
059
060 IEngineService getDelegate()
061 {
062 return _delegate;
063 }
064
065 public ILink getLink(boolean post, Object parameter)
066 {
067 return _delegate.getLink(post, parameter);
068 }
069
070 public void service(IRequestCycle cycle) throws IOException
071 {
072 _delegate.service(cycle);
073 }
074
075 public String getName()
076 {
077 return _serviceName;
078 }
079
080 public String toString()
081 {
082 return ImplMessages.engineServiceOuterProxyToString(_serviceName);
083 }
084
085 }