
com.nedap.archie.creation.RMObjectCreator Maven / Gradle / Ivy
package com.nedap.archie.creation;
import com.nedap.archie.aom.CObject;
import com.nedap.archie.rm.archetyped.Locatable;
import com.nedap.archie.rminfo.ArchieRMInfoLookup;
import com.nedap.archie.rminfo.ModelInfoLookup;
import com.nedap.archie.rminfo.RMAttributeInfo;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* Utility to create Reference model objects based on their RM name. Also can set attribute values on RM Objects based
* on their RM Attribute name.
*
* Created by pieter.bos on 03/02/16.
*/
public class RMObjectCreator {
private final ModelInfoLookup classLookup;
public RMObjectCreator(){
this(ArchieRMInfoLookup.getInstance());
}
public RMObjectCreator(ModelInfoLookup lookup) {
this.classLookup = lookup;
}
public T create(CObject constraint) {
Class clazz = classLookup.getClassToBeCreated(constraint.getRmTypeName());
if(clazz == null) {
throw new IllegalArgumentException("cannot construct RMObject because of unknown constraint name " + constraint.getRmTypeName() + " full constraint " + constraint);
}
try {
Object result = clazz.newInstance();
if(result instanceof Locatable) { //and most often, it will be
Locatable locatable = (Locatable) result;
locatable.setArchetypeNodeId(constraint.getNodeId());
locatable.setNameAsString(constraint.getMeaning());
}
return (T) result;
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("error creating class " + constraint.getRmTypeName(), e);
}
}
public void set(Object object, String rmAttributeName, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy