Skip to content

Commit e5169e0

Browse files
committed
Removed class type configuration for Validatable and Convertable
1 parent 5ea8115 commit e5169e0

8 files changed

Lines changed: 10 additions & 116 deletions

File tree

‎api/src/main/java/org/ocpsoft/rewrite/bind/Convertable.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@
1717

1818
/**
1919
* An object that can hold {@link Converter} instances.
20-
*
20+
*
2121
* @param <IMPLTYPE> The type implementing {@link Convertable}.
2222
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2323
*/
2424
public interface Convertable<IMPLTYPE>
2525
{
26-
/**
27-
* Set the {@link Converter} type with which this {@link Binding} value will be converted.
28-
*/
29-
public <X extends Converter<?>> IMPLTYPE convertedBy(final Class<X> type);
30-
3126
/**
3227
* Set the {@link Converter} with which this {@link Binding} value will be converted.
3328
*/

‎api/src/main/java/org/ocpsoft/rewrite/bind/Validatable.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@
1717

1818
/**
1919
* An object that can hold a {@link Validator}.
20-
*
20+
*
2121
* @param <IMPLTYPE> The type implementing {@link Validatable}.
2222
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2323
*/
2424
public interface Validatable<IMPLTYPE>
2525
{
26-
/**
27-
* Set the {@link Validator} type with which this {@link Binding} value will be validated.
28-
*/
29-
public <X extends Validator<?>> IMPLTYPE validatedBy(final Class<X> type);
30-
3126
/**
3227
* Set the {@link Validator} with which this {@link Binding} value will be validated.
3328
*/

‎api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleParameterBuilder.java‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,13 @@ public ConfigurationRuleParameterBuilder constrainedBy(final Constraint<String>
8989
return this;
9090
}
9191

92-
@Override
93-
public <X extends Validator<?>> ConfigurationRuleParameterBuilder validatedBy(final Class<X> type)
94-
{
95-
param.validatedBy(type);
96-
return this;
97-
}
98-
9992
@Override
10093
public ConfigurationRuleParameterBuilder validatedBy(final Validator<?> validator)
10194
{
10295
param.validatedBy(validator);
10396
return this;
10497
}
10598

106-
@Override
107-
public <X extends Converter<?>> ConfigurationRuleParameterBuilder convertedBy(final Class<X> type)
108-
{
109-
param.convertedBy(type);
110-
return this;
111-
}
112-
11399
@Override
114100
public ConfigurationRuleParameterBuilder convertedBy(final Converter<?> converter)
115101
{

‎api/src/main/java/org/ocpsoft/rewrite/config/DefaultConditionBuilder.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.ocpsoft.rewrite.config;
1717

18-
import org.ocpsoft.rewrite.context.EvaluationContext;
19-
import org.ocpsoft.rewrite.event.Rewrite;
2018

2119
/**
2220
* Used as a base class to create fluent relationships between {@link Condition} objects; this class adds logical

‎api/src/main/java/org/ocpsoft/rewrite/param/ParameterBuilder.java‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ public IMPLTYPE bindsTo(Binding binding)
7272
return super.bindsTo(binding);
7373
}
7474

75-
@Override
76-
@SuppressWarnings("unchecked")
77-
public <X extends Converter<?>> IMPLTYPE convertedBy(Class<X> type)
78-
{
79-
this.converter = ValueHolderUtil.resolveConverter(type);
80-
return (IMPLTYPE) this;
81-
}
82-
8375
@Override
8476
@SuppressWarnings("unchecked")
8577
public IMPLTYPE convertedBy(Converter<?> converter)
@@ -94,14 +86,6 @@ public Converter<?> getConverter()
9486
return converter;
9587
}
9688

97-
@Override
98-
@SuppressWarnings("unchecked")
99-
public <X extends Validator<?>> IMPLTYPE validatedBy(Class<X> type)
100-
{
101-
this.validator = ValueHolderUtil.resolveValidator(type);
102-
return (IMPLTYPE) this;
103-
}
104-
10589
@Override
10690
@SuppressWarnings("unchecked")
10791
public IMPLTYPE validatedBy(Validator<?> validator)

‎api/src/main/java/org/ocpsoft/rewrite/util/ValueHolderUtil.java‎

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,14 @@
11
package org.ocpsoft.rewrite.util;
22

33
import java.lang.reflect.Array;
4-
import java.util.Collection;
54

6-
import org.ocpsoft.common.services.ServiceLoader;
7-
import org.ocpsoft.logging.Logger;
85
import org.ocpsoft.rewrite.bind.Converter;
96
import org.ocpsoft.rewrite.bind.Validator;
107
import org.ocpsoft.rewrite.context.EvaluationContext;
118
import org.ocpsoft.rewrite.event.Rewrite;
12-
import org.ocpsoft.rewrite.exception.RewriteException;
139

1410
public final class ValueHolderUtil
1511
{
16-
private static final Logger log = Logger.getLogger(ValueHolderUtil.class);
17-
18-
public static Validator<?> resolveValidator(final Class<? extends Validator<?>> type)
19-
{
20-
try {
21-
Collection<? extends Validator<?>> enriched = ServiceLoader.loadEnriched(type);
22-
if (enriched != null)
23-
{
24-
if ((enriched.size() > 1) && log.isWarnEnabled())
25-
{
26-
log.warn("Multiple Validator instances available for type [" + type.getName() + "], using first of "
27-
+ enriched + "");
28-
}
29-
for (Validator<?> validator : enriched) {
30-
if (validator != null)
31-
{
32-
return validator;
33-
}
34-
}
35-
}
36-
return null;
37-
}
38-
catch (Exception e) {
39-
throw new RewriteException("Could not instantiate Validator of type [" + type.getName() + "]", e);
40-
}
41-
}
42-
43-
public static final Converter<?> resolveConverter(final Class<? extends Converter<?>> type)
44-
{
45-
try {
46-
Collection<? extends Converter<?>> enriched = ServiceLoader.loadEnriched(type);
47-
if (enriched != null)
48-
{
49-
if ((enriched.size() > 1) && log.isWarnEnabled())
50-
{
51-
log.warn("Multiple Converter instances available for type [" + type.getName() + "], using first of "
52-
+ enriched + "");
53-
}
54-
for (Converter<?> converter : enriched) {
55-
if (converter != null)
56-
{
57-
return converter;
58-
}
59-
}
60-
}
61-
return null;
62-
}
63-
catch (Exception e) {
64-
throw new RewriteException("Could not instantiate Converter of type [" + type.getName() + "]", e);
65-
}
66-
}
67-
6812
@SuppressWarnings({ "unchecked", "rawtypes" })
6913
public static boolean validates(final Rewrite event, final EvaluationContext context, Validator<?> validator,
7014
final Object value)

‎integration-faces/src/main/java/org/ocpsoft/rewrite/faces/config/PhaseBinding.java‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,13 @@ public PhaseBinding after(final PhaseId... phases)
148148
return this;
149149
}
150150

151-
@Override
152-
public <X extends Validator<?>> PhaseBinding validatedBy(Class<X> type)
153-
{
154-
validator = ValueHolderUtil.resolveValidator(type);
155-
return this;
156-
}
157-
158151
@Override
159152
public PhaseBinding validatedBy(Validator<?> validator)
160153
{
161154
this.validator = validator;
162155
return this;
163156
}
164157

165-
@Override
166-
public <X extends Converter<?>> PhaseBinding convertedBy(Class<X> type)
167-
{
168-
converter = ValueHolderUtil.resolveConverter(type);
169-
return this;
170-
}
171-
172158
@Override
173159
public PhaseBinding convertedBy(Converter<?> converter)
174160
{

‎showcase/rest-ws/src/main/java/org/ocpsoft/rewrite/showcase/rest/RestRewriteConfiguration.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ public void setParameterStore(ParameterStore store)
8686
@Inject
8787
private ProductRegistry products;
8888

89+
@Inject
90+
private ProductConverter productConverter;
91+
92+
@Inject
93+
private ProductValidator productValidator;
94+
8995
@Override
9096
public Configuration getConfiguration(final ServletContext context)
9197
{
@@ -134,8 +140,8 @@ public void performHttp(final HttpServletRewrite event, final EvaluationContext
134140
}
135141
}).where("pid").matches("\\d+")
136142
.constrainedBy(new IntegerConstraint())
137-
.convertedBy(ProductConverter.class)
138-
.validatedBy(ProductValidator.class)
143+
.convertedBy(productConverter)
144+
.validatedBy(productValidator)
139145

140146
.addRule()
141147
.when(Path.matches("/store/products").and(Method.isGet()))

0 commit comments

Comments
 (0)