/* * Copyright (C) 2026 welterde * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package de.welterde.em.io; import de.welterde.em.EntityBase; import java.lang.reflect.InvocationTargetException; /** * * @author welterde */ public class EntityLoader { protected EntityBase loadEntity(EntityRecord r, String entityClassName) { try { var c = Class.forName(entityClassName); var cc = c.getConstructor(EntityRecord.class); return (EntityBase) cc.newInstance(r); } catch (ClassNotFoundException ex) { throw new RuntimeException("Could not find class: " + entityClassName); } catch (NoSuchMethodException ex) { throw new RuntimeException("Entity class " + entityClassName + " does not support loading (missing EntityRecord constructor)"); } catch (InstantiationException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } catch (IllegalArgumentException ex) { throw new RuntimeException(ex); } catch (InvocationTargetException ex) { throw new RuntimeException(ex); } } }