Skip to content

Commit 20223db

Browse files
author
=
committed
trying out a bunch of new stuff including property file resource injection, bootstrap api, property file organisation, ui composition...
1 parent f7019ed commit 20223db

11 files changed

+206
-18
lines changed

.idea/artifacts/algorithms_war_exploded.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Maven__commons_collections_commons_collections_3_2_1.xml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Jboss.xml renamed to .idea/runConfigurations/JBoss_.xml

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Algorithms.iml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
<orderEntry type="inheritedJdk" />
4040
<orderEntry type="sourceFolder" forTests="false" />
4141
<orderEntry type="library" name="commons-lang3-3.1" level="application" />
42-
<orderEntry type="library" name="commons-collections4-4.0-alpha1" level="application" />
4342
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jboss.spec:jboss-javaee-all-6.0:3.0.2.Final" level="project" />
4443
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.activation:activation:1.1.1" level="project" />
4544
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.enterprise:cdi-api:1.0-SP4" level="project" />
@@ -75,6 +74,7 @@
7574
<orderEntry type="library" name="Maven: xalan:serializer:2.7.1" level="project" />
7675
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.04" level="project" />
7776
<orderEntry type="library" name="Maven: joda-time:joda-time:2.2" level="project" />
77+
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
7878
</component>
7979
</module>
8080

pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
<artifactId>joda-time</artifactId>
3939
<version>2.2</version>
4040
</dependency>
41+
<dependency>
42+
<groupId>commons-collections</groupId>
43+
<artifactId>commons-collections</artifactId>
44+
<version>3.2.1</version>
45+
</dependency>
4146
</dependencies>
4247

