| 1 | |
package org.jbehave.core.configuration.weld; |
| 2 | |
|
| 3 | |
import java.util.List; |
| 4 | |
|
| 5 | |
import org.jbehave.core.annotations.weld.UsingWeld; |
| 6 | |
import org.jbehave.core.configuration.AnnotationBuilder; |
| 7 | |
import org.jbehave.core.configuration.AnnotationFinder; |
| 8 | |
import org.jbehave.core.configuration.AnnotationMonitor; |
| 9 | |
import org.jbehave.core.configuration.AnnotationRequired; |
| 10 | |
import org.jbehave.core.configuration.Configuration; |
| 11 | |
import org.jbehave.core.configuration.PrintStreamAnnotationMonitor; |
| 12 | |
import org.jbehave.core.steps.CandidateSteps; |
| 13 | |
import org.jbehave.core.steps.InjectableStepsFactory; |
| 14 | |
import org.jbehave.core.steps.ParameterConverters; |
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
public class WeldAnnotationBuilder extends AnnotationBuilder { |
| 23 | |
|
| 24 | |
private Configuration configuration; |
| 25 | |
private InjectableStepsFactory stepsFactory; |
| 26 | |
|
| 27 | |
public WeldAnnotationBuilder(Class<?> annotatedClass) { |
| 28 | 27 | this(annotatedClass, new PrintStreamAnnotationMonitor()); |
| 29 | 27 | } |
| 30 | |
|
| 31 | |
public WeldAnnotationBuilder(Class<?> annotatedClass, AnnotationMonitor annotationMonitor) { |
| 32 | 27 | super(annotatedClass, annotationMonitor); |
| 33 | 27 | } |
| 34 | |
|
| 35 | |
public WeldAnnotationBuilder(Class<?> annotatedClass, Configuration configuration, |
| 36 | |
InjectableStepsFactory stepsFactory) { |
| 37 | 27 | this(annotatedClass); |
| 38 | 27 | this.configuration = configuration; |
| 39 | 27 | this.stepsFactory = stepsFactory; |
| 40 | 27 | } |
| 41 | |
|
| 42 | |
@Override |
| 43 | |
public Configuration buildConfiguration() throws AnnotationRequired { |
| 44 | 8 | AnnotationFinder finder = annotationFinder(); |
| 45 | 8 | if (finder.isAnnotationPresent(UsingWeld.class)) { |
| 46 | 6 | if (configuration == null) { |
| 47 | 0 | return super.buildConfiguration(); |
| 48 | |
} |
| 49 | 6 | return configuration; |
| 50 | |
} else { |
| 51 | 2 | annotationMonitor().annotationNotFound(UsingWeld.class, annotatedClass()); |
| 52 | |
} |
| 53 | 2 | return super.buildConfiguration(); |
| 54 | |
} |
| 55 | |
|
| 56 | |
@Override |
| 57 | |
public List<CandidateSteps> buildCandidateSteps(Configuration configuration) { |
| 58 | 3 | List<CandidateSteps> steps = super.buildCandidateSteps(configuration); |
| 59 | 3 | if (stepsFactory != null) { |
| 60 | 3 | steps.addAll(0, stepsFactory.createCandidateSteps()); |
| 61 | |
} |
| 62 | 3 | return steps; |
| 63 | |
} |
| 64 | |
|
| 65 | |
@Override |
| 66 | |
protected ParameterConverters parameterConverters(AnnotationFinder annotationFinder) { |
| 67 | 0 | ParameterConverters converters = super.parameterConverters(annotationFinder); |
| 68 | 0 | return converters; |
| 69 | |
} |
| 70 | |
} |