<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 華夢行 閱讀(667) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 波多野结衣亚洲一级| 香蕉视频在线观看亚洲| 亚洲偷偷自拍高清| 啦啦啦高清视频在线观看免费| 亚洲av日韩av无码黑人| 久久国产乱子伦精品免费一 | 日韩视频免费在线| 亚洲高清毛片一区二区| 国产网站免费观看| 免费福利资源站在线视频| 亚洲麻豆精品国偷自产在线91| 免费福利在线观看| 亚洲成亚洲乱码一二三四区软件| 在线观看免费黄色网址| 亚洲另类激情综合偷自拍| 国产成人精品免费午夜app| 亚洲av永久无码嘿嘿嘿 | 亚洲?v女人的天堂在线观看| www永久免费视频| 亚洲成a人片77777kkkk| 16女性下面无遮挡免费| 亚洲综合一区国产精品| 亚洲Av无码国产情品久久| 久久免费99精品国产自在现线 | 亚洲免费观看网站| 国产三级免费电影| 国产一区二区三区免费观在线| 亚洲AV无码码潮喷在线观看 | 亚洲国产精品毛片av不卡在线| 成在线人视频免费视频| 亚洲资源在线视频| 日产国产精品亚洲系列| 你懂的免费在线观看网站| 亚洲中文字幕在线无码一区二区 | 国产亚洲av片在线观看16女人| 每天更新的免费av片在线观看 | 亚洲?v无码国产在丝袜线观看| 国精产品一区一区三区免费视频| 四虎永久免费地址在线观看| 免费看的一级毛片| 久久99毛片免费观看不卡|