1 2 24 package org.enhydra.tool.codegen.internal; 25 26 import org.enhydra.tool.codegen.wizard.CodeGenPanel; 28 import org.enhydra.tool.codegen.wizard.ServiceOptionPanel1; 29 import org.enhydra.tool.codegen.wizard.ProjectOptionPanel2; 30 import org.enhydra.tool.codegen.wizard.ServiceOptionPanel3; 31 import org.enhydra.tool.codegen.ProjectGenerator; 32 import org.enhydra.tool.codegen.GeneratorException; 33 import org.enhydra.tool.common.Replacement; 34 import org.enhydra.tool.common.ToolException; 35 36 import java.util.ArrayList ; 38 import java.util.Arrays ; 39 40 43 public class ServiceGenerator extends ProjectGenerator { 44 45 48 public static final String COMMAND_NAME = "service"; 50 53 public static final String displayName = "Enhydra Service"; 54 public static final String wizardTitle = "Enhydra Service Wizard"; 55 private CodeGenPanel[] panels = null; 56 57 60 public ServiceGenerator() { 61 setReplacementSet(new ServiceReplacementSet()); 62 setOptionSet(new ServiceOptionSet()); 63 } 64 65 public CodeGenPanel[] getWizardPanels() throws GeneratorException { 66 67 if (panels == null && isSwing()) { 69 panels = new CodeGenPanel[3]; 70 panels[0] = new ServiceOptionPanel1(); 71 panels[1] = new ProjectOptionPanel2(); 72 panels[2] = new ServiceOptionPanel3(); 73 for (int i = 0; i < panels.length; i++) { 74 panels[i].setOptionSet(getOptionSet()); 75 panels[i].readOptionSet(); 76 } 77 } 78 return panels; 79 } 80 81 84 public String [] getOutputExcludes() { 85 String [] ex = new String [0]; 86 ArrayList list = null; 87 88 list = new ArrayList (Arrays.asList(super.getOutputExcludes())); 89 90 if (!isMBean()) { list.add("qualfiers.xml"); list.add("MBean.java"); } 95 list.trimToSize(); 96 ex = new String [list.size()]; 97 ex = (String []) list.toArray(ex); 98 list.clear(); 99 return ex; 100 } 101 102 protected String [] getInputIncludes() { 103 ArrayList list = null; 104 String [] includes = new String [0]; 105 106 list = new ArrayList (Arrays.asList(super.getInputIncludes())); 107 if (isMBean()) { 108 list.add("mbean"); 109 } else { 110 list.add("nombean"); 111 } 112 list.trimToSize(); 113 includes = new String [list.size()]; 114 includes = (String []) list.toArray(includes); 115 list.clear(); 116 return includes; 117 } 118 119 public void initReplacementSet() throws GeneratorException { 121 super.initReplacementSet(); 122 try { 123 String serviceName = null; 124 125 serviceName = 126 getOptionSet().lookup(ServiceOptionSet.SERVICE).getValue(); 127 getReplacementSet().lookup(ServiceReplacementSet.at_SERVICE_at).setReplaceWith(serviceName); 128 } catch (ToolException e) { 129 e.printStackTrace(); 130 throw new GeneratorException(e, 131 res.getString("Unable_to_init_rep")); 132 } 133 } 134 135 142 public String getCommandName() { 143 return COMMAND_NAME; 144 } 145 146 152 public String getDisplayName() { 153 return ServiceGenerator.displayName; 154 } 155 156 public String getWizardTitle() { 157 return ServiceGenerator.wizardTitle; 158 } 159 160 168 public String getDescription() { 169 return "Generate a simple service that extends the " 170 + "Enhydra application server. Refer to the service developer's " 171 + "guide for a detailed explaintion of how to implement an " 172 + "Enhydra service."; 173 } 174 175 protected String [] getDefaultAddinSteps() { 176 String [] steps = new String [5]; 177 178 steps[0] = "Build your project to compile all source files"; 179 steps[1] = "Start the Enhydra Multiserver from the command line:<BR> <code>$ cd <i>enhydra root</i>/bin</code><BR> <code>$ ./multiserver</code>"; 180 steps[2] = "Deploy the project by selecting Tools | Kelp Deployer.<BR> Click the Deploy button to create an archive and deploy it to the running multiserver."; 181 steps[3] = "Verify that the service has been successfully deployed by inspecting the multiserver console output.<BR><BR>"; 182 steps[4] = getCodeExampleStep(); 183 return steps; 184 } 185 186 protected String [] getDefaultShellSteps() { 187 String [] steps = new String [3]; 188 StringBuffer buf = new StringBuffer (); 189 190 buf.append("Use <eas_root>/bin/ant to compile your project"); 191 buf.append(" using the build.xml file."); 192 steps[0] = buf.toString(); 193 buf.setLength(0); 194 buf.append("To deploy your service, copy the jar from output/lib"); 195 buf.append(" to <eas_root>/deploy"); 196 steps[1] = buf.toString(); 197 steps[2] = getCodeExampleStep(); 198 return steps; 199 } 200 201 private String getCodeExampleStep() { 202 StringBuffer buf = new StringBuffer (); 203 String pack = new String (); 204 String service = new String (); 205 206 try { 207 pack = 208 getReplacementSet().lookup(ServiceReplacementSet.JAVA_PACKAGE).getReplaceWith()[0]; 209 service = 210 getReplacementSet().lookup(ServiceReplacementSet.at_SERVICE_at).getReplaceWith()[0]; 211 } catch (ToolException e) { 212 e.printStackTrace(System.err); 213 pack = "<package_name>"; 214 service = "<service_name>"; 215 } 216 buf.append("To access your new service from a client"); 217 buf.append(" application:"); 218 buf.append("<code><br>"); 219 buf.append("<br>javax.naming.Context ctx = new javax.naming.InitialContext();"); 220 buf.append("<br>Object obj = ctx.lookup(\"ems:/Services/" 221 + service + "/manager\");"); 222 buf.append("<br>" + pack + '.' + service + "Target target = (" + pack 223 + '.' + service + "Target) obj;"); 224 buf.append("<br>String greeting = target.getGreeting();"); 225 buf.append("<br></code>"); 226 return buf.toString(); 227 } 228 229 private boolean isMBean() { 230 boolean mbean = true; 231 232 try { 233 mbean = getOptionSet().lookup(ServiceOptionSet.MBEAN).isValue(); 234 } catch (GeneratorException e) { 235 e.printStackTrace(); 236 mbean = true; 237 } 238 return mbean; 239 } 240 241 } 242 | Popular Tags |