1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package com.sun.star.script.framework.provider.java; 25 26 import java.util.Vector; 27 import java.util.StringTokenizer; 28 29 /** 30 * The <code>ScriptDescriptor</code> object is used to store the search 31 * criteria that should be used for finding a particular script 32 * 33 * @author Tomas O'Connor 34 * @created August 2, 2002 35 */ 36 public class ScriptDescriptor 37 { 38 private String m_name; 39 private String m_methodName; 40 private String m_className; 41 private Vector m_classpath; 42 private Vector m_argumentTypes = new Vector( 11 ); 43 44 45 /** 46 * Constructs a ScriptDescriptor for the given name 47 * 48 * @param name Script Name 49 * @exception IllegalArgumentException if the given name does not contain a "." 50 */ ScriptDescriptor( String name )51 public ScriptDescriptor( String name ) 52 throws IllegalArgumentException 53 { 54 int idx = name.lastIndexOf( '.' ); 55 56 if ( idx == -1 ) 57 { 58 throw new IllegalArgumentException( "Invalid method name" ); 59 } 60 61 this.m_name = name; 62 this.m_methodName = name.substring( idx + 1 ); 63 this.m_className = name.substring( 0, idx ); 64 } 65 66 67 /** 68 * Gets the fully qualified name of this <code>ScriptDescriptor</code> 69 * 70 * @return The Script Name value 71 */ getName()72 public String getName() 73 { 74 return m_name; 75 } 76 77 /** 78 * Gets the fully qualified name of this <code>ScriptDescriptor</code> 79 * 80 * @return The Script Name value 81 */ getClassName()82 public String getClassName() 83 { 84 return m_className; 85 } 86 87 88 /** 89 * Gets the method name of this <code>ScriptDescriptor</code> 90 * 91 * @return The methodName value 92 */ getMethodName()93 public String getMethodName() 94 { 95 return m_methodName; 96 } 97 98 99 /** 100 * Sets the classpath value stored by this <code>ScriptDescriptor</code> 101 * 102 * @param classpath The new classpath value 103 */ setClasspath( String classpath )104 public void setClasspath( String classpath ) 105 { 106 StringTokenizer stk = new StringTokenizer( classpath, ":" ); 107 while( stk.hasMoreElements() ) 108 { 109 this.m_classpath.add( (String) stk.nextElement() ); 110 } 111 } 112 113 /** 114 * Sets the classpath value stored by this <code>ScriptDescriptor</code> 115 * 116 * @param classpath The new classpath value 117 */ setClasspath( Vector classpath )118 public void setClasspath( Vector classpath ) 119 { 120 this.m_classpath = classpath; 121 } 122 123 124 /** 125 * Gets the classpath value stored by this <code>ScriptDescriptor</code> 126 * 127 * @return The classpath value 128 */ getClasspath()129 public Vector getClasspath() 130 { 131 return m_classpath; 132 } 133 134 135 /** 136 * Adds the given <code>Class</code> to the list of argument types stored in 137 * this ScriptDescriptor 138 * 139 * @param clazz The feature to be added to the ArgumentType attribute 140 */ addArgumentType( Class clazz )141 public synchronized void addArgumentType( Class clazz ) 142 { 143 m_argumentTypes.addElement( clazz ); 144 } 145 146 147 /** 148 * Adds the given array of <code>Class</code> to the list of argument types 149 * stored in this ScriptDescriptor 150 * 151 * @param classes The feature to be added to the ArgumentTypes attribute 152 */ addArgumentTypes( Class[] classes )153 public synchronized void addArgumentTypes( Class[] classes ) 154 { 155 for ( int i = 0; i < classes.length; i++ ) 156 { 157 addArgumentType( classes[ i ] ); 158 } 159 } 160 161 162 /** 163 * Gets a list of the types of the arguments stored in this 164 * <code>ScriptDescriptor</code> 165 * 166 * return the argument types as an array of Class 167 * 168 * @return The argumentTypes value 169 */ 170 public synchronized Class[] getArgumentTypes()171 getArgumentTypes() 172 { 173 if ( m_argumentTypes.size() > 0 ) 174 return ( Class[] ) m_argumentTypes.toArray( new Class[ 0 ] ); 175 else 176 return null; 177 } 178 179 180 /** 181 * Returns a <code>String</code> representation of this 182 * <code>ScriptDescriptor</code> 183 * 184 * @return The scriptName including the parameters. 185 */ toString()186 public String toString() 187 { 188 StringBuffer description = new StringBuffer( m_name ); 189 Class[] types = getArgumentTypes(); 190 191 description.append( " (" ); 192 193 if ( types != null ) 194 { 195 for ( int i = 0; i < types.length - 1; i++ ) 196 { 197 description.append( types[ i ].getName() ); 198 description.append( ", " ); 199 } 200 201 description.append( types[ types.length - 1 ].getName() ); 202 } 203 description.append( ")" ); 204 205 return description.toString(); 206 } 207 } 208 209