I mimic current metadata classes but add more data, for example, for EntityMetaData (so that, i can get rid of JDBC<xxx>MetaData).
It would be easier to look at the code really.


It is based on SAXParser and MetaDataContentHandler which delegates to MetaDataFactory implementation (e.g. EjbJarMetaDataFactory, JBossCMPMetaDataFactory, etc)
Metadata factory is the source for metadata objects. When a new element is read, the factory is asked for a new corresponding metadata object. The factory can return null (meanning ignore this child). The returned metadata object is pushed in a stack.
Then we read another element and call the factory for a new metadata object passing in the parent metadata object from the stack, namesapce URI and element name. Again, the factory can ignore by returing null, or return a new new object.
When some text value is read, we call the factory with the current metadata object on the stack, element namesapce URI, element name and text value. This way I initialize the fields.
Finally, when the element is read from the file, I pop the element from the stack, peek its parent from the stack and call factory to add the child to the parent. At this time child also can be validated.


I don't use any special interfaces for metadata objects. The methods are discovered by introspection. For example, from EjbJarMetaDataFactory:

// started a new element
public Object newChild(ApplicationMetaData appMetaData, String namespaceURI, String qName)
{
Object child = null;
if("entity".equals(qName))
{
child = new EntityMetaData(appMetaData);
}
return child;
}


public void addChild(ApplicationMetaData appMetaData, EntityMetaData entity)
   throws MetaDataException
{
   // entity is done, can be validated and added
   appMetaData.addEntityBean(entity);
}

public void setValue(EntityMetaData entity, String namespaceURI, String name, String value)
{
if("ejb-name".equals(name))
{
entity.setEjbName(value);
entity.setTableName(value);
}
else if("home".equals(name))
{
entity.setHome(value);
}
else if("remote".equals(name))
...



This how it looks at the end:


ApplicationMetaData metadata = new ApplicationMetaData();

MetaDataReader reader = new MetaDataReader();

      InputStream is = getResource("ejb-jar.xml");
      MetaDataFactory factory = new EjbJarMetaDataFactory(metadata);
      reader.setMetaDataFactory(factory);
      reader.parse(is);
      is.close();

      is = getResource("jboss.xml");
      factory = new JBossMetaDataFactory(metadata);
      reader.setMetaDataFactory(factory);
      reader.parse(is);
      is.close();

      is = getResource("jbosscmp-jdbc.xml");
      factory = new JBossCMPMetaDataFactory(metadata);
      reader.setMetaDataFactory(factory);
      reader.parse(is);
      is.close();

At the end I have ApplicationMetaData populated from all the files. Only EjbJar factory creates objects, other factories populate existing ones.

julien viet wrote:

in what classe are you storing your metadata in what you wrote ? Typed
classes (Like EntityMetadata we have now) or generic untyped (like DOM) ?

please describe it

julien





------------------------------------------------------- This SF. Net email is sponsored by: GoToMyPC GoToMyPC is the fast, easy and secure way to access your computer from any Web browser or wireless device. Click here to Try it Free! https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl _______________________________________________ JBoss-Development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to