Skip to content

Commit

Permalink
Merge branch 'master' of github.com:caelum/vraptor
Browse files Browse the repository at this point in the history
  • Loading branch information
lucascs committed Mar 30, 2011
2 parents 17a6a6f + f85a620 commit 7eeaddd
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ vraptor-example-compatibility/src/main/webapp/WEB-INF/lib/*.jar
vraptor-blank-project/WebContent/WEB-INF/lib/*.jar
vraptor-blank-project-gae/war/WEB-INF/lib/*.jar
vraptor-blank-project-scala/WebContent/WEB-INF/lib/
vraptor-plugin-flex/lib/*.jar
vraptor-mydvds/WebContent/WEB-INF/lib/*.jar
vraptor-site/todo.log
vraptor-mydvds/mydvds.war
Expand Down
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<ant dir="vraptor-example-compatibility" target="update-jars"/>
<ant dir="vraptor-blank-project" target="update-jars"/>
<ant dir="vraptor-plugin-gae" target="artifacts"/>
<ant dir="vraptor-plugin-flex" target="lib"/>
<ant dir="vraptor-blank-project-gae" target="update-jars"/>
<ant dir="vraptor-mydvds" target="update-jars"/>
</target>
Expand Down
Binary file not shown.
Binary file added vraptor-core/lib/flex/flex-messaging-core.jar
Binary file not shown.
Binary file added vraptor-core/lib/flex/javax.inject-1.jar
Binary file not shown.
38 changes: 38 additions & 0 deletions vraptor-plugin-flex/README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
VRpaptor 3 Flex-plugin
=========

This is a plugin to call a VRator Controller from a flash RemoteObject via AMF

Configuring in your flex project
========================
In fact this plugin is a blazeds factory, all you need is register it.

In your service-config.xml add the VRaptor factory:

<!-- VRaptor factory registration -->
<factories>
<factory id="vraptor" class="br.com.caelum.vraptor.flex.VRaptorServiceFactory" />
</factories>


Then, to register a new destination, use the full qualified name of your controller and the
VRaptor Factory, like this:


<destination id="myVRaptorController">
<properties>
<factory>vraptor</factory>
<source>br.com.caelum.vraptor.example.MyController</source>
</properties>
</destination>



Building in your machine
========================

To copy the lib dependecies run:

ant libs

And then configure the projects in your eclipse using classpath-example and project-example files.
72 changes: 72 additions & 0 deletions vraptor-plugin-flex/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
VRaptor 3 flex plugin build
====================================================================== -->
<project name="VRaptor 3 Flex Plugin" default="artifacts" basedir=".">

<description>VRaptor 3 core module build</description>

<property name="vraptor.core" value="../vraptor-core" />
<property name="vraptor.jar" value="${vraptor.core}/target/" />
<property name="core.lib.dir" value="${vraptor.core}/lib/mandatory" />
<property name="spring.lib.dir" value="${vraptor.core}/lib/containers/spring" />
<property name="flex.lib.dir" value="${vraptor.core}/lib/flex" />
<property name="compile.dir" value="build.tmp" />
<property name="target.dir" value="target" />
<property name="target.file" value="${target.dir}/vraptor-flex.jar" />

<path id="libs.classpath" path=".">
<fileset dir="${vraptor.jar}">
<include name="*.jar" />
</fileset>
<fileset dir="${core.lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${flex.lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${spring.lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>

<path id="compile.classpath">
<path refid="libs.classpath" />
</path>

<target name="compile" depends="clean" description="--> compiles classes">
<mkdir dir="${compile.dir}" />
<javac destdir="${compile.dir}" srcdir="src/" classpathref="compile.classpath" />
<copy todir="${compile.dir}">
<fileset dir="src/" includes="META-INF/**" />
</copy>
</target>

<target name="artifacts" depends="compile" description="--> generate project's artifacts">
<mkdir dir="${target.dir}" />
<jar destfile="${target.file}" compress="true">
<fileset dir="${compile.dir}" includes="**" />
</jar>
</target>

<target name="clean" description="--> delete build artifacts">
<delete dir="${compile.dir}" />
<delete dir="${target.dir}" />
</target>

<target name="libs">
<copy todir="lib" >
<fileset dir="${flex.lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${vraptor.jar}">
<include name="*.jar" />
</fileset>
<fileset dir="${spring.lib.dir}">
<include name="**/*beans*.jar" />
</fileset>
</copy>
</target>

</project>

