basic slit in multi module project
This commit is contained in:
parent
f79378dacb
commit
d6d77072d9
198 changed files with 25404 additions and 0 deletions
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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.ejb3;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.ejb.Remote;
|
||||
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 17 Sep 2010
|
||||
*/
|
||||
public interface VascServiceManager {
|
||||
|
||||
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);
|
||||
|
||||
@Local
|
||||
public interface ILocal extends VascServiceManager {
|
||||
}
|
||||
|
||||
@Remote
|
||||
public interface IRemote extends VascServiceManager {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,402 @@
|
|||
/*
|
||||
* 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.ejb3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.el.ValueExpression;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
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.ejb3.XpqlQueryManager;
|
||||
import com.idcanet.xtes.xpql.query.Query;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 13 Aug 2007
|
||||
*/
|
||||
@Stateless(name="ejb/vascSericeManager")
|
||||
public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascServiceManager.ILocal {
|
||||
|
||||
private Logger logger = Logger.getLogger(VascServiceManagerImpl.class.getName());
|
||||
|
||||
protected EntityManager entityManager;
|
||||
|
||||
protected XpqlQueryManager xpqlController = null;
|
||||
|
||||
protected VascController sharedVascController = null;
|
||||
|
||||
protected ResourceBundle resourceBundle = null;
|
||||
|
||||
@PostConstruct
|
||||
public void loadAll() {
|
||||
logger.fine("VascServiceManager created now loading resources...");
|
||||
try {
|
||||
long s = System.currentTimeMillis();
|
||||
|
||||
Map<String,String> keys = loadKeys();
|
||||
for (String key:keys.keySet()) {
|
||||
String value = keys.get(key);
|
||||
if ("persistenceUnit".equals(key)) {
|
||||
logger.info("getting EntityManager: "+value);
|
||||
entityManager = (EntityManager)new InitialContext().lookup(value);
|
||||
}
|
||||
if ("xpqlController".equals(key)) {
|
||||
logger.info("getting XpqlQueryManagerLocal: "+value);
|
||||
xpqlController = (XpqlQueryManager)new InitialContext().lookup(value);
|
||||
}
|
||||
if ("i18nBundle".equals(key)) {
|
||||
resourceBundle = ResourceBundle.getBundle(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (entityManager==null) {
|
||||
new NullPointerException("Have no entityManager");
|
||||
}
|
||||
if (xpqlController==null) {
|
||||
new NullPointerException("Have no xpqlController");
|
||||
}
|
||||
if (resourceBundle==null) {
|
||||
new NullPointerException("Have no resourceBundle");
|
||||
}
|
||||
|
||||
// get local jvm plugging controller
|
||||
VascController c = DefaultVascFactory.getDefaultVascController(22l, "test", "login");
|
||||
|
||||
for (String key:keys.keySet()) {
|
||||
String value = keys.get(key);
|
||||
if (key.startsWith("load")) {
|
||||
// TODO made reuse working.
|
||||
new HackVascParser(c).parseResource(value);
|
||||
}
|
||||
}
|
||||
finalVascController(c);
|
||||
|
||||
sharedVascController = c;
|
||||
|
||||
long t = System.currentTimeMillis()-s;
|
||||
logger.info("Total loaded vasc entries: "+c.getVascEntryController().getVascEntryIds().size()+" in "+t+" ms.");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error while init resources error: "+e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads xtes-xpql-ejb3.xml from meta-inf and gives the keys
|
||||
*/
|
||||
protected Map<String,String> loadKeys() throws IOException {
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
||||
logger.fine("Getting urls");
|
||||
Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources("META-INF/vasc-ejb3.xml");
|
||||
while(e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logger.finer("Loading reletive namespaces of: "+u+" for: META-INF/vasc-ejb3.xml");
|
||||
InputStream in = u.openStream();
|
||||
try {
|
||||
properties.loadFromXML(in);
|
||||
} finally {
|
||||
if (in!=null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
e = Thread.currentThread().getContextClassLoader().getResources("/META-INF/vasc-ejb3.xml");
|
||||
while(e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logger.finer("Loading root namespaces of: "+u+" for: /META-INF/vasc-ejb3.xml");
|
||||
InputStream in = u.openStream();
|
||||
try {
|
||||
properties.loadFromXML(in);
|
||||
} finally {
|
||||
if (in!=null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.fine("done loading");
|
||||
|
||||
Map<String,String> result = new HashMap<String,String>(20);
|
||||
for (Object key:properties.keySet()) {
|
||||
if (key instanceof String) {
|
||||
String key2 = (String) key;
|
||||
String value = properties.getProperty(key2);
|
||||
result.put(key2, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public Map<String,String> getResourceBundle(String locale) {
|
||||
Map<String,String> result = new HashMap<String,String>(resourceBundle.keySet().size());
|
||||
for (String key:resourceBundle.keySet()) {
|
||||
String value = resourceBundle.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() {
|
||||
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 xpqlController.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 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 void finalVascController(VascController c) {
|
||||
try {
|
||||
// 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());
|
||||
|
||||
DefaultVascEntryResourceResolver t = new DefaultVascEntryResourceResolver(resourceBundle);
|
||||
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.");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue