Skip to content

Commit d707eba

Browse files
author
=
committed
got rid of injections, i had a bad understanding of CDI
1 parent df9733a commit d707eba

File tree

16 files changed

+251
-359
lines changed

16 files changed

+251
-359
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<groupId>com.thenaglecode</groupId>
88
<artifactId>algorithms</artifactId>
9+
<packaging>pom</packaging>
910
<version>1.0.0.Pre-Alpha</version>
1011
<properties>
1112
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/com/thenaglecode/algorithms/ejb/session/singletons/ConfigurationBean.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/main/java/com/thenaglecode/algorithms/ejb/session/singletons/ResourceLocatorBean.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/main/java/com/thenaglecode/algorithms/ejb/session/singletons/StartUpBean.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22

33

44
import com.thenaglecode.core.Configuration;
5-
import com.thenaglecode.core.util.propeties.ConfigurationManager;
6-
import com.thenaglecode.core.util.propeties.InjectConfiguration;
75

86
import javax.annotation.PostConstruct;
9-
import javax.ejb.EJB;
107
import javax.ejb.Singleton;
118
import javax.ejb.Startup;
129
import javax.servlet.http.HttpServlet;
13-
import java.util.MissingResourceException;
14-
import java.util.ResourceBundle;
1510
import java.util.logging.Level;
1611
import java.util.logging.Logger;
1712

@@ -30,46 +25,9 @@ public class StartUpBean extends HttpServlet implements Configuration {
3025

3126
private static final Logger logger = Logger.getLogger(StartUpBean.class.getName());
3227

33-
@InjectConfiguration(subsystem = "core")
34-
private static final ConfigurationManager coreConfiguration = null;
35-
public static final String[] DEFAULT_FILENAMES = coreConfiguration.getValueArray(DEFAULT_CONFIGURATION_FILENAMES_ID);
36-
public static final String DEFAULT_BASE = coreConfiguration.getValue(DEFAULT_BASE_PACKAGE);
37-
38-
@EJB
39-
private ConfigurationBean configurationBean;
40-
4128
@PostConstruct
4229
public void init() {
4330
logger.log(Level.INFO, "---- Initializing App ----");
44-
45-
logger.log(Level.FINE, "loading configuration managers");
46-
initialiseConfigurationManagers();
47-
4831
logger.log(Level.FINE, "---- Initialization complete ----");
4932
}
50-
51-
/**
52-
* finds every configuration file in the project and creates a configuration manager for it if
53-
* it is in the array
54-
*/
55-
private void initialiseConfigurationManagers() {
56-
logger.log(Level.FINE, "finding config files and registering config managers");
57-
for (Package p : Package.getPackages()) {
58-
if (p.getName().startsWith(DEFAULT_BASE + ".")) {
59-
logger.log(Level.FINER, " -found valid package: " + p.getName());
60-
for (String configFileName : DEFAULT_FILENAMES) {
61-
String fileName = p.getName() + "." + configFileName;
62-
try {
63-
ResourceBundle.getBundle(fileName);
64-
logger.log(Level.FINER, "found config file: " + fileName + " registering new configuration manager");
65-
String subsystem = p.getName().substring(DEFAULT_BASE.length() + 1); // +1 accounts for the '.'
66-
logger.log(Level.FINER, "subsystem=" + subsystem);
67-
ConfigurationManager configurationManager = new ConfigurationManager(subsystem, configFileName);
68-
configurationBean.registerConfigurationManager(configurationManager);
69-
} catch (MissingResourceException ignore) {
70-
}
71-
}
72-
}
73-
}
74-
}
7533
}

src/main/java/com/thenaglecode/algorithms/primes/PrimeGenerator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.thenaglecode.algorithms.Configuration;
44
import com.thenaglecode.core.util.Named;
5-
import com.thenaglecode.core.util.propeties.ConfigurationManager;
6-
import com.thenaglecode.core.util.propeties.InjectConfiguration;
5+
import com.thenaglecode.core.util.propeties.ConfigurationUtil;
6+
import com.thenaglecode.core.util.propeties.RefreshablePropertyResourceBundle;
77

