Activating Javonet

Before you perform any operation with Javonet first you must activate your Javonet license.
You can do it either by calling activate(String, String, JavonetFramework) method or specifying your
license details in Javonet XML configuration file.

Usage Sample

Example below shows all what you need to do to activate Javonet and use .NET Random class to
generate random number and retrieve result as JAVA integer:

getUseLegacyExceptions

public static boolean getUseLegacyExceptions()

Returns if Javonet is working in legacy exceptions mode or new NException mode.

Legacy exceptions is standard way how exceptions were handled before version 1.5
all .NET and Javonet exceptions where thrown as JavonetException. For .NET exceptions
the message contained entire .NET exception converted to string.

New exception mode distinguishes between JavonetExceptions and exceptions coming from
users .NET code. For .NET exceptions the NException extension of JavonetException is thrown.
This class contains real .NET message, merges Java and .NET stacktrace and provides access
to internal exceptions. Additionally all other properties from .NET exception are copied to Java
side for further processing including the access to the .NET exception type.

It is recommended to work with new exceptions mode which will be further extended in next releases.
Legacy mode should be used only for backward compatibility in existing projects.

Returns:

Returns true or false indicating if Javonet is working using old exceptions mode.

Since:

1.5

getUsePrivateHandleField

public static boolean getUsePrivateHandleField()

Returns information if Javonet is using the private handles field mode for strongly
typed wrappers.

In private handles mode, when regular Java class is passed to Javonet methods as argument,
new value for a field, part of array etc… to be processed on .NET side, Javonet looks if this
object contains private field of NObject type and name “handle”. If yes the object associated with that
NObject instance is used for further processing.

This is used to simplify strongly typed wrappers creation and make them more natural for end-users. Read
more about creating strongly typed wrappers on Javonet Guides for Java Developers. https://www.javonet.com/java-devs/guides/

Returns:

Returns true or false indicating if Javonet is looking for private handles.

Since:

1.5

isActivated

public static boolean isActivated()

Returns true or false indicating if Javonet engine has been activated
and configured in the current process.

If Javonet has been activate the “activate” method should not be called.

This method can be used in distributed and mulit-threaded environments to
avoid multiple Javonet activation calls.

setActivationRelay

Sets the custom URL that will be used for processing activation requests.

Usage of activation relay servers is allowed for enterprise license only
in order to customize the url that will need to be white-listed for activation
requests.

The customized activation url must be provided with valid signature generated
using Javonet private RSA key by Javonet support. Otherwise the server will not
be authorized for processing activation requests.

setApartmentState

Sets apartment state for .NET process main thread. This method must be called before
any other operation on Javonet is executed.

Apartment state can be also set automatically by specifying it in Javonet XML configuration file.

Javonet during initialization creates .NET process connected to JAVA process of your
application. The .NET process main thread can be in Multi-Threaded Apartment state (MTA)
or Single-Threaded Apartment state (STA). This value is very important for implementations
where WinForms or WPF interface is supposed to be used for JAVA application.

In case when you plan to create WinForms or WPF interface you must use STA apartment thread.

setUseLegacyExceptions

public static void setUseLegacyExceptions(boolean value)

Sets if Javonet is working in legacy exceptions mode or new NException mode.

By default Javonet works in NException mode.

Legacy exceptions is standard way how exceptions were handled before version 1.5
all .NET and Javonet exceptions where thrown as JavonetException. For .NET exceptions
the message contained entire .NET exception converted to string.

New exception mode distinguishes between JavonetExceptions and exceptions coming from
users .NET code. For .NET exceptions the NException extension of JavonetException is thrown.
This class contains real .NET message, merges Java and .NET stacktrace and provides access
to internal exceptions. Additionally all other properties from .NET exception are copied to Java
side for further processing including the access to the .NET exception type.

It is recommended to work with new exceptions mode which will be further extended in next releases.
Legacy mode should be used only for backward compatibility in existing projects.

Parameters:

value – true or false indicating if legacy exceptions should be used.

Since:

1.5

setUsePrivateHandleField

public static void setUsePrivateHandleField(boolean value)

Sets if Javonet should use the private handles field mode for strongly typed wrappers.

In private handles mode, when regular Java class is passed to Javonet methods as argument,
new value for a field, part of array etc… to be processed on .NET side, Javonet looks if this
object contains private field of NObject type and name “handle”. If yes the object associated with that
NObject instance is used for further processing.

This is used to simplify strongly typed wrappers creation and make them more natural for end-users. Read
more about creating strongly typed wrappers on Javonet Guides for Java Developers. https://www.javonet.com/java-devs/guides/