Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you 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.apache.aries.blueprint.container;
  
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import org.slf4j.Logger;
  
  import static org.apache.aries.blueprint.utils.ReflectionUtils.getPublicMethods;
  import static org.apache.aries.blueprint.utils.ReflectionUtils.getRealCause;

A Recipe to create POJOs.

Version:
$Rev: 1690576 $, $Date: 2015-07-13 09:44:53 +0200 (Mon, 13 Jul 2015) $
  
  public class BeanRecipe extends AbstractRecipe {
  	
  	static class UnwrapperedBeanHolder {
  		final BeanRecipe recipe;
  		
  		public UnwrapperedBeanHolder(Object unwrapperedBeanBeanRecipe recipe) {
  			this. = unwrapperedBean;
  			this. = recipe;
  		}
  	}
  
      public class VoidableCallable implements Callable<Object>, Voidable {
  
          private final AtomicReference<Objectref = new AtomicReference<Object>();
          
          private final Semaphore sem = new Semaphore(1);
          
          private final ThreadLocal<ObjectdeadlockDetector = new ThreadLocal<Object>();
          
          public void voidReference() {
              .set(null);
          }
  
          public Object call() throws ComponentDefinitionException {
              Object o = .get();
              
              if (o == null) {
                  if(.get() != null) {
                      .remove();
                      throw new ComponentDefinitionException("Construction cycle detected for bean " + );
                  }
                  
                  .acquireUninterruptibly();
                 try {
                     o = .get();
                     if (o == null) {
                         .set(this);
                         try {
                             o = internalCreate2();
                             .set(o);
                         } finally {
                             .remove();
                         }
                     }
                 } finally {
                   .release();
                 }
             }
             
             return o;
         }
 
     }
 
     private static final Logger LOGGER = LoggerFactory.getLogger(BeanRecipe.class);
 
     private final LinkedHashMap<String,Objectproperties = new LinkedHashMap<String,Object>();
     private final Object type;
 
     private String initMethod;
     private String destroyMethod;
     private List<RecipeexplicitDependencies;
     
     private Recipe factory;
     private String factoryMethod;
     private List<Objectarguments;
     private List<StringargTypes;
     private boolean reorderArguments;
     private final boolean allowsFieldInjection;
     
 
     public BeanRecipe(String nameExtendedBlueprintContainer blueprintContainerObject typeboolean allowsFieldInjection) {
         super(name);
         this. = blueprintContainer;
         this. = type;
         this. = allowsFieldInjection;
     }
 
     public Object getProperty(String name) {
         return .get(name);
     }
 
     public Map<StringObjectgetProperties() {
         return new LinkedHashMap<StringObject>();
     }
 
     public void setProperty(String nameObject value) {
         .put(namevalue);
     }
 
     public void setFactoryMethod(String method) {
         this. = method;
     }
     
     public void setFactoryComponent(Recipe factory) {
         this. = factory;
     }
     
     public void setArgTypes(List<StringargTypes) {
         this. = argTypes;
     }
     
     public void setArguments(List<Objectarguments) {
         this. = arguments;
     }
     
     public void setReorderArguments(boolean reorder) {
         this. = reorder;
     }
     
     public void setInitMethod(String initMethod) {
         this. = initMethod;
     }
     
     public String getInitMethod() {
         return ;
     }
     
     public void setDestroyMethod(String destroyMethod) {
         this. = destroyMethod;
     }
     
     public String getDestroyMethod() {
         return ;
     }
 
     public List<RecipegetExplicitDependencies() {
         return ;
     }
 
     public void setExplicitDependencies(List<RecipeexplicitDependencies) {
         this. = explicitDependencies;
     }
 
     public void setInterceptorLookupKey(BeanMetadata metadata) {
     	 = metadata;
     }
     
     @Override
     public List<RecipegetConstructorDependencies() {
         List<Reciperecipes = new ArrayList<Recipe>();
         if ( != null) {
             recipes.addAll();
         }
         if ( != null) {
             for (Object argument : ) {
                 if (argument instanceof Recipe) {
                     recipes.add((Recipe)argument);
                 }
             }
         }
         return recipes;
     }
     
     public List<RecipegetDependencies() {
         List<Reciperecipes = new ArrayList<Recipe>();
         for (Object o : .values()) {
             if (o instanceof Recipe) {
                 Recipe recipe = (Recipeo;
                 recipes.add(recipe);
             }
         }
         if ( != null) {
             recipes.add();
         }
         recipes.addAll(getConstructorDependencies());
         return recipes
     }
 
     private void instantiateExplicitDependencies() {
         if ( != null) {
             for (Recipe recipe : ) {
                 recipe.create();
             }
         }
     }
 
     @Override
     protected Class loadClass(String className) {
         ClassLoader loader =  instanceof Class ? ((Class).getClassLoader() : null;
         ReifiedType t = loadType(classNameloader);
         return t != null ? t.getRawClass() : null;
     }
 
     @Override
     protected ReifiedType loadType(String className) {
         return loadType(className instanceof Class ? ((Class).getClassLoader() : null);
     }
 
     private Object getInstance() throws ComponentDefinitionException {
         Object instance;
         
         // Instanciate arguments
         List<Objectargs = new ArrayList<Object>();
         List<ReifiedTypeargTypes = new ArrayList<ReifiedType>();
         if ( != null) {
             for (int i = 0; i < .size(); i++) {
                 Object arg = .get(i);
                 if (arg instanceof Recipe) {
                     args.add(((Recipearg).create());
                 } else {
                     args.add(arg);
                 }
                 if (this. != null) {
                     argTypes.add(this..get(i) != null ? loadType(this..get(i)) : null);
                 }
             }
         }
 
         if ( != null) {
             // look for instance method on factory object
             Object factoryObj = .create();
             
             // If the factory is a service reference, we need to get hold of the actual proxy for the service
             if (factoryObj instanceof ReferenceRecipe.ServiceProxyWrapper) {
                 try {
                     factoryObj = ((ReferenceRecipe.ServiceProxyWrapperfactoryObj).convert(new ReifiedType(Object.class));
                 } catch (Exception e) {
                     throw new ComponentDefinitionException("Error when instantiating bean " + getName() + " of class " + getType().getName(), getRealCause(e));
                 }
             } else if (factoryObj instanceof UnwrapperedBeanHolder) {
             	factoryObj = wrap((UnwrapperedBeanHolderfactoryObjObject.class);
             }
             
             // Map of matching methods
             Map<MethodList<Object>> matches = findMatchingMethods(factoryObj.getClass(), trueargsargTypes);
             if (matches.size() == 1) {
                 try {
                     Map.Entry<MethodList<Object>> match = matches.entrySet().iterator().next();
                     instance = invoke(match.getKey(), factoryObjmatch.getValue().toArray());
                 } catch (Throwable e) {
                     throw new ComponentDefinitionException("Error when instantiating bean " + getName() + " of class " + getType().getName(), getRealCause(e));
                 }
             } else if (matches.size() == 0) {
                 throw new ComponentDefinitionException("Unable to find a matching factory method " +  + " on class " + factoryObj.getClass().getName() + " for arguments " + args + " when instanciating bean " + getName());
             } else {
                 throw new ComponentDefinitionException("Multiple matching factory methods " +  + " found on class " + factoryObj.getClass().getName() + " for arguments " + args + " when instanciating bean " + getName() + ": " + matches.keySet());
             }
         } else if ( != null) {
             // Map of matching methods
             Map<MethodList<Object>> matches = findMatchingMethods(getType(), falseargsargTypes);
             if (matches.size() == 1) {
                 try {
                     Map.Entry<MethodList<Object>> match = matches.entrySet().iterator().next();
                     instance = invoke(match.getKey(), nullmatch.getValue().toArray());
                 } catch (Throwable e) {
                     throw new ComponentDefinitionException("Error when instantiating bean " + getName() + " of class " + getType().getName(), getRealCause(e));
                 }
             } else if (matches.size() == 0) {
                 throw new ComponentDefinitionException("Unable to find a matching factory method " +  + " on class " + getType().getName() + " for arguments " + args + " when instanciating bean " + getName());
             } else {
                 throw new ComponentDefinitionException("Multiple matching factory methods " +  + " found on class " + getType().getName() + " for arguments " + args + " when instanciating bean " + getName() + ": " + matches.keySet());
             }
         } else {
             if (getType() == null) {
                 throw new ComponentDefinitionException("No factoryMethod nor class is defined for this bean");
             }
             // Map of matching constructors
             Map<ConstructorList<Object>> matches = findMatchingConstructors(getType(), argsargTypes);
             if (matches.size() == 1) {
                 try {
                     Map.Entry<ConstructorList<Object>> match = matches.entrySet().iterator().next();
                     instance = newInstance(match.getKey(), match.getValue().toArray());
                 } catch (Throwable e) {
                     throw new ComponentDefinitionException("Error when instantiating bean " + getName() + " of class " + getType().getName(), getRealCause(e));
                 }
             } else if (matches.size() == 0) {
                 throw new ComponentDefinitionException("Unable to find a matching constructor on class " + getType().getName() + " for arguments " + args + " when instanciating bean " + getName());
             } else {
                 throw new ComponentDefinitionException("Multiple matching constructors found on class " + getType().getName() + " for arguments " + args + " when instanciating bean " + getName() + ": " + matches.keySet());
             }
         }
         
         return instance;
     }
 
     private Map<MethodList<Object>> findMatchingMethods(Class typeString nameboolean instanceList<ObjectargsList<ReifiedTypetypes) {
         Map<MethodList<Object>> matches = new HashMap<MethodList<Object>>();
         // Get constructors
         List<Methodmethods = new ArrayList<Method>(Arrays.asList(getPublicMethods(type)));
         // Discard any signature with wrong cardinality
         for (Iterator<Methodit = methods.iterator(); it.hasNext();) {
             Method mth = it.next();
             if (!mth.getName().equals(name)) {
                 it.remove();
             } else if (mth.getParameterTypes().length != args.size()) {
                 it.remove();
             } else if (instance ^ !Modifier.isStatic(mth.getModifiers())) {
                 it.remove();
             } else if (mth.isBridge()) {
                 it.remove();
             }
         }
         
         // on some JVMs (J9) hidden static methods are returned by Class.getMethods so we need to weed them out
         // to reduce ambiguity
         if (!instance) {
         	methods = applyStaticHidingRules(methods);
         }
         
         // Find a direct match with assignment
         if (matches.size() != 1) {
             Map<MethodList<Object>> nmatches = new HashMap<MethodList<Object>>();
             for (Method mth : methods) {
                 boolean found = true;
                 List<Objectmatch = new ArrayList<Object>();
                 for (int i = 0; i < args.size(); i++) {
                     ReifiedType argType = new GenericType(mth.getGenericParameterTypes()[i]);
                     if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) {
                         found = false;
                         break;
                     }
                     //If the arg is an Unwrappered bean then we need to do the assignment check against the
                     //unwrappered bean itself.
                     Object arg = args.get(i);
                     Object argToTest = arg;
                     if(arg instanceof UnwrapperedBeanHolder)
                     	argToTest = ((UnwrapperedBeanHolder)arg).;
                     if (!AggregateConverter.isAssignable(argToTestargType)) {
                         found = false;
                         break;
                     }
                     try {
                         match.add(convert(argmth.getGenericParameterTypes()[i]));
                     } catch (Throwable t) {
                         found = false;
                         break;
                     }
                 }
                 if (found) {
                     nmatches.put(mthmatch);
                 }
             }
             if (nmatches.size() > 0) {
                 matches = nmatches;
             }
         }
         // Find a direct match with conversion
         if (matches.size() != 1) {
             Map<MethodList<Object>> nmatches = new HashMap<MethodList<Object>>();
             for (Method mth : methods) {
                 boolean found = true;
                 List<Objectmatch = new ArrayList<Object>();
                 for (int i = 0; i < args.size(); i++) {
                     ReifiedType argType = new GenericType(mth.getGenericParameterTypes()[i]);
                     if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) {
                         found = false;
                         break;
                     }
                     try {
                         Object val = convert(args.get(i), argType);
                         match.add(val);
                     } catch (Throwable t) {
                         found = false;
                         break;
                     }
                 }
                 if (found) {
                     nmatches.put(mthmatch);
                 }
             }
             if (nmatches.size() > 0) {
                 matches = nmatches;
             }
         }
         // Start reordering with assignment
         if (matches.size() != 1 &&  && args.size() > 1) {
             Map<MethodList<Object>> nmatches = new HashMap<MethodList<Object>>();
             for (Method mth : methods) {
                 ArgumentMatcher matcher = new ArgumentMatcher(mth.getGenericParameterTypes(), false);
                 List<Objectmatch = matcher.match(argstypes);
                 if (match != null) {
                     nmatches.put(mthmatch);
                 }
             }
             if (nmatches.size() > 0) {
                 matches = nmatches;
             }
         }
         // Start reordering with conversion
         if (matches.size() != 1 &&  && args.size() > 1) {
             Map<MethodList<Object>> nmatches = new HashMap<MethodList<Object>>();
             for (Method mth : methods) {
                 ArgumentMatcher matcher = new ArgumentMatcher(mth.getGenericParameterTypes(), true);
                 List<Objectmatch = matcher.match(argstypes);
                 if (match != null) {
                     nmatches.put(mthmatch);
                 }
             }
             if (nmatches.size() > 0) {
                 matches = nmatches;
             }
         }
         
         return matches;
     }
     
     private static List<MethodapplyStaticHidingRules(Collection<Methodmethods) {
     	List<Methodresult = new ArrayList<Method>(methods.size());
     	for (Method m : methods) {
     		boolean toBeAdded = true;
 
     		Iterator<Methodit = result.iterator();
     		inner: while (it.hasNext()) {
     			Method other = it.next();
     			if (hasIdenticalParameters(mother)) {
     				Class<?> mClass = m.getDeclaringClass();
     				Class<?> otherClass = other.getDeclaringClass();
     				
     				if (mClass.isAssignableFrom(otherClass)) {
     					toBeAdded = false;
     					break inner;
     				} else if (otherClass.isAssignableFrom(mClass)) {
     					it.remove();
     				}
     			}
     		}
     		
     		if (toBeAddedresult.add(m);
     	}
     	
     	return result;
     }
     
     private static boolean hasIdenticalParameters(Method oneMethod two) {
 		Class<?>[] oneTypes = one.getParameterTypes();
 		Class<?>[] twoTypes = two.getParameterTypes();
     	
 		if (oneTypes.length != twoTypes.lengthreturn false;
 		
 		for (int i=0; i<oneTypes.lengthi++) {
 			if (!oneTypes[i].equals(twoTypes[i])) return false;
 		}
 		
 		return true;
     }
 
     private Map<ConstructorList<Object>> findMatchingConstructors(Class typeList<ObjectargsList<ReifiedTypetypes) {
         Map<ConstructorList<Object>> matches = new HashMap<ConstructorList<Object>>();
         // Get constructors
         List<Constructorconstructors = new ArrayList<Constructor>(Arrays.asList(type.getConstructors()));
         // Discard any signature with wrong cardinality
         for (Iterator<Constructorit = constructors.iterator(); it.hasNext();) {
             if (it.next().getParameterTypes().length != args.size()) {
                 it.remove();
             }
         }
         // Find a direct match with assignment
         if (matches.size() != 1) {
             Map<ConstructorList<Object>> nmatches = new HashMap<ConstructorList<Object>>();
             for (Constructor cns : constructors) {
                 boolean found = true;
                 List<Objectmatch = new ArrayList<Object>();
                 for (int i = 0; i < args.size(); i++) {
                     ReifiedType argType = new GenericType(cns.getGenericParameterTypes()[i]);
                     if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) {
                         found = false;
                         break;
                     }
                     //If the arg is an Unwrappered bean then we need to do the assignment check against the
                     //unwrappered bean itself.
                     Object arg = args.get(i);
                     Object argToTest = arg;
                     if(arg instanceof UnwrapperedBeanHolder)
                     	argToTest = ((UnwrapperedBeanHolder)arg).;
                     if (!AggregateConverter.isAssignable(argToTestargType)) {
                         found = false;
                         break;
                     }
                     try {
                         match.add(convert(argcns.getGenericParameterTypes()[i]));
                     } catch (Throwable t) {
                         found = false;
                         break;
                     }
                 }
                 if (found) {
                     nmatches.put(cnsmatch);
                 }
             }
             if (nmatches.size() > 0) {
                 matches = nmatches;
             }
         }
         // Find a direct match with conversion
         if (matches.size() != 1) {
             Map<ConstructorList<Object>> nmatches = new HashMap<ConstructorList<Object>>();
             for (Constructor cns : constructors) {
                 boolean found = true;
                 List<Objectmatch = new ArrayList<Object>();
                 for (int i = 0; i < args.size(); i++) {
                     ReifiedType argType = new GenericType(cns.getGenericParameterTypes()[i]);
                     if (types.get(i) != null && !argType.getRawClass().equals(types.get(i).getRawClass())) {
                         found = false;
                         break;
                     }
                     try {
                         Object val = convert(args.get(i), argType);
                         match.add(val);
                     } catch (Throwable t) {
                         found = false;
                         break;
                     }
                 }
                 if (found) {
                     nmatches.put(cnsmatch);
                 }
             }
             if (nmatches.size() > 0) {
                 matches = nmatches;
             }
         }
         // Start reordering with assignment
         if (matches.size() != 1 &&  && .size() > 1) {
             Map<ConstructorList<Object>> nmatches = new HashMap<ConstructorList<Object>>();
             for (Constructor cns : constructors) {
                 ArgumentMatcher matcher = new ArgumentMatcher(cns.getGenericParameterTypes(), false);
                 List<Objectmatch = matcher.match(argstypes);
                 if (match != null) {
                     nmatches.put(cnsmatch);
                 }
             }
             if (nmatches.size() > 0) {
                 matches = nmatches;
             }
         }
         // Start reordering with conversion
         if (matches.size() != 1 &&  && .size() > 1) {
             Map<ConstructorList<Object>> nmatches = new HashMap<ConstructorList<Object>>();
             for (Constructor cns : constructors) {
                 ArgumentMatcher matcher = new ArgumentMatcher(cns.getGenericParameterTypes(), true);
                 List<Objectmatch = matcher.match(argstypes);
                 if (match != null) {
                     nmatches.put(cnsmatch);
                 }
             }
             if (nmatches.size() > 0) {
                 matches = nmatches;
             }
         }
         return matches;
     }

    
Returns init method (if any). Throws exception if the init-method was set explicitly on the bean and the method is not found on the instance.
 
     protected Method getInitMethod(Object instancethrows ComponentDefinitionException {
         Method method = null;        
         if ( != null && .length() > 0) {
             method = ReflectionUtils.getLifecycleMethod(instance.getClass(), );
             if (method == null) {
                 throw new ComponentDefinitionException("Component '" + getName() + "' does not have init-method: " + );
             }
         }
         return method;
     }

    
Returns destroy method (if any). Throws exception if the destroy-method was set explicitly on the bean and the method is not found on the instance.
 
     public Method getDestroyMethod(Object instancethrows ComponentDefinitionException {
         Method method = null;        
         if (instance != null &&  != null && .length() > 0) {
             method = ReflectionUtils.getLifecycleMethod(instance.getClass(), );
             if (method == null) {
                 throw new ComponentDefinitionException("Component '" + getName() + "' does not have destroy-method: " + );
             }
         }
         return method;
     }
    
    
Small helper class, to construct a chain of BeanCreators.
Each bean creator in the chain will return a bean that has been processed by every BeanProcessor in the chain before it.
 
     private static class BeanCreatorChain implements BeanProcessor.BeanCreator {
         public enum ChainType{Before,After};
         private final BeanProcessor.BeanCreator parentBeanCreator;
         private final BeanProcessor parentBeanProcessor;
         private final BeanMetadata beanData;
         private final String beanName;        
         private final ChainType when;
         public BeanCreatorChain(BeanProcessor.BeanCreator parentBeanCreator
                                 BeanProcessor parentBeanProcessor,
                                 BeanMetadata beanData,
                                 String beanName,
                                 ChainType when){
             this. = parentBeanCreator;
             this. = parentBeanProcessor;
             this. = beanData;
             this. = beanName;
             this. = when;
         }
 
         public Object getBean() {
             Object previousBean = .getBean();
             Object processed = null;
             switch(){
                 case  :
                   processed = .beforeInit(previousBean);
                   break;
                 case :
                   processed = .afterInit(previousBean);
                   break;
             }
             return processed;
         }   
     }
     
     private Object runBeanProcPreInit(Object obj){
         String beanName = getName();
         BeanMetadata beanData = (BeanMetadata
           .getComponentDefinitionRegistry().getComponentDefinition(beanName);        
         List<BeanProcessorprocessors = .getProcessors(BeanProcessor.class);
         
         //The start link of the chain, that provides the 
         //original, unprocessed bean to the head of the chain.
         BeanProcessor.BeanCreator initialBeanCreator = new BeanProcessor.BeanCreator() {            
             public Object getBean() {
                 Object obj = getInstance();
                 //getinit, getdestroy, addpartial object don't need calling again.
                 //however, property injection does.
                 setProperties(obj);
                 return obj;
             }
         };
 
         BeanProcessor.BeanCreator currentCreator = initialBeanCreator;
         for(BeanProcessor processor : processors){
             obj = processor.beforeInit(objgetName(), currentCreatorbeanData);
             currentCreator = new BeanCreatorChain(currentCreatorprocessorbeanDatabeanName..);
         }
         return obj;
     }
     
     private void runBeanProcInit(Method initMethodObject obj){
         // call init method
         if (initMethod != null) {
             try {
                 invoke(initMethodobj, (Object[]) null);
             } catch (Throwable t) {
                 throw new ComponentDefinitionException("Unable to initialize bean " + getName(), getRealCause(t));
             }
         }   
     }
     
     private Object runBeanProcPostInit(Object obj){
         String beanName = getName();
         BeanMetadata beanData = (BeanMetadata
           .getComponentDefinitionRegistry().getComponentDefinition(beanName);        
         List<BeanProcessorprocessors = .getProcessors(BeanProcessor.class);
         
         //The start link of the chain, that provides the 
         //original, unprocessed bean to the head of the chain.
         BeanProcessor.BeanCreator initialBeanCreator = new BeanProcessor.BeanCreator() {            
             public Object getBean() {                                
                 Object obj = getInstance();
                 //getinit, getdestroy, addpartial object don't need calling again.
                 //however, property injection does.
                 setProperties(obj);
                 //as this is the post init chain, new beans need to go thru 
                 //the pre-init chain, and then have init called, before 
                 //being passed along the post-init chain.
                 obj = runBeanProcPreInit(obj);
                 runBeanProcInit(getInitMethod(obj), obj);
                 return obj;
             }
         };
 
         BeanProcessor.BeanCreator currentCreator = initialBeanCreator;
         for(BeanProcessor processor : processors){
             obj = processor.afterInit(objgetName(), currentCreatorbeanData);
             currentCreator = new BeanCreatorChain(currentCreatorprocessorbeanDatabeanName..);
         }
         return obj;
     }    
     
     private Object addInterceptors(final Object originalCollection<Class<?>> requiredInterfaces)
             throws ComponentDefinitionException {
 
         Object intercepted = null;
         if(requiredInterfaces.isEmpty())
         	requiredInterfaces.add(original.getClass());
         
                 .getComponentDefinitionRegistry();
         List<Interceptorinterceptors = reg.getInterceptors();
         if (interceptors != null && interceptors.size() > 0) {
             try {
                 Bundle b = FrameworkUtil.getBundle(original.getClass());
                 if (b == null) {
                     // we have a class from the framework parent, so use our bundle for proxying.
                     b = .getBundleContext().getBundle();
                 }
                 intercepted = .getProxyManager().createInterceptingProxy(b,
                 requiredInterfacesoriginal, CollaboratorFactory.create(interceptors));
             } catch (org.apache.aries.proxy.UnableToProxyException e) {
                 Bundle b = .getBundleContext().getBundle();
                 throw new ComponentDefinitionException("Unable to create proxy for bean " +  + " in bundle " + b.getSymbolicName() + "/" + b.getVersion(), e);
             }
         } else {
             intercepted = original;
         }
         return intercepted;
     }
         
     @Override
     protected Object internalCreate() throws ComponentDefinitionException {
         if ( instanceof ReferenceRecipe) {
             ReferenceRecipe rr = (ReferenceRecipe;
             if (rr.getProxyChildBeanClasses() != null) {
                 return createProxyBean(rr);
             }
         } 
         return new UnwrapperedBeanHolder(internalCreate2(), this);
     }
     
     private Object createProxyBean(ReferenceRecipe rr) {
         try {
             VoidableCallable vc = new VoidableCallable();
             rr.addVoidableChild(vc);
             return .getProxyManager().createDelegatingProxy(
                 .getBundleContext().getBundle(), rr.getProxyChildBeanClasses(),
                 vcvc.call());
         } catch (UnableToProxyException e) {
             throw new ComponentDefinitionException(e);
         }
     }
     
     private Object internalCreate2() throws ComponentDefinitionException {
         
 
         Object obj = getInstance();
                 
         // check for init lifecycle method (if any)
         Method initMethod = getInitMethod(obj);
         
         // check for destroy lifecycle method (if any)
         getDestroyMethod(obj);
         
         // Add partially created object to the container
 //        if (initMethod == null) {
             addPartialObject(obj);
 //        }
 
         // inject properties
         setProperties(obj);
         
         obj = runBeanProcPreInit(obj);
         
         runBeanProcInit(initMethodobj);
         
         obj = runBeanProcPostInit(obj);
         
         //Replaced by calling wrap on the UnwrapperedBeanHolder
 //        obj = addInterceptors(obj);
         
         return obj;
     }
     
     static Object wrap(UnwrapperedBeanHolder holderCollection<Class<?>> requiredViews) {
         return holder.recipe.addInterceptors(holder.unwrapperedBeanrequiredViews);
     }
     
     static Object wrap(UnwrapperedBeanHolder holderClass<?> requiredView) {
         if(requiredView == Object.class) {
           //We don't know what we need so we have to do everything
             return holder.recipe.addInterceptors(holder.unwrapperedBeannew ArrayList<Class<?>>(1));
         } else {
         	return holder.recipe.addInterceptors(holder.unwrapperedBean, ProxyUtils.asList(requiredView));
         }
     }
     
     
     @Override
     public void destroy(Object obj) {
         if (!(obj instanceof UnwrapperedBeanHolder)) {
             .warn("Object to be destroyed is not an instance of UnwrapperedBeanHolder, type: " + obj);
             return;
         }
     
         obj = ((UnwrapperedBeanHolder)obj).;
     
         for (BeanProcessor processor : .getProcessors(BeanProcessor.class)) {
             processor.beforeDestroy(objgetName());
         }
         try {
             Method method = getDestroyMethod(obj);
             if (method != null) {
                 invoke(methodobj, (Object[]) null);
             }
         } catch (ComponentDefinitionException e) {
             // This exception occurs if the destroy method does not exist, so we just output the exception message.
             .error(e.getMessage());
         } catch (InvocationTargetException ite) {
           Throwable t = ite.getTargetException();
           BundleContext ctx = .getBundleContext();
           Bundle b = ctx.getBundle();
           .error("The blueprint bean {} in bundle {}/{} incorrectly threw an exception from its destroy method."getName(), b.getSymbolicName(), b.getVersion(), t);
         } catch (Exception e) {
             BundleContext ctx = .getBundleContext();
             Bundle b = ctx.getBundle();
             .error("An exception occurred while calling the destroy method of the blueprint bean  in bundle {}/{}."getName(), b.getSymbolicName(), b.getVersion(), getRealCause(e));
         }
         for (BeanProcessor processor : .getProcessors(BeanProcessor.class)) {
             processor.afterDestroy(objgetName());
         }
     }
 
     public void setProperties(Object instancethrows ComponentDefinitionException {
         // clone the properties so they can be used again
         Map<String,ObjectpropertyValues = new LinkedHashMap<String,Object>();
         setProperties(propertyValuesinstanceinstance.getClass());
     }
 
     public Class getType() {
         if ( instanceof Class) {
             return (Class;
         } else if ( instanceof String) {
             return loadClass((String);
         } else {
             return null;
         }
     }
 
     private void setProperties(Map<StringObjectpropertyValuesObject instanceClass clazz) {
         // set remaining properties
         for (Map.Entry<StringObjectentry : propertyValues.entrySet()) {
             String propertyName = entry.getKey();
             Object propertyValue = entry.getValue();
 
             setProperty(instanceclazzpropertyNamepropertyValue);
         }
 
     }
 
     private void setProperty(Object instanceClass clazzString propertyNameObject propertyValue) {
         String[] names = propertyName.split("\\.");
         for (int i = 0; i < names.length - 1; i++) {
             PropertyDescriptor pd = getPropertyDescriptor(clazznames[i]);
             if (pd.allowsGet()) {
                 try {
                     instance = pd.get(instance);
                 } catch (Exception e) {
                     throw new ComponentDefinitionException("Error getting property: " + names[i] + " on bean " + getName() + " when setting property " + propertyName + " on class " + clazz.getName(), getRealCause(e));
                 }
                 if (instance == null) {
                     throw new ComponentDefinitionException("Error setting compound property " + propertyName + " on bean " + getName() + ". Property " + names[i] + " is null");
                 }
                 clazz = instance.getClass();
             } else {
                 throw new ComponentDefinitionException("No getter for " + names[i] + " property on bean " + getName() + " when setting property " + propertyName + " on class " + clazz.getName());
             }
         }
         
         // Instantiate value
         if (propertyValue instanceof Recipe) {
             propertyValue = ((RecipepropertyValue).create();
         }
 
         final PropertyDescriptor pd = getPropertyDescriptor(clazznames[names.length - 1]);
         if (pd.allowsSet()) {
             try {
                 pd.set(instancepropertyValue);
             } catch (Exception e) {
                 throw new ComponentDefinitionException("Error setting property: " + pdgetRealCause(e));
             }
         } else {
             throw new ComponentDefinitionException("No setter for " + names[names.length - 1] + " property");
         }
     }
 
     private ReflectionUtils.PropertyDescriptor getPropertyDescriptor(Class<?> clazzString name) {
         for (ReflectionUtils.PropertyDescriptor pd : ReflectionUtils.getPropertyDescriptors(clazz)) {
             if (pd.getName().equals(name)) {
                 return pd;
             }
         }
         throw new ComponentDefinitionException("Unable to find property descriptor " + name + " on class " + clazz.getName());
     }
         
     private Object invoke(Method methodObject