/*
 * Copyright 2012 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 bingo.lang;

import java.util.Map;

import bingo.lang.beans.BeanModel;
import bingo.lang.beans.BeanProperty;
import bingo.lang.exceptions.ObjectNotFoundException;

public class Beans {

	protected Beans(){
		
	}
	
	public static <T> BeanModel<T> forType(Class<T> classType) {
		return BeanModel.get(classType);
	}
	
	public static BeanModel<?> forName(String className) throws ObjectNotFoundException {
		return BeanModel.get(Classes.forName(className));
	}
	
	public static BeanProperty[] getProperties(Class<?> beanType) {
		return BeanModel.get(beanType).getProperties();
	}
	
	public static <T> T newInstance(Class<T> beanType){
		return BeanModel.get(beanType).newInstance();
	}
	
	public static boolean set(Object bean,String property,Object value){
		return BeanModel.get(bean.getClass()).set(bean, property, value);
	}
	
	public static Object get(Object bean,String property){
		return BeanModel.get(bean.getClass()).get(bean, property);
	}
	
	public static Map<String, Object> toMap(Object bean) {
		if(null == bean){
			return null;
		}
		return BeanModel.get(bean.getClass()).toMap(bean);
	}
}

@@ -669,16 +669,45 @@
 il.Map;%0D
+%0Aimport java.util.Map.Entry;%0D
 %0A%0D%0Aimpor
@@ -1516,32 +1516,363 @@
 value);%0D%0A%09%7D%0D%0A%09%0D%0A
+%09public static void set(Object bean,Map%3CString, Object%3E properties)%7B%0D%0A%09%09if(null == properties %7C%7C properties.isEmpty())%7B%0D%0A%09%09%09return ;%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09BeanModel%3C?%3E model = BeanModel.get(bean.getClass());%0D%0A%09%09%0D%0A%09%09for(Entry%3CString, Object%3E entry : properties.entrySet())%7B%0D%0A%09%09%09model.set(bean, entry.getKey(), entry.getValue());%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09%0D%0A
 %09public static O

add Beans.set(Object bean,Map<String,Object> properties)