001package org.andromda.cartridges.ejb3.metafacades; 002 003import java.text.MessageFormat; 004import org.andromda.cartridges.ejb3.EJB3Globals; 005import org.andromda.cartridges.ejb3.EJB3Profile; 006import org.andromda.metafacades.uml.UMLProfile; 007import org.apache.commons.lang.StringUtils; 008 009/** 010 * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3OperationFacade. 011 * 012 * @see EJB3OperationFacade 013 */ 014public class EJB3OperationFacadeLogicImpl 015 extends EJB3OperationFacadeLogic 016{ 017 private static final long serialVersionUID = 34L; 018 019 // ---------------- constructor ------------------------------- 020 /** 021 * @param metaObject 022 * @param context 023 */ 024 public EJB3OperationFacadeLogicImpl(final Object metaObject, final String context) 025 { 026 super (metaObject, context); 027 } 028 029 // ---------------- methods ------------------------------- 030 031 /** 032 * @see EJB3OperationFacade#isBusinessOperation() 033 */ 034 @Override 035 protected boolean handleIsBusinessOperation() 036 { 037 return !this.isCreateMethod() && 038 !this.isFinderMethod() && 039 !this.isSelectMethod(); 040 } 041 042 /** 043 * @see EJB3OperationFacade#isSelectMethod() 044 */ 045 @Override 046 protected boolean handleIsSelectMethod() 047 { 048 return this.hasStereotype(EJB3Profile.STEREOTYPE_SELECT_METHOD); 049 } 050 051 /** 052 * @see EJB3OperationFacadeLogic#handleIsCreateMethod() 053 */ 054 @Override 055 protected boolean handleIsCreateMethod() 056 { 057 return this.hasStereotype(EJB3Profile.STEREOTYPE_CREATE_METHOD); 058 } 059 060 /** 061 * @see EJB3OperationFacadeLogic#handleIsFinderMethod() 062 */ 063 @Override 064 protected boolean handleIsFinderMethod() 065 { 066 return this.hasStereotype(UMLProfile.STEREOTYPE_FINDER_METHOD) || this.isQuery(); 067 } 068 069 /** 070 * @see EJB3OperationFacadeLogic#handleIsPrePersist() 071 */ 072 @Override 073 protected boolean handleIsPrePersist() 074 { 075 return this.hasStereotype(EJB3Profile.STEREOTYPE_PRE_PERSIST); 076 } 077 078 /** 079 * @see EJB3OperationFacadeLogic#handleIsPostPersist() 080 */ 081 @Override 082 protected boolean handleIsPostPersist() 083 { 084 return this.hasStereotype(EJB3Profile.STEREOTYPE_POST_PERSIST); 085 } 086 087 /** 088 * @see EJB3OperationFacadeLogic#handleIsPreRemove() 089 */ 090 @Override 091 protected boolean handleIsPreRemove() 092 { 093 return this.hasStereotype(EJB3Profile.STEREOTYPE_PRE_REMOVE); 094 } 095 096 /** 097 * @see EJB3OperationFacadeLogic#handleIsPostRemove() 098 */ 099 @Override 100 protected boolean handleIsPostRemove() 101 { 102 return this.hasStereotype(EJB3Profile.STEREOTYPE_POST_REMOVE); 103 } 104 105 /** 106 * @see EJB3OperationFacadeLogic#handleIsPreUpdate() 107 */ 108 @Override 109 protected boolean handleIsPreUpdate() 110 { 111 return this.hasStereotype(EJB3Profile.STEREOTYPE_PRE_UPDATE); 112 } 113 114 /** 115 * @see EJB3OperationFacadeLogic#handleIsPostUpdate() 116 */ 117 @Override 118 protected boolean handleIsPostUpdate() 119 { 120 return this.hasStereotype(EJB3Profile.STEREOTYPE_POST_UPDATE); 121 } 122 123 /** 124 * @see EJB3OperationFacadeLogic#handleIsPostLoad() 125 */ 126 @Override 127 protected boolean handleIsPostLoad() 128 { 129 return this.hasStereotype(EJB3Profile.STEREOTYPE_POST_LOAD); 130 } 131 132 /** 133 * @see EJB3OperationFacadeLogic#handleIsLifecycleCallback() 134 */ 135 @Override 136 protected boolean handleIsLifecycleCallback() 137 { 138 return this.isPostLoad() || 139 this.isPostPersist() || 140 this.isPostRemove() || 141 this.isPostUpdate() || 142 this.isPrePersist() || 143 this.isPreRemove() || 144 this.isPreUpdate(); 145 } 146 147 /** 148 * @see EJB3OperationFacadeLogic#handleGetImplementationName() 149 */ 150 @Override 151 protected String handleGetImplementationName() 152 { 153 return this.getImplementationOperationName(StringUtils.capitalize(this.getName())); 154 } 155 156 /** 157 * @see EJB3OperationFacadeLogic#handleGetImplementationCall() 158 */ 159 @Override 160 protected String handleGetImplementationCall() 161 { 162 return this.getImplementationOperationName(StringUtils.capitalize(this.getCall())); 163 } 164 165 /** 166 * @see EJB3OperationFacadeLogic#handleGetImplementationSignature() 167 */ 168 @Override 169 protected String handleGetImplementationSignature() 170 { 171 return this.getImplementationOperationName(StringUtils.capitalize(this.getSignature())); 172 } 173 174 /** 175 * Retrieves the implementationOperatName by replacing the <code>replacement</code> in the {@link 176 * EJB3Globals#IMPLEMENTATION_OPERATION_NAME_PATTERN} 177 * 178 * @param replacement the replacement string for the pattern. 179 * @return the operation name 180 */ 181 private String getImplementationOperationName(final String replacement) 182 { 183 String implementationNamePattern = 184 (String)this.getConfiguredProperty(EJB3Globals.IMPLEMENTATION_OPERATION_NAME_PATTERN); 185 186 return MessageFormat.format( 187 implementationNamePattern, 188 StringUtils.trimToEmpty(replacement)); 189 } 190}