1 /*
2 * #%L
3 * Nuiton Decorator
4 * %%
5 * Copyright (C) 2004 - 2011 CodeLutin
6 * %%
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Lesser Public License for more details.
16 *
17 * You should have received a copy of the GNU General Lesser Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20 * #L%
21 */
22 package org.nuiton.decorator;
23
24 import java.io.Serializable;
25
26 /**
27 * A simple contract to define a String decorator on any java object.
28 *
29 * @param <O> the type of data to decorate
30 * @author tchemit <chemit@codelutin.com>
31 * @since 2.3
32 */
33 public abstract class Decorator<O> implements Serializable {
34
35 private static final long serialVersionUID = -1L;
36
37 /** Type of the data to decorate */
38 protected final Class<O> type;
39
40 public Decorator(Class<O> type) throws NullPointerException {
41 if (type == null) {
42 throw new NullPointerException("type can not be null.");
43 }
44 this.type = type;
45 }
46
47 /**
48 * @param bean the bean to decorate
49 * @return the string value of the given bean
50 */
51 public abstract String toString(Object bean);
52
53 public Class<O> getType() {
54 return type;
55 }
56 }