at.spardat.xma.mdl.NewModelEventFactory Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2003, 2009 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
package at.spardat.xma.mdl;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import at.spardat.enterprise.exc.SysException;
import at.spardat.xma.mdl.list.ListDomWM.NewListDomWMEvent;
import at.spardat.xma.mdl.list.ListWM.NewListWMEvent;
import at.spardat.xma.mdl.paging.PagingWM.NewPagingWMEvent;
import at.spardat.xma.mdl.simple.SimpleWM.NewSimpleWMEvent;
import at.spardat.xma.mdl.table.TableWM.NewTableWMEvent;
import at.spardat.xma.mdl.tree.TreeWM.NewTreeWMEvent;
import at.spardat.xma.session.XMASession;
/**
* This class is used to create the correct subclass of {@link NewModelEvent} for each
* type id read from serialized data during page synchronization.
* The NewModelEventFactory can be retrieved with {@link XMASession#getNewModelEventFactory()}.
* The implementation of this factory can be configured as optional plugin in xma-app.xml.
* This class defines the interface and is the default implementation.
*
* @author gub
* @since 2.1.0
*/
public class NewModelEventFactory {
/** type id for NewModelEvents creating SimpleWM objects */
public static final byte SimpleWM = 0;
/** type id for NewModelEvents creating ListWM objects */
public static final byte ListWM = 1;
/** type id for NewModelEvents creating ListDomWM objects */
public static final byte ListDomWM = 2;
/** type id for NewModelEvents creating TableWM objects */
public static final byte TableWM = 3;
/** type id for NewModelEvents creating TreeWM objects */
public static final byte TreeWM = 4;
/** type id for NewPagingModelEvents creating PagingWM objects */
public static final byte PagingWM = 5;
/**
* Last id known by this factory.
* Subclasses of this factory have to start their additional ids with LAST+1
* */
public static final byte LAST = PagingWM;
/** server side model classes indexed by type id */
protected String[] eventClassesServer = {
NewSimpleWMEvent.class.getName(),
NewListWMEvent.class.getName(),
NewListDomWMEvent.class.getName(),
NewTableWMEvent.class.getName(),
NewTreeWMEvent.class.getName(),
NewPagingWMEvent.class.getName()
};
/** client side model classes indexed by type id */
protected String[] eventClassesClient = {
"at.spardat.xma.mdl.simple.SimpleWMClient$NewSimpleWMClientEvent",
"at.spardat.xma.mdl.list.ListWMClient$NewListWMClientEvent",
"at.spardat.xma.mdl.list.ListDomWMClient$NewListDomWMClientEvent",
"at.spardat.xma.mdl.table.TableWMClient$NewTableWMClientEvent",
"at.spardat.xma.mdl.tree.TreeWMClient$NewTreeWMClientEvent",
"at.spardat.xma.mdl.paging.PagingWMClient$NewPagingWMClientEvent"
};
/**
* Creates an empty NewModelEvent object. This object is of the correct subclass
* of NewModelEvent corresponding to the given type id.
* @param type type id as read from the serialized data stream
* @param onServer note: there are different NewModelEvent-classes used on client and server
*/
public NewModelEvent createEvent(byte type,boolean onServer) {
String className;
if(onServer) className = eventClassesServer[type];
else className = eventClassesClient[type];
try {
Class eventClass = Class.forName(className);
Constructor constructor = eventClass.getConstructor(new Class[]{});
return (NewModelEvent) constructor.newInstance(new Object[]{});
} catch (InvocationTargetException e) {
throw new SysException(e.getTargetException());
} catch (Exception e) {
throw new SysException(e);
}
}
}