/**
* Copyright 2011 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 org.bricket.web.master;
import java.io.Serializable;
import org.apache.wicket.model.IModel;
import org.bricket.plugin.genericdomain.domain.DomainObject;
import org.bricket.plugin.genericdomain.web.DomainObjectModel;
import org.springframework.util.Assert;
/**
* Implementation of IModelMaster for Bricket @see DomainObject. The model is a @see
* DomainObjectModel based in @see LoadableDetachableModel.
*
* @author Ingo Renner
*
*/
public class DomainModelMaster<T extends DomainObject> implements IModelMaster<T>, Serializable {
private DomainObjectModel<T> iModel;
private Class<T> classOfModelObject;
public DomainModelMaster(Class<T> type, Long id) {
Assert.notNull(type, "type can't be null");
classOfModelObject = type;
Assert.notNull(id, "id can't be null");
iModel = new DomainObjectModel<T>(type, id);
}
@SuppressWarnings("unchecked")
public DomainModelMaster(T domainObject) {
Assert.notNull(domainObject, "domainObject can't be null");
Assert.notNull(domainObject.getId(), "id can't be null");
classOfModelObject = (Class<T>) domainObject.getClass();
iModel = new DomainObjectModel<T>(domainObject);
}
@Override
public IModel<T> getIModel() {
return iModel;
}
@Override
public Class<T> getClassOfModelObject() {
return classOfModelObject;
}
}