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 {
 
 	private final Log logger = LogFactory.getLog(InjectionMetadata.class);
 
 
 
 
 
 	public InjectionMetadata() {
 	}
 
 	public InjectionMetadata(Class targetClass) {
 		this. = targetClass.getName();
 	}
 
 
 	public void addInjectedField(InjectedElement element) {
 		if (.isDebugEnabled()) {
 			.debug("Found injected field on class [" + this. + "]: " + element);
 		}
 		this..add(element);
 	}
 
 	public void addInjectedMethod(InjectedElement element) {
 		if (.isDebugEnabled()) {
 			.debug("Found injected method on class [" + this. + "]: " + 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()) {
 			boolean debug = .isDebugEnabled();
			for (InjectedElement element : this.) {
				if (debug) {
					.debug("Processing injected field of bean '" + beanName + "': " + element);
				}
				element.inject(targetbeanNamenull);
			}
		}
	}
	public void injectMethods(Object targetString beanNamePropertyValues pvsthrows Throwable {
		if (!this..isEmpty()) {
			boolean debug = .isDebugEnabled();
			for (InjectedElement element : this.) {
				if (debug) {
					.debug("Processing injected method of bean '" + beanName + "': " + element);
				}
				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() {
			if (this.) {
				return ((Fieldthis.).getType();
			}
			else if (this. != null) {
				return this..getPropertyType();
			}
			else {
				return ((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 =
						(this. != null ? this..getPropertyType() : ((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();
		}
		public String toString() {
			return getClass().getSimpleName() + " for " + this.;
		}
	}
New to GrepCode? Check out our FAQ X