Skip to content

Commit 2bb49c6

Browse files
committed
added configuration related changes
1 parent 151c85d commit 2bb49c6

File tree

3 files changed

+144
-79
lines changed

3 files changed

+144
-79
lines changed

src/main/java/org/audit4j/core/Configuration.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import java.util.Map;
2626

2727
import org.audit4j.core.filter.AuditEventFilter;
28+
import org.audit4j.core.handler.ConsoleAuditHandler;
2829
import org.audit4j.core.handler.Handler;
2930
import org.audit4j.core.layout.Layout;
31+
import org.audit4j.core.layout.SimpleLayout;
3032

3133
/**
3234
* The Class Configuration.
@@ -65,6 +67,34 @@ public Configuration() {
6567

6668
}
6769

70+
/** Return new static instance.
71+
*
72+
* @since 2.3.1
73+
* */
74+
public static Configuration INSTANCE = new Configuration();
75+
76+
/** Return default configurations of audit4j.
77+
*
78+
* @since 2.3.1
79+
* */
80+
public static Configuration DEFAULT = getDefault();
81+
82+
/**
83+
* Gets the default.
84+
*
85+
* @return the default
86+
*
87+
* @since 2.3.1
88+
*/
89+
private static Configuration getDefault(){
90+
Configuration config = new Configuration();
91+
config.addHandler(new ConsoleAuditHandler());
92+
config.setMetaData(new DummyMetaData());
93+
config.setLayout(new SimpleLayout());
94+
config.addProperty("log.file.location", "user.dir");
95+
return config;
96+
}
97+
6898
/**
6999
* Gets the meta data.
70100
*

src/main/java/org/audit4j/core/CoreConstants.java

Lines changed: 83 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -20,98 +20,115 @@
2020

2121
/**
2222
* The Class CoreConstants.
23-
*
23+
*
2424
* @author <a href="mailto:[email protected]">Janith Bandara</a>
25-
*
25+
*
2626
* @since 1.0.0
2727
*/
2828
public final class CoreConstants {
2929

30-
/** The Constant APP_NAME. */
31-
public static final String APP_NAME = "Audit4j";
30+
/** The Constant APP_NAME. */
31+
public static final String APP_NAME = "Audit4j";
32+
33+
/** The Constant RELEASE_VERSION. */
34+
public static final String RELEASE_VERSION = "2.2.0";
35+
36+
/** The Constant RELEASE_DATE. */
37+
public static final String RELEASE_DATE = "2014-08-29T12:40:21.077Z";
38+
39+
/** The Constant SUPPORT_JAVA_VERSION. */
40+
public static final String SUPPORT_JAVA_VERSION = "7";
41+
42+
/** The Constant AUDIT_EXTENTION. */
43+
public static final String AUDIT_EXTENTION = ".audit";
44+
45+
/** The Constant SITE_URL. */
46+
public static final String SITE_URL = "http://audit4j.org";
47+
48+
/** The Constant CONFIG_FILE_NAME. */
49+
public static final String CONFIG_FILE_NAME = "audit4j.conf.yml";
50+
51+
/** The Constant COLON_CHAR. */
52+
public static final char COLON_CHAR = ':';
53+
54+
/** The Constant COLON. */
55+
public static final String COLON = ":";
56+
57+
/** The Constant SEMI_COLON_CHAR. */
58+
public static final char SEMI_COLON_CHAR = ';';
59+
60+
/** The Constant SEMI_COLON. */
61+
public static final String SEMI_COLON = ";";
62+
63+
/** The Constant COMMA_CHAR. */
64+
public static final char COMMA_CHAR = ',';
3265

33-
/** The Constant RELEASE_VERSION. */
34-
public static final String RELEASE_VERSION = "2.2.0";
66+
/** The Constant EQ_CHAR. */
67+
public static final char EQ_CHAR = '=';
3568

36-
/** The Constant RELEASE_DATE. */
37-
public static final String RELEASE_DATE = "2014-08-29T12:40:21.077Z";
69+
/** The Constant DASH_CHAR. */
70+
public static final char DASH_CHAR = '-';
3871

39-
/** The Constant SUPPORT_JAVA_VERSION. */
40-
public static final String SUPPORT_JAVA_VERSION = "7";
72+
/** The Constant OPEN_BRACES_CHAR. */
73+
public static final char OPEN_BRACES_CHAR = '{';
4174

42-
/** The Constant AUDIT_EXTENTION. */
43-
public static final String AUDIT_EXTENTION = ".audit";
75+
/** The Constant CLOSE_BRACES_CHAR. */
76+
public static final char CLOSE_BRACES_CHAR = '}';
4477

45-
/** The Constant SITE_URL. */
46-
public static final String SITE_URL = "http://audit4j.org";
78+
/** The Constant BRACKETS. */
79+
public static final String BRACKETS = "[]";
4780

48-
/** The Constant CONFIG_FILE_NAME. */
49-
public static final String CONFIG_FILE_NAME = "audit4j.conf.yml";
81+
/** The Constant OPEN_BRACKETS_CHAR. */
82+
public static final char OPEN_BRACKETS_CHAR = '[';
5083

51-
/** The Constant COLON_CHAR. */
52-
public static final char COLON_CHAR = ':';
84+
/** The Constant CLOSE_BRACKETS_CHAR. */
85+
public static final char CLOSE_BRACKETS_CHAR = ']';
5386

54-
/** The Constant COMMA_CHAR. */
55-
public static final char COMMA_CHAR = ',';
56-
57-
public static final char EQ_CHAR = '=';
87+
/** The Constant ARROW. */
88+
public static final String ARROW = "==>";
5889

59-
/** The Constant DASH_CHAR. */
60-
public static final char DASH_CHAR = '-';
61-
62-
public static final char OPEN_BRACES_CHAR = '{';
63-
64-
public static final char CLOSE_BRACES_CHAR = '}';
65-
66-
public static final String BRACKETS = "[]";
67-
68-
public static final char OPEN_BRACKETS_CHAR = '[';
69-
70-
public static final char CLOSE_BRACKETS_CHAR = ']';
90+
/** The Constant PIPE. */
91+
public static final char PIPE = '|';
7192

72-
/** The Constant ARROW. */
73-
public static final String ARROW = "==>";
93+
/** The Constant SPACE. */
94+
public static final char SPACE = ' ';
7495

75-
/** The Constant PIPE. */
76-
public static final char PIPE = '|';
96+
/** The Constant WINDOWS_SEPARATOR. */
97+
public static final char WINDOWS_SEPARATOR = '\\';
7798

78-
/** The Constant SPACE. */
79-
public static final char SPACE = ' ';
99+
/** The Constant UNIX_SEPARATOR. */
100+
public static final char UNIX_SEPARATOR = '/';
80101

81-
/** The Constant WINDOWS_SEPARATOR. */
82-
public static final char WINDOWS_SEPARATOR = '\\';
102+
/** The Constant READ_WRITE. */
103+
public static final String READ_WRITE = "rw";
83104

84-
/** The Constant UNIX_SEPARATOR. */
85-
public static final char UNIX_SEPARATOR = '/';
105+
/** The Constant NEW_LINE. */
106+
public static final String NEW_LINE = "\n";
86107

87-
/** The Constant READ_WRITE. */
88-
public static final String READ_WRITE = "rw";
108+
/** The Constant NULL. */
109+
public static final String NULL = "null";
89110

90-
/** The Constant NEW_LINE. */
91-
public static final String NEW_LINE = "\n";
92-
93-
public static final String NULL = "null";
111+
/** The Constant DEFAULT_ACTOR. */
112+
public static final String DEFAULT_ACTOR = "Audit4j User";
94113

95-
/** The Constant DEFAULT_ACTOR. */
96-
public static final String DEFAULT_ACTOR = "Audit4j User";
114+
/** The Constant ACTION. */
115+
public static final String DEFAULT_ACTION = "action";
97116

98-
/** The Constant ACTION. */
99-
public static final String DEFAULT_ACTION = "action";
117+
/** The Constant SALT. */
118+
public static final String DEFAULT_SECURE_SALT = "232332324";
100119

101-
/** The Constant SALT. */
102-
public static final String DEFAULT_SECURE_SALT = "232332324";
120+
/** The Constant DEFAULT_SECURE_KEY. */
121+
public static final String DEFAULT_SECURE_KEY = "Aud1T4jSecureKey";
103122

104-
/** The Constant DEFAULT_SECURE_KEY. */
105-
public static final String DEFAULT_SECURE_KEY = "Aud1T4jSecureKey";
123+
/** The Constant IV. */
124+
public static final String IV = "e675f725e675f725";
106125

107-
/** The Constant IV. */
108-
public static final String IV = "e675f725e675f725";
126+
/** The Constant ENCODE_UTF8. */
127+
public static final String ENCODE_UTF8 = "UTF-8";
109128

110-
/** The Constant ENCODE_UTF8. */
111-
public static final String ENCODE_UTF8 = "UTF-8";
129+
/** The Constant EMBEDED_DB_NAME. */
130+
public static final String DEFAULT_EMBEDED_DB_NAME = "audit4j";
112131

113-
/** The Constant EMBEDED_DB_NAME. */
114-
public static final String DEFAULT_EMBEDED_DB_NAME = "audit4j";
115-
116-
public static final String DEFAULT_DATE_FORMAT = "MM/dd/yyyy HH:mm:ss";
132+
/** The Constant DEFAULT_DATE_FORMAT. */
133+
public static final String DEFAULT_DATE_FORMAT = "MM/dd/yyyy HH:mm:ss";
117134
}

