001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket; 018 019import org.apache.wicket.model.IModel; 020 021/** 022 * An interface for all {@link Component components} with type-safe accessors and mutators 023 * for the model and its object. 024 * 025 * <p> 026 * Usage:<br> 027 * <code> 028 * public class MyComponent<T> extends AnotherComponent implements IGenericComponent<T, MyComponent<T>> { ... } 029 * </code> 030 * </p> 031 * 032 * @param <T> 033 * the type of the model object 034 * @param <C> 035 * the type of the component 036 */ 037public interface IGenericComponent<T, C extends IGenericComponent<? super T, ?>> 038{ 039 /** 040 * Typesafe getter for the model 041 * 042 * @return the model 043 */ 044 @SuppressWarnings("unchecked") 045 default IModel<T> getModel() 046 { 047 return (IModel<T>)getDefaultModel(); 048 } 049 050 /** 051 * Typesafe setter for the model 052 * 053 * @param model 054 * the new model 055 */ 056 default C setModel(IModel<T> model) 057 { 058 setDefaultModel(model); 059 return (C) this; 060 } 061 062 /** 063 * Typesafe getter for the model's object 064 * 065 * @return the model object 066 */ 067 @SuppressWarnings("unchecked") 068 default T getModelObject() 069 { 070 return (T)getDefaultModelObject(); 071 } 072 073 /** 074 * Typesafe setter for the model object 075 * 076 * @param object 077 * the new model object 078 */ 079 default C setModelObject(T object) 080 { 081 setDefaultModelObject(object); 082 return (C) this; 083 } 084 085 IModel<?> getDefaultModel(); 086 087 Component setDefaultModel(IModel<?> model); 088 089 Component setDefaultModelObject(Object object); 090 091 Object getDefaultModelObject(); 092}