diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/WebServiceEditor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/WebServiceEditor.java index 124e0b7..f6c02aa 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/WebServiceEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/WebServiceEditor.java @@ -1,5 +1,7 @@ package graphicalrefactor.editor; +import static org.junit.Assert.assertThrows; + import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; @@ -11,6 +13,7 @@ import algorithms.UpdateConflictCheck; import models.dataFlowModel.DataFlowModel; +import models.webServices.Service; import models.webServices.WebServicesInfo; import parser.ParserDTRAM; import parser.ParserDTRAMForWebService; @@ -43,7 +46,7 @@ */ public class WebServiceEditor extends Editor{ - private WebServicesInfo webServices = null; + private WebServicesInfo webServicesInfo = null; /**-------------------------------------------------------------------------------- * [Constructor] @@ -54,12 +57,11 @@ */ public WebServiceEditor(final mxGraph graph) { super(graph); - - this.webServices = new WebServicesInfo(this.model); + this.webServicesInfo = new WebServicesInfo(); } /**-------------------------------------------------------------------------------- - * public + * [public] /**-------------------------------------------------------------------------------- /** * @param file @@ -102,4 +104,13 @@ return null; } + + /**-------------------------------------------------------------------------------- + * add service to webServicesInfo + * + */ + public void addService(Service service) { + if(this.webServicesInfo == null) new NullPointerException("webServicesInfo is null"); + this.webServicesInfo = this.webServicesInfo.addService(service); + } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/webServices/Service.java b/AlgebraicDataflowArchitectureModel/src/models/webServices/Service.java index 65757c8..08e19b9 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/webServices/Service.java +++ b/AlgebraicDataflowArchitectureModel/src/models/webServices/Service.java @@ -9,82 +9,75 @@ private String name = null; private String baseURL = null; private ArrayList identifireTemplates = null; - - /** - * [Constructor] - * identifireTemplates are Empty - * - * @param name : it's Web services name. - * - */ + + /**-------------------------------------------------------------------------------- + * [Constructor] + /**-------------------------------------------------------------------------------- + * identifireTemplates are Empty + * + * @param name : it's Web services name. + */ public Service(final String name, final String baseURL) { this.name = name; this.baseURL = baseURL; this.identifireTemplates = new ArrayList<>(); } - /** - * [Copy Constructor] - * - * @param name : it's Web services name. - * - */ + /**-------------------------------------------------------------------------------- + * + * @param name : it's Web services name. + * @param identifierTemplates : the list of resources which formal model of DTRAM. + */ + public Service(final String name, final ArrayList identifierTemplates) { + this.name = name; + this.identifireTemplates = identifierTemplates; + } + + /**-------------------------------------------------------------------------------- + * Copy Constructor + * + * @param name : it's Web services name. + */ private Service(final Service copy) { this.name = copy.name; this.baseURL = copy.baseURL; this.identifireTemplates = copy.identifireTemplates; } - - - /** - * [Constructor] - * - * @param name : it's Web services name. - * @param identifierTemplates : the list of resources which formal model of DTRAM. - */ - public Service(final String name, final ArrayList identifierTemplates) { - this.name = name; - this.identifireTemplates = identifierTemplates; - } - - /** - * [getter] - * - * @return you'll get name of service. - */ + + /**-------------------------------------------------------------------------------- + * [public] + /**-------------------------------------------------------------------------------- + * [getter] + * + * @return you'll get name of service. + */ public String getName() { return this.name; } - /** - * [getter] - * - * @return you'll get services's baseURL - */ + /**-------------------------------------------------------------------------------- + * @return you'll get services's baseURL + */ public String getBaseURL() { return this.baseURL; } - - /** - * [getter] - * - * @return you'll get list of an identifier template. - */ + + /**-------------------------------------------------------------------------------- + * @return you'll get list of an identifier template. + */ public List getIdentifierTemplates(){ return this.identifireTemplates; } - /** - * [public] - * add new to List - * - * @param identifierTemplate - * - * @return - */ + /**-------------------------------------------------------------------------------- + * add new to List + * + * @param identifierTemplate + * + * @return new instance of "Service" + */ public Service addIdentifireTemplate(final IdentifierTemplate identifierTemplate) { this.identifireTemplates.add(identifierTemplate); - return new Service(this); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/webServices/WebServicesInfo.java b/AlgebraicDataflowArchitectureModel/src/models/webServices/WebServicesInfo.java index f10fa8b..1799ea6 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/webServices/WebServicesInfo.java +++ b/AlgebraicDataflowArchitectureModel/src/models/webServices/WebServicesInfo.java @@ -3,29 +3,30 @@ import java.util.ArrayList; import java.util.List; -import models.dataConstraintModel.IdentifierTemplate; -import models.dataFlowModel.DataFlowModel; - public class WebServicesInfo { - + private ArrayList services = null; - - /** - * [Constructor] - * - * @param dataFlowModel : get identifireTemplates and initialize each services. + + /**-------------------------------------------------------------------------------- + * [Constructor] + /**-------------------------------------------------------------------------------- * */ - public WebServicesInfo(final DataFlowModel dataFlowModel) - { + public WebServicesInfo() { this.services = new ArrayList<>(); - -// for (IdentifierTemplate identifireTemplate : dataFlowModel.getIdentifierTemplates()) { -// this.services.add(new Service(identifireTemplate.getResourceName())); -// } } - /** + /**-------------------------------------------------------------------------------- + * copy constructor + */ + private WebServicesInfo(final WebServicesInfo webServicesInfo) { + this.services = webServicesInfo.services; + } + + + /**-------------------------------------------------------------------------------- + * [public] + /**-------------------------------------------------------------------------------- * [getter] * * @return you'll get list of a service. @@ -33,4 +34,16 @@ public List getServices(){ return this.services; } + + /**-------------------------------------------------------------------------------- + * [setter] + * + * @param service + * + * @return added instance + */ + public WebServicesInfo addService(final Service serive) { + this.services.add(serive); + return new WebServicesInfo(this); + } } diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index 1bf402b..df161a3 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -56,8 +56,8 @@ public static final String ASSIGNMENT = "="; public static final String COMMA = ","; public static final String COLON = ":"; - - + + public DataFlowModel doParse(final BufferedReader reader) throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment { TokenStream stream = new TokenStream(); @@ -71,7 +71,7 @@ e.printStackTrace(); return null; } - + return parseDataFlowModel(stream); } @@ -104,7 +104,7 @@ if (!stream.hasNext()) throw new ExpectedChannelName(stream.getLine()); String channelName = stream.next(); if (channelName.equals(LEFT_CURLY_BRACKET)) throw new ExpectedChannelName(stream.getLine()); - + int fromLine = stream.getLine(); DataflowChannelGenerator channel = new DataflowChannelGenerator(channelName); String leftBracket = stream.next(); @@ -148,20 +148,20 @@ identifier = new IdentifierTemplate(resourceName, 0); model.addIdentifierTemplate(identifier); } - + if (!stream.hasNext()) throw new ExpectedAssignment(stream.getLine()); String colon = stream.next(); if (!colon.equals(COLON)) throw new ExpectedAssignment(stream.getLine()); if (!stream.hasNext()) throw new ExpectedAssignment(stream.getLine()); String equals = stream.next(); if (!equals.equals(ASSIGNMENT)) throw new ExpectedAssignment(stream.getLine()); - + int toLine = stream.getLine(); Expression rightTerm = null; if (!stream.hasNext()) throw new ExpectedRHSExpression(stream.getLine()); rightTerm = parseTerm(stream, model); if (rightTerm == null) throw new WrongRHSExpression(stream.getLine()); - + identifier.setInitialValue(rightTerm); identifier.setInitText(stream.getSourceText(fromLine, toLine)); } @@ -173,17 +173,17 @@ Expression leftTerm = parseTerm(stream, model); if (leftTerm == null || !(leftTerm instanceof Term)) throw new WrongLHSExpression(stream.getLine()); Expression rightTerm = null; - + if (!inOrOutOrRef.equals(REF)) { if (!stream.hasNext()) throw new ExpectedEquals(stream.getLine()); String equals = stream.next(); if (!equals.equals(EQUALS)) throw new ExpectedEquals(stream.getLine()); - + if (!stream.hasNext()) throw new ExpectedRHSExpression(stream.getLine()); rightTerm = parseTerm(stream, model); if (rightTerm == null) throw new WrongRHSExpression(stream.getLine()); } - + String resourceName = ((Term) leftTerm).getSymbol().getName(); IdentifierTemplate identifier = model.getIdentifierTemplate(resourceName); if (identifier == null) { @@ -219,7 +219,7 @@ } return channelMember; } - + public Expression parseTerm(final TokenStream stream, final DataFlowModel model) throws ExpectedRightBracket { ArrayList expressions = new ArrayList<>(); ArrayList operators = new ArrayList<>(); @@ -351,17 +351,35 @@ return firstMonomial; } + /**-------------------------------------------------------------------------------- + * [protected] + /**-------------------------------------------------------------------------------- + * checking the token has a token. + * + * @param token + * @param specificTokenName + */ + protected Boolean isMatchSpecificToken(final String token, final String specificTokenName) { + if(token == null) return false; + return (token.equals(specificTokenName)); + } + + /**-------------------------------------------------------------------------------- + * [inner class] + * + * "TokenStream" has a token what is readed from description of "Architecture Language Model". + */ public class TokenStream { private ArrayList> tokens = new ArrayList<>(); private ArrayList lines = new ArrayList<>(); private int line = 0; private int n = 0; - + public TokenStream() { line = 0; n = 0; } - + public void addLine(String line) { lines.add(line); line = line.trim(); @@ -401,7 +419,7 @@ RIGHT_CURLY_BRACKET, RIGHT_CURLY_BRACKET_REGX)); } - + private ArrayList splitBy(final List tokens, final String delimiter, final String delimiterRegx) { ArrayList newTokens = new ArrayList<>(); for (String token: tokens) { @@ -423,7 +441,7 @@ } return newTokens; } - + public String next() { if (line >= tokens.size()) return null; while (n >= tokens.get(line).size()) { @@ -435,7 +453,7 @@ n++; return token; } - + public String checkNext() { if (line >= tokens.size()) return null; while (n >= tokens.get(line).size()) { @@ -445,7 +463,7 @@ } return tokens.get(line).get(n); } - + public boolean hasNext() { if (line >= tokens.size()) return false; while (n >= tokens.get(line).size()) { @@ -455,11 +473,11 @@ } return true; } - + public int getLine() { return line; } - + public String getSourceText(int from, int to) { String text = ""; for (int l = from; l <= to; l++) { diff --git a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java index 16e6702..854694a 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAM.java @@ -2,8 +2,6 @@ import java.io.BufferedReader; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; @@ -12,7 +10,6 @@ import com.mxgraph.view.mxGraph; import com.mxgraph.view.mxGraphView; - import models.dataFlowModel.DataFlowModel; import parser.exceptions.ExpectedAssignment; import parser.exceptions.ExpectedChannel; @@ -36,13 +33,13 @@ protected TokenStream stream = null; - private static final String MODEL = "model"; - private static final String GEOMETRY = "geometry"; - private static final String NODE = "node"; - private static final String RESOURCE = "r"; - private static final String CHANNEL = "c"; - private static final String FORMULA_CHANNEL = "fc"; - private static final String IO_CHANNEL = "ioc"; + private final String MODEL = "model"; + private final String GEOMETRY = "geometry"; + private final String NODE = "node"; + private final String RESOURCE = "r"; + private final String CHANNEL = "c"; + private final String FORMULA_CHANNEL = "fc"; + private final String IO_CHANNEL = "ioc"; /**-------------------------------------------------------------------------------- * @@ -84,30 +81,20 @@ private DataFlowModel getParsedModel(final TokenStream stream) throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment, ExpectedModel, ExpectedGeometry { - if (!stream.hasNext()) { - return null; - } + if (!stream.hasNext()) throw new NullPointerException(); String modelKeyword = stream.next(); - if (!modelKeyword.equals(MODEL)) { - throw new ExpectedModel(stream.getLine()); - } - - if (!stream.hasNext()) { - throw new ExpectedModel(stream.getLine()); - } + if (!modelKeyword.equals(MODEL)) throw new ExpectedModel(stream.getLine()); + if (!stream.hasNext()) throw new ExpectedModel(stream.getLine()); String leftBracket = stream.next(); - if (!leftBracket.equals(LEFT_CURLY_BRACKET)) { - throw new ExpectedLeftCurlyBracket(stream.getLine()); - } - + if (!leftBracket.equals(LEFT_CURLY_BRACKET)) throw new ExpectedLeftCurlyBracket(stream.getLine()); + DataFlowModel model = parseDataFlowModel(stream); String rightBracket = stream.next(); - if(!rightBracket.equals(RIGHT_CURLY_BRACKET)) { - throw new ExpectedRightBracket(stream.getLine()); - } + if(!rightBracket.equals(RIGHT_CURLY_BRACKET))throw new ExpectedRightBracket(stream.getLine()); + return model; } @@ -119,41 +106,44 @@ private void parseGeometry(final TokenStream stream, final mxGraph graph) throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment,ExpectedModel, ExpectedGeometry, ExpectedNode, ExpectedResource, ExpectedFormulaChannel, ExpectedIoChannel { - String geometry = stream.next(); - if (!geometry.equals(GEOMETRY)) { - throw new ExpectedGeometry(stream.getLine()); - } + String geometoryToken = stream.next(); + if(!geometoryToken.equals(GEOMETRY)) throw new ExpectedGeometry(stream.getLine()); - String leftBracket = stream.next(); - if(!leftBracket.equals(LEFT_CURLY_BRACKET)) { - throw new ExpectedLeftCurlyBracket(stream.getLine()); - } + String leftCurlyBracketToken = stream.next(); + if(!leftCurlyBracketToken.equals(LEFT_CURLY_BRACKET)) throw new ExpectedLeftCurlyBracket(stream.getLine()); String node = stream.next(); while (node.equals(NODE)) { + String rOrFcOrIocOrC = stream.next(); - if (!rOrFcOrIocOrC.equals(RESOURCE) &&!rOrFcOrIocOrC.equals(FORMULA_CHANNEL) &&!rOrFcOrIocOrC.equals(IO_CHANNEL) &&!rOrFcOrIocOrC.equals(CHANNEL)) { + if(!rOrFcOrIocOrC.equals(RESOURCE) + && !rOrFcOrIocOrC.equals(FORMULA_CHANNEL) + && !rOrFcOrIocOrC.equals(CHANNEL) + && !rOrFcOrIocOrC.equals(IO_CHANNEL)) throw new ExpectedNode(stream.getLine()); - } String name = stream.next(); - String colon = stream.next(); + String colonToken = stream.next(); + if(!colonToken.equals(COLON)) throw new ExpectedAssignment(stream.getLine()); String x = stream.next(); - int xC = Integer.parseInt(x); // C = Coordinate(���W) + int xC = Integer.parseInt(x); // C = Coordinate(x,y,w,h) - String comma1 = stream.next(); + String commaToken = stream.next(); + if(!commaToken.equals(COMMA))throw new ExpectedAssignment(stream.getLine()); String y = stream.next(); int yC = Integer.parseInt(y); - String comma2 = stream.next(); + commaToken = stream.next(); + if(!commaToken.equals(COMMA))throw new ExpectedAssignment(stream.getLine()); String w = stream.next(); int wC = Integer.parseInt(w); - String comma3 = stream.next(); + commaToken = stream.next(); + if(!commaToken.equals(COMMA))throw new ExpectedAssignment(stream.getLine()); String h = stream.next(); int hC = Integer.parseInt(h); @@ -161,23 +151,24 @@ Object root = graph.getDefaultParent(); mxIGraphModel graphModel = graph.getModel(); for (int i = 0; i < graph.getModel().getChildCount(root); i++) { + Object cell = graph.getModel().getChildAt(root, i); - if (graph.getModel().isVertex(cell)) { - mxGeometry geom = (mxGeometry) ((mxCell) cell).getGeometry().clone(); - mxGraphView view = graph.getView(); - mxCellState state = view.getState(cell); - if (name.equals(state.getLabel())){ - geom.setX(xC); - geom.setY(yC); - graphModel.setGeometry(cell, geom); - } - } + if (!graph.getModel().isVertex(cell)) continue; + + mxGeometry geom = (mxGeometry) ((mxCell) cell).getGeometry().clone(); + mxGraphView view = graph.getView(); + mxCellState state = view.getState(cell); + + if (!name.equals(state.getLabel())) continue; + + geom.setX(xC); + geom.setY(yC); + graphModel.setGeometry(cell, geom); } node = stream.next(); } - if (!node.equals(RIGHT_CURLY_BRACKET)) { - throw new ExpectedRightBracket(stream.getLine()); - } + + if(!node.equals(RIGHT_CURLY_BRACKET)) throw new ExpectedRightBracket(stream.getLine()); } } diff --git a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAMForWebService.java b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAMForWebService.java index d9e150e..bfbcde2 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAMForWebService.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/ParserDTRAMForWebService.java @@ -13,13 +13,13 @@ public class ParserDTRAMForWebService extends ParserDTRAM { - private static final String SERVICES = "services"; - private static final String SERVICE = "service"; - private static final String BASE_URL = "baseURL"; - private static final String RESOURCES = "resources"; + private final String SERVICES = "services"; + private final String SERVICE = "service"; + private final String BASE_URL = "baseURL"; + private final String RESOURCES = "resources"; /**-------------------------------------------------------------------------------- - * public + * [public] /**-------------------------------------------------------------------------------- * execute to parse the DTRAM file. * @@ -34,7 +34,7 @@ } /**-------------------------------------------------------------------------------- - * private + * [private] /**-------------------------------------------------------------------------------- * parse to Web service's options in the DTRAM file. * @@ -44,78 +44,45 @@ throws ExpectedWebService, ExpectedBaseURL, ExpectedResources, ExpectedLeftCurlyBracket, ExpectedRightBracket, ExpectedAssignment { - // check the token name is "services" - if(!hasSpecificToken(stream.next(), SERVICES)) - throw new ExpectedWebService(stream.getLine()); + if(!isMatchSpecificToken(stream.next(),SERVICES)) throw new ExpectedWebService(stream.getLine()); + if(!isMatchSpecificToken(stream.next(),LEFT_CURLY_BRACKET)) throw new ExpectedLeftCurlyBracket(stream.getLine()); - // check the token is "{" - if(!hasSpecificToken(stream.next(), LEFT_CURLY_BRACKET)) - throw new ExpectedLeftCurlyBracket(stream.getLine()); - - while(true) { - if(!hasSpecificToken(stream.checkNext(), SERVICE)) break; + String serviceTokenNode = stream.next(); + while(isMatchSpecificToken(serviceTokenNode, SERVICE)) { - stream.next(); // advance to stream's index - - String name = stream.next(); // it gets a service name here. + String serviceName = stream.next(); // it gets a service name here. - // check the token is "{" - if(!hasSpecificToken(stream.next(), LEFT_CURLY_BRACKET)) - throw new ExpectedLeftCurlyBracket(stream.getLine()); + if(!isMatchSpecificToken(stream.next(), LEFT_CURLY_BRACKET)) throw new ExpectedLeftCurlyBracket(stream.getLine()); + if(!isMatchSpecificToken(stream.next(), BASE_URL)) throw new ExpectedBaseURL(stream.getLine()); + if(!isMatchSpecificToken(stream.next(), COLON)) throw new ExpectedAssignment(stream.getLine()); - // check the token is "baseURL" - if(!hasSpecificToken(stream.next(), BASE_URL)) - throw new ExpectedBaseURL(stream.getLine()); + String baseURL = stream.next(); // it gets a service's base URL here. - // check the token is ":" - if(!hasSpecificToken(stream.next(), COLON)) - throw new ExpectedAssignment(stream.getLine()); + if(!isMatchSpecificToken(stream.next(), RESOURCES)) throw new ExpectedResources(stream.getLine()); + if(!isMatchSpecificToken(stream.next(), COLON)) throw new ExpectedAssignment(stream.getLine()); - // it gets a service's base URL here. - String baseURL = stream.next(); - - // check the token is "resources" - if(!hasSpecificToken(stream.next(), RESOURCES)) - throw new ExpectedResources(stream.getLine()); - - // check the token is ":" - if(!hasSpecificToken(stream.next(), COLON)) - throw new ExpectedAssignment(stream.getLine()); - - // get service - Service service = new Service(name, baseURL); - String resourceName = ""; + // get specific resources from DataFlowModel. + Service service = new Service(serviceName, baseURL); while(true) { - // get here. - resourceName = stream.next(); + // generate here. + String resourceName = stream.next(); IdentifierTemplate identifierTemplate = model.getIdentifierTemplate(resourceName); + service = service.addIdentifireTemplate(identifierTemplate); - - // check the token is "," - if(!hasSpecificToken(stream.checkNext(), COMMA)) break; - - stream.next(); // advance to stream's index + + if(!isMatchSpecificToken(stream.checkNext(), COMMA)) break; + + stream.next(); // advance to next token } + + editor.addService(service); // reflect to instance of "WebServiceEditor". - // check the token is "}" - if(!hasSpecificToken(stream.next(), RIGHT_CURLY_BRACKET)) - throw new ExpectedRightBracket(stream.getLine()); + if(!isMatchSpecificToken(stream.next(), RIGHT_CURLY_BRACKET)) throw new ExpectedRightBracket(stream.getLine()); + + serviceTokenNode = stream.next(); // store "}" token. } - // check the token is "}" - if(!hasSpecificToken(stream.next(), RIGHT_CURLY_BRACKET)) - throw new ExpectedRightBracket(stream.getLine()); - } - - /**-------------------------------------------------------------------------------- - * checking the token has a token. - * - * @param token - * @param specificTokenName - */ - private Boolean hasSpecificToken(final String token, final String specificTokenName) { - if(token == null) return false; - return (token.equals(specificTokenName)); + if(!isMatchSpecificToken(serviceTokenNode, RIGHT_CURLY_BRACKET)) throw new ExpectedRightBracket(stream.getLine()); } }