01: /*
02: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
03: *
04: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
05: *
06: * The contents of this file are subject to the terms of either the GNU
07: * General Public License Version 2 only ("GPL") or the Common
08: * Development and Distribution License("CDDL") (collectively, the
09: * "License"). You may not use this file except in compliance with the
10: * License. You can obtain a copy of the License at
11: * http://www.netbeans.org/cddl-gplv2.html
12: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13: * specific language governing permissions and limitations under the
14: * License. When distributing the software, include this License Header
15: * Notice in each file and include the License file at
16: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17: * particular file as subject to the "Classpath" exception as provided
18: * by Sun in the GPL Version 2 section of the License file that
19: * accompanied this code. If applicable, add the following below the
20: * License Header, with the fields enclosed by brackets [] replaced by
21: * your own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Contributor(s):
25: *
26: * Portions Copyrighted 2007 Sun Microsystems, Inc.
27: */
28: package org.netbeans.modules.db.explorer.actions;
29:
30: import java.io.File;
31: import java.io.FileOutputStream;
32: import java.io.ObjectOutputStream;
33: import java.util.Enumeration;
34: import org.netbeans.lib.ddl.impl.CreateTable;
35: import org.netbeans.lib.ddl.impl.Specification;
36: import org.netbeans.modules.db.explorer.infos.ColumnNodeInfo;
37:
38: /**
39: * This class refactors out logic from GrabTableAction so that we can unit
40: * test it
41: *
42: * @author <a href="mailto:david@vancouvering.com">David Van Couvering</a>
43: */
44: public class GrabTableHelper {
45:
46: public void execute(Specification spec, String tablename,
47: Enumeration nodeChildren, File file) throws Exception {
48: CreateTable cmd = spec.createCommandCreateTable(tablename);
49:
50: while (nodeChildren.hasMoreElements()) {
51: Object element = nodeChildren.nextElement();
52: if (element instanceof ColumnNodeInfo) {
53: cmd.getColumns().add(
54: ((ColumnNodeInfo) element)
55: .getColumnSpecification());
56: }
57: }
58:
59: FileOutputStream fstream = new FileOutputStream(file);
60: ObjectOutputStream ostream = new ObjectOutputStream(fstream);
61: cmd.setSpecification(null);
62: ostream.writeObject(cmd);
63: ostream.flush();
64: ostream.close();
65: }
66: }
|