| 1 |
// |
|---|
| 2 |
// =========================================================================== |
|---|
| 3 |
// |
|---|
| 4 |
// Title: FieldDoc.java |
|---|
| 5 |
// Description: Somehwat similar to javadoc |
|---|
| 6 |
// Author: Raphal Szwarc <zoe (underscore) info (at) mac (dot) com> |
|---|
| 7 |
// Creation Date: Thu Dec 09 2004 |
|---|
| 8 |
// Legal: Copyright (C) 2004 Raphal Szwarc |
|---|
| 9 |
// |
|---|
| 10 |
// This software is provided 'as-is', without any express or implied warranty. |
|---|
| 11 |
// In no event will the author be held liable for any damages arising from |
|---|
| 12 |
// the use of this software. |
|---|
| 13 |
// |
|---|
| 14 |
// Permission is granted to anyone to use this software for any purpose, |
|---|
| 15 |
// including commercial applications, and to alter it and |
|---|
| 16 |
// redistribute it freely, subject to the following restrictions: |
|---|
| 17 |
// |
|---|
| 18 |
// 1. The origin of this software must not be misrepresented; |
|---|
| 19 |
// you must not claim that you wrote the original software. |
|---|
| 20 |
// If you use this software in a product, an acknowledgment |
|---|
| 21 |
// in the product documentation would be appreciated but is not required. |
|---|
| 22 |
// |
|---|
| 23 |
// 2. Altered source versions must be plainly marked as such, |
|---|
| 24 |
// and must not be misrepresented as being the original software. |
|---|
| 25 |
// |
|---|
| 26 |
// 3. This notice may not be removed or altered from any source distribution. |
|---|
| 27 |
// |
|---|
| 28 |
// --------------------------------------------------------------------------- |
|---|
| 29 |
// |
|---|
| 30 |
|
|---|
| 31 |
package alt.dev.dydoc; |
|---|
| 32 |
|
|---|
| 33 |
import java.io.File; |
|---|
| 34 |
|
|---|
| 35 |
import java.lang.reflect.Field; |
|---|
| 36 |
import java.lang.reflect.Modifier; |
|---|
| 37 |
|
|---|
| 38 |
import java.util.Collection; |
|---|
| 39 |
import java.util.Map; |
|---|
| 40 |
import java.util.HashMap; |
|---|
| 41 |
|
|---|
| 42 |
import alt.dev.szapp.SZComponent; |
|---|
| 43 |
import alt.dev.szapp.SZContext; |
|---|
| 44 |
import alt.dev.szapp.SZTemplate; |
|---|
| 45 |
import alt.dev.szapp.SZSpanString; |
|---|
| 46 |
import alt.dev.szapp.SZHTMLCoder; |
|---|
| 47 |
import alt.dev.szapp.SZURIEncoder; |
|---|
| 48 |
|
|---|
| 49 |
import alt.dev.szfoundation.SZLog; |
|---|
| 50 |
|
|---|
| 51 |
public class FieldDoc extends Component |
|---|
| 52 |
{ |
|---|
| 53 |
|
|---|
| 54 |
// =========================================================================== |
|---|
| 55 |
// Constant(s) |
|---|
| 56 |
// --------------------------------------------------------------------------- |
|---|
| 57 |
|
|---|
| 58 |
// =========================================================================== |
|---|
| 59 |
// Class variable(s) |
|---|
| 60 |
// --------------------------------------------------------------------------- |
|---|
| 61 |
|
|---|
| 62 |
// =========================================================================== |
|---|
| 63 |
// Instance variable(s) |
|---|
| 64 |
// --------------------------------------------------------------------------- |
|---|
| 65 |
|
|---|
| 66 |
private Field _value = null; |
|---|
| 67 |
private Collection _values = null; |
|---|
| 68 |
private Map _valueProperties = null; |
|---|
| 69 |
|
|---|
| 70 |
// =========================================================================== |
|---|
| 71 |
// Constructor method(s) |
|---|
| 72 |
// --------------------------------------------------------------------------- |
|---|
| 73 |
|
|---|
| 74 |
protected FieldDoc(final SZContext aContext, final SZComponent aParent, final Map someBindings) |
|---|
| 75 |
{ |
|---|
| 76 |
super( aContext, aParent, someBindings ); |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
// =========================================================================== |
|---|
| 80 |
// Class method(s) |
|---|
| 81 |
// --------------------------------------------------------------------------- |
|---|
| 82 |
|
|---|
| 83 |
// =========================================================================== |
|---|
| 84 |
// Instance method(s) |
|---|
| 85 |
// --------------------------------------------------------------------------- |
|---|
| 86 |
|
|---|
| 87 |
protected Field value() |
|---|
| 88 |
{ |
|---|
| 89 |
if ( _value == null ) |
|---|
| 90 |
{ |
|---|
| 91 |
_value = (Field) this.valueForBinding( "value" ); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
return _value; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
protected Collection values() |
|---|
| 98 |
{ |
|---|
| 99 |
if ( _values == null ) |
|---|
| 100 |
{ |
|---|
| 101 |
_values = (Collection) this.valueForBinding( "values" ); |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
return _values; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
protected Map valueProperties() |
|---|
| 108 |
{ |
|---|
| 109 |
if ( _valueProperties == null ) |
|---|
| 110 |
{ |
|---|
| 111 |
Map aMap = (Map) this.valueForBinding( "valueProperties" ); |
|---|
| 112 |
|
|---|
| 113 |
_valueProperties = new HashMap(); |
|---|
| 114 |
|
|---|
| 115 |
if ( aMap != null ) |
|---|
| 116 |
{ |
|---|
| 117 |
Map anotherMap = null; |
|---|
| 118 |
|
|---|
| 119 |
anotherMap = (Map) aMap.get( "class.variables" ); |
|---|
| 120 |
|
|---|
| 121 |
if ( anotherMap != null ) |
|---|
| 122 |
{ |
|---|
| 123 |
_valueProperties.putAll( anotherMap ); |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
anotherMap = (Map) aMap.get( "instance.variables" ); |
|---|
| 127 |
|
|---|
| 128 |
if ( anotherMap != null ) |
|---|
| 129 |
{ |
|---|
| 130 |
_valueProperties.putAll( anotherMap ); |
|---|
| 131 |
} |
|---|
| 132 |
} |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
return _valueProperties; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
// =========================================================================== |
|---|
| 139 |
// Display method(s) |
|---|
| 140 |
// --------------------------------------------------------------------------- |
|---|
| 141 |
|
|---|
| 142 |
protected String variableAnchor() |
|---|
| 143 |
{ |
|---|
| 144 |
StringBuffer aBuffer = new StringBuffer(); |
|---|
| 145 |
String aName = this.value().getName(); |
|---|
| 146 |
|
|---|
| 147 |
aName = aName.replace( ':', '.' ); |
|---|
| 148 |
aName = SZURIEncoder.encode( aName ); |
|---|
| 149 |
|
|---|
| 150 |
aBuffer.append( "<a name = \"" ); |
|---|
| 151 |
aBuffer.append( aName ); |
|---|
| 152 |
aBuffer.append( "\"></a>" ); |
|---|
| 153 |
|
|---|
| 154 |
return aBuffer.toString(); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
protected SZComponent variableTitle() |
|---|
| 158 |
{ |
|---|
| 159 |
Map someBindings = new HashMap(); |
|---|
| 160 |
someBindings.put( "value", this.value().getName() ); |
|---|
| 161 |
someBindings.put( "isBig", Boolean.TRUE ); |
|---|
| 162 |
someBindings.put( "isBold", Boolean.TRUE ); |
|---|
| 163 |
someBindings.put( "class", "Title" ); |
|---|
| 164 |
SZComponent aComponent = new SZSpanString( this.context(), this, someBindings ); |
|---|
| 165 |
|
|---|
| 166 |
return aComponent; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
protected String modifiers() |
|---|
| 170 |
{ |
|---|
| 171 |
return Modifier.toString( this.value().getModifiers() ); |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
protected SZComponent type() |
|---|
| 175 |
{ |
|---|
| 176 |
Class aType = this.value().getType(); |
|---|
| 177 |
SZComponent aComponent = ClassDoc.altLinkForClassInComponent( aType, this ); |
|---|
| 178 |
|
|---|
| 179 |
if ( ClassInfo.contains( this.values(), aType ) == false ) |
|---|
| 180 |
{ |
|---|
| 181 |
aComponent.takeValueForBinding( Boolean.FALSE, "isEnabled" ); |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
return aComponent; |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
protected String description() |
|---|
| 188 |
{ |
|---|
| 189 |
String aValue = (String) this.valueProperties().get( this.value().getName() ); |
|---|
| 190 |
|
|---|
| 191 |
if ( ( aValue == null ) || ( aValue.length() == 0 ) ) |
|---|
| 192 |
{ |
|---|
| 193 |
aValue = this.property( "No description available for this variable." ); |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
return aValue; |
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
public String toString() |
|---|
| 200 |
{ |
|---|
| 201 |
SZTemplate aTemplate = this.template(); |
|---|
| 202 |
|
|---|
| 203 |
aTemplate.set( "variableAnchor", this.variableAnchor() ); |
|---|
| 204 |
aTemplate.set( "variableTitle", this.variableTitle() ); |
|---|
| 205 |
aTemplate.set( "modifiers", this.modifiers() ); |
|---|
| 206 |
aTemplate.set( "type", this.type() ); |
|---|
| 207 |
aTemplate.set( "description", this.description() ); |
|---|
| 208 |
|
|---|
| 209 |
return aTemplate.toString(); |
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
} |
|---|