();
- IncludeCmdXML = getComponentProperty(componentElement, "IncludeCmdXML");
- IncludeTlmXML = getComponentProperty(componentElement, "IncludeTlmXML");
- IncludeEvrXML = getComponentProperty(componentElement, "IncludeEvrXML");
- IncludeParamXML = getComponentProperty(componentElement, "IncludeParamXML");
- IncludeInternalIFXML = getComponentProperty(componentElement, "IncludeInternalIFXML");
- IncludeIncludeHdr = getComponentProperty(componentElement, "IncludeHdrFile");
-
- Package p = (Package) componentElement.getObjectParent();
- URIName = p.getURI();
- }
-
- /**
- * Sets the component stereotype string value
- * @param compStereotype Stereotype string
- */
- public void setStereoType(String compStereotype) {
- this.compStereotype = compStereotype;
- }
-
- /**
- * Creates a new port object using the port Element inputted. This processes the port and can throw an exception if something in the port is illegal.
- * It also adds the port into fillList.
- *
- *
- *
- *
- * @param portElement
- * @throws PortException
- */
- public void newAddPort(Element portElement) throws PortException {
- portObject port = new portObject();
- String portName = portElement.getHumanName().split(" ")[1];
- port.index = ((MultiplicityElement) portElement).getLower();
- port.datatype = getPortDataType(portElement);
- port.datatypeNamespace = getPortDataTypeNamespace(portElement);
- port.stereotype = getPortStereotype(portElement);
- filtList.put(portName, port);
- if (port.stereotype.equals("async_input")) {
- port.priority = getPortProperty(portElement, "priority");
- port.full = getPortProperty(portElement, "full");
- }
- }
-
- /**
- * Creates a new port object using the port Element inputted. This processes the port and can throw an exception if something in the port is illegal.
- * It also adds the port into fillList.
- *
- * @param portElement
- * @throws PortException
- */
- public void newRolePort(Element portElement) throws PortException {
- portObject port = new portObject();
- String portName = portElement.getHumanName().split(" ")[1];
- port.index = ((MultiplicityElement) portElement).getLower();
- port.datatype = getPortDataType(portElement);
- port.datatypeNamespace = getPortDataTypeNamespace(portElement);
- //port.stereotype = getPortStereotype(portElement);
- if(StereotypesHelper.hasStereotypeOrDerived(portElement, "input")) {
- port.stereotype = "input";
- } else if(StereotypesHelper.hasStereotypeOrDerived(portElement, "output")) {
- port.stereotype = "output";
- }
- port.role = getPortStereotype(portElement);
- filtList.put(portName, port);
- }
-
- /**
- * Returns the port name.
- *
- * @param portElement port which the name will be extracted from
- * @return The name of the port
- */
- public String getPortName(Element portElement) {
- return portElement.getHumanName().split(" ")[1];
- }
-
- /**
- * Returns the port stereotype.
- *
- * @param portElement port which the stereotype will be extracted from
- * @return The stereotype of the port
- */
- public String getPortStereotype(Element portElement) {
- return portElement.getHumanName().split(" ")[0];
- }
-
-
- /**
- * This returns the full path of the data type which includes the directory tree.
- *
- * @param portElement
- * @return port data type string
- * @throws PortException
- */
- public String getPortDataType(Element portElement) throws PortException {
- // Perform a null check
- if(((TypedElement) portElement).getType() == null) {
- String errstr = "Port " + ((TypedElement)portElement).getName() + " of component "
- + ((NamedElement)(portElement.getOwner())).getName() + " has no data type";
- throw new PortException(errstr);
- }
- // Get the parent package of the port interface type
- Package p = (Package) ((TypedElement)portElement).getType().getObjectParent();
- // Get the packages URI name
- String portURIName = p.getURI();
- return portURIName + "/" + ((TypedElement)portElement).getType().getName();
- }
-
-
- /**
- * This returns the port data type without the full path.
- * It also tags on the Namespace.
- *
- * @param portElement
- * @return data type + '::' + name space
- */
- public String getPortDataTypeNamespace(Element portElement) {
- String namespace = "";
- Type portType = ((TypedElement) portElement).getType();
- String propVal = getPortTypeProperty(portType, "Namespace");
- if (!propVal.equals("")) {
- namespace = propVal + "::";
- }
- String[] portName = portType.getHumanName().split(" ");
- return namespace + portName[portName.length - 1];
- }
-
- /**
- * Returns the filtList HashMap, a map with a string associated with a port object.
- * @return HashMap
- */
- public HashMap getPortHashList() {
- return filtList;
- }
-
-
- /**
- * Returns the component's URI, which is the location in the tree hierarchy.
- * @return string of position in hierarchy
- */
- public String getURI() {
- return URIName;
- }
-
-
- /**
- * Return the full dictionary path which includes the URI path specified in the package above the component.
- * @param includeString
- * @return input string prepended by URIName
- */
- private String getDictionaryString(String includeString) {
- if (includeString.equals("")) {
- return "";
- } else {
- if (URIName.equals("")) {
- return includeString;
- }
- else {
- return URIName + "/" + includeString;
- }
- }
- }
-
- /**
- * Prepends the IncludeCmdXML String with the URI Name
- * @return address string
- */
- public String getIncludeCmdXML() {
- return getDictionaryString(IncludeCmdXML);
- }
-
- /**
- * Prepends the IncludeEvrXML String with the URI Name
- * @return address string
- */
- public String getIncludeEvrXML() {
- return getDictionaryString(IncludeEvrXML);
- }
-
- /**
- * Prepends the IncludeTlmXML String with the URI Name
- * @return address string
- */
- public String getIncludeTlmXML() {
- return getDictionaryString(IncludeTlmXML);
- }
-
- /**
- * Prepends the IncludeParamXML String with the URI Name
- * @return address string
- */
- public String getIncludeParamXML() {
- return getDictionaryString(IncludeParamXML);
- }
-
- /**
- * Prepends the IncludeInternalIFXML String with the URI Name
- * @return address string
- */
- public String getIncludeInternalIFXML() {
- return getDictionaryString(IncludeInternalIFXML);
- }
-
- /**
- * Prepends the IncludeIncludeHdr String with the URI Name
- * @return address string
- */
- public String getIncludeHdrFile() {
- return getDictionaryString(IncludeIncludeHdr);
- }
-
- /**
- * Get the component stereotype attribute called "Namespace"
- * @return Namespace string of the componentElement
- */
- public String getNamespace() {
- List propvals = StereotypesHelper
- .getStereotypePropertyValueAsString(componentElement,
- getStereotype(), "Namespace");
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- return "";
- }
- }
-
- /**
- * Returns last part of the componentElement name
- * @return name
- */
- public String getName() {
- return componentElement.getHumanName().split(" ")[1];
- }
-
- /**
- * Returns compStereotype
- * @return the stereotype of the object
- */
- public String getStereotype() {
- return compStereotype;
- }
-
- /**
- * Creates a list of strings based off the data type from filtList values
- * @return A list of data type strings
- */
- public List getPortDataList() {
- List dataList = new ArrayList();
- for (portObject e : filtList.values()) {
- String dataType = e.datatype;
- if (!dataList.contains(dataType)) {
- dataList.add(dataType);
- }
- }
- return dataList;
- }
-
- /**
- * Returns the property value of PortType stereotype of the input element argument.
- * @param portElement Element of the port type
- * @param property String of value to be looked for in the stereotype PortType
- * @return The value of the attribute from property
- */
- public String getPortTypeProperty(Element portElement, String property) {
- List propvals = StereotypesHelper
- .getStereotypePropertyValueAsString(portElement, "PortType", property);
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- return "";
- }
- }
-
-
- /**
- * Returns the property value of Component stereotype of the input element argument.
- * @param portElement Element of the port type
- * @param property String of value to be looked for in the stereotype Component
- * @return The value of the attribute from property
- */
- public String getComponentProperty(Element portElement, String property) {
- List propvals = StereotypesHelper
- .getStereotypePropertyValueAsString(portElement, "Component", property);
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- return "";
- }
- }
-
- /**
- * Returns the property value of async_input stereotype of the input element argument.
- * @param portElement Element of the port type
- * @param property String of value to be looked for in the stereotype async_input
- * @return The value of the attribute from property
- */
- public String getPortProperty(Element portElement, String property) {
- List propvals = StereotypesHelper
- .getStereotypePropertyValueAsString(portElement, "async_input", property);
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- return "";
- }
- }
-
- /**
- *
- */
- public void print() {
- //System.out.println(compStereotype + " " + getName());
- //Application.getInstance().getGUILog()
- // .log(compStereotype + " " + getName());
- // for (Element e : portList) {
- // System.out.println("port stereotype = " + getPortStereotype(e)
- // + ", name = " + getPortName(e) + ", datatype = "
- // + getPortDataType(e));
- // }
- }
-
- /**
- * All passive components cannot have async_input ports
- * All active components should have sync_input ports
- * All queued components should have sync and async input ports
- * @throws ComponentException
- */
- public void checkComponent() throws ComponentException {
- String compName = ((NamedElement)componentElement).getName();
- if(!isValid("passive", "async_input", false) || !isValid("Passive Component", "async_input", false) || !isValid("passive", "Async", false) || !isValid("Passive Component", "Async", false)) {
- String errStr = "Passive component " + compName + " cannot have asynchronous input ports";
- throw new ComponentException(errStr);
- }
-
- /*
- if(!isValid("active", "async_input", true)) {
- String errStr = "===>Warning: Active component " + compName + " should have at least one asynchronous input port";
- warnLog(errStr);
- }
-
-
- if(!isValid("queued", "sync_input", true)) {
- String errStr = "===>Warning: Queued component " + compName + " should have at least one synchronous input port";
- warnLog(errStr);
- }
- */
- }
-
- /**
- * Prints a warning to the Java standard out as well as the MagicDraw console.
- * @param errStr Message to be printed
- */
- public void warnLog(String errStr) {
- System.out.println(errStr);
- Application.getInstance().getGUILog().log(errStr);
- }
-
- /**
- * Checks if a component is of a specific stereotype
- * If so, checks if the component satisfies the requirement for a specific port type
- * @param stereotype the stereotype the component should have
- * @param portType the port type to check for
- * @param atLeastOne if the component should have the port type
- */
- public boolean isValid(String stereotype, String portType, boolean atLeastOne) {
- if(!StereotypesHelper.hasStereotype(componentElement, stereotype)) {
- return true;
- }
- else {
- for(String name : filtList.keySet()) {
- portObject port = filtList.get(name);
- //System.out.println("Port: " + name + ", Stereotype: " +port.stereotype);
- if(port.stereotype.equals(portType)) {
- if(atLeastOne) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- if(atLeastOne) {
- return false;
- }
- else {
- return true;
- }
- }
- }
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ISFPort.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ISFPort.java
deleted file mode 100644
index fa3fda5ed2..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ISFPort.java
+++ /dev/null
@@ -1,263 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Enumeration;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.EnumerationLiteral;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Operation;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Type;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.TypedElement;
-
-/* This class encapsulates information pertaining to the InterfaceBlock stereotype in the MD model */
-public class ISFPort {
- private Element portElement;
- private List dataList; // arguments in the Port Interface
- private Element returnVal; // Port Interface return value
- private List includeList; // List of include header files
-
- /**
- * Creates an ISFPort object
- * @param portElement Element of port type to be used in the creation of the object
- */
- public ISFPort(Element portElement) {
- this.portElement = portElement;
- dataList = new ArrayList();
- includeList = new ArrayList();
- returnVal = null;
-
- //for (Comment c : portElement.get_commentOfAnnotatedElement()) {
- //System.out.println("--- comment: " + c.getBody());
- //}
- }
-
- /**
- * Return the port element's namespace
- * @return namespace string
- */
- public String getNamespace() {
- return getPortTypeProperty(portElement, "Namespace");
- }
-
- /**
- * Adds Element to the dataList and checks to make sure the datatype is not empty before adding it to the includeList.
- * @param dataElement Element to be added
- */
- public void addData(Element dataElement) {
- this.dataList.add(dataElement);
- Type dataType = ((TypedElement) dataElement).getType();
-
- String includefile = getDataTypeProperty(dataType, "Include");
- if (!includefile.equals("")) {
- includeList.add(includefile);
- }
- }
-
- /**
- * Adds Element to the includeList if the datatype is not empty.
- * @param dataElement
- */
- public void addReturn(Element dataElement) {
- Type dataType = ((Operation) dataElement).getType();
- String includefile = getDataTypeProperty(dataType, "Include");
- if (!includefile.equals("")) {
- includeList.add(includefile);
- }
- this.returnVal = dataElement;
- }
-
- /**
- * Checks if the Element object is an instance of Enumeration.
- * @param dataElement Object to be checked
- * @return True if the Element is an instance of Enumeration
- */
- public boolean isReturnEnumeration(Element dataElement) {
- return (((Operation) dataElement).getType() instanceof Enumeration);
- }
-
- /**
- * Checks if the returnVal is null.
- * @return True if the ISFPort has a returnValue
- */
- public boolean hasReturn() {
- return (returnVal != null);
- }
-
- /**
- * Returns the returnVal.
- * @return returnVal
- */
- public Element getReturn() {
- return returnVal;
- }
-
- /**
- * Returns String based off the dataElement.
- * @param dataElement Input Element
- * @return ReturnType
- */
- public String getReturnType(Element dataElement) {
- Type dataType = ((Operation) dataElement).getType();
- String namespace = "";
-
- String namespaceProp = getDataTypeProperty(dataType, "Namespace");
- if (!namespaceProp.equals("")) {
- namespace = namespaceProp + "::";
- }
- String[] parts = dataType.getHumanName().split(" ");
- return namespace + parts[parts.length - 1];
- }
-
- /**
- * Returns the last part of the object name.
- * @return String name
- */
- public String getName() {
- String[] parts = portElement.getHumanName().split(" ");
- return parts[parts.length - 1];
- }
-
- /**
- * Checks if the dataElement is a reference or pointer and returns a list of Strings where the first value is the pass type and the second value is the name of the dataElement.
- * @param dataElement
- * @return List of Strings
- */
- public String[] getDataName(Element dataElement) {
- String[] parts = dataElement.getHumanName().split(" ");
- String retString[] = new String[2];
- String nameString = parts[parts.length - 1];
-
- // Check for the pass by Reference type modifier
- if (nameString.substring(0, 1).equals("&")) {
- retString[0] = nameString.substring(1);
- retString[1] = "reference";
- return retString;
- }
-
- // Check for the pass by Pointer type modifier
- if (nameString.substring(0, 1).equals("*")) {
- retString[0] = nameString.substring(1);
- retString[1] = "pointer";
- return retString;
- }
-
- else {
- retString[0] = nameString;
- retString[1] = "value";
- return retString;
- }
-
- }
-
- /**
- * Returns the data type with the namespace property prepended to it.
- * @param dataElement
- * @return namespace String
- */
- public String getDataType(Element dataElement) {
- Type dataType = ((TypedElement) dataElement).getType();
- String namespace = "";
-
- String namespaceProp = getDataTypeProperty(dataType, "Namespace");
- if (!namespaceProp.equals("")) {
- namespace = namespaceProp + "::";
- }
- String[] parts = dataType.getHumanName().split(" ");
- return namespace + parts[parts.length - 1];
- }
-
- /**
- * Returns the dataLIst
- * @return List of Elements
- */
- public List getDataList() {
- return dataList;
- }
-
- /**
- * Returns the includeList
- * @return List of Strings
- */
- public List getIncludeList() {
- return includeList;
- }
-
- /**
- * Returns the enumerated items of the datatype.
- * @param dataElement
- * @return List of Enumeration Literal objects
- */
- public List getEnumItems(Element dataElement) {
- return ((Enumeration) ((TypedElement) dataElement).getType())
- .getOwnedLiteral();
- }
-
- /**
- * Get enumeration items from a Port's Enumeration return type
- * @param dataElement
- * @return
- */
- public List getReturnEnumItems(Element dataElement) {
- return ((Enumeration) ((Operation) dataElement).getType())
- .getOwnedLiteral();
- }
-
- /**
- * Checks if the Type of the dataElement is an instance of Enumeration.
- * @param dataElement
- * @return boolean
- */
- public boolean isEnumeration(Element dataElement) {
- return (((TypedElement) dataElement).getType() instanceof Enumeration);
- }
-
-
- /**
- * Returns the property value of the PortType's stereotype of the input element argument.
- *
- * @param dataElement The Element in question.
- * @param property The parameter that is being accessed within the PortType stereotype
- * @return the associated value of the property in the PortType stereotype
- */
- public String getPortTypeProperty(Element dataElement, String property) {
- List propvals = StereotypesHelper
- .getStereotypePropertyValueAsString(dataElement, "PortType", property);
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- return "";
- }
- }
-
- /**
- * Returns the property value of DataType stereotype of the input element argument.
- *
- * @param dataElement The Element in question.
- * @param property The parameter that is being accessed within the DataType stereotype
- * @return the associated value of the property in the DataType stereotype
- */
- public String getDataTypeProperty(Element portElement, String property) {
- List propvals = StereotypesHelper
- .getStereotypePropertyValueAsString(portElement, "DataType", property);
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- return "";
- }
- }
-
-
- /**
- * Prints the name of the ISPort object.
- */
- public void print() {
- //Application.getInstance().getGUILog().log("Port Name: " + getName());
- System.out.println("Port Name: " + getName());
- //for (Element e : dataList) {
- // System.out.println("Data Element = " + getDataName(e)
- // + ", datatype = " + getDataType(e));
- //}
- }
-}
\ No newline at end of file
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ISFSubsystem.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ISFSubsystem.java
deleted file mode 100644
index cb28879ffd..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ISFSubsystem.java
+++ /dev/null
@@ -1,797 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-import com.nomagic.magicdraw.core.Application;
-//import com.nomagic.magicdraw.core.Application;
-import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.EnumerationLiteral;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Type;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.MultiplicityElement;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Property;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class;
-import com.nomagic.uml2.ext.magicdraw.components.mdbasiccomponents.Component;
-import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.ConnectableElement;
-import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.Connector;
-import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.ConnectorEnd;
-import com.nomagic.uml2.ext.magicdraw.compositestructures.mdports.Port;
-import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype;
-
-/**
- * Helper class for ProcessISFTopology
- *
- */
-public class ISFSubsystem {
-
- /**
- * Used as a object to store the componentMap, physicalConnectionList, name, baseID, and instanceWindow. An object of this type is then sent to IsfSubXmlWriter and is used to write to
- * the XML output file.
- *
- */
- public static class topologyModel{
- HashMap componentMap;
- ArrayList physicalConnectionList;
- String baseID;
- String instanceWindow;
- String name;
-
- public topologyModel(HashMap componentItemsMap , ArrayList physicalConnList){
- componentMap = componentItemsMap;
- physicalConnectionList = physicalConnList;
- }
-
- public HashMap getComponentMap(){
- return componentMap;
- }
-
- public ArrayList getPhysicalConnectionList(){
- return physicalConnectionList;
- }
-
- public String getBaseID(){
- return baseID;
- }
-
- public String getInstanceWindow(){
- return instanceWindow;
- }
-
- public String getName(){
- return name;
- }
-
- }
-
- /**
- * Used as a dataObject within the componentMap. The objects within this object are used to describe a leaf component. The methods are pretty self-explanatory.
- *
- */
- public static class componentType {
- String name;
- String nameSpace;
- String type;
- String baseID;
- String instanceWindow;
- String XMLLocation;
-
- public componentType(){
-
- }
-
- public String getName(){
- return name;
- }
-
- public String getNameSpace(){
- return nameSpace;
- }
-
- public String getType(){
- return type;
- }
-
- public String getBaseID(){
- return baseID;
- }
-
- public String getInstanceWindow(){
- return instanceWindow;
- }
-
- public String getXMLLocation(){
- return XMLLocation;
- }
-
- }
-
-
- /**
- * The physicalConnectionType is used to describe connections. Connector objects can not be re-defined through the API, so when we find a source port with it's final target port, we make one
- * of these objects to describe the connection. This includes the names of the ports, the type, the parent name, the multiplicities, and the actual connectorEnd.
- */
- public static class physicalConnectionType {
- String source;
- String target;
- String sourcePortName;
- String targetPortName;
- String sourcePortType;
- String targetPortType;
- String targetRoleParentName;
- String sourceRoleParentName;
- ConnectorEnd sourceEnd;
- ConnectorEnd targetEnd;
-
- Integer source_index;
- Integer target_index;
-
- public physicalConnectionType(ConnectorEnd sourceEnd , ConnectorEnd targetEnd , Integer source_index , Integer target_index) {
- this.sourceEnd = sourceEnd;
- this.targetEnd = targetEnd;
-
- Property sourcePart = sourceEnd.getPartWithPort();
- Property targetPart = targetEnd.getPartWithPort();
-
- ConnectableElement sourceRole = sourceEnd.getRole();
- ConnectableElement targetRole = targetEnd.getRole();
-
-
- this.source = sourcePart.getName();
- this.target = targetPart.getName();
- this.sourcePortName = sourceRole.getName();
- this.targetPortName = targetRole.getName();
- this.sourcePortType = sourceRole.getType().getName();
- this.targetPortType = targetRole.getType().getName();
- this.source_index = source_index;
- this.target_index = target_index;
- this.targetRoleParentName = targetPart.getObjectParent().getHumanName();
- this.sourceRoleParentName = sourcePart.getObjectParent().getHumanName();
- }
-
-
- public physicalConnectionType(ConnectorEnd sourceEnd , ConnectorEnd targetEnd , String sourceName , String targetName , Integer source_index , Integer target_index) {
- this.sourceEnd = sourceEnd;
- this.targetEnd = targetEnd;
-
- ConnectableElement sourceRole = sourceEnd.getRole();
- ConnectableElement targetRole = targetEnd.getRole();
-
- Property sourcePart = sourceEnd.getPartWithPort();
- Property targetPart = targetEnd.getPartWithPort();
-
- this.source = sourceName;
- this.target = targetName;
- this.sourcePortName = sourceRole.getName();
- this.targetPortName = targetRole.getName();
- this.sourcePortType = sourceRole.getType().getName();
- this.targetPortType = targetRole.getType().getName();
- this.source_index = source_index;
- this.target_index = target_index;
- this.targetRoleParentName = targetPart.getObjectParent().getHumanName();
- this.sourceRoleParentName = sourcePart.getObjectParent().getHumanName();
- }
-
-
-
- @Override
- public String toString() {
- return "physicalConnectionType [source=" + source + ", target=" + target + ", sourcePortName="
- + sourcePortName + ", targetPortName=" + targetPortName + ", sourcePortType=" + sourcePortType
- + ", targetPortType=" + targetPortType + ", targetRoleParentName=" + targetRoleParentName
- + ", sourceRoleParentName=" + sourceRoleParentName + ", source_index=" + source_index + ", target_index=" + target_index + "]";
- }
-
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((source == null) ? 0 : source.hashCode());
- result = prime * result + ((sourcePortName == null) ? 0 : sourcePortName.hashCode());
- result = prime * result + ((sourcePortType == null) ? 0 : sourcePortType.hashCode());
- result = prime * result + ((sourceRoleParentName == null) ? 0 : sourceRoleParentName.hashCode());
- result = prime * result + ((source_index == null) ? 0 : source_index.hashCode());
- result = prime * result + ((target == null) ? 0 : target.hashCode());
- result = prime * result + ((targetPortName == null) ? 0 : targetPortName.hashCode());
- result = prime * result + ((targetPortType == null) ? 0 : targetPortType.hashCode());
- result = prime * result + ((targetRoleParentName == null) ? 0 : targetRoleParentName.hashCode());
- result = prime * result + ((target_index == null) ? 0 : target_index.hashCode());
-
- return result;
- }
-
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- physicalConnectionType other = (physicalConnectionType) obj;
- if (source == null) {
- if (other.source != null)
- return false;
- } else if (!source.equals(other.source))
- return false;
- if (sourcePortName == null) {
- if (other.sourcePortName != null)
- return false;
- } else if (!sourcePortName.equals(other.sourcePortName))
- return false;
- if (sourcePortType == null) {
- if (other.sourcePortType != null)
- return false;
- } else if (!sourcePortType.equals(other.sourcePortType))
- return false;
- if (sourceRoleParentName == null) {
- if (other.sourceRoleParentName != null)
- return false;
- } else if (!sourceRoleParentName.equals(other.sourceRoleParentName))
- return false;
- if (source_index == null) {
- if (other.source_index != null)
- return false;
- } else if (!source_index.equals(other.source_index))
- return false;
- if (target == null) {
- if (other.target != null)
- return false;
- } else if (!target.equals(other.target))
- return false;
- if (targetPortName == null) {
- if (other.targetPortName != null)
- return false;
- } else if (!targetPortName.equals(other.targetPortName))
- return false;
- if (targetPortType == null) {
- if (other.targetPortType != null)
- return false;
- } else if (!targetPortType.equals(other.targetPortType))
- return false;
- if (targetRoleParentName == null) {
- if (other.targetRoleParentName != null)
- return false;
- } else if (!targetRoleParentName.equals(other.targetRoleParentName))
- return false;
- if (target_index == null) {
- if (other.target_index != null)
- return false;
- } else if (!target_index.equals(other.target_index))
- return false;
- return true;
- }
-
-
- public int getSourcePortIndex(){
- return source_index;
- }
-
- public int getTargetPortIndex(){
- return target_index;
- }
-
- public String getSource() {
- return source;
- }
-
- public String getTarget() {
- return target;
- }
-
- public String getSourcePortName() {
- return sourcePortName;
- }
-
- public String getTargetPortName() {
- return targetPortName;
- }
-
- public String getSourcePortType() {
- return sourcePortType;
- }
-
- public String getTargetPortType() {
- return targetPortType;
- }
- }
-
-
-
- /**
- * Creates and returns new componentType
- *
- *
- * @param name Component name
- * @param nameSpace Component name space
- * @param type Component Type
- * @param baseID Base ID
- * @param instanceWindow Instance Window ID
- * @return componentType
- */
- public static componentType createComponent(String name , String nameSpace , String type, String baseID , String instanceWindow , String xmlPath){
- componentType out = new componentType();
- out.name = name;
- out.nameSpace = nameSpace;
- out.type = type;
- out.baseID = baseID;
- out.instanceWindow = instanceWindow;
- out.XMLLocation = xmlPath;
- return(out);
- }
-
-
- /**
- * Returns the multiplicity of the source end of the connector.
- *
- * @param conn Connector
- * @return multiplicity
- * @throws ConnectorException
- */
- public static int getSourceIndex(Connector conn) throws ConnectorException {
- if (getSourceConnEnd(conn).getLowerValue() == null) {
- return 0;
- }
- return ((MultiplicityElement) getSourceConnEnd(conn)).getLower();
- }
-
- /**
- * Returns the multiplicity of the target end of the connector.
- *
- * @param conn Connector
- * @return multiplicity
- * @throws ConnectorException
- */
- public static int getTargetIndex(Connector conn) throws ConnectorException {
- if (getTargetConnEnd(conn).getLowerValue() == null) {
- return 0;
- }
- return ((MultiplicityElement) getTargetConnEnd(conn)).getLower();
- }
-
-
-
-
- public static void print() {
- System.out
- .println("--------------------------------------------------");
- System.out.println("---Topology Status:");
- System.out
- .println("--------------------------------------------------");
- // printComponents();
- // printPhysicalConnections();
- System.out
- .println("--------------------------------------------------");
- }
-
-
- public static String getFileLocation(Element instanceElement){
- Class ie = (Class) instanceElement;
- String url = "";
- try{
- url = ie.getOwningPackage().getURI() + "/"; // + ie.getName();
- }
- catch(Exception e){
- url = ie.getName();
- }
-
- return(url);
- }
-
-
-
- /**
- * Returns the base ID of the element.
- *
- * @param instanceElement
- * @return
- */
- public static String getBaseId(Element instanceElement){
- List propvals = StereotypesHelper.getStereotypePropertyValueAsString(instanceElement,"ComponentInstance", "BaseID");
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- return "";
- }
- }
-
- /**
- * Returns the instance window of the element.
- *
- * @param instanceElement
- * @return
- */
- public static String getInstanceWindow(Element instanceElement){
- List propvals = StereotypesHelper.getStereotypePropertyValueAsString(instanceElement,"ComponentInstance", "Window");
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- return "";
- }
- }
-
- /**
- * Returns the source name off the attached component.
- *
- * @param c Connector
- * @return Component Name
- * @throws ConnectorException Will raise an exception if the target component does not exist (IE the source is connected to the outside of the subsystem)
- */
- public static String getSourceComp(Connector c) throws ConnectorException {
- if (getSourceConnEnd(c).getPartWithPort() == null) {
- throw new ConnectorException(getSourceConnEnd(c).getRole()
- .getQualifiedName() + " Connection has no source component");
- }
- return getCompName(getSourceConnEnd(c));
- }
-
- /**
- * Returns the target name off the attached component.
- *
- * @param c Connector
- * @return Component Name
- * @throws ConnectorException Will raise an exception if the target component does not exist (IE the target is connected to the outside of the subsystem)
- */
- public static String getTargetComp(Connector c) throws ConnectorException {
- if (getTargetConnEnd(c).getPartWithPort() == null) {
- throw new ConnectorException(getTargetConnEnd(c).getRole()
- .getQualifiedName() + " Connection has no target component");
- }
- return getCompName(getTargetConnEnd(c));
- }
-
- /**
- * Returns the component name of the connectorEnd.
- * @param conn
- * @return
- * @throws ConnectorException
- */
- public static String getCompName(ConnectorEnd conn) throws ConnectorException {
- String parts[] = conn.getPartWithPort().getHumanName().split(" ");
- return parts[parts.length - 1];
- }
-
-
- /**
- * Returns the generic ID of the source port on this Connector.
- *
- * This ID is not unique among different instances of the same module.
- * @param c Connector
- * @return ID String
- * @throws ConnectorException
- */
- public static String getIDSourcePort(Connector c) throws ConnectorException {
- return getSourceConnEnd(c).getRole().getID();
- }
-
- /**
- * Returns the generic ID of the target port on this Connector.
- *
- * This ID is not unique among different instances of the same module.
- * @param c Connector
- * @return ID String
- * @throws ConnectorException
- */
- public static String getIDTargetPort(Connector c) throws ConnectorException {
- return getTargetConnEnd(c).getRole().getID();
- }
-
- /**
- * Returns the generic name of source port on this Connector.
- *
- * @param c Connector
- * @return Name
- * @throws ConnectorException
- */
- public static String getSourcePort(Connector c) throws ConnectorException {
- return getPortName(getSourceConnEnd(c));
- }
-
- /**
- * Returns the generic name of target port on this Connector.
- *
- * @param c Connector
- * @return Name
- * @throws ConnectorException
- */
- public static String getTargetPort(Connector c) throws ConnectorException {
- return getPortName(getTargetConnEnd(c));
- }
-
- /**
- * Returns the generic name of the role of the ConnectorEnd.
- *
- * @param conn ConnectorEnd
- * @return Name
- * @throws ConnectorException
- */
- public static String getPortName(ConnectorEnd conn) throws ConnectorException {
- String[] splitString = conn.getRole().getHumanName().split(" ");
- return splitString[splitString.length - 1];
- }
-
- /**
- * Splits the in string with ' ' and returns the last values in the array.
- *
- * @param in
- * @return
- */
- public static String getLastPartOfString(String in){
- String[] splitString = in.split(" ");
- return splitString[splitString.length - 1];
- }
-
- /**
- * Returns a string with the qualified name of the base port it is attached to, along with the qualified name of the instance of the port (if it exists).
- *
- * This can be used to uniquely identify a port against other ports in a subsystem.
- *
- * @param connEnd ConnectorEnd
- * @return String of the combined qualified name.
- */
- public static String getQualifiedPort(ConnectorEnd connEnd) {
- String role = connEnd.getRole().getQualifiedName();
- String part = "";
- if (!connEnd.getRole().getObjectParent().getHumanType().equals("Subsystem")){
- part = connEnd.getPartWithPort().getQualifiedName();
- }
- return role+"_"+part;
- }
-
-
- /**
- * Returns the qualified name of the source port from the connector.
- *
- * The qualified name describes the port by providing the port's name, the module it is attached to, and the location of the module.
- *
- * @param c Connector
- * @return String qualified name
- * @throws ConnectorException
- */
- public static String getQualifiedSourcePort(Connector c) throws ConnectorException {
- ConnectorEnd connEnd = getSourceConnEnd(c);
- return getQualifiedPort(connEnd);
- }
-
- /**
- * Returns the qualified name of the target port from the connector.
- *
- * The qualified name describes the port by providing the port's name, the module it is attached to, and the location of the module.
- *
- * @param c Connector
- * @return String qualified name
- * @throws ConnectorException
- */
- public static String getQualifiedTargetPort(Connector c) throws ConnectorException {
- ConnectorEnd connEnd = getTargetConnEnd(c);
- return getQualifiedPort(connEnd);
- }
-
- /**
- * Returns the source port type from the Connector.
- *
- * @param c Connector
- * @return Port Type
- * @throws ConnectorException
- */
- public static String getSourcePortType(Connector c) throws ConnectorException {
- Type portType = getSourceConnEnd(c).getRole().getType();
- if (portType != null) {
- String typeString[] = portType.getHumanName().split(" ");
- return typeString[typeString.length - 1];
- } else {
- return "";
- }
- }
-
- /**
- * Returns the target port type from the Connector.
- *
- * @param c Connector
- * @return Port Type
- * @throws ConnectorException
- */
- public static String getTargetPortType(Connector c) throws ConnectorException {
- Type portType = getTargetConnEnd(c).getRole().getType();
- if (portType != null) {
- String typeString[] = portType.getHumanName().split(" ");
- return typeString[typeString.length - 1];
- } else {
- return "";
- }
- }
-
- /**
- * Checks the connectorEnd roles to match the returned value with the input (source) connector end.
- *
- * This function does not check to see if both ConnectorEnds are different or have the same input/output types.
- *
- *
- * @param c Connector
- * @return Source ConnectorEnd
- */
- public static ConnectorEnd getSourceConnEnd(Connector c) throws ConnectorException {
- return(getConnEnd(c , true));
- }
-
- /**
- * Checks the connectorEnd roles to match the returned value with the output (target) connector end.
- *
- * This function does not check to see if both ConnectorEnds are different or have the same input/output types.
- *
- *
- * @param c Connector
- * @return Target ConnectorEnd
- */
- // Get the target end of a Connector
- public static ConnectorEnd getTargetConnEnd(Connector c) throws ConnectorException{
- return(getConnEnd(c , false));
- }
-
- /**
- * Both getSourceConnEnd and getTargetConnEnd use this function. Incorporates error handling/checking.
- *
- * The function checks the direction property of the first stereotype found in each port of the connector.
- * Depending on what the connector can see within and around the system, the function will return what it sees as the source and what is sees as the target.
- *
- * @param c Connector
- * @param isSource true if looking for source end, false if looking for target end
- * @return Connector End
- * @throws ConnectorException
- */
- public static ConnectorEnd getConnEnd(Connector c , boolean isSource) throws ConnectorException {
- // getEnd returns 2 ConnectorEnd's: the first is the source, the second
- // the target end.
- ConnectorEnd out = null;
- int outCount = 0;
- int inCount = 0;
-
- int a = 0;
- int b = 1;
-
- if(!isSource){
- a = 1;
- b = 0;
- }
-
- //Iterate through both ports
- for(int i = 0; i != 2; i++){
- Port tempPort = null;
- //try casting the role into a Port. If it fails, the role doesn't not exist.
- try{
- tempPort = (Port) c.getEnd().get(i).getRole();
- }
- catch(Exception e){
- Utils.throwConnectorException("Connector " + c.getName() + " in " + c.getObjectParent().getHumanName() + " has an end with a null role.");
- }
-
- if(tempPort == null){
- Utils.throwConnectorException("Connector " + c.getName() + " in " + c.getObjectParent().getHumanName() + " has an end with no role.");
- }
-
- //If the direction stereotype property is out
- try{
- if(((EnumerationLiteral) StereotypesHelper.getStereotypePropertyFirst(tempPort, StereotypesHelper.getFirstVisibleStereotype(tempPort) , "direction")).getName().equals("out")){
- outCount++;
- if(isSource){
- out = c.getEnd().get(i);
- }
-
- }
- //If the direction stereotype property is in
- else if(((EnumerationLiteral) StereotypesHelper.getStereotypePropertyFirst(tempPort, StereotypesHelper.getFirstVisibleStereotype(tempPort) , "direction")).getName().equals("in")){
- inCount++;
- if(!isSource){
- out = c.getEnd().get(i);
- }
- }
- else{
- Utils.throwConnectorException("Connector " + c.getName() + " in " + c.getObjectParent().getHumanName() + " has end " + tempPort.getQualifiedName() + " with a non input/output stereotype " + StereotypesHelper.getFirstVisibleStereotype(tempPort) .getName()); //StereotypesHelper.findStereotypePropertyFor(tempPort , "direction").getDefaultValue().toString() + ".");
- }
- }
- catch(Exception e){
- Utils.throwConnectorException("Port in " + c.getObjectParent().getHumanName() + " does not have direction. (The connector end does not have a stereotype with a direction value)");
- }
- }
-
- Property partWithPortZero = c.getEnd().get(0).getPartWithPort();
- Property partWithPortOne = c.getEnd().get(1).getPartWithPort();
-
- //If zero connected to the outside of the system
- if(partWithPortZero == null && partWithPortOne != null){
- //If both ports are input, the real source is coming from the outside of the system
- if(inCount == 2){
- out = c.getEnd().get(a);
- }
- //If both ports are outputs, the real source is coming from inside the system
- else if(outCount == 2){
- out = c.getEnd().get(b);
- }
-
- }
- //If one connected to the outside of the system
- else if(partWithPortZero != null && partWithPortOne == null){
- //If both ports are input, the real source is coming from the outside of the system
- if(inCount == 2){
- out = c.getEnd().get(b);
- }
- //If both ports are outputs, the real source is coming from inside the system
- else if(outCount == 2){
- out = c.getEnd().get(a);
- }
-
- }
- //If both have parts have the same "null value"
- else if(partWithPortZero == null && partWithPortOne == null || partWithPortZero != null && partWithPortOne != null){
- if(inCount == 2){
- Utils.throwConnectorException("Connector " + c.getName() + " in Subsystem " + c.getObjectParent().getHumanName() + " has two input ports connected (invalid).");
- }
- else if(outCount == 2){
- Utils.throwConnectorException("Connector " + c.getName() + " in Subsystem " + c.getObjectParent().getHumanName() + " has two output ports connected (invalid).");
- }
- }
-
- if(out == null){
- String errorMessage = "Connector " + c.getName() + " in Subsystem " + c.getObjectParent().getHumanName() + " with ends " + c.getEnd().get(0).getRole().getQualifiedName() + " and " + c.getEnd().get(1).getRole().getQualifiedName() + " does not have ";
- if(inCount == 0){
- errorMessage += "input ";
- }
- if(outCount == 0){
- errorMessage += "output ";
- }
- Utils.throwConnectorException(errorMessage + "stereotypes.");
- }
- return out;
-
- }
-
- /**
- * Returns a list of elements with the given stereotype String.
- *
- * @param stereotype String
- * @return List of Objects
- */
- public static List getElementsOfStereotype(String stereotype) {
- Stereotype st;
- List elementList = new ArrayList();
- st = StereotypesHelper.getStereotype(Application.getInstance().getProject(), stereotype);
- if (st != null) {
- elementList = Arrays.asList(StereotypesHelper.getExtendedElementsIncludingDerived(st).toArray(new Element[0])); //.getExtendedElements(st);
- }
- return elementList;
- }
-
- /**
- * Returns the name space of the element.
- *
- * @param componentElement
- * @return
- */
- public static String getNamespace(Element componentElement) {
- List propvals;
- propvals = StereotypesHelper.getStereotypePropertyValueAsString(
- componentElement, "active", "Namespace");
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- propvals = StereotypesHelper.getStereotypePropertyValueAsString(
- componentElement, "passive", "Namespace");
- if (propvals.size() > 0) {
- return propvals.get(0);
- } else {
- propvals = StereotypesHelper
- .getStereotypePropertyValueAsString(componentElement,
- "queued", "Namespace");
- if (propvals.size() > 0) {
- return propvals.get(0);
- }
- }
- }
- return "";
- }
-
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfAbout.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfAbout.java
deleted file mode 100644
index e377f61dd9..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfAbout.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import com.nomagic.magicdraw.actions.MDAction;
-import com.nomagic.magicdraw.core.Application;
-/**
- * Action class for information regarding the plugin
- */
-public class IsfAbout extends MDAction {
- File pluginDir;
- private static final long serialVersionUID = -6790954285526957354L;
-
- public IsfAbout(String id, String name, File pluginDir)
- {
- super(id, name, null, null);
- this.pluginDir = pluginDir;
- }
-
- /**
- * Used to display content in the "About" tab. Edit this for tab changes.
- */
- public void actionPerformed(ActionEvent e)
- {
- try {
- JarFile jf = new JarFile(pluginDir + "/FpCompAuto.jar");
- ZipEntry manifest = jf.getEntry("META-INF/MANIFEST.MF");
- long manifestTime = manifest.getTime();
- Date testDate = new Date(manifestTime);
-
- File xmlFile = new File(pluginDir + "/plugin.xml");
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(xmlFile);
- doc.getDocumentElement().normalize();
-
- NodeList nList = doc.getElementsByTagName("plugin");
- Node node = nList.item(0);
- Element el = (Element)node;
-
- String name = el.getAttribute("name");
- String provider = el.getAttribute("provider-name");
- String version = el.getAttribute("version");
- String date = testDate.toString();
- String copyright = "Copyright: 2016 California Institute of Technology. All rights reserved.";
-
- jf.close();
-
- Application.getInstance().getGUILog().showMessage(name
- + "\n" + provider
- + "\nVersion " + version
- + "\nPlugin Generation Date: " + date
- + "\n" + copyright);
- } catch(IOException io) {
- Application.getInstance().getGUILog().showMessage(io.getMessage());
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
-
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfCommandLine.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfCommandLine.java
deleted file mode 100644
index 30c35c7076..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfCommandLine.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.cli.DefaultParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-
-import com.nomagic.magicdraw.commandline.CommandLine;
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.magicdraw.core.Project;
-import com.nomagic.magicdraw.core.project.ProjectDescriptorsFactory;
-
-/**
- * Class to run MagicDraw plugin from command line
- *
- * Before running on headless environment, use Xvfb to set up a virtual X11 display server
- * /usr/bin/Xvfb :1 -screen 0 1024x768x24
- * export DISPLAY=:1
- *
- * To run the utility, use the script isfpluginexec.sh in the MagicDrawCompPlugin directory
- */
-public class IsfCommandLine extends CommandLine
-{
- static File pluginDir;
- static String projectFile;
- private static final String PROJECT = "project_name";
- private static final String PACKAGE = "package";
- //private static final String USAGE = "java -cp -Dinstall.root= -Xmx900M -Xss2M -XX:PermSize=40M -XX:MaxPermSize=150M gov.nasa.jpl.componentaction.IsfCommandLine [options]";
- private static final String USAGE = "isfpluginexec [options]\nBefore running on headless environment, use Xvfb to set up a virtual X11 display server\n/usr/bin/Xvfb :1 -screen 0 1024x768x24\nexport DISPLAY=:1";
- private static final String COPYRIGHT = "Copyright 2015 (California Institute of Technology)\nALL RIGHTS RESERVED. U.S. Government Sponsorship acknowledged.";
- /**
- * Reads the command line arguments and launches the program
- *
- * @param args application arguments.
- */
- public static void main(String[] args) {
- try {
- Options opt = new Options();
- opt.addOption("h", false, "Print help for this plugin");
- opt.addOption(PROJECT, true, "The project to process");
- opt.addOption(PACKAGE, true, "The package to generate the xml for");
- opt.addOption("verbose", false, "Run project in verbose mode");
- DefaultParser parser = new DefaultParser();
- org.apache.commons.cli.CommandLine cl = null;
- cl = parser.parse(opt, args);
- if(cl.hasOption("h")) {
- HelpFormatter f = new HelpFormatter();
- f.printHelp(100, USAGE, COPYRIGHT, opt , "");
- System.exit(0);
- } else {
- if(cl.hasOption(PROJECT)) {
- System.setProperty(PROJECT, cl.getOptionValue(PROJECT));
- } else {
- System.out.println("No project specified!");
- HelpFormatter f = new HelpFormatter();
- f.printHelp(100, USAGE, COPYRIGHT, opt , "");
- System.exit(1);
- }
- if(cl.hasOption(PACKAGE)) {
- System.setProperty(PACKAGE, cl.getOptionValue(PACKAGE));
- }
- }
- } catch (ParseException e) {
- e.printStackTrace();
- }
- projectFile = System.getProperty(PROJECT, "");
- if (projectFile.length() == 0)
- {
- System.out.println("Project file not defined!");
- return;
- }
-
- System.out.println("launching");
- new IsfCommandLine().launch(args);
- }
-
- /**
- * Runs autocoder on the project specified
- */
- @Override
- protected byte execute() {
- System.out.println("executing");
- Application application = Application.getInstance();
- pluginDir = new File(System.getenv("BUILD_ROOT") + "/Autocoders/MagicDrawCompPlugin/");
- application.getProjectsManager()
- .loadProject(ProjectDescriptorsFactory.createProjectDescriptor(new File(projectFile).toURI()), true);
- Project project = application.getProject();
-
- String processPackage = System.getProperty(PACKAGE);
-
- try {
- if(processPackage!=null) {
- ProcessISFProject.process(project, pluginDir, processPackage);
- }
- else {
- ProcessISFProject.process(project, pluginDir);
- }
- System.out.println("*** Completed Component/Port Processing");
- ProcessISFTopology.process(project, pluginDir);
- System.out.println("*** Completed Topology processing");
- } catch (IOException e1) {
- e1.printStackTrace();
- System.out.println("**** " + e1.getMessage());
- } catch(RuntimeException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- return 0;
- }
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfComponentAction.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfComponentAction.java
deleted file mode 100644
index e8cea17b75..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfComponentAction.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.IOException;
-
-import com.nomagic.magicdraw.actions.MDAction;
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.magicdraw.core.Project;
-
-/**
- * Used to only generate Component and Port XML diagrams.
- *
- */
-public class IsfComponentAction extends MDAction {
- File pluginDir;
- /**
- *
- */
- private static final long serialVersionUID = -6790954285526957354L;
-
- public IsfComponentAction(String id, String name, File pluginDir) {
- super(id, name, null, null);
- this.pluginDir = pluginDir;
- }
-
- /**
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
- */
- public void actionPerformed(ActionEvent e) {
-
- Project project = Application.getInstance().getProject();
- try {
- ProcessISFProject.process(project, pluginDir);
- System.out.println("*** Completed Component/Port Processing");
- System.out.println("*** Processing Complete!");
- } catch (IOException e1) {
- e1.printStackTrace();
- System.out.println("**** " + e1.getMessage());
- System.err.flush();
- }
- //System.err.flush();
-
- }
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfTopAction.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfTopAction.java
deleted file mode 100644
index d15292ac5a..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfTopAction.java
+++ /dev/null
@@ -1,51 +0,0 @@
-
-package gov.nasa.jpl.componentaction;
-
-
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.IOException;
-import com.nomagic.magicdraw.actions.MDAction;
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.magicdraw.core.Project;
-
-/**
- *
- * Used to generate only the topology XML diagrams.
- *
- */
-public class IsfTopAction extends MDAction {
- File pluginDir;
-
- /**
- *
- */
- private static final long serialVersionUID = -6790954285526957354L;
- public IsfTopAction(String id, String name, File pluginDir)
- {
- super(id, name, null, null);
- this.pluginDir = pluginDir;
- }
-
- /**
- * Runs the ProcessISFProject.process function.
- *
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
- */
- public void actionPerformed(ActionEvent e)
- {
- Project project = Application.getInstance().getProject();
- try {
- ProcessISFTopology.process(project, pluginDir);
- System.out.println("** Completed Topology processing");
- System.out.println("*** Processing Complete!");
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- System.out.println("**** " + e1.getMessage());
- System.err.flush();
- }
- //System.err.flush();
-
- }
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfXmlAction.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfXmlAction.java
deleted file mode 100644
index 50921f42ca..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfXmlAction.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.IOException;
-import com.nomagic.magicdraw.actions.MDAction;
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.magicdraw.core.Project;
-
-/**
- * Used to generate component, port, and topology XML files.
- *
- */
-public class IsfXmlAction extends MDAction {
- File pluginDir;
-
- /**
- *
- */
- private static final long serialVersionUID = -6790954285526957354L;
- public IsfXmlAction(String id, String name, File pluginDir)
- {
- super(id, name, null, null);
- this.pluginDir = pluginDir;
- }
-
- /**
- * Runs the ProcessISFProject.process and the ProcessISFTopology.process functions.
- *
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
- */
- public void actionPerformed(ActionEvent e)
- {
- Project project = Application.getInstance().getProject();
- try {
- ProcessISFProject.process(project, pluginDir);
- System.out.println("*** Completed Component/Port Processing");
- ProcessISFTopology.process(project, pluginDir);
- System.out.println("** Completed Topology processing");
- System.out.println("*** Processing Complete!");
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- System.out.println("**** " + e1.getMessage());
- System.err.flush();
- }
- //System.err.flush();
-
- }
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfXmlAutocoderAction.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfXmlAutocoderAction.java
deleted file mode 100644
index 4b6e957df3..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/IsfXmlAutocoderAction.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * $Id: ActionTypesExample.java 52410 2007-10-05 06:51:43Z donsim $
- *
- * Copyright (c) 2002 NoMagic, Inc. All Rights Reserved.
- */
-package gov.nasa.jpl.componentaction;
-
-import com.nomagic.actions.ActionsCategory;
-import com.nomagic.actions.NMAction;
-import com.nomagic.magicdraw.actions.ActionsConfiguratorsManager;
-import com.nomagic.magicdraw.plugins.Plugin;
-
-/**
- * Used to create generation/about tabs within MagicDraw. Buttons are attached to different action object.
- *
- */
-public class IsfXmlAutocoderAction extends Plugin
-{
-
- /**
- * @see com.nomagic.magicdraw.plugins.Plugin#init()
- */
- public void init()
- {
- //System.out.println("My Plugin\n");
- //javax.swing.JOptionPane.showMessageDialog(null, "My Plugin init");
-
- ActionsConfiguratorsManager manager = ActionsConfiguratorsManager.getInstance();
- manager.addMainMenuConfigurator(new MainMenuConfigurator(getSeparatedActions()));
-
- }
-
- /**
- * @see com.nomagic.magicdraw.plugins.Plugin#close()
- */
- public boolean close()
- {
- return true;
- }
-
- /**
- * @see com.nomagic.magicdraw.plugins.Plugin#isSupported()
- */
- public boolean isSupported()
- {
- return true;
- }
-
- /**
- * Creates group of actions. This group is separated from others using menu separator (when it represented in menu).
- * Separator is added for group of actions in one actions category.
- */
- private NMAction getSeparatedActions()
- {
- ActionsCategory category = new ActionsCategory(null, null);
- category.addAction(new IsfXmlAction(null,"Auto Generate Component/Port/Topology XML", this.getDescriptor().getPluginDirectory()));
- category.addAction(new IsfComponentAction(null,"Component and Port Only XML", this.getDescriptor().getPluginDirectory()));
- category.addAction(new IsfTopAction(null,"Topology Only XML", this.getDescriptor().getPluginDirectory()));
- category.addAction(new LoadIDConfigAction(null,"Load Base ID/Window ID Config CSV", this.getDescriptor().getPluginDirectory()));
- category.addAction(new IsfAbout(null,"About", this.getDescriptor().getPluginDirectory()));
- return category;
- }
-
-}
-
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDConfig.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDConfig.java
deleted file mode 100644
index 1ab486a1c5..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDConfig.java
+++ /dev/null
@@ -1,364 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.swing.JFileChooser;
-
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.magicdraw.core.Project;
-import com.nomagic.uml2.ext.jmi.helpers.ModelHelper;
-import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Property;
-import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype;
-
-/**
- *
- * LoadIDConfig allows the user to specify a config CSV that will modify all the baseIDs and window ranges within the model.
- * This allows users to have isfgen generate IDs and use them in the future by adding them into the models.
- *
- * Exceptions are generated when anything does not conform to what is expected, including file types, file column amounts, and mismatches between the config file and the model.
- *
- *
- *
- * The format of the config file is so:
- *
- * component,instance,base_id,base_window_range
- *
- * SignalGen,SG1,10,15
- *
- * ...
- *
- *
- */
-public class LoadIDConfig {
- private static Project project;
-
- /**
- * Used to store information for each configuration item from the config file.
- *
- */
- public static class configItem{
-
- String componentType;
- String instanceName;
- int baseID;
- int windowRange;
-
- public configItem(String compType , String instName , int bID , int wRange){
- componentType = compType;
- instanceName = instName;
- baseID = bID;
- windowRange = wRange;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + baseID;
- result = prime * result + ((componentType == null) ? 0 : componentType.hashCode());
- result = prime * result + ((instanceName == null) ? 0 : instanceName.hashCode());
- result = prime * result + windowRange;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- configItem other = (configItem) obj;
- if (baseID != other.baseID)
- return false;
- if (componentType == null) {
- if (other.componentType != null)
- return false;
- } else if (!componentType.equals(other.componentType))
- return false;
- if (instanceName == null) {
- if (other.instanceName != null)
- return false;
- } else if (!instanceName.equals(other.instanceName))
- return false;
- if (windowRange != other.windowRange)
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "configItem [componentType=" + componentType + ", instanceName=" + instanceName + ", baseID="
- + baseID + ", windowRange=" + windowRange + "]";
- }
-
- }
-
- private LoadIDConfig() { }
-
- /**
- * process handles all the phases of this methodology.
- *
- * @param proj Project object
- * @param pluginDir Directory to generate documents into
- * @throws IOException
- */
- public static void process(Project proj, File pluginDir) throws IOException {
- project = proj;
-
- String fileName = null;
-
- try {
- if (project == null) {
- Utils.printToAll("***No model found");
- }
- else {
- Utils.printToAll("Project Name = " + project.getName());
- File projectFile = new File(project.getFileName());
-
- //Phase One: Creating dialog box to retrieve input ID config file
-
- File configFile = getConfigFile(projectFile);
-
- //Phase Two: Validate and process the configFile
-
- Map configMap = validateAndProcessConfig(configFile);
-
- //Phase Three: Parse model and make changes to objects
-
- Element root = project.getModel();
- changeModel(root , proj , configMap);
-
-
- }
-
- }
- catch (LoadIDException e) {
- Application.getInstance().getGUILog()
- .log("===> FATAL Exception: " + e.getMessage() + "");
- throw new RuntimeException(e.getMessage());
- }
-
- }
-
- /**
- * This function goes through the model and matches each component with its respective instance within the configMap.
- *
- * If there isn't any discrepancies between the model and the config files, baseIDs and window ranges are set to the values from the config file.
- *
- * All subsystems have their base IDs set to zero.
- *
- * @param root
- * @param proj
- * @param configMap
- * @throws LoadIDException
- */
- public static void changeModel(Element root , Project proj , Map configMap) throws LoadIDException{
- Collection collection = (Collection)ModelHelper.getElementsOfType(root, null, true, true);
- ArrayList componentList = new ArrayList();
- Stereotype componentInstanceStereotype = StereotypesHelper.getStereotype(proj, "ComponentInstance");
-
- //Make set of all instance names. This will be used to see if all instances are used
- Set instanceNames = new HashSet();
- for(String key : configMap.keySet()){
- instanceNames.add(key);
- }
-
- //Iterate through all the elements in the model
- for(Element el : collection) {
- if(el instanceof NamedElement) {
- NamedElement elNamed = (NamedElement) el;
- if (el.getHumanType().equals("Part Property") || el.getHumanType().equals("Reference Property") ){
- Property elProp = (Property) el;
- //If the element is a component set both window and base ID
- if(elProp.getType() == null){
- throw new LoadIDException("Component " + elNamed.getName() + " is found in the SysML model and is of type " + el.getHumanType() + " but doesn't have an explicit type object.");
- }
- else if(elProp.getType().getHumanType() == null){
- //throw new LoadIDException("Component " + elNamed.getName() + " is found in the SysML model and is of type " + el.getHumanType() + " but doesn't have a human type of the type.");
- }
- else if(!elProp.getType().getHumanType().equalsIgnoreCase("Subsystem")){
- if(configMap.containsKey(elNamed.getName())){
- componentList.add(el);
- instanceNames.remove(elNamed.getName());
- }
- else{
- //throw new LoadIDException("Component " + elNamed.getName() + " is found in the SysML model but not the config file. Make sure the config file matches with this model.");
- }
- }
- }
- //If the element is a subsystem, set the base ID to zero
- else if (el.getHumanType().equals("Subsystem")) {
- StereotypesHelper.setStereotypePropertyValue(el , componentInstanceStereotype, "BaseID" , 0);
- }
- }
- }
-
- if(instanceNames.size() > 0){
- boolean first = true;
- String errorString = "";
- for(String s : instanceNames){
- if(!first){
- errorString += ',';
- }
- else{
- first = false;
- }
- errorString += s;
- }
- throw new LoadIDException("Components " + errorString + " are found in the config file but not in the SysML model. Make sure the config file matches with this model." );
- }
-
- //Set base IDs of subsystems to zero. This wasn't done in the earlier loop to ensure the model and files are valid before any changes are made
- for(Element el : collection) {
- if(el instanceof NamedElement) {
- if (el.getHumanType().equals("Subsystem")) {
- StereotypesHelper.setStereotypePropertyValue(el , componentInstanceStereotype, "BaseID" , 0);
- }
- }
- }
-
- //Change base IDs and Window sizes for all the elements
- for(Element el : componentList){
- NamedElement elNamed = (NamedElement) el;
-
- //Check if current component had previous values assigned to the base ID and window id stereotype values. If so, a override warning message is printed to the console
- Object baseIdObject = StereotypesHelper.getStereotypePropertyFirst(el, componentInstanceStereotype, "BaseID");
- Object windowRangeObject = StereotypesHelper.getStereotypePropertyFirst(el, componentInstanceStereotype, "Window");
- if(baseIdObject != null){
- if(! baseIdObject.toString().equals(((Integer) configMap.get(elNamed.getName()).baseID).toString()) ){
- Utils.printToAll("ValueOverrideWarning: Base ID for component " + elNamed.getName() + " was previously set to " + baseIdObject.toString() + " is being changed to " + ((Integer) configMap.get(elNamed.getName()).baseID).toString() + ".");
- }
- }
- if(windowRangeObject != null){
- if(! windowRangeObject.toString().equals(((Integer) configMap.get(elNamed.getName()).windowRange).toString()) ){
- Utils.printToAll("ValueOverrideWarning: Window range for component " + elNamed.getName() + " was previously set to " + windowRangeObject.toString() + " is being changed to " + ((Integer) configMap.get(elNamed.getName()).windowRange).toString() + ".");
- }
- }
- StereotypesHelper.setStereotypePropertyValue(el , componentInstanceStereotype, "BaseID" , configMap.get(elNamed.getName()).baseID);
- StereotypesHelper.setStereotypePropertyValue(el , componentInstanceStereotype, "Window" , configMap.get(elNamed.getName()).windowRange);
- }
-
- }
-
-
- /**
- * Validates and processes the input config file.
- *
- * Checks if the file is valid, is a .CSV, and has four items per row.
- *
- * This also constructs a map where the key is an instance name and the value is a configItem that holds the associated names and IDs.
- *
- * @param config
- * @return
- * @throws LoadIDException
- */
- public static Map validateAndProcessConfig(File config) throws LoadIDException{
- Map configMap = new HashMap();
- String path = config.getAbsolutePath();
-
- //Validate File name
- //Check if valid file
- if(!config.isFile()){
- throw new LoadIDException("Chosen item " + path + " is not a file.");
- }
- //Check if readable
- if(!config.canRead()){
- throw new LoadIDException("Chosen file " + path + " is not readable.");
- }
- //Check if is a .csv file
- if(path.length() < 5){
- throw new LoadIDException("Chosen file " + path + " is not of type CSV.");
- }
- if(!path.substring(path.length() - 4 , path.length()).equalsIgnoreCase(".csv")){
- throw new LoadIDException("Chosen file " + path + " is not of type CSV.");
- }
-
- //Process and validate file contents
-
- try{
- BufferedReader configRead = new BufferedReader(new FileReader(config));
- String line;
- int lineNumber = 0;
- while((line = configRead.readLine()) != null){
- String[] splitLine = line.split(",");
- //Check if each line has four items
- if(splitLine.length != 4){
- throw new LoadIDException("Chosen file " + path + " has line " + line + " that does not only have four items.");
- }
- String compType = splitLine[0];
- String instanceName = splitLine[1];
- Integer baseID = null;
- Integer windowRange = null;
-
- //Checks if the base ID / window range can be parsed to an integer
- try{
- baseID = Integer.parseInt(splitLine[2]);
- windowRange = Integer.parseInt(splitLine[3]);
- }
- catch(Exception e){
- if(lineNumber > 0){
- Utils.notifyWarning("Line number " + lineNumber + " in file " + path + " has items in columns three and/or four that cannot be parsed to an integer.");
- }
- }
-
-
- //If all the config items are found and valid, add it to the dictionary
- if(baseID != null && windowRange != null){
- configItem newItem = new configItem(compType, instanceName, baseID, windowRange);
-
- //Check if instance name is in the map already
- if(configMap.containsKey(instanceName)){
- throw new LoadIDException("Instance of name " + instanceName + " has been found multiple times in the config file. Please make sure that instance names do not repeat.");
- }
-
- configMap.put(instanceName, newItem);
- }
-
- lineNumber++;
- }
- }
- catch(Exception e){
- throw new LoadIDException(e.getMessage());
- }
-
- return configMap;
- }
-
- /**
- * Opens up a file chooser box for the user to select what config CSV file to choose.
- *
- * The input argument projectFile is used to specify a starting path.
- *
- * @param projectFile
- * @return A config file object
- * @throws LoadIDException
- */
- public static File getConfigFile(File projectFile) throws LoadIDException{
- File outFile;
- JFileChooser configChooser = new JFileChooser();
- configChooser.setCurrentDirectory(projectFile);
- int result = configChooser.showOpenDialog(null);
- if(result == JFileChooser.APPROVE_OPTION){
- outFile = configChooser.getSelectedFile();
- }
- else{
- throw new LoadIDException("No file was selected!");
- }
- return(outFile);
- }
-
-}
\ No newline at end of file
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDConfigAction.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDConfigAction.java
deleted file mode 100644
index b521092493..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDConfigAction.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.IOException;
-import com.nomagic.magicdraw.actions.MDAction;
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.magicdraw.core.Project;
-
-/**
- * Used to generate component, port, and topology XML files.
- *
- */
-public class LoadIDConfigAction extends MDAction {
- File pluginDir;
-
- /**
- *
- */
- private static final long serialVersionUID = -6790954285526957354L;
- public LoadIDConfigAction(String id, String name, File pluginDir)
- {
- super(id, name, null, null);
- this.pluginDir = pluginDir;
- }
-
- /**
- * Runs the LoadIDConfig
- *
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
- */
- public void actionPerformed(ActionEvent e)
- {
- Project project = Application.getInstance().getProject();
- try {
- LoadIDConfig.process(project, pluginDir);
- Utils.printToAll("*** Completed loading Base IDs/Window IDs from file.");
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- System.out.println("**** " + e1.getMessage());
- System.err.flush();
- }
- //System.err.flush();
-
- }
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDException.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDException.java
deleted file mode 100644
index 44f66d44b1..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/LoadIDException.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package gov.nasa.jpl.componentaction;
-/**
- * Shell exception for the LoadIDConfig class. This just serves as a wrapper that can be used to differentiate between where an error happens.
- *
- */
-public class LoadIDException extends Exception {
- public LoadIDException(String message) {
- super(message);
- }
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/MainMenuConfigurator.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/MainMenuConfigurator.java
deleted file mode 100644
index be209e0688..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/MainMenuConfigurator.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*! \mainpage MagicDraw Component Plugin
- *
- * \section intro Introduction
- *
- * This is the documentation for the Magic Draw UML to XML generator plugin.
- *
- *
- * Currently, the program can create XML files from component models and subsystem models. Subsystems within subsystems along side multiple instances of subsystems and models are supported.
- * Additionally, exceptions are thrown if there is something the program cannot handle and error messages are displayed onto the console.
- *
- * Notes
- *
- * -
- * If there are multiple subsystems in a model, make sure to create a stereotype "Top" and assign it to the "Top" level subsystem. This will ensure proper naming of the XML files.
- *
- * -
- * A simple example of how to implement multiple subsystems and multiple instances of subsystems in a model can be found at tests/testMultipleSubsystems.mdzip.
- *
- *
- *
- * -
- * Please make sure to give instances of subsystems unique names.
- *
- * -
- * Velocity (an Apache template engine) is being used to generate the XML files. These files can be found in the root of the MagicDrawPlugin folder and have .vm extensions.
- *
- *
- *
- *
- * \section pluginUse Using The Plugin
- *
- *
- * -
- * Load a project into MagicDraw.
- *
- * -
- * Ensure that the project either only has zero or one subsystems, or has the "Top" stereotype applied to one of the subsystems if many exist.
- *
- * -
- * Click on the "Component Autocoder" tab in the top toolbar.
- *
- * -
- * Click on "Auto Generate Component/Port/Topology XML".
- *
- * -
- * Check the MagicDraw console to see if any errors were generated.
- *
- * -
- * If not, the XML files can be found in /AutoXML/
- *
- *
- *
- * \section programFlow Program Flow
- *
- * \subsection menuConfig Menu Configuration
- *
- * These files take care of the menu configuration:
- *
- * \ref MainMenuConfigurator.java - Creates "Component Autocoder" tab in the toolbar.
- *
- * \ref IsfXMLAutocoderAction.java - Creates buttons within the "Component Autocoder" tab.
- *
- * \ref IsfAbout.java - Creates the modal element that displays the about information.
- *
- * \ref IsfXmlAction.java - Action object that is called when "Auto Generate Component/Port/Topology XML" is clicked. Processes ports, components, and the entire topology.
- *
- * \ref IsfCommandLine.java - Used to handle command line protocol.
- *
- * \ref IsfTopAction.java - NOT USED.
- *
- * \ref IsfComponentAction.java - NOT USED.
- *
- * \ref LoadIDConfigAction.java - Creates button to load id configuration file within the "Component Autocoder" tab.
- *
- *
- * \subsection objectProcessing Processing
- *
- * \ref ProcessISFProject.java - Object processes both components and ports at the same time.
- *
- * Component
- * \ref ISFComponent.java - Helper object for component processing.
- *
- * \ref IsfCompXmlWriter.java - Writes the processed components to XML documents.
- *
- *
- * Port
- * \ref ISFPort.java Helper object for port processing.
- *
- * \ref IsfPortXmlWriter.java - Writes the processed ports to XML documents.
- *
- *
- * Topology
- * \ref ProcessISFTopology.java - This object processes the model to create the topology XML diagrams. It can handle multiple subsystem within subsystems as well and multiple instantiations of subsystems and components.
- *
- * \ref ISFSubsystem.java - Contains many helper functions and objects used when process the model for the topology diagram.
- *
- * \ref IsfSubXmlWriter.java - Writes the processed model to an XML document.
- *
- *
- * \subsection exceptions Exceptions
- * These are the Exception objects of this plugin:
- *
- * \ref ComponentException.java - Thrown during component processing.
- *
- * \ref PortException.java - Thrown during port processing.
- *
- * \ref ConnectorException.java - Thrown during the topology processing
- *
- * \ref LoadIDException.java - Thrown during LoadIDConfig processing.
- *
- *
- * \subsection otherObjects Other
- * \ref Utils.java - Includes simple functions to help reduce code size (IE throwing ConnectorExceptions or raising warnings).
- * \ref LoadIDConfig.java - Loads id configuration file into the model and over writes component base and window ids with ones found in the file.
- *
- *\section aboutDoc About the Documentation
- *
- * More resources can be found in the base MagicDrawCompPlugin/doc/ or at MagicDrawCompPlugin/README.txt
- *
- * To update the documentation to reflect code changes:
- *
- * -
- * This Introduction area can be edited in the top comment block in MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/MainMenuConfigurator.java.
- *
- * -
- * Make sure Doxygen and Graphviz are both installed.
- *
- * -
- * Open the Doxygen Gui.
- *
- * -
- * Under the "File" tab at the top, click "Open" and select the file titled Doxyfile in the MagicDrawCompPlugin directory.
- *
- * -
- * Modify the settings (IE version number) in the GUI.
- *
- * -
- * To regenerate the documentation files, click on the "Run" tab in the GUI and click "Run doxygen".
- *
- * -
- * To update the PDF found in the doc folder, go to doc/rtf and convert refman.rtf to refman.doc using Microsoft Word, and then convert the .doc file to .pdf.
- *
- *
- *
- * \section contact Contact
- *
- * Until the plugin is updated even further, I will be able to answer questions any time.
- * My name is Saikiran Ramanan and I worked on the plugin as an intern during the Summer of 2016.
- * My email address is saikiranra@gmail.com
- *
- */
-package gov.nasa.jpl.componentaction;
-
-import com.nomagic.actions.AMConfigurator;
-import com.nomagic.actions.ActionsCategory;
-import com.nomagic.actions.ActionsManager;
-import com.nomagic.actions.NMAction;
-import com.nomagic.magicdraw.actions.MDActionsCategory;
-
-/**
- * Class for configuring main menu and adding new submenu.
- * @version $Date: 2007-10-05 09:51:43 +0300 (Fri, 05 Oct 2007) $ $Revision: 52410 $
- * @author Donatas Simkunas
- */
-public class MainMenuConfigurator implements AMConfigurator
-{
-
- String MPMCS="Component Autocoder";
-
- /**
- * Action will be added to manager.
- */
- private NMAction action;
-
- /**
- * Creates configurator.
- * @param action action to be added to main menu.
- */
- public MainMenuConfigurator(NMAction action)
- {
- this.action = action;
- }
-
- /**
- * @see com.nomagic.actions.AMConfigurator#configure(ActionsManager)
- * Methods adds action to given manager Examples category.
- */
- public void configure(ActionsManager mngr)
- {
- // searching for Examples action category
- ActionsCategory category = (ActionsCategory) mngr.getActionFor(MPMCS);
-
- if( category == null )
- {
- // creating new category
- category = new MDActionsCategory(MPMCS,MPMCS);
- category.setNested(true);
- mngr.addCategory(category);
- }
- category.addAction(action);
-
- }
-
- public int getPriority()
- {
- return AMConfigurator.MEDIUM_PRIORITY;
- }
-
-}
\ No newline at end of file
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/MpmcsErrorStream.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/MpmcsErrorStream.java
deleted file mode 100644
index 31c063b853..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/MpmcsErrorStream.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
-
-public class MpmcsErrorStream extends PrintStream {
-
- private PrintStream out;
-
- public MpmcsErrorStream(PrintStream out1, PrintStream out2)
- {
- super(out1);
-
- this.out = out2;
- }
-
- public MpmcsErrorStream(OutputStream arg0) {
- super(arg0);
- // TODO Auto-generated constructor stub
- }
-
- public MpmcsErrorStream(String arg0) throws FileNotFoundException {
- super(arg0);
- // TODO Auto-generated constructor stub
- }
-
- public MpmcsErrorStream(File arg0) throws FileNotFoundException {
- super(arg0);
- // TODO Auto-generated constructor stub
- }
-
- public MpmcsErrorStream(OutputStream arg0, boolean arg1) {
- super(arg0, arg1);
- // TODO Auto-generated constructor stub
- }
-
- public MpmcsErrorStream(String arg0, String arg1)
- throws FileNotFoundException, UnsupportedEncodingException {
- super(arg0, arg1);
- // TODO Auto-generated constructor stub
- }
-
- public MpmcsErrorStream(File arg0, String arg1)
- throws FileNotFoundException, UnsupportedEncodingException {
- super(arg0, arg1);
- // TODO Auto-generated constructor stub
- }
-
- public MpmcsErrorStream(OutputStream arg0, boolean arg1, String arg2)
- throws UnsupportedEncodingException {
- super(arg0, arg1, arg2);
- // TODO Auto-generated constructor stub
- }
-
- public void write(byte buf[], int off, int len)
- {
- try
- {
- super.write(buf, off, len);
- out.write(buf, off, len);
- }
- catch (Exception e)
- {
- }
- }
- public void flush()
- {
- super.flush();
- out.flush();
- }
-
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/Partition.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/Partition.java
deleted file mode 100644
index 18253540cd..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/Partition.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.TypedElement;
-
-/**
- * Creates the partition object.
- */
-public class Partition {
- private Element partitionElement;
-
- /**
- * Assigns the input partitionElement to the instance variable partitionElement.
- * @param partitionElement
- */
- public Partition(Element partitionElement) {
- this.partitionElement = partitionElement;
- }
-
- /**
- * Returns the name of the partitionElement.
- * @return name string
- */
- public String getName() {
- return partitionElement.getHumanName();
- }
-
- /**
- * Returns the third word in the name of the dataElement if the name was divided by spaces.
- * @param dataElement
- * @return the name of the dataElement
- */
- public String getDataName(Element dataElement) {
- return dataElement.getHumanName().split(" ")[2];
- }
-
- /**
- * Returns the third word in the type of the dataElement if the type was divided by spaces.
- * @param dataElement
- * @return the type of the dataElement
- */
- public String getDataType(Element dataElement) {
- TypedElement te = (TypedElement)dataElement;
- return te.getType().getHumanName().split(" ")[2];
- }
-
- /**
- * Prints the partition name to Java standard out and the MagicDraw console.
- */
- public void print() {
- System.out.println("Partition Name: " + getName());
- Application.getInstance().getGUILog().log("Partition Name: " + getName());
- }
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/PortException.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/PortException.java
deleted file mode 100644
index 421e43e435..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/PortException.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package gov.nasa.jpl.componentaction;
-/**
- * Port Exception shell class. This just serves as a wrapper that can be used to differentiate between where an error happens.
- *
- */
-public class PortException extends Exception {
- public PortException(String message) {
- super(message);
- }
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- }
-
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ProcessISFProject.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ProcessISFProject.java
deleted file mode 100644
index a3eaf359b1..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ProcessISFProject.java
+++ /dev/null
@@ -1,348 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import gov.nasa.jpl.componentaction.isfxmlwriter.IsfCompXmlWriter;
-import gov.nasa.jpl.componentaction.isfxmlwriter.IsfPortXmlWriter;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.*;
-
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.magicdraw.core.Project;
-import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.InstanceSpecification;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Operation;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.TypedElement;
-import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype;
-
-/**
- * This singleton class will process an ISF Project.
- *
- * @author Garth Watney
- */
-public class ProcessISFProject {
- private static Project project;
- private static List componentList;
- private static List portList;
-
- private ProcessISFProject() {
- }
-
- /**
- * Main function to process the project.
- *
- *
- *
- * -
- * Creates a directory to output XML files into if it does not already exist.
- *
- * -
- * Processes all the components in the model and generates an XML file for each of them.
- *
- * -
- * Processes all the ports in the model and generates an XML file to store all the port data.
- *
- *
- *
- *
- * @param proj Project object
- * @param pluginDir Folder to create XML folder in
- * @throws IOException
- */
- public static void process(Project proj, File pluginDir) throws IOException {
- project = proj;
- componentList = new ArrayList();
- portList = new ArrayList();
-
- Application.getInstance().getGUILog().clearLog();
- if (project == null) {
- System.out.println("***No model found");
- Application.getInstance().getGUILog().log("***No model found");
- } else {
-
- List compStereotypes = Arrays.asList("active", "passive",
- "queued");
-
- System.out.println("Project Name = " + project.getName());
- Application.getInstance().getGUILog()
- .log("My Project Name = " + project.getName());
-
- File projectFile = new File(project.getFileName());
- String projectDir = projectFile.getParent() + "/AutoXML";
-
- File dir = new File(projectDir);
- if(!dir.exists()) {
- dir.mkdir();
- }
-
- // Parse through the model for each component stereotype
- Application.getInstance().getGUILog()
- .log("Parsing model for Components");
- try {
- for (String compType : compStereotypes) {
- List compElementList = getElementsOfStereotype(compType);
- if(compType == "passive"){
- compElementList.addAll(getElementsOfStereotype("Passive Component"));
- }
- else if(compType == "active"){
- compElementList.addAll(getElementsOfStereotype("Active Component"));
- }
- else if(compType == "queued"){
- compElementList.addAll(getElementsOfStereotype("Queued Component"));
- }
- processComponents(compElementList, compType);
- }
-
-
- // Print the components
- for (ISFComponent c : componentList) {
- c.print();
- }
-
- // Or Ports can have the Stereotype of "PortType"
- Application.getInstance().getGUILog()
- .log("Parsing model for Ports");
- List newPortElementList = getElementsOfStereotype("PortType");
- processPorts(newPortElementList);
-
- // Print out the Port meta model
- for (ISFPort p : portList) {
- p.print();
- }
-
- // Write out an XML Interface for each Component in the meta model
- for (ISFComponent c : componentList) {
- IsfCompXmlWriter.write(c, "ComponentAi", projectDir, pluginDir);
- }
- // Write out an XML Interface for each Port in the meta model
- for (ISFPort p : portList) {
- IsfPortXmlWriter.write(p, "PortAi", projectDir, pluginDir);
- }
- }
-
- catch(PortException e) {
- Application.getInstance().getGUILog()
- .log("===> FATAL Exception: " + e.getMessage() + "");
- throw new RuntimeException(e);
- }
- }
- }
-
- /**
- * Function to process the project, except restricts component search to the processPackage.
- *
- *
- *
- * -
- * Creates a directory to output XML files into if it does not already exist.
- *
- * -
- * Processes all the components in the processPackage and generates an XML file for each of them.
- *
- * -
- * Processes all the ports in the processPackage and generates an XML file to store all the port data.
- *
- *
- *
- *
- * @param proj Project object
- * @param pluginDir Folder to create XML folder in
- * @param processPackage String of the process package
- * @throws IOException
- */
- public static void process(Project proj, File pluginDir, String processPackage) throws IOException {
- project = proj;
- componentList = new ArrayList();
- portList = new ArrayList();
- Application.getInstance().getGUILog().clearLog();
- List compStereotypes = Arrays.asList("active", "passive",
- "queued");
- File projectFile = new File(project.getFileName());
- String projectDir = projectFile.getParent() + "/AutoXML";
-
- File dir = new File(projectDir);
- if(!dir.exists()) {
- dir.mkdir();
- }
-
- try {
- for (String compType : compStereotypes) {
- List compElementList = getElementsOfStereotypeAndPackage(compType, processPackage);
- processComponents(compElementList, compType);
- }
-
- // Or Ports can have the Stereotype of "PortType"
- List newPortElementList = getElementsOfStereotypeAndPackage("PortType", processPackage);
- processPorts(newPortElementList);
-
- // Write out an XML Interface for each Component in the meta model
- for (ISFComponent c : componentList) {
- IsfCompXmlWriter.write(c, "ComponentAi", projectDir, pluginDir);
- }
- // Write out an XML Interface for each Port in the meta model
- for (ISFPort p : portList) {
- IsfPortXmlWriter.write(p, "PortAi", projectDir, pluginDir);
- }
- }
-
- catch(PortException e) {
- Application.getInstance().getGUILog()
- .log("===> FATAL Exception: " + e.getMessage() + "");
- throw new RuntimeException(e.getMessage());
- }
- }
-
- /**
- * Converts ports to ISFPort objects with associated data and return elements and adds it to the portList.
- * @param portElementList List of ports
- * @throws PortException
- */
- private static void processPorts(List portElementList) throws PortException {
-
- for (Element port : portElementList) {
- if (!(port instanceof InstanceSpecification)) {
- ISFPort thisPort = new ISFPort(port);
- portList.add(thisPort);
-
- Collection ownedElements = port.getOwnedElement();
- for (Element data : ownedElements) {
-
- if (!(data instanceof InstanceSpecification)) {
- // An argument in the Port
- if (data instanceof TypedElement) {
- //protect against missing type
- if(((TypedElement) data).getType() == null) {
- String errstr = ((TypedElement)data).getName()
- + " of port "
- + ((NamedElement)port).getName()
- + " has no data type";
- System.out.println(errstr);
- throw new PortException(errstr);
- }
- thisPort.addData(data);
- }
- // A return value in the Port
- if (data instanceof Operation) {
- thisPort.addReturn(data);
- }
- }
- }
- }
- else {
- System.out.println("No ports found");
- Application.getInstance().getGUILog().log("No ports found");
- }
- }
- }
-
- /**
- * Creates ISFComponent objects for all components with associated ports and adds them toe the componentList.
- * @param compElementList
- * @param stereotype
- * @throws PortException
- */
- private static void processComponents(List compElementList,
- String stereotype) throws PortException {
- List portTypeNames = Arrays.asList("sync_input", "async_input",
- "guarded_input", "Async" , "Sync" , "Input" , "Guarded" , "Output" , "output", "input");
- List portRoleNames = Arrays.asList("Cmd", "Telemetry", "CmdRegistration",
- "CmdResponse", "LogEvent", "LogTextEvent", "ParamGet", "ParamSet", "TimeGet");
- for (Element el : compElementList) {
- ISFComponent thisComp = new ISFComponent(el);
- componentList.add(thisComp);
- thisComp.setStereoType(stereotype);
- Collection ownedElements = el.getOwnedElement();
- // Loop through all the Port elements in this component
- for (Element oe : ownedElements) {
- //System.out.println(oe.getHumanName() + ": " + StereotypesHelper.hasStereotypeOrDerived(oe, "input"));
- String portStereotype = thisComp.getPortStereotype(oe);
- // Check the Port against all the ISF Port Stereotypes
- if (portTypeNames.contains(portStereotype)) {
- thisComp.newAddPort(oe);
- } else if(portRoleNames.contains(portStereotype)) {
- thisComp.newRolePort(oe);
- } else if (!portStereotype.equals("Instance")) {
- Application
- .getInstance()
- .getGUILog()
- .log("*** Warning: Port Stereotype = "
- + portStereotype + ": In Component "
- + thisComp.getName());
- System.out.println("==> Warning: Port Stereotype = "
- + portStereotype + ": In Component "
- + thisComp.getName());
- }
- }
- try {
- thisComp.checkComponent();
-
- }
- catch(ComponentException e) {
- Application.getInstance().getGUILog()
- .log("===> FATAL Exception: " + e.getMessage() + "");
- throw new RuntimeException(e.getMessage());
- }
- }
- }
-
- /**
- * Returns a list of elements with specified input stereotype string.
- * @param stereotype stereotype string to look for
- * @return list of Elements
- */
- private static List getElementsOfStereotype(String stereotype) {
- Stereotype st;
- List elementList = new ArrayList();
-
- st = StereotypesHelper.getStereotype(project, stereotype);
- if (st != null) {
- elementList = StereotypesHelper.getExtendedElements(st);
- if (elementList.isEmpty())
- System.out.println("Stereotype: " + stereotype
- + ", list is EMPTY?");
- } else {
- System.out.println("==> Warning no stereotype:" + stereotype);
- Application.getInstance().getGUILog()
- .log("==> Warning no stereotype:" + stereotype);
- }
- return elementList;
- }
-
- /**
- * Returns a list of elements with specified input stereotype string and within the processPackage.
- * @param stereotype stereotype string to look for
- * @param processPackage package string to look for
- * @return list of Elements
- */
- private static List getElementsOfStereotypeAndPackage(String stereotype, String processPackage) {
- Stereotype st;
- List elementList = new ArrayList();
-
- st = StereotypesHelper.getStereotype(project, stereotype);
- if (st != null) {
- elementList = StereotypesHelper.getExtendedElements(st);
- if (elementList.isEmpty())
- System.out.println("Stereotype: " + stereotype
- + ", list is EMPTY?");
- else {
- for(int i = elementList.size()-1; i>=0; i--) {
- Element comp = elementList.get(i);
- if(comp instanceof NamedElement) {
- NamedElement namedComp = (NamedElement)comp;
- if(!processPackage.equals(namedComp.getQualifiedName().split("::")[0])) {
- elementList.remove(i);
- }
- }
- }
- }
- } else {
- System.out.println("==> Warning no stereotype:" + stereotype);
- Application.getInstance().getGUILog()
- .log("==> Warning no stereotype:" + stereotype);
- }
- return elementList;
- }
-
-}
diff --git a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ProcessISFTopology.java b/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ProcessISFTopology.java
deleted file mode 100644
index cdd7222d01..0000000000
--- a/Autocoders/MagicDrawCompPlugin/src/gov/nasa/jpl/componentaction/ProcessISFTopology.java
+++ /dev/null
@@ -1,947 +0,0 @@
-package gov.nasa.jpl.componentaction;
-
-import gov.nasa.jpl.componentaction.Utils.Pair;
-import gov.nasa.jpl.componentaction.isfxmlwriter.IsfSubXmlWriter;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.nio.file.Files;
-import java.util.*;
-
-import com.nomagic.magicdraw.core.Application;
-import com.nomagic.magicdraw.core.Project;
-import com.nomagic.uml2.ext.jmi.helpers.ModelHelper;
-import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.EnumerationLiteral;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement;
-import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Property;
-import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.ConnectableElement;
-import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.Connector;
-import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.ConnectorEnd;
-import com.nomagic.uml2.ext.magicdraw.compositestructures.mdports.Port;
-
-/**
- * This singleton class will process an ISF Project.
- *
- * There are three main phases of the processing:
- *
- * -
- * PHASE ONE: Processing the model
- *
- * -
- * A list of all subsystems is made.
- *
- * -
- * A map of all the components is made.
- *
- * -
- * A list of all the target ports is made.
- *
- * -
- * A list of all the source ports is made.
- *
- * -
- * A map of all the port ends with a list of associated connectors (one list going in, the other going out) is made.
- *
- *
- *
- * -
- * PHASE TWO: Creating connections
- *
- * -
- * All full connections are found using each port in the source port list as a start point.
- *
- * -
- * Further connections are found using the map of port ends with their associated connectors.
- *
- * -
- * Some connectors are ignored depending on the multiplicity of the previous source port. This multiplicity is recalculated for every connector.
- *
- * -
- * When reached a port that is not owned by a subsystem, the type is checked. If the source port and the target port type do not matched, that target port is ignored.
- *
- * -
- * This process goes on for each source port until either the target port is found, all the associated connectors have been done being searched, or a time out variable is reached.
- *
- * -
- * Each source and derived target connector ends are processed through the ISFSubsystem physicalConnectionType and added to a list.
- *
- *
- *
- * -
- * PHASE THREE: Checking ports and writing to XML
- *
- * -
- * A map is created with the name of generic modules being associated with a list of the ports on that module.
- *
- * -
- * This map is cross checked with all the instances of the modules. If something in the map does not exist within an instance, the user gets notified by a warning.
- *
- * -
- * An ISFSubsystem topologyModel object is created using the physicalConnectionType list and the map of all the components.
- *
- * -
- * This object is passed to the IsfSubXmlWriter and is used to generate the flattened XML topology file.
- *
- *
- *
- *
- *
- * Please note that if you have more than one subsystem to be processed, make sure one of them has a stereotype with the name "Top".
- * This subsystem will be used for the name of the topology xml. If not, an exception will be thrown.
- *
- *
- * Exceptions can be generated at any time in this process.
- *
- *
- */
-public class ProcessISFTopology {
- private static Project project;
- private static Set subsystemNameSet;
-
-
- private static HashMap>> subsystemMap;
-
- private static Set sourcePorts;
- private static Set targetPorts;
- public static HashSet physicalConnectionSet;
-
- public static HashMap componentMap;
- public static ArrayList physicalConnectionList;
- public static Map> subsystemOwners;
- public static Map subsystemInstances;
- public static Map> uniqueSubsystemInstanceNames;
-
-
- private ProcessISFTopology() { }
-
- /**
- * process handles all the phases of this methodology.
- *
- * @param proj Project object
- * @param pluginDir Directory to generate documents into
- * @throws IOException
- */
- public static void process(Project proj, File pluginDir) throws IOException {
- project = proj;
- subsystemNameSet = new HashSet();
- subsystemMap = new HashMap>>();
-
- sourcePorts = new HashSet();
- targetPorts = new HashSet();
- physicalConnectionSet = new HashSet();
-
- componentMap = new HashMap();
- physicalConnectionList = new ArrayList();
- subsystemInstances = new HashMap();
- subsystemOwners = new HashMap>();
- uniqueSubsystemInstanceNames = new HashMap>();
-
- String fileName = null;
-
- try {
- if (project == null) {
- Utils.printToAll("***No model found");
- }
- else {
- //PHASE ONE: PROCESSING THE MODEL
- Utils.printToAll("Project Name = " + project.getName());
- File projectFile = new File(project.getFileName());
- String projectDir = projectFile.getParent() + "/AutoXML";
-
- //If the project dir doesn't exist, create it
- File projectDirObj = new File(projectDir);
- if (!projectDirObj.isDirectory()){
- projectDirObj.mkdir();
- }
-
- // Get a list of all the Subsystem elements
- Element root = project.getModel();
- List subsystemElementList = processModel(root);
-
- if(subsystemElementList.size() != 0){
- int subsystemListSize = subsystemElementList.size();
- for (int x = 0; x < subsystemListSize; x++) {
- processSubsystem(subsystemElementList.get(x));
- //Try to see if the subsystemListSize is one or if the current subsystem has the stereotype 'Top'. If so, the name of the subsystem is used as the name of the Topology XML file.
- if(subsystemListSize == 1 || StereotypesHelper.hasStereotype(subsystemElementList.get(x), "Top")){
- String[] fileNameList = subsystemElementList.get(x).getHumanName().split(" ");
- fileName = fileNameList[fileNameList.length-1];
- }
- }
-
- //PHASE TWO: CREATING CONNECTIONS
- createConnections();
-
- //PHASE THREE: CHECKING PORTS AND WRITING TO XML
- checkPorts();
-
- //If not filename was found, an error is thrown.
- if(fileName == null){
- throw new ConnectorException("Filename is not specified. Please add the stereotype 'Top' to the top level subsystem or only use one subsystem in the diagram.");
- }
-
- physicalConnectionList = indexChecking(physicalConnectionSet);
-
- ISFSubsystem.topologyModel topModel = new ISFSubsystem.topologyModel(componentMap, physicalConnectionList);
- topModel.baseID = ISFSubsystem.getBaseId(root);
- topModel.instanceWindow = ISFSubsystem.getInstanceWindow(root);
- topModel.name = fileName;
-
- IsfSubXmlWriter.write(topModel, "Topology", fileName, projectDir, pluginDir);
- }
- else{
- Utils.notifyWarning("NoSubsystemsFound - No objects with the stereotype 'Subsystem' have been found. Topology XML will not be generated.");
- }
- }
- }
- catch (ConnectorException e) {
- Application.getInstance().getGUILog()
- .log("===> FATAL Exception: " + e.getMessage() + "");
- throw new RuntimeException(e.getMessage());
- }
-
- }
-
-
- /**
- * PHASE THREE FUNCTION
- *
- *
- * This function serves two purposes. The first is to convert the physicalConnectionSet to a physicalConnectionList. The second is to perform index checking and correction on ports of the cmdReg/cmd or com/cmdResponse type.
- *
- *
- *
- * The index checking/correction is done so multiplicities do not need to be specified for cmd/cmdReg or com/cmdResponse (with port names of seqCmdStatus and seqCmdBuff) blocks.
- * The latter pair has the additional port name constraint because there are multiple other ports with the same cmdResponse type. Some of these port are not to be auto-indexed.
- * This makes it easier for the user to add and remove these ports without needing to worry about if the indexes of the pairings match.
- *
- *
- *
- * The program redefines the indexes in numerical order. Even if initial indexes are given, for the origin of Cmd and the target of CmdReg, they are overwritten. They target index of Cmd is preserved and also is written to the source of CmdReg.
- *
- *
- * METHODOLOGY
- *
- * -
- * Iterate through all items of the physicalConnectionType and add those who have types of Cmd/CmdReg or those who have type of CmdResponse/Com and names of seqCmdStatus/seqCmdBuff to a list in a map where the index is the instance name of the associated cmdDispatch.
- *
- * -
- * Iterate through all keys in the dictionary.
- *
- *
- * -
- * Iterate through each item in the list and find another item that has the opposite target and source components but is off the same pair.
- *
- * -
- * If the associated item does not exist and if the search object is of the type of Cmd or Cmd reg, throw an error.
- *
- * -
- * If the item is of the type Com/CmdResponse or there is an associated pair, add the item(s) to the output list.
- *
- *
- * -
- * Return a new list of physicalConnectionType objects with auto indexed IDS.
- *
- *
- *
- *
- *
- * @param pctSet Set of Physical Connection Types
- * @return List of Physical Connection Types
- */
- private static ArrayList indexChecking(HashSet pctSet) throws ConnectorException{
- ArrayList pctList = new ArrayList();
-
- HashMap> indexCorrectionMap = new HashMap>(); //Two ArrayLists, the first index is for Cmd, the second is for CmdReg
-
-
- for(ISFSubsystem.physicalConnectionType pct : pctSet){
- String componentName = null;
-
- if(pct.sourcePortType.equals("Cmd")){
- componentName = pct.source;
- }
- else if(pct.targetPortType.equals("CmdReg")){
- componentName = pct.target;
- }
-
- if(componentName != null){
- if(!indexCorrectionMap.containsKey(componentName)){
- indexCorrectionMap.put(componentName, new ArrayList());
- }
- indexCorrectionMap.get(componentName).add(pct);
- }
- else{
- pctList.add(pct);
- }
- }
- for(String compName : indexCorrectionMap.keySet()){
- int cmdRegOrderingIndex = 0;
- int cmdSeqOrderingIndex = 0;
- while(indexCorrectionMap.get(compName).size() > 0){
- //System.out.println(indexCorrectionMap.get(compName));
- ISFSubsystem.physicalConnectionType searchPCT = indexCorrectionMap.get(compName).get(0);
- ISFSubsystem.physicalConnectionType currPCT = searchPCT;
- boolean noCompanionConn = true;
- int removeIndex = 0;
- for(int i = 1; i != indexCorrectionMap.get(compName).size(); i++){
- currPCT = indexCorrectionMap.get(compName).get(i);
- //Different Types
- if(
- (searchPCT.sourcePortType.equals("Cmd") && currPCT.targetPortType.equals("CmdReg"))
- ||
- (searchPCT.sourcePortType.equals("CmdReg") && currPCT.targetPortType.equals("Cmd"))
- ) {
- //Check if they are of the same component
- //System.out.println("Search PCT (source: " + searchPCT.source + " , target: " + searchPCT.target + ") " + "Curr PCT (target: " + currPCT.target + " , source: " + currPCT.source + ")");
- if(searchPCT.source.equals(currPCT.target) && searchPCT.target.equals(currPCT.source)){
- if(searchPCT.sourcePortType.equals("CmdReg")){
- currPCT.target_index = searchPCT.source_index;
- currPCT.source_index = cmdRegOrderingIndex;
- searchPCT.target_index = cmdRegOrderingIndex;
- cmdRegOrderingIndex++;
- }
- else if (searchPCT.sourcePortType.equals("Cmd")){
- searchPCT.target_index = currPCT.source_index;
- searchPCT.source_index = cmdRegOrderingIndex;
- currPCT.target_index = cmdRegOrderingIndex;
- cmdRegOrderingIndex++;
- }
- noCompanionConn = false;
- removeIndex = i;
- break;
- }
- }
- }
-
- if(noCompanionConn){
- Utils.throwConnectorException("The connection from " + searchPCT.source + " in subsystem " + searchPCT.sourceRoleParentName + " to " + searchPCT.target + " in subsystem " + searchPCT.targetRoleParentName + " of type " + searchPCT.sourcePortType + " does not have an connection going from the same objects of the opposite type. Auto-assigning indexes cannot be continued.");
- }
- else{
- pctList.add(searchPCT);
- pctList.add(currPCT);
- indexCorrectionMap.get(compName).remove(removeIndex);
- indexCorrectionMap.get(compName).remove(0);
- }
- }
- }
-
- return pctList;
- }
-
- /**
- * PHASE THREE FUNCTION
- *
- * Checks if ports on leaf modules have any connections. If they do not, a warning is brought up onto the console.
- *
- *
- *
- * This function first generates a Map with a generic leaf module's name as a key to a list of the "qualified name" of each port on the module.
- * The qualified name is used as an identifier for the generic module.
- *
- *
- *
- * The function next iterates through all elements with the "PartProperty" stereotype to find "unique" leaf components.
- * The function now uses the unique leaf components generic name to iterate through each of its' ports.
- *
- *
- *
- * Each port is then checked to see if it exists as a key in the subsystemMap.
- * If it doesn't exist, it means that this port has no connections and a warning flag is immediately notified.
- *
- * @throws ConnectorException
- */
- private static void checkPorts() throws ConnectorException{
- HashMap> moduleBaseNameMap = new HashMap>();
-
- //Generates a Map with the base name of module is a key (IE SockGNDIF) associated with the "qualified name" of the module
- for(Element e : ISFSubsystem.getElementsOfStereotype("FlowPort")){
- Property prop = (Property) e;
- String moduleName = prop.getObjectParent().getHumanName();
- String qualified = prop.getQualifiedName();
- if(!e.getObjectParent().getHumanType().equals("Subsystem")){
- if(!moduleBaseNameMap.containsKey(moduleName)){
- moduleBaseNameMap.put(moduleName, new ArrayList());
- }
- moduleBaseNameMap.get(moduleName).add(qualified);
- }
- }
-
- //Iterates through all modules
- for(Element e: ISFSubsystem.getElementsOfStereotype("PartProperty")){
- if(e != null){
- Property prop = (Property) e;
- if(prop.getType() != null){
- String baseModuleName = prop.getType().getHumanName();
- String qualified = prop.getQualifiedName();
- //Checks if subsystem or leaf module
- if(moduleBaseNameMap.containsKey(baseModuleName)){
- //Iterates through all ports on the generic module
- for(String portQualifiedName: moduleBaseNameMap.get(baseModuleName)){
- //Checks if the subsystem map contains the port
- if(!subsystemMap.containsKey(portQualifiedName + "_" + qualified)){
- Utils.notifyWarning("PortNotConnected - Port " + "" +portQualifiedName + "" +" in component " + qualified + " has no connections.");
- }
- else if(qualified.equals("CDHCore::CDHSubsystem::sequenceRunner")){
- //System.out.println(portQualifiedName + " " + moduleBaseNameMap.get(portQualifiedName + "_" + qualified).size());
- }
- }
- }
- }
- else{
- Utils.notifyWarning("NoElementType - Element " + e.getHumanName() + " with stereotype PartProperty does not have a type. Checking if ports on this element have connections has been skipped.");
- }
- }
- }
-
- }
-
- /**
- * PHASE ONE FUNCTION
- *
- * processModel has two main functions: to create a list of subsystems and to create a componentMap.
- *
- *
- *
- * All the elements in the module are iterated through using the Element root.
- *
- *
- *
- * If the element type is Subsystem, the element is added to a list to be returned.
- *
- *
- *
- * If the element is an instance of a subsystem, the subsystemOwners map is updated, where each key (name of subsystem) is associated with an list of two string arrays.
- * The first String corresponds to the instance name and the second corresponds to the name of the owner of the subsystem.
- *
- * @param root Root of the system
- * @return List of subsystem elements
- */
- private static List processModel(Element root) throws ConnectorException{
- List subsystemElementList = new ArrayList();
- Collection collection = (Collection)ModelHelper.getElementsOfType(root, null, true, true);
-
- for(Element el : collection) {
- if(el instanceof NamedElement) {
- if (el.getHumanType().equals("Subsystem")) {
- subsystemElementList.add(el);
- subsystemNameSet.add(((NamedElement) el).getID());
- }
- else if (el.getHumanType().equals("Part Property") || el.getHumanType().equals("Reference Property") ){
- Property prop = (Property) el;
- if(prop.getType() != null){
- if(prop.getType().getHumanType().equals("Subsystem")){
-
- String subName = ISFSubsystem.getLastPartOfString(prop.getType().getHumanName());
- if(!subsystemOwners.containsKey(subName)){
- subsystemOwners.put(subName, new ArrayList());
- }
- //[instanceName , genericName]
- String[] addString = {prop.getName() , ISFSubsystem.getLastPartOfString(prop.getOwner().getHumanName())};
-
- subsystemOwners.get(subName).add(addString);
- }
- }
- else{
- Utils.notifyWarning("NoElementType - Component " + prop.getName() + " in subsystem " + prop.getObjectParent().getHumanName() + " has no type object. Please check the subsystem to see if extraneous elements exist.");
- }
- }
- }
- }
- return(subsystemElementList);
- }
-
- /**
- * Checks the subsystemInstances map (which is a key string mapped to a value of how many times this class is instantiated.
- * Will return true if it is a singular system, false if the system isn't instantiated or the instances equal one.
- * @param key
- * @return
- */
- private static boolean isTopSubsystemNode(String key){
- if(!subsystemInstances.containsKey(key)){
- return false;
- }
- return(subsystemInstances.get(key) == 1);
- }
-
- /**
- * PHASE ONE FUNCTION
- *
- * processSubsystem populates both the subsystemMap as well as the sourcePorts/targetPorts list.
- *
- *
- *
- * First, the function's name is used with the subsystemOwners map to create a list tree. This list tree is then used to generate all the different names needed to clarify
- *
- *
- *
- *
- * The function iterates through all Connectors associated with the subsystem. The subsystemMap, sourcePorts, and targetPorts are populated through this iteration.
- *
- *
- *
- * The subsystemMap is a Map where the key is the ID of each port with an associated list of input and output connectors.
- *
- *
- *
- * ConnectorEnds of leaf components are also pushed onto sourcePorts and targetPorts lists, respective of what direction they accept data.
- *
- *
- *
- *
- * Using the list of all instances, each internal module (bbd) is added as an ISFSubsystem componentType to the component map, with the new name of the module
- *
- * @param subsystem Subsystem Element
- * @throws ConnectorException
- */
- private static void processSubsystem(Element subsystem)
- throws ConnectorException {
- /*
- * Map creation
- * Creates map based off qualified port name
- * map[qualified name] = Connectors[]
- */
- Utils.printToAll("*** Subsystem = " + subsystem.getHumanName());
- //Go through all parents of the subsystem to see if the components within the subsystem need special names
- String subsystemName = ISFSubsystem.getLastPartOfString(subsystem.getHumanName());
- ArrayList subsystemWithinSubsystemList = new ArrayList();
- ArrayList subsystemInstanceNameList = new ArrayList();
- String currSubsystemName = subsystemName;
- String currInstanceName = "";
- int index = 0;
- //Infinite loop protection
- while(index < 50){
- if(subsystemOwners.containsKey(currSubsystemName)){
- for(String[] e: subsystemOwners.get(currSubsystemName)){
- String instanceName = e[0];
- if(!currInstanceName.equals("")){
- instanceName += "_" + currInstanceName;
- }
-
- String[] tuple = {instanceName, e[1]};
- subsystemWithinSubsystemList.add(index , tuple);
- }
- }
- else{
- subsystemInstanceNameList.add(currInstanceName);
- String prefix = "";
- ArrayList reveredPre = new ArrayList();
- for(String pre : currInstanceName.split("_")){
- if(!pre.equals("")){
- reveredPre.add(0 , pre);
- }
- }
- for(String pre : reveredPre){
- if(!prefix.equals("") && !pre.equals("")){
- prefix = pre + "_" + prefix;
- }
-
-
- if(!uniqueSubsystemInstanceNames.containsKey(prefix)){
- uniqueSubsystemInstanceNames.put(prefix, new ArrayList());
- }
- String instanceName = currInstanceName.replace(prefix, "");
- uniqueSubsystemInstanceNames.get(prefix).add(instanceName);
- }
- }
- if(index >= subsystemWithinSubsystemList.size()){
- break;
- }
-
- currSubsystemName = subsystemWithinSubsystemList.get(index)[1];
- currInstanceName = subsystemWithinSubsystemList.get(index)[0];
- index++;
- }
-
-
- subsystemInstances.put(subsystemName, subsystemInstanceNameList.size());
-
- //Iterate through all owned objects of the inputted subsystem
- for(Element e: subsystem.getOwnedElement()){
- //Add connections to a map where the connector end is a key associated with lists of input/output connections
- if(e.getHumanType().equals("Part Property") || e.getHumanType().equals("Reference Property")){
- Property prop = (Property) e;
- if(prop.getType() != null){
- if(!prop.getType().getHumanType().equals("Subsystem")){
- if(prop.get_connectorEndOfPartWithPort().toArray().length > 0){
- if(subsystemInstanceNameList.size() == 0){
- subsystemInstanceNameList.add("");
- }
- for(String instanceName : subsystemInstanceNameList){
- if(isTopSubsystemNode(subsystemName)){
- instanceName = "";
- }
- String id = instanceName+prop.getName();
- String name = prop.getName();
- if(!instanceName.equals("")){
- name = instanceName+"_"+ name;
- }
-
- String[] typeList = ((ConnectorEnd) prop.get_connectorEndOfPartWithPort().toArray()[0]).getRole().getObjectParent().getHumanName().split(" ");
- String type = typeList[typeList.length - 1];
- Element baseComponent = (Element) ((ConnectorEnd) prop.get_connectorEndOfPartWithPort().toArray()[0]).getRole().getObjectParent();
- String nameSpace = ISFSubsystem.getNamespace(baseComponent);
-
- String baseID = ISFSubsystem.getBaseId((Element) prop);
- if(baseID.equals("")){
- baseID = ISFSubsystem.getBaseId(baseComponent);
- }
-
- String instanceWindow = ISFSubsystem.getInstanceWindow((Element) prop);
- if(instanceWindow.equals("")){
- instanceWindow = ISFSubsystem.getInstanceWindow(baseComponent);
- }
-
- String XMLPath = ISFSubsystem.getFileLocation(baseComponent);
- componentMap.put(id, ISFSubsystem.createComponent(name, nameSpace, type, baseID, instanceWindow , XMLPath));
- }
-
- }
- }
- }
- }
- else if (e instanceof Connector) {
- Connector tempConnector = (Connector) e;
- String sourceID = ISFSubsystem.getQualifiedSourcePort(tempConnector);
- String targetID = ISFSubsystem.getQualifiedTargetPort(tempConnector);
- if(!subsystemMap.containsKey(sourceID)){
- subsystemMap.put(sourceID , new ArrayList>());
- ArrayList targetList = new ArrayList();
- ArrayList sourceList = new ArrayList();
- subsystemMap.get(sourceID).add(sourceList);
- subsystemMap.get(sourceID).add(targetList);
- }
- if(!subsystemMap.containsKey(targetID)){
- subsystemMap.put(targetID , new ArrayList>());
- ArrayList targetList = new ArrayList