<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-295  評論-26  文章-1  trackbacks-0

    AnnotationProcessor ???? Annotation 處理的接口,實現類是DefaltAnnotationProcessor?:

    protected static?void lookupFieldResource (javax.naming.Context?context, java.lang.Object?instance, java.lang.reflect.Field?field, java.lang.String?name)
    ??????????Inject resources in specified field.
    protected static?void lookupMethodResource (javax.naming.Context?context, java.lang.Object?instance, java.lang.reflect.Method?method, java.lang.String?name)
    ??????????Inject resources in specified method.
    ?void postConstruct (java.lang.Object?instance)
    ??????????Call postConstruct method on the specified instance.
    ?void preDestroy (java.lang.Object?instance)
    ??????????Call preDestroy method on the specified instance.
    ?void processAnnotations (java.lang.Object?instance)
    ??????????Inject resources in specified instance


    public class DefaultAnnotationProcessor implements AnnotationProcessor {
    ???
    ??? protected javax.naming.Context context = null;
    ???
    ??? public DefaultAnnotationProcessor(javax.naming.Context context) {
    ??????? this.context = context;
    ??? }


    ??? /**
    ???? * Call postConstruct method on the specified instance.
    ???? */
    ??? public void postConstruct(Object instance)
    ??????? throws IllegalAccessException, InvocationTargetException {
    ???????
    ??????? Method[] methods = instance.getClass().getDeclaredMethods();
    ??????? Method postConstruct = null;
    ??????? for (int i = 0; i < methods.length; i++) {
    ??????????? if (methods[i].isAnnotationPresent(PostConstruct.class)) {
    ??????????????? if ((postConstruct != null)
    ??????????????????????? || (methods[i].getParameterTypes().length != 0)
    ??????????????????????? || (Modifier.isStatic(methods[i].getModifiers()))
    ??????????????????????? || (methods[i].getExceptionTypes().length > 0)
    ??????????????????????? || (!methods[i].getReturnType().getName().equals("void"))) {
    ??????????????????? throw new IllegalArgumentException("Invalid PostConstruct annotation");
    ??????????????? }
    ??????????????? postConstruct = methods[i];
    ??????????? }
    ??????? }

    ??????? // At the end the postconstruct annotated
    ??????? // method is invoked
    ??????? if (postConstruct != null) {
    ??????????? boolean accessibility = postConstruct.isAccessible();
    ??????????? postConstruct.setAccessible(true);
    ??????????? postConstruct.invoke(instance);
    ??????????? postConstruct.setAccessible(accessibility);
    ??????? }
    ???????
    ??? }
    ???
    ???
    ??? /**
    ???? * Call preDestroy method on the specified instance.
    ???? */
    ??? public void preDestroy(Object instance)
    ??????? throws IllegalAccessException, InvocationTargetException {
    ???????
    ??????? Method[] methods = instance.getClass().getDeclaredMethods();
    ??????? Method preDestroy = null;
    ??????? for (int i = 0; i < methods.length; i++) {
    ??????????? if (methods[i].isAnnotationPresent(PreDestroy.class)) {
    ??????????????? if ((preDestroy != null)
    ??????????????????????? || (methods[i].getParameterTypes().length != 0)
    ??????????????????????? || (Modifier.isStatic(methods[i].getModifiers()))
    ??????????????????????? || (methods[i].getExceptionTypes().length > 0)
    ??????????????????????? || (!methods[i].getReturnType().getName().equals("void"))) {
    ??????????????????? throw new IllegalArgumentException("Invalid PreDestroy annotation");
    ??????????????? }
    ??????????????? preDestroy = methods[i];
    ??????????? }
    ??????? }

    ??????? // At the end the postconstruct annotated
    ??????? // method is invoked
    ??????? if (preDestroy != null) {
    ??????????? boolean accessibility = preDestroy.isAccessible();
    ??????????? preDestroy.setAccessible(true);
    ??????????? preDestroy.invoke(instance);
    ??????????? preDestroy.setAccessible(accessibility);
    ??????? }
    ???????
    ??? }
    ???
    ???
    ??? /**
    ???? * Inject resources in specified instance.
    ???? */
    ??? public void processAnnotations(Object instance)
    ??????? throws IllegalAccessException, InvocationTargetException, NamingException {
    ???????
    ??????? if (context == null) {
    ??????????? // No resource injection
    ??????????? return;
    ??????? }
    ???????
    ??????? // Initialize fields annotations
    ??????? Field[] fields = instance.getClass().getDeclaredFields();
    ??????? for (int i = 0; i < fields.length; i++) {
    ??????????? if (fields[i].isAnnotationPresent(Resource.class)) {
    ??????????????? Resource annotation = (Resource) fields[i].getAnnotation(Resource.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????????? if (fields[i].isAnnotationPresent(EJB.class)) {
    ??????????????? EJB annotation = (EJB) fields[i].getAnnotation(EJB.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????????? if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
    ??????????????? WebServiceRef annotation =
    ??????????????????? (WebServiceRef) fields[i].getAnnotation(WebServiceRef.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????????? if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
    ??????????????? PersistenceContext annotation =
    ??????????????????? (PersistenceContext) fields[i].getAnnotation(PersistenceContext.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????????? if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
    ??????????????? PersistenceUnit annotation =
    ??????????????????? (PersistenceUnit) fields[i].getAnnotation(PersistenceUnit.class);
    ??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
    ??????????? }
    ??????? }
    ???????
    ??????? // Initialize methods annotations
    ??????? Method[] methods = instance.getClass().getDeclaredMethods();
    ??????? for (int i = 0; i < methods.length; i++) {
    ??????????? if (methods[i].isAnnotationPresent(Resource.class)) {
    ??????????????? Resource annotation = (Resource) methods[i].getAnnotation(Resource.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????????? if (methods[i].isAnnotationPresent(EJB.class)) {
    ??????????????? EJB annotation = (EJB) methods[i].getAnnotation(EJB.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????????? if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
    ??????????????? WebServiceRef annotation =
    ??????????????????? (WebServiceRef) methods[i].getAnnotation(WebServiceRef.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????????? if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
    ??????????????? PersistenceContext annotation =
    ??????????????????? (PersistenceContext) methods[i].getAnnotation(PersistenceContext.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????????? if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
    ??????????????? PersistenceUnit annotation =
    ??????????????????? (PersistenceUnit) methods[i].getAnnotation(PersistenceUnit.class);
    ??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
    ??????????? }
    ??????? }

    ??? }
    ???
    ???
    ??? /**
    ???? * Inject resources in specified field.
    ???? */
    ??? protected static void lookupFieldResource(javax.naming.Context context,
    ??????????? Object instance, Field field, String name)
    ??????? throws NamingException, IllegalAccessException {
    ???
    ??????? Object lookedupResource = null;
    ??????? boolean accessibility = false;
    ???????
    ??????? if ((name != null) &&
    ??????????????? (name.length() > 0)) {
    ??????????? lookedupResource = context.lookup(name);
    ??????? } else {
    ??????????? lookedupResource = context.lookup(instance.getClass().getName() + "/" + field.getName());
    ??????? }
    ???????
    ??????? accessibility = field.isAccessible();
    ??????? field.setAccessible(true);
    ??????? field.set(instance, lookedupResource);
    ??????? field.setAccessible(accessibility);
    ??? }


    ??? /**
    ???? * Inject resources in specified method.
    ???? */
    ??? protected static void lookupMethodResource(javax.naming.Context context,
    ??????????? Object instance, Method method, String name)
    ??????? throws NamingException, IllegalAccessException, InvocationTargetException {
    ???????
    ??????? if (!method.getName().startsWith("set")
    ??????????????? || method.getParameterTypes().length != 1
    ??????????????? || !method.getReturnType().getName().equals("void")) {
    ??????????? throw new IllegalArgumentException("Invalid method resource injection annotation");
    ??????? }
    ???????
    ??????? Object lookedupResource = null;
    ??????? boolean accessibility = false;
    ???????
    ??????? if ((name != null) &&
    ??????????????? (name.length() > 0)) {
    ??????????? lookedupResource = context.lookup(name);
    ??????? } else {
    ??????????? lookedupResource =
    ??????????????? context.lookup(instance.getClass().getName() + "/" + method.getName().substring(3));
    ??????? }
    ???????
    ??????? accessibility = method.isAccessible();
    ??????? method.setAccessible(true);
    ??????? method.invoke(instance, lookedupResource);
    ??????? method.setAccessible(accessibility);
    ??? }
    ???

    }



    大盤預測 國富論
    posted on 2007-06-28 15:26 華夢行 閱讀(666) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲中文字幕无码爆乳av中文| 四虎影院免费视频| 国产精品亚洲精品日韩已满| 精品特级一级毛片免费观看| 日本黄页网站免费| 免费VA在线观看无码| 亚洲精品无码激情AV| 好男人资源在线WWW免费| 亚洲精品无码成人片久久| 两个人看的www免费视频中文| 国产精品亚洲а∨无码播放| 中文字幕乱码一区二区免费| 亚洲国产精品久久久久| 国产高清不卡免费在线| 亚洲一级在线观看| 国产一区二区三区在线观看免费| 美女黄网站人色视频免费| 精品亚洲一区二区三区在线观看 | 日韩精品视频在线观看免费| 国产综合精品久久亚洲| 亚洲免费在线视频| 亚洲另类精品xxxx人妖| 在线视频免费国产成人| 国产特黄一级一片免费 | 亚洲人成无码网站| 222www在线观看免费| 亚洲精品9999久久久久无码 | 国产精品国产免费无码专区不卡| 永久免费观看黄网站| 亚洲AV乱码一区二区三区林ゆな| 很黄很黄的网站免费的| 亚洲heyzo专区无码综合| 国产亚洲精品成人AA片新蒲金| 91高清免费国产自产拍2021| 亚洲综合av一区二区三区| 亚洲精品国精品久久99热| 99热这里只有精品免费播放| 亚洲av日韩精品久久久久久a| 亚洲精品乱码久久久久久久久久久久 | 国产日产亚洲系列最新| 亚洲视频在线免费播放|