001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: *
022: * Copyright 2005 Sun Microsystems, Inc.
023: *
024: * Licensed under the Apache License, Version 2.0 (the "License");
025: * you may not use this file except in compliance with the License.
026: * You may obtain a copy of the License at
027: *
028: * http://www.apache.org/licenses/LICENSE-2.0
029: *
030: * Unless required by applicable law or agreed to in writing, software
031: * distributed under the License is distributed on an "AS IS" BASIS,
032: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
033: * See the License for the specific language governing permissions and
034: * limitations under the License.
035: *
036: */
037:
038: package org.netbeans.modules.jdbcwizard.wizards;
039:
040: import java.awt.Component;
041: import java.util.HashSet;
042: import java.util.Iterator;
043: import java.util.List;
044: import java.util.Set;
045: import java.util.Arrays;
046: import java.io.File;
047: import java.io.FileOutputStream;
048:
049: import javax.swing.event.ChangeListener;
050: import javax.swing.event.ChangeEvent;
051:
052: import org.openide.NotifyDescriptor;
053: import org.openide.WizardDescriptor;
054: import org.openide.util.HelpCtx;
055:
056: import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBColumn;
057: import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBTable;
058: import org.netbeans.modules.jdbcwizard.builder.util.XMLCharUtil;
059: import org.netbeans.modules.jdbcwizard.builder.wsdl.GenerateWSDL;
060: import org.netbeans.modules.jdbcwizard.builder.xsd.XSDGenerator;
061: import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBConnectionDefinition;
062:
063: /**
064: * @author npedapudi
065: */
066: public class JNDINamePanel extends javax.swing.JPanel implements
067: WizardDescriptor.Panel {
068:
069: /**
070: *
071: */
072: private static final long serialVersionUID = 1L;
073:
074: protected final Set listeners = new HashSet(1);
075:
076: private static final String XSD_EXT = ".xsd";
077:
078: private static final boolean enableNext = false;
079:
080: private static final String JNDI_DEFAULT_NAME = "jdbc/__defaultDS";
081:
082: private static final String CONNECTION_INFO_FILE = "config\\ConnectionInfo.xml";
083:
084: /** Creates new form JNDINamePanel */
085: public JNDINamePanel(final String title) {
086: if (title != null && title.trim().length() != 0) {
087: this .setName(title);
088: }
089: this .initComponents();
090: }
091:
092: /**
093: * intializes the components
094: */
095: private void initComponents() {
096: this .jLabel1 = new javax.swing.JLabel();
097: this .jTextField1 = new javax.swing.JTextField();
098: this .jTextField1.setText(JNDINamePanel.JNDI_DEFAULT_NAME);
099:
100: this .jLabel1.setText("JNDI Name:");
101:
102: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
103: this );
104: this .setLayout(layout);
105: layout
106: .setHorizontalGroup(layout
107: .createParallelGroup(
108: org.jdesktop.layout.GroupLayout.LEADING)
109: .add(
110: layout
111: .createSequentialGroup()
112: .add(55, 55, 55)
113: .add(
114: this .jLabel1,
115: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
116: 70,
117: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
118: .add(28, 28, 28)
119: .add(
120: this .jTextField1,
121: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
122: 179,
123: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
124: .addContainerGap(68,
125: Short.MAX_VALUE)));
126: layout
127: .setVerticalGroup(layout
128: .createParallelGroup(
129: org.jdesktop.layout.GroupLayout.LEADING)
130: .add(
131: layout
132: .createSequentialGroup()
133: .add(133, 133, 133)
134: .add(
135: layout
136: .createParallelGroup(
137: org.jdesktop.layout.GroupLayout.BASELINE)
138: .add(
139: this .jLabel1)
140: .add(
141: this .jTextField1,
142: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
143: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
144: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
145: .addContainerGap(128,
146: Short.MAX_VALUE)));
147: }
148:
149: /**
150: * @return
151: */
152: public Component getComponent() {
153: return this ;
154: }
155:
156: /**
157: * @return
158: */
159: public HelpCtx getHelp() {
160: // Show no Help button for this panel:
161: return new HelpCtx(JNDINamePanel.class);
162: }
163:
164: /**
165: * @param settings
166: */
167: public void readSettings(final Object settings) {
168: WizardDescriptor wd = null;
169: if (settings instanceof JDBCWizardContext) {
170: final JDBCWizardContext wizardContext = (JDBCWizardContext) settings;
171: wd = (WizardDescriptor) wizardContext
172: .getProperty(JDBCWizardContext.WIZARD_DESCRIPTOR);
173:
174: } else if (settings instanceof WizardDescriptor) {
175: wd = (WizardDescriptor) settings;
176: }
177: final Object selectedOption = wd.getValue();
178: final boolean isAdvancingPanel = selectedOption == WizardDescriptor.NEXT_OPTION
179: || selectedOption == WizardDescriptor.FINISH_OPTION;
180:
181: if (isAdvancingPanel) {
182:
183: }
184:
185: }
186:
187: /**
188: * @param settings
189: */
190: public void storeSettings(final Object settings) {
191: WizardDescriptor wd = null;
192: if (settings instanceof JDBCWizardContext) {
193: final JDBCWizardContext wizardContext = (JDBCWizardContext) settings;
194: wd = (WizardDescriptor) wizardContext
195: .getProperty(JDBCWizardContext.WIZARD_DESCRIPTOR);
196:
197: } else if (settings instanceof WizardDescriptor) {
198: wd = (WizardDescriptor) settings;
199: }
200:
201: if (wd != null) {
202:
203: final Object selectedOption = wd.getValue();
204: if (NotifyDescriptor.CANCEL_OPTION == selectedOption
205: || NotifyDescriptor.CLOSED_OPTION == selectedOption) {
206: return;
207: }
208: // Need to revisit the code here
209: final boolean isAdvancingPanel = selectedOption == WizardDescriptor.NEXT_OPTION
210: || selectedOption == WizardDescriptor.FINISH_OPTION;
211:
212: if (isAdvancingPanel) {
213: final Object[] listObj = (Object[]) wd
214: .getProperty(JDBCWizardContext.SELECTEDTABLES);
215: final List list = Arrays.asList(listObj);
216: final String jndiName = this .jTextField1.getText()
217: .trim();
218: try {
219: final XSDGenerator xsdGen = new XSDGenerator();
220: final String targetFolderPath = (String) wd
221: .getProperty(JDBCWizardContext.TARGETFOLDER_PATH);
222: final String collabName = (String) wd
223: .getProperty(JDBCWizardContext.COLLABORATION_NAME);
224: DBTable selTable = null;
225: final Iterator it = list.iterator();
226: while (it.hasNext()) {
227: final DBTable sTable = (DBTable) it.next();
228: if (sTable.isSelected()) {
229: //Make the xsd file name as valid name
230: //Otherwise this will fail in "schemalocation" of the wsdl
231: // the reaso ins schemalocation in wsdl is NCName
232: xsdGen
233: .generate(
234: sTable.getName(),
235: targetFolderPath
236: + File.separator
237: + XMLCharUtil
238: .makeValidNCName(sTable
239: .getName())
240: + JNDINamePanel.XSD_EXT,
241: sTable);
242: selTable = sTable;
243: }
244: }
245:
246: // Generate WSDL
247: final String dbType = (String) wd
248: .getProperty(JDBCWizardContext.DBTYPE);
249:
250: final GenerateWSDL tsk = new GenerateWSDL();
251: tsk.setSrcDirectoryLocation(targetFolderPath);
252: tsk.setWSDLFileName(collabName);
253: tsk.setDBTable(selTable);
254: tsk.setDBType(dbType);
255: tsk.setJNDIName(jndiName);
256: tsk
257: .setDBInfo((DBConnectionDefinition) wd
258: .getProperty(JDBCWizardContext.CONNECTION_INFO));
259: tsk.execute();
260:
261: } catch (final Exception e) {
262:
263: }
264: }
265: }
266: }
267:
268: /**
269: * @param l
270: */
271: public void addChangeListener(final ChangeListener l) {
272: synchronized (this .listeners) {
273: this .listeners.add(l);
274: }
275: }
276:
277: /**
278: * @param l
279: */
280: public void removeChangeListener(final ChangeListener l) {
281: synchronized (this .listeners) {
282: this .listeners.remove(l);
283: }
284: }
285:
286: /**
287: *
288: *
289: */
290: public void fireChangeEvent() {
291: Iterator it;
292:
293: synchronized (this .listeners) {
294: it = new HashSet(this .listeners).iterator();
295: }
296:
297: final ChangeEvent ev = new ChangeEvent(this );
298: while (it.hasNext()) {
299: ((ChangeListener) it.next()).stateChanged(ev);
300: }
301: }
302:
303: /**
304: * @see org.openide.WizardDescriptor.Panel#isValid
305: */
306: public boolean isValid() {
307: if (this .enableNext) {
308: return true;
309: }
310:
311: return super .isValid();
312: }
313:
314: // Variables declaration - do not modify
315: private javax.swing.JLabel jLabel1;
316:
317: private javax.swing.JTextField jTextField1;
318: // End of variables declaration
319:
320: }
|