Hello Paul (and all)
I tried to create an enumeration using your template below. However,
when I ran Java2WSDL, I got the following error:
...
[axis-java2wsdl] - The class com.nci.slt.epi.admin.Enumeration does not
contain a default constructor, which is a requirement for a bean class.
The class cannot be converted into an xml schema type. An xml schema
anyType will be used to define this class in the wsdl file.
...
I was under the impression that if I followed your template, that I
wouldn't need a public default constructor. Am I mistaken? Is there
something I'm missing?
Here is my implementation of the enumeration test code:
package com.nci.slt.epi.admin;
import java.util.HashMap;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
public class Enumeration {
public static final int _ONE = 1;
public static final Enumeration ONE = new Enumeration( _ONE );
public static final int _TWO = 1;
public static final Enumeration TWO = new Enumeration( _ONE );
public static final int _THREE = 1;
public static final Enumeration THREE = new Enumeration( _ONE );
private static HashMap ALL = new HashMap();
static {
ALL.put( new Integer( _ONE ), ONE );
ALL.put( new Integer( _TWO ), TWO );
ALL.put( new Integer( _THREE ), THREE );
}
private int value;
protected Enumeration( int type ) {
value = type;
}
public int getType() {
return value;
}
public static Enumeration fromValue( int value ) {
return (Enumeration) ALL.get( new Integer( value ) );
}
public static Enumeration fromString( String valueStr ) {
try {
int value = Integer.parseInt( valueStr );
return fromValue( value );
} catch ( NumberFormatException e ) {
throw new IllegalArgumentException();
}
}
public String toString() {
return new ToStringBuilder( this )
.append( "type", this.getType() )
.toString();
}
public boolean equals( Object object ) {
if ( object == this ) {
return true;
}
if ( !(object instanceof Enumeration) ) {
return false;
}
Enumeration rhs = (Enumeration) object;
return new EqualsBuilder()
.appendSuper( super.equals( object ) )
.append( this.value, rhs.value )
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder( -609718375, -2117186511 )
.appendSuper( super.hashCode() )
.append( this.value )
.toHashCode();
}
}
> -----Original Message-----
> From: Bouche Paul [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 28, 2005 12:41 PM
> To: [email protected]
> Subject: RE: Using axis ant task with typed enums
>
> Or you can read in the jax-rpc spec 1.1 on how to write the
> java 1.4 enums in such a way that the axis engine will
> generate an enum that anne gave an example for...
>
> mainly the following:
> //Java
> public class <enumeration_name> {
> // ...
> // Constructor
> protected <enumeration_name>(<base_type> value) { ... }
> // One for each label in the enumeration
> public static final <base_type> _<label> = <value>;
> public static final <enumeration_name> <label> =
> new <enumeration_name>(_<label>);
> // Gets the value for a enumerated value
> public <base_type> getValue() {...}
> // Gets enumeration with a specific value
> // Required to throw java.lang.IllegalArgumentException if
> // any invalid value is specified
> public static <enumeration_name> fromValue(<base_type> value) {
> ... }
> // Gets enumeration from a String
> // Required to throw java.lang.IllegalArgumentException if
> // any invalid value is specified
> public static <enumeration_name> fromString(String value){ ... }
> // Returns String representation of the enumerated value
> public String toString() { ... }
> public boolean equals(Object obj) { ... }
> public int hashCode() { ... }
> }
>
> > -----Original Message-----
> > From: Anne Thomas Manes [mailto:[EMAIL PROTECTED]
> > Sent: Montag, 28. Februar 2005 16:41
> > To: [email protected]
> > Subject: Re: Using axis ant task with typed enums
> >
> >
> > Ulrich,
> >
> > First of all, WSDL does not contain any "class" descriptions. WSDL
> > contains element and type descriptions -- specified using
> XML Schema.
> > If you read through the archives, you will see frequent
> > recommendations to take a "WSDL first" or "Schema first" approach to
> > web services rather than a "Java first" approach.
> >
> > Here is an example of a definition of simple type that is an
> > enumeration of string values:
> >
> > <xs:simpleType name="MyEnum">
> > <xs:restriction base="xs:string">
> > <xs:enumeration value="value1"/>
> > <xs:enumeration value="value2"/>
> > </xs:restriction>
> > </xs:simpleType>
> >
> > Anne
> >
> >
> > On Sun, 27 Feb 2005 23:20:30 +0100, Ulrich Ackermann
> > <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > in the meantime I came to the conclusion, that my question
> > has no solution that could satisfy me. I fear that there is
> > no way to create a WSDL file containing a class description,
> > where the class contains just public static members (or does
> > the WSDL spec offer a way to express such things?).
> > >
> > > Could anyone confirm my assumption? Is there an alternative
> > way to restrict the value of a method parameter to a set of
> > predefined String values?
> > >
> > > Regards,
> > > Ulrich
> > >
> > > [email protected] schrieb am 27.02.05 00:08:00:
> > >
> > > Hi,
> > >
> > > I have a problem using something like typed enums in the
> > signature of my webservice methods (don't know if 'typed
> > enums' is the right term).
> > >
> > > E.g.:
> > > public class MyEnum {
> > > private String attribute = null;
> > >
> > > public static MyEnum VALUE_1 = new MyEnum("value1");
> > > // other static values go here
> > >
> > > private MyEnum(String attribute) {
> > > this.attribute = attribute;
> > > }
> > >
> > > // other methods like toString() go here
> > > }
> > >
> > > Now, if I have a method like this in my interface...
> > > public void myMethod(String someParam, MyEnum otherParam);
> > >
> > > ... and run the axis-java2wsdl ant task, the MyEnum class
> > looks quit different than before: axis-java2wsdl added some
> > attributes and implemented the equals and hashcode methods
> > (which is quite ok I guesss...) and removed everything I
> > typed in before in the MyEnum class (which is not ok - at
> > least for me).
> > > But maybe this has a reason, and as I'm quite new to
> > webservices this is a feature and not a flaw.
> > > Is there a way to keep the intention of the MyEnum class
> > and let the axis ant task generate what I intended?
> > >
> > > I use the ant task in this way:
> > > <axis-java2wsdl
> > >
> > output="${project.webservice.wsdl.dir}/${project.webservice.ws
> > dl.filename}"
> > >
> > location="http://${project.webservice.host}:${project.webservi
> > ce.port}/axis/services/${project.webservice.service.namespace}"
> > > namespace="${project.webservice.service.name}"
> > >
> > classname="${project.webservice.endpoint.package.structure}">
> > > <classpath>
> > > <path refid="axis.lib.path" ></path>
> > > </classpath>
> > > <mapping namespace="service" package="service"/>
> > > </axis-java2wsdl>
> > >
> > > Regards,
> > > Ulrich
> > >
> > > ______________________________________________________________
> > > Verschicken Sie romantische, coole und witzige Bilder per SMS!
> > > Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
> > >
> > > ______________________________________________________________
> > > Verschicken Sie romantische, coole und witzige Bilder per SMS!
> > > Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
> > >
> > >
> >
> > .
> >
>
> .
>