1 18 package org.apache.beehive.netui.compiler.model; 19 20 import java.util.ArrayList ; 21 import java.util.Map ; 22 import java.util.LinkedHashMap ; 23 import java.util.Iterator ; 24 25 import org.apache.beehive.netui.compiler.model.schema.struts11.ActionDocument.Action; 26 import org.apache.beehive.netui.compiler.model.schema.struts11.SetPropertyDocument.SetProperty; 27 import org.apache.beehive.netui.compiler.model.schema.struts11.ExceptionDocument; 28 import org.apache.beehive.netui.compiler.model.schema.struts11.ForwardDocument; 29 import org.apache.beehive.netui.compiler.model.schema.struts11.ActionDocument; 30 import org.apache.beehive.netui.compiler.JpfLanguageConstants; 31 import org.apache.xmlbeans.XmlObject; 32 33 34 38 public class ActionModel 39 extends AbstractForwardContainer 40 implements ForwardContainer, ExceptionContainer, JpfLanguageConstants 41 { 42 public static final String DEFAULT_FORM_SCOPE = "request"; 43 44 private static final String JPF_ACTION_MAPPING_CLASSNAME = PAGEFLOW_PACKAGE + ".config.PageFlowActionMapping"; 45 46 47 private ArrayList _exceptionCatches = new ArrayList (); 49 private String _attribute; 50 private String _className; 51 private String _forward; 52 private String _include; 53 private String _input; 54 private String _formBeanName; 55 private String _parameter; 56 private String _path; private String _prefix; 58 private String _scope = DEFAULT_FORM_SCOPE; 59 private String _suffix; 60 private String _type; 61 private boolean _unknown; 62 private String _roles; 63 private boolean _validate; 64 65 private String _unqualifiedActionPath; 67 private boolean _loginRequired; 68 private boolean _isOverloaded; 69 private boolean _readonly; 70 private boolean _isSimpleAction = false; 71 private boolean _preventDoubleSubmit = false; 72 private String _formMember; private String _formClass; private Map _conditionalForwards; 75 private String _formBeanMessageResourcesKey; 76 private String _defaultForwardName; 78 79 public ActionModel( String path, StrutsApp parent ) 80 { 81 this( path, null, parent ); 82 } 83 84 85 public ActionModel( String path, String formName, StrutsApp parent ) 86 { 87 super( parent ); 88 this._path = path; 89 this._formBeanName = formName; 90 } 91 92 protected ActionModel( StrutsApp parent ) 93 { 94 this( null, null, parent ); 95 } 96 97 100 public ActionModel( ActionModel src, String newPath ) 101 { 102 super( src ); 103 this._path = newPath; 104 this._formBeanName = src._formBeanName; 105 _exceptionCatches = ( ArrayList ) src._exceptionCatches.clone(); 106 _attribute = src._attribute; 107 _className = src._className; 108 _forward = src._forward; 109 _include = src._include; 110 _input = src._input; 111 _validate = src._validate; 112 _parameter = src._parameter; 113 _prefix = src._prefix; 114 _scope = src._scope; 115 _suffix = src._suffix; 116 _type = src._type; 117 _unknown = src._unknown; 118 _formMember = src._formMember; 119 _formClass = src._formClass; 120 _roles = src._roles; 121 _loginRequired = src._loginRequired; 122 _preventDoubleSubmit = src._preventDoubleSubmit; 123 _isSimpleAction = src._isSimpleAction; 124 _isOverloaded = src._isOverloaded; 125 _readonly = src._readonly; 126 _unqualifiedActionPath = src._unqualifiedActionPath; 127 _defaultForwardName = src._defaultForwardName; 128 } 129 130 public void setFormBeanName( String formBeanName ) 131 { 132 _formBeanName = formBeanName; 133 } 134 135 public void writeToXMLBean( Action xb ) 136 { 137 xb.setPath( _path ); 138 139 if ( xb.getName() == null && _formBeanName != null ) xb.setName( _formBeanName ); 140 if ( xb.getClassName() == null && _className != null ) xb.setClassName( _className ); 141 if ( xb.getType() == null && _type != null ) xb.setType( _type ); 142 if ( xb.getAttribute() == null && _attribute != null ) xb.setAttribute( _attribute ); 143 if ( xb.getInput() == null && _input != null ) xb.setInput( _input ); 144 if ( xb.getParameter() == null && _parameter != null ) xb.setParameter( _parameter ); 145 if ( xb.getPrefix() == null && _prefix != null ) xb.setPrefix( _prefix ); 146 if ( xb.getSuffix() == null && _suffix != null ) xb.setSuffix( _suffix ); 147 148 if ( xb.getScope() == null ) 149 { 150 if ( _scope != null ) 151 { 152 if ( _scope.equals( "request" ) ) 153 { 154 xb.setScope( Action.Scope.REQUEST ); 155 } 156 else if ( _scope.equals( "session" ) ) 157 { 158 xb.setScope( Action.Scope.SESSION ); 159 } 160 else 161 { 162 assert false : _scope; 163 } 164 } 165 else 166 { 167 xb.setScope( Action.Scope.REQUEST ); 168 } 169 } 170 171 if ( xb.getRoles() == null && _roles != null ) xb.setRoles( _roles ); 172 if ( xb.getForward2() == null && _forward != null ) xb.setForward2( _forward ); 173 if ( xb.getInclude() == null && _include != null ) xb.setInclude( _include ); 174 if ( xb.getUnknown() == null && _unknown ) xb.setUnknown( Action.Unknown.TRUE ); 175 if ( xb.getValidate() == null ) xb.setValidate( _validate ? Action.Validate.TRUE : Action.Validate.FALSE ); 176 177 if ( _unqualifiedActionPath != null ) addSetProperty( xb, "unqualifiedActionPath", _unqualifiedActionPath ); 178 if ( _formMember != null ) addSetProperty( xb, "formMember", _formMember ); 179 if ( _formClass != null ) addSetProperty( xb, "formClass", _formClass ); 180 if ( _loginRequired ) addSetProperty( xb, "loginRequired", _loginRequired ); 181 if ( _preventDoubleSubmit ) addSetProperty( xb, "preventDoubleSubmit", _preventDoubleSubmit ); 182 if ( _isOverloaded ) addSetProperty( xb, "overloaded", _isOverloaded ); 183 if ( _readonly ) addSetProperty( xb, "readonly", _readonly ); 184 if ( _isSimpleAction ) addSetProperty( xb, "simpleAction", _isSimpleAction ); 185 if ( _defaultForwardName != null ) addSetProperty( xb, "defaultForward", _defaultForwardName ); 186 187 if ( _conditionalForwards != null ) 188 { 189 addSetProperty( xb, "conditionalForwards", getMapString( _conditionalForwards) ); 190 } 191 192 if ( _formBeanMessageResourcesKey != null ) 193 { 194 addSetProperty( xb, "formBeanMessageResourcesKey", _formBeanMessageResourcesKey ); 195 } 196 197 if ( _exceptionCatches != null && ! _exceptionCatches.isEmpty() ) 198 { 199 ExceptionDocument.Exception[] existingExceptions = xb.getExceptionArray(); 200 201 for ( int i = 0; i < _exceptionCatches.size(); ++i ) 202 { 203 ExceptionModel ec = ( ExceptionModel ) _exceptionCatches.get( i ); 204 ExceptionDocument.Exception exceptionToEdit = null; 205 206 for ( int j = 0; j < existingExceptions.length; ++j ) 207 { 208 if ( ec.getType().equals( existingExceptions[j].getType() ) ) 209 { 210 exceptionToEdit = existingExceptions[j]; 211 break; 212 } 213 } 214 215 if ( exceptionToEdit == null ) 216 { 217 exceptionToEdit = xb.addNewException(); 218 } 219 220 ec.writeToXMLBean( exceptionToEdit ); 221 } 222 } 223 224 writeForwards( xb.getForwardArray(), xb ); 228 229 addComment( xb ); 230 } 231 232 private void addSetProperty( ActionDocument.Action xb, String propertyName, boolean propertyValue ) 233 { 234 addSetProperty( xb, propertyName, Boolean.toString( propertyValue ) ); 235 } 236 237 private void addSetProperty( ActionDocument.Action xb, String propertyName, String propertyValue ) 238 { 239 SetProperty prop = xb.addNewSetProperty(); 240 prop.setProperty( propertyName ); 241 prop.setValue( propertyValue ); 242 if ( xb.getClassName() == null ) xb.setClassName( JPF_ACTION_MAPPING_CLASSNAME ); 243 } 244 245 protected ForwardDocument.Forward addNewForward( XmlObject xmlObject ) 246 { 247 return ( ( Action ) xmlObject ).addNewForward(); 248 } 249 250 253 public void addException( ExceptionModel em ) 254 { 255 _exceptionCatches.add( em ); 256 } 257 258 public String getAttribute() 259 { 260 return _attribute; 261 } 262 263 public void setAttribute( String attribute ) 264 { 265 this._attribute = attribute; 266 } 267 268 public String getClassName() 269 { 270 return _className; 271 } 272 273 public void setClassName( String className ) 274 { 275 this._className = className; 276 } 277 278 public String getForward() 279 { 280 return _forward; 281 } 282 283 public void setForward( String forward ) 284 { 285 this._forward = forward; 286 } 287 288 public String getInclude() 289 { 290 return _include; 291 } 292 293 public void setInclude( String include ) 294 { 295 this._include = include; 296 } 297 298 public String getInput() 299 { 300 return _input; 301 } 302 303 public void setInput( String input ) 304 { 305 this._input = input; 306 } 307 308 public String getName() 309 { 310 return _formBeanName; 311 } 312 313 public String getFormBeanName() 314 { 315 return _formBeanName; 316 } 317 318 public void setName( String name ) 319 { 320 this._formBeanName = name; 321 } 322 323 public String getParameter() 324 { 325 return _parameter; 326 } 327 328 public void setParameter( String parameter ) 329 { 330 this._parameter = parameter; 331 } 332 333 public boolean isValidate() 334 { 335 return _validate; 336 } 337 338 public void setValidate( boolean validate ) 339 { 340 _validate = validate; 341 } 342 343 public String getPath() 344 { 345 return _path; 346 } 347 348 public String getPath( boolean useUnqualifiedPath ) 349 { 350 if ( useUnqualifiedPath && _unqualifiedActionPath != null ) 351 { 352 return _unqualifiedActionPath; 353 } 354 else 355 { 356 return _path; 357 } 358 } 359 360 public void setPath( String path ) 361 { 362 this._path = path; 363 } 364 365 public String getPrefix() 366 { 367 return _prefix; 368 } 369 370 public void setPrefix( String prefix ) 371 { 372 this._prefix = prefix; 373 } 374 375 public String getScope() 376 { 377 return _scope == null ? DEFAULT_FORM_SCOPE : _scope; 378 } 379 380 public void setScope( String scope ) 381 { 382 this._scope = scope; 383 } 384 385 public String getSuffix() 386 { 387 return _suffix; 388 } 389 390 public void setSuffix( String suffix ) 391 { 392 this._suffix = suffix; 393 } 394 395 public String getType() 396 { 397 return _type; 398 } 399 400 public void setType( String type ) 401 { 402 this._type = type; 403 } 404 405 public boolean isUnknown() 406 { 407 return _unknown; 408 } 409 410 public void setUnknown( boolean unknown ) 411 { 412 this._unknown = unknown; 413 } 414 415 public String getUnqualifiedActionPath() 416 { 417 return _unqualifiedActionPath; 418 } 419 420 public void setUnqualifiedActionPath( String unqualifiedActionPath ) 421 { 422 this._unqualifiedActionPath = unqualifiedActionPath; 423 } 424 425 public String getDefaultForwardName() 426 { 427 return _defaultForwardName; 428 } 429 430 public void setDefaultForwardName( String defaultForwardName ) 431 { 432 _defaultForwardName = defaultForwardName; 433 } 434 435 public String getRoles() 436 { 437 return _roles; 438 } 439 440 public void setRoles( String roles ) 441 { 442 _roles = roles; 443 } 444 445 public void setLoginRequired( boolean loginRequired ) 446 { 447 _loginRequired = loginRequired; 448 } 449 450 public void setPreventDoubleSubmit( boolean preventDoubleSubmit ) 451 { 452 _preventDoubleSubmit = preventDoubleSubmit; 453 } 454 455 public boolean isSimpleAction() 456 { 457 return _isSimpleAction; 458 } 459 460 public void setSimpleAction( boolean simpleAction ) 461 { 462 _isSimpleAction = simpleAction; 463 } 464 465 public boolean isOverloaded() 466 { 467 return _isOverloaded; 468 } 469 470 public void setOverloaded( boolean overloaded ) 471 { 472 _isOverloaded = overloaded; 473 } 474 475 public String getFormMember() 476 { 477 return _formMember; 478 } 479 480 public void setFormMember( String formMember ) 481 { 482 _formMember = formMember; 483 } 484 485 public String getFormClass() 486 { 487 return _formClass; 488 } 489 490 public void setFormClass( String formClass ) 491 { 492 _formClass = formClass; 493 } 494 495 public boolean isReadonly() 496 { 497 return _readonly; 498 } 499 500 public void setReadonly( boolean readonly ) 501 { 502 _readonly = readonly; 503 } 504 505 public void addConditionalForward( String expression, String forwardName ) 506 { 507 if ( _conditionalForwards == null ) _conditionalForwards = new LinkedHashMap (); 508 _conditionalForwards.put( expression, forwardName ); 509 } 510 511 private static String getMapString( Map map ) 512 { 513 StringBuffer retVal = new StringBuffer (); 514 515 for ( Iterator i = map.entrySet().iterator(); i.hasNext(); ) 516 { 517 Map.Entry entry = ( Map.Entry ) i.next(); 518 retVal.append( entry.getValue() ).append( ':' ).append( entry.getKey() ).append( ';' ); 519 } 520 521 return retVal.toString(); 522 } 523 524 public void setFormBeanMessageResourcesKey( String formBeanMessageResourcesKey ) 525 { 526 _formBeanMessageResourcesKey = formBeanMessageResourcesKey; 527 } 528 529 530 } 531 | Popular Tags |