1 16 package org.apache.axis.encoding; 17 18 import java.lang.reflect.Constructor ; 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.xml.sax.SAXException ; 23 import org.apache.axis.i18n.Messages; 24 25 26 30 public class ConstructorTarget implements Target { 31 32 35 private Constructor constructor = null; 36 37 40 private Deserializer deSerializer = null; 41 42 43 46 private List values = null; 47 48 public ConstructorTarget(Constructor constructor, Deserializer deSerializer) { 49 this.deSerializer = deSerializer; 50 this.constructor = constructor; 51 values = new ArrayList (); 52 } 53 54 55 60 public void set(Object value) throws SAXException { 61 try { 62 values.add(value); 64 65 if (constructor.getParameterTypes().length == values.size()) { 67 Class [] classes = constructor.getParameterTypes(); 69 70 Object [] args = new Object [constructor.getParameterTypes().length]; 72 73 for (int c = 0; c < classes.length; c++) { 75 boolean found = false; 76 int i = 0; 77 while (!found && i < values.size()) { 78 if (values.get(i).getClass().getName().toLowerCase().indexOf(classes[c].getName().toLowerCase()) != -1) { 80 found = true; 81 args[c] = values.get(i); 82 } 83 i++; 84 85 } 86 if (!found) { 88 throw new SAXException (Messages.getMessage("cannotFindObjectForClass00", classes[c].toString())); 89 } 90 } 91 92 Object o = constructor.newInstance(args); 94 deSerializer.setValue(o); 95 } 96 } catch (Exception e) { 97 throw new SAXException (e); 98 } 99 100 } 101 102 } 103 | Popular Tags |