Announcement Announcement Module
Collapse
No announcement yet.
Creating own .XML beans descriptor. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating own .XML beans descriptor.

    Hello forum people.

    I am going to venture on a journey to build my own beans .xml descriptor.

    Not that I don't like the current one, but it takes too much time to write one, and id does suffer from slight over-head and overcomplication.

    My idea is to do something like the eclipse plugin descriptor. I.e.:
    Code:
    <beans import="java.net.*,java.util.*,test.ImportedClass">
      <bean id="testBean" class="example.Bean">
        <_constructor>
          <argument pos="0" class="example.ConstructorArgumentClass"/>
          <!-- InetAddress is imported. -->
          <argument pos="0" class="InetAddress" method="getLocalAddress"/>
        </_constructor>
        <name>Test</name>
        <description value="Description"/>
        <icon>images/Test.gif</icon>
        <owner ref="owner"/>
        <data class="example.DataImpl"/>
          <dataProperty value="12345"/>
          <someOtherProperty local="testBean"/>
          <localIP value="$&#123;java.rmi.server.exportHost&#125;"/>
        </data>
        <listProperty class="ArrayList"> <!-- imported -->
          <element string="Alabala"/>
          <element int="12345"/>
          <element class="example.DataImpl"/>
        </listProperty>
      </bean>
      <!-- Support for loading stuff from the xml descriptor. -->
      <bean class="spring.ext.InetAddressDOMLoader"/>
    </beans>
    While this is harder to support, it is a lot more readable. Also the spring-doc says that the descriptor has been made to be written by people. This one I think will be much easier to write.

    What do you think?

    Do you have any pointers as to where I should start from, and does the spring framework provide extendability points for such an activity?

  • #2
    I guess you should be looking at BeanDefinitionReader and AbstractBeanDefinitionReader. These are the objects used by a bean factory (e.g. XmlBeanFactory) to load the bean definitions and register them with a BeanDefinitionRegistry, typically DefaultListableBeanFactory.

    Spring provides 2 bean definition readers out of the box: PropertiesBeanDefinitionReader and XmlBeanDefinitionReader. You could provide a new one to support your definition format.

    Erwin

    Comment


    • #3
      I guess simplifications of the bean descriptor can also be classified as syntax sugar [ see for example, http://c2.com/cgi/wiki?SyntacticSugar"].

      There are many ways to do this. Extensions as mentioned in the repllies, but perhaps a generative approach is possible? An xsl transform can expand the sugar into the standard DTD instance.

      j. betancourt

      Comment


      • #4
        Thank you.

        Thank you both.
        I was just making sure it is possible.
        I have experience in writing parsers/readers/configurators this way, so if Spring is not getting in the way I would be able to do that.

        Comment

        Working...
        X