View Javadoc

1   package com.explosion.utilities.preferences.persist;
2   
3   import java.util.Map;
4   import java.util.prefs.Preferences;
5   
6   import com.explosion.utilities.preferences.impl.inmemory.InMemoryPreferencePersister;
7   import com.explosion.utilities.preferences.impl.sun.SunPreferencePersister;
8   import com.explosion.utilities.preferences.impl.xml.XMLPreferencePersistenceRequirement;
9   import com.explosion.utilities.preferences.impl.xml.XMLPreferencePersister;
10  
11  
12  /* =============================================================================
13   *       
14   *     Copyright 2004 Stephen Cowx
15   *
16   *     Licensed under the Apache License, Version 2.0 (the "License");
17   *     you may not use this file except in compliance with the License.
18   *     You may obtain a copy of the License at
19   *
20   *     http://www.apache.org/licenses/LICENSE-2.0
21   *
22   *     Unless required by applicable law or agreed to in writing, software
23   *     distributed under the License is distributed on an "AS IS" BASIS,
24   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25   *     See the License for the specific language governing permissions and
26   *     limitations under the License.
27   * 
28   * =============================================================================
29   */
30  
31  /***
32   * @author Stephen Cowx
33   * Created on 14-Mar-2005
34   */
35  public class PreferencePersisterFactory
36  {
37  
38      /***
39       * 
40       */
41      public PreferencePersisterFactory()
42      {
43      }
44      
45      public static PreferencePersister createPreferencePersister(Object referenceToStore)
46      {
47          PreferencePersister persister = null;
48          
49          if (referenceToStore instanceof Map)
50          {
51              return InMemoryPreferencePersister.createPreferencePersistor(referenceToStore);
52          }
53          else if (referenceToStore instanceof Preferences)
54          {
55              return SunPreferencePersister.createPreferencePersistor(referenceToStore);
56          }
57          else if (referenceToStore instanceof XMLPreferencePersistenceRequirement)
58          {
59              return XMLPreferencePersister.createPreferencePersistor(referenceToStore);
60          }
61          
62          return persister;
63      }
64  
65  }