001/** 002 * Copyright 2014 Tampere University of Technology, Pori Department 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package core.tut.pori.properties; 017 018import java.util.Properties; 019 020/** 021 * Base class for property files. 022 * 023 * All classes sub-classed from this base class will automatically be loaded and initialized by the system property handler. 024 */ 025public abstract class SystemProperty { 026 /* configuration file path */ 027 /** root path for the the configuration files */ 028 public static final String CONFIGURATION_FILE_PATH = "../"; 029 /** system property file path */ 030 protected static final String SYSTEM_PROPERTY_FILE = CONFIGURATION_FILE_PATH+"system.properties"; // the project defaults to WEB-INF/classes, but the properties file is at WEB-INF 031 032 /* core */ 033 /** property prefix for core */ 034 protected static final String PROPERTY_CORE_PORI = "core.tut.pori"; 035 /** property prefix for core/utils */ 036 protected static final String PROPERTY_CORE_PORI_UTILS = PROPERTY_CORE_PORI+".utils"; 037 /** property prefix for core/executor */ 038 protected static final String PROPERTY_CORE_PORI_EXECUTOR = PROPERTY_CORE_PORI+".executor"; 039 /* services */ 040 /** property prefix for service */ 041 protected static final String PROPERTY_SERVICE_PORI = "service.tut.pori"; 042 /** property prefix for service/properties */ 043 protected static final String PROPERTY_SERVICE_PORI_PROPERTIES = PROPERTY_CORE_PORI+".properties"; 044 045 /* parameters */ 046 /** property bind address */ 047 protected static final String PROPERTY_SERVICE_PORI_PROPERTIES_BIND_ADDRESS = PROPERTY_SERVICE_PORI_PROPERTIES+".bind_address"; 048 049 /** 050 * Initialize the system property. 051 * 052 * Note that when using the default file path, the passed object will be of type UnmodifiableProperties, 053 * and when using a custom file path, the object will be of type Properties 054 * 055 * @param properties 056 * @throws IllegalArgumentException 057 */ 058 public abstract void initialize(Properties properties) throws IllegalArgumentException; 059 060 /** 061 * By default, this returns null. On null value, the default system property file will be used. If non-null value is provided, the path will be used to load the requested properties. 062 * 063 * @return the path of the configuration file for this Property 064 */ 065 public String getPropertyFilePath(){ 066 return null; 067 } 068}