// Path: src/main/java/com/modelsolv/kaboom/model/canonical/CanonicalDataType.java
// public interface CanonicalDataType {
// 	
// 	public String getName();
// 	
// 	public void setName(String name);
// 	
// 	public Iterable<CDMProperty> getProperties();
// 	
// 	public CDMProperty getProperty(String propName);
// 	
// 	public boolean hasProperty(CDMProperty property);
// 	
// 	public CanonicalDataType withPrimitive(String name, PrimitiveDataType type);
// 	
// 	public CanonicalDataType withPrimitive(String name, PrimitiveDataType type, Cardinality cardinality);
// 
// 	public CanonicalDataType withReference(String name, CanonicalDataType type);
// 
// 	public CanonicalDataType withReference(String name, CanonicalDataType type, Cardinality cardinality);
// 
// }
// 
// Path: src/main/java/com/modelsolv/kaboom/model/resource/nativeImpl/ObjectResourceDefinitionRegistryImpl.java
// public class ObjectResourceDefinitionRegistryImpl implements
// 		ObjectResourceDefinitionRegistry {
// 
// 	private Map<String, ObjectResourceDefinition> nameMap = new HashMap<String, ObjectResourceDefinition>();
// 	private Map<CanonicalDataType, ObjectResourceDefinition> cdtMap = new HashMap<CanonicalDataType, ObjectResourceDefinition>();
// 	private Map<ResourceDataModel, ObjectResourceDefinition> rdmMap = new HashMap<ResourceDataModel, ObjectResourceDefinition>();
// 
// 	@Override
// 	public void registerDefinition(ObjectResourceDefinition definition) {
// 
// 		class Remover {
// 			/**
// 			 * Remove any entry already keyed to this definition. The algo is
// 			 * aggressive: Any definition having any existing map key will be
// 			 * removed from all three maps.
// 			 * 
// 			 * @param definition
// 			 */
// 			public void removeDuplicates(ObjectResourceDefinition definition) {
// 				removeName(definition.getName());
// 				removeRDM(definition.getResourceDataModel());
// 				removeCDT(definition.getResourceDataModel()
// 						.getCanonicalDataType());
// 			}
// 
// 			void removeName(String name) {
// 				ObjectResourceDefinition def = getResourceDefinition(name);
// 				if (def != null) {
// 					remove(def);
// 				}
// 			}
// 
// 			void removeRDM(ResourceDataModel rdm) {
// 				ObjectResourceDefinition def = getResourceDefinition(rdm);
// 				if (def != null) {
// 					remove(def);
// 				}
// 			}
// 
// 			void removeCDT(CanonicalDataType cdt) {
// 				ObjectResourceDefinition def = getResourceDefinition(cdt);
// 				if (def != null) {
// 					remove(def);
// 				}
// 			}
// 
// 			void remove(ObjectResourceDefinition definition) {
// 				removeFromMap(definition, nameMap);
// 				removeFromMap(definition, rdmMap);
// 				removeFromMap(definition, cdtMap);
// 			}
// 
// 			void removeFromMap(ObjectResourceDefinition definition,
// 					Map<?, ?> map) {
// 				boolean foundAndRemoved;
// 				do {
// 					foundAndRemoved = false;
// 					for (Entry<?, ?> entry : map.entrySet()) {
// 						if (entry.getValue() == definition) {
// 							map.remove(entry.getKey());
// 							foundAndRemoved = true;
// 							break;
// 						}
// 					}
// 				} while (foundAndRemoved); // removed one, look for another
// 			}
// 		}
// 
// 		new Remover().removeDuplicates(definition);
// 		nameMap.put(definition.getName(), definition);
// 		rdmMap.put(definition.getResourceDataModel(), definition);
// 		cdtMap.put(definition.getResourceDataModel().getCanonicalDataType(),
// 				definition);
// 	}
// 
// 	@Override
// 	public ObjectResourceDefinition getResourceDefinition(String name) {
// 		return nameMap.containsKey(name) ? nameMap.get(name) : null;
// 	}
// 
// 	@Override
// 	public ObjectResourceDefinition getResourceDefinition(ResourceDataModel rdm) {
// 		return rdmMap.containsKey(rdm) ? rdmMap.get(rdm) : null;
// 	}
// 
// 	@Override
// 	public ObjectResourceDefinition getResourceDefinition(CanonicalDataType cdt) {
// 		return cdtMap.containsKey(cdt) ? cdtMap.get(cdt) : null;
// 	}
// 
// }


