001package org.andromda.metafacades.uml14; 002 003import java.util.ArrayList; 004import java.util.Collection; 005import java.util.Iterator; 006import java.util.LinkedHashSet; 007import java.util.List; 008import java.util.Set; 009 010import org.andromda.metafacades.uml.ActivityGraphFacade; 011import org.andromda.metafacades.uml.CallEventFacade; 012import org.andromda.metafacades.uml.EventFacade; 013import org.andromda.metafacades.uml.FrontEndAction; 014import org.andromda.metafacades.uml.FrontEndActivityGraph; 015import org.andromda.metafacades.uml.FrontEndControllerOperation; 016import org.andromda.metafacades.uml.FrontEndEvent; 017import org.andromda.metafacades.uml.FrontEndExceptionHandler; 018import org.andromda.metafacades.uml.FrontEndUseCase; 019import org.andromda.metafacades.uml.FrontEndView; 020import org.andromda.metafacades.uml.OperationFacade; 021import org.andromda.metafacades.uml.ServiceOperation; 022import org.andromda.metafacades.uml.StateMachineFacade; 023import org.andromda.metafacades.uml.TransitionFacade; 024import org.andromda.metafacades.uml.UseCaseFacade; 025import org.andromda.utils.StringUtilsHelper; 026import org.apache.commons.collections.CollectionUtils; 027import org.apache.commons.collections.Predicate; 028 029/** 030 * MetafacadeLogic implementation for org.andromda.metafacades.uml.FrontEndActionState. 031 * 032 * @see org.andromda.metafacades.uml.FrontEndActionState 033 * @author Bob Fields 034 */ 035public class FrontEndActionStateLogicImpl 036 extends FrontEndActionStateLogic 037{ 038 private static final long serialVersionUID = 34L; 039 /** 040 * @param metaObject 041 * @param context 042 */ 043 public FrontEndActionStateLogicImpl( 044 Object metaObject, 045 String context) 046 { 047 super(metaObject, context); 048 } 049 050 /** 051 * @see org.andromda.metafacades.uml.FrontEndActionState#isServerSide() 052 */ 053 @Override 054 protected boolean handleIsServerSide() 055 { 056 return !(this.THIS() instanceof FrontEndView); 057 } 058 059 /** 060 * @see org.andromda.metafacades.uml.FrontEndActionState#getActionMethodName() 061 */ 062 @Override 063 protected String handleGetActionMethodName() 064 { 065 return '_' + StringUtilsHelper.lowerCamelCaseName(getName()); 066 } 067 068 /** 069 * @see org.andromda.metafacades.uml.FrontEndActionState#isContainedInFrontEndUseCase() 070 */ 071 @Override 072 protected boolean handleIsContainedInFrontEndUseCase() 073 { 074 return this.getStateMachine() instanceof FrontEndActivityGraph; 075 } 076 077 /** 078 * @see org.andromda.metafacades.uml.FrontEndActionState#getForward() 079 */ 080 @Override 081 protected TransitionFacade handleGetForward() 082 { 083 TransitionFacade forward = null; 084 085 for (final Iterator iterator = this.getOutgoings().iterator(); iterator.hasNext() && forward == null;) 086 { 087 final TransitionFacade transition = (TransitionFacade)iterator.next(); 088 if (!(transition instanceof FrontEndExceptionHandler)) 089 { 090 forward = transition; 091 } 092 } 093 return forward; 094 } 095 096 /** 097 * @see org.andromda.metafacades.uml.FrontEndActionState#getServiceCalls() 098 */ 099 @Override 100 protected List<OperationFacade> handleGetServiceCalls() 101 { 102 final List<OperationFacade> serviceCallsList = new ArrayList<OperationFacade>(); 103 final Collection<EventFacade> deferrableEvents = this.getDeferrableEvents(); 104 for (final Iterator<EventFacade> iterator = deferrableEvents.iterator(); iterator 105 .hasNext();) 106 { 107 final EventFacade event = iterator.next(); 108 if (event instanceof CallEventFacade) 109 { 110 serviceCallsList.addAll(((CallEventFacade)event).getOperations()); 111 } 112 else if (event instanceof FrontEndEvent) 113 { 114 serviceCallsList.addAll(((FrontEndEvent)event).getControllerCalls()); 115 } 116 } 117 //removing the controller calls 118 CollectionUtils.filter(serviceCallsList, new Predicate() { 119 @Override 120 public boolean evaluate(Object object) { 121 final OperationFacade operation=(OperationFacade)object; 122 return operation instanceof ServiceOperation; 123 } 124 }); 125 return serviceCallsList; 126 } 127 128 /** 129 * @see org.andromda.metafacades.uml.FrontEndActionState#getControllerCalls() 130 */ 131 @Override 132 protected List<OperationFacade> handleGetControllerCalls() 133 { 134 final List<OperationFacade> controllerCallsList = new ArrayList(); 135 final Collection<EventFacade> deferrableEvents = this.getDeferrableEvents(); 136 for (final Iterator<EventFacade> iterator = deferrableEvents.iterator(); iterator.hasNext();) 137 { 138 final EventFacade event = iterator.next(); 139 if (event instanceof CallEventFacade) 140 { 141 final OperationFacade operationObject = ((CallEventFacade)event).getOperation(); 142 if (operationObject != null) 143 { 144 controllerCallsList.add(operationObject); 145 } 146 } 147 else if (event instanceof FrontEndEvent) 148 { 149 final FrontEndControllerOperation callObject = ((FrontEndEvent)event).getControllerCall(); 150 if (callObject != null) 151 { 152 controllerCallsList.add(callObject); 153 } 154 } 155 } 156 //removing the direct service calls 157 CollectionUtils.filter(controllerCallsList, new Predicate() { 158 @Override 159 public boolean evaluate(Object object) { 160 final OperationFacade operation=(OperationFacade)object; 161 return operation instanceof FrontEndControllerOperation; 162 } 163 }); 164 return controllerCallsList; 165 } 166 167 /** 168 * @see org.andromda.metafacades.uml.FrontEndActionState#getExceptions() 169 */ 170 @Override 171 protected List<FrontEndExceptionHandler> handleGetExceptions() 172 { 173 final Set<FrontEndExceptionHandler> exceptions = new LinkedHashSet<FrontEndExceptionHandler>(); 174 final Collection<TransitionFacade> outgoing = getOutgoings(); 175 for (final Iterator<TransitionFacade> iterator = outgoing.iterator(); iterator.hasNext();) 176 { 177 final TransitionFacade transition = iterator.next(); 178 if (transition instanceof FrontEndExceptionHandler) 179 { 180 exceptions.add((FrontEndExceptionHandler)transition); 181 } 182 } 183 return new ArrayList<FrontEndExceptionHandler>(exceptions); 184 } 185 186 /** 187 * @see org.andromda.metafacades.uml.FrontEndActionState#getContainerActions() 188 */ 189 @Override 190 protected List<FrontEndAction> handleGetContainerActions() 191 { 192 final Collection<FrontEndAction> actionSet = new LinkedHashSet<FrontEndAction>(); 193 194 final StateMachineFacade stateMachineFacade = this.getStateMachine(); 195 if (stateMachineFacade instanceof ActivityGraphFacade) 196 { 197 final ActivityGraphFacade activityGraph = (ActivityGraphFacade)stateMachineFacade; 198 final UseCaseFacade useCase = activityGraph.getUseCase(); 199 200 if (useCase instanceof FrontEndUseCase) 201 { 202 final Collection<FrontEndAction> actions = ((FrontEndUseCase)useCase).getActions(); 203 for (final Iterator<FrontEndAction> actionIterator = actions.iterator(); actionIterator.hasNext();) 204 { 205 final FrontEndAction action = actionIterator.next(); 206 if (action.getActionStates().contains(this)) 207 { 208 actionSet.add(action); 209 } 210 } 211 } 212 } 213 return new ArrayList<FrontEndAction>(actionSet); 214 } 215}