001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.gbean;
017:
018: import java.io.Serializable;
019: import java.util.ArrayList;
020: import java.util.Arrays;
021: import java.util.Collections;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: /**
026: * Describes an operation on a GBean.
027: *
028: * @version $Rev: 564608 $ $Date: 2007-08-10 07:43:14 -0700 (Fri, 10 Aug 2007) $
029: */
030: public class GOperationInfo implements Serializable {
031: private static final long serialVersionUID = -5593225815559931812L;
032: /**
033: * The name of this method.
034: */
035: private final String name;
036:
037: /**
038: * The return type of this method.
039: */
040: private final String returnType;
041:
042: /**
043: * Parameters of this method.
044: */
045: private final List parameters;
046:
047: /**
048: * Target method name.
049: */
050: private final String methodName;
051:
052: public GOperationInfo(String name, String type) {
053: this (name, name, Collections.EMPTY_LIST, type);
054: }
055:
056: public GOperationInfo(String name, Class[] paramTypes,
057: String returnType) {
058: this .name = this .methodName = name;
059: this .returnType = returnType;
060: String[] args = new String[paramTypes.length];
061: for (int i = 0; i < args.length; i++) {
062: args[i] = paramTypes[i].getName();
063: }
064: this .parameters = Collections.unmodifiableList(Arrays
065: .asList(args));
066: }
067:
068: public GOperationInfo(String name, String[] paramTypes,
069: String returnType) {
070: this (name, name, Arrays.asList(paramTypes), returnType);
071: }
072:
073: public GOperationInfo(String name, List parameters,
074: String returnType) {
075: this (name, name, parameters, returnType);
076: }
077:
078: public GOperationInfo(String name, String methodName,
079: List parameters, String returnType) {
080: this .name = name;
081: this .returnType = returnType;
082: this .methodName = methodName;
083: this .parameters = Collections.unmodifiableList(new ArrayList(
084: parameters));
085: }
086:
087: public String getName() {
088: return name;
089: }
090:
091: public String getReturnType() {
092: return returnType;
093: }
094:
095: public String getMethodName() {
096: return methodName;
097: }
098:
099: public List getParameterList() {
100: return parameters;
101: }
102:
103: public String toString() {
104: return "[GOperationInfo: name=" + name + " parameters="
105: + parameters + " returnType =" + returnType + "]";
106: }
107:
108: public String toXML() {
109: StringBuilder xml = new StringBuilder();
110:
111: xml.append("<gOperationInfo ");
112: xml.append("name='" + name + "' ");
113: xml.append("returnType='" + returnType + "' ");
114: xml.append(">");
115:
116: xml.append("<parameters>");
117:
118: for (Iterator loop = parameters.iterator(); loop.hasNext();) {
119: xml.append("<parameterType>" + loop.next().toString()
120: + "</parameterType>");
121: }
122:
123: xml.append("</parameters>");
124:
125: xml.append("</gOperationInfo>");
126:
127: return xml.toString();
128: }
129: }
|