/*
 * jHears, acoustic fingerprinting framework.
 * Copyright (C) 2009-2010  Juha Heljoranta.
 *
 * This file is part of jHears.
 *
 * jHears is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * jHears 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with jHears.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.jhears.webgui.util;

import java.io.Serializable;

import org.apache.wicket.injection.web.InjectorHolder;
import org.jhears.data.IGenericDao;
import org.jhears.util.Identifiable;

import com.google.inject.Inject;

public class EntityModel<T extends Identifiable<?>> extends
		AbstractEntityModel<T> {

	private static final long serialVersionUID = 1L;

	@Inject
	private IGenericDao dao;

	public EntityModel(T entity) {
		super(entity);
		InjectorHolder.getInjector().inject(this);
	}

	public EntityModel(Class<? extends T> clazz, Serializable id) {
		super(clazz, id);
		InjectorHolder.getInjector().inject(this);
	}

	@SuppressWarnings("unchecked")
	@Override
	protected T load(Class clazz, Serializable id) {
		return (T) dao.get(clazz, id);
	}
}