Skip to content
Snippets Groups Projects
Commit 226dbee3 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Forgot some changes

parent a81855d6
No related branches found
No related tags found
No related merge requests found
package tdt4250.servletsupport.impl;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.osgi.service.component.annotations.Component;
import tdt4250.servletsupport.IReferenceResolver;
@Component
public class NameReferenceResolver implements IReferenceResolver {
public class NameReferenceResolver extends AbstractReferenceResolver implements IReferenceResolver {
@Override
public EObject resolveReference(String reference, EObject context) {
for (EObject contained : context.eContents()) {
EStructuralFeature nameFeature = contained.eClass().getEStructuralFeature("name");
if (nameFeature != null) {
Object name = contained.eGet(nameFeature);
if (reference.equals(String.valueOf(name))) {
return contained;
protected boolean isReferenced(String reference, EObject eObject) {
EStructuralFeature nameFeature = eObject.eClass().getEStructuralFeature("name");
if (nameFeature instanceof EAttribute) {
Object name = eObject.eGet(nameFeature);
if (reference.equals(EcoreUtil.convertToString(((EAttribute) nameFeature).getEAttributeType(), name))) {
return true;
}
}
}
return null;
return false;
}
}
......@@ -119,15 +119,14 @@ public class RequestSupport {
}
}
if (count == 0) {
EList<EObject> selected = null;
if (Character.isUpperCase(step.charAt(0))) {
objects = selectEClass(objects, step);
if (objects.isEmpty()) {
objects = selectKey(objects, step.split(","));
selected = selectEClass(objects, step);
}
} else {
objects = selectKey(objects, step.split(","));
if (selected == null || selected.isEmpty()) {
selected = selectKey(objects, step.split(","));
}
return objects;
return objects = selected;
}
if (values != null) {
return objects = values;
......@@ -235,9 +234,7 @@ public class RequestSupport {
}
protected EList<EObject> selectRelation(Collection<?> objects, final String featureName, final String featureValueString, final String rel) {
return selectEObjects(objects, new EObjectFilter() {
@Override
public boolean accept(EObject eObject) {
return selectEObjects(objects, eObject -> {
EAttribute attr = findEStructuralFeature(featureName, eObject.eClass().getEAllAttributes());
if (attr != null) {
Object featureValue1 = eObject.eGet(attr);
......@@ -260,14 +257,11 @@ public class RequestSupport {
}
}
return false;
}
});
}
protected EList<EObject> selectKey(Collection<?> objects, final String[] keyValueStrings) {
return selectEObjects(objects, new EObjectFilter() {
@Override
public boolean accept(EObject eObject) {
return selectEObjects(objects, eObject -> {
EStructuralFeature containingFeature = eObject.eContainingFeature();
if (containingFeature instanceof EReference) {
EList<EAttribute> keyAttributes = ((EReference) containingFeature).getEKeys();
......@@ -283,7 +277,6 @@ public class RequestSupport {
}
}
return false;
}
});
}
......
......@@ -10,11 +10,25 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Modified;
import tdt4250.servletsupport.IResourceProvider;
@Component(
configurationPid = ResourceProvider.FACTORY_PID,
configurationPolicy = ConfigurationPolicy.REQUIRE
)
public class ResourceProvider implements IResourceProvider {
public static final String FACTORY_PID = "tdt4250.servletsupport.impl.ResourceProvider";
public static final String RESOURCE_NAME_PROP = "resourceName";
public static final String RESOURCE_URI_PROP = "resourceUri";
private URI uri;
private Resource resource;
......@@ -28,6 +42,26 @@ public class ResourceProvider implements IResourceProvider {
this.uri = uri;
}
public @interface ResourceProviderConfig {
String name();
String resourceUri();
}
@Activate
public void activate(BundleContext bc, ResourceProviderConfig config) {
update(bc, config);
}
@Modified
public void modify(BundleContext bc, ResourceProviderConfig config) {
update(bc, config);
}
protected void update(BundleContext bc, ResourceProviderConfig config) {
this.resource = null;
this.uri = URI.createURI(config.resourceUri());
}
public ResourceProvider(Resource resource) {
this.resource = resource;
}
......
Bundle-Version: 1.0.0.${tstamp}
-baseline: *
-buildpath: \
osgi.core;version=7.0.0,\
osgi.annotation;version=7.0.0,\
osgi.cmpn;version=7.0.0,\
com.fasterxml.jackson.core.jackson-annotations,\
com.fasterxml.jackson.core.jackson-core,\
com.fasterxml.jackson.core.jackson-databind,\
......@@ -11,4 +10,5 @@ Bundle-Version: 1.0.0.${tstamp}
javac.source: 1.8
javac.target: 1.8
-runrequires: bnd.identity;id='tdt4250.emf.servletsupport'
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment