package avatartranslator.tosysmlv2; import java.util.ArrayList; public class AvatarFromSysMLSyntax { public class MyArray<E> extends ArrayList<E> { @Override public E set(int index, E element){ int max = size(); for(int i = max; i <= index; i++) add(null); return super.set(index, element); } } /** idents collected while parsing an Avatar SysML Model */ public class Ident { public static final byte DATATYPENAME = 0; public static final byte BLOCKNAME = 1; public static final byte ATTRIBUTENAME = 2; public static final byte RELATIONNAME = 3; public static final byte CHANNELPRENAME = 4; public static final byte SIGNALNAME = 5; public static final byte CHANNELNAME = 6; public static final byte MESSAGENAME = 7; public static final byte STANDARDSTATENAME = 8; public static final byte STARTSTATENAME = 9; public static final byte STOPSTATENAME = 10; public static final byte RANDOMSTATENAME = 11; public static final byte COUNTSTATENAME = 12; public static final byte SENDSTATENAME = 13; public static final byte RECEIVESTATENAME = 14; public static final byte PRESENDSTATENAME = 15; public static final byte PRERECEIVESTATENAME = 16; public static final byte SETTIMERSTATENAME = 17; public static final byte RESETTIMERSTATENAME = 18; public static final byte EXPIRETIMERSTATENAME = 19; public static final byte PRESETTIMERSTATENAME = 20; public static final byte PRERESETTIMERSTATENAME = 21; public static final byte PREEXPIRETIMERSTATENAME = 22; public static final byte TIMERBLOCKNAME = 23; public static final byte QUOTEDNAME = 24; public static final byte AVATARNAME = 25; private byte type; private String sysMLName; private String avatarName; public Ident(byte _type, String _smlName) { type = _type; if (type == AVATARNAME) { sysMLName = _smlName; avatarName = _smlName; } else { sysMLName = _smlName.substring(1, _smlName.length() - 2); if (type == DATATYPENAME) { avatarName = _smlName.substring(5,_smlName.length() - 2); } else if (type == ATTRIBUTENAME) { avatarName = _smlName.substring(2,_smlName.length() - 2); } else if (type == SIGNALNAME) { avatarName = _smlName.substring(6,_smlName.length() - 2); } else if (type == STANDARDSTATENAME) { avatarName = _smlName.substring(14,_smlName.length() - 2); } else if (type == BLOCKNAME) { avatarName = _smlName.substring(6,_smlName.length() - 2); } else { avatarName = sysMLName; if (type == QUOTEDNAME) type = AVATARNAME; } } } public byte getType() { return type; } public String getSysMLName() { return sysMLName; } public String getAvatarName() { return avatarName; } public boolean is_DATATYPENAME() { return type == DATATYPENAME || type == AVATARNAME; } public boolean is_BLOCKNAME() { return type == BLOCKNAME || type == AVATARNAME; } public boolean is_ATTRIBUTENAME() { return type == ATTRIBUTENAME || type == AVATARNAME; } public boolean is_RELATIONNAME() { return type == RELATIONNAME || type == AVATARNAME; } public boolean is_CHANNELPRENAME() { return type == CHANNELPRENAME || type == AVATARNAME; } public boolean is_SIGNALNAME() { return type == SIGNALNAME || type == AVATARNAME; } public boolean is_CHANNELNAME() { return type == CHANNELNAME || type == AVATARNAME; } public boolean is_MESSAGENAME() { return type == MESSAGENAME || type == AVATARNAME; } public boolean is_STANDARDSTATENAME() { return type == STANDARDSTATENAME || type == AVATARNAME; } public boolean is_STARTSTATENAME() { return type == STARTSTATENAME || type == AVATARNAME; } public boolean is_STOPSTATENAME() { return type == STOPSTATENAME || type == AVATARNAME; } public boolean is_RANDOMSTATENAME() { return type == RANDOMSTATENAME || type == AVATARNAME; } public boolean is_COUNTSTATENAME() { return type == COUNTSTATENAME || type == AVATARNAME; } public boolean is_SENDSTATENAME() { return type == SENDSTATENAME || type == AVATARNAME; } public boolean is_RECEIVESTATENAME() { return type == RECEIVESTATENAME || type == AVATARNAME; } public boolean is_PRESENDSTATENAME() { return type == PRESENDSTATENAME || type == AVATARNAME; } public boolean is_PRERECEIVESTATENAME() { return type == PRERECEIVESTATENAME || type == AVATARNAME; } public boolean is_SETTIMERSTATENAME() { return type == SETTIMERSTATENAME || type == AVATARNAME; } public boolean is_RESETTIMERSTATENAME() { return type == RESETTIMERSTATENAME || type == AVATARNAME; } public boolean is_EXPIRETIMERSTATENAME() { return type == EXPIRETIMERSTATENAME || type == AVATARNAME; } public boolean is_PRESETTIMERSTATENAME() { return type == PRESETTIMERSTATENAME || type == AVATARNAME; } public boolean is_PRERESETTIMERSTATENAME() { return type == PRERESETTIMERSTATENAME || type == AVATARNAME; } public boolean is_PREEXPIRETIMERSTATENAME() { return type == PREEXPIRETIMERSTATENAME || type == AVATARNAME; } public boolean is_TIMERBLOCKNAME() { return type == TIMERBLOCKNAME || type == AVATARNAME; } } public abstract static class StxElement { private int row; private int column; public StxElement(int _row, int _column){ row = _row; column = _column; } public StxElement(){ row = -1; column = -1; } public void setRowColumn(int _row, int _column) { row = _row; column = _column; } public int getRow() { return row; } public int getColumn() { return column; } } public static class StxStructure extends StxElement { private String name; private ArrayList<String> fieldNames; private ArrayList<String> fieldTypes; public StxStructure(int _row, int _column, String _name) { super(_row, _column); name = _name; fieldNames = new ArrayList<String>(); fieldTypes = new ArrayList<String>(); } public StxStructure(String _name) { super(); name = _name; fieldNames = new ArrayList<String>(); fieldTypes = new ArrayList<String>(); } public boolean addField(String fieldName, String fieldType){ boolean result = true; for (String fld : fieldNames) result &= (! fld.equals(fieldName)); if (result) { fieldNames.add(fieldName); fieldTypes.add(fieldType); } return result; } public String getName() { return name; } public int getSize() { return fieldNames.size(); } public String getFieldName(int i) { return fieldNames.get(i);} public String getFieldType(int i) { return fieldTypes.get(i);} } public static class StxDataType extends StxStructure { public StxDataType(int _row, int _column, String _name) { super(_row, _column, _name); } public StxDataType(String _name) { super(_name); } } public class StxRelation extends StxElement { ArrayList<StxChannel> channels; String block1; String block2; boolean blocking; int sizeOfFIFO; boolean asynchronous; public StxRelation(int _row, int _column) { super(_row, _column); channels = new ArrayList<StxChannel>(); String block1 = null; String block2 = null; } public StxRelation() { super(); channels = new ArrayList<StxChannel>(); String block1 = null; String block2 = null; } public void setBlock1(String _name) { block1 = _name; } public void setBlock2(String _name) { block2 = _name; } public void setBlocking(Boolean _b) { blocking = _b; } public void setFifoSize(int _size) { sizeOfFIFO = _size; } public void setAsynchronous(boolean _b) { asynchronous = _b; } public void addChannel(StxChannel ch) { channels.add(ch); } public String getBlock1(String _name) { return block1; } public String getBlock2(String _name) { return block2; } public Boolean getblocking(boolean _b) { return blocking; } public int getFifoSize(int _size) { return sizeOfFIFO; } public boolean getAsynchronous(boolean _b) { return asynchronous = _b; } public int getSize() { return channels.size(); } public StxChannel getChannel(int i) { return channels.get(i); } } public static class StxMethod extends StxStructure { public StxMethod(int _row, int _column, String _name) { super(_row, _column, _name); } public StxMethod(String _name) { super(_name); } } public class StxAttribute extends StxElement { String name; String type; public StxAttribute(int _row, int _column, String _name, String _type){ super(_row, _column); name = _name; type = _type; } public StxAttribute(String _name, String _type){ super(); name = _name; type = _type; } public String getName() { return name; } public String getType() { return type; } } public class StxTimer extends StxElement { String name; public StxTimer(int _row, int _column, String _name){ super(_row, _column); name = _name; } public StxTimer(String _name){ super(); name = _name; } public String getName() { return name; } } public class StxBlock extends StxElement { String name; StxBlock father = null; ArrayList<StxAttribute> attributes; ArrayList<StxMethod> methods; ArrayList<StxSignal> signals; ArrayList<StxTimer> timers; StxStateMachine statemachine; public StxBlock(int _row, int _column, String _name) { super(_row, _column); name = _name; father = null; statemachine = null; attributes = new ArrayList<StxAttribute>(); methods = new ArrayList<StxMethod>(); signals = new ArrayList<StxSignal>(); timers = new ArrayList<StxTimer>(); } public StxBlock(String _name) { super(); name = _name; father = null; statemachine = null; attributes = new ArrayList<StxAttribute>(); methods = new ArrayList<StxMethod>(); signals = new ArrayList<StxSignal>(); timers = new ArrayList<StxTimer>(); } public void setFather(StxBlock _father) { father = _father; } public void setstatemachine(StxStateMachine _statemachine) { statemachine = _statemachine; } public boolean addAttribute(StxAttribute a){ boolean result = true; for (StxAttribute att : attributes) result &= (! att.getName().equals(a.getName())); if (result) attributes.add(a); return result; } public boolean addMethod(StxMethod m){ boolean result = true; for (StxMethod mth : methods) result &= (! mth.getName().equals(m.getName())); if (result) methods.add(m); return result; } public boolean addTimer(StxTimer t){ boolean result = true; for (StxTimer tm : timers) result &= (! tm.getName().equals(t.getName())); if (result) timers.add(t); return result; } public String getName() { return name; } public StxBlock getFather() { return father; } public StxStateMachine getstatemachine() { return statemachine; } public int getNbAttributes() { return attributes.size(); } public int getNbMethods() { return methods.size(); } public int getNbSignals() { return signals.size(); } public int getNbTimerss() { return timers.size(); } public StxAttribute getAttribute(int i) { return attributes.get(i); } public StxMethod getMethod(int i) { return methods.get(i); } public StxSignal getSignal(int i) { return signals.get(i); } public StxTimer getTimers(int i) { return timers.get(i); } } public class StxChannel extends StxElement { private String relation; private StxInMessage inProfile; private StxOutMessage outProfile; private String blockA; private StxSignal signalA; private String blockB; private StxSignal signalB; public StxChannel(int _row, int _column){ super(_row, _column); relation = null; inProfile = null; outProfile = null; blockA = null; blockB = null; signalA = null; signalB = null; } public StxChannel(){ super(); relation = null; inProfile = null; outProfile = null; blockA = null; blockB = null; signalA = null; signalB = null; } public void setRelationrelation(String _name) { relation = _name; } public void setInProfile(StxInMessage m) { inProfile = m; } public void setOutProfile(StxOutMessage m) { outProfile = m; } public void setSignal(String _block, StxSignal s) { if (signalA == null) { blockA = _block; signalA = s; } else if (signalB == null) { blockB = _block; signalB = s; } } public void commuteSignals(String _block1) { boolean permut = (blockB != null && blockB.equals(_block1)) ||(blockA != null && ! blockB.equals(_block1)); if (permut) { String auxStr = blockA; StxSignal auxSig = signalA; blockA = blockB; signalA = signalB; blockB = auxStr; signalB = auxSig; } } public void setSignalA(StxSignal s) { signalA = s; } public void setSignalB(StxSignal s) { signalB = s; } public String getRelationrelation() { return relation; } public StxInMessage getInProfile() { return inProfile; } public StxOutMessage getOutProfile() { return outProfile; } public StxSignal getSignalA() { return signalA; } public StxSignal getSignalB() { return signalB; } } public class StxSignal extends StxElement { private String name; private boolean input; public StxSignal(int _row, int _column, String _name){ super(_row, _column); name = _name; } public void setInput(boolean _b) { input = _b; } public boolean isInput() { return input; } public String getName() { return name; } } public class StxInMessage extends StxElement { private String channel; private ArrayList<String> fieldNames; private ArrayList<String> fieldTypes; public StxInMessage(int _row, int _column, String _channel) { super(_row, _column); channel = _channel; fieldNames = new ArrayList<String>(); fieldTypes = new ArrayList<String>(); } public StxInMessage(String _channel) { super(); channel = _channel; fieldNames = new ArrayList<String>(); fieldTypes = new ArrayList<String>(); } public boolean addField(String fieldName, String fieldType){ boolean result = true; for (String fld : fieldNames) result &= (! fld.equals(fieldName)); if (result) { fieldNames.add(fieldName); fieldTypes.add(fieldType); } return result; } public String getChannel() { return channel; } public int getSize() { return fieldNames.size(); } public String getFieldName(int i) { return fieldNames.get(i);} public String getFieldType(int i) { return fieldTypes.get(i);} } public class StxOutMessage extends StxElement { private String inMessage; private ArrayList<String> fieldNames; private ArrayList<String> inFieldNames; public StxOutMessage(int _row, int _column, String _inMessage) { super(_row, _column); inMessage = _inMessage; fieldNames = new ArrayList<String>(); inFieldNames = new ArrayList<String>(); } public StxOutMessage(String _inMessage) { super(); inMessage = _inMessage; fieldNames = new ArrayList<String>(); inFieldNames = new ArrayList<String>(); } public boolean addField(String fieldName, String inFieldName){ boolean result = true; for (String fld : fieldNames) result &= (! fld.equals(fieldName)); for (String fld : inFieldNames) result &= (! fld.equals(inFieldName)); if (result) { fieldNames.add(fieldName); inFieldNames.add(inFieldName); } return result; } public String getInMessage() { return inMessage; } public int getSize() { return fieldNames.size(); } public String getFieldName(int i) { return fieldNames.get(i);} public String getFieldType(int i) { return inFieldNames.get(i);} } public class StxStartState {} public class StxStopState {} public class StxStandardState {} public class StxRandomState {} public class StxCountState {} public class StxSendState {} public class StxReceiveState {} public class StxPresendState {} public class StxPrereceiveState {} public class StxSetTimerState {} public class StxResetTimerState {} public class StxExpireTimerState {} public class StxPresetTimerState {} public class StxPreresetTimerState {} public class StxPreexpireTimerState {} public class StxTimerBlock {} public class StxTimerRelation {} public class StxSetTimerChannel {} public class StxResetTimerChannel {} public class StxExpireTimerChannel {} public class StxTransition {} public class StxStateMachine {} }