From: Kal A. <ka...@te...> - 2001-07-30 14:12:28
|
Hi René > for a long time I'm working with Topic Maps and since a the last > weeks I'm dealing with TM4J. I'm able to create the several > objects in memory, to write the topic map into a file and to read > files with TM4J. > But if I try to write a topic map I created, that also includes > associations, into a file, then everything is written in the > right manner except the associations. > The associations are always omitted. > > I create the association like the following: > > TopicMapFactoryImpl tmfi = new TopicMapFactoryImpl(); > Topic t = tmfi.createTopic( "associationTopic" ); > Association a = tmfi.createAssociation( "association", t ); > Member m1 = tmfi.createMember( a, "m1" ); > Member m2 = tmfi.createMember( a, "m2" ); > m1.addPlayer( tmfi.createTopic( "m1" ) ); > m2.addPlayer( tmfi.createTopic( "m2" ) ); > > > Could you tell me what I've done wrong? > Err...nothing! This looks like a bug in the TopicMapFactoryImpl.java class - when you call createTopic(), the factory both creates the Topic and also adds it to the TopicMap. When you call createAssociation(), the Association is created, but not added to the TopicMap - you need to call TopicMap.addAssociation() explicitly. I'm guessing that your code example missed out the call tmfi.createTopicMap() ? If not, then you need to call that before creating your topics and associations, then you can use the TopicMap object returned from that to add the association explicitly, so your code should be something like: TopicMapFactoryImpl tmfi = new TopicMapFactoryImpl(); TopicMap tm = tmfi.createTopicMap(); Topic t = tmfi.createTopic( "associationTopic" ); Association a = tmfi.createAssociation( "association", t ); Member m1 = tmfi.createMember( a, "m1" ); Member m2 = tmfi.createMember( a, "m2" ); m1.addPlayer( tmfi.createTopic( "m1" ) ); m2.addPlayer( tmfi.createTopic( "m2" ) ); tm.addAssociation(a); It does not matter whether you call tm.addAssociation() before or after creating the members. Hope this helps, Kal |