storeNew()

The javaLib.storeNew() system function invokes the constructor of a class and places the new object into the EGL Java™ object space.

If the identifier is already in the object space, the action is equivalent to the following steps:
  • Running javaLib.remove() to remove the object previously associated with the identifier.
  • Relating the new object to the identifier.

For more information about the EGL Java™ object space in which javaLib.storeNew() and similar functions operate, see "Java™ access functions." EGL maintains this method of Java™ access for compatibility with earlier versions. For new code, use the more powerful ExternalType syntax; for more information, see "ExternalType part."

Syntax

  javaLib.storeNew(
    storeId javaObjId in,
    class STRING in
    {, argument anyEglPrimitive in})
storeId
A case-sensitive name that identifies the new object. Input can be any variable or expression that is assignment compatible with the STRING type, and is cast to objID, as in a later example. EGL strips single- and double-byte blanks from the beginning and end of the argument value.
class
The fully qualified, case-sensitive name of a Java™ class. Input can be any variable or expression that is assignment compatible with the STRING type. EGL strips single- and double-byte blanks from the beginning and end of the argument value.
argument
A value passed to the constructor. A cast might be required; see "Mapping EGL primitives to Java™." The Java™ type-conversion rules are in effect. No error occurs, for example, if you pass a SMALLINT to a constructor parameter that is declared as an int. To avoid losing precision, use an EGL FLOAT for a Java™ double, and an EGL SMALLFLOAT for a Java™ float. Using one of the other EGL types can result in a rounding error.
A value of an EGL external type is valid, as shown here:
SharedResourcePowerServer srps = JavaLib.getSharedResourcePowerServer();
JavaLib.storeNew("storeId" as "objID:java", "myClass", srps);

Example

In the following example, the function places a newly created object in the object space.

  javaLib.storeNew("storeId" as "objID:java", "myClass", 36 );

Error considerations

If the v60ExceptionCompatibility program property is not set, or is set to NO, an exception causes a JavaObjectException. Other errors cause a RuntimeException.

If the v60ExceptionCompatibility program property is set to YES, an error during processing of javaLib.storeNew() can set sysVar.errorCode to a value listed in the next table.

Table 1. javaLib.storeNew() error codes
Value in sysVar.errorCode Description
00001000 An exception was thrown by an invoked method or as a result of a class initialization
00001001 The object was null, or the specified identifier was not in the object space
00001002 A public method, field, or class with the specified name does not exist or cannot be loaded
00001003 The EGL primitive type does not match the type expected in Java™
00001006 The class of an argument cast to null could not be loaded
00001007 A SecurityException or IllegalAccessException was thrown during an attempt to get information about a method or field; or an attempt was made to set the value of a field that was declared final
00001008 The constructor cannot be called; the class name refers to an interface or abstract class