1 9 package com.vladium.emma.report.html.doc; 10 11 import com.vladium.util.asserts.$assert; 12 13 17 public 18 interface ISimpleElement extends IContent 19 { 20 22 Tag getTag (); 23 ISimpleElement setClass (String classID); 24 AttributeSet getAttributes (); 25 26 abstract class Factory 27 { 28 public static ISimpleElement create (final Tag tag) 29 { 30 return new SimpleElementImpl (tag, AttributeSet.create ()); 31 } 32 33 public static ISimpleElement create (final Tag tag, final AttributeSet attrs) 34 { 35 return new SimpleElementImpl (tag, attrs); 36 } 37 38 static class SimpleElementImpl implements ISimpleElement 39 { 40 public String toString () 41 { 42 return "<" + m_tag.getName () + "/>"; 43 } 44 45 public Tag getTag () 46 { 47 return m_tag; 48 } 49 50 public ISimpleElement setClass (final String classID) 51 { 52 if ((classID != null) && (classID.length () > 0)) 53 { 54 getAttributes ().set (Attribute.CLASS, classID); 55 } 56 57 return this; 58 } 59 60 public AttributeSet getAttributes () 61 { 62 return m_attrs; 63 } 64 65 public void emit (final HTMLWriter out) 66 { 67 out.write ('<'); 68 out.write (m_tag.getName ()); 69 70 if (! m_attrs.isEmpty ()) 71 { 72 out.write (' '); 73 m_attrs.emit (out); 74 } 75 76 out.write ("/>"); 77 } 78 79 SimpleElementImpl (final Tag tag, final AttributeSet attrs) 80 { 81 if ($assert.ENABLED) $assert.ASSERT (tag != null, "tag = null"); 82 if ($assert.ENABLED) $assert.ASSERT (attrs != null, "attrs = null"); 83 84 m_tag = tag; 85 m_attrs = attrs; 86 } 87 88 89 protected final Tag m_tag; 90 protected final AttributeSet m_attrs; 91 92 } 94 } 96 97 98 } | Popular Tags |