samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java
changeset 64 7b26c64804c2
parent 63 cbba5b31d11c
child 67 b029a28df444
     1.1 --- a/samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java	Sat Jun 14 09:53:04 2008 +0200
     1.2 +++ b/samples/delegatingwriter/src/org/apidesign/delegatingwriter/AltBufferedWriter.java	Sat Jun 14 09:53:05 2008 +0200
     1.3 @@ -71,8 +71,29 @@
     1.4          // END: writer.delegateout
     1.5      }
     1.6  
     1.7 -    private Writer appendDelegateConditionally(CharSequence csq) {
     1.8 -        throw new UnsupportedOperationException("Not yet implemented");
     1.9 +    private Writer appendDelegateConditionally(CharSequence csq) throws IOException {
    1.10 +        // BEGIN: writer.conditionally
    1.11 +        boolean isOverriden = false;
    1.12 +        try {
    1.13 +            isOverriden = 
    1.14 +                (getClass().getMethod("write", String.class).getDeclaringClass() != Writer.class) ||
    1.15 +                (getClass().getMethod("write", Integer.TYPE).getDeclaringClass() != BufferedWriter.class) ||
    1.16 +                (getClass().getMethod("write", String.class, Integer.TYPE, Integer.TYPE).getDeclaringClass() != BufferedWriter.class);
    1.17 +        } catch (Exception ex) {
    1.18 +            throw new IOException(ex);
    1.19 +        }
    1.20 +        
    1.21 +        if (isOverriden) {
    1.22 +            if (csq == null) {
    1.23 +                write("null");
    1.24 +            } else {
    1.25 +                write(csq.toString());
    1.26 +            }
    1.27 +        } else {
    1.28 +            out.append(csq);
    1.29 +        }
    1.30 +        return this;
    1.31 +        // END: writer.conditionally
    1.32      }
    1.33      
    1.34      public enum Behaviour {