12 changes: 12 additions & 0 deletions vraptor-plugin-flex/classpath-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="lib" path="lib/flex-messaging-common.jar"/>
<classpathentry kind="lib" path="lib/flex-messaging-core.jar"/>
<classpathentry kind="lib" path="lib/javax.inject-1.jar"/>
<classpathentry kind="lib" path="lib/org.springframework.beans-3.0.5.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/vraptor-3.3.2-SNAPSHOT.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions vraptor-plugin-flex/project-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vraptor-plugin-flex</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package br.com.caelum.vraptor.flex;

import java.lang.annotation.Annotation;

import br.com.caelum.vraptor.ioc.ApplicationScoped;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.StereotypeHandler;

@ApplicationScoped
@Component
public class FlexInterceptorStereotypeHandler implements StereotypeHandler {
private final InterceptorsStack stack;

public FlexInterceptorStereotypeHandler(InterceptorsStack stack) {
this.stack = stack;
}

public void handle(Class<?> type) {
stack.add(type);
}

public Class<? extends Annotation> stereotype() {
return FlexIntercepts.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package br.com.caelum.vraptor.flex;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface FlexIntercepts {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package br.com.caelum.vraptor.flex;

import java.util.ArrayList;
import java.util.List;

import br.com.caelum.vraptor.core.DefaultInterceptorStack;
import br.com.caelum.vraptor.core.InterceptorHandlerFactory;
import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.interceptor.Interceptor;
import br.com.caelum.vraptor.ioc.ApplicationScoped;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.Container;

@Component
@ApplicationScoped
public class InterceptorsStack {
private final Container container;
private final InterceptorHandlerFactory interceptorHandlerFactory;

public InterceptorsStack(Container container, InterceptorHandlerFactory interceptorHandlerFactory) {
this.container = container;
this.interceptorHandlerFactory = interceptorHandlerFactory;
}

private List<Class<? extends Interceptor>> types = new ArrayList<Class<? extends Interceptor>>();

public void add(Class<?> type) {
this.types.add((Class<? extends Interceptor>) type);
}

public InterceptorStack createStack() {
DefaultInterceptorStack stack = new DefaultInterceptorStack(interceptorHandlerFactory);

for (Class<? extends Interceptor> type : types) {
stack.add(type);
}
return stack;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package br.com.caelum.vraptor.flex;

import java.lang.reflect.Method;

import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.core.MethodInfo;
import br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor;
import br.com.caelum.vraptor.ioc.Container;
import br.com.caelum.vraptor.proxy.MethodInvocation;
import br.com.caelum.vraptor.proxy.Proxifier;
import br.com.caelum.vraptor.proxy.SuperMethod;
import br.com.caelum.vraptor.resource.DefaultResourceMethod;
import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;

public class VRaptorFactoryInstance extends FactoryInstance {

private final Container container;

public VRaptorFactoryInstance(FlexFactory factory, String id, ConfigMap properties, Container container) {
super(factory, id, properties);
this.container = container;
}

@Override
public Object lookup() {

final Class<?> type;
try {
type = Class.forName(getSource());
} catch (ClassNotFoundException e) {
throw new RuntimeException("Source destination does not match a class name", e);
}

Proxifier proxifier = container.instanceFor(Proxifier.class);
Object proxy = proxifier.proxify(type,
new InterceptorInvocation(type, container.instanceFor(InterceptorsStack.class)));

return proxy;
}

private final class InterceptorInvocation implements MethodInvocation<Object> {
private final Class<?> type;
private final InterceptorsStack stack;

private InterceptorInvocation(Class<?> type, InterceptorsStack stack) {
this.type = type;
this.stack = stack;
}

public Object intercept(Object proxy, Method method, Object[] args, SuperMethod superMethod) {
try {
MethodInfo info = container.instanceFor(MethodInfo.class);
info.setParameters(args);

InterceptorStack vrStack = stack.createStack();
vrStack.add(ExecuteMethodInterceptor.class);
vrStack.next(DefaultResourceMethod.instanceFor(type, method), container.instanceFor(type));

return info.getResult();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Could not invoke method on " + type.getCanonicalName(), e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package br.com.caelum.vraptor.flex;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Autowired;

import br.com.caelum.vraptor.ioc.ApplicationScoped;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.Container;
import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;

@Component
@ApplicationScoped
public class VRaptorServiceFactory implements FlexFactory {

private static Container container;

@Inject
@Autowired
public VRaptorServiceFactory(Container container) {
VRaptorServiceFactory.container = container;
}

public VRaptorServiceFactory() {
}

public void initialize(String id, ConfigMap configMap) {
}

public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {
VRaptorFactoryInstance instance = new VRaptorFactoryInstance(this, id, properties, container);
instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));
return instance;
}

public Object lookup(FactoryInstance instance) {
return instance.lookup();
}

}

0 comments on commit 7eeaddd

Please sign in to comment.