| /** |
| * |
| * 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; |
| |
| import org.apache.log4j.Logger; |
| import org.eclipse.viatra.dse.examples.bpmn.patterns.EnoughResourceInstancesMatch; |
| import org.eclipse.viatra.dse.examples.bpmn.patterns.util.EnoughResourceInstancesQuerySpecification; |
| import org.eclipse.viatra.query.runtime.api.IQuerySpecification; |
| import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; |
| import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; |
| import org.eclipse.viatra.query.runtime.exception.ViatraQueryException; |
| import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; |
| import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; |
| |
| /** |
| * Generated pattern matcher API of the org.eclipse.viatra.dse.examples.bpmn.patterns.enoughResourceInstances pattern, |
| * providing pattern-specific query methods. |
| * |
| * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, |
| * e.g. in conjunction with {@link ViatraQueryEngine#on(Notifier)}. |
| * |
| * <p>Matches of the pattern will be represented as {@link EnoughResourceInstancesMatch}. |
| * |
| * <p>Original source: |
| * <code><pre> |
| * pattern enoughResourceInstances() { |
| * neg find absenceOfResourceInstances(_); |
| * } |
| * </pre></code> |
| * |
| * @see EnoughResourceInstancesMatch |
| * @see EnoughResourceInstancesProcessor |
| * @see EnoughResourceInstancesQuerySpecification |
| * |
| */ |
| @SuppressWarnings("all") |
| public class EnoughResourceInstancesMatcher extends BaseMatcher<EnoughResourceInstancesMatch> { |
| /** |
| * Initializes the pattern matcher within an existing VIATRA Query engine. |
| * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. |
| * The match set will be incrementally refreshed upon updates. |
| * @param engine the existing VIATRA Query engine in which this matcher will be created. |
| * @throws ViatraQueryException if an error occurs during pattern matcher creation |
| * |
| */ |
| public static EnoughResourceInstancesMatcher on(final ViatraQueryEngine engine) throws ViatraQueryException { |
| // check if matcher already exists |
| EnoughResourceInstancesMatcher matcher = engine.getExistingMatcher(querySpecification()); |
| if (matcher == null) { |
| matcher = (EnoughResourceInstancesMatcher)engine.getMatcher(querySpecification()); |
| } |
| return matcher; |
| } |
| |
| /** |
| * Initializes the pattern matcher within an existing VIATRA Query engine. |
| * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. |
| * The match set will be incrementally refreshed upon updates. |
| * @param engine the existing VIATRA Query engine in which this matcher will be created. |
| * @throws ViatraQueryException if an error occurs during pattern matcher creation |
| * |
| */ |
| public static EnoughResourceInstancesMatcher create() throws ViatraQueryException { |
| return new EnoughResourceInstancesMatcher(); |
| } |
| |
| private final static Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EnoughResourceInstancesMatcher.class); |
| |
| /** |
| * Initializes the pattern matcher within an existing VIATRA Query engine. |
| * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. |
| * The match set will be incrementally refreshed upon updates. |
| * @param engine the existing VIATRA Query engine in which this matcher will be created. |
| * @throws ViatraQueryException if an error occurs during pattern matcher creation |
| * |
| */ |
| private EnoughResourceInstancesMatcher() throws ViatraQueryException { |
| super(querySpecification()); |
| } |
| |
| /** |
| * Indicates whether the (parameterless) pattern matches or not. |
| * @return true if the pattern has a valid match. |
| * |
| */ |
| public boolean hasMatch() { |
| return rawHasMatch(new Object[]{}); |
| } |
| |
| @Override |
| protected EnoughResourceInstancesMatch tupleToMatch(final Tuple t) { |
| try { |
| return EnoughResourceInstancesMatch.newMatch(); |
| } catch(ClassCastException e) { |
| LOGGER.error("Element(s) in tuple not properly typed!",e); |
| return null; |
| } |
| } |
| |
| @Override |
| protected EnoughResourceInstancesMatch arrayToMatch(final Object[] match) { |
| try { |
| return EnoughResourceInstancesMatch.newMatch(); |
| } catch(ClassCastException e) { |
| LOGGER.error("Element(s) in array not properly typed!",e); |
| return null; |
| } |
| } |
| |
| @Override |
| protected EnoughResourceInstancesMatch arrayToMatchMutable(final Object[] match) { |
| try { |
| return EnoughResourceInstancesMatch.newMutableMatch(); |
| } catch(ClassCastException e) { |
| LOGGER.error("Element(s) in array not properly typed!",e); |
| return null; |
| } |
| } |
| |
| /** |
| * @return the singleton instance of the query specification of this pattern |
| * @throws ViatraQueryException if the pattern definition could not be loaded |
| * |
| */ |
| public static IQuerySpecification<EnoughResourceInstancesMatcher> querySpecification() throws ViatraQueryException { |
| return EnoughResourceInstancesQuerySpecification.instance(); |
| } |
| } |