/*
 *  Copyright 2012-2014 Eurocommercial Properties NV
 *
 *  Licensed under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.estatio.domsettings;


import org.joda.time.LocalDate;

import org.isisaddons.module.settings.dom.ApplicationSetting;
import org.isisaddons.module.settings.dom.ApplicationSettingsServiceRW;


public interface ApplicationSettingCreator {
    void create(ApplicationSettingsServiceRW appSettings);
    ApplicationSetting find(ApplicationSettingsServiceRW appSettings);
    
    String name();
    
    Class<?> getDataType();
    String getDescription();
    Object getDefaultValue();

    final static class Helper {
        private Helper(){}
        public static ApplicationSetting find(
                final ApplicationSettingCreator creator, final ApplicationSettingsServiceRW appSettings) {
            return appSettings.find(ApplicationSettingCreator.Helper.getKey(creator));
        }
        public static void create(
                final ApplicationSettingCreator creator, final ApplicationSettingsServiceRW appSettings) {
            final Class<?> dataType = creator.getDataType();
            final String key = getKey(creator);
            final String description = creator.getDescription();
            
            if(dataType == LocalDate.class) {
                appSettings.newLocalDate(key, description, (LocalDate)creator.getDefaultValue());
            }
            if(dataType == Boolean.class) {
                appSettings.newBoolean(key, description, (Boolean)creator.getDefaultValue());
            }
            if(dataType == Integer.class) {
                appSettings.newInt(key, description, (Integer)creator.getDefaultValue());
            }
            if(dataType == Long.class) {
                appSettings.newLong(key, description, (Long)creator.getDefaultValue());
            }
            if(dataType == String.class) {
                appSettings.newString(key, description, (String)creator.getDefaultValue());
            }
        }

        public static String getKey(final ApplicationSettingCreator creator) {
            return creator.getClass().getPackage().getName()+"."+creator.name();
        }
    }

}
@@ -662,17 +662,16 @@
 tings;%0A%0A
-%0A
 import o
@@ -830,17 +830,16 @@
 iceRW;%0A%0A
-%0A
 public i
@@ -1276,32 +1276,48 @@
 Creator creator,
+%0A               
  final Applicati
@@ -1470,20 +1470,473 @@
  static 
-void
+ApplicationSetting findOrCreate(%0A                final ApplicationSettingCreator creator,%0A                final ApplicationSettingsServiceRW appSettings) %7B%0A            final ApplicationSetting applicationSetting = appSettings.find(Helper.getKey(creator));%0A            if (applicationSetting == null)%7B%0A                return create(creator, appSettings);%0A            %7D%0A            return applicationSetting;%0A        %7D%0A        public static ApplicationSetting
  create(
@@ -1992,16 +1992,32 @@
 creator,
+%0A               
  final A
@@ -2233,28 +2233,16 @@
 tion();%0A
-            
 %0A       
@@ -2288,32 +2288,39 @@
                 
+return 
 appSettings.newL
@@ -2451,32 +2451,39 @@
                 
+return 
 appSettings.newB
@@ -2610,32 +2610,39 @@
                 
+return 
 appSettings.newI
@@ -2762,32 +2762,39 @@
                 
+return 
 appSettings.newL
@@ -2922,16 +2922,23 @@
         
+return 
 appSetti
@@ -3011,32 +3011,57 @@
 ;%0A            %7D%0A
+            return null;%0A
         %7D%0A%0A     

Introduce a findOrCreate method for application settings. The application setting is returned when created