1 18 package org.apache.beehive.controls.system.webservice.utils; 19 20 import java.lang.reflect.Field ; 21 22 import javax.xml.rpc.holders.Holder ; 23 24 public class HolderUtils { 25 26 public static void stuffHolderValue(Holder holder, Object value) 27 throws NoSuchFieldException , IllegalAccessException { 28 29 Field valueField = holder.getClass().getField("value"); 30 Object curValueInHolder = valueField.get(holder); 31 Class classOfValueFieldInHolder; 32 if (curValueInHolder == null) { 33 classOfValueFieldInHolder = valueField.getType(); 34 } else { 35 classOfValueFieldInHolder = curValueInHolder.getClass(); 36 } 37 38 if (null == value) { 39 setFieldInObject(valueField, holder, null); 40 return; 41 } 42 if (classOfValueFieldInHolder.isAssignableFrom(value.getClass())) { 43 setFieldInObject(valueField, holder, value); 44 45 } else { 47 try { 48 Object convertedValue = org.apache.axis.utils.JavaUtils 49 .convert(value, classOfValueFieldInHolder); 50 setFieldInObject(valueField, holder, convertedValue); 51 } catch (IllegalArgumentException e) { 52 53 e.printStackTrace(); 54 } catch (IllegalAccessException e) { 55 56 e.printStackTrace(); 57 } 58 } 59 60 } 61 62 private static void setFieldInObject(Field valueField, Object destObject, 63 Object value) throws IllegalArgumentException , 64 IllegalAccessException { 65 if (valueField.getType().isPrimitive()) { 66 if (value == null) 67 ; else 69 valueField.set(destObject, value); 70 } else { 71 valueField.set(destObject, value); 72 } 73 } 74 75 } 76 | Popular Tags |