import com.modelsolv.kaboom.model.canonical.CanonicalDataType;
import com.modelsolv.kaboom.model.resource.nativeImpl.ObjectResourceDefinitionRegistryImpl;
/*******************************************************************************
 * Copyright (c) 2014 ModelSolv, Inc. and others.
 * 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:
 *     ModelSolv, Inc. - initial API and implementation.
 *******************************************************************************/
package com.modelsolv.kaboom.model.resource;


/**
 * A registry of ObjectResourceDefinitions, allowing lookup by the name or by
 * the associated ResourceDataModel.
 * 
 * @author Ted
 * 
 */
public interface ObjectResourceDefinitionRegistry {

	// TODO: Check use of Singleton pattern, consider DI/Resource Locator.
	public static ObjectResourceDefinitionRegistry INSTANCE = new ObjectResourceDefinitionRegistryImpl();

	/**
	 * Register a ResourceDataModel. Registering an ObjectResourceDefinition
	 * with a duplicate name, ResourceDataModel or CanonicalDataType will remove
	 * the previous entry from the registry, and add this one in its place.
	 * 
	 * @param rdm
	 * @param definition
	 */
	public void registerDefinition(ObjectResourceDefinition definition);

	/**
	 * Retrieve an ObjectResourceDefinition by its name.
	 * 
	 * @param name
	 * @return
	 */
	public ObjectResourceDefinition getResourceDefinition(String name);

	/**
	 * Retrieve an ObjectResourceDefinition by its associated ResourceDataModel.
	 * 
	 * @param name
	 * @return
	 */
	public ObjectResourceDefinition getResourceDefinition(ResourceDataModel rdm);

