001/* 002 * GWTEventService 003 * Copyright (c) 2011 and beyond, strawbill UG (haftungsbeschr?nkt) 004 * 005 * This is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Lesser General Public License as 007 * published by the Free Software Foundation; either version 3 of 008 * the License, or (at your option) any later version. 009 * Other licensing for GWTEventService may also be possible on request. 010 * Please view the license.txt of the project for more information. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this software; if not, write to the Free 019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 021 */ 022package de.novanic.eventservice.config.level; 023 024/** 025 * {@link de.novanic.eventservice.config.loader.ConfigurationLoader} instances can be registered at a {@link de.novanic.eventservice.config.level.ConfigLevel}. 026 * There are five pre-defined configuration levels ({@link de.novanic.eventservice.config.level.ConfigLevelFactory#LOWEST}, 027 * {@link de.novanic.eventservice.config.level.ConfigLevelFactory#LOW}, {@link de.novanic.eventservice.config.level.ConfigLevelFactory#DEFAULT}, 028 * {@link de.novanic.eventservice.config.level.ConfigLevelFactory#HIGH} and {@link de.novanic.eventservice.config.level.ConfigLevelFactory#HIGHEST}). 029 * Finer levels can be defined with a custom configuration level with {@link de.novanic.eventservice.config.level.ConfigLevelFactory#createConfigLevel(int)}. 030 * 031 * The loading process starts with the ConfigurationLoaders which are registered at the lower levels and check the availability. When the loader or rather the 032 * source is available the loader is used to load the {@link de.novanic.eventservice.config.EventServiceConfiguration}. Otherwise the next loader in the 033 * configuration level queue is checked. 034 * 035 * The ConfigLevelFactory is used by the {@link de.novanic.eventservice.config.EventServiceConfigurationFactory} and there are some pre-registered 036 * {@link de.novanic.eventservice.config.loader.ConfigurationLoader} instances. See {@link de.novanic.eventservice.config.EventServiceConfigurationFactory} 037 * for more information. 038 * 039 * @author sstrohschein 040 * <br>Date: 20.03.2009 041 * <br>Time: 19:44:33 042 */ 043public final class ConfigLevelFactory 044{ 045 /** 046 * LOWEST level = 1 - 2499 047 */ 048 public static final ConfigLevel LOWEST = createConfigLevel(1); 049 050 /** 051 * LOW level = 2500 - 4999 052 */ 053 public static final ConfigLevel LOW = createConfigLevel(2500); 054 055 /** 056 * DEFAULT level = 5000 - 7499 057 */ 058 public static final ConfigLevel DEFAULT = createConfigLevel(5000); 059 060 /** 061 * HIGH level = 7500 - 9999 062 */ 063 public static final ConfigLevel HIGH = createConfigLevel(7500); 064 065 /** 066 * HIGHEST level = >= 10000 067 */ 068 public static final ConfigLevel HIGHEST = createConfigLevel(10000); 069 070 private ConfigLevelFactory() {} 071 072 /** 073 * Creates a custom configuration level for finer steps than the pre-defined configuration levels 074 * ({@link de.novanic.eventservice.config.level.ConfigLevelFactory#LOWEST}, 075 * {@link de.novanic.eventservice.config.level.ConfigLevelFactory#LOW}, {@link de.novanic.eventservice.config.level.ConfigLevelFactory#DEFAULT}, 076 * {@link de.novanic.eventservice.config.level.ConfigLevelFactory#HIGH}, {@link de.novanic.eventservice.config.level.ConfigLevelFactory#HIGHEST}). 077 * @param aLevelIdent queue number of the level (configuration loading is started from the lesser level) 078 * @return created {@link de.novanic.eventservice.config.level.ConfigLevel} 079 */ 080 public static ConfigLevel createConfigLevel(final int aLevelIdent) { 081 return new DefaultConfigLevel(aLevelIdent); 082 } 083 084 /** 085 * Default implementation of {@link de.novanic.eventservice.config.level.ConfigLevel} 086 */ 087 private static class DefaultConfigLevel implements ConfigLevel 088 { 089 private final int myLevel; 090 091 /** 092 * Creates a {@link de.novanic.eventservice.config.level.ConfigLevel} with the specified level / queue number of the level 093 * @param aLevel level / queue number of the level 094 */ 095 private DefaultConfigLevel(final int aLevel) { 096 myLevel = aLevel; 097 } 098 099 /** 100 * Returns the specified level / queue number of the level 101 * @return specified level / queue number of the level 102 */ 103 public int getLevel() { 104 return myLevel; 105 } 106 107 public int compareTo(ConfigLevel aConfigLevel) { 108 final int theOtherLevel = aConfigLevel.getLevel(); 109 if(myLevel > theOtherLevel) { 110 return 1; 111 } else if(myLevel < theOtherLevel) { 112 return -1; 113 } 114 return 0; 115 } 116 117 public boolean equals(Object anObject) { 118 if(this == anObject) { 119 return true; 120 } 121 if(anObject == null || getClass() != anObject.getClass()) { 122 return false; 123 } 124 DefaultConfigLevel theOtherConfigLevel = (DefaultConfigLevel)anObject; 125 return myLevel == theOtherConfigLevel.myLevel; 126 } 127 128 public int hashCode() { 129 return myLevel; 130 } 131 132 public String toString() { 133 return "DefaultConfigLevel: " + myLevel; 134 } 135 } 136}