splitted the event listeners
This commit is contained in:
parent
4f409296d0
commit
029ad96a10
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright 2004-2007 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.core.entry;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jul 05, 2010
|
||||
*/
|
||||
public interface VascEntryBackendEventListener extends Serializable {
|
||||
|
||||
public enum VascBackendEventType {
|
||||
EXECUTE,
|
||||
PERSIST,
|
||||
MERGE,
|
||||
DELETE,
|
||||
PROVIDE_FIELD_VALUE,
|
||||
PROVIDE_RECORD_CREATOR,
|
||||
TOTAL_EXECUTE_SIZE,
|
||||
MOVE_DOWN,
|
||||
MOVE_UP
|
||||
}
|
||||
|
||||
public VascBackendEventType getEventType();
|
||||
|
||||
/**
|
||||
* Is executed when the type of event is fired.
|
||||
* @param entry
|
||||
* @param type
|
||||
* @param data
|
||||
*/
|
||||
public void vascEvent(VascEntry entry,Object data);
|
||||
}
|
299
src/main/java/com/idcanet/vasc/ejb3/VascServiceManager.java
Normal file
299
src/main/java/com/idcanet/vasc/ejb3/VascServiceManager.java
Normal file
|
@ -0,0 +1,299 @@
|
|||
|
||||
|
||||
package com.idcanet.vasc.ejb3;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.el.ValueExpression;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
import com.idcanet.vasc.backends.jpa.EntityManagerProvider;
|
||||
import com.idcanet.vasc.core.VascBackend;
|
||||
import com.idcanet.vasc.core.VascController;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.impl.DefaultVascBackedEntryFinalizer;
|
||||
import com.idcanet.vasc.impl.DefaultVascEntryController;
|
||||
import com.idcanet.vasc.impl.DefaultVascFactory;
|
||||
import com.idcanet.vasc.impl.actions.AddRowAction;
|
||||
import com.idcanet.vasc.impl.actions.CSVExportGlobalAction;
|
||||
import com.idcanet.vasc.impl.actions.DeleteRowAction;
|
||||
import com.idcanet.vasc.impl.actions.EditRowAction;
|
||||
import com.idcanet.vasc.impl.actions.XMLExportGlobalAction;
|
||||
import com.idcanet.vasc.impl.entry.DefaultVascEntryResourceResolver;
|
||||
import com.idcanet.vasc.impl.x4o.VascParser;
|
||||
import com.idcanet.x4o.core.AbstractX4OPhaseHandler;
|
||||
import com.idcanet.x4o.core.X4OPhase;
|
||||
import com.idcanet.x4o.core.X4OPhaseException;
|
||||
import com.idcanet.x4o.core.X4OPhaseHandler;
|
||||
import com.idcanet.x4o.element.Element;
|
||||
import com.idcanet.x4o.element.ElementContext;
|
||||
import com.idcanet.xtes.xpql.query.Query;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 13 Aug 2007
|
||||
*/
|
||||
@Stateless(name="ejb/vascSericeManager")
|
||||
public class VascServiceManager implements VascServiceManagerRemote {
|
||||
|
||||
private Logger logger = Logger.getLogger(VascServiceManager.class.getName());
|
||||
|
||||
//@PersistenceContext
|
||||
//protected EntityManager entityManager;
|
||||
|
||||
// @EJB
|
||||
/// public XtesManagerLocal xtesManager;
|
||||
|
||||
|
||||
private VascController sharedVascController = null;
|
||||
|
||||
public Map<String,String> getResourceBundle(String locale) {
|
||||
Map<String,String> result = new HashMap<String,String>(100);
|
||||
ResourceBundle b = ResourceBundle.getBundle("com/idcanet/logstats/resources/i18n/LogstatsBundleEJB");
|
||||
for (String key:b.keySet()) {
|
||||
String value = b.getString(key);
|
||||
result.put(key,value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<String> getVascEntryIds() {
|
||||
VascController v = getVascController();
|
||||
return v.getVascEntryController().getVascEntryIds();
|
||||
}
|
||||
|
||||
public VascEntry getVascEntry(String entryId) {
|
||||
VascController v = getVascController();
|
||||
VascEntry ve = v.getVascEntryController().getVascEntryById(entryId);
|
||||
|
||||
try {
|
||||
VascEntry result = ve.clone();
|
||||
//logger.info("Returning cloned ve.");
|
||||
/*
|
||||
ByteArrayOutputStream dataArray = new ByteArrayOutputStream(256); // it grows when needed
|
||||
ObjectOutputStream objOutstream = new ObjectOutputStream(dataArray);
|
||||
objOutstream.writeObject(ve);
|
||||
objOutstream.close();
|
||||
|
||||
int objectSize = dataArray.size();
|
||||
*/
|
||||
//logger.info("Writing obj to data: "+objectSize);
|
||||
|
||||
return result;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new RuntimeException("VascEntry should alway be clonable",e);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("VascEntry error:",e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object invokeBackendMethod(String backendId,String method,Object[] args) {
|
||||
VascController v = getVascController();
|
||||
VascBackend vb = v.getVascBackendController().getVascBackendById(backendId);
|
||||
Method vbm = null;
|
||||
for (Method m:vb.getClass().getMethods()) {
|
||||
if (m.getName().equals(method)) {
|
||||
vbm = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (vbm==null) {
|
||||
throw new IllegalArgumentException("Could not find: "+method);
|
||||
}
|
||||
try {
|
||||
Object result = vbm.invoke(vb, args);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public VascController getVascController() {
|
||||
if (sharedVascController==null) {
|
||||
sharedVascController = getParsedVascController();
|
||||
}
|
||||
return sharedVascController;
|
||||
}
|
||||
|
||||
|
||||
class XpqlController implements Map<String,Query> {
|
||||
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set<Map.Entry<String, Query>> entrySet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Query get(Object key) {
|
||||
return null;
|
||||
//return xtesManager.getQuery((String)key);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<String> keySet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Query put(String key, Query value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void putAll(Map m) {
|
||||
}
|
||||
|
||||
public Query remove(Object key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Collection<Query> values() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DatafeedsEntityManagerProvider implements EntityManagerProvider {
|
||||
/**
|
||||
* @see com.idcanet.vasc.backends.jpa.EntityManagerProvider#getEntityManager()
|
||||
*/
|
||||
public EntityManager getEntityManager() {
|
||||
return null;
|
||||
//return entityManager;
|
||||
}
|
||||
|
||||
public boolean hasEntityManagerTransaction() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class HackVascParser extends VascParser {
|
||||
|
||||
public HackVascParser(VascController c) throws Exception {
|
||||
super(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X4OPhaseHandler getConfigOptionalPhase() {
|
||||
final X4OPhaseHandler resultSuper = super.getConfigOptionalPhase();
|
||||
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
|
||||
protected void setX4OPhase() {
|
||||
phase = X4OPhase.configOptionalPhase;
|
||||
}
|
||||
@Override
|
||||
public boolean isElementPhase() {
|
||||
return false;
|
||||
}
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
public void runPhase(ElementContext elementContext) throws X4OPhaseException {
|
||||
resultSuper.runPhase(elementContext); // this is needed !!
|
||||
ValueExpression e1 = getElementContext().getExpressionFactory().createValueExpression(getElementContext().getELContext(),"${entityManagerProvider}", EntityManagerProvider.class);
|
||||
e1.setValue(getElementContext().getELContext(), new DatafeedsEntityManagerProvider());
|
||||
|
||||
ValueExpression e2 = getElementContext().getExpressionFactory().createValueExpression(getElementContext().getELContext(),"${xpqlController}", XpqlController.class);
|
||||
e2.setValue(getElementContext().getELContext(), new XpqlController());
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private VascController getParsedVascController() {
|
||||
try {
|
||||
// get local jvm plugging controller
|
||||
VascController c = DefaultVascFactory.getDefaultVascController(22l, "test", "login");
|
||||
|
||||
// TODO made reuse working.
|
||||
new HackVascParser(c).parseResource("com/idcanet/logstats/resources/vasc/logstats.xml");
|
||||
//new HackVascParser(c).parseResource("com/idcanet/logstats/resources/vasc/flowuser.xml");
|
||||
|
||||
|
||||
// fill stuff in all global entry'ies
|
||||
for (String id:c.getVascEntryController().getVascEntryIds()) {
|
||||
VascEntry entry = ((DefaultVascEntryController)c.getVascEntryController()).getRealVascEntryById(id);
|
||||
if (entry.isVascDisplayOnly()==false) {
|
||||
if (entry.isVascAdminCreate()) {
|
||||
entry.addRowAction(new AddRowAction());
|
||||
}
|
||||
if (entry.isVascAdminEdit()) {
|
||||
entry.addRowAction(new EditRowAction());
|
||||
}
|
||||
if (entry.isVascAdminDelete()) {
|
||||
entry.addRowAction(new DeleteRowAction());
|
||||
}
|
||||
}
|
||||
entry.addGlobalAction(new XMLExportGlobalAction());
|
||||
entry.addGlobalAction(new CSVExportGlobalAction());
|
||||
//entry.addGlobalAction(new RefreshDataGlobalAction());
|
||||
|
||||
Locale locale = null;
|
||||
// auto fix generic edit/del/create descriptiong if i18n key does not excits.
|
||||
locale = Locale.getDefault();
|
||||
DefaultVascEntryResourceResolver t = new DefaultVascEntryResourceResolver();
|
||||
// TODO: new DefaultVascEntryResourceResolver("com/mbuyu/m4n/resources/datafeeds/i18n/DatafeedsBundle",locale);
|
||||
|
||||
if (t.getTextValue(entry.getEditDescription()).equals(entry.getEditDescription())) {
|
||||
entry.setEditDescription("generic.editDescription");
|
||||
}
|
||||
if (t.getTextValue(entry.getDeleteDescription()).equals(entry.getDeleteDescription())) {
|
||||
entry.setDeleteDescription("generic.deleteDescription");
|
||||
}
|
||||
if (t.getTextValue(entry.getCreateDescription()).equals(entry.getCreateDescription())) {
|
||||
entry.setCreateDescription("generic.createDescription");
|
||||
}
|
||||
|
||||
// add global listener to make sure we have all LAZY properties of a bean before we goto edit mode.
|
||||
//entry.addVascEntryEventListener(VascEventType.DATA_SELECT, new RefreshObjectForLazyPropertiesListener());
|
||||
|
||||
// hackje om deze manuale actions van i18n keys te voorzien;
|
||||
// this is temp untill x4o templaing
|
||||
DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer();
|
||||
f.finalizeVascEntry(entry, c);
|
||||
}
|
||||
|
||||
logger.info("VASC COMPLEET LETS RETURN.");
|
||||
|
||||
// finally set the controller for storage in this (session) bean.
|
||||
return c;
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
|
||||
package com.idcanet.vasc.ejb3;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Remote;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 13 Aug 2007
|
||||
*/
|
||||
@Remote
|
||||
public interface VascServiceManagerRemote {
|
||||
|
||||
public Map<String,String> getResourceBundle(String locale);
|
||||
|
||||
public List<String> getVascEntryIds();
|
||||
|
||||
public VascEntry getVascEntry(String entryId);
|
||||
|
||||
public Object invokeBackendMethod(String backendId,String method,Object[] args);
|
||||
}
|
Loading…
Reference in a new issue