/** * Return a Fig that can be used to represent the given node. * * <p> * * @param gm The graph model for which we are rendering. * @param lay The layer in the graph on which we want this figure. * @param node The node to be rendered (an model element object) * @param styleAttributes an optional map of attributes to style the fig * @return The fig to be used, or <code>null</code> if we can't create one. */ public FigNode getFigNodeFor(GraphModel gm, Layer lay, Object node, Map styleAttributes) { FigNodeModelElement figNode = null; // Create a new version of the relevant fig if (Model.getFacade().isAActor(node)) { figNode = new FigActor(gm, node); } else if (Model.getFacade().isAUseCase(node)) { figNode = new FigUseCase(gm, node); } else if (Model.getFacade().isAComment(node)) { figNode = new FigComment(gm, node); } else if (Model.getFacade().isAPackage(node)) { figNode = new FigPackage(gm, node); } else { LOG.debug( this.getClass().toString() + ": getFigNodeFor(" + gm.toString() + ", " + lay.toString() + ", " + node.toString() + ") - cannot create this sort of node."); return null; // TODO: Shouldn't we throw an excdeption here?!?! } lay.add(figNode); figNode.setDiElement(GraphChangeAdapter.getInstance().createElement(gm, node)); return figNode; }
/** @see org.argouml.uml.ui.UMLComboBoxModel2#getSelectedModelElement() */ protected Object getSelectedModelElement() { Object target = TargetManager.getInstance().getModelTarget(); if (Model.getFacade().isACallEvent(target)) { return Model.getFacade().getOperation(target); } return null; }
/** * Finds a type in a model by name * * <p>FIXME: duplicated from the method with the same name in * org.argouml.profile.internal.ModelUtils. * * @param s the type name * @param model the model * @return the type or <code>null</code> if the type has not been found. */ public static Object findTypeInModel(String s, Object model) { if (!Model.getFacade().isANamespace(model)) { throw new IllegalArgumentException( "Looking for the classifier " + s + " in a non-namespace object of " + model + ". A namespace was expected."); } Collection allClassifiers = Model.getModelManagementHelper() .getAllModelElementsOfKind(model, Model.getMetaTypes().getClassifier()); Object[] classifiers = allClassifiers.toArray(); Object classifier = null; for (int i = 0; i < classifiers.length; i++) { classifier = classifiers[i]; if (Model.getFacade().getName(classifier) != null && Model.getFacade().getName(classifier).equals(s)) { return classifier; } } return null; }
@Override public void updateListener(Object modelElement, PropertyChangeEvent pce) { Object obj = pce.getSource(); if ((obj == modelElement) && ("stereotype".equals(pce.getPropertyName()) || "taggedValue".equals(pce.getPropertyName()))) { if (pce instanceof AddAssociationEvent && Model.getFacade().isAStereotype(pce.getNewValue())) { // new stereotype addElementListener(pce.getNewValue(), new String[] {"name", "remove"}); } if (pce instanceof RemoveAssociationEvent && Model.getFacade().isAStereotype(pce.getOldValue())) { // removed stereotype removeElementListener(pce.getOldValue()); } if (pce instanceof AddAssociationEvent && Model.getFacade().isATaggedValue(pce.getNewValue())) { addElementListener(pce.getNewValue()); } if (pce instanceof RemoveAssociationEvent && Model.getFacade().isATaggedValue(pce.getOldValue())) { removeElementListener(pce.getOldValue()); } } }
/** * Compare two UML elements names, ignoring case, using names from the path as tie breakers. As a * convenience, we also compare simple strings using the same primary strength collator. * * @param o1 first model element * @param o2 second model element * @return -1, 0, 1 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Object o1, Object o2) { if (o1 == null) { if (o2 == null) { return 0; } return -1; } if (o2 == null) { return 1; } if (o1.equals(o2)) { return 0; } if (o1 instanceof String && o2 instanceof String) { return collator.compare((String) o1, (String) o2); } // Elements are collated first by name hoping for a quick solution String name1, name2; try { name1 = Model.getFacade().getName(o1); name2 = Model.getFacade().getName(o2); } catch (IllegalArgumentException e) { throw new ClassCastException("Model element or String required"); } if (name1 != null && name2 != null) { int comparison = collator.compare(name1, name2); if (comparison != 0) { return comparison; } } // and then by their enclosing path to fully distinguish them return comparePaths(o1, o2); }
/** @see org.argouml.uml.ui.UMLComboBoxModel2#isValidElement(java.lang.Object) */ protected boolean isValidElement(Object element) { Object target = TargetManager.getInstance().getModelTarget(); if (Model.getFacade().isACallEvent(target)) { return element == Model.getFacade().getOperation(target); } return false; }
/** * @param operation The operation. * @param callName The name that we are trying to match. * @param callParams The parameters that we are trying to match. * @return <code>true</code> if the given Operation names and parameters match the given name and * parameters. */ protected boolean operationMatchesCall(Object operation, String callName, Type[] callParams) { if (!callName.equals(Model.getFacade().getName(operation))) { return false; } Collection operationParameters = Model.getFacade().getParameters(operation); if (!Model.getFacade().isReturn(operationParameters.iterator().next())) { LOG.log( Level.WARNING, "ArgoFacade$ArgoAny expects the first operation parameter " + "to be the return type; this isn't the case"); } if (!(Model.getFacade().isReturn(operationParameters.iterator().next()) && operationParameters.size() == (callParams.length + 1))) { return false; } Iterator paramIter = operationParameters.iterator(); paramIter.next(); // skip first parameter == return type int index = 0; while (paramIter.hasNext()) { Object nextParam = paramIter.next(); Object paramType = Model.getFacade().getType(nextParam); // MClassifier Type operationParam = getOclRepresentation(paramType); if (!callParams[index].conformsTo(operationParam)) { return false; } index++; } return true; }
/** * @param assocEnd the given association end name * @param namespace the namespace * @return the default name for the given associationend */ protected String defaultAssocEndName(Object assocEnd, Object namespace) { String name = null; Object type = Model.getFacade().getType(assocEnd); if (type != null) { name = formatElement(type, namespace); } else { name = "unknown type"; } Object mult = Model.getFacade().getMultiplicity(assocEnd); if (mult != null) { StringBuffer buf = new StringBuffer(name); buf.append("["); buf.append(Integer.toString(Model.getFacade().getLower(mult))); buf.append(".."); int upper = Model.getFacade().getUpper(mult); if (upper >= 0) { buf.append(Integer.toString(upper)); } else { buf.append("*"); } buf.append("]"); name = buf.toString(); } return name; }
public Signal buildSignal(Object element) { Signal signal; if ((element instanceof BehavioralFeature)) { signal = buildSignalInt(element); BehavioralFeature bf = (BehavioralFeature) element; ((UmlPackage) bf.refOutermostPackage()) .getCommonBehavior() .getAContextRaisedSignal() .add((BehavioralFeature) element, signal); } else if (element instanceof Reception) { signal = buildSignalInt(element); ((Reception) element).setSignal(signal); } else if (element instanceof SendAction) { signal = buildSignalInt(element); ((SendAction) element).setSignal(signal); } else if (element instanceof SignalEvent) { signal = buildSignalInt(element); ((SignalEvent) element).setSignal(signal); } else { throw new IllegalArgumentException("Can't build a signal for a " + element); } Object namespace = element; while (!Model.getFacade().isAPackage(namespace)) { namespace = Model.getFacade().getModelElementContainer(namespace); } Model.getCoreHelper().setNamespace(signal, namespace); return signal; }
/* * @see org.argouml.ui.explorer.rules.PerspectiveRule#getChildren(java.lang.Object) */ public Collection getChildren(Object parent) { if (Model.getFacade().isAClass(parent)) { ArrayList list = new ArrayList(); if (Model.getFacade().getAttributes(parent).size() > 0) { list.add(new AttributesNode(parent)); } if (Model.getFacade().getAssociationEnds(parent).size() > 0) { list.add(new AssociationsNode(parent)); } if (Model.getFacade().getOperations(parent).size() > 0) { list.add(new OperationsNode(parent)); } if (hasIncomingDependencies(parent)) { list.add(new IncomingDependencyNode(parent)); } if (hasOutGoingDependencies(parent)) { list.add(new OutgoingDependencyNode(parent)); } if (hasInheritance(parent)) { list.add(new InheritanceNode(parent)); } return list; } return Collections.EMPTY_SET; }
/** * Utility function to create a collaboration. * * @return a new collaboration * @param namespace the back-up namespace to put the collaboration in */ protected static Object createCollaboration(Object namespace) { Object target = TargetManager.getInstance().getModelTarget(); if (Model.getFacade().isAUMLElement(target) && Model.getModelManagementHelper().isReadOnly(target)) { target = namespace; } Object collaboration = null; if (Model.getFacade().isAOperation(target)) { Object ns = Model.getFacade().getNamespace(Model.getFacade().getOwner(target)); collaboration = Model.getCollaborationsFactory().buildCollaboration(ns, target); } else if (Model.getFacade().isAClassifier(target)) { Object ns = Model.getFacade().getNamespace(target); collaboration = Model.getCollaborationsFactory().buildCollaboration(ns, target); } else { collaboration = Model.getCollaborationsFactory().createCollaboration(); if (Model.getFacade().isANamespace(target)) { /* TODO: Not all namespaces are useful here - any WFRs? */ namespace = target; } else { if (Model.getFacade().isAModelElement(target)) { Object ns = Model.getFacade().getNamespace(target); if (Model.getFacade().isANamespace(ns)) { namespace = ns; } } } Model.getCoreHelper().setNamespace(collaboration, namespace); Model.getCoreHelper().setName(collaboration, "unattachedCollaboration"); } return collaboration; }
/* * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object) */ @Override protected void updateListeners(Object oldOwner, Object newOwner) { Set<Object[]> l = new HashSet<Object[]>(); if (newOwner != null) { // add the listeners to the newOwner l.add(new Object[] {newOwner, null}); // and its stereotypes for (Object stereo : Model.getFacade().getStereotypes(newOwner)) { l.add(new Object[] {stereo, null}); } // and its features for (Object feat : Model.getFacade().getFeatures(newOwner)) { l.add(new Object[] {feat, null}); // and the stereotypes of its features for (Object stereo : Model.getFacade().getStereotypes(feat)) { l.add(new Object[] {stereo, null}); } } // and its enumerationLiterals for (Object literal : Model.getFacade().getEnumerationLiterals(newOwner)) { l.add(new Object[] {literal, null}); } } // And now add listeners to them all: updateElementListeners(l); }
/** * Check the offenders. * * <p>This is called from the constructors where the offenders are given. * * <p>TODO: Why do we only care about checking the first 2 offenders above? * * @param offs The offenders. */ private void checkOffs(ListSet offs) { if (offs == null) { throw new IllegalArgumentException("A ListSet of offenders must be supplied."); } Object offender = CollectionUtil.getFirstItemOrNull(offs); if (offender != null && !Model.getFacade().isAModelElement(offender) && !(offender instanceof Fig) && !(offender instanceof Diagram)) { // TODO: The cognotive system should not be aware of any other // system. Find a better way to do this. throw new IllegalArgumentException( "The first offender must be a model element, " + "a Fig or a Diagram"); } if (offs.size() >= 2) { offender = offs.elementAt(1); if (!Model.getFacade().isAModelElement(offender) && !(offender instanceof Fig) && !(offender instanceof Diagram)) { // TODO: The cognotive system should not be aware of any other // system. Find a better way to do this. throw new IllegalArgumentException( "The second offender must be a model element, " + "a Fig or a Diagram"); } } }
private Collection getApplicableTagDefinitions(Object t) { Set<List<String>> paths = new HashSet<List<String>>(); Set<Object> availableTagDefs = new TreeSet<Object>(new PathComparator()); Collection stereotypes = Model.getFacade().getStereotypes(t); Project project = ProjectManager.getManager().getCurrentProject(); for (Object model : project.getModels()) { addAllUniqueModelElementsFrom( availableTagDefs, paths, Model.getModelManagementHelper() .getAllModelElementsOfKind(model, Model.getMetaTypes().getTagDefinition())); } addAllUniqueModelElementsFrom( availableTagDefs, paths, project.getProfileConfiguration().findByMetaType(Model.getMetaTypes().getTagDefinition())); List notValids = new ArrayList(); for (Object tagDef : availableTagDefs) { Object owner = Model.getFacade().getOwner(tagDef); if (owner != null && !stereotypes.contains(owner)) { notValids.add(tagDef); } } int size = availableTagDefs.size(); availableTagDefs.removeAll(notValids); int delta = size - availableTagDefs.size(); return availableTagDefs; }
/* * @see org.argouml.uml.ui.UMLModelElementListModel2#setTarget(java.lang.Object) */ public void setTarget(Object target) { if (getTarget() != null) { Enumeration enumeration = elements(); while (enumeration.hasMoreElements()) { Object base = enumeration.nextElement(); Model.getPump().removeModelEventListener(this, base, "feature"); } Model.getPump().removeModelEventListener(this, getTarget(), "base"); } target = target instanceof Fig ? ((Fig) target).getOwner() : target; if (!Model.getFacade().isAModelElement(target)) // TODO: - isn't this an error condition? Should we not throw // an exception or at least log. return; setListTarget(target); if (getTarget() != null) { Collection bases = Model.getFacade().getBases(getTarget()); Iterator it = bases.iterator(); while (it.hasNext()) { Object base = it.next(); Model.getPump().addModelEventListener(this, base, "feature"); } // make sure we know it when a classifier is added as a base Model.getPump().addModelEventListener(this, getTarget(), "base"); removeAllElements(); setBuildingModel(true); buildModelList(); setBuildingModel(false); if (getSize() > 0) { fireIntervalAdded(this, 0, getSize() - 1); } } }
/** * The trigger for the critic. * * <p>Finds all the operations for the given classifier. Takes each operation in turn and compares * its signature with all earlier operations. This version corrects an earlier bug, which checked * for matching names as well as types in the parameter list. * * <p><em>Note</em>. The signature ignores any return parameters in looking for a match. This is * in line with Java/C++. * * <p>We do not need to worry about signature clashes that are inherited (overloading). This is * something encouraged in many OO environments to facilitate polymorphism. * * <p>This algorithm is quadratic in the number of operations. If this became a problem, we would * have to consider sorting the operations list and comparing only adjacent pairs (potentially O(n * log n) performance). * * <p> * * @param dm the {@link Object} to be checked against the critic. * @param dsgr the {@link Designer} creating the model. Not used, this is for future development * of ArgoUML. * @return {@link #PROBLEM_FOUND PROBLEM_FOUND} if the critic is triggered, otherwise {@link * #NO_PROBLEM NO_PROBLEM}. */ @Override public boolean predicate2(Object dm, Designer dsgr) { // Only do this for classifiers if (!(Model.getFacade().isAClassifier(dm))) { return NO_PROBLEM; } // Get all the features (giving up if there are none). Then loop // through finding all operations. Each time we find one, we compare // its signature with all previous (held in collection operSeen), and then // if it doesn't match add it to the collection. Collection operSeen = new ArrayList(); for (Object op : Model.getFacade().getOperations(dm)) { // Compare against all earlier operations. If there's a match we've // found the problem for (Object o : operSeen) { if (signaturesMatch(op, o)) { return PROBLEM_FOUND; } } // Add to the collection and round to look at the next one operSeen.add(op); } // If we drop out here, there was no match and we have no problem return NO_PROBLEM; }
public String formatElement(Object element, Object namespace) { String value = null; if (element == null) { value = ""; } else { Object elementNs = Model.getFacade().getNamespace(element); // // if element is an AssociationEnd use // the namespace of containing association // if (Model.getFacade().isAAssociationEnd(element)) { Object assoc = Model.getFacade().getAssociation(element); if (assoc != null) { elementNs = Model.getFacade().getNamespace(assoc); } } if (elementNs == namespace) { value = Model.getFacade().getName(element); if (value == null || value.length() == 0) { value = defaultName(element, namespace); } } else { StringBuffer buffer = new StringBuffer(); String pathSep = getPathSeparator(); buildPath(buffer, element, pathSep); value = buffer.toString(); } } return value; }
private Type internalNavigateParameterized( final String name, final Type[] params, boolean fCheckIsQuery) throws OclTypeException { if (classifier == null) { throw new OclTypeException("attempting to access features of Void"); } Type type = Basic.navigateAnyParameterized(name, params); if (type != null) { return type; } Object foundOp = null; // MOperation java.util.Collection operations = Model.getFacade().getOperations(classifier); Iterator iter = operations.iterator(); while (iter.hasNext() && foundOp == null) { Object op = iter.next(); if (operationMatchesCall(op, name, params)) { foundOp = op; } } if (foundOp == null) { throw new OclTypeException("operation " + name + " not found in classifier " + toString()); } if (fCheckIsQuery) { /* Query checking added 05/21/01, sz9 */ if (!Model.getFacade().isQuery(foundOp)) { throw new OclTypeException( "Non-query operations cannot " + "be used in OCL expressions. (" + name + ")"); } } Collection returnParams = Model.getCoreHelper().getReturnParameters(foundOp); Object rp; if (returnParams.size() == 0) { rp = null; } else { rp = returnParams.iterator().next(); } if (returnParams.size() > 1) { LOG.log( Level.WARNING, "OCL compiler only handles one return parameter" + " - Found " + returnParams.size() + " for " + Model.getFacade().getName(foundOp)); } if (rp == null || Model.getFacade().getType(rp) == null) { LOG.log(Level.WARNING, "WARNING: supposing return type void!"); return new ArgoAny(null); } Object returnType = Model.getFacade().getType(rp); return getOclRepresentation(returnType); }
/* * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { super.actionPerformed(e); if (Model.getFacade().isAExtend(getTarget())) { Object point = Model.getUseCasesFactory().buildExtensionPoint(Model.getFacade().getBase(getTarget())); Model.getUseCasesHelper().addExtensionPoint(getTarget(), point); } }
/* * @see org.argouml.uml.cognitive.critics.CrUML#predicate2( * java.lang.Object, org.argouml.cognitive.Designer) */ public boolean predicate2(Object dm, Designer dsgr) { if (!(Model.getFacade().isAAttribute(dm))) return NO_PROBLEM; Object attr = dm; String myName = Model.getFacade().getName(attr); if (myName == null || "".equals(myName)) return PROBLEM_FOUND; if (myName.length() == 0) return PROBLEM_FOUND; return NO_PROBLEM; }
static String generateExpression(Object expr) { if (Model.getFacade().isAExpression(expr)) { return generateUninterpreted((String) Model.getFacade().getBody(expr)); } else if (Model.getFacade().isAConstraint(expr)) { return generateExpression(Model.getFacade().getBody(expr)); } return ""; }
/* * @see org.tigris.gef.util.Predicate#predicate(java.lang.Object) */ public boolean predicate(Object o) { if (!(Model.getFacade().isAUMLElement(o))) { return false; } Object me = o; return theType.predicate(me) && specific.predicate(me) && elementName.predicate(Model.getFacade().getName(me)); }
/** * @param gen the given Generalization * @param namespace the namespace * @return the default generalization name */ protected String defaultGeneralizationName(Object gen, Object namespace) { Object child = Model.getFacade().getSpecific(gen); Object parent = Model.getFacade().getGeneral(gen); StringBuffer buf = new StringBuffer(); buf.append(formatElement(child, namespace)); buf.append(" extends "); buf.append(formatElement(parent, namespace)); return buf.toString(); }
/** @return the value of the tagged value */ protected String getProperty() { String eventName = getEventName(); if (Model.getFacade().isAModelElement(getTarget())) { Object taggedValue = Model.getFacade().getTaggedValue(getTarget(), eventName); if (taggedValue != null) { return Model.getFacade().getValueOfTag(taggedValue); } } return ""; }
@Override public void setValue(Object value) { if (Model.getFacade().isAModelElement(value)) { String name = Model.getFacade().getName(value); setText(name); } else { if (value instanceof String) setText((String) value); else setText(""); } }
static String generateParameter(Object parameter) { StringBuffer sb = new StringBuffer(20); // TODO: qualifiers (e.g., const) // TODO: stereotypes... sb.append(generateClassifierRef(Model.getFacade().getType(parameter))); sb.append(' '); sb.append(Model.getFacade().getName(parameter)); // TODO: initial value return sb.toString(); }
/* * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { Object target = TargetManager.getInstance().getModelTarget(); if (Model.getFacade().isAExtensionPoint(target)) { TargetManager.getInstance() .setTarget( Model.getUseCasesFactory() .buildExtensionPoint(Model.getFacade().getUseCase(target))); super.actionPerformed(e); } }
/* * @see org.tigris.gef.graph.GraphNodeRenderer#getFigNodeFor( * org.tigris.gef.graph.GraphModel, org.tigris.gef.base.Layer, * java.lang.Object, java.util.Map) */ public FigNode getFigNodeFor(GraphModel gm, Layer lay, Object node, Map styleAttributes) { FigNode result = null; if (Model.getFacade().isAClassifierRole(node)) { result = new FigClassifierRole(node); } else if (Model.getFacade().isAComment(node)) { result = new FigComment(gm, node); } LOG.debug("SequenceDiagramRenderer getFigNodeFor " + result); return result; }
/** * @see org.argouml.uml.cognitive.critics.CrUML#predicate2(java.lang.Object, * org.argouml.cognitive.Designer) */ public boolean predicate2(Object dm, Designer dsgr) { Object destinationRegion = null; Object sourceRegion = null; Object aux = null; Object tr = null; if (!Model.getFacade().isASynchState(dm)) return NO_PROBLEM; Iterator outgoing = Model.getFacade().getOutgoings(dm).iterator(); while (outgoing.hasNext()) { tr = outgoing.next(); aux = Model.getFacade().getContainer(Model.getFacade().getTarget(tr)); if (destinationRegion == null) destinationRegion = aux; else if (!aux.equals(destinationRegion)) return PROBLEM_FOUND; } Iterator incoming = Model.getFacade().getIncomings(dm).iterator(); while (incoming.hasNext()) { tr = incoming.next(); aux = Model.getFacade().getContainer(Model.getFacade().getSource(tr)); if (sourceRegion == null) sourceRegion = aux; else if (!aux.equals(sourceRegion)) return PROBLEM_FOUND; } if (destinationRegion != null && !Model.getFacade().isAConcurrentRegion(destinationRegion)) return PROBLEM_FOUND; if (sourceRegion != null && !Model.getFacade().isAConcurrentRegion(sourceRegion)) return PROBLEM_FOUND; return NO_PROBLEM; }
/* * @see org.argouml.ui.explorer.rules.PerspectiveRule#getChildren(java.lang.Object) */ public Collection getChildren(Object parent) { if (Model.getFacade().isATransition(parent)) { Object effect = Model.getFacade().getEffect(parent); if (effect != null) { Collection col = new ArrayList(); col.add(effect); return col; } } return Collections.EMPTY_SET; }