All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.anteros.bean.validation.MetaBeanBuilder Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
/*******************************************************************************
 * Copyright 2012 Anteros Tecnologia
 *  
 * 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 br.com.anteros.bean.validation;

import java.util.HashMap;
import java.util.Map;

import br.com.anteros.bean.validation.model.MetaBean;
import br.com.anteros.core.log.LogLevel;
import br.com.anteros.core.log.Logger;
import br.com.anteros.core.log.LoggerProvider;
import br.com.anteros.core.utils.ArrayUtils;
import br.com.anteros.core.utils.ClassUtils;

/**
 * Description: internal implementation class to construct metabeans with
 * factories
*/ public class MetaBeanBuilder { private static final Logger log = LoggerProvider.getInstance().getLogger(MetaBeanBuilder.class.getName()); /** * here you can install different kinds of factories to create MetaBeans * from */ private MetaBeanFactory[] factories; /** * Create a new MetaBeanBuilder instance. */ public MetaBeanBuilder() { this(new MetaBeanFactory[] { new IntrospectorMetaBeanFactory() }); } /** * Create a new MetaBeanBuilder instance. * * @param factories */ public MetaBeanBuilder(MetaBeanFactory[] factories) { setFactories(factories); } /** * Get the configured set of {@link MetaBeanFactory} objects. * * @return {@link MetaBeanFactory} array */ public MetaBeanFactory[] getFactories() { return ArrayUtils.clone(factories); } /** * Set the array of {@link MetaBeanFactory} instances with which to enrich * {@link MetaBean}s. * * @param factories */ public void setFactories(MetaBeanFactory[] factories) { this.factories = ArrayUtils.clone(factories); } /** * Build a {@link MetaBean} for a given id. * * @param beanInfoId * @return MetaBean * @throws Exception * if unable to build */ public MetaBean buildForId(String beanInfoId) throws Exception { throw new IllegalArgumentException("MetaBean " + beanInfoId + " not found"); } /** * Build beans for all known ids. Default implementation returns an empty * map. * * @return Map of String : MetaBean */ public Map buildAll() throws Exception { return new HashMap(); } /** * Find the named class. * * @param className * @return Class found or null */ protected Class findLocalClass(String className) { if (className != null) { try { return ClassUtils.getClass(className); } catch (ClassNotFoundException e) { log.log(LogLevel.DEBUG, String.format("Class not found: %s", className), e); } } return null; } /** * Build a MetaBean for the specified class. * * @param clazz * @return MetaBean * @throws Exception */ public MetaBean buildForClass(Class clazz) throws Exception { MetaBean meta = new MetaBean(); if (clazz != null) { // local class here? meta.setBeanClass(clazz); meta.setId(clazz.getName()); // default id = full class name! } for (MetaBeanFactory factory : factories) { factory.buildMetaBean(meta); } return meta; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy