001 /******************************************************************************* 002 * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian 003 * Thomschke. 004 * 005 * All Rights Reserved. This program and the accompanying materials 006 * are made available under the terms of the Eclipse Public License v1.0 007 * which accompanies this distribution, and is available at 008 * http://www.eclipse.org/legal/epl-v10.html 009 * 010 * Contributors: 011 * Sebastian Thomschke - initial implementation. 012 *******************************************************************************/ 013 package net.sf.oval.constraint; 014 015 import net.sf.oval.ConstraintTarget; 016 import net.sf.oval.Validator; 017 import net.sf.oval.configuration.annotation.AbstractAnnotationCheck; 018 import net.sf.oval.context.OValContext; 019 020 /** 021 * @author Sebastian Thomschke 022 */ 023 public class AssertFieldConstraintsCheck extends AbstractAnnotationCheck<AssertFieldConstraints> 024 { 025 private static final long serialVersionUID = 1L; 026 027 private String fieldName; 028 029 private Class< ? > declaringClass; 030 031 /** 032 * {@inheritDoc} 033 */ 034 @Override 035 public void configure(final AssertFieldConstraints constraintAnnotation) 036 { 037 super.configure(constraintAnnotation); 038 setFieldName(constraintAnnotation.value()); 039 setDeclaringClass(constraintAnnotation.declaringClass()); 040 } 041 042 /** 043 * {@inheritDoc} 044 */ 045 @Override 046 protected ConstraintTarget[] getAppliesToDefault() 047 { 048 return new ConstraintTarget[]{ConstraintTarget.CONTAINER}; 049 } 050 051 /** 052 * @return the declaringClass 053 */ 054 public Class< ? > getDeclaringClass() 055 { 056 return declaringClass; 057 } 058 059 /** 060 * {@inheritDoc} 061 */ 062 @Override 063 public String getErrorCode() throws UnsupportedOperationException 064 { 065 throw new UnsupportedOperationException(); 066 } 067 068 /** 069 * @return the fieldName 070 */ 071 public String getFieldName() 072 { 073 return fieldName; 074 } 075 076 /** 077 * {@inheritDoc} 078 */ 079 @Override 080 public String getMessage() throws UnsupportedOperationException 081 { 082 throw new UnsupportedOperationException(); 083 } 084 085 /** 086 * {@inheritDoc} 087 */ 088 @Override 089 public int getSeverity() throws UnsupportedOperationException 090 { 091 throw new UnsupportedOperationException(); 092 } 093 094 /** 095 * <b>This method is not used.</b><br> 096 * The validation of this special constraint is directly performed by the Validator class 097 * @throws UnsupportedOperationException always thrown if this method is invoked 098 */ 099 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 }