Added:
/trunk/dependency-shot-container
/trunk/dependency-shot-container/pom.xml
/trunk/dependency-shot-container/src
/trunk/dependency-shot-container/src/main
/trunk/dependency-shot-container/src/main/java
/trunk/dependency-shot-container/src/main/java/cx
/trunk/dependency-shot-container/src/main/java/cx/ath
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/Container.java
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/deploy
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/deploy/BeanArchive.java
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/deploy/CDIBinder.java
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/deploy/ResourceLoader.java
=======================================
--- /dev/null
+++ /trunk/dependency-shot-container/pom.xml Thu Apr 7 09:12:26 2011
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>dependency-shot</artifactId>
+ <groupId>cx.ath.mancel01</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>dependency-shot-container</artifactId>
+ <name>Dependency-Shot (JSR-330) :: Container</name>
+ <url>http://code.google.com/p/dependency-shot/</url>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <configuration>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ </plugins>
+ <finalName>dependency-shot-container</finalName>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <artifactId>dependency-shot-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <artifactId>dependency-shot-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <artifactId>dependency-shot-aop</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <artifactId>dependency-shot-lifecycle</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <artifactId>dependency-shot-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>cx.ath.mancel01</groupId>
+ <artifactId>dependency-shot-dynamic</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>1.0-SP4</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <licenses>
+ <license>
+ <name>Apache 2</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ <comments>A business-friendly OSS license</comments>
+ </license>
+ </licenses>
+</project>
=======================================
--- /dev/null
+++
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/Container.java
Thu Apr 7 09:12:26 2011
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2011 mathieuancelin.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package cx.ath.mancel01.dependencyshot;
+
+import cx.ath.mancel01.dependencyshot.api.Stage;
+import cx.ath.mancel01.dependencyshot.deploy.BeanArchive;
+import cx.ath.mancel01.dependencyshot.deploy.CDIBinder;
+import cx.ath.mancel01.dependencyshot.deploy.ResourceLoader;
+import cx.ath.mancel01.dependencyshot.graph.Binding;
+import cx.ath.mancel01.dependencyshot.graph.BindingBuilder;
+import cx.ath.mancel01.dependencyshot.injection.InjectorBuilder;
+import cx.ath.mancel01.dependencyshot.injection.InjectorImpl;
+import cx.ath.mancel01.dependencyshot.spi.PluginsLoader;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import javax.decorator.Decorator;
+import javax.inject.Named;
+
+/**
+ *
+ * @author mathieuancelin
+ */
+public class Container {
+
+ private final BeanArchive archive;
+
+ private final InjectorImpl injector;
+
+ private Container(BeanArchive archive) {
+ this.archive = archive;
+ this.injector = createInjector();
+ }
+
+ public static Container init(BeanArchive archive) {
+ return new Container(archive);
+ }
+
+ public void shutdown() {
+ injector.triggerLifecycleDestroyCallbacks();
+ }
+
+ public <T> T getInstance(Class<T> clazz) {
+ return injector.getInstance(clazz);
+ }
+
+ public <T> T getInstance(String elName) {
+ // TODO ; getInstance on @Named
+ return injector.getInstance(null);
+ }
+
+ public <T> T injectInstance(T object) {
+ return injector.injectInstance(object);
+ }
+
+ public void injectStatics(Class<?> clazz) {
+ injector.injectStatics(clazz);
+ }
+
+ public <T> void fire(T event) {
+ injector.fire(event);
+ }
+
+ private InjectorImpl createInjector() {
+ PluginsLoader pluginsLoader = new PluginsLoader();
+ InjectorImpl newInjector =
InjectorBuilder.makeInjector(pluginsLoader, Stage.NONE);
+ CDIBinder binder = new CDIBinder();
+ ResourceLoader loader = archive.getResourceLoader();
+ Collection<String> resources = archive.getResources();
+ Collection<String> classesNames = archive.getBeanClasses();
+ Collection<Class<?>> classes = new ArrayList<Class<?>>();
+ for (String resource : resources) {
+ if (resource.endsWith("beans.xml")) {
+ // TODO : parse it and extract informations about special
classes
+ }
+ }
+ for (String className : classesNames) {
+ Class<?> clazz = loader.loadClass(className);
+ classes.add(clazz);
+ }
+ for (Class<?> clazz : classes) {
+ // TODO : register producers beans (methods and fields)
+ // TODO : register interceptors
+ }
+ for (Class<?> clazz : classes) {
+ registerComponent(clazz, newInjector, binder);
+ }
+ newInjector.allowCircularDependencies(true);
+ newInjector.registerShutdownHook();
+ return newInjector;
+ }
+
+ private void registerComponent(Class<?> clazz, InjectorImpl
newInjector, CDIBinder binder) {
+ if (!clazz.isInterface()) {
+ List<Binding> bindings = new ArrayList<Binding>();
+ Collection<Annotation> qualifiers = getQualifiers(clazz);
+ if (qualifiers.isEmpty()) {
+ for (Annotation annotation : qualifiers) {
+ if (annotation.annotationType().equals(Named.class)) {
+ bindings.addAll(getNamedBindingsFor(clazz,
annotation));
+ } else {
+ bindings.addAll(getQualifiedBindingsFor(clazz,
annotation));
+ }
+ }
+ } else {
+ bindings.addAll(getBindingsFor(clazz));
+ }
+
+ // register listener beans
+ newInjector.registerEventListener(clazz);
+
+ // TODO : register as intercepted
+
+ // register decorators
+ if (clazz.isAnnotationPresent(Decorator.class)) {
+ binder.registerDecorator(clazz);
+ }
+ // -----------------------------------------------
+ // TODO : with SPI
+ // TODO : register scopes -- with SPI
+ }
+ }
+
+ private Collection<Binding> getBindingsFor(Class<?> clazz) {
+ // TODO : register for interfaces and supertypes
+ // TODO : check for producers
+ }
+
+ private Collection<Binding> getQualifiedBindingsFor(Class<?> clazz,
Annotation qualifier) {
+ // TODO : register for interfaces and supertypes
+ // TODO : check for producers
+ }
+
+ private Collection<Binding> getNamedBindingsFor(Class<?> clazz,
Annotation named) {
+ // TODO : register for interfaces and supertypes
+ // TODO : check for producers
+ }
+
+ private Collection<Annotation> getQualifiers(Class<?> clazz) {
+ // TODO : check for stereotypes
+ ReflectionUtil.
+ }
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/deploy/BeanArchive.java
Thu Apr 7 09:12:26 2011
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011 mathieuancelin.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package cx.ath.mancel01.dependencyshot.deploy;
+
+import java.util.Collection;
+
+/**
+ *
+ * @author mathieuancelin
+ */
+public interface BeanArchive {
+
+ Collection<String> getBeanClasses();
+ Collection<String> getResources();
+ ResourceLoader getResourceLoader();
+
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/deploy/CDIBinder.java
Thu Apr 7 09:12:26 2011
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2011 mathieuancelin.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package cx.ath.mancel01.dependencyshot.deploy;
+
+import cx.ath.mancel01.dependencyshot.aop.AOPBinder;
+
+/**
+ *
+ * @author mathieuancelin
+ */
+public class CDIBinder extends AOPBinder {
+
+ @Override
+ public void configure() {
+ }
+}
=======================================
--- /dev/null
+++
/trunk/dependency-shot-container/src/main/java/cx/ath/mancel01/dependencyshot/deploy/ResourceLoader.java
Thu Apr 7 09:12:26 2011
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2011 mathieuancelin.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+
+package cx.ath.mancel01.dependencyshot.deploy;
+
+import java.net.URL;
+import java.util.Collection;
+
+/**
+ *
+ * @author mathieuancelin
+ */
+public interface ResourceLoader {
+
+ public Class<?> loadClass(String name);
+
+ public URL getResource(String name);
+
+ public Collection<URL> getResources(String name);
+}