View Javadoc

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