cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r836374 - in /cayenne/sandbox/cayenne-di: ./ .settings/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/cayenne/ src/main/java/org/apache/cayenne/access/ src/main/java/org/apache/cayenne/c...
Date Sun, 15 Nov 2009 15:50:09 GMT
Author: aadamchik
Date: Sun Nov 15 15:50:08 2009
New Revision: 836374

URL: http://svn.apache.org/viewvc?rev=836374&view=rev
Log:
playing with DI ideas

a possible dumb-down DI container, knock off of Guice ideas

Added:
    cayenne/sandbox/cayenne-di/
    cayenne/sandbox/cayenne-di/.classpath
    cayenne/sandbox/cayenne-di/.project
    cayenne/sandbox/cayenne-di/.settings/
    cayenne/sandbox/cayenne-di/.settings/org.maven.ide.eclipse.prefs
    cayenne/sandbox/cayenne-di/pom.xml
    cayenne/sandbox/cayenne-di/src/
    cayenne/sandbox/cayenne-di/src/main/
    cayenne/sandbox/cayenne-di/src/main/java/
    cayenne/sandbox/cayenne-di/src/main/java/org/
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/DataChannel.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/ObjectContext.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/Query.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultDataChannel.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultObjectContext.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/ObjectContextProvider.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/CayenneModule.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/Configuration.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binder.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binding.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/BindingBuilder.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIBootstrap.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIException.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Injector.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/InterfaceBindingBuilder.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapBinder.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapInjector.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Module.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Provider.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/SimpleBinder.java
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/annotation/
    cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/annotation/Inject.java
    cayenne/sandbox/cayenne-di/src/test/
    cayenne/sandbox/cayenne-di/src/test/java/
    cayenne/sandbox/cayenne-di/src/test/java/org/
    cayenne/sandbox/cayenne-di/src/test/java/org/apache/
    cayenne/sandbox/cayenne-di/src/test/java/org/apache/cayenne/
    cayenne/sandbox/cayenne-di/src/test/java/org/apache/cayenne/di/
    cayenne/sandbox/cayenne-di/src/test/java/org/apache/cayenne/di/DIBootstrapTest.java

Added: cayenne/sandbox/cayenne-di/.classpath
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/.classpath?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/.classpath (added)
+++ cayenne/sandbox/cayenne-di/.classpath Sun Nov 15 15:50:08 2009
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: cayenne/sandbox/cayenne-di/.project
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/.project?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/.project (added)
+++ cayenne/sandbox/cayenne-di/.project Sun Nov 15 15:50:08 2009
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cayenne-di</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

Added: cayenne/sandbox/cayenne-di/.settings/org.maven.ide.eclipse.prefs
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/.settings/org.maven.ide.eclipse.prefs?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/.settings/org.maven.ide.eclipse.prefs (added)
+++ cayenne/sandbox/cayenne-di/.settings/org.maven.ide.eclipse.prefs Sun Nov 15 15:50:08 2009
@@ -0,0 +1,9 @@
+#Sun Nov 15 17:10:29 EET 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1

