summaryrefslogtreecommitdiff
path: root/src/net/sourceforge/plantuml/objectdiagram
diff options
context:
space:
mode:
authorAndrew Shadura <andrew@shadura.me>2015-07-21 14:52:03 +0200
committerAndrew Shadura <andrew@shadura.me>2015-07-21 14:52:03 +0200
commit26b872bb194ec7622997914bba53309a94b64d20 (patch)
treea79b966bf55dd61702b900b8ba40be4d2b3403db /src/net/sourceforge/plantuml/objectdiagram
Imported Upstream version 8024
Diffstat (limited to 'src/net/sourceforge/plantuml/objectdiagram')
-rw-r--r--src/net/sourceforge/plantuml/objectdiagram/AbstractClassOrObjectDiagram.java235
-rw-r--r--src/net/sourceforge/plantuml/objectdiagram/ObjectDiagram.java59
-rw-r--r--src/net/sourceforge/plantuml/objectdiagram/ObjectDiagramFactory.java106
-rw-r--r--src/net/sourceforge/plantuml/objectdiagram/command/CommandAddData.java63
-rw-r--r--src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateEntityObject.java97
-rw-r--r--src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateEntityObjectMultilines.java115
6 files changed, 675 insertions, 0 deletions
diff --git a/src/net/sourceforge/plantuml/objectdiagram/AbstractClassOrObjectDiagram.java b/src/net/sourceforge/plantuml/objectdiagram/AbstractClassOrObjectDiagram.java
new file mode 100644
index 0000000..2d72917
--- /dev/null
+++ b/src/net/sourceforge/plantuml/objectdiagram/AbstractClassOrObjectDiagram.java
@@ -0,0 +1,235 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.objectdiagram;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
+import net.sourceforge.plantuml.cucadiagram.Code;
+import net.sourceforge.plantuml.cucadiagram.Display;
+import net.sourceforge.plantuml.cucadiagram.IEntity;
+import net.sourceforge.plantuml.cucadiagram.LeafType;
+import net.sourceforge.plantuml.cucadiagram.Link;
+import net.sourceforge.plantuml.cucadiagram.LinkDecor;
+import net.sourceforge.plantuml.cucadiagram.LinkType;
+import net.sourceforge.plantuml.utils.UniqueSequence;
+
+public abstract class AbstractClassOrObjectDiagram extends AbstractEntityDiagram {
+
+ final public boolean insertBetween(IEntity entity1, IEntity entity2, IEntity node) {
+ final Link link = foundLink(entity1, entity2);
+ if (link == null) {
+ return false;
+ }
+ final Link l1 = new Link(entity1, node, link.getType(), link.getLabel(), link.getLength(),
+ link.getQualifier1(), null, link.getLabeldistance(), link.getLabelangle());
+ final Link l2 = new Link(node, entity2, link.getType(), link.getLabel(), link.getLength(), null,
+ link.getQualifier2(), link.getLabeldistance(), link.getLabelangle());
+ addLink(l1);
+ addLink(l2);
+ removeLink(link);
+ return true;
+ }
+
+ private Link foundLink(IEntity entity1, IEntity entity2) {
+ final List<Link> links = getLinks();
+ for (int i = links.size() - 1; i >= 0; i--) {
+ final Link l = links.get(i);
+ if (l.isBetween(entity1, entity2)) {
+ return l;
+ }
+ }
+ return null;
+ }
+
+ public int getNbOfHozizontalLollipop(IEntity entity) {
+ if (entity.getEntityType() == LeafType.LOLLIPOP) {
+ throw new IllegalArgumentException();
+ }
+ int result = 0;
+ for (Link link : getLinks()) {
+ if (link.getLength() == 1 && link.contains(entity) && link.containsType(LeafType.LOLLIPOP)) {
+ result++;
+ }
+
+ }
+ return result;
+ }
+
+ private final List<Association> assocations = new ArrayList<Association>();
+
+ public boolean associationClass(int mode, Code clName1, Code clName2, IEntity associed, LinkType linkType,
+ Display label) {
+ final IEntity entity1 = getOrCreateLeaf(clName1, null, null);
+ final IEntity entity2 = getOrCreateLeaf(clName2, null, null);
+ final List<Association> same = new ArrayList<Association>();
+ for (Association existing : assocations) {
+ if (existing.sameCouple(entity1, entity2)) {
+ same.add(existing);
+ }
+ }
+ if (same.size() > 1) {
+ return false;
+ } else if (same.size() == 0) {
+ final Association association = new Association(mode, entity1, entity2, associed);
+ association.createNew(mode, linkType, label);
+
+ this.assocations.add(association);
+ return true;
+ }
+ assert same.size() == 1;
+ final Association association = same.get(0).createSecondAssociation(mode, associed, label);
+ association.createInSecond(linkType, label);
+
+ this.assocations.add(association);
+ return true;
+ }
+
+ class Association {
+ private IEntity entity1;
+ private IEntity entity2;
+ private IEntity associed;
+ private IEntity point;
+
+ private Link existingLink;
+
+ private Link entity1ToPoint;
+ private Link pointToEntity2;
+ private Link pointToAssocied;
+
+ private Association other;
+
+ public Association(int mode, IEntity entity1, IEntity entity2, IEntity associed) {
+ this.entity1 = entity1;
+ this.entity2 = entity2;
+ this.associed = associed;
+ point = getOrCreateLeaf(UniqueSequence.getCode("apoint"), LeafType.POINT_FOR_ASSOCIATION, null);
+
+ }
+
+ public Association createSecondAssociation(int mode2, IEntity associed2, Display label) {
+ final Association result = new Association(mode2, entity1, entity2, associed2);
+ result.existingLink = this.existingLink;
+ result.other = this;
+
+ if (this.existingLink.getLength() == 1) {
+ this.entity1ToPoint.setLength(2);
+ this.pointToEntity2.setLength(2);
+ this.pointToAssocied.setLength(1);
+ }
+ return result;
+ }
+
+ void createNew(int mode, LinkType linkType, Display label) {
+ existingLink = foundLink(entity1, entity2);
+ if (existingLink == null) {
+ existingLink = new Link(entity1, entity2, new LinkType(LinkDecor.NONE, LinkDecor.NONE), null,
+ 2);
+ } else {
+ removeLink(existingLink);
+ }
+
+ entity1ToPoint = new Link(entity1, point, existingLink.getType().getPart2(), existingLink.getLabel(),
+ existingLink.getLength(), existingLink.getQualifier1(), null, existingLink.getLabeldistance(),
+ existingLink.getLabelangle());
+ entity1ToPoint.setLinkArrow(existingLink.getLinkArrow());
+ pointToEntity2 = new Link(point, entity2, existingLink.getType().getPart1(), null,
+ existingLink.getLength(), null, existingLink.getQualifier2(), existingLink.getLabeldistance(),
+ existingLink.getLabelangle());
+ addLink(entity1ToPoint);
+ addLink(pointToEntity2);
+
+ int length = 1;
+ if (existingLink.getLength() == 1 && entity1 != entity2) {
+ length = 2;
+ }
+ if (existingLink.getLength() == 2 && entity1 == entity2) {
+ length = 2;
+ }
+
+ if (mode == 1) {
+ pointToAssocied = new Link(point, associed, linkType, label, length);
+ } else {
+ pointToAssocied = new Link(associed, point, linkType, label, length);
+ }
+ addLink(pointToAssocied);
+ }
+
+ void createInSecond(LinkType linkType, Display label) {
+ existingLink = foundLink(entity1, entity2);
+ if (existingLink == null) {
+ existingLink = new Link(entity1, entity2, new LinkType(LinkDecor.NONE, LinkDecor.NONE), null,
+ 2);
+ } else {
+ removeLink(existingLink);
+ }
+
+ entity1ToPoint = new Link(entity1, point, existingLink.getType().getPart2(), existingLink.getLabel(), 2,
+ existingLink.getQualifier1(), null, existingLink.getLabeldistance(), existingLink.getLabelangle());
+ pointToEntity2 = new Link(point, entity2, existingLink.getType().getPart1(), null, 2, null,
+ existingLink.getQualifier2(), existingLink.getLabeldistance(), existingLink.getLabelangle());
+ // entity1ToPoint = new Link(entity1, point, existingLink.getType(),
+ // null, 2);
+ // pointToEntity2 = new Link(point, entity2, existingLink.getType(),
+ // null, 2);
+ addLink(entity1ToPoint);
+ addLink(pointToEntity2);
+ if (other.pointToAssocied.getEntity1().getEntityType() == LeafType.POINT_FOR_ASSOCIATION) {
+ removeLink(other.pointToAssocied);
+ other.pointToAssocied = other.pointToAssocied.getInv();
+ addLink(other.pointToAssocied);
+ }
+ pointToAssocied = new Link(point, associed, linkType, label, 1);
+ addLink(pointToAssocied);
+
+ final Link lnode = new Link(other.point, this.point, new LinkType(LinkDecor.NONE, LinkDecor.NONE), null, 1);
+ lnode.setInvis(true);
+ addLink(lnode);
+
+ }
+
+ boolean sameCouple(IEntity entity1, IEntity entity2) {
+ if (this.entity1 == entity1 && this.entity2 == entity2) {
+ return true;
+ }
+ if (this.entity1 == entity2 && this.entity2 == entity1) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+}
diff --git a/src/net/sourceforge/plantuml/objectdiagram/ObjectDiagram.java b/src/net/sourceforge/plantuml/objectdiagram/ObjectDiagram.java
new file mode 100644
index 0000000..eb85c76
--- /dev/null
+++ b/src/net/sourceforge/plantuml/objectdiagram/ObjectDiagram.java
@@ -0,0 +1,59 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.objectdiagram;
+
+import net.sourceforge.plantuml.UmlDiagramType;
+import net.sourceforge.plantuml.cucadiagram.Code;
+import net.sourceforge.plantuml.cucadiagram.ILeaf;
+import net.sourceforge.plantuml.cucadiagram.LeafType;
+import net.sourceforge.plantuml.graphic.USymbol;
+
+public class ObjectDiagram extends AbstractClassOrObjectDiagram {
+
+ @Override
+ public ILeaf getOrCreateLeaf(Code code, LeafType type, USymbol symbol) {
+ if (type == null) {
+ type = LeafType.OBJECT;
+ }
+ return getOrCreateLeafDefault(code, type, symbol);
+ }
+
+ @Override
+ public UmlDiagramType getUmlDiagramType() {
+ return UmlDiagramType.OBJECT;
+ }
+
+
+}
diff --git a/src/net/sourceforge/plantuml/objectdiagram/ObjectDiagramFactory.java b/src/net/sourceforge/plantuml/objectdiagram/ObjectDiagramFactory.java
new file mode 100644
index 0000000..58b6e48
--- /dev/null
+++ b/src/net/sourceforge/plantuml/objectdiagram/ObjectDiagramFactory.java
@@ -0,0 +1,106 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.objectdiagram;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.plantuml.UmlDiagramType;
+import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass;
+import net.sourceforge.plantuml.classdiagram.command.CommandUrl;
+import net.sourceforge.plantuml.command.Command;
+import net.sourceforge.plantuml.command.CommandEndPackage;
+import net.sourceforge.plantuml.command.CommandFootboxIgnored;
+import net.sourceforge.plantuml.command.CommandPackage;
+import net.sourceforge.plantuml.command.CommandPage;
+import net.sourceforge.plantuml.command.CommandRankDir;
+import net.sourceforge.plantuml.command.UmlDiagramFactory;
+import net.sourceforge.plantuml.command.note.FactoryNoteCommand;
+import net.sourceforge.plantuml.command.note.FactoryNoteOnEntityCommand;
+import net.sourceforge.plantuml.command.note.FactoryNoteOnLinkCommand;
+import net.sourceforge.plantuml.command.regex.RegexLeaf;
+import net.sourceforge.plantuml.objectdiagram.command.CommandAddData;
+import net.sourceforge.plantuml.objectdiagram.command.CommandCreateEntityObject;
+import net.sourceforge.plantuml.objectdiagram.command.CommandCreateEntityObjectMultilines;
+
+public class ObjectDiagramFactory extends UmlDiagramFactory {
+
+ @Override
+ protected List<Command> createCommands() {
+
+ final List<Command> cmds = new ArrayList<Command>();
+ cmds.add(new CommandFootboxIgnored());
+
+ addCommonCommands(cmds);
+ cmds.add(new CommandRankDir());
+ cmds.add(new CommandPage());
+ cmds.add(new CommandAddData());
+ cmds.add(new CommandLinkClass(UmlDiagramType.OBJECT));
+ //
+ cmds.add(new CommandCreateEntityObject());
+ final FactoryNoteCommand factoryNoteCommand = new FactoryNoteCommand();
+
+ cmds.add(factoryNoteCommand.createSingleLine());
+ cmds.add(new CommandPackage());
+ cmds.add(new CommandEndPackage());
+ // addCommand(new CommandNamespace());
+ // addCommand(new CommandEndNamespace());
+ // addCommand(new CommandStereotype());
+ //
+ // addCommand(new CommandImport());
+ final FactoryNoteOnEntityCommand factoryNoteOnEntityCommand = new FactoryNoteOnEntityCommand(new RegexLeaf(
+ "ENTITY", "([\\p{L}0-9_.]+|[%g][^%g]+[%g])"));
+ cmds.add(factoryNoteOnEntityCommand.createSingleLine());
+
+ cmds.add(new CommandUrl());
+
+ cmds.add(factoryNoteCommand.createMultiLine());
+ cmds.add(factoryNoteOnEntityCommand.createMultiLine());
+ cmds.add(new CommandCreateEntityObjectMultilines());
+
+ final FactoryNoteOnLinkCommand factoryNoteOnLinkCommand = new FactoryNoteOnLinkCommand();
+ cmds.add(factoryNoteOnLinkCommand.createSingleLine());
+ cmds.add(factoryNoteOnLinkCommand.createMultiLine());
+
+ // addCommand(new CommandNoopClass());
+ return cmds;
+
+ }
+
+ @Override
+ public ObjectDiagram createEmptyDiagram() {
+ return new ObjectDiagram();
+ }
+}
diff --git a/src/net/sourceforge/plantuml/objectdiagram/command/CommandAddData.java b/src/net/sourceforge/plantuml/objectdiagram/command/CommandAddData.java
new file mode 100644
index 0000000..70f9fce
--- /dev/null
+++ b/src/net/sourceforge/plantuml/objectdiagram/command/CommandAddData.java
@@ -0,0 +1,63 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.objectdiagram.command;
+
+import java.util.List;
+
+import net.sourceforge.plantuml.command.CommandExecutionResult;
+import net.sourceforge.plantuml.command.SingleLineCommand;
+import net.sourceforge.plantuml.cucadiagram.Code;
+import net.sourceforge.plantuml.cucadiagram.IEntity;
+import net.sourceforge.plantuml.objectdiagram.ObjectDiagram;
+import net.sourceforge.plantuml.skin.VisibilityModifier;
+
+public class CommandAddData extends SingleLineCommand<ObjectDiagram> {
+
+ public CommandAddData() {
+ super("(?i)^([\\p{L}0-9_.]+)[%s]*:[%s]*(.*)$");
+ }
+
+ @Override
+ protected CommandExecutionResult executeArg(ObjectDiagram diagram, List<String> arg) {
+ final IEntity entity = diagram.getOrCreateLeaf(Code.of(arg.get(0)), null, null);
+
+ final String field = arg.get(1);
+ if (field.length() > 0 && VisibilityModifier.isVisibilityCharacter(field.charAt(0))) {
+ diagram.setVisibilityModifierPresent(true);
+ }
+ entity.addFieldOrMethod(field);
+ return CommandExecutionResult.ok();
+ }
+}
diff --git a/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateEntityObject.java b/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateEntityObject.java
new file mode 100644
index 0000000..a3f284c
--- /dev/null
+++ b/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateEntityObject.java
@@ -0,0 +1,97 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.objectdiagram.command;
+
+import net.sourceforge.plantuml.FontParam;
+import net.sourceforge.plantuml.Url;
+import net.sourceforge.plantuml.UrlBuilder;
+import net.sourceforge.plantuml.UrlBuilder.ModeUrl;
+import net.sourceforge.plantuml.command.CommandExecutionResult;
+import net.sourceforge.plantuml.command.SingleLineCommand2;
+import net.sourceforge.plantuml.command.regex.RegexConcat;
+import net.sourceforge.plantuml.command.regex.RegexLeaf;
+import net.sourceforge.plantuml.command.regex.RegexResult;
+import net.sourceforge.plantuml.cucadiagram.Code;
+import net.sourceforge.plantuml.cucadiagram.Display;
+import net.sourceforge.plantuml.cucadiagram.IEntity;
+import net.sourceforge.plantuml.cucadiagram.LeafType;
+import net.sourceforge.plantuml.cucadiagram.Stereotype;
+import net.sourceforge.plantuml.graphic.HtmlColorUtils;
+import net.sourceforge.plantuml.objectdiagram.ObjectDiagram;
+
+public class CommandCreateEntityObject extends SingleLineCommand2<ObjectDiagram> {
+
+ public CommandCreateEntityObject() {
+ super(getRegexConcat());
+ }
+
+ private static RegexConcat getRegexConcat() {
+ return new RegexConcat(new RegexLeaf("^"), //
+ new RegexLeaf("TYPE", "(object)[%s]+"), //
+ new RegexLeaf("NAME", "(?:[%g]([^%g]+)[%g][%s]+as[%s]+)?([\\p{L}0-9_.]+)"), //
+ new RegexLeaf("[%s]*"), //
+ new RegexLeaf("STEREO", "(\\<\\<.+\\>\\>)?"), //
+ new RegexLeaf("[%s]*"), //
+ new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), //
+ new RegexLeaf("[%s]*"), //
+ new RegexLeaf("COLOR", "(" + HtmlColorUtils.COLOR_REGEXP + ")?"), //
+ new RegexLeaf("$"));
+ }
+
+ @Override
+ protected CommandExecutionResult executeArg(ObjectDiagram diagram, RegexResult arg) {
+ final Code code = Code.of(arg.get("NAME", 1));
+ final String display = arg.get("NAME", 0);
+ final String stereotype = arg.get("STEREO", 0);
+ if (diagram.leafExist(code)) {
+ return CommandExecutionResult.error("Object already exists : " + code);
+ }
+ final IEntity entity = diagram.createLeaf(code, Display.getWithNewlines(display), LeafType.OBJECT, null);
+ if (stereotype != null) {
+ entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram
+ .getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null, false), diagram.getSkinParam()
+ .getIHtmlColorSet()));
+ }
+ final String urlString = arg.get("URL", 0);
+ if (urlString != null) {
+ final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT);
+ final Url url = urlBuilder.getUrl(urlString);
+ entity.addUrl(url);
+ }
+ entity.setSpecificBackcolor(diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get("COLOR", 0)));
+ return CommandExecutionResult.ok();
+ }
+
+}
diff --git a/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateEntityObjectMultilines.java b/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateEntityObjectMultilines.java
new file mode 100644
index 0000000..f727e2d
--- /dev/null
+++ b/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateEntityObjectMultilines.java
@@ -0,0 +1,115 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.objectdiagram.command;
+
+import java.util.List;
+
+import net.sourceforge.plantuml.FontParam;
+import net.sourceforge.plantuml.UrlBuilder;
+import net.sourceforge.plantuml.command.CommandExecutionResult;
+import net.sourceforge.plantuml.command.CommandMultilines2;
+import net.sourceforge.plantuml.command.MultilinesStrategy;
+import net.sourceforge.plantuml.command.regex.RegexConcat;
+import net.sourceforge.plantuml.command.regex.RegexLeaf;
+import net.sourceforge.plantuml.command.regex.RegexResult;
+import net.sourceforge.plantuml.cucadiagram.Code;
+import net.sourceforge.plantuml.cucadiagram.Display;
+import net.sourceforge.plantuml.cucadiagram.IEntity;
+import net.sourceforge.plantuml.cucadiagram.LeafType;
+import net.sourceforge.plantuml.cucadiagram.Stereotype;
+import net.sourceforge.plantuml.graphic.HtmlColorUtils;
+import net.sourceforge.plantuml.objectdiagram.ObjectDiagram;
+import net.sourceforge.plantuml.skin.VisibilityModifier;
+import net.sourceforge.plantuml.StringUtils;
+
+public class CommandCreateEntityObjectMultilines extends CommandMultilines2<ObjectDiagram> {
+
+ public CommandCreateEntityObjectMultilines() {
+ super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE);
+ }
+
+ private static RegexConcat getRegexConcat() {
+ return new RegexConcat(new RegexLeaf("^"), //
+ new RegexLeaf("TYPE", "(object)[%s]+"), //
+ new RegexLeaf("NAME", "(?:[%g]([^%g]+)[%g][%s]+as[%s]+)?([\\p{L}0-9_.]+)"), //
+ new RegexLeaf("[%s]*"), //
+ new RegexLeaf("STEREO", "(\\<\\<.+\\>\\>)?"), //
+ new RegexLeaf("[%s]*"), //
+ new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), //
+ new RegexLeaf("[%s]*"), //
+ new RegexLeaf("COLOR", "(" + HtmlColorUtils.COLOR_REGEXP + ")?"), //
+ new RegexLeaf("[%s]*\\{[%s]*$"));
+ }
+
+ @Override
+ public String getPatternEnd() {
+ return "(?i)^[%s]*\\}[%s]*$";
+ }
+
+ public CommandExecutionResult executeNow(ObjectDiagram diagram, List<String> lines) {
+ StringUtils.trim(lines, true);
+ final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim());
+ final IEntity entity = executeArg0(diagram, line0);
+ if (entity == null) {
+ return CommandExecutionResult.error("No such entity");
+ }
+ for (String s : lines.subList(1, lines.size() - 1)) {
+ assert s.length() > 0;
+ if (VisibilityModifier.isVisibilityCharacter(s.charAt(0))) {
+ diagram.setVisibilityModifierPresent(true);
+ }
+ entity.addFieldOrMethod(s);
+ }
+ return CommandExecutionResult.ok();
+ }
+
+ private IEntity executeArg0(ObjectDiagram diagram, RegexResult line0) {
+ final Code code = Code.of(line0.get("NAME", 1));
+ final String display = line0.get("NAME", 0);
+ final String stereotype = line0.get("STEREO", 0);
+ if (diagram.leafExist(code)) {
+ return diagram.getOrCreateLeaf(code, null, null);
+ }
+ final IEntity entity = diagram.createLeaf(code, Display.getWithNewlines(display), LeafType.OBJECT, null);
+ if (stereotype != null) {
+ entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram
+ .getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null, false), diagram.getSkinParam()
+ .getIHtmlColorSet()));
+ }
+ entity.setSpecificBackcolor(diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(line0.get("COLOR", 0)));
+ return entity;
+ }
+
+}