Package br.net.woodstock.rockframework.core.reflection.impl

Source Code of br.net.woodstock.rockframework.core.reflection.impl.AbstractBeanDescriptorFactory

/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.core.reflection.impl;

import br.net.woodstock.rockframework.core.RockFrameworkLogger;
import br.net.woodstock.rockframework.core.cache.Cache;
import br.net.woodstock.rockframework.core.cache.CacheManager;
import br.net.woodstock.rockframework.core.cache.impl.CacheManagerImpl;
import br.net.woodstock.rockframework.core.reflection.BeanDescriptor;
import br.net.woodstock.rockframework.core.util.Assert;

abstract class AbstractBeanDescriptorFactory implements BeanDescriptorFactory {

  private Cache  cache;

  public AbstractBeanDescriptorFactory() {
    super();
    String id = String.valueOf(this);
    CacheManager cacheManager = CacheManagerImpl.getInstance();
    this.cache = cacheManager.create(id);
  }

  private void addToCache(final Class<?> clazz, final BeanDescriptor descriptor) {
    this.cache.add(clazz.getCanonicalName(), descriptor);
  }

  private BeanDescriptor getFromCache(final Class<?> clazz) {
    return (BeanDescriptor) this.cache.get(clazz.getCanonicalName());
  }

  private boolean hasOnCache(final Class<?> clazz) {
    return this.cache.contains(clazz.getCanonicalName());
  }

  @Override
  public final BeanDescriptor getBeanDescriptor(final Class<?> clazz) {
    Assert.notNull(clazz, "clazz");

    if (this.hasOnCache(clazz)) {
      RockFrameworkLogger.getLogger().info("Class " + clazz.getSimpleName() + " exists on cache");
      BeanDescriptor descriptor = this.getFromCache(clazz);
      return descriptor;
    }
    BeanDescriptor descriptor = this.getBeanDescriptorInternal(clazz);
    RockFrameworkLogger.getLogger().info("Adding class " + clazz.getSimpleName() + " to cache");
    this.addToCache(clazz, descriptor);
    return descriptor;
  }

  protected abstract BeanDescriptor getBeanDescriptorInternal(Class<?> clazz);

}
TOP

Related Classes of br.net.woodstock.rockframework.core.reflection.impl.AbstractBeanDescriptorFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.