/** * * 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 * * (expand as necessary) * * 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.5 $ * */ 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.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 responsible for generating a java file * for the interface represented by the association end * node passed into the constructor. * */ public class CreateInterfaceFile extends CreateFile { private final String m_sInterfaceName; private final Element m_associationEndElement; private final Map m_id2classElement; private final Map m_id2packageInformation; /** * Description: * Converts a role name to an interface name. * *

* @param sRoleName: role name. *

* *

* @return a string which is the interface name. *

*/ public static String getInterfaceName( String sRoleName ) throws Exception { return "Has" + StringOutputHelpers.initialCap(sRoleName); } /** * Description: * Constructor for the interface file generator. * *

* @param sInterfaceName: the interface name. * * @param associationEndElement: the association end element. * * @param id2classElement: the map from ID to class element. * * @param id2packageInformation: the map from ID to package information. *

*/ public CreateInterfaceFile( String sInterfaceName, Element associationEndElement, Map id2classElement, Map id2packageInformation ) throws Exception { // Progress indicator. StringOutputHelpers.writeOutput("\t" + sInterfaceName, 3); m_sInterfaceName = sInterfaceName; m_associationEndElement = associationEndElement; m_id2classElement = id2classElement; m_id2packageInformation = id2packageInformation; headerInformation(); associationInformation(); } /** * Description: * Puts together the information on the interface associations. * Overwrites base class to handle multi-valued associations * *

*

*/ protected void associationInformation( ) throws Exception { associationInfo = new Vector(); Element classifierElement = XMIParseHelpers.getAssociationEndClassifier(m_associationEndElement); String sClassifierID = XMIParseHelpers.getElementIDRef(classifierElement); Element classElement = (Element)m_id2classElement.get(sClassifierID); String sClassifierName = XMIParseHelpers.getElementName(classElement); // Set up the imports. CreateMageClassFileList.PackageInformation packageInformation = (CreateMageClassFileList.PackageInformation) m_id2packageInformation.get(getPackageID(classElement)); if (packageInformation == null) { if (!"Common".equals(packageName)) { packageImports.add("Common" + "." + sClassifierName); } } else if (!packageInformation.name.equals(packageName)) { packageImports.add(packageInformation.name + "." + sClassifierName); } if (XMIParseHelpers.getAssociationEndMultiplicityRangeUpper( m_associationEndElement) == -1) { importVector = true; } importSerializable = false; // Set up the associations. // BUGBUG: minor problem (since it's currently not used) but the // aggregation of this end comes from the other end) associationInfo.add(new AssociationAttrInformation( XMIParseHelpers.getElementName(m_associationEndElement), "public", sClassifierName, "comment", // TODO get the real comment. XMIParseHelpers.getAssociationEndMultiplicityRangeLower( m_associationEndElement), XMIParseHelpers.getAssociationEndMultiplicityRangeUpper( m_associationEndElement), //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// XMIParseHelpers.getAssociationEndMultiplicityRangeLower( m_associationEndElement), XMIParseHelpers.getAssociationEndMultiplicityRangeUpper( m_associationEndElement), //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// XMIParseHelpers.typeAssociationEndAggregate( m_associationEndElement), XMIParseHelpers.isAssociationEndOrdered( m_associationEndElement), null, false, XMIParseHelpers.isIdentifiable(m_associationEndElement), //////////Add dummy values false for thisNav and otherNav//////////// false, false) ); ///////////////////////////////////////////////////////////////////// } /** * Description: * Obtains the information to generate the information for * the package and the declaration of the class. * *

*

*/ protected void headerInformation( ) throws Exception { className = m_sInterfaceName; packageName = "Interface"; packageDoc = "Generated interfaces for association roles."; visibility = "public"; isInterface = true; } /** * Description: * Returns what kind of model element this class is based on. * * @return returns that this represents the model itself */ public int getFileType() { return JAVA_INTERFACE; } }