Compare Revisions

The credentials to download the source code are:
 Username: svnusers
 Password: svnusers

Ignore whitespace Rev 2755 → Rev 2756

/branches/AMB/AdapterFramework/javasrc/extfunc/org/etsi/extfunc/core/ExternalFunction.java
0,0 → 1,54
package org.etsi.extfunc.core;
 
 
 
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
 
import org.etsi.common.plugins.IXfPlugin;
import org.etsi.ttcn.tri.TriFunctionId;
import org.etsi.ttcn.tri.TriParameter;
import org.etsi.ttcn.tri.TriParameterList;
 
public abstract class ExternalFunction implements IXfPlugin, InvocationHandler {
 
@Override
public void initPlugin() {
XfFactory.getInstance().registerXf(this.getPluginName(), this.getClass());
}
 
public abstract void unpack(TriFunctionId functionId, TriParameterList parameterList, TriParameter returnValue);
public Object getProxy(Class<?> iface) {
Class<?>[] xf_ifaces = this.getClass().getInterfaces();
Class<?>[] ifaces = new Class[xf_ifaces.length + 1];
for(int i=0; i < xf_ifaces.length; i++) {
ifaces[i] = xf_ifaces[i];
}
ifaces[ifaces.length -1] = iface;
Object instance = Proxy.newProxyInstance(
this.getClass().getClassLoader(),
ifaces,
this
);
 
return instance;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.err.println("Calling: " + method.getName());
Class<?>[] params = null;
if(args != null) {
params = new Class<?>[args.length];
for(int i=0; i < args.length; i++) {
params[i] = args[i].getClass();
}
}
Method m = this.getClass().getMethod(method.getName(), params);
return m.invoke(this, args);
}
 
}
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+URL Id
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: AdapterFramework/javasrc/extfunc/org/etsi/extfunc/core/XfFactory.java
===================================================================
--- AdapterFramework/javasrc/extfunc/org/etsi/extfunc/core/XfFactory.java (nonexistent)
+++ AdapterFramework/javasrc/extfunc/org/etsi/extfunc/core/XfFactory.java (revision 2756)
@@ -0,0 +1,83 @@
+/**
+ * Protocol port factory (Singleton)
+ *
+ * @author ETSI / STF424
+ * @version $URL$
+ * $Id$
+ *
+ */
+package org.etsi.extfunc.core;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.etsi.common.plugins.IXfPlugin;
+import org.etsi.common.plugins.PluginLoader;
+
+/**
+ * Protocol port factory (Singleton)
+ */
+public class XfFactory {
+
+ private static boolean initialized = false;
+
+ /**
+ * Unique instance of the factory
+ */
+ private static XfFactory instance = new XfFactory();
+
+ /**
+ * List of the registered protocol port types
+ */
+ protected Map<String, Class<? extends ExternalFunction>> xfs = new TreeMap<String, Class<? extends ExternalFunction>>();
+
+ /**
+ * Private constructor (Singleton pattern)
+ */
+ private XfFactory() {
+ // empty
+ }
+
+ /**
+ * Gets the unique factory instance
+ * @return ProtocolPortFactory instance
+ */
+ public static XfFactory getInstance() {
+
+ instance.initialize();
+ return instance;
+ }
+
+ public void initialize() {
+
+ if(!initialized) {
+ initialized = true;
+
+ PluginLoader pl = new PluginLoader(IXfPlugin.class, "org.etsi.extfunc");
+ pl.load(new String[] {"./lib", "./plugins", "./build"});
+ }
+ }
+
+ public ExternalFunction getXf(String xfName) {
+ // FIXME: temporary
+ Class<? extends ExternalFunction> cls = xfs.entrySet().iterator().next().getValue();;
+ Class<?>[] ctorParams1 = {};
+
+ try {
+ Constructor<? extends ExternalFunction> ctor = cls.getConstructor(ctorParams1);
+ return ctor.newInstance();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public void registerXf(String xfName, Class<? extends ExternalFunction> portClass) {
+ System.err.println("Registering XF: " + xfName);
+ xfs.put(xfName, portClass);
+ }
+}
+
\ No newline at end of file
/AdapterFramework/javasrc/extfunc/org/etsi/extfunc/core/XfFactory.java
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+URL Id
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: AdapterFramework/javasrc/extfunc/org/etsi/extfunc/its/ItsExternalFunctionsProvider.java
===================================================================
--- AdapterFramework/javasrc/extfunc/org/etsi/extfunc/its/ItsExternalFunctionsProvider.java (revision 2755)
+++ AdapterFramework/javasrc/extfunc/org/etsi/extfunc/its/ItsExternalFunctionsProvider.java (revision 2756)
@@ -20,6 +20,7 @@
import org.etsi.ttcn.codec.core.ITciCDWrapper;
import org.etsi.ttcn.codec.core.TciCDWrapperFactory;
import org.etsi.common.ByteHelper;
+import org.etsi.extfunc.core.ExternalFunction;
import org.etsi.helpers.geodesic.DMS;
import org.etsi.helpers.geodesic.Positioning;
import org.etsi.helpers.geodesic.WGS84;
@@ -33,6 +34,9 @@
import org.etsi.ttcn.tci.OctetstringValue;
import org.etsi.ttcn.tci.RecordOfValue;
import org.etsi.ttcn.tci.RecordValue;
+import org.etsi.ttcn.tri.TriFunctionId;
+import org.etsi.ttcn.tri.TriParameter;
+import org.etsi.ttcn.tri.TriParameterList;
import de.fraunhofer.sit.c2x.CryptoLib;
import de.fraunhofer.sit.c2x.EcdsaP256KeyPair;
@@ -43,12 +47,12 @@
* See TTCN-3 modules LibItsGeoNetworking_Functions and LibItsCommon_Functions
*
*/
-public class ItsExternalFunctionsProvider {
+public class ItsExternalFunctionsProvider extends ExternalFunction implements IItsExternalFunctionsProvider {
- /**
- * Module version
- */
- public static final String Version = "1.0.0.0";
+ @Override
+ public String getPluginName() {
+ return "ITS";
+ }
/**
* Unique instance of TciCDWrapper class
@@ -90,6 +94,32 @@
}
}
+ @Override
+ public void unpack(TriFunctionId functionId, TriParameterList parameterList, TriParameter returnValue) {
+
+ functionId.getFunctionName();
+
+ Class<?>[] params = new Class<?>[parameterList.size()];
+ for(int i=0; i < parameterList.size(); i++) {
+ try {
+ params[i] = Class.forName(parameterList.get(i).getParameterName());
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ try {
+ this.getClass().getMethod(functionId.getFunctionName(), params);
+ } catch (NoSuchMethodException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
/**
* This external function gets the current time
*