Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
November 2008
- 5 participants
- 39 discussions
Author: chatellier
Date: 2008-11-18 14:21:49 +0000 (Tue, 18 Nov 2008)
New Revision: 1231
Modified:
topia-service/trunk/pom.xml
Log:
D?\195?\169pend de la version modulaire de topia
Modified: topia-service/trunk/pom.xml
===================================================================
--- topia-service/trunk/pom.xml 2008-11-18 14:11:07 UTC (rev 1230)
+++ topia-service/trunk/pom.xml 2008-11-18 14:21:49 UTC (rev 1231)
@@ -13,13 +13,14 @@
</parent>
<artifactId>topia-service</artifactId>
-
+ <version>1.0.0-SNAPSHOT</version>
+
<dependencies>
<!--Compile-->
<dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>topia</artifactId>
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
<version>${topia.version}</version>
<scope>compile</scope>
</dependency>
@@ -49,7 +50,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <version>1.0.79</version>
+ <version>1.1.103</version>
<scope>test</scope>
</dependency>
@@ -60,9 +61,8 @@
<!-- ************************************************************* -->
<name>ToPIA Service</name>
- <version>0.10-SNAPSHOT</version>
<description>
- ToPIA Service est une librairie de ToPIA pour la gestion de sercices.
+ ToPIA Service est une librairie de ToPIA pour la gestion de services.
</description>
<inceptionYear>2006</inceptionYear>
@@ -80,7 +80,7 @@
<labs.project>topia</labs.project>
<!-- topia version -->
- <topia.version>2.0.28</topia.version>
+ <topia.version>2.1.0-SNAPSHOT</topia.version>
<!-- Test FIXME : should be ok -->
<maven.test.skip>true</maven.test.skip>
@@ -93,10 +93,10 @@
<plugin>
<groupId>org.codelutin</groupId>
<artifactId>maven-generator-plugin</artifactId>
- <version>0.61</version>
+ <version>0.62-SNAPSHOT</version>
<executions>
<execution>
- <phase>process-sources</phase>
+ <phase>generate-sources</phase>
<!--Configuration of model generator-->
<configuration>
<addCompileDirectory>true</addCompileDirectory>
@@ -108,7 +108,6 @@
<destDirGen>${maven.gen.dir}/java</destDirGen>
<defaultPackage>org.codelutin.topia</defaultPackage>
<extractedPackages>org.codelutin.topia.tass</extractedPackages>
-
<copyVersionDir>src/main/resources/oldmappings/%MODELNAME%</copyVersionDir>
<copyVersionFiles>**/*.hbm.xml</copyVersionFiles>
<copyOverwrite>true</copyOverwrite>
@@ -123,10 +122,10 @@
</executions>
<dependencies>
<dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>topia</artifactId>
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
<version>${topia.version}</version>
- <scope>compile</scope>
+ <scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
1
0
r1230 - in topia/trunk: . topia-persistence topia-persistence/src topia-persistence/src/main topia-persistence/src/main/java topia-persistence/src/main/java/org topia-persistence/src/main/java/org/codelutin topia-persistence/src/main/java/org/codelutin/topia topia-persistence/src/main/java/org/codelutin/topia/event topia-persistence/src/main/java/org/codelutin/topia/framework topia-persistence/src/main/java/org/codelutin/topia/generator topia-persistence/src/main/java/org/codelutin/topia/per
by chatellier@users.labs.libre-entreprise.org 18 Nov '08
by chatellier@users.labs.libre-entreprise.org 18 Nov '08
18 Nov '08
Author: chatellier
Date: 2008-11-18 14:11:07 +0000 (Tue, 18 Nov 2008)
New Revision: 1230
Added:
topia/trunk/topia-persistence/
topia/trunk/topia-persistence/LICENSE.txt
topia/trunk/topia-persistence/pom.xml
topia/trunk/topia-persistence/src/
topia/trunk/topia-persistence/src/main/
topia/trunk/topia-persistence/src/main/java/
topia/trunk/topia-persistence/src/main/java/org/
topia/trunk/topia-persistence/src/main/java/org/codelutin/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContext.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContextFactory.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaException.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaNotFoundException.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaRuntimeException.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaVetoException.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/package.html
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/SearchFields.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityAbstract.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/flatfile/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/
topia/trunk/topia-persistence/src/main/java/topia/
topia/trunk/topia-persistence/src/main/resources/
topia/trunk/topia-persistence/src/site/
topia/trunk/topia-persistence/src/test/
topia/trunk/topia-persistence/src/test/java/
topia/trunk/topia-persistence/src/test/java/org/
topia/trunk/topia-persistence/src/test/java/org/codelutin/
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/
topia/trunk/topia-persistence/src/test/java/topia/
topia/trunk/topia-persistence/src/test/resources/
topia/trunk/topia-persistence/src/test/resources/log4j.properties
topia/trunk/topia-soa/
topia/trunk/topia-soa/LICENSE.txt
topia/trunk/topia-soa/TODO
topia/trunk/topia-soa/pom.xml
topia/trunk/topia-soa/src/
topia/trunk/topia-soa/src/main/
topia/trunk/topia-soa/src/main/java/
topia/trunk/topia-soa/src/main/java/org/
topia/trunk/topia-soa/src/main/java/org/codelutin/
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/Protocol.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaProxy.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceProvider.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServer.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/package.html
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/
topia/trunk/topia-soa/src/main/resources/
topia/trunk/topia-soa/src/test/
topia/trunk/topia-soa/src/test/java/
topia/trunk/topia-soa/src/test/java/org/
topia/trunk/topia-soa/src/test/java/org/codelutin/
topia/trunk/topia-soa/src/test/java/org/codelutin/topia/
topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/
topia/trunk/topia-soa/src/test/log4j.properties
topia/trunk/topia-soa/src/test/resources/
topia/trunk/topia-soa/src/test/resources/TopiaApplicationServices.properties
topia/trunk/topia-ui/
topia/trunk/topia-ui/LICENSE.txt
topia/trunk/topia-ui/pom.xml
topia/trunk/topia-ui/src/
topia/trunk/topia-ui/src/main/
topia/trunk/topia-ui/src/main/java/
topia/trunk/topia-ui/src/main/java/org/
topia/trunk/topia-ui/src/main/java/org/codelutin/
topia/trunk/topia-ui/src/main/java/org/codelutin/topia/
topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/
topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java
topia/trunk/topia-ui/src/main/resources/
topia/trunk/topia-ui/src/test/
topia/trunk/topia-ui/src/test/java/
topia/trunk/topia-ui/src/test/resources/
topia/trunk/topia-ui/src/test/resources/log4j.properties
Removed:
topia/trunk/TODO
topia/trunk/src/
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java
topia/trunk/topia-persistence/src/main/java/topia/TopiaContext.java
topia/trunk/topia-persistence/src/main/java/topia/TopiaContextFactory.java
topia/trunk/topia-persistence/src/main/java/topia/TopiaException.java
topia/trunk/topia-persistence/src/main/java/topia/TopiaNotFoundException.java
topia/trunk/topia-persistence/src/main/java/topia/TopiaRuntimeException.java
topia/trunk/topia-persistence/src/main/java/topia/TopiaVetoException.java
topia/trunk/topia-persistence/src/main/java/topia/event/
topia/trunk/topia-persistence/src/main/java/topia/framework/
topia/trunk/topia-persistence/src/main/java/topia/generator/
topia/trunk/topia-persistence/src/main/java/topia/package.html
topia/trunk/topia-persistence/src/main/java/topia/persistence/SearchFields.java
topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAO.java
topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAOAbstract.java
topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAODelegator.java
topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntity.java
topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntityAbstract.java
topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntityEnumEntry.java
topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaId.java
topia/trunk/topia-persistence/src/main/java/topia/persistence/flatfile/
topia/trunk/topia-persistence/src/main/java/topia/persistence/hibernate/
topia/trunk/topia-persistence/src/main/java/topia/service/Protocol.java
topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationService.java
topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationServiceAbstract.java
topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationServiceFactory.java
topia/trunk/topia-persistence/src/main/java/topia/service/TopiaProxy.java
topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceProvider.java
topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceServer.java
topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceServerAbstract.java
topia/trunk/topia-persistence/src/main/java/topia/service/clients/
topia/trunk/topia-persistence/src/main/java/topia/service/package.html
topia/trunk/topia-persistence/src/main/java/topia/service/servers/
topia/trunk/topia-persistence/src/test/java/topia/Person.hbm.xml
topia/trunk/topia-persistence/src/test/java/topia/Person.java
topia/trunk/topia-persistence/src/test/java/topia/PersonAbstract.java
topia/trunk/topia-persistence/src/test/java/topia/PersonImpl.java
topia/trunk/topia-persistence/src/test/java/topia/TopiaContextTest.java
topia/trunk/topia-persistence/src/test/java/topia/framework/
topia/trunk/topia-persistence/src/test/java/topia/service/
Modified:
topia/trunk/changelog
topia/trunk/pom.xml
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaContextEvent.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaContextListener.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntitiesEvent.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityEvent.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityListener.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityVetoable.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionEvent.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionListener.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionVetoable.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/EntityState.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImplementor.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaFiresSupport.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaService.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaUtil.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/DAOAbstractGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaRelationValidator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/EntityStateTest.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/RMIProxy.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/SOAPProxy.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/XMLRPCProxy.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RMIServer.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RemoteClassLoader.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/SOAPServer.java
topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/XMLRPCServer.java
topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestService.java
topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceImpl.java
topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceServer.java
topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceTestCase.java
Log:
Modularisation de topia
Deleted: topia/trunk/TODO
===================================================================
--- topia/trunk/TODO 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/TODO 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,13 +0,0 @@
-Framework WS
-------------
-Le framework Apache CFX est le successeur du framework Codehaus Xfire
-actuellement utilisé.
-Il inclut aussi une partie du code de ObjectWeb Celtix.
-
-Il ne résout pas (encore) le problème de cycle, mais est déjà plus explicite
-sur les messages d'erreurs.
-Il gère aussi plus de protocoles que xfire.
-
-cfx : http://incubator.apache.org/cxf/
-xfire : http://xfire.codehaus.org/
-celtix : http://celtix.objectweb.org/
\ No newline at end of file
Modified: topia/trunk/changelog
===================================================================
--- topia/trunk/changelog 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/changelog 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,6 +1,10 @@
+ver-2-1 chatellier 20081118
+ * 20081118 Switch to multi module project
+
ver-2-0-29 chatellier 20081117
* 20081117 [chemit] improve EntityEnum
* 20081117 [chemit] add method findAllWithOrder in DAO to make have sorted lists
+
ver-2-0-28 chatellier 20081114
* 20081113 [chorlet] add support for lazy loading on attribute with 0..* multiplicity
* 20081113 [chorlet] fix bug on bidirectional association by adding inverse attribute in the one side of two hibernate mapping files
Modified: topia/trunk/pom.xml
===================================================================
--- topia/trunk/pom.xml 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/pom.xml 2008-11-18 14:11:07 UTC (rev 1230)
@@ -6,137 +6,76 @@
<!-- ************************************************************* -->
<!-- *** POM Relationships *************************************** -->
<!-- ************************************************************* -->
-
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinproject</artifactId>
- <version>3.0</version>
+ <version>3.1</version>
</parent>
<artifactId>topia</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
- <dependencies>
- <!--Compile-->
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinutil</artifactId>
- <version>0.31</version>
- <scope>compile</scope>
- </dependency>
+ <modules>
+ <module>topia-persistence</module>
+ <module>topia-soa</module>
+ <module>topia-ui</module>
+ </modules>
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutingenerator</artifactId>
- <version>0.61</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.2.1</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>3.3.1.GA</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.4.GA</version>
- </dependency>
-
- <!--Test-->
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>8.2-507.jdbc4</version>
- <scope>test</scope>
- </dependency>
-
- <!-- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.5</version>
- <scope>test</scope>
- </dependency> -->
-
- <!-- Dependencies for services -->
- <dependency>
- <groupId>org.apache.xmlrpc</groupId>
- <artifactId>xmlrpc-server</artifactId>
- <version>3.1</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.xmlrpc</groupId>
- <artifactId>xmlrpc-client</artifactId>
- <version>3.1</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- <scope>runtime</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.xfire</groupId>
- <artifactId>xfire-java5</artifactId>
- <version>1.2.6</version>
- <exclusions>
- <!-- Fix org.apache.ant conflict) -->
- <exclusion>
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!-- branch 5.1 : ne fonctionne pas en 6+ -->
- <dependency>
- <groupId>jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>5.1.10</version>
- </dependency>
-
- <!-- Dependencies for class generation -->
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>1.5.3</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry-core</artifactId>
- <version>5.0.7</version>
- <scope>compile</scope>
- </dependency>
-
- <!--BD H2 pour le test-->
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.0.79</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ <version>0.62-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ <version>0.31</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ <version>0.16</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <!-- You might change defaut directories -->
+ <!-- srcDir>${basedir}/src/main/java</srcDir>
+ <destDir>${basedir}/target/processed-sources/java</destDir-->
+ <addCompileDirectory>true</addCompileDirectory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ <filters>
+ org.codelutin.processor.filters.GeneratorTemplatesFilter,
+ org.codelutin.processor.filters.ActiveLogsCodeFilter
+ </filters>
+ <verbose>${maven.verbose}</verbose>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
-
<name>ToPIA - Tools for Portable and Independent Architecture</name>
- <version>2.0.30-SNAPSHOT</version>
<description>Framework de persistance et de distribution d'application.</description>
<inceptionYear>2004</inceptionYear>
@@ -144,7 +83,7 @@
<!-- *** Build Settings ****************************************** -->
<!-- ************************************************************* -->
- <packaging>jar</packaging>
+ <packaging>pom</packaging>
<properties>
<!-- id du projet du labs -->
@@ -152,49 +91,11 @@
<!-- nom du projet sur le labs -->
<labs.project>topia</labs.project>
-
- <!-- Test FIXME : -->
+
+ <!-- Don't test for now -->
<maven.test.skip>true</maven.test.skip>
</properties>
- <build>
- <plugins>
- <!--Attaching processor plugin to the Build Lifecycle-->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- <version>0.16</version>
- <executions>
- <execution>
- <phase>generate-sources</phase>
- <goals>
- <goal>process</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <!-- You might change defaut directories -->
- <!-- srcDir>${basedir}/src/main/java</srcDir>
- <destDir>${basedir}/target/processed-sources/java</destDir-->
- <addCompileDirectory>true</addCompileDirectory>
- <includes>
- <include>**/*.java</include>
- </includes>
- <filters>
- org.codelutin.processor.filters.GeneratorTemplatesFilter,
- org.codelutin.processor.filters.ActiveLogsCodeFilter
- </filters>
- <verbose>${maven.verbose}</verbose>
- </configuration>
- </plugin>
-
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- </plugin>
-
- </plugins>
- </build>
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Property changes on: topia/trunk/topia-persistence
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.classpath
.project
Added: topia/trunk/topia-persistence/LICENSE.txt
===================================================================
--- topia/trunk/topia-persistence/LICENSE.txt (rev 0)
+++ topia/trunk/topia-persistence/LICENSE.txt 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Added: topia/trunk/topia-persistence/pom.xml
===================================================================
--- topia/trunk/topia-persistence/pom.xml (rev 0)
+++ topia/trunk/topia-persistence/pom.xml 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.codelutin</groupId>
+ <artifactId>topia</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.3.1.GA</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.4.GA</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- BD H2 for testing -->
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.1.103</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>ToPIA - Persistence</name>
+ <description>Hibernate based persistence module</description>
+ <inceptionYear>2004</inceptionYear>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
+ </scm>
+
+</project>
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContext.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/TopiaContext.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContext.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContext.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,258 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaContext.java
+ *
+ * Created: 3 janv. 2006 21:18:34
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia;
+
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.List;
+
+import org.codelutin.topia.event.TopiaContextListener;
+import org.codelutin.topia.event.TopiaEntitiesVetoable;
+import org.codelutin.topia.event.TopiaEntityListener;
+import org.codelutin.topia.event.TopiaEntityVetoable;
+import org.codelutin.topia.event.TopiaTransactionListener;
+import org.codelutin.topia.event.TopiaTransactionVetoable;
+import org.codelutin.topia.framework.TopiaService;
+import org.codelutin.topia.persistence.TopiaEntity;
+
+/**
+ * @author poussin
+ *
+ */
+
+public interface TopiaContext {
+
+ /* Adders */
+ public void addTopiaEntityListener(TopiaEntityListener listener);
+
+ public void addTopiaEntityListener(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener);
+
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ public void addTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable);
+
+ public void addTopiaTransactionListener(TopiaTransactionListener listener);
+
+ public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
+
+ public void addPropertyChangeListener(PropertyChangeListener listener);
+
+ public void addTopiaContextListener(TopiaContextListener listener);
+
+ public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
+
+ /* Removers */
+ public void removeTopiaEntityListener(TopiaEntityListener listener);
+
+ public void removeTopiaEntityListener(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener);
+
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ public void removeTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable);
+
+ public void removeTopiaTransactionListener(TopiaTransactionListener listener);
+
+ public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
+
+ public void removePropertyChangeListener(PropertyChangeListener listener);
+
+ public void removeTopiaContextListener(TopiaContextListener listener);
+
+ public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
+
+ /**
+ * Return true if specific service is available
+ * @param <E>
+ * @param interfaceService
+ * @return
+ */
+ public <E extends TopiaService> boolean serviceEnabled(
+ Class<E> interfaceService);
+
+ /**
+ * Return the service
+ * @param <E>
+ * @param interfaceService
+ * @return
+ * @throws TopiaNotFoundException if service is can't be retrieved
+ */
+ public <E extends TopiaService> E getService(Class<E> interfaceService)
+ throws TopiaNotFoundException;
+
+ /**
+ * Permet de créer le schema de la base de données
+ * @throws TopiaException if any exception
+ */
+ public void createSchema() throws TopiaException;
+
+ /**
+ * Permet de mettre à jour le schema de la base de données
+ * @throws TopiaException if any exception
+ */
+ public void updateSchema() throws TopiaException;
+
+ public TopiaContext beginTransaction() throws TopiaException;
+
+ /**
+ * applique les modifications apporté a ce context sur la base de données.
+ * @throws TopiaException if any exception
+ */
+ public void commitTransaction() throws TopiaException;
+
+ /**
+ * annule les modifications apporté a ce context
+ * @throws TopiaException if any exception
+ */
+ public void rollbackTransaction() throws TopiaException;
+
+ /**
+ * Permet de rechercher un entite directement par son TopiaId
+ *
+ * @param topiaId l'id de l'entite recherche
+ * @return l'entite trouvee (ou null si non trouve)
+ * @throws TopiaException if any exception
+ */
+ public TopiaEntity findByTopiaId(String topiaId) throws TopiaException;
+
+ /**
+ * Permet de faire une requete HQL hibernate directement sur la base
+ * @param hql la requete a faire
+ * @param args les arguments de la requete
+ * @return La liste des resultats
+ * @throws TopiaException si une erreur survient durant la requete
+ */
+ public List find(String hql, Object... args) throws TopiaException;
+
+ /**
+ * Permet de faire une requete HQL hibernate directement sur la base
+ * en precisant la fenetre des elements a remonter avec les parametres <code>startIndex</code>
+ * et <code>endIndex</code>.
+ * @param hql la requete a faire
+ * @param startIndex la position du premier element a remonter
+ * @param endIndex la position du dernier element a remonter
+ * @param args les arguments de la requete
+ * @return La liste des resultats
+ * @throws TopiaException si une erreur survient durant la requete
+ */
+ public List find(String hql, int startIndex, int endIndex, Object... args)
+ throws TopiaException;
+
+ /**
+ * Execute HQL operation on data (Update, Delete)
+ * @param hql la requete a faire
+ * @param args les arguments de la requete
+ * @return The number of entities updated or deleted.
+ * @throws TopiaException if any exception
+ */
+ public int execute(String hql, Object... args) throws TopiaException;
+
+ /**
+ * Permet d'ajouter dans le TopiaContext une TopiaEntity créé par un
+ * autre context.
+ * @param e l'entity a ajouter
+ * @throws TopiaException if any exception
+ */
+ public void add(TopiaEntity e) throws TopiaException;
+
+ /**
+ * Permet d'importer des données en XML
+ * @param xml le flux XML
+ * @throws TopiaException si une erreur survient durant l'import
+ */
+ public void importXML(Reader xml) throws TopiaException;
+
+ /**
+ * Permet d'exporter certaines données en XML
+ * @param xml le flux XML dans lequel il faut ecrire
+ * @param entityAndCondition paramètre qui vont par deux, qui represente
+ * la classe de l'entity a exporter et la condition where que doit
+ * respecter l'objet pour etre exporter
+ * (entityClass, condition)
+ * @throws TopiaException si une erreur survient durant l'export
+ */
+ public void exportXML(Writer xml, Object... entityAndCondition)
+ throws TopiaException;
+
+ /**
+ * Sauve la base de données dans un format natif a la base, la
+ * representation n'est pas portable d'une base a l'autre. Cette methode
+ * ne doit être utilisé que pour un stockage temporaire utile à une
+ * application
+ *
+ * @param file le nom du fichier ou stocker les informations
+ * @param compress si vrai compress le fichier avec gzip
+ *
+ * @throws TopiaException if any exception
+ */
+ public void backup(File file, boolean compress) throws TopiaException;
+
+ /**
+ * Supprime toutes les tables et autres elements de la database.
+ *
+ * @param dropDatabase si vrai alors supprime aussi la base de données
+ * si la base utilise des fichiers les fichiers seront supprimé (ex: h2)
+ * ou sera fait sur la base (pastgresql)
+ * @throws TopiaException if any exception
+ */
+ public void clear(boolean dropDatabase) throws TopiaException;
+
+ /**
+ * l'inverse de la methode {@link #backup(File,boolean)}
+ *
+ * @param file le fichier ou prendre les informations, il peut-etre
+ * compressé avec gzip ou non.
+ *
+ * @throws TopiaException if any exception
+ */
+ public void restore(File file) throws TopiaException;
+
+ /**
+ * Ferme le contexte
+ * @throws TopiaException if any exception
+ */
+ public void closeContext() throws TopiaException;
+
+ /**
+ * Indique si le contexte a ete ferme
+ * @return <code>true</code> si le context est ferme, <code>false</code> autrement
+ */
+ public boolean isClosed();
+
+} //TopiaContext
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContext.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContextFactory.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/TopiaContextFactory.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContextFactory.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContextFactory.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,124 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaContextFactory.java
+ *
+ * Created: 3 janv. 2006 21:19:37
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Map.Entry;
+
+import org.apache.commons.collections.map.AbstractReferenceMap;
+import org.apache.commons.collections.map.ReferenceMap;
+import org.codelutin.topia.framework.TopiaContextImpl;
+import org.codelutin.topia.framework.TopiaUtil;
+
+/**
+ * @author poussin
+ *
+ */
+
+public class TopiaContextFactory {
+
+ static final private String DEFAULT_CONFIG_PROPERTIES = "TopiaContextImpl.properties";
+
+ /**
+ * Cache contenant tous les contexts deja créé.
+ */
+ @SuppressWarnings("unchecked")
+ static protected Map<Properties, TopiaContextImpl> contextCache = new ReferenceMap(
+ AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
+
+ /**
+ * Permet de connaitre la liste des contexts encore en memoire, utile
+ * pour du debuggage
+ * @return la liste des urls de connexion
+ */
+ static public List<String> getContextOpened() {
+ List<String> result = new ArrayList<String>();
+ for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
+ if (e.getValue() != null) {
+ result.add(e.getKey().getProperty("hibernate.connection.url"));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Used when TopiaContext root is closed
+ * @param context closed
+ */
+ static public void removeContext(TopiaContext context) {
+ Properties key = null;
+ for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
+ if (e.getValue() == context) {
+ key = e.getKey();
+ break;
+ }
+ }
+ if (key != null) {
+ contextCache.remove(key);
+ }
+ }
+
+ /**
+ * Utilise par defaut le fichier de propriete TopiaContextImpl.properties
+ *
+ * @return
+ * @throws TopiaNotFoundException Si le fichier de configuration par defaut
+ * n'est pas retrouvé.
+ */
+ static public TopiaContext getContext() throws TopiaNotFoundException {
+ Properties config = TopiaUtil.getProperties(DEFAULT_CONFIG_PROPERTIES);
+ TopiaContext result = getContext(config);
+ return result;
+ }
+
+ /**
+ * Methode static permettant de recuperer un context. Si on donne plusieurs
+ * fois le meme objet config, on obtient la meme instance de TopiaContextImpl.
+ * Si le context qui devrait etre retourné est ferme, alors un nouveau est
+ * creer et retourné
+ *
+ * @param config
+ * @return Un TopiaContext ouvert
+ * @throws TopiaNotFoundException
+ */
+ static public TopiaContext getContext(Properties config)
+ throws TopiaNotFoundException {
+ TopiaContextImpl result = contextCache.get(config);
+ if (result == null || result.isClosed()) {
+ result = new TopiaContextImpl(config);
+ contextCache.put((Properties) config.clone(), result);
+ }
+ return result;
+ }
+
+}
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaContextFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaException.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/TopiaException.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaException.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaException.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,70 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaException.java
+ *
+ * Created: 23 déc. 2005 23:03:36
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia;
+
+/**
+ * @author poussin
+ *
+ */
+public class TopiaException extends Exception {
+
+ /** */
+ private static final long serialVersionUID = -1251439453383121393L;
+
+ /**
+ *
+ */
+ public TopiaException() {
+ super();
+ }
+
+ /**
+ * @param message
+ */
+ public TopiaException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public TopiaException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param cause
+ */
+ public TopiaException(Throwable cause) {
+ super(cause);
+ }
+
+}
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaException.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaNotFoundException.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/TopiaNotFoundException.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaNotFoundException.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaNotFoundException.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,69 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaNotFoundException.java
+ *
+ * Created: 23 déc. 2005 23:04:28
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia;
+
+/**
+ * @author poussin
+ *
+ */
+public class TopiaNotFoundException extends TopiaException {
+
+ /** */
+ private static final long serialVersionUID = -8206486077608923797L;
+
+ /**
+ *
+ */
+ public TopiaNotFoundException() {
+ super();
+ }
+
+ /**
+ * @param message
+ */
+ public TopiaNotFoundException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public TopiaNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param cause
+ */
+ public TopiaNotFoundException(Throwable cause) {
+ super(cause);
+ }
+}
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaNotFoundException.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaRuntimeException.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/TopiaRuntimeException.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaRuntimeException.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaRuntimeException.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,65 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia;
+
+/**
+ * TopiaRuntimeException
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class TopiaRuntimeException extends RuntimeException {
+
+ /** Version UID */
+ private static final long serialVersionUID = 4706337137948838375L;
+
+ /**
+ * Constructor
+ */
+ public TopiaRuntimeException() {
+ }
+
+ /**
+ * Constructor
+ * @param message message
+ */
+ public TopiaRuntimeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructor
+ * @param cause cause
+ */
+ public TopiaRuntimeException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructor
+ * @param message message
+ * @param cause cause
+ */
+ public TopiaRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaRuntimeException.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaVetoException.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/TopiaVetoException.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaVetoException.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaVetoException.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,71 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaVetoException.java
+ *
+ * Created: 5 janv. 2006 00:47:51
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia;
+
+/**
+ * @author poussin
+ *
+ */
+
+public class TopiaVetoException extends RuntimeException {
+
+ /** */
+ private static final long serialVersionUID = 6809613247516488399L;
+
+ /**
+ *
+ */
+ public TopiaVetoException() {
+ super();
+ }
+
+ /**
+ * @param message
+ */
+ public TopiaVetoException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public TopiaVetoException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param cause
+ */
+ public TopiaVetoException(Throwable cause) {
+ super(cause);
+ }
+
+}
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/TopiaVetoException.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/event)
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaContextEvent.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaContextEvent.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaContextEvent.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -34,7 +34,7 @@
/** Version UID */
private static final long serialVersionUID = 560256125962144181L;
-
+
/**
* Constructor
* @param source
@@ -42,12 +42,12 @@
public TopiaContextEvent(Object source) {
super(source);
}
-
+
/**
* Get source
*/
public TopiaContext getSource() {
- return (TopiaContext)source;
+ return (TopiaContext) source;
}
-
+
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaContextListener.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaContextListener.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaContextListener.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -40,31 +40,31 @@
* @param event evet
*/
public void preCreateSchema(TopiaContextEvent event);
-
+
/**
* Called after createSchema call
* @param event event
*/
public void postCreateSchema(TopiaContextEvent event);
-
+
/**
* Called before updateSchema call
* @param event event
*/
public void preUpdateSchema(TopiaContextEvent event);
-
+
/**
* Called after updateSchema call
* @param event event
*/
public void postUpdateSchema(TopiaContextEvent event);
-
+
/**
* Called after updateSchema call
* @param event event
*/
public void preRestoreSchema(TopiaContextEvent event);
-
+
/**
* Called after updateSchema call
* @param event event
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntitiesEvent.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaEntitiesEvent.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntitiesEvent.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -15,7 +15,7 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
- package org.codelutin.topia.event;
+package org.codelutin.topia.event;
import java.util.EventObject;
import java.util.List;
@@ -23,12 +23,12 @@
import org.codelutin.topia.TopiaContext;
import org.codelutin.topia.persistence.TopiaEntity;
-public class TopiaEntitiesEvent <E extends TopiaEntity> extends EventObject {
+public class TopiaEntitiesEvent<E extends TopiaEntity> extends EventObject {
private static final long serialVersionUID = 1L;
private List<E> entities;
-
+
public TopiaEntitiesEvent(Object source, List<E> entities) {
super(source);
this.entities = entities;
@@ -37,7 +37,7 @@
public List<E> getEntities() {
return entities;
}
-
+
public TopiaContext getSource() {
return (TopiaContext) super.getSource();
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityEvent.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaEntityEvent.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityEvent.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -15,7 +15,7 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
- package org.codelutin.topia.event;
+package org.codelutin.topia.event;
import java.util.EventObject;
@@ -28,7 +28,7 @@
private TopiaEntity entity;
private Object[] state;
-
+
public TopiaEntityEvent(Object source, TopiaEntity entity, Object[] state) {
super(source);
this.entity = entity;
@@ -38,7 +38,7 @@
public TopiaEntity getEntity() {
return entity;
}
-
+
public TopiaContext getSource() {
return (TopiaContext) super.getSource();
}
@@ -46,6 +46,5 @@
public Object[] getState() {
return state;
}
-
-}
+}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityListener.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaEntityListener.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityListener.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -22,8 +22,11 @@
public interface TopiaEntityListener extends EventListener {
public void create(TopiaEntityEvent event);
+
public void load(TopiaEntityEvent event);
+
public void update(TopiaEntityEvent event);
+
public void delete(TopiaEntityEvent event);
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityVetoable.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaEntityVetoable.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaEntityVetoable.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -22,8 +22,11 @@
public interface TopiaEntityVetoable extends EventListener {
public void create(TopiaEntityEvent event);
+
public void load(TopiaEntityEvent event);
+
public void update(TopiaEntityEvent event);
+
public void delete(TopiaEntityEvent event);
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionEvent.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaTransactionEvent.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionEvent.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -31,47 +31,52 @@
private static final long serialVersionUID = 1L;
private Map<TopiaEntity, EntityState> entities = new IdentityMap();
-
+
public TopiaTransactionEvent(TopiaContext source) {
- super(source);
+ super(source);
}
- public TopiaTransactionEvent(TopiaContext source, Map<TopiaEntity, EntityState> entities) {
+ public TopiaTransactionEvent(TopiaContext source,
+ Map<TopiaEntity, EntityState> entities) {
this(source);
this.entities.putAll(entities);
}
-
+
public Set<TopiaEntity> getEntities() {
return entities.keySet();
}
-
+
public boolean isLoad(TopiaEntity entity) {
EntityState state = entities.get(entity);
- return state != null && state.isLoad();
+ return state != null && state.isLoad();
}
+
public boolean isRead(TopiaEntity entity) {
EntityState state = entities.get(entity);
- return state != null && state.isRead();
+ return state != null && state.isRead();
}
+
public boolean isCreate(TopiaEntity entity) {
EntityState state = entities.get(entity);
- return state != null && state.isCreate();
+ return state != null && state.isCreate();
}
+
public boolean isUpdate(TopiaEntity entity) {
EntityState state = entities.get(entity);
- return state != null && state.isUpdate();
+ return state != null && state.isUpdate();
}
+
public boolean isDelete(TopiaEntity entity) {
EntityState state = entities.get(entity);
- return state != null && state.isDelete();
+ return state != null && state.isDelete();
}
public boolean isModification(TopiaEntity entity) {
EntityState state = entities.get(entity);
- return state != null &&
- (state.isCreate() || state.isUpdate() || state.isDelete());
+ return state != null
+ && (state.isCreate() || state.isUpdate() || state.isDelete());
}
-
+
public TopiaContext getTopiaContext() {
return (TopiaContext) super.getSource();
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionListener.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaTransactionListener.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionListener.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -20,8 +20,9 @@
import java.util.EventListener;
public interface TopiaTransactionListener extends EventListener {
-
+
public void commit(TopiaTransactionEvent event);
+
public void rollback(TopiaTransactionEvent event);
-
+
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionVetoable.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/event/TopiaTransactionVetoable.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/event/TopiaTransactionVetoable.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -20,7 +20,7 @@
import java.util.EventListener;
public interface TopiaTransactionVetoable extends EventListener {
-
+
public void beginTransaction(TopiaTransactionEvent event);
-
+
}
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/framework)
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/EntityState.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/framework/EntityState.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/EntityState.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -29,7 +29,6 @@
package org.codelutin.topia.framework;
-
/**
* Used to know the state of entity during transaction
*
@@ -37,46 +36,52 @@
*/
public class EntityState {
- final static int NULL = 0;
- final static int LOAD = 1;
- final static int READ = 2;
- final static int CREATE = 4;
- final static int UPDATE = 8;
- final static int DELETE = 16;
+ final static int NULL = 0;
+ final static int LOAD = 1;
+ final static int READ = 2;
+ final static int CREATE = 4;
+ final static int UPDATE = 8;
+ final static int DELETE = 16;
protected int state = NULL;
-
- public void addLoad(){
+
+ public void addLoad() {
state |= LOAD;
}
- public void addRead(){
+
+ public void addRead() {
state |= READ;
}
- public void addCreate(){
+
+ public void addCreate() {
state |= CREATE;
}
- public void addUpdate(){
+
+ public void addUpdate() {
state |= UPDATE;
}
- public void addDelete(){
+
+ public void addDelete() {
state |= DELETE;
}
-
+
public boolean isLoad() {
- return (state & LOAD) == LOAD;
+ return (state & LOAD) == LOAD;
}
+
public boolean isRead() {
- return (state & READ) == READ;
+ return (state & READ) == READ;
}
+
public boolean isCreate() {
- return (state & CREATE) == CREATE;
+ return (state & CREATE) == CREATE;
}
+
public boolean isUpdate() {
- return (state & UPDATE) == UPDATE;
+ return (state & UPDATE) == UPDATE;
}
+
public boolean isDelete() {
- return (state & DELETE) == DELETE;
+ return (state & DELETE) == DELETE;
}
}
-
-
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImpl.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -145,7 +145,7 @@
* L'objet configuration utilisé pour la creation de la factory hibernate
*/
protected Configuration hibernateConfiguration = null;
-
+
/**
* la factory permettant de recuperer la session hibernate. Seul les
* TopiaContextImpl initiaux contiennent un hibernateFactory
@@ -176,17 +176,18 @@
* Set des sous context creer avec un beginTransaction et donc sur lequel
* nous sommes listener
*/
- protected Set<TopiaContextImplementor> childContext = MapBackedSet.decorate(new WeakHashMap<TopiaContextImplementor, Object>());
+ protected Set<TopiaContextImplementor> childContext = MapBackedSet
+ .decorate(new WeakHashMap<TopiaContextImplementor, Object>());
/** key: service name; value: service instance */
protected Map<String, TopiaService> services = null;
-
+
/** */
protected TopiaFiresSupport firesSupport = new TopiaFiresSupport();
-
+
/** Liste des classes perssitance */
protected List<Class> persistenceClasses = new ArrayList<Class>();
-
+
/**
* constructeur utilisé par la factory pour creer les contexts initiaux
*
@@ -200,11 +201,12 @@
getHibernateConfiguration(); // force mapping loading
postInitServices(services);
}
-
+
protected Map<String, TopiaService> loadServices(Properties config) {
Map<String, TopiaService> result = new HashMap<String, TopiaService>();
// recherche des services present dans la config
- for (Enumeration<String> e=(Enumeration<String>)config.propertyNames(); e.hasMoreElements();) {
+ for (Enumeration<String> e = (Enumeration<String>) config
+ .propertyNames(); e.hasMoreElements();) {
String key = e.nextElement();
if (key.matches("^topia\\.service\\.\\w+$")) {
String classService = config.getProperty(key);
@@ -214,95 +216,112 @@
TopiaService service = (TopiaService) newInstance;
if (key.equals("topia.service." + service.getServiceName())) {
result.put(service.getServiceName(), service);
- log.info("Service " + key + " loaded by " + classService);
+ log.info("Service " + key + " loaded by "
+ + classService);
} else {
- log.warn("Service config key doesn't match service name, disable it: " + key + " != " + service.getServiceName());
+ log
+ .warn("Service config key doesn't match service name, disable it: "
+ + key
+ + " != "
+ + service.getServiceName());
}
} catch (Throwable eee) {
- if(log.isErrorEnabled()) {
- log.error("Service class unknow for " + key + ": " + classService);
+ if (log.isErrorEnabled()) {
+ log.error("Service class unknow for " + key + ": "
+ + classService);
}
- if(log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
log.debug(eee);
}
}
}
- }
+ }
return result;
}
-
+
protected void preInitServices(Map<String, TopiaService> services) {
- for (Iterator<TopiaService> i=services.values().iterator(); i.hasNext();) {
+ for (Iterator<TopiaService> i = services.values().iterator(); i
+ .hasNext();) {
TopiaService service = i.next();
- if(!service.preInit(this)) {
- log.warn("Can't preInit service disable it: " + service.getServiceName());
+ if (!service.preInit(this)) {
+ log.warn("Can't preInit service disable it: "
+ + service.getServiceName());
}
}
}
protected void postInitServices(Map<String, TopiaService> services) {
- for (Iterator<TopiaService> i=services.values().iterator(); i.hasNext();) {
+ for (Iterator<TopiaService> i = services.values().iterator(); i
+ .hasNext();) {
TopiaService service = i.next();
- if(!service.postInit(this)) {
- log.warn("Can't postInit service disable it: " + service.getServiceName());
+ if (!service.postInit(this)) {
+ log.warn("Can't postInit service disable it: "
+ + service.getServiceName());
}
}
}
public Map<String, TopiaService> getServices() {
TopiaContextImplementor parent = getParentContext();
- if(parent != null) {
+ if (parent != null) {
return parent.getServices();
} else {
return services;
}
}
-
+
protected boolean serviceEnabled(String name) {
boolean result = getServices().containsKey(name);
return result;
}
-
+
protected TopiaService getService(String name) {
TopiaService result = getServices().get(name);
return result;
}
- public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService) {
+ public <E extends TopiaService> boolean serviceEnabled(
+ Class<E> interfaceService) {
boolean result = false;
try {
Field f = interfaceService.getField("SERVICE_NAME");
- String name = (String)f.get(null);
+ String name = (String) f.get(null);
result = serviceEnabled(name);
} catch (Exception eee) {
if (log.isWarnEnabled()) {
- log.warn("Can't get service name for: " + interfaceService, eee);
+ log
+ .warn(
+ "Can't get service name for: "
+ + interfaceService, eee);
}
}
return result;
}
-
- /**
- * Take one service, this service must be valid service interface with
- * public static final SERVICE_NAME declaration.
- * @param <E>
- * @throws TopiaNotFoundException
- */
- public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException {
+
+ /**
+ * Take one service, this service must be valid service interface with
+ * public static final SERVICE_NAME declaration.
+ * @param <E>
+ * @throws TopiaNotFoundException
+ */
+ public <E extends TopiaService> E getService(Class<E> interfaceService)
+ throws TopiaNotFoundException {
try {
Field f = interfaceService.getField("SERVICE_NAME");
- String name = (String)f.get(null);
- E result = (E)getService(name);
+ String name = (String) f.get(null);
+ E result = (E) getService(name);
if (result == null) {
- throw new TopiaNotFoundException("Service not available: " + interfaceService);
+ throw new TopiaNotFoundException("Service not available: "
+ + interfaceService);
}
return result;
} catch (Exception eee) {
- throw new TopiaNotFoundException("Can't get service: " + interfaceService, eee);
+ throw new TopiaNotFoundException("Can't get service: "
+ + interfaceService, eee);
}
}
-
+
/* (non-Javadoc)
* @see org.codelutin.topia.framework.TopiaContextImplementor#getAllServices()
*/
@@ -310,7 +329,7 @@
Collection<TopiaService> result = getServices().values();
return result;
}
-
+
/**
* Constructeur utilisé par le beginTransaction pour créer le context fils.
*
@@ -330,7 +349,7 @@
protected void addChildContext(TopiaContextImplementor child) {
childContext.add(child);
}
-
+
public void removeChildContext(TopiaContextImplementor child) {
//On ne retire les fils que si ce contexte n'est pas deja ferme. Permet d'eviter les acces concurrentiels
if (!closed) {
@@ -382,13 +401,14 @@
showSchema = true;
}
getFiresSupport().firePreCreateSchema(this);
- new SchemaExport(getHibernateConfiguration()).create(showSchema, true);
+ new SchemaExport(getHibernateConfiguration()).create(showSchema,
+ true);
getFiresSupport().firePostCreateSchema(this);
} catch (HibernateException eee) {
throw new TopiaException("Can't create database schema", eee);
}
}
-
+
/* (non-Javadoc)
* @see org.codelutin.topia.TopiaContext#createSchema()
*/
@@ -399,13 +419,14 @@
showSchema = true;
}
getFiresSupport().firePreUpdateSchema(this);
- new SchemaUpdate(getHibernateConfiguration()).execute(showSchema, true);
+ new SchemaUpdate(getHibernateConfiguration()).execute(showSchema,
+ true);
getFiresSupport().firePostUpdateSchema(this);
} catch (HibernateException eee) {
throw new TopiaException("Can't create database schema", eee);
}
}
-
+
/*
* (non-Javadoc)
*
@@ -429,22 +450,25 @@
if (getParentContext() != null) {
hibernateFactory = getParentContext().getHibernateFactory();
} else {
- hibernateFactory = getHibernateConfiguration().buildSessionFactory();
+ hibernateFactory = getHibernateConfiguration()
+ .buildSessionFactory();
}
}
return hibernateFactory;
}
- public Configuration getHibernateConfiguration() throws TopiaNotFoundException {
+ public Configuration getHibernateConfiguration()
+ throws TopiaNotFoundException {
if (hibernateConfiguration == null) {
if (getParentContext() != null) {
- hibernateConfiguration = getParentContext().getHibernateConfiguration();
+ hibernateConfiguration = getParentContext()
+ .getHibernateConfiguration();
} else {
hibernateConfiguration = new Configuration();
// Ajout du listeners pour les events
- TopiaFiresSupport.TopiaHibernateEvent listener =
- new TopiaFiresSupport.TopiaHibernateEvent(this);
+ TopiaFiresSupport.TopiaHibernateEvent listener = new TopiaFiresSupport.TopiaHibernateEvent(
+ this);
PreInsertEventListener[] preInsertEventListeners = hibernateConfiguration
.getEventListeners().getPreInsertEventListeners();
@@ -480,23 +504,23 @@
postDeleteEventListeners = ArrayUtil.concatElems(
postDeleteEventListeners, listener);
- hibernateConfiguration.getEventListeners().setPreInsertEventListeners(
- preInsertEventListeners);
- hibernateConfiguration.getEventListeners().setPreLoadEventListeners(
- preLoadEventListeners);
- hibernateConfiguration.getEventListeners().setPreUpdateEventListeners(
- preUpdateEventListeners);
- hibernateConfiguration.getEventListeners().setPreDeleteEventListeners(
- preDeleteEventListeners);
+ hibernateConfiguration.getEventListeners()
+ .setPreInsertEventListeners(preInsertEventListeners);
+ hibernateConfiguration.getEventListeners()
+ .setPreLoadEventListeners(preLoadEventListeners);
+ hibernateConfiguration.getEventListeners()
+ .setPreUpdateEventListeners(preUpdateEventListeners);
+ hibernateConfiguration.getEventListeners()
+ .setPreDeleteEventListeners(preDeleteEventListeners);
- hibernateConfiguration.getEventListeners().setPostInsertEventListeners(
- postInsertEventListeners);
- hibernateConfiguration.getEventListeners().setPostLoadEventListeners(
- postLoadEventListeners);
- hibernateConfiguration.getEventListeners().setPostUpdateEventListeners(
- postUpdateEventListeners);
- hibernateConfiguration.getEventListeners().setPostDeleteEventListeners(
- postDeleteEventListeners);
+ hibernateConfiguration.getEventListeners()
+ .setPostInsertEventListeners(postInsertEventListeners);
+ hibernateConfiguration.getEventListeners()
+ .setPostLoadEventListeners(postLoadEventListeners);
+ hibernateConfiguration.getEventListeners()
+ .setPostUpdateEventListeners(postUpdateEventListeners);
+ hibernateConfiguration.getEventListeners()
+ .setPostDeleteEventListeners(postDeleteEventListeners);
// ajout des repertoires contenant les mappings hibernate
String[] dirs = getConfig().getProperty(
@@ -510,19 +534,20 @@
// ajout des classes dites persistentes
String listPersistenceClasses = getConfig().getProperty(
- TOPIA_PERSISTENCE_CLASSES, "");
-
+ TOPIA_PERSISTENCE_CLASSES, "");
+
for (TopiaService service : getAllServices()) {
- Class [] persistenceClasses = service.getPersistenceClasses();
-
+ Class[] persistenceClasses = service
+ .getPersistenceClasses();
+
// certains service n'ont pas de classe persistantes
- if(persistenceClasses!=null) {
+ if (persistenceClasses != null) {
for (Class clazz : persistenceClasses) {
hibernateConfiguration.addClass(clazz);
}
}
}
-
+
String[] classes = listPersistenceClasses.split(",");
for (String classname : classes) {
classname = classname.trim();
@@ -550,7 +575,7 @@
}
return hibernateConfiguration;
}
-
+
/*
* (non-Javadoc)
*
@@ -563,20 +588,24 @@
throw new IllegalArgumentException("null is not valid entity class");
}
if (getRootContext() == this) {
- throw new TopiaException("Vous êtes sur le root context vous" +
- " devez ouvrir une transaction pour pouvoir accèder" +
- " aux données");
+ throw new TopiaException("Vous êtes sur le root context vous"
+ + " devez ouvrir une transaction pour pouvoir accèder"
+ + " aux données");
}
- if (getHibernateFactory().getClassMetadata(entityClass) == null &&
- getHibernateFactory().getClassMetadata(entityClass.getName() + "Impl") == null &&
- getHibernateFactory().getClassMetadata(entityClass.getName() + "Abstract") == null) {
- log.info("Classes supportées par ce TopiaContext: " +
- getHibernateFactory().getAllClassMetadata().keySet());
- throw new TopiaException("La classe " + entityClass.getName() +
- " n'est pas supportée par ce TopiaContext. Vous avez sans" +
- " doute oublié d'ajouter son mapping");
+ if (getHibernateFactory().getClassMetadata(entityClass) == null
+ && getHibernateFactory().getClassMetadata(
+ entityClass.getName() + "Impl") == null
+ && getHibernateFactory().getClassMetadata(
+ entityClass.getName() + "Abstract") == null) {
+ log.info("Classes supportées par ce TopiaContext: "
+ + getHibernateFactory().getAllClassMetadata().keySet());
+ throw new TopiaException(
+ "La classe "
+ + entityClass.getName()
+ + " n'est pas supportée par ce TopiaContext. Vous avez sans"
+ + " doute oublié d'ajouter son mapping");
}
-
+
TopiaDAO<E> result = (TopiaDAO<E>) daoCache.get(entityClass);
if (result == null) {
// recherche du type de DAO a instancier pour cette entity
@@ -585,7 +614,7 @@
String daoClassname = getConfig().getProperty(
"topia.dao." + entityClass.getName(), defaultDAOClassname);
if ("hibernate".equals(daoClassname)) {
- // FIXME nom en dur ?
+ // FIXME nom en dur ?
daoClassname = "org.codelutin.topia.persistence.hibernate.TopiaDAOHibernate";
} else if ("flatfile".equals(daoClassname)) {
daoClassname = "org.codelutin.topia.persistence.flatfile.TopiaDAOFlatFile";
@@ -641,7 +670,7 @@
// on ne synchronise jamais les données avec la base tant que
// l'utilisateur n'a pas fait de commit du context
result.hibernate.setFlushMode(FlushMode.NEVER);
-
+
// 20060926 poussin ajouter pour voir si ca regle les problemes de deadlock h2
// Conclusion, il faut bien ouvrir une transaction maintenant, sinon
// lorsque l'on fait des acces a la base, une transaction par defaut est
@@ -652,9 +681,9 @@
getFiresSupport().fireOnBeginTransaction(result);
return result;
}
-
-// Transaction tx = null;
-
+
+ // Transaction tx = null;
+
/*
* (non-Javadoc)
*
@@ -671,21 +700,21 @@
dao.commitTransaction();
}
Transaction tx = hibernate.getTransaction();
-// Transaction tx = hibernate.beginTransaction();
+ // Transaction tx = hibernate.beginTransaction();
hibernate.flush();
tx.commit();
-
+
getFiresSupport().fireOnPostCommit(this);
TopiaContextImplementor parent = getParentContext();
- if(parent != null) {
+ if (parent != null) {
parent.getFiresSupport().fireOnPostCommit(this);
}
hibernate.beginTransaction();
// it's seem necessary to change session after commit
// NON, NON, NON, il ne faut surtout pas le faire, ca pose plein de probleme
-// hibernate = getHibernateFactory().openSession();
-// hibernate.setFlushMode(FlushMode.NEVER);
+ // hibernate = getHibernateFactory().openSession();
+ // hibernate.setFlushMode(FlushMode.NEVER);
} catch (Exception eee) {
throw new TopiaException("Error during commit", eee);
}
@@ -707,7 +736,7 @@
dao.rollbackTransaction();
}
Transaction tx = hibernate.getTransaction();
-// Transaction tx = hibernate.beginTransaction();
+ // Transaction tx = hibernate.beginTransaction();
hibernate.clear();
tx.rollback();
hibernate.close();
@@ -715,12 +744,12 @@
// otherwize there are many error during next Entity's modification
hibernate = getHibernateFactory().openSession();
hibernate.setFlushMode(FlushMode.NEVER);
-
+
hibernate.beginTransaction();
-
+
getFiresSupport().fireOnPostRollback(this);
TopiaContextImplementor parent = getParentContext();
- if(parent != null) {
+ if (parent != null) {
parent.getFiresSupport().fireOnPostRollback(this);
}
@@ -731,26 +760,27 @@
public void closeContext() throws TopiaException {
// 20060926 poussin: Si si on peut, ca ferme en fait tous les enfants et c tout
-// if (getRootContext() == this) {
-// throw new TopiaException(
-// "Vous ne pouvez pas fermer le root context");
-// }
-
+ // if (getRootContext() == this) {
+ // throw new TopiaException(
+ // "Vous ne pouvez pas fermer le root context");
+ // }
+
checkClosed("Ce contexte a deja ete ferme");
-
+
// suppression des contexts fils
- TopiaContextImplementor [] childs = childContext.toArray(new TopiaContextImplementor[childContext.size()]);
+ TopiaContextImplementor[] childs = childContext
+ .toArray(new TopiaContextImplementor[childContext.size()]);
for (TopiaContextImplementor child : childs) {
if (!child.isClosed()) {
child.closeContext();
}
- }
-// for (Iterator iter = childContext.iterator(); iter.hasNext();) {
-// TopiaContextImplementor child = (TopiaContextImplementor) iter.next();
-// child.closeContext();
-// iter.remove();
-// }
-
+ }
+ // for (Iterator iter = childContext.iterator(); iter.hasNext();) {
+ // TopiaContextImplementor child = (TopiaContextImplementor) iter.next();
+ // child.closeContext();
+ // iter.remove();
+ // }
+
// on se desenregistre du context pere et on ferme les connexions si
// on est pas le root context
if (getRootContext() != this) {
@@ -780,7 +810,7 @@
log.debug("TopiaContext finalized");
}
}
-
+
public boolean isClosed() {
return closed;
}
@@ -797,61 +827,64 @@
public TopiaEntity findByTopiaId(String topiaId) throws TopiaException {
checkClosed("Ce contexte a ete ferme, impossible de faire une recherche");
TopiaEntity result;
- Class<?extends TopiaEntity> entityClass = TopiaId.getClassName(topiaId);
+ Class<? extends TopiaEntity> entityClass = TopiaId
+ .getClassName(topiaId);
TopiaDAO dao = getDAO(entityClass);
- result = dao.findByTopiaId(topiaId);
+ result = dao.findByTopiaId(topiaId);
return result;
}
-
+
/*
* (non-Javadoc)
* @see org.codelutin.topia.TopiaContext#find(java.lang.String, java.lang.Object[])
*/
- public List find(String hql, Object ... args) throws TopiaException {
+ public List find(String hql, Object... args) throws TopiaException {
checkClosed("Ce contexte a ete ferme, impossible de faire une recherche");
try {
Query query = getHibernate().createQuery(hql);
for (int j = 0; j < args.length; j += 2) {
- String name = (String)args[j];
+ String name = (String) args[j];
Object value = args[j + 1];
- if(value.getClass().isArray()) {
- query.setParameterList(name, (Object[])value);
+ if (value.getClass().isArray()) {
+ query.setParameterList(name, (Object[]) value);
} else {
- query.setParameter(name, value);
+ query.setParameter(name, value);
}
}
List result = query.list();
result = firesSupport.fireEntitiesLoad(this, result);
return result;
} catch (HibernateException eee) {
- throw new TopiaException("Error during query execution: " + hql, eee);
+ throw new TopiaException("Error during query execution: " + hql,
+ eee);
}
}
- public List find(String hql,int startIndex,int endIndex, Object ... args) throws TopiaException {
+ public List find(String hql, int startIndex, int endIndex, Object... args)
+ throws TopiaException {
checkClosed("Ce contexte a ete ferme, impossible de faire une recherche");
try {
Query query = getHibernate().createQuery(hql);
for (int j = 0; j < args.length; j += 2) {
- String name = (String)args[j];
+ String name = (String) args[j];
Object value = args[j + 1];
- if(value.getClass().isArray()) {
- query.setParameterList(name, (Object[])value);
+ if (value.getClass().isArray()) {
+ query.setParameterList(name, (Object[]) value);
} else {
- query.setParameter(name, value);
+ query.setParameter(name, value);
}
}
query.setFirstResult(startIndex);
- query.setMaxResults(endIndex-startIndex+1);
+ query.setMaxResults(endIndex - startIndex + 1);
List result = query.list();
result = firesSupport.fireEntitiesLoad(this, result);
return result;
} catch (HibernateException eee) {
- throw new TopiaException("Error during query execution: " + hql, eee);
+ throw new TopiaException("Error during query execution: " + hql,
+ eee);
}
}
-
/**
* Execute HQL operation on data (Update, Delete)
* @param hql
@@ -859,20 +892,21 @@
* @return The number of entities updated or deleted.
* @throws TopiaException
*/
- public int execute(String hql, Object ... args) throws TopiaException {
+ public int execute(String hql, Object... args) throws TopiaException {
checkClosed("Ce contexte a ete ferme, impossible de faire une recherche");
try {
Query query = getHibernate().createQuery(hql);
for (int j = 0; j < args.length; j += 2) {
- query.setParameter((String)args[j], args[j + 1]);
+ query.setParameter((String) args[j], args[j + 1]);
}
int result = query.executeUpdate();
return result;
} catch (HibernateException eee) {
- throw new TopiaException("Error during query execution: " + hql, eee);
+ throw new TopiaException("Error during query execution: " + hql,
+ eee);
}
}
-
+
/* (non-Javadoc)
* @see org.codelutin.topia.TopiaContext#add(org.codelutin.topia.persistence.TopiaEntity)
*/
@@ -883,7 +917,7 @@
TopiaDAO dao = getDAO(entityClass);
dao.update(e);
}
-
+
/** (non-Javadoc)
* @see org.codelutin.topia.TopiaContext#importXML(java.io.Reader)
*/
@@ -906,7 +940,7 @@
Element rootElement = doc.getRootElement();
Iterator it = rootElement.elementIterator();
while (it.hasNext()) {
- Element entity = (Element)it.next();
+ Element entity = (Element) it.next();
try {
sessionDom4j.replicate(entity, ReplicationMode.EXCEPTION);
} catch (HibernateException he) {
@@ -921,7 +955,8 @@
/** (non-Javadoc)
* @see org.codelutin.topia.TopiaContext#exportXML(java.io.Writer, java.lang.Object...)
*/
- public void exportXML(Writer xml, Object... entityAndcondition) throws TopiaException {
+ public void exportXML(Writer xml, Object... entityAndcondition)
+ throws TopiaException {
checkClosed("Ce contexte a ete ferme, impossible d'effectuer l'export");
try {
Class entityClass;
@@ -930,10 +965,12 @@
// si entityAndcondition est vide alors il faut le remplir
// avec toutes les entités du mapping (class, null)
if (entityAndcondition.length == 0) {
- entityAndcondition = new Object[getHibernateFactory().getAllClassMetadata().size() * 2];
+ entityAndcondition = new Object[getHibernateFactory()
+ .getAllClassMetadata().size() * 2];
int i = 0;
- for (Object className : getHibernateFactory().getAllClassMetadata().keySet()) {
- entityAndcondition[i++] = Class.forName((String)className);
+ for (Object className : getHibernateFactory()
+ .getAllClassMetadata().keySet()) {
+ entityAndcondition[i++] = Class.forName((String) className);
entityAndcondition[i++] = null;
}
}
@@ -946,36 +983,43 @@
String date = format.format(new Date(System.currentTimeMillis()));
rootElement.addAttribute("date", date);
- for(int i=0; i<entityAndcondition.length;) {
+ for (int i = 0; i < entityAndcondition.length;) {
try {
- entityClass = (Class)entityAndcondition[i++];
- condition = (String)entityAndcondition[i++];
-
+ entityClass = (Class) entityAndcondition[i++];
+ condition = (String) entityAndcondition[i++];
+
String query = "from " + entityClass.getName();
if (condition != null && "".equals(condition) == false) {
query += " where " + condition;
}
- for(Object o : sessionDom4j.createQuery(query).list()) {
- rootElement.add((Element)o);
+ for (Object o : sessionDom4j.createQuery(query).list()) {
+ rootElement.add((Element) o);
}
} catch (ClassCastException eee) {
if (i % 2 == 0) {
- throw new IllegalArgumentException("Others arguement must be String not " + entityAndcondition[i-1], eee);
+ throw new IllegalArgumentException(
+ "Others arguement must be String not "
+ + entityAndcondition[i - 1], eee);
} else {
- throw new IllegalArgumentException("Others arguement must be Class not " + entityAndcondition[i-1], eee);
+ throw new IllegalArgumentException(
+ "Others arguement must be Class not "
+ + entityAndcondition[i - 1], eee);
}
} catch (IndexOutOfBoundsException eee) {
- throw new IllegalArgumentException("Others arguement must be couple of (Class, String)", eee);
+ throw new IllegalArgumentException(
+ "Others arguement must be couple of (Class, String)",
+ eee);
}
}
- XMLWriter result = new XMLWriter(xml, OutputFormat.createPrettyPrint());
+ XMLWriter result = new XMLWriter(xml, OutputFormat
+ .createPrettyPrint());
result.write(doc);
result.close();
} catch (HibernateException eee) {
- throw new TopiaException("Can't export XML", eee);
+ throw new TopiaException("Can't export XML", eee);
} catch (IOException eee) {
throw new TopiaException("Can't export XML", eee);
} catch (ClassNotFoundException eee) {
@@ -991,7 +1035,7 @@
public TopiaFiresSupport getFiresSupport() {
return firesSupport;
}
-
+
/**
* Backup database in gzip compressed file
* Only work for h2 database
@@ -1003,48 +1047,49 @@
*/
public void backup(File file, boolean compress) throws TopiaException {
checkClosed("Ce contexte a ete ferme, impossible d'effectuer le backup");
- try {
-// Statement stat = getHibernate().connection().createStatement();
-// ResultSet rs = stat.executeQuery("SCRIPT TO '" + file.getAbsolutePath() + "'");
-
+ try {
+ // Statement stat = getHibernate().connection().createStatement();
+ // ResultSet rs = stat.executeQuery("SCRIPT TO '" + file.getAbsolutePath() + "'");
+
// Bug dans h2 v0.9, on ne peut pas directement passer le fichier dans le SQL
// Il y a un ArrayOutBoundException -> org.h2.command.dml.Script.add:203
// pour certaines lignes. C dommage, car on est obligé de rammener
// tout en texte, ce qui peut-etre gros pour la memoire :(
-
+
String options = "";
if (compress) {
- options += " COMPRESSION GZIP";
+ options += " COMPRESSION GZIP";
}
-
- SQLQuery query = getHibernate().createSQLQuery("SCRIPT TO '" + file.getAbsolutePath() + "'" + options);
+
+ SQLQuery query = getHibernate().createSQLQuery(
+ "SCRIPT TO '" + file.getAbsolutePath() + "'" + options);
query.list();
-
-// List<String> lines = query.list();
-// // en fait on est un peu obligé d'exporter toute la base
-// // (creation du schema compris) car sinon lors de la restauration
-// // si le schema a ete creer avant il contient aussi les
-// // contrainte et du coup les inserts se passent mal :(
-// // Si on ne voulait que les inserts, lors de la resauration il
-// // faudrait desactiver les contraintes et les reactiver ensuite
-//
-// OutputStream os = new BufferedOutputStream (
-// new FileOutputStream(file));
-//
-// PrintStream out;
-// if (compress) {
-// out = new PrintStream(new GZIPOutputStream(os));
-// } else {
-// out = new PrintStream(os);
-// }
-//
-// for (String line : lines) {
-// out.println(line + ";");
-// }
-// out.close();
+ // List<String> lines = query.list();
+
+ // // en fait on est un peu obligé d'exporter toute la base
+ // // (creation du schema compris) car sinon lors de la restauration
+ // // si le schema a ete creer avant il contient aussi les
+ // // contrainte et du coup les inserts se passent mal :(
+ // // Si on ne voulait que les inserts, lors de la resauration il
+ // // faudrait desactiver les contraintes et les reactiver ensuite
+ //
+ // OutputStream os = new BufferedOutputStream (
+ // new FileOutputStream(file));
+ //
+ // PrintStream out;
+ // if (compress) {
+ // out = new PrintStream(new GZIPOutputStream(os));
+ // } else {
+ // out = new PrintStream(os);
+ // }
+ //
+ // for (String line : lines) {
+ // out.println(line + ";");
+ // }
+ // out.close();
} catch (Exception eee) {
- throw new TopiaException("Can't backup", eee);
+ throw new TopiaException("Can't backup", eee);
}
}
@@ -1058,7 +1103,7 @@
public void restore(File file) throws TopiaException {
// send event
getFiresSupport().firePreRestoreSchema(this);
-
+
checkClosed("Ce contexte a ete ferme, impossible d'effectuer le restore");
String sql = null;
try {
@@ -1068,72 +1113,76 @@
// read header to see if is compressed file
int b = in.read();
- int magic = ((int)in.read() << 8) | b;
+ int magic = ((int) in.read() << 8) | b;
in.reset();
String options = "";
-
+
if (magic == GZIPInputStream.GZIP_MAGIC) {
-// in = new GZIPInputStream(in);
+ // in = new GZIPInputStream(in);
options += " COMPRESSION GZIP";
}
in.close();
-
- SQLQuery query = getHibernate().createSQLQuery("RUNSCRIPT FROM '" + file.getAbsolutePath() + "'" + options);
+
+ SQLQuery query = getHibernate()
+ .createSQLQuery(
+ "RUNSCRIPT FROM '" + file.getAbsolutePath() + "'"
+ + options);
query.executeUpdate();
// send event AFTER restore
getFiresSupport().firePostRestoreSchema(this);
-
-// BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-// Connection conn = getHibernate().connection();
-// conn.setAutoCommit(false);
-// Statement stat = conn.createStatement();
-//
-// while((sql = reader.readLine()) != null) {
-// // FIXME remove next line when h2 will do the bug correction (normaly in october 2006)
-// // this permit database restauration
-//// if (sql.startsWith("ALTER TABLE")) {
-//// sql = sql.replaceAll("INDEX CONSTRAINT_INDEX_\\d*", "");
-//// }
-// stat.execute(sql);
-// }
-// stat.close();
-// conn.commit();
-// conn.close();
-
-// // by default we supposed that file is not compressed
-// File tmp = file;
-// if (magic == GZIPInputStream.GZIP_MAGIC) {
-// // in fact file is compressed, use temporaly file
-// tmp = File.createTempFile("tmp-topia-restore", ".sql");
-// tmp.deleteOnExit();
-//
-// // decompresse file in temporary file
-// InputStream gzin = new GZIPInputStream(in);
-//
-// OutputStream out = new BufferedOutputStream(
-// new FileOutputStream(tmp));
-//
-// byte [] buffer = new byte[64 * 1024];
-// int len = 0;
-// while ((len = gzin.read(buffer)) != -1) {
-// out.write(buffer, 0, len);
-// }
-// out.close();
-// gzin.close();
-// }
-//
-// // restore data
-// Statement stat = getHibernate().connection().createStatement();
-// stat.execute("RUNSCRIPT FROM '" + tmp.getAbsolutePath() + "'");
-//
-//// SQLQuery query = getHibernate().createSQLQuery("RUNSCRIPT FROM '" + file.getAbsolutePath() + "'");
-//// List result = query.list();
+
+ // BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ // Connection conn = getHibernate().connection();
+ // conn.setAutoCommit(false);
+ // Statement stat = conn.createStatement();
+ //
+ // while((sql = reader.readLine()) != null) {
+ // // FIXME remove next line when h2 will do the bug correction (normaly in october 2006)
+ // // this permit database restauration
+ //// if (sql.startsWith("ALTER TABLE")) {
+ //// sql = sql.replaceAll("INDEX CONSTRAINT_INDEX_\\d*", "");
+ //// }
+ // stat.execute(sql);
+ // }
+ // stat.close();
+ // conn.commit();
+ // conn.close();
+
+ // // by default we supposed that file is not compressed
+ // File tmp = file;
+ // if (magic == GZIPInputStream.GZIP_MAGIC) {
+ // // in fact file is compressed, use temporaly file
+ // tmp = File.createTempFile("tmp-topia-restore", ".sql");
+ // tmp.deleteOnExit();
+ //
+ // // decompresse file in temporary file
+ // InputStream gzin = new GZIPInputStream(in);
+ //
+ // OutputStream out = new BufferedOutputStream(
+ // new FileOutputStream(tmp));
+ //
+ // byte [] buffer = new byte[64 * 1024];
+ // int len = 0;
+ // while ((len = gzin.read(buffer)) != -1) {
+ // out.write(buffer, 0, len);
+ // }
+ // out.close();
+ // gzin.close();
+ // }
+ //
+ // // restore data
+ // Statement stat = getHibernate().connection().createStatement();
+ // stat.execute("RUNSCRIPT FROM '" + tmp.getAbsolutePath() + "'");
+ //
+ //// SQLQuery query = getHibernate().createSQLQuery("RUNSCRIPT FROM '" + file.getAbsolutePath() + "'");
+ //// List result = query.list();
} catch (Exception eee) {
- throw new TopiaException("Can't restore. Last sql instruction was:" + sql, eee);
+ throw new TopiaException("Can't restore. Last sql instruction was:"
+ + sql, eee);
}
- }
+ }
/**
* Only h2 supported for now
@@ -1141,8 +1190,8 @@
*/
public void clear(boolean dropDatabase) throws TopiaException {
try {
- TopiaContextImpl root = (TopiaContextImpl)getRootContext();
- TopiaContextImpl tx = (TopiaContextImpl)root.beginTransaction();
+ TopiaContextImpl root = (TopiaContextImpl) getRootContext();
+ TopiaContextImpl tx = (TopiaContextImpl) root.beginTransaction();
String sql = "DROP ALL OBJECTS";
if (dropDatabase) {
@@ -1156,7 +1205,7 @@
throw new TopiaException("Can't clear topia context", eee);
}
}
-
+
public List<Class> getPersistenceClasses() {
return persistenceClasses;
}
@@ -1166,7 +1215,9 @@
getFiresSupport().addTopiaEntityListener(listener);
}
- public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) {
+ public void addTopiaEntityListener(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener) {
getFiresSupport().addTopiaEntityListener(entityClass, listener);
}
@@ -1174,7 +1225,9 @@
getFiresSupport().addTopiaEntityVetoable(TopiaEntity.class, vetoable);
}
- public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) {
+ public void addTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable) {
getFiresSupport().addTopiaEntityVetoable(entityClass, vetoable);
}
@@ -1185,29 +1238,35 @@
public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
getFiresSupport().addTopiaTransactionVetoable(vetoable);
}
-
+
public void addPropertyChangeListener(PropertyChangeListener listener) {
getFiresSupport().addPropertyChangeListener(listener);
}
-
+
public void addTopiaContextListener(TopiaContextListener listener) {
getFiresSupport().addTopiaContextListener(listener);
}
/* Removers */
public void removeTopiaEntityListener(TopiaEntityListener listener) {
- getFiresSupport().removeTopiaEntityListener(TopiaEntity.class, listener);
+ getFiresSupport()
+ .removeTopiaEntityListener(TopiaEntity.class, listener);
}
- public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) {
+ public void removeTopiaEntityListener(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener) {
getFiresSupport().removeTopiaEntityListener(entityClass, listener);
}
public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getFiresSupport().removeTopiaEntityVetoable(TopiaEntity.class, vetoable);
+ getFiresSupport()
+ .removeTopiaEntityVetoable(TopiaEntity.class, vetoable);
}
- public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) {
+ public void removeTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable) {
getFiresSupport().removeTopiaEntityVetoable(entityClass, vetoable);
}
@@ -1218,11 +1277,11 @@
public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
getFiresSupport().removeTopiaTransactionVetoable(vetoable);
}
-
+
public void removePropertyChangeListener(PropertyChangeListener listener) {
getFiresSupport().removePropertyChangeListener(listener);
}
-
+
public void removeTopiaContextListener(TopiaContextListener listener) {
getFiresSupport().removeTopiaContextListener(listener);
}
@@ -1234,5 +1293,5 @@
public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
getFiresSupport().removeTopiaEntitiesVetoable(vetoable);
}
-
+
} //TopiaContextImpl
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImplementor.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/framework/TopiaContextImplementor.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaContextImplementor.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -55,7 +55,7 @@
* @return Returns the childContext.
*/
public Set<TopiaContextImplementor> getChildContext();
-
+
/**
* @return Returns the parentContext.
*/
@@ -84,7 +84,8 @@
* @return Returns the hibernate configuration
* @throws TopiaNotFoundException
*/
- public Configuration getHibernateConfiguration() throws TopiaNotFoundException;
+ public Configuration getHibernateConfiguration()
+ throws TopiaNotFoundException;
/**
* Get DAO for specified class. If Specialized DAO exists then it returned
@@ -98,15 +99,14 @@
public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass)
throws TopiaException;
+ public TopiaFiresSupport getFiresSupport();
- public TopiaFiresSupport getFiresSupport();
-
public void removeChildContext(TopiaContextImplementor child);
-
+
public Map<String, TopiaService> getServices();
public Collection<TopiaService> getAllServices();
-
+
public List<Class> getPersistenceClasses();
-
+
} //TopiaContextImplementor
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaFiresSupport.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/framework/TopiaFiresSupport.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaFiresSupport.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -74,26 +74,26 @@
public class TopiaFiresSupport {
static private Log log = LogFactory.getLog(TopiaFiresSupport.class);
-
+
/** used to fire read event */
final static Object NO_CHANGE = new Object();
-
+
/** used to collect entity modification during transaction */
- protected Map<TopiaEntity, EntityState> transactionEntities = new IdentityMap();
-
+ protected Map<TopiaEntity, EntityState> transactionEntities = new IdentityMap();
+
protected Set<PropertyChangeListener> propertyChangeListeners = new HashSet<PropertyChangeListener>();
-
+
/* Pour la transaction */
protected ListenerSet<TopiaTransactionListener> transactionListeners = new ListenerSet<TopiaTransactionListener>();
protected ListenerSet<TopiaTransactionVetoable> transactionVetoables = new ListenerSet<TopiaTransactionVetoable>();
-
+
/* Pour les entités */
protected CategorisedListenerSet<TopiaEntityListener> entityListeners = new CategorisedListenerSet<TopiaEntityListener>();
protected CategorisedListenerSet<TopiaEntityVetoable> entityVetoables = new CategorisedListenerSet<TopiaEntityVetoable>();
-
+
/* Pour les listes d'entités */
protected ListenerSet<TopiaEntitiesVetoable> entitiesVetoables = new ListenerSet<TopiaEntitiesVetoable>();
-
+
/* Pour les actions du topia context */
protected ListenerSet<TopiaContextListener> topiaContextListeners = new ListenerSet<TopiaContextListener>();
@@ -112,7 +112,7 @@
}
state.addLoad();
}
-
+
/**
* used to register objects created during transaction.
* @param entity
@@ -128,7 +128,7 @@
}
state.addCreate();
}
-
+
/**
* used to register objects loaded during transaction.
* @param entity
@@ -144,7 +144,7 @@
}
state.addRead();
}
-
+
/**
* used to register objects modified during transaction.
* @param entity
@@ -161,7 +161,7 @@
}
state.addUpdate();
}
-
+
/**
* used to register objects deleted during transaction.
* @param entity
@@ -177,14 +177,15 @@
}
state.addDelete();
}
-
+
/* Fires sur les transactions */
public void fireOnBeginTransaction(TopiaContextImplementor context) {
if (log.isDebugEnabled()) {
log.debug("fireOnBeginTransaction");
}
TopiaTransactionEvent e = new TopiaTransactionEvent(context);
- for(Iterator<TopiaTransactionVetoable> l=transactionVetoables.iterator(); l.hasNext();) {
+ for (Iterator<TopiaTransactionVetoable> l = transactionVetoables
+ .iterator(); l.hasNext();) {
try {
l.next().beginTransaction(e);
} catch (Exception eee) {
@@ -197,8 +198,10 @@
if (log.isDebugEnabled()) {
log.debug("fireOnPostCommit");
}
- TopiaTransactionEvent e = new TopiaTransactionEvent(context, transactionEntities);
- for(Iterator<TopiaTransactionListener> l=transactionListeners.iterator(); l.hasNext();) {
+ TopiaTransactionEvent e = new TopiaTransactionEvent(context,
+ transactionEntities);
+ for (Iterator<TopiaTransactionListener> l = transactionListeners
+ .iterator(); l.hasNext();) {
try {
l.next().commit(e);
} catch (Exception eee) {
@@ -209,13 +212,15 @@
}
transactionEntities.clear();
}
-
+
public void fireOnPostRollback(TopiaContextImplementor context) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostRollback");
}
- TopiaTransactionEvent e = new TopiaTransactionEvent(context, transactionEntities);
- for(Iterator<TopiaTransactionListener> l=transactionListeners.iterator(); l.hasNext();) {
+ TopiaTransactionEvent e = new TopiaTransactionEvent(context,
+ transactionEntities);
+ for (Iterator<TopiaTransactionListener> l = transactionListeners
+ .iterator(); l.hasNext();) {
try {
l.next().rollback(e);
} catch (Exception eee) {
@@ -226,14 +231,16 @@
}
transactionEntities.clear();
}
-
+
/* Fires sur les entités */
- public void fireOnPreCreate(TopiaContextImplementor context, TopiaEntity entity, Object[] state) {
+ public void fireOnPreCreate(TopiaContextImplementor context,
+ TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPreCreate");
}
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for(Iterator<TopiaEntityVetoable> l=entityVetoables.iterator(entity.getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity
+ .getClass()); l.hasNext();) {
try {
l.next().create(event);
} catch (Exception eee) {
@@ -241,30 +248,35 @@
}
}
}
-
- public void fireOnPostCreate(TopiaContextImplementor context, TopiaEntity entity, Object[] state) {
+
+ public void fireOnPostCreate(TopiaContextImplementor context,
+ TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostCreate");
}
warnOnCreateEntity(entity);
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for(Iterator<TopiaEntityListener> l=entityListeners.iterator(entity.getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity
+ .getClass()); l.hasNext();) {
try {
l.next().create(event);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fireOnPostCreate for entity: " + entity, eee);
+ log.error("Can't fireOnPostCreate for entity: " + entity,
+ eee);
}
}
}
}
-
- public void fireOnPreLoad(TopiaContextImplementor context, TopiaEntity entity, Object[] state) {
+
+ public void fireOnPreLoad(TopiaContextImplementor context,
+ TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPreLoad");
}
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for(Iterator<TopiaEntityVetoable> l=entityVetoables.iterator(entity.getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity
+ .getClass()); l.hasNext();) {
try {
l.next().load(event);
} catch (Exception eee) {
@@ -272,30 +284,37 @@
}
}
}
-
- public void fireOnPostLoad(TopiaContextImplementor context, TopiaEntity entity, Object[] state) {
+
+ public void fireOnPostLoad(TopiaContextImplementor context,
+ TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostLoad");
}
warnOnLoadEntity(entity);
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for(Iterator<TopiaEntityListener> l=entityListeners.iterator(entity.getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity
+ .getClass()); l.hasNext();) {
try {
l.next().load(event);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fireOnPostLoad for entity: " + entity, eee);
+ log
+ .error(
+ "Can't fireOnPostLoad for entity: "
+ + entity, eee);
}
}
}
}
-
- public void fireOnPreUpdate(TopiaContextImplementor context, TopiaEntity entity, Object[] state) {
+
+ public void fireOnPreUpdate(TopiaContextImplementor context,
+ TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPreUpdate");
}
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for(Iterator<TopiaEntityVetoable> l=entityVetoables.iterator(entity.getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity
+ .getClass()); l.hasNext();) {
try {
l.next().update(event);
} catch (Exception eee) {
@@ -303,30 +322,35 @@
}
}
}
-
- public void fireOnPostUpdate(TopiaContextImplementor context, TopiaEntity entity, Object[] state) {
+
+ public void fireOnPostUpdate(TopiaContextImplementor context,
+ TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostUpdate");
}
warnOnUpdateEntity(entity);
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for(Iterator<TopiaEntityListener> l=entityListeners.iterator(entity.getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity
+ .getClass()); l.hasNext();) {
try {
l.next().update(event);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fireOnPostUpdate for entity: " + entity, eee);
+ log.error("Can't fireOnPostUpdate for entity: " + entity,
+ eee);
}
}
}
}
-
- public void fireOnPreDelete(TopiaContextImplementor context, TopiaEntity entity, Object[] state) {
+
+ public void fireOnPreDelete(TopiaContextImplementor context,
+ TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPreDelete");
}
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for(Iterator<TopiaEntityVetoable> l=entityVetoables.iterator(entity.getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityVetoable> l = entityVetoables.iterator(entity
+ .getClass()); l.hasNext();) {
try {
l.next().delete(event);
} catch (Exception eee) {
@@ -334,28 +358,31 @@
}
}
}
-
- public void fireOnPostDelete(TopiaContextImplementor context, TopiaEntity entity, Object[] state) {
+
+ public void fireOnPostDelete(TopiaContextImplementor context,
+ TopiaEntity entity, Object[] state) {
if (log.isDebugEnabled()) {
log.debug("fireOnPostDelete");
}
warnOnDeleteEntity(entity);
TopiaEntityEvent event = new TopiaEntityEvent(context, entity, state);
- for(Iterator<TopiaEntityListener> l=entityListeners.iterator(entity.getClass()); l.hasNext();) {
+ for (Iterator<TopiaEntityListener> l = entityListeners.iterator(entity
+ .getClass()); l.hasNext();) {
try {
l.next().delete(event);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fireOnPostDelete for entity: " + entity, eee);
+ log.error("Can't fireOnPostDelete for entity: " + entity,
+ eee);
}
}
}
}
-
+
/* Fires sur les propriétés */
public void fireOnPreRead(VetoableChangeSupport vetoables,
TopiaEntity entity, String propertyName, Object value) {
-
+
if (log.isDebugEnabled()) {
log.debug("fireOnPreRead");
}
@@ -365,10 +392,10 @@
throw new TopiaVetoException(eee);
}
}
-
+
public void fireOnPostRead(PropertyChangeSupport listeners,
TopiaEntity entity, String propertyName, Object value) {
-
+
if (log.isDebugEnabled()) {
log.debug("fireOnPostRead");
}
@@ -382,27 +409,29 @@
}
}
-
+
public void fireOnPostRead(PropertyChangeSupport listeners,
TopiaEntity entity, String propertyName, int index, Object value) {
-
+
if (log.isDebugEnabled()) {
log.debug("fireOnPostRead");
}
warnOnReadEntity(entity);
try {
- listeners.fireIndexedPropertyChange(propertyName, index, value, NO_CHANGE);
+ listeners.fireIndexedPropertyChange(propertyName, index, value,
+ NO_CHANGE);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fireOnPostRead" , eee);
+ log.error("Can't fireOnPostRead", eee);
}
}
}
-
+
public void fireOnPreWrite(VetoableChangeSupport vetoables,
- TopiaEntity entity, String propertyName, Object oldValue, Object newValue) {
-
+ TopiaEntity entity, String propertyName, Object oldValue,
+ Object newValue) {
+
if (log.isDebugEnabled()) {
log.debug("fireOnPreWrite");
}
@@ -412,22 +441,25 @@
throw new TopiaVetoException(eee);
}
}
-
+
public void fireOnPostWrite(PropertyChangeSupport listeners,
- TopiaEntity entity, String propertyName, Object oldValue, Object newValue) {
-
+ TopiaEntity entity, String propertyName, Object oldValue,
+ Object newValue) {
+
if (log.isDebugEnabled()) {
log.debug("fireOnPostWrite");
}
warnOnUpdateEntity(entity);
if (propertyChangeListeners.size() > 0) {
- PropertyChangeEvent e = new PropertyChangeEvent(entity, propertyName, oldValue, newValue);
+ PropertyChangeEvent e = new PropertyChangeEvent(entity,
+ propertyName, oldValue, newValue);
for (PropertyChangeListener l : propertyChangeListeners) {
try {
l.propertyChange(e);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
- log.error("Can't fire property change for: " + propertyName, eee);
+ log.error("Can't fire property change for: "
+ + propertyName, eee);
}
}
}
@@ -440,32 +472,35 @@
}
}
}
-
+
public void fireOnPostWrite(PropertyChangeSupport listeners,
- TopiaEntity entity, String propertyName, int index, Object oldValue, Object newValue) {
-
+ TopiaEntity entity, String propertyName, int index,
+ Object oldValue, Object newValue) {
+
if (log.isDebugEnabled()) {
log.debug("fireOnPostWrite");
}
warnOnUpdateEntity(entity);
try {
- listeners.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
+ listeners.fireIndexedPropertyChange(propertyName, index, oldValue,
+ newValue);
} catch (Exception eee) {
if (log.isErrorEnabled()) {
log.error("Can't fireOnPostWrite", eee);
}
}
}
+
/**
* Object permettant de faire le lien entre les events hibernate et topia
*
* @author poussin
*/
- static public class TopiaHibernateEvent implements
- PreInsertEventListener, PostInsertEventListener,
- PreLoadEventListener, PostLoadEventListener,
- PreUpdateEventListener, PostUpdateEventListener,
- PreDeleteEventListener, PostDeleteEventListener {
+ static public class TopiaHibernateEvent implements PreInsertEventListener,
+ PostInsertEventListener, PreLoadEventListener,
+ PostLoadEventListener, PreUpdateEventListener,
+ PostUpdateEventListener, PreDeleteEventListener,
+ PostDeleteEventListener {
private static final long serialVersionUID = 7303593133642169218L;
@@ -507,16 +542,18 @@
return result;
}
- private void attachContext(Object entity, TopiaContextImplementor context) {
- if(entity instanceof TopiaEntityAbstract) {
+ private void attachContext(Object entity,
+ TopiaContextImplementor context) {
+ if (entity instanceof TopiaEntityAbstract) {
TopiaEntityAbstract entityAbstract = (TopiaEntityAbstract) entity;
- if(entityAbstract.getTopiaContext() == null) {
+ if (entityAbstract.getTopiaContext() == null) {
try {
entityAbstract.setTopiaContext(context);
} catch (TopiaException eee) {
if (log.isWarnEnabled()) {
- log.warn("Impossible d'initialiser le TopiaContext" +
- " sur cette entité : " + entityAbstract, eee);
+ log.warn("Impossible d'initialiser le TopiaContext"
+ + " sur cette entité : " + entityAbstract,
+ eee);
}
}
}
@@ -525,80 +562,98 @@
/* Création */
public boolean onPreInsert(PreInsertEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPreCreate(context, (TopiaEntity) event.getEntity(), event.getState());
+ context.getFiresSupport().fireOnPreCreate(context,
+ (TopiaEntity) event.getEntity(), event.getState());
}
return false;
}
public void onPostInsert(PostInsertEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPostCreate(context, (TopiaEntity) event.getEntity(), event.getState());
+ context.getFiresSupport().fireOnPostCreate(context,
+ (TopiaEntity) event.getEntity(), event.getState());
}
}
/* Chargement */
public void onPreLoad(PreLoadEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
if (context != null && event.getEntity() instanceof TopiaEntity) {
-// try {
- context.getFiresSupport().fireOnPreLoad(context, (TopiaEntity) event.getEntity(), event.getState());
- //TODO (thimel 20071213) On commente pour le moment @see(TopiaDAOHibernate#filterElements)
-// } catch (TopiaVetoException tve) {
-// //On ne fait pas de remontee d'exception vers Hibernate pour le preLoad, on va agir au niveau du DAO
-// }
+ // try {
+ context.getFiresSupport().fireOnPreLoad(context,
+ (TopiaEntity) event.getEntity(), event.getState());
+ //TODO (thimel 20071213) On commente pour le moment @see(TopiaDAOHibernate#filterElements)
+ // } catch (TopiaVetoException tve) {
+ // //On ne fait pas de remontee d'exception vers Hibernate pour le preLoad, on va agir au niveau du DAO
+ // }
}
}
-
+
public void onPostLoad(PostLoadEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
if (context != null && event.getEntity() instanceof TopiaEntity) {
attachContext(event.getEntity(), context);
- context.getFiresSupport().fireOnPostLoad(context, (TopiaEntity) event.getEntity(), new Object[]{});
+ context.getFiresSupport().fireOnPostLoad(context,
+ (TopiaEntity) event.getEntity(), new Object[] {});
}
}
/* Modification */
public boolean onPreUpdate(PreUpdateEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPreUpdate(context, (TopiaEntity) event.getEntity(), event.getOldState());
+ context.getFiresSupport().fireOnPreUpdate(context,
+ (TopiaEntity) event.getEntity(), event.getOldState());
}
return false;
}
public void onPostUpdate(PostUpdateEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPostUpdate(context, (TopiaEntity) event.getEntity(), event.getState());
+ context.getFiresSupport().fireOnPostUpdate(context,
+ (TopiaEntity) event.getEntity(), event.getState());
}
-// FIXME indexation if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
-// context.getIndexEnginImplementor().recordForIndexation(id, event.getState());
-// }
- }
-
+ // FIXME indexation if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
+ // context.getIndexEnginImplementor().recordForIndexation(id, event.getState());
+ // }
+ }
+
/* Suppression */
public boolean onPreDelete(PreDeleteEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPreDelete(context, (TopiaEntity) event.getEntity(), event.getDeletedState());
+ context.getFiresSupport().fireOnPreDelete(context,
+ (TopiaEntity) event.getEntity(),
+ event.getDeletedState());
}
return false;
}
public void onPostDelete(PostDeleteEvent event) {
- TopiaContextImplementor context = getContext(rootContext, event.getSession());
+ TopiaContextImplementor context = getContext(rootContext, event
+ .getSession());
if (context != null && event.getEntity() instanceof TopiaEntity) {
- context.getFiresSupport().fireOnPostDelete(context, (TopiaEntity) event.getEntity(), event.getDeletedState());
+ context.getFiresSupport().fireOnPostDelete(context,
+ (TopiaEntity) event.getEntity(),
+ event.getDeletedState());
}
-// FIXME indexation if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
-// context.getIndexEnginImplementor().recordForIndexation(id, null);
-// }
- }
+ // FIXME indexation if (!(entity instanceof NotIndexable) && context.isIndexEnabled()) {
+ // context.getIndexEnginImplementor().recordForIndexation(id, null);
+ // }
}
-
+ }
+
/**
* Notify topia context listeners for create schema pre operation
* @param context topia context
@@ -608,7 +663,8 @@
log.debug("firePreCreateSchema");
}
TopiaContextEvent event = new TopiaContextEvent(context);
- for(Iterator<TopiaContextListener> l=topiaContextListeners.iterator(); l.hasNext();) {
+ for (Iterator<TopiaContextListener> l = topiaContextListeners
+ .iterator(); l.hasNext();) {
try {
l.next().preCreateSchema(event);
} catch (Exception eee) {
@@ -616,7 +672,7 @@
}
}
}
-
+
/**
* Notify topia context listeners for create schema post operation
* @param context topia context
@@ -626,7 +682,8 @@
log.debug("firePostCreateSchema");
}
TopiaContextEvent event = new TopiaContextEvent(context);
- for(Iterator<TopiaContextListener> l=topiaContextListeners.iterator(); l.hasNext();) {
+ for (Iterator<TopiaContextListener> l = topiaContextListeners
+ .iterator(); l.hasNext();) {
try {
l.next().postCreateSchema(event);
} catch (Exception eee) {
@@ -634,7 +691,7 @@
}
}
}
-
+
/**
* Notify topia context listeners for create schema pre operation
* @param context topia context
@@ -644,7 +701,8 @@
log.debug("firePostCreateSchema");
}
TopiaContextEvent event = new TopiaContextEvent(context);
- for(Iterator<TopiaContextListener> l=topiaContextListeners.iterator(); l.hasNext();) {
+ for (Iterator<TopiaContextListener> l = topiaContextListeners
+ .iterator(); l.hasNext();) {
try {
l.next().preUpdateSchema(event);
} catch (Exception eee) {
@@ -652,7 +710,7 @@
}
}
}
-
+
/**
* Notify topia context listeners for create schema post operation
* @param context topia context
@@ -662,7 +720,8 @@
log.debug("firePostCreateSchema");
}
TopiaContextEvent event = new TopiaContextEvent(context);
- for(Iterator<TopiaContextListener> l=topiaContextListeners.iterator(); l.hasNext();) {
+ for (Iterator<TopiaContextListener> l = topiaContextListeners
+ .iterator(); l.hasNext();) {
try {
l.next().postUpdateSchema(event);
} catch (Exception eee) {
@@ -670,7 +729,7 @@
}
}
}
-
+
/**
* Notify topia context listeners for schema restore pre operation
* @param context topia context
@@ -680,7 +739,8 @@
log.debug("firePreRestoreSchema");
}
TopiaContextEvent event = new TopiaContextEvent(context);
- for(Iterator<TopiaContextListener> l=topiaContextListeners.iterator(); l.hasNext();) {
+ for (Iterator<TopiaContextListener> l = topiaContextListeners
+ .iterator(); l.hasNext();) {
try {
l.next().preRestoreSchema(event);
} catch (Exception eee) {
@@ -688,7 +748,7 @@
}
}
}
-
+
/**
* Notify topia context listeners for schema restore post operation
* @param context topia context
@@ -698,7 +758,8 @@
log.debug("firePostRestoreSchema");
}
TopiaContextEvent event = new TopiaContextEvent(context);
- for(Iterator<TopiaContextListener> l=topiaContextListeners.iterator(); l.hasNext();) {
+ for (Iterator<TopiaContextListener> l = topiaContextListeners
+ .iterator(); l.hasNext();) {
try {
l.next().postRestoreSchema(event);
} catch (Exception eee) {
@@ -711,15 +772,18 @@
* Notify entities listeners for load operation
* @param entities entities loaded
*/
- public <E extends TopiaEntity> List<E> fireEntitiesLoad(TopiaContextImplementor context, List<E> entities) {
+ public <E extends TopiaEntity> List<E> fireEntitiesLoad(
+ TopiaContextImplementor context, List<E> entities) {
if (log.isDebugEnabled()) {
log.debug("fireEntitiesLoad");
}
-
+
List<E> result = entities;
- for(Iterator<TopiaEntitiesVetoable> l=entitiesVetoables.iterator(); l.hasNext();) {
+ for (Iterator<TopiaEntitiesVetoable> l = entitiesVetoables.iterator(); l
+ .hasNext();) {
try {
- TopiaEntitiesEvent event = new TopiaEntitiesEvent(context, result);
+ TopiaEntitiesEvent event = new TopiaEntitiesEvent(context,
+ result);
result = l.next().load(event);
} catch (Exception eee) {
throw new TopiaVetoException(eee);
@@ -740,25 +804,27 @@
public ListenerSet<TopiaTransactionListener> getTransactionListeners() {
return transactionListeners;
}
-
+
public ListenerSet<TopiaTransactionVetoable> getTransactionVetoable() {
return transactionVetoables;
}
-
+
public ListenerSet<TopiaContextListener> getTopiaContextListeners() {
return topiaContextListeners;
}
-
+
public ListenerSet<TopiaEntitiesVetoable> getTopiaEntitiesVetoable() {
return entitiesVetoables;
}
-
+
/* Adders */
public void addTopiaEntityListener(TopiaEntityListener listener) {
addTopiaEntityListener(TopiaEntity.class, listener);
}
- public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) {
+ public void addTopiaEntityListener(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener) {
entityListeners.add(entityClass, listener);
}
@@ -766,7 +832,9 @@
addTopiaEntityVetoable(TopiaEntity.class, vetoable);
}
- public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) {
+ public void addTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable) {
entityVetoables.add(entityClass, vetoable);
}
@@ -777,25 +845,27 @@
public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
transactionVetoables.add(vetoable);
}
-
+
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeListeners.add(listener);
}
-
+
public void addTopiaContextListener(TopiaContextListener listener) {
topiaContextListeners.add(listener);
}
-
+
public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
entitiesVetoables.add(vetoable);
}
-
+
/* Removers */
public void removeTopiaEntityListener(TopiaEntityListener listener) {
removeTopiaEntityListener(TopiaEntity.class, listener);
}
- public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) {
+ public void removeTopiaEntityListener(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityListener listener) {
entityListeners.remove(entityClass, listener);
}
@@ -803,7 +873,9 @@
removeTopiaEntityVetoable(TopiaEntity.class, vetoable);
}
- public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) {
+ public void removeTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable) {
entityVetoables.remove(entityClass, vetoable);
}
@@ -822,9 +894,9 @@
public void removeTopiaContextListener(TopiaContextListener listener) {
topiaContextListeners.remove(listener);
}
-
+
public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
entitiesVetoables.remove(vetoable);
}
-
+
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaService.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/framework/TopiaService.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaService.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -29,7 +29,6 @@
package org.codelutin.topia.framework;
-
/**
* Permet d'implanter un service Topia. Il faut absolument créer une interface
* pour votre service qui contienne un attribut SERVICE_NAME
@@ -52,12 +51,12 @@
* @return
*/
public String getServiceName();
-
+
/**
* Permet de récupérer les entités à persister pour ce service
* @return Liste des entités à persister, séparées par des virgules
*/
- public Class [] getPersistenceClasses();
+ public Class[] getPersistenceClasses();
/**
* Initialise le service avant de creer le context
@@ -65,14 +64,12 @@
* @return si le service doit etre laissé activé ou pas
*/
public boolean preInit(TopiaContextImplementor context);
-
+
/**
* Initialise le service apres avoir creer le context
* @param context le context
* @return si le service doit etre laissé activé ou pas
*/
public boolean postInit(TopiaContextImplementor context);
-
-}
-
+}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaUtil.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/framework/TopiaUtil.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/framework/TopiaUtil.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -57,10 +57,11 @@
* @throws TopiaNotFoundException Si pathOrUrl n'est pas null ou vide et que
* le fichier devant contenir les propriétés n'est pas retrouvé.
*/
- static public Properties getProperties(String pathOrUrl) throws TopiaNotFoundException {
+ static public Properties getProperties(String pathOrUrl)
+ throws TopiaNotFoundException {
return getProperties(null, pathOrUrl);
}
-
+
/**
* Permet de récupérer le fichier de propriété ayant le nom passé
* en argument.
@@ -75,7 +76,7 @@
static public Properties getProperties(Properties parent, String pathOrUrl)
throws TopiaNotFoundException {
Properties result = new RecursiveProperties(parent);
-
+
// load properties for helper
if (pathOrUrl != null && !pathOrUrl.equals("")) {
try {
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/generator)
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/DAOAbstractGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/DAOAbstractGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/DAOAbstractGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -32,9 +32,7 @@
import java.io.File;
import java.io.IOException;
import java.io.Writer;
-import java.security.Permission;
import java.util.Iterator;
-import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -37,7 +37,6 @@
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -48,8 +47,6 @@
import org.codelutin.generator.models.object.ObjectModelAttribute;
import org.codelutin.generator.models.object.ObjectModelClass;
import org.codelutin.generator.models.object.ObjectModelClassifier;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-import org.codelutin.topia.persistence.TopiaEntity;
import org.codelutin.topia.persistence.TopiaEntityAbstract;
/**
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -45,7 +45,7 @@
*/
public class EntityEnumGenerator extends ObjectModelGenerator {
- private Log log = LogFactory.getLog(EntityEnumGenerator.class);
+ private static Log log = LogFactory.getLog(EntityEnumGenerator.class);
public EntityEnumGenerator() {
super();
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -91,6 +91,12 @@
if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
return;
}
+
+ // log
+ if(log.isDebugEnabled()) {
+ log.debug("Generating interface for : " + interfacez.getName());
+ }
+
generateInterfaceHeader(output, interfacez);
generateInterfaceOperations(output, interfacez);
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/GeneratorUtil.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -121,8 +121,7 @@
* @return le package par défaut du générator donné
*/
public static String getDefaultPackage(Generator generator) {
- String packageName = generator
- .getProperty(PROPERTY_DEFAULT_PACKAGE);
+ String packageName = generator.getProperty(PROPERTY_DEFAULT_PACKAGE);
if (packageName == null || "".equals(packageName)) {
packageName = DEFAULT_PACKAGE;
}
@@ -157,7 +156,7 @@
* @return l'interface trouvée ou null sinon
*/
public static ObjectModelInterface getDAOInterface(ObjectModelClass clazz,
- ObjectModel model) {
+ ObjectModel model) {
for (Object o : model.getInterfaces()) {
ObjectModelInterface daoInterface = (ObjectModelInterface) o;
if (daoInterface.getName().equals(clazz.getName() + "DAO")) {
@@ -216,7 +215,8 @@
* @param model le modele utilisé
* @return le nom du schema ou null
*/
- public static String getSchemaName(ObjectModelElement element, ObjectModel model) {
+ public static String getSchemaName(ObjectModelElement element,
+ ObjectModel model) {
return findTagValue(TAG_SCHEMA_NAME, element, model);
}
@@ -239,7 +239,8 @@
* @param model le modele utilisé
* @return la valeur du tagValue ou null
*/
- public static String findTagValue(String tagName, ObjectModelElement element, Model model) {
+ public static String findTagValue(String tagName,
+ ObjectModelElement element, Model model) {
if (element == null) {
if (model != null) {
if (notEmpty(model.getTagValue(tagName))) {
@@ -267,7 +268,7 @@
}
public static boolean hasStereotypes(ObjectModelElement element,
- String... stereotypes) {
+ String... stereotypes) {
for (String stereotype : stereotypes) {
if (!element.hasStereotype(stereotype)) {
return false;
@@ -279,9 +280,8 @@
public static String getPrimaryKeyAttributesListDeclaration(
ObjectModelClass clazz, boolean includeName) {
String attributes = "";
- for (ObjectModelAttribute attr : getElementsWithStereotype(
- clazz.getAttributes(),
- STEREOTYPE_PRIMARYKAY)) {
+ for (ObjectModelAttribute attr : getElementsWithStereotype(clazz
+ .getAttributes(), STEREOTYPE_PRIMARYKAY)) {
attributes += attr.getType();
if (includeName) {
attributes += " " + attr.getName();
@@ -299,7 +299,10 @@
}
public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) {
- return (attr.getReverseAttribute() != null) && (attr.getDeclaringElement().equals(attr.getReverseAttribute().getDeclaringElement())) && (!Util.isFirstAttribute(attr));
+ return (attr.getReverseAttribute() != null)
+ && (attr.getDeclaringElement().equals(attr
+ .getReverseAttribute().getDeclaringElement()))
+ && (!Util.isFirstAttribute(attr));
}
/**
@@ -311,10 +314,12 @@
* @return le nom de l'attribut de classe d'association
*/
public static String getAssocAttrName(ObjectModelAttribute attr) {
- String typeName = attr.getType().substring(attr.getType().lastIndexOf(".") + 1);
+ String typeName = attr.getType().substring(
+ attr.getType().lastIndexOf(".") + 1);
String result = attr.getName();
if (attr.getName().equalsIgnoreCase(typeName)) {
- result += GeneratorUtil.capitalize(attr.getAssociationClass().getName());
+ result += GeneratorUtil.capitalize(attr.getAssociationClass()
+ .getName());
}
return result;
}
@@ -383,7 +388,8 @@
}
public static boolean isBooleanType(ObjectModelAttribute attr) {
- return ("boolean".equals(attr.getType()) || "java.lang.Boolean".equals(attr.getType()));
+ return ("boolean".equals(attr.getType()) || "java.lang.Boolean"
+ .equals(attr.getType()));
}
/**
@@ -410,7 +416,8 @@
* @return true dans ce cas, false sinon
*/
public static boolean shouldBeAbstract(ObjectModelClass clazz) {
- return clazz != null && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz));
+ return clazz != null
+ && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz));
}
/**
@@ -433,8 +440,8 @@
ObjectModelAttribute attr, ObjectModel model) {
ObjectModelAttribute reverse = attr.getReverseAttribute();
//relation 1-n
- if (reverse != null && isNMultiplicity(attr) &&
- !isNMultiplicity(reverse)) {
+ if (reverse != null && isNMultiplicity(attr)
+ && !isNMultiplicity(reverse)) {
//Pas de navigabilité
if (!reverse.isNavigable()) {
//Il s'agit d'une entity
@@ -477,12 +484,12 @@
result = revers + "_" + name;
}
}
-// String result;
-// if (!Util.isFirstAttribute(attr)) {
-// result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName();
-// } else {
-// result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName();
-// }
+ // String result;
+ // if (!Util.isFirstAttribute(attr)) {
+ // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName();
+ // } else {
+ // result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName();
+ // }
return result.toLowerCase();
}
@@ -543,7 +550,8 @@
* @param sort flag to allow sort the result
* @return the list of filtred classes by their stereotype
*/
- public static List<ObjectModelClass> getEntityClasses(ObjectModel model, boolean sort) {
+ public static List<ObjectModelClass> getEntityClasses(ObjectModel model,
+ boolean sort) {
return getClassesByStereotype(STEREOTYPE_ENTITY, model, sort);
}
@@ -555,7 +563,8 @@
* @param sort flag to allow sort the result
* @return the list of filtred classes by their stereotype
*/
- public static List<ObjectModelClass> getClassesByStereotype(String stereotype, ObjectModel model, boolean sort) {
+ public static List<ObjectModelClass> getClassesByStereotype(
+ String stereotype, ObjectModel model, boolean sort) {
List<ObjectModelClass> classes = new ArrayList<ObjectModelClass>();
for (ObjectModelClass clazz : model.getClasses()) {
if (clazz.hasStereotype(stereotype)) {
@@ -563,11 +572,14 @@
}
}
if (sort && !classes.isEmpty()) {
- java.util.Collections.sort(classes, new java.util.Comparator<ObjectModelClass>() {
- public int compare(ObjectModelClass o1, ObjectModelClass o2) {
- return o1.getQualifiedName().compareTo(o2.getQualifiedName());
- }
- });
+ java.util.Collections.sort(classes,
+ new java.util.Comparator<ObjectModelClass>() {
+ public int compare(ObjectModelClass o1,
+ ObjectModelClass o2) {
+ return o1.getQualifiedName().compareTo(
+ o2.getQualifiedName());
+ }
+ });
}
return classes;
}
Deleted: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,784 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-package org.codelutin.topia.generator;
-
-import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.generator.Generator;
-import org.codelutin.generator.ObjectModelGenerator;
-import org.codelutin.generator.Util;
-import org.codelutin.generator.models.object.ObjectModelAssociationClass;
-import org.codelutin.generator.models.object.ObjectModelAttribute;
-import org.codelutin.generator.models.object.ObjectModelClass;
-import org.codelutin.generator.models.object.ObjectModelClassifier;
-import org.codelutin.generator.models.object.ObjectModelInterface;
-import org.codelutin.generator.models.object.ObjectModelOperation;
-import org.codelutin.generator.models.object.ObjectModelParameter;
-import org.codelutin.topia.service.TopiaApplicationServiceAbstract;
-
-/**
-* ServiceAbstractGenerator.java
-*
-* Created: 19 juin 2007
-*
-* @author dupont
-* @version $Revision$
-*
-* Le service abstrait etend TopiaApplicationServiceAbstract et implemente
-* l'interface du service.
-*
-* Genere l'implantation des methodes qui utilisent les methodes des DAO
-* et celles des entites.
-*
-* @see ServiceInterfaceGenerator
-* @see TopiaApplicationServiceAbstract
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class ServiceAbstractGenerator extends ObjectModelGenerator {
-
- private static final Log log = LogFactory
- .getLog(ServiceAbstractGenerator.class);
-
- public ServiceAbstractGenerator() {
- super();
- }
-
- public ServiceAbstractGenerator(Generator parent) {
- super(parent);
- }
-
- @Override
- public String getFilenameForInterface(ObjectModelInterface clazz) {
- return clazz.getQualifiedName().replace('.', File.separatorChar) + "Abstract.java";
- }
-
- @Override
- public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
-
- if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) {
- return;
- }
-
- // generer l'entete du service abstrait
- generateInterfaceHeader(output, interfacez);
-
- // generer les signatures des methodes metier du service
- generateInterfaceOperations(output, interfacez);
-
- // generer les methodes etendues en modifiant les signatures pour eviter les doublons (findAllByAddress heritee de Person et Employee)
- generateInheritedInterfaceOperations(output, interfacez);
-
- // generer les signatures des methodes metier des entites
- generateAssociatedClassOperations(output, interfacez);
-
- // generer les signatures des methodes des entites (getter/setter)
- generateMethodsGetter(output, interfacez);
-
-/*{} //<%=interfacez.getName()%>
-}*/
- }
-
- private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException {
- String copyright = GeneratorUtil.getCopyright(model);
- if (GeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-/*{package <%=classifier.getPackageName()%>;
-
-import java.util.Arrays;
-import java.util.List;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.service.TopiaApplicationServiceAbstract;
-import org.codelutin.topia.framework.TopiaContextImplementor;}*/
-
- // <%=clazz.getName()%>DAOAbstract
- classifier.getInterfaces();
- // ajouter les imports des interfaces de DAO
- for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
- if(parent.hasStereotype(GeneratorUtil.STEREOTYPE_DAO)){
- // r�cup�rer la classe de l'object model correspondant � la DAO
- String className = parent.getQualifiedName().replace("DAO", "");
- String interfaceName = parent.getQualifiedName()+"Abstract";
-/*{
-import <%=interfaceName%>;
-import <%=className%>;}*/
- }
- }
-
- if (GeneratorUtil.hasDocumentation(classifier)) {
-
-/*{
-/**
- *
- * <%=classifier.getDocumentation()%>
- *)
-}*/
- }
-/*{
-
-public abstract class <%=classifier.getName()+"Abstract"%> extends TopiaApplicationServiceAbstract implements <%=classifier.getName()%>{ }*/
- }
-
- private void generateMethodsGetter(Writer output, ObjectModelClassifier classifier) throws IOException {
-/*{ public String[] getMethods(){
- return methods;
- }
-}*/
- }
-
- private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) {
- ObjectModelOperation op = (ObjectModelOperation)it.next();
-/*{
-
- /**
- * Implementation a la charge du developpeur
-}*/
- if (GeneratorUtil.hasDocumentation(op)) {
-/*{ * <%=op.getName()%> : <%=op.getDocumentation()%>
-}*/
- }
- Collection<ObjectModelParameter> params = (Collection<ObjectModelParameter>)op.getParameters();
- for(ObjectModelParameter param : params) {
- if(log.isTraceEnabled()) {log.trace("Param" + param);}
-/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%>
-}*/
- }
-/*{ *)
- <%=op.getVisibility()%> abstract <%=op.getReturnType()%> <%=op.getName()%>(}*/
- String vir = "";
- for(ObjectModelParameter param : params){
- if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
-/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/
- vir = ", ";
- }
-/*{)}*/
- Set<String> exceptions = (Set<String>)op.getExceptions();
- vir = " throws ";
- for (String exception : exceptions) {
- if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);}
-/*{<%=vir%><%=exception%>}*/
- vir = ", ";
- }
-/*{;
-
-}*/
- }
- }
-
- private void generateInheritedInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
-
- for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
- // pour tous les DAOInterface
- if(parent.hasStereotype(GeneratorUtil.STEREOTYPE_DAO)){
-
- // r�cup�rer la classe de l'object model correspondant � la DAO
- String entityClassName = parent.getQualifiedName().replace("DAO", "");
- if(getModel().hasClass(entityClassName)){
- ObjectModelClass clazz = getModel().getClass(entityClassName);
-
- if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
-/*{
- /**
- * Supprime l'entite <%=clazz.getName()%> passee en parametre
- * @param entity l'entite a supprimer
- *)
- public void delete<%=clazz.getName()%>(<%=clazz.getQualifiedName()%> entity) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- dao.delete(entity);
- }
-
- /**
- * Creer l'entite <%=clazz.getName()%> avec les proprietes passees en parametre
- * @param properties les proprietes de l'entite a creer
- *)
- public <%=clazz.getQualifiedName()%> create<%=clazz.getName()%>(Object ... properties) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>) dao.create(properties);
- return entity;
- }
-
- /**
- * Mise a jour de l'entite <%=clazz.getName()%> passee en parametre
- * @param entity l'entite a mettre a jour
- *)
- public <%=clazz.getQualifiedName()%> update<%=clazz.getName()%>(<%=clazz.getQualifiedName()%> entity) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entit = (<%=clazz.getName()%>) dao.update(entity);
- return entit;
- }
-
- /**
- * Retourne tous les <%=clazz.getName()%>
- * @return une liste
- *)
- public List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>() throws TopiaException {
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- List<<%=clazz.getName()%>> result = dao.findAll();
- return result;
- }
-
- /**
- * Retourne le <%=clazz.getName()%> par son TopiaId
- * @return le <%=clazz.getName()%>
- *)
- public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>ByTopiaId(String v) throws TopiaException {
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(v);
- return entity;
- }
-}*/
- for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
- if (!attr.isNavigable()) {
- continue;
- }
-
- if (!Util.isNMultiplicity(attr)) {
- generateNoNMultiplicity(output, attr, clazz, false);
- } else {
- generateNMultiplicity(output, attr, clazz, false);
- }
- }
-
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz;
- Iterator it = assocClass.getParticipantsAttributes().iterator();
- while (it.hasNext()) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
- if (attr != null) {
- if (!Util.isNMultiplicity(attr)) {
- generateNoNMultiplicity(output, attr, clazz, true);
- } else {
- generateNMultiplicity(output, attr, clazz, true);
- }
- }
- }
- }
- }
- }
- }
- }
-
- protected void generateNoNMultiplicity(Writer output, ObjectModelAttribute attr, ObjectModelClass clazz, boolean isAssoc) throws IOException {
- String propertyName = attr.getName();
- if (!isAssoc && attr.hasAssociationClass()) {
- propertyName = GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName()) + "." + propertyName;
- }
-/*{
- /**
- * Retourne le premier element trouve ayant comme valeur pour l'attribut
- * <%=attr.getName()%> le parametre
- * @param v la valeur que doit avoir <%=attr.getName()%>
- * @return un element ou null
- *)
- public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = dao.findBy<%=GeneratorUtil.capitalize(attr.getName())%>(v);
- return entity;
- };
-
- /**
- * Retourne les elements ayant comme valeur pour l'attribut
- * <%=attr.getName()%> le parametre
- * @param v la valeur que doit avoir <%=attr.getName()%>
- * @return une liste
- *)
- public List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- List<<%=clazz.getName()%>> entityList = dao.findAllBy<%=GeneratorUtil.capitalize(attr.getName())%>(v);
- return entityList;
- };
-}*/
- if (attr.hasAssociationClass()) {
-/*{
- /**
- * Retourne le premier element trouve ayant comme valeur pour l'attribut
- * <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> le parametre
- * @param value la valeur que doit avoir <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>
- * @return un element ou null
- *)
- public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getAssociationClass().getName())%>(<%=attr.getAssociationClass().getQualifiedName()%> value) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = dao.findBy<%=GeneratorUtil.capitalize(attr.getName())%>(v);
- return entity;
- };
-
- /**
- * Retourne les elements ayant comme valeur pour l'attribut
- * <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> le param�tre
- * @param value la valeur que doit avoir <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>
- * @return une liste
- *)
- public List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getAssociationClass().getName())%>(<%=attr.getAssociationClass().getQualifiedName()%> value) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- List<<%=clazz.getName()%>> entityList = dao.findAllBy<%=GeneratorUtil.capitalize(attr.getName())%>(v);
- return entityList;
- };
-}*/
- }
- }
-
- protected void generateNMultiplicity(Writer output, ObjectModelAttribute attr, ObjectModelClass clazz, boolean isAssoc) throws IOException {
-/*{
- /**
- * Retourne le premier element trouve dont l'attribut
- * <%=attr.getName()%> contient le parametre
- * @param v la valeur que doit contenir <%=attr.getName()%>
- * @return un element ou null
- *)
- public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>Contains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>) dao.findContainsProperties("<%=GeneratorUtil.toLowerCaseFirstLetter(attr.getName())%>", Arrays.asList(v));
- return entity;
- };
-
- /**
- * Retourne les elements trouve dont l'attribut
- * <%=attr.getName()%> contient le parametre
- * @param v la valeur que doit contenir <%=attr.getName()%>
- * @return une liste
- *)
- public List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>Contains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- List<<%=clazz.getName()%>> entityList = dao.findAllContainsProperties("<%=GeneratorUtil.toLowerCaseFirstLetter(attr.getName())%>", Arrays.asList(v));
- return entityList;
- };
-}*/
- }
-
-
- private void generateAssociatedClassOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
- // pour tous les DAOInterface
- if(parent.hasStereotype(GeneratorUtil.STEREOTYPE_DAO)){
-
- // r�cup�rer la classe de l'object model correspondant � la DAO
- String entityClassName = null;
- entityClassName = parent.getQualifiedName().replace("DAO", "");
- if(getModel().hasClass(entityClassName)){
- ObjectModelClass clazz = getModel().getClass(entityClassName);
- generateFromDAOClass(output, clazz);
- }
- }
- }
- }
-
- private void generateFromDAOClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
-
- for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!attr.isNavigable()
- && !hasUnidirectionalRelationOnAbstractType(reverse, model)) {
- continue;
- }
- if (!Util.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La valeur de l'attribut <%=attr.getName()%> � positionner.
- *)
- public void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.set<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
- usedContextImpl.commitTransaction();
- }
-
-}*/
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @return La valeur de l'attribut <%=attr.getName()%>.
- *)
- public <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- return entity.get<%=Util.capitalize(attr.getName())%>();
- }
-
-}*/
- } else {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
-/*{ /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La valeur de l'attribut <%=attr.getAssociationClass().getName()%> � positionner.
- *)
- public void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.set<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
- }
-
- /**
- * @return La valeur de l'attribut <%=attr.getAssociationClass().getName()%>.
- *)
- public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- return entity.get<%=Util.capitalize(assocAttrName)%>();
- }
-
-}*/
- }
- } else { //NMultiplicity
- if (!attr.hasAssociationClass()) { //M�thodes remplac�es par des add/set sur les classes d'assoc
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> � ajouter.
- *)
- public void add<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.add<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
- }
-
- /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> Les instances de <%=attr.getName()%> � ajouter.
- *)
- public void addAll<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.addAll<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
- }
-
- /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La Collection de <%=attr.getName()%> � positionner.
- *)
- public void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.set<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
- }
-
- /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> � retirer.
- *)
- public void remove<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.remove<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
- }
-
- /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * Vide la Collection de <%=attr.getName()%>.
- *)
- public void clear<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.clear<%=Util.capitalize(attr.getName())%>();
- }
-
-}*/
- } else {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
-/*{ /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> � ajouter.
- *)
- public void add<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.add<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
- }
-
- /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> Les instances de <%=attr.getAssociationClass().getName()%> � ajouter.
- *)
- public void addAll<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.addAll<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
- }
-
- /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La Collection de <%=attr.getAssociationClass().getName()%> � positionner.
- *)
- public void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.set<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
- }
-
- /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> � retirer.
- *)
- public void remove<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.remove<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
- }
-
- /**
- * Vide la Collection de <%=attr.getAssociationClass().getName()%>.
- *)
- public void clear<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.clear<%=Util.capitalize(assocAttrName)%>();
- }
-
-}*/
- }
-
- if (!attr.hasAssociationClass()) {
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @return La Liste de <%=attr.getName()%>.
- *)
- public <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- return entity.get<%=Util.capitalize(attr.getName())%>();
- }
-
- /**
- * @return Le nombre d'�l�ments de la collection <%=attr.getName()%>.
- *)
- public int size<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- return entity.size<%=Util.capitalize(attr.getName())%>();
- }
-
-}*/
- } else {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
-/*{ /**
- * @return La liste des attributs <%=attr.getAssociationClass().getName()%>.
- *)
- public <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- return entity.get<%=Util.capitalize(assocAttrName)%>();
- }
-
- /**
- * @return L'attribut <%=attr.getAssociationClass().getName()%> associ� � la valeur <code>value</code> de l'attribut <%=attr.getName()%>.
- *)
- public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> value) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- return entity.get<%=Util.capitalize(assocAttrName)%>((<%=attr.getType()%>) value);
- }
-
- /**
- * @return Le nombre d'�l�ments de la collection <%=attr.getName()%>.
- *)
- public int size<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- return entity.size<%=Util.capitalize(assocAttrName)%>();
- }
-
-}*/
- }
- }
- }
-
- //M�thodes d'acc�s aux attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
- for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) {
- ObjectModelAttribute attr = (ObjectModelAttribute) i.next();
- if (attr != null) {
- String type = attr.getType();
- String name = attr.getName();
- generateAssociationAccessors(output, clazz, name, type);
- if (attr.getReverseAttribute() == null) {
- type = ((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName();
- name = attr.getDeclaringElement().getName();
- generateAssociationAccessors(output, clazz, name, type);
- }
- }
- }
- }
-
- generateInterfaceOperationsOfClass(output, clazz);
-
- }
-
- private void generateInterfaceOperationsOfClass(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) {
- ObjectModelOperation op = (ObjectModelOperation)it.next();
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(op)) {
-/*{ * <%=op.getName()%> : <%=op.getDocumentation()%>
-}*/
- }
- Collection<ObjectModelParameter> params = (Collection<ObjectModelParameter>)op.getParameters();
- for(ObjectModelParameter param : params) {
- if(log.isTraceEnabled()) {log.trace("Param" + param);}
-/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%>
- }*/
- }
-/*{ *)
- <%=op.getVisibility()%> <%=op.getReturnType()%> <%=op.getName()%>Of<%=classifier.getName()%>(String topiaId}*/
- String vir = ",";
- for(ObjectModelParameter param : params){
- if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
-/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/
- }
-/*{)}*/
- Set<String> exceptions = (Set<String>)op.getExceptions();
- if(exceptions.isEmpty()){
-/*{throws TopiaException}*/
- }
- vir = " throws ";
- for (String exception : exceptions) {
- if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);}
-/*{<%=vir%><%=exception%>}*/
- vir = ", ";
- }
-/*{{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=classifier.getName()%>DAOAbstract dao = (<%=classifier.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=classifier.getName()%>.class);
- <%=classifier.getName()%> entity = (<%=classifier.getName()%>)dao.findByTopiaId(topiaId);
-}*/
- if(!op.getReturnType().toString().equalsIgnoreCase("void")){
-/*{ return }*/
- }
-/*{ entity.<%=op.getName()%>(}*/
- vir = "";
- for(ObjectModelParameter param : params){
- if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
-/*{<%=vir%><%=param.getName()%>}*/
- vir = ", ";
- }
-/*{);
- }
-}*/
-
-/*{
-
-}*/
- }
- }
-
- private void generateAssociationAccessors(Writer output, ObjectModelClass clazz, String name, String type) throws IOException {
- /*{ /**
- * @param value La valeur de l'attribut <%=name%> � positionner.
- *)
- public void set<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId, <%=type%> value) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- entity.set<%=Util.capitalize(name)%>( value);
- }
-
- /**
- * @return La valeur de l'attribut <%=name%>.
- *)
- public <%=type%> get<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
- TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
- <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
- <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
- return entity.get<%=Util.capitalize(name)%>();
- }
-
- }*/
- }
-
-} //ServiceAbstractGenerator
Deleted: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,137 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.generator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.generator.Generator;
-import org.codelutin.generator.ObjectModelGenerator;
-import org.codelutin.generator.models.object.ObjectModelClass;
-import org.codelutin.generator.models.object.ObjectModelClassifier;
-import org.codelutin.generator.models.object.ObjectModelInterface;
-import org.codelutin.generator.models.object.ObjectModelOperation;
-import org.codelutin.generator.models.object.ObjectModelParameter;
-import org.codelutin.topia.service.TopiaApplicationServiceAbstract;
-
-/**
-* ServiceImplGenerator.java
-*
-* Created: 19 juin 2007
-*
-* @author ndupont
-* @version $Revision$
-*
-* Genere l'entete du service implante.
-*
-* L'implementation du service herite du service abstrait et donc des methodes qui
-* appellent celles des DAOs et celles des entites.
-*
-* L'implementation des methodes metiers est a la charge du developpeur.
-*
-* @see ServiceInterfaceGenerator
-* @see TopiaApplicationServiceAbstract
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class ServiceImplGenerator extends ObjectModelGenerator {
-
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory
- .getLog(ServiceImplGenerator.class);
-
- public ServiceImplGenerator() {
- super();
- }
-
- public ServiceImplGenerator(Generator parent) {
- super(parent);
- }
-
- @Override
- public String getFilenameForInterface(ObjectModelInterface interfacez) {
- return interfacez.getQualifiedName().replace('.', File.separatorChar) + "Impl.java";
- }
-
- @Override
- public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
-
- if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) {
- return;
- }
-
- // pas de génération s'il y a des méthodes métier du service à implémenter
- if(interfacez.getOperations().size()>0){
- return;
- }
-
- // pas de génération s'il y a des méthodes métiers des entités à implémenter
- for (Iterator i=interfacez.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
- // pour tous les DAOInterface
- if(parent.hasStereotype(GeneratorUtil.STEREOTYPE_DAO)){
- // récupérer la classe de l'object model correspondant à la DAO
- String entityClassName = null;
- entityClassName = parent.getQualifiedName().replace("DAO", "");
- if(getModel().hasClass(entityClassName)){
- ObjectModelClass clazz = getModel().getClass(entityClassName);
- if(clazz.getOperations().size()>0)
- return;
- }
- }
- }
-
- // générer l'entête du service
- generateInterfaceHeader(output, interfacez);
-
-/*{} //<%=interfacez.getName()%>
-}*/
- }
-
- private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException {
- String copyright = GeneratorUtil.getCopyright(model);
- if (GeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-/*{package <%=classifier.getPackageName()%>;}*/
-
- if (GeneratorUtil.hasDocumentation(classifier)) {
-
-/*{
-/**
- *
- * <%=classifier.getDocumentation()%>
- *)
-}*/
- }
-/*{
-
-public class <%=classifier.getName()+"Impl"%> extends <%=classifier.getName()+"Abstract"%>{ }*/
- }
-
-} //ServiceImplGenerator
Deleted: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,689 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.generator;
-
-import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.generator.Generator;
-import org.codelutin.generator.ObjectModelGenerator;
-import org.codelutin.generator.Util;
-import org.codelutin.generator.models.object.ObjectModelAssociationClass;
-import org.codelutin.generator.models.object.ObjectModelAttribute;
-import org.codelutin.generator.models.object.ObjectModelClass;
-import org.codelutin.generator.models.object.ObjectModelClassifier;
-import org.codelutin.generator.models.object.ObjectModelInterface;
-import org.codelutin.generator.models.object.ObjectModelOperation;
-import org.codelutin.generator.models.object.ObjectModelParameter;
-import org.codelutin.topia.service.TopiaApplicationService;
-
-/**
-* ServiceInterfaceGenerator.java
-*
-* Created: 14 juin 2007
-*
-* @author ndupont
-* @version $Revision$
-*
-* L'interface du service etend TopiaApplicationService
-*
-* Genere les interfaces des services, genere les signatures de toutes les methodes des
-* DAO et des entites utilises. Les signatures de methodes sont modifiees pour eviter les
-* doublons.
-*
-* Par exemple :
-*
-* findAllByAddress d'un PersonDAO et d'un EmployeeDAO deviennent respectivement
-* findAllPersonByAddress et findAllEmployeeByAddress.
-*
-* getTask d'entites Cost et Bill deviennent respectivement getTaskOfBill, getTaskOfCost
-*
-* @see TopiaApplicationService
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class ServiceInterfaceGenerator extends ObjectModelGenerator {
-
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory
- .getLog(ServiceInterfaceGenerator.class);
-
- private static final String DAO = "dao";
-
- // methodes du service <signature methode>
- private List<String> methods = new ArrayList<String>();
-
- public ServiceInterfaceGenerator() {
- super();
- }
-
- public ServiceInterfaceGenerator(Generator parent) {
- super(parent);
- }
-
- @Override
- public String getFilenameForInterface(ObjectModelInterface interfacez) {
- return interfacez.getQualifiedName().replace('.', File.separatorChar) + ".java";
- }
-
- @Override
- public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
-
- if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) {
- return;
- }
-
- // g�n�rer l'ent�te de l'interface du service
- generateInterfaceHeader(output, interfacez);
-
- // g�n�rer les signatures des m�thodes m�tiers du service
- generateInterfaceOperations(output, interfacez);
-
- // g�n�rer les signatures des m�thodes des DAOs
- generateInheritedInterfaceOperations(output, interfacez);
-
- // g�n�rer les signatures des m�thodes des entit�s (getter/setter)
- generateMethodsGetter(output, interfacez);
-
- // g�n�rer les signatures des m�thodes m�tier des entit�s (getter/setter)
- generateAssociatedClassOperations(output, interfacez);
-
-/*{
- // methodes du service
- public String[] methods = {
-}*/
- String vir=" ";
- for(String m : methods){
-/*{ <%=vir%>"<%=m%>"
-}*/
- vir=", ";
- }
-/*{ }; }*/
-/*{
- } //<%=interfacez.getName()%>
-}*/
- }
-
- private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException {
- String copyright = GeneratorUtil.getCopyright(model);
- if (GeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-/*{package <%=classifier.getPackageName()%>;
-
-import java.util.List;
-import org.codelutin.topia.TopiaException;
-
-}*/
- if (GeneratorUtil.hasDocumentation(classifier)) {
-/*{
-/**
- * <%=classifier.getDocumentation()%>
- *)
-}*/
- }
-/*{public interface <%=classifier.getName()%> extends }*/
- String extendClass = "";
- for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
- // pas pour les interfaces de DAO
- if(!parent.hasStereotype(DAO)){
- extendClass += parent.getQualifiedName();
- extendClass += ", ";
- }
- }
-
- if (classifier instanceof ObjectModelClass) {
- ObjectModelClass clazz = (ObjectModelClass)classifier;
- for (Iterator i=clazz.getSuperclasses().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
- if (parent.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) {
- extendClass += parent.getQualifiedName();
- }
- extendClass += ", ";
- }
- }
-
-/*{<%=extendClass%>org.codelutin.topia.service.TopiaApplicationService {
-
-}*/
- }
-
- private void generateMethodsGetter(Writer output, ObjectModelClassifier classifier) throws IOException {
-/*{ public abstract String[] getMethods();
-
- // =====> methodes utilisant celles des entites <====
-}*/
- }
-
-
- private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) {
- ObjectModelOperation op = (ObjectModelOperation)it.next();
-
- String method = op.getReturnType()+ " "+op.getName()+"(";
-/*{
- /**
- * Methode metier
-}*/
- if (GeneratorUtil.hasDocumentation(op)) {
-/*{ * <%=op.getName()%> : <%=op.getDocumentation()%>
-}*/
- }
- Collection<ObjectModelParameter> params = (Collection<ObjectModelParameter>)op.getParameters();
- for(ObjectModelParameter param : params) {
- if(log.isTraceEnabled()) {log.trace("Param" + param);}
-/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%>
-}*/
- }
-/*{ *)
- <%=op.getVisibility()%> <%=op.getReturnType()%> <%=op.getName()%>(}*/
- String vir = "";
- for(ObjectModelParameter param : params){
- method += " " + param.getType()+" "+param.getName();
- if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
-/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/
- vir = ", ";
- }
-/*{)}*/
- Set<String> exceptions = (Set<String>)op.getExceptions();
- vir = " throws ";
- for (String exception : exceptions) {
- if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);}
-/*{<%=vir%><%=exception%>}*/
- vir = ", ";
- }
-/*{;
-
-}*/
- // ajout des methodes
- methods.add(method+")");
- }
- }
-
- private void generateInheritedInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
-/*{
- // =====> methodes utilisant celles des daos <====
-}*/
- for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
- // pour tous les DAOInterface
- if(parent.hasStereotype(DAO)){
-
- // r�cup�rer la classe de l'object model correspondant � la DAO
- String entityClassName = null;
- entityClassName = parent.getQualifiedName().replace("DAO", "");
- if(getModel().hasClass(entityClassName)){
- ObjectModelClass clazz = getModel().getClass(entityClassName);
-
- if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
-
- // ajouter les methodes � la liste
- methods.add("void delete"+clazz.getName()+"("+clazz.getName()+" entity)");
- methods.add(clazz.getName()+" create"+clazz.getName()+"(Object ... properties)");
- methods.add(clazz.getName()+" update"+clazz.getName()+"("+clazz.getName()+")");
- methods.add("List<"+clazz.getName()+"> findAll"+clazz.getName()+"()");
- methods.add(clazz.getName()+" find"+clazz.getName()+"ByTopiaId(String v)");
-
-/*{
- /**
- * Supprime l'entite <%=clazz.getName()%> passee en parametre
- * @param entity l'entite a supprimer
- *)
- public abstract void delete<%=clazz.getName()%>(<%=clazz.getQualifiedName()%> entity) throws TopiaException;
-
- /**
- * Creer l'entite <%=clazz.getName()%> avec les proprietes passees en parametre
- * @param entity l'entite a mettre a jour
- *)
- public abstract <%=clazz.getQualifiedName()%> create<%=clazz.getName()%>(Object ... properties) throws TopiaException;
-
- /**
- * Mise a jour de l'entite <%=clazz.getName()%> passee en parametre
- * @param properties les proprietes de l'entite a creer
- *)
- public abstract <%=clazz.getQualifiedName()%> update<%=clazz.getName()%>(<%=clazz.getQualifiedName()%> entity) throws TopiaException;
-
- /**
- * Retourne tous les <%=clazz.getName()%>
- * @return une liste
- *)
- public abstract List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>() throws TopiaException;
-
- /**
- * Retourne le <%=clazz.getName()%> par son TopiaId
- * @return le <%=clazz.getName()%>
- *)
- public abstract <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>ByTopiaId(String v) throws TopiaException;
-}*/
- for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
- if (!attr.isNavigable()) {
- continue;
- }
-
- if (!Util.isNMultiplicity(attr)) {
- generateNoNMultiplicity(output, attr, clazz, false);
- } else {
- generateNMultiplicity(output, attr, clazz, false);
- }
- }
-
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz;
- Iterator it = assocClass.getParticipantsAttributes().iterator();
- while (it.hasNext()) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
- if (attr != null) {
- if (!Util.isNMultiplicity(attr)) {
- generateNoNMultiplicity(output, attr, clazz, true);
- } else {
- generateNMultiplicity(output, attr, clazz, true);
- }
- }
- }
- }
- }
- }
- }
- }
-
- protected void generateNoNMultiplicity(Writer output, ObjectModelAttribute attr, ObjectModelClass clazz, boolean isAssoc) throws IOException {
- String propertyName = attr.getName();
- if (!isAssoc && attr.hasAssociationClass()) {
- propertyName = GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName()) + "." + propertyName;
- }
-
- // ajouter les methodes � la liste
- methods.add(clazz.getName()+" find"+clazz.getName()+"By"+GeneratorUtil.capitalize(attr.getName())+"("+attr.getType()+" v)");
- methods.add("List<"+clazz.getName()+"> findAll"+clazz.getName()+"By"+GeneratorUtil.capitalize(attr.getName())+"("+attr.getType()+" v)");
-/*{
- /**
- * Retourne le premier element trouve ayant comme valeur pour l'attribut
- * <%=attr.getName()%> le parametre
- * @param v la valeur que doit avoir <%=attr.getName()%>
- * @return un element ou null
- *)
- public abstract <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException;
- /**
- * Retourne les �l�ments ayant comme valeur pour l'attribut
- * <%=attr.getName()%> le param�tre
- * @param v la valeur que doit avoir <%=attr.getName()%>
- * @return une liste
- *)
- public abstract List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException;
-}*/
- if (attr.hasAssociationClass()) {
- methods.add(clazz.getName() +" find"+clazz.getName()+"By"+GeneratorUtil.capitalize(attr.getAssociationClass().getName())+"("+attr.getAssociationClass().getQualifiedName()+" value)");
- methods.add("List<"+clazz.getName()+"> findAll"+clazz.getName()+"By"+GeneratorUtil.capitalize(attr.getAssociationClass().getName())+"("+attr.getAssociationClass().getQualifiedName()+" value)");
-/*{
- /**
- * Retourne le premier element trouve ayant comme valeur pour l'attribut
- * <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> le parametre
- * @param value la valeur que doit avoir <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>
- * @return un element ou null
- *)
- public abstract <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getAssociationClass().getName())%>(<%=attr.getAssociationClass().getQualifiedName()%> value) throws TopiaException;
- /**
- * Retourne les �l�ments ayant comme valeur pour l'attribut
- * <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> le param�tre
- * @param value la valeur que doit avoir <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>
- * @return une liste
- *)
- public abstract List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getAssociationClass().getName())%>(<%=attr.getAssociationClass().getQualifiedName()%> value) throws TopiaException;
-}*/
- }
- }
-
- protected void generateNMultiplicity(Writer output, ObjectModelAttribute attr, ObjectModelClass clazz, boolean isAssoc) throws IOException {
- methods.add(clazz.getName() + " find"+clazz.getName()+"Contains"+GeneratorUtil.capitalize(attr.getName())+"("+attr.getType()+" ... v)");
- methods.add("List<"+clazz.getName()+"> findAll"+clazz.getName()+"Contains"+GeneratorUtil.capitalize(attr.getName())+"("+attr.getType()+" ... v)");
-/*{
- /**
- * Retourne le premier element trouve dont l'attribut
- * <%=attr.getName()%> contient le parametre
- * @param v la valeur que doit contenir <%=attr.getName()%>
- * @return un element ou null
- *)
- public abstract <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>Contains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) throws TopiaException;
- /**
- * Retourne les elements trouve dont l'attribut
- * <%=attr.getName()%> contient le parametre
- * @param v la valeur que doit contenir <%=attr.getName()%>
- * @return une liste
- *)
- public abstract List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>Contains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) throws TopiaException;
-}*/
- }
-
- private void generateAssociatedClassOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
- // pour tous les DAOInterface
- if(parent.hasStereotype(DAO)){
- // r�cup�rer la classe de l'object model correspondant � la DAO
- String entityClassName = null;
- entityClassName = parent.getQualifiedName().replace("DAO", "");
- if(getModel().hasClass(entityClassName)){
- ObjectModelClass clazz = getModel().getClass(entityClassName);
- generateFromDAOClass(output, clazz);
-
- }
- }
- }
- }
-
- private void generateFromDAOClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
- return;
- }
-
- for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!attr.isNavigable()
- && !hasUnidirectionalRelationOnAbstractType(reverse, model)) {
- continue;
- }
- if (!Util.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
- methods.add("void set"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+attr.getType()+ " "+Util.toLowerCaseFirstLetter(attr.getName())+")");
-
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La valeur de l'attribut <%=attr.getName()%> � positionner.
- *)
- public abstract void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
-
-}*/
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
- methods.add(attr.getType()+" get"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId)");
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @return La valeur de l'attribut <%=attr.getName()%>.
- *)
- public abstract <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
-}*/
- } else {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
- methods.add("void set"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+attr.getAssociationClass().getName()+" "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
- methods.add(attr.getAssociationClass().getName()+" get"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId)");
-
-/*{ /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La valeur de l'attribut <%=attr.getAssociationClass().getName()%> � positionner.
- *)
- public abstract void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
-
- /**
- * @return La valeur de l'attribut <%=attr.getAssociationClass().getName()%>.
- *)
- public abstract <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
-}*/
- }
- } else { //NMultiplicity
- if (!attr.hasAssociationClass()) { //M�thodes remplac�es par des add/set sur les classes d'assoc
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
- methods.add("void add"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+attr.getType()+" "+Util.toLowerCaseFirstLetter(attr.getName())+")");
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> � ajouter.
- *)
- public abstract void add<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
-
- /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
- methods.add("void addAll"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+(attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getType()+"> "+Util.toLowerCaseFirstLetter(attr.getName())+")");;
-
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> Les instances de <%=attr.getName()%> � ajouter.
- *)
- public abstract void addAll<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
-
- /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
- methods.add("void set"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+ (attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getType()+"> "+Util.toLowerCaseFirstLetter(attr.getName())+")");
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La Collection de <%=attr.getName()%> � positionner.
- *)
- public abstract void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
-
- /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
- methods.add("void remove"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+attr.getType()+ " "+Util.toLowerCaseFirstLetter(attr.getName())+")");
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> � retirer.
- *)
- public abstract void remove<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
-
- /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
- methods.add("void clear"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId)");
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * Vide la Collection de <%=attr.getName()%>.
- *)
- public abstract void clear<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
-}*/
- } else {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
- methods.add("void add"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+attr.getAssociationClass().getName()+" "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
- methods.add("void addAll"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+(attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getAssociationClass().getName()+"> "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
- methods.add("void set"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+(attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getAssociationClass().getName()+"> "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
- methods.add("void remove"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+attr.getAssociationClass().getName()+" "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
- methods.add("void clear"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId)");
-/*{ /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> � ajouter.
- *)
- public abstract void add<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
-
- /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> Les instances de <%=attr.getAssociationClass().getName()%> � ajouter.
- *)
- public abstract void addAll<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
-
- /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La Collection de <%=attr.getAssociationClass().getName()%> � positionner.
- *)
- public abstract void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
-
- /**
- * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> � retirer.
- *)
- public abstract void remove<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
-
- /**
- * Vide la Collection de <%=attr.getAssociationClass().getName()%>.
- *)
- public abstract void clear<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
-}*/
- }
-
- if (!attr.hasAssociationClass()) {
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(attr)) {
- methods.add((attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getType()+"> get"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId)");
- methods.add("int size"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId)");
-
-/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
-}*/
- }
-/*{ * @return La Liste de <%=attr.getName()%>.
- *)
- public abstract <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
- /**
- * @return Le nombre d'�l�ments de la collection <%=attr.getName()%>.
- *)
- public abstract int size<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
-}*/
- } else {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
- methods.add((attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getAssociationClass().getName()+"> get"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"Of"+clazz.getName()+"(String topiaId)");
- methods.add(attr.getAssociationClass().getName()+" get"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+attr.getType()+" value)");
- methods.add("int size"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId)");
-/*{ /**
- * @return La liste des attributs <%=attr.getAssociationClass().getName()%>.
- *)
- public abstract <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
- /**
- * @return L'attribut <%=attr.getAssociationClass().getName()%> associ� � la valeur <code>value</code> de l'attribut <%=attr.getName()%>.
- *)
- public abstract <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> value) throws TopiaException;
-
- /**
- * @return Le nombre d'�l�ments de la collection <%=attr.getName()%>.
- *)
- public abstract int size<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
-}*/
- }
- }
- }
-
- //M�thodes d'acc�s aux attributs d'une classe d'associations
- if (clazz instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
- for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) {
- ObjectModelAttribute attr = (ObjectModelAttribute) i.next();
- if (attr != null) {
- String type = attr.getType();
- String name = attr.getName();
- generateAssociationAccessors(output, clazz, name, type);
- if (attr.getReverseAttribute() == null) {
- type = ((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName();
- name = attr.getDeclaringElement().getName();
- generateAssociationAccessors(output, clazz, name, type);
- }
- }
- }
- }
-
- generateInterfaceOperationsOfClass(output, clazz);
-
- }
-
- private void generateInterfaceOperationsOfClass(Writer output, ObjectModelClassifier classifier) throws IOException {
- for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) {
- ObjectModelOperation op = (ObjectModelOperation)it.next();
- String method = op.getReturnType()+ " "+op.getName()+"(";
-/*{ /**
-}*/
- if (GeneratorUtil.hasDocumentation(op)) {
-/*{ * <%=op.getName()%> : <%=op.getDocumentation()%>
-}*/
- }
- Collection<ObjectModelParameter> params = (Collection<ObjectModelParameter>)op.getParameters();
- for(ObjectModelParameter param : params) {
- if(log.isTraceEnabled()) {log.trace("Param" + param);}
-/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%>
- }*/
- }
-/*{ *)
- <%=op.getVisibility()%> abstract <%=op.getReturnType()%> <%=op.getName()%>Of<%=classifier.getName()%>(String topiaId}*/
- if(params.size()>0){
-/*{, }*/
- }
- String vir = "";
- for(ObjectModelParameter param : params){
- if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
- method += " " + param.getType()+" "+param.getName();
-/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/
- vir = ", ";
- }
-/*{)}*/
- Set<String> exceptions = (Set<String>)op.getExceptions();
- if(exceptions.isEmpty()){
-/*{throws TopiaException}*/
- }
- vir = " throws ";
- for (String exception : exceptions) {
- if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);}
-/*{<%=vir%><%=exception%>}*/
- vir = ", ";
- }
-/*{;
-
-}*/
- methods.add(method);
- }
- }
-
- private void generateAssociationAccessors(Writer output, ObjectModelClass clazz, String name, String type) throws IOException {
- methods.add("=> "+"void set"+Util.capitalize(name)+"Of"+clazz.getName()+"(String topiaId, "+type+" value)");
- methods.add("=> "+type+" get"+Util.capitalize(name)+"Of"+clazz.getName()+"(String topiaId)");
-/*{ /**
- * @param value La valeur de l'attribut <%=name%> � positionner.
- *)
- public abstract void set<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId, <%=type%> value) throws TopiaException;
-
- /**
- * @return La valeur de l'attribut <%=name%>.
- *)
- public abstract <%=type%> get<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
-
-}*/
- }
-
-} //ServiceInterfaceGenerator
Deleted: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,612 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.generator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.generator.MonitorWriter;
-import org.codelutin.generator.StateModelGenerator;
-import org.codelutin.generator.Util;
-import org.codelutin.generator.models.state.StateModel;
-import org.codelutin.generator.models.state.StateModelComplexState;
-import org.codelutin.generator.models.state.StateModelSimpleState;
-import org.codelutin.generator.models.state.StateModelState;
-import org.codelutin.generator.models.state.StateModelStateChart;
-import org.codelutin.generator.models.state.StateModelTransition;
-
-/**
- * Genere la navigation basee sur le framework Tapestry 5
- * a partir de la representation StateModel
- *
- * @see org.codelutin.generator.StateModelGenerator
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class TapestryWebGenerator extends StateModelGenerator {
-
- /** logger */
- private static final Log log = LogFactory.getLog(TapestryWebGenerator.class);
-
- /** Already asssigned use case states names */
- protected List<String> assignedUseCaseStateNames;
-
- protected StateModel model;
-
- /**
- * Default Constructeur
- */
- public TapestryWebGenerator() {
- assignedUseCaseStateNames = new ArrayList<String>();
- }
-
- /**
- * Redefintion pour une generation specifique tapestry
- *
- * @param stateModel Le modele d'état
- * @param destDir le dossier de destination
- */
- @Override
- public void generate(StateModel stateModel, File destDir) throws IOException {
-
- this.model = stateModel;
-
- // pour tous les diagramme du model
- for (StateModelStateChart chart : stateModel.getStateCharts()) {
- generate(chart,chart.getStates(),destDir);
-
- // generate use case engine
- generateUseCaseEngineFromModel(stateModel, chart,destDir);
- }
- }
-
- /**
- * Appele par lutin generator pour tous les etats du model
- * @param chart
- * @return
- */
- protected String getFilenameFromState(StateModelStateChart chart,StateModelState state) {
- return (getPackageFromState(chart) + '.' + getNameFromState(state)).replace('.',
- File.separatorChar) + ".java";
- }
-
- /**
- * Get generated class name from state
- *
- * Prefix it with "Abstract"
- *
- * @param state state
- * @return name
- */
- protected String getNameFromState(StateModelState state) {
- return "Abstract" + Util.toUpperCaseFirstLetter(state.getName());
- }
-
- /**
- * Return specifique tapestry package name.
- *
- * Detect "web" patern and replace it with "web.pages".
- *
- * @param chart the chart
- * @return a tapestry package name
- */
- protected String getPackageFromState(StateModelStateChart chart) {
- return chart.getPackageName().replaceFirst("web", "web.pages");
- }
-
- /**
- * Return specifique tapestry package name (base)
- *
- * Detect "web.*" patern and replace it with "web.base"
- * Component are placed into "base" directory
- *
- * @param chart the chart
- * @return a tapestry package name
- */
- protected String getPackageFromComponents(StateModelStateChart chart) {
- return chart.getPackageName().replaceFirst("web.*", "web.base");
- }
-
- /**
- * Generate a collection of states
- *
- * @param chart the chart
- * @param states states collection
- * @throws IOException
- */
- protected void generate(StateModelStateChart chart, Collection<StateModelState> states, File destDir) throws IOException {
-
- // et tous les états de ces diagrammes
- for (Object oState : states.toArray()) {
- generateFromState(chart,(StateModelState)oState,destDir);
- }
- }
-
- /**
- * Generate a state.
- *
- * This state can be complexe, so the method is recusively called.
- *
- * @param chart the parent chart
- * @param state the current state
- * @throws IOException
- */
- protected void generateFromState(StateModelStateChart chart, StateModelState state, File destDir) throws IOException {
-
- // complexe
- if(state.isComplex()) {
- StateModelComplexState complexeState = (StateModelComplexState)state;
- generate(chart,complexeState.getStates(), destDir);
- }
- // simple
- else {
-
- StateModelSimpleState simpleState = (StateModelSimpleState)state;
-
- // les etat initiaux et finaux ne donne pas
- // pas de generation de fichier
- if(!simpleState.isFinal() && !simpleState.isInitial()) {
-
- String filename = getFilenameFromState(chart, simpleState);
- File outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
- try {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- generateFromSimpleState(monitorOut, chart, simpleState);
- write(outputFile, monitorOut);
- } catch (Exception eee) {
- log.warn("Erreur lors de la génération du fichier "
- + outputFile);
- throw new RuntimeException(
- "Erreur lors de la génération du fichier "
- + outputFile, eee);
- }
- }
- } // init && final
- }
- }
-
- /**
- * Called for each simple state
- *
- * @param output writer out
- * @param chart chart
- * @param state simple state
- * @throws IOException
- */
- protected void generateFromSimpleState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
- String copyright = GeneratorUtil.getCopyright(model);
- if (GeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-/*{// Automatically generated by LutinGenerator
-package <%=getPackageFromState(chart)%>;
-
-import org.apache.tapestry.annotations.InjectPage;
-import <%=getPackageFromComponents(chart)%>.UseCasePage;
-
-/*
- * State <%=getNameFromState(state)%>
- *)
-public abstract class <%=getNameFromState(state)%> extends UseCasePage {
-}*/
-
- // generate events
- generateInjectionAndEventsFromState(output,chart,state);
-
- // generate use case name
- generateUseCaseNameFromState(output,chart,state);
-/*{}}*/
- }
-
- /**
- * Generate state injections
- * @param output
- * @param chart
- * @param state
- */
- @SuppressWarnings("unused")
- protected void generateInjectionAndEventsFromState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
-
- // liste les états de destination (pour éviter les doublons)
- List<StateModelState> destStates = new ArrayList<StateModelState>();
-
- for(StateModelTransition transition : state.getTransitions()) {
-
- StateModelState toState = transition.getDestinationState();
-
- if(toState.isComplex()) {
- StateModelState toInitState = ((StateModelComplexState)toState).getInitialState();
-
- // l'attribute doit etre private
- // sinon tapestry ne le traite pas
-
- // si l'état de destination n'a pas encore été traité
- if(!destStates.contains(toState)){
- destStates.add(toState);
-/*{
- /* linked state "<%=toState.getName()%>" *)
- @InjectPage
- private <%=Util.toUpperCaseFirstLetter(toInitState.getName())%> <%=Util.toLowerCaseFirstLetter(toInitState.getName())%>;
-}*/
- // l'attribut etant prive, il faut un getter
-/*{
- /* getter for state "<%=toState.getName()%>" *)
- protected <%=Util.toUpperCaseFirstLetter(toInitState.getName())%> get<%=Util.toUpperCaseFirstLetter(toInitState.getName())%>() {
- return <%=Util.toLowerCaseFirstLetter(toInitState.getName())%>;
- }
-}*/
- }
-/*{
- /* transition on <%=transition.getEvent()%> event *)
- public Object onActionFrom<%=Util.toUpperCaseFirstLetter(transition.getEvent())%>() {
- enterUseCase();
- return <%=Util.toLowerCaseFirstLetter(toInitState.getName())%>;
- }
-}*/
- }
- else {
-
- StateModelSimpleState simpleToState = (StateModelSimpleState)toState;
-
- // si l'etat a injecter n'est pas final
- if(!simpleToState.isFinal()) {
-
- // si l'état de destination n'a pas encore été traité
- if(!destStates.contains(toState)){
- destStates.add(toState);
-/*{
- /* linked state "<%=simpleToState.getName()%>" *)
- @InjectPage
- private <%=Util.toUpperCaseFirstLetter(simpleToState.getName())%> <%=Util.toLowerCaseFirstLetter(simpleToState.getName())%>;
-}*/
- // l'attribut etant prive, il faut un getter
-/*{
- /* getter for state "<%=simpleToState.getName()%>" *)
- protected <%=Util.toUpperCaseFirstLetter(simpleToState.getName())%> get<%=Util.toUpperCaseFirstLetter(simpleToState.getName())%>() {
- return <%=Util.toLowerCaseFirstLetter(simpleToState.getName())%>;
- }
-}*/
- }
- } // isFinal
-/*{
- /* transition on "<%=transition.getEvent()%>" event *)
- public Object onActionFrom<%=Util.toUpperCaseFirstLetter(transition.getEvent())%>() {
-}*/
- if(simpleToState.isFinal()) {
-/*{ return leaveUseCase();
-}*/
- } else {
-/*{ return <%=Util.toLowerCaseFirstLetter(simpleToState.getName())%>;
-}*/
- }
-/*{ }
-}*/
- }
- }
- }
-
- /**
- * Generate use case name
- *
- * @param output
- * @param chart
- * @param state
- */
- @SuppressWarnings("unused")
- protected void generateUseCaseNameFromState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
-
- String stateId = generateStateUseCaseName(state.getName());
-/*{
- /* return a unique state id for model *)
- protected final String getUseCaseName() {
- return "<%=stateId%>";
- }
-}*/
- }
-
- /**
- * Genere un nom unique d'etat pour le model courant.
- *
- * Pour des raisons de debugage, on utilise des lettres particuliere du
- * nom de l'etat, suivit d'un numero, s'il y a collision.
- *
- * @return a unique name
- */
- protected String generateStateUseCaseName(String name) {
-
- String ucsn = getHashStateName(name);
-
- // test already assigned
- String uniqueucsn = ucsn;
- int num = 2;
- while(assignedUseCaseStateNames.contains(uniqueucsn)) {
- uniqueucsn = new StringBuffer(ucsn).append(num++).toString();
- }
-
- assignedUseCaseStateNames.add(uniqueucsn);
-
- return uniqueucsn;
- }
-
- /**
- * Hash a state name.
- *
- * On prend la premiere lettre de chaque mot.
- *
- * ContactList -> cl
- * contactList -> cl
- * ContactListPage -> clp
- *
- * @param name
- * @return
- */
- protected String getHashStateName(String name) {
-
- // bug si moins de 1 caractere
- if(name == null || name.length()<1) return name;
-
- StringBuffer sb = new StringBuffer();
-
- // on prend la premiere lettre
- sb.append(Character.toLowerCase(name.charAt(0)));
-
- // ensuite, on prend les majuscules
- for(int i = 1 ; i < name.length() ; ++i) {
-
- // si maj
- if(Character.isUpperCase(name.charAt(i))) {
- sb.append(Character.toLowerCase(name.charAt(i)));
- }
- }
-
- return sb.toString();
- }
-
- /**
- * Generate the engine use case class.
- *
- * Need to be generated inside client webapp directory to be analysed by
- * tapestry (annotations)
- *
- * @param model model
- * @param chart chart
- */
- protected void generateUseCaseEngineFromModel(StateModel model,StateModelStateChart chart,File destDir) throws IOException {
- String componentPackageName = getPackageFromComponents(chart);
-
- // UseCasePage
- String filename = (componentPackageName + ".UseCasePage").replace('.', File.separatorChar) + ".java";
- File outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
- try {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- // generate UseCasePage class
- generateUseCasePageClass(monitorOut,model,componentPackageName);
- write(outputFile, monitorOut);
- } catch (Exception e) {
- log.warn("Erreur lors de la génération du fichier UseCasePage",e);
- throw new RuntimeException(
- "Erreur lors de la génération du fichier UseCasePage", e);
- }
- }
-
- // UseCaseMap
- filename = (componentPackageName + ".UseCaseMap").replace('.', File.separatorChar) + ".java";
- outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
- try {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- // generate UseCasePage class
- generateUseCaseMapClass(monitorOut,componentPackageName);
- write(outputFile, monitorOut);
- } catch (Exception e) {
- log.warn("Erreur lors de la génération du fichier UseCaseMap",e);
- throw new RuntimeException(
- "Erreur lors de la génération du fichier UseCaseMap", e);
- }
- }
- }
-
- /**
- * Generate base.UseCasePage class
- * @param output
- * @param componentPackageName
- */
- private void generateUseCasePageClass(MonitorWriter output, StateModel model, String componentPackageName) throws IOException {
-/*{package <%=componentPackageName%>;
-
-import org.apache.tapestry.Link;
-import org.apache.tapestry.annotations.ApplicationState;
-import org.apache.tapestry.ioc.annotations.Inject;
-import org.apache.tapestry.annotations.Service;
-import org.apache.tapestry.internal.services.LinkFactory;
-import org.apache.tapestry.internal.services.LinkFactoryListener;
-import org.apache.tapestry.services.Request;
-
-public abstract class UseCasePage}*/
-
- // ajoute un heritage si il a ete specifie dans un fichier de propriete
- Map<String,String> tagValues = model.getTagValues();
- if(tagValues != null) {
- String tagUseCaseEngineExtendedClass = tagValues.get("usecaseengineextendedclass");
- if(tagUseCaseEngineExtendedClass != null) {
- /*{ extends <%=tagUseCaseEngineExtendedClass%>}*/
- }
- }
-
-/*{ implements LinkFactoryListener {
-
- private static final String UC_PARAMETER_NAME = "UC";
- private static final String UC_PARAMETER_SEPARATOR = ":";
-
- @ApplicationState
- private UseCaseMap useCaseManager;
- private boolean useCaseManagerExists;
-
- @Inject
- @Service("LinkFactory")
- private LinkFactory _linkFactory;
-
- @Inject
- @Service("Request")
- private Request _request;
-
- private String UCName;
-
- public void onActivate() {
- _linkFactory.addListener(this);
-
- UCName = _request.getParameter(UC_PARAMETER_NAME);
- }
-
- protected abstract String getUseCaseName();
-
- /**
- * Create stack if not exists
- *)
- protected void init() {
- if(!useCaseManagerExists) {
- useCaseManager = new UseCaseMap();
- }
- }
- /**
- * Enter in a new sub use case
- *)
- protected void enterUseCase() {
- init();
- // current
- String currentUCN = UCName;
- // new
- UCName = (currentUCN == null) ? getUseCaseName() : currentUCN + UC_PARAMETER_SEPARATOR + getUseCaseName();
- useCaseManager.enterSubUseCase(UCName, currentUCN, this);
- }
-
- /**
- * Leave a sub use case
- *)
- protected UseCasePage leaveUseCase() {
- init();
-
- UseCasePage nextPage = null;
-
- // current UCN
- String UC = UCName;
-
- // get state
- Object[] response = useCaseManager.leaveUseCase(UC);
-
- // if null, return null, don't change page
- if(response != null) {
- // get UCN before enter this one
- UCName = (String) response[0];
-
- nextPage = (UseCasePage) response[1];
- }
-
- return nextPage;
- }
-
- /* (non-Javadoc)
- * @see org.apache.tapestry.internal.services.LinkFactoryListener#createdActionLink(org.apache.tapestry.Link)
- *)
- public void createdActionLink(Link _link) {
- addUCParameter(_link);
- }
-
- /* (non-Javadoc)
- * @see org.apache.tapestry.internal.services.LinkFactoryListener#createdPageLink(org.apache.tapestry.Link)
- *)
- public void createdPageLink(Link _link) {
- // PageLink englobe ausssi les redirects envoyés au client apres une
- // action
- addUCParameter(_link);
- }
-
- protected void addUCParameter(Link _link) {
- if(_link.getParameterValue(UC_PARAMETER_NAME) == null) {
-
- if(UCName != null) {
- _link.addParameter(UC_PARAMETER_NAME, UCName);
- }
- }
- }
-}
-}*/
- }
-
- /**
- * Generate base.UseCaseMap class
- * @param output
- * @param componentPackageName
- */
- private void generateUseCaseMapClass(MonitorWriter output, String componentPackageName) throws IOException {
-/*{package <%=componentPackageName%>;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class UseCaseMap {
-
- /**
- * Map (state name -> state instance)
- *)
- private Map<String,Object[]> mapUseCase;
-
- /**
- * Constructor
- *)
- public UseCaseMap () {
- mapUseCase = new HashMap<String,Object[]>();
- }
-
- /**
- * New sub use case
- *)
- public void enterSubUseCase(String newUseCaseName, String previousUseCaseName, Object state) {
- mapUseCase.put(newUseCaseName,new Object[]{previousUseCaseName,state});
- }
-
- /**
- * Finish a subusecase
- *
- * Return the state that init the subuse case
- * @return a state
- *)
- public Object[] leaveUseCase(String useCaseName) {
- return mapUseCase.get(useCaseName);
- }
-}
-}*/
- }
-}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -51,16 +51,16 @@
*/
public class TopiaMetaGenerator extends ObjectModelGenerator {
- protected static final Log log = LogFactory.getLog(TopiaMetaGenerator.class);
+ protected static Log log = LogFactory.getLog(TopiaMetaGenerator.class);
+
/**
* la liste des generateurs par defaut a utiliser
*/
- protected static final List<Class<? extends ObjectModelGenerator>> DEFAULT_GENERATORS =
- java.util.Collections.unmodifiableList(Arrays.asList(
-
+ protected static final List<Class<? extends ObjectModelGenerator>> DEFAULT_GENERATORS = java.util.Collections
+ .unmodifiableList(Arrays.asList(
+
EntityInterfaceGenerator.class,
EntityAbstractGenerator.class,
- EntityAbstractGenerator.class,
EntityImplGenerator.class,
EntityHibernateMappingGenerator.class,
@@ -70,27 +70,35 @@
EntityProviderGenerator.class,
EntityEnumGenerator.class,
- DAOHelperGenerator.class,
+ DAOHelperGenerator.class));
- ServiceInterfaceGenerator.class,
- ServiceAbstractGenerator.class,
- ServiceImplGenerator.class
- ));
-
protected boolean validateModel(ObjectModel model) {
List<ObjectModelValidator> validators = new ArrayList<ObjectModelValidator>();
- AttributeNamesValidator attrValidator = new AttributeNamesValidator(model);
- attrValidator.addNameAndReason("next", "Le nom d'attribut \"next\" est incompatible avec HSQL");
- attrValidator.addNameAndReason("value", "Le nom d'attribut \"value\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("values", "Le nom d'attribut \"values\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("begin", "Le nom d'attribut \"begin\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("end", "Le nom d'attribut \"end\" est incompatible avec certains SGBD");
- attrValidator.addNameAndReason("authorization", "Le nom d'attribut \"authorization\" est incompatible avec certains SGBD");
+ AttributeNamesValidator attrValidator = new AttributeNamesValidator(
+ model);
+ attrValidator.addNameAndReason("next",
+ "Le nom d'attribut \"next\" est incompatible avec HSQL");
+ attrValidator
+ .addNameAndReason("value",
+ "Le nom d'attribut \"value\" est incompatible avec certains SGBD");
+ attrValidator
+ .addNameAndReason("values",
+ "Le nom d'attribut \"values\" est incompatible avec certains SGBD");
+ attrValidator
+ .addNameAndReason("begin",
+ "Le nom d'attribut \"begin\" est incompatible avec certains SGBD");
+ attrValidator
+ .addNameAndReason("end",
+ "Le nom d'attribut \"end\" est incompatible avec certains SGBD");
+ attrValidator
+ .addNameAndReason("authorization",
+ "Le nom d'attribut \"authorization\" est incompatible avec certains SGBD");
validators.add(attrValidator);
ClassNamesValidator classValidator = new ClassNamesValidator(model);
- classValidator.addNameAndReason("constraint", "Nom de classe incompatible avec certains SGBD");
+ classValidator.addNameAndReason("constraint",
+ "Nom de classe incompatible avec certains SGBD");
validators.add(classValidator);
validators.add(new TopiaRelationValidator(model));
@@ -116,25 +124,34 @@
generatePersistence(model, destDir);
}
- public void generatePersistence(ObjectModel model, File destDir) throws IOException {
+ public void generatePersistence(ObjectModel model, File destDir)
+ throws IOException {
for (Class<? extends ObjectModelGenerator> generatorClass : DEFAULT_GENERATORS) {
ObjectModelGenerator generator;
if (excludeTemplates.contains(generatorClass.getName())) {
// exclude generator
- log.info("exclude generateur "+generatorClass);
+ log.info("exclude generateur " + generatorClass);
continue;
}
try {
+
generator = generatorClass.newInstance();
generator.setParent(this);
} catch (Exception e) {
// should never happens
- log.error(e);
+ if(log.isErrorEnabled()) {
+ log.error("An error occurs when generating persistence", e);
+ }
throw new RuntimeException(e);
}
+
+ // log
+ if(log.isDebugEnabled()) {
+ log.debug("call template : " + generatorClass.getSimpleName());
+ }
generator.generate(model, destDir);
- }
+ }
}
} //TopiaMetaGenerator
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaRelationValidator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/TopiaRelationValidator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaRelationValidator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -27,7 +27,6 @@
* par : $Author$
*/
-
package org.codelutin.topia.generator;
import static org.codelutin.generator.Util.isFirstAttribute;
@@ -50,7 +49,8 @@
public class TopiaRelationValidator extends ObjectModelValidator {
/**
- * Constructeur de TopiaRelationValidator
+ * Constructeur de TopiaRelationValidator.
+ *
* @param model le modèle à valider
*/
public TopiaRelationValidator(ObjectModel model) {
@@ -63,18 +63,17 @@
@Override
protected boolean validateAttribute(ObjectModelAttribute attr) {
boolean isValid = true;
- ObjectModelAttribute reverse = attr.getReverseAttribute();
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
/* Relation navigabilité */
//Pour ne pas avoir de doublons, on ne vérifie que sur le premier
//attribut par ordre alphabétique
if (isFirstAttribute(attr)) {
if (!attr.isNavigable() && !reverse.isNavigable()) {
- addError(attr,
- "La relation entre " +
- "\"" + reverse.getType() + "\"[" + attr.getName() + "] et "+
- "\"" + attr.getType() + "\"[" + reverse.getName() + "] " +
- "n'est navigable dans aucun sens");
+ addError(attr, "La relation entre " + "\"" + reverse.getType()
+ + "\"[" + attr.getName() + "] et " + "\""
+ + attr.getType() + "\"[" + reverse.getName() + "] "
+ + "n'est navigable dans aucun sens");
isValid = false;
}
}
@@ -82,13 +81,24 @@
/* Relation héritage */
if (hasUnidirectionalRelationOnAbstractType(attr, model)) {
isValid = false;
- addError(attr,
- "La relation entre " +
- "\"" + reverse.getType() + "\"[" + attr.getName() + "] et "+
- "\"" + attr.getType() + "\"[" + reverse.getName() + "] " +
- "n'est navigable que dans un sens et " +
- "la classe \""+ attr.getType() + "\" a des sous-classes. " +
- "Des accesseurs doivent donc etre generes pour Hibernate.");
+ addError(
+ attr,
+ "La relation entre "
+ + "\""
+ + reverse.getType()
+ + "\"["
+ + attr.getName()
+ + "] et "
+ + "\""
+ + attr.getType()
+ + "\"["
+ + reverse.getName()
+ + "] "
+ + "n'est navigable que dans un sens et "
+ + "la classe \""
+ + attr.getType()
+ + "\" a des sous-classes. "
+ + "Des accesseurs doivent donc etre generes pour Hibernate.");
}
/* Pas d'inverse */
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/package.html (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/package.html)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/package.html (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/package.html 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,131 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
+
+<html>
+ <head>
+ <meta
+ http-equiv="Content-Language"
+ content="fr">
+ <meta
+ http-equiv="Content-Type"
+ content="text/html; charset=UTF-8">
+
+ <title>ToPIA</title>
+ </head>
+
+ <body>
+ <h1>ToPIA</h1>
+
+ <h2>Présentation</h2>
+
+ <p>ToPIA est un framework de persistence basé sur Hibernate. Il
+ contient un point d'entré le TopiaContext qui permet d'ouvrir des
+ transactions qui retourne des TopiaContext fils sur lequel on peut
+ récupéré des DAO pour accèder aux entités.</p>
+
+ <p>ToPIA offre en plus la possibilité de générer à partir d'une
+ fichier XMI toutes les classes utiles pour la persistence. Ce qui
+ permet d'évité un travail fastidieux d'ecriture de classe, d'être sur
+ que le jour on l'on veut ajouter une méthode technique (getXML, ...) à
+ toutes ces entités cela sera fait de façon simple et automatique
+ (modification du générateur puis regénération). Et surtout d'avoir des
+ classes générés qui permettent un typage fort de l'application (pas de
+ cast, pas de générique)</p>
+
+ <p>Bien sur il est possible d'utilisé ToPIA sans générateur, il est
+ d'ailleurs utilisé ainsi pour les tests</p>
+
+ <p>ToPIA contient aussi des classes techniques réutilisables dans ses
+ applications pour tout ce qui touche à l'authentification et
+ l'autorisation (TopiaUser, TopiaGroup, TopiaPermission) (partie non
+ encore développé)</p>
+
+ <h2>La persistance</h2>
+
+ <p>La persistence se base complètement sur hibernate, mais il est
+ aussi possible d'indiquer que certaine classe doivent être sauvé dans
+ des fichiers textes plutot qu'une base de données, cette persistence
+ est appelée FlatFile.</p>
+
+ <p>Le TopiaContext doit être configuré avec un objet Properties.
+ Celui-ci peut contenir différentes entrées. Vu que la persistence est
+ complètement basé sur hibernate, même si vous n'avez que des entités
+ sauvé en FlatFile il vous faudra fournir à hibernate un accès à une
+ base de données. Celle-ci peu très bien être une base embarqué comme
+ hsql, mckoi ou derby.</p>
+
+ <dl>
+ <dt>topia.persistence.properties.file</dt>
+
+ <dd>le fichier de propriété a utiliser pour configurer
+ hibernate</dd>
+
+ <dt>topia.persistence.directories</dt>
+
+ <dd>la liste des repertoires contenant les mappings hibernates
+ (.hbm.xml) la liste de repertoire est separer par des virgules
+ ','</dd>
+
+ <dt>topia.persistence.classes</dt>
+
+ <dd>la liste des classes que doit géré ToPIA. On peut tres bien
+ utiliser topia.persistence.directories pour un ensemble d'entié du
+ meme repertoire et topia.persistence.classes pour d'autres
+ classes</dd>
+ </dl>
+
+ <dl>
+ <dt>topia.dao.flatfile.properties.file</dt>
+
+ <dd>indique le fichier de configuration a utiliser en plus de la
+ configuration du context</dd>
+
+ <dt>topia.dao.flatfile.directory</dt>
+
+ <dd>indique le répertoire au sauver les entités</dd>
+
+ <dt>topia.dao.flatfile.directory.[fqn-entity]</dt>
+
+ <dd>permet de spécifier un répertoire différent pour une entity
+ spécifique</dd>
+
+ <dt>topia.dao.flatfile.mapping</dt>
+
+ <dd>permet d'indique le mapping a utiliser pour les entités</dd>
+
+ <dt>topia.dao.flatfile.mapping.[fqn-entity]</dt>
+
+ <dd>permet d'indique un mapping différent pour entité</dd>
+ </dl>
+
+ <p>à la place flatfile il est possible de mettre le FQN du DAO utilisé
+ par exemple
+ org.codelutin.topia.persistence.flatfile.TopiaDAOFlatFile</p>
+
+ <p>Si directory est absent alors "." est utilisé</p>
+
+ <p>les mappings s'écrivent de la façon suivant:</p>
+
+ <ul>
+ <li>ext=extension a ajouter au fichier contenant l'entity</li>
+
+ <li>key=attribute</li>
+
+ <li>body=attribute</li>
+ </ul>
+
+ <p>Si key est absent alors on utilise le topiaId, key est utilisé
+ comme nom de fichier de sauvegarde</p>
+
+ <p>Si body est absent alors on utilise un fichier de propriété pour
+ sauver l'entity. Si body est présent seul cet attribut sera sauvé.</p>
+
+<pre>
+ topia.dao.flatfile.mapping.key=topiaId
+
+ topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.key=name
+ topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.body=script
+
+</pre>
+ </body>
+</html>
+
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/package.html
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/SearchFields.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/SearchFields.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/SearchFields.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/SearchFields.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,66 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+* SearchFields.java
+*
+* Created: 7 juin 2006
+*
+* @author Arnaud Thimel <thimel(a)codelutin.com>
+* @version $Revision$
+*
+* Mise a jour: $Date$
+* par : $Author$
+*/
+
+package org.codelutin.topia.persistence;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.TYPE;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Ces annotations permettent de savoir quels sont les champs sur lesquels
+ * la recherche pourra s'effectuer.
+ */
+@Retention(RUNTIME)
+@Target(TYPE)
+public @interface SearchFields {
+
+ /**
+ * @return la liste des champs textes
+ */
+ String[] txtFields() default {};
+
+ /**
+ * @return la liste des champs numeriques
+ */
+ String[] numFields() default {};
+
+ /**
+ * @return la liste des champs booleens
+ */
+ String[] boolFields() default {};
+
+ /**
+ * @return la liste des champs date
+ */
+ String[] dateFields() default {};
+
+} //SearchFields
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/SearchFields.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,237 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaDAO.java
+ *
+ * Created: 30 déc. 2005 03:00:57
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.security.Permission;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.event.TopiaEntityListener;
+import org.codelutin.topia.event.TopiaEntityVetoable;
+import org.codelutin.topia.event.TopiaTransactionListener;
+import org.codelutin.topia.event.TopiaTransactionVetoable;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+
+/**
+ * @author poussin
+ *
+ * @param <Entity>
+ */
+public interface TopiaDAO<Entity extends TopiaEntity> {
+
+ /**
+ * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
+ * after
+ *
+ * @param entityClass
+ */
+ public void init(TopiaContextImplementor context, Class<Entity> entityClass)
+ throws TopiaException;
+
+ /**
+ * Return class of entity managed by this DAO
+ * @return
+ */
+ public abstract Class<Entity> getEntityClass();
+
+ /**
+ * @return Returns the context.
+ */
+ public abstract TopiaContextImplementor getContext();
+
+ /**
+ * appelé lorsque le context a eu un commit de fait
+ * TODO il faudrait peut-etre plutot faire un commit a deux phase
+ * car plusieurs type de persistence peuvent etre melangé, et il
+ * serait bien que si l'une echoué les autres echoue aussi.
+ */
+ public void commitTransaction() throws TopiaException;
+
+ /** appelé lorsque le context a eu un commit de fait */
+ public void rollbackTransaction() throws TopiaException;
+
+ /**
+ * Construit une nouvelle instance de l'objet géré par ce DAO
+ * @param properties la liste des propriétés que doit avoir l'objet créé
+ * les arguments vont par paire (propertyName, value)
+ * @return un nouvel objet
+ * @throws TopiaException si un problème est rencontré durant l'instanciation
+ * @throws IllegalArgumentException Si le nombre on le type des arguments
+ * n'est pas bon ou que le type ou le nom d'une propriété est fausse
+ */
+ public abstract Entity create(Object... properties) throws TopiaException;
+
+ /**
+ * Construit une nouvelle instance de l'objet géré par ce DAO
+ * @param properties la liste des propriétés que doit avoir l'objet créé
+ * @return un nouvel objet
+ * @throws TopiaException si un problème est rencontré durant l'instanciation
+ * @throws IllegalArgumentException Si le nombre on le type des arguments
+ * n'est pas bon ou que le type ou le nom d'une propriété est fausse
+ */
+ public Entity create(Map<String, Object> properties) throws TopiaException;
+
+ /**
+ * Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter
+ * par exemple un objet provenant d'un autre context mais du meme type
+ * de DAO
+ * @param e l'entite a ajouter ou mettre a jour
+ * @return l'entity passé en paramètre.
+ * @throws TopiaException
+ */
+ public abstract Entity update(Entity e) throws TopiaException;
+
+ public abstract void delete(Entity e) throws TopiaException;
+
+ public abstract Entity findByTopiaId(String k) throws TopiaException;
+
+ public abstract List<Entity> findAll() throws TopiaException;
+
+ public abstract List<Entity> findAllWithOrder(String... propertyNames)
+ throws TopiaException;
+
+ /**
+ * TODO modifier l'implantation pour faire un simple count sur la base
+ *
+ * @return
+ * @throws TopiaException
+ */
+ public abstract int size() throws TopiaException;
+
+ /**
+ * Recherche la classe en utilisant la cle naturelle, chaque champs de la
+ * cle naturelle est une entre de la map passe en argument.
+ *
+ * @param keys la liste des champs de la cle naturelle avec leur valeur
+ * @return
+ * @throws TopiaException
+ */
+ public abstract Entity findByPrimaryKey(Map<String, Object> keys)
+ throws TopiaException;
+
+ /**
+ * Recherche la classe en utilisant la cle naturelle, si la cle naturelle
+ * est composé de plusieurs champs alors les arguments passés doivent être
+ * dans l'ordre de declaration dans le fichier de mapping
+ *
+ * @param k l'objet cle naturelle de la classe
+ * @return
+ * @throws TopiaException
+ */
+ public abstract Entity findByPrimaryKey(Object... k) throws TopiaException;
+
+ public abstract Entity findByProperty(String propertyName, Object value)
+ throws TopiaException;
+
+ /**
+ *
+ * @param propertyName
+ * @param value
+ * @param others les autres proprietes doivent aller par 2 propertyName,
+ * value
+ * @return
+ * @throws TopiaException
+ */
+ public abstract Entity findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException;
+
+ public abstract Entity findByProperties(Map<String, Object> properties)
+ throws TopiaException;
+
+ public abstract List<Entity> findAllByProperty(String propertyName,
+ Object value) throws TopiaException;
+
+ /**
+ *
+ * @param propertyName
+ * @param value
+ * @param others les autres proprietes doivent aller par 2 propertyName,
+ * value
+ * @return
+ * @throws TopiaException
+ */
+ public abstract List<Entity> findAllByProperties(String propertyName,
+ Object value, Object... others) throws TopiaException;
+
+ public abstract List<Entity> findAllByProperties(
+ Map<String, Object> properties) throws TopiaException;
+
+ /*
+ * Find Contains
+ */
+ /**
+ * Cherche et renvoie la première entité trouvée dont les propriétés en clé
+ * de Map contiennent toutes les valeurs de la Collection.
+ */
+ public abstract Entity findContainsProperties(
+ Map<String, Collection> properties) throws TopiaException;
+
+ /**
+ * Cherche et renvoie la première entité trouvée dont la propriété
+ * propertyName contient values, ainsi de suite avec others.
+ */
+ public abstract Entity findContainsProperties(String propertyName,
+ Collection values, Object... others) throws TopiaException;
+
+ /**
+ * Cherche et renvoie la première entité trouvée dont les propriétés en clé
+ * de Map contiennent toutes les valeurs de la Collection.
+ */
+ public abstract List<Entity> findAllContainsProperties(
+ Map<String, Collection> properties) throws TopiaException;
+
+ /**
+ * Cherche et renvoie toutes les entités trouvées dont la propriété
+ * propertyName contient values, ainsi de suite avec others.
+ */
+ public abstract List<Entity> findAllContainsProperties(String propertyName,
+ Collection values, Object... others) throws TopiaException;
+
+ /**
+ * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas
+ * @param topiaId topiaId d'une entite
+ * @return la liste des permissions
+ */
+ public List<Permission> getRequestPermission(String topiaId, int actions)
+ throws TopiaException;
+
+ /* Adders */
+ public void addTopiaEntityListener(TopiaEntityListener listener);
+
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /* Removers */
+ public void removeTopiaEntityListener(TopiaEntityListener listener);
+
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+} //TopiaDAO
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,749 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaDAOAbstract.java
+ *
+ * Created: 31 déc. 2005 13:10:34
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.event.TopiaEntityListener;
+import org.codelutin.topia.event.TopiaEntityVetoable;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+import org.codelutin.topia.persistence.hibernate.TopiaDAOHibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.metadata.ClassMetadata;
+
+/**
+ * Cette classe permet d'avoir un ensemble de méthode implantée de façon
+ * standard pour les différents DAO existant (FlatFile, Hibernate).
+ * Certaine méthode implanté ici sont particulièrement inéficace et il
+ * est conseillé de les surcharger dans les classes DAO spécifiques.
+ *
+ * Certain accès à Hibernate est tout de même fait ici, car on a pris le
+ * choix de se basé entièrement sur hibernate pour la persistence, et il
+ * est ainsi possible d'accèder au meta information hibernate sur les classes
+ * lorque l'on en a besoin.
+ *
+ * @author poussin
+ *
+ */
+
+public abstract class TopiaDAOAbstract<Entity extends TopiaEntity> implements
+ TopiaDAO<Entity> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(TopiaDAOAbstract.class);
+
+ protected Class<Entity> entityClass = null;
+
+ protected TopiaContextImplementor context = null;
+
+ public Class<Entity> getEntityClass() {
+ throw new UnsupportedOperationException(
+ "This method must be overided in generated DAO");
+ }
+
+ /**
+ * Retourne l'id de l'entity
+ * @param e l'entity
+ * @return l'id de l'entity ou null si pas trouvé
+ * @throws TopiaException Si une erreur survient durant la recherche
+ */
+ protected Serializable getId(Entity e) throws TopiaException {
+ ClassMetadata meta = getClassMetadata();
+ String idPropName = meta.getIdentifierPropertyName();
+
+ Serializable result;
+ try {
+ result = (Serializable) PropertyUtils.getSimpleProperty(e,
+ idPropName);
+ } catch (IllegalAccessException eee) {
+ throw new TopiaException("Impossible de récuperer l'identifiant "
+ + idPropName + " de l'entite: " + e);
+ } catch (InvocationTargetException eee) {
+ throw new TopiaException("Impossible de récuperer l'identifiant "
+ + idPropName + " de l'entite: " + e);
+ } catch (NoSuchMethodException eee) {
+ throw new TopiaException("Impossible de récuperer l'identifiant "
+ + idPropName + " de l'entite: " + e);
+ }
+ return result;
+ }
+
+ /**
+ * Retourne l'id de l'entity representer comme une map
+ * @param map l'entity en representation map
+ * @return l'id de l'entity ou null si pas trouvé
+ * @throws TopiaException Si une erreur survient durant la recherche
+ */
+ protected Serializable getId(Map map) throws TopiaException {
+ try {
+ ClassMetadata meta = getClassMetadata();
+ String idPropName = meta.getIdentifierPropertyName();
+
+ Serializable id = (Serializable) map.get(idPropName);
+ return id;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ /**
+ * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
+ * after
+ *
+ * @param entityClass
+ */
+ public void init(TopiaContextImplementor context, Class<Entity> entityClass)
+ throws TopiaException {
+ log.debug("init dao for " + entityClass.getName());
+ this.context = context;
+ this.entityClass = entityClass;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#getContext()
+ */
+ public TopiaContextImplementor getContext() {
+ return context;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Entity instanciateNew() throws TopiaException {
+ Entity result = null;
+ String classname = entityClass.getName();
+ try {
+ // on commence par essayer d'instancier le Impl
+ result = ((Class<Entity>) Class.forName(classname + "Impl"))
+ .newInstance();
+ if (log.isDebugEnabled()) {
+ log.debug("Utilisation de la classe " + classname + "Impl"
+ + " pour " + classname);
+ }
+ } catch (InstantiationException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'instancier " + classname + "Impl");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ } catch (IllegalAccessException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'instancier " + classname + "Impl");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ } catch (ClassNotFoundException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible de trouver la classe " + classname
+ + "Impl");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ }
+
+ if (result == null) {
+ // le impl n'est pas trouvé on essai avec la classe elle meme
+ try {
+ result = entityClass.newInstance();
+ if (log.isDebugEnabled()) {
+ log.debug("Utilisation de la classe " + classname
+ + " pour " + classname);
+ }
+ } catch (InstantiationException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'instancier " + classname);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ } catch (IllegalAccessException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'instancier " + classname);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ }
+ }
+
+ if (result == null) {
+ throw new TopiaException(
+ "Impossible de trouver ou d'instancier la classe "
+ + classname);
+ }
+
+ return result;
+ }
+
+ /**
+ * Par defaut ne fait rien
+ */
+ public void commitTransaction() throws TopiaException {
+ }
+
+ /**
+ * Par defaut ne fait rien
+ */
+ public void rollbackTransaction() throws TopiaException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object)
+ */
+ public Entity create(Object... properties) throws TopiaException {
+ Map<String, Object> map = new HashMap<String, Object>();
+ Object propertyName = null;
+ Object value = null;
+ try {
+ for (int i = 0; i < properties.length;) {
+ propertyName = properties[i++];
+ value = properties[i++];
+ map.put((String) propertyName, value);
+ }
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException("Wrong number of argument "
+ + properties.length
+ + ", you must have even number. Last property name read: "
+ + propertyName);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Wrong argument type, wait property name as String and have "
+ + propertyName.getClass().getName());
+ }
+
+ Entity result = create(map);
+ return result;
+ }
+
+ /**
+ * Cette methode appelle fireVetoableCreate et fireOnCreated
+ * Si vous la surchargé, faites attention a appeler le super
+ * ou a appeler vous aussi ces deux methodes.
+ */
+ public Entity create(Map<String, Object> properties) throws TopiaException {
+ Entity result = instanciateNew();
+
+ // TODO reflechir s'il ne faudrait pas creer l'id avant l'event precedent
+ // reflechir toujours dans un context on les Entity pourrait ne pas
+ // etre des TopiaEntity
+ if (result instanceof TopiaEntity) {
+ String topiaId = TopiaId.create(entityClass);
+ TopiaEntityAbstract entity = (TopiaEntityAbstract) result;
+ entity.setTopiaId(topiaId);
+ entity.setTopiaContext(getContext());
+ }
+ try {
+ for (Map.Entry<String, Object> e : properties.entrySet()) {
+ String propertyName = e.getKey();
+ Object value = e.getValue();
+ PropertyUtils.setProperty(result, (String) propertyName, value);
+ }
+ } catch (IllegalAccessException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
+ } catch (InvocationTargetException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
+ } catch (NoSuchMethodException eee) {
+ throw new IllegalArgumentException(
+ "Can't put properties on new Object", eee);
+ }
+
+ result.postCreate();
+
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#size()
+ */
+ public int size() throws TopiaException {
+ int result = findAll().size();
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map)
+ */
+ public Entity findByPrimaryKey(Map<String, Object> keys)
+ throws TopiaException {
+ try {
+ // we used hibernate meta information for all persistence type
+ // it's more easy than create different for all persistence
+ ClassMetadata meta = getClassMetadata();
+ if (meta.hasNaturalIdentifier()) {
+ Entity result = findByProperties(keys);
+ return result;
+ }
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ throw new TopiaException("La classe " + entityClass.getName()
+ + " n'a pas de cle primaire naturelle");
+
+ }
+
+ /**
+ * private method because this is hibernate specific method and we don't
+ * want expose it
+ *
+ * @return
+ * @throws TopiaException
+ */
+ private ClassMetadata getClassMetadata() throws TopiaException {
+ ClassMetadata meta = getContext().getHibernateFactory()
+ .getClassMetadata(entityClass);
+ if (meta == null) {
+ meta = getContext().getHibernateFactory().getClassMetadata(
+ entityClass.getName() + "Impl");
+ }
+ return meta;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object)
+ */
+ public Entity findByPrimaryKey(Object... k) throws TopiaException {
+ // TODO pour une meilleur gestion des problemes a la compilation
+ // mettre un premier couple (propName, value) en argument ca evitera
+ // de pouvoir appeler cette methode sans argument
+ try {
+ ClassMetadata meta = getClassMetadata();
+ if (meta.hasNaturalIdentifier()) {
+ int[] ikeys = meta.getNaturalIdentifierProperties();
+ String[] pnames = meta.getPropertyNames();
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ for (int ikey : ikeys) {
+ keys.put(pnames[ikey], k[ikey]);
+ }
+
+ Entity result = findByProperties(keys);
+ return result;
+ }
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ throw new TopiaException("La classe " + entityClass.getName()
+ + " n'a pas de cle primaire naturelle");
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object)
+ */
+ public Entity findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, value);
+ Object name = null;
+ for (int i = 0; i < others.length;) {
+ try {
+ name = others[i++];
+ value = others[i++];
+ properties.put((String) name, value);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et non pas "
+ + propertyName.getClass().getName(), eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2)
+ + " La dernière propriété était: " + name, eee);
+ }
+ }
+ Entity result = findByProperties(properties);
+ return result;
+ }
+
+ /**
+ * Recherche une entity contenant certain propriété. Pour l'instant on
+ * charche toute les entités existantes pour faire la recherche
+ *
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperties(java.util.Map)
+ */
+ public List<Entity> findAllByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ List<Entity> all = findAll();
+ List<Entity> result = new ArrayList<Entity>();
+ for (Entity e : all) {
+ boolean ok = true;
+ try {
+ for (Entry<String, Object> kv : properties.entrySet()) {
+ Object entityValue = PropertyUtils.getProperty(e, kv
+ .getKey());
+ Object value = kv.getValue();
+ if (!ObjectUtils.equals(entityValue, value)) {
+ ok = false;
+ break;
+ }
+ }
+ } catch (IllegalAccessException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn(
+ "Impossible d'acceder a la methode demandé pour l'obbjet "
+ + e, eee);
+ }
+ } catch (InvocationTargetException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn(
+ "Impossible d'acceder a la methode demandé pour l'obbjet "
+ + e, eee);
+ }
+ } catch (NoSuchMethodException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn(
+ "Impossible d'acceder a la methode demandé pour l'obbjet "
+ + e, eee);
+ }
+ }
+ if (ok) {
+ result.add(e);
+ }
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object)
+ */
+ public List<Entity> findAllByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, value);
+ Object name = null;
+ for (int i = 0; i < others.length;) {
+ try {
+ name = others[i++];
+ value = others[i++];
+ properties.put((String) name, value);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et non pas "
+ + propertyName.getClass().getName(), eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2)
+ + " La dernière propriété était: " + name, eee);
+ }
+ }
+ List<Entity> result = findAllByProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
+ */
+ public Entity findContainsProperties(Map<String, Collection> properties)
+ throws TopiaException {
+ List<Entity> results = findAllContainsProperties(properties);
+ Entity result = null;
+ if (results.size() > 0) {
+ result = results.get(0);
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
+ */
+ public Entity findContainsProperties(String propertyName,
+ Collection values, Object... others) throws TopiaException {
+ Map<String, Collection> properties = new HashMap<String, Collection>();
+ properties.put(propertyName, values);
+ Object name = null;
+ for (int i = 0; i < others.length;) {
+ try {
+ name = others[i++];
+ values = (Collection) others[i++];
+ properties.put((String) name, values);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et non pas "
+ + propertyName.getClass().getName(), eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2)
+ + " La dernière propriété était: " + name, eee);
+ }
+ }
+ Entity result = findContainsProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
+ */
+ public List<Entity> findAllContainsProperties(
+ Map<String, Collection> properties) throws TopiaException {
+ List<Entity> all = findAll();
+ List<Entity> result = new ArrayList<Entity>();
+ for (Entity e : all) {
+ boolean ok = true;
+ try {
+ for (Entry<String, Collection> kv : properties.entrySet()) {
+ Collection entityValues = (Collection) PropertyUtils
+ .getProperty(e, kv.getKey());
+ Collection values = kv.getValue();
+ if (!entityValues.containsAll(values)) {
+ ok = false;
+ break;
+ }
+ }
+ } catch (IllegalAccessException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn(
+ "Impossible d'acceder a la methode demandé pour l'obbjet "
+ + e, eee);
+ }
+ } catch (InvocationTargetException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn(
+ "Impossible d'acceder a la methode demandé pour l'obbjet "
+ + e, eee);
+ }
+ } catch (NoSuchMethodException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn(
+ "Impossible d'acceder a la methode demandé pour l'obbjet "
+ + e, eee);
+ }
+ }
+ if (ok) {
+ result.add(e);
+ }
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
+ */
+ public List<Entity> findAllContainsProperties(String propertyName,
+ Collection values, Object... others) throws TopiaException {
+ Map<String, Collection> properties = new HashMap<String, Collection>();
+ properties.put(propertyName, values);
+ Object name = null;
+ for (int i = 0; i < others.length;) {
+ try {
+ name = others[i++];
+ values = (Collection) others[i++];
+ properties.put((String) name, values);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et non pas "
+ + propertyName.getClass().getName(), eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2)
+ + " La dernière propriété était: " + name, eee);
+ }
+ }
+ List<Entity> result = findAllContainsProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByTopiaId()
+ */
+ public Entity findByTopiaId(String k) throws TopiaException {
+ Entity result = findByProperty("topiaId", k);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAll()
+ */
+ public List<Entity> findAll() throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ List<Entity> result = findAllByProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object)
+ */
+ public List<Entity> findAllByProperty(String propertyName, Object value)
+ throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, value);
+ List<Entity> result = findAllByProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object)
+ */
+ public Entity findByProperty(String propertyName, Object value)
+ throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, value);
+ Entity result = findByProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
+ */
+ public Entity findByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ List<Entity> listResult = findAllByProperties(properties);
+ Entity result = null;
+ if (listResult.size() > 0) {
+ result = listResult.get(0);
+ }
+ return result;
+ }
+
+ @Deprecated
+ private Criterion computeCriterions(Object... values) {
+ if (values == null) {
+ return null;
+ }
+ Criterion criterion = null;
+ for (Object value : values) {
+ criterion = or(criterion, computeCriterion(value));
+ }
+ return criterion;
+ }
+
+ @Deprecated
+ private Criterion computeCriterion(Object value) {
+ Criterion criterion = null;
+ SearchFields fields = entityClass.getAnnotation(SearchFields.class);
+ String textValue = "%" + value + "%";
+ //textFields
+ String[] textFields = fields.txtFields();
+ for (String propName : textFields) {
+ criterion = or(criterion, Restrictions.like(propName, textValue));
+ }
+ //numFields
+ boolean isNumber = (value instanceof Number);
+ if (value instanceof String) {
+ try {
+ Double.parseDouble((String) value);
+ isNumber = true;
+ } catch (NumberFormatException nfe) {
+ isNumber = false;
+ }
+
+ }
+ if (isNumber) {
+ String[] numFields = fields.numFields();
+ for (String propName : numFields) {
+ criterion = or(criterion, Restrictions.sqlRestriction(propName
+ + " like '" + textValue + "'"));
+ }
+ }
+ //boolFields
+ boolean isBoolean = (value instanceof Boolean);
+ if (value instanceof String) {
+ isBoolean |= ("true".equalsIgnoreCase((String) value) || "false"
+ .equalsIgnoreCase((String) value));
+ }
+ if (isBoolean) {
+ Boolean booleanValue;
+ if (value instanceof String) {
+ booleanValue = Boolean.valueOf((String) value);
+ } else {
+ booleanValue = (Boolean) value;
+ }
+ String[] boolFields = fields.numFields();
+ for (String propName : boolFields) {
+ criterion = or(criterion, Restrictions.eq(propName,
+ booleanValue));
+ }
+ }
+ //timeFields
+ String[] timeFields = fields.dateFields();
+ for (String propName : timeFields) {
+ criterion = or(criterion, Restrictions.sqlRestriction(propName
+ + " like '" + textValue + "'"));
+ }
+ return criterion;
+ }
+
+ @Deprecated
+ private Criterion or(Criterion crit1, Criterion crit2) {
+ if (crit1 == null) {
+ return crit2;
+ }
+ if (crit2 == null) {
+ return crit1;
+ }
+ return Restrictions.or(crit1, crit2);
+ }
+
+ public void addTopiaEntityListener(TopiaEntityListener listener) {
+ getContext().addTopiaEntityListener((Class<TopiaEntity>) entityClass,
+ listener);
+ }
+
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getContext().addTopiaEntityVetoable((Class<TopiaEntity>) entityClass,
+ vetoable);
+ }
+
+ public void removeTopiaEntityListener(TopiaEntityListener listener) {
+ getContext().removeTopiaEntityListener(
+ (Class<TopiaEntity>) entityClass, listener);
+ }
+
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getContext().removeTopiaEntityVetoable(
+ (Class<TopiaEntity>) entityClass, vetoable);
+ }
+
+} //TopiaDAOAbstract
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,299 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaDAODelegator.java
+ *
+ * Created: 30 déc. 2005 22:28:48
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.security.Permission;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.event.TopiaEntityListener;
+import org.codelutin.topia.event.TopiaEntityVetoable;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+
+/**
+ * Cette classe est utilisé par les DAO générés pour encapsuler un véritable
+ * DAO (Hibernate, FlatFile)
+ * On utilise donc le pattern (TODO retrouver le nom du pattern) qui permet
+ * de générer les classes sans ce soucier de quel DAO va etre utilisé
+ * a l'execution.
+ *
+ * @author poussin
+ *
+ */
+
+public class TopiaDAODelegator<Entity extends TopiaEntity> implements
+ TopiaDAO<Entity> {
+
+ /**
+ * DAO reel sur lequel on peut s'appuyer pour faire les requetes
+ */
+ protected TopiaDAO<Entity> parentDAO = null;
+
+ /**
+ * A priori seul les enfants on besoin de le recuperer
+ */
+ protected TopiaDAO<Entity> getParentDAO() {
+ return parentDAO;
+ }
+
+ /**
+ * Le setter est public car potentiellement le context qui le cree n'est
+ * pas dans le meme package, mais seul le context doit utiliser cette
+ * methode
+ */
+ public void setParentDAO(TopiaDAO<Entity> v) {
+ this.parentDAO = v;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#init(org.codelutin.topia.TopiaContextImpl, java.lang.Class)
+ */
+ public void init(TopiaContextImplementor context, Class entityClass)
+ throws TopiaException {
+ // rien a faire cette methode a ete appele sur le parentDAO
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#getEntityClass()
+ */
+ public Class<Entity> getEntityClass() {
+ return getParentDAO().getEntityClass();
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#getContext()
+ */
+ public TopiaContextImplementor getContext() {
+ return getParentDAO().getContext();
+ }
+
+ public void commitTransaction() throws TopiaException {
+ getParentDAO().commitTransaction();
+ }
+
+ public void rollbackTransaction() throws TopiaException {
+ getParentDAO().rollbackTransaction();
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object...)
+ */
+ public Entity create(Object... properties) throws TopiaException {
+ return getParentDAO().create(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#create(java.util.Map)
+ */
+ public Entity create(Map<String, Object> properties) throws TopiaException {
+ return getParentDAO().create(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#update(Entity)
+ */
+ public Entity update(Entity e) throws TopiaException {
+ return getParentDAO().update(e);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#delete(Entity)
+ */
+ public void delete(Entity e) throws TopiaException {
+ getParentDAO().delete(e);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByTopiaId(java.lang.Object)
+ */
+ public Entity findByTopiaId(String k) throws TopiaException {
+ return getParentDAO().findByTopiaId(k);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAll()
+ */
+ public List<Entity> findAll() throws TopiaException {
+ return getParentDAO().findAll();
+ }
+
+ public List<Entity> findAllWithOrder(String... propertyNames)
+ throws TopiaException {
+ return getParentDAO().findAllWithOrder(propertyNames);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#size()
+ */
+ public int size() throws TopiaException {
+ return getParentDAO().size();
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map)
+ */
+ public Entity findByPrimaryKey(Map<String, Object> keys)
+ throws TopiaException {
+ return getParentDAO().findByPrimaryKey(keys);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object...)
+ */
+ public Entity findByPrimaryKey(Object... k) throws TopiaException {
+ return getParentDAO().findByPrimaryKey(k);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object)
+ */
+ public Entity findByProperty(String propertyName, Object value)
+ throws TopiaException {
+ return getParentDAO().findByProperty(propertyName, value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object...)
+ */
+ public Entity findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+ return getParentDAO().findByProperties(propertyName, value, others);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
+ */
+ public Entity findByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ return getParentDAO().findByProperties(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object)
+ */
+ public List<Entity> findAllByProperty(String propertyName, Object value)
+ throws TopiaException {
+ return getParentDAO().findAllByProperty(propertyName, value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object...)
+ */
+ public List<Entity> findAllByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+ return getParentDAO().findAllByProperties(propertyName, value, others);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map)
+ */
+ public List<Entity> findAllByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ return getParentDAO().findAllByProperties(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
+ */
+ public Entity findContainsProperties(Map<String, Collection> properties)
+ throws TopiaException {
+ return getParentDAO().findContainsProperties(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
+ */
+ public Entity findContainsProperties(String propertyName,
+ Collection values, Object... others) throws TopiaException {
+ return getParentDAO().findContainsProperties(propertyName, values,
+ others);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
+ */
+ public List<Entity> findAllContainsProperties(
+ Map<String, Collection> properties) throws TopiaException {
+ return getParentDAO().findAllContainsProperties(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
+ */
+ public List<Entity> findAllContainsProperties(String propertyName,
+ Collection values, Object... others) throws TopiaException {
+ return getParentDAO().findAllContainsProperties(propertyName, values,
+ others);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener)
+ */
+ public void addTopiaEntityListener(TopiaEntityListener listener) {
+ getParentDAO().addTopiaEntityListener(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable)
+ */
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getParentDAO().addTopiaEntityVetoable(vetoable);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener)
+ */
+ public void removeTopiaEntityListener(TopiaEntityListener listener) {
+ getParentDAO().removeTopiaEntityListener(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable)
+ */
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getParentDAO().removeTopiaEntityVetoable(vetoable);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
+ */
+ public List<Permission> getRequestPermission(String topiaId, int actions)
+ throws TopiaException {
+ return getParentDAO().getRequestPermission(topiaId, actions);
+ }
+
+} //TopiaDAODelegator
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,133 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaEntity.java
+ *
+ * Created: 28 déc. 2005 22:48:10
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.beans.PropertyChangeListener;
+import java.beans.VetoableChangeListener;
+import java.util.Date;
+import java.util.List;
+
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+
+/**
+ * Toutes les methodes set ne doivent être utilisé que par le framework. Elle
+ * sont publique car on ne peut pas faire autrement sur une interface.
+ *
+ * @author poussin
+ */
+@SearchFields
+public interface TopiaEntity {
+
+ public String getTopiaId();
+
+ public void setTopiaId(String v);
+
+ public long getTopiaVersion();
+
+ public void setTopiaVersion(long v);
+
+ /**
+ * @return Returns the topiaCreateTime.
+ */
+ public Date getTopiaCreateDate();
+
+ /**
+ * @param topiaCreateTime The topiaCreateTime to set.
+ */
+ public void setTopiaCreateDate(Date topiaCreatedate);
+
+ public TopiaContext getTopiaContext();
+
+ /**
+ * called just after object creation and initialisation
+ * each entity impl can overide it to do something after creation
+ * @throws TopiaException
+ */
+ public void postCreate() throws TopiaException;
+
+ public void update() throws TopiaException;
+
+ public void delete() throws TopiaException;
+
+ /**
+ * Return all object that must be deleted if this object is deleted
+ * @throws TopiaException
+ */
+ public List<TopiaEntity> getComposite() throws TopiaException;
+
+ /**
+ * Return all object that are aggregate with this instance, aggreate object
+ * are not removed automaticaly
+ * @throws TopiaException
+ */
+ public List<TopiaEntity> getAggregate() throws TopiaException;
+
+ public void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener);
+
+ public void addPropertyChangeListener(PropertyChangeListener listener);
+
+ public void addVetoableChangeListener(String propertyName,
+ VetoableChangeListener vetoable);
+
+ public void addVetoableChangeListener(VetoableChangeListener vetoable);
+
+ public void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener);
+
+ public void removePropertyChangeListener(PropertyChangeListener listener);
+
+ public void removeVetoableChangeListener(String propertyName,
+ VetoableChangeListener vetoable);
+
+ public void removeVetoableChangeListener(VetoableChangeListener vetoable);
+
+ public void addPropertyListener(String propertyName,
+ PropertyChangeListener listener);
+
+ public void addPropertyListener(PropertyChangeListener listener);
+
+ public void addVetoableListener(String propertyName,
+ VetoableChangeListener vetoable);
+
+ public void addVetoableListener(VetoableChangeListener vetoable);
+
+ public void removePropertyListener(String propertyName,
+ PropertyChangeListener listener);
+
+ public void removePropertyListener(PropertyChangeListener listener);
+
+ public void removeVetoableListener(String propertyName,
+ VetoableChangeListener vetoable);
+
+ public void removeVetoableListener(VetoableChangeListener vetoable);
+
+} //TopiaEntity
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityAbstract.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityAbstract.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityAbstract.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,342 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/*******************************************************************************
+ * TopiaEntityAbstract.java
+ *
+ * Created: 28 déc. 2005 22:50:42
+ *
+ * @author poussin
+ *
+ * @version $Revision$
+ *
+ * Last update: $Date$ by : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.beans.VetoableChangeListener;
+import java.beans.VetoableChangeSupport;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+
+/**
+ * Classe de base de toutes les entités, cela permet de concentrer le code
+ * technique dans cette classe. L'identifiant peut-etre n'importe quoi Aucune
+ * restriction n'est faite dessus, il peut meme changer entre deux types
+ * d'entité si cela ne pose pas d'autre probleme (heritage entre ces entités).
+ *
+ * @author poussin
+ */
+public abstract class TopiaEntityAbstract implements TopiaEntity, Serializable {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(TopiaEntityAbstract.class);
+
+ protected String topiaId;
+
+ protected long topiaVersion;
+
+ protected Date topiaCreateDate = new Date();
+
+ transient protected TopiaContext topiaContext = null;
+
+ transient protected VetoableChangeSupport readVetoables = new VetoableChangeSupport(
+ this);
+ transient protected PropertyChangeSupport readListeners = new PropertyChangeSupport(
+ this);
+ transient protected VetoableChangeSupport writeVetoables = new VetoableChangeSupport(
+ this);
+ transient protected PropertyChangeSupport writeListeners = new PropertyChangeSupport(
+ this);
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#getTopiaId()
+ */
+ public String getTopiaId() {
+ return topiaId;
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#setTopiaId(String)
+ */
+ public void setTopiaId(String v) {
+ this.topiaId = v;
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#getTopiaVersion()
+ */
+ public long getTopiaVersion() {
+ return topiaVersion;
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#setTopiaVersion(long)
+ */
+ public void setTopiaVersion(long v) {
+ this.topiaVersion = v;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#getTopiaCreateTime()
+ */
+ public Date getTopiaCreateDate() {
+ return topiaCreateDate;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#setTopiaCreateTime(java.util.Date)
+ */
+ public void setTopiaCreateDate(Date topiaCreateDate) {
+ this.topiaCreateDate = topiaCreateDate;
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#getTopiaContext()
+ */
+ public TopiaContext getTopiaContext() {
+ return topiaContext;
+ }
+
+ /**
+ * @param context The context to set.
+ */
+ public void setTopiaContext(TopiaContext context) throws TopiaException {
+ if (this.topiaContext == null) {
+ this.topiaContext = context;
+ } else {
+ throw new TopiaException("Remplacement du contexte interdit");
+ }
+ }
+
+ public void postCreate() throws TopiaException {
+ // do nothing by default
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#update()
+ */
+ public void update() throws TopiaException {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.persistence.TopiaEntity#delete()
+ */
+ public void delete() throws TopiaException {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaEntity#getComposite()
+ */
+ public List<TopiaEntity> getComposite() throws TopiaException {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaEntity#getAggregate()
+ */
+ public List<TopiaEntity> getAggregate() throws TopiaException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * On utilise la date de creation comme hash code, cette date ne varie pas
+ * au cours du temps
+ */
+ @Override
+ public int hashCode() {
+ int result = getTopiaCreateDate().hashCode();
+ return result;
+ }
+
+ /**
+ * On est sur que les objets sont bien les memes car s'il n'ont pas d'id
+ * cela veut dire qu'il ne vienne pas de la meme session donc qu'il sont
+ * nouveau et different, ou bien qu'ils viennent de la meme session et dans
+ * ce cas l'egalite == fonctionne.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof TopiaEntity == false) {
+ return false;
+ }
+ TopiaEntity other = (TopiaEntity) obj;
+ if (getTopiaId() == null || other.getTopiaId() == null) {
+ return false;
+ }
+ boolean result = getTopiaId().equals(other.getTopiaId());
+ return result;
+ }
+
+ protected void fireOnPreRead(String propertyName, Object value) {
+ TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ if (contextImplementor != null) {
+ contextImplementor.getFiresSupport().fireOnPreRead(readVetoables,
+ this, propertyName, value);
+ }
+ }
+
+ protected void fireOnPostRead(String propertyName, Object value) {
+ TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ if (contextImplementor != null) {
+ contextImplementor.getFiresSupport().fireOnPostRead(readListeners,
+ this, propertyName, value);
+ }
+ }
+
+ protected void fireOnPostRead(String propertyName, int index, Object value) {
+ TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ if (contextImplementor != null) {
+ contextImplementor.getFiresSupport().fireOnPostRead(readListeners,
+ this, propertyName, index, value);
+ }
+ }
+
+ protected void fireOnPreWrite(String propertyName, Object oldValue,
+ Object newValue) {
+ TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ if (contextImplementor != null) {
+ contextImplementor.getFiresSupport().fireOnPreWrite(writeVetoables,
+ this, propertyName, oldValue, newValue);
+ }
+ }
+
+ protected void fireOnPostWrite(String propertyName, Object oldValue,
+ Object newValue) {
+ TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ if (contextImplementor != null) {
+ contextImplementor.getFiresSupport().fireOnPostWrite(
+ writeListeners, this, propertyName, oldValue, newValue);
+ }
+ }
+
+ protected void fireOnPostWrite(String propertyName, int index,
+ Object oldValue, Object newValue) {
+ TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
+ if (contextImplementor != null) {
+ contextImplementor.getFiresSupport().fireOnPostWrite(
+ writeListeners, this, propertyName, index, oldValue,
+ newValue);
+ }
+ }
+
+ public void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ writeListeners.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ writeListeners.addPropertyChangeListener(listener);
+ }
+
+ public void addVetoableChangeListener(String propertyName,
+ VetoableChangeListener vetoable) {
+ writeVetoables.addVetoableChangeListener(propertyName, vetoable);
+ }
+
+ public void addVetoableChangeListener(VetoableChangeListener vetoable) {
+ writeVetoables.addVetoableChangeListener(vetoable);
+ }
+
+ public void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ writeListeners.removePropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ writeListeners.removePropertyChangeListener(listener);
+ }
+
+ public void removeVetoableChangeListener(String propertyName,
+ VetoableChangeListener vetoable) {
+ writeVetoables.removeVetoableChangeListener(propertyName, vetoable);
+ }
+
+ public void removeVetoableChangeListener(VetoableChangeListener vetoable) {
+ writeVetoables.removeVetoableChangeListener(vetoable);
+ }
+
+ public void addPropertyListener(String propertyName,
+ PropertyChangeListener listener) {
+ readListeners.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void addPropertyListener(PropertyChangeListener listener) {
+ readListeners.addPropertyChangeListener(listener);
+ }
+
+ public void addVetoableListener(String propertyName,
+ VetoableChangeListener vetoable) {
+ readVetoables.addVetoableChangeListener(propertyName, vetoable);
+ }
+
+ public void addVetoableListener(VetoableChangeListener vetoable) {
+ readVetoables.addVetoableChangeListener(vetoable);
+ }
+
+ public void removePropertyListener(String propertyName,
+ PropertyChangeListener listener) {
+ readListeners.removePropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyListener(PropertyChangeListener listener) {
+ readListeners.removePropertyChangeListener(listener);
+ }
+
+ public void removeVetoableListener(String propertyName,
+ VetoableChangeListener vetoable) {
+ readVetoables.removeVetoableChangeListener(propertyName, vetoable);
+ }
+
+ public void removeVetoableListener(VetoableChangeListener vetoable) {
+ readVetoables.removeVetoableChangeListener(vetoable);
+ }
+
+} //TopiaEntityAbstract
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityAbstract.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,177 @@
+package org.codelutin.topia.persistence;
+
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/** @author chemit */
+public class TopiaEntityEnumEntry<T extends TopiaEntity> implements
+ java.io.Serializable {
+
+ /** the contract class of the entity's type. */
+ protected Class<T> contractClass;
+
+ /** the concrete implementation class of the entity's type. */
+ protected Class<T> implementationClass;
+
+ private static final long serialVersionUID = 1L;
+
+ public TopiaEntityEnumEntry(Class<T> contractClass) {
+ this.contractClass = contractClass;
+ }
+
+ public Class<T> getContractClass() {
+ return contractClass;
+ }
+
+ @SuppressWarnings( { "unchecked" })
+ public Class<T> getImplementationClass() {
+ if (implementationClass == null) {
+ try {
+ implementationClass = (Class<T>) Class.forName(contractClass
+ .getName()
+ + "Impl");
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(
+ "could not find implementation for entity contract "
+ + contractClass);
+ }
+ }
+ return implementationClass;
+ }
+
+ public TopiaDAO<T> getDAO(TopiaContext ctxt) throws TopiaException {
+ TopiaContextImplementor ci = (TopiaContextImplementor) ctxt;
+ return ci.getDAO(contractClass);
+ }
+
+ public T create(TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ T newInstance = dao.create();
+ // attach topia context to entity (to allow propertyChangeSupport for entity)
+ ((TopiaEntityAbstract) newInstance).setTopiaContext(ctxt);
+ return newInstance;
+ }
+
+ public T create(TopiaContext ctxt, Object... properties)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.create(properties);
+ }
+
+ public T create(TopiaContext ctxt, Map<String, Object> properties)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.create(properties);
+ }
+
+ public T update(T entity, TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.update(entity);
+ }
+
+ public void delete(T entity, TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ dao.delete(entity);
+ }
+
+ public int size(TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.size();
+ }
+
+ public List<T> findAll(TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAll();
+ }
+
+ public List<T> findAllWithOrder(TopiaContext ctxt, String... propertyNames)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllWithOrder(propertyNames);
+ }
+
+ public T findByTopiaId(String topiaId, TopiaContext ctxt)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByTopiaId(topiaId);
+ }
+
+ public T findByPrimaryKey(TopiaContext ctxt, Map<String, Object> keys)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByPrimaryKey(keys);
+ }
+
+ public T findByPrimaryKey(TopiaContext ctxt, Object... k)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByPrimaryKey(k);
+ }
+
+ public T findByProperty(TopiaContext ctxt, String propertyName, Object value)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperty(propertyName, value);
+ }
+
+ public T findByProperties(TopiaContext ctxt, String propertyName,
+ Object value, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperties(propertyName, value, others);
+ }
+
+ public T findByProperties(TopiaContext ctxt, Map<String, Object> properties)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperties(properties);
+ }
+
+ public List<T> findAllByProperty(TopiaContext ctxt, String propertyName,
+ Object value) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperty(propertyName, value);
+ }
+
+ public List<T> findAllByProperties(TopiaContext ctxt, String propertyName,
+ Object value, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperties(propertyName, value, others);
+ }
+
+ public List<T> findAllByProperties(TopiaContext ctxt,
+ Map<String, Object> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperties(properties);
+ }
+
+ public T findContainsProperties(TopiaContext ctxt,
+ Map<String, Collection> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findContainsProperties(properties);
+ }
+
+ public T findContainsProperties(TopiaContext ctxt, String propertyName,
+ Collection values, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findContainsProperties(propertyName, values, others);
+ }
+
+ public List<T> findAllContainsProperties(TopiaContext ctxt,
+ Map<String, Collection> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllContainsProperties(properties);
+ }
+
+ public List<T> findAllContainsProperties(TopiaContext ctxt,
+ String propertyName, Collection values, Object... others)
+ throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllContainsProperties(propertyName, values, others);
+ }
+
+}
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaId.java)
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,142 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaId.java
+ *
+ * Created: 6 juil. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * Copyright Code Lutin
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.io.Serializable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.codelutin.topia.TopiaNotFoundException;
+
+/**
+* Classe representant un Id, utilisable par JDO. Cette classe contient aussi un
+* ensemble de methode static utile pour la manipulation des topiaId
+*/
+public class TopiaId implements Serializable { // TopiaId
+
+ /** */
+ private static final long serialVersionUID = 1L;
+
+ public String topiaId = null;
+
+ public TopiaId() {
+ }
+
+ public TopiaId(String topiaId) {
+ this.topiaId = topiaId;
+ }
+
+ public int hashCode() {
+ if (topiaId == null) {
+ Logger.getLogger(getClass().getName() + ".hashCode").log(
+ Level.WARNING, "Use null topiaId", new Throwable());
+ return 0;
+ }
+ return topiaId.hashCode();
+ }
+
+ public boolean equals(Object o) {
+ return topiaId.equals(o);
+ }
+
+ public String toString() {
+ return topiaId;
+ }
+
+ /**
+ * Cree un topiaId pour une certaine classe
+ */
+ public static String create(Class clazz) {
+ if (!clazz.isInterface()) {
+ throw new IllegalArgumentException(
+ "Only interface is permit to create id: " + clazz);
+ }
+ double random = Math.random();
+ while (Double.toString(random).contains("E-")) {
+ random = Math.random();
+ }
+ return clazz.getName() + "#" + System.currentTimeMillis() + "#"
+ + random;
+ }
+
+ /**
+ * Extrait la classe du topiaId
+ * @throws ClassNotFoundException
+ */
+ public static Class getClassName(String topiaId)
+ throws TopiaNotFoundException {
+ String classname = getClassNameAsString(topiaId);
+ try {
+ Class result = Class.forName(classname);
+ return result;
+ } catch (ClassNotFoundException eee) {
+ throw new TopiaNotFoundException("Can't find class for " + topiaId,
+ eee);
+ }
+ }
+
+ /**
+ * Return class name id topiaId is id, and empty string if topiaId is
+ * not an id
+ *
+ * @param topiaId
+ * @return
+ */
+ public static String getClassNameAsString(String topiaId) {
+ String result = "";
+ int i = topiaId.indexOf("#");
+ if (i > 0) {
+ result = topiaId.substring(0, i);
+ }
+ return result;
+ }
+
+ /**
+ * Verifie si l'id passé en paramètre est bien un Id topia, c-a-d si la
+ * forme est bien classname#timemillis#random et si le classname est
+ * celui d'une classe valide, c-a-d que le systeme arrive a trouver
+ */
+ public static boolean isValidId(String topiaId) {
+ try {
+ if (topiaId.matches(".*?#[0-9]+#[0-9.]+")) {
+ getClassName(topiaId);
+ return true;
+ }
+ return false;
+ } catch (Exception eee) {
+ Logger.getLogger(TopiaId.class.getName() + ".isValidId").log(
+ Level.WARNING, "Error during verfication of topiaId", eee);
+ return false;
+ }
+ }
+
+} // TopiaId
+
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/TopiaId.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/flatfile (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile)
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/flatfile
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -253,12 +253,13 @@
* @see org.codelutin.topia.persistence.TopiaDAO#update(org.codelutin.topia.persistence.TopiaEntity)
*/
public Entity update(Entity e) throws TopiaException {
- getContext().getFiresSupport().fireOnPreUpdate(getContext(), e, new Object[]{});
+ getContext().getFiresSupport().fireOnPreUpdate(getContext(), e,
+ new Object[] {});
// le topiaId contient le nom du fichier a partir duquel l'entity
// a ete chargé
try {
- String oldId = (String)e.getTopiaId();
+ String oldId = (String) e.getTopiaId();
String newId = (String) PropertyUtils.getProperty(e, key);
// Si l'identifiant a changé alors il faut aussi changer le nom
@@ -314,7 +315,8 @@
out.close();
}
- getContext().getFiresSupport().fireOnPostUpdate(getContext(), e, new Object[]{});
+ getContext().getFiresSupport().fireOnPostUpdate(getContext(), e,
+ new Object[] {});
return e;
} catch (IllegalAccessException eee) {
@@ -334,7 +336,8 @@
* @see org.codelutin.topia.persistence.TopiaDAO#delete(org.codelutin.topia.persistence.TopiaEntity)
*/
public void delete(Entity e) throws TopiaException {
- getContext().getFiresSupport().fireOnPreDelete(getContext(), e, new Object[]{});
+ getContext().getFiresSupport().fireOnPreDelete(getContext(), e,
+ new Object[] {});
// le topiaId contient le nom du fichier a partir duquel l'entity
// a ete chargé
String oldId = e.getTopiaId().toString();
@@ -342,7 +345,8 @@
cache.remove(f);
f.delete();
- getContext().getFiresSupport().fireOnPostDelete(getContext(), e, new Object[]{});
+ getContext().getFiresSupport().fireOnPostDelete(getContext(), e,
+ new Object[] {});
}
@@ -372,7 +376,8 @@
protected Entity findByFile(File f) throws TopiaException {
long lastModified = f.lastModified();
Entity e = cache.get(f);
- getContext().getFiresSupport().fireOnPreLoad(getContext(), e, new Object[]{});
+ getContext().getFiresSupport().fireOnPreLoad(getContext(), e,
+ new Object[] {});
// si on a pas encore l'entity ou que le fichier est plus recent
// il faut relire l'entité
if (e == null) {
@@ -431,7 +436,8 @@
// on le met en cache car on doit toujours retourner
// la meme instance au cours du temps
cache.put(f, e);
- getContext().getFiresSupport().fireOnPostLoad(getContext(), e, new Object[]{});
+ getContext().getFiresSupport().fireOnPostLoad(getContext(), e,
+ new Object[] {});
}
return e;
}
@@ -460,8 +466,10 @@
return result;
}
- public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
- throw new IllegalStateException("findAllWithOrder method is not implemented by "+getClass());
+ public List<Entity> findAllWithOrder(String... propertyNames)
+ throws TopiaException {
+ throw new IllegalStateException(
+ "findAllWithOrder method is not implemented by " + getClass());
}
/**
@@ -512,12 +520,14 @@
return null;
}
- public Object query(Projection projection, Criterion criterion) throws TopiaException {
+ public Object query(Projection projection, Criterion criterion)
+ throws TopiaException {
// TODO Auto-generated method stub
return null;
}
- public List queryAll(Projection projection, Criterion criterion) throws TopiaException {
+ public List queryAll(Projection projection, Criterion criterion)
+ throws TopiaException {
// TODO Auto-generated method stub
return null;
}
@@ -531,7 +541,7 @@
// TODO Auto-generated method stub
return null;
}
-
+
public Criteria createCriteria(FlushMode mode) throws TopiaException {
// TODO Auto-generated method stub
return null;
@@ -541,7 +551,8 @@
* (non-Javadoc)
* @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
*/
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
+ public List<Permission> getRequestPermission(String topiaId, int actions)
+ throws TopiaException {
return null;
}
}
Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate)
Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -56,22 +56,23 @@
// FIXME les Entity ne doivent pas forcement etendre TopiaEntity de cette
// facon on peut utiliser le framework sans la generation et sur des POJO
// existant. Cela implique de faire un peu attention au codage
-public class TopiaDAOHibernate<Entity extends TopiaEntity> extends TopiaDAOAbstract<Entity> {
+public class TopiaDAOHibernate<Entity extends TopiaEntity> extends
+ TopiaDAOAbstract<Entity> {
- private static Log log = LogFactory.getLog(TopiaDAOHibernate.class);
+ private static Log log = LogFactory.getLog(TopiaDAOHibernate.class);
/* (non-Javadoc)
* @see org.codelutin.topia.TopiaDAO#create()
*/
@Override
public Entity create(Map<String, Object> properties) throws TopiaException {
- Entity result = super.create(properties);
- // on fait un save maintenant, car puisqu'on a creer l'entity au
- // travers du DAO, on s'attend a l'avoir a disposition tout de
- // suite pour les requetes sans avoir a faire un update dessus
- getSession().save(result);
- getContext().getFiresSupport().warnOnCreateEntity(result);
- return result;
+ Entity result = super.create(properties);
+ // on fait un save maintenant, car puisqu'on a creer l'entity au
+ // travers du DAO, on s'attend a l'avoir a disposition tout de
+ // suite pour les requetes sans avoir a faire un update dessus
+ getSession().save(result);
+ getContext().getFiresSupport().warnOnCreateEntity(result);
+ return result;
}
/* (non-Javadoc)
@@ -114,22 +115,25 @@
public List<Entity> findAll() throws TopiaException {
try {
Criteria criteria = createCriteria(FlushMode.AUTO);
- List<Entity> result = (List<Entity>)criteria.list();
- result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ List<Entity> result = (List<Entity>) criteria.list();
+ result = getContext().getFiresSupport().fireEntitiesLoad(context,
+ result);
return result;
} catch (HibernateException eee) {
throw new TopiaException(eee);
}
}
- public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
+ public List<Entity> findAllWithOrder(String... propertyNames)
+ throws TopiaException {
try {
Criteria criteria = createCriteria(FlushMode.AUTO);
for (String propertyName : propertyNames) {
criteria.addOrder(Order.asc(propertyName));
}
- List<Entity> result = (List<Entity>)criteria.list();
- result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ List<Entity> result = (List<Entity>) criteria.list();
+ result = getContext().getFiresSupport().fireEntitiesLoad(context,
+ result);
return result;
} catch (HibernateException eee) {
throw new TopiaException(eee);
@@ -172,8 +176,9 @@
try {
Criteria criteria = createCriteria(FlushMode.AUTO);
criteria.add(criterion);
- List<Entity> result = (List<Entity>)criteria.list();
- result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ List<Entity> result = (List<Entity>) criteria.list();
+ result = getContext().getFiresSupport().fireEntitiesLoad(context,
+ result);
return result;
} catch (HibernateException eee) {
throw new TopiaException(eee);
@@ -188,14 +193,18 @@
Criteria criteria = createCriteria(FlushMode.AUTO);
criteria.add(criterion);
criteria.setMaxResults(1);
- List<Entity> result = (List<Entity>)criteria.list();
- int sizeBefore = (result != null?result.size():0);
- result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
- int sizeAfter = (result != null?result.size():0);
+ List<Entity> result = (List<Entity>) criteria.list();
+ int sizeBefore = (result != null ? result.size() : 0);
+ result = getContext().getFiresSupport().fireEntitiesLoad(context,
+ result);
+ int sizeAfter = (result != null ? result.size() : 0);
if (sizeAfter < sizeBefore) {
- if (log.isDebugEnabled()) {
- log.debug((sizeBefore - sizeAfter) + " element(s) removed. Filter entity: " + entityClass.getName() + " - criterion: " + criterion);
- }
+ if (log.isDebugEnabled()) {
+ log.debug((sizeBefore - sizeAfter)
+ + " element(s) removed. Filter entity: "
+ + entityClass.getName() + " - criterion: "
+ + criterion);
+ }
}
if (result != null && result.size() > 0) {
Entity elem = result.get(0);
@@ -207,48 +216,48 @@
}
}
-//FIXME : Commenté car impossible de trouver le bon Criterion
+ //FIXME : Commenté car impossible de trouver le bon Criterion
-// /* (non-Javadoc)
-// * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
-// */
-// public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException {
-// try {
-// Criteria criteria = createCriteria(FlushMode.AUTO);
-// for (Entry<String, Collection> entry : properties.entrySet()) {
-// for (Object value : entry.getValue()) {
-// criteria.add(Restrictions.eq(entry.getKey(), value));
-// }
-// }
-// criteria.setMaxResults(1);
-// List<Entity> results = (List<Entity>)criteria.list();
-// if (results.size() > 0) {
-// return (Entity)results.get(0);
-// } else {
-// return null;
-// }
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
-// }
-//
-// /* (non-Javadoc)
-// * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
-// */
-// public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
-// try {
-// Criteria criteria = createCriteria(FlushMode.AUTO);
-// for (Entry<String, Collection> entry : properties.entrySet()) {
-// for (Object value : entry.getValue()) {
-// criteria.add(Restrictions.eq(entry.getKey(), value));
-// }
-// }
-// List<Entity> result = (List<Entity>)criteria.list();
-// return result;
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
-// }
+ // /* (non-Javadoc)
+ // * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
+ // */
+ // public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException {
+ // try {
+ // Criteria criteria = createCriteria(FlushMode.AUTO);
+ // for (Entry<String, Collection> entry : properties.entrySet()) {
+ // for (Object value : entry.getValue()) {
+ // criteria.add(Restrictions.eq(entry.getKey(), value));
+ // }
+ // }
+ // criteria.setMaxResults(1);
+ // List<Entity> results = (List<Entity>)criteria.list();
+ // if (results.size() > 0) {
+ // return (Entity)results.get(0);
+ // } else {
+ // return null;
+ // }
+ // } catch (HibernateException eee) {
+ // throw new TopiaException(eee);
+ // }
+ // }
+ //
+ // /* (non-Javadoc)
+ // * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
+ // */
+ // public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
+ // try {
+ // Criteria criteria = createCriteria(FlushMode.AUTO);
+ // for (Entry<String, Collection> entry : properties.entrySet()) {
+ // for (Object value : entry.getValue()) {
+ // criteria.add(Restrictions.eq(entry.getKey(), value));
+ // }
+ // }
+ // List<Entity> result = (List<Entity>)criteria.list();
+ // return result;
+ // } catch (HibernateException eee) {
+ // throw new TopiaException(eee);
+ // }
+ // }
/**
* Renvoie un Criteria créé avec l'entityClass
@@ -272,8 +281,9 @@
* (non-Javadoc)
* @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
*/
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
+ public List<Permission> getRequestPermission(String topiaId, int actions)
+ throws TopiaException {
return null;
}
-
+
} //TopiaDAOHibernate
Copied: topia/trunk/topia-persistence/src/main/java/topia (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia)
Property changes on: topia/trunk/topia-persistence/src/main/java/topia
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: topia/trunk/topia-persistence/src/main/java/topia/TopiaContext.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/TopiaContext.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/TopiaContext.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,230 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaContext.java
- *
- * Created: 3 janv. 2006 21:18:34
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia;
-
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.List;
-
-import org.codelutin.topia.event.TopiaContextListener;
-import org.codelutin.topia.event.TopiaEntitiesVetoable;
-import org.codelutin.topia.event.TopiaEntityListener;
-import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.event.TopiaTransactionListener;
-import org.codelutin.topia.event.TopiaTransactionVetoable;
-import org.codelutin.topia.framework.TopiaService;
-import org.codelutin.topia.persistence.TopiaEntity;
-
-/**
- * @author poussin
- *
- */
-
-public interface TopiaContext {
-
- /* Adders */
- public void addTopiaEntityListener(TopiaEntityListener listener);
- public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener);
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
- public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable);
- public void addTopiaTransactionListener(TopiaTransactionListener listener);
- public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
- public void addPropertyChangeListener(PropertyChangeListener listener);
- public void addTopiaContextListener(TopiaContextListener listener);
- public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
-
- /* Removers */
- public void removeTopiaEntityListener(TopiaEntityListener listener);
- public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener);
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
- public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable);
- public void removeTopiaTransactionListener(TopiaTransactionListener listener);
- public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable);
- public void removePropertyChangeListener(PropertyChangeListener listener);
- public void removeTopiaContextListener(TopiaContextListener listener);
- public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
-
- /**
- * Return true if specific service is available
- * @param <E>
- * @param interfaceService
- * @return
- */
- public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService);
-
- /**
- * Return the service
- * @param <E>
- * @param interfaceService
- * @return
- * @throws TopiaNotFoundException if service is can't be retrieved
- */
- public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException;
-
- /**
- * Permet de créer le schema de la base de données
- * @throws TopiaException if any exception
- */
- public void createSchema() throws TopiaException;
-
- /**
- * Permet de mettre à jour le schema de la base de données
- * @throws TopiaException if any exception
- */
- public void updateSchema() throws TopiaException;
-
- public TopiaContext beginTransaction() throws TopiaException;
-
- /**
- * applique les modifications apporté a ce context sur la base de données.
- * @throws TopiaException if any exception
- */
- public void commitTransaction() throws TopiaException;
-
- /**
- * annule les modifications apporté a ce context
- * @throws TopiaException if any exception
- */
- public void rollbackTransaction() throws TopiaException;
-
- /**
- * Permet de rechercher un entite directement par son TopiaId
- *
- * @param topiaId l'id de l'entite recherche
- * @return l'entite trouvee (ou null si non trouve)
- * @throws TopiaException if any exception
- */
- public TopiaEntity findByTopiaId(String topiaId) throws TopiaException;
-
- /**
- * Permet de faire une requete HQL hibernate directement sur la base
- * @param hql la requete a faire
- * @param args les arguments de la requete
- * @return La liste des resultats
- * @throws TopiaException si une erreur survient durant la requete
- */
- public List find(String hql, Object ... args) throws TopiaException;
-
- /**
- * Permet de faire une requete HQL hibernate directement sur la base
- * en precisant la fenetre des elements a remonter avec les parametres <code>startIndex</code>
- * et <code>endIndex</code>.
- * @param hql la requete a faire
- * @param startIndex la position du premier element a remonter
- * @param endIndex la position du dernier element a remonter
- * @param args les arguments de la requete
- * @return La liste des resultats
- * @throws TopiaException si une erreur survient durant la requete
- */
- public List find(String hql,int startIndex,int endIndex, Object ... args) throws TopiaException;
-
- /**
- * Execute HQL operation on data (Update, Delete)
- * @param hql la requete a faire
- * @param args les arguments de la requete
- * @return The number of entities updated or deleted.
- * @throws TopiaException if any exception
- */
- public int execute(String hql, Object ... args) throws TopiaException;
-
- /**
- * Permet d'ajouter dans le TopiaContext une TopiaEntity créé par un
- * autre context.
- * @param e l'entity a ajouter
- * @throws TopiaException if any exception
- */
- public void add(TopiaEntity e) throws TopiaException;
-
- /**
- * Permet d'importer des données en XML
- * @param xml le flux XML
- * @throws TopiaException si une erreur survient durant l'import
- */
- public void importXML(Reader xml) throws TopiaException;
-
- /**
- * Permet d'exporter certaines données en XML
- * @param xml le flux XML dans lequel il faut ecrire
- * @param entityAndCondition paramètre qui vont par deux, qui represente
- * la classe de l'entity a exporter et la condition where que doit
- * respecter l'objet pour etre exporter
- * (entityClass, condition)
- * @throws TopiaException si une erreur survient durant l'export
- */
- public void exportXML(Writer xml, Object ... entityAndCondition) throws TopiaException;
-
- /**
- * Sauve la base de données dans un format natif a la base, la
- * representation n'est pas portable d'une base a l'autre. Cette methode
- * ne doit être utilisé que pour un stockage temporaire utile à une
- * application
- *
- * @param file le nom du fichier ou stocker les informations
- * @param compress si vrai compress le fichier avec gzip
- *
- * @throws TopiaException if any exception
- */
- public void backup(File file, boolean compress) throws TopiaException;
-
- /**
- * Supprime toutes les tables et autres elements de la database.
- *
- * @param dropDatabase si vrai alors supprime aussi la base de données
- * si la base utilise des fichiers les fichiers seront supprimé (ex: h2)
- * ou sera fait sur la base (pastgresql)
- * @throws TopiaException if any exception
- */
- public void clear(boolean dropDatabase) throws TopiaException;
-
- /**
- * l'inverse de la methode {@link #backup(File,boolean)}
- *
- * @param file le fichier ou prendre les informations, il peut-etre
- * compressé avec gzip ou non.
- *
- * @throws TopiaException if any exception
- */
- public void restore(File file) throws TopiaException;
-
- /**
- * Ferme le contexte
- * @throws TopiaException if any exception
- */
- public void closeContext() throws TopiaException;
-
- /**
- * Indique si le contexte a ete ferme
- * @return <code>true</code> si le context est ferme, <code>false</code> autrement
- */
- public boolean isClosed();
-
-} //TopiaContext
Deleted: topia/trunk/topia-persistence/src/main/java/topia/TopiaContextFactory.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/TopiaContextFactory.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/TopiaContextFactory.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,126 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaContextFactory.java
- *
- * Created: 3 janv. 2006 21:19:37
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Map.Entry;
-
-import org.apache.commons.collections.map.AbstractReferenceMap;
-import org.apache.commons.collections.map.ReferenceMap;
-import org.codelutin.topia.framework.TopiaContextImpl;
-import org.codelutin.topia.framework.TopiaUtil;
-
-
-/**
- * @author poussin
- *
- */
-
-public class TopiaContextFactory {
-
- static final private String DEFAULT_CONFIG_PROPERTIES = "TopiaContextImpl.properties";
-
- /**
- * Cache contenant tous les contexts deja créé.
- */
- @SuppressWarnings("unchecked")
- static protected Map<Properties, TopiaContextImpl> contextCache = new ReferenceMap(
- AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
-
- /**
- * Permet de connaitre la liste des contexts encore en memoire, utile
- * pour du debuggage
- * @return la liste des urls de connexion
- */
- static public List<String> getContextOpened() {
- List<String> result = new ArrayList<String>();
- for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
- if (e.getValue() != null) {
- result.add(e.getKey().getProperty("hibernate.connection.url"));
- }
- }
- return result;
- }
-
- /**
- * Used when TopiaContext root is closed
- * @param context closed
- */
- static public void removeContext(TopiaContext context) {
- Properties key = null;
- for (Entry<Properties, TopiaContextImpl> e : contextCache.entrySet()) {
- if (e.getValue() == context) {
- key = e.getKey();
- break;
- }
- }
- if (key != null) {
- contextCache.remove(key);
- }
- }
-
- /**
- * Utilise par defaut le fichier de propriete TopiaContextImpl.properties
- *
- * @return
- * @throws TopiaNotFoundException Si le fichier de configuration par defaut
- * n'est pas retrouvé.
- */
- static public TopiaContext getContext() throws TopiaNotFoundException {
- Properties config = TopiaUtil.getProperties(DEFAULT_CONFIG_PROPERTIES);
- TopiaContext result = getContext(config);
- return result;
- }
-
- /**
- * Methode static permettant de recuperer un context. Si on donne plusieurs
- * fois le meme objet config, on obtient la meme instance de TopiaContextImpl.
- * Si le context qui devrait etre retourné est ferme, alors un nouveau est
- * creer et retourné
- *
- * @param config
- * @return Un TopiaContext ouvert
- * @throws TopiaNotFoundException
- */
- static public TopiaContext getContext(Properties config) throws TopiaNotFoundException {
- TopiaContextImpl result = contextCache.get(config);
- if (result == null || result.isClosed()) {
- result = new TopiaContextImpl(config);
- contextCache.put((Properties) config.clone(), result);
- }
- return result;
- }
-
-}
-
-
Deleted: topia/trunk/topia-persistence/src/main/java/topia/TopiaException.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/TopiaException.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/TopiaException.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,73 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaException.java
- *
- * Created: 23 déc. 2005 23:03:36
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia;
-
-/**
- * @author poussin
- *
- */
-public class TopiaException extends Exception {
-
- /** */
- private static final long serialVersionUID = -1251439453383121393L;
-
- /**
- *
- */
- public TopiaException() {
- super();
- }
-
- /**
- * @param message
- */
- public TopiaException(String message) {
- super(message);
- }
-
- /**
- * @param message
- * @param cause
- */
- public TopiaException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * @param cause
- */
- public TopiaException(Throwable cause) {
- super(cause);
- }
-
-}
-
-
-
Deleted: topia/trunk/topia-persistence/src/main/java/topia/TopiaNotFoundException.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/TopiaNotFoundException.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/TopiaNotFoundException.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,72 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaNotFoundException.java
- *
- * Created: 23 déc. 2005 23:04:28
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia;
-
-/**
- * @author poussin
- *
- */
-public class TopiaNotFoundException extends TopiaException {
-
- /** */
- private static final long serialVersionUID = -8206486077608923797L;
-
- /**
- *
- */
- public TopiaNotFoundException() {
- super();
- }
-
- /**
- * @param message
- */
- public TopiaNotFoundException(String message) {
- super(message);
- }
-
- /**
- * @param message
- * @param cause
- */
- public TopiaNotFoundException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * @param cause
- */
- public TopiaNotFoundException(Throwable cause) {
- super(cause);
- }
-}
-
-
-
Deleted: topia/trunk/topia-persistence/src/main/java/topia/TopiaRuntimeException.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/TopiaRuntimeException.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/TopiaRuntimeException.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,66 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia;
-
-/**
- * TopiaRuntimeException
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class TopiaRuntimeException extends RuntimeException {
-
-
- /** Version UID */
- private static final long serialVersionUID = 4706337137948838375L;
-
- /**
- * Constructor
- */
- public TopiaRuntimeException() {
- }
-
- /**
- * Constructor
- * @param message message
- */
- public TopiaRuntimeException(String message) {
- super(message);
- }
-
- /**
- * Constructor
- * @param cause cause
- */
- public TopiaRuntimeException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Constructor
- * @param message message
- * @param cause cause
- */
- public TopiaRuntimeException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/TopiaVetoException.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/TopiaVetoException.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/TopiaVetoException.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,74 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaVetoException.java
- *
- * Created: 5 janv. 2006 00:47:51
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia;
-
-
-/**
- * @author poussin
- *
- */
-
-public class TopiaVetoException extends RuntimeException {
-
- /** */
- private static final long serialVersionUID = 6809613247516488399L;
-
- /**
- *
- */
- public TopiaVetoException() {
- super();
- }
-
- /**
- * @param message
- */
- public TopiaVetoException(String message) {
- super(message);
- }
-
- /**
- * @param message
- * @param cause
- */
- public TopiaVetoException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * @param cause
- */
- public TopiaVetoException(Throwable cause) {
- super(cause);
- }
-
-}
-
-
Deleted: topia/trunk/topia-persistence/src/main/java/topia/package.html
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/package.html 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/package.html 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,131 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
-
-<html>
- <head>
- <meta
- http-equiv="Content-Language"
- content="fr">
- <meta
- http-equiv="Content-Type"
- content="text/html; charset=UTF-8">
-
- <title>ToPIA</title>
- </head>
-
- <body>
- <h1>ToPIA</h1>
-
- <h2>Présentation</h2>
-
- <p>ToPIA est un framework de persistence basé sur Hibernate. Il
- contient un point d'entré le TopiaContext qui permet d'ouvrir des
- transactions qui retourne des TopiaContext fils sur lequel on peut
- récupéré des DAO pour accèder aux entités.</p>
-
- <p>ToPIA offre en plus la possibilité de générer à partir d'une
- fichier XMI toutes les classes utiles pour la persistence. Ce qui
- permet d'évité un travail fastidieux d'ecriture de classe, d'être sur
- que le jour on l'on veut ajouter une méthode technique (getXML, ...) à
- toutes ces entités cela sera fait de façon simple et automatique
- (modification du générateur puis regénération). Et surtout d'avoir des
- classes générés qui permettent un typage fort de l'application (pas de
- cast, pas de générique)</p>
-
- <p>Bien sur il est possible d'utilisé ToPIA sans générateur, il est
- d'ailleurs utilisé ainsi pour les tests</p>
-
- <p>ToPIA contient aussi des classes techniques réutilisables dans ses
- applications pour tout ce qui touche à l'authentification et
- l'autorisation (TopiaUser, TopiaGroup, TopiaPermission) (partie non
- encore développé)</p>
-
- <h2>La persistance</h2>
-
- <p>La persistence se base complètement sur hibernate, mais il est
- aussi possible d'indiquer que certaine classe doivent être sauvé dans
- des fichiers textes plutot qu'une base de données, cette persistence
- est appelée FlatFile.</p>
-
- <p>Le TopiaContext doit être configuré avec un objet Properties.
- Celui-ci peut contenir différentes entrées. Vu que la persistence est
- complètement basé sur hibernate, même si vous n'avez que des entités
- sauvé en FlatFile il vous faudra fournir à hibernate un accès à une
- base de données. Celle-ci peu très bien être une base embarqué comme
- hsql, mckoi ou derby.</p>
-
- <dl>
- <dt>topia.persistence.properties.file</dt>
-
- <dd>le fichier de propriété a utiliser pour configurer
- hibernate</dd>
-
- <dt>topia.persistence.directories</dt>
-
- <dd>la liste des repertoires contenant les mappings hibernates
- (.hbm.xml) la liste de repertoire est separer par des virgules
- ','</dd>
-
- <dt>topia.persistence.classes</dt>
-
- <dd>la liste des classes que doit géré ToPIA. On peut tres bien
- utiliser topia.persistence.directories pour un ensemble d'entié du
- meme repertoire et topia.persistence.classes pour d'autres
- classes</dd>
- </dl>
-
- <dl>
- <dt>topia.dao.flatfile.properties.file</dt>
-
- <dd>indique le fichier de configuration a utiliser en plus de la
- configuration du context</dd>
-
- <dt>topia.dao.flatfile.directory</dt>
-
- <dd>indique le répertoire au sauver les entités</dd>
-
- <dt>topia.dao.flatfile.directory.[fqn-entity]</dt>
-
- <dd>permet de spécifier un répertoire différent pour une entity
- spécifique</dd>
-
- <dt>topia.dao.flatfile.mapping</dt>
-
- <dd>permet d'indique le mapping a utiliser pour les entités</dd>
-
- <dt>topia.dao.flatfile.mapping.[fqn-entity]</dt>
-
- <dd>permet d'indique un mapping différent pour entité</dd>
- </dl>
-
- <p>à la place flatfile il est possible de mettre le FQN du DAO utilisé
- par exemple
- org.codelutin.topia.persistence.flatfile.TopiaDAOFlatFile</p>
-
- <p>Si directory est absent alors "." est utilisé</p>
-
- <p>les mappings s'écrivent de la façon suivant:</p>
-
- <ul>
- <li>ext=extension a ajouter au fichier contenant l'entity</li>
-
- <li>key=attribute</li>
-
- <li>body=attribute</li>
- </ul>
-
- <p>Si key est absent alors on utilise le topiaId, key est utilisé
- comme nom de fichier de sauvegarde</p>
-
- <p>Si body est absent alors on utilise un fichier de propriété pour
- sauver l'entity. Si body est présent seul cet attribut sera sauvé.</p>
-
-<pre>
- topia.dao.flatfile.mapping.key=topiaId
-
- topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.key=name
- topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.body=script
-
-</pre>
- </body>
-</html>
-
Deleted: topia/trunk/topia-persistence/src/main/java/topia/persistence/SearchFields.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/SearchFields.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/persistence/SearchFields.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,66 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
-* SearchFields.java
-*
-* Created: 7 juin 2006
-*
-* @author Arnaud Thimel <thimel(a)codelutin.com>
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-
-package org.codelutin.topia.persistence;
-
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.TYPE;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * Ces annotations permettent de savoir quels sont les champs sur lesquels
- * la recherche pourra s'effectuer.
- */
-@Retention(RUNTIME)
-@Target(TYPE)
-public @interface SearchFields {
-
- /**
- * @return la liste des champs textes
- */
- String [] txtFields() default {};
-
- /**
- * @return la liste des champs numeriques
- */
- String [] numFields() default {};
-
- /**
- * @return la liste des champs booleens
- */
- String [] boolFields() default {};
-
- /**
- * @return la liste des champs date
- */
- String [] dateFields() default {};
-
-} //SearchFields
Deleted: topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAO.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAO.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,230 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaDAO.java
- *
- * Created: 30 déc. 2005 03:00:57
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.security.Permission;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.event.TopiaEntityListener;
-import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.event.TopiaTransactionListener;
-import org.codelutin.topia.event.TopiaTransactionVetoable;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-
-/**
- * @author poussin
- *
- * @param <Entity>
- */
-public interface TopiaDAO<Entity extends TopiaEntity> {
-
- /**
- * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
- * after
- *
- * @param entityClass
- */
- public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException;
-
- /**
- * Return class of entity managed by this DAO
- * @return
- */
- public abstract Class<Entity> getEntityClass();
-
- /**
- * @return Returns the context.
- */
- public abstract TopiaContextImplementor getContext();
-
- /**
- * appelé lorsque le context a eu un commit de fait
- * TODO il faudrait peut-etre plutot faire un commit a deux phase
- * car plusieurs type de persistence peuvent etre melangé, et il
- * serait bien que si l'une echoué les autres echoue aussi.
- */
- public void commitTransaction() throws TopiaException;
- /** appelé lorsque le context a eu un commit de fait */
- public void rollbackTransaction() throws TopiaException;
-
- /**
- * Construit une nouvelle instance de l'objet géré par ce DAO
- * @param properties la liste des propriétés que doit avoir l'objet créé
- * les arguments vont par paire (propertyName, value)
- * @return un nouvel objet
- * @throws TopiaException si un problème est rencontré durant l'instanciation
- * @throws IllegalArgumentException Si le nombre on le type des arguments
- * n'est pas bon ou que le type ou le nom d'une propriété est fausse
- */
- public abstract Entity create(Object ... properties) throws TopiaException;
-
- /**
- * Construit une nouvelle instance de l'objet géré par ce DAO
- * @param properties la liste des propriétés que doit avoir l'objet créé
- * @return un nouvel objet
- * @throws TopiaException si un problème est rencontré durant l'instanciation
- * @throws IllegalArgumentException Si le nombre on le type des arguments
- * n'est pas bon ou que le type ou le nom d'une propriété est fausse
- */
- public Entity create(Map<String, Object> properties) throws TopiaException;
-
- /**
- * Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter
- * par exemple un objet provenant d'un autre context mais du meme type
- * de DAO
- * @param e l'entite a ajouter ou mettre a jour
- * @return l'entity passé en paramètre.
- * @throws TopiaException
- */
- public abstract Entity update(Entity e) throws TopiaException;
-
- public abstract void delete(Entity e) throws TopiaException;
-
- public abstract Entity findByTopiaId(String k) throws TopiaException;
-
- public abstract List<Entity> findAll() throws TopiaException;
-
- public abstract List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException;
-
- /**
- * TODO modifier l'implantation pour faire un simple count sur la base
- *
- * @return
- * @throws TopiaException
- */
- public abstract int size() throws TopiaException;
-
- /**
- * Recherche la classe en utilisant la cle naturelle, chaque champs de la
- * cle naturelle est une entre de la map passe en argument.
- *
- * @param keys la liste des champs de la cle naturelle avec leur valeur
- * @return
- * @throws TopiaException
- */
- public abstract Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException;
-
- /**
- * Recherche la classe en utilisant la cle naturelle, si la cle naturelle
- * est composé de plusieurs champs alors les arguments passés doivent être
- * dans l'ordre de declaration dans le fichier de mapping
- *
- * @param k l'objet cle naturelle de la classe
- * @return
- * @throws TopiaException
- */
- public abstract Entity findByPrimaryKey(Object... k) throws TopiaException;
-
- public abstract Entity findByProperty(String propertyName, Object value)
- throws TopiaException;
-
- /**
- *
- * @param propertyName
- * @param value
- * @param others les autres proprietes doivent aller par 2 propertyName,
- * value
- * @return
- * @throws TopiaException
- */
- public abstract Entity findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
-
- public abstract Entity findByProperties(Map<String, Object> properties)
- throws TopiaException;
-
- public abstract List<Entity> findAllByProperty(String propertyName, Object value)
- throws TopiaException;
-
- /**
- *
- * @param propertyName
- * @param value
- * @param others les autres proprietes doivent aller par 2 propertyName,
- * value
- * @return
- * @throws TopiaException
- */
- public abstract List<Entity> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
-
- public abstract List<Entity> findAllByProperties(Map<String, Object> properties)
- throws TopiaException;
-
- /*
- * Find Contains
- */
- /**
- * Cherche et renvoie la première entité trouvée dont les propriétés en clé
- * de Map contiennent toutes les valeurs de la Collection.
- */
- public abstract Entity findContainsProperties(Map<String, Collection> properties)
- throws TopiaException;
-
- /**
- * Cherche et renvoie la première entité trouvée dont la propriété
- * propertyName contient values, ainsi de suite avec others.
- */
- public abstract Entity findContainsProperties(String propertyName, Collection values, Object... others)
- throws TopiaException;
-
- /**
- * Cherche et renvoie la première entité trouvée dont les propriétés en clé
- * de Map contiennent toutes les valeurs de la Collection.
- */
- public abstract List<Entity> findAllContainsProperties(Map<String, Collection> properties)
- throws TopiaException;
-
- /**
- * Cherche et renvoie toutes les entités trouvées dont la propriété
- * propertyName contient values, ainsi de suite avec others.
- */
- public abstract List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others)
- throws TopiaException;
-
- /**
- * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas
- * @param topiaId topiaId d'une entite
- * @return la liste des permissions
- */
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException;
-
- /* Adders */
- public void addTopiaEntityListener(TopiaEntityListener listener);
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
- /* Removers */
- public void removeTopiaEntityListener(TopiaEntityListener listener);
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
-} //TopiaDAO
Deleted: topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAOAbstract.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAOAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,707 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaDAOAbstract.java
- *
- * Created: 31 déc. 2005 13:10:34
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.event.TopiaEntityListener;
-import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-import org.codelutin.topia.persistence.hibernate.TopiaDAOHibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.metadata.ClassMetadata;
-
-
-/**
- * Cette classe permet d'avoir un ensemble de méthode implantée de façon
- * standard pour les différents DAO existant (FlatFile, Hibernate).
- * Certaine méthode implanté ici sont particulièrement inéficace et il
- * est conseillé de les surcharger dans les classes DAO spécifiques.
- *
- * Certain accès à Hibernate est tout de même fait ici, car on a pris le
- * choix de se basé entièrement sur hibernate pour la persistence, et il
- * est ainsi possible d'accèder au meta information hibernate sur les classes
- * lorque l'on en a besoin.
- *
- * @author poussin
- *
- */
-
-public abstract class TopiaDAOAbstract<Entity extends TopiaEntity> implements TopiaDAO<Entity> {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(TopiaDAOAbstract.class);
-
- protected Class<Entity> entityClass = null;
-
- protected TopiaContextImplementor context = null;
-
- public Class<Entity> getEntityClass() {
- throw new UnsupportedOperationException("This method must be overided in generated DAO");
- }
-
- /**
- * Retourne l'id de l'entity
- * @param e l'entity
- * @return l'id de l'entity ou null si pas trouvé
- * @throws TopiaException Si une erreur survient durant la recherche
- */
- protected Serializable getId(Entity e) throws TopiaException {
- ClassMetadata meta = getClassMetadata();
- String idPropName = meta.getIdentifierPropertyName();
-
- Serializable result;
- try {
- result = (Serializable)PropertyUtils.getSimpleProperty(e, idPropName);
- } catch (IllegalAccessException eee) {
- throw new TopiaException("Impossible de récuperer l'identifiant " +
- idPropName + " de l'entite: " + e);
- } catch (InvocationTargetException eee) {
- throw new TopiaException("Impossible de récuperer l'identifiant " +
- idPropName + " de l'entite: " + e);
- } catch (NoSuchMethodException eee) {
- throw new TopiaException("Impossible de récuperer l'identifiant " +
- idPropName + " de l'entite: " + e);
- }
- return result;
- }
-
- /**
- * Retourne l'id de l'entity representer comme une map
- * @param map l'entity en representation map
- * @return l'id de l'entity ou null si pas trouvé
- * @throws TopiaException Si une erreur survient durant la recherche
- */
- protected Serializable getId(Map map) throws TopiaException {
- try {
- ClassMetadata meta = getClassMetadata();
- String idPropName = meta.getIdentifierPropertyName();
-
- Serializable id = (Serializable)map.get(idPropName);
- return id;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
-
- /**
- * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
- * after
- *
- * @param entityClass
- */
- public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException {
- log.debug("init dao for " + entityClass.getName());
- this.context = context;
- this.entityClass = entityClass;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#getContext()
- */
- public TopiaContextImplementor getContext() {
- return context;
- }
-
- @SuppressWarnings("unchecked")
- protected Entity instanciateNew() throws TopiaException {
- Entity result = null;
- String classname = entityClass.getName();
- try {
- // on commence par essayer d'instancier le Impl
- result = ((Class<Entity>)Class.forName(classname+"Impl")).newInstance();
- if (log.isDebugEnabled()) {
- log.debug("Utilisation de la classe " + classname+"Impl" + " pour " + classname);
- }
- } catch (InstantiationException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname+"Impl");
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- } catch (IllegalAccessException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname+"Impl");
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- } catch (ClassNotFoundException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible de trouver la classe " + classname+"Impl");
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- }
-
- if (result == null) {
- // le impl n'est pas trouvé on essai avec la classe elle meme
- try {
- result = entityClass.newInstance();
- if (log.isDebugEnabled()) {
- log.debug("Utilisation de la classe " + classname + " pour " + classname);
- }
- } catch (InstantiationException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname);
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- } catch (IllegalAccessException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname);
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- }
- }
-
- if (result == null) {
- throw new TopiaException("Impossible de trouver ou d'instancier la classe " + classname);
- }
-
- return result;
- }
-
- /**
- * Par defaut ne fait rien
- */
- public void commitTransaction() throws TopiaException {
- }
-
- /**
- * Par defaut ne fait rien
- */
- public void rollbackTransaction() throws TopiaException {
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object)
- */
- public Entity create(Object ... properties) throws TopiaException{
- Map<String, Object> map = new HashMap<String, Object>();
- Object propertyName = null;
- Object value = null;
- try {
- for(int i=0; i<properties.length;) {
- propertyName = properties[i++];
- value = properties[i++];
- map.put((String)propertyName, value);
- }
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException("Wrong number of argument " + properties.length + ", you must have even number. Last property name read: " + propertyName);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException("Wrong argument type, wait property name as String and have " + propertyName.getClass().getName());
- }
-
- Entity result = create(map);
- return result;
- }
-
- /**
- * Cette methode appelle fireVetoableCreate et fireOnCreated
- * Si vous la surchargé, faites attention a appeler le super
- * ou a appeler vous aussi ces deux methodes.
- */
- public Entity create(Map<String, Object> properties) throws TopiaException {
- Entity result = instanciateNew();
-
- // TODO reflechir s'il ne faudrait pas creer l'id avant l'event precedent
- // reflechir toujours dans un context on les Entity pourrait ne pas
- // etre des TopiaEntity
- if (result instanceof TopiaEntity) {
- String topiaId = TopiaId.create(entityClass);
- TopiaEntityAbstract entity = (TopiaEntityAbstract)result;
- entity.setTopiaId(topiaId);
- entity.setTopiaContext(getContext());
- }
- try {
- for(Map.Entry<String, Object> e : properties.entrySet()) {
- String propertyName = e.getKey();
- Object value = e.getValue();
- PropertyUtils.setProperty(result, (String)propertyName, value);
- }
- } catch (IllegalAccessException eee) {
- throw new IllegalArgumentException("Can't put properties on new Object", eee);
- } catch (InvocationTargetException eee) {
- throw new IllegalArgumentException("Can't put properties on new Object", eee);
- } catch (NoSuchMethodException eee) {
- throw new IllegalArgumentException("Can't put properties on new Object", eee);
- }
-
- result.postCreate();
-
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#size()
- */
- public int size() throws TopiaException {
- int result = findAll().size();
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map)
- */
- public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException {
- try {
- // we used hibernate meta information for all persistence type
- // it's more easy than create different for all persistence
- ClassMetadata meta = getClassMetadata();
- if (meta.hasNaturalIdentifier()) {
- Entity result = findByProperties(keys);
- return result;
- }
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- throw new TopiaException("La classe " + entityClass.getName()
- + " n'a pas de cle primaire naturelle");
-
- }
-
- /**
- * private method because this is hibernate specific method and we don't
- * want expose it
- *
- * @return
- * @throws TopiaException
- */
- private ClassMetadata getClassMetadata() throws TopiaException {
- ClassMetadata meta = getContext().getHibernateFactory()
- .getClassMetadata(entityClass);
- if (meta == null) {
- meta = getContext().getHibernateFactory()
- .getClassMetadata(entityClass.getName() + "Impl");
- }
- return meta;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object)
- */
- public Entity findByPrimaryKey(Object... k) throws TopiaException {
- // TODO pour une meilleur gestion des problemes a la compilation
- // mettre un premier couple (propName, value) en argument ca evitera
- // de pouvoir appeler cette methode sans argument
- try {
- ClassMetadata meta = getClassMetadata();
- if (meta.hasNaturalIdentifier()) {
- int[] ikeys = meta.getNaturalIdentifierProperties();
- String[] pnames = meta.getPropertyNames();
-
- Map<String, Object> keys = new HashMap<String, Object>();
- for (int ikey : ikeys) {
- keys.put(pnames[ikey], k[ikey]);
- }
-
- Entity result = findByProperties(keys);
- return result;
- }
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- throw new TopiaException("La classe " + entityClass.getName()
- + " n'a pas de cle primaire naturelle");
-
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object)
- */
- public Entity findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- value = others[i++];
- properties.put((String) name, value);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2) + " La dernière propriété était: " + name, eee);
- }
- }
- Entity result = findByProperties(properties);
- return result;
- }
-
- /**
- * Recherche une entity contenant certain propriété. Pour l'instant on
- * charche toute les entités existantes pour faire la recherche
- *
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperties(java.util.Map)
- */
- public List<Entity> findAllByProperties(Map<String, Object> properties)
- throws TopiaException {
- List<Entity> all = findAll();
- List<Entity> result = new ArrayList<Entity>();
- for (Entity e : all) {
- boolean ok = true;
- try {
- for(Entry<String, Object> kv : properties.entrySet()) {
- Object entityValue = PropertyUtils.getProperty(e, kv.getKey());
- Object value = kv.getValue();
- if (!ObjectUtils.equals(entityValue, value)) {
- ok = false;
- break;
- }
- }
- } catch (IllegalAccessException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- } catch (InvocationTargetException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- } catch (NoSuchMethodException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- }
- if (ok) {
- result.add(e);
- }
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object)
- */
- public List<Entity> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- value = others[i++];
- properties.put((String) name, value);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2) + " La dernière propriété était: " + name, eee);
- }
- }
- List<Entity> result = findAllByProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
- */
- public Entity findContainsProperties(Map<String, Collection> properties)
- throws TopiaException {
- List<Entity> results = findAllContainsProperties(properties);
- Entity result = null;
- if (results.size() > 0) {
- result = results.get(0);
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
- */
- public Entity findContainsProperties(String propertyName, Collection values, Object... others)
- throws TopiaException {
- Map<String, Collection> properties = new HashMap<String, Collection>();
- properties.put(propertyName, values);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- values = (Collection)others[i++];
- properties.put((String) name, values);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2) + " La dernière propriété était: " + name, eee);
- }
- }
- Entity result = findContainsProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
- */
- public List<Entity> findAllContainsProperties(Map<String, Collection> properties)
- throws TopiaException {
- List<Entity> all = findAll();
- List<Entity> result = new ArrayList<Entity>();
- for (Entity e : all) {
- boolean ok = true;
- try {
- for(Entry<String, Collection> kv : properties.entrySet()) {
- Collection entityValues = (Collection)PropertyUtils.getProperty(e, kv.getKey());
- Collection values = kv.getValue();
- if (!entityValues.containsAll(values)) {
- ok = false;
- break;
- }
- }
- } catch (IllegalAccessException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- } catch (InvocationTargetException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- } catch (NoSuchMethodException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- }
- if (ok) {
- result.add(e);
- }
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
- */
- public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others)
- throws TopiaException {
- Map<String, Collection> properties = new HashMap<String, Collection>();
- properties.put(propertyName, values);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- values = (Collection)others[i++];
- properties.put((String) name, values);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2) + " La dernière propriété était: " + name, eee);
- }
- }
- List<Entity> result = findAllContainsProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByTopiaId()
- */
- public Entity findByTopiaId(String k) throws TopiaException {
- Entity result = findByProperty("topiaId", k);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAll()
- */
- public List<Entity> findAll() throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- List<Entity> result = findAllByProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object)
- */
- public List<Entity> findAllByProperty(String propertyName, Object value) throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- List<Entity> result = findAllByProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object)
- */
- public Entity findByProperty(String propertyName, Object value)
- throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- Entity result = findByProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
- */
- public Entity findByProperties(Map<String, Object> properties)
- throws TopiaException {
- List<Entity> listResult = findAllByProperties(properties);
- Entity result = null;
- if (listResult.size() > 0) {
- result = listResult.get(0);
- }
- return result;
- }
-
- @Deprecated
- private Criterion computeCriterions(Object ... values) {
- if (values == null) {
- return null;
- }
- Criterion criterion = null;
- for (Object value : values) {
- criterion = or(criterion, computeCriterion(value));
- }
- return criterion;
- }
-
- @Deprecated
- private Criterion computeCriterion(Object value) {
- Criterion criterion = null;
- SearchFields fields = entityClass.getAnnotation(SearchFields.class);
- String textValue = "%" + value + "%";
- //textFields
- String[] textFields = fields.txtFields();
- for (String propName : textFields) {
- criterion = or(criterion, Restrictions.like(propName, textValue));
- }
- //numFields
- boolean isNumber = (value instanceof Number);
- if (value instanceof String) {
- try {
- Double.parseDouble((String) value);
- isNumber = true;
- } catch (NumberFormatException nfe) {
- isNumber = false;
- }
-
- }
- if (isNumber) {
- String[] numFields = fields.numFields();
- for (String propName : numFields) {
- criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'"));
- }
- }
- //boolFields
- boolean isBoolean = (value instanceof Boolean);
- if (value instanceof String) {
- isBoolean |= ("true".equalsIgnoreCase((String)value)
- || "false".equalsIgnoreCase((String)value));
- }
- if (isBoolean) {
- Boolean booleanValue;
- if (value instanceof String) {
- booleanValue = Boolean.valueOf((String)value);
- } else {
- booleanValue = (Boolean)value;
- }
- String[] boolFields = fields.numFields();
- for (String propName : boolFields) {
- criterion = or(criterion, Restrictions.eq(propName, booleanValue));
- }
- }
- //timeFields
- String[] timeFields = fields.dateFields();
- for (String propName : timeFields) {
- criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'"));
- }
- return criterion;
- }
-
- @Deprecated
- private Criterion or(Criterion crit1, Criterion crit2) {
- if (crit1 == null) {
- return crit2;
- }
- if (crit2 == null) {
- return crit1;
- }
- return Restrictions.or(crit1, crit2);
- }
-
- public void addTopiaEntityListener(TopiaEntityListener listener) {
- getContext().addTopiaEntityListener((Class<TopiaEntity>) entityClass, listener);
- }
-
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getContext().addTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable);
- }
-
- public void removeTopiaEntityListener(TopiaEntityListener listener) {
- getContext().removeTopiaEntityListener((Class<TopiaEntity>) entityClass, listener);
- }
-
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getContext().removeTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable);
- }
-
-
-} //TopiaDAOAbstract
Deleted: topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAODelegator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaDAODelegator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,282 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaDAODelegator.java
- *
- * Created: 30 déc. 2005 22:28:48
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.security.Permission;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.event.TopiaEntityListener;
-import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-
-
-/**
- * Cette classe est utilisé par les DAO générés pour encapsuler un véritable
- * DAO (Hibernate, FlatFile)
- * On utilise donc le pattern (TODO retrouver le nom du pattern) qui permet
- * de générer les classes sans ce soucier de quel DAO va etre utilisé
- * a l'execution.
- *
- * @author poussin
- *
- */
-
-public class TopiaDAODelegator<Entity extends TopiaEntity> implements TopiaDAO<Entity> {
-
- /**
- * DAO reel sur lequel on peut s'appuyer pour faire les requetes
- */
- protected TopiaDAO<Entity> parentDAO = null;
-
- /**
- * A priori seul les enfants on besoin de le recuperer
- */
- protected TopiaDAO<Entity> getParentDAO() {
- return parentDAO;
- }
- /**
- * Le setter est public car potentiellement le context qui le cree n'est
- * pas dans le meme package, mais seul le context doit utiliser cette
- * methode
- */
- public void setParentDAO(TopiaDAO<Entity> v) {
- this.parentDAO = v;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#init(org.codelutin.topia.TopiaContextImpl, java.lang.Class)
- */
- public void init(TopiaContextImplementor context, Class entityClass) throws TopiaException {
- // rien a faire cette methode a ete appele sur le parentDAO
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#getEntityClass()
- */
- public Class<Entity> getEntityClass() {
- return getParentDAO().getEntityClass();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#getContext()
- */
- public TopiaContextImplementor getContext() {
- return getParentDAO().getContext();
- }
-
- public void commitTransaction() throws TopiaException {
- getParentDAO().commitTransaction();
- }
- public void rollbackTransaction() throws TopiaException {
- getParentDAO().rollbackTransaction();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object...)
- */
- public Entity create(Object... properties) throws TopiaException {
- return getParentDAO().create(properties);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#create(java.util.Map)
- */
- public Entity create(Map<String, Object> properties) throws TopiaException {
- return getParentDAO().create(properties);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#update(Entity)
- */
- public Entity update(Entity e) throws TopiaException {
- return getParentDAO().update(e);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#delete(Entity)
- */
- public void delete(Entity e) throws TopiaException {
- getParentDAO().delete(e);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByTopiaId(java.lang.Object)
- */
- public Entity findByTopiaId(String k) throws TopiaException {
- return getParentDAO().findByTopiaId(k);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAll()
- */
- public List<Entity> findAll() throws TopiaException {
- return getParentDAO().findAll();
- }
-
- public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
- return getParentDAO().findAllWithOrder(propertyNames);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#size()
- */
- public int size() throws TopiaException {
- return getParentDAO().size();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map)
- */
- public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException {
- return getParentDAO().findByPrimaryKey(keys);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object...)
- */
- public Entity findByPrimaryKey(Object... k) throws TopiaException {
- return getParentDAO().findByPrimaryKey(k);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object)
- */
- public Entity findByProperty(String propertyName, Object value)
- throws TopiaException {
- return getParentDAO().findByProperty(propertyName, value);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object...)
- */
- public Entity findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
- return getParentDAO().findByProperties(propertyName, value, others);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
- */
- public Entity findByProperties(Map<String, Object> properties) throws TopiaException {
- return getParentDAO().findByProperties(properties);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object)
- */
- public List<Entity> findAllByProperty(String propertyName, Object value)
- throws TopiaException {
- return getParentDAO().findAllByProperty(propertyName, value);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object...)
- */
- public List<Entity> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
- return getParentDAO().findAllByProperties(propertyName, value, others);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map)
- */
- public List<Entity> findAllByProperties(Map<String, Object> properties) throws TopiaException {
- return getParentDAO().findAllByProperties(properties);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
- */
- public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException {
- return getParentDAO().findContainsProperties(properties);
- }
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
- */
- public Entity findContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException {
- return getParentDAO().findContainsProperties(propertyName, values, others);
- }
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
- */
- public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
- return getParentDAO().findAllContainsProperties(properties);
- }
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
- */
- public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException {
- return getParentDAO().findAllContainsProperties(propertyName, values, others);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener)
- */
- public void addTopiaEntityListener(TopiaEntityListener listener) {
- getParentDAO().addTopiaEntityListener(listener);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable)
- */
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getParentDAO().addTopiaEntityVetoable(vetoable);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener)
- */
- public void removeTopiaEntityListener(TopiaEntityListener listener) {
- getParentDAO().removeTopiaEntityListener(listener);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable)
- */
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getParentDAO().removeTopiaEntityVetoable(vetoable);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
- */
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
- return getParentDAO().getRequestPermission(topiaId, actions);
- }
-
-} //TopiaDAODelegator
Deleted: topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntity.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntity.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntity.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,120 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaEntity.java
- *
- * Created: 28 déc. 2005 22:48:10
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.beans.PropertyChangeListener;
-import java.beans.VetoableChangeListener;
-import java.util.Date;
-import java.util.List;
-
-import org.codelutin.topia.TopiaContext;
-import org.codelutin.topia.TopiaException;
-
-/**
- * Toutes les methodes set ne doivent être utilisé que par le framework. Elle
- * sont publique car on ne peut pas faire autrement sur une interface.
- *
- * @author poussin
- */
-@SearchFields
-public interface TopiaEntity {
-
- public String getTopiaId();
- public void setTopiaId(String v);
- public long getTopiaVersion();
- public void setTopiaVersion(long v);
-
- /**
- * @return Returns the topiaCreateTime.
- */
- public Date getTopiaCreateDate();
-
- /**
- * @param topiaCreateTime The topiaCreateTime to set.
- */
- public void setTopiaCreateDate(Date topiaCreatedate);
-
- public TopiaContext getTopiaContext();
-
- /**
- * called just after object creation and initialisation
- * each entity impl can overide it to do something after creation
- * @throws TopiaException
- */
- public void postCreate() throws TopiaException;
- public void update() throws TopiaException;
- public void delete() throws TopiaException;
-
- /**
- * Return all object that must be deleted if this object is deleted
- * @throws TopiaException
- */
- public List<TopiaEntity> getComposite() throws TopiaException;
-
- /**
- * Return all object that are aggregate with this instance, aggreate object
- * are not removed automaticaly
- * @throws TopiaException
- */
- public List<TopiaEntity> getAggregate() throws TopiaException;
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener);
-
- public void addPropertyChangeListener(PropertyChangeListener listener);
-
- public void addVetoableChangeListener(String propertyName, VetoableChangeListener vetoable);
-
- public void addVetoableChangeListener(VetoableChangeListener vetoable);
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener);
-
- public void removePropertyChangeListener(PropertyChangeListener listener);
-
- public void removeVetoableChangeListener(String propertyName, VetoableChangeListener vetoable);
-
- public void removeVetoableChangeListener(VetoableChangeListener vetoable);
-
- public void addPropertyListener(String propertyName, PropertyChangeListener listener);
-
- public void addPropertyListener(PropertyChangeListener listener);
-
- public void addVetoableListener(String propertyName, VetoableChangeListener vetoable);
-
- public void addVetoableListener(VetoableChangeListener vetoable);
-
- public void removePropertyListener(String propertyName, PropertyChangeListener listener);
-
- public void removePropertyListener(PropertyChangeListener listener);
-
- public void removeVetoableListener(String propertyName, VetoableChangeListener vetoable);
-
- public void removeVetoableListener(VetoableChangeListener vetoable);
-
-} //TopiaEntity
Deleted: topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntityAbstract.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityAbstract.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntityAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,320 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/*******************************************************************************
- * TopiaEntityAbstract.java
- *
- * Created: 28 déc. 2005 22:50:42
- *
- * @author poussin
- *
- * @version $Revision$
- *
- * Last update: $Date$ by : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.beans.VetoableChangeListener;
-import java.beans.VetoableChangeSupport;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.TopiaContext;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-
-/**
- * Classe de base de toutes les entités, cela permet de concentrer le code
- * technique dans cette classe. L'identifiant peut-etre n'importe quoi Aucune
- * restriction n'est faite dessus, il peut meme changer entre deux types
- * d'entité si cela ne pose pas d'autre probleme (heritage entre ces entités).
- *
- * @author poussin
- */
-public abstract class TopiaEntityAbstract implements TopiaEntity, Serializable {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(TopiaEntityAbstract.class);
-
- protected String topiaId;
-
- protected long topiaVersion;
-
- protected Date topiaCreateDate = new Date();
-
- transient protected TopiaContext topiaContext = null;
-
- transient protected VetoableChangeSupport readVetoables = new VetoableChangeSupport(this);
- transient protected PropertyChangeSupport readListeners = new PropertyChangeSupport(this);
- transient protected VetoableChangeSupport writeVetoables = new VetoableChangeSupport(this);
- transient protected PropertyChangeSupport writeListeners = new PropertyChangeSupport(this);
-
- /**
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#getTopiaId()
- */
- public String getTopiaId() {
- return topiaId;
- }
-
- /**
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#setTopiaId(String)
- */
- public void setTopiaId(String v) {
- this.topiaId = v;
- }
-
- /**
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#getTopiaVersion()
- */
- public long getTopiaVersion() {
- return topiaVersion;
- }
-
- /**
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#setTopiaVersion(long)
- */
- public void setTopiaVersion(long v) {
- this.topiaVersion = v;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#getTopiaCreateTime()
- */
- public Date getTopiaCreateDate() {
- return topiaCreateDate;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#setTopiaCreateTime(java.util.Date)
- */
- public void setTopiaCreateDate(Date topiaCreateDate) {
- this.topiaCreateDate = topiaCreateDate;
- }
-
- /**
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#getTopiaContext()
- */
- public TopiaContext getTopiaContext() {
- return topiaContext;
- }
-
- /**
- * @param context The context to set.
- */
- public void setTopiaContext(TopiaContext context) throws TopiaException {
- if (this.topiaContext == null) {
- this.topiaContext = context;
- } else {
- throw new TopiaException("Remplacement du contexte interdit");
- }
- }
-
- public void postCreate() throws TopiaException {
- // do nothing by default
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#update()
- */
- public void update() throws TopiaException {
- throw new UnsupportedOperationException();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.persistence.TopiaEntity#delete()
- */
- public void delete() throws TopiaException {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaEntity#getComposite()
- */
- public List<TopiaEntity> getComposite() throws TopiaException {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaEntity#getAggregate()
- */
- public List<TopiaEntity> getAggregate() throws TopiaException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * On utilise la date de creation comme hash code, cette date ne varie pas
- * au cours du temps
- */
- @Override
- public int hashCode() {
- int result = getTopiaCreateDate().hashCode();
- return result;
- }
-
- /**
- * On est sur que les objets sont bien les memes car s'il n'ont pas d'id
- * cela veut dire qu'il ne vienne pas de la meme session donc qu'il sont
- * nouveau et different, ou bien qu'ils viennent de la meme session et dans
- * ce cas l'egalite == fonctionne.
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof TopiaEntity == false) {
- return false;
- }
- TopiaEntity other = (TopiaEntity) obj;
- if (getTopiaId() == null || other.getTopiaId() == null) {
- return false;
- }
- boolean result = getTopiaId().equals(other.getTopiaId());
- return result;
- }
-
- protected void fireOnPreRead(String propertyName, Object value) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
- if(contextImplementor != null) {
- contextImplementor.getFiresSupport().fireOnPreRead(readVetoables, this, propertyName, value);
- }
- }
-
- protected void fireOnPostRead(String propertyName, Object value) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
- if(contextImplementor != null) {
- contextImplementor.getFiresSupport().fireOnPostRead(readListeners, this, propertyName, value);
- }
- }
-
- protected void fireOnPostRead(String propertyName, int index, Object value) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
- if(contextImplementor != null) {
- contextImplementor.getFiresSupport().fireOnPostRead(readListeners, this, propertyName, index, value);
- }
- }
-
- protected void fireOnPreWrite(String propertyName, Object oldValue, Object newValue) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
- if(contextImplementor != null) {
- contextImplementor.getFiresSupport().fireOnPreWrite(writeVetoables, this, propertyName, oldValue, newValue);
- }
- }
-
- protected void fireOnPostWrite(String propertyName, Object oldValue, Object newValue) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
- if(contextImplementor != null) {
- contextImplementor.getFiresSupport().fireOnPostWrite(writeListeners, this, propertyName, oldValue, newValue);
- }
- }
-
- protected void fireOnPostWrite(String propertyName, int index, Object oldValue, Object newValue) {
- TopiaContextImplementor contextImplementor = (TopiaContextImplementor) getTopiaContext();
- if(contextImplementor != null) {
- contextImplementor.getFiresSupport().fireOnPostWrite(writeListeners, this, propertyName, index, oldValue, newValue);
- }
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- writeListeners.addPropertyChangeListener(propertyName, listener);
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- writeListeners.addPropertyChangeListener(listener);
- }
-
- public void addVetoableChangeListener(String propertyName, VetoableChangeListener vetoable) {
- writeVetoables.addVetoableChangeListener(propertyName, vetoable);
- }
-
- public void addVetoableChangeListener(VetoableChangeListener vetoable) {
- writeVetoables.addVetoableChangeListener(vetoable);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- writeListeners.removePropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- writeListeners.removePropertyChangeListener(listener);
- }
-
- public void removeVetoableChangeListener(String propertyName, VetoableChangeListener vetoable) {
- writeVetoables.removeVetoableChangeListener(propertyName, vetoable);
- }
-
- public void removeVetoableChangeListener(VetoableChangeListener vetoable) {
- writeVetoables.removeVetoableChangeListener(vetoable);
- }
-
- public void addPropertyListener(String propertyName, PropertyChangeListener listener) {
- readListeners.addPropertyChangeListener(propertyName, listener);
- }
-
- public void addPropertyListener(PropertyChangeListener listener) {
- readListeners.addPropertyChangeListener(listener);
- }
-
- public void addVetoableListener(String propertyName, VetoableChangeListener vetoable) {
- readVetoables.addVetoableChangeListener(propertyName, vetoable);
- }
-
- public void addVetoableListener(VetoableChangeListener vetoable) {
- readVetoables.addVetoableChangeListener(vetoable);
- }
-
- public void removePropertyListener(String propertyName, PropertyChangeListener listener) {
- readListeners.removePropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyListener(PropertyChangeListener listener) {
- readListeners.removePropertyChangeListener(listener);
- }
-
- public void removeVetoableListener(String propertyName, VetoableChangeListener vetoable) {
- readVetoables.removeVetoableChangeListener(propertyName, vetoable);
- }
-
- public void removeVetoableListener(VetoableChangeListener vetoable) {
- readVetoables.removeVetoableChangeListener(vetoable);
- }
-
-} //TopiaEntityAbstract
Deleted: topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntityEnumEntry.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaEntityEnumEntry.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,155 +0,0 @@
-package org.codelutin.topia.persistence;
-
-import org.codelutin.topia.TopiaContext;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/** @author chemit */
-public class TopiaEntityEnumEntry<T extends TopiaEntity> implements java.io.Serializable {
-
- /** the contract class of the entity's type. */
- protected Class<T> contractClass;
-
- /** the concrete implementation class of the entity's type. */
- protected Class<T> implementationClass;
-
- private static final long serialVersionUID = 1L;
-
- public TopiaEntityEnumEntry(Class<T> contractClass) {
- this.contractClass = contractClass;
- }
-
- public Class<T> getContractClass() {
- return contractClass;
- }
-
- @SuppressWarnings({"unchecked"})
- public Class<T> getImplementationClass() {
- if (implementationClass == null) {
- try {
- implementationClass = (Class<T>) Class.forName(contractClass.getName() + "Impl");
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("could not find implementation for entity contract " + contractClass);
- }
- }
- return implementationClass;
- }
-
- public TopiaDAO<T> getDAO(TopiaContext ctxt) throws TopiaException {
- TopiaContextImplementor ci = (TopiaContextImplementor) ctxt;
- return ci.getDAO(contractClass);
- }
-
- public T create(TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- T newInstance = dao.create();
- // attach topia context to entity (to allow propertyChangeSupport for entity)
- ((TopiaEntityAbstract) newInstance).setTopiaContext(ctxt);
- return newInstance;
- }
-
- public T create(TopiaContext ctxt, Object... properties) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.create(properties);
- }
-
- public T create(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.create(properties);
- }
-
- public T update(T entity, TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.update(entity);
- }
-
- public void delete(T entity, TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- dao.delete(entity);
- }
-
- public int size(TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.size();
- }
-
- public List<T> findAll(TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findAll();
- }
-
- public List<T> findAllWithOrder(TopiaContext ctxt,String... propertyNames) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findAllWithOrder(propertyNames);
- }
-
- public T findByTopiaId(String topiaId, TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findByTopiaId(topiaId);
- }
-
- public T findByPrimaryKey(TopiaContext ctxt, Map<String, Object> keys) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findByPrimaryKey(keys);
- }
-
- public T findByPrimaryKey(TopiaContext ctxt, Object... k) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findByPrimaryKey(k);
- }
-
- public T findByProperty(TopiaContext ctxt, String propertyName, Object value) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findByProperty(propertyName, value);
- }
-
- public T findByProperties(TopiaContext ctxt, String propertyName, Object value, Object... others) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findByProperties(propertyName, value, others);
- }
-
- public T findByProperties(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findByProperties(properties);
- }
-
- public List<T> findAllByProperty(TopiaContext ctxt, String propertyName, Object value) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findAllByProperty(propertyName, value);
- }
-
- public List<T> findAllByProperties(TopiaContext ctxt, String propertyName, Object value, Object... others) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findAllByProperties(propertyName, value, others);
- }
-
- public List<T> findAllByProperties(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findAllByProperties(properties);
- }
-
- public T findContainsProperties(TopiaContext ctxt, Map<String, Collection> properties) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findContainsProperties(properties);
- }
-
- public T findContainsProperties(TopiaContext ctxt, String propertyName, Collection values, Object... others) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findContainsProperties(propertyName, values, others);
- }
-
- public List<T> findAllContainsProperties(TopiaContext ctxt, Map<String, Collection> properties) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findAllContainsProperties(properties);
- }
-
- public List<T> findAllContainsProperties(TopiaContext ctxt, String propertyName, Collection values, Object... others) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findAllContainsProperties(propertyName, values, others);
- }
-
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaId.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaId.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/persistence/TopiaId.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,134 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaId.java
- *
- * Created: 6 juil. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.io.Serializable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.codelutin.topia.TopiaNotFoundException;
-
-/**
-* Classe representant un Id, utilisable par JDO. Cette classe contient aussi un
-* ensemble de methode static utile pour la manipulation des topiaId
-*/
-public class TopiaId implements Serializable { // TopiaId
-
- /** */
- private static final long serialVersionUID = 1L;
-
- public String topiaId = null;
-
- public TopiaId(){}
- public TopiaId(String topiaId){
- this.topiaId = topiaId;
- }
-
- public int hashCode (){
- if(topiaId == null){
- Logger.getLogger(getClass().getName() + ".hashCode").log(Level.WARNING, "Use null topiaId", new Throwable());
- return 0;
- }
- return topiaId.hashCode();
- }
-
- public boolean equals(Object o){
- return topiaId.equals(o);
- }
-
- public String toString(){
- return topiaId;
- }
-
- /**
- * Cree un topiaId pour une certaine classe
- */
- public static String create(Class clazz){
- if(!clazz.isInterface()){
- throw new IllegalArgumentException("Only interface is permit to create id: " + clazz);
- }
- double random = Math.random();
- while (Double.toString(random).contains("E-")) {
- random = Math.random();
- }
- return clazz.getName() + "#" + System.currentTimeMillis() + "#" + random;
- }
-
- /**
- * Extrait la classe du topiaId
- * @throws ClassNotFoundException
- */
- public static Class getClassName(String topiaId) throws TopiaNotFoundException {
- String classname = getClassNameAsString(topiaId);
- try {
- Class result = Class.forName(classname);
- return result;
- } catch (ClassNotFoundException eee) {
- throw new TopiaNotFoundException("Can't find class for " + topiaId, eee);
- }
- }
-
- /**
- * Return class name id topiaId is id, and empty string if topiaId is
- * not an id
- *
- * @param topiaId
- * @return
- */
- public static String getClassNameAsString(String topiaId){
- String result = "";
- int i = topiaId.indexOf("#");
- if (i>0) {
- result = topiaId.substring(0, i);
- }
- return result;
- }
-
- /**
- * Verifie si l'id passé en paramètre est bien un Id topia, c-a-d si la
- * forme est bien classname#timemillis#random et si le classname est
- * celui d'une classe valide, c-a-d que le systeme arrive a trouver
- */
- public static boolean isValidId(String topiaId){
- try{
- if(topiaId.matches(".*?#[0-9]+#[0-9.]+")){
- getClassName(topiaId);
- return true;
- }
- return false;
- }catch(Exception eee){
- Logger.getLogger(TopiaId.class.getName() + ".isValidId").log(Level.WARNING, "Error during verfication of topiaId", eee);
- return false;
- }
- }
-
-} // TopiaId
-
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/Protocol.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/Protocol.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/Protocol.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,37 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.service;
-
-/**
- * Protocole.
- *
- * Liste des protocoles de web services supportes
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public enum Protocol {
- /** RMI */
- RMI,
- /** XML-RPC */
- XML_RPC,
- /** SOAP */
- SOAP
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationService.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationService.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,50 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.service;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.TopiaContext;
-
-/**
- * TopiaApplicationService.java
- *
- * Represente un service Topia.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public interface TopiaApplicationService {
-
- /** Common logging) */
- final Log log = LogFactory.getLog(TopiaApplicationService.class);
-
- /**
- * Initialise le service
- * @param context
- */
- public void init(TopiaContext context);
-
- /**
- * Detruit le service
- * @param context
- */
- public void destroy();
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationServiceAbstract.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationServiceAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,63 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.service;
-
-import org.codelutin.topia.TopiaContext;
-
-/**
- * TopiaAplicationServiceAbstract.java
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public class TopiaApplicationServiceAbstract implements TopiaApplicationService {
-
- /**
- * TopiaContext du service
- */
- protected TopiaContext topiaContext;
-
- /**
- * Initialise le service avec un context
- *
- * @param context
- */
- public void init(TopiaContext context) {
- this.topiaContext = context;
- }
-
- /**
- * Detruit le service
- *
- * @param context
- */
- public void destroy() {
- }
-
- /**
- *
- * @return le context du service
- */
- public TopiaContext getTopiaContext() {
- return topiaContext;
- }
-
-
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationServiceFactory.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/TopiaApplicationServiceFactory.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,400 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/**
- *
- */
-package org.codelutin.topia.service;
-
-import java.lang.reflect.Proxy;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.TopiaContext;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.TopiaNotFoundException;
-import org.codelutin.topia.framework.TopiaUtil;
-import org.codelutin.topia.service.clients.RMIProxy;
-import org.codelutin.topia.service.clients.SOAPProxy;
-import org.codelutin.topia.service.clients.XMLRPCProxy;
-
-/**
- * TopiaServiceFactory.java
- *
- * Classe utilisee pour charger les services.
- *
- * Deux utilisations possibles :
- * <li>client: pour avoir une interface sur un service local ou distant
- * <li>serveur: pour avoir un service local au serveur
- *
- * Sert aussi au serveur pour declarer des services
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public class TopiaApplicationServiceFactory {
-
- /** Fichier de configuration par defaut */
- static final String DEFAULT_CONFIG_PROPERTIES = "TopiaContextImpl.properties";
-
- /** Nom de la propriete de definition des services utilises */
- static final String TOPIA_APPLICATION_SERVICE_BEGIN = "topia.application.service.";
-
- /** Nom de la propriete de definition des services fournit */
- static final String TOPIA_APPLICATION_PROVIDE_BEGIN = "topia.application.provide.";
-
- /** Nom de la propriete de definition des ports suivant les protocoles */
- static final String TOPIA_APPLICATION_SERVER_PORT_BEGIN = "topia.application.server.port.";
-
- /**
- * Nom du dossier ou sont generer certains fichiers (doit etre dans le
- * classpath )
- */
- public static String TOPIA_GENERATION_DIRECTORY = "topiagen";
-
- /** Fichier de configuration */
- private static Properties config;
-
- /** Dispatcher (servers) */
- private static final TopiaServiceProvider mainDispatcher = new TopiaServiceProvider();
-
- /**
- * Stockage des services deja instancies
- */
- private static Map<Class<? extends TopiaApplicationService>, TopiaApplicationService> mapServiceCache = new HashMap<Class<? extends TopiaApplicationService>, TopiaApplicationService>();
-
- /** Logger (common logging) */
- private static final Log log = LogFactory
- .getLog(TopiaApplicationServiceFactory.class);
-
- private static TopiaContext defaultServiceContext;
-
- /**
- * Retourne la configuration. Charge le fichier s'il n'a pas deja ete
- * charge.
- *
- * @throws TopiaNotFoundException
- * si le fichier de configuration ne peut pas etre charge
- */
- static Properties getConfiguration() throws TopiaNotFoundException {
- if (config == null) {
- config = TopiaUtil.getProperties(DEFAULT_CONFIG_PROPERTIES);
- }
- return config;
- }
-
- /**
- * Charge et lance tous les services contenus dans le fichier de
- * configuration
- *
- * @param config
- * les proprietes du fichier de configuration
- * @param context
- * le contexte pere des contextes fournis aux services
- * @throws TopiaException
- */
- @SuppressWarnings("unchecked")
- public static void loadServices(Properties config, TopiaContext context)
- throws TopiaException {
- if (context == null)
- throw new NullPointerException(
- "I need a valid TopiaContext to initialise application services");
- defaultServiceContext = context;
- // lecture du fichier de configuration
- if (config == null) {
- try {
- config = getConfiguration();
- } catch (TopiaNotFoundException e) {
- throw new TopiaNotFoundException(
- "Can't find configuration file "
- + DEFAULT_CONFIG_PROPERTIES);
- }
- }
- // pour chaque service applicatif
- Set<Object> keySet = config.keySet();
- for (Object key : keySet) {
-
- if (key.toString().startsWith(TOPIA_APPLICATION_PROVIDE_BEGIN)) {
-
- // convertir l'URI pour recuperer les parametres
- String protos = config.getProperty(key.toString());
- String serviceClassName = ((String) key).replace(
- TOPIA_APPLICATION_PROVIDE_BEGIN, "");
-
- // lance pour chaque protocole
- String[] tabProtos = protos.split(",");
-
- for (String proto : tabProtos) {
- // instancier puis lancer le service
- Protocol protocol = Protocol.valueOf(proto.trim().replace(
- '-', '_').toUpperCase());
-
- // read and set server port
- if (config.get(TOPIA_APPLICATION_SERVER_PORT_BEGIN + proto) != null) {
- Integer port = null;
- try {
- port = Integer.valueOf((String)config.get(TOPIA_APPLICATION_SERVER_PORT_BEGIN + proto));
- }
- catch(NumberFormatException e) {
- log.warn("Can't convert " + proto + " server port to integer",e);
- }
- mainDispatcher.setProtocolPort(protocol, port);
- }
-
- Class serviceInterface = null;
- Class serviceImplement = null;
- try {
- serviceInterface = Class.forName(serviceClassName);
- serviceImplement = Class.forName(serviceClassName
- + "Impl");
-
- try {
- Object newInstance = serviceImplement.newInstance();
- TopiaApplicationService service = (TopiaApplicationService) newInstance;
- TopiaContext serviceContext = context
- .beginTransaction();
- service.init(serviceContext);
- addService(serviceInterface, service, protocol);
- } catch (InstantiationException e) {
- throw new TopiaException(
- "Can't instanciate service class "
- + serviceImplement);
- } catch (IllegalAccessException e) {
- throw new TopiaException(
- "Can't access to service class "
- + serviceImplement);
- }
- log.info("service " + serviceClassName
- + " added for protocol " + proto);
- } catch (ClassNotFoundException e) {
- log.error("Class not found for " + serviceClassName, e);
- }
- }
- }
- }
- }
-
- /**
- * Fournit une interface sur un service en l'implementant comme definit dans
- * la configuration.
- *
- * Configuration (TopiaApplicationServices.properties par defaut) :
- * topia.application.service.fqn=local://fqnImpl/#new
- * topia.application.service.fqn=local://fqnImpl
- * topia.application.service.fqn=rmi://127.0.0.1:1099
- * topia.application.service.fqn=xmlrpc://127.0.0.1:9090 ...
- *
- * @param <E>
- * l'interface doit etendre TopiaApplicationService
- * @param serviceclazz
- * l'interface du service
- * @return l'implementation du service ou <tt>null</tt> si le service ne
- * peut etre charge
- * @see TopiaApplicationService
- * @throws TopiaNotFoundException
- * si le fichier de configuration n'existe pas
- * @throws TopiaException
- * si le service ne peut pas etre charge
- */
- @SuppressWarnings("unchecked")
- public static <E extends TopiaApplicationService> E getService(
- Class<E> serviceclazz) throws TopiaNotFoundException,
- TopiaException {
-
- // l'implementation a retourner
- E serviceimpl = (E) mapServiceCache.get(serviceclazz);
-
- // s'il etait dans le cache on le retourne directement
- // dans le cas "#new" il n'est jamais dans le cache, donc recree
- if (serviceimpl != null) {
- return serviceimpl;
- }
-
- // configuration
- Properties config = getConfiguration();
-
- // recherche du service
- String serviceUrl = (String) config.get(TOPIA_APPLICATION_SERVICE_BEGIN
- + serviceclazz.getCanonicalName());
- if (serviceUrl == null) {
- log.error("Properties '" + TOPIA_APPLICATION_SERVICE_BEGIN
- + serviceclazz.getCanonicalName()
- + "' not found in configuration");
- throw new TopiaNotFoundException("Service '"
- + serviceclazz.getCanonicalName()
- + "' not definided in configuration");
- } else {
-
- try {
- // conversion de l'URI
- URI uriService = new URI(serviceUrl);
- String protocole = uriService.getScheme();
- String host = uriService.getHost();
- String fragment = uriService.getFragment();
-
- // ensuite ca depend si le service est local ou distant
- // local = local://fqn
- // sinon, c'est distant
- if ("local".equalsIgnoreCase(protocole)) {
-
- String fqClassImpl = host;
- log.debug("Trying to load local service : " + fqClassImpl);
-
- // instanciation dynamique
- try {
- Class<E> resultClass = (Class<E>) Class
- .forName(fqClassImpl);
- serviceimpl = resultClass.newInstance();
- serviceimpl.init(defaultServiceContext
- .beginTransaction());
-
- // mise en cache
- // sauf dans le cas ou il y a un "#new" a la fin de
- // l'uri
- if (!"new".equalsIgnoreCase(fragment)) {
- mapServiceCache.put(serviceclazz, serviceimpl);
- }
- } catch (ClassNotFoundException eee) {
- throw new TopiaException("Can't find service class "
- + fqClassImpl);
- } catch (InstantiationException eee) {
- throw new TopiaException(
- "Can't instanciate service class "
- + fqClassImpl);
- } catch (IllegalAccessException eee) {
- throw new TopiaException("Can't access service class "
- + fqClassImpl);
- }
- }
- // prefix non local => proxy
- else {
- log.debug("Trying to get remote service : " + serviceUrl);
-
- TopiaProxy tProxy = getProxyForURI(uriService);
-
- if (tProxy == null) {
- log.debug("Unsupported protocole : " + protocole);
- } else {
-
- tProxy.setURI(uriService);
- tProxy.setClass(serviceclazz);
-
- // le proxy tProxy definit suivant le protocole
- // gere maintenant tous les appels sur l'interface
- // demandee (serviceclazz)
- serviceimpl = (E) Proxy.newProxyInstance(serviceclazz
- .getClassLoader(),
- new Class[] { serviceclazz }, tProxy);
-
- // mise en cache
- mapServiceCache.put(serviceclazz, serviceimpl);
- }
- }
- } catch (URISyntaxException e) {
- log.warn("URI for service '" + serviceclazz.getCanonicalName()
- + "' is invalid !", e);
- return null;
- }
- }
-
- return serviceimpl;
- }
-
- /**
- * Retourne l'implementation d'un TopiaProxy en fonction du protocole de
- * l'URI
- *
- * @param uriService
- * @return l'implementation ou null si le protocol n'est pas g�r�
- */
- private static TopiaProxy getProxyForURI(URI uriService) {
-
- // result
- TopiaProxy tProxy = null;
-
- if ("rmi".equalsIgnoreCase(uriService.getScheme())) {
- tProxy = new RMIProxy();
- } else if ("xml-rpc".equalsIgnoreCase(uriService.getScheme())) {
- tProxy = new XMLRPCProxy();
- } else if ("soap".equalsIgnoreCase(uriService.getScheme())) {
- tProxy = new SOAPProxy();
- }
-
- return tProxy;
- }
-
- /**
- * Ajoute un service fournit par ToPIA.
- *
- * @param interfaze
- * l'interface du service
- * @param clazz
- * la classe qui permet de creer des instances de
- * l'implementation du service
- * @param protocoles
- * les protocoles de diffusion du service
- *
- * @see TopiaApplicationService
- */
- public static void addService(
- Class<? extends TopiaApplicationService> interfaze,
- Class<? extends TopiaApplicationService> clazz,
- Protocol... protocoles) {
- log.debug("Adding service for '" + interfaze + "' in protocoles : "
- + Arrays.toString(protocoles));
-
- for (Protocol protocole : protocoles) {
- mainDispatcher.addServiceClass(interfaze, clazz, protocole);
- }
- }
-
- /**
- * Ajoute un service fournit par ToPIA.
- *
- * Celle-ci renvoie toujours la meme instance du service.
- *
- * @param <E>
- * un type qui etend TopiaApplicationService
- * @param interfaze
- * l'interface du service
- * @param instance
- * l'instance de l'implementation du service
- * @param protocoles
- * les protocoles de diffusion du service
- *
- * @see TopiaApplicationService
- */
- public static <E extends TopiaApplicationService> void addService(
- Class<E> interfaze, E instance, Protocol... protocoles) {
- log.debug("Adding service for '" + interfaze
- + "'(unique instance) in protocoles : "
- + Arrays.toString(protocoles));
-
- for (Protocol protocole : protocoles) {
- mainDispatcher.addServiceInstance(interfaze, instance, protocole);
- }
- }
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/TopiaProxy.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/TopiaProxy.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/TopiaProxy.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,49 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.service;
-
-import java.lang.reflect.InvocationHandler;
-import java.net.URI;
-
-/**
- * TopiaProxy.java
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public interface TopiaProxy extends InvocationHandler, TopiaApplicationService {
-
- /**
- * Rensigne l'URI du service
- *
- * @param uri
- * l'URI
- * @see java.net.URI
- */
- public void setURI(URI uri);
-
- /**
- * Renseigne la classe geree
- *
- * @param clazz
- * la class
- */
- public void setClass(Class<? extends TopiaApplicationService> clazz);
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceProvider.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/TopiaServiceProvider.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceProvider.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,266 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.service;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.rmi.RemoteException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.beanutils.MethodUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.service.servers.RMIServer;
-import org.codelutin.topia.service.servers.SOAPServer;
-import org.codelutin.topia.service.servers.XMLRPCServer;
-
-/**
- * TopiaServiceProvider.java
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public class TopiaServiceProvider {
-
- /** Logger (common logging) */
- private static final Log logger = LogFactory
- .getLog(TopiaServiceProvider.class);
-
- /**
- * Map de correspondance interface -> instance
- */
- private Map<Class<? extends TopiaApplicationService>, TopiaApplicationService> mapInstanceForClass;
-
- /**
- * Map de corresponcance class servant a creer une instance pour une
- * interface (pour chaque requete)
- */
- private Map<Class<? extends TopiaApplicationService>, Class<? extends TopiaApplicationService>> mapClassForClass;
-
- /**
- * Sert a savoir si des servers ont deja ete lance ou pas.
- */
- private Map<Protocol, TopiaServiceServer> mapDispatcherForProtocole;
-
- /**
- * Map between port and protocol
- */
- protected Map<Protocol, Integer> mapPortForProtocol;
-
- /**
- * Constructeur
- */
- public TopiaServiceProvider() {
- // instancaition des maps
- mapInstanceForClass = new HashMap<Class<? extends TopiaApplicationService>, TopiaApplicationService>();
- mapClassForClass = new HashMap<Class<? extends TopiaApplicationService>, Class<? extends TopiaApplicationService>>();
- mapDispatcherForProtocole = new HashMap<Protocol, TopiaServiceServer>();
- mapPortForProtocol = new HashMap<Protocol, Integer>();
- }
-
- /**
- * Add a protocol port
- *
- * @param pr protocol
- * @param port port
- */
- public void setProtocolPort(Protocol pr, Integer port) {
- mapPortForProtocol.put(pr, port);
- }
-
- /**
- *
- * @param interfaze
- * @param clazz
- * @param protocole
- */
- public void addServiceClass(
- Class<? extends TopiaApplicationService> interfaze,
- Class<? extends TopiaApplicationService> clazz, Protocol protocole) {
- TopiaServiceServer server = initDispatcher(protocole);
- if (server != null) {
- server.addService(interfaze);
- mapClassForClass.put(interfaze, clazz);
- launchDispatcher(protocole);
- }
- }
-
- /**
- *
- * @param interfaze
- * @param instance
- * @param protocole
- */
- public void addServiceInstance(
- Class<? extends TopiaApplicationService> interfaze,
- TopiaApplicationService instance, Protocol protocole) {
- TopiaServiceServer server = initDispatcher(protocole);
- if (server != null) {
- server.addService(interfaze);
- mapInstanceForClass.put(interfaze, instance);
- launchDispatcher(protocole);
- }
-
- }
-
- /**
- *
- * @param protocole
- */
- private TopiaServiceServer initDispatcher(Protocol protocole) {
-
- TopiaServiceServer server = mapDispatcherForProtocole.get(protocole);
-
- // si un serveur n'est pas deja creer pour ce protocole
- if (server == null) {
-
- switch (protocole) {
- case XML_RPC:
- if(mapPortForProtocol.get(Protocol.XML_RPC) != null) {
- server = new XMLRPCServer(mapPortForProtocol.get(Protocol.XML_RPC));
- }
- else {
- server = new XMLRPCServer();
- }
- break;
- case RMI:
- try {
- if(mapPortForProtocol.get(Protocol.RMI) != null) {
- server = new RMIServer(mapPortForProtocol.get(Protocol.RMI));
- }
- else {
- server = new RMIServer();
- }
- } catch (RemoteException e) {
- logger.debug("Can't start RMIServer.",e);
- }
- break;
- case SOAP:
- if(mapPortForProtocol.get(Protocol.SOAP) != null) {
- server = new SOAPServer(mapPortForProtocol.get(Protocol.SOAP));
- }
- else {
- server = new SOAPServer();
- }
- break;
- default:
- logger.debug("Unsupported protocole");
- break;
- }
-
- // ajoute a la liste
- mapDispatcherForProtocole.put(protocole, server);
- // renseigne le dispatcher
- server.setTopiaServiceProvider(this);
- }
-
- return server;
- }
-
- /**
- *
- * @param protocole
- */
- private void launchDispatcher(Protocol protocole) {
- TopiaServiceServer server = mapDispatcherForProtocole.get(protocole);
-
- /*switch (protocole) {
- case XML_RPC:
- // le lance
- server.launch();
- break;
- case RMI:
- server.launch();
- break;
- case SOAP:
- server.launch();
- break;
- default:
- logger.debug("Unsupported protocole");
- break;
- }*/
- server.launch();
- }
-
- /**
- * Effectue l'appel reel suivant comment a ete fournit le service, classe ou
- * instance.
- *
- * @param args
- * les arguments
- * @param method
- * la methode
- * @return le resultat de l'appel de la methode
- */
- public Object execute(Method method, Object[] args) {
- // log
- logger.debug("Request service : "
- + method.getDeclaringClass().getName() + "." + method.getName()
- + "(" + Arrays.toString(args) + ")");
-
- Object result = null;
-
- // la classe du service
- Class clazz = null;
- try {
- clazz = method.getDeclaringClass();
-
- // le service
- TopiaApplicationService tasService = null;
-
- // recherche du service dans la map class -> class
- if (mapClassForClass.get(clazz) != null) {
- tasService = mapClassForClass.get(clazz).newInstance();
- }
- // sinon dans la map clazz -> instance
- else if (mapInstanceForClass.get(clazz) != null) {
- tasService = mapInstanceForClass.get(clazz);
- } else
- logger.warn("No service set for class " + clazz.getName());
-
- // Appel via commons beanutils
- result = MethodUtils.invokeMethod(tasService, method.getName(),
- args);
-
- } catch (InstantiationException e) {
- logger.debug("Can't instanciate class", e);
- } catch (IllegalAccessException e) {
- logger.debug("Can't access class", e);
- } catch (SecurityException e) {
- logger.debug("Can't call method '" + clazz.getName()
- + "' in class '" + clazz.getName()
- + "' (SecurityException)", e);
- } catch (NoSuchMethodException e) {
- logger.debug("No method '" + clazz.getName() + "' found in class '"
- + clazz.getName() + "'", e);
- } catch (IllegalArgumentException e) {
- logger.debug("Can't call method '" + clazz.getName()
- + "' in class '" + clazz.getName() + "' (security)", e);
- } catch (InvocationTargetException e) {
- logger.debug("Can't call method '" + clazz.getName()
- + "' in class '" + clazz.getName()
- + "' (InvocationTargetException)", e);
- }
-
- return result;
- }
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceServer.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/TopiaServiceServer.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceServer.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,50 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.service;
-
-/**
- * TopiaServiceServer.java
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public interface TopiaServiceServer {
-
- /**
- * Ajoute un service devant etre gere.
- *
- * @param clazz
- * le nom de l'interface.
- */
- public abstract void addService(
- Class<? extends TopiaApplicationService> clazz);
-
- /**
- * Lance le serveur
- */
- public abstract void launch();
-
- /**
- * Set dispatcher
- *
- * @param mainDispatcher
- */
- public void setTopiaServiceProvider(TopiaServiceProvider mainDispatcher);
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceServerAbstract.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/TopiaServiceServerAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,61 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-package org.codelutin.topia.service;
-
-import java.lang.reflect.Method;
-
-/**
- * TopiaServiceServer.java
- *
- * Methodes communes a tous les servers renvoie l'appel sur le dispatcher
- * principal.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public abstract class TopiaServiceServerAbstract implements TopiaServiceServer {
-
- /** Le dispatcher principal */
- private TopiaServiceProvider mainDispatcher;
-
- /**
- * Set dispatcher
- *
- * @param mainDispatcher
- */
- public void setTopiaServiceProvider(TopiaServiceProvider mainDispatcher) {
- this.mainDispatcher = mainDispatcher;
- }
-
- /**
- * Disptach
- *
- * @param className
- * la classe
- * @param methodName
- * le nom de la methode
- * @param args
- * les arguments
- * @return le resultat de l'appel
- */
- protected Object invoke(Method method, Object[] args) {
- return mainDispatcher.execute(method, args);
- }
-}
Deleted: topia/trunk/topia-persistence/src/main/java/topia/service/package.html
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/package.html 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/main/java/topia/service/package.html 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,30 +0,0 @@
-<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
-
-<html>
- <head>
- <meta
- name="service"
- content="HTML Tidy, see www.w3.org">
-
- <title></title>
- </head>
-
- <body>
- <h1>La couche de service ToPIA.</h1>
-
- <p>Toutes l'utilisation s'effectue au travers de la factory TopiaServiceFactory.</p>
-
- <h2>Services utilisés</h2>
-
- <p>TopiaServiceFactory.getService(Class) permet de recuperer une interface
- sur un service, son implmentation est chargée comme definie dans la
- configuration.</p>
-
- <h2>Services fournit</h2>
-
- <p>TopiaServiceFactory.addService(Class,Class,Protocole...) et
- TopiaServiceFactory.addService(Class,Object,Protocole...) permettent de mettre
- à disposition un service sur un protocole donné</p>
- </body>
-</html>
-
Copied: topia/trunk/topia-persistence/src/site (from rev 1229, topia/trunk/src/site)
Copied: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml (from rev 1229, topia/trunk/src/test/java/org/codelutin/topia/Person.hbm.xml)
===================================================================
--- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml (rev 0)
+++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.codelutin.topia.PersonImpl" table="person" node="org.codelutin.topia.Person" proxy="org.codelutin.topia.Person">
+ <id name="topiaId" length="255" node="@topiaId" access="field">
+ <!-- on utilise des TopiaId maintenant <generator class="uuid.hex"/> -->
+ </id>
+ <version name="topiaVersion" type="long" node="@topiaVersion" access="field"/>
+ <property name="topiaCreateDate" type="date" node="@topiaCreateDate" access="field"/>
+ <property name="name" type="string" node="@name" access="field"/>
+ <property name="firstname" type="string" node="@firstname" access="field"/>
+ </class>
+</hibernate-mapping>
Property changes on: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java (from rev 1229, topia/trunk/src/test/java/org/codelutin/topia/Person.java)
===================================================================
--- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java (rev 0)
+++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,59 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * Person.java
+ *
+ * Created: 29 déc. 2005 00:27:53
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia;
+
+import org.codelutin.topia.persistence.TopiaEntity;
+
+/**
+ * @author poussin
+ */
+public interface Person extends TopiaEntity {
+
+ /**
+ * @return Returns the firstname.
+ */
+ public abstract String getFirstname();
+
+ /**
+ * @param firstname The firstname to set.
+ */
+ public abstract void setFirstname(String firstname);
+
+ /**
+ * @return Returns the name.
+ */
+ public abstract String getName();
+
+ /**
+ * @param name The name to set.
+ */
+ public abstract void setName(String name);
+
+}
Property changes on: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java (from rev 1229, topia/trunk/src/test/java/org/codelutin/topia/PersonAbstract.java)
===================================================================
--- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java (rev 0)
+++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,86 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * PersonAbstract.java
+ *
+ * Created: 29 déc. 2005 00:27:53
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.persistence.TopiaEntity;
+import org.codelutin.topia.persistence.TopiaEntityAbstract;
+
+/**
+ * @author poussin
+ *
+ */
+public abstract class PersonAbstract extends TopiaEntityAbstract implements
+ Person {
+
+ protected String name;
+
+ protected String firstname;
+
+ public String getFirstname() {
+ fireOnPreRead("firstname", name);
+ String result = firstname;
+ fireOnPreRead("firstname", result);
+ return result;
+ }
+
+ public void setFirstname(String firstname) {
+ String _oldValue = this.firstname;
+ fireOnPreWrite("firstName", _oldValue, firstname);
+ this.firstname = firstname;
+ fireOnPostWrite("firstName", _oldValue, firstname);
+ }
+
+ public String getName() {
+ fireOnPreRead("name", name);
+ String result = name;
+ fireOnPreRead("name", result);
+ return result;
+ }
+
+ public void setName(String name) {
+ String _oldValue = this.name;
+ fireOnPreWrite("name", _oldValue, name);
+ this.name = name;
+ fireOnPostWrite("name", _oldValue, name);
+ }
+
+ public List<TopiaEntity> getComposite() throws TopiaException {
+ return new ArrayList<TopiaEntity>();
+ }
+
+ public List<TopiaEntity> getAggregate() throws TopiaException {
+ return new ArrayList<TopiaEntity>();
+ }
+
+}
Property changes on: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java (from rev 1229, topia/trunk/src/test/java/org/codelutin/topia/PersonImpl.java)
===================================================================
--- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java (rev 0)
+++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,38 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/*******************************************************************************
+ * PersonImpl.java
+ *
+ * Created: 28 déc. 2005 16:14:04
+ *
+ * @author poussin
+ *
+ * @version $Revision$
+ *
+ * Last update: $Date$ by : $Author$
+ */
+
+package org.codelutin.topia;
+
+/**
+ * @author poussin
+ *
+ */
+public class PersonImpl extends PersonAbstract implements Person {
+
+}
Property changes on: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java (from rev 1229, topia/trunk/src/test/java/org/codelutin/topia/TopiaContextTest.java)
===================================================================
--- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java (rev 0)
+++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,464 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/*******************************************************************************
+ * TopiaContextTest.java
+ *
+ * Created: 28 d?c. 2005 16:26:24
+ *
+ * @author poussin
+ *
+ * @version $Revision$
+ *
+ * Last update: $Date$ by : $Author$
+ */
+
+package org.codelutin.topia;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaContextFactory;
+import org.codelutin.topia.event.TopiaEntityEvent;
+import org.codelutin.topia.event.TopiaEntityListener;
+import org.codelutin.topia.event.TopiaEntityVetoable;
+import org.codelutin.topia.event.TopiaTransactionEvent;
+import org.codelutin.topia.event.TopiaTransactionListener;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+import org.codelutin.topia.persistence.TopiaDAO;
+
+/**
+ * @author poussin
+ *
+ */
+public class TopiaContextTest extends TestCase {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(TopiaContextTest.class);
+
+ protected String entitiesList = Person.class.getName();
+
+ protected Properties getPostgreSQLProperties() {
+ Properties config = new Properties();
+ config.setProperty("hibernate.show_sql", "true");
+ config.setProperty("hibernate.hbm2ddl.auto", "create");
+
+ config.setProperty("topia.dao.flatfile.directory", "/tmp/topiadb");
+ config.setProperty("topia.dao.flatfile.mapping.key", "firstname");
+
+ config.setProperty("topia.persistence.classes", entitiesList);
+ config.setProperty("hibernate.dialect",
+ "org.hibernate.dialect.PostgreSQLDialect");
+ config.setProperty("hibernate.connection.driver_class",
+ "org.postgresql.Driver");
+ config.setProperty("hibernate.connection.url",
+ "jdbc:postgresql:database");
+ config.setProperty("hibernate.connection.username", "dbuser");
+ config.setProperty("hibernate.connection.password", "xxxxxxxx");
+
+ return config;
+ }
+
+ protected Properties getDerbyProperties() {
+ Properties config = new Properties();
+ config.setProperty("hibernate.show_sql", "true");
+ config.setProperty("hibernate.hbm2ddl.auto", "create");
+
+ config.setProperty("topia.dao.flatfile.directory", "/tmp/topiadb");
+ config.setProperty("topia.dao.flatfile.mapping.key", "firstname");
+
+ config.setProperty("topia.persistence.classes", entitiesList);
+ config.setProperty("hibernate.dialect",
+ "org.hibernate.dialect.DerbyDialect");
+ config.setProperty("hibernate.connection.driver_class",
+ "org.apache.derby.jdbc.EmbeddedDriver");
+ config.setProperty("hibernate.connection.url",
+ "jdbc:derby:/tmp/topiaderby;create=true");
+ config.setProperty("hibernate.connection.username", "dbuser");
+ config.setProperty("hibernate.connection.password", "xxxxxxxx");
+
+ return config;
+ }
+
+ protected Properties getH2Properties() {
+ Properties config = new Properties();
+ config.setProperty("hibernate.show_sql", "true");
+ config.setProperty("hibernate.hbm2ddl.auto", "create");
+
+ new File("/tmp/topiadb/").mkdirs();
+ config.setProperty("topia.dao.flatfile.directory", "/tmp/topiadb/h2");
+ config.setProperty("topia.dao.flatfile.mapping.key", "firstname");
+
+ config.setProperty("topia.persistence.classes", entitiesList);
+ config.setProperty("hibernate.dialect",
+ "org.hibernate.dialect.HSQLDialect");
+ config
+ .setProperty("hibernate.connection.driver_class",
+ "org.h2.Driver");
+ config.setProperty("hibernate.connection.url",
+ "jdbc:h2:file:/tmp/topiaderby;create=true");
+ config.setProperty("hibernate.connection.username", "sa");
+ config.setProperty("hibernate.connection.password", "");
+
+ return config;
+ }
+
+ protected Properties getProperties() {
+ return getH2Properties();
+ }
+
+ /*
+ * #hibernate.dialect org.hibernate.dialect.DerbyDialect
+ * #hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver
+ * #hibernate.connection.url jdbc:derby:/test;create=true
+ * #hibernate.connection.username #hibernate.connection.password
+ */
+ public void testGetParentContext() throws Exception {
+ Properties config = getProperties();
+
+ TopiaContextImplementor topiaContext = (TopiaContextImplementor) TopiaContextFactory
+ .getContext(config);
+
+ TopiaContextImplementor child1 = (TopiaContextImplementor) topiaContext
+ .beginTransaction();
+ TopiaContextImplementor child2 = (TopiaContextImplementor) child1
+ .beginTransaction();
+
+ assertEquals(child1, child2.getParentContext());
+ assertEquals(topiaContext, child1.getParentContext());
+ assertEquals(null, topiaContext.getParentContext());
+
+ assertEquals(topiaContext, topiaContext.getRootContext());
+ assertEquals(topiaContext, child1.getRootContext());
+ assertEquals(topiaContext, child2.getRootContext());
+ }
+
+ public void testHibernate() throws Exception {
+ System.out.println("Debut du test Hibernate");
+
+ Properties config = getProperties();
+
+ TopiaContext context = TopiaContextFactory.getContext(config);
+
+ TopiaContextImplementor childContext = (TopiaContextImplementor) context
+ .beginTransaction();
+ TopiaDAO<Person> persons = childContext.getDAO(Person.class);
+ Person p = persons.create();
+ p.setName("poussin");
+ p.setFirstname("benjamin");
+ persons.update(p);
+ childContext.commitTransaction();
+
+ String id = p.getTopiaId();
+
+ Person p1 = persons.create();
+ p1.setName("poussin");
+ p1.setFirstname("jacques");
+ persons.update(p1);
+ childContext.commitTransaction();
+
+ Person p2 = persons.create();
+ p2.setName("poussin");
+ p2.setFirstname("mylene");
+ persons.update(p2);
+ childContext.rollbackTransaction();
+
+ p.setFirstname("berengere");
+ persons.update(p);
+ childContext.commitTransaction();
+
+ p.setFirstname("toto");
+ persons.update(p);
+ assertEquals("toto", p.getFirstname());
+ childContext.rollbackTransaction();
+
+ p = persons.findByTopiaId(id);
+ assertEquals("berengere", p.getFirstname());
+
+ TopiaContextImplementor childContext2 = (TopiaContextImplementor) context
+ .beginTransaction();
+ TopiaDAO<Person> persons2 = childContext2.getDAO(Person.class);
+
+ Person pp = persons2.findByTopiaId(id);
+ assertEquals("berengere", pp.getFirstname());
+ }
+
+ public void testIsolation() throws Exception {
+ System.out.println("Debut du test Isolation");
+
+ Properties config = getProperties();
+
+ TopiaContext context = TopiaContextFactory.getContext(config);
+
+ TopiaContextImplementor c1 = (TopiaContextImplementor) context
+ .beginTransaction();
+ TopiaContextImplementor c2 = (TopiaContextImplementor) context
+ .beginTransaction();
+
+ TopiaDAO<Person> ps1 = c1.getDAO(Person.class);
+ TopiaDAO<Person> ps2 = c2.getDAO(Person.class);
+
+ Person p = ps1.create();
+ p.setName("poussin");
+ p.setFirstname("benjamin");
+ ps1.update(p);
+
+ c1.rollbackTransaction();
+
+ assertEquals(0, ps1.findAll().size());
+ assertEquals(0, ps2.findAll().size());
+
+ p = ps1.create();
+ p.setName("poussin");
+ p.setFirstname("benjamin");
+ ps1.update(p);
+
+ assertEquals(1, ps1.findAll().size());
+ assertEquals(0, ps2.findAll().size());
+
+ c1.commitTransaction();
+
+ assertEquals(1, ps1.findAll().size());
+ assertEquals(0, ps2.findAll().size());
+
+ ps1.delete(p);
+
+ assertEquals(0, ps1.findAll().size());
+ assertEquals(0, ps2.findAll().size());
+
+ c1.commitTransaction();
+
+ assertEquals(0, ps1.findAll().size());
+ assertEquals(0, ps2.findAll().size());
+
+ }
+
+ public void testFlatFile() throws Exception {
+ System.out.println("Debut du test FlatFile");
+
+ Properties config = getProperties();
+ config.setProperty("topia.dao.default.class", "flatfile");
+
+ TopiaContext context = TopiaContextFactory.getContext(config);
+
+ TopiaContextImplementor childContext = (TopiaContextImplementor) context
+ .beginTransaction();
+ TopiaDAO<Person> persons = childContext.getDAO(Person.class);
+ Person p = persons.create();
+ p.setName("poussin");
+ p.setFirstname("benjamin");
+ persons.update(p);
+ childContext.commitTransaction();
+
+ Person p1 = persons.create();
+ p1.setName("poussin");
+ p1.setFirstname("jacques");
+ persons.update(p1);
+ childContext.commitTransaction();
+
+ Person p2 = persons.create();
+ p2.setName("poussin");
+ p2.setFirstname("mylene");
+ persons.update(p2);
+ childContext.rollbackTransaction();
+
+ p.setFirstname("berengere");
+ persons.update(p);
+ childContext.commitTransaction();
+
+ }
+
+ public void testConstructor() throws Exception {
+ System.out.println("Debut du test constructor");
+
+ Properties config = getProperties();
+
+ TopiaContext context = TopiaContextFactory.getContext(config);
+
+ TopiaContextImplementor childContext = (TopiaContextImplementor) context
+ .beginTransaction();
+
+ TopiaDAO<Person> persons = childContext.getDAO(Person.class);
+ Person p = persons.create("name", "poussin", "firstname", "toto");
+ assertEquals("poussin", p.getName());
+ assertEquals("toto", p.getFirstname());
+
+ persons.update(p);
+ childContext.commitTransaction();
+
+ p.setFirstname("titi");
+ assertEquals("titi", p.getFirstname());
+
+ persons.update(p);
+ childContext.commitTransaction();
+
+ p.setFirstname("benjamin");
+ assertEquals("benjamin", p.getFirstname());
+
+ persons.update(p);
+ childContext.commitTransaction();
+
+ persons.delete(p);
+ childContext.commitTransaction();
+ }
+
+ String state = "";
+
+ public void testEventHibernate() throws Exception {
+ System.out.println("Debut du test Event");
+
+ Properties config = getProperties();
+ TopiaContext context = TopiaContextFactory.getContext(config);
+
+ TopiaEntityVetoable entityVetoable = new TopiaEntityVetoable() {
+ private void print(TopiaEntityEvent event, String _state) {
+ state += _state;
+ if (log.isInfoEnabled()) {
+ log.info(_state + " " + event.getEntity());
+ }
+ }
+
+ public void create(TopiaEntityEvent event) {
+ print(event, "vetoCreate");
+ }
+
+ public void update(TopiaEntityEvent event) {
+ print(event, "vetoUpdate");
+ }
+
+ public void delete(TopiaEntityEvent event) {
+ print(event, "vetoDelete");
+ }
+
+ public void load(TopiaEntityEvent event) {
+ print(event, "vetoLoad");
+ }
+ };
+
+ TopiaEntityListener entityListener = new TopiaEntityListener() {
+ private void print(TopiaEntityEvent event, String _state) {
+ state += _state;
+ if (log.isInfoEnabled()) {
+ log.info(_state + " " + event.getEntity());
+ }
+ }
+
+ public void create(TopiaEntityEvent event) {
+ print(event, "entityCreated");
+ }
+
+ public void update(TopiaEntityEvent event) {
+ print(event, "entityUpdated");
+ }
+
+ public void delete(TopiaEntityEvent event) {
+ print(event, "entityDeleted");
+ }
+
+ public void load(TopiaEntityEvent event) {
+ print(event, "entityLoaded");
+ }
+ };
+
+ TopiaTransactionListener transactionListener = new TopiaTransactionListener() {
+ public void commit(TopiaTransactionEvent event) {
+ log.info("commit " + event.getEntities());
+ }
+
+ public void rollback(TopiaTransactionEvent event) {
+ log.info("rollback " + event.getEntities());
+ }
+ };
+
+ TopiaContextImplementor childContext = (TopiaContextImplementor) context
+ .beginTransaction();
+ childContext.addTopiaEntityVetoable(entityVetoable);
+ childContext.addTopiaEntityListener(entityListener);
+ childContext.addTopiaTransactionListener(transactionListener);
+ TopiaDAO<Person> persons = childContext.getDAO(Person.class);
+
+ Person p = persons.create();
+ p.setName("poussin");
+ p.setFirstname("benjamin");
+ persons.update(p);
+ childContext.commitTransaction();
+
+ assertEquals("vetoCreateentityCreatedvetoUpdateentityUpdated", state);
+ state = "";
+
+ p.setFirstname("toto");
+ persons.update(p);
+ childContext.commitTransaction();
+
+ assertEquals("vetoUpdateentityUpdated", state);
+ state = "";
+
+ TopiaContextImplementor childContext2 = (TopiaContextImplementor) context
+ .beginTransaction();
+ childContext2.addTopiaEntityVetoable(entityVetoable);
+ childContext2.addTopiaEntityListener(entityListener);
+ childContext2.addTopiaTransactionListener(transactionListener);
+ TopiaDAO<Person> persons2 = childContext2.getDAO(Person.class);
+
+ Person pp = persons2.findByTopiaId(p.getTopiaId());
+
+ assertEquals(p.getFirstname(), pp.getFirstname());
+ assertEquals("vetoLoadentityLoaded", state);
+ state = "";
+
+ persons2.delete(pp);
+ childContext2.commitTransaction();
+
+ assertEquals("vetoDeleteentityDeleted", state);
+ state = "";
+
+ }
+
+ public void testPropertyEvent() throws Exception {
+ PropertyChangeListener l = new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ System.out.println("entityUpdated " + evt.getSource());
+ state = "entityUpdated";
+ }
+ };
+
+ Properties config = getProperties();
+
+ TopiaContextImplementor ctx = (TopiaContextImplementor) TopiaContextFactory
+ .getContext(config).beginTransaction();
+
+ TopiaDAO<Person> personDAO = ctx.getDAO(Person.class);
+ Person p = personDAO.create();
+ p.addPropertyChangeListener("firstName", l);
+
+ p.setFirstname("Arno");
+ assertEquals("entityUpdated", state);
+ state = "";
+
+ p.setName("Arno");
+ assertEquals("", state);
+ state = "";
+ }
+
+} //TopiaContextTest
Property changes on: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework (from rev 1229, topia/trunk/src/test/java/org/codelutin/topia/framework)
Property changes on: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/EntityStateTest.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/framework/EntityStateTest.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/EntityStateTest.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -29,9 +29,10 @@
package org.codelutin.topia.framework;
+import org.codelutin.topia.framework.EntityState;
+
import junit.framework.TestCase;
-
/**
* @author poussin
*
@@ -46,7 +47,7 @@
assertFalse(state.isCreate());
assertFalse(state.isUpdate());
assertFalse(state.isDelete());
-
+
state.addRead();
state.addCreate();
assertTrue(state.isRead());
@@ -65,7 +66,7 @@
assertTrue(state.isCreate());
assertTrue(state.isUpdate());
assertTrue(state.isDelete());
-
+
state = new EntityState();
state.addDelete();
assertFalse(state.isRead());
@@ -74,5 +75,3 @@
assertTrue(state.isDelete());
}
}
-
-
Copied: topia/trunk/topia-persistence/src/test/java/topia (from rev 1229, topia/trunk/src/test/java/org/codelutin/topia)
Property changes on: topia/trunk/topia-persistence/src/test/java/topia
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: topia/trunk/topia-persistence/src/test/java/topia/Person.hbm.xml
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/Person.hbm.xml 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/test/java/topia/Person.hbm.xml 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,16 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping>
- <class name="org.codelutin.topia.PersonImpl" table="person" node="org.codelutin.topia.Person" proxy="org.codelutin.topia.Person">
- <id name="topiaId" length="255" node="@topiaId" access="field">
- <!-- on utilise des TopiaId maintenant <generator class="uuid.hex"/> -->
- </id>
- <version name="topiaVersion" type="long" node="@topiaVersion" access="field"/>
- <property name="topiaCreateDate" type="date" node="@topiaCreateDate" access="field"/>
- <property name="name" type="string" node="@name" access="field"/>
- <property name="firstname" type="string" node="@firstname" access="field"/>
- </class>
-</hibernate-mapping>
Deleted: topia/trunk/topia-persistence/src/test/java/topia/Person.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/Person.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/test/java/topia/Person.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,61 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * Person.java
- *
- * Created: 29 déc. 2005 00:27:53
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia;
-
-import org.codelutin.topia.persistence.TopiaEntity;
-
-/**
- * @author poussin
- */
-public interface Person extends TopiaEntity {
-
- /**
- * @return Returns the firstname.
- */
- public abstract String getFirstname();
-
- /**
- * @param firstname The firstname to set.
- */
- public abstract void setFirstname(String firstname);
-
- /**
- * @return Returns the name.
- */
- public abstract String getName();
-
- /**
- * @param name The name to set.
- */
- public abstract void setName(String name);
-
-}
-
-
Deleted: topia/trunk/topia-persistence/src/test/java/topia/PersonAbstract.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/PersonAbstract.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/test/java/topia/PersonAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,84 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * PersonAbstract.java
- *
- * Created: 29 déc. 2005 00:27:53
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.codelutin.topia.persistence.TopiaEntity;
-import org.codelutin.topia.persistence.TopiaEntityAbstract;
-
-/**
- * @author poussin
- *
- */
-public abstract class PersonAbstract extends TopiaEntityAbstract implements Person {
-
- protected String name;
-
- protected String firstname;
-
- public String getFirstname() {
- fireOnPreRead("firstname", name);
- String result = firstname;
- fireOnPreRead("firstname", result);
- return result;
- }
-
- public void setFirstname(String firstname) {
- String _oldValue = this.firstname;
- fireOnPreWrite("firstName", _oldValue, firstname);
- this.firstname = firstname;
- fireOnPostWrite("firstName", _oldValue, firstname);
- }
-
- public String getName() {
- fireOnPreRead("name", name);
- String result = name;
- fireOnPreRead("name", result);
- return result;
- }
-
- public void setName(String name) {
- String _oldValue = this.name;
- fireOnPreWrite("name", _oldValue, name);
- this.name = name;
- fireOnPostWrite("name", _oldValue, name);
- }
-
- public List<TopiaEntity> getComposite() throws TopiaException {
- return new ArrayList<TopiaEntity>();
- }
-
- public List<TopiaEntity> getAggregate() throws TopiaException {
- return new ArrayList<TopiaEntity>();
- }
-
-}
Deleted: topia/trunk/topia-persistence/src/test/java/topia/PersonImpl.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/PersonImpl.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/test/java/topia/PersonImpl.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,38 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/*******************************************************************************
- * PersonImpl.java
- *
- * Created: 28 déc. 2005 16:14:04
- *
- * @author poussin
- *
- * @version $Revision$
- *
- * Last update: $Date$ by : $Author$
- */
-
-package org.codelutin.topia;
-
-/**
- * @author poussin
- *
- */
-public class PersonImpl extends PersonAbstract implements Person {
-
-}
Deleted: topia/trunk/topia-persistence/src/test/java/topia/TopiaContextTest.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/TopiaContextTest.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-persistence/src/test/java/topia/TopiaContextTest.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -1,459 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/*******************************************************************************
- * TopiaContextTest.java
- *
- * Created: 28 d?c. 2005 16:26:24
- *
- * @author poussin
- *
- * @version $Revision$
- *
- * Last update: $Date$ by : $Author$
- */
-
-package org.codelutin.topia;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.event.TopiaEntityEvent;
-import org.codelutin.topia.event.TopiaEntityListener;
-import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.event.TopiaTransactionEvent;
-import org.codelutin.topia.event.TopiaTransactionListener;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-import org.codelutin.topia.persistence.TopiaDAO;
-
-/**
- * @author poussin
- *
- */
-public class TopiaContextTest extends TestCase {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(TopiaContextTest.class);
-
- protected String entitiesList = Person.class.getName();
-
- protected Properties getPostgreSQLProperties() {
- Properties config = new Properties();
- config.setProperty("hibernate.show_sql", "true");
- config.setProperty("hibernate.hbm2ddl.auto", "create");
-
- config.setProperty("topia.dao.flatfile.directory", "/tmp/topiadb");
- config.setProperty("topia.dao.flatfile.mapping.key", "firstname");
-
- config.setProperty("topia.persistence.classes", entitiesList);
- config.setProperty("hibernate.dialect",
- "org.hibernate.dialect.PostgreSQLDialect");
- config.setProperty("hibernate.connection.driver_class",
- "org.postgresql.Driver");
- config.setProperty("hibernate.connection.url",
- "jdbc:postgresql:database");
- config.setProperty("hibernate.connection.username", "dbuser");
- config.setProperty("hibernate.connection.password", "xxxxxxxx");
-
- return config;
- }
-
- protected Properties getDerbyProperties() {
- Properties config = new Properties();
- config.setProperty("hibernate.show_sql", "true");
- config.setProperty("hibernate.hbm2ddl.auto", "create");
-
- config.setProperty("topia.dao.flatfile.directory", "/tmp/topiadb");
- config.setProperty("topia.dao.flatfile.mapping.key", "firstname");
-
- config.setProperty("topia.persistence.classes", entitiesList);
- config.setProperty("hibernate.dialect",
- "org.hibernate.dialect.DerbyDialect");
- config.setProperty("hibernate.connection.driver_class",
- "org.apache.derby.jdbc.EmbeddedDriver");
- config.setProperty("hibernate.connection.url",
- "jdbc:derby:/tmp/topiaderby;create=true");
- config.setProperty("hibernate.connection.username", "dbuser");
- config.setProperty("hibernate.connection.password", "xxxxxxxx");
-
- return config;
- }
-
- protected Properties getH2Properties() {
- Properties config = new Properties();
- config.setProperty("hibernate.show_sql", "true");
- config.setProperty("hibernate.hbm2ddl.auto", "create");
-
- new File("/tmp/topiadb/").mkdirs();
- config.setProperty("topia.dao.flatfile.directory", "/tmp/topiadb/h2");
- config.setProperty("topia.dao.flatfile.mapping.key", "firstname");
-
- config.setProperty("topia.persistence.classes", entitiesList);
- config.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
- config.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
- config.setProperty("hibernate.connection.url",
- "jdbc:h2:file:/tmp/topiaderby;create=true");
- config.setProperty("hibernate.connection.username", "sa");
- config.setProperty("hibernate.connection.password", "");
-
- return config;
- }
-
- protected Properties getProperties() {
- return getH2Properties();
- }
-
- /*
- * #hibernate.dialect org.hibernate.dialect.DerbyDialect
- * #hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver
- * #hibernate.connection.url jdbc:derby:/test;create=true
- * #hibernate.connection.username #hibernate.connection.password
- */
- public void testGetParentContext() throws Exception {
- Properties config = getProperties();
-
- TopiaContextImplementor topiaContext = (TopiaContextImplementor) TopiaContextFactory
- .getContext(config);
-
- TopiaContextImplementor child1 = (TopiaContextImplementor) topiaContext
- .beginTransaction();
- TopiaContextImplementor child2 = (TopiaContextImplementor) child1
- .beginTransaction();
-
- assertEquals(child1, child2.getParentContext());
- assertEquals(topiaContext, child1.getParentContext());
- assertEquals(null, topiaContext.getParentContext());
-
- assertEquals(topiaContext, topiaContext.getRootContext());
- assertEquals(topiaContext, child1.getRootContext());
- assertEquals(topiaContext, child2.getRootContext());
- }
-
- public void testHibernate() throws Exception {
- System.out.println("Debut du test Hibernate");
-
- Properties config = getProperties();
-
- TopiaContext context = TopiaContextFactory.getContext(config);
-
- TopiaContextImplementor childContext = (TopiaContextImplementor) context
- .beginTransaction();
- TopiaDAO<Person> persons = childContext.getDAO(Person.class);
- Person p = persons.create();
- p.setName("poussin");
- p.setFirstname("benjamin");
- persons.update(p);
- childContext.commitTransaction();
-
- String id = p.getTopiaId();
-
- Person p1 = persons.create();
- p1.setName("poussin");
- p1.setFirstname("jacques");
- persons.update(p1);
- childContext.commitTransaction();
-
- Person p2 = persons.create();
- p2.setName("poussin");
- p2.setFirstname("mylene");
- persons.update(p2);
- childContext.rollbackTransaction();
-
- p.setFirstname("berengere");
- persons.update(p);
- childContext.commitTransaction();
-
- p.setFirstname("toto");
- persons.update(p);
- assertEquals("toto", p.getFirstname());
- childContext.rollbackTransaction();
-
- p = persons.findByTopiaId(id);
- assertEquals("berengere", p.getFirstname());
-
- TopiaContextImplementor childContext2 = (TopiaContextImplementor) context
- .beginTransaction();
- TopiaDAO<Person> persons2 = childContext2.getDAO(Person.class);
-
- Person pp = persons2.findByTopiaId(id);
- assertEquals("berengere", pp.getFirstname());
- }
-
- public void testIsolation() throws Exception {
- System.out.println("Debut du test Isolation");
-
- Properties config = getProperties();
-
- TopiaContext context = TopiaContextFactory.getContext(config);
-
- TopiaContextImplementor c1 = (TopiaContextImplementor) context
- .beginTransaction();
- TopiaContextImplementor c2 = (TopiaContextImplementor) context
- .beginTransaction();
-
- TopiaDAO<Person> ps1 = c1.getDAO(Person.class);
- TopiaDAO<Person> ps2 = c2.getDAO(Person.class);
-
- Person p = ps1.create();
- p.setName("poussin");
- p.setFirstname("benjamin");
- ps1.update(p);
-
- c1.rollbackTransaction();
-
- assertEquals(0, ps1.findAll().size());
- assertEquals(0, ps2.findAll().size());
-
- p = ps1.create();
- p.setName("poussin");
- p.setFirstname("benjamin");
- ps1.update(p);
-
- assertEquals(1, ps1.findAll().size());
- assertEquals(0, ps2.findAll().size());
-
- c1.commitTransaction();
-
- assertEquals(1, ps1.findAll().size());
- assertEquals(0, ps2.findAll().size());
-
- ps1.delete(p);
-
- assertEquals(0, ps1.findAll().size());
- assertEquals(0, ps2.findAll().size());
-
- c1.commitTransaction();
-
- assertEquals(0, ps1.findAll().size());
- assertEquals(0, ps2.findAll().size());
-
- }
-
- public void testFlatFile() throws Exception {
- System.out.println("Debut du test FlatFile");
-
- Properties config = getProperties();
- config.setProperty("topia.dao.default.class", "flatfile");
-
- TopiaContext context = TopiaContextFactory.getContext(config);
-
- TopiaContextImplementor childContext = (TopiaContextImplementor) context
- .beginTransaction();
- TopiaDAO<Person> persons = childContext.getDAO(Person.class);
- Person p = persons.create();
- p.setName("poussin");
- p.setFirstname("benjamin");
- persons.update(p);
- childContext.commitTransaction();
-
- Person p1 = persons.create();
- p1.setName("poussin");
- p1.setFirstname("jacques");
- persons.update(p1);
- childContext.commitTransaction();
-
- Person p2 = persons.create();
- p2.setName("poussin");
- p2.setFirstname("mylene");
- persons.update(p2);
- childContext.rollbackTransaction();
-
- p.setFirstname("berengere");
- persons.update(p);
- childContext.commitTransaction();
-
- }
-
- public void testConstructor() throws Exception {
- System.out.println("Debut du test constructor");
-
- Properties config = getProperties();
-
- TopiaContext context = TopiaContextFactory.getContext(config);
-
- TopiaContextImplementor childContext = (TopiaContextImplementor) context
- .beginTransaction();
-
- TopiaDAO<Person> persons = childContext.getDAO(Person.class);
- Person p = persons.create("name", "poussin", "firstname", "toto");
- assertEquals("poussin", p.getName());
- assertEquals("toto", p.getFirstname());
-
- persons.update(p);
- childContext.commitTransaction();
-
- p.setFirstname("titi");
- assertEquals("titi", p.getFirstname());
-
- persons.update(p);
- childContext.commitTransaction();
-
- p.setFirstname("benjamin");
- assertEquals("benjamin", p.getFirstname());
-
- persons.update(p);
- childContext.commitTransaction();
-
- persons.delete(p);
- childContext.commitTransaction();
- }
-
- String state = "";
-
- public void testEventHibernate() throws Exception {
- System.out.println("Debut du test Event");
-
- Properties config = getProperties();
- TopiaContext context = TopiaContextFactory.getContext(config);
-
- TopiaEntityVetoable entityVetoable = new TopiaEntityVetoable() {
- private void print(TopiaEntityEvent event, String _state) {
- state += _state;
- if(log.isInfoEnabled()) {
- log.info(_state + " " + event.getEntity());
- }
- }
-
- public void create(TopiaEntityEvent event) {
- print(event, "vetoCreate");
- }
-
- public void update(TopiaEntityEvent event) {
- print(event, "vetoUpdate");
- }
-
- public void delete(TopiaEntityEvent event) {
- print(event, "vetoDelete");
- }
-
- public void load(TopiaEntityEvent event) {
- print(event, "vetoLoad");
- }
- };
-
- TopiaEntityListener entityListener = new TopiaEntityListener() {
- private void print(TopiaEntityEvent event, String _state) {
- state += _state;
- if(log.isInfoEnabled()) {
- log.info(_state + " " + event.getEntity());
- }
- }
-
- public void create(TopiaEntityEvent event) {
- print(event, "entityCreated");
- }
-
- public void update(TopiaEntityEvent event) {
- print(event, "entityUpdated");
- }
-
- public void delete(TopiaEntityEvent event) {
- print(event, "entityDeleted");
- }
-
- public void load(TopiaEntityEvent event) {
- print(event, "entityLoaded");
- }
- };
-
- TopiaTransactionListener transactionListener = new TopiaTransactionListener() {
- public void commit(TopiaTransactionEvent event) {
- log.info("commit " + event.getEntities());
- }
-
- public void rollback(TopiaTransactionEvent event) {
- log.info("rollback " + event.getEntities());
- }
- };
-
- TopiaContextImplementor childContext = (TopiaContextImplementor) context
- .beginTransaction();
- childContext.addTopiaEntityVetoable(entityVetoable);
- childContext.addTopiaEntityListener(entityListener);
- childContext.addTopiaTransactionListener(transactionListener);
- TopiaDAO<Person> persons = childContext.getDAO(Person.class);
-
- Person p = persons.create();
- p.setName("poussin");
- p.setFirstname("benjamin");
- persons.update(p);
- childContext.commitTransaction();
-
- assertEquals("vetoCreateentityCreatedvetoUpdateentityUpdated", state);
- state = "";
-
- p.setFirstname("toto");
- persons.update(p);
- childContext.commitTransaction();
-
- assertEquals("vetoUpdateentityUpdated", state);
- state = "";
-
- TopiaContextImplementor childContext2 = (TopiaContextImplementor) context
- .beginTransaction();
- childContext2.addTopiaEntityVetoable(entityVetoable);
- childContext2.addTopiaEntityListener(entityListener);
- childContext2.addTopiaTransactionListener(transactionListener);
- TopiaDAO<Person> persons2 = childContext2.getDAO(Person.class);
-
- Person pp = persons2.findByTopiaId(p.getTopiaId());
-
- assertEquals(p.getFirstname(), pp.getFirstname());
- assertEquals("vetoLoadentityLoaded", state);
- state = "";
-
- persons2.delete(pp);
- childContext2.commitTransaction();
-
- assertEquals("vetoDeleteentityDeleted", state);
- state = "";
-
- }
-
- public void testPropertyEvent() throws Exception {
- PropertyChangeListener l = new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- System.out.println("entityUpdated " + evt.getSource());
- state = "entityUpdated";
- }
- };
-
- Properties config = getProperties();
-
- TopiaContextImplementor ctx = (TopiaContextImplementor) TopiaContextFactory
- .getContext(config).beginTransaction();
-
- TopiaDAO<Person> personDAO = ctx.getDAO(Person.class);
- Person p = personDAO.create();
- p.addPropertyChangeListener("firstName", l);
-
- p.setFirstname("Arno");
- assertEquals("entityUpdated", state);
- state = "";
-
- p.setName("Arno");
- assertEquals("", state);
- state = "";
- }
-
-} //TopiaContextTest
Added: topia/trunk/topia-persistence/src/test/resources/log4j.properties
===================================================================
--- topia/trunk/topia-persistence/src/test/resources/log4j.properties (rev 0)
+++ topia/trunk/topia-persistence/src/test/resources/log4j.properties 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,9 @@
+# Global logging configuration
+log4j.rootLogger=INFO, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+# package level
+log4j.logger.org.codelutin.topia=INFO
+log4j.logger.org.hibernate=INFO
Property changes on: topia/trunk/topia-soa
___________________________________________________________________
Name: svn:ignore
+ .settings
target
.classpath
.project
Added: topia/trunk/topia-soa/LICENSE.txt
===================================================================
--- topia/trunk/topia-soa/LICENSE.txt (rev 0)
+++ topia/trunk/topia-soa/LICENSE.txt 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Copied: topia/trunk/topia-soa/TODO (from rev 1229, topia/trunk/TODO)
===================================================================
--- topia/trunk/topia-soa/TODO (rev 0)
+++ topia/trunk/topia-soa/TODO 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,13 @@
+Framework WS
+------------
+Le framework Apache CFX est le successeur du framework Codehaus Xfire
+actuellement utilisé.
+Il inclut aussi une partie du code de ObjectWeb Celtix.
+
+Il ne résout pas (encore) le problème de cycle, mais est déjà plus explicite
+sur les messages d'erreurs.
+Il gère aussi plus de protocoles que xfire.
+
+cfx : http://incubator.apache.org/cxf/
+xfire : http://xfire.codehaus.org/
+celtix : http://celtix.objectweb.org/
\ No newline at end of file
Property changes on: topia/trunk/topia-soa/TODO
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Added: topia/trunk/topia-soa/pom.xml
===================================================================
--- topia/trunk/topia-soa/pom.xml (rev 0)
+++ topia/trunk/topia-soa/pom.xml 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.codelutin</groupId>
+ <artifactId>topia</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-soa</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ </dependency>
+
+ <!-- Dependencies for services -->
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-server</artifactId>
+ <version>3.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-client</artifactId>
+ <version>3.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.xfire</groupId>
+ <artifactId>xfire-java5</artifactId>
+ <version>1.2.6</version>
+ <exclusions>
+ <!-- Fix org.apache.ant conflict) -->
+ <exclusion>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- branch 5.1 : ne fonctionne pas en 6+ -->
+ <dependency>
+ <groupId>jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>5.1.10</version>
+ </dependency>
+
+ <!-- Dependencies for class generation -->
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>1.5.3</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>ToPIA - SOA</name>
+ <description>Service Oriented Architecture module</description>
+ <inceptionYear>2004</inceptionYear>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
+ </scm>
+
+</project>
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,784 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+package org.codelutin.topia.generator;
+
+import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.generator.Generator;
+import org.codelutin.generator.ObjectModelGenerator;
+import org.codelutin.generator.Util;
+import org.codelutin.generator.models.object.ObjectModelAssociationClass;
+import org.codelutin.generator.models.object.ObjectModelAttribute;
+import org.codelutin.generator.models.object.ObjectModelClass;
+import org.codelutin.generator.models.object.ObjectModelClassifier;
+import org.codelutin.generator.models.object.ObjectModelInterface;
+import org.codelutin.generator.models.object.ObjectModelOperation;
+import org.codelutin.generator.models.object.ObjectModelParameter;
+import org.codelutin.topia.service.TopiaApplicationServiceAbstract;
+
+/**
+* ServiceAbstractGenerator.java
+*
+* Created: 19 juin 2007
+*
+* @author dupont
+* @version $Revision$
+*
+* Le service abstrait etend TopiaApplicationServiceAbstract et implemente
+* l'interface du service.
+*
+* Genere l'implantation des methodes qui utilisent les methodes des DAO
+* et celles des entites.
+*
+* @see ServiceInterfaceGenerator
+* @see TopiaApplicationServiceAbstract
+*
+* Mise a jour: $Date$
+* par : $Author$
+*/
+public class ServiceAbstractGenerator extends ObjectModelGenerator {
+
+ private static final Log log = LogFactory
+ .getLog(ServiceAbstractGenerator.class);
+
+ public ServiceAbstractGenerator() {
+ super();
+ }
+
+ public ServiceAbstractGenerator(Generator parent) {
+ super(parent);
+ }
+
+ @Override
+ public String getFilenameForInterface(ObjectModelInterface clazz) {
+ return clazz.getQualifiedName().replace('.', File.separatorChar) + "Abstract.java";
+ }
+
+ @Override
+ public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
+
+ if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) {
+ return;
+ }
+
+ // generer l'entete du service abstrait
+ generateInterfaceHeader(output, interfacez);
+
+ // generer les signatures des methodes metier du service
+ generateInterfaceOperations(output, interfacez);
+
+ // generer les methodes etendues en modifiant les signatures pour eviter les doublons (findAllByAddress heritee de Person et Employee)
+ generateInheritedInterfaceOperations(output, interfacez);
+
+ // generer les signatures des methodes metier des entites
+ generateAssociatedClassOperations(output, interfacez);
+
+ // generer les signatures des methodes des entites (getter/setter)
+ generateMethodsGetter(output, interfacez);
+
+/*{} //<%=interfacez.getName()%>
+}*/
+ }
+
+ private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException {
+ String copyright = GeneratorUtil.getCopyright(model);
+ if (GeneratorUtil.notEmpty(copyright)) {
+/*{<%=copyright%>
+}*/
+ }
+/*{package <%=classifier.getPackageName()%>;
+
+import java.util.Arrays;
+import java.util.List;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.service.TopiaApplicationServiceAbstract;
+import org.codelutin.topia.framework.TopiaContextImplementor;}*/
+
+ // <%=clazz.getName()%>DAOAbstract
+ classifier.getInterfaces();
+ // ajouter les imports des interfaces de DAO
+ for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ if(parent.hasStereotype(GeneratorUtil.STEREOTYPE_DAO)){
+ // r�cup�rer la classe de l'object model correspondant � la DAO
+ String className = parent.getQualifiedName().replace("DAO", "");
+ String interfaceName = parent.getQualifiedName()+"Abstract";
+/*{
+import <%=interfaceName%>;
+import <%=className%>;}*/
+ }
+ }
+
+ if (GeneratorUtil.hasDocumentation(classifier)) {
+
+/*{
+/**
+ *
+ * <%=classifier.getDocumentation()%>
+ *)
+}*/
+ }
+/*{
+
+public abstract class <%=classifier.getName()+"Abstract"%> extends TopiaApplicationServiceAbstract implements <%=classifier.getName()%>{ }*/
+ }
+
+ private void generateMethodsGetter(Writer output, ObjectModelClassifier classifier) throws IOException {
+/*{ public String[] getMethods(){
+ return methods;
+ }
+}*/
+ }
+
+ private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
+ for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) {
+ ObjectModelOperation op = (ObjectModelOperation)it.next();
+/*{
+
+ /**
+ * Implementation a la charge du developpeur
+}*/
+ if (GeneratorUtil.hasDocumentation(op)) {
+/*{ * <%=op.getName()%> : <%=op.getDocumentation()%>
+}*/
+ }
+ Collection<ObjectModelParameter> params = (Collection<ObjectModelParameter>)op.getParameters();
+ for(ObjectModelParameter param : params) {
+ if(log.isTraceEnabled()) {log.trace("Param" + param);}
+/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%>
+}*/
+ }
+/*{ *)
+ <%=op.getVisibility()%> abstract <%=op.getReturnType()%> <%=op.getName()%>(}*/
+ String vir = "";
+ for(ObjectModelParameter param : params){
+ if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
+/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/
+ vir = ", ";
+ }
+/*{)}*/
+ Set<String> exceptions = (Set<String>)op.getExceptions();
+ vir = " throws ";
+ for (String exception : exceptions) {
+ if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);}
+/*{<%=vir%><%=exception%>}*/
+ vir = ", ";
+ }
+/*{;
+
+}*/
+ }
+ }
+
+ private void generateInheritedInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
+
+ for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ // pour tous les DAOInterface
+ if(parent.hasStereotype(GeneratorUtil.STEREOTYPE_DAO)){
+
+ // r�cup�rer la classe de l'object model correspondant � la DAO
+ String entityClassName = parent.getQualifiedName().replace("DAO", "");
+ if(getModel().hasClass(entityClassName)){
+ ObjectModelClass clazz = getModel().getClass(entityClassName);
+
+ if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
+ return;
+ }
+/*{
+ /**
+ * Supprime l'entite <%=clazz.getName()%> passee en parametre
+ * @param entity l'entite a supprimer
+ *)
+ public void delete<%=clazz.getName()%>(<%=clazz.getQualifiedName()%> entity) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ dao.delete(entity);
+ }
+
+ /**
+ * Creer l'entite <%=clazz.getName()%> avec les proprietes passees en parametre
+ * @param properties les proprietes de l'entite a creer
+ *)
+ public <%=clazz.getQualifiedName()%> create<%=clazz.getName()%>(Object ... properties) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>) dao.create(properties);
+ return entity;
+ }
+
+ /**
+ * Mise a jour de l'entite <%=clazz.getName()%> passee en parametre
+ * @param entity l'entite a mettre a jour
+ *)
+ public <%=clazz.getQualifiedName()%> update<%=clazz.getName()%>(<%=clazz.getQualifiedName()%> entity) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entit = (<%=clazz.getName()%>) dao.update(entity);
+ return entit;
+ }
+
+ /**
+ * Retourne tous les <%=clazz.getName()%>
+ * @return une liste
+ *)
+ public List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>() throws TopiaException {
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ List<<%=clazz.getName()%>> result = dao.findAll();
+ return result;
+ }
+
+ /**
+ * Retourne le <%=clazz.getName()%> par son TopiaId
+ * @return le <%=clazz.getName()%>
+ *)
+ public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>ByTopiaId(String v) throws TopiaException {
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(v);
+ return entity;
+ }
+}*/
+ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
+ ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+ if (!attr.isNavigable()) {
+ continue;
+ }
+
+ if (!Util.isNMultiplicity(attr)) {
+ generateNoNMultiplicity(output, attr, clazz, false);
+ } else {
+ generateNMultiplicity(output, attr, clazz, false);
+ }
+ }
+
+ if (clazz instanceof ObjectModelAssociationClass) {
+ ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz;
+ Iterator it = assocClass.getParticipantsAttributes().iterator();
+ while (it.hasNext()) {
+ ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+ if (attr != null) {
+ if (!Util.isNMultiplicity(attr)) {
+ generateNoNMultiplicity(output, attr, clazz, true);
+ } else {
+ generateNMultiplicity(output, attr, clazz, true);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected void generateNoNMultiplicity(Writer output, ObjectModelAttribute attr, ObjectModelClass clazz, boolean isAssoc) throws IOException {
+ String propertyName = attr.getName();
+ if (!isAssoc && attr.hasAssociationClass()) {
+ propertyName = GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName()) + "." + propertyName;
+ }
+/*{
+ /**
+ * Retourne le premier element trouve ayant comme valeur pour l'attribut
+ * <%=attr.getName()%> le parametre
+ * @param v la valeur que doit avoir <%=attr.getName()%>
+ * @return un element ou null
+ *)
+ public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = dao.findBy<%=GeneratorUtil.capitalize(attr.getName())%>(v);
+ return entity;
+ };
+
+ /**
+ * Retourne les elements ayant comme valeur pour l'attribut
+ * <%=attr.getName()%> le parametre
+ * @param v la valeur que doit avoir <%=attr.getName()%>
+ * @return une liste
+ *)
+ public List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ List<<%=clazz.getName()%>> entityList = dao.findAllBy<%=GeneratorUtil.capitalize(attr.getName())%>(v);
+ return entityList;
+ };
+}*/
+ if (attr.hasAssociationClass()) {
+/*{
+ /**
+ * Retourne le premier element trouve ayant comme valeur pour l'attribut
+ * <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> le parametre
+ * @param value la valeur que doit avoir <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>
+ * @return un element ou null
+ *)
+ public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getAssociationClass().getName())%>(<%=attr.getAssociationClass().getQualifiedName()%> value) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = dao.findBy<%=GeneratorUtil.capitalize(attr.getName())%>(v);
+ return entity;
+ };
+
+ /**
+ * Retourne les elements ayant comme valeur pour l'attribut
+ * <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> le param�tre
+ * @param value la valeur que doit avoir <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>
+ * @return une liste
+ *)
+ public List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getAssociationClass().getName())%>(<%=attr.getAssociationClass().getQualifiedName()%> value) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ List<<%=clazz.getName()%>> entityList = dao.findAllBy<%=GeneratorUtil.capitalize(attr.getName())%>(v);
+ return entityList;
+ };
+}*/
+ }
+ }
+
+ protected void generateNMultiplicity(Writer output, ObjectModelAttribute attr, ObjectModelClass clazz, boolean isAssoc) throws IOException {
+/*{
+ /**
+ * Retourne le premier element trouve dont l'attribut
+ * <%=attr.getName()%> contient le parametre
+ * @param v la valeur que doit contenir <%=attr.getName()%>
+ * @return un element ou null
+ *)
+ public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>Contains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>) dao.findContainsProperties("<%=GeneratorUtil.toLowerCaseFirstLetter(attr.getName())%>", Arrays.asList(v));
+ return entity;
+ };
+
+ /**
+ * Retourne les elements trouve dont l'attribut
+ * <%=attr.getName()%> contient le parametre
+ * @param v la valeur que doit contenir <%=attr.getName()%>
+ * @return une liste
+ *)
+ public List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>Contains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ List<<%=clazz.getName()%>> entityList = dao.findAllContainsProperties("<%=GeneratorUtil.toLowerCaseFirstLetter(attr.getName())%>", Arrays.asList(v));
+ return entityList;
+ };
+}*/
+ }
+
+
+ private void generateAssociatedClassOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
+ for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ // pour tous les DAOInterface
+ if(parent.hasStereotype(GeneratorUtil.STEREOTYPE_DAO)){
+
+ // r�cup�rer la classe de l'object model correspondant � la DAO
+ String entityClassName = null;
+ entityClassName = parent.getQualifiedName().replace("DAO", "");
+ if(getModel().hasClass(entityClassName)){
+ ObjectModelClass clazz = getModel().getClass(entityClassName);
+ generateFromDAOClass(output, clazz);
+ }
+ }
+ }
+ }
+
+ private void generateFromDAOClass(Writer output, ObjectModelClass clazz) throws IOException {
+ if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
+ return;
+ }
+
+ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
+ ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+ if (!attr.isNavigable()
+ && !hasUnidirectionalRelationOnAbstractType(reverse, model)) {
+ continue;
+ }
+ if (!Util.isNMultiplicity(attr)) {
+ if (!attr.hasAssociationClass()) {
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La valeur de l'attribut <%=attr.getName()%> � positionner.
+ *)
+ public void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.set<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
+ usedContextImpl.commitTransaction();
+ }
+
+}*/
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @return La valeur de l'attribut <%=attr.getName()%>.
+ *)
+ public <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ return entity.get<%=Util.capitalize(attr.getName())%>();
+ }
+
+}*/
+ } else {
+ String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
+ if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+/*{ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La valeur de l'attribut <%=attr.getAssociationClass().getName()%> � positionner.
+ *)
+ public void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.set<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
+ }
+
+ /**
+ * @return La valeur de l'attribut <%=attr.getAssociationClass().getName()%>.
+ *)
+ public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ return entity.get<%=Util.capitalize(assocAttrName)%>();
+ }
+
+}*/
+ }
+ } else { //NMultiplicity
+ if (!attr.hasAssociationClass()) { //M�thodes remplac�es par des add/set sur les classes d'assoc
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> � ajouter.
+ *)
+ public void add<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.add<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
+ }
+
+ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> Les instances de <%=attr.getName()%> � ajouter.
+ *)
+ public void addAll<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.addAll<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
+ }
+
+ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La Collection de <%=attr.getName()%> � positionner.
+ *)
+ public void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.set<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
+ }
+
+ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> � retirer.
+ *)
+ public void remove<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.remove<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>);
+ }
+
+ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * Vide la Collection de <%=attr.getName()%>.
+ *)
+ public void clear<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.clear<%=Util.capitalize(attr.getName())%>();
+ }
+
+}*/
+ } else {
+ String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
+ if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+/*{ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> � ajouter.
+ *)
+ public void add<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.add<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
+ }
+
+ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> Les instances de <%=attr.getAssociationClass().getName()%> � ajouter.
+ *)
+ public void addAll<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.addAll<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
+ }
+
+ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La Collection de <%=attr.getAssociationClass().getName()%> � positionner.
+ *)
+ public void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.set<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
+ }
+
+ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> � retirer.
+ *)
+ public void remove<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.remove<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>);
+ }
+
+ /**
+ * Vide la Collection de <%=attr.getAssociationClass().getName()%>.
+ *)
+ public void clear<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.clear<%=Util.capitalize(assocAttrName)%>();
+ }
+
+}*/
+ }
+
+ if (!attr.hasAssociationClass()) {
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @return La Liste de <%=attr.getName()%>.
+ *)
+ public <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ return entity.get<%=Util.capitalize(attr.getName())%>();
+ }
+
+ /**
+ * @return Le nombre d'�l�ments de la collection <%=attr.getName()%>.
+ *)
+ public int size<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ return entity.size<%=Util.capitalize(attr.getName())%>();
+ }
+
+}*/
+ } else {
+ String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
+ if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+/*{ /**
+ * @return La liste des attributs <%=attr.getAssociationClass().getName()%>.
+ *)
+ public <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ return entity.get<%=Util.capitalize(assocAttrName)%>();
+ }
+
+ /**
+ * @return L'attribut <%=attr.getAssociationClass().getName()%> associ� � la valeur <code>value</code> de l'attribut <%=attr.getName()%>.
+ *)
+ public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> value) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ return entity.get<%=Util.capitalize(assocAttrName)%>((<%=attr.getType()%>) value);
+ }
+
+ /**
+ * @return Le nombre d'�l�ments de la collection <%=attr.getName()%>.
+ *)
+ public int size<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ return entity.size<%=Util.capitalize(assocAttrName)%>();
+ }
+
+}*/
+ }
+ }
+ }
+
+ //M�thodes d'acc�s aux attributs d'une classe d'associations
+ if (clazz instanceof ObjectModelAssociationClass) {
+ ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz;
+ for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) {
+ ObjectModelAttribute attr = (ObjectModelAttribute) i.next();
+ if (attr != null) {
+ String type = attr.getType();
+ String name = attr.getName();
+ generateAssociationAccessors(output, clazz, name, type);
+ if (attr.getReverseAttribute() == null) {
+ type = ((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName();
+ name = attr.getDeclaringElement().getName();
+ generateAssociationAccessors(output, clazz, name, type);
+ }
+ }
+ }
+ }
+
+ generateInterfaceOperationsOfClass(output, clazz);
+
+ }
+
+ private void generateInterfaceOperationsOfClass(Writer output, ObjectModelClassifier classifier) throws IOException {
+ for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) {
+ ObjectModelOperation op = (ObjectModelOperation)it.next();
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(op)) {
+/*{ * <%=op.getName()%> : <%=op.getDocumentation()%>
+}*/
+ }
+ Collection<ObjectModelParameter> params = (Collection<ObjectModelParameter>)op.getParameters();
+ for(ObjectModelParameter param : params) {
+ if(log.isTraceEnabled()) {log.trace("Param" + param);}
+/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%>
+ }*/
+ }
+/*{ *)
+ <%=op.getVisibility()%> <%=op.getReturnType()%> <%=op.getName()%>Of<%=classifier.getName()%>(String topiaId}*/
+ String vir = ",";
+ for(ObjectModelParameter param : params){
+ if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
+/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/
+ }
+/*{)}*/
+ Set<String> exceptions = (Set<String>)op.getExceptions();
+ if(exceptions.isEmpty()){
+/*{throws TopiaException}*/
+ }
+ vir = " throws ";
+ for (String exception : exceptions) {
+ if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);}
+/*{<%=vir%><%=exception%>}*/
+ vir = ", ";
+ }
+/*{{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=classifier.getName()%>DAOAbstract dao = (<%=classifier.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=classifier.getName()%>.class);
+ <%=classifier.getName()%> entity = (<%=classifier.getName()%>)dao.findByTopiaId(topiaId);
+}*/
+ if(!op.getReturnType().toString().equalsIgnoreCase("void")){
+/*{ return }*/
+ }
+/*{ entity.<%=op.getName()%>(}*/
+ vir = "";
+ for(ObjectModelParameter param : params){
+ if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
+/*{<%=vir%><%=param.getName()%>}*/
+ vir = ", ";
+ }
+/*{);
+ }
+}*/
+
+/*{
+
+}*/
+ }
+ }
+
+ private void generateAssociationAccessors(Writer output, ObjectModelClass clazz, String name, String type) throws IOException {
+ /*{ /**
+ * @param value La valeur de l'attribut <%=name%> � positionner.
+ *)
+ public void set<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId, <%=type%> value) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ entity.set<%=Util.capitalize(name)%>( value);
+ }
+
+ /**
+ * @return La valeur de l'attribut <%=name%>.
+ *)
+ public <%=type%> get<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{
+ TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext;
+ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class);
+ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId);
+ return entity.get<%=Util.capitalize(name)%>();
+ }
+
+ }*/
+ }
+
+} //ServiceAbstractGenerator
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,137 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.generator;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.generator.Generator;
+import org.codelutin.generator.ObjectModelGenerator;
+import org.codelutin.generator.models.object.ObjectModelClass;
+import org.codelutin.generator.models.object.ObjectModelClassifier;
+import org.codelutin.generator.models.object.ObjectModelInterface;
+import org.codelutin.generator.models.object.ObjectModelOperation;
+import org.codelutin.generator.models.object.ObjectModelParameter;
+import org.codelutin.topia.service.TopiaApplicationServiceAbstract;
+
+/**
+* ServiceImplGenerator.java
+*
+* Created: 19 juin 2007
+*
+* @author ndupont
+* @version $Revision$
+*
+* Genere l'entete du service implante.
+*
+* L'implementation du service herite du service abstrait et donc des methodes qui
+* appellent celles des DAOs et celles des entites.
+*
+* L'implementation des methodes metiers est a la charge du developpeur.
+*
+* @see ServiceInterfaceGenerator
+* @see TopiaApplicationServiceAbstract
+*
+* Mise a jour: $Date$
+* par : $Author$
+*/
+public class ServiceImplGenerator extends ObjectModelGenerator {
+
+ /**
+ * Logger for this class
+ */
+ private static final Log log = LogFactory
+ .getLog(ServiceImplGenerator.class);
+
+ public ServiceImplGenerator() {
+ super();
+ }
+
+ public ServiceImplGenerator(Generator parent) {
+ super(parent);
+ }
+
+ @Override
+ public String getFilenameForInterface(ObjectModelInterface interfacez) {
+ return interfacez.getQualifiedName().replace('.', File.separatorChar) + "Impl.java";
+ }
+
+ @Override
+ public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
+
+ if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) {
+ return;
+ }
+
+ // pas de génération s'il y a des méthodes métier du service à implémenter
+ if(interfacez.getOperations().size()>0){
+ return;
+ }
+
+ // pas de génération s'il y a des méthodes métiers des entités à implémenter
+ for (Iterator i=interfacez.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ // pour tous les DAOInterface
+ if(parent.hasStereotype(GeneratorUtil.STEREOTYPE_DAO)){
+ // récupérer la classe de l'object model correspondant à la DAO
+ String entityClassName = null;
+ entityClassName = parent.getQualifiedName().replace("DAO", "");
+ if(getModel().hasClass(entityClassName)){
+ ObjectModelClass clazz = getModel().getClass(entityClassName);
+ if(clazz.getOperations().size()>0)
+ return;
+ }
+ }
+ }
+
+ // générer l'entête du service
+ generateInterfaceHeader(output, interfacez);
+
+/*{} //<%=interfacez.getName()%>
+}*/
+ }
+
+ private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException {
+ String copyright = GeneratorUtil.getCopyright(model);
+ if (GeneratorUtil.notEmpty(copyright)) {
+/*{<%=copyright%>
+}*/
+ }
+/*{package <%=classifier.getPackageName()%>;}*/
+
+ if (GeneratorUtil.hasDocumentation(classifier)) {
+
+/*{
+/**
+ *
+ * <%=classifier.getDocumentation()%>
+ *)
+}*/
+ }
+/*{
+
+public class <%=classifier.getName()+"Impl"%> extends <%=classifier.getName()+"Abstract"%>{ }*/
+ }
+
+} //ServiceImplGenerator
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,689 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.generator;
+
+import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.generator.Generator;
+import org.codelutin.generator.ObjectModelGenerator;
+import org.codelutin.generator.Util;
+import org.codelutin.generator.models.object.ObjectModelAssociationClass;
+import org.codelutin.generator.models.object.ObjectModelAttribute;
+import org.codelutin.generator.models.object.ObjectModelClass;
+import org.codelutin.generator.models.object.ObjectModelClassifier;
+import org.codelutin.generator.models.object.ObjectModelInterface;
+import org.codelutin.generator.models.object.ObjectModelOperation;
+import org.codelutin.generator.models.object.ObjectModelParameter;
+import org.codelutin.topia.service.TopiaApplicationService;
+
+/**
+* ServiceInterfaceGenerator.java
+*
+* Created: 14 juin 2007
+*
+* @author ndupont
+* @version $Revision$
+*
+* L'interface du service etend TopiaApplicationService
+*
+* Genere les interfaces des services, genere les signatures de toutes les methodes des
+* DAO et des entites utilises. Les signatures de methodes sont modifiees pour eviter les
+* doublons.
+*
+* Par exemple :
+*
+* findAllByAddress d'un PersonDAO et d'un EmployeeDAO deviennent respectivement
+* findAllPersonByAddress et findAllEmployeeByAddress.
+*
+* getTask d'entites Cost et Bill deviennent respectivement getTaskOfBill, getTaskOfCost
+*
+* @see TopiaApplicationService
+*
+* Mise a jour: $Date$
+* par : $Author$
+*/
+public class ServiceInterfaceGenerator extends ObjectModelGenerator {
+
+ /**
+ * Logger for this class
+ */
+ private static final Log log = LogFactory
+ .getLog(ServiceInterfaceGenerator.class);
+
+ private static final String DAO = "dao";
+
+ // methodes du service <signature methode>
+ private List<String> methods = new ArrayList<String>();
+
+ public ServiceInterfaceGenerator() {
+ super();
+ }
+
+ public ServiceInterfaceGenerator(Generator parent) {
+ super(parent);
+ }
+
+ @Override
+ public String getFilenameForInterface(ObjectModelInterface interfacez) {
+ return interfacez.getQualifiedName().replace('.', File.separatorChar) + ".java";
+ }
+
+ @Override
+ public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
+
+ if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) {
+ return;
+ }
+
+ // génèrer l'entête de l'interface du service
+ generateInterfaceHeader(output, interfacez);
+
+ // génèrer les signatures des méthodes métiers du service
+ generateInterfaceOperations(output, interfacez);
+
+ // génèrer les signatures des méthodes des DAOs
+ generateInheritedInterfaceOperations(output, interfacez);
+
+ // génèrer les signatures des méthodes des entités (getter/setter)
+ generateMethodsGetter(output, interfacez);
+
+ // génèrer les signatures des méthodes métier des entités (getter/setter)
+ generateAssociatedClassOperations(output, interfacez);
+
+/*{
+ // methodes du service
+ public String[] methods = {
+}*/
+ String vir=" ";
+ for(String m : methods){
+/*{ <%=vir%>"<%=m%>"
+}*/
+ vir=", ";
+ }
+/*{ }; }*/
+/*{
+ } //<%=interfacez.getName()%>
+}*/
+ }
+
+ private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException {
+ String copyright = GeneratorUtil.getCopyright(model);
+ if (GeneratorUtil.notEmpty(copyright)) {
+/*{<%=copyright%>
+}*/
+ }
+/*{package <%=classifier.getPackageName()%>;
+
+import java.util.List;
+import org.codelutin.topia.TopiaException;
+
+}*/
+ if (GeneratorUtil.hasDocumentation(classifier)) {
+/*{
+/**
+ * <%=classifier.getDocumentation()%>
+ *)
+}*/
+ }
+/*{public interface <%=classifier.getName()%> extends }*/
+ String extendClass = "";
+ for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ // pas pour les interfaces de DAO
+ if(!parent.hasStereotype(DAO)){
+ extendClass += parent.getQualifiedName();
+ extendClass += ", ";
+ }
+ }
+
+ if (classifier instanceof ObjectModelClass) {
+ ObjectModelClass clazz = (ObjectModelClass)classifier;
+ for (Iterator i=clazz.getSuperclasses().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ if (parent.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) {
+ extendClass += parent.getQualifiedName();
+ }
+ extendClass += ", ";
+ }
+ }
+
+/*{<%=extendClass%>org.codelutin.topia.service.TopiaApplicationService {
+
+}*/
+ }
+
+ private void generateMethodsGetter(Writer output, ObjectModelClassifier classifier) throws IOException {
+/*{ public abstract String[] getMethods();
+
+ // =====> methodes utilisant celles des entites <====
+}*/
+ }
+
+
+ private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
+ for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) {
+ ObjectModelOperation op = (ObjectModelOperation)it.next();
+
+ String method = op.getReturnType()+ " "+op.getName()+"(";
+/*{
+ /**
+ * Methode metier
+}*/
+ if (GeneratorUtil.hasDocumentation(op)) {
+/*{ * <%=op.getName()%> : <%=op.getDocumentation()%>
+}*/
+ }
+ Collection<ObjectModelParameter> params = (Collection<ObjectModelParameter>)op.getParameters();
+ for(ObjectModelParameter param : params) {
+ if(log.isTraceEnabled()) {log.trace("Param" + param);}
+/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%>
+}*/
+ }
+/*{ *)
+ <%=op.getVisibility()%> <%=op.getReturnType()%> <%=op.getName()%>(}*/
+ String vir = "";
+ for(ObjectModelParameter param : params){
+ method += " " + param.getType()+" "+param.getName();
+ if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
+/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/
+ vir = ", ";
+ }
+/*{)}*/
+ Set<String> exceptions = (Set<String>)op.getExceptions();
+ vir = " throws ";
+ for (String exception : exceptions) {
+ if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);}
+/*{<%=vir%><%=exception%>}*/
+ vir = ", ";
+ }
+/*{;
+
+}*/
+ // ajout des methodes
+ methods.add(method+")");
+ }
+ }
+
+ private void generateInheritedInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
+/*{
+ // =====> methodes utilisant celles des daos <====
+}*/
+ for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ // pour tous les DAOInterface
+ if(parent.hasStereotype(DAO)){
+
+ // récupèrer la classe de l'object model correspondant à la DAO
+ String entityClassName = null;
+ entityClassName = parent.getQualifiedName().replace("DAO", "");
+ if(getModel().hasClass(entityClassName)){
+ ObjectModelClass clazz = getModel().getClass(entityClassName);
+
+ if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
+ return;
+ }
+
+ // ajouter les methodes à la liste
+ methods.add("void delete"+clazz.getName()+"("+clazz.getName()+" entity)");
+ methods.add(clazz.getName()+" create"+clazz.getName()+"(Object ... properties)");
+ methods.add(clazz.getName()+" update"+clazz.getName()+"("+clazz.getName()+")");
+ methods.add("List<"+clazz.getName()+"> findAll"+clazz.getName()+"()");
+ methods.add(clazz.getName()+" find"+clazz.getName()+"ByTopiaId(String v)");
+
+/*{
+ /**
+ * Supprime l'entite <%=clazz.getName()%> passee en parametre
+ * @param entity l'entite a supprimer
+ *)
+ public abstract void delete<%=clazz.getName()%>(<%=clazz.getQualifiedName()%> entity) throws TopiaException;
+
+ /**
+ * Creer l'entite <%=clazz.getName()%> avec les proprietes passees en parametre
+ * @param entity l'entite a mettre a jour
+ *)
+ public abstract <%=clazz.getQualifiedName()%> create<%=clazz.getName()%>(Object ... properties) throws TopiaException;
+
+ /**
+ * Mise a jour de l'entite <%=clazz.getName()%> passee en parametre
+ * @param properties les proprietes de l'entite a creer
+ *)
+ public abstract <%=clazz.getQualifiedName()%> update<%=clazz.getName()%>(<%=clazz.getQualifiedName()%> entity) throws TopiaException;
+
+ /**
+ * Retourne tous les <%=clazz.getName()%>
+ * @return une liste
+ *)
+ public abstract List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>() throws TopiaException;
+
+ /**
+ * Retourne le <%=clazz.getName()%> par son TopiaId
+ * @return le <%=clazz.getName()%>
+ *)
+ public abstract <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>ByTopiaId(String v) throws TopiaException;
+}*/
+ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
+ ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+ if (!attr.isNavigable()) {
+ continue;
+ }
+
+ if (!Util.isNMultiplicity(attr)) {
+ generateNoNMultiplicity(output, attr, clazz, false);
+ } else {
+ generateNMultiplicity(output, attr, clazz, false);
+ }
+ }
+
+ if (clazz instanceof ObjectModelAssociationClass) {
+ ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz;
+ Iterator it = assocClass.getParticipantsAttributes().iterator();
+ while (it.hasNext()) {
+ ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+ if (attr != null) {
+ if (!Util.isNMultiplicity(attr)) {
+ generateNoNMultiplicity(output, attr, clazz, true);
+ } else {
+ generateNMultiplicity(output, attr, clazz, true);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected void generateNoNMultiplicity(Writer output, ObjectModelAttribute attr, ObjectModelClass clazz, boolean isAssoc) throws IOException {
+ String propertyName = attr.getName();
+ if (!isAssoc && attr.hasAssociationClass()) {
+ propertyName = GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName()) + "." + propertyName;
+ }
+
+ // ajouter les methodes à la liste
+ methods.add(clazz.getName()+" find"+clazz.getName()+"By"+GeneratorUtil.capitalize(attr.getName())+"("+attr.getType()+" v)");
+ methods.add("List<"+clazz.getName()+"> findAll"+clazz.getName()+"By"+GeneratorUtil.capitalize(attr.getName())+"("+attr.getType()+" v)");
+/*{
+ /**
+ * Retourne le premier element trouve ayant comme valeur pour l'attribut
+ * <%=attr.getName()%> le parametre
+ * @param v la valeur que doit avoir <%=attr.getName()%>
+ * @return un element ou null
+ *)
+ public abstract <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException;
+ /**
+ * Retourne les éléments ayant comme valeur pour l'attribut
+ * <%=attr.getName()%> le paramêtre
+ * @param v la valeur que doit avoir <%=attr.getName()%>
+ * @return une liste
+ *)
+ public abstract List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> v) throws TopiaException;
+}*/
+ if (attr.hasAssociationClass()) {
+ methods.add(clazz.getName() +" find"+clazz.getName()+"By"+GeneratorUtil.capitalize(attr.getAssociationClass().getName())+"("+attr.getAssociationClass().getQualifiedName()+" value)");
+ methods.add("List<"+clazz.getName()+"> findAll"+clazz.getName()+"By"+GeneratorUtil.capitalize(attr.getAssociationClass().getName())+"("+attr.getAssociationClass().getQualifiedName()+" value)");
+/*{
+ /**
+ * Retourne le premier element trouve ayant comme valeur pour l'attribut
+ * <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> le parametre
+ * @param value la valeur que doit avoir <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>
+ * @return un element ou null
+ *)
+ public abstract <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getAssociationClass().getName())%>(<%=attr.getAssociationClass().getQualifiedName()%> value) throws TopiaException;
+ /**
+ * Retourne les éléments ayant comme valeur pour l'attribut
+ * <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> le paramêtre
+ * @param value la valeur que doit avoir <%=GeneratorUtil.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>
+ * @return une liste
+ *)
+ public abstract List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>By<%=GeneratorUtil.capitalize(attr.getAssociationClass().getName())%>(<%=attr.getAssociationClass().getQualifiedName()%> value) throws TopiaException;
+}*/
+ }
+ }
+
+ protected void generateNMultiplicity(Writer output, ObjectModelAttribute attr, ObjectModelClass clazz, boolean isAssoc) throws IOException {
+ methods.add(clazz.getName() + " find"+clazz.getName()+"Contains"+GeneratorUtil.capitalize(attr.getName())+"("+attr.getType()+" ... v)");
+ methods.add("List<"+clazz.getName()+"> findAll"+clazz.getName()+"Contains"+GeneratorUtil.capitalize(attr.getName())+"("+attr.getType()+" ... v)");
+/*{
+ /**
+ * Retourne le premier element trouve dont l'attribut
+ * <%=attr.getName()%> contient le parametre
+ * @param v la valeur que doit contenir <%=attr.getName()%>
+ * @return un element ou null
+ *)
+ public abstract <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>Contains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) throws TopiaException;
+ /**
+ * Retourne les elements trouve dont l'attribut
+ * <%=attr.getName()%> contient le parametre
+ * @param v la valeur que doit contenir <%=attr.getName()%>
+ * @return une liste
+ *)
+ public abstract List<<%=clazz.getQualifiedName()%>> findAll<%=clazz.getName()%>Contains<%=GeneratorUtil.capitalize(attr.getName())%>(<%=attr.getType()%> ... v) throws TopiaException;
+}*/
+ }
+
+ private void generateAssociatedClassOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
+ for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parent = (ObjectModelClassifier)i.next();
+ // pour tous les DAOInterface
+ if(parent.hasStereotype(DAO)){
+ // r�cup�rer la classe de l'object model correspondant à la DAO
+ String entityClassName = null;
+ entityClassName = parent.getQualifiedName().replace("DAO", "");
+ if(getModel().hasClass(entityClassName)){
+ ObjectModelClass clazz = getModel().getClass(entityClassName);
+ generateFromDAOClass(output, clazz);
+
+ }
+ }
+ }
+ }
+
+ private void generateFromDAOClass(Writer output, ObjectModelClass clazz) throws IOException {
+ if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) {
+ return;
+ }
+
+ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) {
+ ObjectModelAttribute attr = (ObjectModelAttribute)it.next();
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+ if (!attr.isNavigable()
+ && !hasUnidirectionalRelationOnAbstractType(reverse, model)) {
+ continue;
+ }
+ if (!Util.isNMultiplicity(attr)) {
+ if (!attr.hasAssociationClass()) {
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+ methods.add("void set"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+attr.getType()+ " "+Util.toLowerCaseFirstLetter(attr.getName())+")");
+
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La valeur de l'attribut <%=attr.getName()%> à positionner.
+ *)
+ public abstract void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
+
+}*/
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+ methods.add(attr.getType()+" get"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId)");
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @return La valeur de l'attribut <%=attr.getName()%>.
+ *)
+ public abstract <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+}*/
+ } else {
+ String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
+ if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+ methods.add("void set"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+attr.getAssociationClass().getName()+" "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
+ methods.add(attr.getAssociationClass().getName()+" get"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId)");
+
+/*{ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La valeur de l'attribut <%=attr.getAssociationClass().getName()%> � positionner.
+ *)
+ public abstract void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
+
+ /**
+ * @return La valeur de l'attribut <%=attr.getAssociationClass().getName()%>.
+ *)
+ public abstract <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+}*/
+ }
+ } else { //NMultiplicity
+ if (!attr.hasAssociationClass()) { //Méthodes remplacées par des add/set sur les classes d'assoc
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+ methods.add("void add"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+attr.getType()+" "+Util.toLowerCaseFirstLetter(attr.getName())+")");
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> à ajouter.
+ *)
+ public abstract void add<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
+
+ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+ methods.add("void addAll"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+(attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getType()+"> "+Util.toLowerCaseFirstLetter(attr.getName())+")");;
+
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> Les instances de <%=attr.getName()%> à ajouter.
+ *)
+ public abstract void addAll<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
+
+ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+ methods.add("void set"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+ (attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getType()+"> "+Util.toLowerCaseFirstLetter(attr.getName())+")");
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La Collection de <%=attr.getName()%> à positionner.
+ *)
+ public abstract void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
+
+ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+ methods.add("void remove"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId, "+attr.getType()+ " "+Util.toLowerCaseFirstLetter(attr.getName())+")");
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> à retirer.
+ *)
+ public abstract void remove<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException;
+
+ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+ methods.add("void clear"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId)");
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * Vide la Collection de <%=attr.getName()%>.
+ *)
+ public abstract void clear<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+}*/
+ } else {
+ String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
+ if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+ methods.add("void add"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+attr.getAssociationClass().getName()+" "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
+ methods.add("void addAll"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+(attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getAssociationClass().getName()+"> "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
+ methods.add("void set"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+(attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getAssociationClass().getName()+"> "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
+ methods.add("void remove"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+attr.getAssociationClass().getName()+" "+Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())+")");
+ methods.add("void clear"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId)");
+/*{ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> à ajouter.
+ *)
+ public abstract void add<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
+
+ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> Les instances de <%=attr.getAssociationClass().getName()%> à ajouter.
+ *)
+ public abstract void addAll<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
+
+ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La Collection de <%=attr.getAssociationClass().getName()%> à positionner.
+ *)
+ public abstract void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
+
+ /**
+ * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> à retirer.
+ *)
+ public abstract void remove<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException;
+
+ /**
+ * Vide la Collection de <%=attr.getAssociationClass().getName()%>.
+ *)
+ public abstract void clear<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+}*/
+ }
+
+ if (!attr.hasAssociationClass()) {
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(attr)) {
+ methods.add((attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getType()+"> get"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId)");
+ methods.add("int size"+Util.capitalize(attr.getName())+"Of"+clazz.getName()+"(String topiaId)");
+
+/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%>
+}*/
+ }
+/*{ * @return La Liste de <%=attr.getName()%>.
+ *)
+ public abstract <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+ /**
+ * @return Le nombre d'éléments de la collection <%=attr.getName()%>.
+ *)
+ public abstract int size<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+}*/
+ } else {
+ String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
+ if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); }
+ methods.add((attr.isOrdered()?"java.util.List":"java.util.Collection")+"<"+attr.getAssociationClass().getName()+"> get"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"Of"+clazz.getName()+"(String topiaId)");
+ methods.add(attr.getAssociationClass().getName()+" get"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId, "+attr.getType()+" value)");
+ methods.add("int size"+Util.capitalize(assocAttrName)+"Of"+clazz.getName()+"(String topiaId)");
+/*{ /**
+ * @return La liste des attributs <%=attr.getAssociationClass().getName()%>.
+ *)
+ public abstract <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+ /**
+ * @return L'attribut <%=attr.getAssociationClass().getName()%> associé à la valeur <code>value</code> de l'attribut <%=attr.getName()%>.
+ *)
+ public abstract <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> value) throws TopiaException;
+
+ /**
+ * @return Le nombre d'éléments de la collection <%=attr.getName()%>.
+ *)
+ public abstract int size<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+}*/
+ }
+ }
+ }
+
+ //Méthodes d'accès aux attributs d'une classe d'associations
+ if (clazz instanceof ObjectModelAssociationClass) {
+ ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
+ for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) {
+ ObjectModelAttribute attr = (ObjectModelAttribute) i.next();
+ if (attr != null) {
+ String type = attr.getType();
+ String name = attr.getName();
+ generateAssociationAccessors(output, clazz, name, type);
+ if (attr.getReverseAttribute() == null) {
+ type = ((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName();
+ name = attr.getDeclaringElement().getName();
+ generateAssociationAccessors(output, clazz, name, type);
+ }
+ }
+ }
+ }
+
+ generateInterfaceOperationsOfClass(output, clazz);
+
+ }
+
+ private void generateInterfaceOperationsOfClass(Writer output, ObjectModelClassifier classifier) throws IOException {
+ for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) {
+ ObjectModelOperation op = (ObjectModelOperation)it.next();
+ String method = op.getReturnType()+ " "+op.getName()+"(";
+/*{ /**
+}*/
+ if (GeneratorUtil.hasDocumentation(op)) {
+/*{ * <%=op.getName()%> : <%=op.getDocumentation()%>
+}*/
+ }
+ Collection<ObjectModelParameter> params = (Collection<ObjectModelParameter>)op.getParameters();
+ for(ObjectModelParameter param : params) {
+ if(log.isTraceEnabled()) {log.trace("Param" + param);}
+/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%>
+ }*/
+ }
+/*{ *)
+ <%=op.getVisibility()%> abstract <%=op.getReturnType()%> <%=op.getName()%>Of<%=classifier.getName()%>(String topiaId}*/
+ if(params.size()>0){
+/*{, }*/
+ }
+ String vir = "";
+ for(ObjectModelParameter param : params){
+ if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);}
+ method += " " + param.getType()+" "+param.getName();
+/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/
+ vir = ", ";
+ }
+/*{)}*/
+ Set<String> exceptions = (Set<String>)op.getExceptions();
+ if(exceptions.isEmpty()){
+/*{throws TopiaException}*/
+ }
+ vir = " throws ";
+ for (String exception : exceptions) {
+ if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);}
+/*{<%=vir%><%=exception%>}*/
+ vir = ", ";
+ }
+/*{;
+
+}*/
+ methods.add(method);
+ }
+ }
+
+ private void generateAssociationAccessors(Writer output, ObjectModelClass clazz, String name, String type) throws IOException {
+ methods.add("=> "+"void set"+Util.capitalize(name)+"Of"+clazz.getName()+"(String topiaId, "+type+" value)");
+ methods.add("=> "+type+" get"+Util.capitalize(name)+"Of"+clazz.getName()+"(String topiaId)");
+/*{ /**
+ * @param value La valeur de l'attribut <%=name%> à positionner.
+ *)
+ public abstract void set<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId, <%=type%> value) throws TopiaException;
+
+ /**
+ * @return La valeur de l'attribut <%=name%>.
+ *)
+ public abstract <%=type%> get<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException;
+
+}*/
+ }
+
+} //ServiceInterfaceGenerator
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/Protocol.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/Protocol.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/Protocol.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/Protocol.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,37 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.service;
+
+/**
+ * Protocole.
+ *
+ * Liste des protocoles de web services supportes
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$ By : $Author$
+ */
+public enum Protocol {
+ /** RMI */
+ RMI,
+ /** XML-RPC */
+ XML_RPC,
+ /** SOAP */
+ SOAP
+}
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/Protocol.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,50 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.service;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaContext;
+
+/**
+ * TopiaApplicationService.java
+ *
+ * Represente un service Topia.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$ By : $Author$
+ */
+public interface TopiaApplicationService {
+
+ /** Common logging) */
+ final Log log = LogFactory.getLog(TopiaApplicationService.class);
+
+ /**
+ * Initialise le service
+ * @param context
+ */
+ public void init(TopiaContext context);
+
+ /**
+ * Detruit le service
+ * @param context
+ */
+ public void destroy();
+}
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationService.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,62 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.service;
+
+import org.codelutin.topia.TopiaContext;
+
+/**
+ * TopiaAplicationServiceAbstract.java
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$ By : $Author$
+ */
+public class TopiaApplicationServiceAbstract implements TopiaApplicationService {
+
+ /**
+ * TopiaContext du service
+ */
+ protected TopiaContext topiaContext;
+
+ /**
+ * Initialise le service avec un context
+ *
+ * @param context
+ */
+ public void init(TopiaContext context) {
+ this.topiaContext = context;
+ }
+
+ /**
+ * Detruit le service
+ *
+ * @param context
+ */
+ public void destroy() {
+ }
+
+ /**
+ *
+ * @return le context du service
+ */
+ public TopiaContext getTopiaContext() {
+ return topiaContext;
+ }
+
+}
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceAbstract.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,402 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/**
+ *
+ */
+package org.codelutin.topia.service;
+
+import java.lang.reflect.Proxy;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.TopiaNotFoundException;
+import org.codelutin.topia.framework.TopiaUtil;
+import org.codelutin.topia.service.clients.RMIProxy;
+import org.codelutin.topia.service.clients.SOAPProxy;
+import org.codelutin.topia.service.clients.XMLRPCProxy;
+
+/**
+ * TopiaServiceFactory.java
+ *
+ * Classe utilisee pour charger les services.
+ *
+ * Deux utilisations possibles :
+ * <li>client: pour avoir une interface sur un service local ou distant
+ * <li>serveur: pour avoir un service local au serveur
+ *
+ * Sert aussi au serveur pour declarer des services
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$ By : $Author$
+ */
+public class TopiaApplicationServiceFactory {
+
+ /** Fichier de configuration par defaut */
+ static final String DEFAULT_CONFIG_PROPERTIES = "TopiaContextImpl.properties";
+
+ /** Nom de la propriete de definition des services utilises */
+ static final String TOPIA_APPLICATION_SERVICE_BEGIN = "topia.application.service.";
+
+ /** Nom de la propriete de definition des services fournit */
+ static final String TOPIA_APPLICATION_PROVIDE_BEGIN = "topia.application.provide.";
+
+ /** Nom de la propriete de definition des ports suivant les protocoles */
+ static final String TOPIA_APPLICATION_SERVER_PORT_BEGIN = "topia.application.server.port.";
+
+ /**
+ * Nom du dossier ou sont generer certains fichiers (doit etre dans le
+ * classpath )
+ */
+ public static String TOPIA_GENERATION_DIRECTORY = "topiagen";
+
+ /** Fichier de configuration */
+ private static Properties config;
+
+ /** Dispatcher (servers) */
+ private static final TopiaServiceProvider mainDispatcher = new TopiaServiceProvider();
+
+ /**
+ * Stockage des services deja instancies
+ */
+ private static Map<Class<? extends TopiaApplicationService>, TopiaApplicationService> mapServiceCache = new HashMap<Class<? extends TopiaApplicationService>, TopiaApplicationService>();
+
+ /** Logger (common logging) */
+ private static final Log log = LogFactory
+ .getLog(TopiaApplicationServiceFactory.class);
+
+ private static TopiaContext defaultServiceContext;
+
+ /**
+ * Retourne la configuration. Charge le fichier s'il n'a pas deja ete
+ * charge.
+ *
+ * @throws TopiaNotFoundException
+ * si le fichier de configuration ne peut pas etre charge
+ */
+ static Properties getConfiguration() throws TopiaNotFoundException {
+ if (config == null) {
+ config = TopiaUtil.getProperties(DEFAULT_CONFIG_PROPERTIES);
+ }
+ return config;
+ }
+
+ /**
+ * Charge et lance tous les services contenus dans le fichier de
+ * configuration
+ *
+ * @param config
+ * les proprietes du fichier de configuration
+ * @param context
+ * le contexte pere des contextes fournis aux services
+ * @throws TopiaException
+ */
+ @SuppressWarnings("unchecked")
+ public static void loadServices(Properties config, TopiaContext context)
+ throws TopiaException {
+ if (context == null)
+ throw new NullPointerException(
+ "I need a valid TopiaContext to initialise application services");
+ defaultServiceContext = context;
+ // lecture du fichier de configuration
+ if (config == null) {
+ try {
+ config = getConfiguration();
+ } catch (TopiaNotFoundException e) {
+ throw new TopiaNotFoundException(
+ "Can't find configuration file "
+ + DEFAULT_CONFIG_PROPERTIES);
+ }
+ }
+ // pour chaque service applicatif
+ Set<Object> keySet = config.keySet();
+ for (Object key : keySet) {
+
+ if (key.toString().startsWith(TOPIA_APPLICATION_PROVIDE_BEGIN)) {
+
+ // convertir l'URI pour recuperer les parametres
+ String protos = config.getProperty(key.toString());
+ String serviceClassName = ((String) key).replace(
+ TOPIA_APPLICATION_PROVIDE_BEGIN, "");
+
+ // lance pour chaque protocole
+ String[] tabProtos = protos.split(",");
+
+ for (String proto : tabProtos) {
+ // instancier puis lancer le service
+ Protocol protocol = Protocol.valueOf(proto.trim().replace(
+ '-', '_').toUpperCase());
+
+ // read and set server port
+ if (config.get(TOPIA_APPLICATION_SERVER_PORT_BEGIN + proto) != null) {
+ Integer port = null;
+ try {
+ port = Integer.valueOf((String) config
+ .get(TOPIA_APPLICATION_SERVER_PORT_BEGIN
+ + proto));
+ } catch (NumberFormatException e) {
+ log.warn("Can't convert " + proto
+ + " server port to integer", e);
+ }
+ mainDispatcher.setProtocolPort(protocol, port);
+ }
+
+ Class serviceInterface = null;
+ Class serviceImplement = null;
+ try {
+ serviceInterface = Class.forName(serviceClassName);
+ serviceImplement = Class.forName(serviceClassName
+ + "Impl");
+
+ try {
+ Object newInstance = serviceImplement.newInstance();
+ TopiaApplicationService service = (TopiaApplicationService) newInstance;
+ TopiaContext serviceContext = context
+ .beginTransaction();
+ service.init(serviceContext);
+ addService(serviceInterface, service, protocol);
+ } catch (InstantiationException e) {
+ throw new TopiaException(
+ "Can't instanciate service class "
+ + serviceImplement);
+ } catch (IllegalAccessException e) {
+ throw new TopiaException(
+ "Can't access to service class "
+ + serviceImplement);
+ }
+ log.info("service " + serviceClassName
+ + " added for protocol " + proto);
+ } catch (ClassNotFoundException e) {
+ log.error("Class not found for " + serviceClassName, e);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Fournit une interface sur un service en l'implementant comme definit dans
+ * la configuration.
+ *
+ * Configuration (TopiaApplicationServices.properties par defaut) :
+ * topia.application.service.fqn=local://fqnImpl/#new
+ * topia.application.service.fqn=local://fqnImpl
+ * topia.application.service.fqn=rmi://127.0.0.1:1099
+ * topia.application.service.fqn=xmlrpc://127.0.0.1:9090 ...
+ *
+ * @param <E>
+ * l'interface doit etendre TopiaApplicationService
+ * @param serviceclazz
+ * l'interface du service
+ * @return l'implementation du service ou <tt>null</tt> si le service ne
+ * peut etre charge
+ * @see TopiaApplicationService
+ * @throws TopiaNotFoundException
+ * si le fichier de configuration n'existe pas
+ * @throws TopiaException
+ * si le service ne peut pas etre charge
+ */
+ @SuppressWarnings("unchecked")
+ public static <E extends TopiaApplicationService> E getService(
+ Class<E> serviceclazz) throws TopiaNotFoundException,
+ TopiaException {
+
+ // l'implementation a retourner
+ E serviceimpl = (E) mapServiceCache.get(serviceclazz);
+
+ // s'il etait dans le cache on le retourne directement
+ // dans le cas "#new" il n'est jamais dans le cache, donc recree
+ if (serviceimpl != null) {
+ return serviceimpl;
+ }
+
+ // configuration
+ Properties config = getConfiguration();
+
+ // recherche du service
+ String serviceUrl = (String) config.get(TOPIA_APPLICATION_SERVICE_BEGIN
+ + serviceclazz.getCanonicalName());
+ if (serviceUrl == null) {
+ log.error("Properties '" + TOPIA_APPLICATION_SERVICE_BEGIN
+ + serviceclazz.getCanonicalName()
+ + "' not found in configuration");
+ throw new TopiaNotFoundException("Service '"
+ + serviceclazz.getCanonicalName()
+ + "' not definided in configuration");
+ } else {
+
+ try {
+ // conversion de l'URI
+ URI uriService = new URI(serviceUrl);
+ String protocole = uriService.getScheme();
+ String host = uriService.getHost();
+ String fragment = uriService.getFragment();
+
+ // ensuite ca depend si le service est local ou distant
+ // local = local://fqn
+ // sinon, c'est distant
+ if ("local".equalsIgnoreCase(protocole)) {
+
+ String fqClassImpl = host;
+ log.debug("Trying to load local service : " + fqClassImpl);
+
+ // instanciation dynamique
+ try {
+ Class<E> resultClass = (Class<E>) Class
+ .forName(fqClassImpl);
+ serviceimpl = resultClass.newInstance();
+ serviceimpl.init(defaultServiceContext
+ .beginTransaction());
+
+ // mise en cache
+ // sauf dans le cas ou il y a un "#new" a la fin de
+ // l'uri
+ if (!"new".equalsIgnoreCase(fragment)) {
+ mapServiceCache.put(serviceclazz, serviceimpl);
+ }
+ } catch (ClassNotFoundException eee) {
+ throw new TopiaException("Can't find service class "
+ + fqClassImpl);
+ } catch (InstantiationException eee) {
+ throw new TopiaException(
+ "Can't instanciate service class "
+ + fqClassImpl);
+ } catch (IllegalAccessException eee) {
+ throw new TopiaException("Can't access service class "
+ + fqClassImpl);
+ }
+ }
+ // prefix non local => proxy
+ else {
+ log.debug("Trying to get remote service : " + serviceUrl);
+
+ TopiaProxy tProxy = getProxyForURI(uriService);
+
+ if (tProxy == null) {
+ log.debug("Unsupported protocole : " + protocole);
+ } else {
+
+ tProxy.setURI(uriService);
+ tProxy.setClass(serviceclazz);
+
+ // le proxy tProxy definit suivant le protocole
+ // gere maintenant tous les appels sur l'interface
+ // demandee (serviceclazz)
+ serviceimpl = (E) Proxy.newProxyInstance(serviceclazz
+ .getClassLoader(),
+ new Class[] { serviceclazz }, tProxy);
+
+ // mise en cache
+ mapServiceCache.put(serviceclazz, serviceimpl);
+ }
+ }
+ } catch (URISyntaxException e) {
+ log.warn("URI for service '" + serviceclazz.getCanonicalName()
+ + "' is invalid !", e);
+ return null;
+ }
+ }
+
+ return serviceimpl;
+ }
+
+ /**
+ * Retourne l'implementation d'un TopiaProxy en fonction du protocole de
+ * l'URI
+ *
+ * @param uriService
+ * @return l'implementation ou null si le protocol n'est pas g�r�
+ */
+ private static TopiaProxy getProxyForURI(URI uriService) {
+
+ // result
+ TopiaProxy tProxy = null;
+
+ if ("rmi".equalsIgnoreCase(uriService.getScheme())) {
+ tProxy = new RMIProxy();
+ } else if ("xml-rpc".equalsIgnoreCase(uriService.getScheme())) {
+ tProxy = new XMLRPCProxy();
+ } else if ("soap".equalsIgnoreCase(uriService.getScheme())) {
+ tProxy = new SOAPProxy();
+ }
+
+ return tProxy;
+ }
+
+ /**
+ * Ajoute un service fournit par ToPIA.
+ *
+ * @param interfaze
+ * l'interface du service
+ * @param clazz
+ * la classe qui permet de creer des instances de
+ * l'implementation du service
+ * @param protocoles
+ * les protocoles de diffusion du service
+ *
+ * @see TopiaApplicationService
+ */
+ public static void addService(
+ Class<? extends TopiaApplicationService> interfaze,
+ Class<? extends TopiaApplicationService> clazz,
+ Protocol... protocoles) {
+ log.debug("Adding service for '" + interfaze + "' in protocoles : "
+ + Arrays.toString(protocoles));
+
+ for (Protocol protocole : protocoles) {
+ mainDispatcher.addServiceClass(interfaze, clazz, protocole);
+ }
+ }
+
+ /**
+ * Ajoute un service fournit par ToPIA.
+ *
+ * Celle-ci renvoie toujours la meme instance du service.
+ *
+ * @param <E>
+ * un type qui etend TopiaApplicationService
+ * @param interfaze
+ * l'interface du service
+ * @param instance
+ * l'instance de l'implementation du service
+ * @param protocoles
+ * les protocoles de diffusion du service
+ *
+ * @see TopiaApplicationService
+ */
+ public static <E extends TopiaApplicationService> void addService(
+ Class<E> interfaze, E instance, Protocol... protocoles) {
+ log.debug("Adding service for '" + interfaze
+ + "'(unique instance) in protocoles : "
+ + Arrays.toString(protocoles));
+
+ for (Protocol protocole : protocoles) {
+ mainDispatcher.addServiceInstance(interfaze, instance, protocole);
+ }
+ }
+}
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaProxy.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/TopiaProxy.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaProxy.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaProxy.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,49 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.service;
+
+import java.lang.reflect.InvocationHandler;
+import java.net.URI;
+
+/**
+ * TopiaProxy.java
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$ By : $Author$
+ */
+public interface TopiaProxy extends InvocationHandler, TopiaApplicationService {
+
+ /**
+ * Rensigne l'URI du service
+ *
+ * @param uri
+ * l'URI
+ * @see java.net.URI
+ */
+ public void setURI(URI uri);
+
+ /**
+ * Renseigne la classe geree
+ *
+ * @param clazz
+ * la class
+ */
+ public void setClass(Class<? extends TopiaApplicationService> clazz);
+}
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaProxy.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceProvider.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/TopiaServiceProvider.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceProvider.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceProvider.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,266 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.service;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.beanutils.MethodUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.service.servers.RMIServer;
+import org.codelutin.topia.service.servers.SOAPServer;
+import org.codelutin.topia.service.servers.XMLRPCServer;
+
+/**
+ * TopiaServiceProvider.java
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$ By : $Author$
+ */
+public class TopiaServiceProvider {
+
+ /** Logger (common logging) */
+ private static final Log logger = LogFactory
+ .getLog(TopiaServiceProvider.class);
+
+ /**
+ * Map de correspondance interface -> instance
+ */
+ private Map<Class<? extends TopiaApplicationService>, TopiaApplicationService> mapInstanceForClass;
+
+ /**
+ * Map de corresponcance class servant a creer une instance pour une
+ * interface (pour chaque requete)
+ */
+ private Map<Class<? extends TopiaApplicationService>, Class<? extends TopiaApplicationService>> mapClassForClass;
+
+ /**
+ * Sert a savoir si des servers ont deja ete lance ou pas.
+ */
+ private Map<Protocol, TopiaServiceServer> mapDispatcherForProtocole;
+
+ /**
+ * Map between port and protocol
+ */
+ protected Map<Protocol, Integer> mapPortForProtocol;
+
+ /**
+ * Constructeur
+ */
+ public TopiaServiceProvider() {
+ // instancaition des maps
+ mapInstanceForClass = new HashMap<Class<? extends TopiaApplicationService>, TopiaApplicationService>();
+ mapClassForClass = new HashMap<Class<? extends TopiaApplicationService>, Class<? extends TopiaApplicationService>>();
+ mapDispatcherForProtocole = new HashMap<Protocol, TopiaServiceServer>();
+ mapPortForProtocol = new HashMap<Protocol, Integer>();
+ }
+
+ /**
+ * Add a protocol port
+ *
+ * @param pr protocol
+ * @param port port
+ */
+ public void setProtocolPort(Protocol pr, Integer port) {
+ mapPortForProtocol.put(pr, port);
+ }
+
+ /**
+ *
+ * @param interfaze
+ * @param clazz
+ * @param protocole
+ */
+ public void addServiceClass(
+ Class<? extends TopiaApplicationService> interfaze,
+ Class<? extends TopiaApplicationService> clazz, Protocol protocole) {
+ TopiaServiceServer server = initDispatcher(protocole);
+ if (server != null) {
+ server.addService(interfaze);
+ mapClassForClass.put(interfaze, clazz);
+ launchDispatcher(protocole);
+ }
+ }
+
+ /**
+ *
+ * @param interfaze
+ * @param instance
+ * @param protocole
+ */
+ public void addServiceInstance(
+ Class<? extends TopiaApplicationService> interfaze,
+ TopiaApplicationService instance, Protocol protocole) {
+ TopiaServiceServer server = initDispatcher(protocole);
+ if (server != null) {
+ server.addService(interfaze);
+ mapInstanceForClass.put(interfaze, instance);
+ launchDispatcher(protocole);
+ }
+
+ }
+
+ /**
+ *
+ * @param protocole
+ */
+ private TopiaServiceServer initDispatcher(Protocol protocole) {
+
+ TopiaServiceServer server = mapDispatcherForProtocole.get(protocole);
+
+ // si un serveur n'est pas deja creer pour ce protocole
+ if (server == null) {
+
+ switch (protocole) {
+ case XML_RPC:
+ if (mapPortForProtocol.get(Protocol.XML_RPC) != null) {
+ server = new XMLRPCServer(mapPortForProtocol
+ .get(Protocol.XML_RPC));
+ } else {
+ server = new XMLRPCServer();
+ }
+ break;
+ case RMI:
+ try {
+ if (mapPortForProtocol.get(Protocol.RMI) != null) {
+ server = new RMIServer(mapPortForProtocol
+ .get(Protocol.RMI));
+ } else {
+ server = new RMIServer();
+ }
+ } catch (RemoteException e) {
+ logger.debug("Can't start RMIServer.", e);
+ }
+ break;
+ case SOAP:
+ if (mapPortForProtocol.get(Protocol.SOAP) != null) {
+ server = new SOAPServer(mapPortForProtocol
+ .get(Protocol.SOAP));
+ } else {
+ server = new SOAPServer();
+ }
+ break;
+ default:
+ logger.debug("Unsupported protocole");
+ break;
+ }
+
+ // ajoute a la liste
+ mapDispatcherForProtocole.put(protocole, server);
+ // renseigne le dispatcher
+ server.setTopiaServiceProvider(this);
+ }
+
+ return server;
+ }
+
+ /**
+ *
+ * @param protocole
+ */
+ private void launchDispatcher(Protocol protocole) {
+ TopiaServiceServer server = mapDispatcherForProtocole.get(protocole);
+
+ /*switch (protocole) {
+ case XML_RPC:
+ // le lance
+ server.launch();
+ break;
+ case RMI:
+ server.launch();
+ break;
+ case SOAP:
+ server.launch();
+ break;
+ default:
+ logger.debug("Unsupported protocole");
+ break;
+ }*/
+ server.launch();
+ }
+
+ /**
+ * Effectue l'appel reel suivant comment a ete fournit le service, classe ou
+ * instance.
+ *
+ * @param args
+ * les arguments
+ * @param method
+ * la methode
+ * @return le resultat de l'appel de la methode
+ */
+ public Object execute(Method method, Object[] args) {
+ // log
+ logger.debug("Request service : "
+ + method.getDeclaringClass().getName() + "." + method.getName()
+ + "(" + Arrays.toString(args) + ")");
+
+ Object result = null;
+
+ // la classe du service
+ Class clazz = null;
+ try {
+ clazz = method.getDeclaringClass();
+
+ // le service
+ TopiaApplicationService tasService = null;
+
+ // recherche du service dans la map class -> class
+ if (mapClassForClass.get(clazz) != null) {
+ tasService = mapClassForClass.get(clazz).newInstance();
+ }
+ // sinon dans la map clazz -> instance
+ else if (mapInstanceForClass.get(clazz) != null) {
+ tasService = mapInstanceForClass.get(clazz);
+ } else
+ logger.warn("No service set for class " + clazz.getName());
+
+ // Appel via commons beanutils
+ result = MethodUtils.invokeMethod(tasService, method.getName(),
+ args);
+
+ } catch (InstantiationException e) {
+ logger.debug("Can't instanciate class", e);
+ } catch (IllegalAccessException e) {
+ logger.debug("Can't access class", e);
+ } catch (SecurityException e) {
+ logger.debug("Can't call method '" + clazz.getName()
+ + "' in class '" + clazz.getName()
+ + "' (SecurityException)", e);
+ } catch (NoSuchMethodException e) {
+ logger.debug("No method '" + clazz.getName() + "' found in class '"
+ + clazz.getName() + "'", e);
+ } catch (IllegalArgumentException e) {
+ logger.debug("Can't call method '" + clazz.getName()
+ + "' in class '" + clazz.getName() + "' (security)", e);
+ } catch (InvocationTargetException e) {
+ logger.debug("Can't call method '" + clazz.getName()
+ + "' in class '" + clazz.getName()
+ + "' (InvocationTargetException)", e);
+ }
+
+ return result;
+ }
+}
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceProvider.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServer.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/TopiaServiceServer.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServer.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServer.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,50 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.service;
+
+/**
+ * TopiaServiceServer.java
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$ By : $Author$
+ */
+public interface TopiaServiceServer {
+
+ /**
+ * Ajoute un service devant etre gere.
+ *
+ * @param clazz
+ * le nom de l'interface.
+ */
+ public abstract void addService(
+ Class<? extends TopiaApplicationService> clazz);
+
+ /**
+ * Lance le serveur
+ */
+ public abstract void launch();
+
+ /**
+ * Set dispatcher
+ *
+ * @param mainDispatcher
+ */
+ public void setTopiaServiceProvider(TopiaServiceProvider mainDispatcher);
+}
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServer.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,61 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.service;
+
+import java.lang.reflect.Method;
+
+/**
+ * TopiaServiceServer.java
+ *
+ * Methodes communes a tous les servers renvoie l'appel sur le dispatcher
+ * principal.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$ By : $Author$
+ */
+public abstract class TopiaServiceServerAbstract implements TopiaServiceServer {
+
+ /** Le dispatcher principal */
+ private TopiaServiceProvider mainDispatcher;
+
+ /**
+ * Set dispatcher
+ *
+ * @param mainDispatcher
+ */
+ public void setTopiaServiceProvider(TopiaServiceProvider mainDispatcher) {
+ this.mainDispatcher = mainDispatcher;
+ }
+
+ /**
+ * Disptach
+ *
+ * @param className
+ * la classe
+ * @param methodName
+ * le nom de la methode
+ * @param args
+ * les arguments
+ * @return le resultat de l'appel
+ */
+ protected Object invoke(Method method, Object[] args) {
+ return mainDispatcher.execute(method, args);
+ }
+}
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/TopiaServiceServerAbstract.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/clients)
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/RMIProxy.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/clients/RMIProxy.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/RMIProxy.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -42,86 +42,86 @@
*/
public class RMIProxy implements TopiaProxy {
- /** Logger (common logging) */
- private static final Log logger = LogFactory.getLog(RMIProxy.class);
+ /** Logger (common logging) */
+ private static final Log logger = LogFactory.getLog(RMIProxy.class);
- /** location du service */
- protected String serviceLocation = null;
+ /** location du service */
+ protected String serviceLocation = null;
- /** La classe geree par le proxy */
- protected Class<? extends TopiaApplicationService> clazz;
+ /** La classe geree par le proxy */
+ protected Class<? extends TopiaApplicationService> clazz;
- /**
- * Constructeur
- *
- */
- public RMIProxy() {
+ /**
+ * Constructeur
+ *
+ */
+ public RMIProxy() {
- }
+ }
- /*
- * (non-Javadoc)
- *
- * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
- * java.lang.reflect.Method, java.lang.Object[])
- */
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
+ * java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
- Object result = null;
+ Object result = null;
- logger.debug("Invoke : " + clazz.getName() + "." + method.getName()
- + "(" + Arrays.toString(args) + ")");
+ logger.debug("Invoke : " + clazz.getName() + "." + method.getName()
+ + "(" + Arrays.toString(args) + ")");
- Remote rObject = LocateRegistry.getRegistry().lookup(clazz.getName());
+ Remote rObject = LocateRegistry.getRegistry().lookup(clazz.getName());
- logger.debug("Interfaces : "
- + Arrays.toString(rObject.getClass().getInterfaces()));
- logger.debug("Lookup for rmi service : rmi://" + this.serviceLocation
- + "/" + clazz.getName() + " is " + rObject);
+ logger.debug("Interfaces : "
+ + Arrays.toString(rObject.getClass().getInterfaces()));
+ logger.debug("Lookup for rmi service : rmi://" + this.serviceLocation
+ + "/" + clazz.getName() + " is " + rObject);
- logger.warn(Arrays.toString(rObject.getClass().getInterfaces()));
+ logger.warn(Arrays.toString(rObject.getClass().getInterfaces()));
- try {
- // l'objet Remote est en fait du type de la classe
- // Remote generee sur le serveur
- // on ne l'a pas ici
- // invocation via MethodUtils de commons beanutils
- result = MethodUtils.invokeMethod(rObject, method.getName(), args);
- } catch (IllegalAccessException e) {
- new TopiaException("Illegal Access to method (" + method.getName()
- + ") in interface " + clazz.getName());
- } catch (InvocationTargetException e) {
- new TopiaException("Can't call method (" + method.getName()
- + ") in interface " + clazz.getName());
- }
+ try {
+ // l'objet Remote est en fait du type de la classe
+ // Remote generee sur le serveur
+ // on ne l'a pas ici
+ // invocation via MethodUtils de commons beanutils
+ result = MethodUtils.invokeMethod(rObject, method.getName(), args);
+ } catch (IllegalAccessException e) {
+ new TopiaException("Illegal Access to method (" + method.getName()
+ + ") in interface " + clazz.getName());
+ } catch (InvocationTargetException e) {
+ new TopiaException("Can't call method (" + method.getName()
+ + ") in interface " + clazz.getName());
+ }
- return result;
- }
+ return result;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.service.clients.TopiaProxy#setURI(java.net.URI)
- */
- public void setURI(URI uri) {
- // serviceLocation = uri.getRawSchemeSpecificPart();
- serviceLocation = uri.getAuthority(); // = host + port si specifie
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.service.clients.TopiaProxy#setURI(java.net.URI)
+ */
+ public void setURI(URI uri) {
+ // serviceLocation = uri.getRawSchemeSpecificPart();
+ serviceLocation = uri.getAuthority(); // = host + port si specifie
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.service.clients.TopiaProxy#setClass(java.lang.Class)
- */
- public void setClass(Class<? extends TopiaApplicationService> clazz) {
- this.clazz = clazz;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.service.clients.TopiaProxy#setClass(java.lang.Class)
+ */
+ public void setClass(Class<? extends TopiaApplicationService> clazz) {
+ this.clazz = clazz;
+ }
- public void destroy() {
- }
+ public void destroy() {
+ }
- public void init(TopiaContext context) {
- }
+ public void init(TopiaContext context) {
+ }
}
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/SOAPProxy.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/clients/SOAPProxy.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/SOAPProxy.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -38,59 +38,59 @@
*/
public class SOAPProxy implements TopiaProxy {
- /** Logger (common logging) */
- //private static final Log logger = LogFactory.getLog(RMIProxy.class);
+ /** Logger (common logging) */
+ //private static final Log logger = LogFactory.getLog(RMIProxy.class);
+ /** Classes geree par le proxy */
+ protected Class<? extends TopiaApplicationService> clazz;
- /** Classes geree par le proxy */
- protected Class<? extends TopiaApplicationService> clazz;
+ /** URL du service */
+ protected String serviceLocation;
- /** URL du service */
- protected String serviceLocation;
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.service.TopiaProxy#setClass(java.lang.Class)
+ */
+ public void setClass(Class<? extends TopiaApplicationService> clazz) {
+ this.clazz = clazz;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.service.TopiaProxy#setClass(java.lang.Class)
- */
- public void setClass(Class<? extends TopiaApplicationService> clazz) {
- this.clazz = clazz;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.service.TopiaProxy#setURI(java.net.URI)
+ */
+ public void setURI(URI uri) {
+ this.serviceLocation = "http:" + uri.getSchemeSpecificPart();
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.service.TopiaProxy#setURI(java.net.URI)
- */
- public void setURI(URI uri) {
- this.serviceLocation = "http:" + uri.getSchemeSpecificPart();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
+ * java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(Object obj, Method method, Object[] args)
+ throws Throwable {
+ Object result = null;
- /*
- * (non-Javadoc)
- *
- * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
- * java.lang.reflect.Method, java.lang.Object[])
- */
- public Object invoke(Object obj, Method method, Object[] args)
- throws Throwable {
- Object result = null;
+ // Create a service model for the client
+ ObjectServiceFactory serviceFactory = new ObjectServiceFactory();
+ Service serviceModel = serviceFactory.create(clazz);
- // Create a service model for the client
- ObjectServiceFactory serviceFactory = new ObjectServiceFactory();
- Service serviceModel = serviceFactory.create(clazz);
+ // Create a client proxy
+ XFireProxyFactory proxyFactory = new XFireProxyFactory();
+ Object xfproxy = proxyFactory.create(serviceModel, serviceLocation
+ + "/" + clazz.getSimpleName());
- // Create a client proxy
- XFireProxyFactory proxyFactory = new XFireProxyFactory();
- Object xfproxy = proxyFactory.create(serviceModel, serviceLocation + "/" + clazz.getSimpleName());
+ result = MethodUtils.invokeMethod(xfproxy, method.getName(), args);
- result = MethodUtils.invokeMethod(xfproxy,method.getName(),args);
+ return result;
+ }
- return result;
- }
+ public void destroy() {
+ }
- public void destroy() {
- }
-
- public void init(TopiaContext context) {
- }
+ public void init(TopiaContext context) {
+ }
}
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/XMLRPCProxy.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/clients/XMLRPCProxy.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/clients/XMLRPCProxy.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -43,37 +43,40 @@
*/
public class XMLRPCProxy implements TopiaProxy {
- /** Logger (common logging) */
- private static final Log logger = LogFactory.getLog(XMLRPCProxy.class);
-
- /** location du service */
- protected String serviceLocation = null;
-
- /** La classe geree par le proxy */
- protected Class<? extends TopiaApplicationService> clazz;
-
- /* (non-Javadoc)
- * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
- */
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
-
- Object result = null;
-
- logger.debug("Invoke : " +clazz.getName() + "." +
- method.getName() + "(" + Arrays.toString(args) + ")");
-
- logger.debug("XML-RPC , Using uri = http:" + this.serviceLocation);
-
- //Le client XMLRPC de crispy est en version < 3
+ /** Logger (common logging) */
+ private static final Log logger = LogFactory.getLog(XMLRPCProxy.class);
- XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+ /** location du service */
+ protected String serviceLocation = null;
+
+ /** La classe geree par le proxy */
+ protected Class<? extends TopiaApplicationService> clazz;
+
+ /* (non-Javadoc)
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+
+ Object result = null;
+
+ logger.debug("Invoke : " + clazz.getName() + "." + method.getName()
+ + "(" + Arrays.toString(args) + ")");
+
+ logger.debug("XML-RPC , Using uri = http:" + this.serviceLocation);
+
+ //Le client XMLRPC de crispy est en version < 3
+
+ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try {
config.setServerURL(new URL("http:" + this.serviceLocation));
XmlRpcClient client = new XmlRpcClient();
- client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));
+ client
+ .setTransportFactory(new XmlRpcCommonsTransportFactory(
+ client));
client.setConfig(config);
- result = client.execute(clazz.getName() + "." + method.getName(), args);
+ result = client.execute(clazz.getName() + "." + method.getName(),
+ args);
} catch (java.net.MalformedURLException e) {
System.out.println("Caught MalformedURLException\n");
e.printStackTrace();
@@ -81,28 +84,28 @@
System.out.println("Caught XmlRpcException\n");
e.printStackTrace();
}
-
- return result;
- }
- /* (non-Javadoc)
- * @see org.codelutin.topia.service.clients.TopiaProxy#setURI(java.net.URI)
- */
- public void setURI(URI uri) {
- serviceLocation = uri.getRawSchemeSpecificPart();
- }
+ return result;
+ }
- /* (non-Javadoc)
- * @see org.codelutin.topia.service.clients.TopiaProxy#setClass(java.lang.Class)
- */
- public void setClass(Class<? extends TopiaApplicationService> clazz) {
- this.clazz = clazz;
- }
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.service.clients.TopiaProxy#setURI(java.net.URI)
+ */
+ public void setURI(URI uri) {
+ serviceLocation = uri.getRawSchemeSpecificPart();
+ }
- public void destroy() {
- }
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.service.clients.TopiaProxy#setClass(java.lang.Class)
+ */
+ public void setClass(Class<? extends TopiaApplicationService> clazz) {
+ this.clazz = clazz;
+ }
- public void init(TopiaContext context) {
- }
+ public void destroy() {
+ }
+ public void init(TopiaContext context) {
+ }
+
}
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/package.html (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/package.html)
===================================================================
--- topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/package.html (rev 0)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/package.html 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
+
+<html>
+ <head>
+ <meta
+ name="service"
+ content="HTML Tidy, see www.w3.org">
+
+ <title></title>
+ </head>
+
+ <body>
+ <h1>La couche de service ToPIA.</h1>
+
+ <p>Toutes l'utilisation s'effectue au travers de la factory TopiaServiceFactory.</p>
+
+ <h2>Services utilisés</h2>
+
+ <p>TopiaServiceFactory.getService(Class) permet de recuperer une interface
+ sur un service, son implmentation est chargée comme definie dans la
+ configuration.</p>
+
+ <h2>Services fournit</h2>
+
+ <p>TopiaServiceFactory.addService(Class,Class,Protocole...) et
+ TopiaServiceFactory.addService(Class,Object,Protocole...) permettent de mettre
+ à disposition un service sur un protocole donné</p>
+ </body>
+</html>
+
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/package.html
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/service/servers)
Property changes on: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RMIServer.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/servers/RMIServer.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RMIServer.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -42,139 +42,140 @@
* Last update : $Date$ By : $Author$
*/
public class RMIServer extends TopiaServiceServerAbstract implements Runnable,
- InvocationHandler {
+ InvocationHandler {
- /** Logger (common logging) */
- private static final Log logger = LogFactory.getLog(RMIServer.class);
+ /** Logger (common logging) */
+ private static final Log logger = LogFactory.getLog(RMIServer.class);
- /** Port de rmiregistry */
- protected final static int DEFAULT_PORT = 1099;
-
- /** instance de registry */
- protected Registry registry;
-
- /** Server already launched */
- protected boolean alreadyLaunched = false;
-
- /**
- * Constructeur
- * @throws RemoteException si la creation echoue
- */
- public RMIServer() throws RemoteException {
- this(DEFAULT_PORT);
- }
-
- /**
- * Constructeur
- * @throws RemoteException si la creation echoue
- */
- public RMIServer(int port) throws RemoteException {
-
- // lance rmiregistry
- registry = LocateRegistry.createRegistry(port);
- logger.info("Starting RMIRegistry on port " + port + "...");
- }
+ /** Port de rmiregistry */
+ protected final static int DEFAULT_PORT = 1099;
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.service.TopiaServiceServer#addService(java.lang.Class)
- */
- public void addService(final Class<? extends TopiaApplicationService> clazz) {
- // /lDelegationInterfaces.add(clazz);
+ /** instance de registry */
+ protected Registry registry;
- // meProxy est le proxy que l'on va bind dans RMI
- // meProxy pointe sur this
+ /** Server already launched */
+ protected boolean alreadyLaunched = false;
- // create class that implements Remote and throws RemoteException
- // for all methods
- try {
- Class clazz2 = RemoteClassLoader.getRemoteClass(clazz);
+ /**
+ * Constructeur
+ * @throws RemoteException si la creation echoue
+ */
+ public RMIServer() throws RemoteException {
+ this(DEFAULT_PORT);
+ }
- // logger.debug("Interface list = " +
- // Arrays.toString(clazz2.getInterfaces()));
+ /**
+ * Constructeur
+ * @throws RemoteException si la creation echoue
+ */
+ public RMIServer(int port) throws RemoteException {
- Remote meProxy = (Remote) Proxy.newProxyInstance(clazz2
- .getClassLoader(), new Class[] { clazz2 }, this);
+ // lance rmiregistry
+ registry = LocateRegistry.createRegistry(port);
+ logger.info("Starting RMIRegistry on port " + port + "...");
+ }
- Remote stub = new UnicastServerRef(false).exportObject(meProxy,
- null, false);
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.service.TopiaServiceServer#addService(java.lang.Class)
+ */
+ public void addService(final Class<? extends TopiaApplicationService> clazz) {
+ // /lDelegationInterfaces.add(clazz);
- registry.rebind(clazz.getName(), stub);
+ // meProxy est le proxy que l'on va bind dans RMI
+ // meProxy pointe sur this
- logger.info("Binding new rmi service = " + clazz.getName());
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (RemoteException e) {
- e.printStackTrace();
- } catch (SecurityException e) {
- e.printStackTrace();
- }
- }
+ // create class that implements Remote and throws RemoteException
+ // for all methods
+ try {
+ Class clazz2 = RemoteClassLoader.getRemoteClass(clazz);
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Runnable#run()
- */
- public void run() {
-
- logger.info("RMI Server running...");
- while (true) {
- // TODO change (attente passive)
- try {
- Thread.sleep(Long.MAX_VALUE);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
+ // logger.debug("Interface list = " +
+ // Arrays.toString(clazz2.getInterfaces()));
- /*
- * (non-Javadoc)
- *
- * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
- * java.lang.reflect.Method, java.lang.Object[])
- */
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
+ Remote meProxy = (Remote) Proxy.newProxyInstance(clazz2
+ .getClassLoader(), new Class[] { clazz2 }, this);
- // log
- logger.debug("Invoke RMIServer = " + method.getName() + "("
- + Arrays.toString(args) + ")");
+ Remote stub = new UnicastServerRef(false).exportObject(meProxy,
+ null, false);
- Class clazzToCall = method.getDeclaringClass();
- // for(Class<? extends TopiaApplicationService> localClazz :
- // lDelegationInterfaces) {
- // Class[] interfaces = proxy.getClass().getInterfaces();
- // List<Class> asList = Arrays.asList(interfaces);
- // if (asList.contains(localClazz)) { // instanceOf marche pas ici
- // clazzToCall = localClazz;
- // }
- // }
+ registry.rebind(clazz.getName(), stub);
- Class realClass = Class.forName(RemoteClassLoader.getOriginClassName(clazzToCall));
- Method realMethod = realClass.getMethod(method.getName(),
- (Class[]) method.getParameterTypes());
+ logger.info("Binding new rmi service = " + clazz.getName());
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ }
+ }
- Object result = null;
- if (clazzToCall != null) {
- logger.debug("Requested class = " + realClass.getName());
- result = super.invoke(realMethod, args);
- }
- return result;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.service.TopiaServiceServer#launch()
- */
- public void launch() {
- if(!alreadyLaunched) {
- (new Thread(this)).start();
- alreadyLaunched = true;
- }
- }
+ logger.info("RMI Server running...");
+ while (true) {
+ // TODO change (attente passive)
+ try {
+ Thread.sleep(Long.MAX_VALUE);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
+ * java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+
+ // log
+ logger.debug("Invoke RMIServer = " + method.getName() + "("
+ + Arrays.toString(args) + ")");
+
+ Class clazzToCall = method.getDeclaringClass();
+ // for(Class<? extends TopiaApplicationService> localClazz :
+ // lDelegationInterfaces) {
+ // Class[] interfaces = proxy.getClass().getInterfaces();
+ // List<Class> asList = Arrays.asList(interfaces);
+ // if (asList.contains(localClazz)) { // instanceOf marche pas ici
+ // clazzToCall = localClazz;
+ // }
+ // }
+
+ Class realClass = Class.forName(RemoteClassLoader
+ .getOriginClassName(clazzToCall));
+ Method realMethod = realClass.getMethod(method.getName(),
+ (Class[]) method.getParameterTypes());
+
+ Object result = null;
+ if (clazzToCall != null) {
+ logger.debug("Requested class = " + realClass.getName());
+ result = super.invoke(realMethod, args);
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.service.TopiaServiceServer#launch()
+ */
+ public void launch() {
+ if (!alreadyLaunched) {
+ (new Thread(this)).start();
+ alreadyLaunched = true;
+ }
+ }
+
}
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RemoteClassLoader.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/servers/RemoteClassLoader.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/RemoteClassLoader.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -60,338 +60,338 @@
*/
public class RemoteClassLoader implements ClassVisitor {
- /** Logger (common logging) */
- private static final Log logger = LogFactory
- .getLog(RemoteClassLoader.class);
+ /** Logger (common logging) */
+ private static final Log logger = LogFactory
+ .getLog(RemoteClassLoader.class);
- /** Ajout au nom de classe */
- public static final String EXTENSION = "Remote";
+ /** Ajout au nom de classe */
+ public static final String EXTENSION = "Remote";
- /**
- * Le writer (global necessaire parce que parcourt par patron visiteur)
- */
- protected ClassWriter cWriter;
+ /**
+ * Le writer (global necessaire parce que parcourt par patron visiteur)
+ */
+ protected ClassWriter cWriter;
- /**
- * Constructeur
- *
- * @param clazz
- * la classes a convertir
- */
- protected RemoteClassLoader() {
- }
+ /**
+ * Constructeur
+ *
+ * @param clazz
+ * la classes a convertir
+ */
+ protected RemoteClassLoader() {
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.objectweb.asm.ClassVisitor#visit(int, int, java.lang.String,
- * java.lang.String, java.lang.String[], java.lang.String)
- */
- public void visit(int version, int access, String name, String superName,
- String[] interfaces, String sourceFile) {
- // creer un writer
- cWriter = new ClassWriter(false);
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.objectweb.asm.ClassVisitor#visit(int, int, java.lang.String,
+ * java.lang.String, java.lang.String[], java.lang.String)
+ */
+ public void visit(int version, int access, String name, String superName,
+ String[] interfaces, String sourceFile) {
+ // creer un writer
+ cWriter = new ClassWriter(false);
- logger.debug("Converting class " + name + " as remote class");
+ logger.debug("Converting class " + name + " as remote class");
- // nouveau nom de fichier
- String newSourceFileName = sourceFile.replaceAll("(.*)\\.java$", "$1"
- + EXTENSION + ".java");
+ // nouveau nom de fichier
+ String newSourceFileName = sourceFile.replaceAll("(.*)\\.java$", "$1"
+ + EXTENSION + ".java");
- // liste des interfaces
- String remoteInterface = Remote.class.getName().replaceAll("\\.",
- String.valueOf(File.separatorChar));
- String[] interfacesNew = null;
- if (interfaces == null) {
- interfacesNew = new String[] { remoteInterface };
- } else {
- interfacesNew = new String[interfaces.length + 1];
- for (int i = 0; i < interfaces.length; ++i)
- interfacesNew[i] = interfaces[i];
- interfacesNew[interfacesNew.length - 1] = remoteInterface;
- }
+ // liste des interfaces
+ String remoteInterface = Remote.class.getName().replaceAll("\\.",
+ String.valueOf(File.separatorChar));
+ String[] interfacesNew = null;
+ if (interfaces == null) {
+ interfacesNew = new String[] { remoteInterface };
+ } else {
+ interfacesNew = new String[interfaces.length + 1];
+ for (int i = 0; i < interfaces.length; ++i)
+ interfacesNew[i] = interfaces[i];
+ interfacesNew[interfacesNew.length - 1] = remoteInterface;
+ }
- cWriter.visit(version, // version de la classe
- access, // visibilite
- name + EXTENSION, // nom
- superName, // superclasse
- interfacesNew, // les interface
- newSourceFileName); // le fichier sources
- }
+ cWriter.visit(version, // version de la classe
+ access, // visibilite
+ name + EXTENSION, // nom
+ superName, // superclasse
+ interfacesNew, // les interface
+ newSourceFileName); // le fichier sources
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute)
- */
- public void visitAttribute(Attribute attr) {
- logger.warn("Attribute " + attr.toString()
- + " found : conversion not supported");
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute)
+ */
+ public void visitAttribute(Attribute attr) {
+ logger.warn("Attribute " + attr.toString()
+ + " found : conversion not supported");
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.objectweb.asm.ClassVisitor#visitEnd()
- */
- public void visitEnd() {
- cWriter.visitEnd();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.objectweb.asm.ClassVisitor#visitEnd()
+ */
+ public void visitEnd() {
+ cWriter.visitEnd();
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String,
- * java.lang.String, java.lang.Object, org.objectweb.asm.Attribute)
- */
- public void visitField(int access, String name, String desc, Object value,
- Attribute attrs) {
- logger.warn("Field " + name + " found : conversion not supported");
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String,
+ * java.lang.String, java.lang.Object, org.objectweb.asm.Attribute)
+ */
+ public void visitField(int access, String name, String desc, Object value,
+ Attribute attrs) {
+ logger.warn("Field " + name + " found : conversion not supported");
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String,
- * java.lang.String, java.lang.String, int)
- */
- public void visitInnerClass(String name, String outerName,
- String innerName, int access) {
- logger.warn("InnerClass " + name + " found : conversion not supported");
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String,
+ * java.lang.String, java.lang.String, int)
+ */
+ public void visitInnerClass(String name, String outerName,
+ String innerName, int access) {
+ logger.warn("InnerClass " + name + " found : conversion not supported");
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String,
- * java.lang.String, java.lang.String[], org.objectweb.asm.Attribute)
- */
- public CodeVisitor visitMethod(int access, String name, String desc,
- String[] exceptions, Attribute attrs) {
- logger.debug("Processing method " + name);
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String,
+ * java.lang.String, java.lang.String[], org.objectweb.asm.Attribute)
+ */
+ public CodeVisitor visitMethod(int access, String name, String desc,
+ String[] exceptions, Attribute attrs) {
+ logger.debug("Processing method " + name);
- // liste des interfaces
- String remoteExceptionName = RemoteException.class.getName()
- .replaceAll("\\.", String.valueOf(File.separatorChar));
- String[] exceptionsNew = null;
- if (exceptions == null) {
- exceptionsNew = new String[] { remoteExceptionName };
- } else {
- exceptionsNew = new String[exceptions.length + 1];
- for (int i = 0; i < exceptions.length; ++i)
- exceptionsNew[i] = exceptions[i];
- exceptionsNew[exceptionsNew.length - 1] = remoteExceptionName;
- }
+ // liste des interfaces
+ String remoteExceptionName = RemoteException.class.getName()
+ .replaceAll("\\.", String.valueOf(File.separatorChar));
+ String[] exceptionsNew = null;
+ if (exceptions == null) {
+ exceptionsNew = new String[] { remoteExceptionName };
+ } else {
+ exceptionsNew = new String[exceptions.length + 1];
+ for (int i = 0; i < exceptions.length; ++i)
+ exceptionsNew[i] = exceptions[i];
+ exceptionsNew[exceptionsNew.length - 1] = remoteExceptionName;
+ }
- cWriter.visitMethod(access, // visibilite
- name, // nom
- desc, // arguments
- exceptionsNew, // les exceptions lancees
- attrs); // retour
+ cWriter.visitMethod(access, // visibilite
+ name, // nom
+ desc, // arguments
+ exceptionsNew, // les exceptions lancees
+ attrs); // retour
- return null;
- }
+ return null;
+ }
- /**
- * Retourne le nom d'origine sans l'ajout
- *
- * @param clazz
- * la classe remote
- * @return le nom non-remote
- */
- public static String getOriginClassName(Class clazz) {
- return clazz.getName().replaceAll("(.*)" + EXTENSION + "$", "$1");
- }
+ /**
+ * Retourne le nom d'origine sans l'ajout
+ *
+ * @param clazz
+ * la classe remote
+ * @return le nom non-remote
+ */
+ public static String getOriginClassName(Class clazz) {
+ return clazz.getName().replaceAll("(.*)" + EXTENSION + "$", "$1");
+ }
- /**
- * Retourne la classe version "remote" de celle specifiee
- *
- * @param clazz
- * la classe non remote
- * @return la classe remote
- * @throws ClassNotFoundException
- * si on ne peut pas genere la classe
- */
- public static Class<?> getRemoteClass(Class clazz)
- throws ClassNotFoundException {
+ /**
+ * Retourne la classe version "remote" de celle specifiee
+ *
+ * @param clazz
+ * la classe non remote
+ * @return la classe remote
+ * @throws ClassNotFoundException
+ * si on ne peut pas genere la classe
+ */
+ public static Class<?> getRemoteClass(Class clazz)
+ throws ClassNotFoundException {
- Class remoteClass = null;
+ Class remoteClass = null;
- // onregarde si la ressource existe,
- // sinon on la genere
+ // onregarde si la ressource existe,
+ // sinon on la genere
- URL url = ClassLoader.getSystemClassLoader().getResource(
- clazz.getName().replaceAll("\\.", "/") + EXTENSION + ".class");
+ URL url = ClassLoader.getSystemClassLoader().getResource(
+ clazz.getName().replaceAll("\\.", "/") + EXTENSION + ".class");
- if (url == null) {
- // classe non trouvee, on la genere
- logger.debug("Remote class not found for '" + clazz.getName()
- + "', generating a new one");
+ if (url == null) {
+ // classe non trouvee, on la genere
+ logger.debug("Remote class not found for '" + clazz.getName()
+ + "', generating a new one");
- RemoteClassLoader rcl = new RemoteClassLoader();
- // recupere la classe generee
- byte[] clazzBytes = rcl.getClassData(clazz);
+ RemoteClassLoader rcl = new RemoteClassLoader();
+ // recupere la classe generee
+ byte[] clazzBytes = rcl.getClassData(clazz);
- try {
- // la sauve en dur
- rcl.saveOnDisk(clazz, clazzBytes);
- } catch (IOException e2) {
- logger.debug("Can't save generated class on disk", e2);
- throw new ClassNotFoundException("Can't find class : "
- + clazz.getName() + EXTENSION, e2);
- }
- }
+ try {
+ // la sauve en dur
+ rcl.saveOnDisk(clazz, clazzBytes);
+ } catch (IOException e2) {
+ logger.debug("Can't save generated class on disk", e2);
+ throw new ClassNotFoundException("Can't find class : "
+ + clazz.getName() + EXTENSION, e2);
+ }
+ }
- // retente un forName et devrai maintenant la trouver
- try {
- remoteClass = Class.forName(clazz.getName() + EXTENSION);
- } catch (ClassNotFoundException e2) {
- logger.debug("Can't find generated class", e2);
- throw new ClassNotFoundException("Can't find class : "
- + clazz.getName() + EXTENSION, e2);
- }
+ // retente un forName et devrai maintenant la trouver
+ try {
+ remoteClass = Class.forName(clazz.getName() + EXTENSION);
+ } catch (ClassNotFoundException e2) {
+ logger.debug("Can't find generated class", e2);
+ throw new ClassNotFoundException("Can't find class : "
+ + clazz.getName() + EXTENSION, e2);
+ }
- return remoteClass;
- }
+ return remoteClass;
+ }
- /**
- * Sauve la classe generee sur le disque.
- *
- * Dans un jar, ou ds un fichier...
- *
- * @param clazz
- * La class d'origine
- * @param clazzBytes
- * La classe generee
- * @throws IOException
- */
- protected void saveOnDisk(Class clazz, byte[] clazzBytes)
- throws IOException {
- // ensuite, on la sauve en dur, sur disque
- // soit dans un jar, soit sur un fichier physique
- // au meme endroit que la classe d'origine
- URL originClazzPath = ClassLoader.getSystemClassLoader().getResource(
- clazz.getName().replaceAll("\\.",
- String.valueOf(File.separatorChar))
- + ".class");
+ /**
+ * Sauve la classe generee sur le disque.
+ *
+ * Dans un jar, ou ds un fichier...
+ *
+ * @param clazz
+ * La class d'origine
+ * @param clazzBytes
+ * La classe generee
+ * @throws IOException
+ */
+ protected void saveOnDisk(Class clazz, byte[] clazzBytes)
+ throws IOException {
+ // ensuite, on la sauve en dur, sur disque
+ // soit dans un jar, soit sur un fichier physique
+ // au meme endroit que la classe d'origine
+ URL originClazzPath = ClassLoader.getSystemClassLoader().getResource(
+ clazz.getName().replaceAll("\\.",
+ String.valueOf(File.separatorChar))
+ + ".class");
- // suivant le protocol
- // file, jar...
- String protocol = originClazzPath.getProtocol();
+ // suivant le protocol
+ // file, jar...
+ String protocol = originClazzPath.getProtocol();
- if ("file".equals(protocol)) {
- saveInFile(originClazzPath, clazzBytes);
- } else if (protocol.matches("ear|jar|war|zip")) {
- saveInJarFile(originClazzPath, clazzBytes);
- } else {
- logger.warn("Unsupported protocol '" + protocol
- + "' for saving clazz.");
- }
- }
+ if ("file".equals(protocol)) {
+ saveInFile(originClazzPath, clazzBytes);
+ } else if (protocol.matches("ear|jar|war|zip")) {
+ saveInJarFile(originClazzPath, clazzBytes);
+ } else {
+ logger.warn("Unsupported protocol '" + protocol
+ + "' for saving clazz.");
+ }
+ }
- /**
- * Sauve le fichier dans un jar.
- *
- * Java ne supporte pas le modification des jar. On le sauve maintenant dan
- * le dossier topiagen.
- *
- * @param originClazzPath
- * @param clazzBytes
- * @throws IOException
- * si erreur d'ecriture
- */
- protected void saveInJarFile(URL originClazzPath, byte[] clazzBytes)
- throws IOException {
- /*
- * TRUEZIP code // write class on disk String path =
- * originClazzPath.getFile(); // chemin valid truezip String archive =
- * path.replaceAll("^file:(.*)!(.*)\\.class$", "$1"); path =
- * path.replaceAll("^file:(.*)!(.*)\\.class$", "$1$2" + EXTENSION +
- * ".class"); // File f = new File(path); // f.createNewFile();
- * FileOutputStream out = new FileOutputStream(path);
- * out.write(clazzBytes, 0, clazzBytes.length); out.close(); // force
- * l'update de l'archive // sinon la modification n'est pas prise en
- * compte dans l'excecution // courante de la JVM // File.update(new
- * File(archive));
- *
- * try { File.umount(new File(archive)); } catch (ArchiveException ouch) {
- * logger .debug("ArchiveException , can't umount archive : " +
- * archive); // At least one exception occured which is not just an //
- * ArchiveWarningException. This is a severe situation that // needs to
- * be handled. // Print the sequential chain of exceptions in order of //
- * descending priority and ascending appearance. //
- * ouch.printStackTrace(); // Print the sequential chain of exceptions
- * in order of // appearance instead.
- * ouch.sortAppearance().printStackTrace(); } TRUEZIP code
- */
+ /**
+ * Sauve le fichier dans un jar.
+ *
+ * Java ne supporte pas le modification des jar. On le sauve maintenant dan
+ * le dossier topiagen.
+ *
+ * @param originClazzPath
+ * @param clazzBytes
+ * @throws IOException
+ * si erreur d'ecriture
+ */
+ protected void saveInJarFile(URL originClazzPath, byte[] clazzBytes)
+ throws IOException {
+ /*
+ * TRUEZIP code // write class on disk String path =
+ * originClazzPath.getFile(); // chemin valid truezip String archive =
+ * path.replaceAll("^file:(.*)!(.*)\\.class$", "$1"); path =
+ * path.replaceAll("^file:(.*)!(.*)\\.class$", "$1$2" + EXTENSION +
+ * ".class"); // File f = new File(path); // f.createNewFile();
+ * FileOutputStream out = new FileOutputStream(path);
+ * out.write(clazzBytes, 0, clazzBytes.length); out.close(); // force
+ * l'update de l'archive // sinon la modification n'est pas prise en
+ * compte dans l'excecution // courante de la JVM // File.update(new
+ * File(archive));
+ *
+ * try { File.umount(new File(archive)); } catch (ArchiveException ouch) {
+ * logger .debug("ArchiveException , can't umount archive : " +
+ * archive); // At least one exception occured which is not just an //
+ * ArchiveWarningException. This is a severe situation that // needs to
+ * be handled. // Print the sequential chain of exceptions in order of //
+ * descending priority and ascending appearance. //
+ * ouch.printStackTrace(); // Print the sequential chain of exceptions
+ * in order of // appearance instead.
+ * ouch.sortAppearance().printStackTrace(); } TRUEZIP code
+ */
- String path = originClazzPath.getFile().replaceAll(
- "^file:(.*)!(.*)\\.class$", "$2" + EXTENSION + ".class");
+ String path = originClazzPath.getFile().replaceAll(
+ "^file:(.*)!(.*)\\.class$", "$2" + EXTENSION + ".class");
- // creer les dossier et fichier
- java.io.File fRemoteClass = new java.io.File(
- TopiaApplicationServiceFactory.TOPIA_GENERATION_DIRECTORY
- + String.valueOf(File.separatorChar) + path);
- fRemoteClass.getParentFile().mkdirs();
+ // creer les dossier et fichier
+ java.io.File fRemoteClass = new java.io.File(
+ TopiaApplicationServiceFactory.TOPIA_GENERATION_DIRECTORY
+ + String.valueOf(File.separatorChar) + path);
+ fRemoteClass.getParentFile().mkdirs();
- // ecrit les donnees
- java.io.FileOutputStream out = new java.io.FileOutputStream(
- fRemoteClass);
- out.write(clazzBytes, 0, clazzBytes.length);
- out.close();
+ // ecrit les donnees
+ java.io.FileOutputStream out = new java.io.FileOutputStream(
+ fRemoteClass);
+ out.write(clazzBytes, 0, clazzBytes.length);
+ out.close();
- logger.debug("Remote clazz saved into archive as path : "
- + fRemoteClass.getAbsolutePath());
- }
+ logger.debug("Remote clazz saved into archive as path : "
+ + fRemoteClass.getAbsolutePath());
+ }
- /**
- * Genere la classe dans son fichier phisyque
- *
- * /home/chatellier/tmp/toto.java file:/home/chatellier/tmp/toto.class
- *
- * @param originClazzPath
- * l'url d'origine
- * @param clazzBytes
- * les donnees de la classe
- * @throws IOException
- * si erreur d'ecriture
- */
- protected void saveInFile(URL originClazzPath, byte[] clazzBytes)
- throws IOException {
- // write class on disk
- String path = originClazzPath.getFile();
+ /**
+ * Genere la classe dans son fichier phisyque
+ *
+ * /home/chatellier/tmp/toto.java file:/home/chatellier/tmp/toto.class
+ *
+ * @param originClazzPath
+ * l'url d'origine
+ * @param clazzBytes
+ * les donnees de la classe
+ * @throws IOException
+ * si erreur d'ecriture
+ */
+ protected void saveInFile(URL originClazzPath, byte[] clazzBytes)
+ throws IOException {
+ // write class on disk
+ String path = originClazzPath.getFile();
- // ajout de "Remote" au nom
- path = path.replaceAll("\\.class$", EXTENSION + ".class");
+ // ajout de "Remote" au nom
+ path = path.replaceAll("\\.class$", EXTENSION + ".class");
- java.io.File f = new java.io.File(path);
- // f.createNewFile();
- java.io.FileOutputStream out = new java.io.FileOutputStream(f);
- out.write(clazzBytes, 0, clazzBytes.length);
- out.close();
+ java.io.File f = new java.io.File(path);
+ // f.createNewFile();
+ java.io.FileOutputStream out = new java.io.FileOutputStream(f);
+ out.write(clazzBytes, 0, clazzBytes.length);
+ out.close();
- logger.debug("Remote class saved to : " + path);
- }
+ logger.debug("Remote class saved to : " + path);
+ }
- /**
- * Convertit la class en class "Remote"
- *
- * @param clazz
- * la classe non remote
- * @return la classe remote
- */
- private byte[] getClassData(Class clazz) {
- byte[] b = null;
+ /**
+ * Convertit la class en class "Remote"
+ *
+ * @param clazz
+ * la classe non remote
+ * @return la classe remote
+ */
+ private byte[] getClassData(Class clazz) {
+ byte[] b = null;
- ClassReader cr;
- try {
- cr = new ClassReader(clazz.getName());
- cr.accept(this, false);
- b = cWriter.toByteArray();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ ClassReader cr;
+ try {
+ cr = new ClassReader(clazz.getName());
+ cr.accept(this, false);
+ b = cWriter.toByteArray();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- return b;
- }
+ return b;
+ }
}
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/SOAPServer.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/servers/SOAPServer.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/SOAPServer.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -40,75 +40,76 @@
*/
public class SOAPServer extends TopiaServiceServerAbstract implements Invoker {
- /** Version UID */
- private static final long serialVersionUID = 3692192673769687321L;
+ /** Version UID */
+ private static final long serialVersionUID = 3692192673769687321L;
- /** Logger (common logging) */
- //private static final Log logger = LogFactory.getLog(SOAPServer.class);
+ /** Logger (common logging) */
+ //private static final Log logger = LogFactory.getLog(SOAPServer.class);
+ /** Port du serveur web */
+ protected static final int DEFAULT_PORT = 8888;
- /** Port du serveur web */
- protected static final int DEFAULT_PORT = 8888;
+ /** Server already launched */
+ protected boolean alreadyLaunched = false;
- /** Server already launched */
- protected boolean alreadyLaunched = false;
-
- /** Current used port */
- protected int port;
- /**
- * Constructeur.
- */
- public SOAPServer() {
- this(DEFAULT_PORT);
- }
-
- /**
- * Constructeur.
- */
- public SOAPServer(int port) {
- this.port = port;
- }
+ /** Current used port */
+ protected int port;
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.service.TopiaServiceServer#addService(java.lang.Class)
- */
- public void addService(Class<? extends TopiaApplicationService> clazz) {
-
- // Create an XFire Service
+ /**
+ * Constructeur.
+ */
+ public SOAPServer() {
+ this(DEFAULT_PORT);
+ }
+
+ /**
+ * Constructeur.
+ */
+ public SOAPServer(int port) {
+ this.port = port;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.service.TopiaServiceServer#addService(java.lang.Class)
+ */
+ public void addService(Class<? extends TopiaApplicationService> clazz) {
+
+ // Create an XFire Service
ObjectServiceFactory serviceFactory = new ObjectServiceFactory();
Service service = serviceFactory.create(clazz);
//service.setInvoker(new BeanInvoker(new EchoImpl()));
service.setInvoker(this);
-
+
// Register the service in the ServiceRegistry
XFire xfire = XFireFactory.newInstance().getXFire();
xfire.getServiceRegistry().register(service);
- }
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.service.TopiaServiceServer#launch()
- */
- public void launch() {
- if(!alreadyLaunched) {
- // Start the HTTP server
- XFireHttpServer server = new XFireHttpServer();
- server.setPort(this.port);
- try {
- server.start();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- alreadyLaunched = true;
- }
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.service.TopiaServiceServer#launch()
+ */
+ public void launch() {
+ if (!alreadyLaunched) {
+ // Start the HTTP server
+ XFireHttpServer server = new XFireHttpServer();
+ server.setPort(this.port);
+ try {
+ server.start();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ alreadyLaunched = true;
+ }
+ }
- /* (non-Javadoc)
- * @see org.codehaus.xfire.service.invoker.Invoker#invoke(java.lang.reflect.Method, java.lang.Object[], org.codehaus.xfire.MessageContext)
- */
- public Object invoke(Method method, Object[] args, MessageContext ctx) throws XFireFault {
- return super.invoke(method, args);
- }
+ /* (non-Javadoc)
+ * @see org.codehaus.xfire.service.invoker.Invoker#invoke(java.lang.reflect.Method, java.lang.Object[], org.codehaus.xfire.MessageContext)
+ */
+ public Object invoke(Method method, Object[] args, MessageContext ctx)
+ throws XFireFault {
+ return super.invoke(method, args);
+ }
}
Modified: topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/XMLRPCServer.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/service/servers/XMLRPCServer.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/main/java/org/codelutin/topia/service/servers/XMLRPCServer.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -49,201 +49,201 @@
* Last update : $Date$ By : $Author$
*/
public class XMLRPCServer extends TopiaServiceServerAbstract implements
- XmlRpcHandler, XmlRpcHandlerMapping {
+ XmlRpcHandler, XmlRpcHandlerMapping {
- /** Logger (common logging) */
- private static final Log logger = LogFactory.getLog(XMLRPCServer.class);
+ /** Logger (common logging) */
+ private static final Log logger = LogFactory.getLog(XMLRPCServer.class);
- /** Le server Web */
- private WebServer webServer;
+ /** Le server Web */
+ private WebServer webServer;
- /** Port */
- public static final int DEFAUTL_PORT = 9090;
+ /** Port */
+ public static final int DEFAUTL_PORT = 9090;
- /** Server already launched */
- protected boolean alreadyLaunched = false;
+ /** Server already launched */
+ protected boolean alreadyLaunched = false;
- /**
- * Constructeur.
- *
- * Initialise le serveur.
- *
- * @param port port de lancement du serveur
- */
- public XMLRPCServer(int port) {
- webServer = new WebServer(port);
- XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
+ /**
+ * Constructeur.
+ *
+ * Initialise le serveur.
+ *
+ * @param port port de lancement du serveur
+ */
+ public XMLRPCServer(int port) {
+ webServer = new WebServer(port);
+ XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
- xmlRpcServer.setHandlerMapping(this);
- }
-
- /**
- * Constructeur.
- */
- public XMLRPCServer() {
- this(DEFAUTL_PORT);
- }
+ xmlRpcServer.setHandlerMapping(this);
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.codelutin.topia.service.TopiaServiceServer#addService(java.lang.Class)
- */
- public void addService(Class<? extends TopiaApplicationService> clazz) {
- // dans ce cas, rien
- }
+ /**
+ * Constructeur.
+ */
+ public XMLRPCServer() {
+ this(DEFAUTL_PORT);
+ }
- /**
- * lance le serveur
- */
- public void launch() {
- if (!alreadyLaunched) {
- try {
- webServer.start();
- logger.info("XML-RPC server running...");
- } catch (IOException e) {
- logger.debug("I/O erreur while launching xml-rpc web serveur",
- e);
- }
- alreadyLaunched = true;
- }
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.codelutin.topia.service.TopiaServiceServer#addService(java.lang.Class)
+ */
+ public void addService(Class<? extends TopiaApplicationService> clazz) {
+ // dans ce cas, rien
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.apache.xmlrpc.server.XmlRpcHandlerMapping#getHandler(java.lang.String)
- */
- public XmlRpcHandler getHandler(String className) throws XmlRpcException {
- logger.debug("Request handler for " + className);
- return this;
- }
+ /**
+ * lance le serveur
+ */
+ public void launch() {
+ if (!alreadyLaunched) {
+ try {
+ webServer.start();
+ logger.info("XML-RPC server running...");
+ } catch (IOException e) {
+ logger.debug("I/O erreur while launching xml-rpc web serveur",
+ e);
+ }
+ alreadyLaunched = true;
+ }
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.apache.xmlrpc.XmlRpcHandler#execute(org.apache.xmlrpc.XmlRpcRequest)
- */
- public Object execute(XmlRpcRequest xmlrequest) throws XmlRpcException {
- Object result = null;
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.xmlrpc.server.XmlRpcHandlerMapping#getHandler(java.lang.String)
+ */
+ public XmlRpcHandler getHandler(String className) throws XmlRpcException {
+ logger.debug("Request handler for " + className);
+ return this;
+ }
- // conversion des arguments
- Object[] args = new Object[xmlrequest.getParameterCount()];
- Class[] argsTypes = new Class[xmlrequest.getParameterCount()];
- for (int i = 0; i < xmlrequest.getParameterCount(); ++i) {
- args[i] = xmlrequest.getParameter(i);
- argsTypes[i] = xmlrequest.getParameter(i).getClass();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.xmlrpc.XmlRpcHandler#execute(org.apache.xmlrpc.XmlRpcRequest)
+ */
+ public Object execute(XmlRpcRequest xmlrequest) throws XmlRpcException {
+ Object result = null;
- // conversion class, methode
- String call = xmlrequest.getMethodName();
- String className = call.substring(0, call.lastIndexOf("."));
- String methodName = call.substring(call.lastIndexOf(".") + 1);
+ // conversion des arguments
+ Object[] args = new Object[xmlrequest.getParameterCount()];
+ Class[] argsTypes = new Class[xmlrequest.getParameterCount()];
+ for (int i = 0; i < xmlrequest.getParameterCount(); ++i) {
+ args[i] = xmlrequest.getParameter(i);
+ argsTypes[i] = xmlrequest.getParameter(i).getClass();
+ }
- logger.debug("Receiving request : " + className + "." + methodName
- + "(" + Arrays.toString(args) + ")");
+ // conversion class, methode
+ String call = xmlrequest.getMethodName();
+ String className = call.substring(0, call.lastIndexOf("."));
+ String methodName = call.substring(call.lastIndexOf(".") + 1);
- Class clazz;
- try {
- clazz = Class.forName(className);
- // get method that matches best via commons beanutils
- Method method = MethodUtils.getAccessibleMethod(clazz, methodName,
- argsTypes);
- result = super.invoke(method, args);
- } catch (ClassNotFoundException e) {
- logger.debug("Class " + className + " not found !", e);
- }
+ logger.debug("Receiving request : " + className + "." + methodName
+ + "(" + Arrays.toString(args) + ")");
- // construit et retourne des maps pour les objets complexes qui ne sont
- // pas supportés par XML-RPC
- if (result instanceof List) {
- result = listToMap((List) result);
- } else if (result instanceof TopiaEntity) {
- result = entityToMap((TopiaEntity) result);
- } else if (result instanceof Long) {
- result = Long.toString((Long)result);
- }
+ Class clazz;
+ try {
+ clazz = Class.forName(className);
+ // get method that matches best via commons beanutils
+ Method method = MethodUtils.getAccessibleMethod(clazz, methodName,
+ argsTypes);
+ result = super.invoke(method, args);
+ } catch (ClassNotFoundException e) {
+ logger.debug("Class " + className + " not found !", e);
+ }
- return result;
- }
+ // construit et retourne des maps pour les objets complexes qui ne sont
+ // pas supportés par XML-RPC
+ if (result instanceof List) {
+ result = listToMap((List) result);
+ } else if (result instanceof TopiaEntity) {
+ result = entityToMap((TopiaEntity) result);
+ } else if (result instanceof Long) {
+ result = Long.toString((Long) result);
+ }
- /**
- * Construit et retourne une map de "maps entité", clé : TopiaId de
- * l'entité, valeur : Map de l'entité
- *
- * @see #entityToMap(E entity)
- * @param <E>
- * la classe étendant TopiaEntity
- * @param list
- * la liste de TopiaEntity
- * @return une map contenant les maps clé : TopiaId de l'entité, valeur :
- * Map des champs de l'entité
- */
- private <E extends TopiaEntity> Map listToMap(List<E> list) {
- // construire la map contenant les entités
- // cl� TopiaId, valeur :Map des attributs de l'entité
- Map<String, Map<String, Object>> resultMap = new HashMap<String, Map<String, Object>>();
- for (E entity : list) {
- // ajouter la map de l'entité
- Map<String, Object> entityMap = entityToMap(entity);
- resultMap.put(entity.getTopiaId(), entityMap);
- }
- return resultMap;
- }
+ return result;
+ }
- /**
- * Construit et retourne une map pour l'entité, clé : nom du champ, valeur :
- * contenu du champ (si c'est une entité, on met le TopiaId de celle ci, si
- * c'est une liste d'entités, on met un tableau de TopiaId)
- *
- * @param <E>
- * la classe étendant TopiaEntity
- * @param entity
- * l'entité
- * @return une map
- */
- private <E extends TopiaEntity> Map entityToMap(E entity) {
- Map<String, Object> entityMap = new HashMap<String, Object>();
- // invoquer tous les getters pour construire la map de l'entit�
- for (Method m : entity.getClass().getMethods()) {
- if (m.getName().startsWith("get")) {
- logger.info("* method " + m);
- String attributeName = m.getName().replace("get", "");
- try {
- Object o = m.invoke(entity, null);
- if (o instanceof String && !((String) o).equals("")) {
- // nom de l'attribut : valeur
- entityMap.put(attributeName, (String) o);
+ /**
+ * Construit et retourne une map de "maps entité", clé : TopiaId de
+ * l'entité, valeur : Map de l'entité
+ *
+ * @see #entityToMap(E entity)
+ * @param <E>
+ * la classe étendant TopiaEntity
+ * @param list
+ * la liste de TopiaEntity
+ * @return une map contenant les maps clé : TopiaId de l'entité, valeur :
+ * Map des champs de l'entité
+ */
+ private <E extends TopiaEntity> Map listToMap(List<E> list) {
+ // construire la map contenant les entités
+ // cl� TopiaId, valeur :Map des attributs de l'entité
+ Map<String, Map<String, Object>> resultMap = new HashMap<String, Map<String, Object>>();
+ for (E entity : list) {
+ // ajouter la map de l'entité
+ Map<String, Object> entityMap = entityToMap(entity);
+ resultMap.put(entity.getTopiaId(), entityMap);
+ }
+ return resultMap;
+ }
- } else if (o instanceof Date && o != null) {
- // nom de l'attribut : date
- entityMap.put(attributeName, ((Date) o).toString());
+ /**
+ * Construit et retourne une map pour l'entité, clé : nom du champ, valeur :
+ * contenu du champ (si c'est une entité, on met le TopiaId de celle ci, si
+ * c'est une liste d'entités, on met un tableau de TopiaId)
+ *
+ * @param <E>
+ * la classe étendant TopiaEntity
+ * @param entity
+ * l'entité
+ * @return une map
+ */
+ private <E extends TopiaEntity> Map entityToMap(E entity) {
+ Map<String, Object> entityMap = new HashMap<String, Object>();
+ // invoquer tous les getters pour construire la map de l'entit�
+ for (Method m : entity.getClass().getMethods()) {
+ if (m.getName().startsWith("get")) {
+ logger.info("* method " + m);
+ String attributeName = m.getName().replace("get", "");
+ try {
+ Object o = m.invoke(entity, null);
+ if (o instanceof String && !((String) o).equals("")) {
+ // nom de l'attribut : valeur
+ entityMap.put(attributeName, (String) o);
- } else if (o instanceof TopiaEntity && o != null) {
- // nom de l'attribut : TopiaId
- entityMap.put(attributeName, ((TopiaEntity) o)
- .getTopiaId());
+ } else if (o instanceof Date && o != null) {
+ // nom de l'attribut : date
+ entityMap.put(attributeName, ((Date) o).toString());
- } else if (o instanceof Collection && o != null
- && ((Collection) o).size() > 0) {
- String composite[] = new String[((Collection) o).size()];
- int index = 0;
- for (Object obj : (Collection) o) {
- composite[index++] = ((TopiaEntity) obj)
- .getTopiaId();
- }
- // nom de l'attribut : tableau de TopiaId
- entityMap.put(attributeName, composite);
- }
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- }
- }
- return entityMap;
- }
+ } else if (o instanceof TopiaEntity && o != null) {
+ // nom de l'attribut : TopiaId
+ entityMap.put(attributeName, ((TopiaEntity) o)
+ .getTopiaId());
+
+ } else if (o instanceof Collection && o != null
+ && ((Collection) o).size() > 0) {
+ String composite[] = new String[((Collection) o).size()];
+ int index = 0;
+ for (Object obj : (Collection) o) {
+ composite[index++] = ((TopiaEntity) obj)
+ .getTopiaId();
+ }
+ // nom de l'attribut : tableau de TopiaId
+ entityMap.put(attributeName, composite);
+ }
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return entityMap;
+ }
}
Copied: topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service (from rev 1229, topia/trunk/src/test/java/org/codelutin/topia/service)
Property changes on: topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestService.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/service/TestService.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestService.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -18,6 +18,7 @@
package org.codelutin.topia.service;
import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.service.TopiaApplicationService;
/**
* TestService.java
@@ -31,11 +32,11 @@
*/
public interface TestService extends TopiaApplicationService {
- /**
- * Declaration d'un service
- *
- * @param name
- * le nom
- */
- public String sayHello(String name) throws TopiaException;
+ /**
+ * Declaration d'un service
+ *
+ * @param name
+ * le nom
+ */
+ public String sayHello(String name) throws TopiaException;
}
Modified: topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceImpl.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/service/TestServiceImpl.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceImpl.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -17,6 +17,8 @@
package org.codelutin.topia.service;
+import org.codelutin.topia.service.TopiaApplicationServiceAbstract;
+
/**
* TestServiceImpl.java
*
@@ -28,36 +30,36 @@
* Last update : $Date$ By : $Author$
*/
public class TestServiceImpl extends TopiaApplicationServiceAbstract implements
- TestService {
+ TestService {
- private String prefix;
+ private String prefix;
- private static int nb = 0;
+ private static int nb = 0;
- /**
- *
- * @param prefix
- */
- public TestServiceImpl() {
- this.prefix = "Salut";
- nb = nb + 1;
- }
+ /**
+ *
+ * @param prefix
+ */
+ public TestServiceImpl() {
+ this.prefix = "Salut";
+ nb = nb + 1;
+ }
- /**
- *
- * @param prefix
- */
- public TestServiceImpl(String prefix) {
- this();
- this.prefix = prefix;
- }
+ /**
+ *
+ * @param prefix
+ */
+ public TestServiceImpl(String prefix) {
+ this();
+ this.prefix = prefix;
+ }
- /*
- * (non-Javadoc)
- *
- * @see service.TestService#sayHello(java.lang.String)
- */
- public String sayHello(String name) {
- return prefix + " " + name + " (instance " + nb + ")";
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see service.TestService#sayHello(java.lang.String)
+ */
+ public String sayHello(String name) {
+ return prefix + " " + name + " (instance " + nb + ")";
+ }
}
Modified: topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceServer.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/service/TestServiceServer.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceServer.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -19,6 +19,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.service.Protocol;
+import org.codelutin.topia.service.TopiaApplicationServiceFactory;
/**
* TopiaServiceServer.java
@@ -33,26 +35,26 @@
*/
public class TestServiceServer {
- /** Logger (common logging) */
- private static final Log logger = LogFactory
- .getLog(TestServiceServer.class);
+ /** Logger (common logging) */
+ private static final Log logger = LogFactory
+ .getLog(TestServiceServer.class);
- /**
- * Main. Demarre les serveurs.
- *
- * @param args
- * arguments
- */
- public static void main(String args[]) {
-
- // TestService ts = new TestServiceImpl("Bonjour");
- // TopiaServiceFactory.addService(TestService.class, ts ,
- // Protocole.XML_RPC);
- //TopiaServiceFactory.addService(TestService.class,
- // TestServiceImpl.class, Protocole.XML_RPC);
- TopiaApplicationServiceFactory.addService(TestService.class,
- TestServiceImpl.class, Protocol.SOAP);
+ /**
+ * Main. Demarre les serveurs.
+ *
+ * @param args
+ * arguments
+ */
+ public static void main(String args[]) {
- logger.info("Service TestService added...");
- }
+ // TestService ts = new TestServiceImpl("Bonjour");
+ // TopiaServiceFactory.addService(TestService.class, ts ,
+ // Protocole.XML_RPC);
+ //TopiaServiceFactory.addService(TestService.class,
+ // TestServiceImpl.class, Protocole.XML_RPC);
+ TopiaApplicationServiceFactory.addService(TestService.class,
+ TestServiceImpl.class, Protocol.SOAP);
+
+ logger.info("Service TestService added...");
+ }
}
Modified: topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceTestCase.java
===================================================================
--- topia/trunk/src/test/java/org/codelutin/topia/service/TestServiceTestCase.java 2008-11-17 09:55:30 UTC (rev 1229)
+++ topia/trunk/topia-soa/src/test/java/org/codelutin/topia/service/TestServiceTestCase.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -21,6 +21,7 @@
import org.codelutin.topia.TopiaException;
import org.codelutin.topia.TopiaNotFoundException;
+import org.codelutin.topia.service.TopiaApplicationServiceFactory;
/**
* TestServiceTestCase.java
@@ -37,30 +38,31 @@
*/
public class TestServiceTestCase extends TestCase {
- /**
- * Test de la methode say hello
- */
- public void testSayHello() {
+ /**
+ * Test de la methode say hello
+ */
+ public void testSayHello() {
- String reponse = null;
+ String reponse = null;
- TestService testService;
- try {
- testService = TopiaApplicationServiceFactory.getService(TestService.class);
+ TestService testService;
+ try {
+ testService = TopiaApplicationServiceFactory
+ .getService(TestService.class);
- String myName = "eric";
+ String myName = "eric";
- reponse = testService.sayHello(myName);
+ reponse = testService.sayHello(myName);
- System.out.println("TestService says : " + reponse);
- } catch (TopiaNotFoundException e) {
- System.err
- .println("TopiaNotFoundException: erreur du fichier de configuration");
- } catch (TopiaException e) {
- System.err
- .println("TopiaException: impossible d'instancier le service");
- }
+ System.out.println("TestService says : " + reponse);
+ } catch (TopiaNotFoundException e) {
+ System.err
+ .println("TopiaNotFoundException: erreur du fichier de configuration");
+ } catch (TopiaException e) {
+ System.err
+ .println("TopiaException: impossible d'instancier le service");
+ }
- assertNotNull(reponse);
- }
+ assertNotNull(reponse);
+ }
}
Added: topia/trunk/topia-soa/src/test/log4j.properties
===================================================================
--- topia/trunk/topia-soa/src/test/log4j.properties (rev 0)
+++ topia/trunk/topia-soa/src/test/log4j.properties 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,9 @@
+# Global logging configuration
+log4j.rootLogger=INFO, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+# package level
+log4j.logger.org.codelutin.topia=INFO
+log4j.logger.org.hibernate=INFO
Copied: topia/trunk/topia-soa/src/test/resources/TopiaApplicationServices.properties (from rev 1229, topia/trunk/src/test/resources/TopiaApplicationServices.properties)
===================================================================
--- topia/trunk/topia-soa/src/test/resources/TopiaApplicationServices.properties (rev 0)
+++ topia/trunk/topia-soa/src/test/resources/TopiaApplicationServices.properties 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,6 @@
+# test du fichier de definition des services
+#topia.application.service.org.codelutin.topia.service.TestService=local://org.codelutin.topia.service.TestServiceImpl/#new
+#topia.application.service.org.codelutin.topia.service.TestService=rmi://localhost:1099
+#topia.application.service.org.codelutin.topia.service.TestService=xml-rpc://localhost:9090
+#topia.application.service.org.codelutin.topia.service.TestService=rmi://localhost:1099
+topia.application.service.org.codelutin.topia.service.TestService=soap://localhost:8888
\ No newline at end of file
Property changes on: topia/trunk/topia-soa/src/test/resources/TopiaApplicationServices.properties
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Property changes on: topia/trunk/topia-ui
___________________________________________________________________
Name: svn:ignore
+ .settings
target
.classpath
.project
Added: topia/trunk/topia-ui/LICENSE.txt
===================================================================
--- topia/trunk/topia-ui/LICENSE.txt (rev 0)
+++ topia/trunk/topia-ui/LICENSE.txt 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Added: topia/trunk/topia-ui/pom.xml
===================================================================
--- topia/trunk/topia-ui/pom.xml (rev 0)
+++ topia/trunk/topia-ui/pom.xml 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.codelutin</groupId>
+ <artifactId>topia</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.codelutin.topia</groupId>
+ <artifactId>topia-ui</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>tapestry-core</artifactId>
+ <version>5.0.7</version>
+ <scope>compile</scope>
+ </dependency>
+
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>ToPIA - UI</name>
+ <description>User interface module</description>
+ <inceptionYear>2004</inceptionYear>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
+ </scm>
+
+</project>
Copied: topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java (from rev 1229, topia/trunk/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java)
===================================================================
--- topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java (rev 0)
+++ topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,612 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.topia.generator;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.generator.MonitorWriter;
+import org.codelutin.generator.StateModelGenerator;
+import org.codelutin.generator.Util;
+import org.codelutin.generator.models.state.StateModel;
+import org.codelutin.generator.models.state.StateModelComplexState;
+import org.codelutin.generator.models.state.StateModelSimpleState;
+import org.codelutin.generator.models.state.StateModelState;
+import org.codelutin.generator.models.state.StateModelStateChart;
+import org.codelutin.generator.models.state.StateModelTransition;
+
+/**
+ * Genere la navigation basee sur le framework Tapestry 5
+ * a partir de la representation StateModel
+ *
+ * @see org.codelutin.generator.StateModelGenerator
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class TapestryWebGenerator extends StateModelGenerator {
+
+ /** logger */
+ private static final Log log = LogFactory.getLog(TapestryWebGenerator.class);
+
+ /** Already asssigned use case states names */
+ protected List<String> assignedUseCaseStateNames;
+
+ protected StateModel model;
+
+ /**
+ * Default Constructeur
+ */
+ public TapestryWebGenerator() {
+ assignedUseCaseStateNames = new ArrayList<String>();
+ }
+
+ /**
+ * Redefintion pour une generation specifique tapestry
+ *
+ * @param stateModel Le modele d'état
+ * @param destDir le dossier de destination
+ */
+ @Override
+ public void generate(StateModel stateModel, File destDir) throws IOException {
+
+ this.model = stateModel;
+
+ // pour tous les diagramme du model
+ for (StateModelStateChart chart : stateModel.getStateCharts()) {
+ generate(chart,chart.getStates(),destDir);
+
+ // generate use case engine
+ generateUseCaseEngineFromModel(stateModel, chart,destDir);
+ }
+ }
+
+ /**
+ * Appele par lutin generator pour tous les etats du model
+ * @param chart
+ * @return filename
+ */
+ protected String getFilenameFromState(StateModelStateChart chart,StateModelState state) {
+ return (getPackageFromState(chart) + '.' + getNameFromState(state)).replace('.',
+ File.separatorChar) + ".java";
+ }
+
+ /**
+ * Get generated class name from state
+ *
+ * Prefix it with "Abstract"
+ *
+ * @param state state
+ * @return name
+ */
+ protected String getNameFromState(StateModelState state) {
+ return "Abstract" + Util.toUpperCaseFirstLetter(state.getName());
+ }
+
+ /**
+ * Return specifique tapestry package name.
+ *
+ * Detect "web" patern and replace it with "web.pages".
+ *
+ * @param chart the chart
+ * @return a tapestry package name
+ */
+ protected String getPackageFromState(StateModelStateChart chart) {
+ return chart.getPackageName().replaceFirst("web", "web.pages");
+ }
+
+ /**
+ * Return specifique tapestry package name (base)
+ *
+ * Detect "web.*" patern and replace it with "web.base"
+ * Component are placed into "base" directory
+ *
+ * @param chart the chart
+ * @return a tapestry package name
+ */
+ protected String getPackageFromComponents(StateModelStateChart chart) {
+ return chart.getPackageName().replaceFirst("web.*", "web.base");
+ }
+
+ /**
+ * Generate a collection of states
+ *
+ * @param chart the chart
+ * @param states states collection
+ * @throws IOException
+ */
+ protected void generate(StateModelStateChart chart, Collection<StateModelState> states, File destDir) throws IOException {
+
+ // et tous les états de ces diagrammes
+ for (Object oState : states.toArray()) {
+ generateFromState(chart,(StateModelState)oState,destDir);
+ }
+ }
+
+ /**
+ * Generate a state.
+ *
+ * This state can be complexe, so the method is recusively called.
+ *
+ * @param chart the parent chart
+ * @param state the current state
+ * @throws IOException
+ */
+ protected void generateFromState(StateModelStateChart chart, StateModelState state, File destDir) throws IOException {
+
+ // complexe
+ if(state.isComplex()) {
+ StateModelComplexState complexeState = (StateModelComplexState)state;
+ generate(chart,complexeState.getStates(), destDir);
+ }
+ // simple
+ else {
+
+ StateModelSimpleState simpleState = (StateModelSimpleState)state;
+
+ // les etat initiaux et finaux ne donne pas
+ // pas de generation de fichier
+ if(!simpleState.isFinal() && !simpleState.isInitial()) {
+
+ String filename = getFilenameFromState(chart, simpleState);
+ File outputFile = getDestinationFile(destDir, filename);
+ if (getOverwrite() || !isNewerThanSource(outputFile)) {
+ try {
+ StringWriter out = new StringWriter();
+ MonitorWriter monitorOut = new MonitorWriter(out);
+ generateFromSimpleState(monitorOut, chart, simpleState);
+ write(outputFile, monitorOut);
+ } catch (Exception eee) {
+ log.warn("Erreur lors de la génération du fichier "
+ + outputFile);
+ throw new RuntimeException(
+ "Erreur lors de la génération du fichier "
+ + outputFile, eee);
+ }
+ }
+ } // init && final
+ }
+ }
+
+ /**
+ * Called for each simple state
+ *
+ * @param output writer out
+ * @param chart chart
+ * @param state simple state
+ * @throws IOException
+ */
+ protected void generateFromSimpleState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
+ //String copyright = GeneratorUtil.getCopyright(model);
+ String copyright = model.getTagValue("copyright");
+ if (copyright != null && !copyright.isEmpty()) {
+/*{<%=copyright%>
+}*/
+ }
+/*{// Automatically generated by LutinGenerator
+package <%=getPackageFromState(chart)%>;
+
+import org.apache.tapestry.annotations.InjectPage;
+import <%=getPackageFromComponents(chart)%>.UseCasePage;
+
+/*
+ * State <%=getNameFromState(state)%>
+ *)
+public abstract class <%=getNameFromState(state)%> extends UseCasePage {
+}*/
+
+ // generate events
+ generateInjectionAndEventsFromState(output,chart,state);
+
+ // generate use case name
+ generateUseCaseNameFromState(output,chart,state);
+/*{}}*/
+ }
+
+ /**
+ * Generate state injections
+ * @param output
+ * @param chart
+ * @param state
+ */
+ @SuppressWarnings("unused")
+ protected void generateInjectionAndEventsFromState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
+
+ // liste les états de destination (pour éviter les doublons)
+ List<StateModelState> destStates = new ArrayList<StateModelState>();
+
+ for(StateModelTransition transition : state.getTransitions()) {
+
+ StateModelState toState = transition.getDestinationState();
+
+ if(toState.isComplex()) {
+ StateModelState toInitState = ((StateModelComplexState)toState).getInitialState();
+
+ // l'attribute doit etre private
+ // sinon tapestry ne le traite pas
+
+ // si l'état de destination n'a pas encore été traité
+ if(!destStates.contains(toState)){
+ destStates.add(toState);
+/*{
+ /* linked state "<%=toState.getName()%>" *)
+ @InjectPage
+ private <%=Util.toUpperCaseFirstLetter(toInitState.getName())%> <%=Util.toLowerCaseFirstLetter(toInitState.getName())%>;
+}*/
+ // l'attribut etant prive, il faut un getter
+/*{
+ /* getter for state "<%=toState.getName()%>" *)
+ protected <%=Util.toUpperCaseFirstLetter(toInitState.getName())%> get<%=Util.toUpperCaseFirstLetter(toInitState.getName())%>() {
+ return <%=Util.toLowerCaseFirstLetter(toInitState.getName())%>;
+ }
+}*/
+ }
+/*{
+ /* transition on <%=transition.getEvent()%> event *)
+ public Object onActionFrom<%=Util.toUpperCaseFirstLetter(transition.getEvent())%>() {
+ enterUseCase();
+ return <%=Util.toLowerCaseFirstLetter(toInitState.getName())%>;
+ }
+}*/
+ }
+ else {
+
+ StateModelSimpleState simpleToState = (StateModelSimpleState)toState;
+
+ // si l'etat a injecter n'est pas final
+ if(!simpleToState.isFinal()) {
+
+ // si l'état de destination n'a pas encore été traité
+ if(!destStates.contains(toState)){
+ destStates.add(toState);
+/*{
+ /* linked state "<%=simpleToState.getName()%>" *)
+ @InjectPage
+ private <%=Util.toUpperCaseFirstLetter(simpleToState.getName())%> <%=Util.toLowerCaseFirstLetter(simpleToState.getName())%>;
+}*/
+ // l'attribut etant prive, il faut un getter
+/*{
+ /* getter for state "<%=simpleToState.getName()%>" *)
+ protected <%=Util.toUpperCaseFirstLetter(simpleToState.getName())%> get<%=Util.toUpperCaseFirstLetter(simpleToState.getName())%>() {
+ return <%=Util.toLowerCaseFirstLetter(simpleToState.getName())%>;
+ }
+}*/
+ }
+ } // isFinal
+/*{
+ /* transition on "<%=transition.getEvent()%>" event *)
+ public Object onActionFrom<%=Util.toUpperCaseFirstLetter(transition.getEvent())%>() {
+}*/
+ if(simpleToState.isFinal()) {
+/*{ return leaveUseCase();
+}*/
+ } else {
+/*{ return <%=Util.toLowerCaseFirstLetter(simpleToState.getName())%>;
+}*/
+ }
+/*{ }
+}*/
+ }
+ }
+ }
+
+ /**
+ * Generate use case name
+ *
+ * @param output
+ * @param chart
+ * @param state
+ */
+ protected void generateUseCaseNameFromState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
+
+ String stateId = generateStateUseCaseName(state.getName());
+/*{
+ /* return a unique state id for model *)
+ protected final String getUseCaseName() {
+ return "<%=stateId%>";
+ }
+}*/
+ }
+
+ /**
+ * Genere un nom unique d'etat pour le model courant.
+ *
+ * Pour des raisons de debugage, on utilise des lettres particuliere du
+ * nom de l'etat, suivit d'un numero, s'il y a collision.
+ *
+ * @return a unique name
+ */
+ protected String generateStateUseCaseName(String name) {
+
+ String ucsn = getHashStateName(name);
+
+ // test already assigned
+ String uniqueucsn = ucsn;
+ int num = 2;
+ while(assignedUseCaseStateNames.contains(uniqueucsn)) {
+ uniqueucsn = new StringBuffer(ucsn).append(num++).toString();
+ }
+
+ assignedUseCaseStateNames.add(uniqueucsn);
+
+ return uniqueucsn;
+ }
+
+ /**
+ * Hash a state name.
+ *
+ * On prend la premiere lettre de chaque mot.
+ *
+ * ContactList -> cl
+ * contactList -> cl
+ * ContactListPage -> clp
+ *
+ * @param name
+ * @return
+ */
+ protected String getHashStateName(String name) {
+
+ // bug si moins de 1 caractere
+ if(name == null || name.length()<1) return name;
+
+ StringBuffer sb = new StringBuffer();
+
+ // on prend la premiere lettre
+ sb.append(Character.toLowerCase(name.charAt(0)));
+
+ // ensuite, on prend les majuscules
+ for(int i = 1 ; i < name.length() ; ++i) {
+
+ // si maj
+ if(Character.isUpperCase(name.charAt(i))) {
+ sb.append(Character.toLowerCase(name.charAt(i)));
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Generate the engine use case class.
+ *
+ * Need to be generated inside client webapp directory to be analysed by
+ * tapestry (annotations)
+ *
+ * @param model model
+ * @param chart chart
+ */
+ protected void generateUseCaseEngineFromModel(StateModel model,StateModelStateChart chart,File destDir) throws IOException {
+ String componentPackageName = getPackageFromComponents(chart);
+
+ // UseCasePage
+ String filename = (componentPackageName + ".UseCasePage").replace('.', File.separatorChar) + ".java";
+ File outputFile = getDestinationFile(destDir, filename);
+ if (getOverwrite() || !isNewerThanSource(outputFile)) {
+ try {
+ StringWriter out = new StringWriter();
+ MonitorWriter monitorOut = new MonitorWriter(out);
+ // generate UseCasePage class
+ generateUseCasePageClass(monitorOut,model,componentPackageName);
+ write(outputFile, monitorOut);
+ } catch (Exception e) {
+ log.warn("Erreur lors de la génération du fichier UseCasePage",e);
+ throw new RuntimeException(
+ "Erreur lors de la génération du fichier UseCasePage", e);
+ }
+ }
+
+ // UseCaseMap
+ filename = (componentPackageName + ".UseCaseMap").replace('.', File.separatorChar) + ".java";
+ outputFile = getDestinationFile(destDir, filename);
+ if (getOverwrite() || !isNewerThanSource(outputFile)) {
+ try {
+ StringWriter out = new StringWriter();
+ MonitorWriter monitorOut = new MonitorWriter(out);
+ // generate UseCasePage class
+ generateUseCaseMapClass(monitorOut,componentPackageName);
+ write(outputFile, monitorOut);
+ } catch (Exception e) {
+ log.warn("Erreur lors de la génération du fichier UseCaseMap",e);
+ throw new RuntimeException(
+ "Erreur lors de la génération du fichier UseCaseMap", e);
+ }
+ }
+ }
+
+ /**
+ * Generate base.UseCasePage class
+ * @param output
+ * @param componentPackageName
+ */
+ private void generateUseCasePageClass(MonitorWriter output, StateModel model, String componentPackageName) throws IOException {
+/*{package <%=componentPackageName%>;
+
+import org.apache.tapestry.Link;
+import org.apache.tapestry.annotations.ApplicationState;
+import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.annotations.Service;
+import org.apache.tapestry.internal.services.LinkFactory;
+import org.apache.tapestry.internal.services.LinkFactoryListener;
+import org.apache.tapestry.services.Request;
+
+public abstract class UseCasePage}*/
+
+ // ajoute un heritage si il a ete specifie dans un fichier de propriete
+ Map<String,String> tagValues = model.getTagValues();
+ if(tagValues != null) {
+ String tagUseCaseEngineExtendedClass = tagValues.get("usecaseengineextendedclass");
+ if(tagUseCaseEngineExtendedClass != null) {
+ /*{ extends <%=tagUseCaseEngineExtendedClass%>}*/
+ }
+ }
+
+/*{ implements LinkFactoryListener {
+
+ private static final String UC_PARAMETER_NAME = "UC";
+ private static final String UC_PARAMETER_SEPARATOR = ":";
+
+ @ApplicationState
+ private UseCaseMap useCaseManager;
+ private boolean useCaseManagerExists;
+
+ @Inject
+ @Service("LinkFactory")
+ private LinkFactory _linkFactory;
+
+ @Inject
+ @Service("Request")
+ private Request _request;
+
+ private String UCName;
+
+ public void onActivate() {
+ _linkFactory.addListener(this);
+
+ UCName = _request.getParameter(UC_PARAMETER_NAME);
+ }
+
+ protected abstract String getUseCaseName();
+
+ /**
+ * Create stack if not exists
+ *)
+ protected void init() {
+ if(!useCaseManagerExists) {
+ useCaseManager = new UseCaseMap();
+ }
+ }
+ /**
+ * Enter in a new sub use case
+ *)
+ protected void enterUseCase() {
+ init();
+ // current
+ String currentUCN = UCName;
+ // new
+ UCName = (currentUCN == null) ? getUseCaseName() : currentUCN + UC_PARAMETER_SEPARATOR + getUseCaseName();
+ useCaseManager.enterSubUseCase(UCName, currentUCN, this);
+ }
+
+ /**
+ * Leave a sub use case
+ *)
+ protected UseCasePage leaveUseCase() {
+ init();
+
+ UseCasePage nextPage = null;
+
+ // current UCN
+ String UC = UCName;
+
+ // get state
+ Object[] response = useCaseManager.leaveUseCase(UC);
+
+ // if null, return null, don't change page
+ if(response != null) {
+ // get UCN before enter this one
+ UCName = (String) response[0];
+
+ nextPage = (UseCasePage) response[1];
+ }
+
+ return nextPage;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.tapestry.internal.services.LinkFactoryListener#createdActionLink(org.apache.tapestry.Link)
+ *)
+ public void createdActionLink(Link _link) {
+ addUCParameter(_link);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.tapestry.internal.services.LinkFactoryListener#createdPageLink(org.apache.tapestry.Link)
+ *)
+ public void createdPageLink(Link _link) {
+ // PageLink englobe ausssi les redirects envoyés au client apres une
+ // action
+ addUCParameter(_link);
+ }
+
+ protected void addUCParameter(Link _link) {
+ if(_link.getParameterValue(UC_PARAMETER_NAME) == null) {
+
+ if(UCName != null) {
+ _link.addParameter(UC_PARAMETER_NAME, UCName);
+ }
+ }
+ }
+}
+}*/
+ }
+
+ /**
+ * Generate base.UseCaseMap class
+ * @param output
+ * @param componentPackageName
+ */
+ private void generateUseCaseMapClass(MonitorWriter output, String componentPackageName) throws IOException {
+/*{package <%=componentPackageName%>;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class UseCaseMap {
+
+ /**
+ * Map (state name -> state instance)
+ *)
+ private Map<String,Object[]> mapUseCase;
+
+ /**
+ * Constructor
+ *)
+ public UseCaseMap () {
+ mapUseCase = new HashMap<String,Object[]>();
+ }
+
+ /**
+ * New sub use case
+ *)
+ public void enterSubUseCase(String newUseCaseName, String previousUseCaseName, Object state) {
+ mapUseCase.put(newUseCaseName,new Object[]{previousUseCaseName,state});
+ }
+
+ /**
+ * Finish a subusecase
+ *
+ * Return the state that init the subuse case
+ * @return a state
+ *)
+ public Object[] leaveUseCase(String useCaseName) {
+ return mapUseCase.get(useCaseName);
+ }
+}
+}*/
+ }
+}
Property changes on: topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Added: topia/trunk/topia-ui/src/test/resources/log4j.properties
===================================================================
--- topia/trunk/topia-ui/src/test/resources/log4j.properties (rev 0)
+++ topia/trunk/topia-ui/src/test/resources/log4j.properties 2008-11-18 14:11:07 UTC (rev 1230)
@@ -0,0 +1,9 @@
+# Global logging configuration
+log4j.rootLogger=INFO, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+# package level
+log4j.logger.org.codelutin.topia=INFO
+log4j.logger.org.hibernate=INFO
1
0
Author: chemit
Date: 2008-11-17 09:55:30 +0000 (Mon, 17 Nov 2008)
New Revision: 1229
Modified:
topia/trunk/pom.xml
Log:
push back scm generic values after release
Modified: topia/trunk/pom.xml
===================================================================
--- topia/trunk/pom.xml 2008-11-17 09:39:45 UTC (rev 1228)
+++ topia/trunk/pom.xml 2008-11-17 09:55:30 UTC (rev 1229)
@@ -199,9 +199,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/trunk/?ro…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
</project>
1
0
Author: tchemit
Date: 2008-11-17 09:39:45 +0000 (Mon, 17 Nov 2008)
New Revision: 1228
Modified:
topia/trunk/pom.xml
Log:
[maven-release-plugin] prepare for next development iteration
Modified: topia/trunk/pom.xml
===================================================================
--- topia/trunk/pom.xml 2008-11-17 09:39:40 UTC (rev 1227)
+++ topia/trunk/pom.xml 2008-11-17 09:39:45 UTC (rev 1228)
@@ -136,7 +136,7 @@
<!-- ************************************************************* -->
<name>ToPIA - Tools for Portable and Independent Architecture</name>
- <version>2.0.29</version>
+ <version>2.0.30-SNAPSHOT</version>
<description>Framework de persistance et de distribution d'application.</description>
<inceptionYear>2004</inceptionYear>
@@ -199,9 +199,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.0.29</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.0.29</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.0.…</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/trunk</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/trunk</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/trunk/?ro…</url>
</scm>
</project>
1
0
r1227 - in topia/tags: . 2.0.29 2.0.29/src/main/java/org/codelutin/topia/generator 2.0.29/src/main/java/org/codelutin/topia/persistence 2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile 2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate
by tchemit@users.labs.libre-entreprise.org 17 Nov '08
by tchemit@users.labs.libre-entreprise.org 17 Nov '08
17 Nov '08
Author: tchemit
Date: 2008-11-17 09:39:40 +0000 (Mon, 17 Nov 2008)
New Revision: 1227
Added:
topia/tags/2.0.29/
topia/tags/2.0.29/changelog
topia/tags/2.0.29/pom.xml
topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java
Removed:
topia/tags/2.0.29/changelog
topia/tags/2.0.29/pom.xml
topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java
topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java
Log:
[maven-release-plugin] copy for tag 2.0.29
Copied: topia/tags/2.0.29 (from rev 1223, topia/trunk)
Deleted: topia/tags/2.0.29/changelog
===================================================================
--- topia/trunk/changelog 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/changelog 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,146 +0,0 @@
-ver-2-0-28 ?? 2008??
- * 20081113 [chorlet] add support for lazy loading on attribute with 0..* multiplicity
- * 20081113 [chorlet] fix bug on bidirectional association by adding inverse attribute in the one side of two hibernate mapping files
- * 20081107 [chatellier] fix "result" named attribute generation in model
- * 20081107 [chatellier] fix ant:ant, org.apache.ant:ant conflict
- * 20081107 [chatellier] set lutingenerator provided scope
- * 20081101 [chemit] bump lutingenerator to 0.61
- * 20081101 [chemit] add a EntityEnum to have a generic way to access Entities.
- * 20081101 [chemit] improve generators :
- - can exclude some generators on TopiaMetaGenerator
- - refactor TopiaMetaGenerator to use a simple List of Generator to launch
- - refactor Generators to have a default public constructor
-
- * 20081029 [chemit] fix infinitive recursion on method findByPrimaryKey and findByProperty in TopiaDAODeleagtor class
- * 20081026 [chemit] add dbName of table if explicit in javadoc
- * 20081024 [chemit] fix bug when no entity defined in model
-
-ver-2-0-27 chemit 20081021
- * 20081021 [chemit] clean pom, use lutingenerator 0.60
- * 20080922 [thimel] Switched to lutinproject 3.0
- * 20080922 [thimel] Sources are correctly maven2 structuted (src/main/xxx)
- * 20080922 [thimel] Fixed maven-processor-plugin usage
- * 20080922 [thimel] License switched to LGPL
-
-ver-2-0-26 thimel 20080922
- * 20080922 [thimel] Last version with lutinproject 2.2
- * 20082608 [chemit] permettre de recuperer uniquement une fenetre de resultat en hql (TopiaContext#find(String hql,int startIndex,int endIndex, Object ... args)
- * 20082907 [chemit] Suppression des dependances en dur sur les implantations d'entites
- * 20072012 [thimel] Support des index sur les attibuts
- * 20072012 [ruchaud] Récupération des classes persistées
- * 20072012 [ruchaud] Création d'un vetoable sur les finds
-
-ver-2-0-25 poussin 20071214
-
- * 20071120 [chatellier] modify service init methods, return boolean to stay
- activated
- * 20071116 [chatellier] add support for topia context listeners
- * 20071114 [chatellier] add support for service without persitent classes
- * 20071109 [chatellier] add type="string" on topiaId in templates
- - update hibernate version to 3.2.5.ga (event patch)
- - jetty version 5.1.10 (better pom.xml)
- * 20071001 [chatellier] move tapestry version to 5.0.5
- * 20070528 [chatellier] add stateModel generation support
- - tapestry generation templates
- - tapestry 5.0.4 dependency
-
- * 20071106 [poussin] add removeContext on TopiaContextFactory and call it
- in TopiaContextImpl.closeContext().
-
- * 20071107 [thimel] add db schema support
- * 20071107 [thimel] several .hbm.xml refactoring
- * 20071108 [thimel] add DTO generator
- * 20071108 [thimel] add copyright support in generators
- * 20071108 [thimel] add serialVersionUID support in EntityAbstractGenerator
-
-ver-2-0-24 poussin 20070425
-
- * 20070420 [chatellier] add services interfaces generation (stereotype=service)
- * 20070420 [chatellier] add topia services support
- * 20070330 [poussin] TopiaContextFactory return new TopiaContext if context is closed
- * 20070331 [poussin] change many string argument to class argument
- * 20070331 [poussin] add getService(Class) method on TopiaContext
- * 20070331 [poussin] remove helper in service that only return service instant
- * 20070331 [poussin] add Devel.rst documentation
- * 20070402 [poussin] replace init to preInit and postInit in TopiaService
-
-ver-2-0-22 ruchaud 20061023
-
- * 20061023 [ruchaud][improve] manage events
- * 20061023 [ruchaud][bug fix] in generator of DAO Abstract on delete
-
-ver-2-0-21 poussin 20061019
-
- * add support for auto-import entities for hql
- * add getComposite and getAggregate on TopiaEntity
- * bug fix for association hibernate mapping wit have attributeh
- cascade="delete" for not navigable link to prevent constraint exception
- * bug fix in delete, remove link before do delete
-
-ver-2-0-20 poussin 20061017
-
- * add support for TopiaService mechanisme
-
-ver-2-0-16 poussin 20060907
-
- * Implantation des méthodes update et delete sur les TopiaUserImpl et TopiaEntityPermissionImpl
- * add backup/restore method on TopiaContext (backup only works for h2)
- * TopiaContext is set in Entity during preload
- * add updateSchema in TopiaContext interface
- * add methods update et delete on TopiaUserImpl and TopiaEntityPermissionImpl
-
-ver-2-0-13 thimel 20060822
-
- * [Secu] ajout d'un champ notes sur les TopiaUser
- * [Secu] ajout d'un champ linkApplication sur les TopiaUser (permettant de faire le lien avec une application externe)
- * [Secu] ajout de commits et rollbacks sur les Manager
- * [Secu] ajout d'un setPassword (sans verification ancien mdp) sur les TopiaUser
-
-ver-2-0-12 thimel 20060721
-
- * ajout des projections sur les DAO
- * positionnement unique des userManager et permissionManager au niveau du contexte racine
- * ajout de la possibilite de tester des permissions sur le permissionManager
-
-ver-2-0-11 thimel 20060703
-
- * support de la fermeture d'un contexte
- * support de la recherche sur tous les attributs d'une entite / annotation sur les interfaces
-
-ver-2-0-8 thimel 20060606
-
- * amelioration detection des classes abstraites
- * correction du polymorphisme avec les proxies d'Hibernate
- * Hibernate 3.2
-
-ver-2-0-7 thimel 20060523
-
- * import/export XML "experimental"
- * one-to-one transformes en many-to-one + unique="true"
- * bug au niveau de la detection des parents abstract
-
-ver-2-0-6 thimel 20060504
-
- * support des annotations sur les attributs des XXXAbstract
- * re-correction du support des relations unidirectionnelles 1-n avec classes d'heritage du cote n
- * ajout de la validation pour les attributs sans inverses (pour les objectmodel faits a la main)
-
-ver-2-0-5 thimel 20060427
-
- * isIndexed remplace isOrdered dans le mapping hibernate
- * add postCreate and postLoad on AbstractTopiaEntity
- * findContains sur les DAO (implante hors Hibernate pour l'instant)
- * support plus coherent des classes abstraites
- * projet compatible maven2
- * correction du support des relations unidirectionnelles 1-n avec classes d'heritage du cote n
-
-ver-2-0-4 thimel 20060303
-
- * Correction du support des interfaces et classes abstraites (conjointement a LutinGenerator 0.30)
- * Ajout des exceptions sur le operations (conjointement a LutinGenerator 0.30)
-
-ver-2-0-3 thimel 20060228
-
- * Correction du support des classes d'associations (mauvais mapping Hibernate)
- * Support de super classes pour les classes d'association (LutinGenerator 0.29)
-
Copied: topia/tags/2.0.29/changelog (from rev 1225, topia/trunk/changelog)
===================================================================
--- topia/tags/2.0.29/changelog (rev 0)
+++ topia/tags/2.0.29/changelog 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,149 @@
+ver-2-0-29 chatellier 20081117
+ * 20081117 [chemit] improve EntityEnum
+ * 20081117 [chemit] add method findAllWithOrder in DAO to make have sorted lists
+ver-2-0-28 chatellier 20081114
+ * 20081113 [chorlet] add support for lazy loading on attribute with 0..* multiplicity
+ * 20081113 [chorlet] fix bug on bidirectional association by adding inverse attribute in the one side of two hibernate mapping files
+ * 20081107 [chatellier] fix "result" named attribute generation in model
+ * 20081107 [chatellier] fix ant:ant, org.apache.ant:ant conflict
+ * 20081107 [chatellier] set lutingenerator provided scope
+ * 20081101 [chemit] bump lutingenerator to 0.61
+ * 20081101 [chemit] add a EntityEnum to have a generic way to access Entities.
+ * 20081101 [chemit] improve generators :
+ - can exclude some generators on TopiaMetaGenerator
+ - refactor TopiaMetaGenerator to use a simple List of Generator to launch
+ - refactor Generators to have a default public constructor
+
+ * 20081029 [chemit] fix infinitive recursion on method findByPrimaryKey and findByProperty in TopiaDAODeleagtor class
+ * 20081026 [chemit] add dbName of table if explicit in javadoc
+ * 20081024 [chemit] fix bug when no entity defined in model
+
+ver-2-0-27 chemit 20081021
+ * 20081021 [chemit] clean pom, use lutingenerator 0.60
+ * 20080922 [thimel] Switched to lutinproject 3.0
+ * 20080922 [thimel] Sources are correctly maven2 structuted (src/main/xxx)
+ * 20080922 [thimel] Fixed maven-processor-plugin usage
+ * 20080922 [thimel] License switched to LGPL
+
+ver-2-0-26 thimel 20080922
+ * 20080922 [thimel] Last version with lutinproject 2.2
+ * 20082608 [chemit] permettre de recuperer uniquement une fenetre de resultat en hql (TopiaContext#find(String hql,int startIndex,int endIndex, Object ... args)
+ * 20082907 [chemit] Suppression des dependances en dur sur les implantations d'entites
+ * 20072012 [thimel] Support des index sur les attibuts
+ * 20072012 [ruchaud] Récupération des classes persistées
+ * 20072012 [ruchaud] Création d'un vetoable sur les finds
+
+ver-2-0-25 poussin 20071214
+
+ * 20071120 [chatellier] modify service init methods, return boolean to stay
+ activated
+ * 20071116 [chatellier] add support for topia context listeners
+ * 20071114 [chatellier] add support for service without persitent classes
+ * 20071109 [chatellier] add type="string" on topiaId in templates
+ - update hibernate version to 3.2.5.ga (event patch)
+ - jetty version 5.1.10 (better pom.xml)
+ * 20071001 [chatellier] move tapestry version to 5.0.5
+ * 20070528 [chatellier] add stateModel generation support
+ - tapestry generation templates
+ - tapestry 5.0.4 dependency
+
+ * 20071106 [poussin] add removeContext on TopiaContextFactory and call it
+ in TopiaContextImpl.closeContext().
+
+ * 20071107 [thimel] add db schema support
+ * 20071107 [thimel] several .hbm.xml refactoring
+ * 20071108 [thimel] add DTO generator
+ * 20071108 [thimel] add copyright support in generators
+ * 20071108 [thimel] add serialVersionUID support in EntityAbstractGenerator
+
+ver-2-0-24 poussin 20070425
+
+ * 20070420 [chatellier] add services interfaces generation (stereotype=service)
+ * 20070420 [chatellier] add topia services support
+ * 20070330 [poussin] TopiaContextFactory return new TopiaContext if context is closed
+ * 20070331 [poussin] change many string argument to class argument
+ * 20070331 [poussin] add getService(Class) method on TopiaContext
+ * 20070331 [poussin] remove helper in service that only return service instant
+ * 20070331 [poussin] add Devel.rst documentation
+ * 20070402 [poussin] replace init to preInit and postInit in TopiaService
+
+ver-2-0-22 ruchaud 20061023
+
+ * 20061023 [ruchaud][improve] manage events
+ * 20061023 [ruchaud][bug fix] in generator of DAO Abstract on delete
+
+ver-2-0-21 poussin 20061019
+
+ * add support for auto-import entities for hql
+ * add getComposite and getAggregate on TopiaEntity
+ * bug fix for association hibernate mapping wit have attributeh
+ cascade="delete" for not navigable link to prevent constraint exception
+ * bug fix in delete, remove link before do delete
+
+ver-2-0-20 poussin 20061017
+
+ * add support for TopiaService mechanisme
+
+ver-2-0-16 poussin 20060907
+
+ * Implantation des méthodes update et delete sur les TopiaUserImpl et TopiaEntityPermissionImpl
+ * add backup/restore method on TopiaContext (backup only works for h2)
+ * TopiaContext is set in Entity during preload
+ * add updateSchema in TopiaContext interface
+ * add methods update et delete on TopiaUserImpl and TopiaEntityPermissionImpl
+
+ver-2-0-13 thimel 20060822
+
+ * [Secu] ajout d'un champ notes sur les TopiaUser
+ * [Secu] ajout d'un champ linkApplication sur les TopiaUser (permettant de faire le lien avec une application externe)
+ * [Secu] ajout de commits et rollbacks sur les Manager
+ * [Secu] ajout d'un setPassword (sans verification ancien mdp) sur les TopiaUser
+
+ver-2-0-12 thimel 20060721
+
+ * ajout des projections sur les DAO
+ * positionnement unique des userManager et permissionManager au niveau du contexte racine
+ * ajout de la possibilite de tester des permissions sur le permissionManager
+
+ver-2-0-11 thimel 20060703
+
+ * support de la fermeture d'un contexte
+ * support de la recherche sur tous les attributs d'une entite / annotation sur les interfaces
+
+ver-2-0-8 thimel 20060606
+
+ * amelioration detection des classes abstraites
+ * correction du polymorphisme avec les proxies d'Hibernate
+ * Hibernate 3.2
+
+ver-2-0-7 thimel 20060523
+
+ * import/export XML "experimental"
+ * one-to-one transformes en many-to-one + unique="true"
+ * bug au niveau de la detection des parents abstract
+
+ver-2-0-6 thimel 20060504
+
+ * support des annotations sur les attributs des XXXAbstract
+ * re-correction du support des relations unidirectionnelles 1-n avec classes d'heritage du cote n
+ * ajout de la validation pour les attributs sans inverses (pour les objectmodel faits a la main)
+
+ver-2-0-5 thimel 20060427
+
+ * isIndexed remplace isOrdered dans le mapping hibernate
+ * add postCreate and postLoad on AbstractTopiaEntity
+ * findContains sur les DAO (implante hors Hibernate pour l'instant)
+ * support plus coherent des classes abstraites
+ * projet compatible maven2
+ * correction du support des relations unidirectionnelles 1-n avec classes d'heritage du cote n
+
+ver-2-0-4 thimel 20060303
+
+ * Correction du support des interfaces et classes abstraites (conjointement a LutinGenerator 0.30)
+ * Ajout des exceptions sur le operations (conjointement a LutinGenerator 0.30)
+
+ver-2-0-3 thimel 20060228
+
+ * Correction du support des classes d'associations (mauvais mapping Hibernate)
+ * Support de super classes pour les classes d'association (LutinGenerator 0.29)
+
Deleted: topia/tags/2.0.29/pom.xml
===================================================================
--- topia/trunk/pom.xml 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/pom.xml 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,207 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
-
- <parent>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinproject</artifactId>
- <version>3.0</version>
- </parent>
-
- <artifactId>topia</artifactId>
-
- <dependencies>
- <!--Compile-->
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutinutil</artifactId>
- <version>0.31</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>lutingenerator</artifactId>
- <version>0.61</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.2.1</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>3.3.1.GA</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.4.GA</version>
- </dependency>
-
- <!--Test-->
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>8.2-507.jdbc4</version>
- <scope>test</scope>
- </dependency>
-
- <!-- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.5</version>
- <scope>test</scope>
- </dependency> -->
-
- <!-- Dependencies for services -->
- <dependency>
- <groupId>org.apache.xmlrpc</groupId>
- <artifactId>xmlrpc-server</artifactId>
- <version>3.1</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.xmlrpc</groupId>
- <artifactId>xmlrpc-client</artifactId>
- <version>3.1</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- <scope>runtime</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.xfire</groupId>
- <artifactId>xfire-java5</artifactId>
- <version>1.2.6</version>
- <exclusions>
- <!-- Fix org.apache.ant conflict) -->
- <exclusion>
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!-- branch 5.1 : ne fonctionne pas en 6+ -->
- <dependency>
- <groupId>jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>5.1.10</version>
- </dependency>
-
- <!-- Dependencies for class generation -->
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>1.5.3</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry-core</artifactId>
- <version>5.0.7</version>
- <scope>compile</scope>
- </dependency>
-
- <!--BD H2 pour le test-->
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.0.79</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>ToPIA - Tools for Portable and Independent Architecture</name>
- <version>2.0.29-SNAPSHOT</version>
- <description>Framework de persistance et de distribution d'application.</description>
- <inceptionYear>2004</inceptionYear>
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
-
- <packaging>jar</packaging>
-
- <properties>
- <!-- id du projet du labs -->
- <labs.id>21</labs.id>
-
- <!-- nom du projet sur le labs -->
- <labs.project>topia</labs.project>
-
- <!-- Test FIXME : -->
- <maven.test.skip>true</maven.test.skip>
- </properties>
-
- <build>
- <plugins>
- <!--Attaching processor plugin to the Build Lifecycle-->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- <version>0.16</version>
- <executions>
- <execution>
- <phase>generate-sources</phase>
- <goals>
- <goal>process</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <!-- You might change defaut directories -->
- <!-- srcDir>${basedir}/src/main/java</srcDir>
- <destDir>${basedir}/target/processed-sources/java</destDir-->
- <addCompileDirectory>true</addCompileDirectory>
- <includes>
- <include>**/*.java</include>
- </includes>
- <filters>
- org.codelutin.processor.filters.GeneratorTemplatesFilter,
- org.codelutin.processor.filters.ActiveLogsCodeFilter
- </filters>
- <verbose>${maven.verbose}</verbose>
- </configuration>
- </plugin>
-
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- </plugin>
-
- </plugins>
- </build>
-
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
- <scm>
- <connection>${maven.scm.connection}</connection>
- <developerConnection>${maven.scm.developerConnection}</developerConnection>
- <url>${maven.scm.url}</url>
- </scm>
-
-</project>
Copied: topia/tags/2.0.29/pom.xml (from rev 1226, topia/trunk/pom.xml)
===================================================================
--- topia/tags/2.0.29/pom.xml (rev 0)
+++ topia/tags/2.0.29/pom.xml 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinproject</artifactId>
+ <version>3.0</version>
+ </parent>
+
+ <artifactId>topia</artifactId>
+
+ <dependencies>
+ <!--Compile-->
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutinutil</artifactId>
+ <version>0.31</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>lutingenerator</artifactId>
+ <version>0.61</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.3.1.GA</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.4.GA</version>
+ </dependency>
+
+ <!--Test-->
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>8.2-507.jdbc4</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.5</version>
+ <scope>test</scope>
+ </dependency> -->
+
+ <!-- Dependencies for services -->
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-server</artifactId>
+ <version>3.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-client</artifactId>
+ <version>3.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.xfire</groupId>
+ <artifactId>xfire-java5</artifactId>
+ <version>1.2.6</version>
+ <exclusions>
+ <!-- Fix org.apache.ant conflict) -->
+ <exclusion>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- branch 5.1 : ne fonctionne pas en 6+ -->
+ <dependency>
+ <groupId>jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>5.1.10</version>
+ </dependency>
+
+ <!-- Dependencies for class generation -->
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>1.5.3</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>tapestry-core</artifactId>
+ <version>5.0.7</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!--BD H2 pour le test-->
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.0.79</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>ToPIA - Tools for Portable and Independent Architecture</name>
+ <version>2.0.29</version>
+ <description>Framework de persistance et de distribution d'application.</description>
+ <inceptionYear>2004</inceptionYear>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>jar</packaging>
+
+ <properties>
+ <!-- id du projet du labs -->
+ <labs.id>21</labs.id>
+
+ <!-- nom du projet sur le labs -->
+ <labs.project>topia</labs.project>
+
+ <!-- Test FIXME : -->
+ <maven.test.skip>true</maven.test.skip>
+ </properties>
+
+ <build>
+ <plugins>
+ <!--Attaching processor plugin to the Build Lifecycle-->
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ <version>0.16</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <!-- You might change defaut directories -->
+ <!-- srcDir>${basedir}/src/main/java</srcDir>
+ <destDir>${basedir}/target/processed-sources/java</destDir-->
+ <addCompileDirectory>true</addCompileDirectory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ <filters>
+ org.codelutin.processor.filters.GeneratorTemplatesFilter,
+ org.codelutin.processor.filters.ActiveLogsCodeFilter
+ </filters>
+ <verbose>${maven.verbose}</verbose>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.0.29</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.0.29</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.0.…</url>
+ </scm>
+
+</project>
Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,251 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/*******************************************************************************
- * EntityProviderGenerator.java
- *
- */
-
-package org.codelutin.topia.generator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.generator.Generator;
-import org.codelutin.generator.ObjectModelGenerator;
-import org.codelutin.generator.models.object.ObjectModel;
-import org.codelutin.generator.models.object.ObjectModelClass;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Ce generateur permet d'avoir une énumeration sur les entités du model.
- * <p/>
- * Chaque entité est associée à un {@link org.codelutin.topia.persistence.TopiaEntityEnumEntry}.
- *
- * @author chemit
- * @see org.codelutin.topia.persistence.TopiaEntityEnumEntry
- */
-public class EntityEnumGenerator extends ObjectModelGenerator {
-
- private Log log = LogFactory.getLog(EntityEnumGenerator.class);
-
- public EntityEnumGenerator() {
- super();
- }
-
- public EntityEnumGenerator(Generator parent) {
- super(parent);
- }
-
- @Override
- public String getFilenameForModel(ObjectModel model) {
- return (getProperty("defaultPackage") + ".").replace('.',
- File.separatorChar)
- + model.getName() + "EntityEnum.java";
- }
-
- @Override
- public void generateFromModel(Writer output, ObjectModel model)
- throws IOException {
- String copyright = GeneratorUtil.getCopyright(model);
- String modelName = model.getName();
- String className = modelName + "EntityEnum";
- if (log.isDebugEnabled()) {
- log.debug("generating " + className);
- }
- if (GeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
-/*{package <%=getProperty("defaultPackage")%>;
-
-import org.codelutin.topia.TopiaContext;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.persistence.TopiaDAO;
-import org.codelutin.topia.persistence.TopiaEntity;
-import org.codelutin.topia.persistence.TopiaEntityEnumEntry;
-
-
-@SuppressWarnings({"unchecked"})
-}*/
-
-/*{public enum <%=className%> {
-}*/
- List<ObjectModelClass> classes = GeneratorUtil.getEntityClasses(model, true);
- if (classes.isEmpty()) {
-/*{
- TopiaEntity(TopiaEntity.class);
-}*/
- } else {
- for (Iterator i = classes.iterator(); i.hasNext();) {
- ObjectModelClass clazz = (ObjectModelClass) i.next();
- boolean hasNext = i.hasNext();
- if (log.isDebugEnabled()) {
- log.debug("generating entry " + clazz + " (hasNext:" + hasNext + ")");
- }
-/*{ <%=clazz.getName()%>(<%=clazz.getQualifiedName()%>.class)<%=(hasNext?",":";")%>
-}*/
- }
- }
-/*{
- private TopiaEntityEnumEntry<TopiaEntity> entry;
-
- <%=className%>(Class<? extends TopiaEntity> contractClass) {
- entry = new TopiaEntityEnumEntry(contractClass);
- }
-}*/
-
-/* public Class<? extends TopiaEntity> getContractClass() {
- return entry.getContractClass();
- }
-
- public Class<? extends TopiaEntity> getImplementationClass() {
- return entry.getImplementationClass();
- }
-
- public TopiaDAO getDAO(TopiaContext ctxt) throws TopiaException {
- return entry.getDAO(ctxt);
- }
-
- public TopiaEntity create(TopiaContext ctxt) throws TopiaException {
- return entry.create(ctxt);
- }
-
- public TopiaEntity update(TopiaEntity entity, TopiaContext
- ctxt) throws TopiaException
- {
- return entry.update(entity, ctxt);
- }
-
- public void delete(TopiaEntity entity, TopiaContext ctxt) throws TopiaException {
- entry.delete(entity, ctxt);
- }
-*/
-
-/*{
- public static <%=className%> valueOf(TopiaEntity entity) {
- return valueOf(entity.getClass());
- }
-
- public static <%=className%> valueOf(Class<?> klass) {
- if (klass.isInterface()) {
- return <%=modelName%>EntityEnum.valueOf(klass.getSimpleName());
- }
- for (<%=className%> entityEnum : <%=className%>.values()) {
- if (entityEnum.entry.getContractClass().isAssignableFrom(klass)) {
- return entityEnum;
- }
- }
- throw new IllegalArgumentException("no entity defined for the class " + klass + " in : " + java.util.Arrays.toString(<%=className%>.values()));
- }
-
- public static <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(klass);
- <%=className%> e = <%=className%>.valueOf(klass);
- return (Class<T>) e.entry.getContractClass();
- }
-
- public static <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(klass);
- <%=className%> e = <%=className%>.valueOf(klass);
- return (Class<T>) e.entry.getImplementationClass();
- }
-
- public static Class<? extends TopiaEntity>[] getContractClasses() {
- <%=className%>[] values = <%=className%>.values();
- Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length);
- for (int i = 0; i < values.length; i++) {
- result[i] = values[i].entry.getContractClass();
- }
- return result;
- }
-
- public static Class<? extends TopiaEntity>[] getImplementationClasses() {
- <%=className%>[] values = <%=className%>.values();
- Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length);
- for (int i = 0; i < values.length; i++) {
- result[i] = values[i].entry.getImplementationClass();
- }
- return result;
- }
-
- public static String getImplementationClassesAsString() {
- StringBuilder buffer = new StringBuilder();
- for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
- buffer.append(',').append(aClass.getName());
- }
- return buffer.substring(1);
- }
-
- public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(Class<T> klass, TopiaContext ctxt) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(klass);
- <%=className%> e = <%=className%>.valueOf(klass);
- return (D) e.entry.getDAO(ctxt);
- }
-
- public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(T entity, TopiaContext ctxt) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(entity);
- <%=className%> e = <%=className%>.valueOf(entity);
- return (D) e.entry.getDAO(ctxt);
- }
-
- public static <T extends TopiaEntity> T create(Class<T> klass, TopiaContext ctxt) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(klass);
- <%=className%> e = <%=className%>.valueOf(klass);
- return (T) e.entry.create(ctxt);
- }
-
- public static <T extends TopiaEntity> T update(T entity, TopiaContext ctxt) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(entity);
- <%=className%> e = <%=className%>.valueOf(entity);
- return (T) e.entry.update(entity, ctxt);
- }
-
- public static <T extends TopiaEntity> void delete(T entity, TopiaContext ctxt) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(entity);
- <%=className%> e = <%=className%>.valueOf(entity);
- e.entry.delete(entity, ctxt);
- }
-
- public static <T extends TopiaEntity> java.util.List<T> findAll(Class<T> klass, TopiaContext ctxt) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(klass);
- return entry.findAll(ctxt);
- }
-
- public static <T extends TopiaEntity> T findByTopiaId(Class<T> klass, TopiaContext ctxt,String topiaId) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(klass);
- return entry.findByTopiaId(topiaId,ctxt);
- }
-
- public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(T entity) throws TopiaException {
- <%=className%> e = <%=className%>.valueOf(entity);
- return (TopiaEntityEnumEntry<T>)e.entry;
- }
-
- public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(Class<T> klass) throws TopiaException {
- <%=className%> e = <%=className%>.valueOf(klass);
- return (TopiaEntityEnumEntry<T>)e.entry;
- }
-}
-}*/
- }
-
-} // EntityEnumGenerator
Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java)
===================================================================
--- topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java (rev 0)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,309 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/*******************************************************************************
+ * EntityProviderGenerator.java
+ *
+ */
+
+package org.codelutin.topia.generator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.generator.Generator;
+import org.codelutin.generator.ObjectModelGenerator;
+import org.codelutin.generator.models.object.ObjectModel;
+import org.codelutin.generator.models.object.ObjectModelClass;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Ce generateur permet d'avoir une énumeration sur les entités du model.
+ * <p/>
+ * Chaque entité est associée à un {@link org.codelutin.topia.persistence.TopiaEntityEnumEntry}.
+ *
+ * @author chemit
+ * @see org.codelutin.topia.persistence.TopiaEntityEnumEntry
+ */
+public class EntityEnumGenerator extends ObjectModelGenerator {
+
+ private Log log = LogFactory.getLog(EntityEnumGenerator.class);
+
+ public EntityEnumGenerator() {
+ super();
+ }
+
+ public EntityEnumGenerator(Generator parent) {
+ super(parent);
+ }
+
+ @Override
+ public String getFilenameForModel(ObjectModel model) {
+ return (getProperty("defaultPackage") + ".").replace('.',
+ File.separatorChar)
+ + model.getName() + "EntityEnum.java";
+ }
+
+ @Override
+ public void generateFromModel(Writer output, ObjectModel model)
+ throws IOException {
+ String copyright = GeneratorUtil.getCopyright(model);
+ String modelName = model.getName();
+ String className = modelName + "EntityEnum";
+ if (log.isDebugEnabled()) {
+ log.debug("generating " + className);
+ }
+ if (GeneratorUtil.notEmpty(copyright)) {
+/*{<%=copyright%>
+}*/
+ }
+/*{package <%=getProperty("defaultPackage")%>;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Collection;
+
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.persistence.TopiaDAO;
+import org.codelutin.topia.persistence.TopiaEntity;
+import org.codelutin.topia.persistence.TopiaEntityEnumEntry;
+
+
+@SuppressWarnings({"unchecked"})
+}*/
+
+/*{public enum <%=className%> {
+}*/
+ List<ObjectModelClass> classes = GeneratorUtil.getEntityClasses(model, true);
+ if (classes.isEmpty()) {
+/*{
+ TopiaEntity(TopiaEntity.class);
+}*/
+ } else {
+ for (Iterator i = classes.iterator(); i.hasNext();) {
+ ObjectModelClass clazz = (ObjectModelClass) i.next();
+ boolean hasNext = i.hasNext();
+ if (log.isDebugEnabled()) {
+ log.debug("generating entry " + clazz + " (hasNext:" + hasNext + ")");
+ }
+/*{ <%=clazz.getName()%>(<%=clazz.getQualifiedName()%>.class)<%=(hasNext?",":";")%>
+}*/
+ }
+ }
+/*{
+ private TopiaEntityEnumEntry<TopiaEntity> entry;
+
+ <%=className%>(Class<? extends TopiaEntity> contractClass) {
+ entry = new TopiaEntityEnumEntry(contractClass);
+ }
+
+ public <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry() {
+ return (TopiaEntityEnumEntry<T>)entry;
+ }
+
+ public static <%=className%> valueOf(TopiaEntity entity) {
+ return valueOf(entity.getClass());
+ }
+
+ public static <%=className%> valueOf(Class<?> klass) {
+ if (klass.isInterface()) {
+ return <%=modelName%>EntityEnum.valueOf(klass.getSimpleName());
+ }
+ for (<%=className%> entityEnum : <%=className%>.values()) {
+ if (entityEnum.entry.getContractClass().isAssignableFrom(klass)) {
+ return entityEnum;
+ }
+ }
+ throw new IllegalArgumentException("no entity defined for the class " + klass + " in : " + java.util.Arrays.toString(<%=className%>.values()));
+ }
+
+ public static <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.getContractClass();
+ }
+
+ public static <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.getImplementationClass();
+ }
+
+ public static Class<? extends TopiaEntity>[] getContractClasses() {
+ <%=className%>[] values = <%=className%>.values();
+ Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length);
+ for (int i = 0; i < values.length; i++) {
+ result[i] = values[i].entry.getContractClass();
+ }
+ return result;
+ }
+
+ public static Class<? extends TopiaEntity>[] getImplementationClasses() {
+ <%=className%>[] values = <%=className%>.values();
+ Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length);
+ for (int i = 0; i < values.length; i++) {
+ result[i] = values[i].entry.getImplementationClass();
+ }
+ return result;
+ }
+
+ public static String getImplementationClassesAsString() {
+ StringBuilder buffer = new StringBuilder();
+ for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
+ buffer.append(',').append(aClass.getName());
+ }
+ return buffer.substring(1);
+ }
+
+ public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(T entity) {
+ <%=className%> e = <%=className%>.valueOf(entity);
+ return (TopiaEntityEnumEntry<T>)e.entry;
+ }
+
+ public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(Class<T> klass) {
+ <%=className%> e = <%=className%>.valueOf(klass);
+ return (TopiaEntityEnumEntry<T>)e.entry;
+ }
+
+ public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(String constantName) {
+ <%=className%> e = <%=className%>.valueOf(constantName);
+ return (TopiaEntityEnumEntry<T>)e.entry;
+ }
+
+ public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext ctxt, Class<T> klass) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return (D) entry.getDAO(ctxt);
+ }
+
+ public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext ctxt, T entity) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(entity);
+ return (D) entry.getDAO(ctxt);
+ }
+
+ public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.create(ctxt);
+ }
+
+ public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass, Object... properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.create(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.create(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> T update(TopiaContext ctxt, T entity) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(entity);
+ return entry.update(entity, ctxt);
+ }
+
+ public static <T extends TopiaEntity> void delete(TopiaContext ctxt, T entity) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(entity);
+ entry.delete(entity, ctxt);
+ }
+
+ public static <T extends TopiaEntity> int size(TopiaContext ctxt, Class<T> klass) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.size(ctxt);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAll(TopiaContext ctxt, Class<T> klass) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAll(ctxt);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllWithOrder(TopiaContext ctxt, Class<T> klass,String... propertyNames) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllWithOrder(ctxt, propertyNames);
+ }
+
+ public static <T extends TopiaEntity> T findByTopiaId(TopiaContext ctxt, Class<T> klass,String topiaId) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByTopiaId(topiaId,ctxt);
+ }
+
+ public static <T extends TopiaEntity> T findByPrimaryKey(TopiaContext ctxt, Class<T> klass, Map<String, Object> keys) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByPrimaryKey(ctxt, keys);
+ }
+
+ public static <T extends TopiaEntity> T findByPrimaryKey(TopiaContext ctxt, Class<T> klass, Object... k) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByPrimaryKey(ctxt, k);
+ }
+
+ public static <T extends TopiaEntity> T findByProperty(TopiaContext ctxt, Class<T> klass, String propertyName, Object value) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByProperty(ctxt, propertyName, value);
+ }
+
+ public static <T extends TopiaEntity> T findByProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Object value, Object... others) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByProperties(ctxt, propertyName, value, others);
+ }
+
+ public static <T extends TopiaEntity> T findByProperties(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByProperties(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllByProperty(TopiaContext ctxt, Class<T> klass, String propertyName, Object value) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllByProperty(ctxt, propertyName, value);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllByProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Object value, Object... others) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllByProperties(ctxt, propertyName, value, others);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllByProperties(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllByProperties(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> T findContainsProperties(TopiaContext ctxt, Class<T> klass, Map<String, Collection> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findContainsProperties(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> T findContainsProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Collection values, Object... others) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findContainsProperties(ctxt, propertyName, values, others);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllContainsProperties(TopiaContext ctxt, Class<T> klass, Map<String, Collection> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllContainsProperties(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllContainsProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Collection values, Object... others) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllContainsProperties(ctxt, propertyName, values, others);
+ }
+
+}
+}*/
+ }
+
+} // EntityEnumGenerator
Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,228 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaDAO.java
- *
- * Created: 30 déc. 2005 03:00:57
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.security.Permission;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.event.TopiaEntityListener;
-import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.event.TopiaTransactionListener;
-import org.codelutin.topia.event.TopiaTransactionVetoable;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-
-/**
- * @author poussin
- *
- * @param <Entity>
- */
-public interface TopiaDAO<Entity extends TopiaEntity> {
-
- /**
- * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
- * after
- *
- * @param entityClass
- */
- public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException;
-
- /**
- * Return class of entity managed by this DAO
- * @return
- */
- public abstract Class<Entity> getEntityClass();
-
- /**
- * @return Returns the context.
- */
- public abstract TopiaContextImplementor getContext();
-
- /**
- * appelé lorsque le context a eu un commit de fait
- * TODO il faudrait peut-etre plutot faire un commit a deux phase
- * car plusieurs type de persistence peuvent etre melangé, et il
- * serait bien que si l'une echoué les autres echoue aussi.
- */
- public void commitTransaction() throws TopiaException;
- /** appelé lorsque le context a eu un commit de fait */
- public void rollbackTransaction() throws TopiaException;
-
- /**
- * Construit une nouvelle instance de l'objet géré par ce DAO
- * @param properties la liste des propriétés que doit avoir l'objet créé
- * les arguments vont par paire (propertyName, value)
- * @return un nouvel objet
- * @throws TopiaException si un problème est rencontré durant l'instanciation
- * @throws IllegalArgumentException Si le nombre on le type des arguments
- * n'est pas bon ou que le type ou le nom d'une propriété est fausse
- */
- public abstract Entity create(Object ... properties) throws TopiaException;
-
- /**
- * Construit une nouvelle instance de l'objet géré par ce DAO
- * @param properties la liste des propriétés que doit avoir l'objet créé
- * @return un nouvel objet
- * @throws TopiaException si un problème est rencontré durant l'instanciation
- * @throws IllegalArgumentException Si le nombre on le type des arguments
- * n'est pas bon ou que le type ou le nom d'une propriété est fausse
- */
- public Entity create(Map<String, Object> properties) throws TopiaException;
-
- /**
- * Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter
- * par exemple un objet provenant d'un autre context mais du meme type
- * de DAO
- * @param e l'entite a ajouter ou mettre a jour
- * @return l'entity passé en paramètre.
- * @throws TopiaException
- */
- public abstract Entity update(Entity e) throws TopiaException;
-
- public abstract void delete(Entity e) throws TopiaException;
-
- public abstract Entity findByTopiaId(String k) throws TopiaException;
-
- public abstract List<Entity> findAll() throws TopiaException;
-
- /**
- * TODO modifier l'implantation pour faire un simple count sur la base
- *
- * @return
- * @throws TopiaException
- */
- public abstract int size() throws TopiaException;
-
- /**
- * Recherche la classe en utilisant la cle naturelle, chaque champs de la
- * cle naturelle est une entre de la map passe en argument.
- *
- * @param keys la liste des champs de la cle naturelle avec leur valeur
- * @return
- * @throws TopiaException
- */
- public abstract Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException;
-
- /**
- * Recherche la classe en utilisant la cle naturelle, si la cle naturelle
- * est composé de plusieurs champs alors les arguments passés doivent être
- * dans l'ordre de declaration dans le fichier de mapping
- *
- * @param k l'objet cle naturelle de la classe
- * @return
- * @throws TopiaException
- */
- public abstract Entity findByPrimaryKey(Object... k) throws TopiaException;
-
- public abstract Entity findByProperty(String propertyName, Object value)
- throws TopiaException;
-
- /**
- *
- * @param propertyName
- * @param value
- * @param others les autres proprietes doivent aller par 2 propertyName,
- * value
- * @return
- * @throws TopiaException
- */
- public abstract Entity findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
-
- public abstract Entity findByProperties(Map<String, Object> properties)
- throws TopiaException;
-
- public abstract List<Entity> findAllByProperty(String propertyName, Object value)
- throws TopiaException;
-
- /**
- *
- * @param propertyName
- * @param value
- * @param others les autres proprietes doivent aller par 2 propertyName,
- * value
- * @return
- * @throws TopiaException
- */
- public abstract List<Entity> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
-
- public abstract List<Entity> findAllByProperties(Map<String, Object> properties)
- throws TopiaException;
-
- /*
- * Find Contains
- */
- /**
- * Cherche et renvoie la première entité trouvée dont les propriétés en clé
- * de Map contiennent toutes les valeurs de la Collection.
- */
- public abstract Entity findContainsProperties(Map<String, Collection> properties)
- throws TopiaException;
-
- /**
- * Cherche et renvoie la première entité trouvée dont la propriété
- * propertyName contient values, ainsi de suite avec others.
- */
- public abstract Entity findContainsProperties(String propertyName, Collection values, Object... others)
- throws TopiaException;
-
- /**
- * Cherche et renvoie la première entité trouvée dont les propriétés en clé
- * de Map contiennent toutes les valeurs de la Collection.
- */
- public abstract List<Entity> findAllContainsProperties(Map<String, Collection> properties)
- throws TopiaException;
-
- /**
- * Cherche et renvoie toutes les entités trouvées dont la propriété
- * propertyName contient values, ainsi de suite avec others.
- */
- public abstract List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others)
- throws TopiaException;
-
- /**
- * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas
- * @param topiaId topiaId d'une entite
- * @return la liste des permissions
- */
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException;
-
- /* Adders */
- public void addTopiaEntityListener(TopiaEntityListener listener);
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
- /* Removers */
- public void removeTopiaEntityListener(TopiaEntityListener listener);
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
-} //TopiaDAO
Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java)
===================================================================
--- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java (rev 0)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,230 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaDAO.java
+ *
+ * Created: 30 déc. 2005 03:00:57
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.security.Permission;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.event.TopiaEntityListener;
+import org.codelutin.topia.event.TopiaEntityVetoable;
+import org.codelutin.topia.event.TopiaTransactionListener;
+import org.codelutin.topia.event.TopiaTransactionVetoable;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+
+/**
+ * @author poussin
+ *
+ * @param <Entity>
+ */
+public interface TopiaDAO<Entity extends TopiaEntity> {
+
+ /**
+ * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
+ * after
+ *
+ * @param entityClass
+ */
+ public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException;
+
+ /**
+ * Return class of entity managed by this DAO
+ * @return
+ */
+ public abstract Class<Entity> getEntityClass();
+
+ /**
+ * @return Returns the context.
+ */
+ public abstract TopiaContextImplementor getContext();
+
+ /**
+ * appelé lorsque le context a eu un commit de fait
+ * TODO il faudrait peut-etre plutot faire un commit a deux phase
+ * car plusieurs type de persistence peuvent etre melangé, et il
+ * serait bien que si l'une echoué les autres echoue aussi.
+ */
+ public void commitTransaction() throws TopiaException;
+ /** appelé lorsque le context a eu un commit de fait */
+ public void rollbackTransaction() throws TopiaException;
+
+ /**
+ * Construit une nouvelle instance de l'objet géré par ce DAO
+ * @param properties la liste des propriétés que doit avoir l'objet créé
+ * les arguments vont par paire (propertyName, value)
+ * @return un nouvel objet
+ * @throws TopiaException si un problème est rencontré durant l'instanciation
+ * @throws IllegalArgumentException Si le nombre on le type des arguments
+ * n'est pas bon ou que le type ou le nom d'une propriété est fausse
+ */
+ public abstract Entity create(Object ... properties) throws TopiaException;
+
+ /**
+ * Construit une nouvelle instance de l'objet géré par ce DAO
+ * @param properties la liste des propriétés que doit avoir l'objet créé
+ * @return un nouvel objet
+ * @throws TopiaException si un problème est rencontré durant l'instanciation
+ * @throws IllegalArgumentException Si le nombre on le type des arguments
+ * n'est pas bon ou que le type ou le nom d'une propriété est fausse
+ */
+ public Entity create(Map<String, Object> properties) throws TopiaException;
+
+ /**
+ * Permet d'ajouter ou de mettre a jour un objet. Cela permet d'ajouter
+ * par exemple un objet provenant d'un autre context mais du meme type
+ * de DAO
+ * @param e l'entite a ajouter ou mettre a jour
+ * @return l'entity passé en paramètre.
+ * @throws TopiaException
+ */
+ public abstract Entity update(Entity e) throws TopiaException;
+
+ public abstract void delete(Entity e) throws TopiaException;
+
+ public abstract Entity findByTopiaId(String k) throws TopiaException;
+
+ public abstract List<Entity> findAll() throws TopiaException;
+
+ public abstract List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException;
+
+ /**
+ * TODO modifier l'implantation pour faire un simple count sur la base
+ *
+ * @return
+ * @throws TopiaException
+ */
+ public abstract int size() throws TopiaException;
+
+ /**
+ * Recherche la classe en utilisant la cle naturelle, chaque champs de la
+ * cle naturelle est une entre de la map passe en argument.
+ *
+ * @param keys la liste des champs de la cle naturelle avec leur valeur
+ * @return
+ * @throws TopiaException
+ */
+ public abstract Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException;
+
+ /**
+ * Recherche la classe en utilisant la cle naturelle, si la cle naturelle
+ * est composé de plusieurs champs alors les arguments passés doivent être
+ * dans l'ordre de declaration dans le fichier de mapping
+ *
+ * @param k l'objet cle naturelle de la classe
+ * @return
+ * @throws TopiaException
+ */
+ public abstract Entity findByPrimaryKey(Object... k) throws TopiaException;
+
+ public abstract Entity findByProperty(String propertyName, Object value)
+ throws TopiaException;
+
+ /**
+ *
+ * @param propertyName
+ * @param value
+ * @param others les autres proprietes doivent aller par 2 propertyName,
+ * value
+ * @return
+ * @throws TopiaException
+ */
+ public abstract Entity findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException;
+
+ public abstract Entity findByProperties(Map<String, Object> properties)
+ throws TopiaException;
+
+ public abstract List<Entity> findAllByProperty(String propertyName, Object value)
+ throws TopiaException;
+
+ /**
+ *
+ * @param propertyName
+ * @param value
+ * @param others les autres proprietes doivent aller par 2 propertyName,
+ * value
+ * @return
+ * @throws TopiaException
+ */
+ public abstract List<Entity> findAllByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException;
+
+ public abstract List<Entity> findAllByProperties(Map<String, Object> properties)
+ throws TopiaException;
+
+ /*
+ * Find Contains
+ */
+ /**
+ * Cherche et renvoie la première entité trouvée dont les propriétés en clé
+ * de Map contiennent toutes les valeurs de la Collection.
+ */
+ public abstract Entity findContainsProperties(Map<String, Collection> properties)
+ throws TopiaException;
+
+ /**
+ * Cherche et renvoie la première entité trouvée dont la propriété
+ * propertyName contient values, ainsi de suite avec others.
+ */
+ public abstract Entity findContainsProperties(String propertyName, Collection values, Object... others)
+ throws TopiaException;
+
+ /**
+ * Cherche et renvoie la première entité trouvée dont les propriétés en clé
+ * de Map contiennent toutes les valeurs de la Collection.
+ */
+ public abstract List<Entity> findAllContainsProperties(Map<String, Collection> properties)
+ throws TopiaException;
+
+ /**
+ * Cherche et renvoie toutes les entités trouvées dont la propriété
+ * propertyName contient values, ainsi de suite avec others.
+ */
+ public abstract List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others)
+ throws TopiaException;
+
+ /**
+ * Retourne les permissions a verifier pour l'acces a l'entite pour le service Taas
+ * @param topiaId topiaId d'une entite
+ * @return la liste des permissions
+ */
+ public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException;
+
+ /* Adders */
+ public void addTopiaEntityListener(TopiaEntityListener listener);
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+ /* Removers */
+ public void removeTopiaEntityListener(TopiaEntityListener listener);
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
+} //TopiaDAO
Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,707 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaDAOAbstract.java
- *
- * Created: 31 déc. 2005 13:10:34
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.event.TopiaEntityListener;
-import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-import org.codelutin.topia.persistence.hibernate.TopiaDAOHibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.metadata.ClassMetadata;
-
-
-/**
- * Cette classe permet d'avoir un ensemble de méthode implantée de façon
- * standard pour les différents DAO existant (FlatFile, Hibernate).
- * Certaine méthode implanté ici sont particulièrement inéficace et il
- * est conseillé de les surcharger dans les classes DAO spécifiques.
- *
- * Certain accès à Hibernate est tout de même fait ici, car on a pris le
- * choix de se basé entièrement sur hibernate pour la persistence, et il
- * est ainsi possible d'accèder au meta information hibernate sur les classes
- * lorque l'on en a besoin.
- *
- * @author poussin
- *
- */
-
-public abstract class TopiaDAOAbstract<Entity extends TopiaEntity> implements TopiaDAO<Entity> {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(TopiaDAOAbstract.class);
-
- protected Class<Entity> entityClass = null;
-
- protected TopiaContextImplementor context = null;
-
- public Class<Entity> getEntityClass() {
- throw new UnsupportedOperationException("This method must be overided in generated DAO");
- }
-
- /**
- * Retourne l'id de l'entity
- * @param e l'entity
- * @return l'id de l'entity ou null si pas trouvé
- * @throws TopiaException Si une erreur survient durant la recherche
- */
- protected Serializable getId(Entity e) throws TopiaException {
- ClassMetadata meta = getClassMetadata();
- String idPropName = meta.getIdentifierPropertyName();
-
- Serializable result;
- try {
- result = (Serializable)PropertyUtils.getSimpleProperty(e, idPropName);
- } catch (IllegalAccessException eee) {
- throw new TopiaException("Impossible de récuperer l'identifiant " +
- idPropName + " de l'entite: " + e);
- } catch (InvocationTargetException eee) {
- throw new TopiaException("Impossible de récuperer l'identifiant " +
- idPropName + " de l'entite: " + e);
- } catch (NoSuchMethodException eee) {
- throw new TopiaException("Impossible de récuperer l'identifiant " +
- idPropName + " de l'entite: " + e);
- }
- return result;
- }
-
- /**
- * Retourne l'id de l'entity representer comme une map
- * @param map l'entity en representation map
- * @return l'id de l'entity ou null si pas trouvé
- * @throws TopiaException Si une erreur survient durant la recherche
- */
- protected Serializable getId(Map map) throws TopiaException {
- try {
- ClassMetadata meta = getClassMetadata();
- String idPropName = meta.getIdentifierPropertyName();
-
- Serializable id = (Serializable)map.get(idPropName);
- return id;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
-
- /**
- * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
- * after
- *
- * @param entityClass
- */
- public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException {
- log.debug("init dao for " + entityClass.getName());
- this.context = context;
- this.entityClass = entityClass;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#getContext()
- */
- public TopiaContextImplementor getContext() {
- return context;
- }
-
- @SuppressWarnings("unchecked")
- protected Entity instanciateNew() throws TopiaException {
- Entity result = null;
- String classname = entityClass.getName();
- try {
- // on commence par essayer d'instancier le Impl
- result = ((Class<Entity>)Class.forName(classname+"Impl")).newInstance();
- if (log.isDebugEnabled()) {
- log.debug("Utilisation de la classe " + classname+"Impl" + " pour " + classname);
- }
- } catch (InstantiationException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname+"Impl");
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- } catch (IllegalAccessException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname+"Impl");
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- } catch (ClassNotFoundException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible de trouver la classe " + classname+"Impl");
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- }
-
- if (result == null) {
- // le impl n'est pas trouvé on essai avec la classe elle meme
- try {
- result = entityClass.newInstance();
- if (log.isDebugEnabled()) {
- log.debug("Utilisation de la classe " + classname + " pour " + classname);
- }
- } catch (InstantiationException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname);
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- } catch (IllegalAccessException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'instancier " + classname);
- }
- if (log.isDebugEnabled()) {
- log.debug("StackTrace", eee);
- }
- }
- }
-
- if (result == null) {
- throw new TopiaException("Impossible de trouver ou d'instancier la classe " + classname);
- }
-
- return result;
- }
-
- /**
- * Par defaut ne fait rien
- */
- public void commitTransaction() throws TopiaException {
- }
-
- /**
- * Par defaut ne fait rien
- */
- public void rollbackTransaction() throws TopiaException {
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object)
- */
- public Entity create(Object ... properties) throws TopiaException{
- Map<String, Object> map = new HashMap<String, Object>();
- Object propertyName = null;
- Object value = null;
- try {
- for(int i=0; i<properties.length;) {
- propertyName = properties[i++];
- value = properties[i++];
- map.put((String)propertyName, value);
- }
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException("Wrong number of argument " + properties.length + ", you must have even number. Last property name read: " + propertyName);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException("Wrong argument type, wait property name as String and have " + propertyName.getClass().getName());
- }
-
- Entity result = create(map);
- return result;
- }
-
- /**
- * Cette methode appelle fireVetoableCreate et fireOnCreated
- * Si vous la surchargé, faites attention a appeler le super
- * ou a appeler vous aussi ces deux methodes.
- */
- public Entity create(Map<String, Object> properties) throws TopiaException {
- Entity result = instanciateNew();
-
- // TODO reflechir s'il ne faudrait pas creer l'id avant l'event precedent
- // reflechir toujours dans un context on les Entity pourrait ne pas
- // etre des TopiaEntity
- if (result instanceof TopiaEntity) {
- String topiaId = TopiaId.create(entityClass);
- TopiaEntityAbstract entity = (TopiaEntityAbstract)result;
- entity.setTopiaId(topiaId);
- entity.setTopiaContext(getContext());
- }
- try {
- for(Map.Entry<String, Object> e : properties.entrySet()) {
- String propertyName = e.getKey();
- Object value = e.getValue();
- PropertyUtils.setProperty(result, (String)propertyName, value);
- }
- } catch (IllegalAccessException eee) {
- throw new IllegalArgumentException("Can't put properties on new Object", eee);
- } catch (InvocationTargetException eee) {
- throw new IllegalArgumentException("Can't put properties on new Object", eee);
- } catch (NoSuchMethodException eee) {
- throw new IllegalArgumentException("Can't put properties on new Object", eee);
- }
-
- result.postCreate();
-
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#size()
- */
- public int size() throws TopiaException {
- int result = findAll().size();
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map)
- */
- public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException {
- try {
- // we used hibernate meta information for all persistence type
- // it's more easy than create different for all persistence
- ClassMetadata meta = getClassMetadata();
- if (meta.hasNaturalIdentifier()) {
- Entity result = findByProperties(keys);
- return result;
- }
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- throw new TopiaException("La classe " + entityClass.getName()
- + " n'a pas de cle primaire naturelle");
-
- }
-
- /**
- * private method because this is hibernate specific method and we don't
- * want expose it
- *
- * @return
- * @throws TopiaException
- */
- private ClassMetadata getClassMetadata() throws TopiaException {
- ClassMetadata meta = getContext().getHibernateFactory()
- .getClassMetadata(entityClass);
- if (meta == null) {
- meta = getContext().getHibernateFactory()
- .getClassMetadata(entityClass.getName() + "Impl");
- }
- return meta;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object)
- */
- public Entity findByPrimaryKey(Object... k) throws TopiaException {
- // TODO pour une meilleur gestion des problemes a la compilation
- // mettre un premier couple (propName, value) en argument ca evitera
- // de pouvoir appeler cette methode sans argument
- try {
- ClassMetadata meta = getClassMetadata();
- if (meta.hasNaturalIdentifier()) {
- int[] ikeys = meta.getNaturalIdentifierProperties();
- String[] pnames = meta.getPropertyNames();
-
- Map<String, Object> keys = new HashMap<String, Object>();
- for (int ikey : ikeys) {
- keys.put(pnames[ikey], k[ikey]);
- }
-
- Entity result = findByProperties(keys);
- return result;
- }
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- throw new TopiaException("La classe " + entityClass.getName()
- + " n'a pas de cle primaire naturelle");
-
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object)
- */
- public Entity findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- value = others[i++];
- properties.put((String) name, value);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2) + " La dernière propriété était: " + name, eee);
- }
- }
- Entity result = findByProperties(properties);
- return result;
- }
-
- /**
- * Recherche une entity contenant certain propriété. Pour l'instant on
- * charche toute les entités existantes pour faire la recherche
- *
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map)
- */
- public List<Entity> findAllByProperties(Map<String, Object> properties)
- throws TopiaException {
- List<Entity> all = findAll();
- List<Entity> result = new ArrayList<Entity>();
- for (Entity e : all) {
- boolean ok = true;
- try {
- for(Entry<String, Object> kv : properties.entrySet()) {
- Object entityValue = PropertyUtils.getProperty(e, kv.getKey());
- Object value = kv.getValue();
- if (!ObjectUtils.equals(entityValue, value)) {
- ok = false;
- break;
- }
- }
- } catch (IllegalAccessException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- } catch (InvocationTargetException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- } catch (NoSuchMethodException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- }
- if (ok) {
- result.add(e);
- }
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object)
- */
- public List<Entity> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- value = others[i++];
- properties.put((String) name, value);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2) + " La dernière propriété était: " + name, eee);
- }
- }
- List<Entity> result = findAllByProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
- */
- public Entity findContainsProperties(Map<String, Collection> properties)
- throws TopiaException {
- List<Entity> results = findAllContainsProperties(properties);
- Entity result = null;
- if (results.size() > 0) {
- result = results.get(0);
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
- */
- public Entity findContainsProperties(String propertyName, Collection values, Object... others)
- throws TopiaException {
- Map<String, Collection> properties = new HashMap<String, Collection>();
- properties.put(propertyName, values);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- values = (Collection)others[i++];
- properties.put((String) name, values);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2) + " La dernière propriété était: " + name, eee);
- }
- }
- Entity result = findContainsProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
- */
- public List<Entity> findAllContainsProperties(Map<String, Collection> properties)
- throws TopiaException {
- List<Entity> all = findAll();
- List<Entity> result = new ArrayList<Entity>();
- for (Entity e : all) {
- boolean ok = true;
- try {
- for(Entry<String, Collection> kv : properties.entrySet()) {
- Collection entityValues = (Collection)PropertyUtils.getProperty(e, kv.getKey());
- Collection values = kv.getValue();
- if (!entityValues.containsAll(values)) {
- ok = false;
- break;
- }
- }
- } catch (IllegalAccessException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- } catch (InvocationTargetException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- } catch (NoSuchMethodException eee) {
- ok = false;
- if (log.isWarnEnabled()) {
- log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
- }
- }
- if (ok) {
- result.add(e);
- }
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
- */
- public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others)
- throws TopiaException {
- Map<String, Collection> properties = new HashMap<String, Collection>();
- properties.put(propertyName, values);
- Object name = null;
- for (int i = 0; i < others.length;) {
- try {
- name = others[i++];
- values = (Collection)others[i++];
- properties.put((String) name, values);
- } catch (ClassCastException eee) {
- throw new IllegalArgumentException(
- "Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
- } catch (ArrayIndexOutOfBoundsException eee) {
- throw new IllegalArgumentException(
- "Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2) + " La dernière propriété était: " + name, eee);
- }
- }
- List<Entity> result = findAllContainsProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByTopiaId()
- */
- public Entity findByTopiaId(String k) throws TopiaException {
- Entity result = findByProperty("topiaId", k);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAll()
- */
- public List<Entity> findAll() throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- List<Entity> result = findAllByProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object)
- */
- public List<Entity> findAllByProperty(String propertyName, Object value) throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- List<Entity> result = findAllByProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object)
- */
- public Entity findByProperty(String propertyName, Object value)
- throws TopiaException {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(propertyName, value);
- Entity result = findByProperties(properties);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
- */
- public Entity findByProperties(Map<String, Object> properties)
- throws TopiaException {
- List<Entity> listResult = findAllByProperties(properties);
- Entity result = null;
- if (listResult.size() > 0) {
- result = listResult.get(0);
- }
- return result;
- }
-
- @Deprecated
- private Criterion computeCriterions(Object ... values) {
- if (values == null) {
- return null;
- }
- Criterion criterion = null;
- for (Object value : values) {
- criterion = or(criterion, computeCriterion(value));
- }
- return criterion;
- }
-
- @Deprecated
- private Criterion computeCriterion(Object value) {
- Criterion criterion = null;
- SearchFields fields = entityClass.getAnnotation(SearchFields.class);
- String textValue = "%" + value + "%";
- //textFields
- String[] textFields = fields.txtFields();
- for (String propName : textFields) {
- criterion = or(criterion, Restrictions.like(propName, textValue));
- }
- //numFields
- boolean isNumber = (value instanceof Number);
- if (value instanceof String) {
- try {
- Double.parseDouble((String) value);
- isNumber = true;
- } catch (NumberFormatException nfe) {
- isNumber = false;
- }
-
- }
- if (isNumber) {
- String[] numFields = fields.numFields();
- for (String propName : numFields) {
- criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'"));
- }
- }
- //boolFields
- boolean isBoolean = (value instanceof Boolean);
- if (value instanceof String) {
- isBoolean |= ("true".equalsIgnoreCase((String)value)
- || "false".equalsIgnoreCase((String)value));
- }
- if (isBoolean) {
- Boolean booleanValue;
- if (value instanceof String) {
- booleanValue = Boolean.valueOf((String)value);
- } else {
- booleanValue = (Boolean)value;
- }
- String[] boolFields = fields.numFields();
- for (String propName : boolFields) {
- criterion = or(criterion, Restrictions.eq(propName, booleanValue));
- }
- }
- //timeFields
- String[] timeFields = fields.dateFields();
- for (String propName : timeFields) {
- criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'"));
- }
- return criterion;
- }
-
- @Deprecated
- private Criterion or(Criterion crit1, Criterion crit2) {
- if (crit1 == null) {
- return crit2;
- }
- if (crit2 == null) {
- return crit1;
- }
- return Restrictions.or(crit1, crit2);
- }
-
- public void addTopiaEntityListener(TopiaEntityListener listener) {
- getContext().addTopiaEntityListener((Class<TopiaEntity>) entityClass, listener);
- }
-
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getContext().addTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable);
- }
-
- public void removeTopiaEntityListener(TopiaEntityListener listener) {
- getContext().removeTopiaEntityListener((Class<TopiaEntity>) entityClass, listener);
- }
-
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getContext().removeTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable);
- }
-
-
-} //TopiaDAOAbstract
Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java)
===================================================================
--- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java (rev 0)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,707 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaDAOAbstract.java
+ *
+ * Created: 31 déc. 2005 13:10:34
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.event.TopiaEntityListener;
+import org.codelutin.topia.event.TopiaEntityVetoable;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+import org.codelutin.topia.persistence.hibernate.TopiaDAOHibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.metadata.ClassMetadata;
+
+
+/**
+ * Cette classe permet d'avoir un ensemble de méthode implantée de façon
+ * standard pour les différents DAO existant (FlatFile, Hibernate).
+ * Certaine méthode implanté ici sont particulièrement inéficace et il
+ * est conseillé de les surcharger dans les classes DAO spécifiques.
+ *
+ * Certain accès à Hibernate est tout de même fait ici, car on a pris le
+ * choix de se basé entièrement sur hibernate pour la persistence, et il
+ * est ainsi possible d'accèder au meta information hibernate sur les classes
+ * lorque l'on en a besoin.
+ *
+ * @author poussin
+ *
+ */
+
+public abstract class TopiaDAOAbstract<Entity extends TopiaEntity> implements TopiaDAO<Entity> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(TopiaDAOAbstract.class);
+
+ protected Class<Entity> entityClass = null;
+
+ protected TopiaContextImplementor context = null;
+
+ public Class<Entity> getEntityClass() {
+ throw new UnsupportedOperationException("This method must be overided in generated DAO");
+ }
+
+ /**
+ * Retourne l'id de l'entity
+ * @param e l'entity
+ * @return l'id de l'entity ou null si pas trouvé
+ * @throws TopiaException Si une erreur survient durant la recherche
+ */
+ protected Serializable getId(Entity e) throws TopiaException {
+ ClassMetadata meta = getClassMetadata();
+ String idPropName = meta.getIdentifierPropertyName();
+
+ Serializable result;
+ try {
+ result = (Serializable)PropertyUtils.getSimpleProperty(e, idPropName);
+ } catch (IllegalAccessException eee) {
+ throw new TopiaException("Impossible de récuperer l'identifiant " +
+ idPropName + " de l'entite: " + e);
+ } catch (InvocationTargetException eee) {
+ throw new TopiaException("Impossible de récuperer l'identifiant " +
+ idPropName + " de l'entite: " + e);
+ } catch (NoSuchMethodException eee) {
+ throw new TopiaException("Impossible de récuperer l'identifiant " +
+ idPropName + " de l'entite: " + e);
+ }
+ return result;
+ }
+
+ /**
+ * Retourne l'id de l'entity representer comme une map
+ * @param map l'entity en representation map
+ * @return l'id de l'entity ou null si pas trouvé
+ * @throws TopiaException Si une erreur survient durant la recherche
+ */
+ protected Serializable getId(Map map) throws TopiaException {
+ try {
+ ClassMetadata meta = getClassMetadata();
+ String idPropName = meta.getIdentifierPropertyName();
+
+ Serializable id = (Serializable)map.get(idPropName);
+ return id;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+
+ /**
+ * When TopiaContextImpl create the TopiaDAOHibernate, it must call this method just
+ * after
+ *
+ * @param entityClass
+ */
+ public void init(TopiaContextImplementor context, Class<Entity> entityClass) throws TopiaException {
+ log.debug("init dao for " + entityClass.getName());
+ this.context = context;
+ this.entityClass = entityClass;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#getContext()
+ */
+ public TopiaContextImplementor getContext() {
+ return context;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Entity instanciateNew() throws TopiaException {
+ Entity result = null;
+ String classname = entityClass.getName();
+ try {
+ // on commence par essayer d'instancier le Impl
+ result = ((Class<Entity>)Class.forName(classname+"Impl")).newInstance();
+ if (log.isDebugEnabled()) {
+ log.debug("Utilisation de la classe " + classname+"Impl" + " pour " + classname);
+ }
+ } catch (InstantiationException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'instancier " + classname+"Impl");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ } catch (IllegalAccessException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'instancier " + classname+"Impl");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ } catch (ClassNotFoundException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible de trouver la classe " + classname+"Impl");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ }
+
+ if (result == null) {
+ // le impl n'est pas trouvé on essai avec la classe elle meme
+ try {
+ result = entityClass.newInstance();
+ if (log.isDebugEnabled()) {
+ log.debug("Utilisation de la classe " + classname + " pour " + classname);
+ }
+ } catch (InstantiationException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'instancier " + classname);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ } catch (IllegalAccessException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'instancier " + classname);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("StackTrace", eee);
+ }
+ }
+ }
+
+ if (result == null) {
+ throw new TopiaException("Impossible de trouver ou d'instancier la classe " + classname);
+ }
+
+ return result;
+ }
+
+ /**
+ * Par defaut ne fait rien
+ */
+ public void commitTransaction() throws TopiaException {
+ }
+
+ /**
+ * Par defaut ne fait rien
+ */
+ public void rollbackTransaction() throws TopiaException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object)
+ */
+ public Entity create(Object ... properties) throws TopiaException{
+ Map<String, Object> map = new HashMap<String, Object>();
+ Object propertyName = null;
+ Object value = null;
+ try {
+ for(int i=0; i<properties.length;) {
+ propertyName = properties[i++];
+ value = properties[i++];
+ map.put((String)propertyName, value);
+ }
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException("Wrong number of argument " + properties.length + ", you must have even number. Last property name read: " + propertyName);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException("Wrong argument type, wait property name as String and have " + propertyName.getClass().getName());
+ }
+
+ Entity result = create(map);
+ return result;
+ }
+
+ /**
+ * Cette methode appelle fireVetoableCreate et fireOnCreated
+ * Si vous la surchargé, faites attention a appeler le super
+ * ou a appeler vous aussi ces deux methodes.
+ */
+ public Entity create(Map<String, Object> properties) throws TopiaException {
+ Entity result = instanciateNew();
+
+ // TODO reflechir s'il ne faudrait pas creer l'id avant l'event precedent
+ // reflechir toujours dans un context on les Entity pourrait ne pas
+ // etre des TopiaEntity
+ if (result instanceof TopiaEntity) {
+ String topiaId = TopiaId.create(entityClass);
+ TopiaEntityAbstract entity = (TopiaEntityAbstract)result;
+ entity.setTopiaId(topiaId);
+ entity.setTopiaContext(getContext());
+ }
+ try {
+ for(Map.Entry<String, Object> e : properties.entrySet()) {
+ String propertyName = e.getKey();
+ Object value = e.getValue();
+ PropertyUtils.setProperty(result, (String)propertyName, value);
+ }
+ } catch (IllegalAccessException eee) {
+ throw new IllegalArgumentException("Can't put properties on new Object", eee);
+ } catch (InvocationTargetException eee) {
+ throw new IllegalArgumentException("Can't put properties on new Object", eee);
+ } catch (NoSuchMethodException eee) {
+ throw new IllegalArgumentException("Can't put properties on new Object", eee);
+ }
+
+ result.postCreate();
+
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#size()
+ */
+ public int size() throws TopiaException {
+ int result = findAll().size();
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map)
+ */
+ public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException {
+ try {
+ // we used hibernate meta information for all persistence type
+ // it's more easy than create different for all persistence
+ ClassMetadata meta = getClassMetadata();
+ if (meta.hasNaturalIdentifier()) {
+ Entity result = findByProperties(keys);
+ return result;
+ }
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ throw new TopiaException("La classe " + entityClass.getName()
+ + " n'a pas de cle primaire naturelle");
+
+ }
+
+ /**
+ * private method because this is hibernate specific method and we don't
+ * want expose it
+ *
+ * @return
+ * @throws TopiaException
+ */
+ private ClassMetadata getClassMetadata() throws TopiaException {
+ ClassMetadata meta = getContext().getHibernateFactory()
+ .getClassMetadata(entityClass);
+ if (meta == null) {
+ meta = getContext().getHibernateFactory()
+ .getClassMetadata(entityClass.getName() + "Impl");
+ }
+ return meta;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object)
+ */
+ public Entity findByPrimaryKey(Object... k) throws TopiaException {
+ // TODO pour une meilleur gestion des problemes a la compilation
+ // mettre un premier couple (propName, value) en argument ca evitera
+ // de pouvoir appeler cette methode sans argument
+ try {
+ ClassMetadata meta = getClassMetadata();
+ if (meta.hasNaturalIdentifier()) {
+ int[] ikeys = meta.getNaturalIdentifierProperties();
+ String[] pnames = meta.getPropertyNames();
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ for (int ikey : ikeys) {
+ keys.put(pnames[ikey], k[ikey]);
+ }
+
+ Entity result = findByProperties(keys);
+ return result;
+ }
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ throw new TopiaException("La classe " + entityClass.getName()
+ + " n'a pas de cle primaire naturelle");
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object)
+ */
+ public Entity findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, value);
+ Object name = null;
+ for (int i = 0; i < others.length;) {
+ try {
+ name = others[i++];
+ value = others[i++];
+ properties.put((String) name, value);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et non pas "
+ + propertyName.getClass().getName(), eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2) + " La dernière propriété était: " + name, eee);
+ }
+ }
+ Entity result = findByProperties(properties);
+ return result;
+ }
+
+ /**
+ * Recherche une entity contenant certain propriété. Pour l'instant on
+ * charche toute les entités existantes pour faire la recherche
+ *
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperties(java.util.Map)
+ */
+ public List<Entity> findAllByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ List<Entity> all = findAll();
+ List<Entity> result = new ArrayList<Entity>();
+ for (Entity e : all) {
+ boolean ok = true;
+ try {
+ for(Entry<String, Object> kv : properties.entrySet()) {
+ Object entityValue = PropertyUtils.getProperty(e, kv.getKey());
+ Object value = kv.getValue();
+ if (!ObjectUtils.equals(entityValue, value)) {
+ ok = false;
+ break;
+ }
+ }
+ } catch (IllegalAccessException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
+ }
+ } catch (InvocationTargetException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
+ }
+ } catch (NoSuchMethodException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
+ }
+ }
+ if (ok) {
+ result.add(e);
+ }
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object)
+ */
+ public List<Entity> findAllByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, value);
+ Object name = null;
+ for (int i = 0; i < others.length;) {
+ try {
+ name = others[i++];
+ value = others[i++];
+ properties.put((String) name, value);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et non pas "
+ + propertyName.getClass().getName(), eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2) + " La dernière propriété était: " + name, eee);
+ }
+ }
+ List<Entity> result = findAllByProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
+ */
+ public Entity findContainsProperties(Map<String, Collection> properties)
+ throws TopiaException {
+ List<Entity> results = findAllContainsProperties(properties);
+ Entity result = null;
+ if (results.size() > 0) {
+ result = results.get(0);
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
+ */
+ public Entity findContainsProperties(String propertyName, Collection values, Object... others)
+ throws TopiaException {
+ Map<String, Collection> properties = new HashMap<String, Collection>();
+ properties.put(propertyName, values);
+ Object name = null;
+ for (int i = 0; i < others.length;) {
+ try {
+ name = others[i++];
+ values = (Collection)others[i++];
+ properties.put((String) name, values);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et non pas "
+ + propertyName.getClass().getName(), eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2) + " La dernière propriété était: " + name, eee);
+ }
+ }
+ Entity result = findContainsProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
+ */
+ public List<Entity> findAllContainsProperties(Map<String, Collection> properties)
+ throws TopiaException {
+ List<Entity> all = findAll();
+ List<Entity> result = new ArrayList<Entity>();
+ for (Entity e : all) {
+ boolean ok = true;
+ try {
+ for(Entry<String, Collection> kv : properties.entrySet()) {
+ Collection entityValues = (Collection)PropertyUtils.getProperty(e, kv.getKey());
+ Collection values = kv.getValue();
+ if (!entityValues.containsAll(values)) {
+ ok = false;
+ break;
+ }
+ }
+ } catch (IllegalAccessException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
+ }
+ } catch (InvocationTargetException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
+ }
+ } catch (NoSuchMethodException eee) {
+ ok = false;
+ if (log.isWarnEnabled()) {
+ log.warn("Impossible d'acceder a la methode demandé pour l'obbjet " + e, eee);
+ }
+ }
+ if (ok) {
+ result.add(e);
+ }
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
+ */
+ public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others)
+ throws TopiaException {
+ Map<String, Collection> properties = new HashMap<String, Collection>();
+ properties.put(propertyName, values);
+ Object name = null;
+ for (int i = 0; i < others.length;) {
+ try {
+ name = others[i++];
+ values = (Collection)others[i++];
+ properties.put((String) name, values);
+ } catch (ClassCastException eee) {
+ throw new IllegalArgumentException(
+ "Les noms des propriétés doivent être des chaines et non pas "
+ + propertyName.getClass().getName(), eee);
+ } catch (ArrayIndexOutOfBoundsException eee) {
+ throw new IllegalArgumentException(
+ "Le nombre d'argument n'est pas un nombre pair: "
+ + (others.length + 2) + " La dernière propriété était: " + name, eee);
+ }
+ }
+ List<Entity> result = findAllContainsProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByTopiaId()
+ */
+ public Entity findByTopiaId(String k) throws TopiaException {
+ Entity result = findByProperty("topiaId", k);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAll()
+ */
+ public List<Entity> findAll() throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ List<Entity> result = findAllByProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object)
+ */
+ public List<Entity> findAllByProperty(String propertyName, Object value) throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, value);
+ List<Entity> result = findAllByProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object)
+ */
+ public Entity findByProperty(String propertyName, Object value)
+ throws TopiaException {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(propertyName, value);
+ Entity result = findByProperties(properties);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
+ */
+ public Entity findByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ List<Entity> listResult = findAllByProperties(properties);
+ Entity result = null;
+ if (listResult.size() > 0) {
+ result = listResult.get(0);
+ }
+ return result;
+ }
+
+ @Deprecated
+ private Criterion computeCriterions(Object ... values) {
+ if (values == null) {
+ return null;
+ }
+ Criterion criterion = null;
+ for (Object value : values) {
+ criterion = or(criterion, computeCriterion(value));
+ }
+ return criterion;
+ }
+
+ @Deprecated
+ private Criterion computeCriterion(Object value) {
+ Criterion criterion = null;
+ SearchFields fields = entityClass.getAnnotation(SearchFields.class);
+ String textValue = "%" + value + "%";
+ //textFields
+ String[] textFields = fields.txtFields();
+ for (String propName : textFields) {
+ criterion = or(criterion, Restrictions.like(propName, textValue));
+ }
+ //numFields
+ boolean isNumber = (value instanceof Number);
+ if (value instanceof String) {
+ try {
+ Double.parseDouble((String) value);
+ isNumber = true;
+ } catch (NumberFormatException nfe) {
+ isNumber = false;
+ }
+
+ }
+ if (isNumber) {
+ String[] numFields = fields.numFields();
+ for (String propName : numFields) {
+ criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'"));
+ }
+ }
+ //boolFields
+ boolean isBoolean = (value instanceof Boolean);
+ if (value instanceof String) {
+ isBoolean |= ("true".equalsIgnoreCase((String)value)
+ || "false".equalsIgnoreCase((String)value));
+ }
+ if (isBoolean) {
+ Boolean booleanValue;
+ if (value instanceof String) {
+ booleanValue = Boolean.valueOf((String)value);
+ } else {
+ booleanValue = (Boolean)value;
+ }
+ String[] boolFields = fields.numFields();
+ for (String propName : boolFields) {
+ criterion = or(criterion, Restrictions.eq(propName, booleanValue));
+ }
+ }
+ //timeFields
+ String[] timeFields = fields.dateFields();
+ for (String propName : timeFields) {
+ criterion = or(criterion, Restrictions.sqlRestriction(propName + " like '" + textValue + "'"));
+ }
+ return criterion;
+ }
+
+ @Deprecated
+ private Criterion or(Criterion crit1, Criterion crit2) {
+ if (crit1 == null) {
+ return crit2;
+ }
+ if (crit2 == null) {
+ return crit1;
+ }
+ return Restrictions.or(crit1, crit2);
+ }
+
+ public void addTopiaEntityListener(TopiaEntityListener listener) {
+ getContext().addTopiaEntityListener((Class<TopiaEntity>) entityClass, listener);
+ }
+
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getContext().addTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable);
+ }
+
+ public void removeTopiaEntityListener(TopiaEntityListener listener) {
+ getContext().removeTopiaEntityListener((Class<TopiaEntity>) entityClass, listener);
+ }
+
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getContext().removeTopiaEntityVetoable((Class<TopiaEntity>) entityClass, vetoable);
+ }
+
+
+} //TopiaDAOAbstract
Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,278 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * TopiaDAODelegator.java
- *
- * Created: 30 déc. 2005 22:28:48
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
-package org.codelutin.topia.persistence;
-
-import java.security.Permission;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.event.TopiaEntityListener;
-import org.codelutin.topia.event.TopiaEntityVetoable;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-
-
-/**
- * Cette classe est utilisé par les DAO générés pour encapsuler un véritable
- * DAO (Hibernate, FlatFile)
- * On utilise donc le pattern (TODO retrouver le nom du pattern) qui permet
- * de générer les classes sans ce soucier de quel DAO va etre utilisé
- * a l'execution.
- *
- * @author poussin
- *
- */
-
-public class TopiaDAODelegator<Entity extends TopiaEntity> implements TopiaDAO<Entity> {
-
- /**
- * DAO reel sur lequel on peut s'appuyer pour faire les requetes
- */
- protected TopiaDAO<Entity> parentDAO = null;
-
- /**
- * A priori seul les enfants on besoin de le recuperer
- */
- protected TopiaDAO<Entity> getParentDAO() {
- return parentDAO;
- }
- /**
- * Le setter est public car potentiellement le context qui le cree n'est
- * pas dans le meme package, mais seul le context doit utiliser cette
- * methode
- */
- public void setParentDAO(TopiaDAO<Entity> v) {
- this.parentDAO = v;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#init(org.codelutin.topia.TopiaContextImpl, java.lang.Class)
- */
- public void init(TopiaContextImplementor context, Class entityClass) throws TopiaException {
- // rien a faire cette methode a ete appele sur le parentDAO
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#getEntityClass()
- */
- public Class<Entity> getEntityClass() {
- return getParentDAO().getEntityClass();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#getContext()
- */
- public TopiaContextImplementor getContext() {
- return getParentDAO().getContext();
- }
-
- public void commitTransaction() throws TopiaException {
- getParentDAO().commitTransaction();
- }
- public void rollbackTransaction() throws TopiaException {
- getParentDAO().rollbackTransaction();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object...)
- */
- public Entity create(Object... properties) throws TopiaException {
- return getParentDAO().create(properties);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#create(java.util.Map)
- */
- public Entity create(Map<String, Object> properties) throws TopiaException {
- return getParentDAO().create(properties);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#update(Entity)
- */
- public Entity update(Entity e) throws TopiaException {
- return getParentDAO().update(e);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#delete(Entity)
- */
- public void delete(Entity e) throws TopiaException {
- getParentDAO().delete(e);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByTopiaId(java.lang.Object)
- */
- public Entity findByTopiaId(String k) throws TopiaException {
- return getParentDAO().findByTopiaId(k);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAll()
- */
- public List<Entity> findAll() throws TopiaException {
- return getParentDAO().findAll();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#size()
- */
- public int size() throws TopiaException {
- return getParentDAO().size();
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map)
- */
- public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException {
- return getParentDAO().findByPrimaryKey(keys);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object...)
- */
- public Entity findByPrimaryKey(Object... k) throws TopiaException {
- return getParentDAO().findByPrimaryKey(k);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object)
- */
- public Entity findByProperty(String propertyName, Object value)
- throws TopiaException {
- return getParentDAO().findByProperty(propertyName, value);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object...)
- */
- public Entity findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
- return getParentDAO().findByProperties(propertyName, value, others);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
- */
- public Entity findByProperties(Map<String, Object> properties) throws TopiaException {
- return getParentDAO().findByProperties(properties);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object)
- */
- public List<Entity> findAllByProperty(String propertyName, Object value)
- throws TopiaException {
- return getParentDAO().findAllByProperty(propertyName, value);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object...)
- */
- public List<Entity> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
- return getParentDAO().findAllByProperties(propertyName, value, others);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map)
- */
- public List<Entity> findAllByProperties(Map<String, Object> properties) throws TopiaException {
- return getParentDAO().findAllByProperties(properties);
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
- */
- public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException {
- return getParentDAO().findContainsProperties(properties);
- }
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
- */
- public Entity findContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException {
- return getParentDAO().findContainsProperties(propertyName, values, others);
- }
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
- */
- public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
- return getParentDAO().findAllContainsProperties(properties);
- }
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
- */
- public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException {
- return getParentDAO().findAllContainsProperties(propertyName, values, others);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener)
- */
- public void addTopiaEntityListener(TopiaEntityListener listener) {
- getParentDAO().addTopiaEntityListener(listener);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable)
- */
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getParentDAO().addTopiaEntityVetoable(vetoable);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener)
- */
- public void removeTopiaEntityListener(TopiaEntityListener listener) {
- getParentDAO().removeTopiaEntityListener(listener);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable)
- */
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getParentDAO().removeTopiaEntityVetoable(vetoable);
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
- */
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
- return getParentDAO().getRequestPermission(topiaId, actions);
- }
-
-} //TopiaDAODelegator
Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java)
===================================================================
--- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java (rev 0)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,282 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+ * TopiaDAODelegator.java
+ *
+ * Created: 30 déc. 2005 22:28:48
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+
+package org.codelutin.topia.persistence;
+
+import java.security.Permission;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.event.TopiaEntityListener;
+import org.codelutin.topia.event.TopiaEntityVetoable;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+
+
+/**
+ * Cette classe est utilisé par les DAO générés pour encapsuler un véritable
+ * DAO (Hibernate, FlatFile)
+ * On utilise donc le pattern (TODO retrouver le nom du pattern) qui permet
+ * de générer les classes sans ce soucier de quel DAO va etre utilisé
+ * a l'execution.
+ *
+ * @author poussin
+ *
+ */
+
+public class TopiaDAODelegator<Entity extends TopiaEntity> implements TopiaDAO<Entity> {
+
+ /**
+ * DAO reel sur lequel on peut s'appuyer pour faire les requetes
+ */
+ protected TopiaDAO<Entity> parentDAO = null;
+
+ /**
+ * A priori seul les enfants on besoin de le recuperer
+ */
+ protected TopiaDAO<Entity> getParentDAO() {
+ return parentDAO;
+ }
+ /**
+ * Le setter est public car potentiellement le context qui le cree n'est
+ * pas dans le meme package, mais seul le context doit utiliser cette
+ * methode
+ */
+ public void setParentDAO(TopiaDAO<Entity> v) {
+ this.parentDAO = v;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#init(org.codelutin.topia.TopiaContextImpl, java.lang.Class)
+ */
+ public void init(TopiaContextImplementor context, Class entityClass) throws TopiaException {
+ // rien a faire cette methode a ete appele sur le parentDAO
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#getEntityClass()
+ */
+ public Class<Entity> getEntityClass() {
+ return getParentDAO().getEntityClass();
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#getContext()
+ */
+ public TopiaContextImplementor getContext() {
+ return getParentDAO().getContext();
+ }
+
+ public void commitTransaction() throws TopiaException {
+ getParentDAO().commitTransaction();
+ }
+ public void rollbackTransaction() throws TopiaException {
+ getParentDAO().rollbackTransaction();
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#create(java.lang.String, java.lang.Object, java.lang.Object...)
+ */
+ public Entity create(Object... properties) throws TopiaException {
+ return getParentDAO().create(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#create(java.util.Map)
+ */
+ public Entity create(Map<String, Object> properties) throws TopiaException {
+ return getParentDAO().create(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#update(Entity)
+ */
+ public Entity update(Entity e) throws TopiaException {
+ return getParentDAO().update(e);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#delete(Entity)
+ */
+ public void delete(Entity e) throws TopiaException {
+ getParentDAO().delete(e);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByTopiaId(java.lang.Object)
+ */
+ public Entity findByTopiaId(String k) throws TopiaException {
+ return getParentDAO().findByTopiaId(k);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAll()
+ */
+ public List<Entity> findAll() throws TopiaException {
+ return getParentDAO().findAll();
+ }
+
+ public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
+ return getParentDAO().findAllWithOrder(propertyNames);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#size()
+ */
+ public int size() throws TopiaException {
+ return getParentDAO().size();
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.util.Map)
+ */
+ public Entity findByPrimaryKey(Map<String, Object> keys) throws TopiaException {
+ return getParentDAO().findByPrimaryKey(keys);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByPrimaryKey(java.lang.Object...)
+ */
+ public Entity findByPrimaryKey(Object... k) throws TopiaException {
+ return getParentDAO().findByPrimaryKey(k);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperty(java.lang.String, java.lang.Object)
+ */
+ public Entity findByProperty(String propertyName, Object value)
+ throws TopiaException {
+ return getParentDAO().findByProperty(propertyName, value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.lang.String, java.lang.Object, java.lang.Object...)
+ */
+ public Entity findByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+ return getParentDAO().findByProperties(propertyName, value, others);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
+ */
+ public Entity findByProperties(Map<String, Object> properties) throws TopiaException {
+ return getParentDAO().findByProperties(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperty(java.lang.String, java.lang.Object)
+ */
+ public List<Entity> findAllByProperty(String propertyName, Object value)
+ throws TopiaException {
+ return getParentDAO().findAllByProperty(propertyName, value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.lang.String, java.lang.Object, java.lang.Object...)
+ */
+ public List<Entity> findAllByProperties(String propertyName, Object value,
+ Object... others) throws TopiaException {
+ return getParentDAO().findAllByProperties(propertyName, value, others);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map)
+ */
+ public List<Entity> findAllByProperties(Map<String, Object> properties) throws TopiaException {
+ return getParentDAO().findAllByProperties(properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
+ */
+ public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException {
+ return getParentDAO().findContainsProperties(properties);
+ }
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
+ */
+ public Entity findContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException {
+ return getParentDAO().findContainsProperties(propertyName, values, others);
+ }
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
+ */
+ public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
+ return getParentDAO().findAllContainsProperties(properties);
+ }
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.lang.String, java.util.Collection, java.lang.Object[])
+ */
+ public List<Entity> findAllContainsProperties(String propertyName, Collection values, Object... others) throws TopiaException {
+ return getParentDAO().findAllContainsProperties(propertyName, values, others);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener)
+ */
+ public void addTopiaEntityListener(TopiaEntityListener listener) {
+ getParentDAO().addTopiaEntityListener(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#addTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable)
+ */
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getParentDAO().addTopiaEntityVetoable(vetoable);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityListener(org.codelutin.topia.event.TopiaEntityListener)
+ */
+ public void removeTopiaEntityListener(TopiaEntityListener listener) {
+ getParentDAO().removeTopiaEntityListener(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#removeTopiaEntityVetoable(org.codelutin.topia.event.TopiaEntityVetoable)
+ */
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getParentDAO().removeTopiaEntityVetoable(vetoable);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
+ */
+ public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
+ return getParentDAO().getRequestPermission(topiaId, actions);
+ }
+
+} //TopiaDAODelegator
Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,73 +0,0 @@
-package org.codelutin.topia.persistence;
-
-import org.codelutin.topia.TopiaContext;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-
-import java.util.List;
-
-/** @author chemit */
-public class TopiaEntityEnumEntry<T extends TopiaEntity> implements java.io.Serializable {
-
- /** the contract class of the entity's type. */
- protected Class<T> contractClass;
-
- /** the concrete implementation class of the entity's type. */
- protected Class<T> implementationClass;
-
- private static final long serialVersionUID = 1L;
-
- public TopiaEntityEnumEntry(Class<T> contractClass) {
- this.contractClass = contractClass;
- }
-
- public Class<T> getContractClass() {
- return contractClass;
- }
-
- @SuppressWarnings({"unchecked"})
- public Class<T> getImplementationClass() {
- if (implementationClass == null) {
- try {
- implementationClass = (Class<T>) Class.forName(contractClass.getName() + "Impl");
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("could not find implementation for entity contract " + contractClass);
- }
- }
- return implementationClass;
- }
-
- public TopiaDAO<T> getDAO(TopiaContext ctxt) throws TopiaException {
- TopiaContextImplementor ci = (TopiaContextImplementor) ctxt;
- return ci.getDAO(contractClass);
- }
-
- public T create(TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- T newInstance = dao.create();
- // attach topia context to entity (to allow propertyChangeSupport for entity)
- ((TopiaEntityAbstract) newInstance).setTopiaContext(ctxt);
- return newInstance;
- }
-
- public T update(T entity, TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.update(entity);
- }
-
- public void delete(T entity, TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- dao.delete(entity);
- }
-
- public List<T> findAll(TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findAll();
- }
-
- public T findByTopiaId(String topiaId, TopiaContext ctxt) throws TopiaException {
- TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findByTopiaId(topiaId);
- }
-
-}
Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java)
===================================================================
--- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java (rev 0)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,155 @@
+package org.codelutin.topia.persistence;
+
+import org.codelutin.topia.TopiaContext;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/** @author chemit */
+public class TopiaEntityEnumEntry<T extends TopiaEntity> implements java.io.Serializable {
+
+ /** the contract class of the entity's type. */
+ protected Class<T> contractClass;
+
+ /** the concrete implementation class of the entity's type. */
+ protected Class<T> implementationClass;
+
+ private static final long serialVersionUID = 1L;
+
+ public TopiaEntityEnumEntry(Class<T> contractClass) {
+ this.contractClass = contractClass;
+ }
+
+ public Class<T> getContractClass() {
+ return contractClass;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public Class<T> getImplementationClass() {
+ if (implementationClass == null) {
+ try {
+ implementationClass = (Class<T>) Class.forName(contractClass.getName() + "Impl");
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("could not find implementation for entity contract " + contractClass);
+ }
+ }
+ return implementationClass;
+ }
+
+ public TopiaDAO<T> getDAO(TopiaContext ctxt) throws TopiaException {
+ TopiaContextImplementor ci = (TopiaContextImplementor) ctxt;
+ return ci.getDAO(contractClass);
+ }
+
+ public T create(TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ T newInstance = dao.create();
+ // attach topia context to entity (to allow propertyChangeSupport for entity)
+ ((TopiaEntityAbstract) newInstance).setTopiaContext(ctxt);
+ return newInstance;
+ }
+
+ public T create(TopiaContext ctxt, Object... properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.create(properties);
+ }
+
+ public T create(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.create(properties);
+ }
+
+ public T update(T entity, TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.update(entity);
+ }
+
+ public void delete(T entity, TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ dao.delete(entity);
+ }
+
+ public int size(TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.size();
+ }
+
+ public List<T> findAll(TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAll();
+ }
+
+ public List<T> findAllWithOrder(TopiaContext ctxt,String... propertyNames) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllWithOrder(propertyNames);
+ }
+
+ public T findByTopiaId(String topiaId, TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByTopiaId(topiaId);
+ }
+
+ public T findByPrimaryKey(TopiaContext ctxt, Map<String, Object> keys) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByPrimaryKey(keys);
+ }
+
+ public T findByPrimaryKey(TopiaContext ctxt, Object... k) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByPrimaryKey(k);
+ }
+
+ public T findByProperty(TopiaContext ctxt, String propertyName, Object value) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperty(propertyName, value);
+ }
+
+ public T findByProperties(TopiaContext ctxt, String propertyName, Object value, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperties(propertyName, value, others);
+ }
+
+ public T findByProperties(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperties(properties);
+ }
+
+ public List<T> findAllByProperty(TopiaContext ctxt, String propertyName, Object value) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperty(propertyName, value);
+ }
+
+ public List<T> findAllByProperties(TopiaContext ctxt, String propertyName, Object value, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperties(propertyName, value, others);
+ }
+
+ public List<T> findAllByProperties(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperties(properties);
+ }
+
+ public T findContainsProperties(TopiaContext ctxt, Map<String, Collection> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findContainsProperties(properties);
+ }
+
+ public T findContainsProperties(TopiaContext ctxt, String propertyName, Collection values, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findContainsProperties(propertyName, values, others);
+ }
+
+ public List<T> findAllContainsProperties(TopiaContext ctxt, Map<String, Collection> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllContainsProperties(properties);
+ }
+
+ public List<T> findAllContainsProperties(TopiaContext ctxt, String propertyName, Collection values, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllContainsProperties(propertyName, values, others);
+ }
+
+}
Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,543 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/*******************************************************************************
- * TopiaDAOFlatFile.java
- *
- * Created: 30 déc. 2005 03:11:55
- *
- * @author poussin
- *
- * @version $Revision$
- *
- * Last update: $Date$ by : $Author$
- */
-
-package org.codelutin.topia.persistence.flatfile;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
-import java.security.Permission;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.commons.collections.map.AbstractReferenceMap;
-import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.commons.lang.ClassUtils;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.framework.TopiaContextImplementor;
-import org.codelutin.topia.framework.TopiaUtil;
-import org.codelutin.topia.persistence.TopiaDAOAbstract;
-import org.codelutin.topia.persistence.TopiaEntity;
-import org.codelutin.util.FileUtil;
-import org.hibernate.Criteria;
-import org.hibernate.FlushMode;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Projection;
-
-/**
- * <p>
- * <b>ATTENTION:</b> Le rollback des transactions n'est pas du tout pris en
- * compte. Et l'implantation n'est pas fait pour les supporter un jour. Il
- * faudrait pour cela que le context préviennent les DAO, lors d'un
- * commit/rollback.
- * <p>
- * <b>REMARQUE:</b> pour l'instant on ne sauve que les types que l'on sait
- * convertir en chaine et inversement. Si on souhaite aller plus loin il
- * faudrait plutot regarde du cote d'hibernate et customiser les objets
- * ClassPersistence ou autre responsable de la sauvegarde des entités,
- * sauvegarde qui pourrait avoir lieu dans un fichier texte, ldap, ...
- * <p>
- * Si on souhaite tout de meme ameliorer cette classe, elle utilise BeanUtils de
- * commons-beanutils. Il est possible d'ajouter des convertisseurs par ce moyen.
- * <p>
- * Permet de sauver les entités dans des fichiers au lieu d'une base de données
- * il est possible de configurer la sauvegarde de différent moyen.
- * <dl>
- * <dt>topia.dao.flatfile.properties.file
- * <dd>indique le fichier de configuration a utiliser en plus de la
- * configuration du context
- *
- * <dt>topia.dao.flatfile.directory
- * <dd>indique le répertoire au sauver les entités
- *
- * <dt>topia.dao.flatfile.directory.<fqn-entity>
- * <dd>permet de spécifier un répertoire différent pour une entity spécifique
- *
- * <dt>topia.dao.flatfile.mapping
- * <dd>permet d'indique le mapping a utiliser pour les entités
- *
- * <dt>topia.dao.flatfile.mapping.<fqn-entity>
- * <dd>permet d'indique un mapping différent pour entité
- * </dl>
- *
- * <p>
- * à la place flatfile il est possible de mettre le FQN du DAO utilisé par
- * exemple org.codelutin.topia.persistence.flatfile.TopiaDAOFlatFile
- *
- * <p>
- * Si directory est absent alors "." est utilisé
- *
- * <p>
- * les mappings s'écrivent de la façon suivant:
- * <li>ext=extension a ajouter au fichier contenant l'entity
- * <li>key=attribute
- * <li>body=attribute
- *
- * <p>
- * Si key est absent alors on utilise le topiaId, key est utilisé comme nom de
- * fichier de sauvegarde
- * <p>
- * Si body est absent alors on utilise un fichier de propriété pour sauver
- * l'entity. Si body est présent seul cet attribut sera sauvé.
- *
- * <pre>
- * topia.dao.flatfile.mapping.key=topiaId
- *
- * topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.key=name
- * topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.body=script
- * </pre>
- *
- * <pre>
- * TODO: auto généré un id pour TopiaId si dans le mapping il n'y a pas de key
- * TODO: Pour la version si presence d'un rep CVS on utilise la version
- * du fichier a l'interieur de Entries comme valeur initial
- * TODO: modifier le champs version lors d'un update
- * TODO: permettre dans mapping.body de mettre une liste d'attribute dans ce cas
- * on sauve toujours sous forme de propriétés mais que les champs demandés
- *
- * NOTE: autre idee
- * - si on a un body avec un champs unique sauver les autres propriétés
- * dans une fichier <id>.properties
- * - peut-etre ameliorer le mapping pour pouvoir mapper une entite sur plusieurs
- * fichiers
- *
- * </pre>
- *
- * @author poussin
- *
- */
-public class TopiaDAOFlatFile<Entity extends TopiaEntity> extends
- TopiaDAOAbstract<Entity> {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(TopiaDAOFlatFile.class);
-
- final protected String DAO_CONFIG_1 = "topia.dao.flatfile";
-
- final protected String DAO_CONFIG_2 = "topia.dao." + getClass().getName();
-
- protected Properties config = null;
-
- protected File directory = null;
-
- protected String ext = null;
-
- protected EntityFileFilter filter = null;
-
- protected String key = null;
-
- protected String body = null;
-
- /**
- * Cache sur les entities.
- */
- @SuppressWarnings("unchecked")
- protected Map<File, Entity> cache = (Map<File, Entity>) new ReferenceMap(
- AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
-
- @Override
- public void init(TopiaContextImplementor context, Class<Entity> entityClass)
- throws TopiaException {
- super.init(context, entityClass);
- // on recherche le fichier par la propriete
- // topia.dao.flatfile.properties.file
- // puis topia.dao.fqnclass.properties.file
-
- String configFile = context.getConfig().getProperty(
- DAO_CONFIG_1 + ".properties.file");
- config = TopiaUtil.getProperties(context.getConfig(), configFile);
- log.debug("Use file " + configFile);
- configFile = context.getConfig().getProperty(
- DAO_CONFIG_2 + ".properties.file");
- config = TopiaUtil.getProperties(context.getConfig(), configFile);
- log.debug("Use file " + configFile);
-
- String dirname = getProperty("directory." + entityClass.getName());
- if (dirname == null) {
- dirname = getProperty("directory", ".");
- }
- directory = new File(dirname);
- directory.mkdirs();
-
- ext = getProperty("mapping." + entityClass.getName() + ".ext");
- if (ext == null) {
- ext = getProperty("mapping.ext", "");
- }
- filter = new EntityFileFilter(ext);
-
- key = getProperty("mapping." + entityClass.getName() + ".key");
- if (key == null) {
- key = getProperty("mapping.key", "topiaId");
- }
-
- body = getProperty("mapping." + entityClass.getName() + ".body");
- if (body == null) {
- body = getProperty("mapping.body");
- }
- }
-
- protected String getProperty(String name) {
- return getProperty(name, null);
- }
-
- protected String getProperty(String name, String defaultValue) {
- String result = config.getProperty(DAO_CONFIG_1 + "." + name,
- defaultValue);
- result = config.getProperty(DAO_CONFIG_2 + "." + name, result);
- return result;
- }
-
- /**
- * Par defaut ne fait rien
- */
- @Override
- public void commitTransaction() throws TopiaException {
- }
-
- /**
- * Par defaut ne fait rien
- */
- @Override
- public void rollbackTransaction() throws TopiaException {
- }
-
- /**
- * Sauve l'entity dans le fichier
- *
- * @see org.codelutin.topia.TopiaDAO#update()
- */
- public Entity update(Entity e) throws TopiaException {
- getContext().getFiresSupport().fireOnPreUpdate(getContext(), e, new Object[]{});
-
- // le topiaId contient le nom du fichier a partir duquel l'entity
- // a ete chargé
- try {
- String oldId = (String)e.getTopiaId();
- String newId = (String) PropertyUtils.getProperty(e, key);
-
- // Si l'identifiant a changé alors il faut aussi changer le nom
- // du fichier, on supprime donc l'ancien nom
- if (ObjectUtils.equals(oldId, newId) == false) {
- File f = new File(directory, getFilename(oldId));
- if (f.exists()) {
- f.delete();
- }
- e.setTopiaId(newId);
- }
-
- File f = new File(directory, getFilename(newId));
- if (body != null) {
- String bodyValue = BeanUtils.getProperty(e, body);
- FileWriter out = new FileWriter(f);
- out.append(bodyValue);
- out.close();
- } else {
- Properties prop = new Properties();
- Map<String, String> propMap = (Map<String, String>) BeanUtils
- .describe(e);
-
- // remove transient field property
- // we search field that match exactly get/set name only
- Class clazz = e.getClass();
- for (Iterator<String> i = propMap.keySet().iterator(); i
- .hasNext();) {
- String propName = i.next();
- List<Class> classes = ClassUtils.getAllSuperclasses(clazz);
- classes.add(0, clazz);
- for (Class c : classes) {
- try {
- Field field = c.getDeclaredField(propName);
- if (Modifier.isTransient(field.getModifiers())) {
- i.remove();
- }
- break;
- } catch (Exception eee) {
- if (log.isWarnEnabled()) {
- log.trace("Unable to find field " + propName
- + " on " + c.getName());// , eee);
- }
- }
-
- }
-
- }
-
- prop.putAll(propMap);
- FileOutputStream out = new FileOutputStream(f);
- prop.store(out, "flatfile topia persistence entity");
- out.close();
- }
-
- getContext().getFiresSupport().fireOnPostUpdate(getContext(), e, new Object[]{});
-
- return e;
- } catch (IllegalAccessException eee) {
- throw new TopiaException("Impossible de sauver l'entity: " + e, eee);
- } catch (InvocationTargetException eee) {
- throw new TopiaException("Impossible de sauver l'entity: " + e, eee);
- } catch (NoSuchMethodException eee) {
- throw new TopiaException("Impossible de sauver l'entity: " + e, eee);
- } catch (IOException eee) {
- throw new TopiaException("Impossible de sauver l'entity: " + e, eee);
- }
- }
-
- /**
- * Supprime le fichier contenant l'entity
- *
- * @see org.codelutin.topia.TopiaDAO#delete()
- */
- public void delete(Entity e) throws TopiaException {
- getContext().getFiresSupport().fireOnPreDelete(getContext(), e, new Object[]{});
- // le topiaId contient le nom du fichier a partir duquel l'entity
- // a ete chargé
- String oldId = e.getTopiaId().toString();
- File f = new File(directory, getFilename(oldId));
- cache.remove(f);
- f.delete();
-
- getContext().getFiresSupport().fireOnPostDelete(getContext(), e, new Object[]{});
-
- }
-
- /**
- * Recherche un fichier si dans mapping key est indiqué il est utilisé a la
- * place du topiaId qui n'existe peut-etre pas
- *
- * @see org.codelutin.topia.TopiaDAO#findByTopiaId()
- */
- @Override
- public Entity findByTopiaId(String k) throws TopiaException {
- String keyValue = (String) k;
- File f = new File(directory, getFilename(keyValue));
- Entity result = findByFile(f);
- return result;
- }
-
- protected String getFilename(String id) {
- String result = ext;
- if (ext != null && !"".equals(ext)) {
- result = "." + result;
- }
- result = id + result;
- return result;
- }
-
- protected Entity findByFile(File f) throws TopiaException {
- long lastModified = f.lastModified();
- Entity e = cache.get(f);
- getContext().getFiresSupport().fireOnPreLoad(getContext(), e, new Object[]{});
- // si on a pas encore l'entity ou que le fichier est plus recent
- // il faut relire l'entité
- if (e == null) {
- // en fait il ne faut pas recharger s'il est plus recent
- // sur le disque car on est dans une transaction,
- // si on veut la nouvelle version il faut ouvrire une
- // nouvelle transaction
- // || e.getTopiaCreateDate().getTime() < lastModified) {
- String keyValue = FileUtil.basename(f, "." + ext);
-
- if (e == null) {
- e = instanciateNew();
- }
- Properties prop = new Properties();
- // on met le topiaCreateDate a lastModified maintenant
- // pour qu'il puisse etre ecrassé si on arrive a lire
- // une meilleur information dans le fichier.
- // FIXME: voir comment en Java recuperer la date de creation
- // d'un fichier
- prop.put("topiaCreateDate", new Date(lastModified));
-
- try {
- InputStream in = new BufferedInputStream(new FileInputStream(f));
- if (body == null) {
- prop.load(in);
- } else {
- StringBuffer buffer = new StringBuffer();
- BufferedReader br = new BufferedReader(
- new InputStreamReader(in));
- int c;
- while ((c = br.read()) != -1) {
- buffer.append((char) c);
- }
- prop.put(body, buffer.toString());
- }
-
- // on ecrase topiaId et la key maintenant car le nom
- // du fichier doit toujours etre l'id de l'objet
- prop.put(key, keyValue);
- prop.put("topiaId", keyValue);
-
- BeanUtils.populate(e, prop);
- } catch (IOException eee) {
- throw new TopiaException(
- "Impossible de lire l'entity du fichier: " + f, eee);
- } catch (IllegalAccessException eee) {
- throw new TopiaException(
- "Impossible de mettre le contenu du fichier dans l'entity: "
- + f, eee);
- } catch (InvocationTargetException eee) {
- throw new TopiaException(
- "Impossible de mettre le contenu du fichier dans l'entity: "
- + f, eee);
- }
-
- // on le met en cache car on doit toujours retourner
- // la meme instance au cours du temps
- cache.put(f, e);
- getContext().getFiresSupport().fireOnPostLoad(getContext(), e, new Object[]{});
- }
- return e;
- }
-
- /**
- * Charge tous les objets présent. Si un objet est invalide, il n'est pas
- * lu, un message WARN est affiché mais aucune exception n'est levé.
- *
- * @see org.codelutin.topia.persistence.TopiaDAOAbstract#findAll()
- */
- @Override
- public List<Entity> findAll() throws TopiaException {
- List<Entity> result = new ArrayList<Entity>();
-
- File[] entitiesFile = directory.listFiles(filter);
- for (File f : entitiesFile) {
- try {
- Entity e = findByFile(f);
- result.add(e);
- } catch (TopiaException eee) {
- if (log.isWarnEnabled()) {
- log.warn(eee);
- }
- }
- }
- return result;
- }
-
- /**
- * Permet de filtrer les fichiers si une extension a ete defini dans le
- * mapping
- *
- * @author poussin
- *
- */
- protected class EntityFileFilter implements FileFilter {
-
- protected String ext = null;
-
- public EntityFileFilter(String ext) {
- this.ext = ext;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.FileFilter#accept(java.io.File)
- */
- public boolean accept(File pathname) {
- boolean result;
- if (ext == null || "".equals(ext)) {
- return true;
- } else {
- String e = FileUtil.extension(pathname, ".");
- result = e.equals(ext);
- }
- return result;
- }
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#query(org.hibernate.criterion.Criterion)
- */
- public Entity query(Criterion criterion) throws TopiaException {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#queryAll(org.hibernate.criterion.Criterion)
- */
- public List<Entity> queryAll(Criterion criterion) throws TopiaException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object query(Projection projection, Criterion criterion) throws TopiaException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public List queryAll(Projection projection, Criterion criterion) throws TopiaException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object project(Projection projection) throws TopiaException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public List projectAll(Projection projection) throws TopiaException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Criteria createCriteria(FlushMode mode) throws TopiaException {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
- */
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
- return null;
- }
-}
Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java)
===================================================================
--- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java (rev 0)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,547 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/*******************************************************************************
+ * TopiaDAOFlatFile.java
+ *
+ * Created: 30 déc. 2005 03:11:55
+ *
+ * @author poussin
+ *
+ * @version $Revision$
+ *
+ * Last update: $Date$ by : $Author$
+ */
+
+package org.codelutin.topia.persistence.flatfile;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
+import java.security.Permission;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.collections.map.AbstractReferenceMap;
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.framework.TopiaContextImplementor;
+import org.codelutin.topia.framework.TopiaUtil;
+import org.codelutin.topia.persistence.TopiaDAOAbstract;
+import org.codelutin.topia.persistence.TopiaEntity;
+import org.codelutin.util.FileUtil;
+import org.hibernate.Criteria;
+import org.hibernate.FlushMode;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Projection;
+
+/**
+ * <p>
+ * <b>ATTENTION:</b> Le rollback des transactions n'est pas du tout pris en
+ * compte. Et l'implantation n'est pas fait pour les supporter un jour. Il
+ * faudrait pour cela que le context préviennent les DAO, lors d'un
+ * commit/rollback.
+ * <p>
+ * <b>REMARQUE:</b> pour l'instant on ne sauve que les types que l'on sait
+ * convertir en chaine et inversement. Si on souhaite aller plus loin il
+ * faudrait plutot regarde du cote d'hibernate et customiser les objets
+ * ClassPersistence ou autre responsable de la sauvegarde des entités,
+ * sauvegarde qui pourrait avoir lieu dans un fichier texte, ldap, ...
+ * <p>
+ * Si on souhaite tout de meme ameliorer cette classe, elle utilise BeanUtils de
+ * commons-beanutils. Il est possible d'ajouter des convertisseurs par ce moyen.
+ * <p>
+ * Permet de sauver les entités dans des fichiers au lieu d'une base de données
+ * il est possible de configurer la sauvegarde de différent moyen.
+ * <dl>
+ * <dt>topia.dao.flatfile.properties.file
+ * <dd>indique le fichier de configuration a utiliser en plus de la
+ * configuration du context
+ *
+ * <dt>topia.dao.flatfile.directory
+ * <dd>indique le répertoire au sauver les entités
+ *
+ * <dt>topia.dao.flatfile.directory.<fqn-entity>
+ * <dd>permet de spécifier un répertoire différent pour une entity spécifique
+ *
+ * <dt>topia.dao.flatfile.mapping
+ * <dd>permet d'indique le mapping a utiliser pour les entités
+ *
+ * <dt>topia.dao.flatfile.mapping.<fqn-entity>
+ * <dd>permet d'indique un mapping différent pour entité
+ * </dl>
+ *
+ * <p>
+ * à la place flatfile il est possible de mettre le FQN du DAO utilisé par
+ * exemple org.codelutin.topia.persistence.flatfile.TopiaDAOFlatFile
+ *
+ * <p>
+ * Si directory est absent alors "." est utilisé
+ *
+ * <p>
+ * les mappings s'écrivent de la façon suivant:
+ * <li>ext=extension a ajouter au fichier contenant l'entity
+ * <li>key=attribute
+ * <li>body=attribute
+ *
+ * <p>
+ * Si key est absent alors on utilise le topiaId, key est utilisé comme nom de
+ * fichier de sauvegarde
+ * <p>
+ * Si body est absent alors on utilise un fichier de propriété pour sauver
+ * l'entity. Si body est présent seul cet attribut sera sauvé.
+ *
+ * <pre>
+ * topia.dao.flatfile.mapping.key=topiaId
+ *
+ * topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.key=name
+ * topia.dao.flatfile.mapping.fr.ifremer.isisfish.entities.Script.body=script
+ * </pre>
+ *
+ * <pre>
+ * TODO: auto généré un id pour TopiaId si dans le mapping il n'y a pas de key
+ * TODO: Pour la version si presence d'un rep CVS on utilise la version
+ * du fichier a l'interieur de Entries comme valeur initial
+ * TODO: modifier le champs version lors d'un update
+ * TODO: permettre dans mapping.body de mettre une liste d'attribute dans ce cas
+ * on sauve toujours sous forme de propriétés mais que les champs demandés
+ *
+ * NOTE: autre idee
+ * - si on a un body avec un champs unique sauver les autres propriétés
+ * dans une fichier <id>.properties
+ * - peut-etre ameliorer le mapping pour pouvoir mapper une entite sur plusieurs
+ * fichiers
+ *
+ * </pre>
+ *
+ * @author poussin
+ *
+ */
+public class TopiaDAOFlatFile<Entity extends TopiaEntity> extends
+ TopiaDAOAbstract<Entity> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(TopiaDAOFlatFile.class);
+
+ final protected String DAO_CONFIG_1 = "topia.dao.flatfile";
+
+ final protected String DAO_CONFIG_2 = "topia.dao." + getClass().getName();
+
+ protected Properties config = null;
+
+ protected File directory = null;
+
+ protected String ext = null;
+
+ protected EntityFileFilter filter = null;
+
+ protected String key = null;
+
+ protected String body = null;
+
+ /**
+ * Cache sur les entities.
+ */
+ @SuppressWarnings("unchecked")
+ protected Map<File, Entity> cache = (Map<File, Entity>) new ReferenceMap(
+ AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
+
+ @Override
+ public void init(TopiaContextImplementor context, Class<Entity> entityClass)
+ throws TopiaException {
+ super.init(context, entityClass);
+ // on recherche le fichier par la propriete
+ // topia.dao.flatfile.properties.file
+ // puis topia.dao.fqnclass.properties.file
+
+ String configFile = context.getConfig().getProperty(
+ DAO_CONFIG_1 + ".properties.file");
+ config = TopiaUtil.getProperties(context.getConfig(), configFile);
+ log.debug("Use file " + configFile);
+ configFile = context.getConfig().getProperty(
+ DAO_CONFIG_2 + ".properties.file");
+ config = TopiaUtil.getProperties(context.getConfig(), configFile);
+ log.debug("Use file " + configFile);
+
+ String dirname = getProperty("directory." + entityClass.getName());
+ if (dirname == null) {
+ dirname = getProperty("directory", ".");
+ }
+ directory = new File(dirname);
+ directory.mkdirs();
+
+ ext = getProperty("mapping." + entityClass.getName() + ".ext");
+ if (ext == null) {
+ ext = getProperty("mapping.ext", "");
+ }
+ filter = new EntityFileFilter(ext);
+
+ key = getProperty("mapping." + entityClass.getName() + ".key");
+ if (key == null) {
+ key = getProperty("mapping.key", "topiaId");
+ }
+
+ body = getProperty("mapping." + entityClass.getName() + ".body");
+ if (body == null) {
+ body = getProperty("mapping.body");
+ }
+ }
+
+ protected String getProperty(String name) {
+ return getProperty(name, null);
+ }
+
+ protected String getProperty(String name, String defaultValue) {
+ String result = config.getProperty(DAO_CONFIG_1 + "." + name,
+ defaultValue);
+ result = config.getProperty(DAO_CONFIG_2 + "." + name, result);
+ return result;
+ }
+
+ /**
+ * Par defaut ne fait rien
+ */
+ @Override
+ public void commitTransaction() throws TopiaException {
+ }
+
+ /**
+ * Par defaut ne fait rien
+ */
+ @Override
+ public void rollbackTransaction() throws TopiaException {
+ }
+
+ /**
+ * Sauve l'entity dans le fichier
+ *
+ * @see org.codelutin.topia.persistence.TopiaDAO#update(org.codelutin.topia.persistence.TopiaEntity)
+ */
+ public Entity update(Entity e) throws TopiaException {
+ getContext().getFiresSupport().fireOnPreUpdate(getContext(), e, new Object[]{});
+
+ // le topiaId contient le nom du fichier a partir duquel l'entity
+ // a ete chargé
+ try {
+ String oldId = (String)e.getTopiaId();
+ String newId = (String) PropertyUtils.getProperty(e, key);
+
+ // Si l'identifiant a changé alors il faut aussi changer le nom
+ // du fichier, on supprime donc l'ancien nom
+ if (ObjectUtils.equals(oldId, newId) == false) {
+ File f = new File(directory, getFilename(oldId));
+ if (f.exists()) {
+ f.delete();
+ }
+ e.setTopiaId(newId);
+ }
+
+ File f = new File(directory, getFilename(newId));
+ if (body != null) {
+ String bodyValue = BeanUtils.getProperty(e, body);
+ FileWriter out = new FileWriter(f);
+ out.append(bodyValue);
+ out.close();
+ } else {
+ Properties prop = new Properties();
+ Map<String, String> propMap = (Map<String, String>) BeanUtils
+ .describe(e);
+
+ // remove transient field property
+ // we search field that match exactly get/set name only
+ Class clazz = e.getClass();
+ for (Iterator<String> i = propMap.keySet().iterator(); i
+ .hasNext();) {
+ String propName = i.next();
+ List<Class> classes = ClassUtils.getAllSuperclasses(clazz);
+ classes.add(0, clazz);
+ for (Class c : classes) {
+ try {
+ Field field = c.getDeclaredField(propName);
+ if (Modifier.isTransient(field.getModifiers())) {
+ i.remove();
+ }
+ break;
+ } catch (Exception eee) {
+ if (log.isWarnEnabled()) {
+ log.trace("Unable to find field " + propName
+ + " on " + c.getName());// , eee);
+ }
+ }
+
+ }
+
+ }
+
+ prop.putAll(propMap);
+ FileOutputStream out = new FileOutputStream(f);
+ prop.store(out, "flatfile topia persistence entity");
+ out.close();
+ }
+
+ getContext().getFiresSupport().fireOnPostUpdate(getContext(), e, new Object[]{});
+
+ return e;
+ } catch (IllegalAccessException eee) {
+ throw new TopiaException("Impossible de sauver l'entity: " + e, eee);
+ } catch (InvocationTargetException eee) {
+ throw new TopiaException("Impossible de sauver l'entity: " + e, eee);
+ } catch (NoSuchMethodException eee) {
+ throw new TopiaException("Impossible de sauver l'entity: " + e, eee);
+ } catch (IOException eee) {
+ throw new TopiaException("Impossible de sauver l'entity: " + e, eee);
+ }
+ }
+
+ /**
+ * Supprime le fichier contenant l'entity
+ *
+ * @see org.codelutin.topia.persistence.TopiaDAO#delete(org.codelutin.topia.persistence.TopiaEntity)
+ */
+ public void delete(Entity e) throws TopiaException {
+ getContext().getFiresSupport().fireOnPreDelete(getContext(), e, new Object[]{});
+ // le topiaId contient le nom du fichier a partir duquel l'entity
+ // a ete chargé
+ String oldId = e.getTopiaId().toString();
+ File f = new File(directory, getFilename(oldId));
+ cache.remove(f);
+ f.delete();
+
+ getContext().getFiresSupport().fireOnPostDelete(getContext(), e, new Object[]{});
+
+ }
+
+ /**
+ * Recherche un fichier si dans mapping key est indiqué il est utilisé a la
+ * place du topiaId qui n'existe peut-etre pas
+ *
+ * @see org.codelutin.topia.persistence.TopiaDAO#findByTopiaId(String)
+ */
+ @Override
+ public Entity findByTopiaId(String k) throws TopiaException {
+ String keyValue = (String) k;
+ File f = new File(directory, getFilename(keyValue));
+ Entity result = findByFile(f);
+ return result;
+ }
+
+ protected String getFilename(String id) {
+ String result = ext;
+ if (ext != null && !"".equals(ext)) {
+ result = "." + result;
+ }
+ result = id + result;
+ return result;
+ }
+
+ protected Entity findByFile(File f) throws TopiaException {
+ long lastModified = f.lastModified();
+ Entity e = cache.get(f);
+ getContext().getFiresSupport().fireOnPreLoad(getContext(), e, new Object[]{});
+ // si on a pas encore l'entity ou que le fichier est plus recent
+ // il faut relire l'entité
+ if (e == null) {
+ // en fait il ne faut pas recharger s'il est plus recent
+ // sur le disque car on est dans une transaction,
+ // si on veut la nouvelle version il faut ouvrire une
+ // nouvelle transaction
+ // || e.getTopiaCreateDate().getTime() < lastModified) {
+ String keyValue = FileUtil.basename(f, "." + ext);
+
+ if (e == null) {
+ e = instanciateNew();
+ }
+ Properties prop = new Properties();
+ // on met le topiaCreateDate a lastModified maintenant
+ // pour qu'il puisse etre ecrassé si on arrive a lire
+ // une meilleur information dans le fichier.
+ // FIXME: voir comment en Java recuperer la date de creation
+ // d'un fichier
+ prop.put("topiaCreateDate", new Date(lastModified));
+
+ try {
+ InputStream in = new BufferedInputStream(new FileInputStream(f));
+ if (body == null) {
+ prop.load(in);
+ } else {
+ StringBuffer buffer = new StringBuffer();
+ BufferedReader br = new BufferedReader(
+ new InputStreamReader(in));
+ int c;
+ while ((c = br.read()) != -1) {
+ buffer.append((char) c);
+ }
+ prop.put(body, buffer.toString());
+ }
+
+ // on ecrase topiaId et la key maintenant car le nom
+ // du fichier doit toujours etre l'id de l'objet
+ prop.put(key, keyValue);
+ prop.put("topiaId", keyValue);
+
+ BeanUtils.populate(e, prop);
+ } catch (IOException eee) {
+ throw new TopiaException(
+ "Impossible de lire l'entity du fichier: " + f, eee);
+ } catch (IllegalAccessException eee) {
+ throw new TopiaException(
+ "Impossible de mettre le contenu du fichier dans l'entity: "
+ + f, eee);
+ } catch (InvocationTargetException eee) {
+ throw new TopiaException(
+ "Impossible de mettre le contenu du fichier dans l'entity: "
+ + f, eee);
+ }
+
+ // on le met en cache car on doit toujours retourner
+ // la meme instance au cours du temps
+ cache.put(f, e);
+ getContext().getFiresSupport().fireOnPostLoad(getContext(), e, new Object[]{});
+ }
+ return e;
+ }
+
+ /**
+ * Charge tous les objets présent. Si un objet est invalide, il n'est pas
+ * lu, un message WARN est affiché mais aucune exception n'est levé.
+ *
+ * @see org.codelutin.topia.persistence.TopiaDAOAbstract#findAll()
+ */
+ @Override
+ public List<Entity> findAll() throws TopiaException {
+ List<Entity> result = new ArrayList<Entity>();
+
+ File[] entitiesFile = directory.listFiles(filter);
+ for (File f : entitiesFile) {
+ try {
+ Entity e = findByFile(f);
+ result.add(e);
+ } catch (TopiaException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(eee);
+ }
+ }
+ }
+ return result;
+ }
+
+ public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
+ throw new IllegalStateException("findAllWithOrder method is not implemented by "+getClass());
+ }
+
+ /**
+ * Permet de filtrer les fichiers si une extension a ete defini dans le
+ * mapping
+ *
+ * @author poussin
+ *
+ */
+ protected class EntityFileFilter implements FileFilter {
+
+ protected String ext = null;
+
+ public EntityFileFilter(String ext) {
+ this.ext = ext;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.FileFilter#accept(java.io.File)
+ */
+ public boolean accept(File pathname) {
+ boolean result;
+ if (ext == null || "".equals(ext)) {
+ return true;
+ } else {
+ String e = FileUtil.extension(pathname, ".");
+ result = e.equals(ext);
+ }
+ return result;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#query(org.hibernate.criterion.Criterion)
+ */
+ public Entity query(Criterion criterion) throws TopiaException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#queryAll(org.hibernate.criterion.Criterion)
+ */
+ public List<Entity> queryAll(Criterion criterion) throws TopiaException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object query(Projection projection, Criterion criterion) throws TopiaException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List queryAll(Projection projection, Criterion criterion) throws TopiaException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object project(Projection projection) throws TopiaException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List projectAll(Projection projection) throws TopiaException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Criteria createCriteria(FlushMode mode) throws TopiaException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
+ */
+ public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
+ return null;
+ }
+}
Deleted: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -1,264 +0,0 @@
-/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/*******************************************************************************
- * TopiaDAOHibernate.java
- *
- * Created: 23 déc. 2005 18:34:01
- *
- * @author poussin
- *
- * @version $Revision$
- *
- * Last update: $Date$ by : $Author$
- */
-
-package org.codelutin.topia.persistence.hibernate;
-
-import java.security.Permission;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.topia.TopiaException;
-import org.codelutin.topia.persistence.TopiaDAOAbstract;
-import org.codelutin.topia.persistence.TopiaEntity;
-import org.hibernate.Criteria;
-import org.hibernate.FlushMode;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-
-/**
- * Cette persistence accède à l'objet Session hibernate pour exécuter
- * les différentes demandes de persistences.
- *
- * @author poussin
- *
- */
-// FIXME les Entity ne doivent pas forcement etendre TopiaEntity de cette
-// facon on peut utiliser le framework sans la generation et sur des POJO
-// existant. Cela implique de faire un peu attention au codage
-public class TopiaDAOHibernate<Entity extends TopiaEntity> extends TopiaDAOAbstract<Entity> {
-
- private static Log log = LogFactory.getLog(TopiaDAOHibernate.class);
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#create()
- */
- @Override
- public Entity create(Map<String, Object> properties) throws TopiaException {
- Entity result = super.create(properties);
- // on fait un save maintenant, car puisqu'on a creer l'entity au
- // travers du DAO, on s'attend a l'avoir a disposition tout de
- // suite pour les requetes sans avoir a faire un update dessus
- getSession().save(result);
- getContext().getFiresSupport().warnOnCreateEntity(result);
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#update(Entity)
- */
- public Entity update(Entity e) throws TopiaException {
- try {
- getSession().saveOrUpdate(e);
- getContext().getFiresSupport().warnOnUpdateEntity(e);
- return e;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#delete(Entity)
- */
- public void delete(Entity e) throws TopiaException {
- try {
- getSession().delete(e);
- getContext().getFiresSupport().warnOnDeleteEntity(e);
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByTopiaId()
- */
- @Override
- public Entity findByTopiaId(String k) throws TopiaException {
- return query(Restrictions.idEq(k));
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAll()
- */
- @Override
- public List<Entity> findAll() throws TopiaException {
- try {
- Criteria criteria = createCriteria(FlushMode.AUTO);
- List<Entity> result = (List<Entity>)criteria.list();
- result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
- return result;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
- /**
- * TODO implanter une facon plus rapide de recupere la size (count direct
- * sur la base)
- * (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#size()
- */
- @Override
- public int size() throws TopiaException {
- int result = findAll().size();
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
- */
- @Override
- public Entity findByProperties(Map<String, Object> properties)
- throws TopiaException {
- return query(Restrictions.allEq(properties));
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map)
- */
- public List<Entity> findAllByProperties(Map<String, Object> properties)
- throws TopiaException {
- return queryAll(Restrictions.allEq(properties));
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#queryAll(org.hibernate.criterion.Criterion)
- */
- private List<Entity> queryAll(Criterion criterion) throws TopiaException {
- try {
- Criteria criteria = createCriteria(FlushMode.AUTO);
- criteria.add(criterion);
- List<Entity> result = (List<Entity>)criteria.list();
- result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
- return result;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
- /* (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#query(org.hibernate.criterion.Criterion)
- */
- private Entity query(Criterion criterion) throws TopiaException {
- try {
- Criteria criteria = createCriteria(FlushMode.AUTO);
- criteria.add(criterion);
- criteria.setMaxResults(1);
- List<Entity> result = (List<Entity>)criteria.list();
- int sizeBefore = (result != null?result.size():0);
- result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
- int sizeAfter = (result != null?result.size():0);
- if (sizeAfter < sizeBefore) {
- if (log.isDebugEnabled()) {
- log.debug((sizeBefore - sizeAfter) + " element(s) removed. Filter entity: " + entityClass.getName() + " - criterion: " + criterion);
- }
- }
- if (result != null && result.size() > 0) {
- Entity elem = result.get(0);
- return elem;
- }
- return null;
- } catch (HibernateException eee) {
- throw new TopiaException(eee);
- }
- }
-
-//FIXME : Commenté car impossible de trouver le bon Criterion
-
-// /* (non-Javadoc)
-// * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
-// */
-// public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException {
-// try {
-// Criteria criteria = createCriteria(FlushMode.AUTO);
-// for (Entry<String, Collection> entry : properties.entrySet()) {
-// for (Object value : entry.getValue()) {
-// criteria.add(Restrictions.eq(entry.getKey(), value));
-// }
-// }
-// criteria.setMaxResults(1);
-// List<Entity> results = (List<Entity>)criteria.list();
-// if (results.size() > 0) {
-// return (Entity)results.get(0);
-// } else {
-// return null;
-// }
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
-// }
-//
-// /* (non-Javadoc)
-// * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
-// */
-// public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
-// try {
-// Criteria criteria = createCriteria(FlushMode.AUTO);
-// for (Entry<String, Collection> entry : properties.entrySet()) {
-// for (Object value : entry.getValue()) {
-// criteria.add(Restrictions.eq(entry.getKey(), value));
-// }
-// }
-// List<Entity> result = (List<Entity>)criteria.list();
-// return result;
-// } catch (HibernateException eee) {
-// throw new TopiaException(eee);
-// }
-// }
-
- /**
- * Renvoie un Criteria créé avec l'entityClass
- * @param mode le FlushMode du Criteria
- * @return le Criteria nouvellement créé
- */
- private Criteria createCriteria(FlushMode mode) throws TopiaException {
- Criteria criteria = getSession().createCriteria(entityClass);
- criteria.setFlushMode(mode);
- return criteria;
- }
-
- /**
- * Renvoie la Session contenue dans le contexte
- */
- private Session getSession() throws TopiaException {
- return getContext().getHibernate();
- }
-
- /*
- * (non-Javadoc)
- * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
- */
- public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
- return null;
- }
-
-} //TopiaDAOHibernate
Copied: topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java (from rev 1224, topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java)
===================================================================
--- topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java (rev 0)
+++ topia/tags/2.0.29/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-17 09:39:40 UTC (rev 1227)
@@ -0,0 +1,279 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/*******************************************************************************
+ * TopiaDAOHibernate.java
+ *
+ * Created: 23 déc. 2005 18:34:01
+ *
+ * @author poussin
+ *
+ * @version $Revision$
+ *
+ * Last update: $Date$ by : $Author$
+ */
+
+package org.codelutin.topia.persistence.hibernate;
+
+import java.security.Permission;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.topia.TopiaException;
+import org.codelutin.topia.persistence.TopiaDAOAbstract;
+import org.codelutin.topia.persistence.TopiaEntity;
+import org.hibernate.Criteria;
+import org.hibernate.FlushMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.criterion.Order;
+
+/**
+ * Cette persistence accède à l'objet Session hibernate pour exécuter
+ * les différentes demandes de persistences.
+ *
+ * @author poussin
+ *
+ */
+// FIXME les Entity ne doivent pas forcement etendre TopiaEntity de cette
+// facon on peut utiliser le framework sans la generation et sur des POJO
+// existant. Cela implique de faire un peu attention au codage
+public class TopiaDAOHibernate<Entity extends TopiaEntity> extends TopiaDAOAbstract<Entity> {
+
+ private static Log log = LogFactory.getLog(TopiaDAOHibernate.class);
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#create()
+ */
+ @Override
+ public Entity create(Map<String, Object> properties) throws TopiaException {
+ Entity result = super.create(properties);
+ // on fait un save maintenant, car puisqu'on a creer l'entity au
+ // travers du DAO, on s'attend a l'avoir a disposition tout de
+ // suite pour les requetes sans avoir a faire un update dessus
+ getSession().save(result);
+ getContext().getFiresSupport().warnOnCreateEntity(result);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#update(Entity)
+ */
+ public Entity update(Entity e) throws TopiaException {
+ try {
+ getSession().saveOrUpdate(e);
+ getContext().getFiresSupport().warnOnUpdateEntity(e);
+ return e;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#delete(Entity)
+ */
+ public void delete(Entity e) throws TopiaException {
+ try {
+ getSession().delete(e);
+ getContext().getFiresSupport().warnOnDeleteEntity(e);
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByTopiaId()
+ */
+ @Override
+ public Entity findByTopiaId(String k) throws TopiaException {
+ return query(Restrictions.idEq(k));
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAll()
+ */
+ @Override
+ public List<Entity> findAll() throws TopiaException {
+ try {
+ Criteria criteria = createCriteria(FlushMode.AUTO);
+ List<Entity> result = (List<Entity>)criteria.list();
+ result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ return result;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
+ try {
+ Criteria criteria = createCriteria(FlushMode.AUTO);
+ for (String propertyName : propertyNames) {
+ criteria.addOrder(Order.asc(propertyName));
+ }
+ List<Entity> result = (List<Entity>)criteria.list();
+ result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ return result;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ /**
+ * TODO implanter une facon plus rapide de recupere la size (count direct
+ * sur la base)
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#size()
+ */
+ @Override
+ public int size() throws TopiaException {
+ int result = findAll().size();
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findByProperties(java.util.Map)
+ */
+ @Override
+ public Entity findByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ return query(Restrictions.allEq(properties));
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map)
+ */
+ public List<Entity> findAllByProperties(Map<String, Object> properties)
+ throws TopiaException {
+ return queryAll(Restrictions.allEq(properties));
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#queryAll(org.hibernate.criterion.Criterion)
+ */
+ private List<Entity> queryAll(Criterion criterion) throws TopiaException {
+ try {
+ Criteria criteria = createCriteria(FlushMode.AUTO);
+ criteria.add(criterion);
+ List<Entity> result = (List<Entity>)criteria.list();
+ result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ return result;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#query(org.hibernate.criterion.Criterion)
+ */
+ private Entity query(Criterion criterion) throws TopiaException {
+ try {
+ Criteria criteria = createCriteria(FlushMode.AUTO);
+ criteria.add(criterion);
+ criteria.setMaxResults(1);
+ List<Entity> result = (List<Entity>)criteria.list();
+ int sizeBefore = (result != null?result.size():0);
+ result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ int sizeAfter = (result != null?result.size():0);
+ if (sizeAfter < sizeBefore) {
+ if (log.isDebugEnabled()) {
+ log.debug((sizeBefore - sizeAfter) + " element(s) removed. Filter entity: " + entityClass.getName() + " - criterion: " + criterion);
+ }
+ }
+ if (result != null && result.size() > 0) {
+ Entity elem = result.get(0);
+ return elem;
+ }
+ return null;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
+//FIXME : Commenté car impossible de trouver le bon Criterion
+
+// /* (non-Javadoc)
+// * @see org.codelutin.topia.persistence.TopiaDAO#findContainsProperties(java.util.Map)
+// */
+// public Entity findContainsProperties(Map<String, Collection> properties) throws TopiaException {
+// try {
+// Criteria criteria = createCriteria(FlushMode.AUTO);
+// for (Entry<String, Collection> entry : properties.entrySet()) {
+// for (Object value : entry.getValue()) {
+// criteria.add(Restrictions.eq(entry.getKey(), value));
+// }
+// }
+// criteria.setMaxResults(1);
+// List<Entity> results = (List<Entity>)criteria.list();
+// if (results.size() > 0) {
+// return (Entity)results.get(0);
+// } else {
+// return null;
+// }
+// } catch (HibernateException eee) {
+// throw new TopiaException(eee);
+// }
+// }
+//
+// /* (non-Javadoc)
+// * @see org.codelutin.topia.persistence.TopiaDAO#findAllContainsProperties(java.util.Map)
+// */
+// public List<Entity> findAllContainsProperties(Map<String, Collection> properties) throws TopiaException {
+// try {
+// Criteria criteria = createCriteria(FlushMode.AUTO);
+// for (Entry<String, Collection> entry : properties.entrySet()) {
+// for (Object value : entry.getValue()) {
+// criteria.add(Restrictions.eq(entry.getKey(), value));
+// }
+// }
+// List<Entity> result = (List<Entity>)criteria.list();
+// return result;
+// } catch (HibernateException eee) {
+// throw new TopiaException(eee);
+// }
+// }
+
+ /**
+ * Renvoie un Criteria créé avec l'entityClass
+ * @param mode le FlushMode du Criteria
+ * @return le Criteria nouvellement créé
+ */
+ private Criteria createCriteria(FlushMode mode) throws TopiaException {
+ Criteria criteria = getSession().createCriteria(entityClass);
+ criteria.setFlushMode(mode);
+ return criteria;
+ }
+
+ /**
+ * Renvoie la Session contenue dans le contexte
+ */
+ private Session getSession() throws TopiaException {
+ return getContext().getHibernate();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.codelutin.topia.persistence.TopiaDAO#getRequestPermission(java.lang.String, int)
+ */
+ public List<Permission> getRequestPermission(String topiaId, int actions) throws TopiaException {
+ return null;
+ }
+
+} //TopiaDAOHibernate
1
0
Author: tchemit
Date: 2008-11-17 09:39:36 +0000 (Mon, 17 Nov 2008)
New Revision: 1226
Modified:
topia/trunk/pom.xml
Log:
[maven-release-plugin] prepare release 2.0.29
Modified: topia/trunk/pom.xml
===================================================================
--- topia/trunk/pom.xml 2008-11-17 08:54:14 UTC (rev 1225)
+++ topia/trunk/pom.xml 2008-11-17 09:39:36 UTC (rev 1226)
@@ -136,7 +136,7 @@
<!-- ************************************************************* -->
<name>ToPIA - Tools for Portable and Independent Architecture</name>
- <version>2.0.29-SNAPSHOT</version>
+ <version>2.0.29</version>
<description>Framework de persistance et de distribution d'application.</description>
<inceptionYear>2004</inceptionYear>
@@ -199,9 +199,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>${maven.scm.connection}</connection>
- <developerConnection>${maven.scm.developerConnection}</developerConnection>
- <url>${maven.scm.url}</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.0.29</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/topia/topia/tags/2.0.29</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/tags/2.0.…</url>
</scm>
</project>
1
0
Author: chemit
Date: 2008-11-17 08:54:14 +0000 (Mon, 17 Nov 2008)
New Revision: 1225
Modified:
topia/trunk/changelog
Log:
prepare release 0.29 (changelog)
Modified: topia/trunk/changelog
===================================================================
--- topia/trunk/changelog 2008-11-16 18:29:50 UTC (rev 1224)
+++ topia/trunk/changelog 2008-11-17 08:54:14 UTC (rev 1225)
@@ -1,6 +1,7 @@
-ver-2-0-28 ?? 2008??
- * 20081116 [chemit] improve EntityEnum
- * 20081116 [chemit] add findAllWithOrder method on Dao to order by properties
+ver-2-0-29 chatellier 20081117
+ * 20081117 [chemit] improve EntityEnum
+ * 20081117 [chemit] add method findAllWithOrder in DAO to make have sorted lists
+ver-2-0-28 chatellier 20081114
* 20081113 [chorlet] add support for lazy loading on attribute with 0..* multiplicity
* 20081113 [chorlet] fix bug on bidirectional association by adding inverse attribute in the one side of two hibernate mapping files
* 20081107 [chatellier] fix "result" named attribute generation in model
1
0
r1224 - in topia/trunk: . src/main/java/org/codelutin/topia/generator src/main/java/org/codelutin/topia/persistence src/main/java/org/codelutin/topia/persistence/flatfile src/main/java/org/codelutin/topia/persistence/hibernate
by tchemit@users.labs.libre-entreprise.org 16 Nov '08
by tchemit@users.labs.libre-entreprise.org 16 Nov '08
16 Nov '08
Author: tchemit
Date: 2008-11-16 18:29:50 +0000 (Sun, 16 Nov 2008)
New Revision: 1224
Modified:
topia/trunk/changelog
topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java
topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java
topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java
topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java
topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java
topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java
Log:
improve EntityEnum + add findAllWithOrder on DAO
Modified: topia/trunk/changelog
===================================================================
--- topia/trunk/changelog 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/trunk/changelog 2008-11-16 18:29:50 UTC (rev 1224)
@@ -1,4 +1,6 @@
ver-2-0-28 ?? 2008??
+ * 20081116 [chemit] improve EntityEnum
+ * 20081116 [chemit] add findAllWithOrder method on Dao to order by properties
* 20081113 [chorlet] add support for lazy loading on attribute with 0..* multiplicity
* 20081113 [chorlet] fix bug on bidirectional association by adding inverse attribute in the one side of two hibernate mapping files
* 20081107 [chatellier] fix "result" named attribute generation in model
Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-16 18:29:50 UTC (rev 1224)
@@ -77,6 +77,10 @@
}
/*{package <%=getProperty("defaultPackage")%>;
+import java.util.Map;
+import java.util.List;
+import java.util.Collection;
+
import org.codelutin.topia.TopiaContext;
import org.codelutin.topia.TopiaException;
import org.codelutin.topia.persistence.TopiaDAO;
@@ -111,36 +115,11 @@
<%=className%>(Class<? extends TopiaEntity> contractClass) {
entry = new TopiaEntityEnumEntry(contractClass);
}
-}*/
-/* public Class<? extends TopiaEntity> getContractClass() {
- return entry.getContractClass();
- }
+ public <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry() {
+ return (TopiaEntityEnumEntry<T>)entry;
+ }
- public Class<? extends TopiaEntity> getImplementationClass() {
- return entry.getImplementationClass();
- }
-
- public TopiaDAO getDAO(TopiaContext ctxt) throws TopiaException {
- return entry.getDAO(ctxt);
- }
-
- public TopiaEntity create(TopiaContext ctxt) throws TopiaException {
- return entry.create(ctxt);
- }
-
- public TopiaEntity update(TopiaEntity entity, TopiaContext
- ctxt) throws TopiaException
- {
- return entry.update(entity, ctxt);
- }
-
- public void delete(TopiaEntity entity, TopiaContext ctxt) throws TopiaException {
- entry.delete(entity, ctxt);
- }
-*/
-
-/*{
public static <%=className%> valueOf(TopiaEntity entity) {
return valueOf(entity.getClass());
}
@@ -159,14 +138,12 @@
public static <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass) throws TopiaException {
TopiaEntityEnumEntry<T> entry = getEntry(klass);
- <%=className%> e = <%=className%>.valueOf(klass);
- return (Class<T>) e.entry.getContractClass();
+ return entry.getContractClass();
}
public static <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass) throws TopiaException {
TopiaEntityEnumEntry<T> entry = getEntry(klass);
- <%=className%> e = <%=className%>.valueOf(klass);
- return (Class<T>) e.entry.getImplementationClass();
+ return entry.getImplementationClass();
}
public static Class<? extends TopiaEntity>[] getContractClasses() {
@@ -195,55 +172,136 @@
return buffer.substring(1);
}
- public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(Class<T> klass, TopiaContext ctxt) throws TopiaException {
- TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(T entity) {
+ <%=className%> e = <%=className%>.valueOf(entity);
+ return (TopiaEntityEnumEntry<T>)e.entry;
+ }
+
+ public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(Class<T> klass) {
<%=className%> e = <%=className%>.valueOf(klass);
- return (D) e.entry.getDAO(ctxt);
+ return (TopiaEntityEnumEntry<T>)e.entry;
}
- public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(T entity, TopiaContext ctxt) throws TopiaException {
+ public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(String constantName) {
+ <%=className%> e = <%=className%>.valueOf(constantName);
+ return (TopiaEntityEnumEntry<T>)e.entry;
+ }
+
+ public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext ctxt, Class<T> klass) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return (D) entry.getDAO(ctxt);
+ }
+
+ public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(TopiaContext ctxt, T entity) throws TopiaException {
TopiaEntityEnumEntry<T> entry = getEntry(entity);
- <%=className%> e = <%=className%>.valueOf(entity);
- return (D) e.entry.getDAO(ctxt);
+ return (D) entry.getDAO(ctxt);
}
- public static <T extends TopiaEntity> T create(Class<T> klass, TopiaContext ctxt) throws TopiaException {
+ public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass) throws TopiaException {
TopiaEntityEnumEntry<T> entry = getEntry(klass);
- <%=className%> e = <%=className%>.valueOf(klass);
- return (T) e.entry.create(ctxt);
+ return entry.create(ctxt);
}
- public static <T extends TopiaEntity> T update(T entity, TopiaContext ctxt) throws TopiaException {
+ public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass, Object... properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.create(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> T create(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.create(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> T update(TopiaContext ctxt, T entity) throws TopiaException {
TopiaEntityEnumEntry<T> entry = getEntry(entity);
- <%=className%> e = <%=className%>.valueOf(entity);
- return (T) e.entry.update(entity, ctxt);
+ return entry.update(entity, ctxt);
}
- public static <T extends TopiaEntity> void delete(T entity, TopiaContext ctxt) throws TopiaException {
+ public static <T extends TopiaEntity> void delete(TopiaContext ctxt, T entity) throws TopiaException {
TopiaEntityEnumEntry<T> entry = getEntry(entity);
- <%=className%> e = <%=className%>.valueOf(entity);
- e.entry.delete(entity, ctxt);
+ entry.delete(entity, ctxt);
}
- public static <T extends TopiaEntity> java.util.List<T> findAll(Class<T> klass, TopiaContext ctxt) throws TopiaException {
+ public static <T extends TopiaEntity> int size(TopiaContext ctxt, Class<T> klass) throws TopiaException {
TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.size(ctxt);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAll(TopiaContext ctxt, Class<T> klass) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
return entry.findAll(ctxt);
}
- public static <T extends TopiaEntity> T findByTopiaId(Class<T> klass, TopiaContext ctxt,String topiaId) throws TopiaException {
+ public static <T extends TopiaEntity> List<T> findAllWithOrder(TopiaContext ctxt, Class<T> klass,String... propertyNames) throws TopiaException {
TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllWithOrder(ctxt, propertyNames);
+ }
+
+ public static <T extends TopiaEntity> T findByTopiaId(TopiaContext ctxt, Class<T> klass,String topiaId) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
return entry.findByTopiaId(topiaId,ctxt);
}
- public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(T entity) throws TopiaException {
- <%=className%> e = <%=className%>.valueOf(entity);
- return (TopiaEntityEnumEntry<T>)e.entry;
+ public static <T extends TopiaEntity> T findByPrimaryKey(TopiaContext ctxt, Class<T> klass, Map<String, Object> keys) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByPrimaryKey(ctxt, keys);
}
- public static <T extends TopiaEntity> TopiaEntityEnumEntry<T> getEntry(Class<T> klass) throws TopiaException {
- <%=className%> e = <%=className%>.valueOf(klass);
- return (TopiaEntityEnumEntry<T>)e.entry;
+ public static <T extends TopiaEntity> T findByPrimaryKey(TopiaContext ctxt, Class<T> klass, Object... k) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByPrimaryKey(ctxt, k);
}
+
+ public static <T extends TopiaEntity> T findByProperty(TopiaContext ctxt, Class<T> klass, String propertyName, Object value) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByProperty(ctxt, propertyName, value);
+ }
+
+ public static <T extends TopiaEntity> T findByProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Object value, Object... others) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByProperties(ctxt, propertyName, value, others);
+ }
+
+ public static <T extends TopiaEntity> T findByProperties(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findByProperties(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllByProperty(TopiaContext ctxt, Class<T> klass, String propertyName, Object value) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllByProperty(ctxt, propertyName, value);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllByProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Object value, Object... others) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllByProperties(ctxt, propertyName, value, others);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllByProperties(TopiaContext ctxt, Class<T> klass, Map<String, Object> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllByProperties(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> T findContainsProperties(TopiaContext ctxt, Class<T> klass, Map<String, Collection> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findContainsProperties(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> T findContainsProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Collection values, Object... others) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findContainsProperties(ctxt, propertyName, values, others);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllContainsProperties(TopiaContext ctxt, Class<T> klass, Map<String, Collection> properties) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllContainsProperties(ctxt, properties);
+ }
+
+ public static <T extends TopiaEntity> List<T> findAllContainsProperties(TopiaContext ctxt, Class<T> klass, String propertyName, Collection values, Object... others) throws TopiaException {
+ TopiaEntityEnumEntry<T> entry = getEntry(klass);
+ return entry.findAllContainsProperties(ctxt, propertyName, values, others);
+ }
+
}
}*/
}
Modified: topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAO.java 2008-11-16 18:29:50 UTC (rev 1224)
@@ -114,6 +114,8 @@
public abstract List<Entity> findAll() throws TopiaException;
+ public abstract List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException;
+
/**
* TODO modifier l'implantation pour faire un simple count sur la base
*
Modified: topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAOAbstract.java 2008-11-16 18:29:50 UTC (rev 1224)
@@ -385,7 +385,7 @@
* Recherche une entity contenant certain propriété. Pour l'instant on
* charche toute les entités existantes pour faire la recherche
*
- * @see org.codelutin.topia.TopiaDAO#findAllByProperties(java.util.Map)
+ * @see org.codelutin.topia.persistence.TopiaDAO#findAllByProperties(java.util.Map)
*/
public List<Entity> findAllByProperties(Map<String, Object> properties)
throws TopiaException {
Modified: topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaDAODelegator.java 2008-11-16 18:29:50 UTC (rev 1224)
@@ -143,6 +143,10 @@
return getParentDAO().findAll();
}
+ public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
+ return getParentDAO().findAllWithOrder(propertyNames);
+ }
+
/* (non-Javadoc)
* @see org.codelutin.topia.TopiaDAO#size()
*/
Modified: topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-16 18:29:50 UTC (rev 1224)
@@ -4,7 +4,9 @@
import org.codelutin.topia.TopiaException;
import org.codelutin.topia.framework.TopiaContextImplementor;
+import java.util.Collection;
import java.util.List;
+import java.util.Map;
/** @author chemit */
public class TopiaEntityEnumEntry<T extends TopiaEntity> implements java.io.Serializable {
@@ -50,6 +52,16 @@
return newInstance;
}
+ public T create(TopiaContext ctxt, Object... properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.create(properties);
+ }
+
+ public T create(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.create(properties);
+ }
+
public T update(T entity, TopiaContext ctxt) throws TopiaException {
TopiaDAO<T> dao = getDAO(ctxt);
return dao.update(entity);
@@ -60,14 +72,84 @@
dao.delete(entity);
}
+ public int size(TopiaContext ctxt) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.size();
+ }
+
public List<T> findAll(TopiaContext ctxt) throws TopiaException {
TopiaDAO<T> dao = getDAO(ctxt);
return dao.findAll();
}
+ public List<T> findAllWithOrder(TopiaContext ctxt,String... propertyNames) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllWithOrder(propertyNames);
+ }
+
public T findByTopiaId(String topiaId, TopiaContext ctxt) throws TopiaException {
TopiaDAO<T> dao = getDAO(ctxt);
- return dao.findByTopiaId(topiaId);
+ return dao.findByTopiaId(topiaId);
}
+ public T findByPrimaryKey(TopiaContext ctxt, Map<String, Object> keys) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByPrimaryKey(keys);
+ }
+
+ public T findByPrimaryKey(TopiaContext ctxt, Object... k) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByPrimaryKey(k);
+ }
+
+ public T findByProperty(TopiaContext ctxt, String propertyName, Object value) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperty(propertyName, value);
+ }
+
+ public T findByProperties(TopiaContext ctxt, String propertyName, Object value, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperties(propertyName, value, others);
+ }
+
+ public T findByProperties(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findByProperties(properties);
+ }
+
+ public List<T> findAllByProperty(TopiaContext ctxt, String propertyName, Object value) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperty(propertyName, value);
+ }
+
+ public List<T> findAllByProperties(TopiaContext ctxt, String propertyName, Object value, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperties(propertyName, value, others);
+ }
+
+ public List<T> findAllByProperties(TopiaContext ctxt, Map<String, Object> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllByProperties(properties);
+ }
+
+ public T findContainsProperties(TopiaContext ctxt, Map<String, Collection> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findContainsProperties(properties);
+ }
+
+ public T findContainsProperties(TopiaContext ctxt, String propertyName, Collection values, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findContainsProperties(propertyName, values, others);
+ }
+
+ public List<T> findAllContainsProperties(TopiaContext ctxt, Map<String, Collection> properties) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllContainsProperties(properties);
+ }
+
+ public List<T> findAllContainsProperties(TopiaContext ctxt, String propertyName, Collection values, Object... others) throws TopiaException {
+ TopiaDAO<T> dao = getDAO(ctxt);
+ return dao.findAllContainsProperties(propertyName, values, others);
+ }
+
}
Modified: topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/trunk/src/main/java/org/codelutin/topia/persistence/flatfile/TopiaDAOFlatFile.java 2008-11-16 18:29:50 UTC (rev 1224)
@@ -250,7 +250,7 @@
/**
* Sauve l'entity dans le fichier
*
- * @see org.codelutin.topia.TopiaDAO#update()
+ * @see org.codelutin.topia.persistence.TopiaDAO#update(org.codelutin.topia.persistence.TopiaEntity)
*/
public Entity update(Entity e) throws TopiaException {
getContext().getFiresSupport().fireOnPreUpdate(getContext(), e, new Object[]{});
@@ -331,7 +331,7 @@
/**
* Supprime le fichier contenant l'entity
*
- * @see org.codelutin.topia.TopiaDAO#delete()
+ * @see org.codelutin.topia.persistence.TopiaDAO#delete(org.codelutin.topia.persistence.TopiaEntity)
*/
public void delete(Entity e) throws TopiaException {
getContext().getFiresSupport().fireOnPreDelete(getContext(), e, new Object[]{});
@@ -350,7 +350,7 @@
* Recherche un fichier si dans mapping key est indiqué il est utilisé a la
* place du topiaId qui n'existe peut-etre pas
*
- * @see org.codelutin.topia.TopiaDAO#findByTopiaId()
+ * @see org.codelutin.topia.persistence.TopiaDAO#findByTopiaId(String)
*/
@Override
public Entity findByTopiaId(String k) throws TopiaException {
@@ -460,6 +460,10 @@
return result;
}
+ public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
+ throw new IllegalStateException("findAllWithOrder method is not implemented by "+getClass());
+ }
+
/**
* Permet de filtrer les fichiers si une extension a ete defini dans le
* mapping
Modified: topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java
===================================================================
--- topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-14 11:16:46 UTC (rev 1223)
+++ topia/trunk/src/main/java/org/codelutin/topia/persistence/hibernate/TopiaDAOHibernate.java 2008-11-16 18:29:50 UTC (rev 1224)
@@ -44,6 +44,7 @@
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.hibernate.criterion.Order;
/**
* Cette persistence accède à l'objet Session hibernate pour exécuter
@@ -121,11 +122,25 @@
}
}
+ public List<Entity> findAllWithOrder(String... propertyNames) throws TopiaException {
+ try {
+ Criteria criteria = createCriteria(FlushMode.AUTO);
+ for (String propertyName : propertyNames) {
+ criteria.addOrder(Order.asc(propertyName));
+ }
+ List<Entity> result = (List<Entity>)criteria.list();
+ result = getContext().getFiresSupport().fireEntitiesLoad(context, result);
+ return result;
+ } catch (HibernateException eee) {
+ throw new TopiaException(eee);
+ }
+ }
+
/**
* TODO implanter une facon plus rapide de recupere la size (count direct
* sur la base)
* (non-Javadoc)
- * @see org.codelutin.topia.TopiaDAO#size()
+ * @see org.codelutin.topia.persistence.TopiaDAO#size()
*/
@Override
public int size() throws TopiaException {
1
0
Author: chatellier
Date: 2008-11-14 11:16:46 +0000 (Fri, 14 Nov 2008)
New Revision: 1223
Modified:
topia-service/trunk/pom.xml
Log:
Correct vars
Modified: topia-service/trunk/pom.xml
===================================================================
--- topia-service/trunk/pom.xml 2008-11-14 11:16:17 UTC (rev 1222)
+++ topia-service/trunk/pom.xml 2008-11-14 11:16:46 UTC (rev 1223)
@@ -142,9 +142,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia-service/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/topia/topia-service/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia-service/t…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
</project>
1
0
Author: chatellier
Date: 2008-11-14 11:16:17 +0000 (Fri, 14 Nov 2008)
New Revision: 1222
Modified:
topia/trunk/pom.xml
Log:
Correct vars
Modified: topia/trunk/pom.xml
===================================================================
--- topia/trunk/pom.xml 2008-11-14 11:04:48 UTC (rev 1221)
+++ topia/trunk/pom.xml 2008-11-14 11:16:17 UTC (rev 1222)
@@ -199,9 +199,9 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/topia/topia/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/topia/topia/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/topia/trunk/?ro…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
</project>
1
0