APIs for Java Developers

Go to APIs for .NET Developers

com.javonet.api

Class NObject

  • java.lang.Object
    • com.javonet.api.NObject

  • public class NObject
    extends java.lang.Object
    A class that represents any object created on .NET side. Each instance of this object holds handle to associated .NET object.

    While creating new .NET object in your JAVA code you can hold this object in NObject variable.
    NObject exposes all methods to operate on .NET objects like: methods invoking, getting/setting
    fields and properties, subscribing/unsubscribing events and disposing.

    Usage

    Use NObject type as it was any .NET object.

    NObject is initialized by:

    • calling Javonet.New(java.lang.String fullTypeName)

      NObject objRandom = Javonet.New("System.Random");

    • extending and calling base constructor with full name of .NET type:

        
       class JavaSubClassForDotNetObject extends NObject {
       	public JavaSubClassForDotNetObject()
       	{
       		super("System.Windows.Forms.Form");
       	}
       }

    NObject is wired to single instance of .NET side object and it’s life-cycle is reflected in
    CLR. When NObject is disposed in JAVA either by calling destructor or by garbage collector
    associated .NET object is disposed as well.

    Invocation chaining

    Methods in this class that do not otherwise have a value to return are specified to return the NObject upon
    which they are invoked. This allows method invocations to be chained; for example the sequence of statements

      
     b.set("Field1",0);
     b.set("Field2",10);
     b.set("Field3","String Value"); 
     

    can be replaced by the single, more compact statement

      
     b.set("Field1",0).set("Field2",10).set("Field3","String Value"); 
     
    Since:
    1.0
    Version:
    1.4hf14


    • Constructor Summary

      Constructors 
      Constructor and Description
      NObject(com.javonet.internal.IGateway gatewayManager,
      java.lang.String oid)

      Internal constructor initializes new instance of NObject connected to specified
      gateway session and associated to object with specified unique identifier.
      NObject(com.javonet.internal.IGateway gatewayManager,
      java.lang.String oid,
      java.lang.Boolean delayDispose)
       



    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addEventListener(java.lang.String eventName,
      INEventListener eventListener)

      Adds event listener for any .NET event on associated .NET object.
      void addEventListener(java.lang.String eventName,
      INEventWithResultListener eventListener)

      Adds event with result listener for any .NET event on associated .NET object.
      NGenericMethod generic(NType... genericTypes)

      Initializes generic method invocation.
      <T> T get(java.lang.String fieldName)

      Returns value of static/instance field or property of .NET object.
      <T> T getIndex(java.lang.Object index)

      Returns indexed value of current object at specified index position.
      NObject getIndexRef(java.lang.Object index)

      Returns referenced indexed value of current object at specified index position.
      java.lang.String getOid()

      Returns unique identifier of associated object initialized on .NET side.
      NObject getRef(java.lang.String fieldName)

      Returns value of static/instance field or property of .NET object which return value is another .NET object.
      static boolean hasEvents(java.lang.String oid)

      For internal usage only.
      <T> T invoke(java.lang.String methodName)

      Invokes any parameter-less method on associated .NET object and returns result.
      <T> T invoke(java.lang.String methodName,
      java.lang.Object... parameters)

      Invokes any method with parameters on associated .NET object and returns result.
      static void raiseEvent(java.lang.String oid,
      java.lang.String eventName,
      java.lang.Object[] arguments)

      Internal method used to receive signals about events raised on .NET side.
      static java.lang.Object raiseEventWithResult(java.lang.String oid,
      java.lang.String eventName,
      java.lang.Object[] arguments)

      Internal method used to receive signals about events raised on .NET side.
      void releaseEventsSubscriptions()

      Only for internal usage.
      void removeEventListener(java.lang.String eventName,
      INEventListener eventListener)

      Removes event listener assignment from specified event.
      void removeEventListener(java.lang.String eventName,
      INEventWithResultListener eventListener)

      Removes event with result listener assignment from specified event.
      NObject set(java.lang.String fieldName,
      java.lang.Object fieldValue)

      Sets value for any static or instance field and property
      on associated .NET object.
      <T extends NObject>
      T
      setIndex(java.lang.Object index,
      java.lang.Object fieldValue)

      Sets value for indexed property at specified key
      on associated .NET object.


      • Methods inherited from class java.lang.Object

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



    • Constructor Detail



      • NObject

        public NObject(com.javonet.internal.IGateway gatewayManager,
                       java.lang.String oid)
        Internal constructor initializes new instance of NObject connected to specified
        gateway session and associated to object with specified unique identifier.

        This constructor should not be used in regular implementation. Instead use New method on Javonet class.

        Parameters:
        gatewayManager – Gateway session to be used
        oid – Unique identifier of associated .NET object
        See Also:
        Javonet.New(String),
        Javonet.New(String, Object...)



      • NObject

        public NObject(com.javonet.internal.IGateway gatewayManager,
                       java.lang.String oid,
                       java.lang.Boolean delayDispose)



    • Method Detail



      • addEventListener

        public void addEventListener(java.lang.String eventName,
                                     INEventListener eventListener)
                              throws JavonetException
        Adds event listener for any .NET event on associated .NET object.

        When event is raised on .NET side, invocation will be automatically passed to JAVA and all
        assigned event listeners will be informed.

        Parameters:
        eventName – Name of the event for which listener should be attached
        eventListener – Event listener instance, anonymous class or class inheriting from INEventListener that will be informed when event is raised
        Throws:
        JavonetException – If .NET exception occurs while attaching event



      • addEventListener

        public void addEventListener(java.lang.String eventName,
                                     INEventWithResultListener eventListener)
                              throws JavonetException
        Adds event with result listener for any .NET event on associated .NET object.

        When event is raised on .NET side, invocation will be automatically passed to JAVA and all
        assigned event listeners will be informed.

        Parameters:
        eventName – Name of the event for which listener should be attached
        eventListener – Event listener instance, anonymous class or class inheriting from INEventListener that will be informed when event is raised
        Throws:
        JavonetException – If .NET exception occurs while attaching event



      • generic

        public NGenericMethod generic(NType... genericTypes)
        Initializes generic method invocation. Following invocation on returned object
        should call invoke(methodName) or invoke(methodName,parameters) to perform generic
        invocation on .NET method.

        Sample usage

        To call (.NET): obj.MyMethod<String>(arg1);

        Use following instruction (JAVA): obj.generic(NType(“String”)).invoke(“MyMethod”,arg1);

        Parameters:
        genericTypes – List of NType objects attached to .NET types to be used as generic arguments
        Returns:
        Generic method execution instance. Before method is executed following invoke method must be called on this object.



      • get

        public <T> T get(java.lang.String fieldName)
                  throws JavonetException
        Returns value of static/instance field or property of .NET object.

        If result is another .NET object a new instance of NObject class will be returned.

        Type Parameters:
        T – JAVA type to which the value returned from .NET field or property will be casted. Provide either JAVA value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        fieldName – Name of the field or property which value needs to be retrieved
        Returns:
        Value of field or property retrieved from associated .NET object
        Throws:
        JavonetException – If .NET exception occurs within corresponding getter on .NET side



      • getIndex

        public <T> T getIndex(java.lang.Object index)
                       throws JavonetException
        Returns indexed value of current object at specified index position.
        This method is equivalent of calling on .NET side following instruction:
        – SampleObject[index];
        – SampleObject[“textIndex”];
        – SampleObject[anotherDotNetObject];

        If result is another .NET object a new instance of NObject class will be returned.

        Type Parameters:
        T – JAVA type to which the value returned from indexed .NET field or property will be casted. Provide either JAVA value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        index – Index position to be retrieved
        Returns:
        Value of item stored at specified index, retrieved from associated .NET object
        Throws:
        JavonetException – If .NET exception occurs within corresponding getter on .NET side
        Since:
        1.1



      • getIndexRef

        public NObject getIndexRef(java.lang.Object index)
                            throws JavonetException
        Returns referenced indexed value of current object at specified index position.
        This method is equivalent of calling on .NET side following instruction:
        – SampleObject[index];
        – SampleObject[“textIndex”];
        – SampleObject[anotherDotNetObject];

        This method assumes that item stored at selected position is instance of another .NET object
        and automatically returns NObject handle for that object.

        Parameters:
        index – Index position to be retrieved
        Returns:
        NObject instance attached to item stored at specified index, retrieved from associated .NET object
        Throws:
        JavonetException – If .NET exception occurs within corresponding getter on .NET side
        Since:
        1.1



      • getOid

        public java.lang.String getOid()
        Returns unique identifier of associated object initialized on .NET side.
        Type of that objects is specified during initialization of NObject class.
        Returns:
        Unique identifier of corresponding .NET object instance



      • getRef

        public NObject getRef(java.lang.String fieldName)
                       throws JavonetException
        Returns value of static/instance field or property of .NET object which return value is another .NET object.

        This method should be used to simplify get calls for properties/fields with reference result.

        Result is an instance of new NObject class associated to returned .NET object.

        Alternatively generic T get with NObject type might be used b.<NObject>get("Controls");

        Parameters:
        fieldName – Name of the field or property which value needs to be retrieved
        Returns:
        NObject instance associated to .NET class returned by specified field or property
        Throws:
        JavonetException – If .NET exception occurs within corresponding getter on .NET side



      • hasEvents

        public static boolean hasEvents(java.lang.String oid)
        For internal usage only. Returns true or false if there are any event listeners subscribed to events
        of .NET object associated with this NObject instance
        Parameters:
        oid – object OID.
        Returns:
        true or false indicating if any listeners are registered.
        Since:
        1.5



      • invoke

        public <T> T invoke(java.lang.String methodName)
                     throws JavonetException
        Invokes any parameter-less method on associated .NET object and returns result.

        For primitive-type results appropriate Java primitive type will be returned (string, integer, float…)

        If reference-type results instance of another NObject will be returned associated to returned .NET object.

        For void results NULL will be returned.

        Type Parameters:
        T – Java type to which the result returned by invoked method will be casted. Provide either Java value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        methodName – Name of the method to be invoked
        Returns:
        Result of method invocation. It can be JAVA primitive type (string, integer, float) or instance of another NObject
        Throws:
        JavonetException – If .NET exception occurs during method invocation
        See Also:
        invoke(String, Object...)



      • invoke

        public <T> T invoke(java.lang.String methodName,
                            java.lang.Object... parameters)
                     throws JavonetException
        Invokes any method with parameters on associated .NET object and returns result.

        Parameters can be specified as any Java primitive type or instance of another NObject to pass reference to another .NET object.

        For primitive-type results appropriate Java primitive type will be returned (String, Integer, Float…)

        If reference-type results instance of another NObject will be returned associated to returned .NET object.

        For void results NULL will be returned.

        Type Parameters:
        T – Java type to which the result returned by invoked method will be casted. Provide either Java value type like: integer, string, boolean or for reference type results please use NObject
        Parameters:
        methodName – Name of the method to be invoked
        parameters – Input parameters for method to be invoked. It can be JAVA primitive types or NObject to pass .NET reference
        Returns:
        Result of method invocation. It can be JAVA primitive type (string, integer, float) or instance of another NObject
        Throws:
        JavonetException – If .NET exception occurs during method invocation



      • raiseEvent

        public static void raiseEvent(java.lang.String oid,
                                      java.lang.String eventName,
                                      java.lang.Object[] arguments)
        Internal method used to receive signals about events raised on .NET side.

        This method should not be used in regular implementations.

        Parameters:
        eventName – Name of the event
        arguments – Event arguments
        Throws:
        JavonetException



      • raiseEventWithResult

        public static java.lang.Object raiseEventWithResult(java.lang.String oid,
                                                            java.lang.String eventName,
                                                            java.lang.Object[] arguments)
        Internal method used to receive signals about events raised on .NET side.

        This method should not be used in regular implementations.

        Parameters:
        eventName – Name of the event
        arguments – Event arguments
        Returns:
        event invocation result



      • releaseEventsSubscriptions

        public void releaseEventsSubscriptions()
        Only for internal usage. This method release all Java events listeners subscription for .NET object associated with this NObject instance.
        Since:
        1.5



      • removeEventListener

        public void removeEventListener(java.lang.String eventName,
                                        INEventListener eventListener)
                                 throws JavonetException
        Removes event listener assignment from specified event.
        Parameters:
        eventName – Name of the event from which listener should be removed
        eventListener – Event listener instance, anonymous class or class inheriting from INEventListener
        Throws:
        JavonetException – If .NET exception occurs while detaching event



      • removeEventListener

        public void removeEventListener(java.lang.String eventName,
                                        INEventWithResultListener eventListener)
                                 throws JavonetException
        Removes event with result listener assignment from specified event.
        Parameters:
        eventName – Name of the event from which listener should be removed
        eventListener – Event listener instance, anonymous class or class inheriting from INEventListener
        Throws:
        JavonetException – If .NET exception occurs while detaching event



      • set

        public NObject set(java.lang.String fieldName,
                           java.lang.Object fieldValue)
                    throws JavonetException
        Sets value for any static or instance field and property
        on associated .NET object.

        Value can be specified as any JAVA primitive type (integer, string, float etc…)
        or as NObject instance to pass reference to another instance of initialized .NET object.

        Parameters:
        fieldName – Name of the instance or static field or property
        fieldValue – Value to be set on selected field or property. Value can be any JAVA primitive type or instance of NObject to pass reference-type
        Returns:
        Instance of NObject upon which method is invoked. This allows method invocations to be chained on that object; for example

         b.set("Field1",0).set("Field2",10).set("Field3","String Value"); 
        Throws:
        JavonetException – If .NET exception occurs within corresponding setter on .NET side



      • setIndex

        public <T extends NObject> T setIndex(java.lang.Object index,
                                              java.lang.Object fieldValue)
                                       throws JavonetException
        Sets value for indexed property at specified key
        on associated .NET object.

        Value and index can be specified as any JAVA primitive type (integer, string, float etc…)
        or as NObject instance to pass reference to another instance of initialized .NET object.

        This method is equivalent of calling on .NET side following instruction:
        – SampleObject[index]=”new value”;
        – SampleObject[“textIndex”]=newValueVar;
        – SampleObject[anotherDotNetObject]=5;

        Type Parameters:
        T – type of the object on which the setIndex(Object, Object) method is called. It must be either NObject or class derived from NObject. Allows further methods chaining.
        Parameters:
        index – Index position to be updated
        fieldValue – Value to be set on selected field or property. Value can be any JAVA primitive type or instance of NObject to pass reference-type
        Returns:
        Instance of NObject upon which method is invoked. This allows method invocations to be chained on that object; for example

         b.setIndex("key","value").setIndex("key2","value2"); 
        Throws:
        JavonetException – If .NET exception occurs within corresponding setter on .NET side
        Since:
        1.4hf6