/** * * C O P Y R I G H T N O T I C E * Copyright (c) 2001 by: * * The MicroArray Gene Expression Database group (MGED) * * Rosetta Inpharmatics * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation files * (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * * @author $Author: rhubley $ * @version $Revision: 1.4 $ * */ package org.biomage.tools.generate_classes; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.TreeSet; import java.util.Set; import java.util.Vector; import org.biomage.tools.helpers.StringOutputHelpers; import org.w3c.dom.*; /** * Description: * Class that is resposible for generating a java file * for the class represented by the class node passed * into the constructor. * */ public class CreatePackageFile extends CreateFile { /** * Description: * Constructor for the package file generator. * *
* @param packageNode: information for the package file to create. * @param packageOrder: information for how the associations should be ordered. * @param id2classFiles: look up to the class files to find which ones * should generate associations in the package file. * @param id2extInfo: map where documentation for the class can be * found *
*/ protected CreatePackageFile( Element packageNode, Element packageOrder, Map id2classFiles, Map id2extInfo ) throws Exception { super(); headerInformation(packageNode, id2extInfo); associationInfo = associationAttrInformation(packageNode, packageOrder, id2classFiles); } /** * Description: * Returns the class name of the class. * *
* @return the class name *
*/ protected String getClassName() throws Exception { return className; } /** * Description: * Obtains the information to generate the information for * the package and the declaration of the class. * *
* @param packageNode: node representing the package. * @param id2extInfo: map where documentation for the class can be * found *
*/ protected void headerInformation( Element packageNode, Map id2extInfo ) throws Exception { try { // Obtain the class information className = XMIParseHelpers.getElementName(packageNode) + "_package"; StringOutputHelpers.writeOutput("\t" + className, 3); isAbstract = false; visibility = "public"; // Obtain the documentation classDoc = getDocumentation(id2extInfo, packageNode.getAttribute("xmi.id")); packageName = XMIParseHelpers.getElementName(packageNode); } catch ( Exception e ) { // for setting a break point for debugging purposes throw e; } } /** * Description: * Puts together the information on the class associations. * *
* @param packageNode: package node and the contained class nodes. * @param id2classFiles: map to the class files for list information. *
* *
* @return Vector of ClassAttrInformations *
* */ protected Vector associationAttrInformation( Element packageNode, Element packageOrder, Map id2classFiles ) throws Exception { NodeList classOrder = packageOrder.getElementsByTagName("list"); Vector associationInfo = new Vector(classOrder.getLength()); Map name2index = new HashMap(); for (int i = 0; i < classOrder.getLength();i++) { associationInfo.add(null); name2index.put(((Element) classOrder.item(i)).getAttribute("name"), new Integer(i)); } NodeList classes = packageNode.getElementsByTagName("Foundation.Core.Class"); for (int i = 0; i < classes.getLength();i++) { Element classNode = (Element) classes.item(i); CreateClassFile classFile = (CreateClassFile) id2classFiles.get(classNode.getAttribute("xmi.id")); String name = classFile.className; if (XMIParseHelpers.COMPOSITE == classFile.typeOwned || null == name2index.get(name)) { continue; } IdentifierAttrInformation classList = new IdentifierAttrInformation(classFile, true); associationInfo.set(((Integer) name2index.get(name)).intValue(), classList); } // All packages require this. importVector = true; return associationInfo; } /** * Description: * Returns what kind of model element this class is based on. * * @return returns that this represents the model itself */ public int getFileType() { return UML_PACKAGE; } }