2ronwalf// The MIT License
2ronwalf//
2ronwalf// Copyright (c) 2004 Evren Sirin
2ronwalf//
2ronwalf// Permission is hereby granted, free of charge, to any person obtaining a copy
2ronwalf// of this software and associated documentation files (the "Software"), to
2ronwalf// deal in the Software without restriction, including without limitation the
2ronwalf// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2ronwalf// sell copies of the Software, and to permit persons to whom the Software is
2ronwalf// furnished to do so, subject to the following conditions:
2ronwalf//
2ronwalf// The above copyright notice and this permission notice shall be included in
2ronwalf// all copies or substantial portions of the Software.
2ronwalf//
2ronwalf// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2ronwalf// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2ronwalf// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2ronwalf// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2ronwalf// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2ronwalf// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2ronwalf// IN THE SOFTWARE.
2ronwalf
2ronwalfpackage examples;
2ronwalf
2ronwalfimport java.awt.Component;
2ronwalfimport java.awt.Dimension;
2ronwalfimport java.awt.GridBagConstraints;
2ronwalfimport java.awt.GridBagLayout;
2ronwalfimport java.awt.GridLayout;
2ronwalfimport java.awt.Insets;
2ronwalfimport java.awt.Window;
2ronwalfimport java.awt.event.ActionEvent;
2ronwalfimport java.awt.event.ActionListener;
2ronwalfimport java.io.File;
2ronwalfimport java.io.FileOutputStream;
2ronwalfimport java.net.MalformedURLException;
2ronwalfimport java.net.URI;
2ronwalfimport java.net.URISyntaxException;
2ronwalfimport java.util.ArrayList;
2ronwalfimport java.util.HashSet;
2ronwalfimport java.util.Iterator;
2ronwalfimport java.util.List;
2ronwalfimport java.util.Set;
2ronwalfimport java.util.Vector;
2ronwalf
2ronwalfimport javax.swing.BorderFactory;
2ronwalfimport javax.swing.Box;
2ronwalfimport javax.swing.BoxLayout;
2ronwalfimport javax.swing.ButtonGroup;
2ronwalfimport javax.swing.JButton;
2ronwalfimport javax.swing.JComboBox;
2ronwalfimport javax.swing.JComponent;
2ronwalfimport javax.swing.JDialog;
2ronwalfimport javax.swing.JFileChooser;
2ronwalfimport javax.swing.JFrame;
2ronwalfimport javax.swing.JLabel;
2ronwalfimport javax.swing.JList;
2ronwalfimport javax.swing.JOptionPane;
2ronwalfimport javax.swing.JPanel;
2ronwalfimport javax.swing.JRadioButton;
2ronwalfimport javax.swing.JScrollPane;
2ronwalfimport javax.swing.JTable;
2ronwalfimport javax.swing.JTextArea;
2ronwalfimport javax.swing.JTextField;
2ronwalfimport javax.swing.ListSelectionModel;
2ronwalfimport javax.swing.SwingConstants;
2ronwalfimport javax.swing.SwingUtilities;
2ronwalfimport javax.swing.WindowConstants;
2ronwalfimport javax.swing.event.ListSelectionEvent;
2ronwalfimport javax.swing.event.ListSelectionListener;
2ronwalfimport javax.swing.table.DefaultTableModel;
2ronwalfimport javax.swing.table.TableModel;
2ronwalfimport javax.xml.namespace.QName;
2ronwalf
2ronwalfimport org.mindswap.owl.OWLFactory;
2ronwalfimport org.mindswap.owl.OWLKnowledgeBase;
2ronwalfimport org.mindswap.owl.vocabulary.OWL;
2ronwalfimport org.mindswap.owl.vocabulary.XSD;
2ronwalfimport org.mindswap.utils.QNameProvider;
2ronwalfimport org.mindswap.utils.SwingUtils;
2ronwalfimport org.mindswap.utils.URIUtils;
2ronwalfimport org.mindswap.wsdl.WSDLConsts;
2ronwalfimport org.mindswap.wsdl.WSDLOperation;
2ronwalfimport org.mindswap.wsdl.WSDLParameter;
2ronwalfimport org.mindswap.wsdl.WSDLService;
2ronwalfimport org.mindswap.wsdl.WSDLTranslator;
2ronwalf
2ronwalf/**
2ronwalf * A simple to GUI to create OWL-S files from WSDL descriptions.
2ronwalf *
2ronwalf * @author Evren Sirin
2ronwalf */
2ronwalfpublic class WSDL2OWLS extends JPanel implements ActionListener {
2ronwalf final String[] nsColumnNames = {"Abbr", "URI"};
2ronwalf final String[] columnNames = {
2ronwalf "WSDL Parameter", "WSDL Type",
2ronwalf "OWL-S Name", "OWL Type", "XSLT"};
2ronwalf final String[][] emptyRow = new String[0][5];
2ronwalf final String[] defaultFiles = {
2ronwalf "http://cheeso.members.winisp.net/books/books.asmx?WSDL",
2ronwalf "http://www.mindswap.org/axis/services/TranslatorService?wsdl",
2ronwalf "http://www.mindswap.org/axis/services/DictionaryService?wsdl",
2ronwalf "http://www.swanandmokashi.com/HomePage/WebServices/StockQuotes.asmx?WSDL",
2ronwalf "http://www.tilisoft.com/ws/LocInfo/ZipCode.asmx?WSDL",
2ronwalf "http://www.webservicex.net/uszip.asmx?WSDL",
2ronwalf };
2ronwalf
2ronwalf public List savedServices = new ArrayList();
2ronwalf
2ronwalf JComboBox urls = new JComboBox(defaultFiles);
2ronwalf JList opList = new JList();
2ronwalf JTable inputTable = new JTable(emptyRow, columnNames);
2ronwalf JTable outputTable = new JTable(emptyRow, columnNames);
2ronwalf JTextField nameSpaceField = new JTextField();
2ronwalf JTextField serviceNameField= new JTextField();
2ronwalf JTextArea textDescription = new JTextArea(10, 20);
2ronwalf JTable nsTable = new JTable(0, 2);
2ronwalf JButton generateButton, addNSButton, removeNSButton;
2ronwalf
2ronwalf JDialog advanced;
2ronwalf JRadioButton prefixButton, manualButton;
2ronwalf JTextField prefixText = new JTextField();
2ronwalf JTextField serviceText = new JTextField();
2ronwalf JTextField profileText = new JTextField();
2ronwalf JTextField processText = new JTextField();
2ronwalf JTextField groundingText = new JTextField();
2ronwalf
2ronwalf
2ronwalf QNameProvider qnames = new QNameProvider();
2ronwalf
2ronwalf public WSDL2OWLS() {
2ronwalf JPanel contentPane = new JPanel();
2ronwalf JPanel addressPanel = new JPanel();
2ronwalf JPanel middlePanel = new JPanel();
2ronwalf JPanel operationsPanel = new JPanel();
2ronwalf JPanel detailsPanel = new JPanel();
2ronwalf JPanel buttonPanel = new JPanel();
2ronwalf
2ronwalf setLayout(new GridLayout(1,1));
2ronwalf add(contentPane);
2ronwalf contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
2ronwalf contentPane.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
2ronwalf contentPane.add(addressPanel);
2ronwalf contentPane.add(Box.createVerticalStrut(2));
2ronwalf contentPane.add(middlePanel);
2ronwalf contentPane.add(Box.createVerticalStrut(2));
2ronwalf contentPane.add(buttonPanel);
2ronwalf
2ronwalf JButton browseButton = new JButton("Browse Local...");
2ronwalf browseButton.setActionCommand("browse");
2ronwalf browseButton.addActionListener(this);
2ronwalf
2ronwalf
2ronwalf addressPanel.setLayout(new BoxLayout(addressPanel, BoxLayout.X_AXIS));
2ronwalf addressPanel.add(new JLabel("Enter URL: "));
2ronwalf addressPanel.add(Box.createHorizontalStrut(2));
2ronwalf addressPanel.add(urls); urls.setEditable(true); urls.setSelectedItem("");
2ronwalf addressPanel.add(Box.createHorizontalStrut(2));
2ronwalf addressPanel.add(browseButton);
2ronwalf addressPanel.add(Box.createHorizontalStrut(2));
2ronwalf
2ronwalf urls.setActionCommand("load");
2ronwalf urls.addActionListener(this);
2ronwalf
2ronwalf middlePanel.setLayout(new BoxLayout(middlePanel, BoxLayout.X_AXIS));
2ronwalf middlePanel.add(operationsPanel);
2ronwalf middlePanel.add(detailsPanel);
2ronwalf
2ronwalf operationsPanel.setBorder(BorderFactory.createTitledBorder("Operations"));
2ronwalf operationsPanel.setLayout(new BoxLayout(operationsPanel, BoxLayout.X_AXIS));
2ronwalf operationsPanel.add(new JScrollPane(opList));
2ronwalf opList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
2ronwalf opList.getSelectionModel().addListSelectionListener(
2ronwalf new ListSelectionListener() {
2ronwalf public void valueChanged(ListSelectionEvent e) {
2ronwalf if (e.getValueIsAdjusting()) return;
2ronwalf
2ronwalf doSelect();
2ronwalf }
2ronwalf }
2ronwalf );
2ronwalf
2ronwalf JPanel servicePanel = new JPanel();
2ronwalf JPanel inputsPanel = new JPanel();
2ronwalf JPanel outputsPanel = new JPanel();
2ronwalf JPanel nsPanel = new JPanel();
2ronwalf JPanel nsButtons = new JPanel();
2ronwalf
2ronwalf JScrollPane textDescriptionPane = new JScrollPane(textDescription);
2ronwalf textDescriptionPane.setPreferredSize(
2ronwalf new Dimension(textDescriptionPane.getPreferredSize().width, 50));
2ronwalf textDescriptionPane.setMinimumSize(
2ronwalf new Dimension(textDescriptionPane.getPreferredSize().width, 50));
2ronwalf
2ronwalf JButton advancedButton = new JButton("Advanced...");
2ronwalf advancedButton.setActionCommand("advanced");
2ronwalf advancedButton.addActionListener(this);
2ronwalf
2ronwalf servicePanel = createTableLayout(
2ronwalf new JComponent[] {
2ronwalf new JLabel("Service Name"),
2ronwalf new JLabel("Text description"),
2ronwalf new JLabel("Logical URI"),
2ronwalf// advancedButton,
2ronwalf },
2ronwalf new JComponent[] {
2ronwalf serviceNameField,
2ronwalf textDescriptionPane,
2ronwalf nameSpaceField,
2ronwalf// new JLabel("")
2ronwalf }
2ronwalf );
2ronwalf servicePanel.setBorder(BorderFactory.createTitledBorder("Service information"));
2ronwalf
2ronwalf textDescription.setLineWrap(true);
2ronwalf textDescription.setWrapStyleWord(true);
2ronwalf
2ronwalf nsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
2ronwalf nsTable.getSelectionModel().addListSelectionListener(
2ronwalf new ListSelectionListener() {
2ronwalf public void valueChanged(ListSelectionEvent e) {
2ronwalf if (e.getValueIsAdjusting()) return;
2ronwalf
2ronwalf removeNSButton.setEnabled(true);
2ronwalf }
2ronwalf }
2ronwalf );
2ronwalf
2ronwalf addNSButton = new JButton("Add");
2ronwalf removeNSButton = new JButton("Remove");
2ronwalf
2ronwalf addNSButton.setActionCommand("addNS");
2ronwalf addNSButton.addActionListener(this);
2ronwalf
2ronwalf removeNSButton.setActionCommand("removeNS");
2ronwalf removeNSButton.addActionListener(this);
2ronwalf
2ronwalf nsButtons.setLayout(new BoxLayout(nsButtons, BoxLayout.X_AXIS));
2ronwalf nsButtons.add(Box.createHorizontalGlue());
2ronwalf nsButtons.add(addNSButton);
2ronwalf nsButtons.add(Box.createHorizontalStrut(5));
2ronwalf nsButtons.add(removeNSButton);
2ronwalf
2ronwalf nsPanel.setLayout(new BoxLayout(nsPanel, BoxLayout.Y_AXIS));
2ronwalf nsPanel.setBorder(BorderFactory.createTitledBorder("Namespaces"));
2ronwalf nsPanel.add(new JScrollPane(nsTable));
2ronwalf nsPanel.add(Box.createVerticalStrut(2));
2ronwalf nsPanel.add(nsButtons);
2ronwalf
2ronwalf inputsPanel.setLayout(new BoxLayout(inputsPanel, BoxLayout.Y_AXIS));
2ronwalf inputsPanel.setBorder(BorderFactory.createTitledBorder("Inputs"));
2ronwalf inputsPanel.add(new JScrollPane(inputTable));
2ronwalf
2ronwalf outputsPanel.setLayout(new BoxLayout(outputsPanel, BoxLayout.Y_AXIS));
2ronwalf outputsPanel.setBorder(BorderFactory.createTitledBorder("Outputs"));
2ronwalf outputsPanel.add(new JScrollPane(outputTable));
2ronwalf
2ronwalf generateButton = new JButton("Generate OWL-S");
2ronwalf generateButton.setEnabled(false);
2ronwalf generateButton.setActionCommand("generate");
2ronwalf generateButton.addActionListener(this);
2ronwalf
2ronwalf JButton closeButton = new JButton("Close");
2ronwalf closeButton.setActionCommand("close");
2ronwalf closeButton.addActionListener(this);
2ronwalf
2ronwalf buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
2ronwalf buttonPanel.add(Box.createHorizontalGlue());
2ronwalf buttonPanel.add(generateButton);
2ronwalf buttonPanel.add(Box.createHorizontalStrut(10));
2ronwalf buttonPanel.add(closeButton);
2ronwalf
2ronwalf detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.Y_AXIS));
2ronwalf detailsPanel.add(servicePanel);
2ronwalf detailsPanel.add(inputsPanel);
2ronwalf detailsPanel.add(outputsPanel);
2ronwalf detailsPanel.add(nsPanel);
2ronwalf
2ronwalf qnames.setMapping("soapEnc", WSDLConsts.soapEnc + "#");
2ronwalf updateNS();
2ronwalf }
2ronwalf
2ronwalf public void actionPerformed(ActionEvent e) {
2ronwalf if(e.getActionCommand().equals("browse"))
2ronwalf doBrowse();
2ronwalf else if(e.getActionCommand().equals("load"))
2ronwalf doLoad();
2ronwalf else if(e.getActionCommand().equals("advanced"))
2ronwalf showAdvanced();
2ronwalf else if(e.getActionCommand().equals("addNS"))
2ronwalf addNS();
2ronwalf else if(e.getActionCommand().equals("removeNS"))
2ronwalf removeNS();
2ronwalf else if(e.getActionCommand().equals("generate"))
2ronwalf doGenerate();
2ronwalf else if(e.getActionCommand().equals("close")) {
2ronwalf Window window = SwingUtilities.getWindowAncestor( this );
2ronwalf if( window != null )
2ronwalf window.dispose();
2ronwalf else
2ronwalf System.exit( 0 );
2ronwalf }
2ronwalf else if(e.getActionCommand().equals("load"))
2ronwalf doLoad();
2ronwalf }
2ronwalf
2ronwalf JLabel createLabel(String text) {
2ronwalf JLabel label = new JLabel(text);
2ronwalf label.setAlignmentX(Component.LEFT_ALIGNMENT);
2ronwalf label.setVerticalAlignment(SwingConstants.TOP);
2ronwalf
2ronwalf int labelWidth = 100;
2ronwalf label.setPreferredSize(new Dimension(labelWidth, label.getPreferredSize().height));
2ronwalf label.setMaximumSize(new Dimension(labelWidth, label.getMaximumSize().height));
2ronwalf label.setMinimumSize(new Dimension(labelWidth, label.getMinimumSize().height));
2ronwalf
2ronwalf return label;
2ronwalf }
2ronwalf
2ronwalf public void addNS() {
2ronwalf JDialog info = new JDialog((JFrame) null, "Add namespace", true);
2ronwalf
2ronwalf JTextField t1 = new JTextField(50);
2ronwalf JTextField t2 = new JTextField(5);
2ronwalf JLabel[] labels = {new JLabel("Enter URL: "), new JLabel("Abbreviation:")};
2ronwalf JComponent[] textFields = {t1, t2};
2ronwalf JButton ok = new JButton("Ok");
2ronwalf ok.addActionListener(new ActionListener() {
2ronwalf public void actionPerformed(ActionEvent e) {
2ronwalf JComponent c = (JComponent) e.getSource();
2ronwalf Window w = (Window) c.getTopLevelAncestor();
2ronwalf w.dispose();
2ronwalf }
2ronwalf });
2ronwalf info.getContentPane().setLayout(new BoxLayout(info.getContentPane(), BoxLayout.Y_AXIS));
2ronwalf info.getContentPane().add(createTableLayout(labels, textFields));
2ronwalf info.getContentPane().add(ok);
2ronwalf ok.setAlignmentX(Component.CENTER_ALIGNMENT);
2ronwalf info.pack();
2ronwalf info.setResizable(false);
2ronwalf SwingUtils.centerFrame(info);
3daenzerorama //info.show();
3daenzerorama info.setVisible(true);
2ronwalf
2ronwalf System.out.println(t1.getText() + " " + t2.getText());
2ronwalf
2ronwalf String uri = t1.getText();
2ronwalf String prefix = t2.getText();
2ronwalf
2ronwalf qnames.setMapping(prefix, uri);
2ronwalf
2ronwalf updateNS();
2ronwalf }
2ronwalf
2ronwalf public void removeNS() {
2ronwalf int row = nsTable.getSelectedRow();
2ronwalf
2ronwalf if(row == -1) {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf null,
2ronwalf "Please first select an entry, then click remove!",
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf return;
2ronwalf }
2ronwalf
2ronwalf String prefix = (String) nsTable.getModel().getValueAt(row, 0);
2ronwalf
2ronwalf qnames.removePrefix(prefix);
2ronwalf
2ronwalf updateNS();
2ronwalf }
2ronwalf
2ronwalf private JPanel createTableLayout(JComponent[] labels, JComponent[] textFields) {
2ronwalf JPanel textControlsPane = new JPanel();
2ronwalf GridBagLayout gridbag = new GridBagLayout();
2ronwalf GridBagConstraints c = new GridBagConstraints();
2ronwalf
2ronwalf textControlsPane.setLayout(gridbag);
2ronwalf
2ronwalf c.anchor = GridBagConstraints.WEST;
2ronwalf int numLabels = labels.length;
2ronwalf
2ronwalf for (int i = 0; i < numLabels; i++) {
2ronwalf c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
2ronwalf c.fill = GridBagConstraints.NONE; //reset to default
2ronwalf c.weightx = 0.0; //reset to default
2ronwalf c.insets = new Insets(2,2,2,2);
2ronwalf gridbag.setConstraints(labels[i], c);
2ronwalf textControlsPane.add(labels[i]);
2ronwalf
2ronwalf c.gridwidth = GridBagConstraints.REMAINDER; //end row
2ronwalf if(i == numLabels - 1)
2ronwalf c.gridheight = GridBagConstraints.REMAINDER; //end row
2ronwalf c.fill = GridBagConstraints.BOTH;
2ronwalf c.weightx = 1.0;
2ronwalf c.weighty = 1.0;
2ronwalf c.insets = new Insets(2,2,2,2);
2ronwalf gridbag.setConstraints(textFields[i], c);
2ronwalf textControlsPane.add(textFields[i]);
2ronwalf }
2ronwalf
2ronwalf return textControlsPane;
2ronwalf }
2ronwalf
2ronwalf void doLoad() {
2ronwalf final String url = urls.getSelectedItem().toString().replaceAll(" ","%20");
2ronwalf try {
2ronwalf WSDLService s = WSDLService.createService(url);
2ronwalf List ops = s.getOperations();
2ronwalf
2ronwalf opList.setListData(ops.toArray());
2ronwalf }
2ronwalf catch(final Exception e) {
2ronwalf opList.setListData(new Vector());
2ronwalf SwingUtilities.invokeLater(new Runnable() {
2ronwalf public void run() {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf null,
2ronwalf "Cannot load service description from file\n " + url + "\n" + e,
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf }
2ronwalf });
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf void doBrowse() {
2ronwalf JFileChooser fc = new JFileChooser();
2ronwalf
2ronwalf //In response to a button click:
2ronwalf int returnVal = fc.showOpenDialog(null);
2ronwalf
2ronwalf if(returnVal != JFileChooser.APPROVE_OPTION)
2ronwalf return;
2ronwalf
2ronwalf File file = fc.getSelectedFile();
2ronwalf if(!file.exists()) {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf null,
2ronwalf file.getAbsolutePath() + "does not exist!",
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf }
2ronwalf else {
2ronwalf try {
2ronwalf urls.setSelectedItem(file.toURL().toExternalForm());
2ronwalf } catch (MalformedURLException e) {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf null,
2ronwalf "Not a valid file path " + file.getAbsolutePath() + "\n" + e,
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf }
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf void doSelect() {
2ronwalf WSDLOperation op = (WSDLOperation) opList.getSelectedValue();
2ronwalf
2ronwalf if(op == null) {
2ronwalf// fileNameField.setText("");
2ronwalf nameSpaceField.setText("");
2ronwalf serviceNameField.setText("");
2ronwalf textDescription.setText("");
2ronwalf
2ronwalf addParams(new Vector(), inputTable);
2ronwalf addParams(new Vector(), outputTable);
2ronwalf
2ronwalf generateButton.setEnabled(false);
2ronwalf }
2ronwalf else {
2ronwalf// fileNameField.setText(op.getName() + ".owl");
2ronwalf
2ronwalf nameSpaceField.setText("http://www.example.org/service.owl");
2ronwalf serviceNameField.setText(op.getName());
2ronwalf if(op.getDocumentation() == null)
2ronwalf textDescription.setText("Auto generated from " + op.getService().getFileURI());
2ronwalf else
2ronwalf textDescription.setText(op.getDocumentation());
2ronwalf textDescription.setCaretPosition(0);
2ronwalf
2ronwalf addParams(op.getInputs(), inputTable);
2ronwalf addParams(op.getOutputs(), outputTable);
2ronwalf
2ronwalf generateButton.setEnabled(true);
2ronwalf }
2ronwalf
2ronwalf updateNS();
2ronwalf }
2ronwalf
2ronwalf void prepareAdvanced() {
2ronwalf advanced = new JDialog((JFrame)null, "Advanced Settings", true);
2ronwalf
2ronwalf JPanel localNamePanel = new JPanel();
2ronwalf
2ronwalf prefixButton = new JRadioButton("Use a prefix to genearate local names");
2ronwalf prefixButton.setSelected(true);
2ronwalf
2ronwalf manualButton = new JRadioButton("Manually enter each local name");
2ronwalf
2ronwalf ButtonGroup group = new ButtonGroup();
2ronwalf group.add(prefixButton);
2ronwalf group.add(manualButton);
2ronwalf
2ronwalf localNamePanel.setBorder(BorderFactory.createTitledBorder("Local name settings for URI's"));
2ronwalf localNamePanel.setLayout(new BoxLayout(localNamePanel, BoxLayout.Y_AXIS));
2ronwalf localNamePanel.add(prefixButton);
2ronwalf localNamePanel.add(prefixText);
2ronwalf localNamePanel.add(createTableLayout(
2ronwalf new JComponent[] {new JLabel("Prefix")},
2ronwalf new JComponent[] {prefixText}));
2ronwalf localNamePanel.add(manualButton);
2ronwalf localNamePanel.add(createTableLayout(
2ronwalf new JComponent[] {new JLabel("Service"),
2ronwalf new JLabel("Profile"),
2ronwalf new JLabel("Process"),
2ronwalf new JLabel("Grounding"),
2ronwalf },
2ronwalf new JComponent[] {serviceText,profileText,processText,groundingText}));
2ronwalf
2ronwalf
2ronwalf JButton okButton = new JButton("Ok");
2ronwalf JButton cancelButton = new JButton("Cancel");
2ronwalf
2ronwalf JPanel buttonPanel = new JPanel();
2ronwalf buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
2ronwalf buttonPanel.add(Box.createHorizontalGlue());
2ronwalf buttonPanel.add(okButton);
2ronwalf buttonPanel.add(Box.createHorizontalStrut(10));
2ronwalf buttonPanel.add(cancelButton);
2ronwalf buttonPanel.add(Box.createHorizontalStrut(5));
2ronwalf
2ronwalf advanced.getContentPane().add(localNamePanel, "Center");
2ronwalf advanced.getContentPane().add(buttonPanel, "South");
2ronwalf
2ronwalf advanced.pack();
2ronwalf advanced.setResizable(false);
2ronwalf }
2ronwalf
2ronwalf void showAdvanced() {
2ronwalf SwingUtils.centerFrame(advanced);
3daenzerorama //advanced.show();
3daenzerorama advanced.setVisible(true);
2ronwalf }
2ronwalf
2ronwalf
2ronwalf private void addParams(Vector params, JTable table) {
2ronwalf DefaultTableModel model = new DefaultTableModel(columnNames, 0);
2ronwalf
2ronwalf for(Iterator i = params.iterator(); i.hasNext(); ) {
2ronwalf String[] row = new String[columnNames.length];
2ronwalf WSDLParameter p = (WSDLParameter) i.next();
2ronwalf QName paramType = (p.getType() == null)
2ronwalf ? new QName(WSDLConsts.xsdURI, "any")
2ronwalf : p.getType();
2ronwalf String wsdlType = paramType.getNamespaceURI() + "#" + paramType.getLocalPart();
2ronwalf
2ronwalf // By default use owl:Thing as param type
2ronwalf String type = OWL.Thing.toString();
2ronwalf
2ronwalf if(paramType.getNamespaceURI().equals(WSDLConsts.soapEnc) ||
2ronwalf (paramType.getNamespaceURI().equals(WSDLConsts.xsdURI) &&
2ronwalf !paramType.getLocalPart().equals("any")))
2ronwalf type = XSD.ns + paramType.getLocalPart();
2ronwalf
2ronwalf row[0] = URIUtils.getLocalName(p.getName());
2ronwalf row[1] = qnames.shortForm(wsdlType);
2ronwalf row[2] = row[0];
2ronwalf row[3] = qnames.shortForm(type);
2ronwalf //row[4] = "None";
2ronwalf
2ronwalf model.addRow(row);
2ronwalf }
2ronwalf
2ronwalf table.setModel(model);
2ronwalf }
2ronwalf
2ronwalf void doGenerate() {
2ronwalf JFileChooser fileChooser = new JFileChooser();
2ronwalf
2ronwalf String serviceName = serviceNameField.getText().trim();
2ronwalf String name = serviceName.replaceAll(" ", " _");
2ronwalf
2ronwalf String fileName =
2ronwalf fileChooser.getCurrentDirectory().getAbsolutePath() +
2ronwalf File.separator +
2ronwalf name +
2ronwalf ".owl";
2ronwalf
2ronwalf fileChooser.setSelectedFile(new File(fileName));
2ronwalf
2ronwalf int retVal = fileChooser.showSaveDialog(this);
2ronwalf if(retVal != JFileChooser.APPROVE_OPTION)
2ronwalf return;
2ronwalf
2ronwalf File file = fileChooser.getSelectedFile();
2ronwalf
2ronwalf if(file.exists()) {
2ronwalf int option =
2ronwalf JOptionPane.showConfirmDialog(
2ronwalf null,
2ronwalf file.getAbsolutePath() + " already exists.\n" +
2ronwalf "Do you want to replace it?",
2ronwalf "Save File",
2ronwalf JOptionPane.YES_NO_OPTION,
2ronwalf JOptionPane.QUESTION_MESSAGE);
2ronwalf if(option == JOptionPane.NO_OPTION)
2ronwalf return;
2ronwalf }
2ronwalf
2ronwalf WSDLOperation op = (WSDLOperation) opList.getSelectedValue();
2ronwalf WSDLTranslator t = new WSDLTranslator(op, nameSpaceField.getText(), name);
2ronwalf
2ronwalf t.setServiceName(serviceNameField.getText());
2ronwalf t.setTextDescription(textDescription.getText());
2ronwalf
2ronwalf Set usedNames = new HashSet();
2ronwalf
2ronwalf TableModel inputs = inputTable.getModel();
2ronwalf for(int i = 0; i < inputs.getRowCount(); i++) {
2ronwalf WSDLParameter param = op.getInput(i);
2ronwalf String paramName = (String) inputs.getValueAt(i, 2);
2ronwalf String paramType = (String) inputs.getValueAt(i, 3);
2ronwalf String xsltTransformation = (String) inputs.getValueAt(i, 4);
2ronwalf
2ronwalf String prefix = paramName;
2ronwalf for( int count = 1; usedNames.contains( paramName ); count++ )
2ronwalf paramName = prefix + count;
2ronwalf
2ronwalf usedNames.add( paramName );
2ronwalf
2ronwalf URI paramTypeURI;
2ronwalf try {
2ronwalf paramType = qnames.longForm(paramType);
2ronwalf paramTypeURI = new URI(paramType);
2ronwalf } catch(IllegalArgumentException e) {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf this,
2ronwalf e.getMessage(),
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf return;
2ronwalf } catch(URISyntaxException e) {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf this,
2ronwalf e.getMessage(),
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf return;
2ronwalf }
2ronwalf
2ronwalf t.addInput(param, paramName, paramTypeURI, xsltTransformation);
2ronwalf }
2ronwalf
2ronwalf TableModel outputs = outputTable.getModel();
2ronwalf for(int i = 0; i < outputs.getRowCount(); i++) {
2ronwalf WSDLParameter param = op.getOutput(i);
2ronwalf String paramName = (String) outputs.getValueAt(i, 2);
2ronwalf String paramType = (String) outputs.getValueAt(i, 3);
2ronwalf String xsltTransformation = (String) outputs.getValueAt(i, 4);
2ronwalf
2ronwalf String prefix = paramName;
2ronwalf for( int count = 1; usedNames.contains( paramName ); count++ )
2ronwalf paramName = prefix + count;
2ronwalf
2ronwalf usedNames.add( paramName );
2ronwalf
2ronwalf URI paramTypeURI;
2ronwalf try {
2ronwalf paramType = qnames.longForm(paramType);
2ronwalf paramTypeURI = new URI(paramType);
2ronwalf } catch(IllegalArgumentException e) {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf this,
2ronwalf e.getMessage(),
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf return;
2ronwalf } catch(URISyntaxException e) {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf this,
2ronwalf e.getMessage(),
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf return;
2ronwalf }
2ronwalf t.addOutput(param, paramName, paramTypeURI, xsltTransformation);
2ronwalf }
2ronwalf
2ronwalf try {
2ronwalf FileOutputStream fos = new FileOutputStream(file);
2ronwalf t.writeOWLS(fos);
2ronwalf fos.close();
2ronwalf System.out.println("Saved to " + file.toURI());
2ronwalf } catch(Exception e) {
2ronwalf e.printStackTrace();
2ronwalf
2ronwalf JOptionPane.showMessageDialog(
2ronwalf null,
2ronwalf "Cannot create OWL-S file!",
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf return;
2ronwalf }
2ronwalf
2ronwalf OWLSValidator validator = new OWLSValidator();
2ronwalf boolean valid = false;
2ronwalf try {
2ronwalf valid = validator.validate(file.toURI().toString());
2ronwalf if( valid ) {
2ronwalf OWLKnowledgeBase kb = OWLFactory.createKB();
2ronwalf kb.setReasoner("Pellet");
2ronwalf kb.getReader().getCache().setLocalCacheDirectory( "cache" );
2ronwalf kb.read(file.toURI());
2ronwalf valid = kb.isConsistent();
2ronwalf }
2ronwalf } catch (Exception e1) {
2ronwalf e1.printStackTrace();
2ronwalf }
2ronwalf
2ronwalf if(!valid)
2ronwalf JOptionPane.showMessageDialog(
2ronwalf null,
2ronwalf "Saved file " + file.getAbsolutePath() + " is not valid",
2ronwalf "Error",
2ronwalf JOptionPane.ERROR_MESSAGE);
2ronwalf else {
2ronwalf JOptionPane.showMessageDialog(
2ronwalf null,
2ronwalf "Service " + file.getAbsolutePath() + " was saved succesfully" ,
2ronwalf "Success",
2ronwalf JOptionPane.INFORMATION_MESSAGE);
2ronwalf
2ronwalf savedServices.add( file );
2ronwalf }
2ronwalf }
2ronwalf
2ronwalf void updateNS() {
2ronwalf DefaultTableModel model = new DefaultTableModel(nsColumnNames, 0);
2ronwalf
2ronwalf Iterator i = qnames.getPrefixSet().iterator();
2ronwalf while(i.hasNext()) {
2ronwalf String prefix = (String) i.next();
2ronwalf String uri = qnames.getURI(prefix);
2ronwalf
2ronwalf model.addRow(new String[] {prefix, uri});
2ronwalf }
2ronwalf
2ronwalf nsTable.setModel(model);
2ronwalf nsTable.getColumnModel().getColumn(0).setMaxWidth(75);
2ronwalf }
2ronwalf
2ronwalf public static void main(String[] args) throws Exception {
2ronwalf JFrame test = new JFrame("WSDL2OWL-S Converter");
2ronwalf
2ronwalf test.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
2ronwalf test.setSize(800, 600);
2ronwalf SwingUtils.centerFrame(test);
2ronwalf test.getContentPane().add(new WSDL2OWLS());
3daenzerorama //test.show();
3daenzerorama test.setVisible(true);
2ronwalf }
2ronwalf
2ronwalf}