Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2010 Jorge J. Gomez-Sanz
*
* This file is part of the INGENME tool. INGENME is an open source meta-editor
* which produces customized editors for user-defined modeling languages
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
**/
package ingenias.ingenme.plugin;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import ingenias.editor.Log;
import java.awt.Frame;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import ingenias.editor.ProjectProperty;
import ingenias.editor.export.Diagram2SVG;
import ingenias.exception.NullEntity;
import ingenias.generator.browser.*;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import ingenias.exception.InvalidEntity;
import ingenias.exception.InvalidGraph;
import ingenias.exception.NotFound;
import ingenias.exception.NotInitialised;
import ingenias.exception.NullEntity;
import ingenias.generator.browser.AttributedElement;
import ingenias.generator.browser.Browser;
import ingenias.generator.browser.BrowserImp;
import ingenias.generator.browser.Graph;
import ingenias.generator.browser.GraphAttribute;
import ingenias.generator.browser.GraphAttributeFactory;
import ingenias.generator.browser.GraphCollection;
import ingenias.generator.browser.GraphEntity;
import ingenias.generator.browser.GraphEntityFactory;
import ingenias.generator.browser.GraphFactory;
import ingenias.generator.browser.GraphRelationship;
import ingenias.generator.browser.GraphRole;
import ingenias.generator.datatemplate.Sequences;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
class FileCopy {
public static void main(String[] args) {
try {
copy("fromFile.txt", "toFile.txt");
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
public static File copy(InputStream from, String toFileName)
throws IOException {
File toFile = new File(toFileName);
System.out.println("AbsolutePath toFile: "+ toFile.getAbsolutePath());
if (toFile.isDirectory())
throw new IOException("Target file "+toFileName+" is a directory when a file was expected");
if (toFile.exists()) {
if (!toFile.canWrite())
throw new IOException("FileCopy: "
+ "destination file is unwriteable: " + toFileName);
} else {
String parent = toFile.getParent();
if (parent == null)
parent = System.getProperty("user.dir");
File dir = new File(parent);
if (!dir.exists())
throw new IOException("FileCopy: "
+ "destination directory doesn't exist: " + parent);
if (dir.isFile())
throw new IOException("FileCopy: "
+ "destination is not a directory: " + parent);
if (!dir.canWrite())
throw new IOException("FileCopy: "
+ "destination directory is unwriteable: " + parent);
}
FileOutputStream to = null;
try {
to = new FileOutputStream(toFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = from.read(buffer)) != -1)
to.write(buffer, 0, bytesRead); // write
} finally {
if (from != null)
try {
from.close();
} catch (IOException e) {
;
}
if (to != null)
try {
to.close();
} catch (IOException e) {
;
}
}
return toFile;
}
public static File copy(String fromFileName, String toFileName)
throws IOException {
File fromFile = new File(fromFileName);
File toFile = new File(toFileName);
System.out.println("AbsolutePath fromFile: "+ fromFile.getAbsolutePath());
System.out.println("AbsolutePath toFile: "+ toFile.getAbsolutePath());
if (!fromFile.exists())
throw new IOException("FileCopy: " + "no such source file: "
+ fromFileName);
if (!fromFile.isFile())
throw new IOException("FileCopy: " + "can't copy directory: "
+ fromFileName);
if (!fromFile.canRead())
throw new IOException("FileCopy: " + "source file is unreadable: "
+ fromFileName);
if (toFile.isDirectory())
toFile = new File(toFile, fromFile.getName());
if (toFile.exists()) {
if (!toFile.canWrite())
throw new IOException("FileCopy: "
+ "destination file is unwriteable: " + toFileName);
} else {
String parent = toFile.getParent();
if (parent == null)
parent = System.getProperty("user.dir");
File dir = new File(parent);
if (!dir.exists())
throw new IOException("FileCopy: "
+ "destination directory doesn't exist: " + parent);
if (dir.isFile())
throw new IOException("FileCopy: "
+ "destination is not a directory: " + parent);
if (!dir.canWrite())
throw new IOException("FileCopy: "
+ "destination directory is unwriteable: " + parent);
}
FileInputStream from = null;
FileOutputStream to = null;
try {
from = new FileInputStream(fromFile);
to = new FileOutputStream(toFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = from.read(buffer)) != -1)
to.write(buffer, 0, bytesRead); // write
} finally {
if (from != null)
try {
from.close();
} catch (IOException e) {
;
}
if (to != null)
try {
to.close();
} catch (IOException e) {
;
}
}
return toFile;
}
}
public class Ingened2Ingenme extends ingenias.editor.extension.BasicToolImp {
private String lastValue="";
private Vector iconsToMove=new Vector();
private int k;
private GraphEntityFactory gef;
private GraphFactory gfact;
private Graph tmpdiagram;
private GraphAttributeFactory atfact;
private String folder="";
/**
* Initialises the class with a file containing a INGENIAS specification
*
*@param file Path to file containing INGENIAS specification
*@exception Exception Error accessing any file or malformed XML exception
*/
public Ingened2Ingenme(String file, String folder) throws Exception {
super(file);
this.folder=folder;
}
/**
* Initialises the class giving access to diagrams in run-time
**/
public Ingened2Ingenme(Browser browser) throws Exception {
super(browser);
}
@Override
public String getVersion() {
return "@modingened2ingenme.ver@";
}
/**
* Gets the description of this module
*
*@return The description
*/
public String getDescription() {
return "This translates the modeling language specification into the GOPRR-like xml format required by INGENME";
}
/**
* Gets the name of this module
*
*@return The name
*/
public String getName() {
return "INGENME translator";
}
private boolean error=false;
/**
* It opens the different files generated under the ingenias/jade/components folder looking
* for specific tags. These tags mark the beginning and the end of the modification
*/
public void run() {
try {
gef=new GraphEntityFactory(browser.getState());
gfact=new GraphFactory(browser.getState());
atfact=new GraphAttributeFactory(browser.getState());
iconsToMove.clear();
final StringBuffer output=new StringBuffer();
Vector errors=new Vector();
Vector binaryRelationships = processEdges(output, errors);
processEntities(output, errors,binaryRelationships);
if (errors.isEmpty()) {
String saveLocation=saveMetamodel(output);
String projectHome = new File(saveLocation).getParentFile().getParent();
for (String icon:iconsToMove){
File iconFile = new File(icon);
try {
FileCopy.copy(icon, projectHome+"/images/"+iconFile.getName());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else
{
/* javax.swing.JOptionPane.showMessageDialog(getResources().getMainFrame(), "There are errors in the metamodel. Check the editor panels","Error",javax.swing.JOptionPane.ERROR_MESSAGE);*/
ingenias.editor.Log.getInstance().logERROR("There were errors processing the metamodel");
int k=0;
for (String errorEntry:errors){
ingenias.editor.Log.getInstance().logERROR(k+":"+errorEntry);
k++;
}
error=true;
}
}
catch (NotFound ex) {
ex.printStackTrace();
}
catch (NullEntity ex) {
ex.printStackTrace();
}
}
private Vector processEdges(StringBuffer output, Vector errors) throws NotFound, NullEntity {
Vector relationships=new Vector();
Vector binaryRelationships=new Vector();
Graph[] graphs=getBrowser().getGraphs();
for (Graph g:graphs){
GraphRelationship[] grels=g.getRelationships();
for (GraphRelationship grel:grels){
relationships.add(grel);
}
};
for (GraphRelationship grel:relationships){
if (grel.getType().equalsIgnoreCase("BinaryRel")){
// build fake metarel
binaryRelationships.add(grel);
String relName=grel.getID();
String rolSourceName=relName+"source";
String rolTargetName=relName+"target";
output.append("\n");
appendProperties(errors,output,grel,grel.getID());
appendVisualRepresentationRelationship(errors,output,grel);
output.append("\n");
boolean oneSource=false;
boolean oneTarget=false;
Vector sources=new Vector();
Vector targets=new Vector();
Hashtable mincardsource=new Hashtable();
Hashtable mincardtarget=new Hashtable();
Hashtable maxcardsource=new Hashtable();
Hashtable maxcardtarget=new Hashtable();
output.append("\n");
output.append("\n");
output.append("\n");
output.append("\n");
// Build fake roles
GraphRole[] groles=grel.getRoles();
String playerSource="";
String playerTarget="";
for (GraphRole grole:groles){
if (grole.getName().equalsIgnoreCase("BinaryRelsource")){
try {
playerSource=grole.getPlayer().getID();
} catch (NullEntity e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (grole.getName().equalsIgnoreCase("BinaryReltarget")){
try {
playerTarget=grole.getPlayer().getID();
} catch (NullEntity e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
output.append("\n");
output.append("\n");
output.append("\n");
// empty properties
output.append("\n");
output.append("\n");
output.append("\n");
output.append("\n");
output.append("\n");
output.append("\n");
output.append("\n");
// empty properties
output.append("\n");
output.append("\n");
output.append("\n");
output.append("\n");
}
}
return binaryRelationships;
}
private void processEntities(final StringBuffer output,
Vector errors, Vector binaryRelationships) throws NotFound, NullEntity {
GraphEntity[] entities = browser.getAllEntities();
for (GraphEntity ge:entities){
if (ge.getType().equalsIgnoreCase("MetaDiagram")){
// generate diagram entry
GraphEntity basicrepre=obtainBasicRepresentation(errors, ge);
String smalliconPath=null;
if (basicrepre==null){
smalliconPath="images/m"+ge.getID().replace(' ', '_').replace(':', '_')+".png";
new File("target/images").mkdirs();
File smallicon=new File("target/"+smalliconPath);
inventIcon(ge, smallicon);
iconsToMove.add(smallicon.getAbsolutePath());
} else {
if (basicrepre.getAttributeByName("SmallIcon")==null){
errors.add("smallicon field of entity "+basicrepre.getID()+" is empty");
}else {
smalliconPath=basicrepre.getAttributeByName("SmallIcon").getSimpleValue();
}
}
output.append("\n");
appendProperties(errors,output,ge);
output.append("\n");
output.append("\n");
output.append("\n");
GraphEntity[] connectedElements = getRelatedElements(ge, "Contains", "Containstarget");
if (connectedElements==null || connectedElements.length==0)
errors.add("metadiagram "+ge.getID()+" does not have objects or relationships associated");
else {
output.append("");
for (int k=0;k");
}
}
output.append("");
output.append("");
for (int k=0;k");
}
}
for (GraphRelationship binaryRel:binaryRelationships){
output.append("");
}
output.append("");
}
output.append("\n");
}
if (ge.getType().equalsIgnoreCase("MetaObject")){
if (ge.getAttributeByName("Instantiable")==null||ge.getAttributeByName("Instantiable").getSimpleValue().equalsIgnoreCase(""))
errors.add("Instantiable field in entity "+ge.getID()+" is empty");
else
if (ge.getAttributeByName("Package")==null)
errors.add("Package field in entity "+ge.getID()+" is empty");
else{
String keyfield="id";
if (ge.getAttributeByName("Keyfield")!=null)
try {
keyfield=ge.getAttributeByName("Keyfield").getEntityValue().getID();
} catch (NullEntity ne){
keyfield="id";
}
Hashtable inheriting = getRelatedElementsHashtable(ge,"InheritsO", "InheritsOtarget");
Set inheritingSet = inheriting.keySet();
inheritingSet.remove(ge);
if (inheritingSet.size()!=0){
if (inheritingSet.size()>1){
errors.add("Entity "+ge.getID()+" inherits from more than one entity. Only simple inheritance is permitted.");
} else
output.append("