Skip to main content
summaryrefslogtreecommitdiffstats
blob: d456f896e9b2a857e943488663290dfc288772ac (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
/*******************************************************************************
 * 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.command;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.ws.internal.consumption.codegen.Generator;
import org.eclipse.wst.command.internal.env.common.FileResourceUtils;
import org.eclipse.wst.command.internal.env.core.common.StatusUtils;
import org.eclipse.wst.command.internal.env.core.context.ResourceContext;
import org.eclipse.wst.common.environment.IEnvironment;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
import org.eclipse.wst.ws.internal.datamodel.Element;
import org.eclipse.wst.ws.internal.datamodel.Model;


/**
 * MofToBeanModelCommand
 * Creation date: (4/10/2001 12:41:48 PM)
 * @author: Gilbert Andrews
 */
public class GeneratePageCommand extends AbstractDataModelOperation 
{
		
private Model model_;
private Generator fGenerator;
private IFile fIFile;
private ResourceContext resourceContext_;
private StringBuffer fStringBuffer;

/**
 * Build constructor comment.
 */
public GeneratePageCommand()
{
}

/**
* Constructor
* This command will generate code from a Model
* @param model The model to be traversed
* @param generator The code generator to be used
* @param resource the resource to place the finished product
*/
public GeneratePageCommand(ResourceContext context, Model model, Generator generator, IFile file)
{
  model_ = model;
  fGenerator = generator;
  fIFile = file;
  resourceContext_ = context;
}

public Model getJavaDataModel()
{
  return model_;
}

/**
 *
 */
public IStatus execute( IProgressMonitor monitor, IAdaptable adaptable )
{
  IEnvironment env = getEnvironment();
  
  IStatus status = Status.OK_STATUS;
  try {
    fGenerator.visit(model_.getRootElement());
    fStringBuffer = fGenerator.getStringBuffer();
    String tempString = fStringBuffer.toString();
    OutputStream fileResource = FileResourceUtils.newFileOutputStream(resourceContext_, fIFile.getFullPath(), monitor, env.getStatusHandler());
    //PrintStream ps = new PrintStream(fileResource);
    //ps.print(tempString);
    OutputStreamWriter osw = new OutputStreamWriter(fileResource,"UTF-8");
    osw.write(tempString,0,fStringBuffer.length());  
    osw.close();
    fileResource.close();
    return status;
  } catch (IOException ioexc) {
  	status = StatusUtils.errorStatus( ioexc );
  	return status;
  }
}

public void setRootElement(Element rootElement)
{
}

}

Back to the top