001package org.andromda.cartridges.jsf2.metafacades; 002 003import org.andromda.cartridges.jsf2.JSFGlobals; 004import org.andromda.metafacades.uml.ModelElementFacade; 005import org.apache.commons.lang.ObjectUtils; 006import org.apache.commons.lang.StringUtils; 007 008/** 009 * MetafacadeLogic implementation for org.andromda.cartridges.jsf2.metafacades.JSFControllerOperation. 010 * 011 * @see org.andromda.cartridges.jsf2.metafacades.JSFControllerOperation 012 */ 013public class JSFControllerOperationLogicImpl 014 extends JSFControllerOperationLogic 015{ 016 private static final long serialVersionUID = 34L; 017 /** 018 * @param metaObject 019 * @param context 020 */ 021 public JSFControllerOperationLogicImpl(Object metaObject, String context) 022 { 023 super(metaObject, context); 024 } 025 026 /** 027 * @return formName 028 * @see org.andromda.cartridges.jsf2.metafacades.JSFControllerOperation#getFormName() 029 */ 030 protected String handleGetFormName() 031 { 032 final String pattern = ObjectUtils.toString(this.getConfiguredProperty(JSFGlobals.FORM_PATTERN)); 033 return pattern.replaceFirst("\\{0\\}", StringUtils.capitalize(this.getName())); 034 } 035 036 /** 037 * @return fullyQualifiedFormName 038 * @see org.andromda.cartridges.jsf2.metafacades.JSFControllerOperation#getFullyQualifiedFormName() 039 */ 040 protected String handleGetFullyQualifiedFormName() 041 { 042 final StringBuilder fullyQualifiedName = new StringBuilder(); 043 final String packageName = this.getPackageName(); 044 if (StringUtils.isNotBlank(packageName)) 045 { 046 fullyQualifiedName.append(packageName + '.'); 047 } 048 return fullyQualifiedName.append(StringUtils.capitalize(this.getFormName())).toString(); 049 } 050 051 /** 052 * @return getFullyQualifiedFormName().replace('.', '/') 053 * @see org.andromda.cartridges.jsf2.metafacades.JSFControllerOperation#getFullyQualifiedFormPath() 054 */ 055 protected String handleGetFullyQualifiedFormPath() 056 { 057 return this.getFullyQualifiedFormName().replace('.', '/'); 058 } 059 060 /** 061 * @return formCall 062 * @see org.andromda.cartridges.jsf2.metafacades.JSFControllerOperation#getFormCall() 063 */ 064 protected String handleGetFormCall() 065 { 066 final StringBuilder call = new StringBuilder(); 067 call.append(this.getName()); 068 call.append("("); 069 if (!this.getFormFields().isEmpty()) 070 { 071 call.append("form"); 072 } 073 call.append(")"); 074 return call.toString(); 075 } 076 077 /** 078 * @return getFormSignature(false) 079 * @see org.andromda.cartridges.jsf2.metafacades.JSFControllerOperation#getImplementationFormSignature() 080 */ 081 protected String handleGetImplementationFormSignature() 082 { 083 return this.getFormSignature(false); 084 } 085 086 /** 087 * @return getFormSignature(true) 088 * @see org.andromda.cartridges.jsf2.metafacades.JSFControllerOperation#getFormSignature() 089 */ 090 protected String handleGetFormSignature() 091 { 092 return this.getFormSignature(true); 093 } 094 095 /** 096 * Constructs the signature that takes the form for this operation. 097 * 098 * @param isAbstract whether or not the signature is abstract. 099 * @return the appropriate signature. 100 */ 101 private String getFormSignature(boolean isAbstract) 102 { 103 final StringBuilder signature = new StringBuilder(); 104 signature.append(this.getVisibility() + ' '); 105 if (isAbstract) 106 { 107 signature.append("abstract "); 108 } 109 final ModelElementFacade returnType = this.getReturnType(); 110 signature.append(returnType != null ? returnType.getFullyQualifiedName() : null); 111 signature.append(" " + this.getName() + "("); 112 if (!this.getFormFields().isEmpty()) 113 { 114 signature.append(this.getFormName() + " form"); 115 } 116 signature.append(")"); 117 return signature.toString(); 118 } 119}