001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.data;
025:
026: import java.io.File;
027: import java.net.URL;
028:
029: import org.java.plugin.Extension;
030: import org.objectweb.salome_tmf.api.Api;
031: import org.objectweb.salome_tmf.api.Util;
032: import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
033: import org.objectweb.salome_tmf.api.data.ScriptWrapper;
034: import org.objectweb.salome_tmf.api.sql.ISQLScript;
035: import org.objectweb.salome_tmf.plugins.JPFManager;
036: import org.objectweb.salome_tmf.plugins.core.ScriptEngine;
037:
038: public class Script extends Attachment {
039:
040: static ISQLScript pISQLScript = null;
041:
042: String plugArg;
043: String scriptExtension = null;
044:
045: protected String type;
046: protected ScriptEngine pEngine = null;
047:
048: /**************************************************************************/
049: /** CONSTRUCTEUR ***/
050: /**************************************************************************/
051:
052: /**
053: * Le nom, le type et la localisation sont initialisés à vide.
054: */
055: public Script(String name, String description) {
056: super (name, description);
057: type = "";
058: //localisation = "";
059: if (pISQLScript == null) {
060: pISQLScript = Api.getISQLObjectFactory().getISQLScript();
061: }
062: plugArg = "";
063: }
064:
065: public Script(ScriptWrapper pScrip) {
066: super (pScrip.getName(), pScrip.getDescription());
067: type = pScrip.getType();
068: idBdd = pScrip.getIdBDD();
069: plugArg = pScrip.getPlugArg();
070: scriptExtension = pScrip.getScriptExtension();
071: //localisation = "";
072: if (pISQLScript == null) {
073: pISQLScript = Api.getISQLObjectFactory().getISQLScript();
074: }
075: }
076:
077: public void clearCache() {
078: /* NOTHING */
079: }
080:
081: /**************************************************************************/
082: /** ACCESSEURS ET MUTATEURS ***/
083: /**************************************************************************/
084:
085: public ScriptEngine getScriptEngine(Extension pExtension,
086: URL urlSalome, JPFManager jpf) { //!!!! PENSER A INIT JPF
087: if (scriptExtension != null && pEngine == null) {
088: if (pExtension != null) {
089: try {
090: pEngine = (ScriptEngine) jpf
091: .activateExtension(pExtension);
092: pEngine.initScriptEngine(urlSalome);
093: Util.log("[Script] ScriptEngine ref : " + pEngine);
094: } catch (Exception e) {
095: pEngine = null;
096: e.printStackTrace();
097: }
098: }
099: }
100: return pEngine;
101: }
102:
103: public String getTypeFromModel() {
104: return type;
105: }
106:
107: public void setTypeInModel(String string) {
108: type = string;
109: }
110:
111: public String getScriptExtensionFromModel() {
112: return scriptExtension;
113: }
114:
115: public void setScriptExtensionInModel(String extension) {
116: scriptExtension = extension;
117: }
118:
119: /********* Plug Arg **********/
120:
121: public void updatePlugArgInDB(String newPlugArg) throws Exception {
122: if (!isInBase()) {
123: throw new Exception("Script " + name + " is not in BDD");
124: }
125: pISQLScript.updatePlugArg(idBdd, newPlugArg);
126: }
127:
128: public void updatePlugArgInModel(String string) {
129: plugArg = string;
130: }
131:
132: public void updatePlugArgInDBAndModel(String arg) throws Exception {
133: updatePlugArgInDB(arg);
134: updatePlugArgInModel(arg);
135: }
136:
137: public String getPlugArgFromModel() {
138: return plugArg;
139: }
140:
141: /********** Basic operation on Script attachement ****************/
142:
143: public void updateInDB(String fileName) throws Exception {
144: if (!isInBase()) {
145: throw new Exception("Script " + name + " is not in BDD");
146: }
147: pISQLScript.update(idBdd, fileName);
148: }
149:
150: public void updateInDB(File f) throws Exception {
151: if (!isInBase()) {
152: throw new Exception("Script " + name + " is not in BDD");
153: }
154: pISQLScript.update(idBdd, new SalomeFileWrapper(f));
155: }
156:
157: // public void updateInDB(SalomeFileWrapper f) throws Exception {
158: // if (!isInBase()) {
159: // throw new Exception("Script " + name + " is not in BDD");
160: // }
161: // pISQLScript.update(idBdd, f);
162: // }
163:
164: public File getFileFromDB() throws Exception {
165: if (!isInBase()) {
166: throw new Exception("Script " + name + " is not in BDD");
167: }
168: return pISQLScript.getFile(idBdd).toFile();
169: }
170:
171: public File getFileFromDB(String path) throws Exception {
172: if (!isInBase()) {
173: throw new Exception("Script " + name + " is not in BDD");
174: }
175: return pISQLScript.getFile(idBdd).toFile(path);
176:
177: }
178:
179: /*public void updateNameInDB(String fileName) throws Exception {
180: if (!isInBase()) {
181: throw new Exception("Script " + name + " is not in BDD");
182: }
183: pISQLScript.updateName(idBdd,fileName);
184: }
185:
186: public void updateContentInDB(String filePath) throws Exception {
187: if (!isInBase()) {
188: throw new Exception("Script " + name + " is not in BDD");
189: }
190: pISQLScript.updateContent(idBdd, filePath);
191: }
192:
193:
194: public void updateDateInDB(Date date) throws Exception {
195: if (!isInBase()) {
196: throw new Exception("Script " + name + " is not in BDD");
197: }
198: pISQLScript.updateDate(idBdd,date);
199: }
200:
201: public void updateLengthInDB(long length) throws Exception {
202: if (!isInBase()) {
203: throw new Exception("Script " + name + " is not in BDD");
204: }
205: pISQLScript.updateLength(idBdd, length);
206: }
207: */
208:
209: }
|