Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8a2774bf15bef54207ccb7016db46a149865c7dc (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*******************************************************************************
 * Copyright (c) 2000, 2006 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
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20060811   153482 mahutch@ca.ibm.com - Mark Hutchinson
 *******************************************************************************/

package org.eclipse.jst.ws.internal.consumption.codegen;

import java.util.Vector;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;



/**
* Objects of this class represent a generator.
* */
public class Generator implements VisitorAction
{

  // Copyright
  public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";


  /**
  * The StringBuffer that holds the codegen 
  * */
  protected StringBuffer fbuffer; 

  /**
  * The Visitor that calls the visit method 
  * */
  protected Visitor fVisitor; 

  /**
  * Vector that holds state data for this  generator 
  * */
  protected Vector fResidentVector;
 
  /*
  * This int holds the current number 
  */
  protected int fUniqueNumber =0;
 

  protected String fClientFolderPath;

  public static final String FACTORY = "Factory"; 

  public static final String TAB = "    ";
  public static final String DOUBLE_TAB = "        ";
  public static final String SPACE = " ";
  
  /**
  * Constructor.
  * 
  */
  public Generator ()
  {
      fbuffer = new StringBuffer();
      fResidentVector = new Vector(); 
    
  }

  /**
  * Constructor.
  * @param StringBuffer Takes the buffer it will write code to
  */
  public Generator (StringBuffer buffer)
  {
      fbuffer = buffer;
      fResidentVector = new Vector(); 
  }
  
  public void initialize(String resident)
  {
    //nothing to be done but must be implemented
  }
  
  public String getClientFolderPath()
  {
    return fClientFolderPath;
  }

  public void setClientFolderPath(String fClientFolderPath_)
  {
    fClientFolderPath = fClientFolderPath_;
  }

  protected String serviceName = "";
  protected String portName = "";
  protected String packageName = "";
  protected String proxyBaseName = "";

  public void setInfo(String service, String port, String packageName, String proxyBase)
  {
    serviceName = service;
    portName = port;
    this.packageName = packageName; 
    proxyBaseName = proxyBase;  
  }

  private static final char UNDERSCORE = '_';
  public String getSessionBeanId()
  {
    String name = getClientFolderPath();
    int index = name.lastIndexOf("/");
    index++;
    StringBuffer newName = new StringBuffer(name.substring(index));
    
    //We need to make this a valid java identifier
    //To do this we will replace any character that is not valid with an underscore
    for (int i = 0; i < newName.length(); i++)
    {
    	char c = newName.charAt(i);
    	if (i == 0 && !Character.isJavaIdentifierStart(c) || !Character.isJavaIdentifierPart(c))
    	{
    		newName.setCharAt(i,UNDERSCORE);
    	}
    }
    return newName + "id";
  }

  /*
  * The Number Factory is here for naming purposes. In 
  * this way we insure no names we create in a piece of
  * code gen are the same. We keep track of the numbers
  * used and we hand back the next one. Like take a number 
  * buddy
  * @param int number we are at as the state data has to be settable
  */
  public void setNumberFactory(int number)
  {
     fUniqueNumber = number;
  }


  /*
  * This is a unique number for state purposes
  * @return int 
  */
  public int getNumberFactory()
  {
     return fUniqueNumber; 
  }
  /*
  * This is a unique number for naming purposes
  * @return int 
  */
  public int getUniqueNumber()
  {
     return fUniqueNumber++;
  }


  /**
  * returns the current StringBuffer
  * @return StringBuffer Takes the buffer it will write code too
  */
  public StringBuffer getStringBuffer ()
  {
      return fbuffer;
  }

  
  /**
  * returns the Visitor that called this generator
  * @return Visitor 
  */
  public Visitor getVisitor ()
  {
      return fVisitor;
  }
  



  /**
  * vector used to hold state data 
  * @parameter Visitor 
  */
  public void putResidentVector (Object object)
  {
      fResidentVector.addElement(object);
  }
  

  /**
  * vector used to hold state data 
  * @parameter Visitor 
  */
  public void setResidentVector (Vector vector)
  {
      fResidentVector = vector;
  }
  

  /**
  * returns the resident vector
  * @return Visitor 
  */
  public Vector getResidentVector ()
  {
      return fResidentVector;
  }
  

  /**
  * This function is used to initialize any state a generator may have
  *
  **/

  public void initialize()
  {
     //to be implemented in sublasses
  }


   /**
  * sets the visitor that calls the visit
  * @parameter Visitor 
  */

  public void setVisitor(Visitor visitor)
  {
      fVisitor = visitor;
  }


  public IStatus visit (Object object)
  {
   //implemented by subclasses
  	return Status.OK_STATUS;
  }
  

}

Back to the top