Hello Jens,
This is the code of the class SaveData :
public class SaveData implements Serializable
{
private DemosProject proj;
private HashMap graphicData;
public SaveData(DemosProject project,HashMap imgData){
this.proj=project;
this.graphicData=imgData;
}
public void setProj(DemosProject project){
proj=project;
}
public void setGraphicData(HashMap imgData){
graphicData=imgData;
}
public DemosProject getProj(){
return proj;
}
public HashMap getGraphicData(){
return graphicData;
}
}
Any idea why it cannot be instantiate?
If you need more code of other things, tell me.
Cheers,
Katja
-----Urspr�ngliche Nachricht-----
Von: Jens Saade [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 4. M�rz 2004 10:12
An: [EMAIL PROTECTED]
Betreff: Re: [castor-dev] saving a java-project
Hi Katja,
comments inline ...
Katja wrote:
>Hello Jens,
>Thank you for answering my 'beginner questions'.
>
>I already thought that I cannot write to object to one file. I correct
>it by creating new class SaveData with two attributes -the two objects,
>I want to save. SaveData dataToSave=new
>SaveData(workingDemosProject,mapPositions);
> writer = new FileWriter(fileProject1);
>
>org.exolab.castor.xml.Marshaller.marshal(dataToSave,
>writer);
>//reading:
>SaveData
>savedData=(SaveData)org.exolab.castor.xml.Unmarshaller.unmarshal(SaveDa
t
>a.class,
> new FileReader(fileOpen));
>This is the new xml-file:
><?xml version="1.0" encoding="UTF-8" ?>
>- <save-data>
> - <proj>
> <objectkind-name>Entity</objectkind-name>
> - <entity-list xsi:type="java:Core.DemosEntity"
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <objectkind-name>Entity</objectkind-name>
> </entity-list>
> </proj>
> <graphic-data xsi:type="java:GUI.MainFrame$ImageAndPositionData"
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
> <graphic-data xsi:type="java:GUI.MainFrame$ImageAndPositionData"
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
> </save-data>
>
>This is the new exception, I'm getting while reading.
> org.xml.sax.SAXException: unable to instantiate GUI.SaveData;
>java.lang.InstantiationException: GUI.SaveData{file: [not available];
>line: 2; column: 12}
>What could cause the problem that GUI.SaveData cannot be instntiated?
>The class is public and serializable.
>
I can only guess without seeing the code. Please provide the relevant
code (or the parts of it).
>
>Do I really have to make any Attribute public, If I want to save
>it????It doesn't make any sense to me.
>
You should not access properties of an object from outside the object
directly, but write getter and setter methods for each variable. E.g.
private int testInt;
public int getTestInt(){
return testInt;
}
public void setTestInt(){
this.testInt = testInt;
}
Castor will you getters and setter if available (afaik).
>
>Maybe you can tell me which documentation I should read that I can
>solve more problems by myself. I thought I read the most important
>documentation of Castor but maybe it wasn't enought.
>
>Cheers,
>Katja
>
>-----Urspr�ngliche Nachricht-----
>Von: Jens Saade [mailto:[EMAIL PROTECTED]
>Gesendet: Mittwoch, 3. M�rz 2004 15:22
>An: [EMAIL PROTECTED]
>Betreff: Re: [castor-dev] saving a java-project
>
>
>
>Katja,
>the XML file is not valid if its one file. You are marshalling objects
>via the same writer into the same file, this results in two independant
>xml-structures appended in one file:
>
>-- file --
><?xml version="1.0" encoding="UTF-8"?>
><demos-project>
> <objectkind-name>Entity</objectkind-name>
> <entity-list xsi:type="java:Core.DemosEntity"
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <objectkind-name>Entity</objectkind-name>
> </entity-list>
></demos-project>
><?xml version="1.0" encoding="UTF-8"?>
><hash-map empty="false"/>
>-- file --
>
>... which is not valid XML. You either have to marshal into two
>different files or implement a root object that encapsulates both the
>DemosProject.class and the HashMap.
>Furthermore you can't read from a mixed invalid XML file into two
>different objects. That's why you get the
>
>org.xml.sax.SAXException: Parsing Error : The processing instruction
>target matching "[xX][mM][lL]" is not allowed.
>
>Cheers,
>Jens
>
>
>
>Katja wrote:
>
>
>
>>Well, let's try it step by step to solve my problems.
>>This is how I write to the xml-file:
>> writer = new FileWriter(fileProject1);
>> org.exolab.castor.xml.Marshaller.marshal(workingDemosProject,
>>writer);
>> org.exolab.castor.xml.Marshaller.marshal(mapPositions, writer);
>>
>>
>This
>
>
>>is how I read from the xml-file:
>> res.project=
>>(DemosProject)org.exolab.castor.xml.Unmarshaller.unmarshal(DemosProjec
t
>>.
>>class,
>> new FileReader(fileOpen));
>>
>>res.graphicData=(HashMap)org.exolab.castor.xml.Unmarshaller.unmarshal(
>>H
>>a
>>shMap.class,
>> new FileReader(fileOpen));
>>
>>The saving works without exception but the xml-file doesn't look ok (I
>>think). <?xml version="1.0" encoding="UTF-8"?>
>><demos-project><objectkind-name>Entity</objectkind-name><entity-list
>>xsi:type="java:Core.DemosEntity"
>>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><objectkind-name
>
>>
>>
>E
>
>
>>ntity</objectkind-name></entity-list></demos-project><?xml
>>
>>
>version="1.0"
>
>
>>encoding="UTF-8"?>
>><hash-map empty="false"/>
>>
>>When I read, I get following exception:
>>org.xml.sax.SAXException: Parsing Error : The processing instruction
>>target matching "[xX][mM][lL]" is not allowed. Line : 2 Column : 233
>>{file: [not available]; line: 2; column: 233}
>>
>>Here the structure of the two objects I want to save:
>>1. workingDemosProject is of Type DemosProject, ist superclass
>>DemosEntity(a) and has one Attribute of type DemosEntityList(b)
>> DemosEntity(a) has three Attributes. Their type is a
>>self-implemented class that extends a ArrayList .
>> DemosEntityList(b) is self-implemented class that extends a
>>ArrayList,too. 2. mapPositions is a Hashmap
>>
>>I hope these are good informations that you can help me.
>>
>>Cheers,
>>Katja
>>
>>
>>
>>-----Urspr�ngliche Nachricht-----
>>Von: Jens Saade [mailto:[EMAIL PROTECTED]
>>Gesendet: Mittwoch, 3. M�rz 2004 11:19
>>An: [EMAIL PROTECTED]
>>Betreff: Re: [castor-dev] saving a java-project
>>
>>
>>
>>Hi Katja,
>>
>>people on the mailing list can better help you on specific problems
>>you encounter. The best thing you can do is to describe each problem
>>with reference to your code (java/xml/xsd, etc) and develop it
>>step-by-step. Getting used to castor may take some time but in the end
>>this will pay off. I'm using castor for lots of projects since a while
>>(JDO and XML) and found the help on this list very useful. The more
>>specific the questions you ask the more answers you'll get =)
>>
>>Jens
>>
>>Katja wrote:
>>
>>
>>
>>
>>
>>>Hi,
>>>I'm trying to save my java-project to a xml-file and back. However my
>>>objects within the project are structured very complicated. I have
>>>sometime six level of superclasses or want to save a HashMap that
>>>contains not basic-objects. I thought castor can do this but I'm
>>>experiencing a lot of problems. Simple testing projects worked fine
>>>with Castor. Can someone give me advices what important is to watch
>>>
>>>
>for
>
>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>>or what kind of objects I cannot save? Or maybe Castor is not the
>>>right
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>>thing to use. I had found another class library that work very good
>>>but
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>>wasn't open-source.
>>>Cheers,
>>>Katja
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>
>
>
--
PIRONET NDH AG
Jens Saade - Application Developer - Business Center Industry Maarweg
149-161, 50825 Cologne - Germany
Phone: +49 (0)221-770-1794 - Fax: +49 (0)221-770 1005
Mail to: [EMAIL PROTECTED] - http://www.pironet-ndh.com
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev