/******************************************************************************* | |
* Copyright (c) 2007 Cisco Systems, Inc. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* E. Dillon (Cisco Systems, Inc.) - reformat for Code Open-Sourcing | |
*******************************************************************************/ | |
package org.eclipse.tigerstripe.workbench.internal.api.impl; | |
import java.io.Reader; | |
import java.net.URI; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.Collections; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
import org.eclipse.core.runtime.IProgressMonitor; | |
import org.eclipse.core.runtime.NullProgressMonitor; | |
import org.eclipse.core.runtime.SubMonitor; | |
import org.eclipse.tigerstripe.workbench.IModelChangeDelta; | |
import org.eclipse.tigerstripe.workbench.TigerstripeException; | |
import org.eclipse.tigerstripe.workbench.internal.api.contract.segment.IFacetReference; | |
import org.eclipse.tigerstripe.workbench.internal.api.impl.updater.ModelUpdaterImpl; | |
import org.eclipse.tigerstripe.workbench.internal.api.model.IActiveFacetChangeListener; | |
import org.eclipse.tigerstripe.workbench.internal.api.model.IArtifactChangeListener; | |
import org.eclipse.tigerstripe.workbench.internal.api.model.artifacts.updater.IModelUpdater; | |
import org.eclipse.tigerstripe.workbench.internal.core.TigerstripeRuntime; | |
import org.eclipse.tigerstripe.workbench.internal.core.TigerstripeWorkspaceNotifier; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.ArtifactManager; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.AssociationArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.AssociationClassArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.DatatypeArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.DependencyArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.EnumArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.EventArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.ExceptionArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.ExecutionContext; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.IAbstractArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.IArtifactManagerInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.ManagedEntityArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.ModelChangeDelta; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.PackageArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.PrimitiveTypeArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.QueryArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.SessionFacadeArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.model.UpdateProcedureArtifactInternal; | |
import org.eclipse.tigerstripe.workbench.internal.core.module.ModuleArtifactManager; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IAbstractArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IArtifactManagerSessionInternal; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IAssociationArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IAssociationClassArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IAssociationEnd; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IDatatypeArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IDependencyArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IEnumArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IEventArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IExceptionArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IManagedEntityArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IPackageArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IPrimitiveTypeArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IQueryArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IRelationship; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.ISessionArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IType; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.IUpdateProcedureArtifact; | |
import org.eclipse.tigerstripe.workbench.model.deprecated_.ossj.IOssjArtifactSpecifics; | |
public class ArtifactManagerSessionImpl extends BaseArtifactManagerSessionImpl | |
implements IArtifactManagerSessionInternal { | |
private final ArtifactManager artifactManager; | |
private IModelUpdater modelUpdater; | |
// ======================================================================= | |
protected ArtifactManagerSessionImpl(ArtifactManager artifactManager) { | |
super(artifactManager); | |
this.artifactManager = artifactManager; | |
} | |
// ======================================================================= | |
// ======================================================================= | |
// ======================================================================= | |
/** | |
* Returns the Artifact Manager for this session | |
* | |
* @return ArtifactManager - The artifact manager for this session | |
*/ | |
public ArtifactManager getArtifactManager() { | |
return this.artifactManager; | |
} | |
public IAbstractArtifact makeArtifact(IAbstractArtifact artifact) { | |
if (artifact instanceof IManagedEntityArtifact) | |
return new ManagedEntityArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IDatatypeArtifact) | |
return new DatatypeArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IExceptionArtifact) | |
return new ExceptionArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IQueryArtifact) | |
return new QueryArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof ISessionArtifact) | |
return new SessionFacadeArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IEnumArtifact) | |
return new EnumArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IEventArtifact) | |
return new EventArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IUpdateProcedureArtifact) | |
return new UpdateProcedureArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IAssociationClassArtifact) | |
return new AssociationClassArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IAssociationArtifact) | |
return new AssociationArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IPrimitiveTypeArtifact) | |
return new PrimitiveTypeArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IDependencyArtifact) | |
return new DependencyArtifactInternal(getArtifactManager()); | |
else if (artifact instanceof IPackageArtifact) | |
return new PackageArtifactInternal(getArtifactManager()); | |
throw new IllegalArgumentException(); | |
} | |
public IAbstractArtifact makeArtifact(String type) throws IllegalArgumentException { | |
if (IManagedEntityArtifact.class.getName().equals(type)) | |
return new ManagedEntityArtifactInternal(getArtifactManager()); | |
else if (IDatatypeArtifact.class.getName().equals(type)) | |
return new DatatypeArtifactInternal(getArtifactManager()); | |
else if (IExceptionArtifact.class.getName().equals(type)) | |
return new ExceptionArtifactInternal(getArtifactManager()); | |
else if (IQueryArtifact.class.getName().equals(type)) | |
return new QueryArtifactInternal(getArtifactManager()); | |
else if (ISessionArtifact.class.getName().equals(type)) | |
return new SessionFacadeArtifactInternal(getArtifactManager()); | |
else if (IEnumArtifact.class.getName().equals(type)) | |
return new EnumArtifactInternal(getArtifactManager()); | |
else if (IEventArtifact.class.getName().equals(type)) | |
return new EventArtifactInternal(getArtifactManager()); | |
else if (IUpdateProcedureArtifact.class.getName().equals(type)) | |
return new UpdateProcedureArtifactInternal(getArtifactManager()); | |
else if (IAssociationClassArtifact.class.getName().equals(type)) | |
return new AssociationClassArtifactInternal(getArtifactManager()); | |
else if (IAssociationArtifact.class.getName().equals(type)) | |
return new AssociationArtifactInternal(getArtifactManager()); | |
else if (IPrimitiveTypeArtifact.class.getName().equals(type)) | |
return new PrimitiveTypeArtifactInternal(getArtifactManager()); | |
else if (IDependencyArtifact.class.getName().equals(type)) | |
return new DependencyArtifactInternal(getArtifactManager()); | |
else if (IPackageArtifact.class.getName().equals(type)) | |
return new PackageArtifactInternal(getArtifactManager()); | |
else | |
throw new IllegalArgumentException("Unknown artifact type: " + type); | |
} | |
public IAbstractArtifact getArtifactByFullyQualifiedName(String fqn) { | |
return getArtifactByFullyQualifiedName(fqn, true); | |
} | |
public IAbstractArtifact getArtifactByFullyQualifiedName(String fqn, boolean includeDependencies) { | |
return getArtifactManager().getArtifactByFullyQualifiedName(fqn, includeDependencies, | |
new NullProgressMonitor()); | |
} | |
@Override | |
public IAbstractArtifact getArtifactByFullyQualifiedName(String fqn, boolean includeDependencies, | |
boolean isOverridePredicate) { | |
return getArtifactManager().getArtifactByFullyQualifiedName(fqn, includeDependencies, isOverridePredicate, | |
new NullProgressMonitor()); | |
} | |
public IAbstractArtifact extractArtifact(Reader reader, IProgressMonitor monitor) throws TigerstripeException { | |
return artifactManager.extractArtifact(reader, monitor); | |
} | |
public void addArtifact(IAbstractArtifact artifact) throws TigerstripeException { | |
artifactManager.addArtifact(artifact, new NullProgressMonitor()); | |
} | |
public void removeArtifact(IAbstractArtifact artifact) throws TigerstripeException { | |
removeArtifact(artifact, true); | |
} | |
public void removeArtifact(IAbstractArtifact artifact, boolean dispose) throws TigerstripeException { | |
URI oldURI = ((IAbstractArtifactInternal) artifact).getAdapter(URI.class); | |
String simpleName = artifact.getClass().getSimpleName(); | |
((IArtifactManagerInternal) getArtifactManager()).removeArtifact(artifact, dispose); | |
// push a notif | |
ModelChangeDelta delta = new ModelChangeDelta(IModelChangeDelta.REMOVE); | |
delta.setFeature(simpleName); | |
delta.setOldValue(oldURI); | |
delta.setProject(artifact.getProject()); | |
delta.setSource(this); | |
TigerstripeWorkspaceNotifier.INSTANCE.signalModelChange(delta); | |
} | |
public void refresh(IProgressMonitor monitor) throws TigerstripeException { | |
refresh(false, monitor); | |
} | |
public void refresh(boolean forceReload, IProgressMonitor monitor) throws TigerstripeException { | |
// @since 2.1: when generating module no need to refresh manager | |
// since this is a module. | |
if (getArtifactManager() instanceof ModuleArtifactManager) | |
return; | |
getArtifactManager().refresh(forceReload, SubMonitor.convert(monitor)); | |
} | |
public void refreshReferences(IProgressMonitor monitor) throws TigerstripeException { | |
((IArtifactManagerInternal) getArtifactManager()).refreshReferences(monitor); | |
} | |
public void updateCaches(IProgressMonitor monitor) throws TigerstripeException { | |
((IArtifactManagerInternal) getArtifactManager()).updateCaches(monitor); | |
} | |
public void refreshAll(IProgressMonitor monitor) throws TigerstripeException { | |
refreshAll(false, monitor); | |
} | |
public void refreshAll(boolean forceReload, IProgressMonitor monitor) throws TigerstripeException { | |
refreshReferences(monitor); | |
refresh(forceReload, monitor); | |
} | |
public IAbstractArtifact extractArtifactModel(Reader reader) throws TigerstripeException { | |
return getArtifactManager().extractArtifactModel(reader); | |
} | |
public IAbstractArtifact makeArtifact(IAbstractArtifact model, IAbstractArtifact orig) throws TigerstripeException { | |
IAbstractArtifact result = makeArtifact(model); | |
result.setComment(orig.getComment()); | |
result.setFullyQualifiedName(orig.getFullyQualifiedName()); | |
result.setExtendedArtifact(orig.getExtendedArtifact()); | |
result.setVisibility(orig.getVisibility()); | |
if (orig.getIStandardSpecifics() instanceof IOssjArtifactSpecifics) { | |
IOssjArtifactSpecifics origISS = (IOssjArtifactSpecifics) orig.getIStandardSpecifics(); | |
IOssjArtifactSpecifics resultISS = (IOssjArtifactSpecifics) result.getIStandardSpecifics(); | |
resultISS.applyDefaults(); | |
resultISS.mergeInterfaceProperties(origISS.getInterfaceProperties()); | |
} | |
if (orig instanceof IAssociationArtifact && model instanceof IAssociationArtifact) { | |
IAssociationArtifact origAssoc = (IAssociationArtifact) orig; | |
IAssociationArtifact resultAssoc = (IAssociationArtifact) result; | |
IAssociationEnd resAEnd = resultAssoc.makeAssociationEnd(); | |
resAEnd.setAggregation(origAssoc.getAEnd().getAggregation()); | |
resAEnd.setChangeable(origAssoc.getAEnd().getChangeable()); | |
resAEnd.setComment(origAssoc.getAEnd().getComment()); | |
resAEnd.setMultiplicity(origAssoc.getAEnd().getMultiplicity()); | |
resAEnd.setName(origAssoc.getAEnd().getName()); | |
resAEnd.setNavigable(origAssoc.getAEnd().isNavigable()); | |
resAEnd.setOrdered(origAssoc.getAEnd().isOrdered()); | |
resAEnd.setVisibility(origAssoc.getAEnd().getVisibility()); | |
IType aType = resAEnd.makeType(); | |
aType.setFullyQualifiedName(origAssoc.getAEnd().getType().getFullyQualifiedName()); | |
resAEnd.setType(aType); | |
resultAssoc.setAEnd(resAEnd); | |
IAssociationEnd resZEnd = resultAssoc.makeAssociationEnd(); | |
resZEnd.setAggregation(origAssoc.getZEnd().getAggregation()); | |
resZEnd.setChangeable(origAssoc.getZEnd().getChangeable()); | |
resZEnd.setComment(origAssoc.getZEnd().getComment()); | |
resZEnd.setMultiplicity(origAssoc.getZEnd().getMultiplicity()); | |
resZEnd.setName(origAssoc.getZEnd().getName()); | |
resZEnd.setNavigable(origAssoc.getZEnd().isNavigable()); | |
resZEnd.setOrdered(origAssoc.getZEnd().isOrdered()); | |
resZEnd.setVisibility(origAssoc.getZEnd().getVisibility()); | |
IType zType = resZEnd.makeType(); | |
zType.setFullyQualifiedName(origAssoc.getZEnd().getType().getFullyQualifiedName()); | |
resZEnd.setType(zType); | |
resultAssoc.setZEnd(resZEnd); | |
} else if (orig instanceof IDependencyArtifact && model instanceof IDependencyArtifact) { | |
IDependencyArtifact origDep = (IDependencyArtifact) orig; | |
IDependencyArtifact resultDep = (IDependencyArtifact) result; | |
IType aType = resultDep.makeType(); | |
aType.setFullyQualifiedName(origDep.getAEndType().getFullyQualifiedName()); | |
resultDep.setAEndType(aType); | |
IType zType = resultDep.makeType(); | |
zType.setFullyQualifiedName(origDep.getZEndType().getFullyQualifiedName()); | |
resultDep.setZEndType(zType); | |
} | |
result.setFields(orig.getFields()); | |
result.setLiterals(orig.getLiterals()); | |
result.setMethods(orig.getMethods()); | |
return result; | |
} | |
public Collection<IAbstractArtifact> getAllKnownArtifactsByFullyQualifiedName(String fqn) { | |
return getArtifactManager().getAllKnownArtifactsByFullyQualifiedName(fqn, new NullProgressMonitor()); | |
} | |
public void addArtifactChangeListener(IArtifactChangeListener listener) { | |
((IArtifactManagerInternal) getArtifactManager()).addArtifactManagerListener(listener); | |
} | |
public void removeArtifactChangeListener(IArtifactChangeListener listener) { | |
((IArtifactManagerInternal) getArtifactManager()).removeArtifactManagerListener(listener); | |
} | |
public IModelUpdater getIModelUpdater() { | |
if (modelUpdater == null) { | |
modelUpdater = new ModelUpdaterImpl(this); | |
} | |
return modelUpdater; | |
} | |
public void setLockForGeneration(boolean isLocked) { | |
getArtifactManager().lock(isLocked); | |
} | |
public Set<IRelationship> removePackageContent(String packageName) { | |
// As we delete the content of the package, we assemble a list of all | |
// the relationship that now have a dangling end. This will be returned | |
// so that the caller may decide to cascade delete them or not. | |
Set<IRelationship> relToCascadeDelete = new HashSet<>(); | |
if (packageName == null || packageName.length() == 0) { | |
return Collections.emptySet(); | |
} | |
List<IAbstractArtifact> forRemovalArtifacts = new ArrayList<>(); | |
Collection<IAbstractArtifact> artifacts = getArtifactManager().getAllArtifacts(false, | |
new NullProgressMonitor()); | |
for (IAbstractArtifact artifact : artifacts) { | |
if (packageName.equals(artifact.getPackage())) { | |
forRemovalArtifacts.add(artifact); | |
try { | |
relToCascadeDelete | |
.addAll(getOriginatingRelationshipForFQN(artifact.getFullyQualifiedName(), false)); | |
relToCascadeDelete | |
.addAll(getTerminatingRelationshipForFQN(artifact.getFullyQualifiedName(), false)); | |
} catch (TigerstripeException e) { | |
TigerstripeRuntime.getDefaultInstance() | |
.logErrorMessage("While trying to assess cascade delete list:" + e.getMessage(), e); | |
} | |
} | |
} | |
for (IAbstractArtifact artifact : forRemovalArtifacts) { | |
try { | |
removeArtifact(artifact); | |
} catch (TigerstripeException e) { | |
TigerstripeRuntime.getDefaultInstance().logErrorMessage("TigerstripeException detected", e); | |
} | |
} | |
return relToCascadeDelete; | |
} | |
public void renamePackageContent(String fromPackageName, String toPackageName) { | |
if (fromPackageName == null || fromPackageName.length() == 0) | |
return; | |
if (toPackageName == null || toPackageName.length() == 0) { | |
removePackageContent(fromPackageName); | |
} | |
List<IAbstractArtifact> forRenamingArtifacts = new ArrayList<>(); | |
Collection<IAbstractArtifact> artifacts = getArtifactManager().getAllArtifacts(false, | |
new NullProgressMonitor()); | |
for (IAbstractArtifact artifact : artifacts) { | |
if (fromPackageName.equals(artifact.getPackage())) { | |
forRenamingArtifacts.add(artifact); | |
} | |
} | |
for (IAbstractArtifact artifact : forRenamingArtifacts) { | |
try { | |
String toFQN = artifact.getName(); | |
if (toPackageName != null && toPackageName.length() != 0) { | |
toFQN = toPackageName + "." + toFQN; | |
} | |
renameArtifact(artifact, toFQN); | |
} catch (TigerstripeException e) { | |
TigerstripeRuntime.getDefaultInstance().logErrorMessage("TigerstripeException detected", e); | |
} | |
} | |
} | |
public void renameArtifact(IAbstractArtifact artifact, String toFQN) throws TigerstripeException { | |
URI oldURI = ((IAbstractArtifactInternal) artifact).getAdapter(URI.class); | |
((IArtifactManagerInternal) getArtifactManager()).renameArtifact(artifact, toFQN, new NullProgressMonitor()); | |
URI newURI = ((IAbstractArtifactInternal) artifact).getAdapter(URI.class); | |
// push a notif | |
ModelChangeDelta delta = new ModelChangeDelta(IModelChangeDelta.SET); | |
delta.setFeature("name"); | |
delta.setAffectedModelComponentURI(oldURI); | |
delta.setNewValue(newURI); | |
delta.setOldValue(oldURI); | |
delta.setProject(artifact.getProject()); | |
delta.setSource(this); | |
TigerstripeWorkspaceNotifier.INSTANCE.signalModelChange(delta); | |
} | |
// ==================================================== | |
// Facet Management | |
public IFacetReference getActiveFacet() throws TigerstripeException { | |
return getArtifactManager().getActiveFacet(); | |
} | |
public void resetActiveFacet() throws TigerstripeException { | |
getArtifactManager().resetActiveFacet(); | |
} | |
public void resetActiveFacet(ExecutionContext context) throws TigerstripeException { | |
getArtifactManager().resetActiveFacet(context); | |
} | |
public void setActiveFacet(IFacetReference facet, IProgressMonitor monitor) throws TigerstripeException { | |
getArtifactManager().setActiveFacet(facet, monitor); | |
} | |
public void setActiveFacet(IFacetReference facet, ExecutionContext context) throws TigerstripeException { | |
getArtifactManager().setActiveFacet(facet, context); | |
} | |
public void addActiveFacetListener(IActiveFacetChangeListener listener) { | |
((IArtifactManagerInternal) getArtifactManager()).addActiveFacetListener(listener); | |
} | |
public void removeActiveFacetListener(IActiveFacetChangeListener listener) { | |
((IArtifactManagerInternal) getArtifactManager()).removeActiveFacetListener(listener); | |
} | |
public void resetBroadcastMask() throws TigerstripeException { | |
((IArtifactManagerInternal) getArtifactManager()).resetBroadcastMask(); | |
} | |
public void setBroadcastMask(int broadcastMask) throws TigerstripeException { | |
((IArtifactManagerInternal) getArtifactManager()).setBroadcastMask(broadcastMask); | |
} | |
public long getLocalTimeStamp() throws TigerstripeException { | |
return ((IArtifactManagerInternal) getArtifactManager()).getLocalTimeStamp(); | |
} | |
public IAbstractArtifact getArtifactByFullyQualifiedName(String fqn, ExecutionContext context) | |
throws TigerstripeException { | |
return getArtifactManager().getArtifactByFullyQualifiedName(fqn, false, // NM: | |
// Exclude | |
// dependencies | |
context); | |
} | |
} |