01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: AbstractProperty.java,v 1.4 2004/09/22 14:32:50 jesper Exp $
23: package net.infonode.properties.util;
24:
25: import net.infonode.properties.base.Property;
26: import net.infonode.properties.base.PropertyGroup;
27: import net.infonode.properties.base.exception.InvalidPropertyValueException;
28:
29: /**
30: * An abstract base class for properties.
31: *
32: * @author $Author: jesper $
33: * @version $Revision: 1.4 $
34: */
35: abstract public class AbstractProperty implements Property {
36: private PropertyGroup group;
37: private String name;
38: private Class type;
39: private String description;
40:
41: /**
42: * Constructor.
43: *
44: * @param group the property group
45: * @param name the property name
46: * @param type the property type
47: * @param description the property description
48: */
49: protected AbstractProperty(PropertyGroup group, String name,
50: Class type, String description) {
51: this .group = group;
52: this .name = name;
53: this .type = type;
54: this .description = description;
55:
56: if (group != null)
57: group.addProperty(this );
58: }
59:
60: public PropertyGroup getGroup() {
61: return group;
62: }
63:
64: public String getName() {
65: return name;
66: }
67:
68: public Class getType() {
69: return type;
70: }
71:
72: public String getDescription() {
73: return description;
74: }
75:
76: public boolean isMutable() {
77: return true;
78: }
79:
80: public void setValue(Object object, Object value) {
81: if (!canBeAssiged(value))
82: throw new InvalidPropertyValueException(this , value);
83: }
84:
85: public String toString() {
86: return getName();
87: }
88:
89: public boolean canBeAssiged(Object value) {
90: return isMutable()
91: && (value == null || getType().isAssignableFrom(
92: value.getClass()));
93: }
94:
95: }
|