gt: 		for (int i = 0; i < allMethods.length; i++)
context: package com.idega.util.reflect;
  /**
   * A utility class to find methods by reflection.
   * Title:       idega Reflection utility classes
   * Description:
   * Copyright:    Copyright (c) 2001-2003
   * Company:      idega
   * @author <a href="tryggvi@idega.is">Tryggvi Larusson</a>
   * @version 1.1
   */
  import java.lang.reflect.Method;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.StringTokenizer;
  import java.util.Vector;
  import com.idega.repository.data.Instantiator;
  import com.idega.repository.data.RefactorClassRegistry;
  import com.idega.repository.data.Singleton;
  import com.idega.repository.data.SingletonRepository;
  import com.idega.util.caching.CacheMap;
  public class MethodFinder implements Singleton
  {
  	static final String separator = ":";
  	static final String methodString = "method";
  	static final int declaringClassIndex = 2;
  	static final int returnedClassIndex = 3;
  	static final int methodIndex = 4;
  	static final int parameterClassStartIndex = 5;
  	
  	private static Instantiator instantiator = new Instantiator() { public Object getInstance() { return new MethodFinder();}};
  	
  	private Map methodCache;
  	private Map classMethodCache;
  	
  	private MethodFinder()
  	{
  	}
  	
  	public static MethodFinder getInstance() {
  		return (MethodFinder) SingletonRepository.getRepository().getInstance(MethodFinder.class, instantiator);
  	}
  
  	private Map getMethodCache()
  	{
  		if (this.methodCache == null)
  		{
  			this.methodCache = new CacheMap(1000);
  		}
  		return this.methodCache;
  	}
  
  	protected Method getMethodFromGlobalCache(String methodIdentifier)
  	{
  		return (Method) getMethodCache().get(methodIdentifier);
  	}
  	protected void putMethodInGlobalCache(String methodIdentifier, Method method)
  	{
  		getMethodCache().put(methodIdentifier, method);
  	}
  	
  	
  	
  	private Map getClassMethodCache(Class declaringClass)
  	{
  		if (this.classMethodCache == null)
  		{
  			this.classMethodCache = new HashMap();
  		}
  		Map mapForClass = (Map) this.classMethodCache.get(declaringClass);
  		if(mapForClass==null){
  			mapForClass = new CacheMap(150);
  			this.classMethodCache.put(declaringClass,mapForClass);
  		}
  		return mapForClass;
  	}
  	
  	protected Method getMethodFromClassCache(Class declaringClass,String methodIdentifier)
  	{
  		return (Method) getClassMethodCache(declaringClass).get(methodIdentifier);
  	}
  	protected void putMethodInClassCache(Class declaringClass,String methodIdentifier, Method method)
  	{
  		getClassMethodCache(declaringClass).put(methodIdentifier, method);
  	}
  	
  	public Method getMethod(String methodIdentifier)
  	{
  		try
  		{
  			Method m = getMethodFromGlobalCache(methodIdentifier);
  			if (m == null)
  			{
  				String[] idArray = getIdentifierAsArray(methodIdentifier);
  				Class declaringClass = getDeclaringClass(idArray);
  				m = getMethod(declaringClass, idArray);
  				putMethodInGlobalCache(methodIdentifier, m);
  			}
  			return m;
  		} catch (Exception e)
  		{
  			e.printStackTrace();
  		}
  		return null;
  	}
  
  	public Method getMethod(String methodIdentifier, Class declaringClass)
  	{
  		Method m = getMethodFromClassCache(declaringClass,methodIdentifier);
  		if(m==null){
  			String[] idArray = getIdentifierAsArray(methodIdentifier);
  			m = getMethod(declaringClass, idArray);
  			putMethodInClassCache(declaringClass,methodIdentifier,m);
  		}
  		return m;
  	}
  	
  	
  	/**
  	 * Does method finding and tries to correct any refactored class types
  	 * @param methodIdentifier
  	 * @param declaringClass
  	 * @param idArray
  	 * @return
  	 */
  	private Method getMethod(Class declaringClass, String[] idArray)
  	{
  		try{
  			return findRealMethod(declaringClass,idArray);
  		}
  		catch(Throwable nsme){
  			RefactorClassRegistry registry = RefactorClassRegistry.getInstance();
  			Map refactoredClassNames = registry.getRefactoredClassNames();
  			Iterator iterator = refactoredClassNames.keySet().iterator();
  			while (iterator.hasNext())
  			{
  				String oldClassName = (String) iterator.next();
  				String newClassName = (String)refactoredClassNames.get(oldClassName);
  				String[] newIdArray = new String[idArray.length];
  				for (int i = 0; i < idArray.length; i++)
  				{
  					String str = idArray[i];
  					if(str.equals(oldClassName)){
  						newIdArray[i]=newClassName;
  					}
  					else{
  						newIdArray[i]=idArray[i];
  					}
  				}
  				try{
  					return findRealMethod(declaringClass,newIdArray);
  				}
  				catch(ClassNotFoundException cnfe){
  					System.err.println("MethodFinder.getMethod() Error finding method with parameter of type : "+cnfe.getMessage());
  				}
  				catch(Throwable nsme2){
  					System.err.println("MethodFinder.getMethod() Error finding method, message: "+nsme2.getMessage());
  				}
  				
  			}
  			throw new NoSuchMethodError(nsme.getMessage());
  		}
  	}
  	
  	
  	/**
  	 * Does the Real method finding
  	 * @param methodIdentifier
  	 * @param declaringClass
  	 * @param idArray
  	 * @return
  	 */
  	private Method findRealMethod(Class declaringClass, String[] idArray) throws ClassNotFoundException
  	{
  		//try
  		//{
  			//System.out.println("Declaring class: "+c.getName());
  			Method[] methods = getMethods(declaringClass);
  			for (int i = 0; i < methods.length; i++)
  			{
  				if (methods[i].getName().equals(getMethodName(idArray)))
  				{
  					//System.out.println("MethodName: "+methods[i].getName()+" returnType = "+methods[i].getReturnType().getName());
  					if (methods[i].getReturnType().equals(getReturnTypeClass(idArray)))
  					{
  						Class[] classes = getArgumentClasses(idArray);
  						Class[] methodClasses = methods[i].getParameterTypes();
  						boolean check = true;
  						if (methodClasses.length > 0)
  						{
  							if (classes.length != methodClasses.length)
  							{
  								check = false;
  							} else
  							{
  								for (int j = 0;(j < classes.length && check); j++)
  								{
  									if (!methodClasses[j].equals(classes[j]))
  									{
  										//System.out.print(methodIdentifier);
  										//System.out.println(methods[i].toString());
  										//System.out.println("MethodClasses["+j+"]"+methodClasses[j].getName());
  										check = false;
  									}
  								}
  							}
  						} else
  						{
  							//System.out.println("Methodfinder length "+classes.length);
  							if (classes.length > 0)
  							{
  								if (!classes[0].equals(java.lang.Void.TYPE))
  								{
  									check = false;
  								}
  							}
  						}
  						if (check)
  						{
  							return methods[i];
  						}
  					}
  				}
  			}
  		//} catch (ClassNotFoundException e)
  		//{
  		//	e.printStackTrace();
  		//}
  		return null;
  	}
  	public String getMethodIdentifierWithoutDeclaringClass(Method method)
  	{
  		return getMethodIdentifier(method, false);
  	}
  	public String getMethodIdentifier(Method method)
  	{
  		return getMethodIdentifier(method, true);
  	}
  	private String getMethodIdentifier(Method method, boolean includeDeclaringClass)
  	{
  		StringBuffer buf = new StringBuffer();
  		buf.append(separator);
  		buf.append(methodString);
  		buf.append(separator);
  		buf.append(method.getModifiers());
  		buf.append(separator);
  		if (includeDeclaringClass)
  		{
  			buf.append(method.getDeclaringClass().getName());
  		} else
  		{
  			buf.append("implied");
  		}
  		buf.append(separator);
  		buf.append(method.getReturnType().getName());
  		buf.append(separator);
  		buf.append(method.getName());
  		buf.append(separator);
  		Class[] parameterTypes = method.getParameterTypes();
  		if (parameterTypes.length > 0)
  		{
  			for (int i = 0; i < parameterTypes.length; i++)
  			{
  				buf.append(parameterTypes[i].getName());
  				buf.append(separator);
  			}
  		} else
  		{
  			buf.append("void");
  			buf.append(separator);
  		}
  		return buf.toString();
  	}
  	private String[] getIdentifierAsArray(String identifier)
  	{
  		StringTokenizer token = new StringTokenizer(identifier, separator);
  		int size = token.countTokens();
  		String array[] = new String[size];
  		for (int i = 0; i < array.length; i++)
  		{
  			array[i] = token.nextToken();
  		}
  		return array;
  	}
  	private static Class getClass(String className) throws ClassNotFoundException
  	{
  		if (className.equals("void"))
  		{
  			return java.lang.Void.TYPE;
  		} else if (className.equals("int"))
  		{
  			return java.lang.Integer.TYPE;
  		} else if (className.equals("boolean"))
  		{
  			return java.lang.Boolean.TYPE;
  		} else if (className.equals("float"))
  		{
  			return java.lang.Float.TYPE;
  		} else if (className.equals("double"))
  		{
  			return java.lang.Double.TYPE;
  		} else if (className.equals("long"))
  		{
  			return java.lang.Long.TYPE;
  		} else
  		{
  			return RefactorClassRegistry.forName(className);
  		}
  	}
  	public String getDeclaringClassName(String[] identifierArray)
  	{
  		return identifierArray[declaringClassIndex];
  	}
  	public Class getDeclaringClass(String[] identifierArray) throws ClassNotFoundException
  	{
  		return RefactorClassRegistry.forName(getDeclaringClassName(identifierArray));
  	}
  	public String getReturnTypeClassName(String[] identifierArray)
  	{
  		return identifierArray[returnedClassIndex];
  	}
  	public Class getReturnTypeClass(String[] identifierArray) throws ClassNotFoundException
  	{
  		return getClass(getReturnTypeClassName(identifierArray));
  	}
  	public String getMethodName(String[] identifierArray)
  	{
  		return identifierArray[methodIndex];
  	}
  	public String[] getArgumentClassNames(String[] identifierArray)
  	{
  		int length = identifierArray.length - parameterClassStartIndex;
  		String[] theReturn = new String[length];
  		if (length != 0)
  		{
  			System.arraycopy(identifierArray, parameterClassStartIndex, theReturn, 0, theReturn.length);
  		}
  		return theReturn;
  	}
  	public Class[] getArgumentClasses(String methodIdentifier) throws ClassNotFoundException
  	{
  		return getArgumentClasses(getIdentifierAsArray(methodIdentifier));
  	}
  	public Class[] getArgumentClasses(String[] identifierArray) throws ClassNotFoundException
  	{
  		String[] strings = getArgumentClassNames(identifierArray);
  		Class[] theReturn = new Class[strings.length];
  		for (int i = 0; i < theReturn.length; i++)
  		{
  			theReturn[i] = getClass(strings[i]);
  		}
  		return theReturn;
  	}
  	public Method[] getMethods(Class c)
  	{
  		return c.getMethods();
  	}
  	public String[] getMethodIdentifiersWithoutDeclaringClass(Class c)
  	{
  		Method[] methods = getMethods(c);
  		String[] theReturn = new String[methods.length];
  		for (int i = 0; i < theReturn.length; i++)
  		{
  			theReturn[i] = getMethodIdentifierWithoutDeclaringClass(methods[i]);
  		}
  		return theReturn;
  	}
  	public String[] getMethodIdentifiers(Class c)
  	{
  		Method[] methods = getMethods(c);
  		String[] theReturn = new String[methods.length];
  		for (int i = 0; i < theReturn.length; i++)
  		{
  			theReturn[i] = getMethodIdentifier(methods[i]);
  		}
  		return theReturn;
  	}
  	/**
  	* Gets only the method that is named "name" in class objectClass and takes in no arguments (parameters)
  	* @throws NoSuchMethodException if no mathing method is found.
  	**/
  	public Method getMethodWithNameAndNoParameters(Class objectClass, String name) throws NoSuchMethodException
  	{
  		Method[] allMethods = objectClass.getMethods();
  		for (int i = 0; i < allMethods.length; i++)
  		{
  			Method methodToCheck = allMethods[i];
  			if (methodToCheck.getName().equals(name))
  			{
  				if (methodToCheck.getParameterTypes().length == 0)
  				{
  					return methodToCheck;
  				}
  			}
  		}
  		throw new NoSuchMethodException("Method " + name + "() not found in " + objectClass.getName());
  	}
  	/**
  	* Gets only the method that is named "name" in class objectClass and takes in one parameter of the type parameterType
  	* @throws NoSuchMethodException if no mathing method is found.
  	**/
  	public Method getMethodWithNameAndOneParameter(Class objectClass, String name,Class parameterType) throws NoSuchMethodException
  	{
  		Method[] allMethods = objectClass.getMethods();
  