Re: Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
- From: "Richard Maher" <maher_rj@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Feb 2007 23:00:25 +0800
Hi Arne,
Thanks for the reply.
There are certain possibilities in JavaScript, but I would do that
part in Java.
Looks like everyone's agreed on that.
You could extend your protocol to be flexible enough to convert[Followed by application specific protocol example. . .]
to and from a text format.
I agree. I will provide a getString() method that returns all of the byte[]
array from the last read; what the client and server code put in there is
their business. (XML if they really have to) IE: No offset or length
arguments and I call the other method with 0 and array.length.
You applet can easily load a class from the server.
With runtime discovery of the class name? How? What verb/method/incantation?
(Or just Jscript applet 2?)
Let the JavaScript send something to the Java applet that makes
it load a class from the serfer, if that is what you want.
I'll send it the class name or filename (eg: PAYROLL) how does one's Applet
now expose/surface PAYROLL's methods and constructors to Javascript and
html? (As well as making existing classes/methods available to PAYROLL)
java.math.BigDecimal is what you are looking for.
That's a relief! I am now also looking at BigInteger to convert 2 or 4 bytes
of my server byte stream to an integer. Does this sound sensible to you as
opposed to the various ">>" but shift examples on the web? IE: I move bytes
[1] to [4] and [2] to [3] (Have to check that?) and then BigInteger them;
sound good? Just to show how; everything in example 1 will be strings
anyway.
BTW. Can you have two (or N) methods in the same class that have the same
name and accept the same parameters but vary only in what they return? (IE
One returns an int and another returns a small)
Cheers Richard Maher
PS. Dragging on a bit, I know :-( Should finish this weekend.
"Arne Vajhøj" <arne@xxxxxxxxxx> wrote in message
news:45ce65b0$0$49203$14726298@xxxxxxxxxxxxxxxxxx
Richard Maher wrote:them,
The immutables are: -
1) I'm running in a Web browser and and am using a combo of html and
Javascript for the user interface.
2) There is an Applet that has established and authorized a Socket
connection back to a non-Java server
3) Data/Messages are exchanged in the form of Byte Arrays (ie Records)
4) The customer doesn't want to "Just do it all in Java" :-)
5) I am not interested in hearing about XDR or IDL, and if a given
application wants to use XML then good-luck to them, I will not stop
andbut for those of you left who are willing to think outside of the box,
please continue.
An example of what might happen is, the user enters an Employee Number
andas part of the validation a "Get Employee" message is sent to the server
twoin response either an "Employee Details" or an "Error" message will be
returned. (For argument's sake let's adopt the convention that the first
Detailsbytes of the message will be reserved for Message Id follow by a
message-specific body. "10" is Employee request, "11" is Employee
integerresponse and "99" is Lookup Error)
Anyway, if a "11" message comes back then we know 200 bytes of data will
follow which might have a Surname in a specific Character set, an
have.(little-endian) for base salary, and all the other crap that we all
and
Am I correct in assuming that there is simply no way that Javascript,
anits "var =" semantics, can deal with the complexities of character-set
theinteger-endian issues, and that one must call back to Java-proper with
guydocument.applet.method() functionality?
There are certain possibilities in JavaScript, but I would do that
part in Java.
The problem I'm faced with now is that I'm the infrastructure/middleware
andand I have no idea about an individual or specific Application's message
passing and formatting requirements. I have established an application
neutral, or generic, link to the host and authorized application access
butI have made available the conduit for interacting with the server code,
Javascript/htmI simply don't know what your subsequent messages will look like or what
they with contain. I give you a read method and a write method (and a
lovely sendUrgentData() method) but you have to provide the Class for
packing and unpacking the messages :-( How do I make your lovely
application-sepcific scatter/gather methods available to your
thatwhen I insist on controlling/owning the Applet?
You could extend your protocol to be flexible enough to convert
to and from a text format.
What you have now is:
applet->server:
10 (req emp info)
177 (emp id)
server->applet:
11 (resp emp info)
"Jones" (name)
80000 (salary)
or:
99 (resp err)
And that info is really not that easy to do js->applet and applet->js.
But look at:
js->applet:
"rec=10,narg=1,arg1=177"
applet->sever:
10 (req emp info)
1 (# args)
1 (type = int)
177 (int value)
server->applet:
11 (resp emp info)
2 (# args)
2 (type = string)
"Jones" (string value)
1 (type = int)
80000 (int value)
or:
99 (resp err)
0 (# args)
applet->js:
"rec=11,narg=2,arg1='Jones',arg2=80000"
or:
"rec=99"
The JavaScript guys should not have any problems formatting and
parsing those strings.
You can come up with a zillion different formats. But a single
method in the Java applet that receives a string as argument and
return a string with data packed in some format should work.
And the wire overhead is not that big.
Can my Applet dynamically load a Class? If I get an Applet Parameter
JVMsays PAYROLL can I not load codebase()payroll.class? OK, forget about my
applet loading the PAYROLL class; is there another way for the
Application-specific programmers to load their PAYROLL class into the
theand make them available to Javascript/html (who in turn will call my
send/recieve)?
> Perhaps a second Applet? How do they know about each other? Is there
> something in DOM that let's them share context? Is dynamic scripting
> answer?with
You applet can easily load a class from the server.
The JavaScript code could generate a new applet tag, but
I think that could get messy.
Let the JavaScript send something to the Java applet that makes
it load a class from the serfer, if that is what you want.
PS. I really like the look of nio sockets and the endian and charset
qualities of the buffers! But I have taken good advice and have stuck
andthe IO class and .net sockets. I am using getbytes(charset) for strings
right?)will REVERSE() work the endian magic or will I have to do that myself?
Data*Stream also looked good! (But only if they talk to each other,
DataInputStream/DataOutputStream always uses net order (big endian).
If you use them for byte arrays and 2/4/8 byte integers, then any
C sprogrammer should be able to communicate with them. Just avoid
using them directly for strings (instead you send 1 or 2 bytes
with length and N bytes with the bytes from the string).
PPS. It's a bit scary that I haven't stumbled across a Scaled Integer
class/primitive/necessity! Please don't tell me that Java uses floating
point primitives for Money. (Note to self: - What does Number class do?)
It does not.
java.math.BigDecimal is what you are looking for.
java.lang.Number is a base class for various classes containing
numeric values.
Arne
.
- Follow-Ups:
- References:
- Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
- From: Richard Maher
- Re: Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
- From: Arne Vajhøj
- Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
- Prev by Date: Re: How to convert .java file to exe file?
- Next by Date: Re: Weird behavior on allocation...what's going on?
- Previous by thread: Re: Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
- Next by thread: Re: Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
- Index(es):
Relevant Pages
|