Skip to content

Commit

Permalink
JFinal 2.0 release ^_^
Browse files Browse the repository at this point in the history
  • Loading branch information
jfinal committed Jun 18, 2015
1 parent 1f06ed8 commit 881baed
Show file tree
Hide file tree
Showing 97 changed files with 5,296 additions and 1,589 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
</classpath>




2 changes: 0 additions & 2 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,3 @@
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>


2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6


10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ JFinal有如下主要特点
#. 功能齐全,拥有struts2的绝大部分功能
#. 体积小仅218K,且无第三方依赖

**JFinal 极速开发QQ群欢迎您的加入: 335699801、38707273**
**JFinal 极速开发QQ群欢迎您的加入: 335699801、326297041、424949661、38707273**

**以下是JFinal实现Blog管理的示例:**

Expand Down Expand Up @@ -81,10 +81,10 @@ Blog()这行代码也不是必须)**
::
public class BlogInterceptor implements Interceptor {
public void intercept(ActionInvocation ai) {
System.out.println("Before invoking " + ai.getActionKey());
ai.invoke();
System.out.println("After invoking " + ai.getActionKey());
public void intercept(Invocation inv) {
System.out.println("Before invoking " + inv.getActionKey());
inv.invoke();
System.out.println("After invoking " + inv.getActionKey());
}
}

Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,19 @@
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>2.29</version>
<scope>provided</scope>
</dependency>

<!--
<dependency>
Expand Down
91 changes: 0 additions & 91 deletions src/com/jfinal/aop/ActionInvocationWrapper.java

This file was deleted.

4 changes: 3 additions & 1 deletion src/com/jfinal/aop/Before.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import java.lang.annotation.Target;

/**
* Before is used to configure Interceptor or Validator.
* Before is used to configure Interceptor and Validator.
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Before {
Class<? extends Interceptor>[] value();
}


92 changes: 92 additions & 0 deletions src/com/jfinal/aop/Callback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright (c) 2011-2015, James Zhan 詹波 ([email protected]).
*
* 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.
*/

package com.jfinal.aop;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import static com.jfinal.aop.InterceptorBuilder.NULL_INTERS;

/**
* Callback.
*/
class Callback implements MethodInterceptor {

private Object injectTarget = null;
private final Interceptor[] injectInters;

private static final Set<String> excludedMethodName = buildExcludedMethodName();

public Callback() {
this.injectInters = NULL_INTERS;
}

public Callback(Interceptor... injectInters) {
if (injectInters == null)
throw new IllegalArgumentException("injectInters can not be null.");
this.injectInters = injectInters;
}

public Callback(Object injectTarget, Interceptor... injectInters) {
if (injectTarget == null)
throw new IllegalArgumentException("injectTarget can not be null.");
if (injectInters == null)
throw new IllegalArgumentException("injectInters can not be null.");
this.injectTarget = injectTarget;
this.injectInters = injectInters;
}

public Object intercept(Object target, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
if (excludedMethodName.contains(method.getName())) {
if (method.getName().equals("finalize"))
return methodProxy.invokeSuper(target, args);
return this.injectTarget != null ? methodProxy.invoke(this.injectTarget, args) : methodProxy.invokeSuper(target, args);
}

if (this.injectTarget != null) {
target = this.injectTarget;
Interceptor[] finalInters = InterceptorBuilder.build(injectInters, target.getClass(), method);
Invocation invocation = new Invocation(target, method, args, methodProxy, finalInters);
invocation.useInjectTarget = true;
invocation.invoke();
return invocation.getReturnValue();
}
else {
Interceptor[] finalInters = InterceptorBuilder.build(injectInters, target.getClass(), method);
Invocation invocation = new Invocation(target, method, args, methodProxy, finalInters);
invocation.useInjectTarget = false;
invocation.invoke();
return invocation.getReturnValue();
}
}

private static final Set<String> buildExcludedMethodName() {
Set<String> excludedMethodName = new HashSet<String>();
Method[] methods = Object.class.getDeclaredMethods();
for (Method m : methods)
excludedMethodName.add(m.getName());

// getClass() registerNatives() can not be enhanced
// excludedMethodName.remove("getClass");
// excludedMethodName.remove("registerNatives");
return excludedMethodName;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,26 @@
import java.lang.annotation.Target;

/**
* ClearInterceptor is used to clear interceptors of different level.
* It clear the upper layer interceptors by default and clear
* all layers with parameter ClearLayer.ALL
* Clear is used to clear all interceptors or the specified interceptors,
* it can not clear the interceptor which declare on method.
*
* <pre>
* Example:
* 1: clear all interceptors but InterA and InterB will be kept, because InterA and InterB declare on method
* @Clear
* @Before({InterA.class, InterB.class})
* public void method(...)
*
* 2: clear InterA and InterB, InterC and InterD will be kept
* @Clear({InterA.class, InterB.class})
* @Before({InterC.class, InterD.class})
* public void method(...)
* </pre>
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ClearInterceptor {
ClearLayer value() default ClearLayer.UPPER;
@Target({ElementType.METHOD})
public @interface Clear {
Class<? extends Interceptor>[] value() default {};
}



Loading

0 comments on commit 881baed

Please sign in to comment.