1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.doxia.sink.impl; 20 21 import java.lang.reflect.InvocationHandler; 22 import java.lang.reflect.InvocationTargetException; 23 import java.lang.reflect.Method; 24 import java.lang.reflect.Proxy; 25 import java.util.List; 26 27 import org.apache.maven.doxia.sink.Sink; 28 29 /** 30 * May be used to invoke the same method on a List of Sinks. 31 * @deprecated Use the {@link SinkWrapper} approach which doesn't require the use of dynamic proxies. 32 * 33 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> 34 * @see SinkWrapper 35 */ 36 @Deprecated 37 public class PipelineSink implements InvocationHandler { 38 private List<Sink> pipeline; 39 40 /** 41 * Constructs a PipelineSink for a given List of Sinks. 42 * 43 * @param pipeline A List of Sinks. 44 */ 45 public PipelineSink(List<Sink> pipeline) { 46 this.pipeline = pipeline; 47 } 48 49 /** 50 * Add a Sink to the List of Sinks. 51 * 52 * @param sink the Sink to add. 53 */ 54 public void addSink(Sink sink) { 55 pipeline.add(sink); 56 } 57 58 /** 59 * {@inheritDoc} 60 * 61 * Invoke a Method on this PipelineSink. 62 * 63 * @throws IllegalAccessException if any. 64 * @throws InvocationTargetException if any. 65 * @param proxy a {@link java.lang.Object} object. 66 * @param method a {@link java.lang.reflect.Method} object. 67 * @param args an array of {@link java.lang.Object} objects. 68 * @return a {@link java.lang.Object} object. 69 */ 70 public Object invoke(Object proxy, Method method, Object[] args) 71 throws IllegalAccessException, InvocationTargetException { 72 for (Sink sink : pipeline) { 73 method.invoke(sink, args); 74 } 75 76 return null; 77 } 78 79 /** 80 * Returns an instance of a PipelineSink as a Sink. 81 * 82 * @param pipeline A List of Sinks. 83 * @return a {@link org.apache.maven.doxia.sink.Sink} object. 84 */ 85 public static Sink newInstance(List<Sink> pipeline) { 86 return (Sink) Proxy.newProxyInstance( 87 PipelineSink.class.getClassLoader(), new Class<?>[] {Sink.class}, new PipelineSink(pipeline)); 88 } 89 }