All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.java.com.dragome.web.enhancers.jsdelegate.JsDelegateFactory Maven / Gradle / Ivy

There is a newer version: 0.96-beta4
Show newest version
/*******************************************************************************
 * Copyright (c) 2011-2014 Fernando Petrola
 * 
 *  This file is part of Dragome SDK.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 ******************************************************************************/

package com.dragome.web.enhancers.jsdelegate;

import com.dragome.commons.javascript.ScriptHelper;

public class JsDelegateFactory
{
	public static  T createFromNode(Object instance, Class type)
	{
		try
		{
			String delegateClassName= JsDelegateGenerator.createDelegateClassName(type.getName());
			Class class2= Class.forName(delegateClassName);
			Object newInstance= class2.newInstance();
			ScriptHelper.put("delegate", newInstance, null);
			ScriptHelper.put("instance", instance, null);
			ScriptHelper.eval("delegate.node= instance.node", null);
			
			return (T) newInstance;
		}
		catch (Exception e)
		{
			throw new RuntimeException(e);
		}
	}
	
	public static  T createFrom(Object instance, Class type)
	{
		try
		{
			String delegateClassName= JsDelegateGenerator.createDelegateClassName(type.getName());
			Class class2= Class.forName(delegateClassName);
			Object newInstance= class2.newInstance();
			ScriptHelper.put("delegate", newInstance, null);
			ScriptHelper.put("instance", instance, null);
			ScriptHelper.eval("delegate.node= instance", null);
			
			return (T) newInstance;
		}
		catch (Exception e)
		{
			throw new RuntimeException(e);
		}
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy