gwt反射

 

Introduction

For maximum efficiency, GWT compiles your Java source into a monolithic script. Now gwt-ent provide a reflection implement by gwt code generator mechanism.

This Framework support

  1. Class http://code.google.com/p/gwt-ent/source/browse/trunk/gwtent/src/main/java/com/gwtent/reflection/client/ClassType.java
  2. Field http://code.google.com/p/gwt-ent/source/browse/trunk/gwtent/src/main/java/com/gwtent/reflection/client/Field.java
  3. Method http://code.google.com/p/gwt-ent/source/browse/trunk/gwtent/src/main/java/com/gwtent/reflection/client/Method.java
  4. Constructor http://code.google.com/p/gwt-ent/source/browse/trunk/gwtent/src/main/java/com/gwtent/reflection/client/Constructor.java
  5. Metedata http://code.google.com/p/gwt-ent/source/browse/trunk/gwtent/src/main/java/com/gwtent/reflection/client/HasMetaData.java
  6. Annotation http://code.google.com/p/gwt-ent/source/browse/trunk/gwtent/src/main/java/com/gwtent/reflection/client/HasAnnotations.java

 

How to use

# add Annotation Or Reflection Marker interface into your pojo class

@Reflectable 
public class TestReflection{ 
} 
 
public class TestReflection implements Reflection{ 
} 
 
@Reflect_Domain 
public class TestReflection{ 
}

# get ClassType.

ClassType classType = TypeOracle.Instance.getClassType(TestReflection.class);

For example:

public void testReflection(){ 
    TestReflection test = new TestReflection(); 
    ClassType classType = TypeOracle.Instance.getClassType(TestReflection.class); 
     
    test.setString("set by code"); 
    System.out.println("after SetByCode:" + test.getString()); 
    System.out.println("after SetByCode:" + classType.invoke(test, "getString", null)); 
     
    classType.invoke(test, "setString", new Object[]{"set by invoke"}); 
    System.out.println("after SetByInvoke:" + classType.invoke(test, "getString", null)); 
  } 
}

The output is :

after SetByCode:set by code 
after SetByCode:set by code 
after SetByInvoke:set by invoke

Control you javascript size

GWTENT provide you more power to control how much reflection information created.

The Class Scope

You can control whether have:
  1. Class Annotation
  2. Fields
  3. Methods
  4. Constructors
  5. Field and Method Annotations
  6. Relation Types(The field type, the return type of method, the type of Parameters)
  7. Super Classes ( all the super classes of this class will generate reflection information)
  8. Assignable Classes (all assignable classes. if annotate to a class, this is mean All subClasses will generate reflection information; if annotate to a interface, then all implement classes will generate reflection information; if annotate to an annotation, then all types annotated by this annotation will generate reflection information)
Click Here For more Information

The Field/Method Scope

You can control whether have:
  1. Annotations
  2. Field Type
  3. Method Return Type
  4. Method Parameter Type
Click Here For more Information

The TestCase

ReflectionTestCase

Understand Reflection Classes

http://code.google.com/p/gwt-ent/source/browse/trunk/gwtent/src/main/java/com/gwtent/reflection/client/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值