Announcement Announcement Module
Collapse
No announcement yet.
locate subclasses of abstract class/interface Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • locate subclasses of abstract class/interface

    I have following problem:
    I need to split application into two parts:
    core part and plugin parts, which will define plugin dependent parts of core objects. Core object should not reference any plugin parts.
    Only binding between mentioned parts should be done in the web.xml file, where the config files for the BeanFactory are defined.
    Core objects should be able to enumerate all plugin parts, which are present in the classpath(or in BeanFactory configuration)


    It is possible to this with Spring?
    Is there any possibility to find all subclasses of defined abstract class/interface in all config files ?

  • #2
    Re: locate subclasses of abstract class/interface

    Originally posted by ferencvaros
    I have following problem:
    I need to split application into two parts:
    core part and plugin parts, which will define plugin dependent parts of core objects. Core object should not reference any plugin parts.
    Only binding between mentioned parts should be done in the web.xml file, where the config files for the BeanFactory are defined.
    Core objects should be able to enumerate all plugin parts, which are present in the classpath(or in BeanFactory configuration)
    Why do so difficult?

    Plugin example:
    Code:
    <bean	id="pluginManager"
    		class="PluginManager">
    	
    	<constructor-arg>
    		<list>
    			<bean class="HtmlPlugin"/>
    			<bean class="PdfPlugin"/>
    			<bean class="TextPlugin"/>
    		</list>
    	</constructor-arg>	
    </bean>
    It is possible to this with Spring?
    If it is possible in Java it is possible in Spring. Don`t let Spring drive your design.. You are in control of your design, so you decide how you want it.

    Is there any possibility to find all subclasses of defined abstract class/interface in all config files ?
    I don`t think you want this. I prefer to register me plugins myself and don`t want to scan the whole classpath. This allows greater control what to use and what not to use. Sometimes you don`t want something but does exist as a classfile.

    Comment


    • #3
      Problem with your approach is, that in your example you directly defined beans references, names and amount of beans. But if you want to extend application to the new plugin, you must edit the file in the core part and that's the problem.
      I need to locate all plugins (all defined plug-in subclasses of abstract core class) whithout directly referencing them in the core part.

      Comment


      • #4
        I found class BeanFactoryUtils which contains beansOfTypeIncludingAncestors() method. Maybe this will help.

        Comment


        • #5
          Originally posted by ferencvaros
          Problem with your approach is, that in your example you directly defined beans references, names and amount of beans. But if you want to extend application to the new plugin, you must edit the file in the core part and that's the problem.
          Hmm.. normally I don`t find this a problem. In the appcontext I create a concrete application with specific functionality.

          I need to locate all plugins (all defined plug-in subclasses of abstract core class) whithout directly referencing them in the core part.
          Hmm.. but how are you going to deal with unwanted plugins? You don`t have control. Is it not a lot easier that you register the plugins yourself?

          If you really want to seperate it, you could use multiple appcontext-files. One core file with no specific functionality. And one concrete part where you could locate the pluginmanager en register your plugins.

          Comment


          • #6
            control over registered plugins will be only via appcontext config-file entry in the web.xml file - each plugin will define its own appcontext config file

            Comment


            • #7
              now, it works.

              I defined bean pluginManager in the core part, then I defined bean factory postprocessor, which call method:
              Code:
              BeanFactoryUtils.beansOfTypeIncludingAncestors&#40;factory, AbstractNeNavigator.class&#41;
              and return value sets to the pluginManager as reference.

              Comment

              Working...
              X