org.jboss.resteasy.plugins.providers.validation.ViolationsContainer Maven / Gradle / Ivy
The newest version!
package org.jboss.resteasy.plugins.providers.validation;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.jboss.resteasy.api.validation.ResteasyConstraintViolation;
/**
* @author Ron Sigal
* @version $Revision: 1.1 $
*
* Copyright Mar 6, 2012
*/
public class ViolationsContainer implements Serializable
{
private static final long serialVersionUID = -7895854137980651539L;
private List fieldViolations = new ArrayList();
private List propertyViolations = new ArrayList();
private List classViolations = new ArrayList();
private List parameterViolations = new ArrayList();
private List returnValueViolations = new ArrayList();
private Exception exception;
private Object target;
public ViolationsContainer(Object target)
{
this.target = target;
}
public ViolationsContainer(Set set)
{
addViolations(set);
}
public Exception getException()
{
return exception;
}
public void setException(Exception exception)
{
this.exception = exception;
}
public Object getTarget()
{
return target;
}
public void setTarget(Object target)
{
this.target = target;
}
public void addViolations(Set extends ResteasyConstraintViolation> set)
{
Iterator extends ResteasyConstraintViolation> it = set.iterator();
while (it.hasNext())
{
ResteasyConstraintViolation violation = it.next();
switch (violation.getConstraintType())
{
case FIELD:
fieldViolations.add(violation);
break;
case PROPERTY:
propertyViolations.add(violation);
break;
case CLASS:
classViolations.add(violation);
break;
case PARAMETER:
parameterViolations.add(violation);
break;
case RETURN_VALUE:
returnValueViolations.add(violation);
break;
}
}
}
public void addFieldViolation(ResteasyConstraintViolation v)
{
fieldViolations.add(v);
}
public void addPropertyViolation(ResteasyConstraintViolation v)
{
propertyViolations.add(v);
}
public void addClassViolation(ResteasyConstraintViolation v)
{
classViolations.add(v);
}
public void addParameterViolation(ResteasyConstraintViolation v)
{
parameterViolations.add(v);
}
public void addReturnValueViolation(ResteasyConstraintViolation v)
{
returnValueViolations.add(v);
}
public List getFieldViolations()
{
return fieldViolations;
}
public List getPropertyViolations()
{
return propertyViolations;
}
public List getClassViolations()
{
return classViolations;
}
public List getParameterViolations()
{
return parameterViolations;
}
public List getReturnValueViolations()
{
return returnValueViolations;
}
public int size()
{
return fieldViolations.size() +
propertyViolations.size() +
classViolations.size() +
parameterViolations.size() +
returnValueViolations.size();
}
public String toString()
{
StringBuffer sb = setToStringBuffer(fieldViolations);
sb.append(setToStringBuffer(propertyViolations));
sb.append(setToStringBuffer(classViolations));
sb.append(setToStringBuffer(parameterViolations));
sb.append(setToStringBuffer(returnValueViolations));
return sb.toString();
}
private StringBuffer setToStringBuffer(List set)
{
StringBuffer sb = new StringBuffer();
Iterator it = set.iterator();
while (it.hasNext())
{
sb.append(it.next().toString()).append('\r');
}
return sb;
}
}