blub
This commit is contained in:
parent
fb77d13eb5
commit
56e19e8039
30 changed files with 485 additions and 37 deletions
49
src/main/java/de/welterde/em/io/EntityLoader.java
Normal file
49
src/main/java/de/welterde/em/io/EntityLoader.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue