You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2005/01/05 19:27:15 UTC

cvs commit: logging-log4j/src/java/org/apache/joran/action NestComponentIA.java

ceki        2005/01/05 10:27:15

  Modified:    src/java/org/apache/joran/action NestComponentIA.java
  Log:
  Pass repository information along to sub-components.
  
  Revision  Changes    Path
  1.16      +4 -1      logging-log4j/src/java/org/apache/joran/action/NestComponentIA.java
  
  Index: NestComponentIA.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/joran/action/NestComponentIA.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- NestComponentIA.java	22 Nov 2004 17:05:13 -0000	1.15
  +++ NestComponentIA.java	5 Jan 2005 18:27:15 -0000	1.16
  @@ -22,6 +22,7 @@
   
   import org.apache.log4j.config.PropertySetter;
   import org.apache.log4j.helpers.Loader;
  +import org.apache.log4j.spi.Component;
   import org.apache.log4j.spi.ErrorItem;
   import org.apache.log4j.spi.OptionHandler;
   
  @@ -101,7 +102,9 @@
           className);
   
         actionData.nestedComponent = Loader.loadClass(className).newInstance();
  -
  +      if(actionData.nestedComponent instanceof Component) {
  +        ((Component) actionData.nestedComponent).setLoggerRepository(this.repository);
  +      }
         getLogger().debug(
           "Pushing component <{}> on top of the object stack.", localName);
         ec.pushObject(actionData.nestedComponent);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: cvs commit: logging-log4j/src/java/org/apache/joran/action NestComponentIA.java

Posted by Ceki Gülcü <ce...@qos.ch>.
At 08:28 PM 1/5/2005, you wrote:
>Instead of
>
>
>>          actionData.nestedComponent = 
>> Loader.loadClass(className).newInstance();
>>   -
>>   +      if(actionData.nestedComponent instanceof Component) {
>>   +        ((Component) 
>> actionData.nestedComponent).setLoggerRepository(this.repository);
>>   +      }
>
>Could you do something like:
>
>actionData.nestedComponent = this.repository.createComponent(className);

that does not look too difficult:

public class Hierarchy implements LoggerRepository {
   ...

   public Object createComponent(String className) {

     Object o  = Loader.loadClass(className).newInstance();

      if(o instanceof Component) {
        ((Component) o).setLoggerRepository(this);
      }

   }
}

The only major issue with this approach occurs when the repository is
null, the repository.createComponent(className) call would bomb while
ActionBase.getLogger() would return valid ULogger even when the
repository is not set (i.e. null).

My basic working assumption has been that owning repository is allowed
to be left blank. To be honest, I am quite happy with the current
approach. It is well aligned with the current component initialization
pattern prevalent in log4j code, that is:

   Component c = new Component();
   c.setOption1(...);
   c.setOption2(...);
   c.activateOptions();


This pattern has the advantage of malleability. It has proven to be
highly tolerant of future extensions. Having said that, I welcome any
suggestions for objective improvements.


-- 
Ceki Gülcü

   The complete log4j manual: http://www.qos.ch/log4j/



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: cvs commit: logging-log4j/src/java/org/apache/joran/action NestComponentIA.java

Posted by Curt Arnold <ca...@apache.org>.
Instead of


>          actionData.nestedComponent = 
> Loader.loadClass(className).newInstance();
>   -
>   +      if(actionData.nestedComponent instanceof Component) {
>   +        ((Component) 
> actionData.nestedComponent).setLoggerRepository(this.repository);
>   +      }

Could you do something like:

actionData.nestedComponent = this.repository.createComponent(className);

That would make it easier to play with alternative approaches to 
component initialization.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org