PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/main/java/org/jboss/as/ejb3/EJBMethodIdentifier.java

#
Java | 98 lines | 50 code | 19 blank | 29 comment | 9 complexity | 6c6e2bbf9d227fda09df81a8543bfdf3 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.ejb3;
  23. import java.lang.reflect.Method;
  24. import org.jboss.invocation.proxy.MethodIdentifier;
  25. import org.jboss.jandex.MethodInfo;
  26. import org.jboss.jandex.Type;
  27. /**
  28. * Identifier for a method on a EJB and is classloader agnostic.
  29. * <p/>
  30. * Unlike the {@link MethodIdentifier} this {@link EJBMethodIdentifier} takes into the account the declaring class of the
  31. * method.
  32. * <p/>
  33. * User: Jaikiran Pai
  34. */
  35. public class EJBMethodIdentifier {
  36. private final MethodIdentifier methodIdentifier;
  37. private final String methodDeclaringClass;
  38. private final int cachedHashCode;
  39. public EJBMethodIdentifier(final MethodIdentifier methodIdentifier, final String methodDeclaringClass) {
  40. this.methodIdentifier = methodIdentifier;
  41. this.methodDeclaringClass = methodDeclaringClass;
  42. this.cachedHashCode = this.generateHashCode();
  43. }
  44. public static EJBMethodIdentifier fromMethodInfo(final MethodInfo methodInfo) {
  45. final String returnType = methodInfo.returnType().name().toString();
  46. final String[] argTypes = new String[methodInfo.args().length];
  47. int i = 0;
  48. for (Type argType : methodInfo.args()) {
  49. argTypes[i++] = argType.name().toString();
  50. }
  51. final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(returnType, methodInfo.name(), argTypes);
  52. return new EJBMethodIdentifier(methodIdentifier, methodInfo.declaringClass().name().toString());
  53. }
  54. public static EJBMethodIdentifier fromMethod(final Method method) {
  55. final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
  56. return new EJBMethodIdentifier(methodIdentifier, method.getDeclaringClass().getName());
  57. }
  58. private int generateHashCode() {
  59. int result = methodIdentifier.hashCode();
  60. result = 31 * result + methodDeclaringClass.hashCode();
  61. return result;
  62. }
  63. public MethodIdentifier getMethodIdentifier() {
  64. return methodIdentifier;
  65. }
  66. @Override
  67. public boolean equals(Object o) {
  68. if (this == o) return true;
  69. if (o == null || getClass() != o.getClass()) return false;
  70. EJBMethodIdentifier that = (EJBMethodIdentifier) o;
  71. if (!methodDeclaringClass.equals(that.methodDeclaringClass)) return false;
  72. if (!methodIdentifier.equals(that.methodIdentifier)) return false;
  73. return true;
  74. }
  75. @Override
  76. public int hashCode() {
  77. return this.cachedHashCode;
  78. }
  79. }