001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.doxia.sink.impl; 020 021import java.lang.reflect.InvocationHandler; 022import java.lang.reflect.InvocationTargetException; 023import java.lang.reflect.Method; 024import java.lang.reflect.Proxy; 025import java.util.List; 026 027import org.apache.maven.doxia.sink.Sink; 028 029/** 030 * May be used to invoke the same method on a List of Sinks. 031 * @deprecated Use the {@link SinkWrapper} approach which doesn't require the use of dynamic proxies. 032 * 033 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> 034 * @see SinkWrapper 035 */ 036@Deprecated 037public class PipelineSink implements InvocationHandler { 038 private List<Sink> pipeline; 039 040 /** 041 * Constructs a PipelineSink for a given List of Sinks. 042 * 043 * @param pipeline A List of Sinks. 044 */ 045 public PipelineSink(List<Sink> pipeline) { 046 this.pipeline = pipeline; 047 } 048 049 /** 050 * Add a Sink to the List of Sinks. 051 * 052 * @param sink the Sink to add. 053 */ 054 public void addSink(Sink sink) { 055 pipeline.add(sink); 056 } 057 058 /** 059 * {@inheritDoc} 060 * 061 * Invoke a Method on this PipelineSink. 062 * 063 * @throws IllegalAccessException if any. 064 * @throws InvocationTargetException if any. 065 * @param proxy a {@link java.lang.Object} object. 066 * @param method a {@link java.lang.reflect.Method} object. 067 * @param args an array of {@link java.lang.Object} objects. 068 * @return a {@link java.lang.Object} object. 069 */ 070 public Object invoke(Object proxy, Method method, Object[] args) 071 throws IllegalAccessException, InvocationTargetException { 072 for (Sink sink : pipeline) { 073 method.invoke(sink, args); 074 } 075 076 return null; 077 } 078 079 /** 080 * Returns an instance of a PipelineSink as a Sink. 081 * 082 * @param pipeline A List of Sinks. 083 * @return a {@link org.apache.maven.doxia.sink.Sink} object. 084 */ 085 public static Sink newInstance(List<Sink> pipeline) { 086 return (Sink) Proxy.newProxyInstance( 087 PipelineSink.class.getClassLoader(), new Class<?>[] {Sink.class}, new PipelineSink(pipeline)); 088 } 089}