mwomack     2002/12/09 23:01:21

  Modified:    src/java/org/apache/log4j/xml DOMConfigurator.java
  Log:
  Added code to parse plugin elements and start the resulting plugin object.
  Added code to fire a configuration changed event on the repository being configured.
  
  Revision  Changes    Path
  1.52      +47 -4     jakarta-log4j/src/java/org/apache/log4j/xml/DOMConfigurator.java
  
  Index: DOMConfigurator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/DOMConfigurator.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- DOMConfigurator.java      16 Oct 2002 13:48:31 -0000      1.51
  +++ DOMConfigurator.java      10 Dec 2002 07:01:21 -0000      1.52
  @@ -87,6 +87,7 @@
     static final String INTERNAL_DEBUG_ATTR  = "debug";
     static final String RENDERING_CLASS_ATTR = "renderingClass";
     static final String RENDERED_CLASS_ATTR = "renderedClass";
  +  static final String PLUGIN_TAG = "plugin";
   
     static final String EMPTY_STR = "";
     static final Class[] ONE_STRING_PARAM = new Class[] {String.class};
  @@ -526,6 +527,40 @@
       LogLog.debug(catName + " level set to " + logger.getLevel());    
     }
   
  +  protected Plugin parsePlugin(Element pluginElement) {
  +    String className = subst(pluginElement.getAttribute(CLASS_ATTR));
  +    LogLog.debug("Creating plugin: [" + className+']');    
  +    try {
  +      Plugin plugin = (Plugin)Loader.loadClass(className).newInstance();
  +      PropertySetter propSetter = new PropertySetter(plugin);
  +
  +      plugin.setName(subst(pluginElement.getAttribute(NAME_ATTR)));
  +      
  +      NodeList children      = pluginElement.getChildNodes();
  +      final int length       = children.getLength();
  +      for (int loop = 0; loop < length; loop++) {
  +        Node currentNode = children.item(loop);
  +
  +        /* We're only interested in Elements */
  +        if (!isElement(currentNode)) {
  +          continue;
  +        }
  +     
  +        Element currentElement = (Element)currentNode;
  +  
  +             // Parse appender parameters 
  +             if (currentElement.getTagName().equals(PARAM_TAG)) {
  +               setParameter(currentElement, propSetter);     
  +             }
  +      }
  +      return plugin;
  +    } catch (Exception e) {
  +      LogLog.error("Could not create plugin. Reported error follows.",
  +                e);
  +      return null;
  +    }
  +  }
  +  
     protected void setParameter(Element elem, PropertySetter propSetter) {
       String name = subst(elem.getAttribute(NAME_ATTR));
       String value = (elem.getAttribute(VALUE_ATTR));
  @@ -759,19 +794,27 @@
       for (int loop = 0; loop < length; loop++) {
         currentNode = children.item(loop);
         if (!isElement(currentNode)) {
  -     continue;
  +        continue;
         }
         currentElement = (Element) currentNode;
         tagName = currentElement.getTagName();
         
         if (tagName.equals(CATEGORY) || tagName.equals(LOGGER)) {
  -     parseCategory(currentElement);
  +        parseCategory(currentElement);
         } else if (tagName.equals(ROOT_TAG)) {
  -     parseRoot(currentElement);
  +        parseRoot(currentElement);
         } else if(tagName.equals(RENDERER_TAG)) {
  -     parseRenderer(currentElement);
  +        parseRenderer(currentElement);
  +      } else if (tagName.equals(PLUGIN_TAG)) {
  +        Plugin plugin = parsePlugin(currentElement);
  +        if (plugin != null) {
  +          PluginRegistry.startPlugin(plugin, repository);
  +        }
         }
       }
  +        
  +    // let listeners know the configuration just changed
  +    repository.fireConfigurationChangedEvent();
     }
   
     
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to