APIs for Java Developers

Go to APIs for .NET Developers

com.javonet

Class Javonet

  • java.lang.Object
    • com.javonet.Javonet

  • public class Javonet
    extends java.lang.Object
    This is main class of Javonet solution. Javonet exposes methods for:

    • initializing javonet
    • activating javonet
    • loading references to .NET assemblies
    • retrieving .NET types
    • creating .NET classes instances

    Use this class as starting point for most Javonet operations.

    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:

     
    	Javonet.activate("your@mail.com", "your-javonet-license-key");
     
    	NObject objRandom = Javonet.New("System.Random");
    	Integer value = objRandom.invoke("Next",10,20);
    		
    	System.out.println(value);
     
     
    Version:
    1.0


    • Constructor Summary

      Constructors 
      Constructor and Description
      Javonet() 



    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static boolean activate(java.lang.String oemLicenceKey,
      JavonetFramework framework)

      Activates Javonet copy with OEM license details.
      static boolean activate(java.lang.String email,
      java.lang.String licenceKey,
      JavonetFramework framework)

      Activates Javonet copy with your license details.
      static boolean activate(java.lang.String email,
      java.lang.String licenceKey,
      java.lang.String proxyHost,
      JavonetFramework framework)

      Activates Javonet copy with your license details.
      static boolean activate(java.lang.String email,
      java.lang.String licenceKey,
      java.lang.String proxyHost,
      java.lang.String proxyUsername,
      java.lang.String proxyPassword,
      JavonetFramework framework)

      Activates Javonet copy with your license details.
      static boolean activate(java.lang.String email,
      java.lang.String licenceKey,
      java.lang.String proxyHost,
      java.lang.String proxyUsername,
      java.lang.String proxyPassword,
      java.lang.String proxyDomain,
      JavonetFramework framework)

      Activates Javonet copy with your license details.
      static void addReference(java.lang.String... pathOrName)

      Loads .NET library or libraries into memory on .NET side.
      static void addReference(java.lang.String name,
      byte[] dotNetAssemblyByteArray)

      Loads .NET library from byte array into memory on .NET side.
      static void addReference(java.lang.String name,
      java.lang.Byte[] dotNetAssemblyByteArray)

      Loads .NET library from byte array into memory on .NET side.
      static NObject create(java.lang.String typeName)

      Creates new instance of .NET class using parameter-less constructor specified by provided type name and located in any of the loaded assemblies.
      static NObject create(java.lang.String typeName,
      java.lang.Object... parameters)

      Creates new instance of .NET class using constructor with parameters specified by provided type name and located in any of the loaded assemblies.
      static void Dispose()

      Disposes Javonet session.
      static JavonetFramework getFramework()

      Returns current .NET Framework version that is being used by Javonet.
      static com.javonet.internal.IGateway getGateway()

      Returns current gateway session object.
      static NType getType(java.lang.String typeName)

      Loads specified type on .NET side and returns new instance of NType class connected to this type.
      static NType getType(java.lang.String typeName,
      java.lang.Object... genericTypes)

      Loads specified generic type on .NET side and returns new instance of NType class connected to this type.
      static boolean isActivated()

      Returns true or false indicating if Javonet engine has been activated
      and configured in the current process.
      static NObject New(java.lang.String typeName)

      Creates new instance of .NET class using parameter-less constructor specified by provided type name and located in any of the loaded assemblies.
      static NObject New(java.lang.String typeName,
      java.lang.Object... parameters)

      Creates new instance of .NET class using constructor with parameters specified by provided type name and located in any of the loaded assemblies.
      static NAssembly reference(java.lang.String pathOrName)

      Loads .NET library and returns instance of associated NAssembly object.
      static void setApartmentState(JavonetApartmentState apartmentState)

      Sets apartment state for .NET process main thread.
      static void setLicenseDirectory(java.lang.String licenseDirectory)

      Sets the absolute path where the Javonet license files should be stored.
      static void setUseHardwareKey(boolean useHardwareKey)

      Sets if the Javonet should use hardware key as a source of machine ID
      for license verification.
      static void showWelcomeMessage()

      Prints on console Javonet Welcome message.


      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait



    • Constructor Detail



      • Javonet

        public Javonet()



    • Method Detail



      • activate

        public static boolean activate(java.lang.String oemLicenceKey,
                                       JavonetFramework framework)
                                throws JavonetException
        Activates Javonet copy with OEM license details.
        Parameters:
        oemLicenceKey – Your OEM license key
        framework – .NET Framework version to be used read more at JavonetFramework
        Returns:
        Activation result true for success and false for failure
        Throws:
        JavonetException – If exception occurs during activation



      • activate

        public static boolean activate(java.lang.String email,
                                       java.lang.String licenceKey,
                                       JavonetFramework framework)
                                throws JavonetException
        Activates Javonet copy with your license details. Activation can be also performed automatically
        by providing your license details in Javonet XML configuration file.
        Parameters:
        email – Your license key email address
        licenceKey – Your license key
        framework – .NET Framework version to be used read more at JavonetFramework
        Returns:
        Activation result true for success and false for failure
        Throws:
        JavonetException – If exception occurs during activation



      • activate

        public static boolean activate(java.lang.String email,
                                       java.lang.String licenceKey,
                                       java.lang.String proxyHost,
                                       JavonetFramework framework)
                                throws JavonetException
        Activates Javonet copy with your license details. Activation can be also performed automatically
        by providing your license details in Javonet XML configuration file.

        With this method optional proxy settings can be provided which should be used to access Internet
        from enterprise network. These settings will be used for performing activation.

        Parameters:
        email – Your license key email address
        licenceKey – Your license key
        proxyHost – Proxy host name in format HOST:PORT or IP:PORT
        framework – .NET Framework version to be used read more at JavonetFramework
        Returns:
        Activation result true for success and false for failure
        Throws:
        JavonetException – If exception occurs during activation



      • activate

        public static boolean activate(java.lang.String email,
                                       java.lang.String licenceKey,
                                       java.lang.String proxyHost,
                                       java.lang.String proxyUsername,
                                       java.lang.String proxyPassword,
                                       JavonetFramework framework)
                                throws JavonetException
        Activates Javonet copy with your license details. Activation can be also performed automatically
        by providing your license details in Javonet XML configuration file.

        With this method optional proxy settings can be provided which should be used to access Internet
        from enterprise network. These settings will be used for performing activation.

        Parameters:
        email – Your license key email address
        licenceKey – Your license key
        proxyHost – Proxy host name in format HOST:PORT or IP:PORT
        proxyUsername – Username to be used for proxy authentication
        proxyPassword – Password to be used for proxy authentication
        framework – .NET Framework version to be used read more at JavonetFramework
        Returns:
        Activation result true for success and false for failure
        Throws:
        JavonetException – If exception occurs during activation



      • activate

        public static boolean activate(java.lang.String email,
                                       java.lang.String licenceKey,
                                       java.lang.String proxyHost,
                                       java.lang.String proxyUsername,
                                       java.lang.String proxyPassword,
                                       java.lang.String proxyDomain,
                                       JavonetFramework framework)
                                throws JavonetException
        Activates Javonet copy with your license details. Activation can be also performed automatically
        by providing your license details in Javonet XML configuration file.

        With this method optional proxy settings can be provided which should be used to access Internet
        from enterprise network. These settings will be used for performing activation.

        Parameters:
        email – Your license key email address
        licenceKey – Your license key
        proxyHost – Proxy host name in format HOST:PORT or IP:PORT
        proxyUsername – Username to be used for proxy authentication
        proxyPassword – Password to be used for proxy authentication
        proxyDomain – User domain to be used for proxy authentication
        framework – .NET Framework version to be used read more at JavonetFramework
        Returns:
        Activation result true for success and false for failure
        Throws:
        JavonetException – If exception occurs during activation



      • addReference

        public static void addReference(java.lang.String... pathOrName)
                                 throws JavonetException
        Loads .NET library or libraries into memory on .NET side.

        Loaded libraries are automatically used for all look-ups on further Javonet calls to .NET
        types or classes.

        Assembly can be located anywhere on the hard drive in local directory or in GAC.

        You can specify full assembly path or full assembly name for GAC assemblies.

        You can provide more then one assembly name in seperate string arguments.

        Parameters:
        pathOrName – List of .NET assemblies paths or full assembly names to be loaded
        Throws:
        JavonetException – If .NET exception occurs during while loading assembly



      • addReference

        public static void addReference(java.lang.String name,
                                        byte[] dotNetAssemblyByteArray)
                                 throws JavonetException
        Loads .NET library from byte array into memory on .NET side.

        Loaded libraries are automatically used for all look-ups on further Javonet calls to .NET
        types or classes.

        You can load the assembly bytes from disk or memory stream extracted from
        your application jar file.

        This method will automatically box the provided bytes array byte[] into Byte[].
        For higher performance use the addReference(String, Byte[]).

        Parameters:
        name – Name of the library provided in second argument.
        dotNetAssemblyByteArray – Byte Array of an assembly to be loaded.
        Throws:
        JavonetException – If .NET exception occurs during while loading assembly



      • addReference

        public static void addReference(java.lang.String name,
                                        java.lang.Byte[] dotNetAssemblyByteArray)
                                 throws JavonetException
        Loads .NET library from byte array into memory on .NET side.

        Loaded libraries are automatically used for all look-ups on further Javonet calls to .NET
        types or classes.

        You can load the assembly bytes from disk or memory stream extracted from
        your application jar file.

        Parameters:
        name – Name of the library provided in second argument.
        dotNetAssemblyByteArray – Byte Array of an assembly to be loaded.
        Throws:
        JavonetException – If .NET exception occurs during while loading assembly



      • create

        public static NObject create(java.lang.String typeName)
                              throws JavonetException
        Creates new instance of .NET class using parameter-less constructor specified by provided type name and located in any of the loaded assemblies.
        Parameters:
        typeName – Name of the type for which new instance should be created
        Returns:
        New instance of NObject associated to new instance of created object on .NET side
        Throws:
        JavonetException – If .NET exception occurs during initialization of .NET object



      • create

        public static NObject create(java.lang.String typeName,
                                     java.lang.Object... parameters)
                              throws JavonetException
        Creates new instance of .NET class using constructor with parameters specified by provided type name and located in any of the loaded assemblies.

        Constructor is being matched by parameters count and type.

        Parameters can be specified as JAVA primitive types (string, integer, float..) or instances of NObject class for reference-type parameters.

        This method returns new instance of NObject class associated to newly created object on .NET side.

        Parameters:
        typeName – Name of the type for which new instance should be created
        parameters – Parameters to be passed to constructor during creation of new instance of associated .NET type
        Returns:
        New instance of NObject associated to new instance of created object on .NET side
        Throws:
        JavonetException – If .NET exception occurs during initialization of .NET object



      • Dispose

        public static void Dispose()
        Disposes Javonet session. All objects and connections are closed. Existing NObject, NType and
        NAssemblies objects cannot be used anymore.



      • getFramework

        public static JavonetFramework getFramework()
        Returns current .NET Framework version that is being used by Javonet.

        Framework version can be set either by calling activate(String, String, JavonetFramework) method
        or setting “framework” property in “settings” section of javonet.xml configuration file.

        Returns:
        current .NET Framework version selected



      • getGateway

        public static com.javonet.internal.IGateway getGateway()
                                                        throws JavonetException
        Returns current gateway session object. If gateway is not yet initialized it will be
        initialized automatically.
        Returns:
        Current gateway session object
        Throws:
        JavonetException – If exception occurs during gateway initialization



      • getType

        public static NType getType(java.lang.String typeName)
                             throws JavonetException
        Loads specified type on .NET side and returns new instance of NType class connected to this type.
        Parameters:
        typeName – Name of the type to be loaded
        Returns:
        New instance of NType associated to loaded .NET type
        Throws:
        JavonetException – If .NET exception occurs during .NET type loading



      • getType

        public static NType getType(java.lang.String typeName,
                                    java.lang.Object... genericTypes)
                             throws JavonetException
        Loads specified generic type on .NET side and returns new instance of NType class connected to this type.
        Parameters:
        typeName – Name of the type to be loaded
        genericTypes – List of generic types used to parameterize this generic type instance
        Returns:
        New instance of NType associated to loaded .NET type
        Throws:
        JavonetException – If .NET exception occurs during .NET type loading



      • 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.

        Returns:
        Boolean value indicating if Javonet activation has been performed



      • New

        public static NObject New(java.lang.String typeName)
                           throws JavonetException
        Creates new instance of .NET class using parameter-less constructor specified by provided type name and located in any of the loaded assemblies.

        This method works the same way as create(String) and was created to provide more semantically meaningful usage.

        Parameters:
        typeName – Name of the type for which new instance should be created
        Returns:
        New instance of NObject associated to new instance of created object on .NET side
        Throws:
        JavonetException – If .NET exception occurs during initialization of .NET object



      • New

        public static NObject New(java.lang.String typeName,
                                  java.lang.Object... parameters)
                           throws JavonetException
        Creates new instance of .NET class using constructor with parameters specified by provided type name and located in any of the loaded assemblies.

        This method works the same way as create(String, Object...) and was created to provide more semantically meaningful usage.

        Constructor is being matched by parameters count and type.

        Parameters can be specified as JAVA primitive types (string, integer, float..) or instances of NObject class for reference-type parameters.

        This method returns new instance of NObject class associated to newly created object on .NET side.

        Parameters:
        typeName – Name of the type for which new instance should be created
        parameters – Parameters to be passed to constructor during creation of new instance of associated .NET type
        Returns:
        New instance of NObject associated to new instance of created object on .NET side
        Throws:
        JavonetException – If .NET exception occurs during initialization of .NET object



      • reference

        public static NAssembly reference(java.lang.String pathOrName)
                                   throws JavonetException
        Loads .NET library and returns instance of associated NAssembly object.

        Loaded libraries are automatically used for all look-ups on further Javonet calls to .NET
        types or classes.

        Assembly can be located anywhere on the hard drive in local directory or in GAC.

        You can specify full assembly path or full assembly name for GAC assemblies.

        Parameters:
        pathOrName – Full path or full assembly name
        Returns:
        New instance of associated NAssembly object
        Throws:
        JavonetException – If .NET exception occurs during while loading assembly



      • setApartmentState

        public static void setApartmentState(JavonetApartmentState apartmentState)
                                      throws JavonetException
        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.

        Parameters:
        apartmentState – Apartment state to be set
        Throws:
        JavonetException – If exception occurs while setting apartment state



      • setLicenseDirectory

        public static void setLicenseDirectory(java.lang.String licenseDirectory)
        Sets the absolute path where the Javonet license files should be stored.
        Parameters:
        licenseDirectory – path for Javonet license files



      • setUseHardwareKey

        public static void setUseHardwareKey(boolean useHardwareKey)
                                      throws JavonetException
        Sets if the Javonet should use hardware key as a source of machine ID
        for license verification. If set to “true” the hardware dongle key must
        be plugged in order to properly activate Javonet.

        Setting this value to true to will cause the creation of javonet_hk.lic
        file in the root directory of Java application.

        Parameters:
        useHardwareKey – flag if hardware dongle key should be used as source of machine id.
        Throws:
        JavonetException – thrown if method is called after activate method



      • showWelcomeMessage

        public static void showWelcomeMessage()
        Prints on console Javonet Welcome message. This method could be used for debugging and logging purposes.

        Welcome message includes details about Javonet version, .NET and C++ runtime loaded and configuration detected.