Copyright © 2013 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C liability, trademark and document use rules apply.
This document defines the Java language binding for Web IDL, the interface definition language for the Web platform.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
Please send comments about this document to public-script-coord@w3.org (archived).
This document originally existed as a section in the Web IDL specification. [WEBIDL] It was split out into this Working Group Note due to the prospect of it impeding the progress of Web IDL due to having insufficient implementations and because of a general lack of interest in the Java binding.
This document is produced by the Web Applications Working Group, part of the Rich Web Clients Activity in the W3C Interaction Domain. Changes made to this document can be found in the W3C public CVS server.
Note: The Working Group reached consensus to stop work on this specification. It is being published for archival reasons and is no longer being progressed along the W3C's Recommendation Track.
Publication as a Working Group Note does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This section is informative.
This document defines a Web IDL language binding for Java 5. [WEBIDL] [JLS3]
The following typographic conventions are used in this document:
a = b + obj.f()
This is a note.
This is an example.
// This is an IDL code block.
interface Example {
attribute long something;
};
// This is a Java code block.
Document doc = element.getOwnerDocument();
Everything in this specification is normative except for diagrams, examples, notes and sections marked as being informative.
The keywords “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY” and “OPTIONAL” in this document are to be interpreted as described in Key words for use in RFCs to Indicate Requirement Levels [RFC2119].
The following conformance class is defined by this specification:
A user agent is considered to be a conforming Java implementation relative to a conforming IDL fragment if it satisfies all of the MUST-, REQUIRED- and SHALL-level criteria in this specification that apply to implementations for the Java language binding.
This section describes how definitions written with Web IDL [WEBIDL] correspond to particular constructs in Java 5 [JLS3].
Since Java has a number of reserved words in the language, some identifiers of Java constructs corresponding to IDL definitions need to be escaped to avoid conflicts. A name is Java escaped as follows:
At the time of publication, the list of Java reserved words is the following:
abstract
,
assert
,
boolean
,
break
,
byte
,
case
,
catch
,
char
,
class
,
const
,
continue
,
default
,
do
,
double
,
else
,
enum
,
extends
,
final
,
finally
,
float
,
for
,
goto
,
if
,
implements
,
import
,
instanceof
,
int
,
interface
,
long
,
native
,
new
,
package
,
private
,
protected
,
public
,
return
,
short
,
static
,
strictfp
,
super
,
switch
,
synchronized
,
this
,
throw
,
throws
,
transient
,
try
,
void
,
volatile
,
while
.
This section describes how types in the IDL map to types in Java.
Each sub-section below describes how values of a given IDL type are represented in Java. For each IDL type, it is described how Java values are converted to an IDL value when passed as an argument to a Java method (corresponding to an operation or attribute). Conversely, it is described how IDL values of that type are converted to Java values when being used as the value of a Java final variable (corresponding to a constant) or when returned from a Java method (corresponding to an operation, attribute or exception field).
The any IDL type corresponds to a Java java.lang.Object value.
How to convert a Java value to an IDL any value depends on the type of the Java value:
booleanValue()
method on the
java.lang.Boolean object to an IDL
boolean value.
byteValue()
method on the
java.lang.Byte object to an IDL
byte value.
shortValue()
method on the
java.lang.Short object to an IDL
short value.
intValue()
method on the
java.lang.Integer object to an IDL
long value.
longValue()
method on the
java.lang.Long object to an IDL
long long value.
floatValue()
method on the
java.lang.Float object to an IDL
float value.
doubleValue()
method on the
java.lang.Double object to an IDL
double value.
How to convert an IDL any value to a Java java.lang.Object value depends on the specific type of the IDL value:
The Java value is the result of converting the IDL value of the given type to a Java value, and then passing that value to the static method according to the following table:
IDL type | Method |
---|---|
boolean | java.lang.Boolean.valueOf(boolean) |
byte | java.lang.Byte.valueOf(byte) |
octet | java.lang.Byte.valueOf(byte) |
short | java.lang.Short.valueOf(short) |
unsigned short | java.lang.Short.valueOf(short) |
long | java.lang.Integer.valueOf(int) |
unsigned long | java.lang.Integer.valueOf(int) |
long long | java.lang.Long.valueOf(long) |
unsigned long long | java.lang.Long.valueOf(long) |
float | java.lang.Float.valueOf(float) |
unrestricted float | java.lang.Float.valueOf(float) |
double | java.lang.Double.valueOf(double) |
unrestricted double | java.lang.Double.valueOf(double) |
The only place that the void type may appear in IDL is as the return type of an operation. Methods on Java objects that implement an operation whose IDL specifies a void return type MUST be declared to have a return type of void.
IDL boolean values are represented by Java boolean values.
The result of converting a Java boolean value to an IDL value is the IDL boolean that represents the same truth value as the Java boolean.
The result of converting an IDL boolean value to a Java value is the Java boolean that represents the same truth value as the IDL boolean.
IDL byte values are represented by Java byte values.
The result of converting a Java byte value to an IDL value is the IDL byte that represents the same numeric value as the Java byte.
The result of converting an IDL byte value to a Java value is the Java byte that represents the same numeric value as the IDL byte.
IDL octet values are represented by Java byte values. Note that while the IDL octet type is unsigned, with a range of [0, 255], the Java byte type is signed, with a range of [−128, 127].
Conversion of an octet value to a byte is performed as follows:
In Java this is the same as having the octet value stored in an int and casting it to a byte.
Conversion of a byte to an octet is performed as follows:
In Java this is the same as performing a bit-wise AND of the byte value with the int constant 0xff.
IDL short values are represented by Java short values.
The result of converting a Java short value to an IDL value is the IDL short that represents the same numeric value as the Java short.
The result of converting an IDL short value to a Java value is the Java short that represents the same numeric value as the IDL short.
IDL unsigned short values are represented by Java short values. Note that while the IDL unsigned short type is unsigned, with a range of [0, 65535], the Java short type is signed, with a range of [−32768, 32767].
Conversion of an IDL unsigned short value to a Java short is performed as follows:
In Java this is the same as having the unsigned short value stored in an int and casting it to a short.
Conversion of a Java short to an IDL unsigned short value is performed as follows:
In Java this is the same as performing a bit-wise AND of the short value with the int constant 0xffff.
IDL long values are represented by Java int values.
The result of converting a Java int value to an IDL value is the IDL long that represents the same numeric value as the Java int.
The result of converting an IDL long value to a Java value is the Java int that represents the same numeric value as the IDL short.
IDL unsigned long values are represented by Java int values. Note that while the IDL unsigned long type is unsigned, with a range of [0, 4294967295], the Java int type is signed, with a range of [−2147483648, 2147483647].
Conversion of an IDL unsigned long value to a Java int is performed as follows:
In Java this is the same as having the unsigned long value stored in a Java long and casting it to an int.
Conversion of a Java int to an IDL unsigned long value is performed as follows:
In Java this is the same as performing a bit-wise AND of the int value with the long constant 0xffffffffL.
IDL long long values are represented by Java long values.
The result of converting a Java long value to an IDL value is the IDL long long that represents the same numeric value as the Java long.
The result of converting an IDL long long value to a Java value is the Java long that represents the same numeric value as the IDL long long.
IDL unsigned long long values are represented by Java long values. Note that while the IDL unsigned long long type is unsigned, with a range of [0, 18446744073709551615], the Java long type is signed, with a range of [−9223372036854775808, 9223372036854775807].
Conversion of an IDL unsigned long long value to a Java long is performed as follows:
Conversion of a Java long to an IDL unsigned long long value is performed as follows:
IDL float values are represented by Java float values.
A Java float value V is converted to an IDL float value as follows:
The result of converting an IDL float value to a Java value is the Java float that represents the same IEEE 754 single precision floating point value as the IDL float.
IDL unrestricted float values are represented by Java float values.
The result of converting a Java float value to an IDL unrestricted float value is the one that represents the same IEEE 754 single precision floating point value as the Java float.
The result of converting an IDL unrestricted float value to a Java value is the Java float that represents the same IEEE 754 single precision floating point value as the IDL unrestricted float.
IDL double values are represented by Java double values.
A Java double value V is converted to an IDL double value as follows:
The result of converting an IDL double value to a Java value is the Java double that represents the same IEEE 754 double precision floating point value as the IDL double.
IDL unrestricted double values are represented by Java double values.
The result of converting a Java double value to an IDL unrestricted double value is the one that represents the same IEEE 754 double precision floating point value as the Java double.
The result of converting an IDL unrestricted double value to a Java value is the Java double that represents the same IEEE 754 double precision floating point value as the IDL unrestricted double.
IDL DOMString values are represented by Java java.lang.String reference values.
A Java java.lang.String reference value is converted to an IDL DOMString value as follows:
The result of converting an IDL DOMString value to a Java java.lang.String value is a java.lang.String object that represents the same sequence of characters that the IDL DOMString represents.
IDL object values are represented by Java java.lang.Object reference values.
A Java java.lang.Object reference value is converted to an IDL object value as follows:
The result of converting an IDL object value to a Java value is a Java java.lang.Object value that is a reference to the same object.
IDL interface type values are represented by Java references of the corresponding Java interface type. (See section 3.4 below for how IDL interfaces have corresponding Java interfaces.)
A Java value V is converted to an IDL interface type value by running the following algorithm (where I is the interface):
Conversions from IDL interface type values to Java values are performed in the same way as that for the IDL object type.
IDL dictionary type values are represented by Java references to objects of the java.util.HashMap<java.lang.String,java.lang.Object> class. Each dictionary member that is present corresponds to an entry in the HashMap.
A Java java.util.HashMap<java.lang.String,java.lang.Object> reference value O is converted to an IDL dictionary type value by running the following algorithm (where D is the dictionary):
containsKey
method on O with javaKey as the only argument.get
method on O javaKey as the only argument.An IDL dictionary type value V is converted to a Java java.util.HashMap<java.lang.String,java.lang.Object> reference value by running the following algorithm (where D is the dictionary):
put
method on O with arguments javaKey and value.IDL enumeration type values are represented by Java java.lang.String reference values.
A Java java.lang.String reference value is converted to an IDL enumeration type value as follows (where E is the enumeration):
The result of converting an IDL enumeration type value to a Java java.lang.String value is a java.lang.String object that represents the same sequence of code units as the enumeration value.
IDL callback function type values are represented by Java references of the corresponding Java interface type. (See section 3.5 below for how IDL callback functions have corresponding Java interfaces.)
A Java value V is converted to an IDL callback function type value by running the following algorithm (where C is the callback function):
Conversions from IDL callback function type values to Java values are performed in the same way as that for the IDL object type.
IDL nullable type values are represented with Java object references of a particular class, as determined by the table below:
Nullable type | Java class | Method to get value |
---|---|---|
boolean? | java.lang.Boolean | booleanValue() |
byte? | java.lang.Byte | byteValue() |
octet? | java.lang.Byte | byteValue() |
short? | java.lang.Short | shortValue() |
unsigned short? | java.lang.Short | shortValue() |
long? | java.lang.Integer | intValue() |
unsigned long? | java.lang.Integer | intValue() |
long long? | java.lang.Long | longValue() |
unsigned long long? | java.lang.Long | longValue() |
float? | java.lang.Float | floatValue() |
unrestricted float? | java.lang.Float | floatValue() |
double? | java.lang.Double | doubleValue() |
unrestricted double? | java.lang.Double | doubleValue() |
DOMString? | java.lang.String | – |
Enumeration type T? | java.lang.String | – |
Interface type T? | The Java interface corresponding to IDL type T | – |
Dictionary type T? | java.util.HashMap<java.lang.String,java.lang.Object> | – |
sequence<T>? | U[], where U is the Java type used to represent the IDL type T | – |
T[]? | The Java array interface for IDL type T | – |
Union type T? | java.lang.Object | – |
How to convert a Java value of one of the above classes to an IDL nullable type T? depends on the object reference value and the type T:
How to convert an IDL nullable type value to a Java value depends on its value and the inner type:
The Java value is the result of converting the IDL inner type to a Java value, and then passing that value to the static method according to the following table, where T is the IDL inner type:
T | Method |
---|---|
boolean | java.lang.Boolean.valueOf(boolean) |
byte | java.lang.Byte.valueOf(byte) |
octet | java.lang.Byte.valueOf(byte) |
short | java.lang.Short.valueOf(short) |
unsigned short | java.lang.Short.valueOf(short) |
long | java.lang.Integer.valueOf(int) |
unsigned long | java.lang.Integer.valueOf(int) |
long long | java.lang.Long.valueOf(long) |
unsigned long long | java.lang.Long.valueOf(long) |
float | java.lang.Float.valueOf(float) |
unrestricted float | java.lang.Float.valueOf(float) |
double | java.lang.Double.valueOf(double) |
unrestricted double | java.lang.Double.valueOf(double) |
IDL sequence<T> values are represented by Java arrays of type U, where U is the Java type used to represent the IDL type T.
A Java array A of type U is converted to an IDL sequence<T> as follows:
An IDL sequence value S0..n−1 of type sequence<T> is converted to a Java array of type U object as follows:
A Java object implementing an interface with an operation declared to return a sequence<T> value MUST NOT return null from the corresponding method. Similarly, a getter method for an IDL attribute MUST NOT return null if the attribute is declared to be of type sequence<T>.
IDL T[] values are represented by Java objects implementing a particular interface, known as the Java array interface, depending on the type T.
For each of the primitive types there MUST exist a corresponding Java array interface of the following form:
package org.w3c.dom;
public interface PrimitiveNameArray {
int getLength();
void setLength(int length);
PrimitiveType getElement(int index);
void setElement(int index, PrimitiveType value);
}
where PrimitiveName is the type name of the primitive type and PrimitiveType is the Java type used to represent it.
For example, the Java array interface for the octet[] type is:
package org.w3c.dom;
public interface OctetArray {
int getLength();
void setLength(int length);
byte getElement(int index);
void setElement(int index, byte value);
}
There MUST also exist the following interface, org.w3c.dom.ObjectArray<E>:
package org.w3c.dom;
public interface ObjectArray<E> {
int getLength();
void setLength(int length);
E getElement(int index);
void setElement(int index, E value);
}
This interface, parameterized by the Java type used to represent array element type T, is the corresponding Java array interface for T.
For example, the Java array interface for the DOMString[]?[] type is org.w3c.dom.ObjectArray<java.lang.ObjectArray<java.lang.String>>.
A Java object that implements a Java array interface represents a given IDL array value of type T[]. The methods on the object that implement that interface MUST behave as follows:
getLength()
This method returns the current length of the IDL array value.
setLength(length)
When called on an object representing a variable length array, this method sets the length of the array to length. When the array is lengthened, the new elements are set to the IDL value that results from converting to an IDL value the default value of the Java type that T corresponds to ([JLS3], section 4.12.5).
When called on an object representing a fixed length array, this method throws a java.lang.UnsupportedOperationException.
getElement(index)
This method returns the IDL value of type T at the represented array’s index index converted to a Java value.
setElement(index, value)
When called on an object representing an array that is not read only, this method sets the IDL value at the represented array’s index index to the result of converting value to an IDL value of type T.
When called on an object representing an array that is read only, this method throws a java.lang.UnsupportedOperationException.
A Java reference value O for an object implementing a Java array interface is converted to an IDL array value as follows:
An IDL array value A of type T[] is converted to a Java value whose type is an object implementing the Java array interface corresponding to T, as follows:
IDL union type values are represented by Java java.lang.Object reference values.
To convert a Java value V to an IDL union type value is done as follows:
booleanValue()
method on V to boolean.byteValue()
method on V to byte.shortValue()
method on V to short.intValue()
method on V to long.longValue()
method on V to long long.floatValue()
method on V to float.floatValue()
method on V to unrestricted float.doubleValue()
method on V to double.doubleValue()
method on V to unrestricted double.An IDL union type is converted to a Java value by following the same rules as if the IDL type were any.
IDL Date values are represented by Java java.util.Date reference values.
A Java java.lang.Date reference value is converted to an IDL Date value as follows:
An IDL Date value is converted to a java.lang.Date reference value as follows:
new java.util.Date(Long.MIN_VALUE)
.This section defines a single extended attribute whose presence affects only the Java binding.
If the [JavaPackage]
extended attribute
appears on an interface or
exception,
it specifies that the corresponding Java interface or class MUST
be placed in the package identified. When [JavaPackage]
is not used, the Java interface or class MUST be placed
in the org.w3c.dom
package.
The [JavaPackage] extended attribute MUST take a dotted name, which is defined as the extended attribute matching ExtendedAttributeDottedName in the following grammar, which is to be interpreted in the same manner as the grammar in Web IDL ([WEBIDL], appendix A):
[1] | ExtendedAttributeDottedName | → | identifier DottedNameParts |
[2] | DottedNameParts | → | "." identifier DottedNameParts | ε |
The dotted name identifies the Java package in which the Java interface or class is to be placed.
Interfaces defined for the Web platform SHOULD NOT use [JavaPackage] unless required for compatibility.
The following IDL fragment defines
an IDL interface whose corresponding
Java interface will not be in the org.w3c.dom
package.
[JavaPackage=org.example]
interface Something {
};
For every supported IDL interface, there MUST exist a corresponding public Java interface whose name is the Java escaped identifier of the IDL interface.
The Java interface for an interface A MUST be declared to extend the following Java interfaces:
If the IDL interface has one or more static operations declared on it, then there MUST also exist a public, abstract Java class, which resides in the same Java package as the interface. This class is known as the utility class for the IDL interface, and provides access to the static operations. The name of the Java class is the concatenation of the identifier of the IDL interface and the string “Utils”. If this name is already the name of a Java class or interface, due to IDL definitions, then the name of the Java class is prefixed with a single U+005F LOW LINE ("_") character so as not to conflict.
For each constant defined on the IDL interface, there MUST be a corresponding constant declared on the Java interface with the following characteristics:
The operations defined on an IDL interface will result in one or more methods being declared on the Java interface (for regular operations) or on a Java utility class (for static operations).
For each unique identifier id of the regular operations declared on the IDL interface:
For each unique identifier id of the static operations declared on the IDL interface:
public static final
.
For each identifierless special operation declared on the IDL interface of the following types,
there MUST exist a method on the Java interface whose name is determined based on the type of special operation:
Type | Name |
---|---|
indexed or named property getter | “_get” |
indexed or named property setter | “_set” |
indexed or named property creator | “_create” |
indexed or named property deleter | “_delete” |
caller | “_call” |
For all of the above operations – regular, static, and the abovementioned special operations – their corresponding Java methods have the following characteristics, based on the effective overload set entry <callable, type list>:
For each attribute defined on the IDL interface that does not inherit its getter, there MUST be a corresponding getter method declared on the Java interface with the following characteristics:
java.lang.Character.toUpperCase()
method.For each attribute defined on the IDL interface that is not read only, there MUST be a corresponding setter method declared on the Java interface with the following characteristics:
java.lang.Character.toUpperCase()
method.For every supported IDL callback function, there MUST exist a corresponding public Java interface whose name is the Java escaped identifier of the callback function.
The Java interface for a callback function A MUST not be declared to inherit from any other Java interface.
For each pair <callback, types> in the effective overload set for callback function A with argument count 0, there MUST exist a method on the Java interface with the following characteristics:
call
.A Java platform object that implements an IDL interface MUST be of a Java class which implements the Java interface that corresponds to the IDL interface.
If the IDL interface has a stringifier,
the String toString()
method
MUST be overridden to allow
stringification of the object as required by the IDL
interface. If the stringifier
keyword
was used on an attribute A,
then, assuming O is the object on which
the method was invoked, the behavior of the overridden
toString
method MUST
be as follows:
Otherwise, if the stringifier
keyword
was used on an operation
O with an identifier,
then, assuming O is the object on which
the method was invoked, the behavior of the overridden
toString
method MUST
be as follows:
Otherwise, if the stringifier
keyword
was used on an operation
without an identifier, then
the behavior of the overridden toString()
method is the stringification behavior
of the IDL interface, as described in the prose for the IDL interface.
A Java user object that implements an IDL callback interface MUST be of a Java class that implements the Java interface that corresponds to the IDL interface, either by implementing the interface directly on that class or by inheriting from another class that implements the interface.
For example, with the following IDL:
callback interface Base {
void f();
};
callback interface Derived : Base {
void g();
};
the Java implementation would provide the following interfaces:
public interface Base {
void f();
}
public interface Derived extends Base {
void g();
}
and user objects implementing Derived could be defined like the following:
// Directly implementing the interface
class DerivedImpl1 implements Derived {
public void f() { ... }
public void g() { ... }
}
// Inheriting from a class that implements the interface
class DerivedImpl2 extends DerivedImpl1 { }
For every IDL exception, there MUST exist a corresponding Java class whose name is the Java escaped identifier of the IDL exception.
The Java class MUST have only the public
modifier.
If the IDL exception inherits from another
exception, then the Java class MUST be declared to extend
the Java class corresponding to that inherited exception. Otherwise, the Java class MUST
be declared to extend org.w3c.dom.Exception.
The class MUST also have constructors and methods with definitions as follows, where ExceptionName is the name of the class:
public ExceptionName() {
}
public ExceptionName(String message) {
super(message);
}
public ExceptionName(String message, Throwable cause) {
super(message, cause);
}
public ExceptionName(Throwable cause) {
super(cause);
}
The class org.w3c.dom.Exception is defined as follows:
public class org.w3c.dom.Exception extends RuntimeException {
public Exception(String message) {
super(message);
}
public Exception(String message, Throwable cause) {
super(message, cause);
}
public Exception(Throwable cause) {
super(cause);
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
private String name;
}
For each constant defined on the exception, there MUST be a corresponding constant declared on the Java class with the following characteristics:
For each exception field defined on the exception, there MUST be a corresponding instance variable declared on the Java class with the following characteristics:
public
.When an IDL exception or predefined exception E is to be thrown, with an optional message M and name N, the following steps MUST be followed:
This section is informative.
Extensions to the Java language binding requirements can be specified using extended attributes that do not conflict with those defined in this document. Extensions for private, project-specific use should not be included in IDL fragments appearing in other specifications. It is recommended that extensions that are required for use in other specifications be coordinated with the group responsible for work on Web IDL, which at the time of writing is the W3C Web Applications Working Group, for possible inclusion in a future version of this document.
Extensions to any other aspect of the IDL language are strongly discouraged.
This section is informative.
It is suggested that specifications defining interfaces with Web IDL for which Java language bindings are required to exist include a sentence such as the following, to indicate that the IDL is to be interpreted as described in this specification:
The IDL fragment in Appendix A of this specification must be interpreted as required for conforming IDL fragments, as described in the “Web IDL” specification. [WEBIDL]
In addition, it is suggested that the conformance class for user agents in referencing specifications be linked to the conforming Java implementation class from this specification:
A conforming FooML user agent must also be a conforming Java implementation of the IDL fragment in Appendix A of this specification, as described in the “Java language binding for Web IDL” specification. [WEBIDL-JAVA]
This section is informative.
The editor would like to thank contributors to the Web IDL specification, from which this Java language binding was split out in December 2011.
The following is a list of substantial changes to the document on each publication.
Changed the org.w3c.dom.Exception class to take into account the renaming of “exception types” to “exception names”.
Added support for IDL unrestricted float and double types.
Added support for IDL callbacks and callback interfaces.
Added support for IDL union types.
Added support for IDL enumerations.
Initial document creation. For changes prior to 12 December 2011, please see the Web IDL Changes appendix.