1 package com.acumenvelocity.ath.common;
2
3 import java.io.IOException;
4 import java.util.Properties;
5
6 import com.acumenvelocity.ath.common.exception.AthRuntimeException;
7
8 /**
9 * Utility class for loading and accessing project properties from the classpath.
10 * Properties are loaded once from '/project.properties' file during class initialization.
11 *
12 * <p>
13 * This class provides type-safe access to property values with support for
14 * both string and integer property types.
15 * </p>
16 *
17 * @author Acumen Velocity
18 * @version 1.0
19 * @since 1.0
20 * @see Properties
21 */
22 public class ProjectProps {
23 // Static Properties object loaded once during class initialization
24 private static final Properties projectProps = new Properties();
25
26 // Static initialization block - loads properties when class is first referenced
27 static {
28 try {
29 // Load properties from project.properties file in classpath root
30 projectProps.load(ProjectProps.class.getResourceAsStream("/project.properties"));
31 } catch (IOException e) {
32 // Log error and throw runtime exception if properties cannot be loaded
33 AthRuntimeException.logAndThrow(ProjectProps.class,
34 "Error loading ATH properties");
35 }
36 }
37
38 /**
39 * Retrieves a string property value by name.
40 *
41 * @param propName the name of the property to retrieve
42 * @return the property value as String, or null if property not found
43 */
44 public static String getProjectPropValue(String propName) {
45 return projectProps.getProperty(propName);
46 }
47
48 /**
49 * Retrieves an integer property value by name.
50 *
51 * @param propName the name of the property to retrieve
52 * @return the property value as int
53 * @throws NumberFormatException if the property value cannot be parsed as integer
54 */
55 public static int getProjectPropIntValue(String propName) {
56 return Integer.valueOf(getProjectPropValue(propName));
57 }
58 }