LoginSignup
8
7

More than 5 years have passed since last update.

Seasar2 を利用しなくても利用したい Seasar2 の ユーティリティ

Last updated at Posted at 2013-11-15

総称型を取得するのに便利

  1. GenericUtil
  2. CollectionsUtil
example
package jp.mirageworld.dao;

import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Map;

import org.seasar.framework.util.tiger.GenericUtil;

@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class AbstractDao<E> {

    protected final Class<E> entityClass;

    @SuppressWarnings("unchecked")
    public AbstractDao() {
        Class<E> entityClass = null;
        Map<TypeVariable<?>, Type> map;
        map = GenericUtil.getTypeVariableMap(getClass());
        for (Class<?> c = getClass(); c != Object.class; c = c.getSuperclass()) {
            if (c.getSuperclass() == AbstractDao.class) {
                Type type = c.getGenericSuperclass();
                Type[] arrays = GenericUtil.getGenericParameters(type);
                entityClass = (Class<E>) GenericUtil.getActualClass(arrays[0], map);
                break;
            }
        }
        this.entityClass = entityClass;
    }
}
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7