blob: f0133555953c02d14ebf74fa9aa75ea5dffeca99 [file] [log] [blame]
/**
*
* Copyright (c) 2010-2015, Andras Szabolcs Nagy, Abel Hegedus, Akos Horvath, Zoltan Ujhelyi and Daniel Varro
* 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:
* Andras Szabolcs Nagy - initial API and implementation
*
*/
package org.eclipse.viatra.dse.examples.bpmn.patterns.util;
import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.eclipse.viatra.dse.examples.bpmn.patterns.EnoughResourceInstancesMatch;
import org.eclipse.viatra.dse.examples.bpmn.patterns.EnoughResourceInstancesMatcher;
import org.eclipse.viatra.dse.examples.bpmn.patterns.util.AbsenceOfResourceInstancesQuerySpecification;
import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
import org.eclipse.viatra.query.runtime.exception.ViatraQueryException;
import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.QueryInitializationException;
import org.eclipse.viatra.query.runtime.matchers.tuple.FlatTuple;
/**
* A pattern-specific query specification that can instantiate EnoughResourceInstancesMatcher in a type-safe way.
*
* @see EnoughResourceInstancesMatcher
* @see EnoughResourceInstancesMatch
*
*/
@SuppressWarnings("all")
public final class EnoughResourceInstancesQuerySpecification extends BaseGeneratedEMFQuerySpecification<EnoughResourceInstancesMatcher> {
private EnoughResourceInstancesQuerySpecification() {
super(GeneratedPQuery.INSTANCE);
}
/**
* @return the singleton instance of the query specification
* @throws ViatraQueryException if the pattern definition could not be loaded
*
*/
public static EnoughResourceInstancesQuerySpecification instance() throws ViatraQueryException {
try{
return LazyHolder.INSTANCE;
} catch (ExceptionInInitializerError err) {
throw processInitializerError(err);
}
}
@Override
protected EnoughResourceInstancesMatcher instantiate(final ViatraQueryEngine engine) throws ViatraQueryException {
return EnoughResourceInstancesMatcher.on(engine);
}
@Override
public EnoughResourceInstancesMatcher instantiate() throws ViatraQueryException {
return EnoughResourceInstancesMatcher.create();
}
@Override
public EnoughResourceInstancesMatch newEmptyMatch() {
return EnoughResourceInstancesMatch.newEmptyMatch();
}
@Override
public EnoughResourceInstancesMatch newMatch(final Object... parameters) {
return EnoughResourceInstancesMatch.newMatch();
}
/**
* Inner class allowing the singleton instance of {@link EnoughResourceInstancesQuerySpecification} to be created
* <b>not</b> at the class load time of the outer class,
* but rather at the first call to {@link EnoughResourceInstancesQuerySpecification#instance()}.
*
* <p> This workaround is required e.g. to support recursion.
*
*/
private static class LazyHolder {
private final static EnoughResourceInstancesQuerySpecification INSTANCE = new EnoughResourceInstancesQuerySpecification();
/**
* Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
* This initialization order is required to support indirect recursion.
*
* <p> The static initializer is defined using a helper field to work around limitations of the code generator.
*
*/
private final static Object STATIC_INITIALIZER = ensureInitialized();
public static Object ensureInitialized() {
INSTANCE.ensureInitializedInternalSneaky();
return null;
}
}
private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
private final static EnoughResourceInstancesQuerySpecification.GeneratedPQuery INSTANCE = new GeneratedPQuery();
private final List<PParameter> parameters = Arrays.asList();
@Override
public String getFullyQualifiedName() {
return "org.eclipse.viatra.dse.examples.bpmn.patterns.enoughResourceInstances";
}
@Override
public List<String> getParameterNames() {
return Arrays.asList();
}
@Override
public List<PParameter> getParameters() {
return parameters;
}
@Override
public Set<PBody> doGetContainedBodies() throws QueryInitializationException {
setEvaluationHints(new QueryEvaluationHint(null, Collections.<String,Object>emptyMap()));
Set<PBody> bodies = Sets.newLinkedHashSet();
try {
{
PBody body = new PBody(this);
PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
));
// neg find absenceOfResourceInstances(_)
new NegativePatternCall(body, new FlatTuple(var___0_), AbsenceOfResourceInstancesQuerySpecification.instance().getInternalQueryRepresentation());
bodies.add(body);
}
// to silence compiler error
if (false) throw new ViatraQueryException("Never", "happens");
} catch (ViatraQueryException ex) {
throw processDependencyException(ex);
}
return bodies;
}
}
}