1 /*
2 * This file is a part of CAST project.
3 * (c) Copyright 2007, AGH University of Science & Technology
4 * https://caribou.iisg.agh.edu.pl/trac/cast
5 *
6 * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 * http://www.eclipse.org/legal/epl-v10.html
10 */
11 /*
12 * File: CustomProperty.java
13 * Created: 2009-03-14
14 * Author: tmilos
15 * $Id: CustomProperty.java 3279 2009-08-31 14:10:02Z tmilos $
16 */
17
18 package pl.edu.agh.cast.data.model.property;
19
20 /**
21 * Custom property - contains the value of the property.
22 *
23 * @author AGH CAST Team
24 */
25 public class CustomProperty extends Property<MetaProperty> {
26
27 /**
28 * Serial version UID.
29 */
30 private static final long serialVersionUID = -781125505759458553L;
31
32 private Object value;
33
34 /**
35 * Creates new custom property.
36 *
37 * @param metaProperty
38 * {@link MetaProperty} which describes this property
39 */
40 public CustomProperty(MetaProperty metaProperty) {
41 super(metaProperty);
42 }
43
44 /**
45 * Creates new custom property with initialized value.
46 *
47 * @param metaProperty
48 * {@link MetaProperty} which describes this property
49 * @param value
50 * initial value
51 */
52 public CustomProperty(MetaProperty metaProperty, Object value) {
53 super(metaProperty);
54 this.value = value;
55 }
56
57 /**
58 * {@inheritDoc}
59 *
60 * @see pl.edu.agh.cast.data.model.property.Property#getValue()
61 */
62 @Override
63 public Object getValue() {
64 return this.value;
65 }
66
67 /**
68 * {@inheritDoc}
69 *
70 * @see pl.edu.agh.cast.data.model.property.Property#setValue(java.lang.Object)
71 */
72 @Override
73 public void setValue(Object value) {
74 if (!this.getMetaProperty().isWritable()) {
75 throw new PropertyException("The property is not writable"); //$NON-NLS-1$
76 }
77 if (!this.isValidValue(value)) {
78 throw new PropertyException(String.format("Invalid value for property of type '%1$s': %2$s", //$NON-NLS-1$
79 this.getMetaProperty().getType(), (value != null) ? value.getClass() : null));
80 }
81 this.value = value;
82 }
83
84 }