openamf/src/java/org/openamf/invoker WebServiceInvoker.java,1.8,1.9 JavaServiceInvoker.java,1.9,1.10

[email protected]
Newsgroups gmane.comp.java.openamf.cvs
Message-ID <[email protected]>
Update of /cvsroot/openamf/openamf/src/java/org/openamf/invoker
In directory sc8-pr-cvs1:/tmp/cvs-serv5698/src/java/org/openamf/invoker

Modified Files:
	WebServiceInvoker.java JavaServiceInvoker.java 
Log Message:
initial ASTranslator integration

Index: WebServiceInvoker.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/invoker/WebServiceInvoker.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** WebServiceInvoker.java	1 May 2003 01:01:58 -0000	1.8
--- WebServiceInvoker.java	1 May 2003 04:01:45 -0000	1.9
***************
*** 2,15 ****
--- 2,20 ----
  
  import java.beans.BeanInfo;
+ import java.beans.IntrospectionException;
  import java.beans.Introspector;
  import java.beans.MethodDescriptor;
+ import java.beans.PropertyDescriptor;
  import java.io.File;
  import java.lang.reflect.Constructor;
+ import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.net.URL;
  import java.net.URLClassLoader;
+ import java.util.HashMap;
  import java.util.List;
  
  import org.apache.axis.client.Service;
+ import org.apache.commons.beanutils.PropertyUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
***************
*** 228,231 ****
--- 233,286 ----
  		}
  		return r;
