/*
* generated by Xtext
*/
package org.panlab.software.fsdl.scoping;
import static org.eclipse.xtext.scoping.Scopes.scopeFor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
import FederationOffice.federationscenarios.ResourceRequest;
import FederationOffice.federationscenarios.ResourceSettingInstance;
import FederationOffice.federationscenarios.ServiceRequest;
import FederationOffice.federationscenarios.ServiceSettingInstance;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* This class contains custom scoping description.
*
* see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping on
* how and when to use it
*
*/
public class FSDLScopeProvider extends AbstractDeclarativeScopeProvider {
// The following is useful to discover Scope signatures. uncomment to see it in action
// @Override
// public IScope getScope(EObject context, EReference ref) {
// System.out.println("scope_" + ref.getEContainingClass().getName() + "_"
// + ref.getName() + "(" + context.eClass().getName() + " ["+context.toString()+"], ..)");
// return super.getScope(context, ref);
// }
IScope scope_ResourceSettingInstance_refResourceSetting(
ResourceSettingInstance ctx,
EReference ref) {
// System.out.println("scope_ResourceSettingInstance_refResourceSetting ctx.eContainer()="+ ctx.eContainer().toString());
ResourceRequest offeredResourceInstance = (ResourceRequest) ctx
.eContainer();
FederationOffice.resources.OfferedResource offeredResource = offeredResourceInstance
.getRefOfferedResource();
// return new SimpleScope(IScope.NULLSCOPE, getOfServs(rv) );
EList<FederationOffice.resources.ResourceSetting> features = offeredResource
.getResourceSettings();
return scopeFor(Iterables.filter(features, rResSets));
// return IScope.NULLSCOPE;
}
protected Predicate<FederationOffice.resources.ResourceSetting> rResSets = new Predicate<FederationOffice.resources.ResourceSetting>() {
public boolean apply(FederationOffice.resources.ResourceSetting input) {
return true;
// return input.getName().length()==6;
}
};
IScope scope_ServiceSettingInstance_refServiceSetting(
ServiceSettingInstance ctx,
EReference ref) {
// System.out.println("scope_ServiceSettingInstance_refServiceSetting ctx.eContainer()="+ ctx.eContainer().toString());
// ctx.getRefServiceSetting()
FederationOffice.services.Service offeredService = null;
if ( ctx.eContainer() instanceof ServiceRequest){
offeredService = ((ServiceRequest)ctx.eContainer()).getRefService();
}
if (offeredService == null)
return IScope.NULLSCOPE;
EList<FederationOffice.services.ServiceSetting> features = offeredService.getServiceSettings() ;
return scopeFor(Iterables.filter(features, rServiceSettings));
}
protected Predicate<FederationOffice.services.ServiceSetting> rServiceSettings = new Predicate<FederationOffice.services.ServiceSetting>() {
public boolean apply(FederationOffice.services.ServiceSetting input) {
return true;
// return input.getName().length()==6;
}
};
////OLD Code
//here we can get the scope by ObjectsProvider
// IScope scope_ZZOfferedService(EObject ctx, EReference ref) {
// System.out
// .println(">>>>>>>>> scoping scope_OfferedService >>>>>>>>>>>>>>>>>>");
// TreeIterator<Object> iterator = EcoreUtil.getAllProperContents(ctx.eResource().getResourceSet(), true);
// ObjectsProvider op = null;
//
// while (iterator.hasNext()) {
// Object object = (Object) iterator.next();
//// System.out.println(">>>>>>>>> scoping scope_OfferedService object=" +
//// object.toString());
// if (object instanceof ObjectsProvider ){
// op = (ObjectsProvider)object;
// break;
// }
// }
//
// if (op !=null){
// System.out.println(">>>>>>>>> scoping scope_OfferedService op="
// + op.toString());
// EList<OfferedService> list = op.getOfferedServices();
// for (int i = 0; i < list.size(); i++) {
// System.out.println(">>>>>>>>> scoping scope_OfferedService op.getOfferedServices=" + list.get(i).toString());
// }
// }
// return scopeFor(Iterables.filter( op.getOfferedServices(), rOfferedServicesSets));
//return IScope.NULLSCOPE;
// System.out.println(">>>>>>>>> scope_OfferedService ctx="+ ctx.
// toString());
// System.out.println(">>>>>>>>> scope_OfferedService ctx.eContainer.eContainer()()="+
// ctx.eContainer().eContainer().toString());
// EList<EObject> list = ctx.eContainer().eContainer().eContents();
// for (int i = 0; i < list.size(); i++) {
// System.out.println(">>>>>>>>> scope_OfferedService ctxlist.get(i)="+
// list.get(i).toString());
// EList<EObject> list2 = list.get(i).eCrossReferences();
// for (int j = 0; j < list2.size(); j++) {
// System.out.println(" >>>>>>>>> scope_OfferedService ctxlist2.get(i)="+
// list2.get(i).toString());
// }
// }
// System.out.println(">>>>>>>>> scope_OfferedService ref="+
// ref.toString() );
// System.out.println("<<<<<<<<< scoping scope_OfferedService <<<<<<<<<<<<<<<<<<<<<<<<<<<");
// try{
// FederationOfficeRule f =
// (FederationOfficeRule)ctx.eContainer().eContainer();
// IScope iscope = Scopes. scopeFor( f.getImports() );
// System.out.println("Got iscope: " + iscope.toString());
// return iscope;
// }catch (Exception e) {
// // TODO: handle exception
// }
// return scopeFor(Iterables.filter(features, rOfferedServicesSets));
// }
// protected Predicate<FederationOffice.services.OfferedService> rOfferedServicesSets = new Predicate<FederationOffice.services.OfferedService>() {
// public boolean apply(FederationOffice.services.OfferedService input) {
// return true;
// // return input.getName().length()==6;
// }
// };
}
//The Following is really time consuming..we'll try with the IQualifiedName
// IScope scope_ResourceRequest_refOfferedResource(
// ResourceRequest ctx, EReference ref) {
//
// TreeIterator<Object> iterator = EcoreUtil.getAllProperContents(ctx.eResource().getResourceSet(), true);
// EList< EObject > features = new BasicEList<EObject>();
// while (iterator.hasNext()) {
// Object object = (Object) iterator.next();
//// System.out.println(">>>>>>>>>scoping ResourceRequest = " + object.toString());
// if (object instanceof FederationOffice.resources.OfferedResource )
// features.add((EObject) object);
// }
//
//// System.out.println("scope_ServiceSettingInstance_refServiceSetting ctx.eContainer()="+ ctx.eContainer().toString());
//
// return scopeFor(Iterables.filter( features, rOfferedResourcesSets));
//
// }
//
//
// protected Predicate<EObject> rOfferedResourcesSets = new Predicate<EObject>() {
// public boolean apply( EObject input) {
// return (input instanceof FederationOffice.resources.OfferedResource);
// // return input.getName().length()==6;
// }
// };
//CHRIS: The following code displays index of model
// @Inject
// IContainer.Manager manager;
// @Inject
// IResourceDescriptions index;
//
// @Inject
// IGlobalScopeProvider gsp;
//
// @Inject
// IResourceServiceProvider.Registry regman;
//
// public void listVisibleResources(Resource myResource,
// IResourceDescriptions index) {
// IResourceDescription descr = index.getResourceDescription(myResource
// .getURI());
// for (IContainer visibleContainer : manager.getVisibleContainers(descr,
// index)) {
// for (IResourceDescription visibleResourceDesc : visibleContainer
// .getResourceDescriptions()) {
// System.out.println(visibleResourceDesc.getURI());
// }
// }
// }
//
// IScope scope_OfferedService(EObject ctx, EReference ref) {
// FederationOfficeRule f = (FederationOfficeRule) ctx.eContainer()
// .eContainer();
//
// System.out.println("Got f uri : " + f.eResource().getURI());
// System.out.println("Got ctx uri : " + ctx.eResource().getURI());
// System.out.println("Got manager. : " + manager.toString());
// System.out.println("Got regman. : " + regman.toString());
// IResourceServiceProvider resourceServiceProvider = regman
// .getResourceServiceProvider(f.eResource().getURI());
// Manager coman = resourceServiceProvider.getContainerManager();
// System.out.println("Got coman. : " + coman.toString());
//
// listVisibleResources(f.eResource(), index);
// return IScope.NULLSCOPE;
// }
// CHRIS: The following code displays index of model ---END