0

I have a class called ObjectClass that was auto-generated by JibX from a .xsd file. To prevent class name issues this class has been relegated to its own package, such as

com.CompanyName.ProductName.SDK.Device.GetCommandsResponse.ObjectClass

This class binds and unbinds as intended.

I would like to create an empty class that extends the above class, and I am wondering will the new class bind and unbind correctly using the original ObjectClass binding? Or must I attempt to make a unique binding for this new extension?

The new class looks similar to this

public class deviceGetCommandsResponse extends 
com.CompanyName.ProductName.SDK.Device.GetCommandsResponse.ObjectClass
{
   /// This is empty
}

This intention of this is to make casting these objects easier/less hassle for third party developers by providing unique names.

So instead of

(com.CompanyName.ProductName.SDK.Device.GetCommandsResponse.ObjectClass) SomeReturnFromAMethod

they can use

(deviceGetCommandsResponse) SomeReturnFromAMethod;

and have all the same functionality.

In broader terms how would I go about making an Adapter Pattern for JibX generated classes?

JME
  • 2,293
  • 9
  • 36
  • 56

1 Answers1

0

The answer to your question is yes, JiBX will work fine in an extended class.

Before you do this, I would consider these options:

First, the default package name is the namespace URL location and the default class name is the top-level element which is an excellent choice for most bindings.

For example, If my schema definition's is:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.jibx.org/sampleschema/person" elementFormDefault="qualified" targetNamespace="http://www.jibx.org/sampleschema/person">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="lastName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

The generated class would be:

package org.jibx.sampleschema.person;
public class Person
{
    private String firstName;
    private String lastName;
    ...

Your code would read:

Person person = new Person();
person.setFirstName("Don");

This is pretty logical and pretty clean. It is very useful to have a globally unique class name, especially if you are using a public schema definition. Releasing your bindings as open source will save some time for others using the same schema.

If the default is not acceptable, changing a package and/or class name is pretty easy by setting the JiBX configuration.

I hope this helps!

Don Corley
JiBX Contributor

Don Corley
  • 496
  • 2
  • 7