    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
    015    package org.apache.tapestry5.ioc.internal;
    016
    017    import java.lang.reflect.Method;
    018    import java.util.Map;
    019
    020    import org.apache.tapestry5.ioc.MethodAdviceReceiver;
    021    import org.apache.tapestry5.ioc.ModuleBuilderSource;
    022    import org.apache.tapestry5.ioc.ServiceAdvisor;
    023    import org.apache.tapestry5.ioc.ServiceResources;
    024    import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
    025    import org.apache.tapestry5.ioc.internal.util.InjectionResources;
    026    import org.apache.tapestry5.ioc.internal.util.MapInjectionResources;
    027    import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
    028
    029    public 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        public void advise(MethodAdviceReceiver methodAdviceReceiver)
    042        {
    043            Map<Class, Object> resources = CollectionFactory.newMap(this.resourcesDefaults);
    044
    045            resources.put(MethodAdviceReceiver.class, methodAdviceReceiver);
    046
    047            InjectionResources injectionResources = new MapInjectionResources(resources);
    048
    049            // By design, advise methods return void, so we know that the return value is null.
    050
    051            invoke(injectionResources);
    052        }
    053    }