Initial commit from SVN.
This commit is contained in:
21
Foundation Test/.classpath
Normal file
21
Foundation Test/.classpath
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Common"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation SWT"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation TCV"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation TCV Client"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation TCV Server"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation TCV SWT"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation TCV SWT Client"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation TCV SWT Client Application"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation TCV SWT Server"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Orb"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/SWT"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Transaction MySQL"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/MySQL ConnectorJ"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
Foundation Test/.project
Normal file
17
Foundation Test/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Foundation Test</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
51
Foundation Test/BIG TestApplication.xml
Normal file
51
Foundation Test/BIG TestApplication.xml
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- com.foundation.transaction.test.TestApplication -->
|
||||
<repository>
|
||||
<name>MySQL</name>
|
||||
<class>com.foundation.transaction.jdbc.mmmysql.MMMySQLRepositoryManager</class>
|
||||
<properties>
|
||||
<user-name>root</user-name>
|
||||
<user-password></user-password>
|
||||
<database-url>jdbc:mysql://localhost/test</database-url>
|
||||
</properties>
|
||||
<classes>
|
||||
<class>
|
||||
<class-name>com.foundation.transaction.test.TestObject</class-name>
|
||||
<repository-name>TEST</repository-name>
|
||||
<attributes>
|
||||
<attribute>
|
||||
<attribute-name>number</attribute-name>
|
||||
<repository-name>NUMBER</repository-name>
|
||||
<attribute-type></attribute-type>
|
||||
<repository-type>INTEGER</repository-type>
|
||||
<is-key>false</is-key>
|
||||
<is-auto-generated>false</is-auto-generated>
|
||||
<properties>
|
||||
</properties>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<attribute-name>text</attribute-name>
|
||||
<repository-name>TEXT</repository-name>
|
||||
<attribute-type></attribute-type>
|
||||
<repository-type>VARCHAR</repository-type>
|
||||
<is-key>false</is-key>
|
||||
<is-auto-generated>false</is-auto-generated>
|
||||
<properties>
|
||||
</properties>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<attribute-name>id</attribute-name>
|
||||
<repository-name>ID</repository-name>
|
||||
<attribute-type></attribute-type>
|
||||
<repository-type>INTEGER</repository-type>
|
||||
<is-key>true</is-key>
|
||||
<is-auto-generated>true</is-auto-generated>
|
||||
<properties>
|
||||
</properties>
|
||||
</attribute>
|
||||
</attributes>
|
||||
<properties>
|
||||
</properties>
|
||||
</class>
|
||||
</classes>
|
||||
</repository>
|
||||
1
Foundation Test/Generate Self Signed Keystore.bat
Normal file
1
Foundation Test/Generate Self Signed Keystore.bat
Normal file
@@ -0,0 +1 @@
|
||||
keytool -genkey -keyalg RSA -keystore test.key -storepass kspassword -keypass kpassword -validity 1825 -dname "cn=localhost, ou=IT, o=Mr Smith, c=US"
|
||||
113
Foundation Test/Model Test/metadata.xml
Normal file
113
Foundation Test/Model Test/metadata.xml
Normal file
@@ -0,0 +1,113 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- com.foundation.model.test.TestApplication -->
|
||||
<repository name='MySQL' class='com.foundation.transaction.jdbc.mysql.MySQLRepositoryManager'>
|
||||
<properties user-name='test' user-password='test' database-url='jdbc:mysql://localhost/test'/>
|
||||
<class name="com.foundation.model.test.KeyTest" repository-class="KEY_TEST">
|
||||
<attribute name="id" type="Integer" repository-name="ID" repository-type="INTEGER" is-key="true" is-auto-generated="true"/>
|
||||
<attribute name="keys" type="byte[]" repository-name="KEYS" repository-type="LONGBLOB"/>
|
||||
</class>
|
||||
<class name="com.foundation.model.LogicalObjectChangeLog" repository-class="LOGICAL_OBJECT_CHANGE_LOG">
|
||||
<attribute name="objectId" type="java.lang.Long" repository-name="VERSION_ID" repository-type="BIGINT"/>
|
||||
<attribute name="version" repository-name="VERSION" repository-type="BIGINT"/>
|
||||
<attribute name="changes" repository-name="CHANGES" repository-type="BLOB"/>
|
||||
</class>
|
||||
<class name="com.foundation.model.LogicalObjectMetadata" repository-class="LOGICAL_OBJECT">
|
||||
<attribute name="logicalObjectId" type="java.lang.Long" repository-name="ID" repository-type="BIGINT"/>
|
||||
<attribute name="version" type="java.lang.Long" repository-name="VERSION" repository-type="BIGINT"/>
|
||||
<attribute name="lastObjectId" type="java.lang.Long" repository-name="LAST_OBJECT_ID" repository-type="BIGINT"/>
|
||||
</class>
|
||||
<class name="com.foundation.model.test.StatelessData" repository-class="STATELESS_DATA">
|
||||
<attribute name='id' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute name="text" type="java.lang.String" repository-name="TEXT" repository-type="VARCHAR"/>
|
||||
|
||||
<attribute name="logicalObjectId" type="java.lang.Long" repository-name="ID" repository-type="BIGINT" metadata="logical object id" repository-class="LOGICAL_OBJECT" is-auto-generated='true' is-key='true'>
|
||||
<join repository-name="LO_ID"/>
|
||||
</attribute>
|
||||
<attribute name='objectId' type="java.lang.Long" repository-name="O_ID" repository-type="BIGINT"/>
|
||||
<attribute name="version" type="java.lang.Long" repository-name="VERSION" repository-type="BIGINT" metadata="version" repository-class="LOGICAL_OBJECT"/>
|
||||
|
||||
<!--
|
||||
Another example which works the same as above (or should).
|
||||
<attribute name="versionId" type="java.lang.Integer" repository-name="ID" repository-type="INTEGER" metadata="version id">
|
||||
<join repository-name="VERSION_ID" repository-class="VERSION"/>
|
||||
</attribute>
|
||||
-->
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.ClassA' repository-name='CLASS_A'>
|
||||
<attribute attribute-name='key' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<attribute attribute-name='classBKey' repository-name='B_ID' repository-type='INTEGER'/>
|
||||
<attribute attribute-name='classCKey' repository-name='C_ID' repository-type='INTEGER'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.ClassB' repository-name='CLASS_B'>
|
||||
<attribute attribute-name='key' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.ClassC' repository-name='CLASS_C'>
|
||||
<attribute attribute-name='key' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.ClassD' repository-name='CLASS_D'>
|
||||
<attribute attribute-name='key' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<attribute attribute-name='classAKey' repository-name='A_ID' repository-type='INTEGER'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.Widget' repository-name='WIDGET'>
|
||||
<attribute attribute-name='key' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<attribute attribute-name='classAKey' repository-name='A_ID' repository-type='INTEGER'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.Gadget' repository-name='GADGET'>
|
||||
<attribute attribute-name='key' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<attribute attribute-name='classAKey' repository-name='A_ID' repository-type='INTEGER'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.Thing' repository-name='THING'>
|
||||
<attribute attribute-name='key' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.ClassAThing' repository-name='CLASS_A_THING'>
|
||||
<attribute attribute-name='classAKey' repository-name='A_ID' repository-type='INTEGER' is-key='true'/>
|
||||
<attribute attribute-name='thingKey' repository-name='THING_ID' repository-type='INTEGER' is-key='true'/>
|
||||
<properties/>
|
||||
</class>
|
||||
|
||||
<class class-name='com.foundation.model.test.Employee' repository-name='EMPLOYEE'>
|
||||
<attribute attribute-name='id' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.Employer' repository-name='EMPLOYER'>
|
||||
<attribute attribute-name='id' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<attribute attribute-name='employeeCount' repository-name='EMPLOYEE_COUNT' repository-type='INTEGER'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.EmployeeEmployerMap' repository-name='EMPLOYEE_EMPLOYER_MAP'>
|
||||
<attribute attribute-name='employeeId' repository-name='EMPLOYEE_ID' repository-type='INTEGER' is-key='true'/>
|
||||
<attribute attribute-name='employerId' repository-name='EMPLOYER_ID' repository-type='INTEGER' is-key='true'/>
|
||||
<properties/>
|
||||
</class>
|
||||
|
||||
<class class-name='com.foundation.model.test.DbProduct' repository-name='DBPRODUCT'>
|
||||
<attribute attribute-name='id' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<attribute attribute-name='cost' attribute-type="BigDecimal" repository-name='COST' repository-type='DECIMAL'/>
|
||||
<attribute attribute-name='price' attribute-type="BigDecimal" repository-name='PRICE' repository-type='DECIMAL'/>
|
||||
<properties/>
|
||||
</class>
|
||||
<class class-name='com.foundation.model.test.DbPart' repository-name='DBPART'>
|
||||
<attribute attribute-name='id' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='name' repository-name='NAME' repository-type='VARCHAR'/>
|
||||
<attribute attribute-name='cost' attribute-type="BigDecimal" repository-name='COST' repository-type='DECIMAL'/>
|
||||
<attribute attribute-name='price' attribute-type="BigDecimal" repository-name='PRICE' repository-type='DECIMAL'/>
|
||||
<properties/>
|
||||
</class>
|
||||
</repository>
|
||||
270
Foundation Test/Model Test/setup.sql
Normal file
270
Foundation Test/Model Test/setup.sql
Normal file
@@ -0,0 +1,270 @@
|
||||
-- MySQL Administrator dump 1.4
|
||||
--
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 4.1.14-max
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
|
||||
|
||||
--
|
||||
-- Create schema test
|
||||
--
|
||||
|
||||
CREATE DATABASE /*!32312 IF NOT EXISTS*/ test;
|
||||
USE test;
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`class_a`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `class_a`;
|
||||
CREATE TABLE `class_a` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
`B_ID` int(10) default NULL,
|
||||
`C_ID` int(10) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='ClassA';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`class_a`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `class_a` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `class_a` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`class_a_thing`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `class_a_thing`;
|
||||
CREATE TABLE `class_a_thing` (
|
||||
`A_ID` int(10) unsigned NOT NULL default '0',
|
||||
`THING_ID` int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`A_ID`,`THING_ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='ClassAThing';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`class_a_thing`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `class_a_thing` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `class_a_thing` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`class_b`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `class_b`;
|
||||
CREATE TABLE `class_b` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='ClassB';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`class_b`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `class_b` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `class_b` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`class_c`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `class_c`;
|
||||
CREATE TABLE `class_c` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='ClassC';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`class_c`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `class_c` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `class_c` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`class_d`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `class_d`;
|
||||
CREATE TABLE `class_d` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
`A_ID` int(10) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='ClassD';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`class_d`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `class_d` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `class_d` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`employee`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `employee`;
|
||||
CREATE TABLE `employee` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Employee';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`employee`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `employee` DISABLE KEYS */;
|
||||
INSERT INTO `employee` VALUES (23,'Wynne Crisman'),
|
||||
(24,'Jeff Miller');
|
||||
/*!40000 ALTER TABLE `employee` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`employee_employer_map`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `employee_employer_map`;
|
||||
CREATE TABLE `employee_employer_map` (
|
||||
`EMPLOYEE_ID` int(10) unsigned NOT NULL default '0',
|
||||
`EMPLOYER_ID` int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`EMPLOYEE_ID`,`EMPLOYER_ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='EmployeeEmployerMap';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`employee_employer_map`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `employee_employer_map` DISABLE KEYS */;
|
||||
INSERT INTO `employee_employer_map` VALUES (23,18),
|
||||
(24,18);
|
||||
/*!40000 ALTER TABLE `employee_employer_map` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`employer`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `employer`;
|
||||
CREATE TABLE `employer` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
`EMPLOYEE_COUNT` int(11) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Employer';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`employer`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `employer` DISABLE KEYS */;
|
||||
INSERT INTO `employer` VALUES (18,'Declarative Engineering LLC',2);
|
||||
/*!40000 ALTER TABLE `employer` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`gadget`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `gadget`;
|
||||
CREATE TABLE `gadget` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
`A_ID` int(10) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Gadget';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`gadget`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `gadget` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `gadget` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`test_object`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `test_object`;
|
||||
CREATE TABLE `test_object` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NUMBER` int(10) unsigned NOT NULL default '0',
|
||||
`TEXT` varchar(30) NOT NULL default 'text',
|
||||
`FIXED_SIZE_DATA` tinyblob,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Test Object Table';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`test_object`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `test_object` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `test_object` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`thing`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `thing`;
|
||||
CREATE TABLE `thing` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Thing';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`thing`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `thing` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `thing` ENABLE KEYS */;
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `test`.`widget`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `widget`;
|
||||
CREATE TABLE `widget` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NAME` varchar(50) default NULL,
|
||||
`A_ID` int(10) default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Widget';
|
||||
|
||||
--
|
||||
-- Dumping data for table `test`.`widget`
|
||||
--
|
||||
|
||||
/*!40000 ALTER TABLE `widget` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `widget` ENABLE KEYS */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
12
Foundation Test/TestApplication/TestApplication.xml
Normal file
12
Foundation Test/TestApplication/TestApplication.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- com.foundation.transaction.test.TestApplication -->
|
||||
<repository name='MySQL' class='com.foundation.transaction.jdbc.mysql.MySQLRepositoryManager'>
|
||||
<properties user-name='test' user-password='test' database-url='jdbc:mysql://localhost/test'/>
|
||||
<class class-name='com.foundation.transaction.test.TestObject' repository-name='TEST_OBJECT'>
|
||||
<attribute attribute-name='number' repository-name='NUMBER' repository-type='INTEGER'/>
|
||||
<attribute attribute-name='text' repository-name='TEXT' repository-type='VARCHAR'/>
|
||||
<attribute attribute-name='id' repository-name='ID' repository-type='INTEGER' is-key='true' is-auto-generated='true'/>
|
||||
<attribute attribute-name='fixedSizeData' attribute-type='byte[]' repository-name='FIXED_SIZE_DATA' repository-type='BLOB'/>
|
||||
<properties/>
|
||||
</class>
|
||||
</repository>
|
||||
8
Foundation Test/TestApplication/setup.sql
Normal file
8
Foundation Test/TestApplication/setup.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
DROP TABLE IF EXISTS `test`.`test_object`;
|
||||
CREATE TABLE `test`.`test_object` (
|
||||
`ID` int(10) unsigned NOT NULL auto_increment,
|
||||
`NUMBER` int(10) unsigned NOT NULL default '0',
|
||||
`TEXT` varchar(30) NOT NULL default 'text',
|
||||
`FIXED_SIZE_DATA` tinyblob default NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Test Object Table';
|
||||
19
Foundation Test/src/com/de22/javabytecode/ChildOfA.java
Normal file
19
Foundation Test/src/com/de22/javabytecode/ChildOfA.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.de22.javabytecode;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2008<p>
|
||||
* Sample code used by the byte code system to test reverse engineering.
|
||||
*/
|
||||
public class ChildOfA extends SampleA {
|
||||
public interface IInnerChildOfA {
|
||||
public String test();
|
||||
}
|
||||
public class InnerChildOfA implements IInnerChildOfA {
|
||||
public String test() {
|
||||
return "Test";
|
||||
}
|
||||
}
|
||||
public String peform() {
|
||||
return "Child's: " + text + " " + new InnerChildOfA().test();
|
||||
}
|
||||
}
|
||||
9
Foundation Test/src/com/de22/javabytecode/ISampleA.java
Normal file
9
Foundation Test/src/com/de22/javabytecode/ISampleA.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.de22.javabytecode;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2008<p>
|
||||
* Sample code used by the byte code system to test reverse engineering.
|
||||
*/
|
||||
public interface ISampleA {
|
||||
public String perform();
|
||||
}
|
||||
13
Foundation Test/src/com/de22/javabytecode/SampleA.java
Normal file
13
Foundation Test/src/com/de22/javabytecode/SampleA.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.de22.javabytecode;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2008<p>
|
||||
* Sample code used by the byte code system to test reverse engineering.
|
||||
*/
|
||||
public class SampleA implements ISampleA {
|
||||
public String text = "SAMPLEA";
|
||||
|
||||
public String perform() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
12
Foundation Test/src/com/de22/javabytecode/SampleB.java
Normal file
12
Foundation Test/src/com/de22/javabytecode/SampleB.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.de22.javabytecode;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2008<p>
|
||||
* Sample code used by the byte code system to test reverse engineering.
|
||||
*/
|
||||
public class SampleB {
|
||||
public static void main(String[] args) {
|
||||
ISampleA sample = new ChildOfA();
|
||||
System.out.println(sample.perform());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.foundation.aggregatecollection.test;
|
||||
|
||||
import com.foundation.application.IApplication;
|
||||
import com.foundation.model.Model;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2006<p>
|
||||
*/
|
||||
public class AbstractModel extends Model {
|
||||
/**
|
||||
* AbstractModel constructor.
|
||||
*/
|
||||
public AbstractModel() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#getApplication()
|
||||
*/
|
||||
public IApplication getApplication() {
|
||||
return AggregateCollectionApplication.getSingleton();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package com.foundation.aggregatecollection.test;
|
||||
|
||||
import com.common.comparison.Comparator;
|
||||
import com.common.debug.Debug;
|
||||
import com.common.util.IIterator;
|
||||
import com.common.util.IList;
|
||||
import com.foundation.application.Application;
|
||||
import com.foundation.common.AttributeBinding;
|
||||
import com.foundation.event.model.IModelListenerCollectionHandler;
|
||||
import com.foundation.event.model.ModelListener;
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.util.ManagedHashSet;
|
||||
import com.foundation.util.IManagedList;
|
||||
import com.foundation.util.ListAdapter;
|
||||
import com.foundation.util.ManagedList;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2006<p>
|
||||
* This application is designed to test the following scenario:
|
||||
* <p>Collect all qunie Bar instances and sort by Bar.NAME and listen to everything for any changes.</p>
|
||||
* This scenario is likely to be used to generate a collection for display in a list, table, or tree.
|
||||
*/
|
||||
public class AggregateCollectionApplication extends Application {
|
||||
public static final Attribute FOOS = registerCollection(AggregateCollectionApplication.class, "foos", AO_REFERENCED | AO_LAZY);
|
||||
public static final Attribute UNIQUE_BARS = registerAttribute(AggregateCollectionApplication.class, "uniqueBars", AO_REFERENCED | AO_LAZY);
|
||||
public static final Attribute ORDERED_UNIQUE_BARS = registerAttribute(AggregateCollectionApplication.class, "orderedUniqueBars", AO_REFERENCED | AO_LAZY);
|
||||
|
||||
private static final Bar BAR1 = new Bar(new Integer(1), "This is bar 1..");
|
||||
private static final Bar BAR2 = new Bar(new Integer(2), "Another bar (2)");
|
||||
private static final Bar BAR3 = new Bar(new Integer(3), "Yet another bar - 3");
|
||||
private static final Bar BAR4 = new Bar(new Integer(4), "How about a fourth bar.");
|
||||
private static final Bar BAR5 = new Bar(new Integer(5), "Bar 5");
|
||||
private static final Bar BAR6 = new Bar(new Integer(6), "Get this - Bar 6");
|
||||
private static final Bar BAR7 = new Bar(new Integer(7), "How about a Bar 7.");
|
||||
|
||||
private static final AggregateCollectionApplication singleton = new AggregateCollectionApplication();
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static AggregateCollectionApplication getSingleton() {
|
||||
return singleton;
|
||||
}//getSingleton()//
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
getSingleton().startup();
|
||||
}//main()//
|
||||
/**
|
||||
* AggregateCollectionApplication constructor.
|
||||
*/
|
||||
private AggregateCollectionApplication() {
|
||||
}//AggregateCollectionApplication()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result = null;
|
||||
|
||||
if(attribute == FOOS) {
|
||||
IManagedList list = new ManagedList(10, 20);
|
||||
Foo foo;
|
||||
|
||||
//Save bar 6 & 7 for dynamically adding.//
|
||||
list.add(foo = new Foo());
|
||||
foo.getBars().add(BAR1);
|
||||
foo.getBars().add(BAR3);
|
||||
foo.getBars().add(BAR5);
|
||||
list.add(foo = new Foo());
|
||||
foo.getBars().add(BAR1);
|
||||
foo.getBars().add(BAR4);
|
||||
foo.getBars().add(BAR5);
|
||||
list.add(foo = new Foo());
|
||||
foo.getBars().add(BAR2);
|
||||
foo.getBars().add(BAR4);
|
||||
foo.getBars().add(BAR3);
|
||||
list.add(foo = new Foo());
|
||||
foo.getBars().add(BAR1);
|
||||
foo.getBars().add(BAR2);
|
||||
|
||||
result = list;
|
||||
}//if//
|
||||
else if(attribute == UNIQUE_BARS) {
|
||||
final ManagedHashSet set = new ManagedHashSet(20, ManagedHashSet.DEFAULT_LOAD_FACTOR, ManagedHashSet.DEFAULT_COMPARATOR, ManagedHashSet.STYLE_COUNT_DUPLICATES);
|
||||
ModelListener listener = new ModelListener(this);
|
||||
|
||||
listener.addBinding(new AttributeBinding(AggregateCollectionApplication.class, FOOS, AttributeBinding.FLAG_LAZY_LOAD_ATTRIBUTE));
|
||||
listener.addBinding(new AttributeBinding(Foo.class, Foo.BARS, AttributeBinding.FLAG_LAZY_LOAD_ATTRIBUTE, null, new IModelListenerCollectionHandler[] {new IModelListenerCollectionHandler() {
|
||||
public Class getReferenceType() {
|
||||
return Bar.class;
|
||||
}//getReferenceType()//
|
||||
public void run(Object object, int flags, IList addedValues, IList removedValues) {
|
||||
set.addAll(addedValues);
|
||||
set.removeAll(removedValues);
|
||||
}//run()//
|
||||
}}));
|
||||
listener.initialize();
|
||||
result = set;
|
||||
}//else if//
|
||||
else if(attribute == ORDERED_UNIQUE_BARS) {
|
||||
result = new ListAdapter((ManagedHashSet) getUniqueBars());
|
||||
((ListAdapter) result).setOrderComparator(new Comparator() {
|
||||
public int compare(Object value1, Object value2) {
|
||||
return ((Bar) value1).getName().compareTo(((Bar) value2).getName());
|
||||
}//compare()//
|
||||
});
|
||||
}//else if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#getDefaultRepositoryIdentifier()
|
||||
*/
|
||||
public Object getDefaultRepositoryIdentifier() {
|
||||
return null;
|
||||
}//getDefaultRepositoryIdentifier()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#getMetadataLocation()
|
||||
*/
|
||||
public Object getMetadataLocation() {
|
||||
return null;
|
||||
}//getMetadataLocation()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#startup()
|
||||
*/
|
||||
protected void startup() {
|
||||
setupMetadataService();
|
||||
|
||||
try {
|
||||
Foo newFoo;
|
||||
IIterator iterator = getOrderedUniqueBars().iterator();
|
||||
|
||||
Debug.log("This test will collect all unique Bars from all Foos and order them by name.");
|
||||
//Display the list.//
|
||||
Debug.log("Initial Set:");
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log(" " + ((Bar) iterator.next()).getName());
|
||||
}//while//
|
||||
Debug.log("---------------");
|
||||
|
||||
//Make some additions.//
|
||||
((Foo) getFoos().getFirst()).getBars().add(BAR6);
|
||||
getFoos().add(newFoo = new Foo());
|
||||
newFoo.getBars().add(BAR1);
|
||||
newFoo.getBars().add(BAR7);
|
||||
newFoo.getBars().add(BAR3);
|
||||
|
||||
//Display the list.//
|
||||
iterator = getOrderedUniqueBars().iterator();
|
||||
|
||||
Debug.log("Modified Set (Bar6 and Bar7 added):");
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log(" " + ((Bar) iterator.next()).getName());
|
||||
}//while//
|
||||
Debug.log("---------------");
|
||||
|
||||
//Remove bar 6.//
|
||||
((Foo) getFoos().getFirst()).getBars().remove(BAR6);
|
||||
|
||||
//Display the list.//
|
||||
iterator = getOrderedUniqueBars().iterator();
|
||||
|
||||
Debug.log("Modified Set (Bar6 removed):");
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log(" " + ((Bar) iterator.next()).getName());
|
||||
}//while//
|
||||
Debug.log("---------------");
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//startup()//
|
||||
/**
|
||||
* Gets the foos value.
|
||||
* @return The foos value.
|
||||
*/
|
||||
public IManagedList getFoos() {
|
||||
return (IManagedList) getAttributeValue(FOOS);
|
||||
}//getFoos()//
|
||||
/**
|
||||
* Gets the uniqueBars value.
|
||||
* @return The uniqueBars value.
|
||||
*/
|
||||
public ManagedHashSet getUniqueBars() {
|
||||
return (ManagedHashSet) getAttributeValue(UNIQUE_BARS);
|
||||
}//getUniqueBars()//
|
||||
/**
|
||||
* Gets the orderedUniqueBars value.
|
||||
* @return The orderedUniqueBars value.
|
||||
*/
|
||||
public IList getOrderedUniqueBars() {
|
||||
return (IList) getAttributeValue(ORDERED_UNIQUE_BARS);
|
||||
}//getOrderedUniqueBars()//
|
||||
}//AggregateCollectionApplication//
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.foundation.aggregatecollection.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2006<p>
|
||||
*/
|
||||
public class Bar extends AbstractModel {
|
||||
public static final Attribute ID = registerAttribute(Bar.class, "id");
|
||||
public static final Attribute NAME = registerAttribute(Bar.class, "name");
|
||||
/**
|
||||
* Bar constructor.
|
||||
*/
|
||||
public Bar(Integer id, String name) {
|
||||
setId(id);
|
||||
setName(name);
|
||||
}//Bar()//
|
||||
/**
|
||||
* Gets the id value.
|
||||
* @return The id value.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
* Sets the id value.
|
||||
* @param id The id value.
|
||||
*/
|
||||
private void setId(Integer id) {
|
||||
setAttributeValue(ID, id);
|
||||
}//setId()//
|
||||
/**
|
||||
* Gets the name value.
|
||||
* @return The name value.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name value.
|
||||
* @param name The name value.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//Bar//
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.foundation.aggregatecollection.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.util.IManagedList;
|
||||
import com.foundation.util.ManagedList;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2006<p>
|
||||
*/
|
||||
public class Foo extends AbstractModel {
|
||||
public static final Attribute BARS = registerCollection(Foo.class, "bars", AO_REFERENCED | AO_LAZY);
|
||||
/**
|
||||
* Foo constructor.
|
||||
*/
|
||||
public Foo() {
|
||||
}//Foo()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result = null;
|
||||
|
||||
if(attribute == BARS) {
|
||||
result = new ManagedList(10, 20);
|
||||
}//if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/**
|
||||
* Gets the bars value.
|
||||
* @return The bars value.
|
||||
*/
|
||||
public IManagedList getBars() {
|
||||
return (IManagedList) getAttributeValue(BARS);
|
||||
}//getBars()//
|
||||
}//Foo//
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.foundation.attribute;
|
||||
|
||||
import com.foundation.application.IApplication;
|
||||
import com.foundation.model.Model;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2004<p>
|
||||
*/
|
||||
public class AbstractModel extends Model {
|
||||
/**
|
||||
* AbstractModel constructor.
|
||||
*/
|
||||
public AbstractModel() {
|
||||
super();
|
||||
}//AbstractModel()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#getApplication()
|
||||
*/
|
||||
public IApplication getApplication() {
|
||||
return TestApplication.getSingleton();
|
||||
}//getApplication()//
|
||||
}//AbstractModel//
|
||||
38
Foundation Test/src/com/foundation/attribute/Contact.java
Normal file
38
Foundation Test/src/com/foundation/attribute/Contact.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.foundation.attribute;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2005<p>
|
||||
*/
|
||||
public class Contact extends AbstractModel {
|
||||
public static final Attribute ID = registerAttribute(Contact.class, "id");
|
||||
public static final Attribute NAME = registerAttribute(Contact.class, "name");
|
||||
/**
|
||||
* Contact constructor.
|
||||
*/
|
||||
public Contact() {
|
||||
super();
|
||||
}//Contact()//
|
||||
/**
|
||||
* Gets the id value.
|
||||
* @return The id value.
|
||||
*/
|
||||
public java.lang.Integer getId() {
|
||||
return (java.lang.Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
* Gets the name value.
|
||||
* @return The name value.
|
||||
*/
|
||||
public java.lang.String getName() {
|
||||
return (java.lang.String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name value.
|
||||
* @param name The name value.
|
||||
*/
|
||||
public void setName(java.lang.String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//Contact//
|
||||
69
Foundation Test/src/com/foundation/attribute/Project.java
Normal file
69
Foundation Test/src/com/foundation/attribute/Project.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.foundation.attribute;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.util.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2005<p>
|
||||
*/
|
||||
public class Project extends AbstractModel {
|
||||
public static final Attribute ID = registerAttribute(Project.class, "id");
|
||||
public static final Attribute CONTACTS = registerCollection(Project.class, "contacts", AO_REFERENCED | AO_LAZY);
|
||||
public static final Attribute NAME = registerAttribute(Project.class, "name");
|
||||
/**
|
||||
* Project constructor.
|
||||
*/
|
||||
public Project() {
|
||||
super();
|
||||
}//Project()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result = null;
|
||||
|
||||
if(attribute == CONTACTS) {
|
||||
result = new ManagedList(10, 50);
|
||||
}//if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/**
|
||||
* Gets the id value.
|
||||
* @return The id value.
|
||||
*/
|
||||
public java.lang.Integer getId() {
|
||||
return (java.lang.Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
* Gets the contacts value.
|
||||
* @return The contacts value.
|
||||
*/
|
||||
public com.foundation.util.ManagedList getContacts() {
|
||||
return (com.foundation.util.ManagedList) getAttributeValue(CONTACTS);
|
||||
}//getContacts()//
|
||||
/**
|
||||
* Sets the contacts value.
|
||||
* @param contacts The contacts value.
|
||||
*/
|
||||
public void setContacts(com.foundation.util.ManagedList contacts) {
|
||||
setAttributeValue(CONTACTS, contacts);
|
||||
}//setContacts()//
|
||||
/**
|
||||
* Gets the name value.
|
||||
* @return The name value.
|
||||
*/
|
||||
public java.lang.String getName() {
|
||||
return (java.lang.String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name value.
|
||||
* @param name The name value.
|
||||
*/
|
||||
public void setName(java.lang.String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//Project//
|
||||
277
Foundation Test/src/com/foundation/attribute/ReflectionTest.java
Normal file
277
Foundation Test/src/com/foundation/attribute/ReflectionTest.java
Normal file
@@ -0,0 +1,277 @@
|
||||
package com.foundation.attribute;
|
||||
|
||||
import com.common.debug.Debug;
|
||||
import com.common.thread.IRunnable;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 2004<p>
|
||||
* A JUnit for testing the reflection code.
|
||||
*/
|
||||
public class ReflectionTest extends TestCase {
|
||||
/** Tracks the number of executing threads so the test does not end prematurely. */
|
||||
private int threadCount = 0;
|
||||
private int testRunCounter = 0;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 2005<p>
|
||||
* Defines a test method to allow a single runnable to work with multiple test view controllers.
|
||||
*/
|
||||
public interface ITestViewController {
|
||||
public void doTest();
|
||||
}//ITestViewController//
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 2005<p>
|
||||
* A simulated view controller for this test.
|
||||
*/
|
||||
private class AddContactToProjectViewController extends SimulatedViewController implements ITestViewController {
|
||||
private Project project;
|
||||
private Contact contact;
|
||||
private int validationCount = 0;
|
||||
|
||||
public AddContactToProjectViewController(final Project project, final Contact contact) {
|
||||
super();
|
||||
execute(new IRunnable() {
|
||||
public Object run() {
|
||||
AddContactToProjectViewController.this.project = (Project) getReflectionManager().createReflection(project);
|
||||
AddContactToProjectViewController.this.contact = (Contact) getReflectionManager().createReflection(contact);
|
||||
AddContactToProjectViewController.this.project.getContacts(); //Force the list to load so we can properly test the counting.//
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}//AddContactToProjectViewController()//
|
||||
public void doTest() {
|
||||
project.getContacts().add(contact);
|
||||
|
||||
getReflectionManager().synchronizeAll();
|
||||
|
||||
synchronized(ReflectionTest.this) {
|
||||
threadCount--;
|
||||
ReflectionTest.this.notify();
|
||||
}//synchronized//
|
||||
}//doTest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.attribute.SimulatedViewController#validate()
|
||||
*/
|
||||
public boolean validate() {
|
||||
validationCount++;
|
||||
return true; //project.getContacts().getValueCount(contact) <= 1;
|
||||
}//validate()//
|
||||
}//AddContactToProjectViewController//
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 2005<p>
|
||||
* A simulated view controller for this test.
|
||||
*/
|
||||
private class AddTwoContactsToProjectViewController extends SimulatedViewController implements ITestViewController {
|
||||
private Project project;
|
||||
private Contact contact1;
|
||||
private Contact contact2;
|
||||
|
||||
public AddTwoContactsToProjectViewController(final Project project, final Contact contact1, final Contact contact2) {
|
||||
super();
|
||||
execute(new IRunnable() {
|
||||
public Object run() {
|
||||
AddTwoContactsToProjectViewController.this.project = (Project) getReflectionManager().createReflection(project);
|
||||
AddTwoContactsToProjectViewController.this.contact1 = (Contact) getReflectionManager().createReflection(contact1);
|
||||
AddTwoContactsToProjectViewController.this.contact2 = (Contact) getReflectionManager().createReflection(contact2);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}//AddTwoContactsToProjectViewController()//
|
||||
public void doTest() {
|
||||
project.getContacts().add(contact1);
|
||||
|
||||
getReflectionManager().synchronizeAll();
|
||||
|
||||
project.getContacts().add(contact2);
|
||||
|
||||
getReflectionManager().synchronizeAll();
|
||||
|
||||
synchronized(ReflectionTest.this) {
|
||||
threadCount--;
|
||||
ReflectionTest.this.notify();
|
||||
}//synchronized//
|
||||
|
||||
//getReflectionManager().release();
|
||||
}//doTest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.attribute.SimulatedViewController#validate()
|
||||
*/
|
||||
public boolean validate() {
|
||||
return true; //project.getContacts().getValueCount(contact) <= 1;
|
||||
}//validate()//
|
||||
}//AddContactToProjectViewController//
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2005<p>
|
||||
* A runnable which invokes the doTest method of the simulated view controller.
|
||||
*/
|
||||
private class StartTest implements IRunnable {
|
||||
private ITestViewController controller;
|
||||
private long initialSleepTime = 0;
|
||||
|
||||
/**
|
||||
* StartTest constructor.
|
||||
* @param controller The simulated view controller containing a doTest method.
|
||||
* @param initialSleepTime An optional sleep time when starting up the test thread & prior to calling the controller's test method. This is useful to ensure all threads are inside the view controllers (and holding the event thread) prior to starting the test.
|
||||
*/
|
||||
public StartTest(ITestViewController controller, long initialSleepTime) {
|
||||
this.controller = controller;
|
||||
this.initialSleepTime = initialSleepTime;
|
||||
}//StartTest()//
|
||||
public Object run() {
|
||||
if(initialSleepTime > 0) {
|
||||
//Sleep the specified time.//
|
||||
try {
|
||||
Thread.sleep(initialSleepTime);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//if//
|
||||
|
||||
controller.doTest();
|
||||
|
||||
return null;
|
||||
}//run()//
|
||||
}//StartTest//
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
TestApplication.getSingleton().startup();
|
||||
}//setUpBeforeClass()//
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
TestApplication.getSingleton().shutdown();
|
||||
}//tearDownAfterClass()//
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}//setUp()//
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#tearDown()
|
||||
*/
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}//tearDown()//
|
||||
/**
|
||||
* Tests two views where one view is making several additions to a list and the other view receives the updates from the reflected object after each synchronization by the first view.
|
||||
*/
|
||||
public void testLocalListUpdates() {
|
||||
System.out.println("Starting local list updates test.");
|
||||
AddTwoContactsToProjectViewController controller1;
|
||||
final SimulatedViewController controller2;
|
||||
final Project project = new Project();
|
||||
Contact contact1 = new Contact();
|
||||
Contact contact2 = new Contact();
|
||||
Project projectReflection = null;
|
||||
|
||||
testRunCounter++;
|
||||
|
||||
//Setup the project and contact.//
|
||||
project.setName("Test Project");
|
||||
project.entityUpdate();
|
||||
contact1.setName("First Contact");
|
||||
contact1.entityUpdate();
|
||||
contact2.setName("First Contact");
|
||||
contact2.entityUpdate();
|
||||
|
||||
//Setup the view controllers.//
|
||||
controller1 = new AddTwoContactsToProjectViewController(project, contact1, contact2);
|
||||
controller2 = new SimulatedViewController();
|
||||
|
||||
//Create a project reflection so we can see if it gets updates to the contacts list.//
|
||||
projectReflection = (Project) controller2.execute(new IRunnable() {
|
||||
public Object run() {
|
||||
Project result = (Project) controller2.getReflectionManager().createReflection(project);
|
||||
|
||||
result.getContacts();
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
//projectReflection = (Project) controller2.getReflectionManager().createReflection(project);
|
||||
//projectReflection.getContacts();
|
||||
//Set the thread count so we know when to finish the test.//
|
||||
threadCount = 1;
|
||||
|
||||
//Setup two view controllers which will compete to add the contact to the project.//
|
||||
controller1.executeAsynch(new StartTest(controller1, 0));
|
||||
|
||||
synchronized(this) {
|
||||
while(threadCount != 0) {
|
||||
try {
|
||||
wait(0);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.handle(e);
|
||||
}//catch//
|
||||
}//while//
|
||||
}//synchronized//
|
||||
|
||||
//Sleep since it may take a short time for the update thread to complete its task.//
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
if((projectReflection.getContacts().getSize() != 2) || (((Contact) projectReflection.getContacts().get(0)).getReflected() != contact1) || (((Contact) projectReflection.getContacts().get(1)).getReflected() != contact2)) {
|
||||
throw new RuntimeException("Failed to receive the correct updates for a reflected list.");
|
||||
}//if//
|
||||
System.out.println("Ending local list updates test.");
|
||||
}//testLocalListUpdates()//
|
||||
/**
|
||||
* Tests a conflict between two views synchronzing the same change (addition of an object to a list) at the same time (no orb involved).
|
||||
*/
|
||||
public void testLocalListSynchronizationConflict() {
|
||||
System.out.println("Starting local sync conflict test.");
|
||||
AddContactToProjectViewController controller1;
|
||||
AddContactToProjectViewController controller2;
|
||||
Project project = new Project();
|
||||
Contact contact = new Contact();
|
||||
|
||||
testRunCounter++;
|
||||
|
||||
//Setup the project and contact.//
|
||||
project.setName("Test Project");
|
||||
project.entityUpdate();
|
||||
contact.setName("First Contact");
|
||||
contact.entityUpdate();
|
||||
|
||||
//Setup the view controllers.//
|
||||
controller1 = new AddContactToProjectViewController(project, contact);
|
||||
controller2 = new AddContactToProjectViewController(project, contact);
|
||||
|
||||
threadCount = 2;
|
||||
|
||||
//Setup two view controllers which will compete to add the contact to the project.//
|
||||
controller1.executeAsynch(new StartTest(controller1, 100));
|
||||
controller2.executeAsynch(new StartTest(controller2, 100));
|
||||
|
||||
synchronized(this) {
|
||||
while(threadCount != 0) {
|
||||
try {
|
||||
wait(0);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.handle(e);
|
||||
}//catch//
|
||||
}//while//
|
||||
}//synchronized//
|
||||
|
||||
if((controller1.validationCount + controller2.validationCount) != 3) {
|
||||
throw new RuntimeException("Failed to receive a reflection synchronize rejection when a conflict occured between two user's changes.");
|
||||
}//if//
|
||||
System.out.println("Ending local sync conflict test.");
|
||||
}//testLocalListSynchronizationConflict()//
|
||||
}//ReflectionTest//
|
||||
@@ -0,0 +1,459 @@
|
||||
package com.foundation.attribute;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
import com.common.thread.*;
|
||||
import com.foundation.view.IViewRequestHandler;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2007<p>
|
||||
* A simple version of the event loops used by view systems. This is intended primarily for use in a test system or non-view system that requires reflections.
|
||||
*/
|
||||
public class SimpleEventLoop implements Runnable, IViewRequestHandler, ISingleThreadedContext {
|
||||
/** The queue that all requests are sent to. Requests made on the event thread are handled immediatly and are never queued. */
|
||||
private Queue queue = new Queue(5);
|
||||
/** The thread currently handing requests. */
|
||||
private Thread queueRunner = null;
|
||||
/** Whether the loop is running. */
|
||||
private boolean isRunning = false;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2007<p>
|
||||
*/
|
||||
public interface IEventLoopComponent {
|
||||
public Object processRequest(int requestNumber, Object value1, Object value2, Object value3, Object value4);
|
||||
}//IEventLoopComponent//
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2007<p>
|
||||
* Maintains request information and handles notification of completion.
|
||||
*/
|
||||
private static final class Request implements Runnable {
|
||||
private IEventLoopComponent component;
|
||||
private IRunnable runnable = null;
|
||||
private int requestNumber = 0;
|
||||
private Object value1 = null;
|
||||
private Object value2 = null;
|
||||
private Object value3 = null;
|
||||
private Object value4 = null;
|
||||
private Object returnValue = null;
|
||||
private boolean requestComplete = false;
|
||||
|
||||
/**
|
||||
* Request constructor.
|
||||
*/
|
||||
private Request(IEventLoopComponent component, int requestNumber, Object value1, Object value2, Object value3, Object value4) {
|
||||
this.component = component;
|
||||
this.requestNumber = requestNumber;
|
||||
this.value1 = value1;
|
||||
this.value2 = value2;
|
||||
this.value3 = value3;
|
||||
this.value4 = value4;
|
||||
}//Request()//
|
||||
/**
|
||||
* Request constructor.
|
||||
*/
|
||||
private Request(IRunnable runnable) {
|
||||
this.runnable = runnable;
|
||||
}//Request()//
|
||||
public synchronized void waitForCompletion() {
|
||||
while(!requestComplete) {
|
||||
try {
|
||||
wait(1000);
|
||||
}//try//
|
||||
catch(InterruptedException e) {
|
||||
Debug.handle(e);
|
||||
}//catch//
|
||||
}//while//
|
||||
}//waitForCompletion()//
|
||||
public void run() {
|
||||
try {
|
||||
if(runnable != null) {
|
||||
returnValue = runnable.run();
|
||||
}//if//
|
||||
else {
|
||||
returnValue = component.processRequest(requestNumber, value1, value2, value3, value4);
|
||||
}//else//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log("Failed to complete the processing of a test view request.", e);
|
||||
}//catch//
|
||||
|
||||
synchronized(this) {
|
||||
requestComplete = true;
|
||||
notifyAll();
|
||||
}//synchronized//
|
||||
}//run()//
|
||||
}//Request//
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2007<p>
|
||||
* Encapsulates an event thread which has reliquished its status for a time while it performs some unrelated processing which may take an arbitrary amount of time.
|
||||
*/
|
||||
public class EventThread {
|
||||
/** Whether the held thread is once again the event thread. */
|
||||
private boolean isEventThread = false;
|
||||
/** The thread which requested a pause in it being the event thread. */
|
||||
private Thread eventThread = null;
|
||||
|
||||
/**
|
||||
* EventThread constructor.
|
||||
*/
|
||||
public EventThread() {
|
||||
this.eventThread = Thread.currentThread();
|
||||
}//EventThread()//
|
||||
/**
|
||||
* Requests that the calling thread become the event thread once more.
|
||||
*/
|
||||
public void requestResumeEventProcessing() {
|
||||
processRequest(this);
|
||||
}//resumeEventProcessing()//
|
||||
/**
|
||||
* Waits for the current event thread to make us the event thread.
|
||||
*/
|
||||
public void waitToResumeEventProcessing() {
|
||||
//A little bit of error checking.//
|
||||
if(eventThread != Thread.currentThread()) {
|
||||
throw new IllegalArgumentException("Only the former event thread may request it become the event thread again.");
|
||||
}//if//
|
||||
|
||||
//Synchronize so we can wait to be called on.//
|
||||
synchronized(SimpleEventLoop.this) {
|
||||
//Wait while we have not been called on to become the event thread again.//
|
||||
while(!isEventThread) {
|
||||
try {
|
||||
SimpleEventLoop.this.wait(3000);
|
||||
}//try//
|
||||
catch(InterruptedException e) {
|
||||
Debug.handle(e);
|
||||
}//catch//
|
||||
}//while//
|
||||
}//synchronized//
|
||||
|
||||
ThreadService.setIsInSingleThreadedContext(SimpleEventLoop.this);
|
||||
}//waitToResumeEventProcessing()//
|
||||
/**
|
||||
* Called by the current event thread to yield event processing to the held thread.
|
||||
* <p>Note: The caller must hold a synch lock on the SimpleEventLoop object.</p>
|
||||
*/
|
||||
private void notifyEventThread() {
|
||||
//Let the proper thread know it is now the event thread.//
|
||||
isEventThread = true;
|
||||
//Assign the new queue runner to this thread.//
|
||||
queueRunner = eventThread;
|
||||
//Notify all waiting threads.//
|
||||
SimpleEventLoop.this.notifyAll();
|
||||
}//notifyEventThread()//
|
||||
}//EventThread//
|
||||
/**
|
||||
* SimpleEventLoop constructor.
|
||||
*/
|
||||
public SimpleEventLoop() {
|
||||
}//SimpleEventLoop()//
|
||||
/**
|
||||
* Runs the request handler.
|
||||
* <p>The handler is designed to run until there are no more requests, then it will quit. When new requests arrive they will start the handler if it is not already running.</p>
|
||||
*/
|
||||
public void run() {
|
||||
boolean stop = false;
|
||||
boolean isEventThread = true;
|
||||
|
||||
ThreadService.setIsInSingleThreadedContext(this);
|
||||
isRunning = true;
|
||||
|
||||
while((isEventThread) && (!stop)) {
|
||||
try {
|
||||
Object next = null;
|
||||
|
||||
do {
|
||||
next = null;
|
||||
|
||||
//Get the next runnable.//
|
||||
synchronized(this) {
|
||||
if(queue.getSize() > 0) {
|
||||
//Check the message queue.//
|
||||
next = queue.dequeue();
|
||||
}//if//
|
||||
}//synchronized//
|
||||
|
||||
if(next != null) {
|
||||
if(next instanceof EventThread) {
|
||||
EventThread eventThread = (EventThread) next;
|
||||
|
||||
synchronized(this) {
|
||||
//Notify the event thread that it may now take over as the event thread again.//
|
||||
eventThread.notifyEventThread();
|
||||
}//synchronized//
|
||||
|
||||
//Set the flag to immediatly quit processing messages as the event thread.//
|
||||
isEventThread = false;
|
||||
}//if//
|
||||
else {
|
||||
((Runnable) next).run();
|
||||
}//else//
|
||||
}//if//
|
||||
} while((isEventThread) && (!stop) && (next != null));
|
||||
|
||||
if((isEventThread) && (!stop)) {
|
||||
synchronized(this) {
|
||||
if(queue.getSize() == 0) {
|
||||
//Wait a very short time to see if new messages are queued or event threads ready to restart. If not then reclaim this thread.//
|
||||
try {
|
||||
wait(100);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.handle(e);
|
||||
}//catch//
|
||||
|
||||
if(queue.getSize() == 0) {
|
||||
stop = true;
|
||||
queueRunner = null;
|
||||
}//if//
|
||||
}//if//
|
||||
}//synchronized//
|
||||
}//if//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
//Keep processing messages so the client might not lock up.//
|
||||
}//catch//
|
||||
}//while//
|
||||
|
||||
ThreadService.setIsInSingleThreadedContext(null);
|
||||
isRunning = false;
|
||||
}//run()//
|
||||
/**
|
||||
* Pauses the calling thread such that it is no longer the event thread and may block without affecting the event processing system.
|
||||
* When the calling thread is ready to resume being the event thread then it must call the returned EventThread object's resumeEventProcessing() method which will block until the calling thread is once again the event thread.
|
||||
* <p>Warning: The EventThread object should never be passed to another thread since it will corrupt the SimpleEventLoop state.</p>
|
||||
* @return The EventThread instance which is necessary for resuming the mantel of event thread when the thread has finished waiting.
|
||||
*/
|
||||
public EventThread pauseEventProcessing() {
|
||||
EventThread result = new EventThread();
|
||||
|
||||
ThreadService.setIsInSingleThreadedContext(this);
|
||||
|
||||
synchronized(this) {
|
||||
//Ensure that all know we are no longer the event thread.//
|
||||
queueRunner = null;
|
||||
|
||||
//If necessary, start another thread to be the event thread.//
|
||||
if(queue.getSize() != 0) {
|
||||
queueRunner = ThreadService.run(this, false);
|
||||
}//if//
|
||||
}//synchronized//
|
||||
|
||||
return result;
|
||||
}//pauseEventProcessing()//
|
||||
/**
|
||||
* Processes a request through the event thread. This is required to access any SWT method due to the design of SWT.
|
||||
* @param request The object that will be run when the request is processed.
|
||||
* @param synchronous Whether the thread should block until the request has been processed (should be true if a result is desired).
|
||||
*/
|
||||
public void processRequest(final Runnable request, boolean synchronous) {
|
||||
execute(new IRunnable() {
|
||||
public Object run() {
|
||||
request.run();
|
||||
|
||||
return null;
|
||||
}//run()//
|
||||
}, synchronous);
|
||||
}//processRequest()//
|
||||
/**
|
||||
* Processes a request through the event thread.
|
||||
* @param request The request to be processed.
|
||||
*/
|
||||
private synchronized void processRequest(Runnable request) {
|
||||
queue.enqueue(request);
|
||||
|
||||
if(queueRunner == null) {
|
||||
//Start the QueueRunner thread.//
|
||||
queueRunner = ThreadService.run(this, false);
|
||||
}//if//
|
||||
}//processRequest()//
|
||||
/**
|
||||
* Processes a request through the event thread.
|
||||
* @param request The request to be processed.
|
||||
*/
|
||||
private synchronized void processRequest(EventThread request) {
|
||||
queue.enqueue(request);
|
||||
|
||||
if(queueRunner == null) {
|
||||
//Start the QueueRunner thread.//
|
||||
queueRunner = ThreadService.run(this, false);
|
||||
}//if//
|
||||
}//processRequest()//
|
||||
/**
|
||||
* Processes a request through the event thread. This is required to access any SWT method due to the design of SWT.
|
||||
* @param component The component to handle the request.
|
||||
* @param requestNumber The request number which indicates to the component what is being requested.
|
||||
* @param value1 The first of four optional values to be passed as part of the request.
|
||||
* @param value2 The second of four optional values to be passed as part of the request.
|
||||
* @param value3 The third of four optional values to be passed as part of the request.
|
||||
* @param value4 The fourth of four optional values to be passed as part of the request.
|
||||
* @param synchronous Whether the thread should block until the request has been processed.
|
||||
* @return The result of the request. This is dependant on the request number and the component and may be null. This will be null if the call was not synchronous.
|
||||
*/
|
||||
public Object processRequest(IEventLoopComponent component, int requestNumber, Object value1, Object value2, Object value3, Object value4, boolean synchronous) {
|
||||
Object result = null;
|
||||
boolean isQueueRunner = false;
|
||||
Thread currentThread = Thread.currentThread();
|
||||
|
||||
//This synchronization is necessary in order to ensure the local processor cache is updated.//
|
||||
synchronized(this) {
|
||||
isQueueRunner = queueRunner == currentThread;
|
||||
}//synchronized//
|
||||
|
||||
//Make sure we don't have the event thread creating requests since it would deadlock the system.//
|
||||
if(!isQueueRunner) {
|
||||
Request request = new Request(component, requestNumber, value1, value2, value3, value4);
|
||||
|
||||
processRequest(request);
|
||||
|
||||
if(synchronous) {
|
||||
request.waitForCompletion();
|
||||
result = request.returnValue;
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
//The calling thread is the event thread, so there is no need to pass the request through the event thread!.//
|
||||
result = component.processRequest(requestNumber, value1, value2, value3, value4);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//processRequest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#isRunning()
|
||||
*/
|
||||
public boolean isRunning() {
|
||||
return isRunning;
|
||||
}//isRunning()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#isRequestThread()
|
||||
*/
|
||||
public boolean isRequestThread() {
|
||||
Thread currentThread = Thread.currentThread();
|
||||
|
||||
//This synchronization is necessary in order to ensure the local processor cache is updated.//
|
||||
synchronized(this) {
|
||||
return queueRunner == currentThread;
|
||||
}//synchronized//
|
||||
}//isRequestThread()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#processRequest(java.lang.Object, int, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, boolean)
|
||||
*/
|
||||
public Object processRequest(Object component, int requestNumber, Object value1, Object value2, Object value3, Object value4, boolean synchronous) {
|
||||
return processRequest((IEventLoopComponent) component, requestNumber, value1, value2, value3, value4, synchronous);
|
||||
}//processRequest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#processRequest(java.lang.Object, int, java.lang.Object, java.lang.Object, java.lang.Object, boolean)
|
||||
*/
|
||||
public Object processRequest(Object component, int requestNumber, Object value1, Object value2, Object value3, boolean synchronous) {
|
||||
return processRequest((IEventLoopComponent) component, requestNumber, value1, value2, value3, null, synchronous);
|
||||
}//processRequest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#processRequest(java.lang.Object, int, java.lang.Object, java.lang.Object, boolean)
|
||||
*/
|
||||
public Object processRequest(Object component, int requestNumber, Object value1, Object value2, boolean synchronous) {
|
||||
return processRequest((IEventLoopComponent) component, requestNumber, value1, value2, null, null, synchronous);
|
||||
}//processRequest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#processRequest(java.lang.Object, int, java.lang.Object, boolean)
|
||||
*/
|
||||
public Object processRequest(Object component, int requestNumber, Object value, boolean synchronous) {
|
||||
return processRequest((IEventLoopComponent) component, requestNumber, value, null, null, null, synchronous);
|
||||
}//processRequest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#processRequest(java.lang.Object, int, boolean)
|
||||
*/
|
||||
public Object processRequest(Object component, int requestNumber, boolean synchronous) {
|
||||
return processRequest((IEventLoopComponent) component, requestNumber, null, null, null, null, synchronous);
|
||||
}//processRequest()//
|
||||
/**
|
||||
* Processes a request through the event thread. This is required to access any SWT method due to the design of SWT.
|
||||
* @param component The component to handle the request.
|
||||
* @param requestNumber The request number which indicates to the component what is being requested.
|
||||
* @param value1 The first of three optional values to be passed as part of the request.
|
||||
* @param value2 The second of three optional values to be passed as part of the request.
|
||||
* @param value3 The third of three optional values to be passed as part of the request.
|
||||
* @param synchronous Whether the thread should block until the request has been processed.
|
||||
* @return The result of the request. This is dependant on the request number and the component and may be null. This will be null if the call was not synchronous.
|
||||
*/
|
||||
public Object processRequest(IEventLoopComponent component, int requestNumber, Object value1, Object value2, Object value3, boolean synchronous) {
|
||||
return processRequest(component, requestNumber, value1, value2, value3, null, synchronous);
|
||||
}//processRequest()//
|
||||
/**
|
||||
* Processes a request through the event thread. This is required to access any SWT method due to the design of SWT.
|
||||
* @param component The component to handle the request.
|
||||
* @param requestNumber The request number which indicates to the component what is being requested.
|
||||
* @param value1 The first of two optional values to be passed as part of the request.
|
||||
* @param value2 The second of two optional values to be passed as part of the request.
|
||||
* @return The result of the request. This is dependant on the request number and the component and may be null. This will be null if the call was not synchronous.
|
||||
*/
|
||||
public Object processRequest(IEventLoopComponent component, int requestNumber, Object value1, Object value2, boolean synchronous) {
|
||||
return processRequest(component, requestNumber, value1, value2, null, null, synchronous);
|
||||
}//processRequest()//
|
||||
/**
|
||||
* Processes a request through the event thread. This is required to access any SWT method due to the design of SWT.
|
||||
* @param component The component to handle the request.
|
||||
* @param requestNumber The request number which indicates to the component what is being requested.
|
||||
* @param value The optional values to be passed as part of the request.
|
||||
* @return The result of the request. This is dependant on the request number and the component and may be null. This will be null if the call was not synchronous.
|
||||
*/
|
||||
public Object processRequest(IEventLoopComponent component, int requestNumber, Object value, boolean synchronous) {
|
||||
return processRequest(component, requestNumber, value, null, null, null, synchronous);
|
||||
}//processRequest()//
|
||||
/**
|
||||
* Processes a request through the event thread. This is required to access any SWT method due to the design of SWT.
|
||||
* @param component The component to handle the request.
|
||||
* @param requestNumber The request number which indicates to the component what is being requested.
|
||||
* @param synchronous Whether the thread should block until the request has been processed.
|
||||
* @return The result of the request. This is dependant on the request number and the component and may be null. This will be null if the call was not synchronous.
|
||||
*/
|
||||
public Object processRequest(IEventLoopComponent component, int requestNumber, boolean synchronous) {
|
||||
return processRequest(component, requestNumber, null, null, null, null, synchronous);
|
||||
}//processRequest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#execute(com.common.thread.IRunnable, boolean)
|
||||
*/
|
||||
public Object execute(IRunnable runnable, boolean synchronous) {
|
||||
Object result = null;
|
||||
boolean isQueueRunner = false;
|
||||
Thread currentThread = Thread.currentThread();
|
||||
|
||||
//This synchronization is necessary in order to ensure the local processor cache is updated.//
|
||||
synchronized(this) {
|
||||
isQueueRunner = queueRunner == currentThread;
|
||||
}//synchronized//
|
||||
|
||||
//Make sure we don't have the event thread creating requests since it would deadlock the system.//
|
||||
if(!isQueueRunner || !synchronous) {
|
||||
Request request = new Request(runnable);
|
||||
|
||||
processRequest(request);
|
||||
|
||||
if(synchronous) {
|
||||
request.waitForCompletion();
|
||||
result = request.returnValue;
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
//The calling thread is the event thread, so there is no need to pass the request through the event thread!.//
|
||||
result = runnable.run();
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//execute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#execute(com.common.thread.IRunnable)
|
||||
*/
|
||||
public Object execute(IRunnable runnable) {
|
||||
return execute(runnable, true);
|
||||
}//execute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.event.IRequestHandler#executeAsync(com.common.thread.IRunnable)
|
||||
*/
|
||||
public void executeAsync(IRunnable runnable) {
|
||||
execute(runnable, false);
|
||||
}//executeAsync()//
|
||||
}//RequestHandler//
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.foundation.attribute;
|
||||
|
||||
import com.common.thread.*;
|
||||
import com.common.debug.*;
|
||||
import com.foundation.controller.ViewController;
|
||||
import com.foundation.view.IViewContext;
|
||||
import com.foundation.view.IViewRequestHandler;
|
||||
import com.foundation.view.ViewSystemMetadata;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 2005<p>
|
||||
*/
|
||||
public class SimulatedViewController extends ViewController {
|
||||
/**
|
||||
* Copyright Wynne Crisman 2005<p>
|
||||
* Wrappres a runnable and allows the creating thread to wait for the runnable to complete execution.
|
||||
*/
|
||||
public static class Task implements Runnable {
|
||||
private IRunnable runnable = null;
|
||||
private boolean isComplete = false;
|
||||
private Object result = null;
|
||||
|
||||
/**
|
||||
* Task constructor.
|
||||
* @param runnable
|
||||
*/
|
||||
public Task(IRunnable runnable) {
|
||||
this.runnable = runnable;
|
||||
}//Task()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
public void run() {
|
||||
result = runnable.run();
|
||||
|
||||
synchronized(this) {
|
||||
isComplete = true;
|
||||
notifyAll();
|
||||
}//synchronized//
|
||||
}//run()//
|
||||
/**
|
||||
* Waits for and retreives the result.
|
||||
* @return The result of the wrappered runnable.
|
||||
*/
|
||||
public Object waitForResult() {
|
||||
synchronized(this) {
|
||||
while(!isComplete) {
|
||||
try {
|
||||
wait(0);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.handle(e);
|
||||
}//catch//
|
||||
}//while//
|
||||
}//synchronized//
|
||||
|
||||
return result;
|
||||
}//waitForResult()//
|
||||
}//Task//
|
||||
|
||||
/**
|
||||
* SimulatedViewController constructor.
|
||||
*/
|
||||
public SimulatedViewController() {
|
||||
super(new IViewContext() {
|
||||
SimpleEventLoop loop = new SimpleEventLoop();
|
||||
|
||||
public void setApplicationData(Object applicationData) {
|
||||
}
|
||||
public Object getApplicationData() {
|
||||
return null;
|
||||
}
|
||||
public IViewRequestHandler getRequestHandler() {
|
||||
return loop;
|
||||
}
|
||||
public ViewSystemMetadata getViewSystemMetadata() {
|
||||
return null;
|
||||
}
|
||||
public Object getApplicationData(Object key) {
|
||||
return null;
|
||||
}
|
||||
public void setApplicationData(Object key, Object applicationData) {
|
||||
}
|
||||
});
|
||||
//Start the event thread simulation.//
|
||||
//eventThread = new EventThread();
|
||||
//ThreadService.run(eventThread);
|
||||
}//SimualtedViewController()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.controller.ViewController#validate()
|
||||
*/
|
||||
public boolean validate() {
|
||||
return true;
|
||||
}//validate()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.controller.AbstractViewController#getViewClass()
|
||||
*/
|
||||
protected Class getViewClass() {
|
||||
return null;
|
||||
}//getViewClass()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.controller.ViewController#execute(com.common.thread.IRunnable)
|
||||
*/
|
||||
public Object execute(IRunnable runnable) {
|
||||
return getContext().getRequestHandler().execute(runnable, true);
|
||||
}//execute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.controller.ViewController#executeAsynch(com.common.thread.IRunnable)
|
||||
*/
|
||||
public void executeAsynch(IRunnable runnable) {
|
||||
getContext().getRequestHandler().execute(runnable, false);
|
||||
}//executeAsynch()//
|
||||
}//SimulatedViewController//
|
||||
38
Foundation Test/src/com/foundation/attribute/Test.java
Normal file
38
Foundation Test/src/com/foundation/attribute/Test.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.foundation.attribute;
|
||||
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2007<p>
|
||||
*/
|
||||
public class Test {
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.foundation.attribute;
|
||||
|
||||
import com.common.debug.Debug;
|
||||
import com.common.orb.Orb;
|
||||
import com.foundation.transaction.TransactionService;
|
||||
import com.foundation.view.resource.ResourceService;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 2005<p>
|
||||
* See ReflectionTest which is a JUnit runnable. Right click and run as JUnit test.
|
||||
*/
|
||||
public class TestApplication extends com.foundation.application.Application {
|
||||
/** The one and only instance of this class. */
|
||||
private static TestApplication singleton = new TestApplication();
|
||||
/**
|
||||
* TestApplication constructor.
|
||||
*/
|
||||
private TestApplication() {
|
||||
super();
|
||||
}//TestApplication()//
|
||||
/**
|
||||
* Gets the repository identifier for the application's primary (default) repository connection.
|
||||
* @return The repository identifier the application objects will use by default.
|
||||
*/
|
||||
public Object getDefaultRepositoryIdentifier() {
|
||||
return null;
|
||||
}//getDefaultRepositoryIdentifier()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#initializeResources(com.foundation.view.resource.ResourceService)
|
||||
*/
|
||||
protected void initializeResources(ResourceService resourceService) {
|
||||
}//initializeResources()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#getMetadataLocation()
|
||||
*/
|
||||
public Object getMetadataLocation() {
|
||||
return null;
|
||||
}//getMetadataLocation()//
|
||||
/**
|
||||
* Gets the one and only application instance.
|
||||
* @return The one and only test application instance.
|
||||
*/
|
||||
public static TestApplication getSingleton() {
|
||||
return singleton;
|
||||
}//getSingleton()//
|
||||
/**
|
||||
* Starts the application by initializing the application services and then initializing the application.
|
||||
*/
|
||||
public void startup() {
|
||||
try {
|
||||
setupMetadataService();
|
||||
setupTransactionService();
|
||||
getTransactionService().debug(TransactionService.DEBUG_ALL);
|
||||
Orb.setOrbWrapper(new com.de22.orb.optional.CommonOrbWrapper(new com.de22.orb.development.OrbClassLoader(), null, null));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//startup()//
|
||||
}//TestApplication//
|
||||
107
Foundation Test/src/com/foundation/controller/test/Address.java
Normal file
107
Foundation Test/src/com/foundation/controller/test/Address.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package com.foundation.controller.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.model.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class Address extends Model implements IAddress {
|
||||
public static final Attribute CITY = registerAttribute(Address.class, "city");
|
||||
public static final Attribute COUNTRY = registerAttribute(Address.class, "country");
|
||||
public static final Attribute LINE1 = registerAttribute(Address.class, "line1");
|
||||
public static final Attribute LINE2 = registerAttribute(Address.class, "line2");
|
||||
public static final Attribute POSTAL_CODE = registerAttribute(Address.class, "postalCode");
|
||||
public static final Attribute STATE = registerAttribute(Address.class, "state");
|
||||
/**
|
||||
* Address constructor.
|
||||
*/
|
||||
public Address() {
|
||||
super();
|
||||
}//Address()//
|
||||
/**
|
||||
* Gets the application object that this object is running under. The application object provides the object various services that it will need.
|
||||
* @return The application reference for the application this object is running under.
|
||||
*/
|
||||
public com.foundation.application.IApplication getApplication() {
|
||||
return TestApplication.getSingleton();
|
||||
}//getApplication()//
|
||||
/**
|
||||
* getCity method comment.
|
||||
*/
|
||||
public String getCity() {
|
||||
return (String) getAttributeValue(CITY);
|
||||
}//getCity()//
|
||||
/**
|
||||
* getCountry method comment.
|
||||
*/
|
||||
public String getCountry() {
|
||||
return (String) getAttributeValue(COUNTRY);
|
||||
}//getCountry()//
|
||||
/**
|
||||
* getLine1 method comment.
|
||||
*/
|
||||
public String getLine1() {
|
||||
return (String) getAttributeValue(LINE1);
|
||||
}//getLine1()//
|
||||
/**
|
||||
* getLine2 method comment.
|
||||
*/
|
||||
public String getLine2() {
|
||||
return (String) getAttributeValue(LINE2);
|
||||
}//getLine2()//
|
||||
/**
|
||||
* getPostalCode method comment.
|
||||
*/
|
||||
public String getPostalCode() {
|
||||
return (String) getAttributeValue(POSTAL_CODE);
|
||||
}//getPostalCode()//
|
||||
/**
|
||||
* getState method comment.
|
||||
*/
|
||||
public String getState() {
|
||||
return (String) getAttributeValue(STATE);
|
||||
}//getState()//
|
||||
/**
|
||||
* setCity method comment.
|
||||
*/
|
||||
public void setCity(String city) {
|
||||
setAttributeValue(CITY, city);
|
||||
}//setCity()//
|
||||
/**
|
||||
* setCountry method comment.
|
||||
*/
|
||||
public void setCountry(String country) {
|
||||
setAttributeValue(COUNTRY, country);
|
||||
}//setCountry()//
|
||||
/**
|
||||
* setLine1 method comment.
|
||||
*/
|
||||
public void setLine1(String line1) {
|
||||
setAttributeValue(LINE1, line1);
|
||||
}//setLine1()//
|
||||
/**
|
||||
* setLine2 method comment.
|
||||
*/
|
||||
public void setLine2(String line2) {
|
||||
setAttributeValue(LINE2, line2);
|
||||
}//setLine2()//
|
||||
/**
|
||||
* setPostalCode method comment.
|
||||
*/
|
||||
public void setPostalCode(String postalCode) {
|
||||
setAttributeValue(POSTAL_CODE, postalCode);
|
||||
}//setPostalCode()//
|
||||
/**
|
||||
* setState method comment.
|
||||
*/
|
||||
public void setState(String state) {
|
||||
setAttributeValue(STATE, state);
|
||||
}//setState()//
|
||||
/**
|
||||
* Gets a debug string representing the object.
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString() + "\r\n" + getLine1() + "\r\n" + (((getLine2() != null) && (getLine2().length() > 0)) ? (getLine2() + "\r\n") : "") + getCity() + ", " + getState() + " " + getPostalCode();
|
||||
}//toString()//
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.foundation.controller.test;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.util.*;
|
||||
import com.foundation.controller.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class AddressController extends Controller {
|
||||
public static final Attribute ADDRESSES = registerAttribute(AddressController.class, "addresses");
|
||||
/**
|
||||
* AddressController constructor.
|
||||
*/
|
||||
public AddressController() {
|
||||
super();
|
||||
|
||||
IList addresses = new ManagedList();
|
||||
Address address = null;
|
||||
|
||||
address = new Address();
|
||||
address.setCity("San Francisco");
|
||||
address.setCountry("United States");
|
||||
address.setLine1("291 32nd Ave");
|
||||
address.setLine2("");
|
||||
address.setPostalCode("94121");
|
||||
address.setState("California");
|
||||
|
||||
addresses.add(address);
|
||||
setAddresses(addresses);
|
||||
}//AddressController()//
|
||||
/**
|
||||
* Gets a collection of all addresses.
|
||||
* @return A collection of addresses.
|
||||
*/
|
||||
public IList getAddresses() {
|
||||
return (IList) getAttributeValue(ADDRESSES);
|
||||
}//getAddresses()//
|
||||
/**
|
||||
* Gets the application object that this object is running under. The application object provides the object various services that it will need.
|
||||
* @return The application reference for the application this object is running under.
|
||||
*/
|
||||
public com.foundation.application.IApplication getApplication() {
|
||||
return TestApplication.getSingleton();
|
||||
}//getApplication()//
|
||||
private void setAddresses(IList addresses) {
|
||||
setAttributeValue(ADDRESSES, addresses);
|
||||
}//setAddresses()//
|
||||
}//AddressController//
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.foundation.controller.test;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
* Models a simple shipping address.
|
||||
*/
|
||||
public interface IAddress {
|
||||
public String getCity();
|
||||
public String getCountry();
|
||||
public String getLine1();
|
||||
public String getLine2();
|
||||
public String getPostalCode();
|
||||
public String getState();
|
||||
public void setCity(String city);
|
||||
public void setCountry(String country);
|
||||
public void setLine1(String line1);
|
||||
public void setLine2(String line2);
|
||||
public void setPostalCode(String postalCode);
|
||||
public void setState(String state);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package com.foundation.controller.test;
|
||||
|
||||
import com.common.orb.*;
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
import com.de22.orb.development.*;
|
||||
import com.de22.orb.optional.*;
|
||||
import com.foundation.util.*;
|
||||
import com.foundation.view.resource.ResourceService;
|
||||
import com.foundation.attribute.*;
|
||||
import com.foundation.controller.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class TestApplication extends com.foundation.application.Application {
|
||||
private static final TestApplication singleton = new TestApplication();
|
||||
/**
|
||||
* TestApplication constructor comment.
|
||||
*/
|
||||
protected TestApplication() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Gets the repository identifier for the application's primary (default) repository connection.
|
||||
* @return The repository identifier the application objects will use by default.
|
||||
*/
|
||||
public Object getDefaultRepositoryIdentifier() {
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#initializeResources(com.foundation.view.resource.ResourceService)
|
||||
*/
|
||||
protected void initializeResources(ResourceService resourceService) {
|
||||
}
|
||||
/**
|
||||
* Gets the location of the metadata file for this application.
|
||||
* @return The file location for the metadata file. The path may be relative or absolute.
|
||||
*/
|
||||
public Object getMetadataLocation() {
|
||||
return null;
|
||||
}
|
||||
public static TestApplication getSingleton() {
|
||||
return singleton;
|
||||
}//getSingleton()//
|
||||
public static void main(String[] args) {
|
||||
singleton.startup();
|
||||
}//main()//
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void startup() {
|
||||
try {
|
||||
com.common.system.SystemManager.setupSystem(null, new java.io.File(".\\..\\common\\").getAbsolutePath(), "WindowsCommon.dll");
|
||||
com.common.thread.ThreadService.getSingleton();
|
||||
Orb.setOrbWrapper(new CommonOrbWrapper(new OrbClassLoader(".\\proxies\\"), null, null));
|
||||
|
||||
startupApplication();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//startup()//
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void startupApplication() {
|
||||
try {
|
||||
/* Major problems - hasn't been updated to current interfaces.
|
||||
AddressController controller = new AddressController();
|
||||
IList addresses = controller.getAddresses();
|
||||
ReflectionContext reflectionContext = ViewController.createReflectionManager();
|
||||
IList addressesReflection = (IList) reflectionContext.createReflection((IReflectable) addresses, IReflectableCollection.TYPE_REFLECT, null);
|
||||
IIterator iterator = addressesReflection.iterator();
|
||||
Address newAddress = new Address();
|
||||
|
||||
newAddress.setCity("Atlanta");
|
||||
newAddress.setCountry("United States");
|
||||
newAddress.setLine1("8842 Jaw Drop Rd.");
|
||||
newAddress.setPostalCode("55420");
|
||||
newAddress.setState("Georgia");
|
||||
|
||||
Debug.log("\r\nReflection collection's initial state.");
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
addressesReflection.add(newAddress);
|
||||
Debug.log("\r\nReflection collection after adding value to the reflection collection.");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
Debug.log("\r\nReflected collection's state after adding to the reflection.");
|
||||
iterator = addresses.iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
reflectionContext.synchronizeAll();
|
||||
|
||||
Debug.log("\r\nReflected collection's state after synchronizing the reflection.");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
Debug.log("\r\nReflection collection's state after synchronizing the reflection.");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
Debug.log("\r\n\r\nNow removing the first address and synchronizing....");
|
||||
addressesReflection.remove(0);
|
||||
reflectionContext.synchronizeAll();
|
||||
|
||||
Debug.log("\r\nReflected collection's state after removing the first reflection collection value and synchronizing.");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
Debug.log("\r\nReflection collection's state after removing the first reflection collection value and synchronizing.");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
reflectionContext.unregisterAll();
|
||||
Debug.log("\r\nTest successfully completed.");
|
||||
*/
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}//startupApplication()//
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package com.foundation.controller.test;
|
||||
|
||||
import com.common.orb.*;
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
import com.de22.orb.development.*;
|
||||
import com.de22.orb.optional.*;
|
||||
import com.foundation.util.*;
|
||||
import com.foundation.view.resource.ResourceService;
|
||||
import com.foundation.attribute.*;
|
||||
import com.foundation.controller.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class TestClientApplication extends com.foundation.application.Application {
|
||||
private static final TestClientApplication singleton = new TestClientApplication();
|
||||
/**
|
||||
* TestApplication constructor comment.
|
||||
*/
|
||||
protected TestClientApplication() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Gets the repository identifier for the application's primary (default) repository connection.
|
||||
* @return The repository identifier the application objects will use by default.
|
||||
*/
|
||||
public Object getDefaultRepositoryIdentifier() {
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#initializeResources(com.foundation.view.resource.ResourceService)
|
||||
*/
|
||||
protected void initializeResources(ResourceService resourceService) {
|
||||
}
|
||||
/**
|
||||
* Gets the location of the metadata file for this application.
|
||||
* @return The file location for the metadata file. The path may be relative or absolute.
|
||||
*/
|
||||
public Object getMetadataLocation() {
|
||||
return null;
|
||||
}
|
||||
public static TestClientApplication getSingleton() {
|
||||
return singleton;
|
||||
}//getSingleton()//
|
||||
public static void main(String[] args) {
|
||||
singleton.startup();
|
||||
}//main()//
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void startup() {
|
||||
try {
|
||||
com.common.system.SystemManager.setupSystem(null, new java.io.File(".\\..\\common\\").getAbsolutePath(), "WindowsCommon.dll");
|
||||
com.common.thread.ThreadService.getSingleton();
|
||||
Orb.setOrbWrapper(new CommonOrbWrapper(new OrbClassLoader(".\\proxies\\"), null, null));
|
||||
|
||||
startupApplication();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//startup()//
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void startupApplication() {
|
||||
try {
|
||||
/* Needs major updating to conform to latest interfaces.
|
||||
Object socketId = Orb.openSocket("Server", new SocketOptions(new com.de22.orb.Address("127.0.0.1:7777"), null, null));
|
||||
|
||||
if(socketId == null) {
|
||||
throw new RuntimeException("Error: Could not open socket.");
|
||||
}//if//
|
||||
|
||||
IReflectableCollection addresses = (IReflectableCollection) Orb.lookup("Addresses", socketId);
|
||||
ReflectionContext reflectionContext = ViewController.createReflectionManager();
|
||||
IList addressesReflection = (IList) reflectionContext.createReflection(addresses, IReflectableCollection.TYPE_REFLECT, null);
|
||||
IIterator iterator = addressesReflection.iterator();
|
||||
Address newAddress = new Address();
|
||||
|
||||
newAddress.setCity("Gloomington");
|
||||
newAddress.setCountry("United States");
|
||||
newAddress.setLine1("101 Thoughts Rd.");
|
||||
newAddress.setPostalCode("19299");
|
||||
newAddress.setState("Illinois");
|
||||
|
||||
Debug.log("\r\nReflection collection's initial state.");
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
addressesReflection.add(newAddress);
|
||||
|
||||
waitForUserInput("Waiting to add a value to the reflected collection...");
|
||||
|
||||
Debug.log("\r\nReflection collection after adding value to the reflection collection.");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
waitForUserInput("Waiting to synchronize the added value...");
|
||||
|
||||
reflectionContext.synchronizeAll();
|
||||
|
||||
Debug.log("\r\nReflection collection's state after synchronizing the reflection.");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
waitForUserInput("Waiting to remove the first value and synchronize...");
|
||||
|
||||
Debug.log("\r\n\r\nNow removing the first address and synchronizing....");
|
||||
addressesReflection.remove(0);
|
||||
reflectionContext.synchronizeAll();
|
||||
|
||||
Debug.log("\r\nReflection collection's state after removing the first reflection collection value and synchronizing.");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
waitForUserInput("Waiting to shutdown...");
|
||||
|
||||
reflectionContext.unregisterAll();
|
||||
Debug.log("\r\nTest successfully completed.");
|
||||
*/
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}//startupApplication()//
|
||||
/**
|
||||
* Waits for the user to hit any key.
|
||||
*/
|
||||
public void waitForUserInput(String message) throws java.io.IOException {
|
||||
while(System.in.available() > 0) {
|
||||
System.in.read();
|
||||
}//while//
|
||||
|
||||
Debug.log(message);
|
||||
System.in.read();
|
||||
}//waitForUserInput()//
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.foundation.controller.test;
|
||||
|
||||
import com.common.orb.*;
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
import com.de22.orb.development.*;
|
||||
import com.de22.orb.optional.*;
|
||||
import com.foundation.util.*;
|
||||
import com.foundation.view.resource.ResourceService;
|
||||
import com.foundation.attribute.*;
|
||||
import com.foundation.controller.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class TestServerApplication extends com.foundation.application.Application {
|
||||
private static final TestServerApplication singleton = new TestServerApplication();
|
||||
/**
|
||||
* TestApplication constructor comment.
|
||||
*/
|
||||
protected TestServerApplication() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Gets the repository identifier for the application's primary (default) repository connection.
|
||||
* @return The repository identifier the application objects will use by default.
|
||||
*/
|
||||
public Object getDefaultRepositoryIdentifier() {
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#initializeResources(com.foundation.view.resource.ResourceService)
|
||||
*/
|
||||
protected void initializeResources(ResourceService resourceService) {
|
||||
}
|
||||
/**
|
||||
* Gets the location of the metadata file for this application.
|
||||
* @return The file location for the metadata file. The path may be relative or absolute.
|
||||
*/
|
||||
public Object getMetadataLocation() {
|
||||
return null;
|
||||
}
|
||||
public static TestServerApplication getSingleton() {
|
||||
return singleton;
|
||||
}//getSingleton()//
|
||||
public static void main(String[] args) {
|
||||
singleton.startup();
|
||||
}//main()//
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void startup() {
|
||||
try {
|
||||
com.common.system.SystemManager.setupSystem(null, new java.io.File(".\\..\\common\\").getAbsolutePath(), "WindowsCommon.dll");
|
||||
com.common.thread.ThreadService.getSingleton();
|
||||
Orb.setOrbWrapper(new CommonOrbWrapper(new OrbClassLoader(".\\proxies\\"), null, null));
|
||||
|
||||
startupApplication();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//startup()//
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected void startupApplication() {
|
||||
try {
|
||||
AddressController controller = new AddressController();
|
||||
IList addresses = controller.getAddresses();
|
||||
Address newAddress = new Address();
|
||||
IIterator iterator = addresses.iterator();
|
||||
|
||||
newAddress.setCity("Atlanta");
|
||||
newAddress.setCountry("United States");
|
||||
newAddress.setLine1("8842 Jaw Drop Rd.");
|
||||
newAddress.setPostalCode("55420");
|
||||
newAddress.setState("Georgia");
|
||||
|
||||
Orb.bind(Orb.getProxy(addresses, IReflectableCollection.class), "Addresses", null);
|
||||
Object serverSocketId = Orb.openServerSocket("MyServerSocket", new ServerSocketOptions(new com.de22.orb.Address("127.0.0.1:7777"), null, new SocketOptions()));
|
||||
|
||||
if(serverSocketId == null) {
|
||||
throw new RuntimeException("Error: Could not open the server socket.");
|
||||
}//if//
|
||||
|
||||
Debug.log("\r\nCollection's initial state:");
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
waitForUserInput("\r\nWaiting to add the new address...");
|
||||
|
||||
addresses.add(newAddress);
|
||||
Debug.log("\r\nCollection after adding value:");
|
||||
iterator.resetToFront();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Address address = (Address) iterator.next();
|
||||
|
||||
Debug.log(address.toString());
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Debug.log(" --- ");
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
waitForUserInput("\r\nTest successfully completed. Waiting to shutdown...");
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}//startupApplication()//
|
||||
/**
|
||||
* Waits for the user to hit any key.
|
||||
*/
|
||||
public void waitForUserInput(String message) throws java.io.IOException {
|
||||
while(System.in.available() > 0) {
|
||||
System.in.read();
|
||||
}//while//
|
||||
|
||||
Debug.log(message);
|
||||
System.in.read();
|
||||
}//waitForUserInput()//
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.foundation.io.test;
|
||||
|
||||
import com.common.comparison.Comparator;
|
||||
import com.common.debug.Debug;
|
||||
import com.common.io.*;
|
||||
import com.common.util.LiteHashMap;
|
||||
import com.foundation.io.*;
|
||||
|
||||
public class IndexedStreamTest {
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
final String msg1 = "This is the first test.";
|
||||
final String msg2 = "Testing Nested Streams";
|
||||
final String msg3 = "I am nested.";
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(1000, false);
|
||||
ObjectOutputStream out = new ObjectOutputStream(bout, new LiteHashMap());
|
||||
IndexedObjectOutputStream iout;
|
||||
IndexedObjectOutputStream iout2;
|
||||
|
||||
out.writeInt(100);
|
||||
iout = new IndexedObjectOutputStream(out);
|
||||
iout.begin(1);
|
||||
iout.writeObject(msg1);
|
||||
iout.begin(3);
|
||||
iout.writeObject(new Integer(100));
|
||||
iout.begin(4);
|
||||
iout.write(-20);
|
||||
iout.close();
|
||||
iout = new IndexedObjectOutputStream(out);
|
||||
iout.begin(1);
|
||||
iout.writeObject(msg2);
|
||||
iout.begin(2);
|
||||
iout2 = new IndexedObjectOutputStream(iout);
|
||||
iout2.begin(1);
|
||||
iout2.writeObject(msg3);
|
||||
iout2.close();
|
||||
iout.close();
|
||||
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
ObjectInputStream in = new ObjectInputStream(bin, null, null);
|
||||
IndexedObjectInputStream iin;
|
||||
IndexedObjectInputStream iin2;
|
||||
|
||||
if(in.readInt() != 100) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
iin = new IndexedObjectInputStream(in);
|
||||
|
||||
if(!iin.begin(1)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(!Comparator.equals(iin.readObject(), msg1)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(iin.begin(2)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(!iin.begin(3)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(!Comparator.equals(iin.readObject(), new Integer(100))) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(!iin.begin(4)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(iin.read() != -20) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
iin.close();
|
||||
iin = new IndexedObjectInputStream(in);
|
||||
|
||||
if(!iin.begin(1)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(!Comparator.equals(iin.readObject(), msg2)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(!iin.begin(2)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
iin2 = new IndexedObjectInputStream(iin);
|
||||
|
||||
if(!iin2.begin(1)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
if(!Comparator.equals(iin2.readObject(), msg3)) {
|
||||
throw new RuntimeException();
|
||||
}//if//
|
||||
|
||||
iin2.close();
|
||||
iin.close();
|
||||
|
||||
Debug.log("Success");
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}
|
||||
}
|
||||
171
Foundation Test/src/com/foundation/misc/TarTest.java
Normal file
171
Foundation Test/src/com/foundation/misc/TarTest.java
Normal file
@@ -0,0 +1,171 @@
|
||||
package com.foundation.misc;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.nio.file.LinkOption;
|
||||
|
||||
import com.common.io.StreamSupport;
|
||||
|
||||
public class TarTest {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
File out = new File("c:/temp/Movie Transfer/American Girl Movies/de_test.tar");
|
||||
FileOutputStream fout = new FileOutputStream(out);
|
||||
File[] files = {new File("c:/temp/Movie Transfer/American Girl Movies/(2004) Samantha - American Girl Holiday.avi"), new File("c:/temp/Movie Transfer/American Girl Movies/(2005) Felicity - An American Girl Adventure.avi")};
|
||||
ByteBuffer buffer = ByteBuffer.allocate(512);
|
||||
|
||||
for(int fileIndex = 0; fileIndex < files.length; fileIndex++) {
|
||||
File nextFile = files[fileIndex];
|
||||
FileChannel channel = new FileInputStream(nextFile).getChannel();
|
||||
byte[] header = new byte[512];
|
||||
byte[] name = nextFile.getName().getBytes("ASCII");
|
||||
byte[] octalLength = Long.toOctalString(nextFile.length()).getBytes("ASCII");
|
||||
byte[] timestamp = Long.toOctalString(nextFile.lastModified() / 1000).getBytes("ASCII");
|
||||
//byte[] owner = Files.getOwner(Paths.get(nextFile.toURI()), new LinkOption[] {LinkOption.NOFOLLOW_LINKS}).getName().getBytes("ASCII");
|
||||
byte[] owner = "Administrator".getBytes("ASCII");
|
||||
long checksum = 0;
|
||||
byte[] checksumBytes;
|
||||
|
||||
//Verify the name's max length.//
|
||||
if(name.length > 255) {
|
||||
throw new RuntimeException("Name too long!");
|
||||
}//if//
|
||||
|
||||
if(octalLength.length > 11) {
|
||||
throw new RuntimeException("File size too big!");
|
||||
}//if//
|
||||
|
||||
//Write the file name to the header.//
|
||||
if(name.length > 100) {
|
||||
System.arraycopy(name, 0, header, 345, name.length - 100);
|
||||
System.arraycopy(name, name.length - 100, header, 0, 100);
|
||||
}//if//
|
||||
else {
|
||||
System.arraycopy(name, 0, header, 0, name.length);
|
||||
}//else//
|
||||
|
||||
//Write the header fields.//
|
||||
header[100] = 0x30;
|
||||
header[101] = 0x31;
|
||||
header[102] = 0x30;
|
||||
header[103] = 0x30;
|
||||
header[104] = 0x36;
|
||||
header[105] = 0x36;
|
||||
header[106] = 0x36;
|
||||
header[107] = 0x00;
|
||||
header[108] = 0x30;
|
||||
header[109] = 0x30;
|
||||
header[110] = 0x30;
|
||||
header[111] = 0x30;
|
||||
header[112] = 0x30;
|
||||
header[113] = 0x30;
|
||||
header[114] = 0x30;
|
||||
header[115] = 0x00;
|
||||
header[116] = 0x30;
|
||||
header[117] = 0x30;
|
||||
header[118] = 0x30;
|
||||
header[119] = 0x30;
|
||||
header[120] = 0x30;
|
||||
header[121] = 0x30;
|
||||
header[122] = 0x30;
|
||||
header[123] = 0x00;
|
||||
//Write the length of the file in octal characters.//
|
||||
for(int index = 0; index < (11 - octalLength.length); index++) {header[124 + index] = 0x30;}
|
||||
System.arraycopy(octalLength, 0, header, 124 + (11 - octalLength.length), octalLength.length);
|
||||
header[135] = 0x00;
|
||||
//Write the modified timestamp.//
|
||||
for(int index = 0; index < (11 - timestamp.length); index++) {header[136 + index] = 0x30;}
|
||||
System.arraycopy(timestamp, 0, header, 136 + (timestamp.length > 11 ? 0 : (11 - timestamp.length)), timestamp.length > 11 ? 11 : timestamp.length);
|
||||
header[147] = 0x00;
|
||||
//Use ascii spaces for the checksum calculation, then change this to a six diget octal checksum followed by a null and an ascii space.//
|
||||
header[148] = 0x32;
|
||||
header[149] = 0x32;
|
||||
header[150] = 0x32;
|
||||
header[151] = 0x32;
|
||||
header[152] = 0x32;
|
||||
header[153] = 0x32;
|
||||
header[154] = 0x32;
|
||||
header[155] = 0x32;
|
||||
//Type flag 0 == normal file.//
|
||||
header[156] = 0x30;
|
||||
//Ignore the next 100 bytes.//
|
||||
//Write the USTAR header.//
|
||||
header[257] = 0x75;
|
||||
header[258] = 0x73;
|
||||
header[259] = 0x74;
|
||||
header[260] = 0x61;
|
||||
header[261] = 0x72;
|
||||
header[262] = 0x00; //maybe 0x20 or 0x00
|
||||
header[263] = 0x30; //maybe 0x20 or 0x30
|
||||
header[264] = 0x30; //maybe 0x00 or 0x30
|
||||
//Skip the next 80 bytes.//
|
||||
// System.arraycopy(owner, 0, header, 265, owner.length);
|
||||
//File name prefix written already.//
|
||||
|
||||
//Calculate the checksum.//
|
||||
for(int index = 0; index < header.length; index++) {
|
||||
checksum += header[index];
|
||||
}//for//
|
||||
|
||||
checksum -= 144; //I am off by 144, not sure why, but it must have something to do with the padding put in for the checksum's final resting place [148-155].//
|
||||
checksumBytes = Long.toOctalString(checksum).getBytes("ASCII");
|
||||
//Write a zero checksum initially as an easy method of zero padding the checksum. Follow the six octal digets with a null and space.//
|
||||
header[148] = 0x30;
|
||||
header[149] = 0x30;
|
||||
header[150] = 0x30;
|
||||
header[151] = 0x30;
|
||||
header[152] = 0x30;
|
||||
header[153] = 0x30;
|
||||
header[154] = 0x00;
|
||||
header[155] = 0x20;
|
||||
//Copy the checksum into the header using zeros to pad the number.//
|
||||
System.arraycopy(checksumBytes, 0, header, 148 + (6 - checksumBytes.length), checksumBytes.length);
|
||||
|
||||
//Write the 512 byte header.//
|
||||
fout.write(header);
|
||||
|
||||
//Write the file contents in blocks of 512.//
|
||||
while(channel.position() != channel.size()) {
|
||||
while(channel.read(buffer) != -1 && buffer.remaining() > 0) {}
|
||||
//int readCount = channel.read(buffer);
|
||||
|
||||
//if(readCount != buffer.capacity()) {
|
||||
if(buffer.remaining() > 0) {
|
||||
byte[] temp = new byte[buffer.remaining()];
|
||||
|
||||
buffer.put(temp);
|
||||
}//if//
|
||||
|
||||
fout.write(buffer.array());
|
||||
buffer.rewind();
|
||||
}//while//
|
||||
|
||||
channel.close();
|
||||
}//for//
|
||||
|
||||
//Write two zero filled 512 byte blocks to end the tar.//
|
||||
byte[] temp = new byte[512];
|
||||
fout.write(temp);
|
||||
fout.write(temp);
|
||||
// fout.write(temp);
|
||||
// fout.write(temp);
|
||||
// for(int index = 0; index < 10; index++) {
|
||||
// fout.write(temp);
|
||||
// }
|
||||
//Close the file.//
|
||||
fout.close();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
}//main()//
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public abstract class AbstractController extends com.foundation.controller.Controller {
|
||||
/**
|
||||
* AbstractController constructor.
|
||||
*/
|
||||
public AbstractController() {
|
||||
super();
|
||||
}//AbstractController()//
|
||||
/**
|
||||
* Gets the application object that this object is running under. The application object provides the object various services that it will need.
|
||||
* @return The application reference for the application this object is running under.
|
||||
*/
|
||||
public com.foundation.application.IApplication getApplication() {
|
||||
return TestApplication.getSingleton();
|
||||
}//getApplication()//
|
||||
}//AbstractController//
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public abstract class AbstractModel extends com.foundation.model.Model {
|
||||
/**
|
||||
* AbstractModel constructor.
|
||||
*/
|
||||
public AbstractModel() {
|
||||
super();
|
||||
}//AbstractModel()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.IEntity#getApplication()
|
||||
*/
|
||||
public com.foundation.application.IApplication getApplication() {
|
||||
return TestApplication.getSingleton();
|
||||
}//getApplication()//
|
||||
}//AbstractModel//
|
||||
169
Foundation Test/src/com/foundation/model/test/ClassA.java
Normal file
169
Foundation Test/src/com/foundation/model/test/ClassA.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.util.IManagedList;
|
||||
import com.foundation.util.ManagedList;
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.transaction.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class ClassA extends AbstractModel {
|
||||
public static final Attribute KEY = registerAttribute(ClassA.class, "key");
|
||||
public static final Attribute NAME = registerAttribute(ClassA.class, "name");
|
||||
public static final Attribute CLASS_B = registerAttribute(ClassA.class, "classB", AO_REFERENCED); //B key exists in this object.//
|
||||
public static final Attribute CLASS_B_KEY = registerAttribute(ClassA.class, "classBKey", CLASS_B, ClassB.KEY);
|
||||
public static final Attribute CLASS_C = registerAttribute(ClassA.class, "classC", AO_PART_OF); //C key exists in this object.//
|
||||
public static final Attribute CLASS_C_KEY = registerAttribute(ClassA.class, "classCKey", CLASS_C, ClassC.KEY);
|
||||
public static final Attribute CLASS_D = registerAttribute(ClassA.class, "classD", AO_REFERENCED); //A key exists in D and D references this object.//
|
||||
|
||||
public static final Attribute GADGETS = registerCollection(ClassA.class, "gadgets", AO_PART_OF | AO_LAZY);
|
||||
public static final Attribute WIDGETS = registerCollection(ClassA.class, "widgets", AO_REFERENCED | AO_LAZY);
|
||||
public static final Attribute THINGS = registerCollection(ClassA.class, "things", AO_PART_OF | AO_LAZY | AO_MAPPED); //Use a mapping table.//
|
||||
/**
|
||||
* ClassA constructor comment.
|
||||
*/
|
||||
public ClassA() {
|
||||
super();
|
||||
}//ClassA()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#createCollectionMap(com.foundation.metadata.Attribute, java.lang.Object)
|
||||
*/
|
||||
protected com.foundation.common.Entity createCollectionMap(Attribute attribute, Object value) {
|
||||
if(attribute == THINGS) {
|
||||
return new ClassAThing(this, (Thing) value);
|
||||
}//if//
|
||||
else {
|
||||
return super.createCollectionMap(attribute, value);
|
||||
}//else//
|
||||
}//createCollectionMap()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result = null;
|
||||
|
||||
if(attribute == GADGETS) { //Part of: May query here since we should hold the logical object lock.//
|
||||
if(getKey() != null) {
|
||||
Gadget query = new Gadget();
|
||||
|
||||
query.setClassA(this);
|
||||
result = getTransactionService().readMany(query, new ManagedList());
|
||||
}//if//
|
||||
else {
|
||||
result = new ManagedList();
|
||||
}//else//
|
||||
}//if//
|
||||
else if(attribute == WIDGETS) {
|
||||
if(getKey() != null) {
|
||||
//Delegate to the model controller to load the widgets.//
|
||||
result = WidgetController.getSingleton().getWidgets();
|
||||
}//if//
|
||||
else {
|
||||
result = new ManagedList();
|
||||
}//else//
|
||||
}//else if//
|
||||
else if(attribute == THINGS) {
|
||||
if(getKey() != null) {
|
||||
Thing query = new Thing();
|
||||
ClassAThing map = new ClassAThing(this);
|
||||
ReadManyTransactionDefinition definition = new ReadManyTransactionDefinition(query, null, new Attribute[0], null);
|
||||
ReadManyTransaction transaction = null;
|
||||
|
||||
//Setup the query to retrieve Thing objects given this ClassA object.//
|
||||
definition.addParticipant(map);
|
||||
definition.addRequirement(query, query.KEY, Operator.EQUALS, map, map.THING_KEY);
|
||||
//definition.addRequirement(map, map.CLASS_A_KEY, Operator.EQUALS);
|
||||
definition.addRequirements(map);
|
||||
//Create a transaction from the query definition and supply it with the necessary model objects.//
|
||||
transaction = definition.createTransaction(query);
|
||||
transaction.addParticipant(map);
|
||||
//Make sure to provide a result collection capable of being used in the model.//
|
||||
transaction.setResultCollection(new ManagedList());
|
||||
|
||||
//Perform the query and return the results.//
|
||||
result = query.getTransactionService().readMany(transaction);
|
||||
}//if//
|
||||
else {
|
||||
result = new ManagedList();
|
||||
}//else//
|
||||
}//else if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/**
|
||||
* Gets the class B reference.
|
||||
*/
|
||||
public ClassB getClassB() {
|
||||
return (ClassB) getAttributeValue(CLASS_B);
|
||||
}//getClassB()//
|
||||
/**
|
||||
* Gets the class C reference.
|
||||
*/
|
||||
public ClassC getClassC() {
|
||||
return (ClassC) getAttributeValue(CLASS_C);
|
||||
}//getClassC()//
|
||||
/**
|
||||
* Gets the class D reference.
|
||||
*/
|
||||
public ClassD getClassD() {
|
||||
return (ClassD) getAttributeValue(CLASS_D);
|
||||
}//getClassD()//
|
||||
/**
|
||||
* Gets the gadgets collection.
|
||||
*/
|
||||
public IManagedList getGadgets() {
|
||||
return (IManagedList) getAttributeValue(GADGETS);
|
||||
}//getGadgets()//
|
||||
/**
|
||||
* Gets the key.
|
||||
*/
|
||||
public Integer getKey() {
|
||||
return (Integer) getAttributeValue(KEY);
|
||||
}//getKey()//
|
||||
/**
|
||||
* Gets the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Gets the things collection.
|
||||
*/
|
||||
public IManagedList getThings() {
|
||||
return (IManagedList) getAttributeValue(THINGS);
|
||||
}//getThings()//
|
||||
/**
|
||||
* Gets the widgets collection.
|
||||
*/
|
||||
public IManagedList getWidgets() {
|
||||
return (IManagedList) getAttributeValue(WIDGETS);
|
||||
}//getWidgets()//
|
||||
/**
|
||||
* Sets the class B reference.
|
||||
*/
|
||||
public void setClassB(ClassB classB) {
|
||||
setAttributeValue(CLASS_B, classB);
|
||||
}//setClassB()//
|
||||
/**
|
||||
* Sets the class C reference.
|
||||
*/
|
||||
public void setClassC(ClassC classC) {
|
||||
setAttributeValue(CLASS_C, classC);
|
||||
}//setClassC()//
|
||||
/**
|
||||
* Sets the class D reference.
|
||||
*/
|
||||
public void setClassD(ClassD classD) {
|
||||
setAttributeValue(CLASS_D, classD);
|
||||
}//setClassD()//
|
||||
/**
|
||||
* Sets the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//ClassA//
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
* A mapping object between ClassA instances and Thing instances.
|
||||
*/
|
||||
public class ClassAThing extends AbstractModel {
|
||||
public static final Attribute CLASS_A = registerAttribute(ClassAThing.class, "classA", AO_REFERENCED);
|
||||
public static final Attribute CLASS_A_KEY = registerAttribute(ClassAThing.class, "classAKey", CLASS_A, ClassA.KEY);
|
||||
public static final Attribute THING = registerAttribute(ClassAThing.class, "thing", AO_REFERENCED);
|
||||
public static final Attribute THING_KEY = registerAttribute(ClassAThing.class, "thingKey", THING, Thing.KEY);
|
||||
/**
|
||||
* ClassAThing constructor comment.
|
||||
*/
|
||||
public ClassAThing() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* ClassAThing constructor comment.
|
||||
*/
|
||||
public ClassAThing(ClassA classA) {
|
||||
super();
|
||||
setClassA(classA);
|
||||
}
|
||||
/**
|
||||
* ClassAThing constructor comment.
|
||||
*/
|
||||
public ClassAThing(ClassA classA, Thing thing) {
|
||||
super();
|
||||
setClassA(classA);
|
||||
setThing(thing);
|
||||
}
|
||||
/**
|
||||
* ClassAThing constructor comment.
|
||||
*/
|
||||
public ClassAThing(Thing thing) {
|
||||
super();
|
||||
setThing(thing);
|
||||
}
|
||||
/**
|
||||
* Gets the class A reference.
|
||||
*/
|
||||
public ClassA getClassA() {
|
||||
return (ClassA) getAttributeValue(CLASS_A);
|
||||
}//getClassA()//
|
||||
/**
|
||||
* Gets the thing reference.
|
||||
*/
|
||||
public Thing getThing() {
|
||||
return (Thing) getAttributeValue(THING);
|
||||
}//getThing()//
|
||||
/**
|
||||
* Sets the class A reference.
|
||||
*/
|
||||
public void setClassA(ClassA classA) {
|
||||
setAttributeValue(CLASS_A, classA);
|
||||
}//setClassA()//
|
||||
/**
|
||||
* Sets the thing reference.
|
||||
*/
|
||||
public void setThing(Thing thing) {
|
||||
setAttributeValue(THING, thing);
|
||||
}//setThing()//
|
||||
}
|
||||
41
Foundation Test/src/com/foundation/model/test/ClassB.java
Normal file
41
Foundation Test/src/com/foundation/model/test/ClassB.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class ClassB extends AbstractModel {
|
||||
public static final Attribute KEY = registerAttribute(ClassB.class, "key");
|
||||
public static final Attribute NAME = registerAttribute(ClassB.class, "name");
|
||||
/**
|
||||
* ClassB constructor comment.
|
||||
*/
|
||||
public ClassB() {
|
||||
super();
|
||||
}//ClassB()//
|
||||
/**
|
||||
* Gets the key.
|
||||
*/
|
||||
public Integer getKey() {
|
||||
return (Integer) getAttributeValue(KEY);
|
||||
}//getKey()//
|
||||
/**
|
||||
* @param key
|
||||
*/
|
||||
public void setKey(Integer key) {
|
||||
setAttributeValue(KEY, key);
|
||||
}//setKey()//
|
||||
/**
|
||||
* Gets the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//ClassB//
|
||||
38
Foundation Test/src/com/foundation/model/test/ClassC.java
Normal file
38
Foundation Test/src/com/foundation/model/test/ClassC.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class ClassC extends AbstractModel {
|
||||
public static final Attribute KEY = registerAttribute(ClassC.class, "key");
|
||||
public static final Attribute NAME = registerAttribute(ClassC.class, "name");
|
||||
/**
|
||||
* ClassC constructor.
|
||||
*/
|
||||
public ClassC() {
|
||||
super();
|
||||
}//ClassC()//
|
||||
/**
|
||||
* Gets the key.
|
||||
*/
|
||||
public Integer getKey() {
|
||||
return (Integer) getAttributeValue(KEY);
|
||||
}//getKey()//
|
||||
public void setKey(Integer key) {
|
||||
setAttributeValue(KEY, key);
|
||||
}
|
||||
/**
|
||||
* Gets the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//ClassC//
|
||||
49
Foundation Test/src/com/foundation/model/test/ClassD.java
Normal file
49
Foundation Test/src/com/foundation/model/test/ClassD.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class ClassD extends AbstractModel {
|
||||
public static final Attribute KEY = registerAttribute(ClassD.class, "key");
|
||||
public static final Attribute NAME = registerAttribute(ClassD.class, "name");
|
||||
public static final Attribute CLASS_A = registerAttribute(ClassD.class, "classA", AO_REFERENCED); //A key exists in this object.//
|
||||
public static final Attribute CLASS_A_KEY = registerAttribute(ClassD.class, "classAKey", CLASS_A, ClassA.KEY);
|
||||
/**
|
||||
* ClassD constructor comment.
|
||||
*/
|
||||
public ClassD() {
|
||||
super();
|
||||
}//ClassD()//
|
||||
/**
|
||||
* Gets the class A reference.
|
||||
*/
|
||||
public ClassA getClassA() {
|
||||
return (ClassA) getAttributeValue(CLASS_A);
|
||||
}//getClassA()//
|
||||
/**
|
||||
* Gets the key.
|
||||
*/
|
||||
public Integer getKey() {
|
||||
return (Integer) getAttributeValue(KEY);
|
||||
}//getKey()//
|
||||
/**
|
||||
* Gets the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the class A reference.
|
||||
*/
|
||||
public void setClassA(ClassA classA) {
|
||||
setAttributeValue(CLASS_A, classA);
|
||||
}//setClassA()//
|
||||
/**
|
||||
* Sets the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//ClassD//
|
||||
147
Foundation Test/src/com/foundation/model/test/DbPart.java
Normal file
147
Foundation Test/src/com/foundation/model/test/DbPart.java
Normal file
@@ -0,0 +1,147 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.foundation.common.AttributeBinding;
|
||||
import com.foundation.event.model.ModelListener;
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2006<p>
|
||||
*/
|
||||
public class DbPart extends AbstractModel {
|
||||
public static final Attribute ID = registerAttribute(DbPart.class, "id");
|
||||
public static final Attribute NAME = registerAttribute(DbPart.class, "name");
|
||||
public static final Attribute PRODUCT = registerAttribute(DbPart.class, "product", DbProduct.class);
|
||||
public static final Attribute COST = registerAttribute(DbPart.class, "cost", AO_LAZY);
|
||||
public static final Attribute PRICE = registerAttribute(DbPart.class, "price", AO_CALCULATED);
|
||||
/**
|
||||
* DbPart constructor.
|
||||
*/
|
||||
public DbPart() {
|
||||
super();
|
||||
}//DbPart()//
|
||||
/**
|
||||
* DbPart constructor.
|
||||
*/
|
||||
public DbPart(String name, BigDecimal cost) {
|
||||
super();
|
||||
setName(name);
|
||||
setAttributeValue(PRICE, new BigDecimal(0));
|
||||
setCost(cost);
|
||||
}//DbPart()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == COST) {
|
||||
result = new BigDecimal(1.50);
|
||||
}//if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeRegister(com.foundation.metadata.Attribute, com.foundation.common.Entity.ICalculatedAttributeListener)
|
||||
*/
|
||||
protected ModelListener calculatedAttributeRegister(Attribute attribute, ICalculatedAttributeListener listener) {
|
||||
if(attribute == PRICE) {
|
||||
ModelListener priceListener = new ModelListener(this);
|
||||
priceListener.addBinding(new AttributeBinding(DbPart.class, COST, 0, listener, null));
|
||||
priceListener.addBinding(new AttributeBinding(DbPart.class, PRODUCT));
|
||||
priceListener.addBinding(new AttributeBinding(DbProduct.class, DbProduct.MARKUP, 0, listener, null));
|
||||
priceListener.initialize();
|
||||
return priceListener;
|
||||
}//if//
|
||||
else {
|
||||
return super.calculatedAttributeRegister(attribute, listener);
|
||||
}//else//
|
||||
}//calculatedAttributeRegister()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeUpdate(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object calculatedAttributeUpdate(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == PRICE) {
|
||||
result = calculatePrice();
|
||||
}//if//
|
||||
else {
|
||||
result = super.calculatedAttributeUpdate(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeUpdate()//
|
||||
/**
|
||||
* Gets the id for the part.
|
||||
* @return
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
* Gets the name for the part.
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name for the part.
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
/**
|
||||
* Gets the cost for the part.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getCost() {
|
||||
return (BigDecimal) getAttributeValue(COST);
|
||||
}//getCost()//
|
||||
/**
|
||||
* Sets the cost for the part.
|
||||
* @param cost
|
||||
*/
|
||||
public void setCost(BigDecimal cost) {
|
||||
if(cost == null) {
|
||||
cost = new BigDecimal(0.00);
|
||||
}//if//
|
||||
|
||||
setAttributeValue(COST, cost);
|
||||
}//setCost()//
|
||||
/**
|
||||
* Gets the part's containing product.
|
||||
* @return
|
||||
*/
|
||||
public DbProduct getProduct() {
|
||||
return (DbProduct) getAttributeValue(PRODUCT);
|
||||
}//getProduct()//
|
||||
/**
|
||||
* Calculates the price for the item based on the product's markup.
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal calculatePrice() {
|
||||
BigDecimal result = getCost();
|
||||
|
||||
if(getProduct() != null) {
|
||||
result = result.multiply(getProduct().getMarkup());
|
||||
}//if//
|
||||
|
||||
result.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
return result;
|
||||
}//calculatePrice()//
|
||||
/**
|
||||
* Gets the price for the part which is a function of the product's markup and the cost of this item.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getPrice() {
|
||||
return (BigDecimal) getAttributeValue(PRICE);
|
||||
}//getPrice()//
|
||||
}//Part//
|
||||
171
Foundation Test/src/com/foundation/model/test/DbProduct.java
Normal file
171
Foundation Test/src/com/foundation/model/test/DbProduct.java
Normal file
@@ -0,0 +1,171 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.common.util.IIterator;
|
||||
import com.foundation.common.AttributeBinding;
|
||||
import com.foundation.event.model.ModelListener;
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.util.IManagedList;
|
||||
import com.foundation.util.ManagedList;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2006<p>
|
||||
*/
|
||||
public class DbProduct extends AbstractModel {
|
||||
public static final Attribute ID = registerAttribute(DbProduct.class, "id");
|
||||
public static final Attribute NAME = registerAttribute(DbProduct.class, "name");
|
||||
public static final Attribute PARTS = registerCollection(DbProduct.class, "parts", AO_LAZY | AO_PART_OF);
|
||||
public static final Attribute COST = registerAttribute(DbProduct.class, "cost", AO_CALCULATED);
|
||||
public static final Attribute PRICE = registerAttribute(DbProduct.class, "price", AO_CALCULATED);
|
||||
public static final Attribute MARKUP = registerAttribute(DbProduct.class, "markup");
|
||||
/**
|
||||
* DbProduct constructor.
|
||||
*/
|
||||
public DbProduct() {
|
||||
super();
|
||||
}//DbProduct()//
|
||||
/**
|
||||
* DbProduct constructor.
|
||||
*/
|
||||
public DbProduct(String name) {
|
||||
super();
|
||||
setAttributeValue(NAME, name);
|
||||
setAttributeValue(MARKUP, new BigDecimal(1.5));
|
||||
setAttributeValue(COST, new BigDecimal(0));
|
||||
setAttributeValue(PRICE, new BigDecimal(0));
|
||||
}//DbProduct()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == PARTS) {
|
||||
result = new ManagedList(10, 20);
|
||||
}//if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeRegister(com.foundation.metadata.Attribute, com.foundation.common.Entity.ICalculatedAttributeListener)
|
||||
*/
|
||||
protected ModelListener calculatedAttributeRegister(Attribute attribute, ICalculatedAttributeListener listener) {
|
||||
if(attribute == COST) {
|
||||
ModelListener costListener = new ModelListener(this);
|
||||
costListener.addBinding(new AttributeBinding(DbProduct.class, PARTS));
|
||||
costListener.addBinding(new AttributeBinding(DbPart.class, DbPart.COST, 0, listener, null));
|
||||
costListener.initialize();
|
||||
return costListener;
|
||||
}//if//
|
||||
else if(attribute == PRICE) {
|
||||
ModelListener priceListener = new ModelListener(this);
|
||||
priceListener.addBinding(new AttributeBinding(DbProduct.class, PARTS));
|
||||
priceListener.addBinding(new AttributeBinding(DbPart.class, DbPart.PRICE, 0, listener, null));
|
||||
priceListener.initialize();
|
||||
return priceListener;
|
||||
}//else if//
|
||||
else {
|
||||
return super.calculatedAttributeRegister(attribute, listener);
|
||||
}//else//
|
||||
}//calculatedAttributeRegister()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeUpdate(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object calculatedAttributeUpdate(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == COST) {
|
||||
result = calculateCost();
|
||||
}//if//
|
||||
else if(attribute == PRICE) {
|
||||
result = calculatePrice();
|
||||
}//else if//
|
||||
else {
|
||||
result = super.calculatedAttributeUpdate(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeUpdate()//
|
||||
/**
|
||||
* Calculates the total cost for the product.
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal calculateCost() {
|
||||
BigDecimal result = new BigDecimal(0.00);
|
||||
IIterator iterator = getParts().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
DbPart part = (DbPart) iterator.next();
|
||||
|
||||
result = result.add(part.getCost());
|
||||
}//while//
|
||||
|
||||
result.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
return result;
|
||||
}//calculateCost()//
|
||||
/**
|
||||
* Calculates the total price for the product.
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal calculatePrice() {
|
||||
BigDecimal result = new BigDecimal(0.00);
|
||||
IIterator iterator = getParts().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
DbPart part = (DbPart) iterator.next();
|
||||
|
||||
result = result.add(part.getPrice());
|
||||
}//while//
|
||||
|
||||
result.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
return result;
|
||||
}//calculatePrice()//
|
||||
/**
|
||||
* Gets the name for the product.
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Gets the id for the part.
|
||||
* @return
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
* Gets the total cost for the product.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getCost() {
|
||||
return (BigDecimal) getAttributeValue(COST);
|
||||
}//getCost()//
|
||||
/**
|
||||
* Gets the total price for the product.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getPrice() {
|
||||
return (BigDecimal) getAttributeValue(PRICE);
|
||||
}//getPrice()//
|
||||
/**
|
||||
* Gets the total cost markup used to generate the price for the product.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getMarkup() {
|
||||
return (BigDecimal) getAttributeValue(MARKUP);
|
||||
}//getMarkup()//
|
||||
/**
|
||||
* Gets the parts that make up this product.
|
||||
* @return
|
||||
*/
|
||||
public IManagedList getParts() {
|
||||
return (IManagedList) getAttributeValue(PARTS);
|
||||
}//getParts()//
|
||||
}//Product//
|
||||
89
Foundation Test/src/com/foundation/model/test/Employee.java
Normal file
89
Foundation Test/src/com/foundation/model/test/Employee.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.foundation.util.*;
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.transaction.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
* Models the employee and its zero or more employers.
|
||||
*/
|
||||
public class Employee extends AbstractModel {
|
||||
public static final Attribute ID = registerAttribute(Employee.class, "id");
|
||||
public static final Attribute NAME = registerAttribute(Employee.class, "name");
|
||||
public static final Attribute EMPLOYERS = registerCollection(Employee.class, "employers", AO_LAZY); //Not mapped because we don't want to store the mapping twice (Employer has a mapped collection).//
|
||||
/**
|
||||
* Employee constructor.
|
||||
*/
|
||||
public Employee() {
|
||||
super();
|
||||
}//Employee()//
|
||||
/**
|
||||
* Employee constructor.
|
||||
*/
|
||||
public Employee(String name) {
|
||||
super();
|
||||
setName(name);
|
||||
}//Employee()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public IList getEmployers() {
|
||||
return (IList) getAttributeValue(EMPLOYERS);
|
||||
}//getEmployers()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == EMPLOYERS) {
|
||||
if(getId() != null) {
|
||||
//TODO: Should use a ModelController to manage objects in memory and shared access.//
|
||||
Employer query = new Employer();
|
||||
EmployeeEmployerMap map = new EmployeeEmployerMap(this);
|
||||
ReadManyTransactionDefinition transactionDefinition = new ReadManyTransactionDefinition(query, null, new Attribute[0], null);
|
||||
ReadManyTransaction transaction = null;
|
||||
|
||||
transactionDefinition.addParticipant(map);
|
||||
transactionDefinition.addRequirement(query, query.ID, Operator.EQUALS, map, map.EMPLOYER_ID);
|
||||
transaction = transactionDefinition.createTransaction(query);
|
||||
transaction.addParticipant(map);
|
||||
transaction.setResultCollection(new ManagedList());
|
||||
|
||||
result = getTransactionService().readMany(transaction);
|
||||
}//if//
|
||||
else {
|
||||
result = new ManagedList();
|
||||
}//else//
|
||||
}//if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//Employee//
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
* Provides the mapping between employees and employers.
|
||||
*/
|
||||
public class EmployeeEmployerMap extends AbstractModel {
|
||||
public static final Attribute EMPLOYEE = registerAttribute(EmployeeEmployerMap.class, "employee");
|
||||
public static final Attribute EMPLOYER = registerAttribute(EmployeeEmployerMap.class, "employer");
|
||||
public static final Attribute EMPLOYEE_ID = registerAttribute(EmployeeEmployerMap.class, "employeeId", EMPLOYEE, Employee.ID);
|
||||
public static final Attribute EMPLOYER_ID = registerAttribute(EmployeeEmployerMap.class, "employerId", EMPLOYER, Employer.ID);
|
||||
/**
|
||||
* EmployeeEmployerMap constructor.
|
||||
*/
|
||||
public EmployeeEmployerMap() {
|
||||
super();
|
||||
}//EmployeeEmployerMap()//
|
||||
/**
|
||||
* EmployeeEmployerMap constructor.
|
||||
*/
|
||||
public EmployeeEmployerMap(Employee employee) {
|
||||
super();
|
||||
setEmployee(employee);
|
||||
}//EmployeeEmployerMap()//
|
||||
/**
|
||||
* EmployeeEmployerMap constructor.
|
||||
*/
|
||||
public EmployeeEmployerMap(Employee employee, Employer employer) {
|
||||
super();
|
||||
setEmployee(employee);
|
||||
setEmployer(employer);
|
||||
}//EmployeeEmployerMap()//
|
||||
/**
|
||||
* EmployeeEmployerMap constructor.
|
||||
*/
|
||||
public EmployeeEmployerMap(Employer employer) {
|
||||
super();
|
||||
setEmployer(employer);
|
||||
}//EmployeeEmployerMap()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Employee getEmployee() {
|
||||
return (Employee) getAttributeValue(EMPLOYEE);
|
||||
}//getEmployee()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Employer getEmployer() {
|
||||
return (Employer) getAttributeValue(EMPLOYER);
|
||||
}//getEmployer()//
|
||||
/**
|
||||
*
|
||||
* @param employee
|
||||
*/
|
||||
public void setEmployee(Employee employee) {
|
||||
setAttributeValue(EMPLOYEE, employee);
|
||||
}//setEmployee()//
|
||||
/**
|
||||
*
|
||||
* @param employer
|
||||
*/
|
||||
public void setEmployer(Employer employer) {
|
||||
setAttributeValue(EMPLOYER, employer);
|
||||
}//setEmployer()//
|
||||
}//EmployeeEmployerMap//
|
||||
222
Foundation Test/src/com/foundation/model/test/Employer.java
Normal file
222
Foundation Test/src/com/foundation/model/test/Employer.java
Normal file
@@ -0,0 +1,222 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.common.comparison.Comparator;
|
||||
import com.foundation.common.AttributeBinding;
|
||||
import com.foundation.event.model.IModelListenerCollectionHandler;
|
||||
import com.foundation.event.model.ModelListener;
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.util.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
* Models the employer and its zero or more employees.
|
||||
*/
|
||||
public class Employer extends AbstractModel {
|
||||
public static final Attribute ID = registerAttribute(Employer.class, "id");
|
||||
public static final Attribute NAME = registerAttribute(Employer.class, "name");
|
||||
public static final Attribute EMPLOYEE_COUNT = registerAttribute(Employer.class, "employeeCount", AO_CALCULATED);
|
||||
public static final Attribute EMPLOYEES = registerCollection(Employer.class, "employees", AO_LAZY | AO_MAPPED | AO_PART_OF);
|
||||
public static final Attribute CEO = registerAttribute(Employer.class, "ceo", AO_PART_OF | AO_LAZY);
|
||||
public static final Attribute JANITOR = registerAttribute(Employer.class, "janitor", AO_PART_OF | AO_LAZY);
|
||||
public static final Attribute CEO_ID = registerAttribute(Employer.class, "ceoId", CEO, com.foundation.model.test.Employee.ID);
|
||||
public static final Attribute JANITOR_ID = registerAttribute(Employer.class, "janitorId", JANITOR, com.foundation.model.test.Employee.ID);
|
||||
public static final Attribute PHONE_NUMBERS = registerCollection(Employer.class, "phoneNumbers", AO_PART_OF | AO_LAZY);
|
||||
/**
|
||||
* Employer constructor.
|
||||
*/
|
||||
public Employer() {
|
||||
super();
|
||||
}//Employer()//
|
||||
/**
|
||||
* Employer constructor.
|
||||
*/
|
||||
public Employer(String name) {
|
||||
super();
|
||||
setName(name);
|
||||
}//Employer()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#createCollectionMap(com.foundation.metadata.Attribute, java.lang.Object)
|
||||
*/
|
||||
protected com.foundation.common.Entity createCollectionMap(Attribute attribute, Object value) {
|
||||
if(attribute == EMPLOYEES) {
|
||||
return new EmployeeEmployerMap((Employee) value, this);
|
||||
}//if//
|
||||
else {
|
||||
return super.createCollectionMap(attribute, value);
|
||||
}//else//
|
||||
}//createCollectionMap()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result = null;
|
||||
|
||||
if(attribute == EMPLOYEES) {
|
||||
/*
|
||||
//TODO: Should use a ModelController to manage objects in memory and shared access.//
|
||||
Employee query = new Employee();
|
||||
EmployeeEmployerMap map = new EmployeeEmployerMap(this);
|
||||
ReadManyTransactionDefinition transactionDefinition = new ReadManyTransactionDefinition(query, null, new int[0], null);
|
||||
ReadManyTransaction transaction = null;
|
||||
|
||||
transactionDefinition.addParticipant(map);
|
||||
transactionDefinition.addRequirement(query, query.ID, Operator.EQUALS, map, map.EMPLOYEE_ID);
|
||||
transactionDefinition.addRequirements(map);
|
||||
transaction = transactionDefinition.createTransaction(query);
|
||||
transaction.addParticipant(map);
|
||||
transaction.setResultCollection(new ManagedList());
|
||||
|
||||
return getTransactionService().readMany(transaction);
|
||||
*/
|
||||
result = new ManagedList(10, 20);
|
||||
}//if//
|
||||
else if(attribute == PHONE_NUMBERS) {
|
||||
result = new ManagedHashSet(10);
|
||||
}//else if//
|
||||
else if(attribute == JANITOR) {
|
||||
Integer janitorId = getJanitorId();
|
||||
IManagedList employees = getEmployees();
|
||||
|
||||
if(janitorId != null) {
|
||||
for(int index = 0, length = employees.getSize(); result == null && index < length; index++) {
|
||||
Employee next = (Employee) employees.get(index);
|
||||
|
||||
if(Comparator.equals(next.getId(), janitorId)) {
|
||||
result = next;
|
||||
}//if//
|
||||
}//for//
|
||||
}//if//
|
||||
}//else if//
|
||||
else if(attribute == CEO) {
|
||||
Integer ceoId = getCeoId();
|
||||
IManagedList employees = getEmployees();
|
||||
|
||||
if(ceoId != null) {
|
||||
for(int index = 0, length = employees.getSize(); result == null && index < length; index++) {
|
||||
Employee next = (Employee) employees.get(index);
|
||||
|
||||
if(Comparator.equals(next.getId(), ceoId)) {
|
||||
result = next;
|
||||
}//if//
|
||||
}//for//
|
||||
}//if//
|
||||
}//else if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeRegister(com.foundation.metadata.Attribute, com.foundation.common.Entity.ICalculatedAttributeListener)
|
||||
*/
|
||||
protected ModelListener calculatedAttributeRegister(Attribute attribute, ICalculatedAttributeListener listener) {
|
||||
if(attribute == EMPLOYEE_COUNT) {
|
||||
ModelListener employeeCountListener = new ModelListener(this);
|
||||
employeeCountListener.addBinding(new AttributeBinding(Employer.class, EMPLOYEES, 0, null, new IModelListenerCollectionHandler[] {listener}));
|
||||
employeeCountListener.initialize();
|
||||
return employeeCountListener;
|
||||
}//if//
|
||||
else {
|
||||
return super.calculatedAttributeRegister(attribute, listener);
|
||||
}//else//
|
||||
}//calculatedAttributeRegister()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeUpdate(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object calculatedAttributeUpdate(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == EMPLOYEE_COUNT) {
|
||||
result = new Integer(getEmployees().getSize());
|
||||
}//if//
|
||||
else {
|
||||
result = super.calculatedAttributeUpdate(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeUpdate()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public IManagedList getEmployees() {
|
||||
return (IManagedList) getAttributeValue(EMPLOYEES);
|
||||
}//getEmployees()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Integer getEmployeeCount() {
|
||||
return (Integer) getAttributeValue(EMPLOYEE_COUNT);
|
||||
}//getEmployeeCount()//
|
||||
/**
|
||||
* Gets the ceo value.
|
||||
* @return The ceo value.
|
||||
*/
|
||||
public Employee getCeo() {
|
||||
return (Employee) getAttributeValue(CEO);
|
||||
}//getCeo()//
|
||||
/**
|
||||
* Sets the ceo value.
|
||||
* @param ceo The ceo value.
|
||||
*/
|
||||
public void setCeo(Employee ceo) {
|
||||
setAttributeValue(CEO, ceo);
|
||||
}//setCeo()//
|
||||
/**
|
||||
* Gets the janitor value.
|
||||
* @return The janitor value.
|
||||
*/
|
||||
public Employee getJanitor() {
|
||||
return (Employee) getAttributeValue(JANITOR);
|
||||
}//getJanitor()//
|
||||
/**
|
||||
* Sets the janitor value.
|
||||
* @param janitor The janitor value.
|
||||
*/
|
||||
public void setJanitor(Employee janitor) {
|
||||
setAttributeValue(JANITOR, janitor);
|
||||
}//setJanitor()//
|
||||
/**
|
||||
* Gets the ceoId value.
|
||||
* @return The ceoId value.
|
||||
*/
|
||||
public Integer getCeoId() {
|
||||
return (Integer) getAttributeValue(CEO_ID);
|
||||
}//getCeoId()//
|
||||
/**
|
||||
* Gets the janitorId value.
|
||||
* @return The janitorId value.
|
||||
*/
|
||||
public Integer getJanitorId() {
|
||||
return (Integer) getAttributeValue(JANITOR_ID);
|
||||
}//getJanitorId()//
|
||||
/**
|
||||
* Gets the phoneNumbers value.
|
||||
* @return The phoneNumbers value.
|
||||
*/
|
||||
public IManagedHashSet getPhoneNumbers() {
|
||||
return (IManagedHashSet) getAttributeValue(PHONE_NUMBERS);
|
||||
}//getPhoneNumbers()//
|
||||
}//Employer//
|
||||
49
Foundation Test/src/com/foundation/model/test/Gadget.java
Normal file
49
Foundation Test/src/com/foundation/model/test/Gadget.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class Gadget extends AbstractModel {
|
||||
public static final Attribute KEY = registerAttribute(Gadget.class, "key");
|
||||
public static final Attribute NAME = registerAttribute(Gadget.class, "name");
|
||||
public static final Attribute CLASS_A = registerAttribute(Gadget.class, "classA", ClassA.class);
|
||||
public static final Attribute CLASS_A_KEY = registerAttribute(Gadget.class, "classAKey", CLASS_A, ClassA.KEY);
|
||||
/**
|
||||
* Gadget constructor comment.
|
||||
*/
|
||||
public Gadget() {
|
||||
super();
|
||||
}//Gadget()//
|
||||
/**
|
||||
* Gets the class A reference.
|
||||
*/
|
||||
public ClassA getClassA() {
|
||||
return (ClassA) getAttributeValue(CLASS_A);
|
||||
}//getClassA()//
|
||||
/**
|
||||
* Gets the key.
|
||||
*/
|
||||
public Integer getKey() {
|
||||
return (Integer) getAttributeValue(KEY);
|
||||
}//getKey()//
|
||||
/**
|
||||
* Gets the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the class A reference.
|
||||
*/
|
||||
public void setClassA(ClassA classA) {
|
||||
setAttributeValue(CLASS_A, classA);
|
||||
}//setClassA()//
|
||||
/**
|
||||
* Sets the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//Gadget//
|
||||
42
Foundation Test/src/com/foundation/model/test/KeyTest.java
Normal file
42
Foundation Test/src/com/foundation/model/test/KeyTest.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
public class KeyTest extends AbstractModel {
|
||||
|
||||
public static final Attribute ID = registerAttribute(KeyTest.class, "id");
|
||||
public static final Attribute KEYS = registerAttribute(KeyTest.class, "keys");
|
||||
|
||||
/**
|
||||
* Gets the id value.
|
||||
* @return The id value.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
|
||||
/**
|
||||
* Sets the id value.
|
||||
* @param id The id value.
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
setAttributeValue(ID, id);
|
||||
}//setId()//
|
||||
|
||||
/**
|
||||
* Gets the keys value.
|
||||
* @return The keys value.
|
||||
*/
|
||||
public byte[] getKeys() {
|
||||
return (byte[]) getAttributeValue(KEYS);
|
||||
}//getKeys()//
|
||||
|
||||
/**
|
||||
* Sets the keys value.
|
||||
* @param keys The keys value.
|
||||
*/
|
||||
public void setKeys(byte[] keys) {
|
||||
setAttributeValue(KEYS, keys);
|
||||
}//setKeys()//
|
||||
|
||||
}
|
||||
141
Foundation Test/src/com/foundation/model/test/Part.java
Normal file
141
Foundation Test/src/com/foundation/model/test/Part.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.foundation.common.AttributeBinding;
|
||||
import com.foundation.event.model.ModelListener;
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2006<p>
|
||||
*/
|
||||
public class Part extends AbstractModel {
|
||||
public static final Attribute NAME = registerAttribute(Part.class, "name");
|
||||
public static final Attribute PRODUCT = registerAttribute(Part.class, "product", Product.class);
|
||||
public static final Attribute COST = registerAttribute(Part.class, "cost", AO_LAZY);
|
||||
public static final Attribute PRICE = registerAttribute(Part.class, "price", AO_CALCULATED, new BigDecimal(0));
|
||||
/**
|
||||
* Part constructor.
|
||||
*/
|
||||
public Part() {
|
||||
super();
|
||||
}//Part()//
|
||||
/**
|
||||
* Part constructor.
|
||||
*/
|
||||
public Part(String name, BigDecimal cost) {
|
||||
super();
|
||||
setName(name);
|
||||
setCost(cost);
|
||||
}//Part()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == COST) {
|
||||
result = new BigDecimal(1.50);
|
||||
}//if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeRegister(com.foundation.metadata.Attribute, com.foundation.common.Entity.ICalculatedAttributeListener)
|
||||
*/
|
||||
protected ModelListener calculatedAttributeRegister(Attribute attribute, ICalculatedAttributeListener listener) {
|
||||
ModelListener result = null;
|
||||
|
||||
if(attribute == PRICE) {
|
||||
result = new ModelListener(this);
|
||||
result.addBinding(new AttributeBinding(Part.class, COST, 0, listener, null));
|
||||
result.addBinding(new AttributeBinding(Part.class, PRODUCT));
|
||||
result.addBinding(new AttributeBinding(Product.class, Product.MARKUP, 0, listener, null));
|
||||
result.initialize();
|
||||
}//if//
|
||||
else {
|
||||
result = super.calculatedAttributeRegister(attribute, listener);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeRegister()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeUpdate(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object calculatedAttributeUpdate(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == PRICE) {
|
||||
result = calculatePrice();
|
||||
}//if//
|
||||
else {
|
||||
result = super.calculatedAttributeUpdate(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeUpdate()//
|
||||
/**
|
||||
* Gets the name for the part.
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name for the part.
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
/**
|
||||
* Gets the cost for the part.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getCost() {
|
||||
return (BigDecimal) getAttributeValue(COST);
|
||||
}//getCost()//
|
||||
/**
|
||||
* Sets the cost for the part.
|
||||
* @param cost
|
||||
*/
|
||||
public void setCost(BigDecimal cost) {
|
||||
if(cost == null) {
|
||||
cost = new BigDecimal(0.00);
|
||||
}//if//
|
||||
|
||||
setAttributeValue(COST, cost);
|
||||
}//setCost()//
|
||||
/**
|
||||
* Gets the part's containing product.
|
||||
* @return
|
||||
*/
|
||||
public Product getProduct() {
|
||||
return (Product) getAttributeValue(PRODUCT);
|
||||
}//getProduct()//
|
||||
/**
|
||||
* Calculates the price for the item based on the product's markup.
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal calculatePrice() {
|
||||
BigDecimal result = getCost();
|
||||
|
||||
if(getProduct() != null) {
|
||||
result = result.multiply(getProduct().getMarkup());
|
||||
}//if//
|
||||
|
||||
result.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
return result;
|
||||
}//calculatePrice()//
|
||||
/**
|
||||
* Gets the price for the part which is a function of the product's markup and the cost of this item.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getPrice() {
|
||||
return (BigDecimal) getAttributeValue(PRICE);
|
||||
}//getPrice()//
|
||||
}//Part//
|
||||
110
Foundation Test/src/com/foundation/model/test/PartContainer.java
Normal file
110
Foundation Test/src/com/foundation/model/test/PartContainer.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.common.util.IList;
|
||||
import com.foundation.common.AttributeBinding;
|
||||
import com.foundation.common.IEntity.ICalculatedAttributeListener;
|
||||
import com.foundation.event.model.ModelListener;
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Tracks the total cost of a subset of a product's parts.
|
||||
* This stress tests the auto calculated attributes and reflection system.
|
||||
*/
|
||||
public class PartContainer extends AbstractModel {
|
||||
public static final Attribute PART_NAME_PATTERN = registerAttribute(PartContainer.class, "partNamePattern");
|
||||
public static final Attribute TOTAL_COST = registerAttribute(PartContainer.class, "totalCost", AO_REFERENCED | AO_CALCULATED, new BigDecimal(0));
|
||||
public static final Attribute PRODUCT = registerAttribute(PartContainer.class, "product", Product.class);
|
||||
/**
|
||||
* PartContainer constructor.
|
||||
*/
|
||||
public PartContainer() {
|
||||
}//PartContainer()//
|
||||
/**
|
||||
* PartContainer constructor.
|
||||
* @param pattern The pattern of the name of the part's being totalled. The part name must start with the pattern to qualify.
|
||||
*/
|
||||
public PartContainer(String pattern) {
|
||||
setPartNamePattern(pattern);
|
||||
}//PartContainer()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeRegister(com.foundation.metadata.Attribute, com.foundation.common.IEntity.ICalculatedAttributeListener)
|
||||
*/
|
||||
protected ModelListener calculatedAttributeRegister(Attribute attribute, ICalculatedAttributeListener listener) {
|
||||
ModelListener result = null;
|
||||
|
||||
if(attribute == TOTAL_COST) {
|
||||
result = new ModelListener(this);
|
||||
result.addBinding(new AttributeBinding(PartContainer.class, PRODUCT));
|
||||
result.addBinding(new AttributeBinding(Product.class, Product.PARTS, 0, listener, null));
|
||||
}//if//
|
||||
else {
|
||||
result = super.calculatedAttributeRegister(attribute, listener);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeRegister()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeUpdate(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object calculatedAttributeUpdate(Attribute attribute) {
|
||||
Object result = null;
|
||||
|
||||
if(attribute == TOTAL_COST) {
|
||||
result = new BigDecimal(0);
|
||||
|
||||
if(getProduct() != null) {
|
||||
IList parts = getProduct().getParts();
|
||||
|
||||
for(int index = 0, length = parts.getSize(); index < length; index++) {
|
||||
Part part = (Part) parts.get(index);
|
||||
|
||||
if(part.getName().startsWith(getPartNamePattern())) {
|
||||
result = ((BigDecimal) result).add(part.getCost());
|
||||
}//if//
|
||||
}//for//
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
result = super.calculatedAttributeUpdate(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeUpdate()//
|
||||
/**
|
||||
* Gets the partNamePattern value.
|
||||
* @return The partNamePattern value.
|
||||
*/
|
||||
public String getPartNamePattern() {
|
||||
return (String) getAttributeValue(PART_NAME_PATTERN);
|
||||
}//getPartNamePattern()//
|
||||
/**
|
||||
* Sets the partNamePattern value.
|
||||
* @param partNamePattern The partNamePattern value.
|
||||
*/
|
||||
public void setPartNamePattern(String partNamePattern) {
|
||||
setAttributeValue(PART_NAME_PATTERN, partNamePattern);
|
||||
}//setPartNamePattern()//
|
||||
/**
|
||||
* Gets the totalCost value.
|
||||
* @return The totalCost value.
|
||||
*/
|
||||
public BigDecimal getTotalCost() {
|
||||
return (BigDecimal) getAttributeValue(TOTAL_COST);
|
||||
}//getTotalCost()//
|
||||
/**
|
||||
* Sets the totalCost value.
|
||||
* @param totalCost The totalCost value.
|
||||
*/
|
||||
public void setTotalCost(BigDecimal totalCost) {
|
||||
setAttributeValue(TOTAL_COST, totalCost);
|
||||
}//setTotalCost()//
|
||||
/**
|
||||
* Gets the product value.
|
||||
* @return The product value.
|
||||
*/
|
||||
public Product getProduct() {
|
||||
return (Product) getAttributeValue(PRODUCT);
|
||||
}//getProduct()//
|
||||
}//PartContainer//
|
||||
183
Foundation Test/src/com/foundation/model/test/Product.java
Normal file
183
Foundation Test/src/com/foundation/model/test/Product.java
Normal file
@@ -0,0 +1,183 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.common.util.IIterator;
|
||||
import com.foundation.common.AttributeBinding;
|
||||
import com.foundation.event.model.ModelListener;
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.util.IManagedList;
|
||||
import com.foundation.util.ManagedList;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2006<p>
|
||||
*/
|
||||
public class Product extends AbstractModel {
|
||||
public static final Attribute NAME = registerAttribute(Product.class, "name");
|
||||
public static final Attribute PARTS = registerCollection(Product.class, "parts", AO_LAZY | AO_PART_OF);
|
||||
public static final Attribute COST = registerAttribute(Product.class, "cost", AO_CALCULATED, new BigDecimal(0));
|
||||
public static final Attribute PRICE = registerAttribute(Product.class, "price", AO_CALCULATED, new BigDecimal(0));
|
||||
public static final Attribute MARKUP = registerAttribute(Product.class, "markup", AO_LAZY, new BigDecimal(1));
|
||||
public static final Attribute PART_CONTAINER = registerCollection(Product.class, "partContainer", AO_PART_OF | AO_LAZY);
|
||||
/**
|
||||
* Product constructor.
|
||||
*/
|
||||
public Product() {
|
||||
super();
|
||||
}//Product()//
|
||||
/**
|
||||
* Product constructor.
|
||||
*/
|
||||
public Product(String name) {
|
||||
super();
|
||||
setAttributeValue(NAME, name);
|
||||
}//Product()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == PARTS) {
|
||||
result = new ManagedList(10, 20);
|
||||
}//if//
|
||||
else if(attribute == MARKUP) {
|
||||
result = new BigDecimal(1.50);
|
||||
}//else if//
|
||||
else if(attribute == PART_CONTAINER) {
|
||||
result = new ManagedList(10, 20);
|
||||
}//else if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeRegister(com.foundation.metadata.Attribute, com.foundation.common.Entity.ICalculatedAttributeListener)
|
||||
*/
|
||||
protected ModelListener calculatedAttributeRegister(Attribute attribute, ICalculatedAttributeListener listener) {
|
||||
ModelListener result = null;
|
||||
|
||||
if(attribute == COST) {
|
||||
result = new ModelListener(this);
|
||||
result.addBinding(new AttributeBinding(Product.class, PARTS));
|
||||
result.addBinding(new AttributeBinding(Part.class, Part.COST, 0, listener, null));
|
||||
result.initialize();
|
||||
}//if//
|
||||
else if(attribute == PRICE) {
|
||||
result = new ModelListener(this);
|
||||
result.addBinding(new AttributeBinding(Product.class, PARTS));
|
||||
result.addBinding(new AttributeBinding(Part.class, Part.PRICE, 0, listener, null));
|
||||
result.initialize();
|
||||
}//else if//
|
||||
else {
|
||||
result = super.calculatedAttributeRegister(attribute, listener);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeRegister()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#calculatedAttributeUpdate(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object calculatedAttributeUpdate(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == COST) {
|
||||
result = calculateCost();
|
||||
}//if//
|
||||
else if(attribute == PRICE) {
|
||||
result = calculatePrice();
|
||||
}//else if//
|
||||
else {
|
||||
result = super.calculatedAttributeUpdate(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//calculatedAttributeUpdate()//
|
||||
/**
|
||||
* Calculates the total cost for the product.
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal calculateCost() {
|
||||
BigDecimal result = new BigDecimal(0.00);
|
||||
IIterator iterator = getParts().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Part part = (Part) iterator.next();
|
||||
|
||||
result = result.add(part.getCost());
|
||||
}//while//
|
||||
|
||||
result.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
return result;
|
||||
}//calculateCost()//
|
||||
/**
|
||||
* Calculates the total price for the product.
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal calculatePrice() {
|
||||
BigDecimal result = new BigDecimal(0.00);
|
||||
IIterator iterator = getParts().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Part part = (Part) iterator.next();
|
||||
|
||||
result = result.add(part.getPrice());
|
||||
}//while//
|
||||
|
||||
result.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
return result;
|
||||
}//calculatePrice()//
|
||||
/**
|
||||
* Gets the name for the product.
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Gets the total cost for the product.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getCost() {
|
||||
return (BigDecimal) getAttributeValue(COST);
|
||||
}//getCost()//
|
||||
/**
|
||||
* Gets the total price for the product.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getPrice() {
|
||||
return (BigDecimal) getAttributeValue(PRICE);
|
||||
}//getPrice()//
|
||||
/**
|
||||
* Gets the total cost markup used to generate the price for the product.
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getMarkup() {
|
||||
return (BigDecimal) getAttributeValue(MARKUP);
|
||||
}//getMarkup()//
|
||||
/**
|
||||
* Gets the parts that make up this product.
|
||||
* @return
|
||||
*/
|
||||
public IManagedList getParts() {
|
||||
return (IManagedList) getAttributeValue(PARTS);
|
||||
}//getParts()//
|
||||
/**
|
||||
* Gets the partContainer value.
|
||||
* @return The partContainer value.
|
||||
*/
|
||||
public IManagedList getPartContainer() {
|
||||
return (IManagedList) getAttributeValue(PART_CONTAINER);
|
||||
}//getPartContainer()//
|
||||
/**
|
||||
* Sets the partContainer value.
|
||||
* @param partContainer The partContainer value.
|
||||
*/
|
||||
public void setPartContainer(IManagedList partContainer) {
|
||||
setAttributeValue(PART_CONTAINER, partContainer);
|
||||
}//setPartContainer()//
|
||||
}//Product//
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.model.VersionedModel;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2008<p>
|
||||
*/
|
||||
public class StatelessData extends VersionedModel {
|
||||
public static final Attribute ID = registerAttribute(StatelessData.class, "id");
|
||||
public static final Attribute TEXT = registerAttribute(StatelessData.class, "text");
|
||||
/**
|
||||
* StatelessData constructor.
|
||||
*/
|
||||
public StatelessData() {
|
||||
}//StatelessData()//
|
||||
/**
|
||||
* StatelessData constructor.
|
||||
* @param id The object's identifier.
|
||||
*/
|
||||
public StatelessData(Integer id) {
|
||||
setAttributeValue(ID, id);
|
||||
}//StatelessData()//
|
||||
/**
|
||||
* Gets the object's identifier
|
||||
* @return The instance's ID.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
* Gets the text.
|
||||
* @return The text.
|
||||
*/
|
||||
public String getText() {
|
||||
return (String) getAttributeValue(TEXT);
|
||||
}//getText()//
|
||||
/**
|
||||
* Sets the text.
|
||||
* @param text The text.
|
||||
*/
|
||||
public void setText(String text) {
|
||||
setAttributeValue(TEXT, text);
|
||||
}//setText()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.model.Model#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "StatelessData {id: " + getId() + "; txt: " + getText() + "; logicalObjectId: " + getLogicalObjectId() + "; objectId: " + getObjectId() + "; version: " + getVersion() + "}";
|
||||
}//toString()//
|
||||
}//StatelessData//
|
||||
1845
Foundation Test/src/com/foundation/model/test/TestApplication.java
Normal file
1845
Foundation Test/src/com/foundation/model/test/TestApplication.java
Normal file
File diff suppressed because it is too large
Load Diff
35
Foundation Test/src/com/foundation/model/test/Thing.java
Normal file
35
Foundation Test/src/com/foundation/model/test/Thing.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class Thing extends AbstractModel {
|
||||
public static final Attribute KEY = registerAttribute(Thing.class, "key");
|
||||
public static final Attribute NAME = registerAttribute(Thing.class, "name");
|
||||
/**
|
||||
* Thing constructor.
|
||||
*/
|
||||
public Thing() {
|
||||
super();
|
||||
}//Thing()//
|
||||
/**
|
||||
* Gets the key.
|
||||
*/
|
||||
public Integer getKey() {
|
||||
return (Integer) getAttributeValue(KEY);
|
||||
}//getKey()//
|
||||
/**
|
||||
* Gets the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//Thing//
|
||||
49
Foundation Test/src/com/foundation/model/test/Widget.java
Normal file
49
Foundation Test/src/com/foundation/model/test/Widget.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class Widget extends AbstractModel {
|
||||
public static final Attribute KEY = registerAttribute(Widget.class, "key");
|
||||
public static final Attribute NAME = registerAttribute(Widget.class, "name");
|
||||
public static final Attribute CLASS_A = registerAttribute(Widget.class, "classA", AO_REFERENCED);
|
||||
public static final Attribute CLASS_A_KEY = registerAttribute(Widget.class, "classAKey", CLASS_A, ClassA.KEY);
|
||||
/**
|
||||
* Widget constructor comment.
|
||||
*/
|
||||
public Widget() {
|
||||
super();
|
||||
}//Widget()//
|
||||
/**
|
||||
* Gets the class A reference.
|
||||
*/
|
||||
public ClassA getClassA() {
|
||||
return (ClassA) getAttributeValue(CLASS_A);
|
||||
}//getClassA()//
|
||||
/**
|
||||
* Gets the key.
|
||||
*/
|
||||
public Integer getKey() {
|
||||
return (Integer) getAttributeValue(KEY);
|
||||
}//getKey()//
|
||||
/**
|
||||
* Gets the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) getAttributeValue(NAME);
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the class A reference.
|
||||
*/
|
||||
public void setClassA(ClassA classA) {
|
||||
setAttributeValue(CLASS_A, classA);
|
||||
}//setClassA()//
|
||||
/**
|
||||
* Sets the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
setAttributeValue(NAME, name);
|
||||
}//setName()//
|
||||
}//Widget//
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.foundation.model.test;
|
||||
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.util.IManagedList;
|
||||
import com.foundation.util.ManagedList;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
* TODO: Fix this test code to not use the cache code.
|
||||
*/
|
||||
public class WidgetController extends AbstractController {
|
||||
public static final Attribute WIDGETS = registerCollection(WidgetController.class, "widgets", AO_LAZY | AO_WEAK);
|
||||
private static WidgetController singleton = new WidgetController();
|
||||
/**
|
||||
* WidgetController constructor.
|
||||
*/
|
||||
private WidgetController() {
|
||||
super();
|
||||
}//WidgetController()//
|
||||
/**
|
||||
* Gets the collection of widgets.
|
||||
* @return The set of all widgets.
|
||||
*/
|
||||
public IManagedList getWidgets() {
|
||||
try {
|
||||
lock(this);
|
||||
|
||||
return (IManagedList) getAttributeValue(WIDGETS);
|
||||
}//try//
|
||||
finally {
|
||||
unlock(this);
|
||||
}//finally//
|
||||
}//getWidgets()//
|
||||
/**
|
||||
* Creates a single widget in the repository and caches it for future access.
|
||||
* @param widget The new widget to be created.
|
||||
* @return The collection of loaded widgets.
|
||||
*/
|
||||
public void createWidget(Widget widget) {
|
||||
try {
|
||||
lock(this);
|
||||
|
||||
if((widget.getIsObjectNew()) && (widget.entityUpdate() == null)) {
|
||||
getWidgets().add(widget);
|
||||
}//if//
|
||||
}//try//
|
||||
finally {
|
||||
unlock(this);
|
||||
}//finally//
|
||||
}//createWidget()//
|
||||
/**
|
||||
* Deletes a single widget from the repository and removes it from the local cache.
|
||||
* @param widget The old widget to be deleted.
|
||||
* @return Whether the widget was successfully deleted from the system.
|
||||
*/
|
||||
public void deleteWidget(Widget widget) {
|
||||
try {
|
||||
lock(this);
|
||||
|
||||
if((!widget.getIsObjectNew()) && (widget.entityDelete() == null)) {
|
||||
getWidgets().remove(widget);
|
||||
}//if//
|
||||
}//try//
|
||||
finally {
|
||||
unlock(this);
|
||||
}//finally//
|
||||
}//deleteWidget()//
|
||||
/**
|
||||
* Gets the one and only widget controller instance in this process.
|
||||
* @return The only instance of the widget controller class.
|
||||
*/
|
||||
public static WidgetController getSingleton() {
|
||||
return singleton;
|
||||
}//getSingleton()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.common.Entity#lazyLoadAttribute(com.foundation.metadata.Attribute)
|
||||
*/
|
||||
protected Object lazyLoadAttribute(Attribute attribute) {
|
||||
Object result;
|
||||
|
||||
if(attribute == WIDGETS) {
|
||||
result = new ManagedList(10, 40);
|
||||
}//if//
|
||||
else {
|
||||
result = super.lazyLoadAttribute(attribute);
|
||||
}//else//
|
||||
|
||||
return result;
|
||||
}//lazyLoadAttribute()//
|
||||
}//WidgetController//
|
||||
68
Foundation Test/src/com/foundation/orb/Client.java
Normal file
68
Foundation Test/src/com/foundation/orb/Client.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package com.foundation.orb;
|
||||
|
||||
import com.common.debug.Debug;
|
||||
import com.common.orb.Orb;
|
||||
import com.common.security.IHashAlgorithm;
|
||||
import com.common.security.ISignatureAlgorithm;
|
||||
import com.common.security.RsaAlgorithm;
|
||||
import com.common.security.Sha1;
|
||||
import com.common.security.Sha512;
|
||||
import com.common.util.StringSupport;
|
||||
import com.de22.orb.Address;
|
||||
import com.de22.orb.IVersionChangeHandler;
|
||||
import com.de22.orb.development.OrbClassLoader;
|
||||
import com.de22.orb.optional.CommonOrbWrapper;
|
||||
import com.de22.orb.optional.SocketOptions;
|
||||
|
||||
public class Client implements ITest {
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Orb.setOrbWrapper(new CommonOrbWrapper(new OrbClassLoader(), null, null));
|
||||
Address address = new Address("localhost", port);
|
||||
|
||||
try {
|
||||
Object socketId = Orb.openSocket("Socket", new SocketOptions(1, new Address[] {address}, null, null, null, new IVersionChangeHandler() {
|
||||
public void newVersionAvailable(String[] uris, boolean isRequired) {
|
||||
//TODO:
|
||||
Debug.log("New Version Found...");
|
||||
}//newVersionAvailable()//
|
||||
}, null) {
|
||||
IHashAlgorithm hash = new Sha1();
|
||||
ISignatureAlgorithm signature = new RsaAlgorithm(StringSupport.fromHexString("000001000000020100AE2F1B25EE59D90C86EE395F2BE15A05DA20523047150AA57A6AA37D39BDD956744C2CE3443033E30181DC541B50BEC879679B6D855415267438C67F12C5829CAA9BBE70885942878AD761DA61A2CCEEA83C48554B68A4CA46E220FF619321A048A2D946709F86E5826D25B5CD8A0379FF78430AB8E1C5522C814DACEEBC4FBF875E43FF3BE38DC67A445132329CE150128CB543C4260185FCBCD1CE9D46798CC4C21C27EFE65ABDB4358DB28131B6AA313E599A278FFA7EDE4ECC6AC18550A81244A70CF5D5529A6854FAEF764388424BBD95B0185AADF13AC6C03F27D608F969DAFF303EDE9B5A80E35882A658FECBAAC4969E15078F072C7C68FCE50C93C0E0679705B397B2B0E6CD6B9C4868AD8C5F39BAEE590B05DBE1ADE6F71D99AB14BC7C94099FF1BE62C0CBC35982BCE238444578FBA3117AE454CCAFDBB7D125204157C4D6009982B94DAC4A62B4B76F2ED485278BFCD5AD1CE549BE19DD4D778D0C23CAF8A6D4DBE42D9FA782CE0468875EE6CBC684CC7504B1C18D59D4D463CBB1F96AD707F9D36A7A17BC936CA97B30730498185C849FF8C9D76E3C2DA51E860959D038563A7B989A4DFCE557874EAE4C970E2C2A7D6FE59E61FF1338ACFF2EAA4C0C997BDDB233402D6756890AF592323F598D5C054D913E63694A1DE29076BFFAC6427F64F457A6E63A5690EC290E9071790F257EB3F3C85968C68B9AC31D00856D1F27E547FABD5356C57150D191D3EE219CB04D9876B6030A3EE0207C119D04B58AD50299303919E37DCA621AC963FB3C4434B0C994D17327EBB5895D62DF779F38E7F51B4C4F017D5B5F8D6F2DC099DF0174717BA91D3E36C2534598C92D7B891AB7FAB8AAA7340D92D51ABB7ABD822EC201C2BE7FCA53CB195682854956405BF1F817CEFAFAD1AE264F3FD1D4F07C3452A16128FCF9A4A6184060173E09C05A2D660A8A2A017ED93ED802BBCDB526857534A674BDD40FE1D9E2146AE6E3D179E707544FED8B532D2175558A9756CD9BB00FD5ABC82D20474F43C8BBF2536672D32DCB2CDA33343CBCF518DB618B21CDE942E0485DED628759061EA8A269A68185057D02B7029F7891523457A9CA6E49D2F0F3F39E3D1BB68469E9A6244FB0B12F91099F7EAC0006DD94BD2E2077B9EA54DB6A964B33B93834EFA07629DF429893A8703020777804010AB79B23EBE8C8570FD0F5B0B06F80CBAC0FDB03AD1E10CAEFF82FA4736F7AA3E61D21EA2C5431ABF6645B163836CC24F9FE8BA3EDED75D83EFC4D94E4D318A60732054A89770EB240FD4C47338D83C9FC09C53CC18453419575607EFD34BF4081532BB339BB3CFE510A187DACFEB00E59D6E1D9F330D434754F38CB46A8F7DDFB9EF08833C4ADA4291FB73E9D91CBD9349C098EFC2F90865410495BC3320B0B419BFD476196EFAF7821BD7293BB680040F6B73E5B"), true);
|
||||
|
||||
public IHashAlgorithm getHashAlgorithm() {
|
||||
return hash;
|
||||
}//getHashAlgorithm()//
|
||||
public int getSignatureSize() {
|
||||
return signature.getSignedSize(hash.getHashSize());
|
||||
}//getSignatureSize()//
|
||||
public boolean isValidSignature(byte[] data, byte[] signedData) {
|
||||
byte[] unsignedData = signature.verify(signedData);
|
||||
boolean result = unsignedData != null && unsignedData.length == data.length;
|
||||
|
||||
for(int index = 0; result && index < unsignedData.length; index++) {
|
||||
result = unsignedData[index] == data[index];
|
||||
}//for//
|
||||
|
||||
return result;
|
||||
}//isValidSignature()//
|
||||
});
|
||||
|
||||
if(socketId == null) {
|
||||
Debug.log("Failed to create a connection to the server.");
|
||||
System.exit(0);
|
||||
}//if//
|
||||
|
||||
ITestService service = (ITestService) Orb.lookup(ITestService.ID, socketId);
|
||||
|
||||
String result = service.performAction("Wynne Crisman");
|
||||
Debug.log(result);
|
||||
Orb.closeSocket(socketId);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//main()//
|
||||
}//Client//
|
||||
5
Foundation Test/src/com/foundation/orb/ITest.java
Normal file
5
Foundation Test/src/com/foundation/orb/ITest.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package com.foundation.orb;
|
||||
|
||||
public interface ITest {
|
||||
public static final int port = 10224;
|
||||
}
|
||||
6
Foundation Test/src/com/foundation/orb/ITestService.java
Normal file
6
Foundation Test/src/com/foundation/orb/ITestService.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.foundation.orb;
|
||||
|
||||
public interface ITestService extends ITest {
|
||||
public static final String ID = "testId";
|
||||
public String performAction(String input);
|
||||
}
|
||||
92
Foundation Test/src/com/foundation/orb/SecurityTest.java
Normal file
92
Foundation Test/src/com/foundation/orb/SecurityTest.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package com.foundation.orb;
|
||||
|
||||
import java.security.KeyStore;
|
||||
|
||||
import com.common.debug.Debug;
|
||||
import com.common.security.Sha512;
|
||||
import com.common.util.StreamBuffer;
|
||||
import com.de22.orb.SecurityMessageFilter;
|
||||
import com.de22.orb.security.AbstractSecuritySystem;
|
||||
import com.de22.orb.security.SslSecurityProvider;
|
||||
import com.de22.orb.security.SslSecuritySystem;
|
||||
import com.de22.orb.AbstractConnection.IMessageFilterInputHandler;
|
||||
import com.de22.orb.AbstractConnection.IMessageFilterOutputHandler;
|
||||
|
||||
public class SecurityTest {
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Sha512 hash = new Sha512();
|
||||
|
||||
for(int i = 0; i < 2000; i++) {
|
||||
hash.add((byte) i);
|
||||
}//for//
|
||||
|
||||
hash.hash();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}
|
||||
|
||||
try {
|
||||
SslSecurityProvider provider = new SslSecurityProvider("TLS"/*SSLv3*/, "./test.key", "kspassword", "kpassword");
|
||||
AbstractSecuritySystem serverSystem = provider.createSecuritySystem();
|
||||
AbstractSecuritySystem clientSystem = (AbstractSecuritySystem) Class.forName(provider.getSecuritySystemClientClassName()).newInstance();
|
||||
|
||||
clientSystem.initialize(provider.getSecuritySystemClientMetadata());
|
||||
|
||||
final SecurityMessageFilter serverFilter = new SecurityMessageFilter(serverSystem);
|
||||
final SecurityMessageFilter clientFilter = new SecurityMessageFilter(clientSystem);
|
||||
|
||||
serverFilter.setHandlers(new IMessageFilterInputHandler() {
|
||||
public void startIncommingMessage(StreamBuffer input) {
|
||||
//TODO: Take the input and pass it to the client.
|
||||
Debug.log("Receiving data from the client orb.");
|
||||
}
|
||||
public void initializeFilter() {
|
||||
Debug.log("Server filter initialization completed.");
|
||||
}
|
||||
public void closeConnection(boolean force) {
|
||||
Debug.log("Server connection closed: " + force);
|
||||
}
|
||||
}, new IMessageFilterOutputHandler() {
|
||||
public void startOutgoingMessage(StreamBuffer input) {
|
||||
//TODO: Output should be handled by the orb.
|
||||
// Debug.log("Sending data to the server orb.");
|
||||
clientFilter.startIncommingMessage(input);
|
||||
}
|
||||
});
|
||||
clientFilter.setHandlers(new IMessageFilterInputHandler() {
|
||||
public void startIncommingMessage(StreamBuffer input) {
|
||||
//TODO: Take the input and pass it to the server.
|
||||
Debug.log("Receiving data from the server orb.");
|
||||
}
|
||||
public void initializeFilter() {
|
||||
Debug.log("Client filter initialization completed.");
|
||||
StreamBuffer content = new StreamBuffer();
|
||||
|
||||
for(int index = 0; index < 100; index++) {
|
||||
content.writeByte((byte) index);
|
||||
}//if//
|
||||
|
||||
clientFilter.startOutgoingMessage(content);
|
||||
}
|
||||
public void closeConnection(boolean force) {
|
||||
Debug.log("Client connection closed: " + force);
|
||||
}
|
||||
}, new IMessageFilterOutputHandler() {
|
||||
public void startOutgoingMessage(StreamBuffer input) {
|
||||
//TODO: Output should be handled by the orb.
|
||||
//Debug.log("Sending data to the client orb.");
|
||||
serverFilter.startIncommingMessage(input);
|
||||
}
|
||||
});
|
||||
clientFilter.beginInitialization();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}
|
||||
}
|
||||
150
Foundation Test/src/com/foundation/orb/Server.java
Normal file
150
Foundation Test/src/com/foundation/orb/Server.java
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,20 @@
|
||||
package com.foundation.transaction.test;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class AbstractModel extends com.foundation.model.Model {
|
||||
/**
|
||||
* AbstractModel constructor comment.
|
||||
*/
|
||||
public AbstractModel() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Gets the application object that this object is running under. The application object provides the object various services that it will need.
|
||||
* @return The application reference for the application this object is running under.
|
||||
*/
|
||||
public com.foundation.application.IApplication getApplication() {
|
||||
return TestApplication.getSingleton();
|
||||
}//getApplication()//
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
package com.foundation.transaction.test;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
import com.foundation.application.*;
|
||||
import com.foundation.metadata.Attribute;
|
||||
import com.foundation.transaction.*;
|
||||
import com.foundation.view.resource.ResourceService;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999-2002<p>
|
||||
* Designed to test the transaction part of the foundation.
|
||||
*/
|
||||
public class TestApplication extends Application {
|
||||
public static final String REPOSITORY_MYSQL = "MySQL";
|
||||
public static final String TDI_CREATE_TEST = "Create Test Transaction";
|
||||
public static final String TDI_READ_MANY_TEST_1 = "ReadMany Test Transaction Forward";
|
||||
public static final String TDI_READ_MANY_TEST_2 = "ReadMany Test Transaction Reverse";
|
||||
|
||||
private static TestApplication singleton = null;
|
||||
/**
|
||||
* PManApplication constructor.
|
||||
*/
|
||||
public TestApplication() {
|
||||
super();
|
||||
}//PManApplication()//
|
||||
/**
|
||||
* Gets the application object that this object is running under. The application object provides the object various services that it will need.
|
||||
* @return The application reference for the application this object is running under.
|
||||
*/
|
||||
public IApplication getApplication() {
|
||||
return this;
|
||||
}//getApplication()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#initializeResources(com.foundation.view.resource.ResourceService)
|
||||
*/
|
||||
protected void initializeResources(ResourceService resourceService) {
|
||||
}
|
||||
/**
|
||||
* Gets the repository identifier for the application's primary (default) repository connection.
|
||||
* @return The repository identifier the application objects will use by default.
|
||||
*/
|
||||
public Object getDefaultRepositoryIdentifier() {
|
||||
return REPOSITORY_MYSQL;
|
||||
}//getDefaultRepositoryIdentifier()//
|
||||
/**
|
||||
* Gets the location of the metadata file for this application.
|
||||
* @return The file location for the metadata file. The path may be relative or absolute.
|
||||
*/
|
||||
public Object getMetadataLocation() {
|
||||
return "./TestApplication/TestApplication.xml";
|
||||
}//getMetadataLocation()//
|
||||
/**
|
||||
* Gets the test application singleton reference.
|
||||
* @return The application singleton for the process.
|
||||
*/
|
||||
public static TestApplication getSingleton() {
|
||||
return singleton;
|
||||
}//getSingleton()//
|
||||
/**
|
||||
* Starts the PMan application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new TestApplication().startup();
|
||||
}//main()//
|
||||
protected void updateTest() {
|
||||
TestObject query = new TestObject("Hello World", null);
|
||||
TestObject query2 = new TestObject("Hello World", new Integer(100));
|
||||
UpdateTransactionDefinition def = new UpdateTransactionDefinition(query2, new Attribute[] {TestObject.TEXT, TestObject.NUMBER}, new Attribute[] {}, null, null);
|
||||
def.addRequirement(TestObject.NUMBER, Operator.EQUALS, null);
|
||||
UpdateTransaction tran = new UpdateTransaction(def, query2);
|
||||
|
||||
tran.setRequirementValue(TestObject.NUMBER, null);
|
||||
query.getTransactionService().process(tran);
|
||||
}
|
||||
/**
|
||||
* Tests writing a test object to the database and then reading it back into memory.
|
||||
* The basic attributes (ID, NUMBER, TEXT) are compared to ensure they were saved and read correctly.
|
||||
* The fixed size data is then compared to ensure it was translated properly.
|
||||
*/
|
||||
protected void simpleCreateReadDeleteTest() {
|
||||
TestObject o = new TestObject("Test", new Integer(100));
|
||||
|
||||
if(getTransactionService().create(o) == 1) {
|
||||
TestObject r = new TestObject(o.getId());
|
||||
|
||||
if(getTransactionService().readSingle(r, true) != null) {
|
||||
if(!r.getId().equals(o.getId())) {
|
||||
Debug.log(new RuntimeException(), "Failed the ID comparison test.");
|
||||
}//if//
|
||||
|
||||
if(!o.getNumber().equals(r.getNumber())) {
|
||||
Debug.log(new RuntimeException(), "Failed the NUMBER comparison test.");
|
||||
}//if//
|
||||
|
||||
if(!o.getText().equals(r.getText())) {
|
||||
Debug.log(new RuntimeException(), "Failed the TEXT comparison test.");
|
||||
}//if//
|
||||
|
||||
if(r.getFixedSizeData() != null && o.getFixedSizeData() != null && r.getFixedSizeData().length == o.getFixedSizeData().length) {
|
||||
Debug.log("Fixed size data comparison: ");
|
||||
boolean correct = true;
|
||||
|
||||
for(int index = 0; index < r.getFixedSizeData().length; index++) {
|
||||
Debug.log(o.getFixedSizeData()[index] + " -> " + r.getFixedSizeData()[index]);
|
||||
correct &= o.getFixedSizeData()[index] == r.getFixedSizeData()[index];
|
||||
}//for//
|
||||
|
||||
if(!correct) {
|
||||
Debug.log(new RuntimeException(), "Failed the FIXED_SIZE_DATA comparison test.");
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
Debug.log(new RuntimeException(), "Failed to compare the fixed sized data from the create & read.");
|
||||
}//else//
|
||||
}//if//
|
||||
else {
|
||||
Debug.log(new RuntimeException(), "Failed to read the test object.");
|
||||
}//else//
|
||||
}//if//
|
||||
else {
|
||||
Debug.log(new RuntimeException(), "Failed to create the test object.");
|
||||
}//else//
|
||||
}//simpleCreateReadDeleteTest()//
|
||||
/**
|
||||
* Runs a simple performance test which times the creation, reading single, reading all, and updating of objects.
|
||||
*/
|
||||
protected void simplePerformanceTest(int count) {
|
||||
long t = System.currentTimeMillis();
|
||||
for(int index = 0; index < count; index++) {
|
||||
testCreate();
|
||||
testReadSingle();
|
||||
testReadMany();
|
||||
testUpdate();
|
||||
}//for//
|
||||
t = System.currentTimeMillis() - t;
|
||||
Debug.log("Total time: " + t + " Average time: " + ((int) (t / count)));
|
||||
}//simplePerformanceTest()//
|
||||
/**
|
||||
* Tests the performance of creating objects.
|
||||
*/
|
||||
protected void performanceTestCreate() {
|
||||
LiteList objects = new LiteList(100, 100);
|
||||
TestObject object = null;
|
||||
IIterator iterator = null;
|
||||
Object transactionIdentifier = new Object();
|
||||
long time = 0;
|
||||
|
||||
//Initialize 100 objects for the first test.//
|
||||
for(int index = 1; index <= 100; index++) {
|
||||
objects.add(new TestObject("My number is " + index + ".", new Integer(index)));
|
||||
}//for//
|
||||
|
||||
//Start test 1.//
|
||||
iterator = objects.iterator();
|
||||
time = System.currentTimeMillis();
|
||||
|
||||
//Run the first test.//
|
||||
while(iterator.hasNext()) {
|
||||
object = (TestObject) iterator.next();
|
||||
getTransactionService().create(object);
|
||||
}//while//
|
||||
|
||||
time = System.currentTimeMillis() - time;
|
||||
Debug.log("TEST#1: Total time to create " + objects.getSize() + " test objects was " + time + "ms.");
|
||||
objects.removeAll();
|
||||
|
||||
//Initialize 100 objects for the second test.//
|
||||
for(int index = 101; index <= 200; index++) {
|
||||
objects.add(new TestObject("My number is " + index + ".", new Integer(index)));
|
||||
}//for//
|
||||
|
||||
//Start test 2.//
|
||||
iterator = objects.iterator();
|
||||
CreateTransactionDefinition ctd = (CreateTransactionDefinition) getTransactionService().getTransactionDefinition(TDI_CREATE_TEST);
|
||||
|
||||
//Define the transaction if it has not yet been defined.//
|
||||
if(ctd == null) {
|
||||
ctd = new CreateTransactionDefinition(new TestObject("Text", new Integer(0)), null);
|
||||
getTransactionService().completeTransactionDefinition(TDI_CREATE_TEST, ctd);
|
||||
}//if//
|
||||
|
||||
time = System.currentTimeMillis();
|
||||
|
||||
//Run the second test.//
|
||||
while(iterator.hasNext()) {
|
||||
object = (TestObject) iterator.next();
|
||||
getTransactionService().create(new CreateTransaction((CreateTransactionDefinition) getTransactionService().getTransactionDefinition(transactionIdentifier), object));
|
||||
}//while//
|
||||
|
||||
time = System.currentTimeMillis() - time;
|
||||
Debug.log("TEST#2: Total time to create " + objects.getSize() + " test objects was " + time + "ms.");
|
||||
}//performanceTestCreate()//
|
||||
/**
|
||||
* Starts the application by setting up the necessary services and then executing any necessary application code.
|
||||
*/
|
||||
protected void startApplication() {
|
||||
try {
|
||||
//Turn on debugging of transactions.//
|
||||
getTransactionService().debug(TransactionService.DEBUG_ALL);
|
||||
|
||||
updateTest();
|
||||
//simpleCreateReadDeleteTest();
|
||||
//simplePerformanceTest(100);
|
||||
//performanceTestCreate();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
try {
|
||||
//Delete all test objects.//
|
||||
getTransactionService().delete(new TestObject());
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//startApplication()//
|
||||
/**
|
||||
* Starts the application by setting up the necessary services and then executing any necessary application code.
|
||||
*/
|
||||
public void startup() {
|
||||
singleton = this;
|
||||
|
||||
if(setupMetadataService()) {
|
||||
setupTransactionService();
|
||||
|
||||
com.foundation.metadata.RepositoryMetadata metadata = com.foundation.metadata.MetadataService.getSingleton().getRepositoryMetadata(REPOSITORY_MYSQL);
|
||||
|
||||
try {
|
||||
startApplication();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
shutdown();
|
||||
}//if//
|
||||
else {
|
||||
shutdown();
|
||||
}//else//
|
||||
}//startup()//
|
||||
/**
|
||||
* Tests creating objects.
|
||||
*/
|
||||
protected void testCreate() {
|
||||
TestObject test = new TestObject();
|
||||
|
||||
test.setText("First test");
|
||||
test.setNumber(new Integer(1));
|
||||
Debug.log(test.getTransactionService().create(test) + " rows were created.");
|
||||
|
||||
test = new TestObject();
|
||||
test.setText("Second test");
|
||||
test.setNumber(new Integer(2));
|
||||
Debug.log(test.getTransactionService().create(test) + " rows were created.");
|
||||
|
||||
test = new TestObject();
|
||||
test.setText("Some middle test");
|
||||
test.setNumber(new Integer(102));
|
||||
Debug.log(test.getTransactionService().create(test) + " rows were created.");
|
||||
|
||||
test = new TestObject();
|
||||
test.setText("Last test");
|
||||
test.setNumber(new Integer(4502));
|
||||
Debug.log(test.getTransactionService().create(test) + " rows were created.");
|
||||
}//testCreate()//
|
||||
/**
|
||||
* Tests deleting objects.
|
||||
*/
|
||||
protected void testDelete() {
|
||||
TestObject test = new TestObject();
|
||||
DeleteTransaction transaction = null;
|
||||
|
||||
test.setNumber(new Integer(102));
|
||||
Debug.log(test.getTransactionService().delete(test) + " rows were deleted.");
|
||||
}//testDelete()//
|
||||
/**
|
||||
* Tests reading objects.
|
||||
*/
|
||||
protected void testReadMany() {
|
||||
TestObject test = new TestObject();
|
||||
ReadManyTransactionDefinition definition = null;
|
||||
ReadManyTransaction transaction = null;
|
||||
|
||||
//Read the one with the text = "text"//
|
||||
test.setText("text");
|
||||
Debug.log(test.getTransactionService().readMany(test).getSize() + " rows were returned.");
|
||||
|
||||
//Read the one with the text = "this is a test"//
|
||||
test.setText("this is a test");
|
||||
Debug.log(test.getTransactionService().readMany(test).getSize() + " rows were returned.");
|
||||
|
||||
//Read All//
|
||||
test = new TestObject();
|
||||
Debug.log(test.getTransactionService().readMany(test).getSize() + " rows were returned.");
|
||||
|
||||
|
||||
//Read All ordered (code style 1)//
|
||||
try {
|
||||
IIterator iterator = null;
|
||||
|
||||
Debug.log("Forward order test.");
|
||||
test = new TestObject();
|
||||
transaction = test.getTransactionService().initializeReadManyTransaction(test);
|
||||
((ReadManyTransactionDefinition) transaction.getTransactionDefinition()).addOrderAttribute(test.NUMBER, true);
|
||||
iterator = test.getTransactionService().readMany(transaction).iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log("\t" + iterator.next().toString());
|
||||
}//while//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e, "In test code");
|
||||
}//catch//
|
||||
|
||||
//Read All ordered (code style 2)//
|
||||
try {
|
||||
IIterator iterator = null;
|
||||
|
||||
Debug.log("Forward order test.");
|
||||
ReadManyTransactionDefinition rtd = (ReadManyTransactionDefinition) getTransactionService().getTransactionDefinition(TDI_READ_MANY_TEST_1);
|
||||
|
||||
if(rtd == null) {
|
||||
definition = new ReadManyTransactionDefinition(new TestObject(), null);
|
||||
definition.addOrderAttribute(test.NUMBER, true);
|
||||
getTransactionService().completeTransactionDefinition(TDI_READ_MANY_TEST_1, rtd);
|
||||
}//if//
|
||||
|
||||
test = new TestObject();
|
||||
iterator = test.getTransactionService().readMany(rtd.createTransaction(test)).iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log("\t" + iterator.next().toString());
|
||||
}//while//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e, "In test code");
|
||||
}//catch//
|
||||
|
||||
//Read All reverse ordered//
|
||||
try {
|
||||
IIterator iterator = null;
|
||||
|
||||
Debug.log("Reverse order test.");
|
||||
ReadManyTransactionDefinition rtd = (ReadManyTransactionDefinition) getTransactionService().getTransactionDefinition(TDI_READ_MANY_TEST_2);
|
||||
|
||||
if(rtd == null) {
|
||||
definition = new ReadManyTransactionDefinition(new TestObject(), null);
|
||||
definition.addOrderAttribute(test.NUMBER, false);
|
||||
getTransactionService().completeTransactionDefinition(TDI_READ_MANY_TEST_2, rtd);
|
||||
}//if//
|
||||
|
||||
test = new TestObject();
|
||||
iterator = test.getTransactionService().readMany(definition.createTransaction(test)).iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log("\t" + iterator.next().toString());
|
||||
}//while//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e, "In test code");
|
||||
}//catch//
|
||||
}//testReadMany()//
|
||||
/**
|
||||
* Tests reading objects.
|
||||
*/
|
||||
protected void testReadSingle() {
|
||||
TestObject test = new TestObject();
|
||||
ReadSingleTransaction transaction = null;
|
||||
|
||||
test = new TestObject();
|
||||
Debug.log((test.getTransactionService().readSingle(test) != null ? 1 : 0) + " rows were returned.");
|
||||
}//testReadMany()//
|
||||
/**
|
||||
* Tests reading objects.
|
||||
*/
|
||||
protected void testCustom() {
|
||||
TestObject test = new TestObject();
|
||||
|
||||
test = new TestObject();
|
||||
CustomTransaction t = test.getTransactionService().initializeCustomTransaction(test);
|
||||
t.setCustomTransactionProcessor(new CustomTransactionProcessor() {
|
||||
public void execute(Object resource, CustomTransaction transaction, RepositoryManager repositoryManager) throws Exception {
|
||||
java.sql.Connection connection = (java.sql.Connection) resource;
|
||||
|
||||
connection.prepareCall("myqueryhere");
|
||||
...
|
||||
}
|
||||
});
|
||||
}//testCustom()//
|
||||
/**
|
||||
* Tests updating objects.
|
||||
*/
|
||||
protected void testUpdate() {
|
||||
TestObject test = new TestObject();
|
||||
UpdateTransaction transaction = null;
|
||||
|
||||
test.setText("this is a test");
|
||||
test.setNumber(new Integer(102));
|
||||
Debug.log(test.getTransactionService().update(test.getTransactionService().initializeUpdateTransaction(test, new Attribute[] {TestObject.TEXT}, new Attribute[] {TestObject.NUMBER}, null)) + " rows were updated.");
|
||||
}//testUpdate()//
|
||||
}//PManApplication//
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.foundation.transaction.test;
|
||||
|
||||
import com.common.security.Random;
|
||||
import com.foundation.metadata.Attribute;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999-2002<p>
|
||||
*/
|
||||
public class TestObject extends AbstractModel {
|
||||
public static final Attribute NUMBER = registerAttribute(TestObject.class, "number");
|
||||
public static final Attribute TEXT = registerAttribute(TestObject.class, "text");
|
||||
public static final Attribute ID = registerAttribute(TestObject.class, "id");
|
||||
public static final Attribute FIXED_SIZE_DATA = registerAttribute(TestObject.class, "fixedSizeData");
|
||||
/**
|
||||
* TestObject constructor.
|
||||
*/
|
||||
public TestObject() {
|
||||
super();
|
||||
}//TestObject()//
|
||||
/**
|
||||
* TestObject constructor.
|
||||
*/
|
||||
public TestObject(Integer id) {
|
||||
super();
|
||||
|
||||
setId(id);
|
||||
}//TestObject()//
|
||||
/**
|
||||
* TestObject constructor.
|
||||
*/
|
||||
public TestObject(Integer id, String text, Integer number) {
|
||||
super();
|
||||
|
||||
setId(id);
|
||||
setText(text);
|
||||
setNumber(number);
|
||||
}//TestObject()//
|
||||
/**
|
||||
* TestObject constructor.
|
||||
* Also calls initialize data to setup the data arrays.
|
||||
*/
|
||||
public TestObject(String text, Integer number) {
|
||||
super();
|
||||
|
||||
setText(text);
|
||||
setNumber(number);
|
||||
initializeData();
|
||||
}//TestObject()//
|
||||
/**
|
||||
* Initializes the object with some random data.
|
||||
*/
|
||||
public void initializeData() {
|
||||
byte[] data = new byte[20];
|
||||
Random random = new Random();
|
||||
|
||||
for(int index = 0; index < data.length; index++) {
|
||||
data[index] = random.nextByte();
|
||||
}//for//
|
||||
|
||||
setFixedSizeData(data);
|
||||
}//initializeData()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) getAttributeValue(ID);
|
||||
}//getId()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Integer getNumber() {
|
||||
return (Integer) getAttributeValue(NUMBER);
|
||||
}//getNumber()//
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getText() {
|
||||
return (String) getAttributeValue(TEXT);
|
||||
}//getText()//
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public byte[] getFixedSizeData() {
|
||||
return (byte[]) getAttributeValue(FIXED_SIZE_DATA);
|
||||
}//getFixedSizeData()//
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
setAttributeValue(ID, id);
|
||||
}//setId()//
|
||||
/**
|
||||
*
|
||||
* @param number
|
||||
*/
|
||||
public void setNumber(Integer number) {
|
||||
setAttributeValue(NUMBER, number);
|
||||
}//setNumber()//
|
||||
/**
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
public void setText(String text) {
|
||||
setAttributeValue(TEXT, text);
|
||||
}//setText()//
|
||||
/**
|
||||
* @param fixedSizeData
|
||||
*/
|
||||
private void setFixedSizeData(byte[] fixedSizeData) {
|
||||
setAttributeValue(FIXED_SIZE_DATA, fixedSizeData);
|
||||
}//setFixedSizeData()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "Id: " + getId() + " Number: " + getNumber() + " Text: " + getText();
|
||||
}//toString()//
|
||||
}//TestObject//
|
||||
84
Foundation Test/src/com/foundation/util/test/Main.java
Normal file
84
Foundation Test/src/com/foundation/util/test/Main.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package com.foundation.util.test;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
import com.foundation.util.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
try {
|
||||
ManagedList list = new ManagedList(ManagedList.DEFAULT_INITIAL_SIZE, ManagedList.DEFAULT_CAPACITY_INCREMENT);
|
||||
byte[] buffer = null;
|
||||
LiteList added = new LiteList(10, 20);
|
||||
LiteList removed = new LiteList(10, 20);
|
||||
|
||||
//Test 1//
|
||||
list.add("Hello");
|
||||
list.remove("Hello");
|
||||
list.getCollectionChanges(added, removed);
|
||||
|
||||
if((added.getSize() != 0) || (removed.getSize() != 0)) {
|
||||
throw new RuntimeException("Failed test 1");
|
||||
}//if//
|
||||
|
||||
added.removeAll();
|
||||
removed.removeAll();
|
||||
|
||||
//Test 2//
|
||||
list.add(new Integer(10));
|
||||
list.add("Bonkers");
|
||||
list.remove("bonkers");
|
||||
list.getCollectionChanges(added, removed);
|
||||
|
||||
if((added.getSize() != 2) || (removed.getSize() != 0)) {
|
||||
throw new RuntimeException("Failed test 2");
|
||||
}//if//
|
||||
|
||||
added.removeAll();
|
||||
removed.removeAll();
|
||||
|
||||
list = new ManagedList();
|
||||
list.add("abc");
|
||||
|
||||
{//Test write.//
|
||||
com.common.io.ByteArrayOutputStream bout = new com.common.io.ByteArrayOutputStream(100, false);
|
||||
//java.io.FileOutputStream fout = new java.io.FileOutputStream("c:\\temp\\temp.dat", false);
|
||||
com.common.io.ObjectOutputStream out = new com.common.io.ObjectOutputStream(bout, null);
|
||||
|
||||
out.writeObject(list);
|
||||
buffer = bout.toByteArray();
|
||||
out.close();
|
||||
}//block//
|
||||
|
||||
{//Test read.//
|
||||
com.common.io.ByteArrayInputStream bin = new com.common.io.ByteArrayInputStream(buffer);
|
||||
//java.io.File file = new java.io.File("c:\\temp\\temp.dat");
|
||||
//java.io.FileInputStream fin = new java.io.FileInputStream(file);
|
||||
com.common.io.ObjectInputStream in = new com.common.io.ObjectInputStream(bin, null, null);
|
||||
|
||||
list = (ManagedList) in.readObject();
|
||||
in.close();
|
||||
//file.delete();
|
||||
}//block//
|
||||
|
||||
//Verify the list contents.//
|
||||
if((list.getSize() != 1) && (!list.get(0).equals("abc"))) {
|
||||
Debug.log("Error: Bad serialization.");
|
||||
}//if//
|
||||
|
||||
Debug.log("Tests successfull.");
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,618 @@
|
||||
package com.foundation.util.xml.test;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.ShellEvent;
|
||||
import org.eclipse.swt.events.ShellListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
import com.foundation.util.xml.*;
|
||||
import com.foundation.view.JefColor;
|
||||
import com.foundation.view.swt.util.SwtUtilities;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2008<p>
|
||||
*/
|
||||
public class HtmlReadTest {
|
||||
public static final String[] BROKEN_HTML_TESTS = new String[] {
|
||||
"<s a='1\\'/>",
|
||||
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n/<!-- Test -->\n<html>\n<head>\n</head>\n</html>",
|
||||
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n/<html>\n<head>\n</head>\n</html>",
|
||||
"<!-- Test",
|
||||
"<",
|
||||
"h></h>",
|
||||
"<?<h></h>",
|
||||
"<b><f n=</b>",
|
||||
"<?xml version=\"1.0?><html></html>",
|
||||
"<a></<b/>",
|
||||
"<? xml version='1.0' encoding=\"iso-8859-1\" ?>",
|
||||
"<tag a='1'b/>",
|
||||
"<tag a='1'b></tag>",
|
||||
"<html><head></</html>",
|
||||
"<html><<head></head></html>",
|
||||
"<!DOCT",
|
||||
"<!DOCTYPE",
|
||||
"<!DOCTYPE ",
|
||||
"<!DOCTYPE ht",
|
||||
"<!DOCTYPE>",
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.",
|
||||
"<a>abc</a x='1'>",
|
||||
"abc",
|
||||
"</>",
|
||||
"<>",
|
||||
"<a=\"x\"/>",
|
||||
"<tag 1attr=\"test\">",
|
||||
"<tag attr=\">",
|
||||
"<tag attr='>",
|
||||
"<tag attr=\"/>",
|
||||
"<tag attr='/>",
|
||||
"< tag attr=''/>",
|
||||
"<tag attr=-\"/>",
|
||||
"<1tag> </1tag>",
|
||||
"<1tag/>",
|
||||
"<",
|
||||
"<tag",
|
||||
"<tag> </wrong>",
|
||||
"<tag> </tag",
|
||||
"<tag></",
|
||||
"<tag attr/='abc'/>",
|
||||
"<tag'123'/>",
|
||||
"<tag attr'123'/>",
|
||||
"<tag attr='ne<!--='hello'-->w'/>",
|
||||
"<tag <!--test-->/>",
|
||||
"<tag <!--test /> -->/>",
|
||||
"<tag attr<!--='hello'-->='new'/>",
|
||||
"<tag attr=<!--='hello'-->'new'/>",
|
||||
"<tag attr='new'<!--='hello'-->/>",
|
||||
"<ta<!-- test -->ble/>"
|
||||
};
|
||||
public static final String[] MABYE_BROKEN_HTML_TESTS = new String[] {
|
||||
"<%tag%>",
|
||||
"<tag attr = abc />",
|
||||
"<tag>",
|
||||
"<outer><tag></outer>",
|
||||
"<tag attr=abc attr2='123'/>",
|
||||
"<tag attr ibute='abc'/>",
|
||||
"<%tag%>",
|
||||
"<%tag/%>"
|
||||
};
|
||||
public static final String[] GOOD_HTML_TESTS = new String[] {
|
||||
"<a:b></a:b>",
|
||||
"<?xml version=\"1.0\"?>\n<!-- com.declarativeengineering.jetson.application.JetsonApplication -->\n<repository name='HSQL' class='com.foundation.transaction.jdbc.hsql.HsqlRepositoryManager'>",
|
||||
"<?xml version='1.0' encoding=\"iso-8859-1\"?>",
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>",
|
||||
"",
|
||||
"<tag attr = 'abc' />",
|
||||
"<tag attr='abc'attr2='123'/>",
|
||||
"<!--test <tag /> -->",
|
||||
"<tag attr-ibute='abc'/>",
|
||||
"<tag attr_ibute='abc'/>",
|
||||
"<tag attr123ibute123='abc'/>",
|
||||
"<tag attr \r\n ='abc'/>",
|
||||
"<tag attr= \r\n 'abc'/>",
|
||||
"<tag attr \r\n = \r\n 'abc'/>",
|
||||
"<tag attr=\"abc>\"/>",
|
||||
"<tag attr=\"abc/>\"/>",
|
||||
"<tag-2/>",
|
||||
"<tag>text</tag>",
|
||||
"<tag> text </tag>"
|
||||
//TODO: Test these...
|
||||
//<?xml version='1.0' encoding=\"UTF-8\"?>,
|
||||
//"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
|
||||
};
|
||||
private Color errorColor = null;
|
||||
private Color textColor = null;
|
||||
private Color nodeColor = null;
|
||||
private Color commentColor = null;
|
||||
private Color attributeNameColor = null;
|
||||
private Color attributeValueColor = null;
|
||||
private Color documentNodeColor = null;
|
||||
private Color documentAttributeColor = null;
|
||||
private StyledText styledText = null;
|
||||
public static void main(String[] args) {
|
||||
new HtmlReadTest().run();
|
||||
}//main()//
|
||||
/**
|
||||
* Appends tabs to the output buffer.
|
||||
* @param tabs
|
||||
* @param output
|
||||
*/
|
||||
private void appendTabs(int tabs, StringBuffer output) {
|
||||
while(tabs-- > 0) {
|
||||
output.append('\t');
|
||||
}//while//
|
||||
}//appendTabs()//
|
||||
public void run() {
|
||||
final Display display = Display.getDefault();
|
||||
final Shell shell = new Shell(display);
|
||||
FillLayout layout = new FillLayout();
|
||||
layout.marginHeight = 4;
|
||||
layout.marginWidth = 4;
|
||||
shell.setText("HTML Read Test Output");
|
||||
shell.setLayout(layout);
|
||||
styledText = new StyledText(shell, SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
|
||||
styledText.setText("Processing...");
|
||||
shell.addShellListener(new ShellListener() {
|
||||
public void shellIconified(ShellEvent e) {
|
||||
}
|
||||
public void shellDeiconified(ShellEvent e) {
|
||||
}
|
||||
public void shellDeactivated(ShellEvent e) {
|
||||
}
|
||||
public void shellClosed(ShellEvent e) {
|
||||
shell.setVisible(false);
|
||||
shell.dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
public void shellActivated(ShellEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
errorColor = SwtUtilities.getColor(display, new JefColor(JefColor.COLOR_RED));
|
||||
textColor = SwtUtilities.getColor(display, new JefColor(JefColor.COLOR_BLACK));
|
||||
nodeColor = SwtUtilities.getColor(display, new JefColor(JefColor.COLOR_BLUE));
|
||||
commentColor = SwtUtilities.getColor(display, new JefColor(JefColor.COLOR_GREEN));
|
||||
attributeNameColor = SwtUtilities.getColor(display, new JefColor(JefColor.COLOR_DARK_YELLOW));
|
||||
attributeValueColor = SwtUtilities.getColor(display, new JefColor(JefColor.COLOR_GRAY));
|
||||
documentNodeColor = SwtUtilities.getColor(display, new JefColor(JefColor.COLOR_DARK_CYAN));
|
||||
documentAttributeColor = SwtUtilities.getColor(display, new JefColor(JefColor.COLOR_DARK_GREEN));
|
||||
|
||||
//Run the test outside of the view thread.//
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
final IList styleRanges = new LiteList(100, 1000);
|
||||
final IList originalStyleRanges = new LiteList(100, 1000);
|
||||
final StringBuffer output = new StringBuffer(1000);
|
||||
final StringBuffer originalOutput = new StringBuffer(1000);
|
||||
/*
|
||||
try {
|
||||
File testFile = new File("test.xml");
|
||||
|
||||
com.foundation.util.xml.DocumentBuilder builder = new com.foundation.util.xml.DocumentBuilder();
|
||||
String text = StreamSupport.readText(testFile, "UTF8");
|
||||
IDocument document = builder.readDocument(text);
|
||||
|
||||
nextElement(document, 0, output, styleRanges, 0, originalStyleRanges);
|
||||
originalOutput.append(text);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
*/
|
||||
|
||||
output.append("\r\n");
|
||||
output.append("----------------------------\r\n");
|
||||
output.append("Testing Broken HTML Segments\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("----------------------------\r\n");
|
||||
originalOutput.append("Testing Broken HTML Segments\r\n");
|
||||
for(int index = 0; index < 1; index++) { //BROKEN_HTML_TESTS.length
|
||||
Debug.log("Testing " + BROKEN_HTML_TESTS[index]);
|
||||
|
||||
try {
|
||||
com.foundation.util.xml.DocumentBuilder builder = new com.foundation.util.xml.DocumentBuilder();
|
||||
builder.allowAttributesWithoutValues(true);
|
||||
builder.allowAttributesWithUnquotedValues(true);
|
||||
builder.allowUnendedNodes(true);
|
||||
IDocument document = builder.readDocument(BROKEN_HTML_TESTS[index]);
|
||||
|
||||
output.append("\r\n");
|
||||
output.append("Testing: " + BROKEN_HTML_TESTS[index] + "\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("Testing: " + BROKEN_HTML_TESTS[index] + "\r\n");
|
||||
nextElement(document, 1, output, styleRanges, originalOutput.length(), originalStyleRanges);
|
||||
originalOutput.append(BROKEN_HTML_TESTS[index]);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//for//
|
||||
/*
|
||||
output.append("\r\n");
|
||||
output.append("----------------------------------\r\n");
|
||||
output.append("Testing Maybe Broken HTML Segments\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("----------------------------------\r\n");
|
||||
originalOutput.append("Testing Maybe Broken HTML Segments\r\n");
|
||||
for(int index = 0; index < MABYE_BROKEN_HTML_TESTS.length; index++) {
|
||||
Debug.log("Testing " + MABYE_BROKEN_HTML_TESTS[index]);
|
||||
|
||||
try {
|
||||
com.foundation.util.xml.DocumentBuilder builder = new com.foundation.util.xml.DocumentBuilder();
|
||||
builder.allowAttributesWithoutValues(true);
|
||||
builder.allowAttributesWithUnquotedValues(true);
|
||||
builder.allowUnendedNodes(true);
|
||||
IDocument document = builder.readDocument(MABYE_BROKEN_HTML_TESTS[index]);
|
||||
|
||||
output.append("\r\n");
|
||||
output.append("Testing: " + MABYE_BROKEN_HTML_TESTS[index] + "\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("Testing: " + MABYE_BROKEN_HTML_TESTS[index] + "\r\n");
|
||||
nextElement(document, 1, output, styleRanges, originalOutput.length(), originalStyleRanges);
|
||||
originalOutput.append(MABYE_BROKEN_HTML_TESTS[index]);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//for//
|
||||
|
||||
output.append("\r\n");
|
||||
output.append("--------------------------\r\n");
|
||||
output.append("Testing Good HTML Segments\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("--------------------------\r\n");
|
||||
originalOutput.append("Testing Good HTML Segments\r\n");
|
||||
for(int index = 0; index < GOOD_HTML_TESTS.length; index++) {
|
||||
Debug.log("Testing " + GOOD_HTML_TESTS[index]);
|
||||
|
||||
try {
|
||||
com.foundation.util.xml.DocumentBuilder builder = new com.foundation.util.xml.DocumentBuilder();
|
||||
IDocument document = builder.readDocument(GOOD_HTML_TESTS[index]);
|
||||
|
||||
output.append("\r\n");
|
||||
output.append("Testing: " + GOOD_HTML_TESTS[index] + "\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("Testing: " + GOOD_HTML_TESTS[index] + "\r\n");
|
||||
nextElement(document, 1, output, styleRanges, originalOutput.length(), originalStyleRanges);
|
||||
originalOutput.append(GOOD_HTML_TESTS[index]);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//for//
|
||||
*/
|
||||
/*
|
||||
//String test = "<html onload='<%=attr%>'>abc</html>";
|
||||
String test = "<a b='<%=c%>'><%if attribute='z'%>abc<%/if%><%else%>123<%/else%></a>";
|
||||
//int[] ignoredSections = new int[] {14, 22};
|
||||
int[] ignoredSections = new int[] {6, 11, 14, 33, 37, 43, 44, 51, 55, 63};
|
||||
output.append("\r\n");
|
||||
output.append("----------------------------\r\n");
|
||||
output.append("Testing Custom HTML Segments\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("----------------------------\r\n");
|
||||
originalOutput.append("Testing Custom HTML Segments\r\n");
|
||||
Debug.log("Testing " + test);
|
||||
|
||||
try {
|
||||
com.foundation.util.xml.DocumentBuilder builder = new com.foundation.util.xml.DocumentBuilder();
|
||||
IDocument document = builder.readDocument(test, ignoredSections);
|
||||
|
||||
output.append("\r\n");
|
||||
output.append("Testing: " + test + "\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("Testing: " + test + "\r\n");
|
||||
nextElement(document, 1, output, styleRanges, originalOutput.length(), originalStyleRanges);
|
||||
originalOutput.append(test);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
*/
|
||||
/*
|
||||
String fileTest = null;
|
||||
try {
|
||||
fileTest = StreamSupport.readText(new File("./view.txt"), "UTF8");
|
||||
}catch(Throwable e) {Debug.log(e);}
|
||||
output.append("\r\n");
|
||||
output.append("----------------------------\r\n");
|
||||
output.append("Testing HTML From File\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("----------------------------\r\n");
|
||||
originalOutput.append("Testing HTML From File\r\n");
|
||||
Debug.log("Testing " + fileTest);
|
||||
|
||||
try {
|
||||
com.foundation.util.xml.DocumentBuilder builder = new com.foundation.util.xml.DocumentBuilder();
|
||||
IDocument document = builder.readDocument(fileTest);
|
||||
|
||||
output.append("\r\n");
|
||||
output.append("Testing: " + fileTest + "\r\n");
|
||||
originalOutput.append("\r\n");
|
||||
originalOutput.append("Testing: " + fileTest + "\r\n");
|
||||
nextElement(document, 1, output, styleRanges, originalOutput.length(), originalStyleRanges);
|
||||
originalOutput.append(fileTest);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
*/
|
||||
display.asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
StyleRange[] styleRangeArray = null;
|
||||
|
||||
/*
|
||||
//Display the generated html output.//
|
||||
styleRangeArray = new StyleRange[styleRanges.getSize()];
|
||||
styleRanges.toArray(styleRangeArray);
|
||||
styledText.setText(output.toString());
|
||||
styledText.setStyleRanges(styleRangeArray);
|
||||
*/
|
||||
//Display the original html output.//
|
||||
styleRangeArray = new StyleRange[originalStyleRanges.getSize()];
|
||||
originalStyleRanges.toArray(styleRangeArray);
|
||||
styledText.setText(originalOutput.toString());
|
||||
styledText.setStyleRanges(styleRangeArray);
|
||||
}//run()//
|
||||
});
|
||||
}//run()//
|
||||
}).start();
|
||||
|
||||
shell.setVisible(true);
|
||||
|
||||
//Keep processing view messages until the view is closed.//
|
||||
while(!shell.isDisposed()) {
|
||||
if(!display.readAndDispatch())
|
||||
display.sleep();
|
||||
}//while//
|
||||
}//run()//
|
||||
/**
|
||||
* Displays the next element in the document.
|
||||
* @param element The next element to process.
|
||||
* @param tabs The current tab level for the generated output.
|
||||
* @param output The generated output from the document tree.
|
||||
* @param styleRanges Styles applied to the generated output.
|
||||
* @param originalOffset The offset to be applied to the indices in the original style ranges.
|
||||
* @param originalStyleRanges Styles applied to the original text.
|
||||
*/
|
||||
private void nextElement(IElement element, int tabs, StringBuffer output, IList styleRanges, int originalOffset, IList originalStyleRanges) {
|
||||
if(element.isDocument()) {
|
||||
IList attributeNames = ((IDocument) element).getAttributeNames();
|
||||
IList elements = ((IAbstractNode) element).getElements();
|
||||
|
||||
for(int index = 0; index < attributeNames.getSize(); index++) {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
StyleRange originalStyleRange = new StyleRange();
|
||||
IAttribute next = ((IAbstractNode) element).getAttribute((String) attributeNames.get(index));
|
||||
|
||||
output.append("\r\n");
|
||||
appendTabs(tabs, output);
|
||||
output.append("<!");
|
||||
styleRange.start = output.length();
|
||||
output.append(next.getName());
|
||||
output.append('=');
|
||||
output.append('\'');
|
||||
output.append(next.getValue());
|
||||
output.append('\'');
|
||||
output.append(">");
|
||||
styleRange.length = output.length() - styleRange.start;
|
||||
styleRange.foreground = documentAttributeColor;
|
||||
originalStyleRange.start = next.getStartCharacter() + originalOffset;
|
||||
originalStyleRange.length = next.getEndCharacter() - next.getStartCharacter() + 1;
|
||||
originalStyleRange.foreground = documentAttributeColor;
|
||||
|
||||
if(next.hasErrors()) {
|
||||
styleRange.underline = true;
|
||||
styleRange.underlineColor = errorColor;
|
||||
styleRange.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
originalStyleRange.underline = true;
|
||||
originalStyleRange.underlineColor = errorColor;
|
||||
originalStyleRange.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
}//if//
|
||||
|
||||
originalStyleRanges.add(originalStyleRange);
|
||||
styleRanges.add(styleRange);
|
||||
}//for//
|
||||
|
||||
for(int index = 0; index < elements.getSize(); index++) {
|
||||
IElement next = (IElement) elements.get(index);
|
||||
|
||||
nextElement(next, tabs + 1, output, styleRanges, originalOffset, originalStyleRanges);
|
||||
}//for//
|
||||
}//if//
|
||||
else if(element.isNode()) {
|
||||
IList elements = ((IAbstractNode) element).getElements();
|
||||
IList attributes = ((IAbstractNode) element).getAttributes();
|
||||
StyleRange nodeStyle = new StyleRange();
|
||||
StyleRange originalNodeStyle = new StyleRange();
|
||||
StyleRange startNodeTailStyle = new StyleRange();
|
||||
StyleRange originalStartNodeTailStyle = new StyleRange();
|
||||
|
||||
output.append("\r\n");
|
||||
appendTabs(tabs, output);
|
||||
nodeStyle.start = output.length();
|
||||
output.append("<");
|
||||
output.append(((INode) element).getName());
|
||||
nodeStyle.length = output.length() - nodeStyle.start;
|
||||
nodeStyle.foreground = nodeColor;
|
||||
originalNodeStyle.start = element.getStartCharacter() + originalOffset;
|
||||
originalNodeStyle.length = ((INode) element).getStartTagEndNameCharacter() != -1 ? ((INode) element).getStartTagEndNameCharacter() - element.getStartCharacter() + 1 : 1;
|
||||
originalNodeStyle.foreground = nodeColor;
|
||||
|
||||
if(element.hasErrors()) {
|
||||
nodeStyle.underline = true;
|
||||
nodeStyle.underlineColor = errorColor;
|
||||
nodeStyle.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
originalNodeStyle.underline = true;
|
||||
originalNodeStyle.underlineColor = errorColor;
|
||||
originalNodeStyle.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
}//if//
|
||||
|
||||
styleRanges.add(nodeStyle);
|
||||
originalStyleRanges.add(originalNodeStyle);
|
||||
|
||||
for(int index = 0; index < attributes.getSize(); index++) {
|
||||
StyleRange nameStyleRange = new StyleRange();
|
||||
StyleRange valueStyleRange = new StyleRange();
|
||||
StyleRange originalNameStyleRange = new StyleRange();
|
||||
StyleRange originalValueStyleRange = new StyleRange();
|
||||
IAttribute next = (IAttribute) attributes.get(index);
|
||||
|
||||
output.append("\r\n");
|
||||
appendTabs(tabs + 2, output);
|
||||
nameStyleRange.start = output.length();
|
||||
output.append(next.getName());
|
||||
nameStyleRange.length = output.length() - nameStyleRange.start;
|
||||
nameStyleRange.foreground = attributeNameColor;
|
||||
originalNameStyleRange.start = next.getStartCharacter() + originalOffset;
|
||||
originalNameStyleRange.length = next.getNameEndCharacter() - next.getStartCharacter() + 1;
|
||||
originalNameStyleRange.foreground = attributeNameColor;
|
||||
|
||||
if(next.hasErrors()) {
|
||||
nameStyleRange.underline = true;
|
||||
nameStyleRange.underlineColor = errorColor;
|
||||
nameStyleRange.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
originalNameStyleRange.underline = true;
|
||||
originalNameStyleRange.underlineColor = errorColor;
|
||||
originalNameStyleRange.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
}//if//
|
||||
|
||||
styleRanges.add(nameStyleRange);
|
||||
originalStyleRanges.add(originalNameStyleRange);
|
||||
|
||||
if(next.getValue() != null) {
|
||||
output.append('=');
|
||||
valueStyleRange.start = output.length();
|
||||
output.append('\'');
|
||||
output.append(next.getValue());
|
||||
output.append('\'');
|
||||
output.append(' ');
|
||||
valueStyleRange.length = output.length() - valueStyleRange.start;
|
||||
valueStyleRange.foreground = attributeValueColor;
|
||||
originalValueStyleRange.start = next.getValueStartCharacter() + originalOffset;
|
||||
originalValueStyleRange.length = next.getEndCharacter() - next.getValueStartCharacter() + 1;
|
||||
originalValueStyleRange.foreground = attributeValueColor;
|
||||
|
||||
if(next.hasValueErrors()) {
|
||||
valueStyleRange.underline = true;
|
||||
valueStyleRange.underlineColor = errorColor;
|
||||
valueStyleRange.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
originalValueStyleRange.underline = true;
|
||||
originalValueStyleRange.underlineColor = errorColor;
|
||||
originalValueStyleRange.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
}//if//
|
||||
|
||||
styleRanges.add(valueStyleRange);
|
||||
originalStyleRanges.add(originalValueStyleRange);
|
||||
}//if//
|
||||
}//for//
|
||||
|
||||
startNodeTailStyle.start = output.length();
|
||||
output.append(elements.getSize() > 0 || ((INode) element).isEndless() ? ">" : "/>");
|
||||
startNodeTailStyle.length = elements.getSize() > 0 ? 1 : 2;
|
||||
styleRanges.add(startNodeTailStyle);
|
||||
|
||||
if(((INode) element).getStartTagTailStartCharacter() != -1 && ((INode) element).getStartTagTailEndCharacter() != -1) {
|
||||
originalStartNodeTailStyle.start = ((INode) element).getStartTagTailStartCharacter() + originalOffset;
|
||||
originalStartNodeTailStyle.length = ((INode) element).getStartTagTailEndCharacter() - ((INode) element).getStartTagTailStartCharacter() + 1;
|
||||
originalStartNodeTailStyle.foreground = nodeColor;
|
||||
|
||||
if(element.hasErrors()) {
|
||||
originalStartNodeTailStyle.underline = true;
|
||||
originalStartNodeTailStyle.underlineColor = errorColor;
|
||||
originalStartNodeTailStyle.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
}//if//
|
||||
|
||||
originalStyleRanges.add(originalStartNodeTailStyle);
|
||||
}//if//
|
||||
|
||||
//If there are children of this node then handle them and follow up with an end node tag.//
|
||||
if(elements.getSize() > 0) {
|
||||
StyleRange endNodeStyle = new StyleRange();
|
||||
|
||||
//Add the child elements.//
|
||||
for(int index = 0; index < elements.getSize(); index++) {
|
||||
IElement next = (IElement) elements.get(index);
|
||||
|
||||
nextElement(next, tabs + 1, output, styleRanges, originalOffset, originalStyleRanges);
|
||||
}//for//
|
||||
|
||||
output.append("\r\n");
|
||||
appendTabs(tabs, output);
|
||||
endNodeStyle.start = output.length();
|
||||
output.append("</");
|
||||
output.append(((INode) element).getName());
|
||||
output.append('>');
|
||||
endNodeStyle.length = output.length() - endNodeStyle.start;
|
||||
endNodeStyle.foreground = nodeColor;
|
||||
|
||||
if(element.hasErrors()) {
|
||||
endNodeStyle.underline = true;
|
||||
endNodeStyle.underlineColor = errorColor;
|
||||
endNodeStyle.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
}//if//
|
||||
|
||||
styleRanges.add(endNodeStyle);
|
||||
}//if//
|
||||
|
||||
//If there was an end node tag on this node then setup it's styling.//
|
||||
if(((INode) element).getEndTagStartCharacter() != -1) {
|
||||
StyleRange originalEndNodeStyle = new StyleRange();
|
||||
|
||||
originalEndNodeStyle.start = ((INode) element).getEndTagStartCharacter() + originalOffset;
|
||||
originalEndNodeStyle.length = ((INode) element).getEndCharacter() - ((INode) element).getEndTagStartCharacter() + 1;
|
||||
originalEndNodeStyle.foreground = nodeColor;
|
||||
|
||||
if(element.hasErrors()) {
|
||||
originalEndNodeStyle.underline = true;
|
||||
originalEndNodeStyle.underlineColor = errorColor;
|
||||
originalEndNodeStyle.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
}//if//
|
||||
|
||||
originalStyleRanges.add(originalEndNodeStyle);
|
||||
}//if//
|
||||
}//else if//
|
||||
else if(element.isComment()) {
|
||||
StyleRange style = new StyleRange();
|
||||
StyleRange originalStyle = new StyleRange();
|
||||
|
||||
output.append("\r\n");
|
||||
appendTabs(tabs, output);
|
||||
style.start = output.length();
|
||||
output.append("<!--");
|
||||
output.append(((IComment) element).getText());
|
||||
output.append("-->");
|
||||
style.length = output.length() - style.start;
|
||||
style.foreground = commentColor;
|
||||
originalStyle.start = element.getStartCharacter() + originalOffset;
|
||||
originalStyle.length = element.getEndCharacter() - element.getStartCharacter() + 1;
|
||||
originalStyle.foreground = commentColor;
|
||||
styleRanges.add(style);
|
||||
originalStyleRanges.add(originalStyle);
|
||||
}//else if//
|
||||
else if(element.isText()) {
|
||||
StyleRange style = new StyleRange();
|
||||
StyleRange originalStyle = new StyleRange();
|
||||
|
||||
output.append("\r\n");
|
||||
appendTabs(tabs, output);
|
||||
style.start = output.length();
|
||||
output.append(((IText) element).getText());
|
||||
style.length = output.length() - style.start;
|
||||
style.foreground = textColor;
|
||||
originalStyle.start = element.getStartCharacter() + originalOffset;
|
||||
originalStyle.length = element.getEndCharacter() - element.getStartCharacter() + 1;
|
||||
originalStyle.foreground = textColor;
|
||||
styleRanges.add(style);
|
||||
originalStyleRanges.add(originalStyle);
|
||||
}//else if//
|
||||
else if(element.isInvalid()) {
|
||||
StyleRange style = new StyleRange();
|
||||
StyleRange originalStyle = new StyleRange();
|
||||
|
||||
output.append("\r\n");
|
||||
appendTabs(tabs, output);
|
||||
style.start = output.length();
|
||||
output.append(((IInvalid) element).getInvalidText());
|
||||
style.length = output.length() - style.start;
|
||||
style.foreground = textColor;
|
||||
style.underline = true;
|
||||
style.underlineColor = errorColor;
|
||||
style.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
originalStyle.start = element.getStartCharacter() + originalOffset;
|
||||
originalStyle.length = element.getEndCharacter() - element.getStartCharacter() + 1;
|
||||
originalStyle.foreground = textColor;
|
||||
originalStyle.underline = true;
|
||||
originalStyle.underlineColor = errorColor;
|
||||
originalStyle.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
|
||||
styleRanges.add(style);
|
||||
originalStyleRanges.add(originalStyle);
|
||||
}//else if//
|
||||
}//nextNode()//
|
||||
}//HtmlReadTest//
|
||||
BIN
Foundation Test/test.key
Normal file
BIN
Foundation Test/test.key
Normal file
Binary file not shown.
41
Foundation Test/test.xml
Normal file
41
Foundation Test/test.xml
Normal file
File diff suppressed because one or more lines are too long
3
Foundation Test/view.txt
Normal file
3
Foundation Test/view.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
<a>
|
||||
</
|
||||
<b/>
|
||||
Reference in New Issue
Block a user