Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2008 the original author or authors.
   *
   * 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.springframework.beans.factory.annotation;
 
 import java.util.Set;
 
Internal class for managing injection metadata. Not intended for direct use in applications.

Used by AutowiredAnnotationBeanPostProcessor, org.springframework.context.annotation.CommonAnnotationBeanPostProcessor and org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.

Author(s):
Juergen Hoeller
Since:
2.5
 
 public class InjectionMetadata {
 
 
 
 
 	public void addInjectedField(InjectedElement element) {
 		this..add(element);
 	}
 
 	public void addInjectedMethod(InjectedElement element) {
 		this..add(element);
 	}
 
 	public void checkConfigMembers(RootBeanDefinition beanDefinition) {
 		doRegisterConfigMembers(beanDefinitionthis.);
 		doRegisterConfigMembers(beanDefinitionthis.);
 	}
 
 	private void doRegisterConfigMembers(RootBeanDefinition beanDefinitionSet<InjectedElementmembers) {
 		for (Iterator<InjectedElementit = members.iterator(); it.hasNext();) {
 			Member member = it.next().getMember();
 			if (!beanDefinition.isExternallyManagedConfigMember(member)) {
 				beanDefinition.registerExternallyManagedConfigMember(member);
 			}
 			else {
 				it.remove();
 			}
 		}
 	}
 
 	public void injectFields(Object targetString beanNamethrows Throwable {
 		if (!this..isEmpty()) {
 			for (InjectedElement element : this.) {
 				element.inject(targetbeanNamenull);
 			}
 		}
 	}
 
 	public void injectMethods(Object targetString beanNamePropertyValues pvsthrows Throwable {
 		if (!this..isEmpty()) {
 			for (InjectedElement element : this.) {
 				element.inject(targetbeanNamepvs);
 			}
 		}
 	}
 
 
 	public static abstract class InjectedElement {
 
 		protected final Member member;
 
 		protected final boolean isField;
 
 		protected final PropertyDescriptor pd;
		protected volatile boolean skip = false;
		protected InjectedElement(Member memberPropertyDescriptor pd) {
			this. = member;
			this. = (member instanceof Field);
			this. = pd;
		}
		public final Member getMember() {
			return this.;
		}
		protected final Class getResourceType() {
			return (this. ?
					((Fieldthis.).getType() : ((Methodthis.).getParameterTypes()[0]);
		}
		protected final void checkResourceType(Class resourceType) {
			if (this.) {
				Class fieldType = ((Fieldthis.).getType();
				if (!(resourceType.isAssignableFrom(fieldType) || fieldType.isAssignableFrom(resourceType))) {
					throw new IllegalStateException("Specified field type [" + fieldType +
							"] is incompatible with resource type [" + resourceType.getName() + "]");
				}
			}
			else {
				Class paramType = ((Methodthis.).getParameterTypes()[0];
				if (!(resourceType.isAssignableFrom(paramType) || paramType.isAssignableFrom(resourceType))) {
					throw new IllegalStateException("Specified parameter type [" + paramType +
							"] is incompatible with resource type [" + resourceType.getName() + "]");
				}
			}
		}

Either this or getResourceToInject(java.lang.Object,java.lang.String) needs to be overridden.
		protected void inject(Object targetString requestingBeanNamePropertyValues pvsthrows Throwable {
			if (this.) {
				return;
			}
			if (this.) {
				Field field = (Fieldthis.;
				ReflectionUtils.makeAccessible(field);
				field.set(targetgetResourceToInject(targetrequestingBeanName));
			}
			else {
				if (this. != null && pvs != null && pvs.contains(this..getName())) {
					// Explicit value provided as part of the bean definition.
					this. = true;
					return;
				}
				try {
					Method method = (Methodthis.;
					ReflectionUtils.makeAccessible(method);
					method.invoke(targetgetResourceToInject(targetrequestingBeanName));
				}
					throw ex.getTargetException();
				}
			}
		}

		protected Object getResourceToInject(Object targetString requestingBeanName) {
			return null;
		}
		public boolean equals(Object other) {
			if (this == other) {
				return true;
			}
			if (!(other instanceof InjectedElement)) {
				return false;
			}
			InjectedElement otherElement = (InjectedElementother;
			if (this.) {
				return this..equals(otherElement.member);
			}
			else {
				return (otherElement.member instanceof Method &&
						this..getName().equals(otherElement.member.getName()) &&
								((MethodotherElement.member).getParameterTypes()));
			}
		}
		public int hashCode() {
			return this..getClass().hashCode() * 29 + this..getName().hashCode();
		}
	}
New to GrepCode? Check out our FAQ X