View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
3    * Thomschke.
4    * 
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    * 
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.constraint;
14  
15  import net.sf.oval.ConstraintTarget;
16  import net.sf.oval.Validator;
17  import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
18  import net.sf.oval.context.OValContext;
19  
20  /**
21   * @author Sebastian Thomschke
22   */
23  public class AssertFieldConstraintsCheck extends AbstractAnnotationCheck<AssertFieldConstraints>
24  {
25  	private static final long serialVersionUID = 1L;
26  
27  	private String fieldName;
28  
29  	private Class< ? > declaringClass;
30  
31  	/**
32  	 * {@inheritDoc}
33  	 */
34  	@Override
35  	public void configure(final AssertFieldConstraints constraintAnnotation)
36  	{
37  		super.configure(constraintAnnotation);
38  		setFieldName(constraintAnnotation.value());
39  		setDeclaringClass(constraintAnnotation.declaringClass());
40  	}
41  
42  	/**
43  	 * {@inheritDoc}
44  	 */
45  	@Override
46  	protected ConstraintTarget[] getAppliesToDefault()
47  	{
48  		return new ConstraintTarget[]{ConstraintTarget.CONTAINER};
49  	}
50  
51  	/**
52  	 * @return the declaringClass
53  	 */
54  	public Class< ? > getDeclaringClass()
55  	{
56  		return declaringClass;
57  	}
58  
59  	/**
60  	 * {@inheritDoc}
61  	 */
62  	@Override
63  	public String getErrorCode() throws UnsupportedOperationException
64  	{
65  		throw new UnsupportedOperationException();
66  	}
67  
68  	/**
69  	 * @return the fieldName
70  	 */
71  	public String getFieldName()
72  	{
73  		return fieldName;
74  	}
75  
76  	/**
77  	 * {@inheritDoc}
78  	 */
79  	@Override
80  	public String getMessage() throws UnsupportedOperationException
81  	{
82  		throw new UnsupportedOperationException();
83  	}
84  
85  	/**
86  	 * {@inheritDoc}
87  	 */
88  	@Override
89  	public int getSeverity() throws UnsupportedOperationException
90  	{
91  		throw new UnsupportedOperationException();
92  	}
93  
94  	/**
95  	 *  <b>This method is not used.</b><br>
96  	 *  The validation of this special constraint is directly performed by the Validator class
97  	 *  @throws UnsupportedOperationException always thrown if this method is invoked
98  	 */
99  	public boolean isSatisfied(final Object validatedObject, final Object valueToValidate, final OValContext context,
100 			final Validator validator) throws UnsupportedOperationException
101 	{
102 		throw new UnsupportedOperationException();
103 	}
104 
105 	/**
106 	 * @param declaringClass the declaringClass to set
107 	 */
108 	public void setDeclaringClass(final Class< ? > declaringClass)
109 	{
110 		this.declaringClass = declaringClass == Void.class ? null : declaringClass;
111 	}
112 
113 	/**
114 	 * {@inheritDoc}
115 	 */
116 	@Override
117 	public void setErrorCode(final String errorCode) throws UnsupportedOperationException
118 	{
119 		throw new UnsupportedOperationException();
120 	}
121 
122 	/**
123 	 * @param fieldName the fieldName to set
124 	 */
125 	public void setFieldName(final String fieldName)
126 	{
127 		this.fieldName = fieldName;
128 	}
129 
130 	/**
131 	 * {@inheritDoc}
132 	 */
133 	@Override
134 	public void setMessage(final String message) throws UnsupportedOperationException
135 	{
136 		throw new UnsupportedOperationException();
137 	}
138 
139 	/**
140 	 * {@inheritDoc}
141 	 */
142 	@Override
143 	public void setSeverity(final int severity) throws UnsupportedOperationException
144 	{
145 		throw new UnsupportedOperationException();
146 	}
147 }