2
0
Fork 0

renamed vasc-ejb3 to vasc-core-ejb3 and started with i18n lib

This commit is contained in:
Willem Cazander 2012-05-07 16:44:19 +02:00
parent beb57fe92e
commit fe5842768f
14 changed files with 77 additions and 8 deletions

41
vasc-core-ejb3/.project Normal file
View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-core-ejb3</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builders</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

43
vasc-core-ejb3/pom.xml Normal file
View file

@ -0,0 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc</artifactId>
<groupId>net.forwardfire.vasc</groupId>
<version>0.3.5-SNAPSHOT</version>
</parent>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core-ejb3</artifactId>
<version>0.3.5-SNAPSHOT</version>
<name>vasc-core-ejb3</name>
<description>vasc-core-ejb3</description>
<dependencies>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-backend-jpa</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-xpql-ejb3</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,56 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * 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 THE COPYRIGHT HOLDERS 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
* THE COPYRIGHT HOLDER 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.
*/
package net.forwardfire.vasc.ejb3;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.ejb.Remote;
import net.forwardfire.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 {
}
}

View file

@ -0,0 +1,313 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * 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 THE COPYRIGHT HOLDERS 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
* THE COPYRIGHT HOLDER 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.
*/
package net.forwardfire.vasc.ejb3;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
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.naming.InitialContext;
import javax.persistence.EntityManager;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backends.jpa.EntityManagerProvider;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryControllerLocal;
import net.forwardfire.vasc.impl.DefaultVascFactory;
import net.forwardfire.vasc.impl.x4o.VascParser;
import net.forwardfire.vasc.xpql.ejb3.XpqlQueryManager;
import net.forwardfire.vasc.xpql.query.Query;
/**
*
* @author Willem Cazander
* @version 1.0 13 Aug 2007
*/
@Stateless(name="ejb/vascServiceManager")
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 {
Map<String,String> keys = loadKeys();
for (String key:keys.keySet()) {
String value = keys.get(key);
if ("persistenceUnit".equals(key)) {
logger.fine("getting EntityManager: "+value);
entityManager = (EntityManager)new InitialContext().lookup(value);
}
if ("xpqlController".equals(key)) {
logger.fine("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");
}
long s = System.currentTimeMillis();
// get local jvm plugging controller
VascController c = DefaultVascFactory.getDefaultVascController(0l, "nobody", "NO_ROLE");
for (String key:keys.keySet()) {
String value = keys.get(key);
if (key.startsWith("load")) {
// TODO made reuse working.
VascParser vp = new VascParser(c);
vp.addGlobalELBean("xpqlController", new XpqlController());
vp.addGlobalELBean("entityManagerProvider", new LocalEntityManagerProvider());
vp.parseResource(value);
}
}
DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) c.getVascEntryController(), 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();
if (v==null) {
return new ArrayList<String>(0);
}
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 LocalEntityManagerProvider implements EntityManagerProvider {
/**
* @see net.forwardfire.vasc.backends.jpa.EntityManagerProvider#getEntityManager()
*/
public EntityManager getEntityManager() {
return entityManager;
}
public boolean hasEntityManagerTransaction() {
return false;
}
};
}

View file

View file

View file