Skip to content

Commit fd382e7

Browse files
committed
Added weight to all handlers, fixed usage of RuleBuilder.when() and perform() (see #64)
1 parent b7b0d6c commit fd382e7

15 files changed

Lines changed: 121 additions & 49 deletions

File tree

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/ForwardToHandler.java‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import org.ocpsoft.prettyfaces.annotation.ForwardTo;
66
import org.ocpsoft.rewrite.annotation.api.ClassContext;
77
import org.ocpsoft.rewrite.annotation.spi.AnnotationHandler;
8-
import org.ocpsoft.rewrite.config.OperationBuilder;
9-
import org.ocpsoft.rewrite.config.RuleBuilder;
108
import org.ocpsoft.rewrite.servlet.config.Forward;
119

1210
public class ForwardToHandler implements AnnotationHandler<ForwardTo>
@@ -19,14 +17,14 @@ public Class<ForwardTo> handles()
1917
}
2018

2119
@Override
22-
public void process(ClassContext context, AnnotatedElement element, ForwardTo annotation)
20+
public int priority()
2321
{
24-
25-
RuleBuilder ruleBuilder = context.getRuleBuilder();
26-
27-
// add new operation to the rule
28-
OperationBuilder operation = ruleBuilder.getOperationBuilder().and(Forward.to(annotation.value()));
29-
ruleBuilder.perform(operation);
22+
return HandlerConstants.WEIGHT_TYPE_STRUCTURAL;
3023
}
3124

25+
@Override
26+
public void process(ClassContext context, AnnotatedElement element, ForwardTo annotation)
27+
{
28+
context.getRuleBuilder().perform(Forward.to(annotation.value()));
29+
}
3230
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.ocpsoft.prettyfaces.annotation.handlers;
2+
3+
public class HandlerConstants
4+
{
5+
6+
/**
7+
* Suggested weight for handlers which build the basic structure of the rule. This is for example the case for
8+
* handlers that define the rule itself, add parameter bindings or operations.
9+
*/
10+
public static final int WEIGHT_TYPE_STRUCTURAL = 100;
11+
12+
/**
13+
* Suggested weight for handlers which enrich the structure built by other handlers. Typical examples are handles
14+
* that add conditions to the rule or that add validation or conversion to parameter bindings.
15+
*/
16+
public static final int WEIGHT_TYPE_ENRICHING = 200;
17+
18+
}

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/HostnameHandler.java‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@
55
import org.ocpsoft.prettyfaces.annotation.Hostname;
66
import org.ocpsoft.rewrite.annotation.api.ClassContext;
77
import org.ocpsoft.rewrite.annotation.spi.AnnotationHandler;
8-
import org.ocpsoft.rewrite.config.ConditionBuilder;
98
import org.ocpsoft.rewrite.servlet.config.Domain;
109

1110
public class HostnameHandler implements AnnotationHandler<Hostname>
1211
{
1312

14-
@Override
15-
public Class<Hostname> handles()
16-
{
17-
return Hostname.class;
18-
}
13+
@Override
14+
public Class<Hostname> handles()
15+
{
16+
return Hostname.class;
17+
}
1918

20-
@Override
21-
public void process(ClassContext context, AnnotatedElement element, Hostname annotation)
22-
{
23-
Domain domain = Domain.matches(annotation.value());
24-
ConditionBuilder condition = context.getRuleBuilder().getConditionBuilder().and(domain);
25-
context.getRuleBuilder().when(condition);
26-
}
19+
@Override
20+
public int priority()
21+
{
22+
return HandlerConstants.WEIGHT_TYPE_ENRICHING;
23+
}
24+
25+
@Override
26+
public void process(ClassContext context, AnnotatedElement element, Hostname annotation)
27+
{
28+
context.getRuleBuilder().when(Domain.matches(annotation.value()));
29+
}
2730
}

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/JSFConverterHandler.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public Class<JSFConverter> handles()
2929
return JSFConverter.class;
3030
}
3131

32+
@Override
33+
public int priority()
34+
{
35+
return HandlerConstants.WEIGHT_TYPE_ENRICHING;
36+
}
37+
3238
@Override
3339
@SuppressWarnings({ "rawtypes", "unchecked" })
3440
public void process(FieldContext context, Field field, JSFConverter annotation)

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/JSFValidatorHandler.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public Class<JSFValidator> handles()
3535
return JSFValidator.class;
3636
}
3737

38+
@Override
39+
public int priority()
40+
{
41+
return HandlerConstants.WEIGHT_TYPE_ENRICHING;
42+
}
43+
3844
@Override
3945
@SuppressWarnings({ "rawtypes", "unchecked" })
4046
public void process(FieldContext context, Field field, JSFValidator annotation)

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/JoinHandler.java‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.ocpsoft.prettyfaces.annotation.Join;
66
import org.ocpsoft.rewrite.annotation.api.ClassContext;
77
import org.ocpsoft.rewrite.annotation.spi.AnnotationHandler;
8-
import org.ocpsoft.rewrite.servlet.config.rule.IJoin;
98

