cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1033234 - in /cayenne/sandbox/cayenne-mixin/trunk: ./ .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/mixin/
Date Tue, 09 Nov 2010 21:18:46 GMT
Author: aadamchik
Date: Tue Nov  9 21:18:45 2010
New Revision: 1033234

URL: http://svn.apache.org/viewvc?rev=1033234&view=rev
Log:
initial checkin - cayenne-mixin 3.1

Added:
    cayenne/sandbox/cayenne-mixin/trunk/.classpath
    cayenne/sandbox/cayenne-mixin/trunk/.project
    cayenne/sandbox/cayenne-mixin/trunk/.settings/
    cayenne/sandbox/cayenne-mixin/trunk/.settings/org.eclipse.jdt.core.prefs
    cayenne/sandbox/cayenne-mixin/trunk/.settings/org.maven.ide.eclipse.prefs
    cayenne/sandbox/cayenne-mixin/trunk/pom.xml
    cayenne/sandbox/cayenne-mixin/trunk/src/
    cayenne/sandbox/cayenne-mixin/trunk/src/main/
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandler.java
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandlerManager.java

Added: cayenne/sandbox/cayenne-mixin/trunk/.classpath
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/.classpath?rev=1033234&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/.classpath (added)
+++ cayenne/sandbox/cayenne-mixin/trunk/.classpath Tue Nov  9 21:18:45 2010
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: cayenne/sandbox/cayenne-mixin/trunk/.project
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/.project?rev=1033234&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/.project (added)
+++ cayenne/sandbox/cayenne-mixin/trunk/.project Tue Nov  9 21:18:45 2010
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cayenne-mixin</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-mixin/trunk/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/.settings/org.eclipse.jdt.core.prefs?rev=1033234&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/.settings/org.eclipse.jdt.core.prefs (added)
+++ cayenne/sandbox/cayenne-mixin/trunk/.settings/org.eclipse.jdt.core.prefs Tue Nov  9 21:18:45
2010
@@ -0,0 +1,6 @@
+#Tue Nov 09 16:14:31 EST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5

Added: cayenne/sandbox/cayenne-mixin/trunk/.settings/org.maven.ide.eclipse.prefs
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/.settings/org.maven.ide.eclipse.prefs?rev=1033234&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/.settings/org.maven.ide.eclipse.prefs (added)
+++ cayenne/sandbox/cayenne-mixin/trunk/.settings/org.maven.ide.eclipse.prefs Tue Nov  9 21:18:45
2010
@@ -0,0 +1,9 @@
+#Tue Nov 09 16:14:25 EST 2010
+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-mixin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/pom.xml?rev=1033234&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/pom.xml (added)
+++ cayenne/sandbox/cayenne-mixin/trunk/pom.xml Tue Nov  9 21:18:45 2010
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+		<artifactId>cayenne-parent</artifactId>
+		<groupId>org.apache.cayenne</groupId>
+		<version>3.1-SNAPSHOT</version>
+	</parent>
+	<artifactId>cayenne-mixin</artifactId>
+	<version>3.1-SNAPSHOT</version>
+	<name>Library: cayenne-mixin</name>
+	<packaging>jar</packaging>
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.cayenne</groupId>
+			<artifactId>cayenne-server</artifactId>
+			<version>${version}</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-collections</groupId>
+			<artifactId>commons-collections</artifactId>
+		</dependency>
+	</dependencies>
+	<build>
+		<pluginManagement>
+			<plugins>
+				<plugin>
+					<groupId>org.apache.maven.plugins</groupId>
+					<artifactId>maven-compiler-plugin</artifactId>
+					<configuration>
+						<source>1.5</source>
+						<target>1.5</target>
+					</configuration>
+				</plugin>
+			</plugins>
+		</pluginManagement>
+	</build>
+</project>

Added: cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandler.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandler.java?rev=1033234&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandler.java
(added)
+++ cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandler.java
Tue Nov  9 21:18:45 2010
@@ -0,0 +1,39 @@
+/*****************************************************************
+ *   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.mixin;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
+
+/**
+ * A handler that can be defined by application to setup lifecycle listeners for
+ * a given mixin type.
+ * 
+ * @param <T>
+ *            Custom mixin annotation type
+ */
+public interface MixinHandler<T extends Annotation> {
+
+	Class<T> getMixinType();
+
+	void setupListeners(LifecycleCallbackRegistry registry,
+			Class<? extends DataObject> entityType);
+}

Added: cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandlerManager.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandlerManager.java?rev=1033234&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandlerManager.java
(added)
+++ cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/MixinHandlerManager.java
Tue Nov  9 21:18:45 2010
@@ -0,0 +1,76 @@
+/*****************************************************************
+ *   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.mixin;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Inherited;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.util.Util;
+
+/**
+ * A wrapper around EntityResolver that allows to install custom
+ * {@link MixinHandler} instances.
+ */
+public class MixinHandlerManager {
+
+	protected EntityResolver entityResolver;
+
+	public MixinHandlerManager(EntityResolver entityResolver) {
+		this.entityResolver = entityResolver;
+	}
+
+	@SuppressWarnings("all")
+	public void addMixinHandler(MixinHandler<?> handler) {
+
+		Class<? extends Annotation> type = handler.getMixinType();
+		boolean inherited = type.isAnnotationPresent(Inherited.class);
+
+		for (ObjEntity entity : entityResolver.getObjEntities()) {
+			Class<?> entityType;
+			try {
+				entityType = Util.getJavaClass(entity.getClassName());
+			} catch (ClassNotFoundException e) {
+				throw new CayenneRuntimeException("Class not found: "
+						+ entity.getClassName(), e);
+			}
+
+			if (!DataObject.class.isAssignableFrom(entityType)) {
+				throw new CayenneRuntimeException(
+						"ObjEntity class is not a DataObject: "
+								+ entity.getClassName());
+			}
+
+			Class<?> entityTypeOrSupertype = entityType;
+			do {
+				if (entityTypeOrSupertype.isAnnotationPresent(type)) {
+					handler.setupListeners(
+							entityResolver.getCallbackRegistry(),
+							(Class<? extends DataObject>) entityType);
+				}
+
+				entityTypeOrSupertype = entityTypeOrSupertype.getSuperclass();
+
+			} while (inherited && entityTypeOrSupertype != null);
+		}
+	}
+}



Mime
View raw message