Skip to main content
summaryrefslogtreecommitdiffstats
blob: c942e136ad0121bdbb98377d6db46156a421313e (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2009 Red Hat and others.
 * 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:
 *     Red Hat - Initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.common.internal.modulecore;

import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.common.util.URI;
import org.eclipse.wst.common.componentcore.internal.ComponentcorePackage;
import org.eclipse.wst.common.componentcore.internal.DependencyType;
import org.eclipse.wst.common.componentcore.internal.ReferencedComponent;
import org.eclipse.wst.common.componentcore.internal.impl.PlatformURLModuleConnection;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualReference;
import org.eclipse.wst.common.componentcore.resolvers.IReferenceResolver;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualReference;

public class ClasspathContainerReferenceResolver implements IReferenceResolver {
	public static final String PROTOCOL = PlatformURLModuleConnection.MODULE_PROTOCOL
		+IPath.SEPARATOR + ClasspathContainerVirtualComponent.CLASSPATH_CON + IPath.SEPARATOR;
	public boolean canResolve(IVirtualComponent context,
			ReferencedComponent referencedComponent) {
		URI uri = referencedComponent.getHandle();
		if( uri.segmentCount() > 2 && uri.segment(0).equals(ClasspathContainerVirtualComponent.CLASSPATH)
				&& uri.segment(1).equals(ClasspathContainerVirtualComponent.CON))
			return true;
		return false;
	}

	public IVirtualReference resolve(IVirtualComponent context,
			ReferencedComponent referencedComponent) {
		URI uri = referencedComponent.getHandle();
		if( uri.segmentCount() > 2 && uri.segment(0).equals(ClasspathContainerVirtualComponent.CLASSPATH)
				&& uri.segment(1).equals(ClasspathContainerVirtualComponent.CON)) {
			String path = uri.toString().substring(PROTOCOL.length());
            IVirtualReference ref = new VirtualReference(context, 
            		new ClasspathContainerVirtualComponent(context.getProject(), context, path));
            ref.setArchiveName(referencedComponent.getArchiveName());
            ref.setRuntimePath(referencedComponent.getRuntimePath());
            ref.setDependencyType(referencedComponent.getDependencyType().getValue());
            return ref;
		}
		return null;
	}

	public boolean canResolve(IVirtualReference reference) {
		if( reference.getReferencedComponent() instanceof ClasspathContainerVirtualComponent )
			return true;
		return false;
	}

	public ReferencedComponent resolve(IVirtualReference reference) {
		ClasspathContainerVirtualComponent vc = (ClasspathContainerVirtualComponent)reference.getReferencedComponent();
        ReferencedComponent rc = ComponentcorePackage.eINSTANCE.getComponentcoreFactory().createReferencedComponent();
        rc.setArchiveName(reference.getArchiveName());
        rc.setRuntimePath(reference.getRuntimePath());
        rc.setHandle(URI.createURI(PROTOCOL + vc.getClasspathContainerPath()));
        rc.setDependencyType(DependencyType.CONSUMES_LITERAL);
        return rc;
	}

}

Back to the top