4348
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.thenaglecode.core;
2+
3+
4+
import javax.servlet.ServletException;
5+
import javax.servlet.annotation.WebServlet;
6+
import javax.servlet.http.HttpServlet;
7+
8+
/**
9+
* Created with IntelliJ IDEA.
10+
* User: jxnagl
11+
* Date: 8/6/13
12+
* Time: 3:46 PM
13+
*
14+
* place all initialization code in here.
15+
*/
16+
17+
@WebServlet(name = "startup", loadOnStartup = 1)
18+
public class StartUp extends HttpServlet{
19+
20+
@Override
21+
public void init() throws ServletException {
22+
super.init();
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.thenaglecode.core.util;
2+
3+
import com.thenaglecode.core.util.propeties.AbstractConfigurationManager;
4+
import org.apache.commons.collections.MapIterator;
5+
import org.apache.commons.collections.map.HashedMap;
6+
7+
import javax.validation.constraints.NotNull;
8+
9+
/**
10+
* Created with IntelliJ IDEA.
11+
* User: jxnagl
12+
* Date: 8/6/13
13+
* Time: 3:54 PM
14+
*/
15+
public class ConfigurationUtil {
16+
17+
@NotNull
18+
private static final HashedMap configurationManagers = new HashedMap();
19+
20+
/**
21+
* returns true if the configuration was successfully refreshed, false if the configuration was not found.
22+
* is equivalent to calling refreshConfigurationManager(fqn, "configuration");
23+
* @param fqn the fully qualified name of the ConfigurationManager e.g. com.thenaglecode.core
24+
* @return true if it was successfully refreshed, false if not.
25+
*/
26+
public static boolean refreshConfigurationManager(@NotNull String fqn){
27+
return refreshConfigurationManager(fqn, "configuration");
28+
}
29+
30+
public static boolean refreshConfigurationManager(@NotNull String subsystem, @NotNull String fileName){
31+
AbstractConfigurationManager manager = (AbstractConfigurationManager) configurationManagers.get(subsystem + "." + fileName);
32+
if(manager == null) return false;
33+
manager.refresh();
34+
return true;
35+
}
36+
37+
public static void refreshAllConfigurationManagers(){
38+
MapIterator it = configurationManagers.mapIterator();
39+
while (it.hasNext()){
40+
((AbstractConfigurationManager)it.getValue()).refresh();
41+
}
42+
}
43+
44+
public static void registerConfigurationManager(AbstractConfigurationManager configurationManager){
45+
configurationManagers.put(configurationManager.getName(), configurationManager);
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.thenaglecode.core.util;
2+
3+
/**
4+
* Created with IntelliJ IDEA.
5+
* User: jxnagl
6+
* Date: 8/6/13
7+
* Time: 12:21 PM
8+
* This interface defines a class whose state may be refreshed. an example would be a class that manages
9+
* a list of properties contained in a properties file.
10+
*/
11+
public interface Refreshable {
12+
13+
/**
14+
* Refresh this object's state.
15+
*/
16+
public void refresh();
17+
}

src/main/java/com/thenaglecode/core/util/propeties/AbstractConfigurationManager.java

+39-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.thenaglecode.core.util.propeties;
22

33
import com.thenaglecode.core.util.ConfigurationItem;
4+
import com.thenaglecode.core.util.ConfigurationUtil;
5+
import com.thenaglecode.core.util.Named;
6+
import com.thenaglecode.core.util.Refreshable;
47

5-
import java.util.PropertyResourceBundle;
6-
import java.util.ResourceBundle;
8+
import javax.validation.constraints.NotNull;
79

810
/**
911
* Created with IntelliJ IDEA.
@@ -16,10 +18,13 @@
1618
* <tt>AbstractConfigurationManager</tt> implementation. if a filename is not specified, the default of
1719
* <tt>"configuration"</tt> is used.
1820
*/
19-
public abstract class AbstractConfigurationManager {
21+
public abstract class AbstractConfigurationManager implements Refreshable, Named {
2022

21-
ResourceBundle bundle;
23+
@NotNull
2224
private String propertyFile;
25+
@NotNull
26+
RefreshablePropertyResourceBundle bundle;
27+
@NotNull
2328
private static final String DEFAULT_CONFIG_BUDNLE_NAME = "configuration";
2429

2530
/**
@@ -31,19 +36,20 @@ protected AbstractConfigurationManager(){
3136

3237
protected AbstractConfigurationManager(String propertyFile){
3338
init(propertyFile);
39+
ConfigurationUtil.registerConfigurationManager(this);
3440
}
3541

36-
private final String getPropertyFile() {
42+
private String getPropertyFile() {
3743
return propertyFile;
3844
}
3945

40-
private final void setPropertyFile(String propertyFile) {
46+
private void setPropertyFile(String propertyFile) {
4147
this.propertyFile = propertyFile;
4248
}
4349

4450
public String getValue(String key){
4551
if(bundle != null){
46-
return bundle.getString(key);
52+
return bundle.getBundle().getString(key);
4753
} else {
4854
return null;
4955
}
@@ -54,14 +60,37 @@ public String getValue(ConfigurationItem configurationItem){
5460
return (value == null) ? configurationItem.getDefaultValue() : value;
5561
}
5662

63+
/**
64+
* {@inheritDoc}
65+
*/
66+
@Override
67+
synchronized public void refresh() {
68+
bundle.refresh();
69+
}
70+
5771
protected void init(){
5872
init(getPropertyFile());
5973
}
6074

75+
/**
76+
* {@inheritDoc}
77+
*/
78+
@Override
79+
public String getName() {
80+
return getFullyQualifiedPropertyFileReference();
81+
}
82+
83+
/**
84+
* returns the fully qualified name of the properties file without the .properties
85+
* @return the fully qualified name of the properties file without the .properties
86+
*/
87+
private String getFullyQualifiedPropertyFileReference(){
88+
return getClass().getPackage().getName() + "." + propertyFile;
89+
}
90+
6191
protected void init(String propertyFile) {
6292
setPropertyFile(propertyFile);
63-
String baseName = getClass().getPackage().getName() + "." + propertyFile;
64-
65-
bundle = PropertyResourceBundle.getBundle(baseName);
93+
String baseName = getFullyQualifiedPropertyFileReference();
94+
bundle = new RefreshablePropertyResourceBundle(baseName);
6695
}
6796
}

src/main/java/com/thenaglecode/core/util/propeties/PropertiesResourceBundleLocator.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import javax.enterprise.inject.Produces;
44
import javax.enterprise.inject.spi.InjectionPoint;
55
import java.io.IOException;
6-
import java.util.PropertyResourceBundle;
7-
import java.util.ResourceBundle;
86
import java.util.logging.Level;
97
import java.util.logging.Logger;
108

@@ -20,9 +18,9 @@ public class PropertiesResourceBundleLocator {
2018

2119
@Produces
2220
@PropertyBundleResource(name = "")
23-
ResourceBundle loadPropertiesResource(InjectionPoint ip) throws IOException {
21+
RefreshablePropertyResourceBundle loadPropertiesResource(InjectionPoint ip) throws IOException {
2422
logger.log(Level.FINE, "-- called PropertiesResourceBundle loader");
2523
PropertiesResource annotation = ip.getAnnotated().getAnnotation(PropertiesResource.class);
26-
return PropertyResourceBundle.getBundle(annotation.name());
24+
return new RefreshablePropertyResourceBundle(annotation.name());
2725
}
2826
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.thenaglecode.core.util.propeties;
2+
3+
import com.thenaglecode.core.util.Refreshable;
4+
5+
import javax.validation.constraints.NotNull;
6+
import java.util.MissingResourceException;
7+
import java.util.PropertyResourceBundle;
8+
import java.util.ResourceBundle;
9+
10+
/**
11+
* Created with IntelliJ IDEA.
12+
* User: jxnagl
13+
* Date: 8/6/13
14+
* Time: 12:23 PM
15+
* Wrapper class for the Resource bundle that allows the bundle to be refreshed.
16+
*/
17+
public class RefreshablePropertyResourceBundle implements Refreshable {
18+
19+
private String propertyFileFQN;
20+
private ResourceBundle bundle;
21+
22+
/**
23+
* Accepts a fully qualified file name with out the .properties extension and loads the bundle into the class.
24+
* @param propertyFileFQN the fully qualified name of the resource.
25+
* @throws MissingResourceException if the given properties file could not be found.
26+
*/
27+
public RefreshablePropertyResourceBundle(@NotNull String propertyFileFQN) throws MissingResourceException {
28+
setPropertyFileFQN(propertyFileFQN);
29+
setBundle(PropertyResourceBundle.getBundle(propertyFileFQN));
30+
}
31+
32+
/**
33+
* {@inheritDoc}
34+
*/
35+
@Override
36+
public void refresh() {
37+
setBundle(PropertyResourceBundle.getBundle(getPropertyFileFQN()));
38+
}
39+
40+
public String getPropertyFileFQN() {
41+
return propertyFileFQN;
42+
}
43+
44+
private void setPropertyFileFQN(String propertyFileFQN) {
45+
this.propertyFileFQN = propertyFileFQN;
46+
}
47+
48+
public ResourceBundle getBundle() {
49+
return bundle;
50+
}
51+
52+
private void setBundle(ResourceBundle bundle) {
53+
this.bundle = bundle;
54+
}
55+
}

0 commit comments

Comments
 (0)