Hello,
it seems to be quite easy to generate a Graphical Dependency Visualization from one or more spring configuration files.
One option would be to use XSLT to transform a spring configuration file to a graph-Format which can
be displayed by e.g. yEd - Java™ Graph Editor ( http://www.yworks.com/en/products_yed_about.html ).
For instance .graphml ( http://graphml.graphdrawing.org/ )
If you want to do this programatically then you would need to do the following (at least that's how I did it):
1) Create a Custom implementation of IObjectDefinitionRegistry which simply delegates to an Dictionary.
2) Create a XmlObjectDefinitionReader which uses the custom ObjectDefinitionRegistry in order to read the ObjectDefinitions found within the given config locations
3) Loop over all ObjectDefinitions in your ObjectDefinitionRegistry
4) For each ObjectDefinition you have to analyze it's dependencies ( -> objectDefinition.PropertyValues.PropertyValues)
If you encounter a RuntimeObjectReference (then you found an entry like <property name="SessionFactory" ref="sessionFactory"/> )
An ObjectDefinition is a Node and a Dependency (e.g. via ref="..." or inline ObjectDefinition) is an Edge.
With this approach I generated a simple graph from this Spring Configuration as you can see in the attached image.
Code:
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object name="personService"
type="De.Tutorials.Training.Spring.Services.Internal.PersonService,SpringTraining">
<property name="personDAO" ref="personDAO"/>
</object>
<object name="personDAO"
type="De.Tutorials.Training.Spring.DAO.Internal.PersonDAO,SpringTraining">
<property name="SessionFactory" ref="sessionFactory"/>
</object>
<!-- object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="ConfigSections" value="databaseSettings"/>
</object -->
<object id="dbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data">
<property name="ConnectionString" value="Data Source=localhost;Initial Catalog=test;User Id=root;Password=tutorials"/>
</object>
<object id="sessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate">
<property name="dbProvider" ref="dbProvider"/>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MySQLDialect"/>
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver"/>
<!-- entry key="hibernate.connection.connection_string" value="Data Source=localhost;Initial Catalog=test;User Id=root;Password=tutorials"/ -->
</dictionary>
</property>
<property name="MappingAssemblies">
<list>
<value>SpringTraining</value>
</list>
</property>
</object>
<object id="hibernateTransactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate">
<property name="dbProvider" ref="dbProvider"/>
<property name="sessionFactory" ref="sessionFactory"/>
</object>
</objects>
Best regards,
Thomas