bamskeleton.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 562 行 · 第 1/2 页

JAVA
562
字号
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * *   Free Software Foundation, Inc. *   59 Temple Place, Suite 330 *   Boston, MA 02111-1307  USA * * @author Emil Ong */package com.caucho.bam;import com.caucho.config.*;import com.caucho.bam.annotation.*;import com.caucho.bam.BamError;import com.caucho.util.*;import java.io.Serializable;import java.lang.annotation.*;import java.lang.reflect.*;import java.util.*;import java.util.logging.*;import javax.annotation.*;import javax.webbeans.*;/** */public class BamSkeleton<C>{  private static final L10N L = new L10N(BamSkeleton.class);  private static final Logger log    = Logger.getLogger(BamSkeleton.class.getName());  private final static WeakHashMap<Class, BamSkeleton> _skeletons    = new WeakHashMap<Class, BamSkeleton>();  private Class _cl;    private final HashMap<Class, Method> _messageHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _messageErrorHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _queryGetHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _querySetHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _queryResultHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _queryErrorHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _presenceHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _presenceProbeHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _presenceSubscribeHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _presenceSubscribedHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _presenceUnsubscribeHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _presenceUnsubscribedHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _presenceUnavailableHandlers    = new HashMap<Class, Method>();  private final HashMap<Class, Method> _presenceErrorHandlers    = new HashMap<Class, Method>();  private BamSkeleton(Class<C> cl)  {    _cl = cl;        log.finest(L.l("{0} introspecting class {1}", this, cl.getName()));    Method[] methods = cl.getMethods();    for (int i = 0; i < methods.length; i++) {      Method method = methods[i];            Class messageType = getMessageType(Message.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @Message handler type={1} method={2}",		       this, messageType.getName(), method));	        _messageHandlers.put(messageType, method);        continue;      }      messageType = getMessageType(MessageError.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @MessageError handler type={1} method={2}",		       this, messageType.getName(), method));	        _messageErrorHandlers.put(messageType, method);        continue;      }      messageType = getQueryMessageType(QueryGet.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @QueryGet handler type={1} method={2}",		       this, messageType.getName(), method));	        _queryGetHandlers.put(messageType, method);        continue;      }      messageType = getQueryMessageType(QuerySet.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @QuerySet handler type={1} method={2}",		       this, messageType.getName(), method));        _querySetHandlers.put(messageType, method);        continue;      }      messageType = getQueryMessageType(QueryResult.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @QueryResult handler type={1} method={2}",		       this, messageType.getName(), method));        _queryResultHandlers.put(messageType, method);        continue;      }            messageType = getQueryMessageType(QueryError.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @QueryError handler type={1} method={2}",		       this, messageType.getName(), method));	        _queryErrorHandlers.put(messageType, method);        continue;      }      messageType = getMessageType(Presence.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @Presence handler type={1} method={2}",		       this, messageType.getName(), method));	        _presenceHandlers.put(messageType, method);	        continue;      }      messageType = getMessageType(PresenceProbe.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @PresenceProbe handler type={1} method={2}",		       this, messageType.getName(), method));        _presenceProbeHandlers.put(messageType, methods[i]);	        continue;      }      messageType = getMessageType(PresenceSubscribe.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @PresenceSubscribe handler type={1} method={2}",		       this, messageType.getName(), method));	        _presenceSubscribeHandlers.put(messageType, methods[i]);        continue;      }      messageType = getMessageType(PresenceSubscribed.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @PresenceSubscribe handler type={1} method={2}",		       this, messageType.getName(), method));        _presenceSubscribedHandlers.put(messageType, methods[i]);        continue;      }      messageType = getMessageType(PresenceUnsubscribe.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @PresenceUnsubscribe handler type={1} method={2}",		       this, messageType.getName(), method));        _presenceUnsubscribeHandlers.put(messageType, methods[i]);        continue;      }      messageType = getMessageType(PresenceUnsubscribed.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @PresenceUnsubscribed handler type={1} method={2}",		       this, messageType.getName(), method));        _presenceUnsubscribedHandlers.put(messageType, methods[i]);        continue;      }      messageType = getMessageType(PresenceUnavailable.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @PresenceUnavailable handler type={1} method={2}",		       this, messageType.getName(), method));	        _presenceUnavailableHandlers.put(messageType, methods[i]);        continue;      }      messageType = getMessageType(PresenceError.class, method);      if (messageType != null) {        log.finest(L.l("{0} found @PresenceError handler type={1} method={2}",		       this, messageType.getName(), method));        _presenceErrorHandlers.put(messageType, methods[i]);        continue;      }    }  }  private Class getMessageType(Class annotationType, Method method)  {    Class []paramTypes = method.getParameterTypes();    if (paramTypes.length < 3)      return null;    if (method.isAnnotationPresent(annotationType))      return paramTypes[2];    else      return null;  }  private Class getQueryMessageType(Class annotationType, Method method)  {    Class []paramTypes = method.getParameterTypes();    if (paramTypes.length < 4)      return null;    if (method.isAnnotationPresent(annotationType))      return paramTypes[3];    else      return null;  }   public static BamSkeleton getBamSkeleton(Class cl)  {    synchronized(_skeletons) {      BamSkeleton skeleton = _skeletons.get(cl);      if (skeleton == null) {        skeleton = new BamSkeleton(cl);        _skeletons.put(cl, skeleton);      }      return skeleton;    }  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?