Added: cayenne/sandbox/cayenne-di/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/pom.xml?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/pom.xml (added)
+++ cayenne/sandbox/cayenne-di/pom.xml Sun Nov 15 15:50:08 2009
@@ -0,0 +1,23 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.cayenne</groupId>
+		<artifactId>cayenne-parent</artifactId>
+		<version>3.1-SNAPSHOT</version>
+	</parent>
+	<artifactId>cayenne-di</artifactId>
+	<packaging>jar</packaging>
+	<name>cayenne-di</name>
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.cayenne.unpublished</groupId>
+			<artifactId>cayenne-jdk1.5-unpublished</artifactId>
+			<version>${version}</version>
+		</dependency>
+	</dependencies>
+</project>

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/DataChannel.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/DataChannel.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/DataChannel.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/DataChannel.java Sun Nov 15
15:50:08 2009
@@ -0,0 +1,26 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne;
+
+public interface DataChannel {
+
+	<T> Object onQuery(ObjectContext originatingContext, Query<T> query);
+
+	void onSync(ObjectContext originatingContext);
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/ObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/ObjectContext.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/ObjectContext.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/ObjectContext.java Sun Nov
15 15:50:08 2009
@@ -0,0 +1,28 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne;
+
+import java.util.List;
+
+public interface ObjectContext {
+
+	<T> List<T> performQuery(Query<T> query);
+	
+	DataChannel getChannel();
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/Query.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/Query.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/Query.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/Query.java Sun Nov 15 15:50:08
2009
@@ -0,0 +1,23 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne;
+
+public interface Query<T> {
+
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultDataChannel.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultDataChannel.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultDataChannel.java
(added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultDataChannel.java
Sun Nov 15 15:50:08 2009
@@ -0,0 +1,37 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.access;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.Query;
+
+public class DefaultDataChannel implements DataChannel {
+
+	public <T> Object onQuery(ObjectContext originatingContext, Query<T> query)
{
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public void onSync(ObjectContext originatingContext) {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultObjectContext.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultObjectContext.java
(added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/DefaultObjectContext.java
Sun Nov 15 15:50:08 2009
@@ -0,0 +1,44 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.access;
+
+import java.util.List;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.Query;
+
+public class DefaultObjectContext implements ObjectContext {
+
+	private DataChannel dataChannel;
+
+	public DefaultObjectContext(DataChannel dataChannel) {
+		this.dataChannel = dataChannel;
+	}
+
+	public <T> List<T> performQuery(Query<T> query) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public DataChannel getChannel() {
+		return dataChannel;
+	}
+
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/ObjectContextProvider.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/ObjectContextProvider.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/ObjectContextProvider.java
(added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/access/ObjectContextProvider.java
Sun Nov 15 15:50:08 2009
@@ -0,0 +1,34 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.access;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.di.annotation.Inject;
+
+public class ObjectContextProvider implements Provider<ObjectContext> {
+
+	@Inject
+	private DataChannel dataChannel;
+	
+	public ObjectContext get() {
+		return new DefaultObjectContext(dataChannel);
+	}
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/CayenneModule.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/CayenneModule.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/CayenneModule.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/CayenneModule.java Sun
Nov 15 15:50:08 2009
@@ -0,0 +1,36 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.conf;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.access.DefaultDataChannel;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+
+/**
+ * A DI module containing all Cayenne framework configurations.
+ */
+public class CayenneModule implements Module {
+
+	public void configure(Binder binder) {
+		
+		binder.bind(DataChannel.class).to(DefaultDataChannel.class);
+
+	}
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/Configuration.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/Configuration.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/Configuration.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/conf/Configuration.java Sun
Nov 15 15:50:08 2009
@@ -0,0 +1,52 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.conf;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Module;
+
+public class Configuration {
+
+	private Injector injector;
+
+	/**
+	 * Initializes a configuration with default CayenneModule.
+	 */
+	public Configuration() {
+		this(new CayenneModule());
+	}
+
+	/**
+	 * Initializes a configuration with provided DI module.
+	 */
+	public Configuration(Module... modules) {
+		this.injector = DIBootstrap.createInjector(modules);
+	}
+
+	public DataChannel getDataChannel() {
+		return injector.getInstance(DataChannel.class);
+	}
+
+	public ObjectContext getNewContext() {
+		return injector.getInstance(ObjectContext.class);
+	}
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binder.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binder.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binder.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binder.java Sun Nov 15
15:50:08 2009
@@ -0,0 +1,28 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+public interface Binder {
+
+	/**
+	 * Starts a binding of a specific interface. Binding should continue using
+	 * returned BindingBuilder.
+	 */
+	<T> BindingBuilder<T> bind(Class<T> type);
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binding.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binding.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binding.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Binding.java Sun Nov 15
15:50:08 2009
@@ -0,0 +1,23 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+public interface Binding<T> {
+
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/BindingBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/BindingBuilder.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/BindingBuilder.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/BindingBuilder.java Sun
Nov 15 15:50:08 2009
@@ -0,0 +1,32 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+/**
+ * A binding builder that helps with fluent binding creation.
+ * 
+ * @param <T>
+ *            An interface type of the service being bound.
+ */
+public interface BindingBuilder<T> {
+
+	void to(Class<? extends T> implementation);
+
+	void toProvider(Class<? extends Provider<? extends T>> providerType);
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIBootstrap.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIBootstrap.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIBootstrap.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIBootstrap.java Sun Nov
15 15:50:08 2009
@@ -0,0 +1,29 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+/**
+ * A class that bootstraps the Cayenne DI registry.
+ */
+public class DIBootstrap {
+
+	public static Injector createInjector(Module... modules) throws DIException {
+		return new MapInjector(modules);
+	}
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIException.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIException.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIException.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/DIException.java Sun Nov
15 15:50:08 2009
@@ -0,0 +1,40 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+import org.apache.cayenne.CayenneRuntimeException;
+
+public class DIException extends CayenneRuntimeException {
+
+	public DIException() {
+
+	}
+
+	public DIException(String message) {
+		super(message);
+	}
+
+	public DIException(Throwable cause) {
+		super(cause);
+	}
+
+	public DIException(String message, Throwable cause) {
+		super(message, cause);
+	}
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Injector.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Injector.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Injector.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Injector.java Sun Nov 15
15:50:08 2009
@@ -0,0 +1,24 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+public interface Injector {
+
+	<T> T getInstance(Class<T> type);
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/InterfaceBindingBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/InterfaceBindingBuilder.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/InterfaceBindingBuilder.java
(added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/InterfaceBindingBuilder.java
Sun Nov 15 15:50:08 2009
@@ -0,0 +1,38 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+class InterfaceBindingBuilder<T> implements BindingBuilder<T> {
+
+	private Class<T> interfaceType;
+
+	InterfaceBindingBuilder(Class<T> interfaceType) {
+		this.interfaceType = interfaceType;
+	}
+
+	public void to(Class<? extends T> implementation) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void toProvider(Class<? extends Provider<? extends T>> providerType)
{
+		// TODO Auto-generated method stub
+
+	}
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapBinder.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapBinder.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapBinder.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapBinder.java Sun Nov
15 15:50:08 2009
@@ -0,0 +1,28 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+class MapBinder implements Binder {
+
+	public <T> BindingBuilder<T> bind(Class<T> type) {
+		return new InterfaceBindingBuilder<T>(type);
+	}
+	
+	
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapInjector.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapInjector.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapInjector.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/MapInjector.java Sun Nov
15 15:50:08 2009
@@ -0,0 +1,37 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+class MapInjector implements Injector {
+
+	MapInjector(Module... modules) throws DIException {
+
+		if (modules != null && modules.length > 0) {
+			MapBinder binder = new MapBinder();
+			for (Module module : modules) {
+				module.configure(binder);
+			}
+		}
+
+	}
+
+	public <T> T getInstance(Class<T> type) {
+		throw new UnsupportedOperationException("TODO");
+	}
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Module.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Module.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Module.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Module.java Sun Nov 15
15:50:08 2009
@@ -0,0 +1,24 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+public interface Module {
+
+	void configure(Binder binder);
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Provider.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Provider.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Provider.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/Provider.java Sun Nov 15
15:50:08 2009
@@ -0,0 +1,30 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+/**
+ * A DI object factory interface.
+ * 
+ * @param <T>
+ *            Type of object the provider creates.
+ */
+public interface Provider<T> {
+
+	T get();
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/SimpleBinder.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/SimpleBinder.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/SimpleBinder.java (added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/SimpleBinder.java Sun Nov
15 15:50:08 2009
@@ -0,0 +1,28 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+public class SimpleBinder implements Binder {
+
+	public <T> BindingBuilder<T> bind(Class<T> type) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+}

Added: cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/annotation/Inject.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/annotation/Inject.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/annotation/Inject.java
(added)
+++ cayenne/sandbox/cayenne-di/src/main/java/org/apache/cayenne/di/annotation/Inject.java
Sun Nov 15 15:50:08 2009
@@ -0,0 +1,23 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di.annotation;
+
+public @interface Inject {
+
+}

Added: cayenne/sandbox/cayenne-di/src/test/java/org/apache/cayenne/di/DIBootstrapTest.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-di/src/test/java/org/apache/cayenne/di/DIBootstrapTest.java?rev=836374&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-di/src/test/java/org/apache/cayenne/di/DIBootstrapTest.java (added)
+++ cayenne/sandbox/cayenne-di/src/test/java/org/apache/cayenne/di/DIBootstrapTest.java Sun
Nov 15 15:50:08 2009
@@ -0,0 +1,68 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.di;
+
+import junit.framework.TestCase;
+
+
+public class DIBootstrapTest extends TestCase {
+
+	public void testCreateInjector_Empty() {
+		Injector emptyInjector = DIBootstrap.createInjector();
+		assertNotNull(emptyInjector);
+	}
+
+	public void testCreateInjector_SingleModule() {
+		final boolean[] configureCalled = new boolean[1];
+
+		Module module = new Module() {
+			public void configure(Binder binder) {
+				configureCalled[0] = true;
+			}
+		};
+
+		Injector injector = DIBootstrap.createInjector(module);
+		assertNotNull(injector);
+
+		assertTrue(configureCalled[0]);
+	}
+
+	public void testCreateInjector_MultiModule() {
+
+		final boolean[] configureCalled = new boolean[2];
+
+		Module module1 = new Module() {
+			public void configure(Binder binder) {
+				configureCalled[0] = true;
+			}
+		};
+
+		Module module2 = new Module() {
+			public void configure(Binder binder) {
+				configureCalled[1] = true;
+			}
+		};
+
+		Injector injector = DIBootstrap.createInjector(module1, module2);
+		assertNotNull(injector);
+
+		assertTrue(configureCalled[0]);
+		assertTrue(configureCalled[1]);
+	}
+}



Mime
View raw message