Discussion:
How can I pass a Structure from ColdFusion to Java?
Troy Simpson
2005-02-09 00:01:38 UTC
Permalink
I have data in a coldfusion mx structure and I need to pass that
structure to a Java method. Anyone know how to do this or where I
might find an answer to this?

Also, what about other coldfusion datatypes?

Thanks,
Troy
--
Troy Simpson
Applications Analyst/Programmer, OCPDBA, MCSE, SCSA
North Carolina State University Libraries
Campus Box 7111 | Raleigh | North Carolina
ph.919.515.3855 | fax.919.513.3330
E-mail: Troy_Simpson-***@public.gmane.org

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:193764
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=13123.11886.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Adam Haskell
2005-02-09 00:23:11 UTC
Permalink
I don't think any complex datatype will transfer over to Java in a
snap...Most complex data types are vectors or something along that
lines...Heck depending on the function you are calling and the
overloading that might occur even a string might need to be
javacast()ed to get everything to play nice :) Sorry no good insight
on getting the structure over smoothly.

Adam H
Post by Troy Simpson
I have data in a coldfusion mx structure and I need to pass that
structure to a Java method. Anyone know how to do this or where I
might find an answer to this?
Also, what about other coldfusion datatypes?
Thanks,
Troy
--
Troy Simpson
Applications Analyst/Programmer, OCPDBA, MCSE, SCSA
North Carolina State University Libraries
Campus Box 7111 | Raleigh | North Carolina
ph.919.515.3855 | fax.919.513.3330
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:193766
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=13123.11886.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Barney Boisvert
2005-02-09 00:37:36 UTC
Permalink
You should be able to pass it as an instance of java.util.Map. Arrays
go as java.util.Vector, though they're pass by value in CF and pass by
reference in Java. Queries are javax.sql.ResultSet, I believe.
Numerics go in as type Double or double, unless you use JavaCast, and
dates go in as java.util.Date. And you can get a null using the
forDigit method of the Character class, should you need one. Note
that that's only a Java null, it won't work in CF as a null value.

That's for CFMX, things might have changed in CF7, though I doubt it.

cheers,
barneyb
Post by Troy Simpson
I have data in a coldfusion mx structure and I need to pass that
structure to a Java method. Anyone know how to do this or where I
might find an answer to this?
Also, what about other coldfusion datatypes?
Thanks,
Troy
--
Troy Simpson
--
Barney Boisvert
bboisvert-***@public.gmane.org
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 50 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:193767
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=13123.11886.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Troy Simpson
2005-02-09 01:07:26 UTC
Permalink
Thanks Barney.

I am writing the JAVA Class so I have control of how to define it.
I saw that I have to define a variable as java.util.Map.

Do you know how to do this in java, because java.util.Map is not a
class but an interface. The following line give me an error:

java.util.Map wc = new java.util.Map();

The compiler is giving me the following error:
"Cannot instantiate the type Map, since it is not a concrete class"

Thanks,
Troy
--
Troy Simpson
Applications Analyst/Programmer, OCPDBA, MCSE, SCSA
North Carolina State University Libraries
Campus Box 7111 | Raleigh | North Carolina
ph.919.515.3855 | fax.919.513.3330
E-mail: Troy_Simpson-***@public.gmane.org

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:193768
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=13123.11886.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Troy Simpson
2005-02-09 01:14:33 UTC
Permalink
Hey,
I want to add that I found this article at bpurcell.org:
http://www.bpurcell.org/blog/index.cfm?mode=entry&entry=925

It says that a ColdFusion Structure is an Object of type
coldfusion.runtime.Struct. Here is the inheritance change:

java.util.Hashtable
--coldfusion.util.FastHashtable
----coldfusion.runtime.Struct

Do you think I could use this data type in my Code like so?
coldfusion.runtime.Struct wc = new coldfusion.runtime.Struct();

Where would I find the libraries?
Would this be bad practice?

Thanks,
Troy
--
Troy Simpson
Applications Analyst/Programmer, OCPDBA, MCSE, SCSA
North Carolina State University Libraries
Campus Box 7111 | Raleigh | North Carolina
ph.919.515.3855 | fax.919.513.3330
E-mail: Troy_Simpson-***@public.gmane.org

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:193769
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=13123.11886.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Barney Boisvert
2005-02-09 01:23:58 UTC
Permalink
If you had the library, you could do this, but it'd be asking for
trouble, because the class might change names at some future point (or
maybe already has in CF7).

java.util.Hashtable implements java.util.Map, so therefore CF structs
also implement the interface. Your original question was about
passing a CF struct into Java. Since the CF struct implements the Map
interface, you can declare your parameter of type Map, and treat the
CF struct exactly as any other Map instance you might come across.

If, however, what you need to do is create a CF structure in Java and
return it to CF, you're in a bit of a bind. You can do it, but I
wouldn't. Rather, I'd just return a Map (your choice of
implementation) and then use it from your CF with the Map interface
(i.e. contains(), put(), get(), etc.) rather than the native CF struct
nomenclature. That'll give you more flexibility down the road, and
since you're already programming in Java, continuing to use the Java
methods shouldn't be a hassle. If nothing else, you can return the
Map from your Java method and then convert it into a CF struct.

As for your interface exception, you can't instantiate interfaces, you
have to instantiate a class that implements the interface.
java.util.Hashtable and java.util.HashMap are the most common choices
(the former is synchronized, the latter isn't), and there's a
java.util.TreeMap as well in the core JRE.

cheers,
barneyb
Post by Troy Simpson
Hey,
http://www.bpurcell.org/blog/index.cfm?mode=entry&entry=925
It says that a ColdFusion Structure is an Object of type
java.util.Hashtable
--coldfusion.util.FastHashtable
----coldfusion.runtime.Struct
Do you think I could use this data type in my Code like so?
coldfusion.runtime.Struct wc = new coldfusion.runtime.Struct();
Where would I find the libraries?
Would this be bad practice?
Thanks,
Troy
--
Barney Boisvert
bboisvert-***@public.gmane.org
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 50 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:193770
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=13123.11886.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Chris Jensen
2005-02-09 01:28:02 UTC
Permalink
Hi,
Are you passing from java to CF or CF to java?
Your subject suggests the later, but
Post by Troy Simpson
java.util.Map wc = new java.util.Map();
suggests the former.

Your compiler problem is easy enough to solve, use one of the java
implementations of map.
Head to the java doc at http://java.sun.com/j2se/1.4.2/docs/api, and
lookup Map, then close to the top of the doc for Map there will be a
list of "All Known Implementing Classes"
eg HashMap

(An interface in java merely describes methods that an object/class must
define to adhere to that interface, so you can't instantiate an
interface because it has no code to run those methods. You must find a
class that implements those methods and that interface)
Post by Troy Simpson
Do you think I could use this data type in my Code like so?
coldfusion.runtime.Struct wc = new coldfusion.runtime.Struct();
Where would I find the libraries?
Would this be bad practice?
You could probably do that, the libraries would probably be in a jar
somewhere in your CF server directory.
Though as you don't have access to any doc on it, you won't have a clear
definition of the objects behaviour (nor will maintainers of your code),
so you would probably be better off working with a java class you know,
either a predifined java class, or a specialised class if you require
that much specialisation.

Chris
--
---------------------------------------------------------------------
Chris Jensen cjensen-cAZcWrUPIDC6c6uEtOJ/***@public.gmane.org

Educational Experience (Australia)
Postal Address: PO Box 860, Newcastle NSW 2300
Freecall: 1-800-025 270 International: +61-2-4923 8222
Fax: (02) 4942 1991 International: +61-2-4942 1991

Visit our online Toy store! http://www.toysandmore.com.au/
---------------------------------------------------------------------


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:193771
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=13123.11886.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Troy Simpson
2005-02-11 23:17:30 UTC
Permalink
Thanks Chris,

Actually, I am doing both:
ColdFusion Structure to Java Map
and
Java Map to ColdFusion Structure.

Thanks,
Troy
--
Troy Simpson
Applications Analyst/Programmer, OCPDBA, MCSE, SCSA
North Carolina State University Libraries
Campus Box 7111 | Raleigh | North Carolina
ph.919.515.3855 | fax.919.513.3330
E-mail: Troy_Simpson-***@public.gmane.org

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:194382
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=13123.11886.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Continue reading on narkive:
Loading...