001// Copyright 2009, 2011 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
015package org.apache.tapestry5.ioc.internal;
016
017import java.lang.reflect.Method;
018import java.util.Map;
019
020import org.apache.tapestry5.commons.services.PlasticProxyFactory;
021import org.apache.tapestry5.commons.util.CollectionFactory;
022import org.apache.tapestry5.ioc.MethodAdviceReceiver;
023import org.apache.tapestry5.ioc.ModuleBuilderSource;
024import org.apache.tapestry5.ioc.ServiceAdvisor;
025import org.apache.tapestry5.ioc.ServiceResources;
026import org.apache.tapestry5.ioc.internal.util.InjectionResources;
027import org.apache.tapestry5.ioc.internal.util.MapInjectionResources;
028
029public class ServiceAdvisorImpl extends AbstractMethodInvokingInstrumenter implements ServiceAdvisor
030{
031    public ServiceAdvisorImpl(ModuleBuilderSource moduleSource, Method method, ServiceResources resources,
032            PlasticProxyFactory proxyFactory)
033    {
034        super(moduleSource, method, resources, proxyFactory);
035    }
036
037    /**
038     * Invokes the configured method, passing the builder. The method will always take, as a parameter, a
039     * MethodAdvisor.
040     */
041    @Override
042    public void advise(MethodAdviceReceiver methodAdviceReceiver)
043    {
044        Map<Class, Object> resources = CollectionFactory.newMap(this.resourcesDefaults);
045
046        resources.put(MethodAdviceReceiver.class, methodAdviceReceiver);
047
048        InjectionResources injectionResources = new MapInjectionResources(resources);
049
050        // By design, advise methods return void, so we know that the return value is null.
051
052        invoke(injectionResources);
053    }
054}