+ 	}
+ 	protected static Object convertHashMapToBean(HashMap data, Class beanClass)
+ 		throws
+ 			InstantiationException,
+ 			IntrospectionException,
+ 			IllegalArgumentException,
+ 			IllegalAccessException,
+ 			InvocationTargetException {
+ 
+ 		Object bean = beanClass.newInstance();
+ 
+ 		PropertyDescriptor[] properties =
+ 			PropertyUtils.getPropertyDescriptors(beanClass);
+ 		for (int i = 0; i < properties.length; i++) {
+ 			if (!properties[i].getName().equals("class")) {
+ 				String propertyName = properties[i].getName();
+ 				log.debug("propertyName: " + propertyName);
+ 				Method writeMethod = properties[i].getWriteMethod();
+ 				log.debug("writeMethod: " + writeMethod);
+ 				if (writeMethod != null) {
+ 					Class[] parameterTypes = writeMethod.getParameterTypes();
+ 					if (parameterTypes.length == 1) {
+ 						Object value = data.get(propertyName);
+ 						log.debug(
+ 							"propertyName = "
+ 								+ propertyName
+ 								+ ", value = "
+ 								+ value);
+ 						Class parameterType = parameterTypes[0];
+ 						if (!parameterType.isInstance(value)) {
+ 							//try to convert types
+ 							log.debug("types don't match, try to convert");
+ 							log.debug("parameterType = " + parameterType);
+ 							if (parameterType.equals(Integer.TYPE)
+ 								&& value instanceof Double) {
+ 								log.debug("Converting Double to Integer");
+ 								value =
+ 									new Integer(((Double) value).intValue());
+ 							}
+ 						}
+ 						writeMethod.invoke(bean, new Object[] { value });
+ 					} else {
+ 						throw new IllegalArgumentException("write method has more than one parameter");
+ 					}
+ 				}
+ 
+ 			}
+ 		}
+ 
+ 		return bean;
  	}
  	public String removeChar(String s, char c) {

Index: JavaServiceInvoker.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/invoker/JavaServiceInvoker.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** JavaServiceInvoker.java	1 May 2003 00:59:23 -0000	1.9
--- JavaServiceInvoker.java	1 May 2003 04:01:46 -0000	1.10
***************
*** 2,18 ****
  
  import java.beans.IntrospectionException;
- import java.beans.PropertyDescriptor;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
- import java.util.HashMap;
  import java.util.List;
  
  import javax.servlet.ServletContext;
  
- import org.apache.commons.beanutils.PropertyUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.openamf.ServiceRequest;
  
  public class JavaServiceInvoker extends ServiceInvoker {
  
--- 2,19 ----
  
  import java.beans.IntrospectionException;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.util.List;
  
  import javax.servlet.ServletContext;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
+ import org.openamf.ASObject;
  import org.openamf.ServiceRequest;
  
+ import com.carbonfive.flash.decoder.ActionScriptDecoder;
+ import com.carbonfive.flash.decoder.DecoderFactory;
+ 
  public class JavaServiceInvoker extends ServiceInvoker {
  
***************
*** 62,66 ****
  	}
  
! 	protected static Object invokeServiceMethod(
  		Object service,
  		Class serviceClass,
--- 63,67 ----
  	}
  
! 	protected Object invokeServiceMethod(
  		Object service,
  		Class serviceClass,
***************
*** 95,99 ****
  	}
  
! 	private static Method getServiceMethod(
  		Class serviceClass,
  		String methodName,
--- 96,100 ----
  	}
  
! 	private Method getServiceMethod(
  		Class serviceClass,
  		String methodName,
***************
*** 112,116 ****
  	}
  
! 	private static Object invokeServiceMethodAdvanced(
  		Object service,
  		Class serviceClass,
--- 113,117 ----
  	}
  
! 	private Object invokeServiceMethodAdvanced(
  		Object service,
  		Class serviceClass,
***************
*** 142,218 ****
  			throw new NoSuchMethodException();
  		} else {
  			Class[] parameterTypes = serviceMethod.getParameterTypes();
  			for (int i = 0; i < parameterTypes.length; i++) {
  				Class parameterType = parameterTypes[i];
  				Object parameter = parameters.get(i);
- 				if (parameterType.isInstance(parameter)) {
- 					// don't do anything
- 				} else if (parameter instanceof HashMap) {
- 					Object bean =
- 						convertHashMapToBean(
- 							(HashMap) parameter,
- 							parameterType);
- 					parameters.set(i, bean);
- 				} else {
- 					//TODO more conversion here
- 					//invoke is going to fail
- 					throw new NoSuchMethodException();
- 				}
- 			}
- 			serviceMethod.invoke(service, parameters.toArray());
- 		}
- 
- 		return serviceResult;
- 	}
  
! 	protected static Object convertHashMapToBean(HashMap data, Class beanClass)
! 		throws
! 			InstantiationException,
! 			IntrospectionException,
! 			IllegalArgumentException,
! 			IllegalAccessException,
! 			InvocationTargetException {
! 
! 		Object bean = beanClass.newInstance();
! 
! 		PropertyDescriptor[] properties =
! 			PropertyUtils.getPropertyDescriptors(beanClass);
! 		for (int i = 0; i < properties.length; i++) {
! 			if (!properties[i].getName().equals("class")) {
! 				String propertyName = properties[i].getName();
! 				log.debug("propertyName: " + propertyName);
! 				Method writeMethod = properties[i].getWriteMethod();
! 				log.debug("writeMethod: " + writeMethod);
! 				if (writeMethod != null) {
! 					Class[] parameterTypes = writeMethod.getParameterTypes();
! 					if (parameterTypes.length == 1) {
! 						Object value = data.get(propertyName);
! 						log.debug(
! 							"propertyName = "
! 								+ propertyName
! 								+ ", value = "
! 								+ value);
! 						Class parameterType = parameterTypes[0];
! 						if (!parameterType.isInstance(value)) {
! 							//try to convert types
! 							log.debug("types don't match, try to convert");
! 							log.debug("parameterType = " + parameterType);
! 							if (parameterType.equals(Integer.TYPE)
! 								&& value instanceof Double) {
! 								log.debug("Converting Double to Integer");
! 								value =
! 									new Integer(((Double) value).intValue());
! 							}
! 						}
! 						writeMethod.invoke(bean, new Object[] { value });
! 					} else {
! 						throw new IllegalArgumentException("write method has more than one parameter");
! 					}
  				}
  
  			}
  		}
  
! 		return bean;
  	}
  
--- 143,167 ----
  			throw new NoSuchMethodException();
  		} else {
+ 			DecoderFactory decoderFactory = DecoderFactory.getInstance();
  			Class[] parameterTypes = serviceMethod.getParameterTypes();
  			for (int i = 0; i < parameterTypes.length; i++) {
  				Class parameterType = parameterTypes[i];
  				Object parameter = parameters.get(i);
  
! 				if (parameter instanceof ASObject
! 					&& ((ASObject) parameter).getType() == null) {
! 					((ASObject) parameter).setType(parameterType.getName());
  				}
+ 				ActionScriptDecoder decoder =
+ 					decoderFactory.getDecoder(parameter, parameterType);
+ 
+ 				Object value = decoder.decodeObject(parameter, parameterType);
+ 				parameters.set(i, value);
  
  			}
+ 			serviceMethod.invoke(service, parameters.toArray());
  		}
  
! 		return serviceResult;
  	}
  
***************
*** 225,230 ****
  				request.getServiceName());
  			supports = true;
! 		} catch (Exception e) {}
! 		
  		return supports;
  	}
--- 174,180 ----
  				request.getServiceName());
  			supports = true;
! 		} catch (Exception e) {
! 		}
! 
  		return supports;
  	}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.