The present invention relates to a method and system for using Java® objects. The present invention further relates to setting up a generic interface to allow any arbitrary scripting language to use Java objects.
In the early 1990's, Sun Microsystems® developed an object-oriented programming language named Java®. The extreme portability of Java® made it ideal for use by internet websites. The structure of Java® is very similar to such programming languages as C and C++. Java® has become an incredibly popular programming language among internet developers.
A second type of programming language is a scripting language. A scripting language file may be interpreted without conversion to a binary executable file. Scripting languages improve ease of development and allow for multiple types of components to be used simultaneously. Numerous different type of scripting languages exist.
Object-based programming languages, as the name would imply, includes several different programming languages that use of objects in programming. Objects refer to the data structures used by these programming languages. These data structures may include values, such as integers, floats, Booleans (true or false values), strings, or characters. The data structures may be arrays or other matrices. The data structures may include various predetermined methods, or an algorithm for performing a transformation of a value or a set of values. The data structures may also include a class, which is a combination of various values and methods.
A typical scripting language has a collection of built-in primitive types that differ from Java®, usually having a narrower set of options. Usually a scripting language has one numeric type, one string type, and one Boolean type. Thus, during type conversion some type information may be lost. Thus, an efficient method is needed to convert between scripting language and Java® language.
A method, apparatus, and electronic device for executing programming across multiple programming languages are disclosed. The method may include executing an object method invocation for a Java® object using an arbitrary scripting language; and accessing the Java® object through a Java® scripting language interface. The Java® scripting language interface may determine the type of each Java® object, and match it with the appropriate scripting language object, be the object a value, method or class. The Java® scripting language interface may also build a scripting language object using Java® values and methods.
In order to describe the manner in which the above-recited and other advantages and features of the invention can be obtained, a more particular description of the invention briefly described above will be rendered by reference to specific embodiments thereof which are illustrated in the appended drawings. Understanding that these drawings depict only typical embodiments of the invention and are not therefore to be considered to be limiting of its scope, the invention will be described and explained with additional specificity and detail through the use of the accompanying drawings in which:
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The features and advantages of the invention may be realized and obtained by means of the instruments and combinations particularly pointed out in the appended claims. These and other features of the present invention will become more fully apparent from the following description and appended claims, or may be learned by the practice of the invention as set forth herein.
Various embodiments of the invention are discussed in detail below. While specific implementations are discussed, it should be understood that this is done for illustration purposes only. A person skilled in the relevant art will recognize that other components and configurations may be used without parting from the spirit and scope of the invention.
The present invention comprises a variety of embodiments, such as a method, an apparatus, and an electronic device, and other embodiments that relate to the basic concepts of the invention. The electronic device may be any manner of computer, mobile device, or wireless communication device.
A method, apparatus, and electronic device for executing programming across multiple programming languages are disclosed. The method may include executing a Java® object method invocation using an arbitrary scripting language; and accessing the Java® object through a Java® scripting language interface. The Java® scripting language interface may determine the type of each Java® object, and match it with the appropriate scripting language object, be the object a value, method or class. The Java® scripting language interface may also build a scripting language object using Java® values and methods.
The Atom type 150 encapsulates values of all the primitive types of a particular language, including strings, arrays, and objects 130. The arrays may include nested arrays. The Atom objects 130 may be used to represent Java® objects in the script code. The Atom objects 130 may contain a native C++ part that remains to exist as long as the underlying object does. The Atom objects 130 may even exist between different contexts, such as a parameter passed to a method, a return value of a method, and a property assigned to or acquired from a Java® or scripting language object.
The Atom type 150 may be implemented for a particular scripting language. Before producing a method call or getting or setting a property, the scripting language object is marshaled to an Atom object 150. The value that is received as a return value from a method or as a value of a property is in the Atom type 150 and must be converted to a native scripting language type before use.
A generic implementation 140 of the Atom type 150 may be provided in a form of an abstract C++ class template. The class may include a number getter 141 and setter 142 functions for the various possible types available. The base abstract class 140 of the Atom class 150 holds a state property that holds information about its current type. If an attempt is made to retrieve the value of the Atom object by calling a getter of a mismatched type, an exception is thrown.
At least three kinds of type conversion may be performed: conversion from scripting language type (AtomType) to Java® class type (jclass) (a “set property” operation), from jclass to AtomType (a “get property” operation) and from AtomType to a Java® value type (jvalue) (a “call method” operation). All these conversions, although being done in different directions or with different source (the “from” type) and destination (the “to” type) types, share a common stage, called type traversing. Type traversing is the process of determining the type and calling an appropriate callback function to handle it. Type traversing may use a signature argument to set the type of the destination value, as some scripting language types (like the number type) are ambiguous in relation to Java® types (like byte, int, or long types).
Since a typical scripting language lacks exact analogs to some of the Java® built-in types, a type hinting mechanism may be used with arguments in method calls. The type hinting is achieved by creating a set of new object types in the scripting languages to serve as wrappers to the value. These new object types may be used in overloaded method calls to specify the exact type to determine the most appropriate method. The name of the type may be used to deduce the desired type. These types may be enumerated 212 in the generic atom 214.
Field lookups 216 and method lookups 218 may be based on the name of the field or method that is looked up. For a method lookup 218, the types of the arguments that are passed to the method may be used to select the most appropriate method amongst overloaded methods. The classes that perform field lookups 216 and method lookups 218 may be written in Java®.
An accessor utility class 220 may be used by both the method lookup 218 and the field lookup 216. The accessor 220 may determine whether the value of the second type is assignable to the value of the first type and add a check if the class can be found within the available classes.
The field lookup 216 may be used to check if the desired field exists in the class, and returns a reference to the field in case of success. The field lookup 216 may make use of the accessor class 220 to check if the value of the type of the field can be assigned to the type desired by the caller.
The method lookup 218 may be used to check if the desired method exists in the class, and returns a reference to the method in case of success. The method lookup 218 may make use of the accessor class 220 to find the best matching method according to the types of the arguments given.
A value is deemed assignable if the types are equal. Both types are checked to determine if they are non-arrays, or arrays of an equal number of dimensions. Both types are equivalent if the first type is of a number type and the second type is one of the integral or floating types, if the first type is of string type and the second type is either of character or of string type, if the first type is of an object type which is assignable from the second type, or if the first type is of object or array type and the second type is null.
A type specification class 222 contains a collection of useful jclass types implemented in both Java® and native code. The type specification class 222 may also define methods to retrieve the element type of an array using type reflection, get the number of dimensions in an array, and construct an array by given element type and number of dimensions.
In native code, the Java® type is always defined by a pairing of jclass and dimensions. The jclass specifies the type and the dimensions specify the number of array dimensions. If the type is not an array type, the dimensions are zero. Thus, before converting a jclass to an atom type, a type traverser 202 implementation, via a generic atom 214, identifies the jclass and dimension pair type by getting the element type of the array and deducing the number of dimensions. If the type is identified as not being an array, the number of dimensions is set to zero. Alternatively, a textual signature may be used to identify a Java® object type.
Runtime class generation is necessary to support dynamic creation of subscriber objects, using a publisher-subscriber design pattern, in order to use them with APIs that are implemented in the way of calling back a function of the given object. Given the name of the super class and/or the list of interfaces to implement, an adapter class 224 is capable of creating a class with an automatically generated name that implements all of the interface and super class methods. When instantiated and linked with a scripting object, the adapter class 224 may create the direct connection between the Java® object class methods and the methods of its associated scripting object in such a way that whenever a particular method is called, the method with the same name of the scripting object is called, given all the arguments passed to the original method. The adapter class may be written in Java® using bytecode generation.
A Java® object interface class 226 may be used to create objects and adapters, access properties, call methods, and handle exceptions. The Java® object interface class 226 may hold a reference to a Java® object. The lifecycle of the Java® object interface class to the lifecycle of the underlying scripting objects.
Property getting and setting procedures are similar, differing mainly in direction. In property getting, the jclass value is converted to the AtomType value, while in the property setting procedure the AtomType value is converted to the jclass value.
The method invocation workflow follows a similar set of procedures to the property getting and setting procedures. The method invocation uses a different lookup procedure and performs two conversions.
The adapter class 224 may provide the ability for a scripting language to create a new Java® object 226 that will act as the subscriber in a publisher-subscriber design pattern. Since scripting languages usually contain no actual compilation stage, such an object has to be constructed at run time. The adapter class may define a set of functions to create a class, adding fields and methods to the class. These functions may be implemented using bytecode generation, using Java® Language Specification as a reference.
The controller/processor 710 may be any programmed processor known to one of skill in the art. However, the decision support method can also be implemented on a general-purpose or a special purpose computer, a programmed microprocessor or microcontroller, peripheral integrated circuit elements, an application-specific integrated circuit or other integrated circuits, hardware/electronic logic circuits, such as a discrete element circuit, a programmable logic device, such as a programmable logic array, field programmable gate-array, or the like. In general, any device or devices capable of implementing the decision support method as described herein can be used to implement the decision support system functions of this invention.
The memory 720 may include volatile and nonvolatile data storage, including one or more electrical, magnetic or optical memories such as a RAM, cache, hard drive, CD-ROM drive, tape drive or removable storage disk. The memory may have a cache 725 to speed access to specific data.
The Input/Output interface 750 may be connected to one or more input devices that may include a keyboard, mouse, pen-operated touch screen or monitor, voice-recognition device, or any other device that accepts input. The Input/Output interface 750 may also be connected to one or more output devices, such as a monitor, printer, disk drive, speakers, or any other device provided to output data.
The network interface 760 may be connected to a communication device, modem, network interface card, a transceiver, or any other device capable of transmitting and receiving signals over a network. The components of the computer system 700 may be connected via an electrical bus 770, for example, or linked wirelessly.
Client software and databases may be accessed by the controller/processor 710 from memory 720 or through the database interface 740, and may include, for example, database applications, word processing applications, the client side of a client/server application such as a billing system, as well as components that embody the decision support functionality of the present invention. The computer system 700 may implement any operating system, such as Windows or UNIX, for example. Client and server software may be written in any programming language, such as ABAP, C, C++, Java® or Visual Basic, for example.
Although not required, the invention is described, at least in part, in the general context of computer-executable instructions, such as program modules, being executed by the electronic device, such as a general purpose computer. Generally, program modules include routine programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. Moreover, those skilled in the art will appreciate that other embodiments of the invention may be practiced in network computing environments with many types of computer system configurations, including personal computers, hand-held devices, multi-processor systems, microprocessor-based or programmable consumer electronics, network PCs, minicomputers, mainframe computers, and the like.
Embodiments may also be practiced in distributed computing environments where tasks are performed by local and remote processing devices that are linked (either by hardwired links, wireless links, or by a combination thereof through a communications network.
Embodiments within the scope of the present invention may also include computer-readable media for carrying or having computer-executable instructions or data structures stored thereon. Such computer-readable media can be any available media that can be accessed by a general purpose or special purpose computer. By way of example, and not limitation, such computer-readable media can comprise RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to carry or store desired program code means in the form of computer-executable instructions or data structures. When information is transferred or provided over a network or another communications connection (either hardwired, wireless, or combination thereof to a computer, the computer properly views the connection as a computer-readable medium. Thus, any such connection is properly termed a computer-readable medium. Combinations of the above should also be included within the scope of the computer-readable media.
Computer-executable instructions include, for example, instructions and data which cause a general purpose computer, special purpose computer, or special purpose processing device to perform a certain function or group of functions. Computer-executable instructions also include program modules that are executed by computers in stand-alone or network environments. Generally, program modules include routines, programs, objects, components, and data structures, etc. that perform particular tasks or implement particular abstract data types. Computer-executable instructions, associated data structures, and program modules represent examples of the program code means for executing steps of the methods disclosed herein. The particular sequence of such executable instructions or associated data structures represents examples of corresponding acts for implementing the functions described in such steps.
Although the above description may contain specific details, they should not be construed as limiting the claims in any way. Other configurations of the described embodiments of the invention are part of the scope of this invention. For example, the principles of the invention may be applied to each individual user where each user may individually deploy such a system. This enables each user to utilize the benefits of the invention even if any one of the large number of possible applications do not need the functionality described herein. It does not necessarily need to be one system used by all end users. Accordingly, the appended claims and their legal equivalents should only define the invention, rather than any specific examples given.