0001: // This file is part of KeY - Integrated Deductive Software Design
0002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
0003: // Universitaet Koblenz-Landau, Germany
0004: // Chalmers University of Technology, Sweden
0005: //
0006: // The KeY system is protected by the GNU General Public License.
0007: // See LICENSE.TXT for details.
0008: //
0009: //
0010:
0011: package de.uka.ilkd.key.casetool.together.patterns.HelperClasses.MyPatternBase;
0012:
0013: import java.io.*;
0014: import java.util.Enumeration;
0015: import java.util.Vector;
0016:
0017: import javax.swing.JDialog;
0018: import javax.swing.JOptionPane;
0019:
0020: import com.togethersoft.modules.patterns.UNIVERSAL.PatternBaseException;
0021: import com.togethersoft.modules.patterns.UNIVERSAL.PatternUIBuilder;
0022: import com.togethersoft.openapi.ide.inspector.IdeInspector;
0023: import com.togethersoft.openapi.ide.inspector.IdeInspectorProperty;
0024: import com.togethersoft.openapi.ide.inspector.IdeInspectorPropertySetComponent;
0025: import com.togethersoft.openapi.ide.inspector.util.editors.PropertyMapMultiValueElementChooserEditor;
0026: import com.togethersoft.openapi.ide.inspector.util.property.PropertyMapInspectorProperty;
0027: import com.togethersoft.openapi.ide.message.IdeMessageManagerAccess;
0028: import com.togethersoft.openapi.ide.message.IdeMessageType;
0029: import com.togethersoft.openapi.ide.window.IdeSelectorDialogType;
0030: import com.togethersoft.openapi.ide.window.IdeWindowManagerAccess;
0031: import com.togethersoft.openapi.sci.*;
0032: import com.togethersoft.openapi.sci.pattern.SciPatternProperty;
0033: import com.togethersoft.openapi.sci.pattern.SciPatternUtil;
0034: import com.togethersoft.openapi.util.propertyMap.Property;
0035: import com.togethersoft.openapi.util.propertyMap.PropertyMap;
0036: import com.togethersoft.openapi.util.propertyMap.PropertyMapListener;
0037:
0038: import de.uka.ilkd.key.casetool.together.patterns.HelperClasses.MyParser.Entry;
0039: import de.uka.ilkd.key.casetool.together.patterns.HelperClasses.MyParser.MyParser;
0040: import de.uka.ilkd.key.casetool.together.patterns.HelperClasses.MyParser.ParseException;
0041: import de.uka.ilkd.key.util.Debug;
0042:
0043: public abstract class MyPatternBase extends
0044: com.togethersoft.modules.patterns.UNIVERSAL.PatternBase {
0045:
0046: private Vector additionalProperties = new Vector();
0047: private Vector constraintVector = new Vector();
0048: private Vector mappingVector = new Vector();
0049: private Vector mappingVectorTemp = new Vector();
0050: private Vector placeVector = new Vector();
0051: private Vector commentVector = new Vector();
0052: private final static String beginOfComment = "<!-- begin of my comments -->";
0053: protected static PropertyMap myProperties = null;
0054: protected static IdeInspector myIdeInspector = null;
0055: private Vector myAttributePropertyVector = new Vector();
0056: private static PatternUIBuilder myUIBuilder = null;
0057: private static Vector inspectorPropertiesVector = new Vector();
0058: private static String pageName = "";
0059:
0060: public SciClass getSelectedClass() {
0061: Object selectedObject = getProperties().getPropertyValue(
0062: SciPatternProperty.ELEMENT);
0063: if (selectedObject != null
0064: && selectedObject instanceof SciClass) {
0065: return (SciClass) selectedObject;
0066: } else {
0067: return null;
0068: }
0069: }
0070:
0071: public SciOperation getSelectedMethod() {
0072: Object selectedObject = getProperties().getPropertyValue(
0073: SciPatternProperty.ELEMENT);
0074: // System.out.println("Object: "+selectedObject.toString());
0075: if (selectedObject != null
0076: && selectedObject instanceof SciOperation) {
0077: return (SciOperation) selectedObject;
0078: } else {
0079: return null;
0080: }
0081: }
0082:
0083: public SciAttribute getSelectedAttribute() {
0084: Object selectedObject = getProperties().getPropertyValue(
0085: SciPatternProperty.ELEMENT);
0086: if (selectedObject != null
0087: && selectedObject instanceof SciAttribute) {
0088: return (SciAttribute) selectedObject;
0089: } else {
0090: return null;
0091: }
0092: }
0093:
0094: public MyPatternBase() {
0095: super ();
0096: if (myProperties == null)
0097: myProperties = getProperties();
0098: if (myIdeInspector == null)
0099: myIdeInspector = getIdeInspector();
0100: }
0101:
0102: public void addPropertyMapListener(String name,
0103: PropertyMapListener listener) {
0104: myProperties.addPropertyMapListener(name, listener);
0105: }
0106:
0107: protected void addToPropertiesVector(Vector v) {
0108: for (int i = 0; i < v.size(); i++)
0109: inspectorPropertiesVector.addElement(v.elementAt(i));
0110: }
0111:
0112: protected boolean removeFromPropertiesVector(String s) {
0113: for (int i = 0; i < inspectorPropertiesVector.size(); i++) {
0114: if (inspectorPropertiesVector.elementAt(i).toString()
0115: .equals(s)) {
0116: inspectorPropertiesVector.removeElementAt(i);
0117: return true;
0118: }
0119: }
0120: return false;
0121: }
0122:
0123: protected void setUIBuilder(PatternUIBuilder builder) {
0124: myUIBuilder = builder;
0125: }
0126:
0127: protected void setPageName(String name) {
0128: pageName = name;
0129: }
0130:
0131: protected String classNameShouldBeCorrect(String propertyName)
0132: throws MyPatternBaseException {
0133: String result = getStringPropertyValue(propertyName);
0134: if (result == null || result.length() == 0) {
0135: Object[] arguments = { propertyName };
0136: String message = createTextByPattern(
0137: "{0} should be defined.", arguments);
0138: throw new MyPatternBaseException(message);
0139: }
0140: return checkStringValue(result, true);
0141: }
0142:
0143: protected String checkStringValue(String value, boolean isClassName)
0144: throws MyPatternBaseException {
0145: String identifier = value;
0146: if (isClassName && SciLanguage.JAVA.equals(getLanguage())) {
0147: int lastIndex = identifier.lastIndexOf('.');
0148: if (lastIndex >= 0) {
0149: String packageName = identifier.substring(0, lastIndex);
0150: if (EMPTY_STRING.equals(packageName)
0151: || (getModel().findClass(getLanguage(),
0152: packageName) == null && getModel()
0153: .findPackage(packageName) == null)) {
0154: Object[] arguments = { packageName };
0155: String message = createTextByPattern(
0156: "Container \"{0}\" not found.", arguments);
0157: throw new MyPatternBaseException(message);
0158: }
0159: identifier = identifier.substring(lastIndex + 1);
0160: }
0161: }
0162:
0163: if (!getLanguageHelper().isValidIdentifier(identifier)) {
0164: Object[] arguments = { identifier };
0165: String message = createTextByPattern(
0166: "\"{0}\" is invalid identifier.", arguments);
0167: throw new MyPatternBaseException(message);
0168: }
0169:
0170: return value;
0171: }
0172:
0173: protected void addBooleanFieldItem(String name, boolean initialValue) {
0174: // if (myUIBuilder==null)
0175: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "myUIBuilder ist null!!!\n");
0176: try {
0177: if (myUIBuilder.addPropertyToPage(pageName, name, name,
0178: PatternUIBuilder.PropertyType.Boolean) == null) {
0179: throw new MyPatternBaseException(
0180: CANNOT_CREATE_PATTERN_UI);
0181: }
0182: if (initialValue)
0183: setPropertyValue(name, Boolean.TRUE);
0184: else
0185: setPropertyValue(name, Boolean.FALSE);
0186: inspectorPropertiesVector.addElement(name);
0187: myUIBuilder.setCreatedPatternUI();
0188: } catch (MyPatternBaseException ex) {
0189: myUIBuilder = null;
0190: getIdeInspector().clear();
0191: return;
0192: }
0193:
0194: }
0195:
0196: protected void addBooleanFieldItem(String name,
0197: boolean initialValue, MyCondition condition) {
0198: IdeInspectorProperty property = new PropertyMapInspectorProperty(
0199: getProperties(), name, Boolean.class);
0200: property.setName(name);
0201: if (initialValue)
0202: setPropertyValue(name, Boolean.TRUE);
0203: else
0204: setPropertyValue(name, Boolean.FALSE);
0205: inspectorPropertiesVector.addElement(name);
0206: myUIBuilder.setCreatedPatternUI();
0207: IdeInspectorPropertySetComponent propertyPage = (IdeInspectorPropertySetComponent) getIdeInspector()
0208: .findComponent(pageName);
0209: if (propertyPage == null) {
0210: return;
0211: }
0212:
0213: propertyPage.addProperty(property, condition);
0214: ((IdeInspectorPropertySetComponent) getIdeInspector()
0215: .findComponent(pageName)).update();
0216: }
0217:
0218: protected boolean isBooleanFieldSelected(String name) {
0219: if ("true".equals(getPropertyValue(name).toString()))
0220: return true;
0221: else
0222: return false;
0223: }
0224:
0225: protected void addStringFieldItem(String name) {
0226: // if (myUIBuilder==null)
0227: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "myUIBuilder ist null!!!\n");
0228: try {
0229: if (myUIBuilder.addPropertyToPage(pageName, name, name,
0230: PatternUIBuilder.PropertyType.String) == null) {
0231: throw new MyPatternBaseException(
0232: CANNOT_CREATE_PATTERN_UI);
0233: }
0234: inspectorPropertiesVector.addElement(name);
0235: myUIBuilder.setCreatedPatternUI();
0236: } catch (MyPatternBaseException ex) {
0237: myUIBuilder = null;
0238: getIdeInspector().clear();
0239: return;
0240: }
0241: }
0242:
0243: protected void addStringFieldItem(String name, MyCondition condition) {
0244: IdeInspectorProperty property = new PropertyMapInspectorProperty(
0245: getProperties(), name, String.class);
0246: property.setName(name);
0247: inspectorPropertiesVector.addElement(name);
0248: myUIBuilder.setCreatedPatternUI();
0249: IdeInspectorPropertySetComponent propertyPage = (IdeInspectorPropertySetComponent) getIdeInspector()
0250: .findComponent(pageName);
0251: if (propertyPage == null) {
0252: return;
0253: }
0254:
0255: propertyPage.addProperty(property, condition);
0256: ((IdeInspectorPropertySetComponent) getIdeInspector()
0257: .findComponent(pageName)).update();
0258:
0259: }
0260:
0261: protected void addClassPropertyItem(String name,
0262: boolean allowInterface, boolean multiple) {
0263: //if (myUIBuilder==null)
0264: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "myUIBuilder ist null!!!\n");
0265: int m = 0;
0266: if (multiple)
0267: m = PatternUIBuilder.PropertyType.MultiValue;
0268: else
0269: m = PatternUIBuilder.PropertyType.SingleValue;
0270: try {
0271: if (myUIBuilder.addClassPropertyToPage(pageName, name,
0272: name, m, allowInterface) == null) {
0273: throw new MyPatternBaseException(
0274: CANNOT_CREATE_PATTERN_UI);
0275: }
0276: inspectorPropertiesVector.addElement(name);
0277: myUIBuilder.setCreatedPatternUI();
0278: } catch (MyPatternBaseException ex) {
0279: myUIBuilder = null;
0280: getIdeInspector().clear();
0281: return;
0282: }
0283: }
0284:
0285: // wenn der Benutzer nicht in der Combobox rumklickt, dann wird als Element null
0286: // zurueckkgeliefert!!! Um das zu vermeiden, muss in der prepare-methode in Pattern.java
0287: // von Hand mit setPropertyValue initialisiert werden. Das setPropertyValue hier bringt
0288: // nichts!!!
0289: protected void addComboboxFieldItem(String name, Vector values,
0290: String defaultValue) {
0291: //if (myUIBuilder==null)
0292: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "myUIBuilder ist null!!!\n");
0293: try {
0294: if (myUIBuilder.addPropertyToPage(pageName, name, name,
0295: PatternUIBuilder.PropertyType.StringChooser, values
0296: .toArray()) == null) {
0297: throw new MyPatternBaseException(
0298: CANNOT_CREATE_PATTERN_UI);
0299: }
0300: setPropertyValue(name, defaultValue);
0301: inspectorPropertiesVector.addElement(name);
0302: myUIBuilder.setCreatedPatternUI();
0303: } catch (MyPatternBaseException ex) {
0304: myUIBuilder = null;
0305: getIdeInspector().clear();
0306: return;
0307: }
0308: }
0309:
0310: protected void initializeInspector() {
0311: try {
0312: myUIBuilder = null;
0313: myUIBuilder = createUIBuilder(true);
0314:
0315: // Create page
0316: if (myUIBuilder.addInspectorPage(pageName,
0317: PatternUIBuilder.UIPresentation.Table) == null) {
0318: throw new MyPatternBaseException(
0319: CANNOT_CREATE_PATTERN_UI);
0320: }
0321:
0322: myUIBuilder.setCreatedPatternUI();
0323: } catch (MyPatternBaseException ex) {
0324: myUIBuilder = null;
0325: getIdeInspector().clear();
0326: return;
0327: }
0328: }
0329:
0330: public void showItem(String name, boolean show) {
0331:
0332: //myProperties.setPropertyValue(getIdeInspector()+ ".item." + name + ".condition", (new Boolean(show)).toString());
0333: // weiss nicht, wie das unter TJ4.0 funktioniert
0334: enableItem(name, show);
0335: }
0336:
0337: public void showItem(String name, boolean show,
0338: MyCondition condition) {
0339:
0340: //myProperties.setPropertyValue(getIdeInspector()+ ".item." + name + ".condition", (new Boolean(show)).toString());
0341: // weiss nicht, wie das unter TJ4.0 funktioniert
0342: //enableItem(name, show);
0343:
0344: IdeInspectorPropertySetComponent propertyPage = (IdeInspectorPropertySetComponent) getIdeInspector()
0345: .findComponent(pageName);
0346: if (propertyPage == null) {
0347: return;
0348: }
0349: IdeInspectorProperty property = propertyPage.findProperty(name);
0350: if (property == null) {
0351: return;
0352: }
0353:
0354: // System.out.println("Fuege jetzt die condition hinzu");
0355: condition.setFlag(show);
0356: propertyPage.addProperty(property, condition);
0357: ((IdeInspectorPropertySetComponent) getIdeInspector()
0358: .findComponent(pageName)).update();
0359:
0360: }
0361:
0362: public boolean isItemShown(String name) {
0363: if ("true".equals(getPropertyValue(name).toString()))
0364: return true;
0365: else
0366: return false;
0367: }
0368:
0369: public void setMultiple(String item, boolean on) {
0370: // wei� noch nicht, wie das geht. Stimmt so nicht
0371: Enumeration enum1 = getProperties().properties(item);
0372: if (on) {
0373: while (enum1.hasMoreElements()) {
0374: IdeInspectorProperty property = (IdeInspectorProperty) enum1
0375: .nextElement();
0376: String name = (String) property.getValue();
0377: property
0378: .setPropertyEditor(new PropertyMapMultiValueElementChooserEditor(
0379: null, item,
0380: IdeSelectorDialogType.MULTIPLE_CLASSES));
0381: // System.out.println(name);
0382: }
0383: } else {
0384: while (enum1.hasMoreElements()) {
0385: IdeInspectorProperty property = (IdeInspectorProperty) enum1
0386: .nextElement();
0387: String name = (String) property.getValue();
0388: property
0389: .setPropertyEditor(new PropertyMapMultiValueElementChooserEditor(
0390: null, item,
0391: IdeSelectorDialogType.CLASSES));
0392: // System.out.println(name);
0393: }
0394: }
0395:
0396: }
0397:
0398: public boolean isMultiple(String item) {
0399: if (item != null) {
0400: if (getPropertyValue(item) != null
0401: && "true".equals(getPropertyValue(item).toString()))
0402: return true;
0403: else
0404: return false;
0405: } else
0406: return false;
0407: }
0408:
0409: public void showItemVector(Vector v, String oclScheme, boolean show) {
0410: for (int i = 0; i < v.size(); i = i + 3) {
0411: if (((String) (v.elementAt(i))).equals(oclScheme)) {
0412: if ("visible".equals(v.elementAt(i + 1)))
0413: showItem((String) v.elementAt(i + 2), show);
0414: if ("multiple".equals(v.elementAt(i + 1)))
0415: setMultiple((String) v.elementAt(i + 2), show);
0416: }
0417: }
0418:
0419: }
0420:
0421: public void copySpecFromTo(SciClass sc, String tm, SciClass tc) {
0422: Enumeration opEnum = sc.operations();
0423: SciOperation op;
0424: while (opEnum.hasMoreElements()) {
0425: op = (SciOperation) opEnum.nextElement();
0426: if (tm.equals(op.getName())) {
0427: String pre = op.getTagList().getTagValue(
0428: "preconditions");
0429: String post = op.getTagList().getTagValue(
0430: "postconditions");
0431:
0432: Enumeration targetOpEnum = tc.operations();
0433: SciOperation top;
0434: while (targetOpEnum.hasMoreElements()) {
0435: top = (SciOperation) targetOpEnum.nextElement();
0436: if (tm.equals(top.getName())) {
0437: top.getTagList().setTagValue("preconditions",
0438: pre);
0439: top.getTagList().setTagValue("postconditions",
0440: post);
0441:
0442: }
0443: }
0444: }
0445: }
0446: }
0447:
0448: protected void initPattern() {
0449:
0450: // read OCL-Schemes from file
0451:
0452: final Vector oclSchemeVector = new Vector();
0453: final Vector oclSchemeNamesVector = new Vector();
0454: final String patternTopPath = System
0455: .getProperty("key.pattern.path");
0456: final String[] extensions = { ".ocl" };
0457: String classname = getClass().getName().replace('.',
0458: File.separatorChar);
0459: String path = patternTopPath
0460: + File.separator
0461: + classname.substring(0, classname
0462: .lastIndexOf(File.separatorChar));
0463: String oclPath = path + File.separator + "OCL";
0464: System.out.println("Pattern Path:" + path);
0465: commentVector.removeAllElements();
0466: additionalProperties.removeAllElements();
0467: constraintVector.removeAllElements();
0468: mappingVector.removeAllElements();
0469: placeVector.removeAllElements();
0470:
0471: try {
0472: int data;
0473: String dummy = "";
0474: // check, if the directory for OCL-SCHEMES does exist
0475: File oclSchemeDir = new File(oclPath);
0476: if ((oclSchemeDir.exists()) && oclSchemeDir.isDirectory()) {
0477: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Verzeichnis existiert!!!");
0478: // get list with files in this directory
0479: String[] fileList = oclSchemeDir
0480: .list(new FilenameFilter() {
0481: public boolean accept(File f, String name) {
0482: int length = name.length();
0483: for (int i = 0; i < extensions.length; i++) {
0484: String ext = extensions[i];
0485: if (name.endsWith(ext)
0486: && name.charAt(length
0487: - ext.length()) == '.') {
0488: return true;
0489: }
0490: }
0491: return false;
0492: }
0493: });
0494:
0495: String fileInputPath = oclPath;
0496:
0497: for (int i = 0; i < fileList.length; i++) {
0498: FileInputStream fileInput = new FileInputStream(
0499: new File(fileInputPath, fileList[i]));
0500:
0501: // InputStream from file to parser
0502: MyParser parser = new MyParser(
0503: (InputStream) fileInput);
0504: try {
0505: // add a checkbox (initially false), so that the user can select this OCL-Scheme.
0506: addBooleanFieldItem(fileList[i].substring(0,
0507: fileList[i].length() - 4), false);
0508: myUIBuilder
0509: .assignListenedInspectorProperties(inspectorPropertiesVector);
0510: parser.parse(fileList[i].substring(0,
0511: fileList[i].length() - 4));
0512: mappingVectorTemp = parser.getMappingVector();
0513: for (int z = 0; z < mappingVectorTemp.size(); z++)
0514: mappingVector.addElement(mappingVectorTemp
0515: .elementAt(z));
0516: // add the parsed additional properties to the vector in which all additional props. are stored
0517: for (int z = 0; z < parser
0518: .getAdditionalPropertiesVector().size(); z++)
0519: additionalProperties.addElement(parser
0520: .getAdditionalPropertiesVector()
0521: .elementAt(z));
0522: for (int z = 0; z < parser.getPlaceVector()
0523: .size(); z++)
0524: placeVector.addElement(parser
0525: .getPlaceVector().elementAt(z));
0526: for (int z = 0; z < parser
0527: .getConstraintVector().size(); z = z + 2) {
0528: constraintVector.addElement(fileList[i]
0529: .substring(0,
0530: fileList[i].length() - 4));
0531: constraintVector
0532: .addElement(parser
0533: .getConstraintVector()
0534: .elementAt(z));
0535: constraintVector.addElement(parser
0536: .getConstraintVector().elementAt(
0537: z + 1));
0538: }
0539: commentVector.addElement(parser
0540: .getCommentString());
0541: } catch (ParseException parseError) {
0542: IdeMessageManagerAccess.printMessage(
0543: IdeMessageType.ERROR_MODAL,
0544: "Parse error in file " + fileList[i]
0545: + ": " + parseError.toString());
0546: // parse error, so remove
0547: getProperties().setPropertyValue(
0548: "inspector.item." + fileList[i], "");
0549: }
0550:
0551: fileInput.close();
0552: fileInput = new FileInputStream(new File(
0553: fileInputPath, fileList[i]));
0554:
0555: // read OclScheme
0556: dummy = "";
0557: Vector puffer = new Vector();
0558: while ((data = fileInput.read()) != -1) {
0559: if ((char) data == "\n".charAt(0)) {
0560: puffer.addElement(dummy);
0561: dummy = "";
0562: } else
0563: dummy = dummy + "" + (char) data;
0564: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,data+";");
0565: }
0566:
0567: fileInput.close();
0568:
0569: if (!puffer.isEmpty()) {
0570: // print input-files
0571: for (int j = 0; j < puffer.size(); j++)
0572: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, puffer.elementAt(j).toString());
0573:
0574: oclSchemeNamesVector
0575: .addElement(fileList[i]); // name of ocl-scheme
0576: oclSchemeVector.addElement(puffer); // Stringrepresentation of ocl-scheme as a Vector of Strings
0577: }
0578:
0579: }
0580: } else
0581: IdeMessageManagerAccess.printMessage(
0582: IdeMessageType.ERROR_MODAL, "Verzeichnis "
0583: + oclPath + " existiert nicht!!!");
0584: } catch (FileNotFoundException e) {
0585: IdeMessageManagerAccess.printMessage(
0586: IdeMessageType.ERROR_MODAL, "File " + e.toString()
0587: + " not found!");
0588: } catch (IOException ioe) {
0589: IdeMessageManagerAccess.printMessage(
0590: IdeMessageType.ERROR_MODAL, "IOException");
0591: }
0592:
0593: // manipulate Desciption.html
0594:
0595: try {
0596: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "bearbeite jetzt description!\n");
0597: RandomAccessFile descriptionFile = new RandomAccessFile(
0598: path + File.separatorChar + "Description.html",
0599: "rw");
0600: String line = "";
0601: boolean found = false;
0602: while ((line = descriptionFile.readLine()) != null)
0603: if (line.equals(beginOfComment)) {
0604: found = true;
0605: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Kommentar gefunden!\n");
0606: descriptionFile
0607: .writeBytes("<h3>Documentation of OCL-Schemata</h3>");
0608: for (int y = 0; y < commentVector.size(); y++) {
0609: if (!"".equals(commentVector.elementAt(y)))
0610: descriptionFile.writeBytes("<ul>"
0611: + commentVector.elementAt(y)
0612: .toString() + "</ul>");
0613: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Kommentar: "+commentVector.elementAt(y).toString());
0614: }
0615: //descriptionFile.writeBytes("</body>");
0616: //descriptionFile.writeBytes("</html>");
0617: descriptionFile.setLength(descriptionFile
0618: .getFilePointer());
0619: }
0620: if (!found) {
0621: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Kommentar nicht gefunden!\n");
0622: descriptionFile.seek(descriptionFile.length());
0623: descriptionFile.writeBytes(beginOfComment + "\n");
0624: descriptionFile
0625: .writeBytes("<h3>Documentation of OCL-Schemata</h3>");
0626: for (int y = 0; y < commentVector.size(); y++) {
0627: if (!"".equals(commentVector.elementAt(y)))
0628: descriptionFile.writeBytes("<ul>"
0629: + commentVector.elementAt(y).toString()
0630: + "</ul>");
0631: }
0632: //descriptionFile.writeBytes("</body>");
0633: //descriptionFile.writeBytes("</html>");
0634: descriptionFile.setLength(descriptionFile
0635: .getFilePointer());
0636: }
0637: descriptionFile.close();
0638: } catch (FileNotFoundException e) {
0639: IdeMessageManagerAccess.printMessage(
0640: IdeMessageType.ERROR_MODAL, "File not found: " + e);
0641: } catch (IOException ioe) {
0642: IdeMessageManagerAccess.printMessage(
0643: IdeMessageType.ERROR_MODAL, "IOException");
0644: }
0645:
0646: //IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "PARSEN UND EINLESEN BEENDET\n");
0647:
0648: myUIBuilder
0649: .assignListenedInspectorProperties(inspectorPropertiesVector);
0650:
0651: }
0652:
0653: protected Vector extractParameter(String paraList) {
0654: Vector v = new Vector();
0655: int pos = 0;
0656: int endpos = 0;
0657: String dummy;
0658: if (paraList.length() > 0) {
0659: while (pos >= 0) {
0660: endpos = paraList.indexOf(",", pos);
0661: if (endpos >= 0) {
0662: dummy = (new StringBuffer(paraList)).substring(pos,
0663: endpos).trim();
0664: if (dummy.indexOf(" ") != -1) {
0665: dummy = dummy.substring(dummy.indexOf(" "))
0666: .trim();
0667: }
0668: v.addElement(dummy);
0669: pos = endpos + 1;
0670: } else {
0671: dummy = (new StringBuffer(paraList)).substring(pos)
0672: .trim();
0673: if (dummy.indexOf(" ") != -1) {
0674: dummy = dummy.substring(dummy.indexOf(" "))
0675: .trim();
0676: }
0677: v.addElement(dummy);
0678: pos = -1000;
0679: }
0680: }
0681:
0682: return v;
0683: } else
0684: return null;
0685: }
0686:
0687: // only a wrapper-method
0688: protected void applyOCLSchemes() {
0689: applyOCLSchemeAdjustments(additionalProperties,
0690: constraintVector);
0691: applyOCLConstraints(additionalProperties, constraintVector,
0692: mappingVector, placeVector);
0693: }
0694:
0695: // this method adds the classes, methods, etc., that were defined in the OCLScheme to the UML-diagram
0696: protected void applyOCLSchemeAdjustments(Vector additionalProps,
0697: Vector constraintVector) {
0698: SciClass cls;
0699: for (int i = 0; i < additionalProps.size(); i++) {
0700: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,((Entry)additionalProps.elementAt(i)).toString() );
0701: // test, whether canHaveSeveralSubclasses is added and whether it is selected (selected <-> visible)
0702: if ("canHaveSeveralSubclasses#"
0703: .equals(((Entry) additionalProps.elementAt(i))
0704: .getProperty())
0705: && (isBooleanFieldSelected(((Entry) additionalProps
0706: .elementAt(i)).getOclSchemeName()))) {
0707: Enumeration en = propertiesEnumeration(((Entry) additionalProps
0708: .elementAt(i)).getPropertyName());
0709: while (en.hasMoreElements()) {
0710: Property property = (Property) en.nextElement();
0711: String name = (String) property.getValue();
0712: cls = getClassByName(name, false);
0713: try {
0714: SciPatternUtil
0715: .createInheritance(
0716: cls,
0717: findClassByName(classNameShouldBeCorrect(((Entry) additionalProps
0718: .elementAt(i))
0719: .getName())));
0720: } catch (MyPatternBaseException e) {
0721: Debug
0722: .out("Exception thrown by class MyPatternBase at createInheritance");
0723: }
0724: }
0725: }
0726: // is there "canHaveMultipleInstances#"?
0727: if ("canHaveMultipleInstances#"
0728: .equals(((Entry) additionalProps.elementAt(i))
0729: .getProperty())
0730: && isMultiple(((Entry) additionalProps.elementAt(i))
0731: .getName())) {
0732: Enumeration enum2 = propertiesEnumeration(((Entry) additionalProps
0733: .elementAt(i)).getName());
0734: while (enum2.hasMoreElements()) {
0735: Property property = (Property) enum2.nextElement();
0736: String name = (String) property.getValue();
0737:
0738: // create a copy of the class, that can have multiple instances, because the other instances
0739: // should have the same behaviour
0740:
0741: // does the class already exist?
0742: if (findClassByName(name) == null) {
0743: try {
0744: SciClass cpy = (SciClass) findClassByName(
0745: classNameShouldBeCorrect(((Entry) additionalProps
0746: .elementAt(i)).getName()))
0747: .copy();
0748: // change name of cpy
0749: cpy.setName(name);
0750: // paste it in container (it becomes visible)
0751: getContainer().paste(cpy, null, false);
0752: } catch (MyPatternBaseException e) {
0753: Debug
0754: .out("Exception thrown by class MyPatternBase at findClassByName");
0755: }
0756: }
0757:
0758: }
0759: }
0760:
0761: // is there "addClassAttribute#"?
0762: if ("addClassAttribute#".equals(((Entry) additionalProps
0763: .elementAt(i)).getProperty())
0764: && isBooleanFieldSelected(((Entry) additionalProps
0765: .elementAt(i)).getOclSchemeName())) {
0766:
0767: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Versuche jetzt, ord einzuf�gen!!!\n" );
0768: String dummy = ((Entry) additionalProps.elementAt(i))
0769: .getName();
0770: int separator1 = dummy.indexOf("#");
0771:
0772: String className = dummy.substring(0, separator1);
0773: String type = dummy.substring(separator1 + 1, dummy
0774: .length());
0775:
0776: SciAttribute newAttribute = SciModelAccess.getModel()
0777: .getFactory(SciLanguage.JAVA).newAttribute();
0778: newAttribute
0779: .setName(getStringPropertyValue(((Entry) additionalProps
0780: .elementAt(i)).getPropertyName()));
0781:
0782: newAttribute.setProperty(SciProperty.STATIC, true); //making it static
0783: newAttribute.getType().setText(type); //setting the type
0784: newAttribute.setProperty(SciProperty.PUBLIC, true); //setting the public modifier
0785: //pasting it into someSciClass
0786: try {
0787: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Bin bei addClassAttribute: className :" +className+"\n" );
0788: ((SciClass) findClassByName(classNameShouldBeCorrect(className)))
0789: .paste(newAttribute, null, false);
0790: } catch (MyPatternBaseException e) {
0791: Debug
0792: .out("Exception thrown by class MyPatternBase at findClassByName");
0793: }
0794: }
0795:
0796: // is there "addMethod"?
0797: if ("addMethod#".equals(((Entry) additionalProps
0798: .elementAt(i)).getProperty())
0799: && isBooleanFieldSelected(((Entry) additionalProps
0800: .elementAt(i)).getOclSchemeName())) {
0801:
0802: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"erstelle gerade Method" );
0803: SciOperation method = getFactory().newOperation();
0804: method
0805: .setName(getStringPropertyValue(((Entry) additionalProps
0806: .elementAt(i)).getPropertyName()));
0807: method.getReturnType().setText("void");
0808: method.setProperty(SciProperty.PUBLIC, true);
0809: // paste the new method in the modell
0810: try {
0811: ((SciClass) findClassByName(classNameShouldBeCorrect(((Entry) additionalProps
0812: .elementAt(i)).getName()))).paste(method,
0813: null, false);
0814: } catch (PatternBaseException e) {
0815: Debug
0816: .out("Exception thrown by class MyPatternBase at findClassByName");
0817: }
0818: }
0819:
0820: }
0821: }
0822:
0823: // add the ocl-constraints that were specified in the OCL-scheme
0824: protected void applyOCLConstraints(Vector additionalProps,
0825: Vector constraintVector, Vector mappingVector,
0826: Vector placeVector) {
0827: StringBuffer stringBuffer;
0828: String newString;
0829: String s;
0830: int start, length;
0831: boolean selectedClassFound = false;
0832: boolean fehler = false;
0833: for (int i = 0; i < constraintVector.size(); i = i + 3) {
0834: //is scheme selected?
0835: if (isBooleanFieldSelected((String) constraintVector
0836: .elementAt(i))) {
0837: fehler = false;
0838: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Ocl-Constraint "+(String)constraintVector.elementAt(i)+" mit folgenden Mappings ausgew�hlt:\n");
0839: stringBuffer = new StringBuffer(constraintVector
0840: .elementAt(i + 1).toString());
0841: selectedClassFound = false;
0842: for (int j = 0; j < mappingVector.size(); j = j + 3) {
0843: // System.out.println("Vergleich: "+mappingVector.elementAt(j).toString()+":"+constraintVector.elementAt(i).toString()+"\n");
0844: if (mappingVector.elementAt(j).toString().equals(
0845: constraintVector.elementAt(i).toString())) {
0846:
0847: // System.out.println("EINS\n");
0848:
0849: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,mappingVector.elementAt(j)+" : "+ mappingVector.elementAt(j+1)+" : "+mappingVector.elementAt(j+2).toString().trim()+" : "+getStringPropertyValue(mappingVector.elementAt(j+2).toString().trim())+"\n");
0850:
0851: // System.out.println(mappingVector.elementAt(j+1).toString());
0852:
0853: //------------------------------------------------
0854: // sonderparameter pr�fen
0855:
0856: newString = null;
0857:
0858: if ("selectedMethod".equals(mappingVector
0859: .elementAt(j + 1).toString())) {
0860: // System.out.println("ZWEI\n");
0861: String str1 = constraintVector.elementAt(
0862: i + 1).toString();
0863: if ((str1 != null)
0864: && (str1.indexOf("selectedMethod") >= 0)) {
0865: // System.out.println("bin bei selectedMethod\n");
0866: if (getSelectedMethod() != null) {
0867: s = getSelectedMethod().toString();
0868: //newString = s.substring( s.indexOf("Class#")+6, s.indexOf(":",s.indexOf("Class#")));
0869: selectedClassFound = true;
0870: setPropertyValue(
0871: mappingVector.elementAt(
0872: j + 2).toString(),
0873: getSelectedMethod()
0874: .getContainingClass()
0875: .getQualifiedName());
0876: newString = s;
0877: // System.out.println("gew�hlte Methode: "+s+"in der Klasse: "+getStringPropertyValue(mappingVector.elementAt(j+2).toString())+"\n");
0878: }
0879: }
0880: }
0881:
0882: if ("selectedAttribute".equals(mappingVector
0883: .elementAt(j + 1).toString())) {
0884: // System.out.println("DREI\n");
0885: String str5 = constraintVector.elementAt(
0886: i + 1).toString();
0887: if ((str5 != null)
0888: && (str5
0889: .indexOf("selectedAttribute") >= 0)) {
0890: // System.out.println("bin bei selectedAttribute\n");
0891: if (getSelectedAttribute() != null) {
0892: s = getSelectedAttribute()
0893: .toString();
0894: //newString = s.substring( s.indexOf("Class#")+6, s.indexOf(":",s.indexOf("Class#")));
0895: selectedClassFound = true;
0896: setPropertyValue(
0897: mappingVector.elementAt(
0898: j + 2).toString(),
0899: getSelectedMethod()
0900: .getContainingClass()
0901: .getQualifiedName());
0902: newString = s;
0903: // System.out.println("gew�hltes Attribute: "+s+"\n");
0904: }
0905: }
0906: }
0907:
0908: if ("selectedClass".equals(mappingVector
0909: .elementAt(j + 1).toString())
0910: && !selectedClassFound) {
0911: // System.out.println("VIER\n");
0912: String str3 = constraintVector.elementAt(
0913: i + 1).toString();
0914: // System.out.println(str3);
0915: if (str3 != null) {
0916: // System.out.println("VIER-EINS\n");
0917: if (getSelectedClass() != null) {
0918: // System.out.println("VIER-ZWEI\n");
0919: s = getSelectedClass().toString();
0920: selectedClassFound = true;
0921: newString = s
0922: .substring(
0923: s.indexOf("Class#") + 6,
0924: s
0925: .indexOf(
0926: ":",
0927: s
0928: .indexOf("Class#")));
0929: setPropertyValue(mappingVector
0930: .elementAt(j + 2)
0931: .toString(), newString);
0932: } else {
0933: IdeMessageManagerAccess
0934: .printMessage(
0935: IdeMessageType.ERROR_MODAL,
0936: "Please first select a class before applying this pattern!");
0937: }
0938: }
0939: }
0940:
0941: if ("selectedParameter".equals(mappingVector
0942: .elementAt(j + 1).toString())) {
0943: // System.out.println("F�NF\n");
0944: String str2 = constraintVector.elementAt(
0945: i + 1).toString();
0946: if ((str2 != null)
0947: && (str2
0948: .indexOf("selectedParameter") >= 0)) {
0949: String paraList = "";
0950: if (getSelectedMethod() != null)
0951: paraList = getSelectedMethod()
0952: .getParameterList()
0953: .getText();
0954: // System.out.println("paraString: "+paraList+"\n");
0955: Vector v = new Vector();
0956: v = extractParameter(paraList);
0957: if (v != null) {
0958: if (v.size() > 1) {
0959: Object[] possibleValues = v
0960: .toArray();
0961: JDialog jdialog = IdeWindowManagerAccess
0962: .getWindowManager()
0963: .createDialog(null);
0964: JOptionPane pane = new JOptionPane();
0965: jdialog = IdeWindowManagerAccess
0966: .getWindowManager()
0967: .createDialog(null);
0968: //jdialog = pane.createDialog(null, "titel");
0969: Object selectedValue = JOptionPane
0970: .showInputDialog(
0971: null,
0972: "Choose a parameter",
0973: "",
0974: JOptionPane.INFORMATION_MESSAGE,
0975: null,
0976: possibleValues,
0977: possibleValues[0]);
0978: // jdialog.show();
0979: if (selectedValue != null)
0980: newString = selectedValue
0981: .toString();
0982: else {
0983: newString = "";
0984: fehler = true;
0985: }
0986: } else
0987: newString = v.elementAt(0)
0988: .toString();
0989:
0990: } else {
0991: // IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL,"Selected method has no parameter");
0992: // muss jetzt constraint abbrechen!!!!!
0993: fehler = true;
0994: }
0995: }
0996:
0997: }
0998:
0999: //------------------------------------------------------
1000:
1001: if ((!fehler) && (newString == null))
1002: newString = getStringPropertyValue(mappingVector
1003: .elementAt(j + 2).toString());
1004:
1005: start = 0;
1006: if (!fehler) {
1007: while (start >= 0) {
1008: start = stringBuffer.toString()
1009: .indexOf(
1010: mappingVector
1011: .elementAt(
1012: j + 1)
1013: .toString(),
1014: start);
1015: // System.out.println("index von "+mappingVector.elementAt(j+1).toString()+" in "+stringBuffer.toString()+" ist "+start+"\n");
1016: length = mappingVector.elementAt(j + 1)
1017: .toString().length();
1018: if (start != -1) {
1019:
1020: // System.out.println(newString+"\n");
1021: if (newString == null)
1022: newString = "";
1023: if (start >= 0)
1024: stringBuffer.replace(start,
1025: start + length,
1026: newString);
1027: start += newString.length();
1028: }
1029: }
1030: }
1031: }
1032: }
1033:
1034: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"angepa�tes Constraint: "+stringBuffer.toString());
1035: // are there OCL-Constraints for this method?
1036: String whichMethod = "";
1037: if (!fehler) {
1038: for (int k = 0; k < placeVector.size(); k += 6) {
1039: //found
1040: // System.out.println("placeVector: "+placeVector.elementAt(k).toString()+"\n");
1041: // System.out.println("constrintVecotr: "+constraintVector.elementAt(i).toString()+"\n");
1042:
1043: if (placeVector.elementAt(k).toString().equals(
1044: constraintVector.elementAt(i)
1045: .toString())) {
1046:
1047: // System.out.println("SECHS\n");
1048: if ("class".equals(placeVector.elementAt(
1049: k + 2).toString())) {
1050: //System.out.println("SIEBEN\n");
1051: for (int j = 0; j < mappingVector
1052: .size(); j = j + 3) {
1053: if (mappingVector
1054: .elementAt(j)
1055: .toString()
1056: .equals(
1057: placeVector
1058: .elementAt(
1059: k)
1060: .toString())
1061: && mappingVector
1062: .elementAt(j + 1)
1063: .toString()
1064: .equals(
1065: placeVector
1066: .elementAt(
1067: k + 3)
1068: .toString())
1069: && (placeVector.elementAt(
1070: k + 5).toString()
1071: .equals(constraintVector
1072: .elementAt(
1073: i + 2)
1074: .toString()))) {
1075:
1076: //System.out.println("ACHT\n");
1077: if (getStringPropertyValue(mappingVector
1078: .elementAt(j + 2)
1079: .toString()) != null) {
1080: //System.out.println("NEUN\n");
1081: SciClass searchedClass = findClassByName(getStringPropertyValue(mappingVector
1082: .elementAt(j + 2)
1083: .toString()));
1084: if (searchedClass != null) {
1085: String old = searchedClass
1086: .getTagList()
1087: .getTagValue(
1088: "invariants");
1089: // System.out.println("ZZZZZZZZZZZZZZZZZZZZZZ "+stringBuffer.toString());
1090: if (old == null) {
1091: searchedClass
1092: .getTagList()
1093: .setTagValue(
1094: "invariants",
1095: stringBuffer
1096: .toString());
1097: } else {
1098: searchedClass
1099: .getTagList()
1100: .setTagValue(
1101: "invariants",
1102: old
1103: + " \nand "
1104: + stringBuffer
1105: .toString());
1106: }
1107: }
1108: }
1109: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Dieses Constraint soll zu: "+placeVector.elementAt(k+3).toString()+ " : "+getStringPropertyValue(mappingVector.elementAt(j+2).toString()) );
1110:
1111: }
1112: }
1113: }
1114:
1115: if ("method".equals(placeVector.elementAt(
1116: k + 2).toString())) {
1117: for (int j = 0; j < mappingVector
1118: .size(); j = j + 3) {
1119: if (mappingVector
1120: .elementAt(j)
1121: .toString()
1122: .equals(
1123: placeVector
1124: .elementAt(
1125: k)
1126: .toString())
1127: && (mappingVector
1128: .elementAt(j + 1)
1129: .toString()
1130: .equals(placeVector
1131: .elementAt(
1132: k + 3)
1133: .toString()))
1134: && (placeVector.elementAt(
1135: k + 5).toString()
1136: .equals(constraintVector
1137: .elementAt(
1138: i + 2)
1139: .toString()))) {
1140:
1141: String className = "";
1142:
1143: if ("selectedMethod"
1144: .equals(mappingVector
1145: .elementAt(
1146: j + 1)
1147: .toString())) {
1148: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Habs gefunden!!!\n" );
1149: SciFunction member = getSelectedMethod();
1150: SciFunction cpy = (SciFunction) member
1151: .copy();
1152: if ("postcondition#"
1153: .equals(placeVector
1154: .elementAt(
1155: k + 1)
1156: .toString()))
1157: cpy
1158: .getTagList()
1159: .setTagValue(
1160: "postconditions",
1161: stringBuffer
1162: .toString());
1163: else if ("precondition#"
1164: .equals(placeVector
1165: .elementAt(
1166: k + 1)
1167: .toString()))
1168: cpy
1169: .getTagList()
1170: .setTagValue(
1171: "preconditions",
1172: stringBuffer
1173: .toString());
1174: member.replace(cpy);
1175: } else {
1176: // find name of class this method belongs to
1177: for (int z = 0; z < mappingVector
1178: .size(); z += 3) {
1179: if (mappingVector
1180: .elementAt(z)
1181: .toString()
1182: .equals(
1183: constraintVector
1184: .elementAt(
1185: i)
1186: .toString())) {
1187: if (mappingVector
1188: .elementAt(
1189: z + 1)
1190: .toString()
1191: .equals(
1192: placeVector
1193: .elementAt(
1194: k + 4)
1195: .toString())) {
1196:
1197: if ("selectedClass"
1198: .equals(mappingVector
1199: .elementAt(
1200: z + 1)
1201: .toString())) {
1202: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Habs gefunden!!!\n" );
1203: if (getSelectedClass() != null) {
1204: s = getSelectedClass()
1205: .toString();
1206: className = s
1207: .substring(
1208: s
1209: .indexOf("Class#") + 6,
1210: s
1211: .indexOf(
1212: ":",
1213: s
1214: .indexOf("Class#")));
1215: } else
1216: className = "";
1217: } else
1218: className = getStringPropertyValue(mappingVector
1219: .elementAt(
1220: z + 2)
1221: .toString());
1222:
1223: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Classname ist: "+ className +"\n" );
1224:
1225: }
1226: }
1227: }
1228:
1229: if (findClassByName(className) != null) {
1230: Enumeration allMembersEnum = SciUtil
1231: .allMembers(
1232: findClassByName(className),
1233: false);
1234: SciMember member;
1235: while (allMembersEnum
1236: .hasMoreElements()) {
1237: member = (SciMember) allMembersEnum
1238: .nextElement();
1239: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Alle Members: "+member.toString()+"\n");
1240: if ((member
1241: .toString()
1242: .indexOf(
1243: "#"
1244: + className
1245: + "#") != -1)
1246: && (member instanceof SciOperation)
1247: && (member
1248: .toString()
1249: .indexOf(
1250: getStringPropertyValue(mappingVector
1251: .elementAt(
1252: j + 2)
1253: .toString())) != -1)) {
1254:
1255: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Habs gefunden!!!\n" );
1256: SciMember cpy = (SciMember) member
1257: .copy();
1258:
1259: if ("postcondition#"
1260: .equals(placeVector
1261: .elementAt(
1262: k + 1)
1263: .toString()))
1264: cpy
1265: .getTagList()
1266: .setTagValue(
1267: "postconditions",
1268: stringBuffer
1269: .toString());
1270: else if ("precondition#"
1271: .equals(placeVector
1272: .elementAt(
1273: k + 1)
1274: .toString()))
1275: cpy
1276: .getTagList()
1277: .setTagValue(
1278: "preconditions",
1279: stringBuffer
1280: .toString());
1281:
1282: member
1283: .replace(cpy);
1284: }
1285:
1286: }
1287: }
1288:
1289: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Dieses Constraint soll zu: "+placeVector.elementAt(k+3).toString()+ " : "+getStringPropertyValue(mappingVector.elementAt(j+2).toString().trim()) );
1290: }
1291: }
1292: }
1293: }
1294: }
1295: }
1296: }
1297: }
1298:
1299: }
1300:
1301: }
1302:
1303: }
|