1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
package org.eclipse.wst.common.componentcore.resolvers;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.common.util.URI;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.UnresolveableURIException;
import org.eclipse.wst.common.componentcore.ComponentcorePackage;
import org.eclipse.wst.common.componentcore.internal.DependencyType;
import org.eclipse.wst.common.componentcore.internal.ReferencedComponent;
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualReference;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
public class DefaultReferenceResolver implements IReferenceResolver {
// Does not need to implement,
// default is always called as last resort
public boolean canResolve(IVirtualComponent context,
ReferencedComponent referencedComponent) {
return false;
}
// Does not need to implement,
// default is always called as last resort
public boolean canResolve(IVirtualReference reference) {
return false;
}
public IVirtualReference resolve(IVirtualComponent context,
ReferencedComponent referencedComponent) {
IVirtualComponent targetComponent = null;
IProject targetProject = null;
URI uri = referencedComponent.getHandle();
if (uri == null)
return null;
boolean isClassPathURI = ModuleURIUtil.isClassPathURI(uri);
if( !isClassPathURI ){
try {
targetProject = StructureEdit.getContainingProject(uri);
} catch(UnresolveableURIException uurie) {
//Ignore
}
// if the project cannot be resolved, assume it's local - really it probably deleted
targetComponent = ComponentCore.createComponent(targetProject);
}else{
String archiveType = ""; //$NON-NLS-1$
String archiveName = ""; //$NON-NLS-1$
try {
archiveType = ModuleURIUtil.getArchiveType(uri);
archiveName = ModuleURIUtil.getArchiveName(uri);
} catch (UnresolveableURIException e) {
//Ignore
}
targetComponent = ComponentCore.createArchiveComponent(context.getProject(), archiveType + IPath.SEPARATOR + archiveName );
}
VirtualReference vRef = new VirtualReference(context, targetComponent, referencedComponent.getRuntimePath(), referencedComponent.getDependencyType().getValue());
vRef.setArchiveName(referencedComponent.getArchiveName());
return vRef;
}
public ReferencedComponent resolve(IVirtualReference reference) {
IVirtualComponent referencedComponent = reference.getReferencedComponent();
ReferencedComponent refComp = ComponentcorePackage.eINSTANCE.getComponentcoreFactory().createReferencedComponent();
refComp.setRuntimePath(reference.getRuntimePath());
refComp.setDependencyType(DependencyType.get(reference.getDependencyType()));
refComp.setArchiveName(reference.getArchiveName());
if( referencedComponent != null ) {
if( !referencedComponent.isBinary())
refComp.setHandle(ModuleURIUtil.fullyQualifyURI(referencedComponent.getProject()));
else
refComp.setHandle(ModuleURIUtil.archiveComponentfullyQualifyURI(referencedComponent.getName()));
}
return refComp;
}
}
|