001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.jee;
018:
019: import javax.xml.bind.annotation.XmlAccessType;
020: import javax.xml.bind.annotation.XmlAccessorType;
021: import javax.xml.bind.annotation.XmlAttribute;
022: import javax.xml.bind.annotation.XmlElement;
023: import javax.xml.bind.annotation.XmlID;
024: import javax.xml.bind.annotation.XmlType;
025: import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
026: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
027:
028: /**
029: */
030: @XmlAccessorType(XmlAccessType.FIELD)
031: @XmlType(name="named-methodType",propOrder={"methodName","methodParams"})
032: public class NamedMethod {
033:
034: @XmlElement(name="method-name",required=true)
035: protected String methodName;
036: @XmlElement(name="method-params")
037: protected MethodParams methodParams;
038: @XmlAttribute
039: @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
040: @XmlID
041: protected String id;
042:
043: public NamedMethod() {
044: }
045:
046: public NamedMethod(java.lang.reflect.Method method) {
047: this .methodName = method.getName();
048: MethodParams methodParams = new MethodParams();
049: for (Class<?> type : method.getParameterTypes()) {
050: methodParams.getMethodParam().add(type.getCanonicalName());
051: }
052: this .methodParams = methodParams;
053: }
054:
055: public NamedMethod(String methodName, String... parameters) {
056: this .methodName = methodName;
057:
058: if (parameters.length > 0) {
059: MethodParams params = new MethodParams();
060: for (String paramName : parameters) {
061: params.getMethodParam().add(paramName);
062: }
063: this .methodParams = params;
064: }
065: }
066:
067: public String getMethodName() {
068: return methodName;
069: }
070:
071: public void setMethodName(String value) {
072: this .methodName = value;
073: }
074:
075: public MethodParams getMethodParams() {
076: return methodParams;
077: }
078:
079: public void setMethodParams(MethodParams value) {
080: this .methodParams = value;
081: }
082:
083: public String getId() {
084: return id;
085: }
086:
087: public void setId(String value) {
088: this .id = value;
089: }
090:
091: public boolean equals(Object o) {
092: if (this == o)
093: return true;
094: if (o == null || getClass() != o.getClass())
095: return false;
096:
097: final NamedMethod that = (NamedMethod) o;
098:
099: if (methodName != null ? !methodName.equals(that.methodName)
100: : that.methodName != null)
101: return false;
102:
103: if (nullOrEmpty(this .methodParams)
104: && nullOrEmpty(that.methodParams))
105: return true;
106:
107: if (methodParams != null ? !methodParams
108: .equals(that.methodParams) : that.methodParams != null)
109: return false;
110:
111: return true;
112: }
113:
114: private boolean nullOrEmpty(MethodParams methodParams) {
115: return methodParams == null
116: || methodParams.getMethodParam().size() == 0;
117: }
118:
119: public int hashCode() {
120: int result;
121: result = (methodName != null ? methodName.hashCode() : 0);
122: result = 29 * result
123: + (methodParams != null ? methodParams.hashCode() : 0);
124: return result;
125: }
126: }
|