0

I sometimes need to send a list of primitives over a web service, for example as the parameters to run a stored procedure. In Java basically I have List. This doesn't work with CXF. I ended up doing List where SimpleDataItem is the attached code. Is this a good idea, or are there better aproaches?

I'm basically executing a function that I would like to look like this:

ResultSet executeStoredProc(String procName, Object... args) throws SQLException;

Right now SimpleDataItem looks like this:

public class SimpleDataItem {
    private String s;
    private Long l;
    private Integer i;
    private BigDecimal d;
    private Boolean b;
    private Long t;
    private byte[] ba;



    public SimpleDataItem() {

    }

    public SimpleDataItem(Object o) {
        doSetObject(o);
    }

    public void doSetObject(Object o) {
        if (o==null) {
            return;
        }
        if (o instanceof String ) {
            s=(String)o;
            return;
        }
        if (o instanceof Long ) {
            l=(Long)o;
            return;
        }
        if (o instanceof Integer ) {
            i=(Integer)o;
            return;
        }
        if (o instanceof BigDecimal) {
            d=(BigDecimal)o;
            return ;
        }

        if (o instanceof Boolean) {
            b=(Boolean)o;
            return ;
        }
        if (o instanceof Timestamp) {
            t=((Timestamp)o).getTime();
            return;
        }
        if (o instanceof byte[]) {
            ba=(byte[])o;
        }

    }

    public Object doGetObject() {
        if (s!=null) {
            return s;
        }
        if (l!=null) {
            return l;
        }
        if (i!=null) {
            return i;
        }
        if (d!=null) {
            return d;
        }
        if (b!=null) {
            return b;
        }
        if (t!=null) {
            return new Timestamp(t);
        }
        if (ba!=null) {
            return ba;
        }
        return null;
    }

    /**
     * @return the ba
     */
    public byte[] getBa() {
        return ba;
    }

    /**
     * @param ba the ba to set
     */
    public void setBa(byte[] ba) {
        this.ba = ba;
    }

    public String getS() {
        return s;
    }

    public void setS(String s) {
        this.s = s;
    }

    public Long getL() {
        return l;
    }

    public void setL(Long l) {
        this.l = l;
    }

    public Integer getI() {
        return i;
    }

    public void setI(Integer i) {
        this.i = i;
    }

    public BigDecimal getD() {
        return d;
    }

    public void setD(BigDecimal d) {
        this.d = d;
    }

    public Boolean getB() {
        return b;
    }

    public void setB(Boolean b) {
        this.b = b;
    }

    public Long getT() {
        return t;
    }

    public void setT(Long t) {
        this.t = t;
    }

    public String toString() {
        Object o=doGetObject();
        if (o!=null) {
            return o.toString();
        }
        return null;
    }   
}

Is this a good idea? Are there better aproaches?

Andres Olarte
  • 4,380
  • 3
  • 24
  • 45
  • possible duplicate of [JAXB - Unmarshalling polymorphic objects](http://stackoverflow.com/questions/5491982/jaxb-unmarshalling-polymorphic-objects) – bmargulies Mar 11 '12 at 00:30
  • @AndresOlarte: Perhaps you'd better start from what you have as input and what is your target. The community will advise you the solution. – dma_k Mar 11 '12 at 18:33

1 Answers1

1

This isn't a CXF problem, it's a web service problem. You are trying to send a polymorphic data structure. So you need a schema that uses an XML Schema union of the possible types.

See JAXB - Unmarshalling polymorphic objects.

Community
  • 1
  • 1
bmargulies
  • 97,814
  • 39
  • 186
  • 310