109
public class JoinHandler implements AnnotationHandler<Join>
1110
{
@@ -17,15 +16,17 @@ public Class<Join> handles()
1716
}
1817

1918
@Override
20-
public void process(ClassContext context, AnnotatedElement element, Join annotation)
19+
public int priority()
2120
{
21+
return HandlerConstants.WEIGHT_TYPE_STRUCTURAL;
22+
}
2223

23-
IJoin join = org.ocpsoft.rewrite.servlet.config.rule.Join
24+
@Override
25+
public void process(ClassContext context, AnnotatedElement element, Join annotation)
26+
{
27+
context.setBaseRule(org.ocpsoft.rewrite.servlet.config.rule.Join
2428
.path(annotation.path())
25-
.to(annotation.to());
26-
27-
context.setBaseRule(join);
28-
29+
.to(annotation.to()));
2930
}
3031

3132
}

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/MappingIdHandler.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public Class<MappingId> handles()
1515
return MappingId.class;
1616
}
1717

18+
@Override
19+
public int priority()
20+
{
21+
return HandlerConstants.WEIGHT_TYPE_ENRICHING;
22+
}
23+
1824
@Override
1925
public void process(ClassContext context, AnnotatedElement element, MappingId annotation)
2026
{

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/ParameterBindingHandler.java‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public Class<ParameterBinding> handles()
2727
return ParameterBinding.class;
2828
}
2929

30+
@Override
31+
public int priority()
32+
{
33+
return HandlerConstants.WEIGHT_TYPE_STRUCTURAL;
34+
}
35+
3036
@Override
3137
public void process(FieldContext context, Field field, ParameterBinding annotation)
3238
{
@@ -68,6 +74,7 @@ public AddBindingVisitor(FieldContext context, String paramName, Field field)
6874
@SuppressWarnings("rawtypes")
6975
public void visit(Condition condition)
7076
{
77+
7178
if (condition instanceof Parameterized) {
7279
Parameterized parameterized = (Parameterized) condition;
7380

@@ -104,15 +111,15 @@ else if (beforePhase != null && afterPhase == null) {
104111
context.setBindingBuilder(elBinding);
105112

106113
if (log.isDebugEnabled()) {
107-
log.debug("Added binding for parameter [{}] to: {}", param, parameterized);
114+
log.debug("Added binding for parameter [{}] to: {}", param, parameterized.getClass().getSimpleName());
108115
}
109116

110117
}
111118

112-
// TODO: does not work correct. Never thrown?
119+
// parameter does not exist
113120
catch (IllegalArgumentException e) {
114121
if (log.isTraceEnabled()) {
115-
log.trace("Parameter [{}] not found on: {}", param, parameterized);
122+
log.trace("Parameter [{}] not found on: {}", param, parameterized.getClass().getSimpleName());
116123
}
117124
}
118125

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/PriorityHandler.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public Class<Priority> handles()
1515
return Priority.class;
1616
}
1717

18+
@Override
19+
public int priority()
20+
{
21+
return HandlerConstants.WEIGHT_TYPE_ENRICHING;
22+
}
23+
1824
@Override
1925
public void process(ClassContext context, AnnotatedElement element, Priority annotation)
2026
{

‎annotations/src/main/java/org/ocpsoft/prettyfaces/annotation/handlers/QueryParameterBindingHandler.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.ocpsoft.rewrite.bind.Bindable;
1515
import org.ocpsoft.rewrite.bind.Binding;
1616
import org.ocpsoft.rewrite.bind.Bindings;
17-
import org.ocpsoft.rewrite.config.Condition;
1817
import org.ocpsoft.rewrite.context.EvaluationContext;
1918
import org.ocpsoft.rewrite.el.El;
2019
import org.ocpsoft.rewrite.faces.config.PhaseBinding;
@@ -33,6 +32,12 @@ public Class<QueryParameterBinding> handles()
3332
return QueryParameterBinding.class;
3433
}
3534

35+
@Override
36+
public int priority()
37+
{
38+
return HandlerConstants.WEIGHT_TYPE_STRUCTURAL;
39+
}
40+
3641
@Override
3742
public void process(FieldContext context, Field field, QueryParameterBinding annotation)
3843
{
@@ -47,8 +52,7 @@ public void process(FieldContext context, Field field, QueryParameterBinding ann
4752

4853
// add the binding condition
4954
QueryParameterBindingCondition bindingCondition = new QueryParameterBindingCondition(queryParam);
50-
Condition conjunction = context.getRuleBuilder().getConditionBuilder().and(bindingCondition);
51-
context.getRuleBuilder().when(conjunction);
55+
context.getRuleBuilder().when(bindingCondition);
5256

5357
// build an deferred EL binding
5458
El elBinding = El.property(field);

0 commit comments

Comments
 (0)