org.eclipse.epsilon.eol.models.CachedModel Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2010-2019 The University of York.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Louis Rose - initial API and implementation
* Sina Madani - concurrency support
******************************************************************************/
package org.eclipse.epsilon.eol.models;
import java.util.*;
import org.eclipse.epsilon.common.concurrent.ConcurrencyUtils;
import org.eclipse.epsilon.common.util.Multimap;
import org.eclipse.epsilon.common.util.StringProperties;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
import org.eclipse.epsilon.eol.exceptions.models.*;
/**
* A model that performs memoization of allContents, getAllOfType
* and getAllOfKind. Subclasses should implement the template
* methods, which compute real values from the model
* or provide keys that can be used with a {@link Map}.
*
* Although the collections used here are optionally thread-safe,
* subclasses should manage their own data structures according to the
* isConcurrent flag. In particular, {@link #allContentsFromModel()} should
* be managed appropriately by subclasses.
*/
public abstract class CachedModel extends Model {
/**
* Whether to cache allOf* calls by default. False for compatibility.
*/
public static final String PROPERTY_CACHED = "cached";
/**
* Whether to use thread-safe collections by default. False for compatibility.
* @since 1.6
*/
public static final String PROPERTY_CONCURRENT = "concurrent";
protected abstract Collection allContentsFromModel();
protected abstract Collection getAllOfTypeFromModel(String type) throws EolModelElementTypeNotFoundException;
protected abstract Collection getAllOfKindFromModel(String kind) throws EolModelElementTypeNotFoundException;
protected abstract ModelElementType createInstanceInModel(String type) throws EolModelElementTypeNotFoundException, EolNotInstantiableModelElementTypeException;
protected abstract void loadModel() throws EolModelLoadingException;
protected abstract void disposeModel();
/**
* Returns true iff the given instance was deleted from the model.
*/
protected abstract boolean deleteElementInModel(Object instance) throws EolRuntimeException;
/**
* Returns an identity for the given type,
* which will be used by {@link CachedModel}
* as a key for the memoization of model elements
* by type.
*
* @throws EolModelElementTypeNotFoundException
*/
protected abstract Object getCacheKeyForType(String type) throws EolModelElementTypeNotFoundException;
/**
* Returns the fully qualified names of every type to which the
* given object conforms. The values are used by
* by {@link CachedModel} for the memoization of
* model elements by their kind ({@link #getAllOfKind(String)}).
*/
protected abstract Collection getAllTypeNamesOf(Object instance);
protected Collection allContentsCache;
protected Multimap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy