RE: [Quickfix-developers] Casting from "Message" to "org.quickfix .fix42.QuoteRequest"
Brought to you by:
orenmnero
From: Alexandre H. <a....@ca...> - 2003-04-02 09:27:33
|
Hello, Many thanks for the ideas.=20 What I have done is to create my own message factory, which uses the "DefaultMessageFactory". My "create" method (see code below) takes as parameters :=20 - the begin string ("FIX.4.2"),=20 - the message type ("D")=20 - and the full FIX String: "8=3DFIX.4.2=019=3D136=0135=3DD=0134=3D16=0149=3DLeTrader02=0152=3D20030= 402-08:09:11=0156=3DLeBroker02 =0111=3DTrader_OrderID_1=0121=3D1=0138=3D1280=0140=3D1=0154=3D1=0155=3Dt= f1=0159=3D0=0160=3D20030402-08:09:11 =0110=3D104=01" The message I get can then be cast into = (org.quickfix.fix42.NewOrderSingle). The only problem is that the "create" method doesn't handle Quote = Requests (because of repeating groups). Is there a "setString" method that takes a full FIX String and returns = an object of class "org.quickfix.Message" that can be cast to "org.quickfix.fix42.QuoteRequest" for example ? Alternately, I think I should write a second "create" method that = handles repeating groups. Thanks, Alexandre ****** public Message create(String beginString, String msgType,String str) { =09 Message message =3D new Message() ; try { =09 MessageFactory messageFactory =3D new DefaultMessageFactory(); message =3D messageFactory.create(beginString, msgType); =09 StringTokenizer st =3D new StringTokenizer(str, "\1"); while(st.hasMoreTokens()) { String tag=3Dst.nextToken(); StringTokenizer st2 =3D new StringTokenizer(tag, "=3D");=20 int tagID =3D Integer.parseInt(st2.nextToken()); String tagValue =3D st2.nextToken(); =09 if ((tagID !=3D35) && (tagID !=3D8) && (tagID !=3D10) && (tagID !=3D9)) { message.setString(tagID,tagValue); } } } =09 catch(Exception e ) { e.printStackTrace(); } return message;=09 }=09 ****** -----Message d'origine----- De : OM...@th... [mailto:OM...@th...] Envoy=E9 : mercredi 2 avril 2003 01:49 =C0 : Alexandre Hoang Cc : Olivier Bonheur; 'qui...@li...'; qui...@li... Objet : Re: [Quickfix-developers] Casting from "Message" to "org.quickfix.fix42.QuoteRequest" There is a couple of ways to do this, depending on how much type safety = you want. If you want to conitinue using the base Message class, you just = need to start using the non-type safe getField method instead of get. If = you want to be able to get a class that represents the message type, you = can use the DefaultMessageFactory class to create the derived message = class. You need to pass in a valid beginstring and a msgtype. To do this it might be worthwhile to put the values of just those two fields in separate columns in your database. Then you can pull them = out, pass them into the factory, and call setString using your stored = string. Then you will be able to cast the resulting message to the appropriate type. --oren -------------------------------------------------------- =20 >-----------------------------------------------------------------------= ---- -------------------| | | | To: "'qui...@li...'" | | <qui...@li...> | | cc: Olivier Bonheur <o.b...@ca...> | | Subject: [Quickfix-developers] Casting from "Message" to | | "org.quickfix.fix42.QuoteRequest" | =20 >-----------------------------------------------------------------------= ---- -------------------| Hello, I archive the FIX messages I receive through QuickFIX in an SQL Server database. Basically, if I receive a quote request, encapsulated in an object of = class "QuoteRequest", I do: "aQuoteRequest.toString()" and I put the string in the database. Now I want to retrieve from my database the quote request. So I first = use a query to get the string I have just stored. Then a can create a Message: Message aMessage =3D new Message(stringRetrievedFromDB); But then, I cannot do the following: Symbol aSymbol =3D new Symbol(); aMessage.get(aSymbol); // does not work ! I actually need to cast to the "Message" to "org.quickfix.fix42.QuoteRequest". But this is not possible: I get a class cast exception. Is there a way to do this casting ? Or is there a better way to archive messages ? I have thought of = archiving the tags one by one, but doing with makes it more difficult to = reconstruct an object of class "Message". Thanks for any idea, Alexandre -------------------------------------------------------- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * = * *=20 Confidentiality Notice :=20 The information contained in this e-mail message is intended only for = the personal and confidential use of the recipient(s) named above. If the = reader of this message is not the intended recipient or an agent responsible = for delivering it to the intended recipient, you are hereby notified that = you have received this document in error and that any review, = dissemination, distribution, or copying of this message is strictly prohibited. If you = have received this communication in error, please notify = pos...@ca... immediately by e-mail, and delete the original message. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * = * *=20 |