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 */ 017 018 package org.apache.geronimo.gbean; 019 020 import java.io.Serializable; 021 import java.util.ArrayList; 022 import java.util.Arrays; 023 import java.util.Collections; 024 import java.util.Iterator; 025 import java.util.List; 026 027 /** 028 * Describes an operation on a GBean. 029 * 030 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 031 */ 032 public class GOperationInfo implements Serializable { 033 private static final long serialVersionUID = -5593225815559931812L; 034 /** 035 * The name of this method. 036 */ 037 private final String name; 038 039 /** 040 * The return type of this method. 041 */ 042 private final String returnType; 043 044 /** 045 * Parameters of this method. 046 */ 047 private final List parameters; 048 049 /** 050 * Target method name. 051 */ 052 private final String methodName; 053 054 public GOperationInfo(String name, String type) { 055 this(name, name, Collections.EMPTY_LIST, type); 056 } 057 058 public GOperationInfo(String name, Class[] paramTypes, String returnType) { 059 this.name = this.methodName = name; 060 this.returnType = returnType; 061 String[] args = new String[paramTypes.length]; 062 for (int i = 0; i < args.length; i++) { 063 args[i] = paramTypes[i].getName(); 064 } 065 this.parameters = Collections.unmodifiableList(Arrays.asList(args)); 066 } 067 068 public GOperationInfo(String name, String[] paramTypes, String returnType) { 069 this(name, name, Arrays.asList(paramTypes), returnType); 070 } 071 072 public GOperationInfo(String name, List parameters, String returnType) { 073 this(name, name, parameters, returnType); 074 } 075 076 public GOperationInfo(String name, String methodName, List parameters, String returnType) { 077 this.name = name; 078 this.returnType = returnType; 079 this.methodName = methodName; 080 this.parameters = Collections.unmodifiableList(new ArrayList(parameters)); 081 } 082 083 public String getName() { 084 return name; 085 } 086 087 public String getReturnType() { 088 return returnType; 089 } 090 091 public String getMethodName() { 092 return methodName; 093 } 094 095 public List getParameterList() { 096 return parameters; 097 } 098 099 public String toString() { 100 return "[GOperationInfo: name=" + name + " parameters=" + parameters + " returnType =" + returnType + "]"; 101 } 102 103 public String toXML() { 104 StringBuilder xml = new StringBuilder(); 105 106 xml.append("<gOperationInfo "); 107 xml.append("name='" + name + "' "); 108 xml.append("returnType='" + returnType + "' "); 109 xml.append(">"); 110 111 xml.append("<parameters>"); 112 113 for (Iterator loop = parameters.iterator(); loop.hasNext(); ) { 114 xml.append("<parameterType>" + loop.next().toString() + "</parameterType>"); 115 } 116 117 xml.append("</parameters>"); 118 119 xml.append("</gOperationInfo>"); 120 121 return xml.toString(); 122 } 123 }