Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2009 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);
 
 	private final Set<InjectedElementinjectedElements;
 
 
 	public InjectionMetadata(Class targetClassCollection<InjectedElementelements) {
 		for (InjectedElement element : elements) {
 			if (.isDebugEnabled()) {
 				.debug("Found injected element on class [" + targetClass.getName() + "]: " + element);
 			}
 			this..add(element);
 		}
 	}
 
 	public void checkConfigMembers(RootBeanDefinition beanDefinition) {
 		for (Iterator<InjectedElementit = this..iterator(); it.hasNext();) {
 			Member member = it.next().getMember();
 			if (!beanDefinition.isExternallyManagedConfigMember(member)) {
 				beanDefinition.registerExternallyManagedConfigMember(member);
 			}
 			else {
 				it.remove();
 			}
 		}
 	}
 
 	public void inject(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;
 
		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.) {
				Field field = (Fieldthis.;
				ReflectionUtils.makeAccessible(field);
				field.set(targetgetResourceToInject(targetrequestingBeanName));
			}
			else {
				if (this. == null) {
				}
				if (this.) {
					return;
				}
				try {
					Method method = (Methodthis.;
					ReflectionUtils.makeAccessible(method);
					method.invoke(targetgetResourceToInject(targetrequestingBeanName));
				}
					throw ex.getTargetException();
				}
			}
		}

Checks whether this injector's property needs to be skipped due to an explicit property value having been specified. Also marks the affected property as processed for other processors to ignore it.
		protected boolean checkPropertySkipping(PropertyValues pvs) {
			if (this. != null && pvs != null) {
				if (pvs.contains(this..getName())) {
					// Explicit value provided as part of the bean definition.
					return true;
				}
				else if (pvs instanceof MutablePropertyValues) {
				}
			}
			return false;
		}

		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;
			return this..equals(otherElement.member);
		}
		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