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 * Inner proxy that actually resolves the engine service using the 027 * {@link org.apache.tapestry.services.impl.EngineServiceSource}, then replaces itself in the outer 028 * proxy. 029 * 030 * @author Howard M. Lewis Ship 031 * @since 4.0 032 * @see org.apache.tapestry.services.impl.EngineServiceOuterProxy 033 */ 034 public class EngineServiceInnerProxy implements IEngineService, Serializable 035 { 036 private static final long serialVersionUID = -8128030027597659447L; 037 038 private final String _serviceName; 039 040 private final EngineServiceOuterProxy _outerProxy; 041 042 private final EngineServiceSource _source; 043 044 public EngineServiceInnerProxy(String serviceName, EngineServiceOuterProxy outerProxy, 045 EngineServiceSource source) 046 { 047 Defense.notNull(serviceName, "serviceName"); 048 Defense.notNull(outerProxy, "outerProxy"); 049 Defense.notNull(source, "source"); 050 051 _serviceName = serviceName; 052 _outerProxy = outerProxy; 053 _source = source; 054 } 055 056 public String toString() 057 { 058 return ImplMessages.engineServiceInnerProxyToString(_serviceName); 059 } 060 061 private IEngineService resolve() 062 { 063 IEngineService service = _source.resolveEngineService(_serviceName); 064 065 _outerProxy.installDelegate(service); 066 067 return service; 068 } 069 070 public synchronized ILink getLink(boolean post, Object parameter) 071 { 072 return resolve().getLink(post, parameter); 073 } 074 075 public synchronized void service(IRequestCycle cycle) throws IOException 076 { 077 resolve().service(cycle); 078 } 079 080 public String getName() 081 { 082 return _serviceName; 083 } 084 085 }