Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PipelineSink |
|
| 1.25;1,25 |
1 | package org.apache.maven.doxia.sink; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.lang.reflect.InvocationHandler; | |
23 | import java.lang.reflect.InvocationTargetException; | |
24 | import java.lang.reflect.Method; | |
25 | import java.lang.reflect.Proxy; | |
26 | ||
27 | import java.util.List; | |
28 | ||
29 | /** | |
30 | * May be used to invoke the same method on a List of Sinks. | |
31 | * | |
32 | * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> | |
33 | * @version $Id: PipelineSink.java 1185112 2011-10-17 11:33:00Z ltheussl $ | |
34 | */ | |
35 | public class PipelineSink | |
36 | implements InvocationHandler | |
37 | { | |
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 | 0 | { |
47 | 0 | this.pipeline = pipeline; |
48 | 0 | } |
49 | ||
50 | /** | |
51 | * Add a Sink to the List of Sinks. | |
52 | * | |
53 | * @param sink the Sink to add. | |
54 | */ | |
55 | public void addSink( Sink sink ) | |
56 | { | |
57 | 0 | pipeline.add( sink ); |
58 | 0 | } |
59 | ||
60 | /** | |
61 | * {@inheritDoc} | |
62 | * | |
63 | * Invoke a Method on this PipelineSink. | |
64 | * | |
65 | * @throws IllegalAccessException if any. | |
66 | * @throws InvocationTargetException if any. | |
67 | */ | |
68 | public Object invoke( Object proxy, Method method, Object[] args ) | |
69 | throws IllegalAccessException, InvocationTargetException | |
70 | { | |
71 | 0 | for ( Sink sink : pipeline ) |
72 | { | |
73 | 0 | method.invoke( sink, args ); |
74 | } | |
75 | ||
76 | 0 | 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 | { | |
87 | 0 | return (Sink) Proxy.newProxyInstance( PipelineSink.class.getClassLoader(), |
88 | new Class<?>[]{Sink.class}, | |
89 | new PipelineSink( pipeline ) ); | |
90 | } | |
91 | } |