src/main/java/org/audit4j/core/util/ReflectUtil.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,65 @@
22

33
import java.lang.reflect.Constructor;
44
import java.lang.reflect.InvocationTargetException;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import org.audit4j.core.exception.InitializationException;
59

610
/**
711
* The Class ReflectUtil.
812
*
9-
* @param <T> the generic type
13+
* @param <I> the generic type
1014
* @author <a href="mailto:[email protected]">Janith Bandara</a>
15+
*
16+
* @since 2.3.1
1117
*/
12-
public class ReflectUtil<T> {
18+
public class ReflectUtil<I> {
1319

1420
/**
1521
* Gets the new instance.
1622
*
1723
* @param clazz the clazz
1824
* @return the new instance
1925
*/
20-
public T getNewInstance(Class<T> clazz) {
21-
Constructor<T> ctor;
26+
public I getNewInstance(Class<I> clazz) {
27+
Constructor<I> ctor;
2228
try {
2329
ctor = clazz.getConstructor();
2430
return ctor.newInstance();
2531
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
2632
| IllegalArgumentException | InvocationTargetException e) {
27-
// TODO Auto-generated catch block
28-
e.printStackTrace();
33+
throw new InitializationException("Given class not found", e);
2934
}
30-
return null;
3135
}
32-
36+
3337
/**
3438
* Gets the new instance.
3539
*
3640
* @param className the class name
3741
* @return the new instance
3842
*/
39-
public T getNewInstance(String className) {
43+
@SuppressWarnings("unchecked")
44+
public I getNewInstance(String className) {
4045
try {
41-
return getNewInstance((Class<T>) Class.forName(className));
46+
return getNewInstance((Class<I>) Class.forName(className));
4247
} catch (ClassNotFoundException e) {
43-
// TODO Auto-generated catch block
44-
e.printStackTrace();
48+
throw new InitializationException("Given class not found", e);
49+
}
50+
}
51+
52+
/**
53+
* Gets the new instance list.
54+
*
55+
* @param clsssList the clsss list
56+
* @return the new instance list
57+
*/
58+
public List<I> getNewInstanceList(String[] clsssList) {
59+
List<I> instances = new ArrayList<>();
60+
for (String className : clsssList) {
61+
I instance = new ReflectUtil<I>().getNewInstance(className);
62+
instances.add(instance);
4563
}
46-
return null;
64+
return instances;
4765
}
4866
}

0 commit comments

Comments
 (0)