FileDocCategorySizeDatePackage
ConstructorTarget.javaAPI DocApache Axis 1.43240Sat Apr 22 18:57:28 BST 2006org.apache.axis.encoding

ConstructorTarget

public class ConstructorTarget extends Object implements Target
Used when the class need a specific Constructor (not default one)
author
Florent Benoit

Fields Summary
private Constructor
constructor
Constructor to use
private Deserializer
deSerializer
Deserializer on which set value
private List
values
List of values
Constructors Summary
public ConstructorTarget(Constructor constructor, Deserializer deSerializer)

    
         
        this.deSerializer = deSerializer;
        this.constructor = constructor;
        values = new ArrayList();
    
Methods Summary
public voidset(java.lang.Object value)
Instantiate a new class with right constructor

param
value value to use on Constructor
throws
SAXException on error

        try {
            // store received value
            values.add(value);

            // got right parameter length
            if (constructor.getParameterTypes().length == values.size()) {
                // type of parameters
                Class[] classes = constructor.getParameterTypes();
                
                // args array
                Object[] args = new Object[constructor.getParameterTypes().length];
                
                // Get arg for the type of the class
                for (int c = 0; c < classes.length; c++) {
                    boolean found = false;
                    int i = 0;
                    while (!found && i < values.size()) {
                         // got right class arg
                        if (values.get(i).getClass().getName().toLowerCase().indexOf(classes[c].getName().toLowerCase()) != -1) {
                            found = true;
                            args[c] = values.get(i);
                        }
                        i++;

                    }
                    // no suitable object for class required
                    if (!found) {
                        throw new SAXException(Messages.getMessage("cannotFindObjectForClass00", classes[c].toString()));
                    }
                }
                
                // then build object
                Object o = constructor.newInstance(args);
            	deSerializer.setValue(o);
            }
        } catch (Exception e) {
            throw new SAXException(e);
        }