Skip to main content
summaryrefslogtreecommitdiffstats
blob: fc4d6337e59efc7ac4fd5673be4c96d5d41048ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<%@ jet 
package="org.eclipse.jubula.toolkit.api.gen" 
imports="java.util.*
			org.eclipse.jubula.toolkit.api.gen.internal.genmodel.ComponentGenInfo
			org.eclipse.jubula.toolkit.api.gen.internal.genmodel.CommonGenInfo 
			org.eclipse.jubula.toolkit.api.gen.internal.utils.NameLoader
			org.eclipse.jubula.toolkit.enums.LiteralProvider
		   org.eclipse.jubula.tools.internal.xml.businessmodell.Action
		   org.eclipse.jubula.tools.internal.xml.businessmodell.Component
		   org.eclipse.jubula.tools.internal.xml.businessmodell.ConcreteComponent
		   org.eclipse.jubula.tools.internal.xml.businessmodell.Param" 
class="ClassGenerator"%>
<%
CommonGenInfo genInfo = (CommonGenInfo)argument;
Object specInfo = genInfo.getSpecificInformation();
if (specInfo instanceof ComponentGenInfo) {
	ComponentGenInfo compGenInfo = (ComponentGenInfo) specInfo;
	String toolkitName = genInfo.getToolkitName();
	String className = genInfo.getClassName();
	Component component = compGenInfo.getComponent();
	Boolean genInterface = compGenInfo.generatesInterface();
	Boolean hasDefaultMapping = compGenInfo.hasDefaultMapping();
	String packageName = null;
	if (genInterface) {
		packageName = compGenInfo.getInterfacePackageName();
	} else {
		packageName = genInfo.getClassPackageName();
	}
	String implementedTypeFqn = compGenInfo.getFqInterfaceName();
	
	NameLoader nameLoader = NameLoader.getInstance();
	List<Action> actions = new ArrayList<>(component.getActions());
	List<Component> realized = component.getRealized();
	Component realizedComponent = realized.size() > 0 ? realized.get(0) : null;
	Boolean hasRealizedType = (realizedComponent != null);
	String realizedType = null;
	CommonGenInfo superInfo = null;
	List<Action> superActions = null;
	String realizedTypeFqn = null;
	if (hasRealizedType) {
		realizedType = realizedComponent.getType();
		superInfo = new CommonGenInfo(realizedComponent);
		superActions = realizedComponent.getActions();
		if (genInterface) {
			ComponentGenInfo superCompGenInfo = new ComponentGenInfo(
				realizedComponent, true, superInfo.getToolkitName(),
				superInfo.getClassName());
			realizedTypeFqn = superCompGenInfo.getFqInterfaceName();
		} else {
			realizedTypeFqn = superInfo.getFqClassName();
		}
	}
	String testerClass = "";
	String componentClassName = "";
	Boolean hasComponentClass = false;
	if (component instanceof ConcreteComponent) {
		ConcreteComponent concreteComponent = (ConcreteComponent)component;
		testerClass = concreteComponent.getTesterClass();
		componentClassName = concreteComponent.getComponentClass().getName();
		if (!componentClassName.isEmpty()) {
			hasComponentClass = true;
		}
	}
	%>
/*******************************************************************************
 * Copyright (c) 2014 BREDEX GmbH.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     BREDEX GmbH - initial API and implementation and/or initial documentation
 *******************************************************************************/
package <%=packageName%>;

import org.eclipse.jubula.communication.CAP;
<%if (!genInterface) {%>
import org.eclipse.jubula.communication.internal.message.MessageCap;
import org.eclipse.jubula.communication.internal.message.MessageParam;
import org.eclipse.jubula.tools.ComponentIdentifier;
import org.eclipse.jubula.tools.internal.exception.Assert;
import org.eclipse.jubula.tools.internal.objects.IComponentIdentifier;
import org.eclipse.jubula.toolkit.internal.annotations.RealizedType;
import org.eclipse.jubula.toolkit.internal.annotations.TesterClass;
<%}%>

/**
 * Generated <%if (genInterface) {%>interface<%} else {%>class<%}%> representing the <%=className%> component from the <%=toolkitName%> toolkit.
 * <%if (genInterface) {%>This interface is not intended to be implemented by any other than the automatically generated classes.<%}%>
 */
<%if (!genInterface) {%>
<%if (realizedType != null && !realizedType.isEmpty()) {%>
@RealizedType(realizedType="<%=realizedType%>")<%}%>
<%if (testerClass != null && !testerClass.isEmpty()) {%>
@TesterClass(testerClass="<%=testerClass%>")<%}%>
<%}%>
public <%if (genInterface) {%>interface<%} else {%>class<%}%> <%=className%>
	<%if (hasRealizedType) {%>extends <%=realizedTypeFqn%><%}%>
	<%if (!genInterface) {%>implements <%=implementedTypeFqn%><%}%> {
	<%// generate constructor only for implementation classes%>
	<%if (!genInterface) {%>
		<%/* check whether constructor should call super
		and whether constructor needs an object mapping */%>
		<%if (hasRealizedType) {%>
			<%if (hasDefaultMapping) {%>
			public <%=className%>() {
				super();
			}<%} else {%>
			public <%=className%>(ComponentIdentifier componentIdentifier) {
				super(componentIdentifier);
			}<%}%>
		<%} else {%>
			<%if (hasDefaultMapping) {%>
			public <%=className%>() {
				super();
			}<%} else {%>
			protected IComponentIdentifier m_componentIdentifier;
			public <%=className%>(ComponentIdentifier componentIdentifier) {
				super();
				Assert.verify(componentIdentifier instanceof IComponentIdentifier);
				m_componentIdentifier = (IComponentIdentifier) componentIdentifier;
			}<%}%>
		<%}%>
	<%}%>
	
	<%if (!genInterface && hasDefaultMapping) {%>
	protected IComponentIdentifier getPseudoComponentIdentifier() {
		<%if (hasComponentClass) {%>
		org.eclipse.jubula.tools.internal.objects.ComponentIdentifier pseudoIdentifier =
			new org.eclipse.jubula.tools.internal.objects.ComponentIdentifier();
		pseudoIdentifier.setComponentClassName("<%=componentClassName%>");
		return pseudoIdentifier;
		<%} else {%>
		return null;
		<%}%>
	}<%}%>
	
	<%
	if (superActions != null) {
		// generate only methods for non-inherited actions
		actions.removeAll(superActions);
	}
	// generate method for each action
	Iterator<Action> actionsIterator = actions.iterator();
	while (actionsIterator.hasNext()) {	
		Action action = actionsIterator.next();
		if (action.isClientAction()) {
			continue;
		}
		String methodName = nameLoader.translateFromCompSystem(action.getName());
		List<Param> params = action.getParams();
		%>
		<%if (action.isDeprecated()) {%>@Deprecated<%}%>
		public CAP <%=methodName%>(
		<%	
		// add parameters to method
		Map<String, String> paramMap = new HashMap<String, String>();
		Iterator<Param> paramIterator = params.iterator();
		while (paramIterator.hasNext()) {
			Param param = paramIterator.next();
			String type = param.getType();
			String name = param.getName();
			String paramType = nameLoader.findTypeForParameter(type, name);
			String paramName = nameLoader.translateFromCompSystem(name);
			paramMap.put(name, paramType);
			%>
			<%=paramType%> <%=paramName%><%if(paramIterator.hasNext()){%>,<%}%>
		<%}%>
		) <%if (genInterface) {%>;<%} else {%>{
			MessageCap messageCap = new MessageCap();
			messageCap.setMethod("<%=action.getMethod()%>");
			messageCap.sethasDefaultMapping(<%=hasDefaultMapping%>);
			<%if (!hasDefaultMapping) {%>
			messageCap.setCi(m_componentIdentifier);
			<%} else {%>
			messageCap.setCi(getPseudoComponentIdentifier());<%}%>
			<%for (Param parameter : params) {
			String paramName = parameter.getName();%>
			<%String translatedParamName = nameLoader.translateFromCompSystem(paramName);%>
			Assert.verify(<%=translatedParamName%> != null, "Argument '<%=translatedParamName%>' must not be null");
				<%String paramType = paramMap.get(paramName);%>
				<%if (nameLoader.isInEnumMap(paramType)) {%>
			messageCap.addMessageParam(new MessageParam(<%=translatedParamName%>.rcValue(), "java.lang.String"));
				<%} else {%>
			messageCap.addMessageParam(new MessageParam(<%=translatedParamName%>.toString(), "<%=paramType%>"));
				<%}%>
			<%}%>
			return messageCap;
		}<%}%>
	<%}%>
}
<%}%> 

Back to the top