1 18 package org.apache.beehive.netui.compiler.model; 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.List ; 23 24 import org.apache.beehive.netui.compiler.model.schema.struts11.FormBeanDocument; 25 import org.apache.beehive.netui.compiler.model.schema.struts11.SetPropertyDocument.SetProperty; 26 import org.apache.beehive.netui.compiler.JpfLanguageConstants; 27 28 29 32 public class FormBeanModel 33 extends StrutsElementSupport 34 implements JpfLanguageConstants 35 { 36 public static class Property 37 { 38 private String _name; 39 private String _type; 40 private boolean _required; 41 private boolean _multiValue; 42 43 public Property( String name, String type, boolean required, boolean multival ) 44 { 45 _name = name; 46 _type = type; 47 _required = required; 48 _multiValue = multival; 49 } 50 51 public String getName() 52 { 53 return _name; 54 } 55 56 public void setName( String name ) 57 { 58 _name = name; 59 } 60 61 public String getType() 62 { 63 return _type; 64 } 65 66 public void setType( String type ) 67 { 68 _type = type; 69 } 70 71 public boolean isRequired() 72 { 73 return _required; 74 } 75 76 public void setRequired( boolean required ) 77 { 78 _required = required; 79 } 80 81 public boolean isMultiValue () 82 { 83 return _multiValue; 84 } 85 86 public void setMultiValue ( boolean multi ) 87 { 88 _multiValue = multi; 89 } 90 } 91 92 93 private static final String JPF_ACTION_FORM_BEAN_CLASSNAME = PAGEFLOW_PACKAGE + ".config.PageFlowActionFormBean"; 94 95 private String _id = ""; private String _className = null; 97 private boolean _dynamic = false; 98 private String _name = null; private String _type = null; 101 102 private String _actualType = null; 103 104 105 private boolean _pageFlowScoped; 107 private ArrayList _properties = new ArrayList (); 108 109 public FormBeanModel( String name, String type, String actualType, boolean pageFlowScoped, StrutsApp parent ) 110 { 111 super( parent ); 112 _name = name; 113 _type = type; 114 _actualType = actualType; 115 _pageFlowScoped = pageFlowScoped; 116 } 117 118 public void writeToXMLBean( FormBeanDocument.FormBean xb ) 119 { 120 xb.setName( _name ); 121 122 if ( xb.getType() == null ) xb.setType( _type ); 123 if ( xb.getId() == null && _id != null && _id.length() > 0 ) xb.setId( _id ); 124 if ( xb.getClassName() == null &&_className != null ) xb.setClassName( _className ); 125 if ( xb.getDynamic() == null && _dynamic ) xb.setDynamic( FormBeanDocument.FormBean.Dynamic.TRUE ); 126 127 if ( _actualType != null && ! _actualType.equals( xb.getType() ) ) 128 { 129 SetProperty prop = xb.addNewSetProperty(); 130 prop.setProperty( "actualType" ); 131 prop.setValue( _actualType ); 132 if ( xb.getClassName() == null ) xb.setClassName( JPF_ACTION_FORM_BEAN_CLASSNAME ); 133 } 134 135 } 136 137 public String getId() 138 { 139 return _id; 140 } 141 142 public void setId( String id ) 143 { 144 _id = id; 145 } 146 147 public String getClassName() 148 { 149 return _className; 150 } 151 152 public void setClassName( String className ) 153 { 154 if ( className != null ) 155 { 156 if ("org.apache.struts.action.DynaActionForm".equals( className ) ) _dynamic = true; 158 159 _className = className; 160 } 161 } 162 163 public boolean isDynamic() 164 { 165 return _dynamic; 166 } 167 168 public void setDynamic( boolean dynamic ) 169 { 170 _dynamic = dynamic; 171 } 172 173 public String getName() 174 { 175 return _name; 176 } 177 178 public void setName( String name ) 179 { 180 _name = name; 181 } 182 183 public String getType() 184 { 185 return _type; 186 } 187 188 public void setType( String type ) 189 { 190 _type = type; 191 } 192 193 public String getActualType() 194 { 195 return _actualType; 196 } 197 198 public void setActualType(String actualType) 199 { 200 _actualType = actualType; 201 } 202 203 public void addProperty( String name, String type, boolean required, boolean multival ) 204 { 205 _properties.add( new Property( name, type, required, multival ) ); 206 } 207 208 211 public void updateProperties( Collection newProps ) 212 { 213 _properties = new ArrayList (); 214 215 if ( newProps != null ) 216 { 217 _properties.addAll( newProps ); 218 } 219 } 220 221 public Property[] getProperties() 222 { 223 return ( Property[] ) _properties.toArray( new Property[]{} ); 224 } 225 226 public void deleteProperty( String name ) 227 { 228 for ( int i = 0; i < _properties.size(); ++i ) 229 { 230 Property prop = ( Property ) _properties.get( i ); 231 232 if ( prop.getName().equals( name ) ) 233 { 234 _properties.remove( i-- ); 235 } 236 } 237 } 238 239 public void deleteProperty( Property prop ) 240 { 241 _properties.remove( prop ); 242 } 243 244 public Property findProperty( String name ) 245 { 246 int index = findPropertyIndex( name ); 247 return index != -1 ? ( Property ) _properties.get( index ) : null; 248 } 249 250 protected int findPropertyIndex( String name ) 251 { 252 for ( int i = 0; i < _properties.size(); ++i ) 253 { 254 Property prop = ( Property ) _properties.get( i ); 255 256 if ( prop.getName().equals( name ) ) 257 { 258 return i; 259 } 260 } 261 262 return -1; 263 } 264 265 268 protected final List getPropertyList() 269 { 270 return ( List ) _properties.clone(); 271 } 272 273 public boolean isPageFlowScoped() 274 { 275 return _pageFlowScoped; 276 } 277 } 278 | Popular Tags |