/*
 * Copyright 2007-2107 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 net.ymate.platform.core.beans;

import org.apache.commons.lang.NullArgumentException;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Ioc受控类描述对象
 *
 * @author 刘镇 (suninformation@163.com) on 15/5/21 上午10:50
 * @version 1.0
 */
public class BeanMeta implements Serializable {

    private Class<?> __beanClass;

    private Object __beanObject;

    private boolean __singleton;

    public static BeanMeta create(Object beanObject, Class<?> beanClass) {
        return new BeanMeta(beanClass, true, beanObject);
    }

    public static BeanMeta create(Class<?> beanClass) {
        return new BeanMeta(beanClass, false, null);
    }

    /**
     * 构造方法
     *
     * @param beanClass  受控Bean类型
     * @param singleton  是否单例模式
     * @param beanObject 若为单例模式则此参数可为空
     */
    public BeanMeta(Class<?> beanClass, boolean singleton, Object beanObject) {
        __beanClass = beanClass;
        __singleton = singleton;
        __beanObject = beanObject;
        if (singleton && beanObject == null) {
            throw new NullArgumentException("beanObject");
        }
    }

    public boolean isSingleton() {
        return __singleton;
    }

    public Class<?> getBeanClass() {
        return __beanClass;
    }

    public Object getBeanObject() {
        return __beanObject;
    }

    public void setBeanObject(Object beanObject) {
        if (!__singleton || beanObject == null) {
            throw new NullArgumentException("Not singleton Or beanObject was null");
        }
        __beanObject = beanObject;
    }

    public List<Class<?>> getBeanInterfaces(List<Class<?>> excludedClassSet) {
        List<Class<?>> _returnValues = new ArrayList<Class<?>>();
        if (__singleton && __beanObject != null) { // 仅处理单例且非空对象
            Class<?>[] _interfaces = __beanObject.getClass().getInterfaces();
            for (Class<?> _interface : _interfaces) {
                // 排除自定义接口
                if (excludedClassSet != null && excludedClassSet.contains(_interface)) {
                    continue;
                }
                _returnValues.add(_interface);
            }
        }
        return _returnValues;
    }
}

@@ -2350,85 +2350,21 @@
     
-if (__singleton && __beanObject != null) %7B // %E4%BB%85%E5%A4%84%E7%90%86%E5%8D%95%E4%BE%8B%E4%B8%94%E9%9D%9E%E7%A9%BA%E5%AF%B9%E8%B1%A1%0A            
+for (
 Class%3C?%3E
 %5B%5D _
@@ -2363,10 +2363,8 @@
 s%3C?%3E
-%5B%5D
  _in
@@ -2374,35 +2374,22 @@
 face
-s =
+ :
  __bean
-Object.get
 Class
-()
 .get
@@ -2404,68 +2404,12 @@
 es()
-;%0A            for (Class%3C?%3E _interface : _interfaces) %7B%0A    
+) %7B%0A
     
@@ -2427,20 +2427,16 @@
 %E6%8E%92%E9%99%A4%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%8F%A3%0A
-    
         
@@ -2528,20 +2528,16 @@
         
-    
 continue
@@ -2546,34 +2546,26 @@
             
- 
-   %7D%0A    
+%7D%0A
             
@@ -2595,30 +2595,16 @@
 rface);%0A
-            %7D%0A
         

优化获取受控Bean实现的接口集合方法，不区分是否单例