private void addAttributes(
      final JBossServiceAttributeConfig[] attributeConfigs,
      final List<ClassReflectionIndex> mBeanClassHierarchy,
      final MBeanServices mBeanServices,
      final ClassLoader classLoader)
      throws DeploymentUnitProcessingException {
    if (attributeConfigs != null) {
      final Service<Object> createDestroyService = mBeanServices.getCreateDestroyService();
      for (final JBossServiceAttributeConfig attributeConfig : attributeConfigs) {
        final String propertyName = attributeConfig.getName();
        final Inject injectConfig = attributeConfig.getInject();
        final ValueFactory valueFactoryConfig = attributeConfig.getValueFactory();

        if (injectConfig != null) {
          final Value<?> value = getValue(injectConfig, mBeanClassHierarchy);
          final Injector<Object> injector =
              getPropertyInjector(propertyName, mBeanClassHierarchy, createDestroyService, value);
          mBeanServices.addAttribute(injectConfig.getBeanName(), injector);
        } else if (valueFactoryConfig != null) {
          final Value<?> value = getValue(valueFactoryConfig, mBeanClassHierarchy, classLoader);
          final Injector<Object> injector =
              getPropertyInjector(propertyName, mBeanClassHierarchy, createDestroyService, value);
          mBeanServices.addAttribute(valueFactoryConfig.getBeanName(), injector);
        } else {
          final Value<?> value = getValue(attributeConfig, mBeanClassHierarchy);
          final Injector<Object> injector =
              getPropertyInjector(
                  propertyName, mBeanClassHierarchy, createDestroyService, Values.injectedValue());
          mBeanServices.addInjectionValue(injector, value);
        }
      }
    }
  }
 private static Value<?> getValue(
     final Inject injectConfig, final List<ClassReflectionIndex> mBeanClassHierarchy) {
   final String propertyName = injectConfig.getPropertyName();
   Value<?> valueToInject = Values.injectedValue();
   if (propertyName != null) {
     final Method getter = ReflectionUtils.getGetter(mBeanClassHierarchy, propertyName);
     final Value<Method> getterValue = new ImmediateValue<Method>(getter);
     valueToInject =
         cached(new MethodValue<Object>(getterValue, valueToInject, Values.<Object>emptyList()));
   }
   return valueToInject;
 }
 private static Value<?> getValue(
     final ValueFactory valueFactory,
     final List<ClassReflectionIndex> mBeanClassHierarchy,
     final ClassLoader classLoader)
     throws DeploymentUnitProcessingException {
   final String methodName = valueFactory.getMethodName();
   final ValueFactoryParameter[] parameters = valueFactory.getParameters();
   final List<Class<?>> paramTypes = new ArrayList<Class<?>>(parameters.length);
   final List<Value<?>> paramValues = new ArrayList<Value<?>>(parameters.length);
   for (ValueFactoryParameter parameter : parameters) {
     final Class<?> attributeTypeValue =
         ReflectionUtils.getClass(parameter.getType(), classLoader);
     paramTypes.add(attributeTypeValue);
     paramValues.add(
         new ImmediateValue<Object>(newValue(attributeTypeValue, parameter.getValue())));
   }
   final Value<Method> methodValue =
       new ImmediateValue<Method>(
           ReflectionUtils.getMethod(
               mBeanClassHierarchy, methodName, paramTypes.toArray(new Class<?>[0]), true));
   return cached(new MethodValue<Object>(methodValue, Values.injectedValue(), paramValues));
 }
 private static Injector<Object> getOptionalAttributeInjector(
     final String attributeName,
     final List<ClassReflectionIndex> mBeanClassHierarchy,
     final Service<Object> service) {
   return getPropertyInjector(attributeName, mBeanClassHierarchy, service, Values.injectedValue());
 }