From: David A. <web...@av...> - 2009-03-13 13:17:55
|
Out of curiosity, why are you doing this? Why not just use a to-many relationship? This seems like a awful lot of work just to do something that EOF will do for you without even blinking. Dave On Mar 12, 2009, at 7:24 PM, Amedeo Mantica wrote: > Hi, I finally solved serializing all in XML (just to get data human > readable) than storing it as string > > I created custom methods for gettng and setting my array, now > everything is working fine :-) > > Thanks :-) > > Here the piece of code for my entity: > > protected byte[] serialize(NSArray preSerialized) { > byte[] result = new byte[0]; > > try { > ByteArrayOutputStream os = new ByteArrayOutputStream(); > BufferedOutputStream bos = new BufferedOutputStream(os); > NSXMLOutputStream xmlStream = new NSXMLOutputStream(bos); > NSXMLOutputFormat format = new NSXMLOutputFormat(true); > format.setEncoding("UTF-8"); > xmlStream.setOutputFormat(format); > > xmlStream.writeObject(preSerialized); > > // Close the streams. > xmlStream.flush(); > xmlStream.close(); > bos.close(); > os.close(); > > result = os.toByteArray(); > > } catch (IOException ioe) { > ioe.printStackTrace(); > } > > > return result; > } > > > public NSArray<CFNewsLetterItem> deserialize(String serialized) { > > NSArray<CFNewsLetterItem> result = null; > > try { > ByteArrayInputStream is = new > ByteArrayInputStream(serialized.getBytes("UTF-8")); > BufferedInputStream bis = new java.io.BufferedInputStream(is); > NSXMLInputStream xmlStream = new NSXMLInputStream(bis); > > result = (NSArray<CFNewsLetterItem>)xmlStream.readObject(); > > // Close the streams. > xmlStream.close(); > bis.close(); > is.close(); > } catch (IOException ioe) { > ioe.printStackTrace(); > } catch (ClassNotFoundException cnfe) { > cnfe.printStackTrace(); > } > > return result; > } > > > public void setStaticArticles(NSArray<CFNewsLetterItem> a) { > super.setStaticArticles( new String(serialize(a)) ); > } > > public NSArray<CFNewsLetterItem> staticArticlesList() { > return deserialize(super.staticArticles()); > } > > > > and the serializer code on my CFNewsLetterItem class > > > private void writeObject(java.io.ObjectOutputStream out) throws > java.io.IOException { > NSXMLOutputStream xml_stream = (NSXMLOutputStream)out; > xml_stream.writeObject(title); > xml_stream.writeObject(link); > xml_stream.writeObject(area); > xml_stream.writeObject(categoria); > } > > private void readObject(java.io.ObjectInputStream in) throws > java.io.IOException, java.lang.ClassNotFoundException { > title = (String) in.readObject(); > link = (String) in.readObject(); > area = (String) in.readObject(); > categoria = (String) in.readObject(); > } > > > > Amedeo > > > > > On 12/mar/09, at 23:29, Mike Schrag wrote: > >> It looks to me like you're trying to use that array type prototype >> but >> with EO's as the values in the array ... that's a HUUUGE recipe for >> disaster ... that arrayType is intended for generally primitive types >> (you have an array of Strings, or something like that). If you have >> an array of EO's, that should be a to-many relationship. If you >> really don't want to dothat for some reason, then you could MAYBE use >> the ERXEOControlUtils method to convert your array of EO's to an >> array >> of GIDs, but even that probably won't serialize into a plist ... >> without knowing more, I'm definitely putting this in the "smells >> fishy" category. >> >> On Mar 12, 2009, at 6:13 PM, Amedeo Mantica wrote: >> >>> ? >>> >>> On 12/mar/09, at 21:50, Chuck Hill wrote: >>> >>>> >>>> On Mar 12, 2009, at 12:33 PM, Amedeo Mantica wrote: >>>> >>>>> ok, so I'm going to switch to plists... but i'm still having some >>>>> trouble >>>>> >>>>> i get this in the generated plist >>>>> >>>>> PLIST: ( >>>>> "it.chieti.confindustria.CFNewsLetterItem@a1d7d9", >>>>> "it.chieti.confindustria.CFNewsLetterItem@621a25" >>>>> ) >>>>> >>>>> should i need to implement something in the CFNewsLetterItem >>>>> class ? >>>>> >>>>> regards >>>>> Amedeo >>>>> >>>>> On 12/mar/09, at 19:44, Chuck Hill wrote: >>>>> >>>>>> It is a bug, either in EOF or in the FrontBase plugin. I am not >>>>>> sure which. File a bug report with Apple. >>>>>> >>>>>> >>>>>> Chuck >>>>>> >>>>>> >>>>>> On Mar 12, 2009, at 10:27 AM, Amedeo Mantica wrote: >>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> I have seen that there is the prototype mutableArray in the >>>>>>> EOModeler >>>>>>> >>>>>>> >>>>>>> I'm using FrontBase, this prototype by default set external type >>>>>>> BLOB and use methods fromBlob e toBlob >>>>>>> >>>>>>> My entity is called CFNewsLetter, here the piece on >>>>>>> _CFNewsLetter >>>>>>> >>>>>>> public ERXMutableArray staticArticles() { >>>>>>> return (ERXMutableArray) storedValueForKey("staticArticles"); >>>>>>> } >>>>>>> >>>>>>> public void setStaticArticles(ERXMutableArray value) { >>>>>>> if (_CFNewsLetter.LOG.isDebugEnabled()) { >>>>>>> _CFNewsLetter.LOG.debug( "updating staticArticles from " + >>>>>>> staticArticles() + " to " + value); >>>>>>> } >>>>>>> takeStoredValueForKey(value, "staticArticles"); >>>>>>> } >>>>>>> >>>>>>> now, static aticle is an object that have whit his serializable >>>>>>> methods, the class is called CFNewsLetterItem, here the relevant >>>>>>> piece of code: >>>>>>> >>>>>>> >>>>>>> public class CFNewsLetterItem implements Serializable { >>>>>>> >>>>>>> /** >>>>>>> * >>>>>>> */ >>>>>>> private static final long serialVersionUID = >>>>>>> 782612934512287294L; >>>>>>> protected String title; >>>>>>> protected String link; >>>>>>> protected String area; >>>>>>> protected String categoria; >>>>>>> >>>>>>> private void writeObject(java.io.ObjectOutputStream stream) >>>>>>> throws java.io.IOException { >>>>>>> stream.writeObject(title); >>>>>>> stream.writeObject(link); >>>>>>> stream.writeObject(area); >>>>>>> stream.writeObject(categoria); >>>>>>> } >>>>>>> >>>>>>> private void readObject(java.io.ObjectInputStream in) throws >>>>>>> java.io.IOException, java.lang.ClassNotFoundException { >>>>>>> title = (String) in.readObject(); >>>>>>> link = (String) in.readObject(); >>>>>>> area = (String) in.readObject(); >>>>>>> categoria = (String) in.readObject(); >>>>>>> } >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> Now, storing is working fine, but when I try to read object I >>>>>>> have this cast error >>>>>>> >>>>>>> Sure I'm missing something, but I don't know where, this is the >>>>>>> rist time I store array is database. >>>>>>> >>>>>>> Can you help me? >>>>>>> Regards >>>>>>> Amedeo >>>>>>> >>>>>>> >>>>>>> >>>>>>> Mar 12 18:16:56 ConfindustriaNet[22500] INFO >>>>>>> er.transaction.adaptor.Exceptions - Database Exception occured: >>>>>>> java.lang.ClassCastException: >>>>>>> er.extensions.foundation.ERXMutableArray >>>>>>> Mar 12 18:16:56 ConfindustriaNet[22500] WARN NSLog - >>>>>>> <com.webobjects.appserver._private.WOComponentRequestHandler>: >>>>>>> Exception occurred while handling request: >>>>>>> java.lang.ClassCastException: >>>>>>> er.extensions.foundation.ERXMutableArray >>>>>>> [2009-3-12 18:16:56 CET] <WorkerThread0> >>>>>>> java.lang.ClassCastException: >>>>>>> er.extensions.foundation.ERXMutableArray >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .jdbcadaptor.JDBCColumn._fetchCorrectObject(JDBCColumn.java:273) >>>>>>> at >>>>>>> com >>>>>>> .webobjects.jdbcadaptor.JDBCColumn._fetchValue(JDBCColumn.java: >>>>>>> 384) >>>>>>> at >>>>>>> com >>>>>>> .webobjects.jdbcadaptor.JDBCColumn.fetchValue(JDBCColumn.java: >>>>>>> 372) >>>>>>> at >>>>>>> com >>>>>>> .webobjects.jdbcadaptor.JDBCChannel.fetchRow(JDBCChannel.java: >>>>>>> 1462) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .eoaccess.EODatabaseChannel._fetchObject(EODatabaseChannel.java: >>>>>>> 321) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .eoaccess >>>>>>> .EODatabaseContext >>>>>>> ._objectsWithFetchSpecificationEditingContext >>>>>>> (EODatabaseContext.java:3071) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .eoaccess >>>>>>> .EODatabaseContext >>>>>>> .objectsWithFetchSpecification(EODatabaseContext.java:3195) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .eocontrol >>>>>>> .EOObjectStoreCoordinator >>>>>>> .objectsWithFetchSpecification(EOObjectStoreCoordinator.java: >>>>>>> 488) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .eocontrol >>>>>>> .EOEditingContext >>>>>>> .objectsWithFetchSpecification(EOEditingContext.java:4069) >>>>>>> at >>>>>>> er >>>>>>> .extensions.eof.ERXEC.objectsWithFetchSpecification(ERXEC.java: >>>>>>> 1114) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .eocontrol >>>>>>> .EOEditingContext >>>>>>> .objectsWithFetchSpecification(EOEditingContext.java:4444) >>>>>>> at >>>>>>> it >>>>>>> .chieti >>>>>>> .confindustria >>>>>>> .components >>>>>>> .CFPGNewsLetterList.appendToResponse(CFPGNewsLetterList.java:29) >>>>>>> at >>>>>>> com >>>>>>> .webobjects.appserver.WOSession.appendToResponse(WOSession.java: >>>>>>> 1385) >>>>>>> at >>>>>>> er >>>>>>> .extensions >>>>>>> .appserver.ERXSession.appendToResponse(ERXSession.java: >>>>>>> 540) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver.WOApplication.appendToResponse(WOApplication.java: >>>>>>> 1794) >>>>>>> at >>>>>>> er >>>>>>> .extensions >>>>>>> .appserver.ERXApplication.appendToResponse(ERXApplication.java: >>>>>>> 1639) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver >>>>>>> ._private >>>>>>> .WOComponentRequestHandler >>>>>>> ._dispatchWithPreparedPage(WOComponentRequestHandler.java:242) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver >>>>>>> ._private >>>>>>> .WOComponentRequestHandler >>>>>>> ._dispatchWithPreparedSession(WOComponentRequestHandler.java: >>>>>>> 298) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver >>>>>>> ._private >>>>>>> .WOComponentRequestHandler >>>>>>> ._dispatchWithPreparedApplication >>>>>>> (WOComponentRequestHandler.java: >>>>>>> 332) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver >>>>>>> ._private >>>>>>> .WOComponentRequestHandler >>>>>>> ._handleRequest(WOComponentRequestHandler.java:369) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver >>>>>>> ._private >>>>>>> .WOComponentRequestHandler >>>>>>> .handleRequest(WOComponentRequestHandler.java:442) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver.WOApplication.dispatchRequest(WOApplication.java: >>>>>>> 1687) >>>>>>> at >>>>>>> er >>>>>>> .extensions >>>>>>> .appserver >>>>>>> .ERXApplication.dispatchRequestImmediately(ERXApplication.java: >>>>>>> 1737) >>>>>>> at >>>>>>> er >>>>>>> .extensions >>>>>>> .appserver.ERXApplication.dispatchRequest(ERXApplication.java: >>>>>>> 1702) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver._private.WOWorkerThread.runOnce(WOWorkerThread.java: >>>>>>> 144) >>>>>>> at >>>>>>> com >>>>>>> .webobjects >>>>>>> .appserver._private.WOWorkerThread.run(WOWorkerThread.java:226) >>>>>>> at java.lang.Thread.run(Thread.java:613) >>>>>>> >>>>>>> ------------------------------------------------------------------------------ >>>>>>> Apps built with the Adobe(R) Flex(R) framework and Flex >>>>>>> Builder(TM) are >>>>>>> powering Web 2.0 with engaging, cross-platform capabilities. >>>>>>> Quickly and >>>>>>> easily build your RIAs with Flex Builder, the Eclipse(TM)based >>>>>>> development >>>>>>> software that enables intelligent coding and step-through >>>>>>> debugging. >>>>>>> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com_______________________________________________ >>>>>>> Wonder-disc mailing list >>>>>>> Won...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/wonder-disc >>>>>> >>>>>> -- >>>>>> Chuck Hill Senior Consultant / VP Development >>>>>> >>>>>> Practical WebObjects - for developers who want to increase their >>>>>> overall knowledge of WebObjects or who are trying to solve >>>>>> specific problems. >>>>>> http://www.global-village.net/products/practical_webobjects >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>> >>>> -- >>>> Chuck Hill Senior Consultant / VP Development >>>> >>>> Practical WebObjects - for developers who want to increase their >>>> overall knowledge of WebObjects or who are trying to solve specific >>>> problems. >>>> http://www.global-village.net/products/practical_webobjects >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) >>> are >>> powering Web 2.0 with engaging, cross-platform capabilities. Quickly >>> and >>> easily build your RIAs with Flex Builder, the Eclipse(TM)based >>> development >>> software that enables intelligent coding and step-through debugging. >>> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com >>> _______________________________________________ >>> Wonder-disc mailing list >>> Won...@li... >>> https://lists.sourceforge.net/lists/listinfo/wonder-disc >> >> >> >> ------------------------------------------------------------------------------ >> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) >> are >> powering Web 2.0 with engaging, cross-platform capabilities. >> Quickly and >> easily build your RIAs with Flex Builder, the Eclipse(TM)based >> development >> software that enables intelligent coding and step-through debugging. >> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com >> _______________________________________________ >> Wonder-disc mailing list >> Won...@li... >> https://lists.sourceforge.net/lists/listinfo/wonder-disc >> > > ------------------------------------------------------------------------------ > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) > are > powering Web 2.0 with engaging, cross-platform capabilities. Quickly > and > easily build your RIAs with Flex Builder, the Eclipse(TM)based > development > software that enables intelligent coding and step-through debugging. > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com_______________________________________________ > Wonder-disc mailing list > Won...@li... > https://lists.sourceforge.net/lists/listinfo/wonder-disc |