题
我使用的轴线型的样本服务.什么我现在所做的是试图了解其限制的自动化的户代码生成。
现在对于某些服务器方代码:
这是骨架的样品网服务:
public class TestWebService {
public AbstractAttribute[] testCall( AbstractAttribute someAttribute ) {
....
和我的数据类别:公共抽象的类AbstractAttribute{ 串名称;
/*get/set for name*/
public abstract T getValue();
public abstract void setValue(T value);
}
public class IntAttribute extends AbstractAttribute<Integer> {
Integer value;
public Integer getValue(){ return value; }
public void setValue(Integer value){ this.value = value; }
}
public class StringAttribute extends AbstractAttribute<String> {
String value;
/* ok, you got the point, get/set for value field */
}
日食的工具,用于Axis2是相当快乐的生成wsdl从这些来源,包括模式的特性类,这是:
<xs:complexType name="AbstractAttribute">
<xs:sequence>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="value" nillable="true" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="IntAttribute">
<xs:complexContent>
<xs:extension base="xsd:AbstractAttribute">
<xs:sequence>
<xs:element minOccurs="0" name="value" nillable="true" type="xs:int"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="StringAttribute">
<xs:complexContent>
<xs:extension base="xsd:AbstractAttribute">
<xs:sequence>
<xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
现在,如果看到一些奇怪的东西在这里,AbstractAttribute没有**abstract="真正的"**属性,并确定一个anyType值元,其中获得重写在IntAttribute和StirngAttribute.我甚至不知道如果这是一个法律架构(我不认为它是合法的,通过的方式)。
更重要的是,如果我试图产生一个客户从这wsdl(总是使用蚀工具)所产生的来源不会编制的,因为AbstractAttribute定义
Object localValue;
领域和Int/String属性的定义
int localValue;
和
String localValue;
我试图以"适应"的来源(无许多人的希望,很明显),并将结果,该服务器的尝试的一个实例AbstractAttribute实例(投掷一InstantiationException).
所以我的问题是:有一种方法模型类似的数据模型以上,或网络服务和XML模式'一般是不是最好的工具来使用这种特殊情况下?
解决方案
解释的问题,你遇到了,这有助于思考什么样的轴需要做的时候您的服务。
轴是一个简单的java网络的应用程序...在收到请求的服务,它将映射,你一定义。如果它发现的映射,它试图创建的一个实例,必要的类定义的服务的请求。
如果你一定义的类抽象的或作为接口,然后你会得到InstantiationExceptions由于这些类型不能被创建。当轴试图创建的wsdl,它将不能够找出什么类型的投入,因此它将使用"anyType。"
来回答你的问题:你可以使用的模型的你必须上在你的代码,但你不能使用这些课程的轴。我们通常在我们的项目是:
- 定义的课程,我们需要的,因为我们将在一个典型的面向对象的应用程序
- 定义"运输"的课程,用于网络的服务。这些课程都是由简单的类型和可以很容易地创建。他们只是用于交换网络的业务信息。我们使用这些课程的轴。
- 找到某种方式对于这两种类型的课程很容易地分享/交流信息。你可以接口,分享这两个(但轴不知道有关),或者甚至使用BeanUtils.copyProperites保持两个不同的目的同步。
希望回答你的问题。