[dependency-shot] r394 committed - Refactor injector API to be more fluent

0 views
Skip to first unread message

depende...@googlecode.com

unread,
Mar 20, 2011, 12:49:14 PM3/20/11
to depende...@googlegroups.com
Revision: 394
Author: mathieu.ancelin
Date: Sun Mar 20 09:48:06 2011
Log: Refactor injector API to be more fluent
http://code.google.com/p/dependency-shot/source/detail?r=394

Modified:

/trunk/dependency-shot-api/src/main/java/cx/ath/mancel01/dependencyshot/api/DSInjector.java

/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/InjectorImpl.java

=======================================
---
/trunk/dependency-shot-api/src/main/java/cx/ath/mancel01/dependencyshot/api/DSInjector.java
Sat Mar 12 11:50:44 2011
+++
/trunk/dependency-shot-api/src/main/java/cx/ath/mancel01/dependencyshot/api/DSInjector.java
Sun Mar 20 09:48:06 2011
@@ -17,15 +17,36 @@

package cx.ath.mancel01.dependencyshot.api;

-import cx.ath.mancel01.dependencyshot.api.event.Event;
-import cx.ath.mancel01.dependencyshot.api.event.EventListener;
-
/**
* Injector interface.
*
* @author Mathieu ANCELIN
*/
public interface DSInjector {
+
+ /**
+ * Inject the static members of c.
+ *
+ * @param c the class to inject.
+ */
+ DSInjector injectStatics(Class<?> c);
+
+ /**
+ * Enable or not the circular dependencies in the injector.
+ *
+ * @param allowCircularDependencies new value for circular
dependencies.
+ */
+ DSInjector allowCircularDependencies(boolean
allowCircularDependencies);
+
+ /**
+ * Register a shutdown hook to shutdown container when JVM stop.
+ */
+ DSInjector registerShutdownHook();
+
+ DSInjector registerEventListener(Class listener);
+
+ DSInjector allowLazyStaticInjection(boolean allowLazyStaticInjection);
+
/**
* Get a instance of c.
*
@@ -34,13 +55,7 @@
* @return an instance of c.
*/
<T> T getInstance(Class<T> c);
- /**
- * Inject the static members of c.
- *
- * @param c the class to inject.
- */
- void injectStatics(Class<?> c);
-
+
/**
* Injection on an instance.
* WARNING : Constructor injection doesn't work
@@ -51,33 +66,20 @@
* @return injected instance
*/
<T> T injectInstance(T instance);
-
+
/**
* @return the actual stage of the injector.
*/
Stage getStage();

- /**
- * Enable or not the circular dependencies in the injector.
- *
- * @param allowCircularDependencies new value for circular
dependencies.
- */
- void allowCircularDependencies(boolean allowCircularDependencies);
-
/**
* @return if circular dependencies are allowed by the injector
*/
boolean areCircularDependenciesAllowed();

- /**
- * Register a shutdown hook to shutdown container when JVM stop.
- */
- void registerShutdownHook();
-
- void registerEventListener(Class listener);
-
- void allowLazyStaticInjection(boolean allowLazyStaticInjection);
-
boolean isLazyStaticInjectionAllowed();

-}
+ void fire(Object event);
+
+ void fireAsync(Object event);
+}
=======================================
---
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/InjectorImpl.java
Thu Mar 17 12:21:53 2011
+++
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/InjectorImpl.java
Sun Mar 20 09:48:06 2011
@@ -494,7 +494,7 @@
* @param c the class to inject.
*/
@Override
- public final void injectStatics(Class<?> c) {
+ public final DSInjector injectStatics(Class<?> c) {
InjectionStartedEvent start = new InjectionStartedEvent();
InjectionStoppedEvent stop = new InjectionStoppedEvent();
start.setBeanType(c);
@@ -514,6 +514,7 @@
throw new RuntimeException(); // should never happen
}
eventManager.fireAsyncEvent(stop);
+ return this;
}

/**
@@ -570,15 +571,17 @@
* Register a shutdown hook to shutdown container when JVM stop.
*/
@Override
- public final void registerShutdownHook() {
+ public final DSInjector registerShutdownHook() {
ShutdownThread thread = new ShutdownThread();
thread.setInjector(this);
Runtime.getRuntime().addShutdownHook(thread);
+ return this;
}

@Override
- public final void registerEventListener(Class listener) {
+ public final DSInjector registerEventListener(Class listener) {
eventManager.registerListener(listener);
+ return this;
}

/**
@@ -620,8 +623,9 @@
}

@Override
- public void allowCircularDependencies(boolean
allowCircularDependencies) {
+ public DSInjector allowCircularDependencies(boolean
allowCircularDependencies) {
this.allowCircularDependencies = allowCircularDependencies;
+ return this;
}

@Override
@@ -630,8 +634,9 @@
}

@Override
- public void allowLazyStaticInjection(boolean allowLazyStaticInjection)
{
+ public DSInjector allowLazyStaticInjection(boolean
allowLazyStaticInjection) {
this.allowLazyStaticInjection = allowLazyStaticInjection;
+ return this;
}

@Override
@@ -662,5 +667,26 @@

public Map<Class<? extends Annotation>, CustomScopeHandler>
getScopeHandlers() {
return scopeHandlers;
- }
-}
+ }
+
+ @Override
+ public void fire(Object event) {
+ eventManager.fireEvent(event);
+ }
+
+ @Override
+ public void fireAsync(Object event) {
+ eventManager.fireEvent(event);
+ }
+
+ public DSInjector registerScope(Class<? extends CustomScopeHandler>
scope) {
+ try {
+ CustomScopeHandler handler = scope.newInstance();
+ scopeHandlers.put(handler.getScope(), handler);
+ return this;
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, null, ex);
+ return this;
+ }
+ }
+}

Reply all
Reply to author
Forward
0 new messages