2012-05-23 68 views
0

我在Java.Here使用Web服務是我的問題:返回Web服務的對象多kinf在Java中

public Object execute(int servicecode) 
{ 
    switch (servicecode) 
    { 
     case 1: 
      return OBJECT_1; 
     case 2: 
      return OBJECT_2; 
     case 3: 
      return OBJECT_3; 
    } 
} 
  • 我的函數返回OBJECT_1,OBJECT_2,OBJECT_3。我希望客戶瞭解:
    • 情況1個對象= OBJECT_1
    • 情況下2對象= OBJECT_2
    • 情況下3對象= OBJECT_3

我怎樣才能做一個Web服務?我試圖在Web Service中使用繼承,但我無法獲得OBJECT_1,OBJECT_2,OBJECT_3的屬性。

+0

你返回不同類型的對象?讓我們說在情況1你返回一個Person對象,並在案例2 House對象?或者它總是返回相同類型的對象? – MaVRoSCy

回答

0

是,如果OBJECT_1,OBJECT_2,OBJECT_3有不同的類型,然後..你可以不喜歡它..


public class Object { 
// here we are creating a class who has all objects you want to return, 
    // this is called wrapper class 
private Object_1 object_1; 
private Object_2 object_1; 
private Object_3 object_1; 
public Object_1 getObject_1() { 
    return object_1; 
} 
public void setObject_1(Object_1 object_1) { 
    this.object_1 = object_1; 
} 
public Object_2 getObject_1() { 
    return object_1; 
} 
public void setObject_1(Object_2 object_1) { 
    this.object_1 = object_1; 
} 
public Object_3 getObject_1() { 
    return object_1; 
} 
public void setObject_1(Object_3 object_1) { 
    this.object_1 = object_1; 
} 

}

public class Test{ 
public Object execute(int servicecode) 
{ 
    Object object = new Object(); 
    switch (servicecode) 
    { 
     case 1: 
      return object.setObject_1(object_1); 
     case 2: 
      return object.setObject_2(object_2);; 
     case 3: 
      return object.setObject_3(object_3);; 
    } 
} 

}