View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.repository.ui.wizards;
26  
27  import java.io.ByteArrayInputStream;
28  
29  import org.eclipse.core.resources.IFile;
30  import org.eclipse.jface.wizard.IWizardPage;
31  import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
32  import org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard;
33  import org.wsmo.common.IRI;
34  import org.wsmo.common.TopEntity;
35  import org.wsmo.datastore.WsmoRepository;
36  import org.wsmo.wsml.Serializer;
37  import org.wsmostudio.repository.ui.WSMOEntityContainer;
38  import org.wsmostudio.runtime.LogManager;
39  import org.wsmostudio.runtime.WSMORuntime;
40  
41  /***
42   * This wizard supports importing wsml resources into the workspace from a certain
43   * repository.
44   *
45   * @author not attributable
46   * @version $Revision: 689 $ $Date: 2006-04-13 17:46:59 +0300 $
47   */
48  
49  public class SaveEntityWizard extends BasicNewFileResourceWizard {
50  
51      private String title;
52      private WsmoRepository repository;
53      private IRI wsmoID;
54      private byte entityType;
55  
56      public SaveEntityWizard(String title, 
57                              WsmoRepository repo, 
58                              IRI wsmoRef,
59                              byte entityType) {
60          this.title = title;
61          this.repository = repo;
62          this.wsmoID = wsmoRef;
63          this.entityType = entityType;
64      }
65      
66      public String getWindowTitle() {
67          return this.title;
68      }
69      
70      public boolean performFinish() {
71          IWizardPage page = getStartingPage();
72          if (false == page instanceof WizardNewFileCreationPage) {
73              return false;
74          }
75          WizardNewFileCreationPage mainPage = (WizardNewFileCreationPage)page; 
76          
77          String newFileName = mainPage.getFileName();
78          if (false == newFileName.toLowerCase().endsWith(".wsml")) {
79              mainPage.setFileName(newFileName+".wsml");
80          }
81  
82          IFile file = ((WizardNewFileCreationPage)page).createNewFile();
83      	if (file == null) {
84      		return false;
85      	}
86      	TopEntity entity = WSMOEntityContainer.retrieveTopEntity(repository, wsmoID, entityType);
87  		Serializer wsmlSerialiser = WSMORuntime.getRuntime().getWsmlSerializer();
88          StringBuffer str = new StringBuffer();
89          wsmlSerialiser.serialize( new TopEntity[] { entity }, str);
90  		try {
91              file.setContents(new ByteArrayInputStream(str.toString().getBytes()), true, false, null);
92  		}
93  		catch(Exception e) {
94  		    LogManager.logError(e);
95  		}
96  
97      	selectAndReveal(file);
98          return true;
99      }
100 
101 }
102 
103 /*
104  * $Log$
105  * Revision 1.10  2006/04/13 14:46:59  alex_simov
106  * refactoring: method retrieveTopEntity() moved from SaveEntityWizard to
107  *  WSMOEntityContainer
108  *
109  * Revision 1.9  2006/01/09 12:51:11  alex_simov
110  * Copyright message in header updated
111  *
112  * Revision 1.8  2005/07/25 12:59:18  alex_simov
113  * WSML serializer now accepts an array of TopEntities
114  *
115  * Revision 1.7  2005/07/21 11:46:32  alex_simov
116  * added javadoc: class description, footer
117  *
118  */