ingenias.idegen.ObjectsGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
The INGENIAS Meta-Editor core. It is a set of facilities to generate an editor from a detailed xml description
/**
* 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 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.idegen;
import ingenias.generator.interpreter.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import org.w3c.dom.*;
import org.apache.xerces.parsers.*;
import java.io.*;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import org.w3c.dom.*;
import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.InputSource;
import org.xml.sax.AttributeList;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.DocumentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator;
import org.xml.sax.Parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.ParserAdapter;
import org.xml.sax.helpers.ParserFactory;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
import org.apache.xerces.parsers.SAXParser;
import ingenias.idegen.*;
public class ObjectsGenerator {
private Hashtable objects = new Hashtable();
private Hashtable metamodels = new Hashtable();
private Hashtable roles = new Hashtable();
private Hashtable relationships = new Hashtable();
/**
* Default constructor.
*/
public ObjectsGenerator() {
}
// ()
/**
* Description of the Method
*
*@param source Description of Parameter
*@return Description of the Returned Value
*@exception IOException Description of Exception
*@exception SAXException Description of Exception
*/
public String parse(String source, String directory) throws IOException, SAXException,
Exception {
DOMParser parser = new DOMParser();
// Parse the Document
// and traverse the DOM
// parser.setIncludeIgnorableWhitespace(false);
InputSource sr = new InputSource(source);
parser.parse(sr);
// Obtain the document.
Document doc = parser.getDocument();
Vector qr = new Vector();
NodeList nl = doc.getElementsByTagName("meta-models");
/*NodeList nlobjects = doc.getElementsByTagName("object");
this.extractObjects(nlobjects);*/
nl = nl.item(0).getChildNodes();
// Read symbols
for (int k = 0; k < nl.getLength(); k++) {
Node n = nl.item(k);
if (n.getNodeName().equalsIgnoreCase("object")) {
ingenias.idegen.Object object = new ingenias.idegen.Object(n);
this.objects.put(object.getId(), object);
}
/*if (n.getNodeName().equalsIgnoreCase("objects")) {
this.extractObjects(n.getChildNodes());
}*/
if (n.getNodeName().equalsIgnoreCase("metamodel")) {
Metamodel mm = new Metamodel(n);
this.metamodels.put(mm.getId(), mm);
}
if (n.getNodeName().equalsIgnoreCase("relationship")) {
Relationship mm = new Relationship(n);
this.relationships.put(mm.getId(), mm);
}
if (n.getNodeName().equalsIgnoreCase("role")) {
Role mm = new Role(n);
this.roles.put(mm.getId(), mm);
}
}
// Generate symbols
String result = "";
Enumeration enumeration = objects.elements();
while (enumeration.hasMoreElements()) {
ingenias.idegen.Object object = (ingenias.idegen.Object) enumeration.
nextElement();
result = result + this.generateObjectsCode(object);
}
enumeration = relationships.elements();
while (enumeration.hasMoreElements()) {
Relationship relationship = (Relationship) enumeration.nextElement();
result = result + this.generateRelationshipCode(relationship);
}
enumeration = metamodels.elements();
while (enumeration.hasMoreElements()) {
Metamodel metamodel = (Metamodel) enumeration.nextElement();
result = result + this.generateMetamodelCode(metamodel);
}
result=result+""+directory+" ";
result = result + " ";
return result;
}
/**
* Description of the Method
*
*@param nl Description of Parameter
*@return Description of the Returned Value
*/
private void extractObjects(NodeList nl) throws SAXException {
for (int k = 0; k < nl.getLength(); k++) {
Node n = nl.item(k);
if (n.getNodeName().equalsIgnoreCase("object")) {
ingenias.idegen.Object object = new ingenias.idegen.Object(n);
this.objects.put(object.getId(), object);
}
}
}
private String generateRelationshipCode(ingenias.idegen.Relationship
relationship) throws Exception {
String result = "";
String resultRoles = "";
result = "\n";
result = result + " " + relationship.getId() +" \n";
Enumeration enumeration = relationship.getPreferredOrder().elements();
while (enumeration.hasMoreElements()) {
result = result + "";
result = result + "" +
enumeration.nextElement().toString() + " \n";
result = result + " ";
}
Graphics graphics = relationship.getGraphics();
if (relationship.getGraphics() != null) {
result = result + "";
result = result + " " + relationship.getId() +
" \n";
result = result + " " +
relationship.getGraphics().getBigIcon() + " \n";
result = result + " " +
relationship.getGraphics().getSmallIcon() + " \n";
enumeration = relationship.getGraphics().getProperties().keys();
/* Hashtable properties = relationship.getProperties();
enumeration = properties.elements();
while (enumeration.hasMoreElements()) {
ingenias.idegen.Property property = (ingenias.idegen.Property) enumeration.
nextElement();
System.err.println("rel code for "+relationship.getId()+" generating "+property.getId()+"\n\n"+result);
String relAttrCode=generateCodeAttributes(property);
result = result + relAttrCode;
System.err.println("rel code for "+relationship.getId()+"\n\n"+result);
}*/
while (enumeration.hasMoreElements()) {
String pname = enumeration.nextElement().toString();
java.awt.Point value = (java.awt.Point) relationship.getGraphics().
getProperties().get(pname);
result = result + " \n";
result = result + " " +
pname.substring(0, 1).toUpperCase() +
pname.substring(1, pname.length()) + " \n";
result = result + " " + value.x + " \n";
result = result + " " + value.y + " \n";
result = result + " \n";
}
/* result = result + " " +
relationship.getGraphics().getImage().x +
" ";
result = result + " " +
relationship.getGraphics().getImage().y +
" ";*/
Hashtable views = relationship.getGraphics().getContent();
enumeration = views.keys();
while (enumeration.hasMoreElements()) {
String viewid = enumeration.nextElement().toString();
result = result + "";
result = result + " " +
views.get(viewid).toString() +
" ";
result = result + " " +
viewid +
" ";
result = result + " \n";
}
enumeration = relationship.getProperties().keys();
while (enumeration.hasMoreElements()) {
String pname = enumeration.nextElement().toString();
Property value = (Property) relationship.getProperties().get(pname);
result = result + " \n";
pname = value.getId().substring(0, 1).toUpperCase() +
value.getId().substring(1, value.getId().length());
result = result + " " + pname + " \n";
result = result + " \n";
}
Hashtable properties = relationship.getProperties();
enumeration = properties.elements();
while (enumeration.hasMoreElements()) {
ingenias.idegen.Property property = (ingenias.idegen.Property) enumeration.
nextElement();
String relAttrCode=generateCodeAttributes(property);
result = result + relAttrCode;
}
result = result + " \n";
}
Hashtable properties = relationship.getProperties();
enumeration = properties.elements();
while (enumeration.hasMoreElements()) {
ingenias.idegen.Property property = (ingenias.idegen.Property) enumeration.
nextElement();
String relAttrCode=generateCodeAttributes(property);
result = result + relAttrCode;
}
/* Object[] spair=(Object[])(relationship.getSource().firstElement());
String source=spair[0].toString();
String smincard=spair[1].toString();
String smaxcard=spair[2].toString();
result=result+" "+source+" \n";
result=result+" "+smincard+" \n";
result=result+" "+smaxcard+" \n";
Role rs=(Role)this.roles.get(source);
Enumeration enumeration=rs.getPlayers().elements();
while (enumeration.hasMoreElements()){
String player=enumeration.nextElement().toString();
result=result+" \n";
result=result+" "+player+" \n";
result=result+" ";
}
result=result+" ";*/
Enumeration tenumeration = relationship.getRoles().elements();
while (tenumeration.hasMoreElements()) {
Vector rpair = (Vector) tenumeration.nextElement();
String target = rpair.elementAt(0).toString();
String tmincard = rpair.elementAt(1).toString();
String tmaxcard = rpair.elementAt(2).toString();
resultRoles = resultRoles + " \n";
resultRoles = resultRoles + " " + target + " \n";
try {
if (this.roles.get(target)==null){
System.err.println("Could not find a role named "+target);
throw new Exception("Could not find a role named "+target);
} else {
Enumeration enumeration2 = ( (Role)this.roles.get(target)).getPreferredOrder().
elements();
while (enumeration2.hasMoreElements()) {
resultRoles = resultRoles + "";
resultRoles = resultRoles + "" +
enumeration2.nextElement().toString() + " \n";
resultRoles = resultRoles + " ";
}
}
}
catch (Exception t) {
System.err.println("error processing " + target);
throw t;
}
Hashtable properties1 = ( (Role)this.roles.get(target)).getProperties();
Enumeration enumeration1 = properties1.elements();
while (enumeration1.hasMoreElements()) {
ingenias.idegen.Property property = (ingenias.idegen.Property)
enumeration1.nextElement();
resultRoles = resultRoles + this.generateCodeAttributes(property);
}
resultRoles = resultRoles + " ";
result = result + " \n";
result = result + " " + target + " \n";
result = result + " " + tmincard + " \n";
result = result + " " + tmaxcard + " \n";
Role rt = (Role)this.roles.get(target);
if (rt == null) {
System.err.println("error obteniendo " + target);
}
enumeration = rt.getPlayers().elements();
while (enumeration.hasMoreElements()) {
String player = enumeration.nextElement().toString();
result = result + " \n";
result = result + " " + player + " \n";
result = result + " ";
}
result = result + " ";
}
result = result + "\n" + resultRoles + "\n";
return result;
}
private String generateObjectsCode(ingenias.idegen.Object object) {
String result = "";
result = "";
result = result + " " + object.getId() + " \n";
System.err.println(object.getId());
result = result + " " + this.capitalize(object.getKey()) +
" \n";
if (!object.getToString().equals(""))
result = result + " " + object.getToString() +" \n";
else
result = result + " get" + this.capitalize(object.getKey()) +"() \n";
result = result + " " +
ingenias.generator.util.Conversor.
replace(object.getDescription(), "\n", "<br>") +
" \n";
result = result + " " +
ingenias.generator.util.Conversor.
replace(object.getRecomm(), "\n", "<br>") +
" \n";
Enumeration enumeration = object.getPreferredOrder().elements();
while (enumeration.hasMoreElements()) {
result = result + "";
result = result + "" +
enumeration.nextElement().toString() + " \n";
result = result + " ";
}
if (object.getInherits() == null ||
object.getInherits().trim().equalsIgnoreCase("")) {
result = result + " Entity \n";
}
else {
result = result + " " + object.getInherits() + " \n";
}
Hashtable properties = object.getProperties();
enumeration = properties.elements();
while (enumeration.hasMoreElements()) {
ingenias.idegen.Property property = (ingenias.idegen.Property) enumeration.
nextElement();
result = result + generateCodeAttributes(property);
}
result = result + " \n";
if (object.getGraphics() != null) {
result = result + "";
properties = object.getProperties();
enumeration = properties.elements();
while (enumeration.hasMoreElements()) {
ingenias.idegen.Property property =
(ingenias.idegen.Property) enumeration. nextElement();
result = result + generateCodeAttributes(property);
}
result = result + " " + object.getId() + " \n";
result = result + " " +
object.getGraphics().getBigIcon() + " \n";
result = result + " " +
object.getGraphics().getSmallIcon() + " \n";
enumeration = object.getGraphics().getProperties().keys();
while (enumeration.hasMoreElements()) {
String pname = enumeration.nextElement().toString();
java.awt.Point value = (java.awt.Point) object.getGraphics().
getProperties().get(pname);
result = result + " \n";
result = result + " " +
pname.substring(0, 1).toUpperCase() +
pname.substring(1, pname.length()) + " \n";
result = result + " " + value.x + " \n";
result = result + " " + value.y + " \n";
result = result + " \n";
System.err.println("looking "+object.getId()+" "+pname);
Property gproperty=this.findProperty(object,pname);
if (gproperty!=null)
result = result + generateCodeAttributes(gproperty);
}
/* result = result + " " + object.getGraphics().getImage().x +
" ";
result = result + " " + object.getGraphics().getImage().y +
" ";*/
Hashtable views = object.getGraphics().getContent();
enumeration = views.keys();
while (enumeration.hasMoreElements()) {
String viewid = enumeration.nextElement().toString();
result = result + "";
result = result + " " +
views.get(viewid).toString() +
" ";
result = result + " " +
viewid +
" ";
result = result + " \n";
}
enumeration = object.getProperties().keys();
while (enumeration.hasMoreElements()) {
String pname = enumeration.nextElement().toString();
Property value = (Property) object.getProperties().get(pname);
result = result + " \n";
pname = value.getId().substring(0, 1).toUpperCase() +
value.getId().substring(1, value.getId().length());
result = result + " " + pname + " \n";
result = result + " \n";
}
if (object.getInstanciable()) {
result = result + " \n";
result = result + " " + object.getId() + " \n";
result = result + " \n";
}
result = result + " \n";
}
result = result + "\n";
result = result + " " + object.getId() + " \n";
result = result + " \n";
if (object.getInstanciable()) {
result = result + "\n";
result = result + " " + object.getId() + " \n";
result = result + " \n";
}
if (object.getInherits() == null || object.getInherits().equals("")) {
result = result + "\n";
result = result + " " + object.getId() + " \n";
result = result + " \n";
}
if (object.getInherits() != null && !object.getInherits().equals("")) {
result = result + "\n";
result = result + " " + object.getId() + " \n";
result = result + " " + object.getInherits() + " \n";
result = result + " \n";
}
return result;
}
private String generateSingleType(Property property) {
String result = "";
String pname = property.getId();
String pid = pname.substring(0, 1).toUpperCase() +
pname.substring(1, pname.length());
if (property.getIsmetamodelinstance() || property.getIsmetaclassinstance()) {
result = result + " \n";
result = result + " " + pid + " \n";
result = result + " \n";
}
result = result + " \n";
result = result + " " + pid + " \n";
if (property.getIsmetamodelinstance()) {
result = result + " ingenias.editor.entities." +
property.getType() + "ModelEntity \n";
}
else {
if (property.getIsmetaclassinstance()) {
result = result + " ingenias.editor.entities." +
property.getType() + " \n";
}
else {
result = result + " " + property.getType() + " \n";
}
}
result = result + " \n";
result = result + " \n";
if (property.getIsmetamodelinstance()) {
result = result + " " + property.getType() +
"ModelEntity \n";
}
else
if (property.getIsmetaclassinstance()) {
result = result + " ingenias.editor.entities." +
property.getType() + " \n";
}
else {
result = result + " " + property.getType() + " \n";
}
result = result + " " + pid + " \n";
result = result + " \n";
if (!property.getIsmetaclassinstance() && !property.getIsmetamodelinstance() && !property.getIscollection()) {
System.err.println("Es simple........"+property.getId());
result = result + " \n";
result=result+" "+property.getType()+" \n";
result = result + " " + pid + " \n";
if (property.getPreferredwidget() == null) {
result = result +
" ingenias.editor.widget.CustomJTextField \n";
}
else {
result = result + " " + property.getPreferredwidget() +
" \n";
}
Enumeration enumeration2 = property.getDefaultValues().elements();
while (enumeration2.hasMoreElements()) {
String value = enumeration2.nextElement().toString();
result = result + " \n";
result = result + " " + value + " \n";
result = result + " \n";
}
result = result + " \n";
}
return result;
}
private String generateCollectionType(Property property) {
String result = "";
String pname = property.getId();
String pid = pname.substring(0, 1).toUpperCase() +
pname.substring(1, pname.length());
if (property.getIsmetamodelinstance() || property.getIsmetaclassinstance()) {
result = result + " ";
result = result + " " + pid + " \n";
result = result + " \n";
}
result = result + " \n";
result = result + " " + pid + " \n";
if (property.getIsmetamodelinstance()) {
result = result + " ingenias.editor.entities." +
property.getType() + "ModelEntity \n";
}
else {
if (property.getIsmetaclassinstance()) {
result = result + " ingenias.editor.entities." +
property.getType() + " \n";
}
else {
result = result + " " + property.getType() + " \n";
}
}
result = result + " \n";
result = result + " \n";
if (property.getIsmetamodelinstance()) {
result = result + " " + property.getType() +
"ModelEntity \n";
}
else
if (property.getIsmetaclassinstance()) {
result = result + " ingenias.editor.entities." +
property.getType() + " \n";
}
else {
result = result + " " + property.getType() + " \n";
}
result = result + " " + pid + " \n";
result = result + " \n";
if (!property.getIsmetaclassinstance() && !property.getIsmetamodelinstance() && !property.getIscollection()) {
System.err.println("Ejecución de simple1");
System.err.println("Ejecución de simple");
System.err.println("Ejecución de simple");
System.err.println("Ejecución de simple");
System.err.println("Ejecución de simple");
System.err.println("Ejecución de simple");
System.err.println("Ejecución de simple");
result = result + " \n";
// result=result+" "+property.getType()+" \n";
result = result + " " + pid + " \n";
result = result + " \n";
}
return result;
}
private String generateCodeAttributes(Property property) {
if (property.getIscollection()) {
return this.generateCollectionType(property);
}
else {
return this.generateSingleType(property);
}
}
private Property findProperty(ingenias.idegen.Object obj,String pname){
if (obj.getProperties().containsKey(pname))
return (Property)obj.getProperties().get(pname);
else {
if (obj.getInherits()!=null){
System.err.println("now "+obj.getInherits()+" "+this.objects.get(obj.getInherits())+" "+pname);
return findProperty((ingenias.idegen.Object)this.objects.get(obj.getInherits()),pname);
} else
return null;
}
}
private Vector findInstantiableGraphicalInheritors(ingenias.idegen.Object obj){
Vector result=new Vector();
for (ingenias.idegen.Object currentObject:this.objects.values()){
if (currentObject.getInherits()!=null && currentObject.getInherits().equalsIgnoreCase(obj.getId())){
if (currentObject.getInstanciable() && currentObject.getGraphics()!=null){
result.add(currentObject);
}
result.addAll(findInstantiableGraphicalInheritors(currentObject));
}
}
return result;
}
private String generateMetamodelCode(Metamodel metamodel) throws Exception {
String result = "";
try {
result = "\n";
result = result + "" + metamodel.getId() + " \n";
result = result + "" + metamodel.getIcon() + " \n";
result = result + " ";
result = result + "\n";
result = result + "" + metamodel.getIcon() + " \n";
result = result + "" + metamodel.getCode() + " \n";
Hashtable properties = metamodel.getProperties();
Enumeration enumeration = metamodel.getPreferredOrder().elements();
while (enumeration.hasMoreElements()) {
result = result + "";
result = result + "" +
enumeration.nextElement().toString() + " ";
result = result + " \n";
}
enumeration = properties.elements();
while (enumeration.hasMoreElements()) {
ingenias.idegen.Property property = (ingenias.idegen.Property) enumeration.
nextElement();
result = result + generateCodeAttributes(property);
}
enumeration = metamodel.getRelationships().elements();
while (enumeration.hasMoreElements()) {
String relat = enumeration.nextElement().toString();
result = result + "\n";
result = result + "" + relat + " ";
ingenias.idegen.Relationship relationshipobject = (ingenias.idegen.Relationship)this.
relationships.get(relat);
Hashtable views = relationshipobject.getGraphics().getContent();
Enumeration enumeration_1 = views.keys();
while (enumeration_1.hasMoreElements()) {
String viewid = enumeration_1.nextElement().toString();
result = result + "";
result = result + " " + views.get(viewid).toString() + " ";
result = result + " " +viewid +" ";
result = result + " \n";
}
result = result + " \n";
result = result + "\n";
result = result + "" + relat + " ";
result = result + " ";
result = result + "\n";
result = result + "" + relat + " ";
result = result + " ";
}
result = result + "" + metamodel.getId() + " \n";
Enumeration objects = metamodel.getObjects().elements();
HashSet additionalInvisibleTypes=new HashSet ();
HashSet visibleTypes=new HashSet ();
while (objects.hasMoreElements()) {
String objid = objects.nextElement().toString();
ingenias.idegen.Object object = (ingenias.idegen.Object)this.
objects.get(objid);
if (object==null)
System.err.println(objid+" not found when studying metamodel "+metamodel.getId());
result = result + " \n";
try {
result = result + " " + object.getId() + " \n";
}
catch (Exception ex) {
System.err.println("error reading " + objid);
throw ex;
}
Hashtable views = object.getGraphics().getContent();
Enumeration enumeration1 = views.keys();
while (enumeration1.hasMoreElements()) {
String viewid = enumeration1.nextElement().toString();
result = result + "";
result = result + " " +
views.get(viewid).toString() +
" ";
result = result + " " +
viewid +
" ";
result = result + " \n";
}
result = result + " \n";
result = result + " \n";
result = result + " true \n";
result = result + " " + object.getId() + " \n";
result = result + " " +
object.getGraphics().getSmallIcon() + " \n";
result = result + " \n";
visibleTypes.add(object.getId());
Hashtable props = object.getProperties();
for (ingenias.idegen.Property prop:props.values()){
if (prop.ismetaclassinstance){
Object currentType = this.objects.get(prop.getType());
if (currentType.getInstanciable() && currentType.getGraphics()!=null){
additionalInvisibleTypes.add(currentType.getId());
}
Vector ";
}
catch (RuntimeException ex) {
ex.printStackTrace();
System.err.println(result);
throw ex;
}
return result;
}
/**
* Description of the Method
*
*@param nl Description of Parameter
*@return Description of the Returned Value
*/
private String extractRelationships(NodeList nl) {
return "";
}
/**
* Description of the Method
*
*@param nl Description of Parameter
*@return Description of the Returned Value
*/
private String extractMetamodels(NodeList nl) {
return "";
}
public static void main(String args[]) throws Exception {
ingenias.editor.Log.initInstance(new PrintWriter(System.out),
new PrintWriter(System.err));
if (args.length==0){
System.err.println("Call this program with the following arguments");
System.err.println("java ingenias.idegen.ObjectsGenerator path_to_a_metamodelfile [path_to_a_template_file]");
// instead of doing a System.exit, a runtimeException is created
// this permits to return an error code. System.exit simply aborts the
// running JVM and disturbs the original execution
throw new RuntimeException(new Exception("Wrong invocation"));
}
boolean alreadyAccepted=false;
char acceptance=' ';
File acceptanceFile=new File (""+System.getProperty("user.home")+"/.ingened.properties");
if (System.getProperty("user.home")!=null){
alreadyAccepted=acceptanceFile.exists();
}
String header="\n\n\nINGENME Copyright (C) 2010 Jorge J. Gomez-Sanz\n"+
"This file is part of the INGENME tool. INGENME is an open source meta-editor\n"+
"which produces customized editors for user-defined modeling languages\n"+
"This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you \n" +
"are welcome to use it according to the following terms :\n\n";
String toBeShown="";
if (!alreadyAccepted){
toBeShown=toBeShown+header;
StringBuffer licenseContent=new StringBuffer();
System.err.println(getResourceList("/licenses"));
InputStream fis=getResourceList("/licenses").get("licenses/LICENSE_EN.txt");
int read=1;
while (read!=-1){
read=fis.read();
if (read!=-1)
licenseContent.append((char)read);
}
fis.close();
toBeShown=toBeShown+("\n"+licenseContent);
/* String[] lines = toBeShown.split("\n");
int k=0;
while (k2) {
String file = args[2];
if (!new File(file).exists()){
System.err.println("The template file "+args[1]+" does not exist");
// instead of doing a System.exit, a runtimeException is created
// this permits to return an error code. System.exit simply aborts the
// running JVM and disturbs the original execution
throw new RuntimeException(new Exception("The template file "+args[1]+" does not exist"));
}
System.err.println(file);
Codegen.applyArroba(result, new FileInputStream(file));
}
else {
String packageName="/templates";
Hashtable inputStreamInFolder = getResourceList(packageName);
for(String filename:inputStreamInFolder.keySet()){
if (filename.toLowerCase().endsWith(".xml")){
System.err.println(filename);
Codegen.applyArroba(result, inputStreamInFolder.get(filename));
}
};
}
} else {
for (Frame f:Frame.getFrames()){
f.dispose();
}
// instead of doing a System.exit, a runtimeException is created
// this permits to return an error code. System.exit simply aborts the
// running JVM and disturbs the original execution
throw new RuntimeException(new Exception("Wrong parameters"));
}
}
// based on code from Axel in https://forums.oracle.com/thread/2086378
public static Hashtable getResourceList(String resourceFolder) throws IOException {
URL url = ObjectsGenerator.class.getResource(resourceFolder);
URLConnection uconn = url.openConnection();
Hashtable inputStreams=new Hashtable();
if (uconn.getClass().getName().endsWith("FileURLConnection")) {
File f = new File(url.getFile());
String[] dir = f.list();
if (dir != null) {
for (int i = 0 ; i < dir.length; i++) {
inputStreams.put(dir[i], uconn.getInputStream());
}
}
} else if (uconn.getClass().getName().endsWith("JarURLConnection")) {
JarFile jf = ((JarURLConnection)uconn).getJarFile();
for (Enumeration e = jf.entries() ; e.hasMoreElements() ;) {
JarEntry je = (JarEntry)e.nextElement();
if (je.getName().startsWith(resourceFolder.substring(1,resourceFolder.length()))) {
// it is assumed the first character in the resourceFolder variable is a slash "/"
inputStreams.put(je.getName(), jf.getInputStream(je));
}
}
}
return inputStreams;
}
// Modified version of
// http://stackoverflow.com/questions/6022672/why-does-inputstreamreader-throw-a-npe-when-reading-from-a-jar
public static List getResourcesInFolder(JarInputStream jarFile, String packageName) throws IOException {
packageName = packageName.replace(".", "/");
List classes = new ArrayList();
try {
for (JarEntry jarEntry; (jarEntry = jarFile.getNextJarEntry()) != null;) {
if ((jarEntry.getName().startsWith(packageName)) ) {
classes.add(jarEntry.getName().replace("/", "."));
}
}
} finally {
jarFile.close();
}
return classes;
}
private String capitalize(String pname) {
return pname.substring(0, 1).toUpperCase() +
pname.substring(1, pname.length());
}
}