Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to seek design suggestion on a schema based request object for a CXF endpoint. I've created a CXF SOAP endpoint which takes the following object as an input. The request object will have required fields, non-mandatory fields as well as user-defined fields.Required fields are enforced through the schema. Tag object is defined as a placeholder for user defined properties. The eventual goal of the endpoint is transform the values into Tag object and send them for processing.

public class TestServiceRequest{

  @XmlElement(required = true)
    protected String url;
    @XmlElement(required = true)
    protected String title;
    protected String source;
    protected List tags;

    public void setUrl(String value) {
        this.url = value;
    public void setTitle(String title) {
        this.title = title;
    public void setSource(String value) {
        this.text = value;
    public List getTags() {
        if (tags == null) {
            tags = new ArrayList();
        return this.tags;

Tag object :

public class Tag{
   public String name;
   public String value;
   public String weight;

Schema snippet:

<xsd:complexType name="tag">
            <xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="1" />
            <xsd:element name="value" type="xsd:string" minOccurs="1" maxOccurs="1" />
            <xsd:element name="weight" type="xsd:string" minOccurs="0" maxOccurs="1" />
            <xsd:element name="attribute" type="tns:attribute" minOccurs="0" maxOccurs="unbounded"/>

    <xsd:element name="testServiceRequest">
                <xsd:extension base="br:BaseRequest">
                        <xsd:element name="url" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="title" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="text" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="source" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="tags" type="tns:tag" minOccurs="0" maxOccurs="unbounded"/>

As you can see, Tag object has an additional field called weight, which is the crux of the issue. Weight is an optional field for each property defined as required (url, title) and optional fields (source) as well. The weights are static value defined for these properties.

The reason why I inclined towards this model is firstly, property field names (url, title, etc.) conform to a standard and cannot deviate. Having defined them in a schema and generating the request based on it, allows me to impose that. The end-user is free from using the exact field name and just use the setter instead, thus reducing the scope of error. Moreover, schema validation can be integrated with cxf endpoint easily, hence maintenance is easy. Any change is restricted to the schema.

Issue with this model is the service end-point explicitly needs to add the weight for the fields while converting them to Tag objects. If the client ever decides to send their own weight values specific to properties, then this model will break.

The other option is to use a simplified request object instead of a schema generated one.

public class Tag{
   public String name;
   public String value;
   public String weight;

The pros are that this model is simple and flexible and allows user to define weights and other metadata if required.

Issue with this, I need an explicit validation code to make sure the required fields are provided and the field names are correct. That means, every time a new field is added, I need to touch the code to add it as part of the validation.

I'm in a dilemma to decide which is the best possible way to design this. Maybe,there's a better way to do this instead.

Any pointer will be highly appreciated.


share|improve this question

migrated from Aug 7 '12 at 12:46

This question came from our site for professional and enthusiast programmers.

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.