2
0
Fork 0

split event listeners and made xml elements for event en actions on back/frontend

This commit is contained in:
willem.cazander 2010-10-19 15:44:57 +02:00
parent 3d0d609462
commit a51eeeb254
26 changed files with 559 additions and 123 deletions

View file

@ -41,6 +41,6 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE)
public @interface VascEventListener {
String[] backendEventListeners();
String[] frontendEventListeners();
String[] backendEventListeners() default {};
String[] frontendEventListeners() default {};
}

View file

@ -34,6 +34,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.idcanet.vasc.backends.MapVascEntryFieldValue;
import com.idcanet.vasc.backends.MapVascEntryRecordCreator;
import com.idcanet.vasc.core.AbstractVascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
@ -151,49 +153,13 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
VascEntryFieldValue result = new VascEntryFieldValue() {
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public Object getValue(VascEntryField field, Object record) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
Object o = map.get(field.getBackendName());
return o;
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
public String getDisplayValue(VascEntryField field, Object record) throws VascException {
return ""+getValue(field,record); // not supported
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public void setValue(VascEntryField field, Object record,Object value) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
map.put(field.getBackendName(), value);
}
};
return result;
return new MapVascEntryFieldValue();
}
/**
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new VascEntryRecordCreator() {
public Class<?> getObjectClass() {
return Map.class;
}
public Object newRecord(VascEntry entry) throws Exception {
return new HashMap<String,Object>(10);
}
};
return new MapVascEntryRecordCreator();
}
}

View file

@ -26,6 +26,9 @@
package com.idcanet.vasc.core;
import java.util.logging.Logger;
/**
*
* @author Willem Cazander
@ -56,10 +59,11 @@ abstract public class AbstractVascFrontend implements VascFrontend {
*/
public void initEntry(VascEntry entry) throws Exception {
if (entry.getVascFrontendData().getVascFrontend()==null) {
Logger.getLogger(AbstractVascFrontend.class.getName()).fine("Bind frontend: "+this+" to: "+entry.getVascFrontendData()+" entry: "+entry.getId());
entry.getVascFrontendData().setVascFrontend(this);
} else {
if (entry.getVascFrontendData().getVascFrontend()!=this) {
throw new IllegalArgumentException("VascEntry has already a differtent VascFrontend attected");
throw new IllegalArgumentException("VascEntry '"+entry.getId()+"' data: "+entry.getVascFrontendData()+" frontend: "+this+" has already a differtent VascFrontend attected");
}
}
this.entry=entry;

View file

@ -393,13 +393,13 @@ public interface VascEntry extends Cloneable,Serializable {
* Added an VascEntryFrontendEventListener
* @param listener The class of the event listener.
*/
public void addVascEntryFrontendEventListener(String listener);
public void addVascEntryFrontendEventListener(String listener,String frontendType);
/**
* Returns the list of VascEntryFrontendEventListener
* @return
*/
public List<String> getVascEntryFrontendEventListeners();
public List<String> getVascEntryFrontendEventListenersByType(String frontendType);
public void addListOption(VascEntryField listOption);
@ -409,6 +409,9 @@ public interface VascEntry extends Cloneable,Serializable {
public void addVascBackendFilter(VascBackendFilter filter);
public List<VascBackendFilter> getVascBackendFilters();
public void addVascEntryFrontendAction(String actionClass,String frontendType);
public List<String> getVascEntryFrontendActionsByType(String frontendType);
/**
* Force impl to have public clone methode
* @return

View file

@ -40,6 +40,8 @@ public interface VascFrontend {
public String getId();
public String getFrontendType();
public void initEntry(VascEntry entry) throws Exception;
public void renderView() throws Exception;

View file

@ -103,7 +103,7 @@ public interface VascFrontendData {
public VascEntryState getVascEntryState();
public void setVascEntryState(VascEntryState state);
public void initFrontendListeners(VascEntry entry) throws InstantiationException, IllegalAccessException;
public void initFrontendListeners(VascEntry entry,String frontendType) throws InstantiationException, IllegalAccessException;
public void addVascEntryFrontendEventListener(VascEntryFrontendEventListener listener);
public List<VascEntryFrontendEventListener> getVascEntryFrontendEventListener(VascEntryFrontendEventListener.VascFrontendEventType type);
}

View file

@ -60,7 +60,7 @@ public interface VascEntryBackendEventListener extends Serializable {
POST_MOVE_UP
}
public VascBackendEventType[] getEventType();
public VascBackendEventType[] getEventTypes();
/**
* Is executed when the type of event is fired.

View file

@ -41,9 +41,7 @@ import com.idcanet.vasc.core.actions.ColumnVascAction;
import com.idcanet.vasc.core.actions.GlobalVascAction;
import com.idcanet.vasc.core.actions.RowVascAction;
import com.idcanet.vasc.core.actions.VascAction;
import com.idcanet.vasc.core.entry.VascEntryBackendEventListener;
import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel;
import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener;
/**
* VascEntry
@ -87,11 +85,12 @@ public class DefaultVascEntry implements VascEntry {
private List<VascLinkEntry> vascLinkEntries = null;
private Map<String,Object> entryParameters = null;
private VascEntryFieldEventChannel vascEntryFieldEventChannel = null;
private List<String> eventEntryFrontendEventListeners = null;
private Map<String,List<String>> eventEntryFrontendEventListeners = null;
private List<String> eventEntryBackendEventListeners = null;
private List<VascEntryField> listOptions = null;
private List<VascBackendFilter> backendFilters = null;
private Map<String,List<String>> eventEntryFrontendActions = null;
private String backendId = null;
private VascFrontendData vascFrontendData = null;
@ -109,7 +108,8 @@ public class DefaultVascEntry implements VascEntry {
vascLinkEntries = new ArrayList<VascLinkEntry>(10);
entryParameters = new HashMap<String,Object>(10);
eventEntryFrontendEventListeners = new ArrayList<String>(10);
eventEntryFrontendActions = new HashMap<String,List<String>>(10);
eventEntryFrontendEventListeners = new HashMap<String,List<String>>(10);
eventEntryBackendEventListeners = new ArrayList<String>(10);
listOptions = new ArrayList<VascEntryField>(5);
backendFilters = new ArrayList<VascBackendFilter>(3);
@ -143,8 +143,9 @@ public class DefaultVascEntry implements VascEntry {
result.vascAdminDelete=vascAdminDelete;
result.backendId=backendId;
result.vascEntryFieldEventChannel=vascEntryFieldEventChannel;
result.eventEntryFrontendEventListeners.addAll(eventEntryFrontendEventListeners);
result.eventEntryFrontendEventListeners.putAll(eventEntryFrontendEventListeners);
result.eventEntryBackendEventListeners.addAll(eventEntryBackendEventListeners);
result.eventEntryFrontendActions.putAll(eventEntryFrontendActions);
// skipping 'vascFrontendData' because it should always be null when cloning happens.
for (VascEntryField f:vascFields) {
@ -172,10 +173,10 @@ public class DefaultVascEntry implements VascEntry {
ff.setVascEntry(result);
result.listOptions.add(ff);
}
for (VascBackendFilter f:backendFilters) {
VascBackendFilter ff = f.clone();
result.backendFilters.add(ff);
}
// for (VascBackendFilter f:backendFilters) {
// VascBackendFilter ff = f.clone();
// result.backendFilters.add(ff);
// }
// no cloning of the values here ?
@ -736,18 +737,84 @@ public class DefaultVascEntry implements VascEntry {
* Added an VascEntryFrontendEventListener
* @param listener The class of the event listener.
*/
public void addVascEntryFrontendEventListener(String listener) {
eventEntryFrontendEventListeners.add(listener);
public void addVascEntryFrontendEventListener(String listener,String frontendType) {
if (frontendType==null) {
frontendType = "__ALL__";
}
if (frontendType.isEmpty() | "all".equalsIgnoreCase(frontendType)) {
frontendType = "__ALL__";
}
List<String> typeList = eventEntryFrontendEventListeners.get(frontendType);
if (typeList==null) {
typeList = new ArrayList<String>(10);
eventEntryFrontendEventListeners.put(frontendType,typeList);
}
typeList.add(listener);
}
/**
* Returns the list of VascEntryFrontendEventListener
* @return
*/
public List<String> getVascEntryFrontendEventListeners() {
return eventEntryFrontendEventListeners;
public List<String> getVascEntryFrontendEventListenersByType(String frontendType) {
if (frontendType==null) {
frontendType = "__ALL__";
}
if (frontendType.isEmpty() | "all".equalsIgnoreCase(frontendType)) {
frontendType = "__ALL__";
}
List<String> typeList = eventEntryFrontendEventListeners.get(frontendType);
if (typeList==null) {
typeList = new ArrayList<String>(0);
}
if (frontendType.equals("__ALL__")==false) {
// also add all
List<String> typeListAll = eventEntryFrontendEventListeners.get("__ALL__");
if (typeListAll!=null) {
typeList.addAll(typeListAll);
}
}
return typeList;
}
public void addVascEntryFrontendAction(String actionClass,String frontendType) {
if (frontendType==null) {
frontendType = "__ALL__";
}
if (frontendType.isEmpty() | "all".equalsIgnoreCase(frontendType)) {
frontendType = "__ALL__";
}
List<String> typeList = eventEntryFrontendActions.get(frontendType);
if (typeList==null) {
typeList = new ArrayList<String>(10);
eventEntryFrontendActions.put(frontendType,typeList);
}
typeList.add(actionClass);
}
public List<String> getVascEntryFrontendActionsByType(String frontendType) {
if (frontendType==null) {
frontendType = "__ALL__";
}
if (frontendType.isEmpty() | "all".equalsIgnoreCase(frontendType)) {
frontendType = "__ALL__";
}
List<String> typeList = eventEntryFrontendActions.get(frontendType);
if (typeList==null) {
typeList = new ArrayList<String>(0);
}
if (frontendType.equals("__ALL__")==false) {
// also add all
List<String> typeListAll = eventEntryFrontendActions.get("__ALL__");
if (typeListAll!=null) {
typeList.addAll(typeListAll);
}
}
return typeList;
}
public void addListOption(VascEntryField listOption) {
if (listOption==null) {
throw new NullPointerException("can not add null listOption.");

View file

@ -115,10 +115,7 @@ public class DefaultVascFactory {
if (backend.isPageable()==false) {
backend = new VascBackendProxyPaged(backend,entry);
}
// execute backend event listeners
backend = new VascBackendProxyEventExecutor(backend,entry);
// return the configed backend.
return backend;
}

View file

@ -40,6 +40,10 @@ import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.VascFrontend;
import com.idcanet.vasc.core.VascFrontendData;
import com.idcanet.vasc.core.VascFrontendHelper;
import com.idcanet.vasc.core.actions.ColumnVascAction;
import com.idcanet.vasc.core.actions.GlobalVascAction;
import com.idcanet.vasc.core.actions.RowVascAction;
import com.idcanet.vasc.core.actions.VascAction;
import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService;
import com.idcanet.vasc.core.entry.VascEntryFrontendEventListener;
import com.idcanet.vasc.core.entry.VascEntryResourceImageResolver;
@ -247,12 +251,12 @@ public class DefaultVascFrontendData implements VascFrontendData {
}
public void initFrontendListeners(VascEntry entry) throws InstantiationException, IllegalAccessException {
public void initFrontendListeners(VascEntry entry,String frontendType) throws InstantiationException, IllegalAccessException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl==null) {
cl = entry.getClass().getClassLoader();
}
for (String clazz:entry.getVascEntryFrontendEventListeners()) {
for (String clazz:entry.getVascEntryFrontendEventListenersByType(frontendType)) {
VascEntryFrontendEventListener listener;
try {
listener = (VascEntryFrontendEventListener)cl.loadClass(clazz).newInstance();
@ -261,6 +265,44 @@ public class DefaultVascFrontendData implements VascFrontendData {
}
addVascEntryFrontendEventListener(listener);
}
for (String clazz:entry.getVascEntryFrontendActionsByType(frontendType)) {
Object obj = null;
try {
obj = cl.loadClass(clazz).newInstance();
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not load frontend action of: "+clazz);
}
if (obj instanceof VascAction) {
VascAction action = (VascAction)obj;
String aid = action.getId();
if (aid==null) {
throw new IllegalArgumentException("Action has no id: "+action+" in entryId: "+entry.getId());
}
if (action.getName()==null) {
action.setName("vasc.action."+aid+".name");
}
if (action.getDescription()==null) {
action.setDescription("vasc.action."+aid+".description");
}
if (action.getImage()==null) {
action.setImage("vasc.action."+aid+".image");
}
if (action.getHelpId()==null) {
action.setHelpId("vasc.action."+aid+".helpId");
}
}
if (obj instanceof RowVascAction) {
entry.addRowAction((RowVascAction)obj);
}
if (obj instanceof ColumnVascAction) {
entry.addColumnAction((ColumnVascAction)obj);
}
if (obj instanceof GlobalVascAction) {
entry.addGlobalAction((GlobalVascAction)obj);
}
}
}
public void addVascEntryFrontendEventListener(VascEntryFrontendEventListener listener) {

View file

@ -67,11 +67,29 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy {
listeners.add(listener);
}
}
public VascBackendProxyEventExecutor(VascBackend backend,VascEntry entry,List<VascEntryBackendEventListener> listeners) {
super(backend);
this.entry=entry;
this.listeners=listeners;
}
private void fireVascEvent(VascBackendEventType type, Object data) {
for (int i=0;i<listeners.size();i++) {
VascEntryBackendEventListener l = listeners.get(i);
l.vascEvent(entry, data);
VascBackendEventType[] types = l.getEventTypes();
if (types==null) {
continue;
}
if (types.length==0) {
continue;
}
for (int t=0;t<types.length;t++) {
VascBackendEventType typeListener = types[t];
if (typeListener==type) {
l.vascEvent(entry, data);
}
}
}
}

View file

@ -0,0 +1,137 @@
package com.idcanet.vasc.impl.entry;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.entry.VascEntryBackendEventListener;
public class SetParameterBackendListener implements VascEntryBackendEventListener {
private static final long serialVersionUID = 1L;
private String name = null;
private String value = null;
private String type = null;
private boolean isUserValue = false;
private Long userId = null;
private String userName = null;
public SetParameterBackendListener() {
}
public SetParameterBackendListener(Long userId,String userName) {
this.userId=userId;
this.userName=userName;
isUserValue = true;
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryBackendEventListener#getEventType()
*/
public VascBackendEventType[] getEventTypes() {
return new VascBackendEventType[] {
VascBackendEventType.PRE_DELETE,
VascBackendEventType.PRE_EXECUTE,
VascBackendEventType.PRE_MERGE,
VascBackendEventType.PRE_MOVE_DOWN,
VascBackendEventType.PRE_MOVE_UP,
VascBackendEventType.PRE_PERSIST,
VascBackendEventType.PRE_TOTAL_EXECUTE_SIZE
};
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryBackendEventListener#vascEvent(com.idcanet.vasc.core.VascEntry, java.lang.Object)
*/
public void vascEvent(VascEntry entry, Object data) {
if (data instanceof VascBackendState) {
VascBackendState state = (VascBackendState)data;
if (isUserValue) {
if (value==null) {
value="id";
}
if ("id".equals(value)) {
if ("int".equals(type)) {
state.setDataParameter(name, userId.intValue());
} else {
state.setDataParameter(name, userId);
}
} else {
state.setDataParameter(name, userName);
}
} else {
state.setDataParameter(name, value);
}
}
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* @return the type
*/
public String getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* @return the userId
*/
public Long getUserId() {
return userId;
}
/**
* @param userId the userId to set
*/
public void setUserId(Long userId) {
this.userId = userId;
}
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
}

View file

@ -112,7 +112,7 @@ public class AnnotationParserElement extends AbstractElement {
VascEventListener vc = parser.getVascEventListener(modelClass);
if (vc!=null) {
for (String listener:vc.frontendEventListeners()) {
entry.addVascEntryFrontendEventListener(listener);
entry.addVascEntryFrontendEventListener(listener,null);
}
for (String listener:vc.backendEventListeners()) {
entry.addVascEntryBackendEventListener(listener);

View file

@ -58,21 +58,7 @@ public class SetParameterElement extends AbstractElement {
logger.fine("Setting parameter name: "+name+" value: "+value+" type: "+type);
if ("setUserParameter".equals(getElementClass().getTag())) {
if (value==null) {
value="id";
}
if ("id".equals(value)) {
if ("int".equals(type)) {
Long userId = cont.getVascUserRoleController().getUserId();
entry.setEntryParameter(name, userId.intValue());
} else {
Long userId = cont.getVascUserRoleController().getUserId();
entry.setEntryParameter(name, userId);
}
} else {
String userName = cont.getVascUserRoleController().getUserName();
entry.setEntryParameter(name, userName);
}
entry.setEntryParameter(name, "userPara:"+type+":"+value);
return;
}
@ -92,4 +78,6 @@ public class SetParameterElement extends AbstractElement {
throw new ElementException("Could not set dataParameter: "+name+" with type: "+type);
}
}

View file

@ -0,0 +1,87 @@
/*
* Copyright 2004-2008 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.impl.x4o;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.actions.ColumnVascAction;
import com.idcanet.vasc.core.actions.GlobalVascAction;
import com.idcanet.vasc.core.actions.RowVascAction;
import com.idcanet.x4o.core.X4OParser;
import com.idcanet.x4o.element.AbstractElement;
import com.idcanet.x4o.element.ElementException;
/**
* Handed the eventListener xml tag.
*
* @author Willem Cazander
* @version 1.0 Oct 18, 2010
*/
public class VascEntryActionElement extends AbstractElement {
/**
* @see com.idcanet.x4o.element.AbstractElement#doElementRun()
*/
@Override
public void doElementRun() throws ElementException {
String clazz = getAttributes().get("class");
String type = getAttributes().get("type");
String frontendType = getAttributes().get("frontendType");
if (clazz==null) {
throw new ElementException("No class attribute given.");
}
if (clazz.isEmpty()) {
throw new ElementException("class attribute is empty.");
}
if (getParent().getElementObject() instanceof VascEntry==false) {
throw new ElementException("Parent object is not vasc entry.");
}
VascEntry v = (VascEntry)getParent().getElementObject();
if ("backend".equalsIgnoreCase(type)) {
Object obj = null;
try {
Class<?> clazz2 = X4OParser.loadClass(clazz);
obj = clazz2.newInstance();
} catch (Exception e) {
throw new ElementException("Could not load class: "+clazz);
}
if (obj instanceof RowVascAction) {
v.addRowAction((RowVascAction)obj);
}
if (obj instanceof ColumnVascAction) {
v.addColumnAction((ColumnVascAction)obj);
}
if (obj instanceof GlobalVascAction) {
v.addGlobalAction((GlobalVascAction)obj);
}
} else if ("frontend".equalsIgnoreCase(type)) {
v.addVascEntryFrontendAction(clazz, frontendType);
} else {
throw new ElementException("Unsupported type attribute: "+type);
}
}
}

View file

@ -0,0 +1,68 @@
/*
* Copyright 2004-2008 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.impl.x4o;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.x4o.element.AbstractElement;
import com.idcanet.x4o.element.ElementException;
/**
* Handed the eventListener xml tag.
*
* @author Willem Cazander
* @version 1.0 Oct 18, 2010
*/
public class VascEventListenerElement extends AbstractElement {
/**
* @see com.idcanet.x4o.element.AbstractElement#doElementRun()
*/
@Override
public void doElementRun() throws ElementException {
String clazz = getAttributes().get("class");
String type = getAttributes().get("type");
String frontendType = getAttributes().get("frontendType");
if (clazz==null) {
throw new ElementException("No class attribute given.");
}
if (clazz.isEmpty()) {
throw new ElementException("class attribute is empty.");
}
if (getParent().getElementObject() instanceof VascEntry==false) {
throw new ElementException("Parent object is not vasc entry.");
}
VascEntry v = (VascEntry)getParent().getElementObject();
if ("backend".equalsIgnoreCase(type)) {
v.addVascEntryBackendEventListener(clazz);
} else if ("frontend".equalsIgnoreCase(type)) {
v.addVascEntryFrontendEventListener(clazz, frontendType);
} else {
throw new ElementException("Unsupported type attribute: "+type);
}
}
}

View file

@ -22,6 +22,8 @@
<eld:elementClassAttributeConverter attributeName="vascEntryFieldType" bean.class="com.idcanet.vasc.impl.x4o.VascEntryFieldTypeAttributeConverter"/>
</eld:elementClass>
<eld:elementClass tag="vascEntryFieldType" elementClassName="com.idcanet.vasc.impl.x4o.VascEntryFieldTypeElement"/>
<eld:elementClass tag="eventListener" elementClassName="com.idcanet.vasc.impl.x4o.VascEventListenerElement"/>
<eld:elementClass tag="entryAction" elementClassName="com.idcanet.vasc.impl.x4o.VascEntryActionElement"/>
<eld:elementClass tag="vascSelectItemModel" objectClassName="com.idcanet.vasc.impl.DefaultVascSelectItemModel"/>
<eld:elementClass tag="vascSelectItemEntryParameter" elementClassName="com.idcanet.vasc.impl.x4o.VascLinkEntryParameterElement"/>