Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public <T> T getInstance(Class<T> clazz, String code,String packageName)
- throws IOException, InstantiationException, IllegalAccessException, NameNotFoundException {
- final String name = getClassName(code);
- final Path wrappedCodede = wrapCode(packageName, name, code);
- final Path classFile = compile(wrappedCodede);
- final ClassLoaderFromTemp loader = new ClassLoaderFromTemp();
- final Class<?> p1Class = loader.findClassInTemp(classFile);
- final Object instace = p1Class.newInstance();
- cleanupTmp();
- return clazz.cast(instace);
- }
- public static void main(String[] args) {
- try {
- AgentBuilder.addToClassPath("src");
- AgentBuilder ab = new AgentBuilder();
- ab.getInstance(Ship.class, CODE, "Teste");
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- }
- void checkCode() throws SoncException {
- try {
- AgentBuilder agentBuilder = new AgentBuilder();
- agentBuilder.getInstance(Ship.class, this.code, this.nick);
- } catch (IOException | InstantiationException | IllegalAccessException | NameNotFoundException
- | NullPointerException | ClassCastException e) {
- throw new SoncException("An error occurred on checking player's code.", e);
- }
- }
Add Comment
Please, Sign In to add comment