Added:
trunk/opt/eecore3/
trunk/opt/eecore3/build.xml
trunk/opt/eecore3/cfg/
trunk/opt/eecore3/cfg/_hibernate.cfg.mappings
trunk/opt/eecore3/deploy/
trunk/opt/eecore3/src/
trunk/opt/eecore3/src/org/
trunk/opt/eecore3/src/org/jpos/
trunk/opt/eecore3/src/org/jpos/ee/
trunk/opt/eecore3/src/org/jpos/ee/BLException.java
trunk/opt/eecore3/src/org/jpos/ee/Cloneable.java
trunk/opt/eecore3/src/org/jpos/ee/Constants.k
trunk/opt/eecore3/src/org/jpos/ee/DB.java
trunk/opt/eecore3/src/org/jpos/ee/EEUtil.java
trunk/opt/eecore3/src/org/jpos/ee/K.java
trunk/opt/eecore3/src/org/jpos/ee/LoggeableSysLogEvent.java
trunk/opt/eecore3/src/org/jpos/ee/Permission.java
trunk/opt/eecore3/src/org/jpos/ee/ResultCode.hbm.xml
trunk/opt/eecore3/src/org/jpos/ee/ResultCode.java
trunk/opt/eecore3/src/org/jpos/ee/ResultCodeFinder.java
trunk/opt/eecore3/src/org/jpos/ee/ResultCodeInfo.java
trunk/opt/eecore3/src/org/jpos/ee/ResultCodeInfoFinder.java
trunk/opt/eecore3/src/org/jpos/ee/ResultCodeManager.java
trunk/opt/eecore3/src/org/jpos/ee/RevisionEntry.hbm.xml
trunk/opt/eecore3/src/org/jpos/ee/RevisionEntry.java
trunk/opt/eecore3/src/org/jpos/ee/RevisionManager.java
trunk/opt/eecore3/src/org/jpos/ee/StatusRevisionEntry.java
trunk/opt/eecore3/src/org/jpos/ee/SysConfig.hbm.xml
trunk/opt/eecore3/src/org/jpos/ee/SysConfig.java
trunk/opt/eecore3/src/org/jpos/ee/SysConfigManager.java
trunk/opt/eecore3/src/org/jpos/ee/SysLog.java
trunk/opt/eecore3/src/org/jpos/ee/SysLogEvent.hbm.xml
trunk/opt/eecore3/src/org/jpos/ee/SysLogEvent.java
trunk/opt/eecore3/src/org/jpos/ee/SysLogEventBase.java
trunk/opt/eecore3/src/org/jpos/ee/SystemDate.java
trunk/opt/eecore3/src/org/jpos/ee/User.hbm.xml
trunk/opt/eecore3/src/org/jpos/ee/User.java
trunk/opt/eecore3/src/org/jpos/ee/UserManager.java
trunk/opt/eecore3/src/org/jpos/ee/UserRevisionEntry.java
trunk/opt/eecore3/src/org/jpos/ee/Visitor.hbm.xml
trunk/opt/eecore3/src/org/jpos/ee/Visitor.java
trunk/opt/eecore3/src/org/jpos/ee/VisitorBase.java
trunk/opt/eecore3/src/org/jpos/ee/VisitorManager.java
trunk/opt/eecore3/src/org/jpos/ee/info/
trunk/opt/eecore3/src/org/jpos/ee/info/StartStop.java
trunk/opt/eecore3/src/org/jpos/ee/status/
trunk/opt/eecore3/src/org/jpos/ee/status/ChannelMonitor.java
trunk/opt/eecore3/src/org/jpos/ee/status/Heartbeat.java
trunk/opt/eecore3/src/org/jpos/ee/status/Monitor.java
trunk/opt/eecore3/src/org/jpos/ee/status/MonitorTask.java
trunk/opt/eecore3/src/org/jpos/ee/status/Ping.java
trunk/opt/eecore3/src/org/jpos/ee/status/Status.hbm.xml
trunk/opt/eecore3/src/org/jpos/ee/status/Status.java
trunk/opt/eecore3/src/org/jpos/ee/status/StatusBase.java
trunk/opt/eecore3/src/org/jpos/ee/status/StatusManager.java
trunk/opt/eecore3/src/org/jpos/ee/status/TwoWayMonitorTask.java
trunk/opt/eecore3/src/org/jpos/util/
trunk/opt/eecore3/src/org/jpos/util/BeanDiff.java
trunk/opt/eecore3/src/org/jpos/util/DateUtil.java
trunk/opt/eecore3/src/org/jpos/util/DiffEntry.java
Log:
eecore3 r1631
Added: trunk/opt/eecore3/build.xml
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/build.xml Thu Aug 2 15:12:12 2007
@@ -0,0 +1,65 @@
+<project name="jPOS-EE-SDK-eecore3" basedir="../..">
+ <property file="build.properties"/>
+ <property name="module.name" value="eecore3" />
+ <property name="dist.dir" value="dist"/>
+ <property name="build.dir" value="build"/>
+ <property name="modules.dir" value="modules"/>
+ <property name="build.src" value="${build.dir}/src"/>
+ <property name="build.lib" value="${build.dir}/lib"/>
+ <property name="build.cfg" value="${build.dir}/cfg"/>
+ <property name="classes.dir" value="${build.dir}/classes"/>
+ <property name="module.src.dir" value="${modules.dir}/${module.name}/src"/>
+ <property name="module.lib.dir" value="${modules.dir}/${module.name}/lib"/>
+ <property name="module.cfg.dir" value="${modules.dir}/${module.name}/cfg"/>
+ <property name="jpos.home" value="http://jpos.org/ee" />
+
+ <path id="main.classpath">
+ <fileset dir="${build.lib}">
+ <include name="*.jar"/>
+ </fileset>
+ <pathelement location="${classes.dir}"/>
+ </path>
+
+ <target name="prepare">
+ <filter filtersfile="${filter.properties}" />
+ <concat destfile="${build.src}/org/jpos/ee/Constants.tmp" append="false" force="true">
+ <header filtering="no" trimleading="yes"><![CDATA[package org.jpos.ee;
+ public interface Constants {]]>
+ </header>
+ <filterchain>
+ <expandproperties/>
+ </filterchain>
+ <path>
+ <fileset dir="${modules.dir}" excludesfile="${modules.ignore.list}">
+ <include name="**/*.k"/>
+ </fileset>
+ </path>
+ <footer filtering="no" trimleading="yes">}</footer>
+ </concat>
+ <copy file="${build.src}/org/jpos/ee/Constants.tmp"
+ tofile="${build.src}/org/jpos/ee/Constants.java"
+ filtering="true" />
+ <delete file="${build.src}/org/jpos/ee/Constants.tmp" />
+
+ <!-- Do the same with .p files, in order to create Constants.properties -->
+ <concat destfile="${build.src}/org/jpos/ee/Constants.tmp" append="false" force="true">
+ <header filtering="no" trimleading="yes"><![CDATA[#
+ # Autogenerated by jPOS-EE - do not edit
+ #
+ ]]></header>
+ <filterchain>
+ <expandproperties/>
+ </filterchain>
+ <path>
+ <fileset dir="${modules.dir}" excludesfile="${modules.ignore.list}">
+ <include name="**/*.p"/>
+ </fileset>
+ </path>
+ </concat>
+ <copy file="${build.src}/org/jpos/ee/Constants.tmp"
+ tofile="${build.src}/org/jpos/ee/Constants.properties"
+ filtering="true" />
+ <delete file="${build.src}/org/jpos/ee/Constants.tmp" />
+ </target>
+</project>
+
Added: trunk/opt/eecore3/cfg/_hibernate.cfg.mappings
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/cfg/_hibernate.cfg.mappings Thu Aug 2 15:12:12 2007
@@ -0,0 +1,9 @@
+
+ <mapping resource="org/jpos/ee/SysConfig.hbm.xml" />
+ <mapping resource="org/jpos/ee/SysLogEvent.hbm.xml" />
+ <mapping resource="org/jpos/ee/User.hbm.xml" />
+ <mapping resource="org/jpos/ee/Visitor.hbm.xml" />
+ <mapping resource="org/jpos/ee/RevisionEntry.hbm.xml" />
+ <mapping resource="org/jpos/ee/ResultCode.hbm.xml" />
+ <mapping resource="org/jpos/ee/status/Status.hbm.xml" />
+
Added: trunk/opt/eecore3/src/org/jpos/ee/BLException.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/BLException.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,101 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.io.PrintStream;
+import org.jpos.util.Loggeable;
+
+/**
+ * @author Alejandro P. Revilla
+ * @version $Revision: 1.5 $ $Date: 2004/12/09 19:45:33 $
+ *
+ * Business Logic Exception
+ */
+public class BLException extends Exception implements Loggeable {
+ Throwable nested = null;
+ String detail;
+
+ public BLException() {
+ super();
+ }
+ public BLException (String s) {
+ super (s);
+ }
+ public BLException (String s, String detail) {
+ super(s);
+ this.detail = detail;
+ }
+ public BLException (Throwable nested) {
+ super(nested.toString());
+ this.nested = nested;
+ }
+ public BLException (String s, Throwable nested) {
+ super(s);
+ this.nested = nested;
+ }
+ public BLException (String s, String detail, Throwable nested) {
+ super(s);
+ this.detail = detail;
+ this.nested = nested;
+ }
+ public Throwable getNested() {
+ return nested;
+ }
+ public String getDetail () {
+ return detail;
+ }
+ public String getDetailedMessage () {
+ StringBuffer sb = new StringBuffer (getMessage());
+
+ if (detail != null) {
+ sb.append (" (");
+ sb.append (detail);
+ sb.append (')');
+ }
+ return sb.toString();
+ }
+ public void dump (PrintStream p, String indent) {
+ String inner = indent + " ";
+ p.println (indent + "<bl-exception>");
+ p.println (inner + "<message>" + getMessage() + "</message>");
+ if (detail != null)
+ p.println (inner + "<detail>" + detail + "</detail>");
+ if (nested != null) {
+ if (nested instanceof Loggeable)
+ ((Loggeable)nested).dump (p, inner);
+ else {
+ p.println (inner + "<nested-exception>");
+ p.print (inner);
+ nested.printStackTrace (p);
+ p.println (inner + "</nested-exception>");
+ }
+ }
+ p.print (inner);
+ printStackTrace (p);
+ p.println (indent + "</bl-exception>");
+ }
+ public String toString() {
+ StringBuffer buf = new StringBuffer (super.toString());
+ if (nested != null)
+ buf.append (" (" + nested.toString() +")");
+ return buf.toString();
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/Cloneable.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/Cloneable.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,27 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+public class Cloneable implements java.lang.Cloneable {
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/Constants.k
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/Constants.k Thu Aug 2 15:12:12 2007
@@ -0,0 +1,3 @@
+ // eecore/src/org/jpos/ee/Constants.k
+ public static final String VERSION = "@version@";
+
Added: trunk/opt/eecore3/src/org/jpos/ee/DB.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/DB.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,160 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Iterator;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.JDBCException;
+import org.hibernate.Hibernate;
+import org.hibernate.Transaction;
+import org.hibernate.SessionFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.type.Type;
+import org.jpos.util.Log;
+import org.jpos.core.Sequencer;
+
+/**
+ * @author Alejandro P. Revilla
+ * @version $Revision: 1.5 $ $Date: 2004/12/09 00:50:14 $
+ *
+ * DB encapsulate some housekepping specific
+ * to Hibernate O/R mapping engine
+ */
+public class DB {
+ protected static SessionFactory sf;
+ protected static Configuration cfg;
+ Session session;
+ Log log;
+
+ static {
+ try {
+ init ();
+ } catch (Exception e) {
+ // now we're in deep trouble
+ e.printStackTrace();
+ }
+ }
+ public DB () {
+ super();
+ }
+ public DB (Log log) {
+ super ();
+ setLog (log);
+ }
+ private static void init () throws HibernateException {
+ synchronized (DB.class) {
+ if (cfg != null)
+ return;
+
+ cfg = new Configuration().configure();
+ sf = cfg.buildSessionFactory();
+ }
+ }
+ /**
+ * @return Hibernate's session factory
+ */
+ public SessionFactory getSessionFactory () {
+ return sf;
+ }
+ /**
+ * Creates database schema
+ * @param outputFile optional output file (may be null)
+ * @param create true to actually issue the create statements
+ */
+ public void createSchema (String outputFile, boolean create)
+ throws HibernateException
+ {
+ SchemaExport export = new SchemaExport (cfg);
+ if (outputFile != null) {
+ export.setOutputFile (outputFile);
+ export.setDelimiter (";");
+ }
+ export.create (true, create);
+ }
+ /**
+ * open a new HibernateSession if none exists
+ * @throws HibernateException
+ * @return HibernateSession associated with this DB object
+ */
+ public synchronized Session open () throws HibernateException {
+ if (session == null)
+ session = sf.openSession ();
+ return session;
+ }
+ /**
+ * close hibernate session
+ * @throws HibernateException
+ */
+ public synchronized void close () throws HibernateException {
+ if (session != null) {
+ session.close ();
+ session = null;
+ }
+ }
+ /**
+ * @return session hibernate Session
+ */
+ public Session session () {
+ return session;
+ }
+ /**
+ * handy method used to avoid having to call db.session().save (xxx)
+ * @param obj to save
+ */
+ public void save (Object obj) throws HibernateException {
+ session.save (obj);
+ }
+ /**
+ * @return newly created Transaction
+ * @throws HibernateException
+ */
+ public synchronized Transaction beginTransaction ()
+ throws HibernateException
+ {
+ return session.beginTransaction ();
+ }
+ /**
+ * @param timeout in seconds
+ * @return newly created Transaction
+ * @throws HibernateException
+ */
+ public synchronized Transaction beginTransaction (int timeout)
+ throws HibernateException
+ {
+ Transaction tx = session.beginTransaction ();
+ if (timeout > 0)
+ tx.setTimeout (timeout);
+ return tx;
+ }
+ public synchronized Log getLog () {
+ if (log == null)
+ log = Log.getLog ("Q2", "DB"); // Q2 standard Logger
+ return log;
+ }
+ public synchronized void setLog (Log log) {
+ this.log = log;
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/EEUtil.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/EEUtil.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,64 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import org.jpos.iso.ISOUtil;
+import java.util.Random;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * @author Alejandro P. Revilla
+ * @version $Revision: 1.5 $ $Date: 2004/12/09 19:45:33 $
+ *
+ * Assorted helpers
+ */
+public class EEUtil {
+ public static String getHash (String userName, String pass) {
+ String hash = null;
+ try {
+ MessageDigest md = MessageDigest.getInstance ("MD5");
+ md.update (userName.getBytes());
+ hash = ISOUtil.hexString (
+ md.digest (pass.getBytes())
+ ).toLowerCase();
+ } catch (NoSuchAlgorithmException e) {
+ // should never happen
+ }
+ return hash;
+ }
+ public static String getHash (String s) {
+ String hash = null;
+ try {
+ MessageDigest md = MessageDigest.getInstance ("MD5");
+ hash = ISOUtil.hexString (md.digest (s.getBytes())).toLowerCase();
+ } catch (NoSuchAlgorithmException e) {
+ // should never happen
+ }
+ return hash;
+ }
+ public static String getRandomHash () {
+ return getHash (
+ Double.toString (Math.random()),
+ Double.toString (Math.random())
+ );
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/K.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/K.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,40 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.util.ResourceBundle;
+
+public class K implements Constants {
+ protected static ResourceBundle rb =
+ ResourceBundle.getBundle(Constants.class.getName());
+
+ public static String get (String rn) {
+ try {
+ return rb.getString (rn);
+ } catch (Throwable t) {
+ // we don't care
+ }
+ return rn;
+ }
+ public static ResourceBundle getResourceBundle() {
+ return rb;
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/LoggeableSysLogEvent.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/LoggeableSysLogEvent.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,50 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee;
+import org.jpos.util.Loggeable;
+import java.io.PrintStream;
+
+public class LoggeableSysLogEvent implements Loggeable {
+ SysLogEvent evt;
+ public LoggeableSysLogEvent (SysLogEvent evt) {
+ this.evt = evt;
+ }
+ public void dump (PrintStream p, String indent) {
+ String newIndent = indent + " ";
+ p.println (indent + "<syslog-event>");
+ if (evt.isDeleted())
+ p.println (newIndent + "<deleted />" );
+ p.println (newIndent + "<date>" + evt.getDate() + "</date>");
+ p.println (newIndent + "<source>" + evt.getSource()+ "</source>");
+ p.println (newIndent + "<type>" + evt.getType() + "</type>");
+ p.println (newIndent
+ + "<severity>" + evt.getSeverityAsString () + "</severity>"
+ );
+ if (evt.getSummary() != null)
+ p.println (newIndent + "<summary>"+ evt.getSummary()+"</summary>");
+ if (evt.getDetail() != null)
+ p.println (newIndent + "<detail>" + evt.getDetail() + "</detail>");
+ if (evt.getTrace() != null)
+ p.println (newIndent + "<trace>" + evt.getTrace() + "</trace>");
+ p.println (indent + "</syslog-event>");
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/Permission.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/Permission.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,56 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.io.Serializable;
+
+public class Permission implements Serializable, Constants {
+ String name;
+ public Permission () {
+ super ();
+ setName ("");
+ }
+ public Permission (String name) {
+ super ();
+ setName (name);
+ }
+ public void setName (String name) {
+ this.name = name;
+ }
+ public String getName () {
+ return name;
+ }
+ public boolean equals (Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof Permission) {
+ return this.getName().equals (((Permission)obj).getName());
+ }
+ return false;
+ }
+ public String toString () {
+ return getName ();
+ }
+ public int hashCode() {
+ return name.hashCode ();
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/ResultCode.hbm.xml
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/ResultCode.hbm.xml Thu Aug 2 15:12:12 2007
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping
+ SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.jpos.ee.ResultCode" table="rc">
+ <id name="id" column="id" type="long">
+ <generator class="assigned" />
+ </id>
+ <property name="mnemonic" type="string" length="32">
+ <meta attribute="finder-method">findByMnemonic</meta>
+ <!-- column name="mnemonic" index="mnemonic" unique="true" /-->
+ <column name="mnemonic" unique="true" />
+ </property>
+ <property name="description" type="string" />
+
+ <map name="locales" lazy="true" table="rc_locale">
+ <key />
+ <index column="locale" type="string" length="32"/>
+ <composite-element class="org.jpos.ee.ResultCodeInfo">
+ <property name="resultCode" type="string" length="4" />
+ <property name="resultInfo" type="string" />
+ <property name="extendedResultCode" type="string" length="32" />
+ </composite-element>
+ </map>
+ </class>
+</hibernate-mapping>
+
Added: trunk/opt/eecore3/src/org/jpos/ee/ResultCode.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/ResultCode.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,79 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.Map;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+
+/** @author Hibernate CodeGenerator */
+public class ResultCode implements Serializable {
+
+ /** identifier field */
+ private Long id;
+
+ /** nullable persistent field */
+ private String mnemonic;
+
+ /** nullable persistent field */
+ private String description;
+
+ /** persistent field */
+ private Map locales;
+
+ /** full constructor */
+ public ResultCode(Long id, String mnemonic, String description, Map locales) {
+ this.id = id;
+ this.mnemonic = mnemonic;
+ this.description = description;
+ this.locales = locales;
+ }
+
+ /** default constructor */
+ public ResultCode() {
+ }
+
+ /** minimal constructor */
+ public ResultCode(Long id, Map locales) {
+ this.id = id;
+ this.locales = locales;
+ }
+
+ public Long getId() {
+ return this.id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getMnemonic() {
+ return this.mnemonic;
+ }
+
+ public void setMnemonic(String mnemonic) {
+ this.mnemonic = mnemonic;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Map getLocales() {
+ return this.locales;
+ }
+
+ public void setLocales(Map locales) {
+ this.locales = locales;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/ResultCodeFinder.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/ResultCodeFinder.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,27 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.List;
+import java.sql.SQLException;
+
+import org.hibernate.*;
+
+/** Automatically generated Finder class for ResultCodeFinder.
+ * @author Hibernate FinderGenerator **/
+public class ResultCodeFinder implements Serializable {
+
+ public static List findByMnemonic(Session session, java.lang.String mnemonic) throws SQLException, HibernateException {
+ Query q = session.createQuery (
+ "from org.jpos.ee.ResultCode as resultcode where resultcode.mnemonic=:mnemonic"
+ );
+ q.setParameter ("mnemonic", mnemonic);
+ return q.list();
+ }
+
+ public static List findAll(Session session) throws SQLException, HibernateException {
+ return session.createQuery(
+ "from ResultCode in class org.jpos.ee.ResultCode"
+ ).list();
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/ResultCodeInfo.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/ResultCodeInfo.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,59 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+
+/** @author Hibernate CodeGenerator */
+public class ResultCodeInfo implements Serializable {
+
+ /** nullable persistent field */
+ private String resultCode;
+
+ /** nullable persistent field */
+ private String resultInfo;
+
+ /** nullable persistent field */
+ private String extendedResultCode;
+
+ /** full constructor */
+ public ResultCodeInfo(String resultCode, String resultInfo, String extendedResultCode) {
+ this.resultCode = resultCode;
+ this.resultInfo = resultInfo;
+ this.extendedResultCode = extendedResultCode;
+ }
+
+ /** default constructor */
+ public ResultCodeInfo() {
+ }
+
+ public String getResultCode() {
+ return this.resultCode;
+ }
+
+ public void setResultCode(String resultCode) {
+ this.resultCode = resultCode;
+ }
+
+ public String getResultInfo() {
+ return this.resultInfo;
+ }
+
+ public void setResultInfo(String resultInfo) {
+ this.resultInfo = resultInfo;
+ }
+
+ public String getExtendedResultCode() {
+ return this.extendedResultCode;
+ }
+
+ public void setExtendedResultCode(String extendedResultCode) {
+ this.extendedResultCode = extendedResultCode;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/ResultCodeInfoFinder.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/ResultCodeInfoFinder.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,19 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.List;
+import java.sql.SQLException;
+
+import org.hibernate.*;
+import org.hibernate.type.Type;
+
+/** Automatically generated Finder class for ResultCodeInfoFinder.
+ * @author Hibernate FinderGenerator **/
+public class ResultCodeInfoFinder implements Serializable {
+
+ public static List findAll(Session session) throws SQLException, HibernateException {
+ return session.createQuery(
+ "from ResultCodeInfo in class org.jpos.ee.ResultCodeInfo"
+ ).list();
+ }
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/ResultCodeManager.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/ResultCodeManager.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,86 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.util.List;
+import java.util.Iterator;
+import java.sql.SQLException;
+import org.jpos.util.Logger;
+import org.jpos.util.LogEvent;
+import org.jpos.core.Configuration;
+import org.hibernate.Query;
+import org.hibernate.Transaction;
+import org.hibernate.HibernateException;
+import org.hibernate.ObjectNotFoundException;
+
+public class ResultCodeManager {
+ DB db;
+
+ public ResultCodeManager (DB db) {
+ super();
+ this.db = db;
+ }
+ public ResultCode get (long id) {
+ try {
+ return (ResultCode) db.session().load (
+ ResultCode.class, new Long(id)
+ );
+ } catch (ObjectNotFoundException e) {
+ LogEvent evt = db.getLog().createWarn ();
+ evt.addMessage ("error loading unconfigured result code " + id);
+ evt.addMessage (e);
+ Logger.log (evt);
+ } catch (HibernateException e) {
+ db.getLog().warn (e);
+ }
+ return null;
+ }
+ public ResultCode get (String rc) {
+ try {
+ List l = ResultCodeFinder.findByMnemonic (db.session(), rc);
+ if (l.size() == 0) {
+ LogEvent evt = db.getLog().createWarn ();
+ evt.addMessage (
+ "errorloading unconfigured result code '" + rc + "'"
+ );
+ Logger.log (evt);
+ } else {
+ return (ResultCode) l.get(0);
+ }
+ } catch (HibernateException e) {
+ db.getLog().warn (e);
+ } catch (SQLException e) {
+ db.getLog().warn (e);
+ }
+ return null;
+ }
+ public ResultCode get (String rc, ResultCode defRc) {
+ ResultCode resultCode = get (rc);
+ return resultCode != null ? resultCode : defRc;
+ }
+ public ResultCodeInfo getInfo (ResultCode rc, String locale) {
+ return (ResultCodeInfo) rc.getLocales().get(locale);
+ }
+ public ResultCodeInfo getInfo (String rc, String locale) {
+ ResultCode resultCode = get (rc);
+ return (resultCode != null) ? getInfo (resultCode, locale) : null;
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/RevisionEntry.hbm.xml
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/RevisionEntry.hbm.xml Thu Aug 2 15:12:12 2007
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping
+ SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.jpos.ee.RevisionEntry" table="revision"
+ discriminator-value=" ">
+ <id name="id" column="id" type="long">
+ <generator class="native" />
+ </id>
+ <discriminator column="subclass" type="string" length="16" />
+
+ <property name="date" type="timestamp" />
+ <property name="info" type="text" />
+ <many-to-one name="author" class="org.jpos.ee.User" column="author" />
+ <subclass name="org.jpos.ee.UserRevisionEntry"
+ discriminator-value="user">
+ <many-to-one name="user" class="org.jpos.ee.User" column="eeuser" />
+ </subclass>
+ <subclass name="org.jpos.ee.StatusRevisionEntry"
+ discriminator-value="status">
+ <many-to-one name="status" class="org.jpos.ee.status.Status"
+ column="status" />
+ </subclass>
+ <!--
+ <subclass name="org.jpos.ee.MerchantRevisionEntry"
+ discriminator-value="merchant">
+ <many-to-one name="merchant" class="org.jpos.ee.Merchant"
+ column="merchant" />
+ </subclass>
+ -->
+ </class>
+</hibernate-mapping>
+
Added: trunk/opt/eecore3/src/org/jpos/ee/RevisionEntry.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/RevisionEntry.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,72 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.Date;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+
+/** @author Hibernate CodeGenerator */
+public class RevisionEntry implements Serializable {
+
+ /** identifier field */
+ private Long id;
+
+ /** nullable persistent field */
+ private Date date;
+
+ /** nullable persistent field */
+ private String info;
+
+ /** nullable persistent field */
+ private org.jpos.ee.User author;
+
+ /** full constructor */
+ public RevisionEntry(Date date, String info, org.jpos.ee.User author) {
+ this.date = date;
+ this.info = info;
+ this.author = author;
+ }
+
+ /** default constructor */
+ public RevisionEntry() {
+ }
+
+ public Long getId() {
+ return this.id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Date getDate() {
+ return this.date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public String getInfo() {
+ return this.info;
+ }
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+
+ public org.jpos.ee.User getAuthor() {
+ return this.author;
+ }
+
+ public void setAuthor(org.jpos.ee.User author) {
+ this.author = author;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/RevisionManager.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/RevisionManager.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,73 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee;
+
+import java.util.Date;
+import java.beans.Expression;
+import java.beans.Introspector;
+import java.beans.Statement;
+
+public class RevisionManager {
+ DB db;
+ public RevisionManager (DB db) {
+ this.db = db;
+ }
+ /*
+ public RevisionEntry set
+ (Object obj, String propName, String newValue, User user)
+ throws BLException
+ {
+ try {
+ Expression expr = new Expression (
+ obj,Introspector.decapitalize ("get" + propName), new Object[0]
+ );
+ expr.execute();
+
+ String oldValue = (String) expr.getValue ();
+
+ if (oldValue == null) {
+ if (newValue == null)
+ return null;
+ } else {
+ if (oldValue.equals (newValue))
+ return null;
+ }
+ new Statement (
+ obj, Introspector.decapitalize ("set" + propName),
+ new Object[] { newValue }
+ ).execute ();
+
+ RevisionEntry re = new RevisionEntry ();
+ re.setDate (new Date());
+ re.setUser (user);
+ re.setProp (propName);
+ re.setOldValue ((String) expr.getValue ());
+ re.setNewValue (newValue);
+ db.save (re);
+ return re;
+ }
+ catch (Exception e) {
+ throw new BLException ("Error setting "+propName, e);
+ }
+ }
+ */
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/StatusRevisionEntry.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/StatusRevisionEntry.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,39 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.Date;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.jpos.ee.status.Status;
+
+
+/** @author Hibernate CodeGenerator */
+public class StatusRevisionEntry extends RevisionEntry implements Serializable {
+
+ /** nullable persistent field */
+ private Status status;
+
+ /** full constructor */
+ public StatusRevisionEntry(Date date, String info, org.jpos.ee.User author, Status status) {
+ super(date, info, author);
+ this.status = status;
+ }
+
+ /** default constructor */
+ public StatusRevisionEntry() {
+ }
+
+ public Status getStatus() {
+ return this.status;
+ }
+
+ public void setStatus(Status status) {
+ this.status = status;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/SysConfig.hbm.xml
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/SysConfig.hbm.xml Thu Aug 2 15:12:12 2007
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping
+ SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<hibernate-mapping package="org.jpos.ee">
+ <class name="SysConfig" table="sysconfig">
+ <id name="id" column="id" type="string" length="64">
+ <generator class="assigned" />
+ </id>
+ <property name="value" type="text">
+ <meta attribute="finder-method">findByValue</meta>
+ </property>
+ <property name="readPerm" type="string" length="32" />
+ <property name="writePerm" type="string" length="32" />
+ </class>
+</hibernate-mapping>
+
Added: trunk/opt/eecore3/src/org/jpos/ee/SysConfig.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/SysConfig.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,77 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+
+/** @author Hibernate CodeGenerator */
+public class SysConfig implements Serializable {
+
+ /** identifier field */
+ private String id;
+
+ /** nullable persistent field */
+ private String value;
+
+ /** nullable persistent field */
+ private String readPerm;
+
+ /** nullable persistent field */
+ private String writePerm;
+
+ /** full constructor */
+ public SysConfig(String id, String value, String readPerm, String writePerm) {
+ this.id = id;
+ this.value = value;
+ this.readPerm = readPerm;
+ this.writePerm = writePerm;
+ }
+
+ /** default constructor */
+ public SysConfig() {
+ }
+
+ /** minimal constructor */
+ public SysConfig(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getReadPerm() {
+ return this.readPerm;
+ }
+
+ public void setReadPerm(String readPerm) {
+ this.readPerm = readPerm;
+ }
+
+ public String getWritePerm() {
+ return this.writePerm;
+ }
+
+ public void setWritePerm(String writePerm) {
+ this.writePerm = writePerm;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/SysConfigManager.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/SysConfigManager.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,140 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.util.List;
+import java.util.Iterator;
+import org.jpos.core.Configuration;
+import org.hibernate.Query;
+import org.hibernate.Transaction;
+import org.hibernate.HibernateException;
+import org.hibernate.ObjectNotFoundException;
+
+public class SysConfigManager { // implements Configuration {
+ DB db;
+ String prefix = "";
+
+ public SysConfigManager() {
+ super();
+ db = new DB();
+ }
+ public SysConfigManager (DB db) {
+ super();
+ this.db = db;
+ }
+ public void setPrefix (String prefix) {
+ this.prefix = prefix;
+ }
+ public String getPrefix() {
+ return prefix;
+ }
+ public String get (String name, String defaultValue) {
+ try {
+ if (prefix != null)
+ name = prefix + name;
+ SysConfig cfg = (SysConfig) db.session().load (SysConfig.class, name);
+ return cfg.getValue();
+ } catch (ObjectNotFoundException e) {
+ // okay to happen
+ } catch (HibernateException e) {
+ db.getLog().warn (e);
+ }
+ return defaultValue;
+ }
+ public String[] getAll (String name) {
+ String[] values = null;
+ try {
+ if (prefix != null)
+ name = prefix + name;
+ Query query = db.session().createQuery (
+ "from sysconfig in class org.jpos.ee.SysConfig where id like :name order by id"
+ );
+ query.setParameter ("name", name);
+ List l = query.list();
+ values = new String[l.size()];
+ Iterator iter = l.iterator();
+ for (int i=0; iter.hasNext(); i++) {
+ values[i] = (String) iter.next();
+ }
+ } catch (HibernateException e) {
+ db.getLog().warn (e);
+ values = new String[0];
+ }
+ return values;
+ }
+ public void put (String name, String value) {
+ put (name, value, null, null);
+ }
+ public void put (String name, String value, String readPerm, String writePerm) {
+ SysConfig cfg = null;
+ if (prefix != null)
+ name = prefix + name;
+ try {
+ Transaction tx = db.beginTransaction();
+ try {
+ cfg = (SysConfig) db.session().get (SysConfig.class, name);
+ } catch (ObjectNotFoundException e) {
+ cfg = new SysConfig ();
+ cfg.setId (name);
+ cfg.setReadPerm (readPerm);
+ cfg.setWritePerm (writePerm);
+ db.session().save (cfg);
+ }
+ cfg.setValue (value);
+ tx.commit();
+ } catch (HibernateException e) {
+ db.getLog().warn (e);
+ }
+ }
+ public String get (String name) {
+ return get (name, "");
+ }
+ public int getInt (String name) {
+ return Integer.parseInt(get (name, "0").trim());
+ }
+ public int getInt (String name, int defaultValue) {
+ String value = get (name, null);
+ return value != null ? Integer.parseInt(value.trim()) : defaultValue;
+ }
+ public long getLong (String name) {
+ return Long.parseLong(get (name, "0").trim());
+ }
+ public long getLong (String name, long defaultValue) {
+ String value = get (name, null);
+ return value != null ? Long.parseLong(value.trim()) : defaultValue;
+ }
+ public double getDouble (String name) {
+ return Double.parseDouble(get (name, "0.00").trim());
+ }
+ public double getDouble (String name, double defaultValue) {
+ String value = get (name, null);
+ return value != null ? Double.parseDouble(value.trim()) : defaultValue;
+ }
+ public boolean getBoolean (String name) {
+ String v = get (name, "false").trim();
+ return v.equalsIgnoreCase("true") || v.equalsIgnoreCase("yes");
+ }
+ public boolean getBoolean (String name, boolean def) {
+ String v = get (name);
+ return v.length() == 0 ? def :
+ (v.equalsIgnoreCase("true") || v.equalsIgnoreCase("yes"));
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/SysLog.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/SysLog.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,173 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee;
+
+import java.util.Date;
+import org.jpos.util.Log;
+import org.jpos.util.Logger;
+import org.jpos.util.LogEvent;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
+/**
+ * Helper class used to log entries in the SysLog.
+ */
+public class SysLog {
+ DB db;
+ boolean autoCommit;
+ public static final int DEBUG = 0;
+ public static final int TRACE = 1;
+ public static final int INFO = 2;
+ public static final int WARN = 3;
+ public static final int ERROR = 4;
+ public static final int CRITICAL = 5;
+
+ /**
+ * create a SysLog object with auto commit on.
+ * (open/begin/commit/close is not required).
+ */
+ public SysLog () {
+ super ();
+ db = new DB();
+ autoCommit = true;
+ }
+ /**
+ * create a SysLog object with auto commit off.
+ * User is responsible for openning the underlying session
+ * and committing the transaction.
+ */
+ public SysLog (DB db) {
+ super();
+ this.db = db;
+ autoCommit = false;
+ }
+ /**
+ * @param autoCommit set autocommit mode
+ */
+ public void setAutocommit (boolean autoCommit) {
+ this.autoCommit = autoCommit;
+ }
+ /**
+ * @return auto commit mode
+ */
+ public boolean isAutoCommit() {
+ return autoCommit;
+ }
+
+ /**
+ * Create a SysLogEvent and add it to the DB.
+ * If auto commit is on, then the operation is performed
+ * within a transaction, otherwise, it's up to the user
+ * to commit or flush the session.
+ * @param source this log event source
+ * @param type application specific event type (i.e. INFO, WARN, ERROR, ...)
+ * @param severity either DEBUG, TRACE, INFO, WARN, ERROR or CRITICAL
+ * @param summary summary information
+ * @param detail optional detail information
+ * @param trace optional trace information
+ * @return the newly created SysLogEvent
+ */
+ public SysLogEvent log (String source, String type, int severity,
+ String summary, String detail, String trace)
+ {
+ SysLogEvent evt = new SysLogEvent ();
+ try {
+ evt.setDate (new Date());
+ evt.setSource (source);
+ evt.setType (type);
+ evt.setSeverity (severity);
+ evt.setSummary (summary);
+ evt.setDetail (detail);
+ evt.setTrace (trace);
+
+ boolean autoClose = false;
+ if (autoCommit && db.session() == null) {
+ db.open ();
+ autoClose = true;
+ }
+ if (autoCommit) {
+ Transaction tx = db.beginTransaction ();
+ db.session().save (evt);
+ tx.commit ();
+ } else {
+ db.session().save (evt);
+ }
+ if (autoClose)
+ db.close ();
+ } catch (Throwable t) {
+ errorLog (evt, t);
+ }
+ return evt;
+ }
+ /**
+ * Create a SysLogEvent and add it to the DB.
+ * If auto commit is on, then the operation is performed
+ * within a transaction, otherwise, it's up to the user
+ * to commit or flush the session.
+ * @param source this log event source
+ * @param type application specific event type (i.e. INFO, WARN, ERROR, ...)
+ * @param severity either DEBUG, TRACE, INFO, WARN, ERROR or CRITICAL
+ * @param summary summary information
+ * @param detail optional detail information
+ * @return the newly created SysLogEvent
+ */
+ public SysLogEvent log (String source, String type, int severity,
+ String summary, String detail)
+ {
+ return log (source, type, severity, summary, detail, null);
+ }
+ /**
+ * Create a SysLogEvent and add it to the DB.
+ * If auto commit is on, then the operation is performed
+ * within a transaction, otherwise, it's up to the user
+ * to commit or flush the session.
+ * @param source this log event source
+ * @param type application specific event type (i.e. INFO, WARN, ERROR, ...)
+ * @param severity either DEBUG, TRACE, INFO, WARN, ERROR or CRITICAL
+ * @param summary summary information
+ * @return the newly created SysLogEvent
+ */
+ public SysLogEvent log
+ (String source, String type, int severity, String summary)
+ {
+ return log (source, type, severity, summary, null, null);
+ }
+ private void errorLog (SysLogEvent evt, Throwable t) {
+ LogEvent ev = db.getLog().createError ();
+ ev.addMessage (new LoggeableSysLogEvent (evt));
+ ev.addMessage (t);
+ Logger.log (ev);
+ }
+ /**
+ * @param event id
+ * @return log event
+ */
+ public SysLogEvent get (long id) {
+ try {
+ return (SysLogEvent)
+ db.session().load (SysLogEvent.class, new Long (id));
+ } catch (Throwable e) {
+ db.getLog().error (e);
+ }
+ return null;
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/SysLogEvent.hbm.xml
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/SysLogEvent.hbm.xml Thu Aug 2 15:12:12 2007
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping
+ SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.jpos.ee.SysLogEvent" table="syslog">
+ <meta attribute="extends">org.jpos.ee.SysLogEventBase</meta>
+ <id name="id" column="id" type="long">
+ <generator class="native" />
+ </id>
+ <property name="date" type="timestamp" />
+ <property name="deleted" type="boolean" />
+ <property name="source" type="string" length="32" />
+ <property name="type" type="string" length="32" />
+ <property name="severity" type="int" />
+ <property name="summary" type="string" length="255" />
+ <property name="detail" type="text" />
+ <property name="trace" type="text" />
+ </class>
+</hibernate-mapping>
+
Added: trunk/opt/eecore3/src/org/jpos/ee/SysLogEvent.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/SysLogEvent.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,132 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.Date;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+
+/** @author Hibernate CodeGenerator */
+public class SysLogEvent extends org.jpos.ee.SysLogEventBase implements Serializable {
+
+ /** identifier field */
+ private Long id;
+
+ /** nullable persistent field */
+ private Date date;
+
+ /** nullable persistent field */
+ private boolean deleted;
+
+ /** nullable persistent field */
+ private String source;
+
+ /** nullable persistent field */
+ private String type;
+
+ /** nullable persistent field */
+ private int severity;
+
+ /** nullable persistent field */
+ private String summary;
+
+ /** nullable persistent field */
+ private String detail;
+
+ /** nullable persistent field */
+ private String trace;
+
+ /** full constructor */
+ public SysLogEvent(Date date, boolean deleted, String source, String type, int severity, String summary, String detail, String trace) {
+ this.date = date;
+ this.deleted = deleted;
+ this.source = source;
+ this.type = type;
+ this.severity = severity;
+ this.summary = summary;
+ this.detail = detail;
+ this.trace = trace;
+ }
+
+ /** default constructor */
+ public SysLogEvent() {
+ }
+
+ public Long getId() {
+ return this.id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Date getDate() {
+ return this.date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public boolean isDeleted() {
+ return this.deleted;
+ }
+
+ public void setDeleted(boolean deleted) {
+ this.deleted = deleted;
+ }
+
+ public String getSource() {
+ return this.source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public int getSeverity() {
+ return this.severity;
+ }
+
+ public void setSeverity(int severity) {
+ this.severity = severity;
+ }
+
+ public String getSummary() {
+ return this.summary;
+ }
+
+ public void setSummary(String summary) {
+ this.summary = summary;
+ }
+
+ public String getDetail() {
+ return this.detail;
+ }
+
+ public void setDetail(String detail) {
+ this.detail = detail;
+ }
+
+ public String getTrace() {
+ return this.trace;
+ }
+
+ public void setTrace(String trace) {
+ this.trace = trace;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/SysLogEventBase.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/SysLogEventBase.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,40 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee;
+
+public abstract class SysLogEventBase {
+ public static final String[] severityAsString =
+ new String[] { "debug", "trace", "info", "warn", "error", "critical" };
+
+ public abstract int getSeverity();
+
+ /**
+ * @param severity the severity
+ * @return DEBUG, TRACE, INFO, WARN, ERROR, CRITICAL or severity'a value
+ */
+ public String getSeverityAsString () {
+ if (getSeverity() > SysLog.CRITICAL)
+ return Integer.toString (getSeverity());
+ else
+ return severityAsString [getSeverity()];
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/SystemDate.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/SystemDate.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,30 @@
+package org.jpos.ee;
+
+import java.util.Date;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+public class SystemDate {
+ static long offset = 0L;
+ public static Date getDate() {
+ return new Date (System.currentTimeMillis() + offset);
+ }
+ public static void forceDate (Date d) {
+ offset = d.getTime() - System.currentTimeMillis();
+ }
+ public static Calendar getCalendar() {
+ Calendar cal = new GregorianCalendar();
+ cal.setTime (getDate());
+ return cal;
+ }
+ public static long getOffset() {
+ return offset;
+ }
+ public static void resetOffset() {
+ this.offset = 0L;
+ }
+ public static long currentTimeMillis() {
+ return System.currentTimeMillis() + offset;
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/User.hbm.xml
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/User.hbm.xml Thu Aug 2 15:12:12 2007
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping
+ SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.jpos.ee.User" table="eeuser">
+ <id name="id" column="id" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="nick" type="string">
+ <column name="nick" sql-type="varchar(32)" unique="true" not-null="true" />
+ </property>
+ <property name="password" length="32" type="string" />
+ <property name="name" length="128" not-null="false" type="string" />
+ <property name="deleted" type="boolean" />
+
+ <set name="permissions" lazy="false" table="eeuser_perms" cascade="delete">
+ <key column="eeuser" />
+ <composite-element class="org.jpos.ee.Permission">
+ <property name="name" type="string">
+ <column name="name" sql-type="varchar(64)" not-null="true" />
+ </property>
+ </composite-element>
+ </set>
+
+ <map name="props" lazy="true" table="eeuser_props"
+ cascade="all-delete-orphan">
+ <key />
+ <index column="propName" type="string" length="32"/>
+ <element column="propValue" type="string"/>
+ </map>
+
+ <set name="visitors" cascade="all-delete-orphan" lazy="true">
+ <key column="eeuser" />
+ <one-to-many class="org.jpos.ee.Visitor" />
+ </set>
+
+ <list name="revisions" lazy="true" cascade="all-delete-orphan">
+ <key column="eeuser" />
+ <index column="posn" />
+ <one-to-many class="org.jpos.ee.UserRevisionEntry" />
+ </list>
+
+ </class>
+</hibernate-mapping>
+
Added: trunk/opt/eecore3/src/org/jpos/ee/User.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/User.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,174 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.List;
+import java.util.Date;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Iterator;
+import java.io.Serializable;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.EqualsBuilder;
+
+public class User extends Cloneable implements Serializable {
+ private long id;
+ private String nick;
+ private String password;
+ private String name;
+ private Set perms;
+ private Map props;
+ private Set visitors;
+ private List revisions;
+ private boolean deleted;
+
+ public User() {
+ super();
+ perms = new LinkedHashSet ();
+ visitors = new LinkedHashSet ();
+ }
+ public String getNick() {
+ return nick;
+ }
+ public void setNick (String nick) {
+ this.nick = nick;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public long getId() {
+ return id;
+ }
+ public void setId (long id) {
+ this.id = id;
+ }
+ public void setPassword (String password) {
+ this.password = password;
+ }
+ public String getPassword () {
+ return password;
+ }
+ public void setDeleted (boolean deleted) {
+ this.deleted = deleted;
+ }
+ public boolean isDeleted() {
+ return deleted;
+ }
+ public void setPermissions (Set perms) {
+ this.perms = perms;
+ }
+ public Set getPermissions () {
+ return perms;
+ }
+ public void setVisitors (Set visitors) {
+ this.visitors = visitors;
+ }
+ public Set getVisitors () {
+ return visitors;
+ }
+ public boolean hasPermission (String permName) {
+ return permName != null ? perms.contains (new Permission (permName)) : false;
+ }
+ public void grant (String permName) {
+ perms.add (new Permission (permName));
+ }
+ public void revoke (String permName) {
+ perms.remove (new Permission (permName));
+ }
+ public void revokeAll () {
+ perms.clear ();
+ }
+ public void setProps (Map props) {
+ this.props = props;
+ }
+ public Map getProps () {
+ return (props = props == null ? new HashMap () : props);
+ }
+ public void set (String prop, String value) {
+ getProps().put (prop, value);
+ }
+ public String get (String prop) {
+ return (String) getProps().get (prop);
+ }
+ public String get (String prop, String defValue) {
+ String value = (String) getProps().get (prop);
+ return value == null ? defValue : value;
+ }
+ public void setRevisions (List revisions) {
+ this.revisions = revisions;
+ }
+ public List getRevisions () {
+ if (revisions == null)
+ revisions = new ArrayList();
+ return revisions;
+ }
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .append("nick", getNick())
+ .toString();
+ }
+ public boolean equals(Object other) {
+ if ( !(other instanceof User) ) return false;
+ User castOther = (User) other;
+ return new EqualsBuilder()
+ .append(this.getId(), castOther.getId())
+ .isEquals();
+ }
+ public int hashCode() {
+ return new HashCodeBuilder()
+ .append(getId())
+ .toHashCode();
+ }
+ /**
+ * factory method used to create a RevisionEntry associated with this user.
+ *
+ * @param summary information
+ * @param detail detailed information
+ * @param author change author
+ */
+ public UserRevisionEntry logRevision (String info, User author) {
+ UserRevisionEntry re = new UserRevisionEntry();
+ re.setDate (new Date());
+ re.setInfo (info);
+ re.setUser (this);
+ re.setAuthor (author);
+ getRevisions().add (re);
+ return re;
+ }
+ /**
+ * @return "nick(id)"
+ */
+ public String getNickAndId() {
+ StringBuffer sb = new StringBuffer (getNick());
+ sb.append ('(');
+ sb.append (Long.toString(getId()));
+ sb.append (')');
+ return sb.toString();
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/UserManager.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/UserManager.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,112 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.util.List;
+import org.hibernate.Criteria;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.criterion.Expression;
+import org.hibernate.Session;
+
+/**
+ * @author Alejandro Revilla
+ */
+public class UserManager {
+ Session session;
+ String digest;
+
+ public UserManager (DB db) {
+ super ();
+ this.session = db.session();
+ }
+ public UserManager (Session session) {
+ super ();
+ this.session = session;
+ }
+ public User getUserByNick (String nick, boolean includeDeleted)
+ throws HibernateException
+ {
+ try {
+ Criteria crit = session.createCriteria (User.class)
+ .add (Expression.eq ("nick", nick));
+ if (!includeDeleted)
+ crit = crit.add (Expression.eq ("deleted", Boolean.FALSE));
+ return (User) crit.uniqueResult();
+ } catch (ObjectNotFoundException e) { }
+ return null;
+ }
+ public User getUserByNick (String nick)
+ throws HibernateException
+ {
+ return getUserByNick (nick, false);
+ }
+ /**
+ * @param nick name.
+ * @param seed initial seed
+ * @param pass hash
+ * @throws BLException if invalid user/pass
+ */
+ public User getUserByNick (String nick, String seed, String pass)
+ throws HibernateException, BLException
+ {
+ User u = getUserByNick (nick);
+ assertNotNull (u, "User does not exist");
+ assertTrue (checkPassword (u, seed, pass), "Invalid password");
+ return u;
+ }
+ /**
+ * @param nick name.
+ * @param seed initial seed
+ * @param pass hash
+ * @return true if password matches
+ * @throws BLException if invalid user/pass
+ */
+ public boolean checkPassword (User u, String seed, String pass)
+ throws HibernateException, BLException
+ {
+ assertNotNull (seed, "Invalid seed");
+ assertNotNull (pass, "Invalid pass");
+ String password = u.getPassword();
+ assertNotNull (password, "Password is null");
+ String computedPass = EEUtil.getHash (seed, password);
+ return pass.equals (computedPass);
+ }
+ /**
+ * @return all users
+ */
+ public List findAll () throws HibernateException {
+ return session.createCriteria (User.class)
+ .add (Expression.eq ("deleted", Boolean.FALSE))
+ .list();
+ }
+ private void assertNotNull (Object obj, String error) throws BLException {
+ if (obj == null)
+ throw new BLException (error);
+ }
+ private void assertTrue (boolean condition, String error)
+ throws BLException
+ {
+ if (!condition)
+ throw new BLException (error);
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/UserRevisionEntry.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/UserRevisionEntry.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,38 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.Date;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+
+/** @author Hibernate CodeGenerator */
+public class UserRevisionEntry extends RevisionEntry implements Serializable {
+
+ /** nullable persistent field */
+ private org.jpos.ee.User user;
+
+ /** full constructor */
+ public UserRevisionEntry(Date date, String info, org.jpos.ee.User author, org.jpos.ee.User user) {
+ super(date, info, author);
+ this.user = user;
+ }
+
+ /** default constructor */
+ public UserRevisionEntry() {
+ }
+
+ public org.jpos.ee.User getUser() {
+ return this.user;
+ }
+
+ public void setUser(org.jpos.ee.User user) {
+ this.user = user;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/Visitor.hbm.xml
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/Visitor.hbm.xml Thu Aug 2 15:12:12 2007
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping
+ SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.jpos.ee.Visitor" table="visitor">
+ <meta attribute="extends">org.jpos.ee.VisitorBase</meta>
+ <id name="id" column="id" type="string" length="32">
+ <generator class="assigned" />
+ </id>
+ <property name="lastUpdate" type="timestamp" />
+ <many-to-one name="user"
+ class="org.jpos.ee.User"
+ column="eeuser" />
+ <map name="props" lazy="true" table="visitor_props">
+ <key />
+ <index column="propName" type="string" length="32"/>
+ <element column="propValue" type="string"/>
+ </map>
+ </class>
+</hibernate-mapping>
+
Added: trunk/opt/eecore3/src/org/jpos/ee/Visitor.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/Visitor.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,80 @@
+package org.jpos.ee;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Map;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+
+/** @author Hibernate CodeGenerator */
+public class Visitor extends org.jpos.ee.VisitorBase implements Serializable {
+
+ /** identifier field */
+ private String id;
+
+ /** nullable persistent field */
+ private Date lastUpdate;
+
+ /** nullable persistent field */
+ private org.jpos.ee.User user;
+
+ /** persistent field */
+ private Map props;
+
+ /** full constructor */
+ public Visitor(String id, Date lastUpdate, org.jpos.ee.User user, Map props) {
+ this.id = id;
+ this.lastUpdate = lastUpdate;
+ this.user = user;
+ this.props = props;
+ }
+
+ /** default constructor */
+ public Visitor() {
+ }
+
+ /** minimal constructor */
+ public Visitor(String id, Map props) {
+ this.id = id;
+ this.props = props;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public Date getLastUpdate() {
+ return this.lastUpdate;
+ }
+
+ public void setLastUpdate(Date lastUpdate) {
+ this.lastUpdate = lastUpdate;
+ }
+
+ public org.jpos.ee.User getUser() {
+ return this.user;
+ }
+
+ public void setUser(org.jpos.ee.User user) {
+ this.user = user;
+ }
+
+ public Map getProps() {
+ return this.props;
+ }
+
+ public void setProps(Map props) {
+ this.props = props;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/VisitorBase.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/VisitorBase.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,39 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee;
+
+import java.util.Map;
+
+public abstract class VisitorBase {
+ public abstract Map getProps ();
+
+ public void set (String prop, String value) {
+ getProps().put (prop, value);
+ }
+ public String get (String prop) {
+ return (String) getProps().get (prop);
+ }
+ public String get (String prop, String defValue) {
+ String value = (String) getProps().get (prop);
+ return value == null ? defValue : value;
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/VisitorManager.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/VisitorManager.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,102 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Date;
+import java.util.Set;
+import java.util.HashMap;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.Session;
+import org.jpos.iso.ISOUtil;
+import javax.servlet.http.Cookie;
+
+
+/**
+ * @author Alejandro Revilla
+ */
+public class VisitorManager {
+ Session session;
+ String digest;
+ public static final String COOKIE_NAME = "JPOSEE";
+ public static final int COOKIE_EXPIRATION = 365*24*3600;
+
+ public VisitorManager (Session session) {
+ super ();
+ this.session = session;
+ }
+ public VisitorManager (Session session, Cookie[] cookies) {
+ this (session);
+ if (cookies != null)
+ init (cookies);
+ }
+ private void init (Cookie[] cookies) {
+ for (int i=0; i<cookies.length; i++) {
+ if (COOKIE_NAME.equals (cookies[i].getName()))
+ digest = cookies[i].getValue();
+ }
+ if (digest == null)
+ digest = EEUtil.getRandomHash();
+ }
+ public Cookie getCookie () {
+ Cookie cookie = new Cookie (COOKIE_NAME, digest);
+ // cookie.setPath ("/");
+ cookie.setMaxAge (COOKIE_EXPIRATION);
+ return cookie;
+ }
+ public Visitor getVisitor ()
+ throws HibernateException
+ {
+ try {
+ Visitor v = (Visitor) session.load (Visitor.class, digest);
+ if (v != null)
+ v.setLastUpdate(new Date()); // force proxy to actually load the object
+ return v;
+ } catch (ObjectNotFoundException e) { }
+ return null;
+ }
+ public Visitor getVisitor (boolean create)
+ throws HibernateException
+ {
+ Visitor visitor = getVisitor ();
+ if (visitor == null && create) {
+ visitor = new Visitor();
+ visitor.setId (digest);
+ visitor.setProps (new HashMap ());
+ visitor.setLastUpdate (new Date());
+ session.save (visitor);
+ }
+ return visitor;
+ }
+ public void set (Visitor visitor, String prop, String value)
+ throws HibernateException
+ {
+ visitor.getProps().put (prop, value);
+ }
+ public void update (Visitor visitor)
+ throws HibernateException
+ {
+ visitor.setLastUpdate (new Date());
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/info/StartStop.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/info/StartStop.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,41 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee.info;
+
+import org.jpos.ee.SysLog;
+import org.jpos.q2.QBeanSupport;
+
+public class StartStop extends QBeanSupport {
+ long start;
+ public void startService() {
+ start = System.currentTimeMillis();
+ new SysLog().log (cfg.get ("source", getName()),
+ "SYSTEM", SysLog.INFO, "Start");
+ }
+ public void stopService() {
+ long elapsed = System.currentTimeMillis() - start;
+ new SysLog().log (cfg.get ("source", getName()),
+ "SYSTEM", SysLog.INFO, "Stop",
+ "time up: " + elapsed / 1000 + " secs."
+ );
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/ChannelMonitor.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/ChannelMonitor.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,74 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2005 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee.status;
+
+import java.net.Socket;
+import java.io.IOException;
+import org.jpos.core.Configurable;
+import org.jpos.core.Configuration;
+import org.jpos.core.ConfigurationException;
+import org.jpos.util.Log;
+import org.jpos.util.NameRegistrar;
+import org.jpos.q2.iso.ChannelAdaptor;
+
+public class ChannelMonitor extends Log implements TwoWayMonitorTask, Configurable {
+ Configuration cfg;
+ String serviceName;
+ public String checkService () {
+ boolean rc = false;
+ ChannelAdaptor channel;
+ try {
+ channel = (ChannelAdaptor) NameRegistrar.get (serviceName);
+ } catch (NameRegistrar.NotFoundException e) {
+ return Status.ERROR + " channel '" + serviceName + "' not found.";
+ }
+ if (channel.isConnected())
+ return Status.OK + " Connected";
+ else
+ return Status.ERROR + " Not connected";
+ }
+ public String command (String command) {
+ String response = "Unknown command";
+ ChannelAdaptor channel;
+ try {
+ channel = (ChannelAdaptor) NameRegistrar.get (serviceName);
+ } catch (NameRegistrar.NotFoundException e) {
+ return "Channel '" + serviceName + "' not found";
+ }
+ if ("STOP".equalsIgnoreCase (command)) {
+ channel.stop();
+ response = "Channel stopped";
+ } else if ("START".equalsIgnoreCase (command)) {
+ channel.start();
+ response = "Channel started";
+ }
+ return response;
+ }
+ public void setConfiguration (Configuration cfg)
+ throws ConfigurationException
+ {
+ this.cfg = cfg;
+ serviceName = cfg.get ("channel", null);
+ if (serviceName == null)
+ throw new ConfigurationException ("property 'channel' is null");
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/Heartbeat.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/Heartbeat.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,106 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2005 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee.status;
+
+import java.util.Date;
+import java.sql.SQLException;
+import org.hibernate.Transaction;
+import org.hibernate.HibernateException;
+
+import org.jpos.ee.DB;
+import org.jpos.q2.QBeanSupport;
+import org.jpos.iso.ISOUtil;
+import org.jpos.util.DateUtil;
+
+public class Heartbeat extends QBeanSupport implements Runnable {
+ DB db;
+ StatusManager mgr;
+ long interval;
+ String statusId;
+
+ public void initService () throws Exception {
+ db = new DB();
+ mgr = new StatusManager (db);
+ interval = cfg.getLong ("interval", 60000L);
+ initStatus();
+ }
+ public void startService() {
+ new Thread (this).start();
+ }
+ public void run() {
+ long start = System.currentTimeMillis();
+ for (int i=1; running(); i++) {
+ try {
+ db.open ();
+ mgr.check ();
+ mgr.touch (statusId, Status.OK, getDetail (start, i));
+ Thread.sleep (interval);
+ } catch (Throwable t) {
+ getLog().error (t);
+ ISOUtil.sleep (1000);
+ } finally {
+ close();
+ }
+ }
+ }
+ private void close() {
+ try {
+ db.close();
+ } catch (HibernateException e) {
+ getLog().error (e);
+ }
+ }
+ private String getDetail (long start, int tick) {
+ Runtime r = Runtime.getRuntime();
+ StringBuffer sb = new StringBuffer();
+ sb.append ("memory=");
+ sb.append (r.totalMemory());
+ sb.append (", threads=");
+ sb.append (Thread.activeCount());
+ sb.append (", uptime=");
+ sb.append (DateUtil.toDays (System.currentTimeMillis() - start));
+ sb.append (", tick=");
+ sb.append (tick);
+ return sb.toString();
+ }
+ private void initStatus()
+ throws HibernateException, SQLException
+ {
+ try {
+ db.open ();
+ statusId = cfg.get ("status-id", getName());
+ Status s = mgr.getStatus (statusId, false);
+ if (s == null) {
+ Transaction tx = db.beginTransaction();
+ s = mgr.getStatus (statusId, true);
+ s.setName (cfg.get ("status-name", statusId));
+ s.setGroupName (cfg.get ("status-group", ""));
+ s.setTimeoutState (cfg.get ("on-timeout", Status.OFF));
+ s.setTimeout (cfg.getLong ("status-timeout", 360000L));
+ s.setLastTick (new Date());
+ tx.commit();
+ }
+ } finally {
+ close();
+ }
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/Monitor.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/Monitor.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,160 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2005 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee.status;
+
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.Iterator;
+import java.util.ArrayList;
+import org.jpos.ee.DB;
+import org.jpos.q2.QFactory;
+import org.jpos.q2.QBeanSupport;
+import org.jpos.iso.ISOUtil;
+import org.jpos.util.DateUtil;
+import org.jpos.core.XmlConfigurable;
+import org.jpos.core.ConfigurationException;
+import org.jdom.Element;
+import org.hibernate.HibernateException;
+
+public class Monitor extends QBeanSupport implements XmlConfigurable {
+ DB db;
+ StatusManager mgr;
+ long interval;
+ String statusId;
+ Element config;
+ Timer timer;
+
+ public void initService () {
+ db = new DB();
+ mgr = new StatusManager (db);
+ timer = new Timer (true);
+ Iterator iter = config.getChildren ("monitor").iterator();
+ List handlers = new ArrayList();
+ while (iter.hasNext()) {
+ Element e = (Element) iter.next();
+ try {
+ registerTask (e);
+ } catch (ConfigurationException ex) {
+ getLog().error (ex);
+ }
+ }
+ }
+ public void destroyService() {
+ getLog().info ("Cancelling timer");
+ timer.cancel();
+ }
+ private void close() {
+ try {
+ db.close();
+ } catch (HibernateException e) {
+ getLog().error (e);
+ }
+ }
+ public void setConfiguration (Element config) {
+ this.config = config;
+ }
+ private void registerTask (Element e)
+ throws ConfigurationException
+ {
+ QFactory qf = getServer().getFactory();
+ Object obj = qf.newInstance (e.getChildTextTrim ("class"));
+ if (!(obj instanceof MonitorTask)) {
+ throw new ConfigurationException (
+ obj.toString() + " is not an instance of MonitorTask"
+ );
+ }
+ qf.setLogger (obj, e);
+ qf.setConfiguration (obj, e);
+ timer.schedule (
+ new MonitorTimerTask (
+ e.getAttributeValue("id"),
+ (MonitorTask) obj),
+ getLong (e.getAttributeValue ("delay")),
+ getLong (e.getAttributeValue ("period"))
+ );
+ }
+ private long getLong (String l)
+ throws ConfigurationException
+ {
+ try {
+ return Long.parseLong (l);
+ } catch (Exception e) {
+ throw new ConfigurationException (e);
+ }
+ }
+ private synchronized void touch (String id, String detail) {
+ int sp = detail.indexOf (" ");
+ String state = Status.OFF;
+ if (sp > 0 && detail.length() > sp) {
+ state = detail.substring (0, sp);
+ detail = detail.substring (++sp);
+ }
+ try {
+ db.open ();
+ mgr.touch (id, state, detail);
+ } catch (Throwable t) {
+ getLog().error (t);
+ } finally {
+ close();
+ }
+ }
+ private synchronized String getNextCommand (String id) {
+ try {
+ db.open ();
+ return mgr.getNextCommand (id);
+ } catch (Throwable t) {
+ getLog().error (t);
+ } finally {
+ close();
+ }
+ return null;
+ }
+ private synchronized void setResponse (String id, String response) {
+ try {
+ db.open ();
+ mgr.setResponse (id, response);
+ } catch (Throwable t) {
+ getLog().error (t);
+ } finally {
+ close();
+ }
+ }
+ public class MonitorTimerTask extends TimerTask {
+ String id;
+ MonitorTask task;
+ public MonitorTimerTask (String id, MonitorTask task) {
+ super();
+ this.id = id;
+ this.task = task;
+ }
+ public void run() {
+ if (task instanceof TwoWayMonitorTask) {
+ String command = getNextCommand (id);
+ if (command != null)
+ setResponse (id,
+ ((TwoWayMonitorTask)task).command (command));
+ }
+ touch (id, task.checkService());
+ }
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/MonitorTask.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/MonitorTask.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,26 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2005 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee.status;
+
+public interface MonitorTask {
+ public String checkService ();
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/Ping.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/Ping.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,70 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2005 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee.status;
+
+import java.net.Socket;
+import java.io.IOException;
+import org.jpos.core.Configurable;
+import org.jpos.core.Configuration;
+import org.jpos.core.ConfigurationException;
+import org.jpos.util.Log;
+
+public class Ping extends Log implements MonitorTask, Configurable {
+ String host;
+ int port = 7;
+
+ // code taken from Alireza's blog
+ // http://jroller.com/page/alireza/20050601
+ public String checkService () {
+ boolean rc = false;
+ String detail = "";
+ long start = System.currentTimeMillis();
+ try {
+ Socket socket = new Socket(host, port);
+ socket.setSoLinger (true, 0);
+ socket.close();
+ rc = true;
+ } catch (IOException e) {
+ String msg = e.getMessage().toUpperCase();
+ if (msg.indexOf ("CONNECTION REFUSED") >= 0) {
+ rc = true;
+ }
+ else {
+ rc = false;
+ detail = " " + msg;
+ }
+ }
+ long elapsed = System.currentTimeMillis() - start;
+ return (rc ? Status.OK : Status.WARN) + detail
+ + " time=" + elapsed + "ms";
+ }
+ public void setConfiguration (Configuration cfg)
+ throws ConfigurationException
+ {
+ host = cfg.get ("host", null);
+ if (host == null)
+ throw new ConfigurationException (
+ "host property has not been specified"
+ );
+ port = cfg.getInt ("port", 7);
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/Status.hbm.xml
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/Status.hbm.xml Thu Aug 2 15:12:12 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping
+ SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.jpos.ee.status.Status" table="status">
+ <meta attribute="extends">org.jpos.ee.status.StatusBase</meta>
+ <id name="id" type="string" length="32">
+ <generator class="assigned"/>
+ </id>
+ <property name="name" type="string"/>
+ <property name="state" type="string" length="8" />
+ <property name="detail" type="string"/>
+ <property name="groupName" type="string" length="32" />
+ <property name="lastTick" type="timestamp"/>
+ <property name="timeout" type="long"/>
+ <property name="timeoutState" type="string" length="8" />
+ <property name="command" type="string" />
+ <property name="validCommands" type="string" />
+ <property name="expired" type="boolean" />
+ <property name="maxEvents" type="int" />
+
+ <set name="events" lazy="true" cascade="all-delete-orphan"
+ order-by="id asc">
+ <key column="status"/>
+ <one-to-many class="org.jpos.ee.SysLogEvent" />
+ </set>
+ <set name="revisions" lazy="true" cascade="all-delete-orphan"
+ order-by="id asc">
+ <key column="status" />
+ <one-to-many class="org.jpos.ee.StatusRevisionEntry" />
+ </set>
+ </class>
+</hibernate-mapping>
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/Status.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/Status.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,201 @@
+package org.jpos.ee.status;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Set;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+
+/** @author Hibernate CodeGenerator */
+public class Status extends org.jpos.ee.status.StatusBase implements Serializable {
+
+ /** identifier field */
+ private String id;
+
+ /** nullable persistent field */
+ private String name;
+
+ /** nullable persistent field */
+ private String state;
+
+ /** nullable persistent field */
+ private String detail;
+
+ /** nullable persistent field */
+ private String groupName;
+
+ /** nullable persistent field */
+ private Date lastTick;
+
+ /** nullable persistent field */
+ private long timeout;
+
+ /** nullable persistent field */
+ private String timeoutState;
+
+ /** nullable persistent field */
+ private String command;
+
+ /** nullable persistent field */
+ private String validCommands;
+
+ /** nullable persistent field */
+ private boolean expired;
+
+ /** nullable persistent field */
+ private int maxEvents;
+
+ /** persistent field */
+ private Set events;
+
+ /** persistent field */
+ private Set revisions;
+
+ /** full constructor */
+ public Status(String id, String name, String state, String detail, String groupName, Date lastTick, long timeout, String timeoutState, String command, String validCommands, boolean expired, int maxEvents, Set events, Set revisions) {
+ this.id = id;
+ this.name = name;
+ this.state = state;
+ this.detail = detail;
+ this.groupName = groupName;
+ this.lastTick = lastTick;
+ this.timeout = timeout;
+ this.timeoutState = timeoutState;
+ this.command = command;
+ this.validCommands = validCommands;
+ this.expired = expired;
+ this.maxEvents = maxEvents;
+ this.events = events;
+ this.revisions = revisions;
+ }
+
+ /** default constructor */
+ public Status() {
+ }
+
+ /** minimal constructor */
+ public Status(String id, Set events, Set revisions) {
+ this.id = id;
+ this.events = events;
+ this.revisions = revisions;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getState() {
+ return this.state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getDetail() {
+ return this.detail;
+ }
+
+ public void setDetail(String detail) {
+ this.detail = detail;
+ }
+
+ public String getGroupName() {
+ return this.groupName;
+ }
+
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ public Date getLastTick() {
+ return this.lastTick;
+ }
+
+ public void setLastTick(Date lastTick) {
+ this.lastTick = lastTick;
+ }
+
+ public long getTimeout() {
+ return this.timeout;
+ }
+
+ public void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
+
+ public String getTimeoutState() {
+ return this.timeoutState;
+ }
+
+ public void setTimeoutState(String timeoutState) {
+ this.timeoutState = timeoutState;
+ }
+
+ public String getCommand() {
+ return this.command;
+ }
+
+ public void setCommand(String command) {
+ this.command = command;
+ }
+
+ public String getValidCommands() {
+ return this.validCommands;
+ }
+
+ public void setValidCommands(String validCommands) {
+ this.validCommands = validCommands;
+ }
+
+ public boolean isExpired() {
+ return this.expired;
+ }
+
+ public void setExpired(boolean expired) {
+ this.expired = expired;
+ }
+
+ public int getMaxEvents() {
+ return this.maxEvents;
+ }
+
+ public void setMaxEvents(int maxEvents) {
+ this.maxEvents = maxEvents;
+ }
+
+ public Set getEvents() {
+ return this.events;
+ }
+
+ public void setEvents(Set events) {
+ this.events = events;
+ }
+
+ public Set getRevisions() {
+ return this.revisions;
+ }
+
+ public void setRevisions(Set revisions) {
+ this.revisions = revisions;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("id", getId())
+ .toString();
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/ee/status/StatusBase.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/StatusBase.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,119 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2005 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee.status;
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.StringTokenizer;
+import java.util.Date;
+import java.sql.SQLException;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.jpos.util.DateUtil;
+import org.jpos.ee.DB;
+import org.jpos.ee.User;
+import org.jpos.ee.StatusRevisionEntry;
+
+/**
+ * @author Alejandro Revilla
+ */
+public abstract class StatusBase {
+ public static final String OK = "OK";
+ public static final String OFF = "OFF";
+ public static final String WARN = "WARN";
+ public static final String ERROR = "ERROR";
+ public static final String CRITICAL = "CRITICAL";
+ public static final String[] possibleStates = { OFF, OK, WARN, ERROR, CRITICAL };
+
+ public static final Map icons = new HashMap();
+
+ static {
+ icons.put (OK, "green.gif");
+ icons.put (OFF, "off.gif");
+ icons.put (WARN, "yellow.gif");
+ icons.put (ERROR, "red.gif");
+ icons.put (CRITICAL, "critical.gif");
+ }
+
+ public abstract String getState();
+ public abstract Date getLastTick();
+ public abstract long getTimeout();
+ public abstract Set getRevisions();
+ public abstract String getValidCommands();
+
+ public String getIconName() {
+ String state = getState();
+ String icon = null;
+ if (state != null)
+ icon = (String) icons.get (state);
+ return icon != null ? icon : "red.gif";
+ }
+ /**
+ * Computes expiration based on last tick + timeout
+ * @return true if lasttick+timeout < current-time
+ */
+ public boolean hasExpired() {
+ long now = System.currentTimeMillis();
+ Date lastTick = getLastTick();
+ long timeout = getTimeout();
+ if (lastTick == null || timeout == 0)
+ return false;
+
+ long exp = lastTick.getTime() + timeout;
+ return now > exp;
+ }
+ public String getElapsedAsString () {
+ Date lastTick = getLastTick();
+ if (lastTick == null)
+ return "never";
+ long elapsed = System.currentTimeMillis() - lastTick.getTime();
+ return DateUtil.toDays (elapsed);
+ }
+ /**
+ * factory method used to create a RevisionEntry associated with this user.
+ *
+ * @param summary information
+ * @param detail detailed information
+ * @param author change author
+ */
+ public StatusRevisionEntry logRevision (String info, User author) {
+ StatusRevisionEntry re = new StatusRevisionEntry();
+ re.setDate (new Date());
+ re.setInfo (info);
+ re.setStatus ((Status) this);
+ re.setAuthor (author);
+ getRevisions().add (re);
+ return re;
+ }
+ public String[] getPossibleStates() {
+ return possibleStates;
+ }
+ public StringTokenizer getCommands () {
+ if (getValidCommands() != null) {
+ return new StringTokenizer (getValidCommands());
+ }
+ return null;
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/StatusManager.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/StatusManager.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,293 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2005 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.ee.status;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.Date;
+import java.sql.SQLException;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.Query;
+import org.jpos.ee.DB;
+import org.jpos.ee.SysLog;
+import org.jpos.ee.SysLogEvent;
+
+/**
+ * @author Alejandro Revilla
+ */
+public class StatusManager {
+ DB db;
+ SysLog syslog;
+ public static final Map severity = new HashMap();
+
+ static {
+ severity.put (Status.OK, new Integer (SysLog.INFO));
+ severity.put (Status.OFF, new Integer (SysLog.INFO));
+ severity.put (Status.WARN, new Integer (SysLog.WARN));
+ severity.put (Status.ERROR, new Integer (SysLog.ERROR));
+ severity.put (Status.CRITICAL, new Integer (SysLog.CRITICAL));
+ }
+
+ public StatusManager (DB db) {
+ super ();
+ this.db = db;
+ this.syslog = new SysLog (db);
+ }
+ /**
+ * @param id status id
+ * @param state Status.OK, Status.WARN, Status.ERROR or user defined
+ * @param detail optional detail information
+ */
+ public void touch (String id, String state, String detail)
+ throws HibernateException, SQLException
+ {
+ Transaction tx = db.beginTransaction();
+ Status status = touch (id, state, detail, tx);
+ tx.commit();
+ db.session().evict (status);
+ }
+
+ /**
+ * @param id status id
+ * @param state Status.OK, Status.WARN, Status.ERROR or user defined
+ * @param detail optional detail information
+ * @param tx transaction
+ */
+ public Status touch (String id, String state, String detail, Transaction tx)
+ throws HibernateException, SQLException
+ {
+ Status status = getStatus (id, true);
+ if (state == null) {
+ state = Status.ERROR;
+ if (detail == null)
+ detail = "";
+ detail = detail + " invalid state (null)";
+ }
+ Date now = new Date();
+
+ String previousState = status.getState();
+ if (status.getMaxEvents() > 0 && previousState != null && !state.equals (previousState)) {
+ Set events = status.getEvents();
+ if (events != null) {
+ purgeEvents (events, status.getMaxEvents());
+ StringBuffer transition = new StringBuffer();
+ transition.append (status.getState());
+ transition.append ("-->");
+ transition.append (state);
+ events.add (
+ syslog.log (
+ "status:" + status.getId(), state,
+ getSysLogSeverity (state),
+ transition.toString(),
+ detail)
+ );
+ }
+ }
+ status.setState (state);
+ status.setLastTick (now);
+ status.setDetail (detail);
+ status.setExpired (false);
+ return status;
+ }
+
+ /**
+ * @param state
+ * @return syslog severity associated with this state
+ */
+ public int getSysLogSeverity (String state) {
+ if (state != null) {
+ Integer sev = (Integer) severity.get (state);
+ if (sev != null)
+ return sev.intValue();
+ }
+ return SysLog.ERROR;
+ }
+
+ /**
+ * @param key status name
+ * @param state Status.OK, Status.WARN, Status.ERROR or user defined
+ * @param info optional information
+ */
+ public void touch (String key, String state)
+ throws HibernateException, SQLException
+ {
+ touch (key, state, null);
+ }
+ /**
+ * @param id status id and optional name (used when create=true)
+ * @param create if true and status doesn't exist, a new status with an optional name would be created.
+ */
+ public Status getStatus (String id, boolean create)
+ throws HibernateException, SQLException
+ {
+ String name = "";
+ int sp = id.indexOf (" ");
+ if (sp > 0 && id.length() > sp) {
+ name = id.substring (sp + 1);
+ id = id.substring (0, sp);
+ }
+ Status s = (Status) db.session().get(Status.class, id);
+ if (s == null && create) {
+ s = new Status ();
+ s.setId (id);
+ s.setName (name.length() > 0 ? name : id);
+ s.setTimeoutState (Status.OFF);
+ s.setGroupName ("Unfiled");
+ db.save (s);
+ }
+ return s;
+ }
+
+ /**
+ * Get optional command associated with this status.
+ * If response is not null, then we understand the command has been executed
+ * already and we return null.
+ * @return command or null
+ */
+ public String getNextCommand (String id)
+ throws HibernateException, SQLException
+ {
+ Status status = getStatus (id, false);
+ if (status != null)
+ return status.getCommand();
+ return null;
+ }
+ public void setNextCommand (String id, String command)
+ throws HibernateException, SQLException
+ {
+ Transaction tx = db.beginTransaction();
+ Status status = getStatus (id, false);
+ if (status != null)
+ status.setCommand (command);
+ tx.commit();
+ }
+ /**
+ * Set command to null and optionally log optional response
+ * @param id status id
+ * @param response response to be logged in revision history - may be null
+ */
+ public void setResponse (String id, String response)
+ throws HibernateException, SQLException
+ {
+ Transaction tx = db.beginTransaction();
+ Status status = getStatus (id, false);
+ if (status != null && status.getCommand() != null && response != null && status.getMaxEvents() > 0) {
+ Set events = status.getEvents();
+ if (events != null) {
+ purgeEvents (events, status.getMaxEvents());
+ StringBuffer sb = new StringBuffer();
+ sb.append (status.getCommand());
+ sb.append (" = ");
+ sb.append (response);
+ events.add (
+ syslog.log (
+ "status:" + status.getId(), "AUDIT",
+ SysLog.INFO,
+ sb.toString(),
+ null)
+ );
+ }
+ }
+ status.setCommand (null); // command has been processed
+ tx.commit();
+ db.session().evict (status);
+ }
+
+ /**
+ * check if a status is expired, and create appropriate syslog event
+ * @param id status id
+ */
+ public void check (Status status) throws HibernateException, SQLException
+ {
+ Transaction tx = null;
+ try {
+ if (!status.isExpired() && status.hasExpired()) {
+ tx = db.beginTransaction();
+ String state = status.getState();
+ String timeoutState = status.getTimeoutState();
+ String detail = status.getDetail();
+ if (state == null)
+ state = Status.ERROR;
+ if (timeoutState == null)
+ timeoutState = Status.ERROR;
+ if (detail == null)
+ detail = "(timeout)";
+ else
+ detail = detail + " (timeout)";
+ StringBuffer transition = new StringBuffer();
+ if (!state.equals (timeoutState)) {
+ transition.append (state);
+ transition.append ("-->");
+ transition.append (timeoutState);
+ }
+ Set events = status.getEvents();
+ purgeEvents (events, status.getMaxEvents());
+ if (status.getMaxEvents() > 0) {
+ events.add (
+ syslog.log (
+ "status:" + status.getId(), state,
+ getSysLogSeverity (timeoutState),
+ transition.toString())
+ );
+ }
+ status.setState (timeoutState);
+ status.setExpired (true);
+ status.setDetail (detail);
+ }
+ } finally {
+ if (tx != null)
+ tx.commit();
+ }
+ }
+
+ /**
+ * check if unexpired status entries became expired, and create
+ * appropriate syslog event.
+ * @param id status id
+ */
+ public void check () throws HibernateException, SQLException {
+ Iterator iter = findByExpired(false).iterator();
+ while (iter.hasNext()) {
+ check ((Status) iter.next());
+ }
+ }
+
+ public List findByExpired(boolean expired) throws SQLException, HibernateException {
+ Query q = db.session().createQuery ("from org.jpos.ee.status.Status where expired=:expired");
+ q.setBoolean ("expired", expired);
+ return q.list();
+ }
+ private void purgeEvents (Set events, int maxEvents) {
+ int rmcount = events.size() - maxEvents + 1;
+ Iterator iter = events.iterator();
+ for (; rmcount > 0 && iter.hasNext(); rmcount--) {
+ iter.next();
+ iter.remove ();
+ }
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/ee/status/TwoWayMonitorTask.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/ee/status/TwoWayMonitorTask.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,30 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2005 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.ee.status;
+
+public interface TwoWayMonitorTask extends MonitorTask {
+ /**
+ * @param command the command to be executed
+ * @return string to place in the 'command' column for next call (may be null)
+ */
+ public String command (String command);
+}
+
Added: trunk/opt/eecore3/src/org/jpos/util/BeanDiff.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/util/BeanDiff.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,308 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jpos.util;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Andres Alcarraz
+ * @author Alejandro Revilla
+ */
+public class BeanDiff {
+ /**
+ * should update diff info?
+ */
+ private boolean dirty = false;
+
+ /**
+ * first bean to compare
+ */
+ private Object b1;
+
+ /**
+ * second bean to compare
+ */
+ private Object b2;
+
+ /**
+ * list of object diferences.
+ * it has entries for different elements only.
+ */
+ private List differences;
+
+ /**
+ * properties to check, if null all properties will get compared
+ */
+ private String[] properties;
+
+ private static Map classInfo = new Hashtable();
+
+ private String[] actualProperties;
+
+ public BeanDiff () {
+ super();
+ }
+
+ public BeanDiff (Object b1, Object b2) {
+ super();
+ setB1 (b1);
+ setB2 (b2);
+ }
+ public BeanDiff (Object b1, Object b2, String[] props) {
+ this (b1, b2);
+ setProperties (props);
+ }
+ protected boolean isDirty() {
+ return dirty;
+ }
+ protected void setDirty(boolean dirty) {
+ this.dirty = dirty;
+ if (dirty)
+ setDifferences (null);
+ }
+
+ public Object getB1() {
+ return b1;
+ }
+
+ public void setB1(Object b1) {
+ setDirty (true);
+ this.b1 = b1;
+ }
+
+ public Object getB2() {
+ return b2;
+ }
+
+ public void setB2(Object b2) {
+ setDirty (true);
+ this.b2 = b2;
+ }
+
+ protected static ClassInfo getClassInfo (String className)
+ throws IntrospectionException
+ {
+ try {
+ return getClassInfo(Class.forName(className));
+ } catch (ClassNotFoundException e) {
+ return null;
+ //FIXME see what to do here
+ //throw new DiffException("Managed class does not exists", e);
+ }
+ }
+
+ protected static ClassInfo getClassInfo(Class c)
+ throws IntrospectionException
+ {
+ ClassInfo ret = (ClassInfo)classInfo.get(c.getName());
+ if(ret == null)
+ classInfo.put(c.getName(), ret = new ClassInfo(c));
+ return ret;
+ }
+
+ protected static class ClassInfo {
+ protected Class c;
+ protected BeanInfo info;
+ protected Map properties = new Hashtable();
+ public ClassInfo(String className)
+ throws ClassNotFoundException, IntrospectionException
+ {
+ try {
+ c = Class.forName(className);
+ init();
+ } catch (ClassNotFoundException e){
+ // This should never happen as instances of this class
+ // should already exist in the current classloader.
+ }
+ }
+ public ClassInfo (Class c) throws IntrospectionException {
+ this.c = c;
+ init();
+ }
+ protected final void init() throws IntrospectionException {
+ info = Introspector.getBeanInfo(c);
+ PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
+ for (int i=0; i<descriptors.length; i++){
+ Method reader = descriptors[i].getReadMethod();
+ // only add readable attributes, to avoid future errors
+ if (reader != null && Modifier.isPublic(reader.getModifiers())
+ && !"class".equals(descriptors[i].getName()))
+ properties.put (descriptors[i].getName(), descriptors[i]);
+ }
+ }
+ protected PropertyDescriptor getPropertyDescriptor(String propName){
+ return (PropertyDescriptor) properties.get(propName);
+ }
+ /**
+ * @return property's info.
+ */
+ public BeanInfo getInfo() {
+ return info;
+ }
+
+ /**
+ * @return property's properties.
+ */
+ public Map getProperties() {
+ return properties;
+ }
+
+ /**
+ * @return Subset of desired properties in a Map whose iteration order
+ * is the same as the <code>props</code> array.
+ * @param props desired properties
+ */
+ public Map getProperties(String[] props){
+ if (props == null)
+ return getProperties();
+ Map ret = new LinkedHashMap();
+ for(int i = 0; i < props.length; i++){
+ ret.put(props[i], properties.get(props[i]));
+ }
+ return ret;
+ }
+
+ public Object getValue(Object bean, String prop) {
+ try{
+ PropertyDescriptor descriptor = getPropertyDescriptor(prop);
+ return descriptor.getReadMethod().invoke(bean, null);
+ } catch (InvocationTargetException e){
+ } catch (IllegalAccessException e){
+ }
+ return "{error}";
+ }
+ }
+ /**
+ * Hook method to let a subclass change the way the values are compared
+ * @param i index of the property being compared in de order
+ * given by the <code>properties<code> attribute.
+ */
+ protected boolean equals (int i, Object v1, Object v2){
+ if (v1 instanceof Comparable)
+ return ((Comparable)v1).compareTo(v2) == 0;
+ else if (v1 != null)
+ return v1.equals(v2);
+ else
+ return v2 == null;
+ }
+ /**
+ * intersects two collections the first parameter will hold the
+ * result.
+ */
+ protected static void intersect (Collection col1, Collection col2){
+ Collection col1_col2 = new LinkedList (col1); //clone col1
+ col1_col2.removeAll (col2); //
+ col1.removeAll (col1_col2); //remve all elements of col1 that are not in col2
+ }
+ protected void updateActualProperties(ClassInfo info1, ClassInfo info2){
+ String[] actualProperties = getProperties();
+ List res;
+ if (actualProperties != null) {
+ res = new LinkedList(Arrays.asList(actualProperties));
+ intersect(res, new LinkedList(info1.getProperties().keySet()));
+ } else {
+ res = new LinkedList(info1.getProperties().keySet());
+ }
+ intersect(res, info2.getProperties().keySet());
+ setActualProperties((String [])res.toArray(new String[] {}));
+ }
+ protected void updateDiffInfo()
+ throws IntrospectionException
+ {
+ if (!isDirty())
+ return;
+ setDirty(false);
+ List differences = new ArrayList();
+ setDifferences(differences);
+ Object b1 = getB1(), b2 = getB2();
+ ClassInfo bean1Props = getClassInfo(b1.getClass());
+ ClassInfo bean2Props = getClassInfo(b2.getClass());
+ updateActualProperties(bean1Props, bean2Props);
+ String[] props = getActualProperties();
+
+ for (int i = 0; i < props.length; i++){
+ Object v1 = bean1Props.getValue(b1, props[i]);
+ Object v2 = bean2Props.getValue(b2, props[i]);
+ if (!equals(i, v1, v2))
+ differences.add(new DiffEntry(this, props[i], v1, v2));
+ }
+ }
+ public List getDifferences()
+ throws IntrospectionException
+ {
+ updateDiffInfo();
+ return differences;
+ }
+ protected void setDifferences(List differences) {
+ this.differences = differences;
+ }
+
+ public String toString() {
+ try {
+ updateDiffInfo();
+ Iterator iter = getDifferences().iterator();
+ StringBuffer sb = new StringBuffer();
+ while (iter.hasNext()) {
+ DiffEntry de = (DiffEntry) iter.next();
+ sb.append (de.toString());
+ }
+ return sb.toString();
+ } catch (IntrospectionException e) {
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * @return properties that are effectively being checked, these are the intersection
+ * of <code> properties</code>, properties of bean 1 and properties of bean 2
+ */
+ public String[] getActualProperties()
+ throws IntrospectionException
+ {
+ updateDiffInfo();
+ return actualProperties;
+ }
+ protected void setActualProperties(String[] actualProperties){
+ this.actualProperties = actualProperties;
+ }
+ public String[] getProperties() {
+ return properties;
+ }
+ public void setProperties(String[] properties) {
+ setDirty(true);
+ this.properties = properties;
+ }
+
+}
Added: trunk/opt/eecore3/src/org/jpos/util/DateUtil.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/util/DateUtil.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,224 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.util;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+public class DateUtil {
+ static SimpleDateFormat dfDate = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
+ static SimpleDateFormat dfDateTime = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.US);
+
+ static SimpleDateFormat dfDate_mmddyyyy = new SimpleDateFormat("MM/dd/yyyy");
+ static SimpleDateFormat dfDate_yyyymmdd = new SimpleDateFormat("yyyyMMdd");
+ static SimpleDateFormat dfDateTime_mmddyyyy = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
+
+ static SimpleDateFormat dfDate_mmddyy = new SimpleDateFormat("MM/dd/yy");
+ public static Date parseDate (String s) throws ParseException {
+ if (s == null)
+ return null;
+ return dfDate.parse (s);
+ }
+ public static Date parseDate_mmddyyyy (String s) throws ParseException {
+ if (s == null)
+ return null;
+ return dfDate_mmddyyyy.parse (s);
+ }
+ public static Date parseDate_yyyymmdd (String s) throws ParseException {
+ if (s == null)
+ return null;
+ return dfDate_yyyymmdd.parse (s);
+ }
+ public static Date parseDate_mmddyy (String s) throws ParseException {
+ if (s == null)
+ return null;
+ return dfDate_mmddyy.parse (s);
+ }
+
+ public static Date parseDateTime (String s) throws ParseException {
+ if (s == null)
+ return null;
+ return dfDateTime.parse (s);
+ }
+ public static Date parseDateTime_mmddyyyy (String s) throws ParseException {
+ if (s == null)
+ return null;
+ return dfDateTime_mmddyyyy.parse (s);
+ }
+ public static Date parseTimestamp (String s) throws ParseException {
+ if (s == null)
+ return null;
+ return dfDateTime_mmddyyyy.parse (s);
+ }
+
+ public static Date parseDateTime_mmddyyyy (String s, String tzString)
+ throws ParseException
+ {
+ if (s == null)
+ return null;
+ DateFormat df = (DateFormat) dfDateTime_mmddyyyy.clone();
+ if (tzString != null)
+ df.setTimeZone (TimeZone.getTimeZone (tzString));
+ return df.parse (s);
+ }
+
+ public static String dateToString (Date d) {
+ if (d == null)
+ return null;
+ return dfDate.format (d);
+ }
+ public static String dateToString_mmddyyyy (Date d) {
+ if (d == null)
+ return null;
+ return dfDate_mmddyyyy.format (d);
+ }
+
+ public static String dateTimeToString (Date d) {
+ if (d == null)
+ return null;
+ return dfDateTime.format (d);
+ }
+ public static String dateTimeToString (Date d, String tzString) {
+ if (d == null)
+ return null;
+ DateFormat df = (DateFormat) dfDateTime.clone();
+ if (tzString != null)
+ df.setTimeZone (TimeZone.getTimeZone (tzString));
+ return df.format (d);
+ }
+ public static String dateTimeToString_mmddyyyy (Date d) {
+ if (d == null)
+ return null;
+ return dfDateTime_mmddyyyy.format (d);
+ }
+ public static String timestamp (Date d) {
+ if (d == null)
+ return null;
+ return dfDateTime_mmddyyyy.format (d);
+ }
+ public static String postdate (Date d) {
+ if (d == null)
+ return null;
+ return dfDate_mmddyyyy.format (d);
+ }
+
+ /**
+ * @param date MMDDAA
+ * @param time HHMMSS
+ * @return Date Object
+ */
+ public static Date parseDateTime (String d, String t) {
+ Calendar cal = new GregorianCalendar();
+ Date now = new Date ();
+ cal.setTime (now);
+
+ int YY = Integer.parseInt (d.substring (4));
+ int MM = Integer.parseInt (d.substring (0, 2))-1;
+ int DD = Integer.parseInt (d.substring (2, 4));
+ int hh = Integer.parseInt (t.substring (0, 2));
+ int mm = Integer.parseInt (t.substring (2, 4));
+ int ss = Integer.parseInt (t.substring (4));
+ int century = cal.get (Calendar.YEAR) / 100;
+
+ cal.set (Calendar.YEAR, (century * 100) + YY);
+ cal.set (Calendar.MONTH, MM);
+ cal.set (Calendar.DATE, DD);
+ cal.set (Calendar.HOUR_OF_DAY, hh);
+ cal.set (Calendar.MINUTE, mm);
+ cal.set (Calendar.SECOND, ss);
+
+ //
+ // I expect this program to continue running by 2099 ... --a...@jpos.org
+ //
+ Date thisCentury = cal.getTime();
+ cal.set (Calendar.YEAR, (--century * 100) + YY);
+ Date previousCentury = cal.getTime();
+
+ if (Math.abs (now.getTime() - previousCentury.getTime()) <
+ Math.abs (now.getTime() - thisCentury.getTime()) )
+ thisCentury = previousCentury;
+ return thisCentury;
+ }
+ /**
+ * @param time HHMM[SS]
+ * @return Date Object
+ */
+ public static Date parseTime (String t) {
+ return parseTime (t, new Date());
+ }
+ public static Date parseTime (String t, Date now) {
+ Calendar cal = new GregorianCalendar();
+ cal.setTime (now);
+
+ int hh = Integer.parseInt (t.substring (0, 2));
+ int mm = Integer.parseInt (t.substring (2, 4));
+ int ss = t.length() > 4 ? Integer.parseInt (t.substring (4)) : 0;
+
+ cal.set (Calendar.HOUR_OF_DAY, hh);
+ cal.set (Calendar.MINUTE, mm);
+ cal.set (Calendar.SECOND, ss);
+
+ return cal.getTime();
+ }
+
+ public static String dateToString (Date d, String tzString) {
+ DateFormat df = (DateFormat) DateFormat.getDateInstance().clone();
+ if (tzString != null)
+ df.setTimeZone (TimeZone.getTimeZone (tzString));
+ return df.format (d);
+ }
+ public static String timeToString (Date d, String tzString) {
+ DateFormat df = (DateFormat)
+ DateFormat.getTimeInstance(DateFormat.SHORT).clone();
+ if (tzString != null)
+ df.setTimeZone (TimeZone.getTimeZone (tzString));
+ return df.format (d);
+ }
+ public static String timeToString (Date d) {
+ return timeToString (d, null);
+ }
+ public static String toDays (long period) {
+ StringBuffer sb = new StringBuffer();
+ long hours = period / 3600000L;
+ if (hours > 0) {
+ sb.append (hours);
+ sb.append ("h");
+ period -= (hours * 3600000L);
+ }
+ long mins = period / 60000L;
+ if (mins > 0) {
+ sb.append (mins);
+ sb.append ("m");
+ period -= (mins * 60000L);
+ }
+ long secs = period / 1000L;
+ sb.append (secs);
+ sb.append ("s");
+ return sb.toString();
+ }
+}
+
Added: trunk/opt/eecore3/src/org/jpos/util/DiffEntry.java
==============================================================================
--- (empty file)
+++ trunk/opt/eecore3/src/org/jpos/util/DiffEntry.java Thu Aug 2 15:12:12 2007
@@ -0,0 +1,83 @@
+/*
+ * jPOS Extended Edition
+ * Copyright (C) 2004 Alejandro P. Revilla
+ * jPOS.org (http://jpos.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.jpos.util;
+
+/**
+ *
+ * @author Andres Alcarraz
+ */
+public class DiffEntry {
+ private String property;
+ private Object value1;
+ private Object value2;
+ private BeanDiff beanDiff;
+ private static String lineSep = System.getProperty ("line.separator");
+
+ public DiffEntry() {
+ super();
+ }
+ public DiffEntry (BeanDiff beanDiff, String prop,
+ Object value1, Object value2) {
+ super ();
+ setBeanDiff(beanDiff);
+ setProperty(prop);
+ setValue1(value1);
+ setValue2(value2);
+ }
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append ('-');
+ sb.append (getProperty());
+ sb.append (':');
+ sb.append (getValue1());
+ sb.append (lineSep);
+ sb.append ('+');
+ sb.append (getProperty());
+ sb.append (':');
+ sb.append (getValue2());
+ return sb.toString();
+ }
+ public String getProperty() {
+ return property;
+ }
+ public void setProperty (String property) {
+ this.property = property;
+ }
+ public Object getValue1 () {
+ return value1;
+ }
+ public void setValue1 (Object value1) {
+ this.value1 = value1;
+ }
+ public Object getValue2 () {
+ return value2;
+ }
+ public void setValue2 (Object value2) {
+ this.value2 = value2;
+ }
+ public BeanDiff getBeanDiff() {
+ return beanDiff;
+ }
+ public void setBeanDiff (BeanDiff beanDiff) {
+ this.beanDiff = beanDiff;
+ }
+}
+