Browse Source

SPR-7354 - Added equivalent of JAX-RS @Consumes to Spring MVC

pull/7/head
Arjen Poutsma 14 years ago
parent
commit
0cdb237576
  1. 6
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/AbstractNameValueCondition.java
  2. 12
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/AbstractRequestCondition.java
  3. 5
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/ConsumesRequestCondition.java
  4. 7
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/RequestConditionComposite.java
  5. 15
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/RequestConditionFactory.java

6
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/AbstractNameValueCondition.java

@ -35,7 +35,6 @@ abstract class AbstractNameValueCondition<T> extends AbstractRequestCondition { @@ -35,7 +35,6 @@ abstract class AbstractNameValueCondition<T> extends AbstractRequestCondition {
protected final boolean isNegated;
AbstractNameValueCondition(String expression) {
super(1);
int separator = expression.indexOf('=');
if (separator == -1) {
this.isNegated = expression.startsWith("!");
@ -66,6 +65,11 @@ abstract class AbstractNameValueCondition<T> extends AbstractRequestCondition { @@ -66,6 +65,11 @@ abstract class AbstractNameValueCondition<T> extends AbstractRequestCondition {
protected abstract boolean matchValue(HttpServletRequest request);
@Override
public int getWeight() {
return 1;
}
@Override
public int hashCode() {
int result = name.hashCode();

12
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/AbstractRequestCondition.java

@ -24,19 +24,11 @@ package org.springframework.web.servlet.mvc.method.condition; @@ -24,19 +24,11 @@ package org.springframework.web.servlet.mvc.method.condition;
*/
public abstract class AbstractRequestCondition implements RequestCondition {
private final int weight;
protected AbstractRequestCondition(int weight) {
this.weight = weight;
}
public int getWeight() {
return weight;
}
public abstract int getWeight();
public int compareTo(RequestCondition o) {
AbstractRequestCondition other = (AbstractRequestCondition) o;
return other.weight - this.weight;
return other.getWeight() - this.getWeight();
}
}

5
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/ConsumesRequestCondition.java

@ -29,7 +29,6 @@ class ConsumesRequestCondition extends AbstractRequestCondition { @@ -29,7 +29,6 @@ class ConsumesRequestCondition extends AbstractRequestCondition {
private final MediaType mediaType;
ConsumesRequestCondition(String mediaType) {
super(1);
this.mediaType = MediaType.parseMediaType(mediaType);
}
@ -42,4 +41,8 @@ class ConsumesRequestCondition extends AbstractRequestCondition { @@ -42,4 +41,8 @@ class ConsumesRequestCondition extends AbstractRequestCondition {
return false;
}
@Override
public int getWeight() {
return 1;
}
}

7
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/RequestConditionComposite.java

@ -20,6 +20,8 @@ import java.util.Collections; @@ -20,6 +20,8 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.springframework.util.Assert;
/**
* Abstract base class for {@link RequestCondition} implementations that wrap other request conditions.
*
@ -31,11 +33,12 @@ abstract class RequestConditionComposite extends AbstractRequestCondition { @@ -31,11 +33,12 @@ abstract class RequestConditionComposite extends AbstractRequestCondition {
protected final List<RequestCondition> conditions;
protected RequestConditionComposite(List<RequestCondition> conditions) {
super(getWeight(conditions));
Assert.notEmpty(conditions, "'conditions' must not be empty");
this.conditions = Collections.unmodifiableList(conditions);
}
private static int getWeight(List<RequestCondition> conditions) {
@Override
public int getWeight() {
int weight = 0;
for (RequestCondition condition : conditions) {
if (condition instanceof AbstractRequestCondition) {

15
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/RequestConditionFactory.java

@ -33,22 +33,33 @@ import org.springframework.util.ObjectUtils; @@ -33,22 +33,33 @@ import org.springframework.util.ObjectUtils;
*/
public abstract class RequestConditionFactory {
private static final RequestCondition TRUE_CONDITION = new AbstractRequestCondition(0) {
private static final RequestCondition TRUE_CONDITION = new AbstractRequestCondition() {
public boolean match(HttpServletRequest request) {
return true;
}
@Override
public int getWeight() {
return 0;
}
@Override
public String toString() {
return "TRUE";
}
};
private static final RequestCondition FALSE_CONDITION = new AbstractRequestCondition(0) {
private static final RequestCondition FALSE_CONDITION = new AbstractRequestCondition() {
public boolean match(HttpServletRequest request) {
return false;
}
@Override
public int getWeight() {
return 0;
}
@Override
public String toString() {
return "FALSE";

Loading…
Cancel
Save