1 package com.atlassian.config;
2
3 public abstract class AbstractConfigElement implements ConfigElement
4 {
5 private String propertyName;
6 private AbstractConfigurationPersister config;
7
8 public AbstractConfigElement(String name, Object context, AbstractConfigurationPersister config)
9 {
10 this.propertyName = name;
11 setContext(context);
12 this.config = config;
13 }
14
15 public final void save(Object object) throws ConfigurationException
16 {
17 checkSaveObject(object);
18 saveConfig(object);
19 }
20
21 public final Object load() throws ConfigurationException
22 {
23 return loadConfig();
24 }
25
26
27 protected void checkSaveObject(Object object) throws ConfigurationException
28 {
29 if (object == null)
30 {
31 throw new ConfigurationException("Object to save cannot be null");
32 }
33
34 if (!getObjectClass().isAssignableFrom(object.getClass()))
35 {
36 throw new ConfigurationException("Object to save was not of expected type. Expected type was: " + getObjectClass() +
37 ", actual type is: " + object.getClass().getName());
38 }
39 }
40
41 public AbstractConfigurationPersister getConfiguration()
42 {
43 return config;
44 }
45
46 public String getPropertyName()
47 {
48 return propertyName;
49 }
50
51 public void setPropertyName(String name)
52 {
53 propertyName = name;
54 }
55
56 protected abstract Object loadConfig() throws ConfigurationException;
57
58 protected abstract void saveConfig(Object object) throws ConfigurationException;
59 }