Skip to main content
summaryrefslogtreecommitdiffstats
blob: 586bba91aec4ddf968c4bc94ba40438448a6494c (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
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.sampleapp.codegen;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.ws.internal.common.StringUtils;
import org.eclipse.jst.ws.internal.consumption.codegen.Generator;
import org.eclipse.jst.ws.internal.consumption.codegen.bean.MethodVisitor;
import org.eclipse.jst.ws.internal.consumption.datamodel.beanmodel.BeanElement;
import org.eclipse.wst.ws.internal.datamodel.Element;


/**
* Objects of this class represent a MethodFilegenerator.
* */
public class ResultFileGenerator extends Generator 
{
  public static String TRIPLE_TAB = Generator.DOUBLE_TAB + Generator.TAB; 
  public static String QUAD_TAB = Generator.DOUBLE_TAB + Generator.DOUBLE_TAB;
  
  private String setEndpointMethod;

  /**
  * Constructor.
  * 
  */
  public ResultFileGenerator ()
  {
      super();
  }

   /**
  * Constructor.
  * 
  */
  public ResultFileGenerator (StringBuffer buffer)
  {
      super(buffer);
  }

  //takes in a bean node
  public IStatus visit (Object object)
  {
      Element beanElement = (Element)object;
      BeanElement bean = (BeanElement)beanElement;
      fbuffer.append("<%@page contentType=\"text/html;charset=UTF-8\"%>");
      fbuffer.append("<HTML>" + StringUtils.NEWLINE);
      fbuffer.append("<HEAD>" + StringUtils.NEWLINE);
      fbuffer.append("<TITLE>Result</TITLE>" + StringUtils.NEWLINE);
      fbuffer.append("</HEAD>" + StringUtils.NEWLINE);
      fbuffer.append("<BODY>" + StringUtils.NEWLINE);
      fbuffer.append("<H1>Result</H1>" + StringUtils.NEWLINE + StringUtils.NEWLINE);

      fbuffer.append("<jsp:useBean id=\""+ getSessionBeanId() + "\" scope=\"session\" class=\"");
      fbuffer.append(bean.getName() + "\" />" + StringUtils.NEWLINE);
      if (setEndpointMethod != null && setEndpointMethod.length() > 0)
      {
        fbuffer.append("<%");
        fbuffer.append(StringUtils.NEWLINE);
        fbuffer.append("if (request.getParameter(\"endpoint\") != null && request.getParameter(\"endpoint\").length() > 0)");
        fbuffer.append(StringUtils.NEWLINE);
        fbuffer.append(getSessionBeanId());
        fbuffer.append(".");
        int index = setEndpointMethod.indexOf('?');
        if (index != -1)
        {
          fbuffer.append(setEndpointMethod.substring(0, index));
          fbuffer.append("(new ");
          fbuffer.append(setEndpointMethod.substring(index+1, setEndpointMethod.length()));
          fbuffer.append("(request.getParameter(\"endpoint\")));");
        }
        else
        {
          fbuffer.append(setEndpointMethod);
          fbuffer.append("(request.getParameter(\"endpoint\"));");
        }
        fbuffer.append(StringUtils.NEWLINE);
        fbuffer.append("%>");
        fbuffer.append(StringUtils.NEWLINE);
      }
      fbuffer.append(StringUtils.NEWLINE); 
            
      //carry on with regular gorp
      fbuffer.append("<%" + StringUtils.NEWLINE);
      fbuffer.append("String method = request.getParameter(\"method\");" + StringUtils.NEWLINE);
      fbuffer.append("int methodID = 0;" + StringUtils.NEWLINE);
      fbuffer.append("if (method == null) methodID = -1;" + StringUtils.NEWLINE + "" + StringUtils.NEWLINE);
      fbuffer.append("if(methodID != -1) methodID = Integer.parseInt(method);" + StringUtils.NEWLINE); 
      fbuffer.append("boolean gotMethod = false;" + StringUtils.NEWLINE + StringUtils.NEWLINE);

      fbuffer.append("try {" + StringUtils.NEWLINE);
      fbuffer.append("switch (methodID){ " + StringUtils.NEWLINE);
    
      // go to the next generator
      MethodVisitor methodVisitor = new MethodVisitor();
      ResultFileHelp1Generator resultFileHelp1Generator = new ResultFileHelp1Generator(fbuffer); 
      resultFileHelp1Generator.setNumberFactory(getNumberFactory());
      resultFileHelp1Generator.setClientFolderPath(getClientFolderPath());
      methodVisitor.run(beanElement,resultFileHelp1Generator);
      setNumberFactory(resultFileHelp1Generator.getNumberFactory());

      fbuffer = resultFileHelp1Generator.getStringBuffer();
 
      fbuffer.append("}" + StringUtils.NEWLINE);    
      fbuffer.append("} catch (Exception e) { " + StringUtils.NEWLINE);
      fbuffer.append("%>" + StringUtils.NEWLINE);
      fbuffer.append("exception: <%= e %>" + StringUtils.NEWLINE);
      fbuffer.append("<%" + StringUtils.NEWLINE);
      fbuffer.append("return;" + StringUtils.NEWLINE);
      fbuffer.append("}" + StringUtils.NEWLINE);
      fbuffer.append("if(!gotMethod){" + StringUtils.NEWLINE);
      fbuffer.append("%>" + StringUtils.NEWLINE);
      fbuffer.append("result: N/A" + StringUtils.NEWLINE);
      fbuffer.append("<%" + StringUtils.NEWLINE);
      fbuffer.append("}" + StringUtils.NEWLINE);
      fbuffer.append("%>" + StringUtils.NEWLINE);
      fbuffer.append("</BODY>" + StringUtils.NEWLINE);
      fbuffer.append("</HTML>");

      return Status.OK_STATUS;
    }

  /**
   * @param setEndpointMethod The setEndpointMethod to set.
   */
  public void setSetEndpointMethod(String setEndpointMethod)
  {
    this.setEndpointMethod = setEndpointMethod;
  }
}

Back to the top