88
/**
99
* Created with IntelliJ IDEA.
@@ -13,8 +13,8 @@
1313
*/
1414
public abstract class PrimeGenerator implements Named, Configuration {
1515

16-
@InjectConfiguration(subsystem = "core")
17-
private static ConfigurationManager configurationManager;
16+
private static final RefreshablePropertyResourceBundle coreBundle
17+
= ConfigurationUtil.getRefreshablePropertyResourceBundle("core");
1818

1919
private static PrimeGenerator instance;
2020

@@ -25,7 +25,7 @@ public abstract class PrimeGenerator implements Named, Configuration {
2525
public static PrimeGenerator getGenerator() {
2626
if (instance == null) {
2727
try {
28-
instance = (PrimeGenerator) Class.forName(configurationManager.getValue(PRIMES_GENERATOR_CLASS)).newInstance();
28+
instance = (PrimeGenerator) Class.forName(coreBundle.getString(PRIMES_GENERATOR_CLASS)).newInstance();
2929
} catch (Exception e){
3030
instance = new PGSimple1();
3131
}

src/main/java/com/thenaglecode/core/security/Roles.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
*/
99
public interface Roles {
1010
public static final String SYSTEM = "system";
11+
public static final String ADMIN = "admin";
12+
public static final String USER = "user";
1113
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.thenaglecode.core.security;
2+
3+
import java.security.Principal;
4+
5+
/**
6+
* Created with IntelliJ IDEA.
7+
* User: jxnagl
8+
* Date: 8/9/13
9+
* Time: 2:04 PM
10+
*/
11+
public class User implements Principal {
12+
@Override
13+
public String getName() {
14+
return null;// todo implement method getName in class User
15+
}
16+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.thenaglecode.core.util;
2+
3+
import com.thenaglecode.core.Configuration;
4+
import com.thenaglecode.core.util.propeties.PropertiesResource;
5+
import com.thenaglecode.core.util.propeties.PropertyBundleResource;
6+
7+
import javax.enterprise.inject.Produces;
8+
import javax.enterprise.inject.spi.InjectionPoint;
9+
import java.io.IOException;
10+
import java.io.InputStream;
11+
import java.net.URL;
12+
import java.util.MissingResourceException;
13+
import java.util.Properties;
14+
import java.util.PropertyResourceBundle;
15+
import java.util.ResourceBundle;
16+
import java.util.logging.Level;
17+
import java.util.logging.Logger;
18+
19+
/**
20+
* Created with IntelliJ IDEA.
21+
* User: jxnagl
22+
* Date: 8/2/13
23+
* Time: 4:53 PM
24+
* used to find the resources associated with these annotations
25+
*/
26+
@SuppressWarnings("UnusedDeclaration")
27+
public class ResourceLocator {
28+
29+
private static final Logger logger = Logger.getLogger(ResourceLocator.class.getName());
30+
private static final ResourceBundle bundle = PropertyResourceBundle.getBundle("com.thenaglecode.core.configuration");
31+
32+
@Produces
33+
@PropertyBundleResource(subsystem = "", file = "")
34+
private ResourceBundle loadResourceBundle(InjectionPoint ip) throws IOException {
35+
logger.log(Level.FINE, "-- called PropertiesResourceBundle loader");
36+
PropertyBundleResource annotation = ip.getAnnotated().getAnnotation(PropertyBundleResource.class);
37+
logger.log(Level.FINE, "subsystem=" + annotation.subsystem() + " file=" + annotation.file());
38+
String baseName = bundle.getString(Configuration.DEFAULT_BASE_PACKAGE_ID) + "."
39+
+ annotation.subsystem() + "." + annotation.file();
40+
try {
41+
logger.log(Level.FINE, "full name=" + baseName);
42+
return PropertyResourceBundle.getBundle(baseName);
43+
} catch (MissingResourceException e) {
44+
return null;
45+
}
46+
}
47+
48+
@Produces
49+
@PropertiesResource(name = "")
50+
private Properties loadProperties(InjectionPoint ip) throws IOException {
51+
logger.log(Level.FINE, "-- called PropertiesResource loader");
52+
PropertiesResource annotation = ip.getAnnotated().getAnnotation(PropertiesResource.class);
53+
String fileName = annotation.name();
54+
Properties props = null;
55+
56+
URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
57+
if (url != null) {
58+
props = new Properties();
59+
try (InputStream in = url.openStream()) {
60+
props.load(in);
61+
}
62+
}
63+
return props;
64+
}
65+
}

0 commit comments

Comments
 (0)