From 7e1d63dd9fd149e4934bf77095c8610fac786b04 Mon Sep 17 00:00:00 2001 From: Henri Herscher Date: Thu, 20 Oct 2005 13:40:58 +0000 Subject: First checkin git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@2 09dcff7a-b715-0410-9601-b79a96267cd0 --- orkbasej/.classpath | 11 + orkbasej/.project | 17 + orkbasej/build.xml | 58 +++ orkbasej/java/hsqldb.hbm.template.xml | 17 + orkbasej/java/log4j.template.properties | 40 ++ orkbasej/java/mysql.hbm.template.xml | 35 ++ orkbasej/java/net/sf/oreka/Cycle.java | 16 + orkbasej/java/net/sf/oreka/Direction.java | 16 + orkbasej/java/net/sf/oreka/HibernateManager.java | 67 +++ orkbasej/java/net/sf/oreka/OrkException.java | 22 + orkbasej/java/net/sf/oreka/OrkObject.java | 23 + orkbasej/java/net/sf/oreka/OrkObjectFactory.java | 66 +++ orkbasej/java/net/sf/oreka/OrkTest.java | 123 +++++ orkbasej/java/net/sf/oreka/ServiceClass.java | 16 + .../java/net/sf/oreka/messages/AsyncMessage.java | 18 + orkbasej/java/net/sf/oreka/messages/Message.java | 19 + .../sf/oreka/messages/SimpleResponseMessage.java | 56 +++ .../java/net/sf/oreka/messages/SyncMessage.java | 19 + .../net/sf/oreka/messages/test/TestMessage.java | 97 ++++ .../sf/oreka/messages/test/TestNestedMessage.java | 108 +++++ .../net/sf/oreka/messages/test/TestSubMessage.java | 57 +++ .../sf/oreka/persistent/AnnotatedTestClass.java | 59 +++ .../net/sf/oreka/persistent/AnnotationsTest.java | 316 +++++++++++++ orkbasej/java/net/sf/oreka/persistent/Domain.java | 91 ++++ .../java/net/sf/oreka/persistent/HbnXmlTest.java | 195 ++++++++ .../net/sf/oreka/persistent/HbnXmlTestClass.java | 62 +++ .../java/net/sf/oreka/persistent/LoginString.java | 114 +++++ orkbasej/java/net/sf/oreka/persistent/RecPort.java | 33 ++ .../java/net/sf/oreka/persistent/RecPortFace.java | 49 ++ .../java/net/sf/oreka/persistent/RecProgram.java | 516 +++++++++++++++++++++ .../java/net/sf/oreka/persistent/RecSegment.java | 321 +++++++++++++ .../java/net/sf/oreka/persistent/RecSession.java | 79 ++++ orkbasej/java/net/sf/oreka/persistent/RecTape.java | 249 ++++++++++ orkbasej/java/net/sf/oreka/persistent/Service.java | 172 +++++++ orkbasej/java/net/sf/oreka/persistent/User.java | 133 ++++++ .../net/sf/oreka/serializers/DomSerializer.java | 186 ++++++++ .../sf/oreka/serializers/KeyValueSerializer.java | 47 ++ .../net/sf/oreka/serializers/OrkSerializer.java | 239 ++++++++++ .../serializers/ServletRequestSerializer.java | 79 ++++ .../sf/oreka/serializers/SingleLineSerializer.java | 231 +++++++++ .../oreka/serializers/test/DomSerializerTest.java | 82 ++++ .../serializers/test/NullHttpServletRequest.java | 163 +++++++ .../test/ServletRequestSerializerTest.java | 45 ++ .../serializers/test/SingleLineSerializerTest.java | 172 +++++++ .../oreka/serializers/test/TestMessageSimple.xml | 5 + .../oreka/serializers/test/TestNestedMessage.xml | 6 + orkbasej/java/net/sf/oreka/test/FillDatabase.java | 118 +++++ 47 files changed, 4663 insertions(+) create mode 100644 orkbasej/.classpath create mode 100644 orkbasej/.project create mode 100644 orkbasej/build.xml create mode 100644 orkbasej/java/hsqldb.hbm.template.xml create mode 100644 orkbasej/java/log4j.template.properties create mode 100644 orkbasej/java/mysql.hbm.template.xml create mode 100644 orkbasej/java/net/sf/oreka/Cycle.java create mode 100644 orkbasej/java/net/sf/oreka/Direction.java create mode 100644 orkbasej/java/net/sf/oreka/HibernateManager.java create mode 100644 orkbasej/java/net/sf/oreka/OrkException.java create mode 100644 orkbasej/java/net/sf/oreka/OrkObject.java create mode 100644 orkbasej/java/net/sf/oreka/OrkObjectFactory.java create mode 100644 orkbasej/java/net/sf/oreka/OrkTest.java create mode 100644 orkbasej/java/net/sf/oreka/ServiceClass.java create mode 100644 orkbasej/java/net/sf/oreka/messages/AsyncMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/Message.java create mode 100644 orkbasej/java/net/sf/oreka/messages/SimpleResponseMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/SyncMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/test/TestMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/test/TestNestedMessage.java create mode 100644 orkbasej/java/net/sf/oreka/messages/test/TestSubMessage.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/AnnotatedTestClass.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/AnnotationsTest.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/Domain.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/HbnXmlTest.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/HbnXmlTestClass.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/LoginString.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecPort.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecPortFace.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecProgram.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecSegment.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecSession.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/RecTape.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/Service.java create mode 100644 orkbasej/java/net/sf/oreka/persistent/User.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/DomSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/KeyValueSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/OrkSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/ServletRequestSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/SingleLineSerializer.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/DomSerializerTest.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/NullHttpServletRequest.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/ServletRequestSerializerTest.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/SingleLineSerializerTest.java create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/TestMessageSimple.xml create mode 100644 orkbasej/java/net/sf/oreka/serializers/test/TestNestedMessage.xml create mode 100644 orkbasej/java/net/sf/oreka/test/FillDatabase.java (limited to 'orkbasej') diff --git a/orkbasej/.classpath b/orkbasej/.classpath new file mode 100644 index 0000000..2c1efe8 --- /dev/null +++ b/orkbasej/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/orkbasej/.project b/orkbasej/.project new file mode 100644 index 0000000..41bc85d --- /dev/null +++ b/orkbasej/.project @@ -0,0 +1,17 @@ + + + orkbasej + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/orkbasej/build.xml b/orkbasej/build.xml new file mode 100644 index 0000000..8dfad7f --- /dev/null +++ b/orkbasej/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +---------------------------------------------------+ + | | + | R U N N I N G H I B E R N A T E D O C L E T | + | | + +---------------------------------------------------+ + + + + + + + + + + + \ No newline at end of file diff --git a/orkbasej/java/hsqldb.hbm.template.xml b/orkbasej/java/hsqldb.hbm.template.xml new file mode 100644 index 0000000..c3c6f12 --- /dev/null +++ b/orkbasej/java/hsqldb.hbm.template.xml @@ -0,0 +1,17 @@ + + + + + true + create-drop + org.hibernate.cache.HashtableCacheProvider + true + org.hibernate.dialect.HSQLDialect + jdbc:hsqldb:mem:test + + sa + org.hsqldb.jdbcDriver + + diff --git a/orkbasej/java/log4j.template.properties b/orkbasej/java/log4j.template.properties new file mode 100644 index 0000000..af9e970 --- /dev/null +++ b/orkbasej/java/log4j.template.properties @@ -0,0 +1,40 @@ +### stdout ### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +### logfile ### +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.File=c:\oreka\oreka.log +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +# HUB is a socket hub appender +#log4j.appender.HUB=org.apache.log4j.net.SocketHubAppender +#log4j.appender.HUB.layout=org.apache.log4j.PatternLayout +#log4j.appender.HUB.layout.ConversionPattern=[cc]%d{MMM-dd HH:mm:ss} %-14.14c{1}- %m%n +#log4j.appender.HUB.port=9000 + +log4j.rootLogger=info, file, stdout + +################# +### Hibernate logging +log4j.logger.org.hibernate=info +#log4j.logger.org.hibernate=debug +### log just the SQL +#log4j.logger.org.hibernate.SQL=debug +### log JDBC bind parameters ### +log4j.logger.org.hibernate.type=info +#log4j.logger.org.hibernate.type=debug +### log schema export/update ### +log4j.logger.org.hibernate.tool.hbm2ddl=info +### log HQL parse trees +#log4j.logger.org.hibernate.hql=debug +### log cache activity ### +#log4j.logger.org.hibernate.cache=debug +### log JDBC resource acquisition +#log4j.logger.org.hibernate.jdbc=debug +### enable the following line if you want to track down connection ### +### leakages when using DriverManagerConnectionProvider ### +#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace diff --git a/orkbasej/java/mysql.hbm.template.xml b/orkbasej/java/mysql.hbm.template.xml new file mode 100644 index 0000000..353f5cc --- /dev/null +++ b/orkbasej/java/mysql.hbm.template.xml @@ -0,0 +1,35 @@ + + + + + org.hibernate.dialect.MySQLMyISAMDialect + com.mysql.jdbc.Driver + jdbc:mysql://localhost/test + mypassword + root + 1 + + update + true + + + + + + + + + true + true 1, false 0, yes 'Y', no 'N' + hibernate.test + pool1 + 8 + true + 1 + org.hibernate.cache.HashtableCacheProvider + true + true + + diff --git a/orkbasej/java/net/sf/oreka/Cycle.java b/orkbasej/java/net/sf/oreka/Cycle.java new file mode 100644 index 0000000..1d48893 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/Cycle.java @@ -0,0 +1,16 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +public enum Cycle {permanent, hourly, daily, weekly, monthly, unknown} diff --git a/orkbasej/java/net/sf/oreka/Direction.java b/orkbasej/java/net/sf/oreka/Direction.java new file mode 100644 index 0000000..4a828af --- /dev/null +++ b/orkbasej/java/net/sf/oreka/Direction.java @@ -0,0 +1,16 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +public enum Direction {IN, OUT, ALL, UNKN} diff --git a/orkbasej/java/net/sf/oreka/HibernateManager.java b/orkbasej/java/net/sf/oreka/HibernateManager.java new file mode 100644 index 0000000..806f5ba --- /dev/null +++ b/orkbasej/java/net/sf/oreka/HibernateManager.java @@ -0,0 +1,67 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka; + +import java.io.File; + +import net.sf.oreka.persistent.Domain; +import net.sf.oreka.persistent.LoginString; +import net.sf.oreka.persistent.RecPort; +import net.sf.oreka.persistent.RecPortFace; +import net.sf.oreka.persistent.RecProgram; +import net.sf.oreka.persistent.RecSegment; +import net.sf.oreka.persistent.RecSession; +import net.sf.oreka.persistent.RecTape; +import net.sf.oreka.persistent.Service; +import net.sf.oreka.persistent.User; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AnnotationConfiguration; + + +public class HibernateManager { + + private static SessionFactory sessionFactory = null; + + public static void configure(String filename) throws Exception { + + File configFile = new File(filename); + + AnnotationConfiguration config = new AnnotationConfiguration(); + config.configure(configFile); + + config.addAnnotatedClass(RecProgram.class); + config.addAnnotatedClass(RecSession.class); + config.addAnnotatedClass(RecSegment.class); + config.addAnnotatedClass(RecTape.class); + config.addAnnotatedClass(User.class); + config.addAnnotatedClass(LoginString.class); + config.addAnnotatedClass(Domain.class); + config.addAnnotatedClass(Service.class); + config.addAnnotatedClass(RecPort.class); + config.addAnnotatedClass(RecPortFace.class); + sessionFactory = config.buildSessionFactory(); + } + + public static Session getSession() throws Exception { + if (sessionFactory == null) { + throw new OrkException("HibernateManager.getSession: application must configure hibernate before using it."); + } + return sessionFactory.openSession(); + } +} diff --git a/orkbasej/java/net/sf/oreka/OrkException.java b/orkbasej/java/net/sf/oreka/OrkException.java new file mode 100644 index 0000000..9ec3076 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/OrkException.java @@ -0,0 +1,22 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +public class OrkException extends Exception { + + public OrkException(String message) + { + super(message); + } +} diff --git a/orkbasej/java/net/sf/oreka/OrkObject.java b/orkbasej/java/net/sf/oreka/OrkObject.java new file mode 100644 index 0000000..5469001 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/OrkObject.java @@ -0,0 +1,23 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +import net.sf.oreka.serializers.*; + +public interface OrkObject { + + public String getOrkClassName(); + public void define(OrkSerializer serializer) throws OrkException; + public void validate(); +} diff --git a/orkbasej/java/net/sf/oreka/OrkObjectFactory.java b/orkbasej/java/net/sf/oreka/OrkObjectFactory.java new file mode 100644 index 0000000..79c2734 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/OrkObjectFactory.java @@ -0,0 +1,66 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; +/** + * The ObjectFactory can be used to instanciate Objects based on class name. + * All existing Objects must be registered to the ObjectFactory at startup. + */ +public class OrkObjectFactory { + + static OrkObjectFactory instance = null; + java.util.HashMap classes; + + private OrkObjectFactory() + { + classes = new java.util.HashMap(); + } + + public static OrkObjectFactory instance() + { + if(instance == null) + { + instance = new OrkObjectFactory(); + } + return instance; + } + + public OrkObject newOrkObject(String className) throws OrkException + { + className = className.toLowerCase(); + OrkObject classObject = classes.get(className); + OrkObject newInstance = null; + if(classObject != null) + { + try + { + newInstance = classObject.getClass().newInstance(); + } + catch (Exception e) + { + throw new OrkException("OrkObjectFactory: Could not instanciate:" + className); + } + } + else + { + throw new OrkException("OrkObjectFactory: class does not exist:" + className); + } + return newInstance; + } + + public void registerOrkObject(OrkObject object) + { + classes.put(object.getOrkClassName(), object); + } + +} diff --git a/orkbasej/java/net/sf/oreka/OrkTest.java b/orkbasej/java/net/sf/oreka/OrkTest.java new file mode 100644 index 0000000..c08ec1e --- /dev/null +++ b/orkbasej/java/net/sf/oreka/OrkTest.java @@ -0,0 +1,123 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import net.sf.oreka.messages.test.TestMessage; +import net.sf.oreka.messages.test.TestNestedMessage; +import net.sf.oreka.messages.test.TestSubMessage; +import net.sf.oreka.serializers.DomSerializer; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class OrkTest { + + enum MyEnum {one, two, three}; + enum MyEnum2 {four, five, six}; + + + + + public static void main(String args[]) throws Exception + { + /* Enums + MyEnum toto = MyEnum.three; + MyEnum2 titi = MyEnum2.six; + + Enum grrrr = toto; + System.out.printf("%s", grrrr.name()); + grrrr = titi; + System.out.printf("%s", grrrr.name()); + + Class aClass = titi.getClass(); + grrrr = Enum.valueOf(aClass, "five"); + + System.out.printf("%s", grrrr.name()); + */ + /* Reflection + Class myClass = Class.forName("java.lang.String"); + Object myObj = myClass.newInstance(); + String boum = (String)myObj; + */ + /* + TestMessage msg = new TestMessage(); + SingleLineSerializer ser = new SingleLineSerializer(); + String serialized = ser.serialize(msg); + System.out.println(serialized); + */ + /* + Class toto = null; + toto = TestMessage.class; + + System.out.println(toto.toString()); + + java.util.ArrayList al = new java.util.ArrayList(); + al.add(toto); + + java.util.HashMap hm = new java.util.HashMap(); + hm.put(toto, toto); + */ + +// TestMessage toto = new TestMessage(); +// +// OrkObjectFactory.instance().RegisterOrkObject(toto); +// OrkObject obj = OrkObjectFactory.instance().newOrkObject("test"); +// +// TestMessage msg = (TestMessage)obj; +// msg.setIntParm(5); +// msg.setStringParm("henri"); +// +// SingleLineSerializer ser = new SingleLineSerializer(); +// ser.setClassKey("message"); +// String serialized = ser.serialize(msg); +// System.out.println(serialized); +// +// OrkObject obj2 = ser.deSerialize(serialized); +// String str = ser.serialize(obj2); +// System.out.println(str); + + OrkObjectFactory.instance().registerOrkObject(new TestMessage()); +// InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream ("net/sf/oreka/TestMessage.xml"); +// +// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); +// DocumentBuilder builder = factory.newDocumentBuilder(); +// //Document doc = builder.parse("c:/toto.xml"); +// Document doc = builder.parse(is); +// +// DomSerializer ser = new DomSerializer(); +// OrkObject obj = ser.deSerialize(doc.getFirstChild()); + + TestMessage msg = new TestMessage(); + DomSerializer ser = new DomSerializer(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.newDocument(); + + Element el = doc.createElement("nob"); + doc.appendChild(el); + +// System.out.println(DomSerializer.NodeToString(doc)); + + ser.serialize(doc, el, msg); + System.out.println(DomSerializer.NodeToString(doc)); + + TestNestedMessage tnm = new TestNestedMessage(); + TestSubMessage tsm = tnm.getSubMsg(); + + + } +} diff --git a/orkbasej/java/net/sf/oreka/ServiceClass.java b/orkbasej/java/net/sf/oreka/ServiceClass.java new file mode 100644 index 0000000..6e8abde --- /dev/null +++ b/orkbasej/java/net/sf/oreka/ServiceClass.java @@ -0,0 +1,16 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka; + +public enum ServiceClass {unkn, audio, cti} diff --git a/orkbasej/java/net/sf/oreka/messages/AsyncMessage.java b/orkbasej/java/net/sf/oreka/messages/AsyncMessage.java new file mode 100644 index 0000000..7cfa9f5 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/AsyncMessage.java @@ -0,0 +1,18 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages; + +public abstract class AsyncMessage extends Message { + +} diff --git a/orkbasej/java/net/sf/oreka/messages/Message.java b/orkbasej/java/net/sf/oreka/messages/Message.java new file mode 100644 index 0000000..72dfaad --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/Message.java @@ -0,0 +1,19 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages; + +import net.sf.oreka.*; + +public abstract class Message implements OrkObject { +} diff --git a/orkbasej/java/net/sf/oreka/messages/SimpleResponseMessage.java b/orkbasej/java/net/sf/oreka/messages/SimpleResponseMessage.java new file mode 100644 index 0000000..2da9131 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/SimpleResponseMessage.java @@ -0,0 +1,56 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages; + +import net.sf.oreka.OrkException; +import net.sf.oreka.serializers.OrkSerializer; + +public class SimpleResponseMessage extends AsyncMessage { + + boolean success = false; + String comment = ""; + + public void define(OrkSerializer serializer) throws OrkException { + + success = serializer.booleanValue("success", success, true); + comment = serializer.stringValue("comment", comment, false); + } + + public String getOrkClassName() { + + return "simpleresponse"; + } + + public void validate() { + // TODO Auto-generated method stub + + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + +} diff --git a/orkbasej/java/net/sf/oreka/messages/SyncMessage.java b/orkbasej/java/net/sf/oreka/messages/SyncMessage.java new file mode 100644 index 0000000..0aae393 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/SyncMessage.java @@ -0,0 +1,19 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages; + +public abstract class SyncMessage extends Message { + + public abstract AsyncMessage process(); +} diff --git a/orkbasej/java/net/sf/oreka/messages/test/TestMessage.java b/orkbasej/java/net/sf/oreka/messages/test/TestMessage.java new file mode 100644 index 0000000..6ac8fea --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/test/TestMessage.java @@ -0,0 +1,97 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages.test; + +import net.sf.oreka.*; +import net.sf.oreka.messages.AsyncMessage; +import net.sf.oreka.messages.SyncMessage; +import net.sf.oreka.serializers.*; + +public class TestMessage extends SyncMessage +{ + static final String orkObjectClass = "test"; + + public enum TestEnum {value1, value2, value3}; + + String stringParm = ""; + int intParm = 0; + double doubleParm = 0.0; + boolean boolParm = false; + TestEnum enumParm = TestEnum.value1; + + public String getOrkClassName() + { + return orkObjectClass; + } + + public void define(OrkSerializer serializer) throws OrkException + { + //serializer.stringValue("command", orkObjectClass, true); + intParm = serializer.intValue("intParm", intParm, true); + doubleParm = serializer.doubleValue("doubleParm", doubleParm, false); + stringParm = serializer.stringValue("stringParm", stringParm, false); + boolParm = serializer.booleanValue("boolParm", boolParm, false); + enumParm = (TestEnum)serializer.enumValue("enumParm", enumParm, false); + } + + public void validate() + { + ; + } + + public AsyncMessage process() + { + return null; + } + + public int getIntParm() { + return intParm; + } + + public void setIntParm(int intParm) { + this.intParm = intParm; + } + + public String getStringParm() { + return stringParm; + } + + public void setStringParm(String stringParm) { + this.stringParm = stringParm; + } + + public boolean isBoolParm() { + return boolParm; + } + + public void setBoolParm(boolean boolParm) { + this.boolParm = boolParm; + } + + public double getDoubleParm() { + return doubleParm; + } + + public void setDoubleParm(double doubleParm) { + this.doubleParm = doubleParm; + } + + public TestEnum getEnumParm() { + return enumParm; + } + + public void setEnumParm(TestEnum enumParm) { + this.enumParm = enumParm; + } +} diff --git a/orkbasej/java/net/sf/oreka/messages/test/TestNestedMessage.java b/orkbasej/java/net/sf/oreka/messages/test/TestNestedMessage.java new file mode 100644 index 0000000..c949652 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/test/TestNestedMessage.java @@ -0,0 +1,108 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages.test; + +import net.sf.oreka.*; +import net.sf.oreka.messages.AsyncMessage; +import net.sf.oreka.messages.SyncMessage; +import net.sf.oreka.serializers.*; + +public class TestNestedMessage extends SyncMessage +{ + static final String orkObjectClass = "testnested"; + + public enum TestEnum {value1, value2, value3}; + + String stringParm = ""; + int intParm = 0; + double doubleParm = 0.0; + boolean boolParm = false; + TestEnum enumParm = TestEnum.value1; + TestSubMessage subMsg = new TestSubMessage(); + + + public String getOrkClassName() + { + return orkObjectClass; + } + + public void define(OrkSerializer serializer) throws OrkException + { + //serializer.stringValue("command", orkObjectClass, true); + intParm = serializer.intValue("intParm", intParm, true); + doubleParm = serializer.doubleValue("doubleParm", doubleParm, false); + stringParm = serializer.stringValue("stringParm", stringParm, false); + boolParm = serializer.booleanValue("boolParm", boolParm, false); + enumParm = (TestEnum)serializer.enumValue("enumParm", enumParm, false); + subMsg = (TestSubMessage)serializer.objectValue("testsub", subMsg, false); + } + + public void validate() + { + ; + } + + public AsyncMessage process() + { + return null; + } + + public int getIntParm() { + return intParm; + } + + public void setIntParm(int intParm) { + this.intParm = intParm; + } + + public String getStringParm() { + return stringParm; + } + + public void setStringParm(String stringParm) { + this.stringParm = stringParm; + } + + public boolean isBoolParm() { + return boolParm; + } + + public void setBoolParm(boolean boolParm) { + this.boolParm = boolParm; + } + + public double getDoubleParm() { + return doubleParm; + } + + public void setDoubleParm(double doubleParm) { + this.doubleParm = doubleParm; + } + + public TestEnum getEnumParm() { + return enumParm; + } + + public void setEnumParm(TestEnum enumParm) { + this.enumParm = enumParm; + } + + public TestSubMessage getSubMsg() { + return subMsg; + } + + public void setSubMsg(TestSubMessage subMsg) { + this.subMsg = subMsg; + } +} \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/messages/test/TestSubMessage.java b/orkbasej/java/net/sf/oreka/messages/test/TestSubMessage.java new file mode 100644 index 0000000..919e995 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/messages/test/TestSubMessage.java @@ -0,0 +1,57 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.messages.test; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.serializers.OrkSerializer; + +public class TestSubMessage implements OrkObject { + + String stringSubParm = ""; + int intSubParm = 0; + + public void define(OrkSerializer serializer) throws OrkException { + + stringSubParm = serializer.stringValue("stringsubparm",stringSubParm,false); + intSubParm = serializer.intValue("intsubparm", intSubParm, false); + } + + public String getOrkClassName() { + + return "testsub"; + } + + public void validate() { + // TODO Auto-generated method stub + + } + + public int getIntSubParm() { + return intSubParm; + } + + public void setIntSubParm(int intSubParm) { + this.intSubParm = intSubParm; + } + + public String getStringSubParm() { + return stringSubParm; + } + + public void setStringSubParm(String stringSubParm) { + this.stringSubParm = stringSubParm; + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/AnnotatedTestClass.java b/orkbasej/java/net/sf/oreka/persistent/AnnotatedTestClass.java new file mode 100644 index 0000000..e75217a --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/AnnotatedTestClass.java @@ -0,0 +1,59 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + + +@Entity +public class AnnotatedTestClass { + + public enum TestEnum{value1, value2}; + + long Id; + TestEnum myEnum; + + String firstname; + String lastname; + public String getFirstname() { + return firstname; + } + public void setFirstname(String firstname) { + this.firstname = firstname; + } + @Id(generate=GeneratorType.AUTO) + public long getId() { + return Id; + } + public void setId(long id) { + Id = id; + } + public String getLastname() { + return lastname; + } + public void setLastname(String lastname) { + this.lastname = lastname; + } + + @Column(columnDefinition="varchar(255)") + public TestEnum getMyEnum() { + return myEnum; + } + public void setMyEnum(TestEnum myEnum) { + this.myEnum = myEnum; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/AnnotationsTest.java b/orkbasej/java/net/sf/oreka/persistent/AnnotationsTest.java new file mode 100644 index 0000000..6b15796 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/AnnotationsTest.java @@ -0,0 +1,316 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + + + +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Iterator; + +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.cfg.AnnotationConfiguration; +//import org.hibernate.tool.hbm2ddl.SchemaExport; +//import org.hibernate.ScrollableResults; + +public class AnnotationsTest { + + /** Creates a new instance of TestHibernate */ + public AnnotationsTest() { + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + +// Service srv1 = new Service(); +// srv1.setHostname("aoum"); +// +// srv1.setServiceClass(Service.ServiceClass.unkn); +// +// Method method = null; +// Object[] values = null; +// try { +// Class myClass = Service.ServiceClass.class; +// method = myClass.getDeclaredMethod( "values", new Class[0] ); +// values = (Object[]) method.invoke(null, new Object[0] ); +// } +// catch (Exception e) { +// int i = 0; +// } + +// if(true) {return;} + +// Date date = new Date(); +// long mili = date.getTime(); +// int sec = (int)(mili/1000); +// long mili2 = (long)sec*1000; +// Date date2 = new Date(mili2); + + AnnotationConfiguration config = (AnnotationConfiguration)new AnnotationConfiguration(); +// .setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect") +// .setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver") +// .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:test") +// .setProperty("hibernate.connection.username", "sa") +// .setProperty("hibernate.connection.password", "") +// .setProperty("hibernate.connection.pool_size", "1") +// .setProperty("hibernate.connection.autocommit", "true") +// .setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider") +// .setProperty("hibernate.hbm2ddl.auto", "create-drop") +// .setProperty("hibernate.show_sql", "true"); +// config.configure("mysql.hbm.xml"); + config.configure("hsqldb.hbm.xml"); + + config.addAnnotatedClass(AnnotatedTestClass.class); + config.addAnnotatedClass(RecProgram.class); + config.addAnnotatedClass(RecSession.class); + config.addAnnotatedClass(RecSegment.class); + config.addAnnotatedClass(RecTape.class); + config.addAnnotatedClass(User.class); + config.addAnnotatedClass(LoginString.class); + config.addAnnotatedClass(Domain.class); + config.addAnnotatedClass(Service.class); + config.addAnnotatedClass(RecPort.class); + config.addAnnotatedClass(RecPortFace.class); + + SessionFactory sessions = config.buildSessionFactory(); + Session session = sessions.openSession(); + + Transaction tx = null; + + try { + /* + SchemaExport export = new SchemaExport(config); + export.setOutputFile("c:\\schema.sql"); + export.create(true,false); + */ + + // single insert +// tx = session.beginTransaction(); +// AnnotatedTestClass obj = new AnnotatedTestClass(); +// obj.setMyEnum(TestEnum.value2); +// session.save(obj); +// tx.commit(); + + // insert +// for (int i=0; i<100 ; i++) +// { +// tx = session.beginTransaction(); +// Domain obj = new Domain(); +// session.save(obj); +// tx.commit(); +// } + + /* + // iterator select + Iterator documents = session.createQuery( + "from Documents doc join doc.car") + .list() + .iterator(); + + while ( documents.hasNext() ) { + Object[] row = (Object[]) documents.next(); + Documents doc = (Documents)row[0]; + Car car = (Car)row[1]; + + //Documents doc = (Documents)documents.next(); + + System.out.println(doc.getId() + " " + car.getId()); + } + */ + /* + // scrollable select + ScrollableResults scrollDocs = session.createQuery( + "from RecSegment intr join intr.RecSession").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecSegment doc = (RecSegment)scrollDocs.get(0); + RecSession car = (RecSession)scrollDocs.get(1); + System.out.println(doc.getId() + " " + car.getId()); + } + */ + + /* + // many to many insert + tx = session.beginTransaction(); + + RecProgram prog1 = new RecProgram(); + RecProgram prog2 = new RecProgram(); + RecSegment seg = new RecSegment(); + + HashSet programs = new HashSet(); + programs.add(prog1); + programs.add(prog2); + seg.setRecPrograms(programs); + + session.save(prog1); + session.save(prog2); + session.save(seg); + tx.commit(); + */ + /* + // Many to many select + ScrollableResults scrollDocs = session.createQuery( + "from RecSegment as seg join seg.recPrograms as prg where prg.id=2").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecSegment seg = (RecSegment)scrollDocs.get(0); + RecProgram prg = (RecProgram)scrollDocs.get(1); + System.out.println(seg.getId() + " " + prg.getId()); + } + */ + + /* + // one to many create + tx = session.beginTransaction(); + + RecProgram prog = new RecProgram(); + User user = new User(); + prog.setTargetUser(user); + + session.save(user); + session.save(prog); + tx.commit(); + */ + /* + // one to many select + ScrollableResults scrollDocs = session.createQuery( + "from RecProgram as prg join prg.targetUser as tgt").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecProgram prg = (RecProgram)scrollDocs.get(0); + User tgt = (User)scrollDocs.get(1); + System.out.println(prg.getId() + " " + tgt.getId()); + } + */ + + // multi-session stuff +// tx = session.beginTransaction(); +// RecTape obj = new RecTape(); +// Service srv = new Service(); +// obj.setService(srv); +// srv.setName("service1"); +// session.save(srv); +// session.save(obj); +// tx.commit(); +// session.close(); +// +// session = sessions.openSession(); +// tx = session.beginTransaction(); +// obj = new RecTape(); +// obj.setService(srv); +// session.save(obj); +// tx.commit(); +// session.close(); + +// tx = session.beginTransaction(); +// //Service.retrieveByName("toto", session); +// RecSegment seg = new RecSegment(); +// seg.setLoginString("too"); +// seg.setDuration(56); +// seg.setDirection(Direction.in); +// seg.setRemoteParty("135"); +// session.save(seg); +// +// java.util.List recSegments = session.createQuery( +// "from RecSegment as seg where seg.remoteParty = :rp") +// .setString("rp", "135") +// .list(); +// if (recSegments.size() > 0) { +// RecSegment result = (RecSegment)recSegments.get(0); +// System.out.println(result.getLoginString() + " " + result.getDirection().name()); +// } + + // enum stuff +// tx = session.beginTransaction(); +// //Service.retrieveByName("toto", session); +// Service srv = new Service(); +// srv.setHostname("aoum"); +// srv.setServiceClass(ServiceClass.audio); +// session.save(srv); +// +// java.util.List services = session.createQuery( +// "from Service as srv where srv.hostname = :rp") +// .setString("rp", "aoum") +// .list(); +// if (services.size() > 0) { +// Service result = (Service)services.get(0); +// System.out.println(result.getHostname() + result.getServiceClass().name()); +// } + + + +// tx = session.beginTransaction(); +// +// Iterator portFaces = session.createQuery( +// "from RecPortFace") +// .list() +// .iterator(); + + tx = session.beginTransaction(); + System.out.println("hello"); + RecSegment seg = new RecSegment(); + GregorianCalendar cal = new GregorianCalendar(); + Date now = cal.getTime(); + seg.setTimestamp(now); + session.save(seg); + + GregorianCalendar cal2 = new GregorianCalendar(); + cal2.setTimeInMillis(cal.getTimeInMillis() + 1000); + + Iterator segments = session.createQuery( + "from RecSegment as seg where seg.timestamp= :date") + //.setDate("date", now) + //.setDate("date2", new Date(time+10000000)) + .setCalendar("date", cal) + .list() + .iterator(); + if(segments.hasNext()) { + RecSegment seg2 = (RecSegment)segments.next(); + System.out.println("db timestamp:" + seg2.getTimestamp().getTime() + " my:" + now.getTime()); + } + else { + System.out.println("fail"); + } + + } + catch ( HibernateException he ) { + if ( tx != null ) tx.rollback(); + throw he; + } + finally { + session.close(); + } + } + +} \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/persistent/Domain.java b/orkbasej/java/net/sf/oreka/persistent/Domain.java new file mode 100644 index 0000000..edb463d --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/Domain.java @@ -0,0 +1,91 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + +/** + * @hibernate.class + */ +@Entity +public class Domain { + + private int id; + private String name = ""; + private String description = ""; + + /** + * + */ + public Domain() { + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the description. + */ + public String getDescription() { + return description; + } + + + /** + * @param description The description to set. + */ + public void setDescription(String description) { + this.description = description; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the name. + */ + public String getName() { + return name; + } + + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/HbnXmlTest.java b/orkbasej/java/net/sf/oreka/persistent/HbnXmlTest.java new file mode 100644 index 0000000..2554a70 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/HbnXmlTest.java @@ -0,0 +1,195 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import org.hibernate.cfg.Configuration; +import org.hibernate.SessionFactory; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.HibernateException; +//import org.hibernate.tool.hbm2ddl.SchemaExport; +//import org.hibernate.ScrollableResults; + +public class HbnXmlTest { + + /** Creates a new instance of TestHibernate */ + public HbnXmlTest() { + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + Configuration config = new Configuration() + .configure("mysql.hbm.xml"); + + config.addClass(HbnXmlTestClass.class); + SessionFactory sessions = config.buildSessionFactory(); + Session session = sessions.openSession(); + + Transaction tx = null; + + try { + /* + SchemaExport export = new SchemaExport(config); + export.setOutputFile("c:\\schema.sql"); + export.create(true,false); + */ + + for (int i=0; i<100 ; i++) + { + tx = session.beginTransaction(); + + HbnXmlTestClass obj = new HbnXmlTestClass(); + + session.save(obj); + tx.commit(); + } + + + // insert + /* + for (int i=0; i<100 ; i++) + { + tx = session.beginTransaction(); + + RecSession RecSession = new RecSession(); + RecSession.setDuration(i); + + + RecSegment intr1 = new RecSegment(); + intr1.setRecSession(RecSession); + intr1.setLocalParty(i + " " + 1); + intr1.setDuration(23); + RecSegment intr2 = new RecSegment(); + intr2.setRecSession(RecSession); + intr2.setLocalParty(i + " " + 2); + intr2.setDuration(45); + + session.save(RecSession); + session.save(intr1); + session.save(intr2); + tx.commit(); + } +*/ + /* + // iterator select + Iterator documents = session.createQuery( + "from Documents doc join doc.car") + .list() + .iterator(); + + while ( documents.hasNext() ) { + Object[] row = (Object[]) documents.next(); + Documents doc = (Documents)row[0]; + Car car = (Car)row[1]; + + //Documents doc = (Documents)documents.next(); + + System.out.println(doc.getId() + " " + car.getId()); + } + */ + /* + // scrollable select + ScrollableResults scrollDocs = session.createQuery( + "from RecSegment intr join intr.RecSession").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecSegment doc = (RecSegment)scrollDocs.get(0); + RecSession car = (RecSession)scrollDocs.get(1); + System.out.println(doc.getId() + " " + car.getId()); + } + */ + + /* + // many to many insert + tx = session.beginTransaction(); + + RecProgram prog1 = new RecProgram(); + RecProgram prog2 = new RecProgram(); + RecSegment seg = new RecSegment(); + + HashSet programs = new HashSet(); + programs.add(prog1); + programs.add(prog2); + seg.setRecPrograms(programs); + + session.save(prog1); + session.save(prog2); + session.save(seg); + tx.commit(); + */ + + // Many to many select + /* + ScrollableResults scrollDocs = session.createQuery( + "from RecSegment as seg join seg.recPrograms as prg where prg.id=2").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecSegment seg = (RecSegment)scrollDocs.get(0); + RecProgram prg = (RecProgram)scrollDocs.get(1); + System.out.println(seg.getId() + " " + prg.getId()); + } + */ + + /* + // one to one create + tx = session.beginTransaction(); + + RecProgram prog = new RecProgram(); + User user = new User(); + prog.setTargetUser(user); + + session.save(user); + session.save(prog); + tx.commit(); + */ + /* + // one to one select + ScrollableResults scrollDocs = session.createQuery( + "from RecProgram as prg join prg.targetUser as tgt").scroll(); + if ( scrollDocs.last() ) { + System.out.println("Num res:" + scrollDocs.getRowNumber() + "\n\n"); + } + + scrollDocs.beforeFirst(); + while (scrollDocs.next()) + { + RecProgram prg = (RecProgram)scrollDocs.get(0); + User tgt = (User)scrollDocs.get(1); + System.out.println(prg.getId() + " " + tgt.getId()); + } + */ + } + catch ( HibernateException he ) { + if ( tx != null ) tx.rollback(); + throw he; + } + finally { + session.close(); + } + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/HbnXmlTestClass.java b/orkbasej/java/net/sf/oreka/persistent/HbnXmlTestClass.java new file mode 100644 index 0000000..8706455 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/HbnXmlTestClass.java @@ -0,0 +1,62 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +/** + * @hibernate.class + */ +public class HbnXmlTestClass { + + long Id; + String firstname = ""; + String lastname = ""; + + /** + * @hibernate.property + * not-null="true" + * @return Returns the filename. + */ + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the filename. + */ + public String getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + /** + * @hibernate.id + * generator-class="native" + */ + public long getId() { + return Id; + } + + public void setId(long id) { + Id = id; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/LoginString.java b/orkbasej/java/net/sf/oreka/persistent/LoginString.java new file mode 100644 index 0000000..ad44057 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/LoginString.java @@ -0,0 +1,114 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +/** + * @hibernate.class + */ +@Entity +public class LoginString { + + private int id; + private String loginString; + private User user; + private Domain domain; + + /** + * @hibernate.many-to-one + * @return Returns the domain. + */ + @ManyToOne + public Domain getDomain() { + return domain; + } + + + /** + * @param domain The domain to set. + */ + public void setDomain(Domain domain) { + this.domain = domain; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the loginString. + */ + public String getLoginString() { + return loginString; + } + + + /** + * @param loginString The loginString to set. + */ + public void setLoginString(String loginString) { + this.loginString = loginString; + } + + + /** + * @hibernate.many-to-one + * @return Returns the user. + */ + @ManyToOne + public User getUser() { + return user; + } + + + /** + * @param user The user to set. + */ + public void setUser(User user) { + this.user = user; + } + + + /** + * + */ + public LoginString() { + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecPort.java b/orkbasej/java/net/sf/oreka/persistent/RecPort.java new file mode 100644 index 0000000..9886bdc --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecPort.java @@ -0,0 +1,33 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + +@Entity +public class RecPort { + + private int id; + + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecPortFace.java b/orkbasej/java/net/sf/oreka/persistent/RecPortFace.java new file mode 100644 index 0000000..2824926 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecPortFace.java @@ -0,0 +1,49 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class RecPortFace { + + private RecPort recPort; + private Service service; + private String name; + + @Id + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + @ManyToOne + public RecPort getRecPort() { + return recPort; + } + public void setRecPort(RecPort recPort) { + this.recPort = recPort; + } + @ManyToOne + public Service getService() { + return service; + } + public void setService(Service service) { + this.service = service; + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecProgram.java b/orkbasej/java/net/sf/oreka/persistent/RecProgram.java new file mode 100644 index 0000000..48d8bdb --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecProgram.java @@ -0,0 +1,516 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; + +import java.util.Collection; +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import net.sf.oreka.Cycle; +import net.sf.oreka.Direction; + +/** + * @hibernate.class + */ +@Entity +public class RecProgram { + + private int id; + private String name = ""; + private String description = ""; + private boolean discarded = false; + private Date timestamp; + private User owner; + private boolean active = true; + private Direction direction = Direction.ALL; + private int minDuration = 0; + private int maxDuration = 0; + private double randomPercent = 0.0; + private Cycle cycle = Cycle.permanent; + private int startDay = 0; + private int stopDay = 0; + private Date startTime; + private Date stopTime; + private int recPerCycle = 0; + private int recordedSoFar = 0; + private String localParty = ""; + private String remoteParty = ""; + private int keepForHours = 0; + private User targetUser; + private RecPort targetPort; + + //private Set RecSegments; + private Collection recSegments; + + /** + * @hibernate.set + * lazy="true" + * table="PrgToSeg" + * @hibernate.collection-key + * column="RecProgram" + * @hibernate.collection-many-to-many + * column="RecSegment" + * class="net.sf.oreka.persistent.RecSegment" + * @return Returns the recSegments. + */ + @ManyToMany +// ( +// targetEntity="net.sf.oreka.persistent.RecSegment" +// ) + @JoinTable( + table=@Table(name="ProgToSeg"), + joinColumns={@JoinColumn(name="ProgId")}, + inverseJoinColumns={@JoinColumn(name="SegId")} + ) + public Collection getRecSegments() { + return recSegments; + } + + + /** + * @param recSegments The recSegments to set. + */ + public void setRecSegments(Collection recSegments) { + this.recSegments = recSegments; + } + + + public RecProgram () { + direction = Direction.ALL; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the active. + */ + public boolean isActive() { + return active; + } + + + /** + * @param active The active to set. + */ + public void setActive(boolean active) { + this.active = active; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the cycle. + */ + public Cycle getCycle() { + return cycle; + } + + + /** + * @param cycle The cycle to set. + */ + public void setCycle(Cycle cycle) { + this.cycle = cycle; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the description. + */ + public String getDescription() { + return description; + } + + + /** + * @param description The description to set. + */ + public void setDescription(String description) { + this.description = description; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the direction. + */ + public Direction getDirection() { + return direction; + } + + + /** + * @param direction The direction to set. + */ + public void setDirection(Direction direction) { + this.direction = direction; + } + + + /** + * @return Returns the discarded. + */ + public boolean isDiscarded() { + return discarded; + } + + + /** + * @param discarded The discarded to set. + */ + public void setDiscarded(boolean discarded) { + this.discarded = discarded; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the keepForHours. + */ + public int getKeepForHours() { + return keepForHours; + } + + + /** + * @param keepForHours The keepForHours to set. + */ + public void setKeepForHours(int keepForHours) { + this.keepForHours = keepForHours; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the localParty. + */ + public String getLocalParty() { + return localParty; + } + + + /** + * @param localParty The localParty to set. + */ + public void setLocalParty(String localParty) { + this.localParty = localParty; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the maxDuration. + */ + public int getMaxDuration() { + return maxDuration; + } + + + /** + * @param maxDuration The maxDuration to set. + */ + public void setMaxDuration(int maxDuration) { + this.maxDuration = maxDuration; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the minDuration. + */ + public int getMinDuration() { + return minDuration; + } + + + /** + * @param minDuration The minDuration to set. + */ + public void setMinDuration(int minDuration) { + this.minDuration = minDuration; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the name. + */ + public String getName() { + return name; + } + + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the randomPercent. + */ + public double getRandomPercent() { + return randomPercent; + } + + + /** + * @param randomPercent The randomPercent to set. + */ + public void setRandomPercent(double randomPercent) { + this.randomPercent = randomPercent; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the recordedSoFar. + */ + public int getRecordedSoFar() { + return recordedSoFar; + } + + + /** + * @param recordedSoFar The recordedSoFar to set. + */ + public void setRecordedSoFar(int recordedSoFar) { + this.recordedSoFar = recordedSoFar; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the recPerCycle. + */ + public int getRecPerCycle() { + return recPerCycle; + } + + + /** + * @param recPerCycle The recPerCycle to set. + */ + public void setRecPerCycle(int recPerCycle) { + this.recPerCycle = recPerCycle; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the remoteParty. + */ + public String getRemoteParty() { + return remoteParty; + } + + + /** + * @param remoteParty The remoteParty to set. + */ + public void setRemoteParty(String remoteParty) { + this.remoteParty = remoteParty; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the startDay. + */ + public int getStartDay() { + return startDay; + } + + + /** + * @param startDay The startDay to set. + */ + public void setStartDay(int startDay) { + this.startDay = startDay; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the startTime. + */ + public Date getStartTime() { + return startTime; + } + + + /** + * @param startTime The startTime to set. + */ + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the stopDay. + */ + public int getStopDay() { + return stopDay; + } + + + /** + * @param stopDay The stopDay to set. + */ + public void setStopDay(int stopDay) { + this.stopDay = stopDay; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the stopTime. + */ + public Date getStopTime() { + return stopTime; + } + + + /** + * @param stopTime The stopTime to set. + */ + public void setStopTime(Date stopTime) { + this.stopTime = stopTime; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the targetPort. + */ + @OneToOne + public RecPort getTargetPort() { + return targetPort; + } + + + /** + * @param targetPort The targetPort to set. + */ + public void setTargetPort(RecPort targetPort) { + this.targetPort = targetPort; + } + + /** + * @hibernate.many-to-one + * @return Returns the targetUser. + */ + @ManyToOne + public User getTargetUser() { + return targetUser; + } + + + + /** + * @param targetUser The targetUser to set. + */ + public void setTargetUser(User targetUser) { + this.targetUser = targetUser; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the timestamp. + */ + public Date getTimestamp() { + return timestamp; + } + + + /** + * @param timestamp The timestamp to set. + */ + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + + /** + * @hibernate.many-to-one + * @return Returns the owner. + */ + @ManyToOne + public User getOwner() { + return owner; + } + + + + /** + * @param owner The owner to set. + */ + public void setOwner(User owner) { + this.owner = owner; + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecSegment.java b/orkbasej/java/net/sf/oreka/persistent/RecSegment.java new file mode 100644 index 0000000..716de5b --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecSegment.java @@ -0,0 +1,321 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +import net.sf.oreka.Direction; + +/** + * @hibernate.class + */ +@Entity +public class RecSegment { + + private int id; + private RecSession recSession; + private long recSessionOffset; + private RecTape recTape; + private long recTapeOffset; + private Date timestamp = new Date(0); + private long duration; + private String localParty = ""; + private String localEntryPoint = ""; + private String remoteParty = ""; + private Direction direction;; + private User user; + private String loginString = ""; + private RecPort port; + //private java.util.Set RecPrograms; + private Collection recPrograms; + + public RecSegment() { + direction = Direction.UNKN; + recPrograms = new ArrayList(); + } + + /** + * @hibernate.property + * + * @hibernate.column + * name="direction" + * index="direction" + * not-null="true" + * @return Returns the direction. + */ + public Direction getDirection() { + return direction; + } + + /** + * @param direction The direction to set. + */ + public void setDirection(Direction direction) { + this.direction = direction; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the duration. + */ + public long getDuration() { + return duration; + } + + /** + * @param duration The duration to set. + */ + public void setDuration(long duration) { + this.duration = duration; + } + + /** + * @hibernate.id + * generator-class="native" + * @hibernate.collection-many-to-many + * column="RecSegmentId" + * class="RecProgram" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @hibernate.property + * + * @hibernate.column + * name="localParty" + * index="localParty" + * not-null="true" + * + * @return Returns the localParty. + */ + public String getLocalParty() { + return localParty; + } + + /** + * @param localParty The localParty to set. + */ + public void setLocalParty(String localParty) { + this.localParty = localParty; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the loginString. + */ + public String getLoginString() { + return loginString; + } + + /** + * @param loginString The loginString to set. + */ + public void setLoginString(String loginString) { + this.loginString = loginString; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the remoteParty. + */ + public String getRemoteParty() { + return remoteParty; + } + + /** + * @param remoteParty The remoteParty to set. + */ + public void setRemoteParty(String remoteParty) { + this.remoteParty = remoteParty; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the RecTapeOffset. + */ + public long getRecTapeOffset() { + return recTapeOffset; + } + + /** + * @param RecTapeOffset The RecTapeOffset to set. + */ + public void setRecTapeOffset(long recTapeOffset) { + this.recTapeOffset = recTapeOffset; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the timestamp. + */ + public Date getTimestamp() { + return timestamp; + } + + /** + * @param timestamp The timestamp to set. + */ + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + /** + * @hibernate.many-to-one + * @return Returns the RecSession. + */ + @ManyToOne + public RecSession getRecSession() { + return recSession; + } + + /** + * @param RecSession The RecSession to set. + */ + public void setRecSession(RecSession recSession) { + this.recSession = recSession; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the RecSessionOffset. + */ + public long getRecSessionOffset() { + return recSessionOffset; + } + + /** + * @param RecSessionOffset The RecSessionOffset to set. + */ + public void setRecSessionOffset(long recSessionOffset) { + this.recSessionOffset = recSessionOffset; + } + + /** + * @hibernate.many-to-one + * @return Returns the recTape. + */ + @ManyToOne + public RecTape getRecTape() { + return recTape; + } + + + /** + * @param recTape The recTape to set. + */ + public void setRecTape(RecTape recTape) { + this.recTape = recTape; + } + + /** + * @hibernate.set + * lazy="true" + * table="PrgToSeg" + * @hibernate.collection-key + * column="RecSegment" + * @hibernate.collection-many-to-many + * column="RecProgram" + * class="net.sf.oreka.persistent.RecProgram" + * @return Returns the recPrograms. + */ + @ManyToMany + @JoinTable( + table=@Table(name="ProgToSeg"), + joinColumns={@JoinColumn(name="SegId")}, + inverseJoinColumns={@JoinColumn(name="ProgId")} + ) + public Collection getRecPrograms() { + return recPrograms; + } + + + /** + * @param recPrograms The recPrograms to set. + */ + public void setRecPrograms(Collection recPrograms) { + this.recPrograms = recPrograms; + } + + /** + * @hibernate.many-to-one + * @return Returns the user. + */ + @ManyToOne + public User getUser() { + return user; + } + + + /** + * @param user The user to set. + */ + public void setUser(User user) { + this.user = user; + } + + public String getLocalEntryPoint() { + return localEntryPoint; + } + + public void setLocalEntryPoint(String localEntryPoint) { + this.localEntryPoint = localEntryPoint; + } + + @Transient + public long getStopTime() { + return timestamp.getTime() + duration; + } + + @OneToOne + public RecPort getPort() { + return port; + } + + public void setPort(RecPort port) { + this.port = port; + } + + + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecSession.java b/orkbasej/java/net/sf/oreka/persistent/RecSession.java new file mode 100644 index 0000000..214f678 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecSession.java @@ -0,0 +1,79 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.Transient; + +/** + * @hibernate.class + */ +@Entity +public class RecSession { + private int id; + private Date timestamp = new Date(0); + private long duration; + + /** + * @hibernate.property + * not-null="true" + * @return + */ + public long getDuration() { + return duration; + } + + public void setDuration(long duration) { + this.duration = duration; + } + + /** + * @hibernate.id + * generator-class="native" + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + public void setId(int id) { + this.id = id; + } + + /** + * @hibernate.property + * @return + */ + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + @Transient + public long getStopTime() { + return timestamp.getTime() + duration; + } + + public void setStopTime(long stopTime) { + duration = stopTime - timestamp.getTime(); + } +} diff --git a/orkbasej/java/net/sf/oreka/persistent/RecTape.java b/orkbasej/java/net/sf/oreka/persistent/RecTape.java new file mode 100644 index 0000000..d5f6d73 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/RecTape.java @@ -0,0 +1,249 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.persistent; + +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Transient; + +import net.sf.oreka.Direction; + +/** + * @hibernate.class + */ +@Entity +public class RecTape { + + private int id; + private Date timestamp = new Date(0); + private long duration; + private String filename = ""; + private Service service; + private String localParty = ""; + private String localEntryPoint = ""; + private String remoteParty = ""; + private Direction direction; + private RecPort port; + private Date expiryTimestamp = new Date(0); + + public RecTape() + { + // Defaults + direction = Direction.UNKN; + } + + /** + * @hibernate.property + * @hibernate.column + * name="direction" + * index="direction" + * not-null="true" + * @return Returns the direction. + */ + public Direction getDirection() { + return direction; + } + + /** + * @param direction The direction to set. + */ + public void setDirection(Direction direction) { + this.direction = direction; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the duration. + */ + public long getDuration() { + return duration; + } + + /** + * @param duration The duration to set. + */ + public void setDuration(long duration) { + this.duration = duration; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the expiryTimestamp. + */ + public Date getExpiryTimestamp() { + return expiryTimestamp; + } + + /** + * @param expiryTimestamp The expiryTimestamp to set. + */ + public void setExpiryTimestamp(Date expiryTimestamp) { + this.expiryTimestamp = expiryTimestamp; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the filename. + */ + public String getFilename() { + return filename; + } + + /** + * @param filename The filename to set. + */ + public void setFilename(String filename) { + this.filename = filename; + } + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the localParty. + */ + public String getLocalParty() { + return localParty; + } + + /** + * @param localParty The localParty to set. + */ + public void setLocalParty(String localParty) { + this.localParty = localParty; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the port. + */ + @OneToOne + public RecPort getPort() { + return port; + } + + /** + * @param port The port to set. + */ + public void setPort(RecPort port) { + this.port = port; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the remoteParty. + */ + public String getRemoteParty() { + return remoteParty; + } + + /** + * @param remoteParty The remoteParty to set. + */ + public void setRemoteParty(String remoteParty) { + this.remoteParty = remoteParty; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the timestamp. + */ + public Date getTimestamp() { + return timestamp; + } + + /** + * @param timestamp The timestamp to set. + */ + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + /** + * @hibernate.many-to-one + * @return Returns the service. + */ + @ManyToOne + public Service getService() { + return service; + } + + + /** + * @param server The service to set. + */ + public void setService(Service service) { + this.service = service; + } + + public String getLocalEntryPoint() { + return localEntryPoint; + } + + public void setLocalEntryPoint(String localEntryPoint) { + this.localEntryPoint = localEntryPoint; + } + + @Transient + public long getStopTime() { + return timestamp.getTime() + duration; + } + + @Transient + public String getUrl() { + + if(service != null) { + return service.getFileServeProtocol() + "://" + + service.getHostname() + ":" + service.getFileServeTcpPort() + + "/" + service.getFileServePath() + "/" + filename; + } + else { + return ""; + } + } + + @Transient + public String getPlayUrl() { + + return "javascript:play('" + getUrl() + "')"; + } + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/Service.java b/orkbasej/java/net/sf/oreka/persistent/Service.java new file mode 100644 index 0000000..361676a --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/Service.java @@ -0,0 +1,172 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + +import net.sf.oreka.ServiceClass; + +/** + * @hibernate.class + */ +@Entity +public class Service { + + private int id; + private String name = ""; + private String hostname = ""; + private int tcpPort = 0; + private String fileServeProtocol = ""; + private int fileServeTcpPort = 0; + private String fileServePath = ""; + private ServiceClass serviceClass; + private boolean recordMaster = false; + + /** + * + */ + public Service() { + serviceClass = ServiceClass.unkn; + } + + /** + * + * @hibernate.property + * not-null="true" + * @return Returns the fileServePath. + */ + public String getFileServePath() { + return fileServePath; + } + + + /** + * @param fileServePath The fileServePath to set. + */ + public void setFileServePath(String fileServePath) { + this.fileServePath = fileServePath; + } + + public int getFileServeTcpPort() { + return fileServeTcpPort; + } + + public void setFileServeTcpPort(int fileServeTcpPort) { + this.fileServeTcpPort = fileServeTcpPort; + } + + public int getTcpPort() { + return tcpPort; + } + + public void setTcpPort(int tcpPort) { + this.tcpPort = tcpPort; + } + + /** + * @hibernate.property + * not-null="true" + * @return Returns the fileServeProtocol. + */ + public String getFileServeProtocol() { + return fileServeProtocol; + } + + + /** + * @param fileServeProtocol The fileServeProtocol to set. + */ + public void setFileServeProtocol(String fileServeProtocol) { + this.fileServeProtocol = fileServeProtocol; + } + + + /** + * @hibernate.property + * unique="true" + * not-null="true" + * @return Returns the gUID. + */ + public String getName() { + return name; + } + + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the hostname. + */ + public String getHostname() { + return hostname; + } + + + /** + * @param hostname The hostname to set. + */ + public void setHostname(String hostname) { + this.hostname = hostname; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + public void setId(int id) { + this.id = id; + } + + public ServiceClass getServiceClass() { + return serviceClass; + } + + public void setServiceClass(ServiceClass serviceClass) { + this.serviceClass = serviceClass; + } + + public boolean isRecordMaster() { + return recordMaster; + } + + public void setRecordMaster(boolean cdrMaster) { + this.recordMaster = cdrMaster; + } + + +} diff --git a/orkbasej/java/net/sf/oreka/persistent/User.java b/orkbasej/java/net/sf/oreka/persistent/User.java new file mode 100644 index 0000000..5d78760 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/persistent/User.java @@ -0,0 +1,133 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * + */ +package net.sf.oreka.persistent; + +import javax.persistence.Entity; +import javax.persistence.GeneratorType; +import javax.persistence.Id; + +/** + * @hibernate.class + */ +@Entity +public class User { + + private int id; + private String password = ""; + private String firstname = ""; + private String lastname = ""; + private String email = ""; + + /** + * @hibernate.property + * not-null="true" + * @return Returns the email. + */ + public String getEmail() { + return email; + } + + + /** + * @param email The email to set. + */ + public void setEmail(String email) { + this.email = email; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the firstname. + */ + public String getFirstname() { + return firstname; + } + + + /** + * @param firstname The firstname to set. + */ + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + + /** + * @hibernate.id + * generator-class="native" + * @return Returns the id. + */ + @Id(generate=GeneratorType.AUTO) + public int getId() { + return id; + } + + + /** + * @param id The id to set. + */ + @Id(generate=GeneratorType.AUTO) + public void setId(int id) { + this.id = id; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the lastname. + */ + public String getLastname() { + return lastname; + } + + + /** + * @param lastname The lastname to set. + */ + public void setLastname(String lastname) { + this.lastname = lastname; + } + + + /** + * @hibernate.property + * not-null="true" + * @return Returns the password. + */ + public String getPassword() { + return password; + } + + + /** + * @param password The password to set. + */ + public void setPassword(String password) { + this.password = password; + } + + + /** + * + */ + public User() { + } + +} diff --git a/orkbasej/java/net/sf/oreka/serializers/DomSerializer.java b/orkbasej/java/net/sf/oreka/serializers/DomSerializer.java new file mode 100644 index 0000000..ac64a13 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/DomSerializer.java @@ -0,0 +1,186 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + + + +package net.sf.oreka.serializers; + + +import java.io.ByteArrayOutputStream; + +import javax.xml.transform.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.OrkObjectFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.Text; + +public class DomSerializer extends OrkSerializer { + + Node node = null; + Document document = null; + + public OrkObject deSerialize(Node node) throws OrkException + { + if (node == null) + { + throw (new OrkException("DomSerializer: null node was passed in")); + } + this.node = node; + deserialize = true; // Set DeSerialize mode + OrkObject obj = OrkObjectFactory.instance().newOrkObject(node.getNodeName()); + obj.define(this); + obj.validate(); + return obj; + } + + public void serialize(Document document, Node node, OrkObject object) throws OrkException { + + if (node == null) { + throw ( new OrkException("DomSerializer: passed DOM node is null")); + } + if (document == null) { + throw ( new OrkException("DomSerializer: passed DOM document is null")); + } + this.document = document; + this.node = node; + + deserialize = false; // Set Serialize mode + object.define(this); + } + + @Override + public void addClassName(String value) { + // TODO Auto-generated method stub + + } + + @Override + void addString(String key, String value) { + + Element newElem = document.createElement(key); + node.appendChild(newElem); + + Text newText = document.createTextNode(value); + newElem.appendChild(newText); + } + + @Override + String getString(String key, String oldValue, boolean required) throws OrkException { + + String value = null; + + // Find the right node + Node stringNode = findElementByName(node, key); + + if(stringNode != null) + { + // Now, the string associated to element should be the first child (text element) + Node textNode = stringNode.getFirstChild(); + if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) { + value = textNode.getNodeValue().trim(); + } + } + if (value == null) { + if (required) { + throw(new OrkException("DomSerializer::GetString: required parameter missing:" + key)); + } + value = oldValue; + } + return value; + } + + @Override + public OrkObject objectValue(String key, OrkObject value, boolean required) throws OrkException { + + if (deserialize) { + return getObject(key, value, required); + } + else { + addObject(key, value); + return value; + } + } + + void addObject(String key, OrkObject value) throws OrkException { + + Element newElem = document.createElement(key); + node.appendChild(newElem); + DomSerializer ser = new DomSerializer(); + ser.serialize(document, newElem, value); + } + + OrkObject getObject(String key, OrkObject oldValue, boolean required) throws OrkException { + + OrkObject value = null; + + // Find the node corresponding to the object wanting to be populated + Node objectNode = findElementByName(node, key); + + // Create a new serializer and affect it to this object + if (objectNode != null) + { + DomSerializer serializer = new DomSerializer(); + value = serializer.deSerialize(objectNode); + } + if (value == null) { + if (required) { + throw(new OrkException("DomSerializer.getObject: required node missing:" + key)); + } + value = oldValue; + } + return value; + } + + public Node findElementByName(Node node, String name) + { + Node child = node.getFirstChild(); + while(child != null) + { + if (child.getNodeName().equalsIgnoreCase(name) && child.getNodeType() == Node.ELEMENT_NODE) + { + return child; + } + child = child.getNextSibling(); + } + return null; + } + + public static String NodeToString(Node node) { + + String result = null; + TransformerFactory xformerFactory = TransformerFactory.newInstance(); + try { + Transformer xformer = xformerFactory.newTransformer(); + xformer.setOutputProperty("indent", "yes"); + ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); + Result output = new StreamResult(byteArray); + DOMSource source = new DOMSource(node); + xformer.transform(source,output); + result = byteArray.toString(); + } + catch (Exception e) { + ; + } + return result; + } + +} diff --git a/orkbasej/java/net/sf/oreka/serializers/KeyValueSerializer.java b/orkbasej/java/net/sf/oreka/serializers/KeyValueSerializer.java new file mode 100644 index 0000000..bc65819 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/KeyValueSerializer.java @@ -0,0 +1,47 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers; + +import java.util.HashMap; + +import net.sf.oreka.*; + +public abstract class KeyValueSerializer extends OrkSerializer +{ + HashMap map; + + KeyValueSerializer() + { + map = new HashMap(); + } + + String getString(String key, String oldValue, boolean required) throws OrkException + { + String value = map.get(key.toLowerCase()); + if (value == null) + { + if (required == true) + { + throw (new OrkException("Serializer.GetString: required parameter missing:" + key)); + } + value = oldValue; + } + return value; + } + + public OrkObject objectValue(String key, OrkObject value, boolean required) throws OrkException + { + throw (new OrkException("KeyValueSerializer.objectValue: Nested objects not allowed for key-value serializers")); + } +} diff --git a/orkbasej/java/net/sf/oreka/serializers/OrkSerializer.java b/orkbasej/java/net/sf/oreka/serializers/OrkSerializer.java new file mode 100644 index 0000000..f4b0d54 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/OrkSerializer.java @@ -0,0 +1,239 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers; + +import net.sf.oreka.*; + +/** + * + * Base class for all serializers. + * Serializers have to implement their own serialize and deserialize methods + * since the data can be read from and written to many different formats + * + * Enum and Boolean value are case insensitive (all enum values must be defined + * lower case in the project, otherwise they won't be recognized at all) + * + */ +public abstract class OrkSerializer { + + boolean deserialize = false; + String classKey = "class"; + + public void setClassKey(String classKey) + { + this.classKey = classKey; + } + + public int intValue(String key, int value, boolean required) throws OrkException + { + if (deserialize) + { + return getInt(key, value, required); + } + else + { + addInt(key, value); + return value; + } + } + + public double doubleValue(String key, double value, boolean required) throws OrkException + { + if (deserialize) + { + return getDouble(key, value, required); + } + else + { + addDouble(key, value); + return value; + } + } + + public String stringValue(String key, String value, boolean required ) throws OrkException + { + if (deserialize) + { + return getString(key, value, required); + } + else + { + addString(key, value); + return value; + } + } + + public boolean booleanValue(String key, boolean value, boolean required ) throws OrkException + { + if (deserialize) + { + return getBoolean(key, value, required); + } + else + { + addBoolean(key, value); + return value; + } + } + + public Enum enumValue(String key, Enum value, boolean required ) throws OrkException + { + if (deserialize) + { + return getEnum(key, value, required); + } + else + { + addEnum(key, value); + return value; + } + } + + public abstract OrkObject objectValue(String key, OrkObject value, boolean required ) throws OrkException; + + public abstract void addClassName(String value); + + void addInt(String key, int value) + { + String valueString = String.valueOf(value); + addString(key, valueString); + } + + void addDouble(String key, double value) + { + String valueString = String.valueOf(value); + addString(key, valueString); + } + + void addBoolean(String key, boolean value) + { + if(value) + { + addString(key, "true"); + } + else + { + addString(key, "false"); + } + } + + void addEnum(String key, Enum value) + { + addString(key, value.name()); + } + + abstract void addString(String key, String value); + + int getInt(String key, int oldValue, boolean required) throws OrkException + { + int value = 0; + String stringValue = getString(key, null, required); + + if (stringValue == null) + { + value = oldValue; + } + else + { + try + { + value = Integer.valueOf(stringValue); + } + catch (Exception e) + { + throw (new OrkException("Serializer: value:" + stringValue + " not an int for key:" + key)); + } + } + return value; + } + + double getDouble(String key, double oldValue, boolean required) throws OrkException + { + double value = 0.0; + String stringValue = getString(key, null, required); + + if (stringValue == null) + { + value = oldValue; + } + else + { + try + { + value = Double.valueOf(stringValue); + } + catch (Exception e) + { + throw (new OrkException("Serializer: value:" + stringValue + " not a double for key:" + key)); + } + } + return value; + } + + boolean getBoolean(String key, boolean oldValue, boolean required) throws OrkException + { + boolean value; + String stringValue = getString(key, null, required); + + if (stringValue == null) + { + value = oldValue; + } + else + { + stringValue = stringValue.toLowerCase(); + + if( stringValue.equals("true") || stringValue.equals("yes") || stringValue.equals("1") ) + { + value = true; + } + else if( stringValue.equals("false") || stringValue.equals("no") || stringValue.equals("0") ) + { + value = false; + } + else + { + throw(new OrkException("Serializer: Invalid boolean value:" + stringValue + " for key:" + key)); + } + } + return value; + } + + Enum getEnum(String key, Enum oldValue, boolean required) throws OrkException + { + Enum value = null; + String stringValue = getString(key, null, required); + + if (stringValue == null) + { + value = oldValue; + } + else + { + stringValue = stringValue.toLowerCase(); + Class valueClass = oldValue.getClass(); + try + { + value = Enum.valueOf(valueClass, stringValue); + } + catch (IllegalArgumentException e) + { + throw (new OrkException("Serializer: Invalid enum value:" + stringValue + " for parameter:" + key)); + } + } + return value; + } + + abstract String getString(String key, String oldValue, boolean required ) throws OrkException; +} diff --git a/orkbasej/java/net/sf/oreka/serializers/ServletRequestSerializer.java b/orkbasej/java/net/sf/oreka/serializers/ServletRequestSerializer.java new file mode 100644 index 0000000..8eded74 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/ServletRequestSerializer.java @@ -0,0 +1,79 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers; + +import javax.servlet.http.*; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.OrkObjectFactory; + +public class ServletRequestSerializer extends OrkSerializer { + + HttpServletRequest request = null; + final String classMarker = "cmd"; + + public OrkObject deSerialize(HttpServletRequest request) throws OrkException + { + this.request = request; + deserialize = true; // Set DeSerialize mode + + // Instanciate the right object + String classMarker2 = (String)request.getParameterNames().nextElement(); + String orkClass = null; + if(classMarker2 != null) + { + orkClass = request.getParameter(classMarker2); + } + if(orkClass == null) { + throw (new OrkException("ServletRequestSerializer.deSerialize: where is the command in:" + request.getQueryString())); + } + + OrkObject obj = OrkObjectFactory.instance().newOrkObject(orkClass.toLowerCase()); + obj.define(this); + obj.validate(); + return obj; + } + + @Override + public void addClassName(String value) { + ; // not needed, this serializer is only a de-serializer + } + + @Override + void addString(String key, String value) { + ; // not needed, this serializer is only a de-serializer + } + + @Override + String getString(String key, String oldValue, boolean required) throws OrkException { + String value = request.getParameter(key); + if(value == null) { + if (required) { + throw (new OrkException("ServletRequestSerializer.getString: parameter not found:" + key)); + } + else { + value = oldValue; + } + } + return value; + } + + @Override + public OrkObject objectValue(String key, OrkObject value, boolean required) throws OrkException { + throw (new OrkException("ServletRequestSerializer.objectValue: Nested objects not allowed")); + } + + +} diff --git a/orkbasej/java/net/sf/oreka/serializers/SingleLineSerializer.java b/orkbasej/java/net/sf/oreka/serializers/SingleLineSerializer.java new file mode 100644 index 0000000..44f2fe3 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/SingleLineSerializer.java @@ -0,0 +1,231 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers; + +import net.sf.oreka.OrkException; +import net.sf.oreka.OrkObject; +import net.sf.oreka.OrkObjectFactory; + +/** + * Serializer that generates and parses objects to and from a single line of text. + * key-value pairs are separated by spaces. + * key and values are separated by equal signs. + * example: message=doit what=run + */ +public class SingleLineSerializer extends KeyValueSerializer +{ + StringBuffer output; + + public String serialize(OrkObject input) throws OrkException + { + output = new StringBuffer(); + deserialize = false; // Set Serialize mode + addClassName(input.getOrkClassName()); + input.define(this); + return output.toString(); + } + + enum SingleLineState {StartState, KeyState, ValueState}; + + public OrkObject deSerialize(String input) throws OrkException + { + // read string and extract values into map + input = input.trim(); + + SingleLineState state = SingleLineState.StartState; + + StringBuffer key = new StringBuffer(); + StringBuffer value = new StringBuffer(); + String firstValue = null; + + for(int i=0; i 0) + { + // Add pair to key-value map + map.put(key.toString().toLowerCase(), unEscapeSingleLine(value.toString())); + if (firstValue == null) + { + firstValue = value.toString().toLowerCase(); + } + key = new StringBuffer(); + value = new StringBuffer(); + } + } + } + + deserialize = true; // Set DeSerialize mode + + OrkObject obj = OrkObjectFactory.instance().newOrkObject(firstValue); + obj.define(this); + obj.validate(); + return obj; + } + + public void addClassName(String value) + { + addString(classKey, value); + } + + void addString(String key, String value) + { + String pair; + String escapedValue = escapeSingleLine(value); + pair = key + "=" + escapedValue + " "; + output.append(pair); + } + + /** + * Finds the Object Class from a serialized string. + * i.e. for a serialized object of the form: + * message=dosomething when=now + * it returns "dosomething" + * + * @param input + * @return + */ + /* + static String findClass(String input) + { + String result = ""; + int equalsPosition = input.indexOf("="); + if (equalsPosition != -1) + { + int spacePostion = input.indexOf(" "); + if (spacePostion > equalsPosition) + { + result = input.substring(equalsPosition+1, spacePostion-1); + } + else + { + result = input.substring(equalsPosition+1, input.length() - 1); + } + } + return result.toLowerCase(); + } + */ + + String escapeSingleLine(String in) + { + StringBuffer out = new StringBuffer(); + for(int i=0; i parameters = new Hashtable(); + + public void setParameter(String key, String value) { + parameters.put(key, value); + } + + public String getParameter(String key) { + return (String)this.parameters.get(key); + } + + public Enumeration getParameterNames(){ + return this.parameters.elements(); + } + + public Cookie[] getCookies() {return null;} + public String getMethod(){return null;} + public String getRequestURI(){return null;} + public String getServletPath(){return null;} + public String getPathInfo(){return null;} + public String getPathTranslated(){return null;} + public String getQueryString(){return null;} + public String getRemoteUser(){return null;} + public String getAuthType(){return null;} + public String getHeader(String name){return null;} + public int getIntHeader(String name){return 0;} + public long getDateHeader(String name){return 0;} + public Enumeration getHeaderNames(){return null;} + public HttpSession getSession(boolean create){return null;} + public String getRequestedSessionId(){return null;} + public boolean isRequestedSessionIdValid(){return false;} + public boolean isRequestedSessionIdFromCookie(){return false;} + public boolean isRequestedSessionIdFromUrl(){return false;} + public int getContentLength(){return 0;} + public String getContentType(){return null;} + public String getProtocol(){return null;} + public String getScheme(){return null;} + public String getServerName(){return null;} + public int getServerPort(){return 0;} + public String getRemoteAddr(){return null;} + public String getRemoteHost(){return null;} + public String getRealPath(String path){return null;} + public ServletInputStream getInputStream() throws IOException{return null;} + public String[] getParameterValues(String name){return null;} + public Enumeration getAttributeNames(){return null;} + public Object getAttribute(String name){return null;} + public HttpSession getSession(){return null;} + public BufferedReader getReader() throws IOException{return null;} + public String getCharacterEncoding(){return null;} + public void setAttribute(String name, Object o) {} + public boolean isRequestedSessionIdFromURL() {return false;} + + public String getContextPath() { + // TODO Auto-generated method stub + return null; + } + + public Enumeration getHeaders(String arg0) { + // TODO Auto-generated method stub + return null; + } + + public StringBuffer getRequestURL() { + // TODO Auto-generated method stub + return null; + } + + public Principal getUserPrincipal() { + // TODO Auto-generated method stub + return null; + } + + public boolean isUserInRole(String arg0) { + // TODO Auto-generated method stub + return false; + } + + public String getLocalAddr() { + // TODO Auto-generated method stub + return null; + } + + public Locale getLocale() { + // TODO Auto-generated method stub + return null; + } + + public Enumeration getLocales() { + // TODO Auto-generated method stub + return null; + } + + public String getLocalName() { + // TODO Auto-generated method stub + return null; + } + + public int getLocalPort() { + // TODO Auto-generated method stub + return 0; + } + + public Map getParameterMap() { + // TODO Auto-generated method stub + return null; + } + + public int getRemotePort() { + // TODO Auto-generated method stub + return 0; + } + + public RequestDispatcher getRequestDispatcher(String arg0) { + // TODO Auto-generated method stub + return null; + } + + public boolean isSecure() { + // TODO Auto-generated method stub + return false; + } + + public void removeAttribute(String arg0) { + // TODO Auto-generated method stub + + } + + public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { + // TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/serializers/test/ServletRequestSerializerTest.java b/orkbasej/java/net/sf/oreka/serializers/test/ServletRequestSerializerTest.java new file mode 100644 index 0000000..08260fb --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/test/ServletRequestSerializerTest.java @@ -0,0 +1,45 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers.test; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import net.sf.oreka.OrkObject; +import net.sf.oreka.OrkObjectFactory; +import net.sf.oreka.messages.test.TestMessage; +import net.sf.oreka.serializers.ServletRequestSerializer; + +public class ServletRequestSerializerTest extends TestCase { + + public static void main (String[] args) { + junit.textui.TestRunner.run (suite()); + } + protected void setUp() { + OrkObjectFactory.instance().registerOrkObject(new TestMessage()); + } + public static Test suite() { + return new TestSuite(ServletRequestSerializerTest.class); + } + + public void testSerializeBasic() throws Exception + { + NullHttpServletRequest req = new NullHttpServletRequest(); + ServletRequestSerializer ser = new ServletRequestSerializer(); + req.setParameter("cmd", "test"); + req.setParameter("intParm", "45"); + OrkObject obj = ser.deSerialize(req); + assertTrue(((TestMessage)obj).getIntParm() == 45); + } +} diff --git a/orkbasej/java/net/sf/oreka/serializers/test/SingleLineSerializerTest.java b/orkbasej/java/net/sf/oreka/serializers/test/SingleLineSerializerTest.java new file mode 100644 index 0000000..5520626 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/test/SingleLineSerializerTest.java @@ -0,0 +1,172 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.serializers.test; + +import junit.framework.*; +import net.sf.oreka.*; +import net.sf.oreka.messages.*; +import net.sf.oreka.messages.test.TestMessage; +import net.sf.oreka.serializers.SingleLineSerializer; + +public class SingleLineSerializerTest extends TestCase +{ + public static void main (String[] args) { + junit.textui.TestRunner.run (suite()); + } + protected void setUp() { + OrkObjectFactory.instance().registerOrkObject(new TestMessage()); + } + public static Test suite() { + return new TestSuite(SingleLineSerializerTest.class); + } + + public void testSerializeBasic() throws Exception + { + String output = null; + + TestMessage msg = new TestMessage(); + SingleLineSerializer ser = new SingleLineSerializer(); + + msg.setIntParm(6); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("intparm=6") != -1); + + msg.setIntParm(-5); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("intparm=-5") != -1); + + msg.setDoubleParm(7.7); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("doubleparm=7.7") != -1); + + msg.setBoolParm(true); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("boolparm=true") != -1); + + msg.setStringParm("hello"); + output = ser.serialize(msg); + System.out.println("\noutput:" + output); + assertTrue(output.toLowerCase().indexOf("stringparm=hello") != -1); + } + + public void testDeSerializeBasic() throws Exception + { + String input; + SingleLineSerializer ser = new SingleLineSerializer(); + TestMessage msg; + + input = "class=test intparm=3"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.getIntParm() == 3); + + input = "class=test doubleparm=-14.6"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.getDoubleParm() == -14.6); + + input = "class=test boolparm=yes"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.isBoolParm()); + } + + public void testDeSerializeBoolean() throws Exception + { + String input; + SingleLineSerializer ser = new SingleLineSerializer(); + TestMessage msg; + + input = "class=test intparm=78 boolparm=no"; + msg = (TestMessage)ser.deSerialize(input); + assertFalse(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=0"; + msg = (TestMessage)ser.deSerialize(input); + assertFalse(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=false"; + msg = (TestMessage)ser.deSerialize(input); + assertFalse(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=true"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=yes"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=1"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.isBoolParm()); + + input = "class=test intparm=78 boolparm=asdf"; + boolean threw = false; + try { + msg = (TestMessage)ser.deSerialize(input); + } + catch (OrkException e) { + threw = true; + } + assertTrue(threw); + } + + public void testDeSerializeRequired() throws Exception + { + String input; + SingleLineSerializer ser = new SingleLineSerializer(); + TestMessage msg; + + input = "class=test"; + boolean threw = false; + try { + msg = (TestMessage)ser.deSerialize(input); + } + catch (OrkException e) { + threw = true; + } + assertTrue(threw); + } + + public void testEnum() throws Exception + { + // deserialize + String input; + SingleLineSerializer ser = new SingleLineSerializer(); + TestMessage msg; + + input = "class=test intparm=78 enumparm=value2"; + msg = (TestMessage)ser.deSerialize(input); + assertTrue(msg.getEnumParm() == TestMessage.TestEnum.value2); + + input = "class=test intparm=78 enumparm=garbage"; + boolean threw = false; + try { + msg = (TestMessage)ser.deSerialize(input); + } + catch (OrkException e) { + threw = true; + } + assertTrue(threw); + + // serialize + String output = null; + msg.setEnumParm(TestMessage.TestEnum.value3); + output = ser.serialize(msg); + assertTrue(output.toLowerCase().indexOf("enumparm=value3") != -1); + } + +} diff --git a/orkbasej/java/net/sf/oreka/serializers/test/TestMessageSimple.xml b/orkbasej/java/net/sf/oreka/serializers/test/TestMessageSimple.xml new file mode 100644 index 0000000..20347c4 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/test/TestMessageSimple.xml @@ -0,0 +1,5 @@ + + + 546 + + \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/serializers/test/TestNestedMessage.xml b/orkbasej/java/net/sf/oreka/serializers/test/TestNestedMessage.xml new file mode 100644 index 0000000..0309449 --- /dev/null +++ b/orkbasej/java/net/sf/oreka/serializers/test/TestNestedMessage.xml @@ -0,0 +1,6 @@ + + 546 + + hello + + \ No newline at end of file diff --git a/orkbasej/java/net/sf/oreka/test/FillDatabase.java b/orkbasej/java/net/sf/oreka/test/FillDatabase.java new file mode 100644 index 0000000..849af3c --- /dev/null +++ b/orkbasej/java/net/sf/oreka/test/FillDatabase.java @@ -0,0 +1,118 @@ +/* + * Oreka -- A media capture and retrieval platform + * + * Copyright (C) 2005, orecx LLC + * + * http://www.orecx.com + * + * This program is free software, distributed under the terms of + * the GNU General Public License. + * Please refer to http://www.gnu.org/copyleft/gpl.html + * + */ + +package net.sf.oreka.test; + +import java.util.Date; + +import net.sf.oreka.Direction; +import net.sf.oreka.HibernateManager; +import net.sf.oreka.persistent.LoginString; +import net.sf.oreka.persistent.RecProgram; +import net.sf.oreka.persistent.RecSegment; +import net.sf.oreka.persistent.RecTape; +import net.sf.oreka.persistent.Service; +import net.sf.oreka.persistent.User; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +public class FillDatabase { + + public static void main(String args[]) throws Exception + { + HibernateManager.configure("c:/oreka/test/mysql.hbm.xml"); + + Session hbnSession = HibernateManager.getSession(); + Transaction tx = hbnSession.beginTransaction(); + + Service service = new Service(); + service.setFileServePath(""); + service.setFileServeProtocol("http"); + service.setFileServeTcpPort(8080); + service.setHostname("localhost"); + service.setRecordMaster(true); + service.setName("orkaudio1"); + hbnSession.save(service); + + User user = new User(); + user.setFirstname("salisse"); + LoginString ls = new LoginString(); + ls.setUser(user); + ls.setLoginString("1973"); + hbnSession.save(user); + hbnSession.save(ls); + + // create program that does not filter anything + RecProgram prog1 = new RecProgram(); + hbnSession.save(prog1); + + // Create a bunch of segments + String lastParty = "123-234-5678"; + java.util.Random generator = new java.util.Random(); + for(int i=0; i<500; i++) { + RecSegment seg = new RecSegment(); + RecTape tape = new RecTape(); + + tape.setService(service); + tape.setFilename("f1.mp3"); + + Date date = new Date(new Date().getTime() - 600000 +(i*1000)); + seg.setTimestamp(date); + tape.setTimestamp(date); + + String randomString = "" + generator.nextInt(); + randomString = randomString.replace("-", "a"); + seg.setLocalParty(randomString); + seg.setRemoteParty(lastParty); + lastParty = randomString; + + float randomDirection = generator.nextFloat(); + if(randomDirection > .5){ + seg.setDirection(Direction.IN); + } + else { + seg.setDirection(Direction.OUT); + } + + long duration = (long)(generator.nextFloat()*60.0); + seg.setDuration(duration); + tape.setDuration(duration+1); + + seg.setRecTape(tape); + hbnSession.save(tape); + hbnSession.save(seg); + } + +// StringBuffer queryString = new StringBuffer("from RecSegment as seg "); +// Query query = hbnSession.createQuery(queryString.toString()); +// +// ScrollableResults scrollDocs = query.scroll(); +// scrollDocs.first(); +// +// while (scrollDocs.get()!= null) +// { +// RecSegment seg = (RecSegment)scrollDocs.get(0); +// //RecTape tape = (RecTape)scrollDocs.get(1); +// //RecTape tape = new RecTape(); +// System.out.println(seg.getId()); +// scrollDocs.next(); +// } + + tx.commit(); + hbnSession.close(); + + System.out.println("Done"); + } + +} -- cgit v1.2.3