2012-03-11 7 views
0

たとえば、ストアドプロシージャを実行するためのパラメータなど、Webサービスを介してプリミティブのリストを送信する必要があることがあります。 Javaでは、基本的に私はリストを持っています。これはCXFでは機能しません。私は、SimpleDataItemが添付されたコードであるリストをやってしまった。これはいいアイデアですか、それとも良いですか?CXFのラッピングプリミティブ

私は基本的に、私は次のようになりたい関数を実行しています:

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

今SimpleDataItemは、次のようになります。

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; 
    } 
} 

は、これは良いアイデアですか?より良いaproachesはありますか?

+0

[JAXB - 非整列多型オブジェクト]の複製が可能です。(http://stackoverflow.com/questions/5491982/jaxb-unmarshalling-polymorphic-objects) – bmargulies

+0

@AndresOlarte:おそらく、入力として持っているものから始める方がよいでしょうあなたの目標は何ですか?コミュニティが解決策をあなたにアドバイスします。 –

答えて

1

これはCXFの問題ではなく、Webサービスの問題です。多相データ構造を送信しようとしています。したがって、可能な型のXMLスキーマ結合を使用するスキーマが必要です。

JAXB - Unmarshalling polymorphic objectsを参照してください。

+0

これは私のアプローチがうまくいかない理由の説明であるようです。ありがとう –