|
Added
Link Here
|
| 1 |
package org.eclipse.jst.j2ee.ejb.internal.operations; |
| 2 |
|
| 3 |
import java.util.*; |
| 4 |
|
| 5 |
import org.eclipse.jst.j2ee.internal.common.operations.*; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
@SuppressWarnings("restriction") |
| 10 |
public class EjbTimerTemplate { |
| 11 |
protected static String nl; |
| 12 |
public static synchronized EjbTimerTemplate create(String lineSeparator) |
| 13 |
{ |
| 14 |
nl = lineSeparator; |
| 15 |
EjbTimerTemplate result = new EjbTimerTemplate(); |
| 16 |
nl = null; |
| 17 |
return result; |
| 18 |
} |
| 19 |
|
| 20 |
public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; //$NON-NLS-1$ |
| 21 |
protected final String TEXT_1 = "package "; //$NON-NLS-1$ |
| 22 |
protected final String TEXT_2 = ";"; //$NON-NLS-1$ |
| 23 |
protected final String TEXT_3 = NL; |
| 24 |
protected final String TEXT_4 = NL + "import "; //$NON-NLS-1$ |
| 25 |
protected final String TEXT_5 = ";"; //$NON-NLS-1$ |
| 26 |
protected final String TEXT_6 = NL + NL + "@Stateless"; //$NON-NLS-1$ |
| 27 |
protected final String TEXT_7 = NL + "public "; //$NON-NLS-1$ |
| 28 |
protected final String TEXT_8 = "abstract "; //$NON-NLS-1$ |
| 29 |
protected final String TEXT_9 = "final "; //$NON-NLS-1$ |
| 30 |
protected final String TEXT_10 = "class "; //$NON-NLS-1$ |
| 31 |
protected final String TEXT_11 = " extends "; //$NON-NLS-1$ |
| 32 |
protected final String TEXT_12 = " implements "; //$NON-NLS-1$ |
| 33 |
protected final String TEXT_13 = ", "; //$NON-NLS-1$ |
| 34 |
protected final String TEXT_14 = " {"; //$NON-NLS-1$ |
| 35 |
protected final String TEXT_15 = NL + NL + " /**" + NL + " * Default constructor. " + NL + " */" + NL + " public "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| 36 |
protected final String TEXT_16 = "() {" + NL + " // TODO Auto-generated constructor stub" + NL + " }"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 37 |
protected final String TEXT_17 = NL + " " + NL + " /**" + NL + " * @see "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 38 |
protected final String TEXT_18 = "#"; //$NON-NLS-1$ |
| 39 |
protected final String TEXT_19 = "("; //$NON-NLS-1$ |
| 40 |
protected final String TEXT_20 = ")" + NL + " */" + NL + " public "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 41 |
protected final String TEXT_21 = "("; //$NON-NLS-1$ |
| 42 |
protected final String TEXT_22 = ") {" + NL + " super("; //$NON-NLS-1$ //$NON-NLS-2$ |
| 43 |
protected final String TEXT_23 = ");" + NL + " // TODO Auto-generated constructor stub" + NL + " }"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 44 |
protected final String TEXT_24 = NL + NL + "\t/**" + NL + " * @see "; //$NON-NLS-1$ //$NON-NLS-2$ |
| 45 |
protected final String TEXT_25 = "#"; //$NON-NLS-1$ |
| 46 |
protected final String TEXT_26 = "("; //$NON-NLS-1$ |
| 47 |
protected final String TEXT_27 = ")" + NL + " */" + NL + " public "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 48 |
protected final String TEXT_28 = " "; //$NON-NLS-1$ |
| 49 |
protected final String TEXT_29 = "("; //$NON-NLS-1$ |
| 50 |
protected final String TEXT_30 = ") {" + NL + " // TODO Auto-generated method stub"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 51 |
protected final String TEXT_31 = NL + "\t\t\treturn "; //$NON-NLS-1$ |
| 52 |
protected final String TEXT_32 = ";"; //$NON-NLS-1$ |
| 53 |
protected final String TEXT_33 = NL + " }"; //$NON-NLS-1$ |
| 54 |
protected final String TEXT_34 = NL + "\t"; //$NON-NLS-1$ |
| 55 |
protected final String TEXT_35 = NL + "\t@SuppressWarnings(\"unused\")" + NL + "\t@Schedule("; //$NON-NLS-1$ //$NON-NLS-2$ |
| 56 |
protected final String TEXT_36 = ")" + NL + " private void scheduledTimeout(final Timer t) {" + NL + " System.out.println(\"@Schedule called at: \" + new java.util.Date());" + NL + " }" + NL + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
| 57 |
|
| 58 |
public String generate(Object argument) |
| 59 |
{ |
| 60 |
final StringBuffer stringBuffer = new StringBuffer(); |
| 61 |
AddEjbTimerTemplateModel model = (AddEjbTimerTemplateModel) argument; |
| 62 |
/* This Content is provided under the terms and conditions of the Eclipse Public License Version 1.0 |
| 63 |
("EPL"). A copy of the EPL is available at http://www.eclipse.org/org/documents/epl-v10.php |
| 64 |
For purposes of the EPL, "Program" will mean the Content. |
| 65 |
|
| 66 |
Copied from org.eclipse.jst.j2ee.ejb plugin. */ |
| 67 |
|
| 68 |
model.removeFlags(CreateJavaEEArtifactTemplateModel.FLAG_QUALIFIED_SUPERCLASS_NAME); |
| 69 |
|
| 70 |
/* This Content is provided under the terms and conditions of the Eclipse Public License Version 1.0 |
| 71 |
("EPL"). A copy of the EPL is available at http://www.eclipse.org/org/documents/epl-v10.php |
| 72 |
For purposes of the EPL, "Program" will mean the Content. |
| 73 |
|
| 74 |
Copied from org.eclipse.jst.j2ee.ejb plugin. */ |
| 75 |
|
| 76 |
if (model.getJavaPackageName() != null && model.getJavaPackageName().length() > 0) { |
| 77 |
|
| 78 |
stringBuffer.append(TEXT_1); |
| 79 |
stringBuffer.append( model.getJavaPackageName() ); |
| 80 |
stringBuffer.append(TEXT_2); |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
stringBuffer.append(TEXT_3); |
| 85 |
/* This Content is provided under the terms and conditions of the Eclipse Public License Version 1.0 |
| 86 |
("EPL"). A copy of the EPL is available at http://www.eclipse.org/org/documents/epl-v10.php |
| 87 |
For purposes of the EPL, "Program" will mean the Content. |
| 88 |
|
| 89 |
Copied from org.eclipse.jst.j2ee.ejb plugin. */ |
| 90 |
|
| 91 |
Collection<String> imports = model.getImports(); |
| 92 |
for (String anImport : imports) { |
| 93 |
|
| 94 |
stringBuffer.append(TEXT_4); |
| 95 |
stringBuffer.append( anImport ); |
| 96 |
stringBuffer.append(TEXT_5); |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
stringBuffer.append(TEXT_6); |
| 101 |
/* This Content is provided under the terms and conditions of the Eclipse Public License Version 1.0 |
| 102 |
("EPL"). A copy of the EPL is available at http://www.eclipse.org/org/documents/epl-v10.php |
| 103 |
For purposes of the EPL, "Program" will mean the Content. |
| 104 |
|
| 105 |
Copied from org.eclipse.jst.j2ee.ejb plugin. */ |
| 106 |
|
| 107 |
if (model.isPublic()) { |
| 108 |
|
| 109 |
stringBuffer.append(TEXT_7); |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
if (model.isAbstract()) { |
| 114 |
|
| 115 |
stringBuffer.append(TEXT_8); |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
if (model.isFinal()) { |
| 120 |
|
| 121 |
stringBuffer.append(TEXT_9); |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
stringBuffer.append(TEXT_10); |
| 126 |
stringBuffer.append( model.getClassName() ); |
| 127 |
|
| 128 |
String superClass = model.getSuperclassName(); |
| 129 |
if (superClass != null && superClass.length() > 0) { |
| 130 |
|
| 131 |
stringBuffer.append(TEXT_11); |
| 132 |
stringBuffer.append( superClass ); |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
List<String> interfaces = model.getInterfaces(); |
| 137 |
if ( interfaces.size() > 0) { |
| 138 |
|
| 139 |
stringBuffer.append(TEXT_12); |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
for (int i = 0; i < interfaces.size(); i++) { |
| 144 |
String INTERFACE = interfaces.get(i); |
| 145 |
if (i > 0) { |
| 146 |
|
| 147 |
stringBuffer.append(TEXT_13); |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
stringBuffer.append( INTERFACE ); |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
stringBuffer.append(TEXT_14); |
| 156 |
/* This Content is provided under the terms and conditions of the Eclipse Public License Version 1.0 |
| 157 |
("EPL"). A copy of the EPL is available at http://www.eclipse.org/org/documents/epl-v10.php |
| 158 |
For purposes of the EPL, "Program" will mean the Content. |
| 159 |
|
| 160 |
Copied from org.eclipse.jst.j2ee.ejb plugin. */ |
| 161 |
|
| 162 |
if (!model.hasEmptySuperclassConstructor()) { |
| 163 |
|
| 164 |
stringBuffer.append(TEXT_15); |
| 165 |
stringBuffer.append( model.getClassName() ); |
| 166 |
stringBuffer.append(TEXT_16); |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
if (model.shouldGenSuperclassConstructors()) { |
| 171 |
List<Constructor> constructors = model.getConstructors(); |
| 172 |
for (Constructor constructor : constructors) { |
| 173 |
if (constructor.isPublic() || constructor.isProtected()) { |
| 174 |
|
| 175 |
stringBuffer.append(TEXT_17); |
| 176 |
stringBuffer.append( model.getSuperclassName() ); |
| 177 |
stringBuffer.append(TEXT_18); |
| 178 |
stringBuffer.append( model.getSuperclassName() ); |
| 179 |
stringBuffer.append(TEXT_19); |
| 180 |
stringBuffer.append( constructor.getParamsForJavadoc() ); |
| 181 |
stringBuffer.append(TEXT_20); |
| 182 |
stringBuffer.append( model.getClassName() ); |
| 183 |
stringBuffer.append(TEXT_21); |
| 184 |
stringBuffer.append( constructor.getParamsForDeclaration() ); |
| 185 |
stringBuffer.append(TEXT_22); |
| 186 |
stringBuffer.append( constructor.getParamsForCall() ); |
| 187 |
stringBuffer.append(TEXT_23); |
| 188 |
|
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
/* This Content is provided under the terms and conditions of the Eclipse Public License Version 1.0 |
| 194 |
("EPL"). A copy of the EPL is available at http://www.eclipse.org/org/documents/epl-v10.php |
| 195 |
For purposes of the EPL, "Program" will mean the Content. |
| 196 |
|
| 197 |
Copied from org.eclipse.jst.j2ee.ejb plugin. */ |
| 198 |
|
| 199 |
if (model.shouldImplementAbstractMethods()) { |
| 200 |
for (Method method : model.getUnimplementedMethods()) { |
| 201 |
|
| 202 |
stringBuffer.append(TEXT_24); |
| 203 |
stringBuffer.append( method.getContainingJavaClass() ); |
| 204 |
stringBuffer.append(TEXT_25); |
| 205 |
stringBuffer.append( method.getName() ); |
| 206 |
stringBuffer.append(TEXT_26); |
| 207 |
stringBuffer.append( method.getParamsForJavadoc() ); |
| 208 |
stringBuffer.append(TEXT_27); |
| 209 |
stringBuffer.append( method.getReturnType() ); |
| 210 |
stringBuffer.append(TEXT_28); |
| 211 |
stringBuffer.append( method.getName() ); |
| 212 |
stringBuffer.append(TEXT_29); |
| 213 |
stringBuffer.append( method.getParamsForDeclaration() ); |
| 214 |
stringBuffer.append(TEXT_30); |
| 215 |
|
| 216 |
String defaultReturnValue = method.getDefaultReturnValue(); |
| 217 |
if (defaultReturnValue != null) { |
| 218 |
|
| 219 |
stringBuffer.append(TEXT_31); |
| 220 |
stringBuffer.append( defaultReturnValue ); |
| 221 |
stringBuffer.append(TEXT_32); |
| 222 |
|
| 223 |
} |
| 224 |
|
| 225 |
stringBuffer.append(TEXT_33); |
| 226 |
|
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
stringBuffer.append(TEXT_34); |
| 231 |
|
| 232 |
String schedule = model.getProperty(AddEjbTimerDataModelProvider.SCHEDULE).trim(); |
| 233 |
|
| 234 |
stringBuffer.append(TEXT_35); |
| 235 |
stringBuffer.append( schedule ); |
| 236 |
stringBuffer.append(TEXT_36); |
| 237 |
return stringBuffer.toString(); |
| 238 |
} |
| 239 |
} |