001/* 002 * Copyright c 2018 Rusi Popov, MDA Tools.net All rights reserved. 003 * 004 * This program and the accompanying materials are made available under the terms of the 005 * Eclipse Public License v2.0 which accompanies this distribution, and is available at 006 * http://www.eclipse.org/legal/epl-v20.html 007 */ 008package net.mdatools.modelant.core.util; 009 010import java.util.Iterator; 011 012import javax.jmi.reflect.RefClass; 013import javax.jmi.reflect.RefObject; 014 015import net.mdatools.modelant.core.util.map.MapToList; 016 017/** 018 * A cache of Key (1)-to-Value(Many) map of model elements, usually representing associations that are not supported directly in the model 019 */ 020public abstract class Cache<Key extends RefObject, 021 Value extends RefObject> extends MapToList<Key, Value>{ 022 023 /** 024 * This method registers in the cache all instances of that class 025 * @param classProxy not null 026 */ 027 public final void load(RefClass classProxy) { 028 Iterator iterator; 029 RefObject refObject; 030 031 iterator = classProxy.refAllOfClass().iterator(); 032 while ( iterator.hasNext() ) { 033 refObject = (RefObject) iterator.next(); 034 035 register(refObject); 036 } 037 } 038 039 public abstract void register(RefObject refObject); 040 public abstract void unregister(RefObject refObject); 041}