1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.typicals;
\r
14 import gnu.trove.map.hash.THashMap;
\r
15 import gnu.trove.set.hash.THashSet;
\r
17 import java.awt.geom.Point2D;
\r
18 import java.util.ArrayList;
\r
19 import java.util.Collection;
\r
20 import java.util.Collections;
\r
21 import java.util.Date;
\r
22 import java.util.HashMap;
\r
23 import java.util.HashSet;
\r
24 import java.util.Iterator;
\r
25 import java.util.List;
\r
26 import java.util.Map;
\r
27 import java.util.Set;
\r
29 import org.eclipse.core.runtime.IProgressMonitor;
\r
30 import org.simantics.Logger;
\r
31 import org.simantics.Simantics;
\r
32 import org.simantics.databoard.Bindings;
\r
33 import org.simantics.db.ReadGraph;
\r
34 import org.simantics.db.Resource;
\r
35 import org.simantics.db.Statement;
\r
36 import org.simantics.db.WriteGraph;
\r
37 import org.simantics.db.common.CommentMetadata;
\r
38 import org.simantics.db.common.NamedResource;
\r
39 import org.simantics.db.common.primitiverequest.Adapter;
\r
40 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
\r
41 import org.simantics.db.common.request.ObjectsWithType;
\r
42 import org.simantics.db.common.request.PossibleIndexRoot;
\r
43 import org.simantics.db.common.request.WriteRequest;
\r
44 import org.simantics.db.common.uri.UnescapedChildMapOfResource;
\r
45 import org.simantics.db.common.utils.CommonDBUtils;
\r
46 import org.simantics.db.common.utils.NameUtils;
\r
47 import org.simantics.db.exception.DatabaseException;
\r
48 import org.simantics.db.layer0.adapter.Instances;
\r
49 import org.simantics.db.layer0.request.ActiveModels;
\r
50 import org.simantics.db.layer0.util.RemoverUtil;
\r
51 import org.simantics.diagram.content.ConnectionUtil;
\r
52 import org.simantics.diagram.handler.CopyPasteStrategy;
\r
53 import org.simantics.diagram.handler.ElementObjectAssortment;
\r
54 import org.simantics.diagram.handler.PasteOperation;
\r
55 import org.simantics.diagram.handler.Paster;
\r
56 import org.simantics.diagram.stubs.DiagramResource;
\r
57 import org.simantics.diagram.synchronization.CollectingModificationQueue;
\r
58 import org.simantics.diagram.synchronization.CopyAdvisor;
\r
59 import org.simantics.diagram.synchronization.SynchronizationHints;
\r
60 import org.simantics.diagram.synchronization.graph.GraphSynchronizationContext;
\r
61 import org.simantics.diagram.ui.DiagramModelHints;
\r
62 import org.simantics.document.DocumentResource;
\r
63 import org.simantics.g2d.canvas.ICanvasContext;
\r
64 import org.simantics.g2d.diagram.DiagramClass;
\r
65 import org.simantics.g2d.diagram.IDiagram;
\r
66 import org.simantics.g2d.diagram.impl.Diagram;
\r
67 import org.simantics.layer0.Layer0;
\r
68 import org.simantics.modeling.ModelingResources;
\r
69 import org.simantics.modeling.ModelingUtils;
\r
70 import org.simantics.modeling.mapping.ModelingSynchronizationHints;
\r
71 import org.simantics.modeling.typicals.rules.AuxKeys;
\r
72 import org.simantics.modeling.typicals.rules.FlagRule;
\r
73 import org.simantics.modeling.typicals.rules.InstanceOfRule;
\r
74 import org.simantics.modeling.typicals.rules.LabelRule;
\r
75 import org.simantics.modeling.typicals.rules.MonitorRule;
\r
76 import org.simantics.modeling.typicals.rules.NameRule;
\r
77 import org.simantics.modeling.typicals.rules.ProfileMonitorRule;
\r
78 import org.simantics.modeling.typicals.rules.SVGElementRule;
\r
79 import org.simantics.modeling.typicals.rules.TransformRule;
\r
80 import org.simantics.scenegraph.g2d.events.command.Commands;
\r
81 import org.simantics.scl.runtime.function.Function4;
\r
82 import org.simantics.structural.stubs.StructuralResource2;
\r
83 import org.simantics.utils.datastructures.MapSet;
\r
84 import org.simantics.utils.strings.AlphanumComparator;
\r
85 import org.simantics.utils.strings.EString;
\r
86 import org.simantics.utils.ui.ErrorLogger;
\r
89 * A write request that synchronizes typical master templates and their
\r
90 * instances as specified.
\r
93 * Use {@link #SyncTypicalTemplatesToInstances(Resource[], MapSet)} to
\r
94 * synchronize all instances of specified templates. Use
\r
95 * {@link #syncSingleInstance(Resource)} to synchronize a single typical
\r
96 * instance with its master template.
\r
98 * @author Tuukka Lehtonen
\r
100 * @see ReadTypicalInfo
\r
102 * @see TypicalSynchronizationMetadata
\r
104 public class SyncTypicalTemplatesToInstances extends WriteRequest {
\r
107 * A constant used as the second argument to
\r
108 * {@link #SyncTemplates(Resource[], MapSet)} for stating that all specified
\r
109 * templates should be fully synchronized to their instances.
\r
111 * This is useful for forcing complete synchronization and unit testing.
\r
113 public static final EmptyMapSet ALL = EmptyMapSet.INSTANCE;
\r
115 public static class EmptyMapSet extends MapSet<Resource, Resource> {
\r
117 public static final EmptyMapSet INSTANCE = new EmptyMapSet();
\r
119 public EmptyMapSet() {
\r
120 this.sets = Collections.emptyMap();
\r
124 protected Set<Resource> getOrCreateSet(Resource key) {
\r
125 throw new UnsupportedOperationException("immutable constant instance");
\r
130 protected static final boolean DEBUG = false;
\r
134 final private IProgressMonitor monitor;
\r
136 * Typical diagram rules to apply
\r
138 protected Set<Resource> selectedRules;
\r
141 * Typical diagram templates to synchronize with their instances.
\r
143 protected Resource[] templates;
\r
146 * Typical diagram instances to synchronize with their templates.
\r
148 protected Resource[] instances;
\r
151 * For each template diagram in {@link #templates}, shall contain a set of
\r
152 * elements that have changed and should be synchronized into the instance
\r
153 * diagrams. Provided as an argument by the client. Allows optimizing
\r
154 * real-time synchronization by not processing everything all the time.
\r
156 * If the value is {@link #ALL}, all elements of the template shall be fully
\r
159 protected MapSet<Resource, Resource> changedElementsByDiagram;
\r
163 protected Layer0 L0;
\r
164 protected StructuralResource2 STR;
\r
165 protected DiagramResource DIA;
\r
166 protected ModelingResources MOD;
\r
169 * Needed for using {@link Paster} in
\r
170 * {@link #addMissingElements(WriteGraph, TypicalInfo, Resource, Resource, Set)}
\r
172 protected GraphSynchronizationContext syncCtx;
\r
175 * For collecting commit metadata during the processing of this request.
\r
177 protected TypicalSynchronizationMetadata metadata;
\r
180 * Necessary for using {@link CopyPasteStrategy} and {@link PasteOperation}
\r
181 * for now. Will be removed in the future once IDiagram is removed from
\r
184 protected IDiagram temporaryDiagram;
\r
186 protected ConnectionUtil cu;
\r
189 * Maps source -> target connection route nodes, i.e. connectors and
\r
190 * interior route nodes (route lines). Inverse mapping of {@link #t2s}.
\r
192 protected Map<Resource, Resource> s2t;
\r
195 * Maps target -> source connection route nodes, i.e. connectors and
\r
196 * interior route nodes (route lines). Inverse mapping of {@link #s2t}.
\r
198 protected Map<Resource, Resource> t2s;
\r
201 * An auxiliary resource map for extracting the correspondences between
\r
202 * originals and copied resource when diagram contents are copied from
\r
203 * template to instance.
\r
205 protected Map<Object, Object> copyMap;
\r
207 final private Map<Resource, List<String>> messageLogs = new HashMap<Resource, List<String>>();
\r
209 public List<Resource> logs = new ArrayList<Resource>();
\r
211 private boolean writeLog;
\r
214 * @param templates typical diagram templates to completely synchronize with
\r
217 public SyncTypicalTemplatesToInstances(Set<Resource> selectedRules, Resource... templates) {
\r
218 this(selectedRules, templates, null, ALL, null);
\r
222 * @param templates typical diagram templates to partially synchronize with
\r
224 * @param changedElementsByDiagram see {@link #changedElementsByDiagram}
\r
226 public SyncTypicalTemplatesToInstances(Set<Resource> selectedRules, Resource[] templates, MapSet<Resource, Resource> changedElementsByDiagram) {
\r
227 this(selectedRules, templates, null, changedElementsByDiagram, null);
\r
231 * Return a write request that completely synchronizes the specified
\r
232 * instance diagram with its template.
\r
237 public static SyncTypicalTemplatesToInstances syncSingleInstance(Set<Resource> selectedRules, Resource instance) {
\r
238 return new SyncTypicalTemplatesToInstances(selectedRules, null, new Resource[] { instance }, ALL, null);
\r
242 * @param templates typical diagram templates to synchronize with their instances
\r
243 * @param instances typical diagram instances to synchronize with their templates
\r
244 * @param changedElementsByDiagram see {@link #changedElementsByDiagram}
\r
246 private SyncTypicalTemplatesToInstances(Set<Resource> selectedRules, Resource[] templates, Resource[] instances, MapSet<Resource, Resource> changedElementsByDiagram, IProgressMonitor monitor) {
\r
247 this.selectedRules = selectedRules;
\r
248 this.templates = templates;
\r
249 this.instances = instances;
\r
250 this.changedElementsByDiagram = changedElementsByDiagram;
\r
251 this.monitor = monitor;
\r
254 public SyncTypicalTemplatesToInstances logging(boolean writeLog) {
\r
255 this.writeLog = writeLog;
\r
259 private Resource getDiagramNameResource(ReadGraph graph, Resource diagram) throws DatabaseException {
\r
260 Resource composite = graph.getPossibleObject(diagram, MOD.DiagramToComposite);
\r
261 if(composite != null) return composite;
\r
262 else return diagram;
\r
265 private Resource getElementNameResource(ReadGraph graph, Resource element) throws DatabaseException {
\r
266 Resource corr = ModelingUtils.getPossibleElementCorrespondendence(graph, element);
\r
267 if(corr != null) return corr;
\r
268 else return element;
\r
271 private List<String> getLog(ReadGraph graph, Resource diagram) throws DatabaseException {
\r
272 Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(diagram));
\r
273 if(indexRoot == null) throw new DatabaseException("FATAL: Diagram is not under any index root.");
\r
274 List<String> log = messageLogs.get(indexRoot);
\r
276 log = new ArrayList<String>();
\r
277 messageLogs.put(indexRoot, log);
\r
282 private String elementName(ReadGraph graph, Resource element) throws DatabaseException {
\r
284 StringBuilder b = new StringBuilder();
\r
285 b.append(safeNameAndType(graph, element));
\r
287 int spaces = 60-b.length();
\r
288 for(int i=0;i<spaces;i++) b.append(" ");
\r
290 Resource corr = ModelingUtils.getPossibleElementCorrespondendence(graph, element);
\r
292 b.append(safeNameAndType(graph, corr));
\r
297 return b.toString();
\r
302 public void perform(WriteGraph graph) throws DatabaseException {
\r
303 this.L0 = Layer0.getInstance(graph);
\r
304 this.STR = StructuralResource2.getInstance(graph);
\r
305 this.DIA = DiagramResource.getInstance(graph);
\r
306 this.MOD = ModelingResources.getInstance(graph);
\r
308 this.syncCtx = GraphSynchronizationContext.getWriteInstance( graph, new CollectingModificationQueue() );
\r
309 this.syncCtx.set(ModelingSynchronizationHints.MODELING_RESOURCE, ModelingResources.getInstance(graph));
\r
311 this.metadata = new TypicalSynchronizationMetadata();
\r
312 this.metadata.synchronizedTypicals = new ArrayList<Resource>();
\r
314 this.temporaryDiagram = Diagram.spawnNew(DiagramClass.DEFAULT);
\r
315 this.temporaryDiagram.setHint(SynchronizationHints.CONTEXT, syncCtx);
\r
317 this.cu = new ConnectionUtil(graph);
\r
319 if (templates != null) {
\r
320 // Look for typical template instances from the currently active models only.
\r
321 Collection<Resource> activeModels = graph.syncRequest(new ActiveModels(Simantics.getProjectResource()));
\r
322 if (!activeModels.isEmpty()) {
\r
323 for (Resource template : templates) {
\r
324 syncTemplate(graph, template, activeModels);
\r
328 if (instances != null) {
\r
329 for (Resource instance : instances) {
\r
330 syncInstance(graph, instance);
\r
335 for(Map.Entry<Resource, List<String>> entry : messageLogs.entrySet()) {
\r
337 Resource indexRoot = entry.getKey();
\r
338 List<String> messageLog = entry.getValue();
\r
340 Layer0 L0 = Layer0.getInstance(graph);
\r
341 DocumentResource DOC = DocumentResource.getInstance(graph);
\r
343 Collection<Resource> libs = graph.syncRequest(new ObjectsWithType(indexRoot, L0.ConsistsOf, DOC.DocumentLibrary));
\r
344 if(libs.isEmpty()) continue;
\r
346 List<NamedResource> nrs = new ArrayList<NamedResource>();
\r
347 for(Resource lib : libs) nrs.add(new NamedResource(NameUtils.getSafeName(graph, lib), lib));
\r
348 Collections.sort(nrs, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);
\r
349 Resource library = nrs.iterator().next().getResource();
\r
351 CommonDBUtils.selectClusterSet(graph, library);
\r
353 String text = "--- Created: " + new Date().toString() + " ---\n";
\r
354 text += EString.implode(messageLog);
\r
356 Resource log = graph.newResource();
\r
357 graph.claim(log, L0.InstanceOf, null, DOC.PlainTextDocument);
\r
358 graph.claimLiteral(log, L0.HasName, L0.String, "Typical Sync " + new Date().toString());
\r
359 graph.claim(library, L0.ConsistsOf, L0.PartOf, log);
\r
360 graph.claimLiteral(log, DOC.PlainTextDocument_text, L0.String, text);
\r
366 if (!metadata.getTypicals().isEmpty()) {
\r
367 graph.addMetadata(metadata);
\r
369 // Add comment to change set.
\r
370 CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
\r
371 graph.addMetadata( cm.add("Synchronized " + metadata.getTypicals().size() + " typical diagram instances (" + metadata.getTypicals() + ") with their templates.") );
\r
374 temporaryDiagram = null;
\r
378 private Collection<Resource> findInstances(ReadGraph graph, Resource ofType, Collection<Resource> indexRoots) throws DatabaseException {
\r
379 Instances index = graph.adapt(ofType, Instances.class);
\r
380 Set<Resource> instances = new HashSet<>();
\r
381 for (Resource indexRoot : indexRoots)
\r
382 instances.addAll( index.find(graph, indexRoot) );
\r
386 private void syncTemplate(WriteGraph graph, Resource template, Collection<Resource> indexRoots) throws DatabaseException {
\r
387 Resource templateType = graph.getPossibleType(template, DIA.Diagram);
\r
388 if (templateType == null)
\r
391 Collection<Resource> instances = findInstances(graph, templateType, indexRoots);
\r
392 // Do not include the template itself as it is also an instance of templateType
\r
393 instances.remove(template);
\r
394 if (instances.isEmpty())
\r
397 Set<Resource> templateElements = new THashSet<Resource>( graph.syncRequest(
\r
398 new ObjectsWithType(template, L0.ConsistsOf, DIA.Element) ) );
\r
401 for (Resource instance : instances) {
\r
402 this.temporaryDiagram.setHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE, instance);
\r
403 syncInstance(graph, template, instance, templateElements);
\r
405 } catch (Exception e) {
\r
406 Logger.defaultLogError(e);
\r
407 e.printStackTrace();
\r
409 this.temporaryDiagram.removeHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE);
\r
413 private void syncInstance(WriteGraph graph, Resource instance) throws DatabaseException {
\r
414 Resource template = graph.getPossibleObject(instance, MOD.HasDiagramSource);
\r
415 if (template == null)
\r
418 Set<Resource> templateElements = new THashSet<Resource>( graph.syncRequest(
\r
419 new ObjectsWithType(template, L0.ConsistsOf, DIA.Element) ) );
\r
422 this.temporaryDiagram.setHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE, instance);
\r
423 syncInstance(graph, template, instance, templateElements);
\r
425 this.temporaryDiagram.removeHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE);
\r
429 private Resource findInstanceCounterpart(ReadGraph graph, Resource instanceDiagram, Resource templateElement) throws DatabaseException {
\r
430 Map<String,Resource> children = graph.syncRequest(new UnescapedChildMapOfResource(instanceDiagram));
\r
431 for(Resource child : children.values()) {
\r
432 if(graph.hasStatement(child, MOD.HasElementSource, templateElement)) return child;
\r
437 private boolean isSynchronizedConnector(ReadGraph graph, Resource templateConnection, Resource instanceConnector) throws DatabaseException {
\r
438 DiagramResource DIA = DiagramResource.getInstance(graph);
\r
439 Resource instanceConnection = graph.getPossibleObject(instanceConnector, DIA.IsConnectorOf);
\r
440 return graph.hasStatement(instanceConnection, MOD.HasElementSource, templateConnection);
\r
444 * Perform the following synchronization steps for the instance diagram:
\r
446 * <li>remove such templatized elements from the instance diagram whose
\r
447 * template counterpart no longer exists</li>
\r
448 * <li>add elements to the instance diagram that are only in the template</li>
\r
449 * <li>synchronize elements of the instance diagram that have been deemed
\r
453 * @param graph database write access
\r
454 * @param template the synchronization source diagram
\r
455 * @param instance the synchronization target diagram
\r
456 * @param currentTemplateElements the set of all elements currently in the
\r
458 * @throws DatabaseException if anything goes wrong
\r
460 private void syncInstance(WriteGraph graph, Resource template, Resource instance, Set<Resource> currentTemplateElements) throws DatabaseException {
\r
462 List<String> messageLog = getLog(graph, instance);
\r
464 messageLog.add("Synchronization of changed typical template: " + SyncTypicalTemplatesToInstances.safeNameAndType(graph, getDiagramNameResource(graph, template)));
\r
465 messageLog.add("----\n\ttypical instance: " + safeNameAndType(graph, getDiagramNameResource(graph, instance)));
\r
467 CommonDBUtils.selectClusterSet(graph, instance);
\r
469 // Form instance element <-> template element bijection
\r
470 TypicalInfoBean typicalInfoBean = graph.syncRequest(
\r
471 new ReadTypicalInfo(instance),
\r
472 TransientCacheListener.<TypicalInfoBean> instance());
\r
473 // Must be able to modify the typicalInfo structure,
\r
474 // therefore clone the query result.
\r
475 typicalInfoBean = (TypicalInfoBean) typicalInfoBean.clone();
\r
476 typicalInfoBean.templateElements = currentTemplateElements;
\r
477 typicalInfoBean.auxiliary = new HashMap<Object, Object>(1);
\r
479 TypicalInfo info = new TypicalInfo();
\r
480 info.monitor = monitor;
\r
481 info.messageLog = messageLog;
\r
482 info.bean = typicalInfoBean;
\r
484 // Resolve naming function for this typical instance.
\r
485 Resource compositeInstance = graph.getPossibleObject(instance, MOD.DiagramToComposite);
\r
486 if (compositeInstance != null) {
\r
487 Function4<ReadGraph, Resource, Resource, String, String> namingFunction = TypicalUtil.getTypicalNamingFunction(graph, compositeInstance);
\r
488 if (namingFunction != null)
\r
489 typicalInfoBean.auxiliary.put(AuxKeys.KEY_TYPICAL_NAMING_FUNCTION, namingFunction);
\r
492 int dSizeAbs = Math.abs(typicalInfoBean.instanceElements.size() - currentTemplateElements.size());
\r
495 System.out.println("typical <-> template mapping: " + typicalInfoBean.instanceToTemplate);
\r
497 // Find elements to be removed from instance by looking for all
\r
498 // instance elements that do not have a MOD.HasElementSource
\r
499 // relation but have a MOD.IsTemplatized tag.
\r
500 Set<Resource> instanceElementsRemovedFromTemplate = findInstanceElementsRemovedFromTemplate(
\r
501 graph, info, new THashSet<Resource>(dSizeAbs));
\r
503 // Find elements in template that do not yet exist in the instance
\r
504 Set<Resource> templateElementsAddedToTemplate = findTemplateElementsMissingFromInstance(
\r
505 graph, currentTemplateElements, info,
\r
506 new THashSet<Resource>(dSizeAbs));
\r
508 Set<Resource> changedTemplateElements = changedElementsByDiagram.removeValues(template);
\r
511 System.out.println("ADDED: " + templateElementsAddedToTemplate.size() + ", REMOVED: " + instanceElementsRemovedFromTemplate.size() + ", CHANGED: " + changedTemplateElements.size());
\r
514 for(Resource templateElement : graph.getObjects(template, L0.ConsistsOf)) {
\r
515 if(graph.isInstanceOf(templateElement, DIA.RouteGraphConnection)) {
\r
516 for(Resource connector : graph.getObjects(templateElement, DIA.HasConnector)) {
\r
517 for(Statement elementStm : graph.getStatements(connector, STR.Connects)) {
\r
518 Resource otherElement = elementStm.getObject();
\r
519 if(!otherElement.equals(templateElement)) {
\r
520 Resource counterPartElement = findInstanceCounterpart(graph, instance, otherElement);
\r
521 if(counterPartElement != null) {
\r
522 Resource diagramConnectionPoint = graph.getInverse(elementStm.getPredicate());
\r
523 Resource connectionPoint = graph.getPossibleObject(diagramConnectionPoint, MOD.DiagramConnectionRelationToConnectionRelation);
\r
524 if(connectionPoint != null) {
\r
525 Statement stm = graph.getPossibleStatement(counterPartElement, diagramConnectionPoint);
\r
527 if(graph.isInstanceOf(connectionPoint, L0.FunctionalRelation)) {
\r
528 if(!isSynchronizedConnector(graph, templateElement, stm.getObject())) {
\r
529 messageLog.add("\t\tABORTED: tried to connect to an already connected terminal " + NameUtils.getSafeName(graph, counterPartElement) + " " + NameUtils.getSafeName(graph, connectionPoint));
\r
543 boolean changed = false;
\r
544 changed |= removeElements(graph, info, instanceElementsRemovedFromTemplate);
\r
545 changed |= addMissingElements(graph, info, template, instance, templateElementsAddedToTemplate);
\r
546 changed |= synchronizeChangedElements(graph, info, template, instance, changedTemplateElements, templateElementsAddedToTemplate, changedElementsByDiagram == ALL);
\r
549 metadata.addTypical(instance);
\r
553 * Add elements from template that do not yet exist in the instance.
\r
558 * @param elementsAddedToTemplate
\r
559 * @return <code>true</code> if changes were made to the instance
\r
560 * @throws DatabaseException
\r
562 private boolean addMissingElements(WriteGraph graph, TypicalInfo typicalInfo, Resource template,
\r
563 Resource instance, Set<Resource> elementsAddedToTemplate)
\r
564 throws DatabaseException {
\r
565 if (elementsAddedToTemplate.isEmpty())
\r
568 CopyAdvisor copyAdvisor = graph.syncRequest(new Adapter<CopyAdvisor>(instance, CopyAdvisor.class));
\r
569 this.temporaryDiagram.setHint(SynchronizationHints.COPY_ADVISOR, copyAdvisor);
\r
571 ElementObjectAssortment assortment = new ElementObjectAssortment(graph, elementsAddedToTemplate);
\r
572 if (copyMap == null)
\r
573 copyMap = new THashMap<Object, Object>();
\r
578 System.out.println("ADD MISSING ELEMENTS: " + assortment);
\r
580 // initialCopyMap argument is needed for copying just connections
\r
581 // when their end-points are not copied at the same time.
\r
583 PasteOperation pasteOp = new PasteOperation(Commands.COPY,
\r
584 (ICanvasContext) null, template, instance, temporaryDiagram,
\r
585 assortment, false, new Point2D.Double(0, 0),
\r
586 typicalInfo.bean.templateToInstance, copyMap)
\r
587 .options(PasteOperation.ForceCopyReferences.INSTANCE);
\r
589 new Paster(graph.getSession(), pasteOp).perform(graph);
\r
591 boolean changed = false;
\r
593 if(!elementsAddedToTemplate.isEmpty())
\r
594 typicalInfo.messageLog.add("\tadded elements");
\r
596 for (Resource addedElement : elementsAddedToTemplate) {
\r
597 Resource copyElement = (Resource) copyMap.get(addedElement);
\r
598 if (copyElement != null) {
\r
599 graph.claim(copyElement, MOD.IsTemplatized, MOD.IsTemplatized, copyElement);
\r
600 graph.claim(copyElement, MOD.HasElementSource, MOD.ElementHasInstance, addedElement);
\r
602 typicalInfo.bean.instanceElements.add(copyElement);
\r
603 typicalInfo.bean.instanceToTemplate.put(copyElement, addedElement);
\r
604 typicalInfo.bean.templateToInstance.put(addedElement, copyElement);
\r
606 typicalInfo.messageLog.add("\t\t" + safeNameAndType(graph, copyElement));
\r
612 ModelingResources MOD = ModelingResources.getInstance(graph);
\r
613 Resource instanceComposite = graph.getPossibleObject(instance, MOD.DiagramToComposite);
\r
614 List<Resource> instanceComponents = new ArrayList<Resource>(elementsAddedToTemplate.size());
\r
616 // Post-process added elements after typicalInfo has been updated and
\r
617 // template mapping statements are in place.
\r
618 for (Resource addedElement : elementsAddedToTemplate) {
\r
619 Resource copyElement = (Resource) copyMap.get(addedElement);
\r
620 if (copyElement != null) {
\r
621 postProcessAddedElement(graph, addedElement, copyElement, typicalInfo);
\r
623 if (instanceComponents != null) {
\r
624 // Gather all instance typical components for applying naming
\r
625 // strategy on them.
\r
626 Resource component = graph.getPossibleObject(copyElement, MOD.ElementToComponent);
\r
627 if (component != null)
\r
628 instanceComponents.add(component);
\r
633 if (instanceComposite != null)
\r
634 TypicalUtil.applySelectedModuleNames(graph, instanceComposite, instanceComponents);
\r
639 private void postProcessAddedElement(WriteGraph graph,
\r
640 Resource addedTemplateElement, Resource addedInstanceElement,
\r
641 TypicalInfo typicalInfo) throws DatabaseException {
\r
642 if (graph.isInstanceOf(addedInstanceElement, DIA.Monitor)) {
\r
643 postProcessAddedMonitor(graph, addedTemplateElement, addedInstanceElement, typicalInfo);
\r
647 private void postProcessAddedMonitor(WriteGraph graph,
\r
648 Resource addedTemplateMonitor, Resource addedInstanceMonitor,
\r
649 TypicalInfo typicalInfo) throws DatabaseException {
\r
650 Resource monitor = addedInstanceMonitor;
\r
651 Resource monitoredComponent = graph.getPossibleObject(monitor, DIA.HasMonitorComponent);
\r
652 if (monitoredComponent != null) {
\r
653 Resource monitoredTemplateElement = graph.getPossibleObject(monitoredComponent, MOD.ComponentToElement);
\r
654 if (monitoredTemplateElement != null) {
\r
655 Resource monitoredInstanceElement = typicalInfo.bean.templateToInstance.get(monitoredTemplateElement);
\r
656 if (monitoredInstanceElement != null) {
\r
657 Resource monitoredInstanceComponent = graph.getPossibleObject(monitoredInstanceElement, MOD.ElementToComponent);
\r
658 if (monitoredInstanceComponent != null) {
\r
659 // Ok, the monitor refers to a component within the
\r
660 // template composite. Change it to refer to the
\r
661 // instance composite.
\r
662 graph.deny(monitor, DIA.HasMonitorComponent);
\r
663 graph.claim(monitor, DIA.HasMonitorComponent, monitoredInstanceComponent);
\r
670 private boolean removeElements(WriteGraph graph, TypicalInfo typicalInfo, Set<Resource> elementsRemovedFromTemplate) throws DatabaseException {
\r
671 if (elementsRemovedFromTemplate.isEmpty())
\r
674 // Remove mapped elements from instance that are removed from the template.
\r
675 boolean changed = false;
\r
677 if(!elementsRemovedFromTemplate.isEmpty())
\r
678 typicalInfo.messageLog.add("\tremoved elements");
\r
680 for (Resource removedElement : elementsRemovedFromTemplate) {
\r
681 typicalInfo.messageLog.add("\t\t" + safeNameAndType(graph, removedElement));
\r
683 RemoverUtil.remove(graph, removedElement);
\r
685 typicalInfo.bean.instanceElements.remove(removedElement);
\r
686 Resource template = typicalInfo.bean.instanceToTemplate.remove(removedElement);
\r
687 if (template != null)
\r
688 typicalInfo.bean.templateToInstance.remove(template);
\r
695 private Set<Resource> findTemplateElementsMissingFromInstance(
\r
696 WriteGraph graph, Collection<Resource> currentTemplateElements,
\r
697 TypicalInfo typicalInfo, THashSet<Resource> result)
\r
698 throws DatabaseException {
\r
699 for (Resource templateElement : currentTemplateElements) {
\r
700 Resource instanceElement = typicalInfo.bean.templateToInstance.get(templateElement);
\r
701 if (instanceElement == null) {
\r
703 System.out.println("No instance correspondence for template element " + NameUtils.getSafeName(graph, templateElement, true) + " => add");
\r
704 result.add(templateElement);
\r
710 public Set<Resource> findInstanceElementsRemovedFromTemplate(
\r
711 ReadGraph graph, TypicalInfo typicalInfo,
\r
712 THashSet<Resource> result) throws DatabaseException {
\r
713 for (Resource instanceElement : typicalInfo.bean.instanceElements) {
\r
714 if (!typicalInfo.bean.instanceToTemplate.containsKey(instanceElement)) {
\r
715 if (typicalInfo.bean.isTemplatized.contains(instanceElement)) {
\r
717 System.out.println("Templatized typical instance element " + NameUtils.getSafeName(graph, instanceElement, true) + " has no correspondence in template => remove");
\r
718 result.add(instanceElement);
\r
726 * Synchronize basic visual aspects of changed elements. For all elements,
\r
727 * transform and label are synchronized. Otherwise synchronization is
\r
728 * type-specific for connections, flags, monitors and svg elements.
\r
731 * @param typicalInfo
\r
734 * @param changedTemplateElements
\r
735 * @param addedElements
\r
736 * elements that have been added and thus need not be
\r
738 * @param synchronizeAllElements
\r
740 * @throws DatabaseException
\r
742 private boolean synchronizeChangedElements(WriteGraph graph,
\r
743 TypicalInfo typicalInfo, Resource template, Resource instance,
\r
744 Collection<Resource> changedTemplateElements,
\r
745 Set<Resource> addedElements,
\r
746 boolean synchronizeAllElements) throws DatabaseException {
\r
748 if (synchronizeAllElements) {
\r
749 // For unit testing purposes.
\r
750 changedTemplateElements = graph.syncRequest(new ObjectsWithType(template, L0.ConsistsOf, DIA.Element));
\r
753 if (changedTemplateElements.isEmpty())
\r
756 boolean changed = false;
\r
758 typicalInfo.messageLog.add("\telement change analysis");
\r
759 int analysisLogPosition = typicalInfo.messageLog.size();
\r
761 for (Resource changedTemplateElement : changedTemplateElements) {
\r
762 // Skip synchronization of elements that were just added and are
\r
763 // thus already synchronized.
\r
764 if (addedElements.contains(changedTemplateElement))
\r
767 Resource instanceElement = typicalInfo.bean.templateToInstance.get(changedTemplateElement);
\r
768 if (instanceElement == null) {
\r
769 // There's an earlier problem in the sync process if this happens.
\r
770 typicalInfo.messageLog.add("SKIPPING SYNC OF CHANGED TEMPLATE ELEMENT DUE TO MISSING INSTANCE: " + safeNameAndType(graph, getElementNameResource(graph, changedTemplateElement)));
\r
774 typicalInfo.messageLog.add("\t\t" + elementName(graph, changedTemplateElement));
\r
775 int currentLogSize = typicalInfo.messageLog.size();
\r
777 changed |= InstanceOfRule.INSTANCE.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
778 changed |= NameRule.INSTANCE.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
779 changed |= TransformRule.INSTANCE.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
780 changed |= LabelRule.INSTANCE.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
782 Collection<Resource> types = graph.getTypes(changedTemplateElement);
\r
783 if (types.contains(DIA.RouteGraphConnection)) {
\r
784 changed |= synchronizeConnection(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
785 } else if (types.contains(DIA.Flag)) {
\r
786 changed |= FlagRule.INSTANCE.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
787 } else if (types.contains(DIA.Monitor)) {
\r
788 changed |= MonitorRule.INSTANCE.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
789 } else if (types.contains(DIA.SVGElement)) {
\r
790 changed |= SVGElementRule.INSTANCE.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
793 changed |= ProfileMonitorRule.INSTANCE.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
795 for (Resource rule : graph.getObjects(changedTemplateElement, MOD.HasTypicalSynchronizationRule)) {
\r
796 if(selectedRules != null && !selectedRules.contains(rule)) continue;
\r
797 ITypicalSynchronizationRule r = graph.getPossibleAdapter(rule, ITypicalSynchronizationRule.class);
\r
799 changed |= r.synchronize(graph, changedTemplateElement, instanceElement, typicalInfo);
\r
802 // Show element only if something has happened
\r
803 if(currentLogSize == typicalInfo.messageLog.size())
\r
804 typicalInfo.messageLog.remove(typicalInfo.messageLog.size()-1);
\r
813 // Show analysis header only if something has happened
\r
814 if(analysisLogPosition == typicalInfo.messageLog.size())
\r
815 typicalInfo.messageLog.remove(typicalInfo.messageLog.size()-1);
\r
821 * Synchronizes two route graph connection topologies if and only if the
\r
822 * destination connection is not attached to any node elements besides
\r
823 * the ones that exist in the source. This means that connections that
\r
824 * have instance-specific connections to non-template nodes are ignored
\r
828 * @param sourceConnection
\r
829 * @param targetConnection
\r
830 * @param typicalInfo
\r
831 * @return <code>true</code> if changes were made
\r
832 * @throws DatabaseException
\r
834 private boolean synchronizeConnection(WriteGraph graph, Resource sourceConnection, Resource targetConnection, TypicalInfo typicalInfo)
\r
835 throws DatabaseException {
\r
838 System.out.println("connection " + NameUtils.getSafeName(graph, sourceConnection, true) + " to target connection " + NameUtils.getSafeName(graph, targetConnection, true));
\r
840 boolean changed = false;
\r
842 // Initialize utilities and data maps
\r
843 s2t = newOrClear(s2t);
\r
844 t2s = newOrClear(t2s);
\r
847 cu = new ConnectionUtil(graph);
\r
849 // 0.1. find mappings between source and target connection connectors
\r
850 Collection<Resource> targetConnectors = graph.getObjects(targetConnection, DIA.HasConnector);
\r
851 for (Resource targetConnector : targetConnectors) {
\r
852 Statement toNode = cu.getConnectedComponentStatement(targetConnection, targetConnector);
\r
853 if (toNode == null) {
\r
854 // Corrupted target connection!
\r
855 ErrorLogger.defaultLogError("Encountered corrupted typical template connection " + NameUtils.getSafeName(graph, targetConnection, true) + " with a stray DIA.Connector instance " + NameUtils.getSafeName(graph, targetConnector, true), new Exception("trace"));
\r
859 // Check that the target connections does not connect to
\r
860 // non-templatized elements before syncing.
\r
861 if (!graph.hasStatement(toNode.getObject(), MOD.IsTemplatized))
\r
864 //Resource templateNode = typicalInfo.instanceToTemplate.get(toNode.getObject());
\r
865 Resource templateNode = graph.getPossibleObject(toNode.getObject(), MOD.HasElementSource);
\r
866 if (templateNode != null) {
\r
867 Resource isConnectedTo = graph.getPossibleInverse(toNode.getPredicate());
\r
868 if (isConnectedTo != null) {
\r
869 Resource templateConnector = graph.getPossibleObject(templateNode, isConnectedTo);
\r
870 if (templateConnector != null) {
\r
871 Resource connectionOfTemplateConnector = ConnectionUtil.tryGetConnection(graph, templateConnector);
\r
872 if (sourceConnection.equals(connectionOfTemplateConnector)) {
\r
873 s2t.put(templateConnector, targetConnector);
\r
874 t2s.put(targetConnector, templateConnector);
\r
877 System.out.println("Mapping connector "
\r
878 + NameUtils.getSafeName(graph, templateConnector, true)
\r
879 + " to " + NameUtils.getSafeName(graph, targetConnector, true));
\r
886 // 0.2. find mapping between source and target route lines
\r
887 Collection<Resource> sourceInteriorRouteNodes = graph.getObjects(sourceConnection, DIA.HasInteriorRouteNode);
\r
888 Collection<Resource> targetInteriorRouteNodes = graph.getObjects(targetConnection, DIA.HasInteriorRouteNode);
\r
889 Map<Resource, Paster.RouteLine> sourceToRouteLine = new THashMap<Resource, Paster.RouteLine>();
\r
890 Map<Resource, Paster.RouteLine> targetToRouteLine = new THashMap<Resource, Paster.RouteLine>();
\r
892 for (Resource source : sourceInteriorRouteNodes)
\r
893 sourceToRouteLine.put(source, Paster.readRouteLine(graph, source));
\r
894 for (Resource target : targetInteriorRouteNodes)
\r
895 targetToRouteLine.put(target, Paster.readRouteLine(graph, target));
\r
898 for (Iterator<Map.Entry<Resource, Paster.RouteLine>> sourceIt = sourceToRouteLine.entrySet().iterator(); !targetToRouteLine.isEmpty() && sourceIt.hasNext();) {
\r
899 Map.Entry<Resource, Paster.RouteLine> sourceEntry = sourceIt.next();
\r
900 Paster.RouteLine sourceLine = sourceEntry.getValue();
\r
901 for (Iterator<Map.Entry<Resource, Paster.RouteLine>> targetIt = targetToRouteLine.entrySet().iterator(); targetIt.hasNext();) {
\r
902 Map.Entry<Resource, Paster.RouteLine> targetEntry = targetIt.next();
\r
903 if (sourceLine.equals(targetEntry.getValue())) {
\r
904 s2t.put(sourceEntry.getKey(), targetEntry.getKey());
\r
905 t2s.put(targetEntry.getKey(), sourceEntry.getKey());
\r
910 System.out.println("Mapping routeline "
\r
911 + NameUtils.getSafeName(graph, sourceEntry.getKey(), true)
\r
912 + " - " + sourceEntry.getValue()
\r
913 + " to " + NameUtils.getSafeName(graph, targetEntry.getKey(), true)
\r
914 + " - " + targetEntry.getValue());
\r
916 continue nextSourceLine;
\r
922 System.out.println("Take 1: Source to target route nodes map : " + s2t);
\r
923 System.out.println("Take 1: Target to source route nodes map : " + t2s);
\r
926 // 1.1 remove excess connectors
\r
927 for (Resource targetConnector : targetConnectors) {
\r
928 if (!t2s.containsKey(targetConnector)) {
\r
929 typicalInfo.messageLog.add("\t\t\tremove excess connector from target connection: " + NameUtils.getSafeName(graph, targetConnector));
\r
930 cu.removeConnectionPart(targetConnector);
\r
935 // 1.2 add missing connectors to target
\r
936 Collection<Resource> sourceConnectors = graph.getObjects(sourceConnection, DIA.HasConnector);
\r
937 for (Resource sourceConnector : sourceConnectors) {
\r
938 if (!s2t.containsKey(sourceConnector)) {
\r
939 Statement sourceIsConnectorOf = graph.getSingleStatement(sourceConnector, DIA.IsConnectorOf);
\r
940 Statement connects = cu.getConnectedComponentStatement(sourceConnection, sourceConnector);
\r
941 if (connects == null) {
\r
942 // TODO: serious error!
\r
943 throw new DatabaseException("ERROR: connector is astray, i.e. not connected to a node element: " + safeNameAndType(graph, sourceConnector));
\r
945 Resource connectsInstanceElement = typicalInfo.bean.templateToInstance.get(connects.getObject());
\r
946 if (connectsInstanceElement == null) {
\r
947 // TODO: serious error!
\r
948 throw new DatabaseException("ERROR: could not find instance element to which template element " + safeNameAndType(graph, connects.getObject()) + " is connected to");
\r
950 Resource hasConnector = graph.getInverse(sourceIsConnectorOf.getPredicate());
\r
952 Resource newTargetConnector = cu.newConnector(targetConnection, hasConnector);
\r
953 graph.claim(newTargetConnector, connects.getPredicate(), connectsInstanceElement);
\r
956 s2t.put(sourceConnector, newTargetConnector);
\r
957 t2s.put(newTargetConnector, sourceConnector);
\r
959 typicalInfo.messageLog.add("\t\t\tadd new connector to target connection: " + NameUtils.getSafeName(graph, newTargetConnector) + " to map to source connector " + NameUtils.getSafeName(graph, sourceConnector));
\r
963 // 2. sync route lines and their connectivity:
\r
964 // 2.1. assign correspondences in target for each source route line
\r
965 // by reusing excess routelines in target and by creating new
\r
968 Resource[] targetRouteLines = targetToRouteLine.keySet().toArray(Resource.NONE);
\r
969 int targetRouteLine = targetRouteLines.length - 1;
\r
971 for (Iterator<Map.Entry<Resource, Paster.RouteLine>> sourceIt = sourceToRouteLine.entrySet().iterator(); sourceIt.hasNext();) {
\r
972 Map.Entry<Resource, Paster.RouteLine> sourceEntry = sourceIt.next();
\r
973 Resource source = sourceEntry.getKey();
\r
974 Paster.RouteLine sourceLine = sourceEntry.getValue();
\r
976 typicalInfo.messageLog.add("\t\t\tassign an instance-side routeline complement for " + NameUtils.getSafeName(graph, source, true) + " - " + sourceLine);
\r
978 // Assign target route line for source
\r
979 Resource target = null;
\r
980 if (targetRouteLine < 0) {
\r
981 // by creating new route lines
\r
982 target = cu.newRouteLine(targetConnection, sourceLine.getPosition(), sourceLine.isHorizontal());
\r
983 typicalInfo.messageLog.add("\t\t\tcreate new route line " + NameUtils.getSafeName(graph, target));
\r
986 // by reusing existing route line
\r
987 target = targetRouteLines[targetRouteLine--];
\r
988 copyRouteLine(graph, source, target);
\r
989 cu.disconnectFromAllRouteNodes(target);
\r
990 typicalInfo.messageLog.add("\t\t\treused existing route line " + NameUtils.getSafeName(graph, target));
\r
993 s2t.put(source, target);
\r
994 t2s.put(target, source);
\r
996 typicalInfo.messageLog.add("\t\t\tmapped source route line " + NameUtils.getSafeName(graph, source) + " to target route line " + NameUtils.getSafeName(graph, target));
\r
999 if (targetRouteLine >= 0) {
\r
1000 typicalInfo.messageLog.add("\t\t\tremove excess route lines (" + (targetRouteLine + 1) + ") from target connection");
\r
1001 for (; targetRouteLine >= 0; targetRouteLine--) {
\r
1002 typicalInfo.messageLog.add("\t\t\t\tremove excess route line: " + NameUtils.getSafeName(graph, targetRouteLines[targetRouteLine], true));
\r
1003 cu.removeConnectionPart(targetRouteLines[targetRouteLine]);
\r
1008 System.out.println("Take 2: Source to target route nodes map : " + s2t);
\r
1009 System.out.println("Take 2: Target to source route nodes map : " + t2s);
\r
1012 // 2.2. Synchronize target connection topology (DIA.AreConnected)
\r
1013 changed |= connectRouteNodes(graph, typicalInfo, sourceInteriorRouteNodes);
\r
1014 changed |= connectRouteNodes(graph, typicalInfo, sourceConnectors);
\r
1016 // 3. remove excess routelines & connectors from target connection
\r
1017 changed |= cu.removeExtraInteriorRouteNodes(targetConnection) > 0;
\r
1018 changed |= cu.removeUnusedConnectors(targetConnection) > 0;
\r
1023 private boolean connectRouteNodes(WriteGraph graph, TypicalInfo typicalInfo, Collection<Resource> sourceRouteNodes) throws DatabaseException {
\r
1024 boolean changed = false;
\r
1025 for (Resource src : sourceRouteNodes) {
\r
1026 Resource dst = s2t.get(src);
\r
1027 if (dst == null) {
\r
1028 throw new DatabaseException("TARGET ROUTE NODE == NULL FOR SRC: " + NameUtils.getSafeName(graph, src));
\r
1031 Collection<Resource> connectedToSrcs = graph.getObjects(src, DIA.AreConnected);
\r
1032 Collection<Resource> connectedToDsts = graph.getObjects(dst, DIA.AreConnected);
\r
1034 // Remove excess statements
\r
1035 for (Resource connectedToDst : connectedToDsts) {
\r
1036 Resource connectedToSrc = t2s.get(connectedToDst);
\r
1037 if (connectedToSrc == null) {
\r
1038 throw new DatabaseException("CONNECTED TO SRC == NULL FOR DST: " + NameUtils.getSafeName(graph, connectedToDst));
\r
1040 if (connectedToSrc == null || !graph.hasStatement(src, DIA.AreConnected, connectedToSrc)) {
\r
1041 graph.deny(dst, DIA.AreConnected, DIA.AreConnected, connectedToDst);
\r
1043 typicalInfo.messageLog.add("\t\t\tdisconnected route nodes (" + NameUtils.getSafeName(graph, dst) + ", " + NameUtils.getSafeName(graph, connectedToDst) + ")");
\r
1047 // Add necessary statements
\r
1048 for (Resource connectedToSrc : connectedToSrcs) {
\r
1049 Resource connectedToDst = s2t.get(connectedToSrc);
\r
1050 if (connectedToDst == null) {
\r
1051 throw new DatabaseException("CONNECTED TO DST == NULL FOR SRC: " + NameUtils.getSafeName(graph, connectedToSrc));
\r
1053 if (!graph.hasStatement(dst, DIA.AreConnected, connectedToDst)) {
\r
1054 graph.claim(dst, DIA.AreConnected, DIA.AreConnected, connectedToDst);
\r
1056 typicalInfo.messageLog.add("\t\t\tconnected route nodes (" + NameUtils.getSafeName(graph, dst) + ", " + NameUtils.getSafeName(graph, connectedToDst) + ")");
\r
1063 private void copyRouteLine(WriteGraph graph, Resource src, Resource tgt) throws DatabaseException {
\r
1064 Double pos = graph.getPossibleRelatedValue(src, DIA.HasPosition, Bindings.DOUBLE);
\r
1065 Boolean hor = graph.getPossibleRelatedValue(src, DIA.IsHorizontal, Bindings.BOOLEAN);
\r
1069 hor = Boolean.TRUE;
\r
1070 graph.claimLiteral(tgt, DIA.HasPosition, L0.Double, pos, Bindings.DOUBLE);
\r
1071 graph.claimLiteral(tgt, DIA.IsHorizontal, L0.Boolean, hor, Bindings.BOOLEAN);
\r
1074 private static String safeNameAndType(ReadGraph graph, Resource r) throws DatabaseException {
\r
1075 StringBuilder sb = new StringBuilder();
\r
1076 sb.append(NameUtils.getSafeName(graph, r, true));
\r
1077 sb.append(" : [");
\r
1078 boolean first = true;
\r
1079 for (Resource type : graph.getPrincipalTypes(r)) {
\r
1083 sb.append(NameUtils.getSafeName(graph, type, true));
\r
1086 return sb.toString();
\r
1089 private static <K, V> Map<K, V> newOrClear(Map<K, V> current) {
\r
1090 if (current == null)
\r
1091 return new THashMap<K, V>();
\r