1.1 --- a/mdr/extras/uml2mof/build.xml Thu Mar 20 08:21:13 2003 +0000
1.2 +++ b/mdr/extras/uml2mof/build.xml Thu Mar 20 11:31:18 2003 +0000
1.3 @@ -11,20 +11,20 @@
1.4 Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
1.5 Microsystems, Inc. All Rights Reserved.
1.6 -->
1.7 -
1.8 -<project name="uml2mof" basedir="." default="jars">
1.9 +<project basedir="." default="jars" name="uml2mof">
1.10 <!-- =========================================================== -->
1.11 <!-- == Properties ============================================= -->
1.12 <!-- =========================================================== -->
1.13 <property file="ant.properties"/>
1.14 - <property name="nbroot" location="../../../"/>
1.15 - <property name="nbext" location="${nbroot}/nbbuild"/>
1.16 + <property location="../../../" name="nbroot"/>
1.17 + <property location="${nbroot}/nbbuild" name="nbext"/>
1.18 <property name="build.compiler.debug" value="true"/>
1.19 <property name="build.compiler.deprecation" value="true"/>
1.20 <property name="homepage.base" value="netbeans.org"/>
1.21 <property name="dist.base" value="www.netbeans.org/download/nbms/40/MDR"/>
1.22 - <property name="build.dir" location="release"/>
1.23 - <property name="build.classes.dir" location="src"/>
1.24 + <property location="release" name="build.dir"/>
1.25 + <property location="src" name="build.classes.dir"/>
1.26 + <property location="common" name="common.dir"/>
1.27
1.28 <!-- all external files and directories -->
1.29 <property name="openide-lookup.jar" value="${nbroot}/openide/standalone/openide-lookup.jar"/>
1.30 @@ -37,11 +37,14 @@
1.31 <property name="mdrapi.jar" value="${nbroot}/mdr/netbeans/modules/autoload/mdrapi.jar"/>
1.32 <property name="jmiutils.jar" value="${nbroot}/mdr/netbeans/modules/autoload/ext/jmiutils.jar"/>
1.33 <property name="nbmdr.jar" value="${nbroot}/mdr/netbeans/modules/ext/nbmdr.jar"/>
1.34 + <property name="fileupload.jar" value="${common.dir}/commons-fileupload-1.0-beta-1.jar"/>
1.35 + <property name="servlet.jar" value="${nbroot}/web/external/servlet-2.3.jar"/>
1.36 <property name="umlclasses.dir" value="uml"/>
1.37 <property name="umlmetamodel.xml" value="${nbroot}/mdr/xmidiffs/01-02-15.xml"/>
1.38 <property name="umlmetamodel.diff" value="${nbroot}/mdr/xmidiffs/01-02-15_Diff.xml"/>
1.39 <property name="mdrant.jar" value="${nbroot}/mdr/extras/mdrant/release/mdrant.jar"/>
1.40 <property name="storage.file" value="build"/>
1.41 + <property name="warfile" value="uml2mof.war"/>
1.42
1.43 <!-- =========================================================== -->
1.44 <!-- == Taskdefs =============================================== -->
1.45 @@ -51,7 +54,7 @@
1.46 <!--taskdef name="genlist" classname="org.netbeans.nbbuild.MakeListOfNBM" classpath="${nbantext.jar}"/-->
1.47 <!--taskdef name="locjar" classname="org.netbeans.nbbuild.LocalizedJar" classpath="${nbantext.jar}"/-->
1.48
1.49 - <taskdef name="mdr" classname="org.netbeans.mdrant.MdrTask">
1.50 + <taskdef classname="org.netbeans.mdrant.MdrTask" name="mdr">
1.51 <classpath>
1.52 <pathelement location="${mdrant.jar}"/>
1.53 <pathelement location="${nbmdr.jar}"/>
1.54 @@ -76,7 +79,7 @@
1.55 <mkdir dir="${build.classes.dir}"/>
1.56 <condition property="storageExists">
1.57 <and>
1.58 - <available property="storageExists" file="${storage.file}.btd"/>
1.59 + <available file="${storage.file}.btd" property="storageExists"/>
1.60 <available file="${storage.file}.btx"/>
1.61 <not><available file="${storage.file}.btb"/></not>
1.62 </and>
1.63 @@ -88,7 +91,7 @@
1.64 <mkdir dir="${umlclasses.dir}"/>
1.65 <mdr storageFile="${storage.file}">
1.66 <instantiate name="uml"/>
1.67 - <readXMI file="${umlmetamodel.diff}" extent="uml"/>
1.68 + <readXMI extent="uml" file="${umlmetamodel.diff}"/>
1.69 <mapClass dir="${umlclasses.dir}" extent="uml"/>
1.70 </mdr>
1.71 </target>
1.72 @@ -96,11 +99,9 @@
1.73 <!-- == Compilation of all parts =============================== -->
1.74 <!-- =========================================================== -->
1.75
1.76 - <target name="compile" depends="init,jmi">
1.77 + <target depends="init,jmi" name="compile">
1.78 <!-- sources -->
1.79 - <javac srcdir="src" destdir="${build.classes.dir}"
1.80 - debug="${build.compiler.debug}"
1.81 - deprecation="${build.compiler.deprecation}">
1.82 + <javac debug="${build.compiler.debug}" deprecation="${build.compiler.deprecation}" destdir="${build.classes.dir}" srcdir="src">
1.83 <classpath>
1.84 <pathelement location="${openide-lookup.jar}"/>
1.85 <pathelement location="${xml-apis.jar}"/>
1.86 @@ -109,6 +110,7 @@
1.87 <pathelement location="${mdrapi.jar}"/>
1.88 <pathelement location="${umlclasses.dir}"/>
1.89 </classpath>
1.90 + <exclude name="org/netbeans/lib/jmi/uml2mof/servlet/"/>
1.91 </javac>
1.92 </target>
1.93
1.94 @@ -116,14 +118,14 @@
1.95 <!-- == Creating all mdr jars ================================== -->
1.96 <!-- =========================================================== -->
1.97
1.98 - <target name="jars" depends="compile">
1.99 + <target depends="compile" name="jars">
1.100 <mkdir dir="${build.dir}"/>
1.101
1.102 <mkdir dir="${umlclasses.dir}/org/omg/uml/resources"/>
1.103 <copy file="${umlmetamodel.xml}" todir="${umlclasses.dir}/org/omg/uml/resources"/>
1.104 <copy file="${umlmetamodel.diff}" todir="${umlclasses.dir}/org/omg/uml/resources"/>
1.105
1.106 - <jar jarfile="${build.dir}/uml-1.4.jar" compress="false">
1.107 + <jar compress="false" jarfile="${build.dir}/uml-1.4.jar">
1.108 <fileset dir="${umlclasses.dir}" excludesfile="${standard-jar-excludes.txt}">
1.109 <include name="org/omg/uml/"/>
1.110 </fileset>
1.111 @@ -138,21 +140,55 @@
1.112 <copy file="${xml-apis.jar}" todir="${build.dir}"/>
1.113 <copy file="${openide-lookup.jar}" todir="${build.dir}"/>
1.114
1.115 - <jar jarfile="${build.dir}/uml2mof.jar" compress="false" manifest="manifest.mf">
1.116 + <jar compress="false" jarfile="${build.dir}/uml2mof.jar" manifest="manifest.mf">
1.117 <fileset dir="${build.classes.dir}" excludesfile="${standard-jar-excludes.txt}">
1.118 - <include name="org/netbeans/lib/jmi/uml2mof"/>
1.119 + <include name="org/netbeans/lib/jmi/uml2mof/"/>
1.120 + <exclude name="org/netbeans/lib/jmi/uml2mof/servlet/"/>
1.121 </fileset>
1.122 <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
1.123 <include name="org/netbeans/lib/jmi/uml2mof/"/>
1.124 + <exclude name="org/netbeans/lib/jmi/uml2mof/servlet/"/>
1.125 </fileset>
1.126 </jar>
1.127 </target>
1.128
1.129 <!-- =========================================================== -->
1.130 + <!-- == Make WAR file ========================================== -->
1.131 + <!-- =========================================================== -->
1.132 +
1.133 + <target depends="jars" name="war">
1.134 + <javac debug="${build.compiler.debug}" deprecation="${build.compiler.deprecation}" destdir="${build.classes.dir}" srcdir="src">
1.135 + <classpath>
1.136 + <pathelement location="${openide-lookup.jar}"/>
1.137 + <pathelement location="${xml-apis.jar}"/>
1.138 + <pathelement location="${jmi.jar}"/>
1.139 + <pathelement location="${mof.jar}"/>
1.140 + <pathelement location="${mdrapi.jar}"/>
1.141 + <pathelement location="${umlclasses.dir}"/>
1.142 + <pathelement location="${fileupload.jar}"/>
1.143 + <pathelement location="${servlet.jar}"/>
1.144 + </classpath>
1.145 + </javac>
1.146 + <jar compress="false" jarfile="${build.dir}/uml2mof-servlet.jar">
1.147 + <fileset dir="${build.classes.dir}" excludesfile="${standard-jar-excludes.txt}">
1.148 + <include name="org/netbeans/lib/jmi/uml2mof/servlet/"/>
1.149 + </fileset>
1.150 + <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
1.151 + <include name="org/netbeans/lib/jmi/uml2mof/servlet/"/>
1.152 + </fileset>
1.153 + </jar>
1.154 + <war warfile="${build.dir}/${warfile}" webxml="webApplication/WEB-INF/web.xml">
1.155 + <fileset dir="webApplication" includes="**/*.jsp,**/*.htm"/>
1.156 + <lib dir="${build.dir}" includes="*.jar"/>
1.157 + <lib dir="${common.dir}" includes="*.jar"/>
1.158 + </war>
1.159 + </target>
1.160 +
1.161 + <!-- =========================================================== -->
1.162 <!-- == Cleaning compiled stuff ================================ -->
1.163 <!-- =========================================================== -->
1.164
1.165 - <target name="clean" description="Removes all build products.">
1.166 + <target description="Removes all build products." name="clean">
1.167 <delete>
1.168 <fileset dir="${build.classes.dir}">
1.169 <include name="**/*.class"/>
1.170 @@ -161,7 +197,7 @@
1.171 <delete dir="${umlclasses.dir}/org/omg/uml/resouces"/>
1.172 <delete dir="${build.dir}"/>
1.173 </target>
1.174 - <target name="real-clean" depends="clean">
1.175 + <target depends="clean" name="real-clean">
1.176 <delete dir="${umlclasses.dir}"/>
1.177 <delete file="${storage.file}.btd"/>
1.178 <delete file="${storage.file}.btx"/>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/mdr/extras/uml2mof/src/org/netbeans/lib/jmi/uml2mof/servlet/TransformServlet.java Thu Mar 20 11:31:18 2003 +0000
2.3 @@ -0,0 +1,181 @@
2.4 +/**
2.5 + * Sun Public License Notice
2.6 + *
2.7 + * The contents of this file are subject to the Sun Public License Version
2.8 + * 1.0 (the "License"). You may not use this file except in compliance with
2.9 + * the License. A copy of the License is available at http://www.sun.com/
2.10 + *
2.11 + * The Original Code is NetBeans.
2.12 + * The Initial Developer of the Original Code is Adaptive Inc.
2.13 + * Portions created by Sun Microsystems, Inc. are Copyright (C) 2003 Sun
2.14 + * Microsystems, Inc. All Rights Reserved.
2.15 + *
2.16 + * Contributor(s): Nick Dowler.
2.17 + */
2.18 +
2.19 +package org.netbeans.lib.jmi.uml2mof.servlet;
2.20 +
2.21 +import java.util.*;
2.22 +import java.io.*;
2.23 +import javax.servlet.*;
2.24 +import javax.servlet.http.*;
2.25 +import org.apache.commons.fileupload.*;
2.26 +import java.util.Iterator;
2.27 +import javax.jmi.model.ModelPackage;
2.28 +import javax.jmi.model.MofPackage;
2.29 +import javax.jmi.xmi.XmiReader;
2.30 +import javax.jmi.xmi.XmiWriter;
2.31 +
2.32 +import org.netbeans.api.mdr.CreationFailedException;
2.33 +import org.netbeans.api.mdr.MDRManager;
2.34 +import org.netbeans.api.mdr.MDRepository;
2.35 +import org.netbeans.lib.jmi.uml2mof.Transformer;
2.36 +import org.omg.uml.UmlPackage;
2.37 +import org.openide.ErrorManager;
2.38 +import org.openide.util.Lookup;
2.39 +
2.40 +public class TransformServlet extends HttpServlet {
2.41 +
2.42 + private static final String MOF_INSTANCE = "MOFInstance";
2.43 + private static final String UML_INSTANCE = "UMLInstance";
2.44 + private static final String UML_MM = "UML";
2.45 + private static final String TRANSFORM_IN_PROGRESS = "<meta http-equiv=\"refresh\" content=\"0;url='TransformServlet'\"/><html><body><font size=\"medium\">Please wait! Transforming UML 1.4 to MOF 1.4...</font></body></html>";
2.46 + private static final String NOTHING_TO_TRANSFORM = "There is no file on the session to transform";
2.47 +
2.48 + private String fileStore;
2.49 + private FileUpload fu;
2.50 +
2.51 + class TransformInfo {
2.52 + TransformInfo(FileItem fi) { this.fi = fi; }
2.53 + public FileItem getFileItem() { return fi; }
2.54 + private FileItem fi;
2.55 + }
2.56 +
2.57 + public void init(ServletConfig config) throws ServletException {
2.58 + super.init(config);
2.59 + try {
2.60 + fu = new FileUpload();
2.61 + // maximum size before a FileUploadException will be thrown
2.62 + Integer maxFileSize = new Integer(config.getInitParameter("maxFileSize"));
2.63 + fu.setSizeMax(maxFileSize.intValue());
2.64 + // maximum size that will be stored in memory
2.65 + Integer maxMemSize = new Integer(config.getInitParameter("maxMemSize"));
2.66 + fu.setSizeThreshold(maxMemSize.intValue());
2.67 + // the location for saving data that is larger than getSizeThreshold()
2.68 + fileStore = config.getInitParameter("fileStore");
2.69 + fu.setRepositoryPath(fileStore);
2.70 + // set up mdrepository to use in memory storage
2.71 + System.setProperty("org.netbeans.mdr.storagemodel.StorageFactoryClassName", "org.netbeans.mdr.persistence.memoryimpl.StorageFactoryImpl");
2.72 + } catch (Exception cfe) {
2.73 + throw new ServletException(cfe);
2.74 + }
2.75 + }
2.76 +
2.77 + private MofPackage getUmlPackage(MDRepository rep) throws Exception {
2.78 + ModelPackage umlMM = (ModelPackage) rep.getExtent(UML_MM);
2.79 + if (umlMM == null) {
2.80 + umlMM = (ModelPackage) rep.createExtent(UML_MM);
2.81 + }
2.82 + MofPackage result = getUmlPackage(umlMM);
2.83 + if (result == null) {
2.84 + XmiReader reader = (XmiReader)Lookup.getDefault().lookup(XmiReader.class);
2.85 + reader.read(UmlPackage.class.getResource("resources/01-02-15_Diff.xml").toString(), umlMM);
2.86 + }
2.87 + result = getUmlPackage(umlMM);
2.88 + return result;
2.89 + }
2.90 +
2.91 + private MofPackage getUmlPackage(ModelPackage umlMM) {
2.92 + for (Iterator it = umlMM.getMofPackage().refAllOfClass().iterator(); it.hasNext();) {
2.93 + MofPackage pkg = (MofPackage) it.next();
2.94 + if (pkg.getContainer() == null && "UML".equals(pkg.getName())) {
2.95 + return pkg;
2.96 + }
2.97 + }
2.98 + return null;
2.99 + }
2.100 +
2.101 + private String formatException(Exception e) {
2.102 + StringWriter sw = new StringWriter();
2.103 + PrintWriter pw = new PrintWriter(sw);
2.104 + e.printStackTrace(pw);
2.105 + return e.toString() + "\n" + sw.toString();
2.106 + }
2.107 +
2.108 + private void doTransform(FileItem fi, OutputStream out) throws Exception {
2.109 + XmiReader reader = (XmiReader)Lookup.getDefault().lookup(XmiReader.class);
2.110 + XmiWriter writer = (XmiWriter)Lookup.getDefault().lookup(XmiWriter.class);
2.111 + MDRepository rep = MDRManager.getDefault().getDefaultRepository();
2.112 + rep.beginTrans(true);
2.113 + try {
2.114 + ModelPackage mof = (ModelPackage) rep.getExtent(MOF_INSTANCE);
2.115 + UmlPackage uml = (UmlPackage) rep.getExtent(UML_INSTANCE);
2.116 + if (mof == null) {
2.117 + mof = (ModelPackage)rep.createExtent(MOF_INSTANCE);
2.118 + }
2.119 + if (uml == null) {
2.120 + uml = (UmlPackage)rep.createExtent(UML_INSTANCE, getUmlPackage(rep));
2.121 + }
2.122 + reader.read(fi.getInputStream(), "", uml);
2.123 + Transformer.execute(uml, mof);
2.124 + writer.write(out, mof, null);
2.125 + } finally {
2.126 + rep.endTrans(true);
2.127 + }
2.128 + }
2.129 +
2.130 + public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException
2.131 + {
2.132 + try {
2.133 + HttpSession session = req.getSession();
2.134 + TransformInfo ti = (TransformInfo)session.getAttribute("transform");
2.135 + if (ti != null) {
2.136 + try {
2.137 + FileItem fi = ti.getFileItem();
2.138 + doTransform(fi, res.getOutputStream());
2.139 + res.setContentType(fi.getContentType());
2.140 + res.setHeader("Content-Disposition", "inline;filename=" + fi.getName());
2.141 + } finally {
2.142 + session.setAttribute("transform", null);
2.143 + }
2.144 + } else {
2.145 + res.getWriter().println(NOTHING_TO_TRANSFORM);
2.146 + }
2.147 + } catch (Exception e) {
2.148 + throw new ServletException(e);
2.149 + }
2.150 + }
2.151 +
2.152 + public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException
2.153 + {
2.154 + try {
2.155 + HttpSession session = req.getSession();
2.156 + TransformInfo ti = (TransformInfo)session.getAttribute("transform");
2.157 + if (ti == null) {
2.158 + List fileItems = fu.parseRequest(req);
2.159 + Iterator i = fileItems.iterator();
2.160 + String redirect = null;
2.161 + while (i.hasNext()) {
2.162 + FileItem fi = (FileItem)i.next();
2.163 + if ("umlfile".equals(fi.getFieldName()) && ti == null) {
2.164 + ti = new TransformInfo(fi);
2.165 + session.setAttribute("transform", ti);
2.166 + }
2.167 + if ("redirect".equals(fi.getFieldName()) && redirect == null)
2.168 + redirect = fi.getString();
2.169 + }
2.170 + if (redirect != null)
2.171 + res.sendRedirect(res.encodeRedirectURL(redirect));
2.172 + } else {
2.173 + PrintWriter out = res.getWriter();
2.174 + out.println(TRANSFORM_IN_PROGRESS);
2.175 + }
2.176 + } catch (Exception e) {
2.177 + try {
2.178 + (res.getWriter()).println(formatException(e));
2.179 + } catch (Exception n) {
2.180 + throw new ServletException(n);
2.181 + }
2.182 + }
2.183 + }
2.184 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/mdr/extras/uml2mof/webApplication/WEB-INF/web.xml Thu Mar 20 11:31:18 2003 +0000
3.3 @@ -0,0 +1,44 @@
3.4 +<!--
3.5 + Sun Public License Notice
3.6 +
3.7 +The contents of this file are subject to the Sun Public License
3.8 +Version 1.0 (the "License"). You may not use this file except in
3.9 +compliance with the License. A copy of the License is available at
3.10 +http://www.sun.com/
3.11 +
3.12 +The Original Code is NetBeans. The Initial Developer of the Original
3.13 +Code is Adaptive, Inc. Portions Copyright 2003 Sun
3.14 +Microsystems, Inc. All Rights Reserved.
3.15 +
3.16 +Contributors: Nick Dowler (Adaptive Inc.)
3.17 +-->
3.18 +<?xml version="1.0" encoding="UTF-8"?>
3.19 +<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
3.20 +<web-app>
3.21 + <display-name>uml2mof</display-name>
3.22 + <description>A sample web application to convert UML 1.4 to MOF 1.4.</description>
3.23 + <servlet>
3.24 + <servlet-name>TransformServlet</servlet-name>
3.25 + <servlet-class>org.netbeans.lib.jmi.uml2mof.servlet.TransformServlet</servlet-class>
3.26 + <init-param>
3.27 + <param-name>fileStore</param-name>
3.28 + <param-value>c:/temp</param-value>
3.29 + </init-param>
3.30 + <init-param>
3.31 + <param-name>maxMemSize</param-name>
3.32 + <param-value>256000</param-value>
3.33 + </init-param>
3.34 + <init-param>
3.35 + <param-name>maxFileSize</param-name>
3.36 + <param-value>1000000</param-value>
3.37 + </init-param>
3.38 + <load-on-startup>1</load-on-startup>
3.39 + </servlet>
3.40 + <servlet-mapping>
3.41 + <servlet-name>TransformServlet</servlet-name>
3.42 + <url-pattern>/TransformServlet</url-pattern>
3.43 + </servlet-mapping>
3.44 + <welcome-file-list>
3.45 + <welcome-file>transform.htm</welcome-file>
3.46 + </welcome-file-list>
3.47 +</web-app>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/mdr/extras/uml2mof/webApplication/feedback.htm Thu Mar 20 11:31:18 2003 +0000
4.3 @@ -0,0 +1,20 @@
4.4 +<!--
4.5 + Sun Public License Notice
4.6 +
4.7 +The contents of this file are subject to the Sun Public License
4.8 +Version 1.0 (the "License"). You may not use this file except in
4.9 +compliance with the License. A copy of the License is available at
4.10 +http://www.sun.com/
4.11 +
4.12 +The Original Code is NetBeans. The Initial Developer of the Original
4.13 +Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
4.14 +Microsystems, Inc. All Rights Reserved.
4.15 +
4.16 +Contributors: Nick Dowler (Adaptive Inc.)
4.17 +-->
4.18 +<meta http-equiv="refresh" content="0;url='TransformServlet'"/>
4.19 +<html>
4.20 + <body>
4.21 + <font size="medium">Please wait! Transforming UML 1.4 to MOF 1.4...</font>
4.22 + </body>
4.23 +</html>
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/mdr/extras/uml2mof/webApplication/transform.htm Thu Mar 20 11:31:18 2003 +0000
5.3 @@ -0,0 +1,26 @@
5.4 +<!--
5.5 + Sun Public License Notice
5.6 +
5.7 +The contents of this file are subject to the Sun Public License
5.8 +Version 1.0 (the "License"). You may not use this file except in
5.9 +compliance with the License. A copy of the License is available at
5.10 +http://www.sun.com/
5.11 +
5.12 +The Original Code is NetBeans. The Initial Developer of the Original
5.13 +Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
5.14 +Microsystems, Inc. All Rights Reserved.
5.15 +
5.16 +Contributors: Nick Dowler (Adaptive Inc.)
5.17 +-->
5.18 +<html>
5.19 + <head>
5.20 + <title>Transform UML 1.4 to MOF 1.4</title>
5.21 + </head>
5.22 + <body>
5.23 + <form name="umltomof" action="TransformServlet" method="POST" enctype="multipart/form-data">
5.24 + <input type="file" name="umlfile"/>
5.25 + <input type="submit" name="submit" value="Transform"/>
5.26 + <input type="hidden" name="redirect" value="feedback.htm"/>
5.27 + </form>
5.28 + </body>
5.29 +</html>
5.30 \ No newline at end of file