• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: ISimpleElement.java,v 1.1.1.1 2004/05/09 16:57:41 vlad_r Exp $
8  */
9 package com.vladium.emma.report.html.doc;
10 
11 import com.vladium.util.asserts.$assert;
12 
13 // ----------------------------------------------------------------------------
14 /**
15  * @author Vlad Roubtsov, (C) 2003
16  */
17 public
18 interface ISimpleElement extends IContent
19 {
20     // public: ................................................................
21 
getTag()22     Tag getTag ();
setClass(String classID)23     ISimpleElement setClass (String classID);
getAttributes()24     AttributeSet getAttributes ();
25 
26     abstract class Factory
27     {
create(final Tag tag)28         public static ISimpleElement create (final Tag tag)
29         {
30             return new SimpleElementImpl (tag, AttributeSet.create ());
31         }
32 
create(final Tag tag, final AttributeSet attrs)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         {
toString()40             public String toString ()
41             {
42                 return "<" + m_tag.getName () + "/>";
43             }
44 
getTag()45             public Tag getTag ()
46             {
47                 return m_tag;
48             }
49 
setClass(final String classID)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 
getAttributes()60             public AttributeSet getAttributes ()
61             {
62                 return m_attrs;
63             }
64 
emit(final HTMLWriter out)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 
SimpleElementImpl(final Tag tag, final AttributeSet attrs)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         } // end of nested class
93 
94     } // end of nested class
95 
96 
97 
98 } // end of interface
99 // ----------------------------------------------------------------------------