|
What this is
Other links
The source code
// $Id: UmlFactory.java,v 1.50 2004/08/11 16:30:18 mvw Exp $
// Copyright (c) 1996-2004 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation without fee, and without a written
// agreement is hereby granted, provided that the above copyright notice
// and this paragraph appear in all copies. This software program and
// documentation are copyrighted by The Regents of the University of
// California. The software program and documentation are supplied "AS
// IS", without any accompanying services from The Regents. The Regents
// does not warrant that the operation of the program will be
// uninterrupted or error-free. The end-user understands that the program
// was developed for research purposes and is advised not to rely
// exclusively on the program for any reason. IN NO EVENT SHALL THE
// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
package org.argouml.model.uml;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import org.apache.log4j.Logger;
import org.argouml.model.ModelFacade;
import org.argouml.model.UmlModelEntity;
import org.argouml.model.uml.behavioralelements.activitygraphs.ActivityGraphsFactory;
import org.argouml.model.uml.behavioralelements.collaborations.CollaborationsFactory;
import org.argouml.model.uml.behavioralelements.commonbehavior.CommonBehaviorFactory;
import org.argouml.model.uml.behavioralelements.statemachines.StateMachinesFactory;
import org.argouml.model.uml.behavioralelements.usecases.UseCasesFactory;
import org.argouml.model.uml.foundation.core.CoreFactory;
import org.argouml.model.uml.foundation.datatypes.DataTypesFactory;
import org.argouml.model.uml.foundation.extensionmechanisms.ExtensionMechanismsFactory;
import org.argouml.model.uml.modelmanagement.ModelManagementFactory;
import org.argouml.uml.diagram.static_structure.ui.CommentEdge;
import ru.novosoft.uml.MBase;
import ru.novosoft.uml.MFactory;
import ru.novosoft.uml.behavior.activity_graphs.MActivityGraph;
import ru.novosoft.uml.behavior.activity_graphs.MCallState;
import ru.novosoft.uml.behavior.activity_graphs.MClassifierInState;
import ru.novosoft.uml.behavior.activity_graphs.MObjectFlowState;
import ru.novosoft.uml.behavior.activity_graphs.MPartition;
import ru.novosoft.uml.behavior.activity_graphs.MSubactivityState;
import ru.novosoft.uml.behavior.collaborations.MAssociationEndRole;
import ru.novosoft.uml.behavior.collaborations.MAssociationRole;
import ru.novosoft.uml.behavior.collaborations.MClassifierRole;
import ru.novosoft.uml.behavior.collaborations.MCollaboration;
import ru.novosoft.uml.behavior.collaborations.MInteraction;
import ru.novosoft.uml.behavior.collaborations.MMessage;
import ru.novosoft.uml.behavior.common_behavior.MAction;
import ru.novosoft.uml.behavior.common_behavior.MAttributeLink;
import ru.novosoft.uml.behavior.common_behavior.MCallAction;
import ru.novosoft.uml.behavior.common_behavior.MComponentInstance;
import ru.novosoft.uml.behavior.common_behavior.MCreateAction;
import ru.novosoft.uml.behavior.common_behavior.MDataValue;
import ru.novosoft.uml.behavior.common_behavior.MDestroyAction;
import ru.novosoft.uml.behavior.common_behavior.MException;
import ru.novosoft.uml.behavior.common_behavior.MInstance;
import ru.novosoft.uml.behavior.common_behavior.MLink;
import ru.novosoft.uml.behavior.common_behavior.MLinkEnd;
import ru.novosoft.uml.behavior.common_behavior.MLinkObject;
import ru.novosoft.uml.behavior.common_behavior.MNodeInstance;
import ru.novosoft.uml.behavior.common_behavior.MObject;
import ru.novosoft.uml.behavior.common_behavior.MReception;
import ru.novosoft.uml.behavior.common_behavior.MReturnAction;
import ru.novosoft.uml.behavior.common_behavior.MSendAction;
import ru.novosoft.uml.behavior.common_behavior.MSignal;
import ru.novosoft.uml.behavior.common_behavior.MTerminateAction;
import ru.novosoft.uml.behavior.common_behavior.MUninterpretedAction;
import ru.novosoft.uml.behavior.state_machines.MCompositeState;
import ru.novosoft.uml.behavior.state_machines.MFinalState;
import ru.novosoft.uml.behavior.state_machines.MGuard;
import ru.novosoft.uml.behavior.state_machines.MPseudostate;
import ru.novosoft.uml.behavior.state_machines.MSimpleState;
import ru.novosoft.uml.behavior.state_machines.MState;
import ru.novosoft.uml.behavior.state_machines.MStateMachine;
import ru.novosoft.uml.behavior.state_machines.MStateVertex;
import ru.novosoft.uml.behavior.state_machines.MStubState;
import ru.novosoft.uml.behavior.state_machines.MSubmachineState;
import ru.novosoft.uml.behavior.state_machines.MSynchState;
import ru.novosoft.uml.behavior.state_machines.MTransition;
import ru.novosoft.uml.behavior.use_cases.MActor;
import ru.novosoft.uml.behavior.use_cases.MExtend;
import ru.novosoft.uml.behavior.use_cases.MExtensionPoint;
import ru.novosoft.uml.behavior.use_cases.MInclude;
import ru.novosoft.uml.behavior.use_cases.MUseCase;
import ru.novosoft.uml.behavior.use_cases.MUseCaseInstance;
import ru.novosoft.uml.foundation.core.MAbstraction;
import ru.novosoft.uml.foundation.core.MAssociation;
import ru.novosoft.uml.foundation.core.MAssociationClass;
import ru.novosoft.uml.foundation.core.MAssociationEnd;
import ru.novosoft.uml.foundation.core.MAttribute;
import ru.novosoft.uml.foundation.core.MBehavioralFeature;
import ru.novosoft.uml.foundation.core.MBinding;
import ru.novosoft.uml.foundation.core.MClass;
import ru.novosoft.uml.foundation.core.MClassifier;
import ru.novosoft.uml.foundation.core.MComment;
import ru.novosoft.uml.foundation.core.MComponent;
import ru.novosoft.uml.foundation.core.MConstraint;
import ru.novosoft.uml.foundation.core.MDataType;
import ru.novosoft.uml.foundation.core.MDependency;
import ru.novosoft.uml.foundation.core.MElement;
import ru.novosoft.uml.foundation.core.MFeature;
import ru.novosoft.uml.foundation.core.MFlow;
import ru.novosoft.uml.foundation.core.MGeneralizableElement;
import ru.novosoft.uml.foundation.core.MGeneralization;
import ru.novosoft.uml.foundation.core.MInterface;
import ru.novosoft.uml.foundation.core.MMethod;
import ru.novosoft.uml.foundation.core.MModelElement;
import ru.novosoft.uml.foundation.core.MNamespace;
import ru.novosoft.uml.foundation.core.MNode;
import ru.novosoft.uml.foundation.core.MOperation;
import ru.novosoft.uml.foundation.core.MParameter;
import ru.novosoft.uml.foundation.core.MPermission;
import ru.novosoft.uml.foundation.core.MPresentationElement;
import ru.novosoft.uml.foundation.core.MRelationship;
import ru.novosoft.uml.foundation.core.MStructuralFeature;
import ru.novosoft.uml.foundation.core.MTemplateParameter;
import ru.novosoft.uml.foundation.core.MUsage;
import ru.novosoft.uml.foundation.data_types.MActionExpression;
import ru.novosoft.uml.foundation.data_types.MAggregationKind;
import ru.novosoft.uml.foundation.extension_mechanisms.MStereotype;
import ru.novosoft.uml.foundation.extension_mechanisms.MTaggedValue;
import ru.novosoft.uml.model_management.MElementImport;
import ru.novosoft.uml.model_management.MModel;
import ru.novosoft.uml.model_management.MPackage;
import ru.novosoft.uml.model_management.MSubsystem;
/**
* Root factory for UML model element instance creation.
*
* @since ARGO0.11.2
* @author Thierry Lach
* @stereotype singleton
*/
public class UmlFactory extends AbstractUmlModelFactory {
/**
* The logger
*/
private static final Logger LOG =
Logger.getLogger(UmlFactory.class);
/**
* A map of valid connections keyed by the connection type.
* The constructor builds this from the data in the VALID_CONNECTIONS array
*/
private Map validConnectionMap = new HashMap();
private boolean jmiProxyCreated = false;
/**
* An array of valid connections, the combination of connecting class
* and node classes must exist as a row in this list to be considered
* valid.
*
* * The actual deletion is delegated to delete methods in the rest of the * factories. For example: a method deleteClass exists on CoreHelper. * Delete methods as deleteClass should only do those extra actions that are * necessary for the deletion of the modelelement itself. I.e. deleteClass * should only take care of things specific to MClass. * * The delete methods in the UML Factories should not be called directly * throughout the code! Calls should allways refer to this method and never * call the deleteXXX method on XXXFactory directly. The reason that it is * possible to call the deleteXXX methods directly is a pure implementation * detail. * * The implementation of this method uses a quite complicate if then else * tree. This is done to provide optimal performance and full compliance to * the UML 1.3 model. The last remark refers to the fact that the UML 1.3 * model knows multiple inheritance in several places. This has to be taken * into account. * * Extensions and its children are not taken into account * here. They do not require extra cleanup actions. Not in the * form of a call to the remove method as is normal for all * children of MBase and not in the form of other behaviour we * want to implement via this operation. * @param elem The element to be deleted */ public void delete(Object elem) { if (elem == null) throw new IllegalArgumentException("Element may not be null " + "in delete"); if (elem instanceof MElement) { getCore().deleteElement((MElement) elem); if (elem instanceof MModelElement) { getCore().deleteModelElement((MModelElement) elem); if (elem instanceof MFeature) { deleteFeature((MFeature) elem); } else if (elem instanceof MNamespace) { deleteNamespace((MNamespace) elem); } // no else here to make sure MClassifier with // its double inheritance goes ok // no else here too to make sure MAssociationClass goes ok if (elem instanceof MGeneralizableElement) { MGeneralizableElement ge = (MGeneralizableElement) elem; getCore().deleteGeneralizableElement(ge); if (elem instanceof MStereotype) { MStereotype s = (MStereotype) elem; getExtensionMechanisms().deleteStereotype(s); } } // no else here to make sure MAssociationClass goes ok if (elem instanceof MParameter) { getCore().deleteParameter((MParameter) elem); } else if (elem instanceof MConstraint) { getCore().deleteConstraint((MConstraint) elem); } else if (elem instanceof MRelationship) { deleteRelationship((MRelationship) elem); } else if (elem instanceof MAssociationEnd) { getCore().deleteAssociationEnd((MAssociationEnd) elem); if (elem instanceof MAssociationEndRole) { getCollaborations() .deleteAssociationEndRole( (MAssociationEndRole) elem); } } else if (elem instanceof MComment) { getCore().deleteComment((MComment) elem); } else if (ModelFacade.isAAction(elem)) { deleteAction(elem); } else if (elem instanceof MAttributeLink) { getCommonBehavior() .deleteAttributeLink((MAttributeLink) elem); } else if (elem instanceof MInstance) { deleteInstance((MInstance) elem); } // no else to handle multiple inheritance of linkobject if (elem instanceof MLink) { getCommonBehavior().deleteLink((MLink) elem); } else if (elem instanceof MLinkEnd) { getCommonBehavior().deleteLinkEnd((MLinkEnd) elem); } else if (elem instanceof MInteraction) { getCollaborations().deleteInteraction((MInteraction) elem); } else if (elem instanceof MMessage) { getCollaborations().deleteMessage((MMessage) elem); } else if (elem instanceof MExtensionPoint) { getUseCases().deleteExtensionPoint((MExtensionPoint) elem); } else if (elem instanceof MStateVertex) { deleteStateVertex((MStateVertex) elem); } if (elem instanceof MStateMachine) { getStateMachines().deleteStateMachine((MStateMachine) elem); if (elem instanceof MActivityGraph) { getActivityGraphs() .deleteActivityGraph((MActivityGraph) elem); } } else if (elem instanceof MTransition) { getStateMachines().deleteTransition((MTransition) elem); } else if (elem instanceof MGuard) { getStateMachines().deleteGuard((MGuard) elem); } // else if (elem instanceof MEvent) { // //} } else if (elem instanceof MPresentationElement) { getCore().deletePresentationElement( (MPresentationElement) elem); } } else if (elem instanceof MTemplateParameter) { getCore().deleteTemplateParameter((MTemplateParameter) elem); } else if (elem instanceof MTaggedValue) { getExtensionMechanisms().deleteTaggedValue((MTaggedValue) elem); } if (elem instanceof MPartition) { getActivityGraphs().deletePartition((MPartition) elem); } else if (elem instanceof MElementImport) { getModelManagement().deleteElementImport((MElementImport) elem); } if (elem instanceof MBase) { ((MBase) elem).remove(); UmlModelEventPump.getPump().cleanUp((MBase) elem); } } /** * Factored this method out of delete to simplify the design of the delete * operation * @param elem */ private void deleteFeature(MFeature elem) { getCore().deleteFeature(elem); if (elem instanceof MBehavioralFeature) { getCore().deleteBehavioralFeature((MBehavioralFeature) elem); if (elem instanceof MOperation) { getCore().deleteOperation((MOperation) elem); } else if (elem instanceof MMethod) { getCore().deleteMethod((MMethod) elem); } else if (elem instanceof MReception) { getCommonBehavior().deleteReception((MReception) elem); } } else if (elem instanceof MStructuralFeature) { getCore().deleteStructuralFeature((MStructuralFeature) elem); if (elem instanceof MAttribute) { getCore().deleteAttribute((MAttribute) elem); } } } /** * Factored this method out of delete to simplify the design of the delete * operation * @param elem */ private void deleteNamespace(MNamespace elem) { getCore().deleteNamespace(elem); if (elem instanceof MClassifier) { getCore().deleteClassifier(elem); if (elem instanceof MClass) { getCore().deleteClass((MClass) elem); if (elem instanceof MAssociationClass) { getCore().deleteAssociationClass((MAssociationClass) elem); } } else if (elem instanceof MInterface) { getCore().deleteInterface((MInterface) elem); } else if (elem instanceof MDataType) { getCore().deleteDataType((MDataType) elem); } else if (elem instanceof MNode) { getCore().deleteNode((MNode) elem); } else if (elem instanceof MComponent) { getCore().deleteComponent((MComponent) elem); } else if (elem instanceof MSignal) { getCommonBehavior().deleteSignal((MSignal) elem); if (elem instanceof MException) { getCommonBehavior().deleteException((MException) elem); } } else if (elem instanceof MClassifierRole) { getCollaborations().deleteClassifierRole( (MClassifierRole) elem); } else if (elem instanceof MUseCase) { getUseCases().deleteUseCase((MUseCase) elem); } else if (elem instanceof MActor) { getUseCases().deleteActor((MActor) elem); } else if (elem instanceof MClassifierInState) { getActivityGraphs().deleteClassifierInState( (MClassifierInState) elem); } } else if (elem instanceof MCollaboration) { getCollaborations().deleteCollaboration((MCollaboration) elem); } else if (elem instanceof MPackage) { getModelManagement().deletePackage((MPackage) elem); if (elem instanceof MModel) { getModelManagement().deleteModel((MModel) elem); } else if (elem instanceof MSubsystem) { getModelManagement().deleteSubsystem((MSubsystem) elem); } } } /** * Factored this method out of delete to simplify the design of the delete * operation * @param elem */ private void deleteRelationship(MRelationship elem) { getCore().deleteRelationship(elem); if (elem instanceof MFlow) { getCore().deleteFlow((MFlow) elem); } else if (elem instanceof MGeneralization) { getCore().deleteGeneralization((MGeneralization) elem); } else if (elem instanceof MAssociation) { getCore().deleteAssociation((MAssociation) elem); if (elem instanceof MAssociationRole) { getCollaborations().deleteAssociationRole( (MAssociationRole) elem); } } else if (elem instanceof MDependency) { getCore().deleteDependency((MDependency) elem); if (ModelFacade.isAAbstraction(elem)) { getCore().deleteAbstraction(elem); } else if (elem instanceof MBinding) { getCore().deleteBinding((MBinding) elem); } else if (elem instanceof MUsage) { getCore().deleteUsage((MUsage) elem); } else if (elem instanceof MPermission) { getCore().deletePermission((MPermission) elem); } } else if (elem instanceof MInclude) { getUseCases().deleteInclude((MInclude) elem); } else if (elem instanceof MExtend) { getUseCases().deleteExtend((MExtend) elem); } } /** * Factored this method out of delete to simplify the design of the delete * operation * @param elem */ private void deleteAction(Object elem) { getCommonBehavior().deleteAction(elem); if (ModelFacade.isAActionSequence(elem)) { getCommonBehavior().deleteActionSequence(elem); } else if (elem instanceof MCreateAction) { getCommonBehavior().deleteCreateAction((MCreateAction) elem); } else if (elem instanceof MCallAction) { getCommonBehavior().deleteCallAction((MCallAction) elem); } else if (elem instanceof MReturnAction) { getCommonBehavior().deleteReturnAction((MReturnAction) elem); } else if (elem instanceof MSendAction) { getCommonBehavior().deleteSendAction((MSendAction) elem); } else if (elem instanceof MTerminateAction) { getCommonBehavior().deleteTerminateAction((MTerminateAction) elem); } else if (elem instanceof MUninterpretedAction) { getCommonBehavior().deleteUninterpretedAction( (MUninterpretedAction) elem); } else if (elem instanceof MDestroyAction) { getCommonBehavior().deleteDestroyAction((MDestroyAction) elem); } } /** * Factored this method out of delete to simplify the design of the delete * operation * @param elem */ private void deleteInstance(MInstance elem) { getCommonBehavior().deleteInstance(elem); if (elem instanceof MDataValue) { getCommonBehavior().deleteDataValue((MDataValue) elem); } else if (elem instanceof MComponentInstance) { getCommonBehavior().deleteComponentInstance( (MComponentInstance) elem); } else if (elem instanceof MNodeInstance) { getCommonBehavior().deleteNodeInstance((MNodeInstance) elem); } else if (elem instanceof MObject) { getCommonBehavior().deleteObject((MObject) elem); if (elem instanceof MLinkObject) { getCommonBehavior().deleteLinkObject((MLinkObject) elem); } } if (elem instanceof MUseCaseInstance) { getUseCases().deleteUseCaseInstance((MUseCaseInstance) elem); } } /** * Factored this method out of delete to simplify the design of the delete * operation * @param elem */ private void deleteStateVertex(MStateVertex elem) { getStateMachines().deleteStateVertex(elem); if (elem instanceof MPseudostate) { getStateMachines().deletePseudostate((MPseudostate) elem); } else if (elem instanceof MSynchState) { getStateMachines().deleteSynchState((MSynchState) elem); } else if (elem instanceof MStubState) { getStateMachines().deleteStubState((MStubState) elem); } else if (elem instanceof MState) { getStateMachines().deleteState((MState) elem); if (elem instanceof MCompositeState) { getStateMachines().deleteCompositeState((MCompositeState) elem); if (elem instanceof MSubmachineState) { getStateMachines().deleteSubmachineState( (MSubmachineState) elem); if (elem instanceof MSubactivityState) { getActivityGraphs().deleteSubactivityState( (MSubactivityState) elem); } } } else if (elem instanceof MSimpleState) { getStateMachines().deleteSimpleState((MSimpleState) elem); if (ModelFacade.isAActionState(elem)) { getActivityGraphs().deleteActionState(elem); if (elem instanceof MCallState) { getActivityGraphs().deleteCallState((MCallState) elem); } } else if (elem instanceof MObjectFlowState) { getActivityGraphs().deleteObjectFlowState( (MObjectFlowState) elem); } } else if (elem instanceof MFinalState) { getStateMachines().deleteFinalState((MFinalState) elem); } } } class ObjectCreateInfo { private Object factory; private String createMethod; private Class javaClass; // ObjectCreateInfo (Class javaClass, Object fact, String meth) { // this(javaClass, fact, meth, fact, meth); // } ObjectCreateInfo (Class cls, Object fact, String meth) { javaClass = cls; factory = fact; createMethod = meth; } /** * @return */ public Class getJavaClass() { return javaClass; } /** * @return */ public String getCreateMethod() { return createMethod; } /** * @return */ public Object getFactory() { return factory; } } /** Create an empty but initialized instance of a UML ActionExpression. * NSUML does not have a factory method for this. * * @return an initialized UML ActionExpression instance. */ public MActionExpression createActionExpression() { MActionExpression expression = new MActionExpression("", ""); DataTypesFactory.getFactory().initialize(expression); return expression; } /** Create a UML object from the implementation name. * * This will allow abstraction of the create mechanism at a single point. * * @param entity name to create - must be implemented in * {@link org.argouml.model.uml.Uml}. * * @return the entity requested or null if unable to create */ public Object create(String entity) { throw new RuntimeException("Not yet implemented"); // return create((Class) Uml.getUmlClassList().get(entity)); } /** Create a UML object from the implementation. * * This will allow abstraction of the create mechanism at a single point. * * @param entity Class to create - must implement * {@link UmlModelEntity} * @return the created entity or null if unable to create */ public Object create(UmlModelEntity entity) { ObjectCreateInfo oi = (ObjectCreateInfo) elements.get(entity); if (oi == null) { return null; // TODO: decide if we want to throw an exception instead // throw new InvalidObjectRequestException //("Cannot identify the object type", entity); } Method method = null; try { method = oi.getFactory().getClass().getMethod(oi.getCreateMethod(), new Class[] {} ); } catch (Exception e) { LOG.error("Failed to invoke create method on factory.", e); return null; // TODO: decide if we want to throw an exception instead // throw new InvalidObjectRequestException //("Cannot find creator method", entity, e); } Object obj = null; try { obj = method.invoke(oi.getFactory(), new Object[] {} ); } catch (Exception e) { // TODO: decide if we want to throw an exception instead // throw new InvalidObjectRequestException //("Cannot execute creator method", entity, e); LOG.error("Failed to invoke create method on factory.", e); return null; } UmlFactory.getFactory().initialize(obj); // Allow for testing of the proxy capability if (jmiProxyCreated) { // TODO: implement RefPackageProxy handling // if (obj instanceof MPackage) { // return RefPackageProxy.newInstance(obj); // } return RefBaseObjectProxy.newInstance(obj); } return obj; } } |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.