Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 package org.hibernate.validator.internal.util.annotationfactory;
 
 import java.util.Map;
 import java.util.Set;
 
A concrete implementation of Annotation that pretends it is a "real" source code annotation. It's also an InvocationHandler.

When you create an AnnotationProxy, you must initialize it with an AnnotationDescriptor. The adapter checks that the provided elements are the same elements defined in the annotation interface. However, it does not check that their values are the right type. If you omit an element, the adapter will use the default value for that element from the annotation interface, if it exists. If no default exists, it will throw an exception.

Warning: this class does not implement hashCode() and equals() - it just uses the ones it inherits from Object. This means that an AnnotationProxy does not follow the recommendations of the Annotation javadoc about these two methods. That's why you should never mix AnnotationProxies with "real" annotations. For example, don't put them into the same Collection.

Author(s):
Paolo Perrotta
Davide Marchignoli
See also:
java.lang.annotation.Annotation
 
 public class AnnotationProxy implements AnnotationInvocationHandlerSerializable {
 
 	private static final long serialVersionUID = 6907601010599429454L;
 	private static final Log log = LoggerFactory.make();
 
 	private final Class<? extends AnnotationannotationType;
 	private final Map<StringObjectvalues;
 
 	public AnnotationProxy(AnnotationDescriptor<?> descriptor) {
 		this. = descriptor.type();
 		 = getAnnotationValuesdescriptor );
 	}
 
 	private Map<StringObjectgetAnnotationValues(AnnotationDescriptor<?> descriptor) {
 		Map<StringObjectresult = new HashMap<StringObject>();
 		int processedValuesFromDescriptor = 0;
 		final Method[] declaredMethods = ReflectionHelper.getDeclaredMethods );
 		for ( Method m : declaredMethods ) {
 			if ( descriptor.containsElementm.getName() ) ) {
 				result.putm.getName(), descriptor.valueOfm.getName() ) );
 				processedValuesFromDescriptor++;
 			}
 			else if ( m.getDefaultValue() != null ) {
 				result.putm.getName(), m.getDefaultValue() );
 			}
 			else {
 			}
 		}
 		if ( processedValuesFromDescriptor != descriptor.numberOfElements() ) {
 
 			Set<StringunknownParameters = descriptor.getElements().keySet();
 			unknownParameters.removeAllresult.keySet() );
 
 					unknownParameters
 			);
 		}
 		return result;
 	}
 
 	public Object invoke(Object proxyMethod methodObject[] argsthrows Throwable {
		if ( .containsKeymethod.getName() ) ) {
			return .getmethod.getName() );
		}
		return method.invokethisargs );
	}
	public Class<? extends AnnotationannotationType() {
	}
	public String toString() {
		StringBuilder result = new StringBuilder();
		result.append'@' ).append.getName() ).append'(' );
			result.appends ).append'=' ).append.gets ) ).append", " );
		}
		// remove last separator:
		if ( .size() > 0 ) {
			result.deleteresult.length() - 2, result.length() );
			result.append")" );
		}
		else {
			result.deleteresult.length() - 1, result.length() );
		}
		return result.toString();
	}
		SortedSet<Stringresult = new TreeSet<String>();
		result.addAll.keySet() );
		return result;
	}
New to GrepCode? Check out our FAQ X