[logback-dev] svn commit: r2141 - in logback/trunk: logback-core/src/main/java/ch/qos/logback/core/util logback-core/src/test/java/ch/qos/logback/core/joran/spi logback-examples logback-site/src/site/pages/manual

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Feb 4 22:00:49 CET 2009


Author: ceki
Date: Wed Feb  4 22:00:48 2009
New Revision: 2141

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PropertySetterTest.java
   logback/trunk/logback-examples/   (props changed)
   logback/trunk/logback-site/src/site/pages/manual/onJoran.html

Log:
Ongoing work on Joran documentation LBSITE-25

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java	Wed Feb  4 22:00:48 2009
@@ -12,6 +12,19 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+/**
+ * Instances of this class represent the size of a file. Internally, the size is
+ * stored as long.>
+ * 
+ * <p>The {@link #valueOf} method can convert strings such as "3 kb", "5 mb", into
+ * FileSize instances. The recognized unit specifications for file size are the
+ * "kb", "mb", and "gb". The unit name may be followed by an "s". Thus, "2 kbs"
+ * and "2 kb" are equivalent. In the absence of a time unit specification, byte
+ * is assumed.
+ *  
+ * @author Ceki G&uuml;lc&uuml;
+ * 
+ */
 public class FileSize {
 
   private final static String LENGTH_PART = "([0-9]+)";
@@ -27,7 +40,6 @@
   static final long MB_COEFFICIENT = 1024 * KB_COEFFICIENT;
   static final long GB_COEFFICIENT = 1024 * MB_COEFFICIENT;
 
-
   final long size;
 
   FileSize(long size) {
@@ -55,7 +67,7 @@
         coefficient = MB_COEFFICIENT;
       } else if (unitStr.equalsIgnoreCase("gb")) {
         coefficient = GB_COEFFICIENT;
-      }  else {
+      } else {
         throw new IllegalStateException("Unexpected " + unitStr);
       }
       return new FileSize(lenValue * coefficient);

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PropertySetterTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PropertySetterTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PropertySetterTest.java	Wed Feb  4 22:00:48 2009
@@ -136,7 +136,7 @@
     setter.setContext(context);
     setter.addBasicProperty("adjective", "nice");
     setter.addBasicProperty("adjective", "big");
-   
+
     assertEquals(2, house.adjectiveList.size());
     assertEquals("nice", house.adjectiveList.get(0));
     assertEquals("big", house.adjectiveList.get(1));
@@ -216,6 +216,24 @@
         defaultComponentRegistry);
     assertEquals(SwimmingPoolImpl.class, classViaImplicitRules);
   }
+  
+  @Test
+  public void testDefaultClassAnnotationForLists() {
+    House house = new House();
+    PropertySetter setter = new PropertySetter(house);
+    Method relevantMethod = setter.getRelevantMethod("LargeSwimmingPool",
+        AggregationType.AS_COMPLEX_PROPERTY_COLLECTION);
+    assertNotNull(relevantMethod);
+    Class spClass = setter.getDefaultClassNameByAnnonation("LargeSwimmingPool",
+        relevantMethod);
+    assertEquals(LargeSwimmingPoolImpl.class, spClass);
+
+    Class classViaImplicitRules = setter.getClassNameViaImplicitRules(
+        "LargeSwimmingPool", AggregationType.AS_COMPLEX_PROPERTY_COLLECTION,
+        defaultComponentRegistry);
+    assertEquals(LargeSwimmingPoolImpl.class, classViaImplicitRules);
+    
+  }
 }
 
 class House {
@@ -232,6 +250,7 @@
 
   List<String> adjectiveList = new ArrayList<String>();
   List<Window> windowList = new ArrayList<Window>();
+  List<SwimmingPool> largePoolList = new ArrayList<SwimmingPool>();
 
   public String getCamelCase() {
     return camelCase;
@@ -273,6 +292,11 @@
     this.open = open;
   }
 
+  @DefaultClass(LargeSwimmingPoolImpl.class)
+  public void addLargeSwimmingPool(SwimmingPool pool) {
+    this.pool = pool;
+  }
+
   @DefaultClass(SwimmingPoolImpl.class)
   public void setSwimmingPool(SwimmingPool pool) {
     this.pool = pool;
@@ -341,6 +365,12 @@
   int depth;
 }
 
+class LargeSwimmingPoolImpl implements SwimmingPool {
+  int length;
+  int width;
+  int depth;
+}
+
 enum HouseColor {
   WHITE, BLUE
 }

Modified: logback/trunk/logback-site/src/site/pages/manual/onJoran.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/onJoran.html	(original)
+++ logback/trunk/logback-site/src/site/pages/manual/onJoran.html	Wed Feb  4 22:00:48 2009
@@ -566,26 +566,37 @@
   <p><code>NestedBasicPropertyIA</code> is applicable for any property
   whose type, is a primitive type, or equivalent object type in the
   <code>java.lang</code> package, an enumeration type, or any type
-  adhering to the "valueOf" convention. A class is said to adhere to
+  adhering to the "valueOf" convention.  Such properties are said to
+  be <em>basic</em> or <em>simple</em>. A class is said to adhere to
   the "valueOf" convention if it contains a static method named
   <code>valueOf</code>() taking a <code>java.lang.String</code> as
-  parameter and returning an instance of the type in question. 
+  parameter and returning an instance of the type in question.  At
+  present time, <a
+  href="../xref/ch/qos/logback/classic/Level.html"><code>Level</code></a>,
+  <a
+  href="../xref/ch/qos/logback/core/util/Duration.html"><code>Duration</code></a>
+  and <a
+  href="../xref/ch/qos/logback/core/util/FileSize.html"><code>FileSize</code></a>
+  classes follow this convention..
   </p>
   
   <p><code>NestedComplexPropertyIA</code> action is applicable, in the
   remaining cases where <code>NestedBasicPropertyIA</code> is not
   applicable <em>and</em> if the object at the top of the object stack
   has a setter or adder method for a property name equal to the
-  current element name. This strategy allows <a
+  current element name. Note that such properties can in turn contain
+  other components. Thus, such properties are said to be
+  <em>complex</em>.  In presence of a complex property, <a
   href="../xref/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.html">
-  <code>NestedComplexPropertyIA</code></a> to instantiate the
+  <code>NestedComplexPropertyIA</code></a> will instantiate the
   appropriate class for the nested component and attach it to the
   parent component (at the top of the object stack) by using the
   setter/adder method of the parent component and the nested element's
-  name. The class to instantiate is specified by the <span
-  class="attr">class</span> attribute of the nested element. However,
-  the class name can be deduced implicitly, if any of the following is
-  true:
+  name. The corresponding class is specified by the <span
+  class="attr">class</span> attribute of the (nested) current
+  element. However, if the <span class="attr">class</span> attribute
+  is missing, the class name can be deduced implicitly, if any of the
+  following is true:
   </p>
 
   <ol>
@@ -601,7 +612,8 @@
   </ol>
 
   <p>In logback-classic, there are just two rules mapping (parent
-  class/property name) couples to a default class.</p>
+  class/property name) couples to a default class. These are listed in
+  the table below.</p>
 
   <table class="bodyTable">
     <tr>
@@ -635,6 +647,14 @@
   <code>addDefaultNestedComponentRegistryRules</code> method for the
   latest rules.
   </p>
+  
+  <h4>Collection of properties</h4>
+
+  
+  <p>Note that in addition to single simple properties or single
+  complex properties, logback's implicit actions support collectons of
+  properties, be they simple or complex. Instead of a setter method,
+  the property is specified by an "adder" method.</p>
 
   <h3><a name="newRule" href="#newRule">New rules on the fly</a></h3>
 
@@ -707,7 +727,7 @@
   href="#calculator">original calculator example</a>.</p>
 
 
-  <script src="templates/footer.js" type="text/javascript"></script>
+  <script src="../templates/footer.js" type="text/javascript"></script>
 </div>
 </body>
 </html>


More information about the logback-dev mailing list