	/**
	 * Retrieve an ObjectResourceDefinition by its associated CanonicalDataType.
	 * 
	 * @param name
	 * @return
	 */
// Path: src/main/java/com/modelsolv/kaboom/model/canonical/CanonicalDataType.java
// public interface CanonicalDataType {
// 	
// 	public String getName();
// 	
// 	public void setName(String name);
// 	
// 	public Iterable<CDMProperty> getProperties();
// 	
// 	public CDMProperty getProperty(String propName);
// 	
// 	public boolean hasProperty(CDMProperty property);
// 	
// 	public CanonicalDataType withPrimitive(String name, PrimitiveDataType type);
// 	
// 	public CanonicalDataType withPrimitive(String name, PrimitiveDataType type, Cardinality cardinality);
// 
// 	public CanonicalDataType withReference(String name, CanonicalDataType type);
// 
// 	public CanonicalDataType withReference(String name, CanonicalDataType type, Cardinality cardinality);
// 
// }
// 
// Path: src/main/java/com/modelsolv/kaboom/model/resource/nativeImpl/ObjectResourceDefinitionRegistryImpl.java
// public class ObjectResourceDefinitionRegistryImpl implements
// 		ObjectResourceDefinitionRegistry {
// 
// 	private Map<String, ObjectResourceDefinition> nameMap = new HashMap<String, ObjectResourceDefinition>();
// 	private Map<CanonicalDataType, ObjectResourceDefinition> cdtMap = new HashMap<CanonicalDataType, ObjectResourceDefinition>();
// 	private Map<ResourceDataModel, ObjectResourceDefinition> rdmMap = new HashMap<ResourceDataModel, ObjectResourceDefinition>();
// 
// 	@Override
// 	public void registerDefinition(ObjectResourceDefinition definition) {
// 
// 		class Remover {
// 			/**
// 			 * Remove any entry already keyed to this definition. The algo is
// 			 * aggressive: Any definition having any existing map key will be
// 			 * removed from all three maps.
// 			 * 
// 			 * @param definition
// 			 */
// 			public void removeDuplicates(ObjectResourceDefinition definition) {
// 				removeName(definition.getName());
// 				removeRDM(definition.getResourceDataModel());
// 				removeCDT(definition.getResourceDataModel()
// 						.getCanonicalDataType());
// 			}
// 
// 			void removeName(String name) {
// 				ObjectResourceDefinition def = getResourceDefinition(name);
// 				if (def != null) {
// 					remove(def);
// 				}
// 			}
// 
// 			void removeRDM(ResourceDataModel rdm) {
// 				ObjectResourceDefinition def = getResourceDefinition(rdm);
// 				if (def != null) {
// 					remove(def);
// 				}
// 			}
// 
// 			void removeCDT(CanonicalDataType cdt) {
// 				ObjectResourceDefinition def = getResourceDefinition(cdt);
// 				if (def != null) {
// 					remove(def);
// 				}
// 			}
// 
// 			void remove(ObjectResourceDefinition definition) {
// 				removeFromMap(definition, nameMap);
// 				removeFromMap(definition, rdmMap);
// 				removeFromMap(definition, cdtMap);
// 			}
// 
// 			void removeFromMap(ObjectResourceDefinition definition,
// 					Map<?, ?> map) {
// 				boolean foundAndRemoved;
// 				do {
// 					foundAndRemoved = false;
// 					for (Entry<?, ?> entry : map.entrySet()) {
// 						if (entry.getValue() == definition) {
// 							map.remove(entry.getKey());
// 							foundAndRemoved = true;
// 							break;
// 						}
// 					}
// 				} while (foundAndRemoved); // removed one, look for another
// 			}
// 		}
// 
// 		new Remover().removeDuplicates(definition);
// 		nameMap.put(definition.getName(), definition);
// 		rdmMap.put(definition.getResourceDataModel(), definition);
// 		cdtMap.put(definition.getResourceDataModel().getCanonicalDataType(),
// 				definition);
// 	}
// 
// 	@Override
// 	public ObjectResourceDefinition getResourceDefinition(String name) {
// 		return nameMap.containsKey(name) ? nameMap.get(name) : null;
// 	}
// 
// 	@Override
// 	public ObjectResourceDefinition getResourceDefinition(ResourceDataModel rdm) {
// 		return rdmMap.containsKey(rdm) ? rdmMap.get(rdm) : null;
// 	}
// 
// 	@Override
// 	public ObjectResourceDefinition getResourceDefinition(CanonicalDataType cdt) {
// 		return cdtMap.containsKey(cdt) ? cdtMap.get(cdt) : null;
// 	}
// 
// }


// Path: src/main/java/com/modelsolv/kaboom/model/resource/ObjectResourceDefinitionRegistry.java
import com.modelsolv.kaboom.model.canonical.CanonicalDataType;
import com.modelsolv.kaboom.model.resource.nativeImpl.ObjectResourceDefinitionRegistryImpl;

/*******************************************************************************
 * Copyright (c) 2014 ModelSolv, Inc. and others.
 * 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:
 *     ModelSolv, Inc. - initial API and implementation.
 *******************************************************************************/
package com.modelsolv.kaboom.model.resource;


/**
 * A registry of ObjectResourceDefinitions, allowing lookup by the name or by
 * the associated ResourceDataModel.
 * 
 * @author Ted
 * 
 */
public interface ObjectResourceDefinitionRegistry {

	// TODO: Check use of Singleton pattern, consider DI/Resource Locator.
	public static ObjectResourceDefinitionRegistry INSTANCE = new ObjectResourceDefinitionRegistryImpl();

	/**
	 * Register a ResourceDataModel. Registering an ObjectResourceDefinition
	 * with a duplicate name, ResourceDataModel or CanonicalDataType will remove
	 * the previous entry from the registry, and add this one in its place.
	 * 
	 * @param rdm
	 * @param definition
	 */
	public void registerDefinition(ObjectResourceDefinition definition);

	/**
	 * Retrieve an ObjectResourceDefinition by its name.
	 * 
	 * @param name
	 * @return
	 */
	public ObjectResourceDefinition getResourceDefinition(String name);

	/**
	 * Retrieve an ObjectResourceDefinition by its associated ResourceDataModel.
	 * 
	 * @param name
	 * @return
	 */
	public ObjectResourceDefinition getResourceDefinition(ResourceDataModel rdm);

	/**
	 * Retrieve an ObjectResourceDefinition by its associated CanonicalDataType.
	 * 
	 * @param name
	 * @return
	 */
	public ObjectResourceDefinition getResourceDefinition(CanonicalDataType canonicalDataType);