Skip to main content

Preventing Interface (annotation) processing

2 replies [Last post]
amarkel
Offline
Joined: 2004-05-13

I am trying to generate a schema from a set of classes
and interfaces that are as follows:

package foo;

public interface Bar
{
public String getName();
}

package foo;

import java.util.Collection;

public interface Baz
{
public Collection getBar();
}

package foo.impl;

@XmlAccessorType( AccessType.PROPERTY )
@XmlType
public class Bar implements foo.Bar
{
protected String name;

public String getName() { return name; }
public void setName( String theName ) { name = theName ; }

}

package foo.impl;

@XmlAccessorType(AccessType.PROPERTY)
@XmlRootElement( name = "Baz" )
public class Baz extends foo.Baz
{
Collection bar;

public Collection getBar() { return bar; }
public void setBar( Collection theBar )
{ bar = theBar; }
}

As I run 'schemagen', it complains that the interface
class does not have a no-args constructor.

Why does it try to do that ?

The reason I want to do that is that I want to allow
developers to opt to create the foo.Bar, and foo.Baz
implementations, without going the XML binding route
if they so desire.

Here are some errors that are also thrown.

[schemagen] Generating schema from 7 source files
[schemagen] error: foo.Bar does not have a no-arg default constructor
[schemagen] this problem is related to the following location:
[schemagen] at foo.Bar (Unknown Source)
[schemagen] at foo.impl.Baz.getBar(Bar.java:13)
[schemagen] at foo.impl.Baz(Baz.java:20)
[schemagen] error: Two classes have the same XML type name "bar". Use @XmlType.name and @XmlType.namespace to assign different names to them.
[schemagen] this problem is related to the following location:
[schemagen] at foo.Bar (Unknown Source)
[schemagen] at foo.impl.Baz.getBar(Bar.java:20)

Am I doing something wrong ?

How do I manage getting successful processing of the schema ?

Thanks,

Arieh

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09

Because
[code]
public Collection getBar() { return bar; }
[/code]
points JAXB to "foo.Bar", which is an interface and therefore cannot be bound.

you can use the following annotation to tell JAXB that this collection actually only contains Bar impl class.
[code]
@XmlElement(type=foo.impl.Bar)
public Collection getBar() { return bar; }
[/code]

amarkel
Offline
Joined: 2004-05-13

Thanks,

that helped.

Arieh