|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
VerifyingVisitor.java | 100% | 100% | 100% | 100% |
|
1 |
/*****************************************************************************
|
|
2 |
* Copyright (C) PicoContainer Organization. All rights reserved. *
|
|
3 |
* ------------------------------------------------------------------------- *
|
|
4 |
* The software in this package is published under the terms of the BSD *
|
|
5 |
* style license a copy of which has been included with this distribution in *
|
|
6 |
* the LICENSE.txt file. *
|
|
7 |
*****************************************************************************/
|
|
8 |
package org.picocontainer.defaults;
|
|
9 |
|
|
10 |
import org.picocontainer.ComponentAdapter;
|
|
11 |
import org.picocontainer.Parameter;
|
|
12 |
import org.picocontainer.PicoContainer;
|
|
13 |
import org.picocontainer.PicoVerificationException;
|
|
14 |
import org.picocontainer.PicoVisitor;
|
|
15 |
|
|
16 |
import java.util.ArrayList;
|
|
17 |
import java.util.HashSet;
|
|
18 |
import java.util.List;
|
|
19 |
import java.util.Set;
|
|
20 |
|
|
21 |
|
|
22 |
/**
|
|
23 |
* Visitor to verify {@link PicoContainer}instances. The visitor walks down the logical
|
|
24 |
* container hierarchy.
|
|
25 |
*
|
|
26 |
* @author Jörg Schaible
|
|
27 |
* @since 1.1
|
|
28 |
*/
|
|
29 |
public class VerifyingVisitor |
|
30 |
extends AbstractPicoVisitor {
|
|
31 |
|
|
32 |
private final List nestedVerificationExceptions;
|
|
33 |
private final Set verifiedComponentAdapters;
|
|
34 |
private final PicoVisitor componentAdapterCollector;
|
|
35 |
private PicoContainer currentPico;
|
|
36 |
|
|
37 | 28 |
public VerifyingVisitor() {
|
38 | 28 |
nestedVerificationExceptions = new ArrayList();
|
39 | 28 |
verifiedComponentAdapters = new HashSet();
|
40 | 28 |
componentAdapterCollector = new ComponentAdapterCollector();
|
41 |
} |
|
42 |
|
|
43 |
/**
|
|
44 |
* Traverse through all components of the {@link PicoContainer} hierarchy and verify the
|
|
45 |
* components.
|
|
46 |
*
|
|
47 |
* @throws PicoVerificationException if some components could not be verified.
|
|
48 |
* @see org.picocontainer.PicoVisitor#traverse(java.lang.Object)
|
|
49 |
*/
|
|
50 | 28 |
public Object traverse(Object node) throws PicoVerificationException { |
51 | 28 |
nestedVerificationExceptions.clear(); |
52 | 28 |
verifiedComponentAdapters.clear(); |
53 | 28 |
try {
|
54 | 28 |
super.traverse(node);
|
55 | 22 |
if (!nestedVerificationExceptions.isEmpty()) {
|
56 | 14 |
throw new PicoVerificationException(new ArrayList(nestedVerificationExceptions)); |
57 |
} |
|
58 |
} finally {
|
|
59 | 28 |
nestedVerificationExceptions.clear(); |
60 | 28 |
verifiedComponentAdapters.clear(); |
61 |
} |
|
62 | 8 |
return Void.TYPE;
|
63 |
} |
|
64 |
|
|
65 |
/**
|
|
66 |
* {@inheritDoc}
|
|
67 |
*
|
|
68 |
* @see org.picocontainer.PicoVisitor#visitContainer(org.picocontainer.PicoContainer)
|
|
69 |
*/
|
|
70 | 20 |
public void visitContainer(PicoContainer pico) { |
71 | 20 |
checkTraversal(); |
72 | 18 |
currentPico = pico; |
73 |
} |
|
74 |
|
|
75 |
/**
|
|
76 |
* {@inheritDoc}
|
|
77 |
*
|
|
78 |
* @see org.picocontainer.PicoVisitor#visitComponentAdapter(org.picocontainer.ComponentAdapter)
|
|
79 |
*/
|
|
80 | 82 |
public void visitComponentAdapter(ComponentAdapter componentAdapter) { |
81 | 82 |
checkTraversal(); |
82 | 82 |
if (!verifiedComponentAdapters.contains(componentAdapter)) {
|
83 | 34 |
try {
|
84 | 34 |
componentAdapter.verify(currentPico); |
85 |
} catch (RuntimeException e) {
|
|
86 | 26 |
nestedVerificationExceptions.add(e); |
87 |
} |
|
88 | 34 |
componentAdapter.accept(componentAdapterCollector); |
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
/**
|
|
93 |
* {@inheritDoc}
|
|
94 |
*
|
|
95 |
* @see org.picocontainer.PicoVisitor#visitParameter(org.picocontainer.Parameter)
|
|
96 |
*/
|
|
97 | 4 |
public void visitParameter(Parameter parameter) { |
98 | 4 |
checkTraversal(); |
99 |
} |
|
100 |
|
|
101 |
private class ComponentAdapterCollector |
|
102 |
implements PicoVisitor {
|
|
103 |
///CLOVER:OFF
|
|
104 |
public Object traverse(Object node) {
|
|
105 |
return null; |
|
106 |
} |
|
107 |
|
|
108 |
public void visitContainer(PicoContainer pico) { |
|
109 |
} |
|
110 |
|
|
111 |
///CLOVER:ON
|
|
112 |
|
|
113 | 82 |
public void visitComponentAdapter(ComponentAdapter componentAdapter) { |
114 | 82 |
verifiedComponentAdapters.add(componentAdapter); |
115 |
} |
|
116 |
|
|
117 | 4 |
public void visitParameter(Parameter parameter) { |
118 |
} |
|
119 |
} |
|
120 |
} |
|
121 |
|
|