forked from caelum/vraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:caelum/vraptor
- Loading branch information
Showing
14 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
26 changes: 26 additions & 0 deletions
26
...lugin-flex/src/main/java/br/com/caelum/vraptor/flex/FlexInterceptorStereotypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
vraptor-plugin-flex/src/main/java/br/com/caelum/vraptor/flex/FlexIntercepts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
vraptor-plugin-flex/src/main/java/br/com/caelum/vraptor/flex/InterceptorsStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
vraptor-plugin-flex/src/main/java/br/com/caelum/vraptor/flex/VRaptorFactoryInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
vraptor-plugin-flex/src/main/java/br/com/caelum/vraptor/flex/VRaptorServiceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |