From 1c308a684a64973bf8df3ecb46c6548d1d31710c Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Sun, 22 Jan 2012 08:16:15 +0100 Subject: [PATCH] Small refactor for comming converters --- .settings/org.eclipse.core.resources.prefs | 3 + pom.xml | 4 +- vasc-backend/vasc-backend-jdbc/.classpath | 10 + vasc-backend/vasc-backend-jdbc/.project | 23 ++ .../org.eclipse.core.resources.prefs | 7 + .../.settings/org.eclipse.jdt.core.prefs | 6 + .../.settings/org.eclipse.m2e.core.prefs | 5 + vasc-backend/vasc-backend-jdbc/pom.xml | 19 + .../backend/jdbc/JdbcConnectionProvider.java | 37 ++ .../jdbc/JdbcConnectionProviderImpl.java | 117 ++++++ .../jdbc/JdbcConnectionProviderJdniImpl.java | 108 ++++++ .../vasc/backend/jdbc/JdbcVascBackend.java | 157 ++++++++ .../backend/jdbc/JdbcVascBackendXpql.java | 163 +++++++++ .../META-INF/vasc/vasc-backend-jdbc.eld | 14 + .../META-INF/vasc/vasc-namespaces.xml | 8 + vasc-backend/vasc-backend-jpa/.project | 4 +- .../jpa/AbstractHibernateVascBackend.java | 2 +- .../jpa/AbstractPersistenceVascBackend.java | 2 +- .../jpa/XpqlHibernateVascBackend.java | 20 +- .../jpa/XpqlPersistanceVascBackend.java | 18 +- .../META-INF/vasc/vasc-backend-jpa.eld | 26 ++ .../META-INF/vasc/vasc-namespaces.xml | 8 + .../backend/ldap/LdapConnectionProvider.java | 35 ++ .../ldap/LdapConnectionProviderImpl.java | 133 +++++++ .../vasc/backend/ldap/LdapVascBackend.java | 334 ++++++++++++++++++ .../META-INF/vasc/vasc-backend-ldap.eld | 9 + .../META-INF/vasc/vasc-namespaces.xml | 8 + .../vasc-backend-metamodel/.classpath | 10 + vasc-backend/vasc-backend-metamodel/.project | 23 ++ .../org.eclipse.core.resources.prefs | 7 + .../.settings/org.eclipse.jdt.core.prefs | 6 + .../.settings/org.eclipse.m2e.core.prefs | 5 + vasc-backend/vasc-backend-metamodel/pom.xml | 24 ++ .../metamodel/MetaModelVascBackend.java | 97 +++++ .../mongodb/MongodbConnectionProvider.java | 40 +++ .../MongodbConnectionProviderImpl.java | 163 +++++++++ .../backend/mongodb/MongodbVascBackend.java | 151 ++++++++ .../mongodb/MongodbVascEntryFieldValue.java | 59 ++++ .../MongodbVascEntryRecordCreator.java | 49 +++ .../META-INF/vasc/vasc-backend-mongodb.eld | 7 + .../META-INF/vasc/vasc-namespaces.xml | 8 + vasc-core/.project | 4 +- .../AbstractVascBackend.java | 30 +- .../AbstractVascBackendState.java | 22 +- .../vasc/{core => backend}/VascBackend.java | 5 +- .../VascBackendController.java | 2 +- .../VascBackendControllerLocal.java | 2 +- .../{core => backend}/VascBackendFilter.java | 4 +- .../VascBackendPageNumber.java | 2 +- .../{core => backend}/VascBackendState.java | 2 +- .../data}/BeanVascEntryFieldValue.java | 2 +- .../data}/BeanVascEntryRecordCreator.java | 2 +- .../data}/MapVascEntryFieldValue.java | 24 +- .../data}/MapVascEntryRecordCreator.java | 2 +- .../proxy}/AbstractVascBackendProxy.java | 42 ++- .../proxy}/VascBackendProxyCache.java | 9 +- .../proxy}/VascBackendProxyEventExecutor.java | 21 +- .../proxy}/VascBackendProxyFilter.java | 11 +- .../proxy}/VascBackendProxyPaged.java | 11 +- .../proxy}/VascBackendProxySearch.java | 29 +- .../proxy}/VascBackendProxySort.java | 9 +- .../proxy}/VascBackendProxyTimerLogger.java | 19 +- .../vasc/core/AbstractVascEntryFieldType.java | 7 +- .../vasc/core/AbstractVascEntryState.java | 3 + .../forwardfire/vasc/core/VascController.java | 2 + .../net/forwardfire/vasc/core/VascEntry.java | 2 + .../vasc/core/VascEntryControllerLocal.java | 2 + .../forwardfire/vasc/core/VascEntryState.java | 3 + .../AbstractVascFrontend.java | 10 +- .../vasc/{core => frontend}/VascFrontend.java | 3 +- .../vasc/frontend/VascFrontendActions.java | 52 +++ .../{core => frontend}/VascFrontendData.java | 29 +- .../VascFrontendExceptionHandler.java | 4 +- .../VascFrontendHelper.java | 38 +- .../vasc/frontend/VascFrontendPager.java | 55 +++ .../impl/DefaultVascBackedEntryFinalizer.java | 12 +- .../impl/DefaultVascBackendController.java | 6 +- .../vasc/impl/DefaultVascBackendState.java | 2 +- .../vasc/impl/DefaultVascController.java | 2 +- .../vasc/impl/DefaultVascEntry.java | 4 +- .../vasc/impl/DefaultVascEntryController.java | 2 +- .../vasc/impl/DefaultVascFactory.java | 115 +++++- .../vasc/impl/DefaultVascFrontendActions.java | 290 +++++++++++++++ .../vasc/impl/DefaultVascFrontendData.java | 62 +++- .../vasc/impl/DefaultVascFrontendHelper.java | 312 ++++------------ .../vasc/impl/DefaultVascFrontendPager.java | 223 ++++++++++++ .../vasc/impl/actions/AddRowAction.java | 2 +- .../impl/actions/CSVExportGlobalAction.java | 2 +- .../vasc/impl/actions/EditRowAction.java | 2 +- .../impl/actions/RefreshDataGlobalAction.java | 2 +- .../impl/actions/XMLExportGlobalAction.java | 2 +- .../entry/SetParameterBackendListener.java | 2 +- .../impl/ui/VascSelectItemModelEntry.java | 293 +++++++++++++++ .../ui/VascSelectItemModelStringEnum.java | 146 ++++++++ .../impl/x4o/AnnotationParserElement.java | 20 +- .../x4o/VascBackendElementConfigurator.java | 6 +- ...r.java => VascEntryFieldConfigurator.java} | 34 +- .../vasc/impl/x4o/VascEntryFieldElement.java | 3 +- ...ter.java => VascEntryFieldSetElement.java} | 21 +- .../META-INF/fieldtype/fieldtype-lang.eld | 8 +- .../resources/META-INF/vasc/vasc-lang.eld | 28 +- .../vasc-demo-petstore-j2ee5-ejb/.classpath | 6 +- .../vasc-demo-petstore-j2ee5-ejb/.project | 13 + .../.settings/org.eclipse.jdt.core.prefs | 5 +- .../vasc/demo/swing/SwingStartup.java | 150 ++++---- .../vasc/demo/swing/example/tables.xml | 263 ++++++++++++++ vasc-ejb3/.project | 4 +- .../vasc/ejb3/VascServiceManagerImpl.java | 133 +------ vasc-frontend/vasc-frontend-swing/pom.xml | 6 + .../frontends/swing/SwingActionPanel.java | 283 +++++++++++++++ .../vasc/frontends/swing/SwingPagerPanel.java | 164 +++++++++ .../frontends/swing/SwingVascEditDialog.java | 176 +++++++++ .../frontends/swing/SwingVascFrontend.java | 187 +++++++--- .../frontends/swing/SwingVascTableModel.java | 110 ++++++ .../java/net/forwardfire/vasc/SwingTest.java | 43 ++- .../vasc/TestModelVascDataSource.java | 145 -------- vasc-frontend/vasc-frontend-swt/pom.xml | 8 +- .../vasc/frontends/swt/SwtActionPanel.java | 154 ++++++++ .../vasc/frontends/swt/SwtPagerPanel.java | 82 +++++ .../vasc/frontends/swt/SwtVascEditDialog.java | 3 +- .../vasc/frontends/swt/SwtVascFrontend.java | 38 +- .../java/net/forwardfire/vasc/SWTTest.java | 25 +- .../java/net/forwardfire/vasc/TestModel.java | 167 --------- vasc-frontend/vasc-frontend-web-jsf/.project | 4 +- .../AbstractJSFVascFacesControllerBase.java | 63 ++++ ...=> AbstractJSFVascFacesControllerEJB.java} | 61 +--- .../AbstractJSFVascFacesControllerLocal.java | 157 ++++++++ .../web/jsf/JSFVascEntryEventListener.java | 2 +- .../web/jsf/JSFVascEntrySupportBean.java | 206 ++--------- .../web/jsf/JSFVascFrontendRenderer.java | 14 +- .../frontends/web/jsf/JSFVascUIComponent.java | 14 +- .../web/jsf/JSFVascUIComponentRenderer.java | 6 +- .../frontends/web/jsf/OldVascUIComponent.java | 42 +-- .../web/jsf/VascRequestFacesFilter.java | 3 +- vasc-test/.project | 17 + .../org.eclipse.core.resources.prefs | 3 + .../.settings/org.eclipse.m2e.core.prefs | 5 + vasc-test/pom.xml | 16 + vasc-test/vasc-test-frontend-data/.classpath | 10 + vasc-test/vasc-test-frontend-data/.project | 23 ++ .../org.eclipse.core.resources.prefs | 7 + .../.settings/org.eclipse.jdt.core.prefs | 6 + .../.settings/org.eclipse.m2e.core.prefs | 5 + vasc-test/vasc-test-frontend-data/pom.xml | 17 + .../vasc/test/frontend/data}/TestModel.java | 2 +- .../test/frontend/data/TestModelEntry.java | 118 +++---- .../data}/TestModelVascDataSource.java | 72 ++-- vasc-xpql-ejb3-client/.classpath | 10 + vasc-xpql-ejb3-client/.project | 23 ++ .../org.eclipse.core.resources.prefs | 7 + .../.settings/org.eclipse.jdt.core.prefs | 6 + .../.settings/org.eclipse.m2e.core.prefs | 5 + vasc-xpql-ejb3-client/pom.xml | 25 ++ .../vasc/xpql/ejb3/XpqlQueryManager.java | 0 .../xpql/ejb3/x4o/XpqlEjb3QueriesElement.java | 106 ++++++ .../META-INF/vasc/vasc-namespaces.xml | 8 + .../META-INF/vasc/vasc-xpql-ejb3.eld | 4 + .../.classpath | 0 .../.project | 4 +- .../org.eclipse.core.resources.prefs | 0 .../.settings/org.eclipse.jdt.core.prefs | 0 .../.settings/org.eclipse.m2e.core.prefs | 0 .../.settings/org.maven.ide.eclipse.prefs | 0 .../pom.xml | 20 +- .../vasc/xpql/ejb3/XpqlQueryManagerImpl.java | 0 .../src/main/resources/.empty | 0 .../src/test/java/.empty | 0 .../src/test/resources/.empty | 0 vasc-xpql/.project | 4 +- ...java => ParameterTypeObjectConverter.java} | 26 +- ...ter.java => QueryTypeObjectConverter.java} | 29 +- .../vasc/xpql/x4o/XpqlLoadQueriesElement.java | 49 +++ .../META-INF/vasc/vasc-namespaces.xml | 8 + .../resources/META-INF/vasc/vasc-xpql.eld | 4 + .../resources/META-INF/xpql/xpql-lang.eld | 14 +- .../src/test/resources/xpql/test-all.xml | 4 +- .../src/test/resources/xpql/test-meta.xml | 4 +- vasc-xpql/src/test/resources/xpql/tests.xml | 4 +- 178 files changed, 5865 insertions(+), 1531 deletions(-) create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 vasc-backend/vasc-backend-jdbc/.classpath create mode 100644 vasc-backend/vasc-backend-jdbc/.project create mode 100644 vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.core.resources.prefs create mode 100644 vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.jdt.core.prefs create mode 100644 vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.m2e.core.prefs create mode 100644 vasc-backend/vasc-backend-jdbc/pom.xml create mode 100644 vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProvider.java create mode 100644 vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProviderImpl.java create mode 100644 vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProviderJdniImpl.java create mode 100644 vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcVascBackend.java create mode 100644 vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcVascBackendXpql.java create mode 100644 vasc-backend/vasc-backend-jdbc/src/main/resources/META-INF/vasc/vasc-backend-jdbc.eld create mode 100644 vasc-backend/vasc-backend-jdbc/src/main/resources/META-INF/vasc/vasc-namespaces.xml create mode 100644 vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-backend-jpa.eld create mode 100644 vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-namespaces.xml create mode 100644 vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProvider.java create mode 100644 vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProviderImpl.java create mode 100644 vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapVascBackend.java create mode 100644 vasc-backend/vasc-backend-ldap/src/main/resources/META-INF/vasc/vasc-backend-ldap.eld create mode 100644 vasc-backend/vasc-backend-ldap/src/main/resources/META-INF/vasc/vasc-namespaces.xml create mode 100644 vasc-backend/vasc-backend-metamodel/.classpath create mode 100644 vasc-backend/vasc-backend-metamodel/.project create mode 100644 vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.core.resources.prefs create mode 100644 vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.jdt.core.prefs create mode 100644 vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.m2e.core.prefs create mode 100644 vasc-backend/vasc-backend-metamodel/pom.xml create mode 100644 vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java create mode 100644 vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbConnectionProvider.java create mode 100644 vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbConnectionProviderImpl.java create mode 100644 vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascBackend.java create mode 100644 vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascEntryFieldValue.java create mode 100644 vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascEntryRecordCreator.java create mode 100644 vasc-backend/vasc-backend-mongodb/src/main/resources/META-INF/vasc/vasc-backend-mongodb.eld create mode 100644 vasc-backend/vasc-backend-mongodb/src/main/resources/META-INF/vasc/vasc-namespaces.xml rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend}/AbstractVascBackend.java (71%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend}/AbstractVascBackendState.java (81%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend}/VascBackend.java (95%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend}/VascBackendController.java (97%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend}/VascBackendControllerLocal.java (97%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend}/VascBackendFilter.java (95%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend}/VascBackendPageNumber.java (98%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend}/VascBackendState.java (98%) rename vasc-core/src/main/java/net/forwardfire/vasc/{backends => backend/data}/BeanVascEntryFieldValue.java (98%) rename vasc-core/src/main/java/net/forwardfire/vasc/{backends => backend/data}/BeanVascEntryRecordCreator.java (97%) rename vasc-core/src/main/java/net/forwardfire/vasc/{backends => backend/data}/MapVascEntryFieldValue.java (82%) rename vasc-core/src/main/java/net/forwardfire/vasc/{backends => backend/data}/MapVascEntryRecordCreator.java (97%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => backend/proxy}/AbstractVascBackendProxy.java (71%) rename vasc-core/src/main/java/net/forwardfire/vasc/{impl => backend/proxy}/VascBackendProxyCache.java (91%) rename vasc-core/src/main/java/net/forwardfire/vasc/{impl => backend/proxy}/VascBackendProxyEventExecutor.java (83%) rename vasc-core/src/main/java/net/forwardfire/vasc/{impl => backend/proxy}/VascBackendProxyFilter.java (88%) rename vasc-core/src/main/java/net/forwardfire/vasc/{impl => backend/proxy}/VascBackendProxyPaged.java (88%) rename vasc-core/src/main/java/net/forwardfire/vasc/{impl => backend/proxy}/VascBackendProxySearch.java (80%) rename vasc-core/src/main/java/net/forwardfire/vasc/{impl => backend/proxy}/VascBackendProxySort.java (93%) rename vasc-core/src/main/java/net/forwardfire/vasc/{impl => backend/proxy}/VascBackendProxyTimerLogger.java (84%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => frontend}/AbstractVascFrontend.java (89%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => frontend}/VascFrontend.java (95%) create mode 100644 vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendActions.java rename vasc-core/src/main/java/net/forwardfire/vasc/{core => frontend}/VascFrontendData.java (80%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => frontend}/VascFrontendExceptionHandler.java (95%) rename vasc-core/src/main/java/net/forwardfire/vasc/{core => frontend}/VascFrontendHelper.java (76%) create mode 100644 vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendPager.java create mode 100644 vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendActions.java create mode 100644 vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendPager.java create mode 100644 vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelEntry.java create mode 100644 vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelStringEnum.java rename vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/{VascEntryFieldTypeAttributeConverter.java => VascEntryFieldConfigurator.java} (64%) rename vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/{VascEntryFieldSetAttributeConverter.java => VascEntryFieldSetElement.java} (72%) rename vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestTable.java => vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/SwingStartup.java (52%) create mode 100644 vasc-demo/vasc-demo-swing/src/main/resources/net/forwardfire/vasc/demo/swing/example/tables.xml create mode 100644 vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingActionPanel.java create mode 100644 vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPagerPanel.java create mode 100644 vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascEditDialog.java create mode 100644 vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascTableModel.java delete mode 100644 vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestModelVascDataSource.java create mode 100644 vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtActionPanel.java create mode 100644 vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtPagerPanel.java delete mode 100644 vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestModel.java create mode 100644 vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerBase.java rename vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/{AbstractJSFVascFacesController.java => AbstractJSFVascFacesControllerEJB.java} (86%) create mode 100644 vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerLocal.java create mode 100644 vasc-test/.project create mode 100644 vasc-test/.settings/org.eclipse.core.resources.prefs create mode 100644 vasc-test/.settings/org.eclipse.m2e.core.prefs create mode 100644 vasc-test/pom.xml create mode 100644 vasc-test/vasc-test-frontend-data/.classpath create mode 100644 vasc-test/vasc-test-frontend-data/.project create mode 100644 vasc-test/vasc-test-frontend-data/.settings/org.eclipse.core.resources.prefs create mode 100644 vasc-test/vasc-test-frontend-data/.settings/org.eclipse.jdt.core.prefs create mode 100644 vasc-test/vasc-test-frontend-data/.settings/org.eclipse.m2e.core.prefs create mode 100644 vasc-test/vasc-test-frontend-data/pom.xml rename {vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc => vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data}/TestModel.java (98%) rename vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestTable.java => vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelEntry.java (51%) rename {vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc => vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data}/TestModelVascDataSource.java (74%) create mode 100644 vasc-xpql-ejb3-client/.classpath create mode 100644 vasc-xpql-ejb3-client/.project create mode 100644 vasc-xpql-ejb3-client/.settings/org.eclipse.core.resources.prefs create mode 100644 vasc-xpql-ejb3-client/.settings/org.eclipse.jdt.core.prefs create mode 100644 vasc-xpql-ejb3-client/.settings/org.eclipse.m2e.core.prefs create mode 100644 vasc-xpql-ejb3-client/pom.xml rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-client}/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManager.java (100%) create mode 100644 vasc-xpql-ejb3-client/src/main/java/net/forwardfire/vasc/xpql/ejb3/x4o/XpqlEjb3QueriesElement.java create mode 100644 vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-namespaces.xml create mode 100644 vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-xpql-ejb3.eld rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/.classpath (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/.project (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/.settings/org.eclipse.core.resources.prefs (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/.settings/org.eclipse.jdt.core.prefs (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/.settings/org.eclipse.m2e.core.prefs (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/.settings/org.maven.ide.eclipse.prefs (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/pom.xml (69%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManagerImpl.java (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/src/main/resources/.empty (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/src/test/java/.empty (100%) rename {vasc-xpql-ejb3 => vasc-xpql-ejb3-server}/src/test/resources/.empty (100%) rename vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/{ParameterTypeAttributeConverter.java => ParameterTypeObjectConverter.java} (70%) rename vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/{QueryTypeAttributeConverter.java => QueryTypeObjectConverter.java} (70%) create mode 100644 vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/x4o/XpqlLoadQueriesElement.java create mode 100644 vasc-xpql/src/main/resources/META-INF/vasc/vasc-namespaces.xml create mode 100644 vasc-xpql/src/main/resources/META-INF/vasc/vasc-xpql.eld diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..7f9d102 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Sat Jan 14 05:41:26 CET 2012 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/pom.xml b/pom.xml index 5e59e8b..078efb6 100644 --- a/pom.xml +++ b/pom.xml @@ -28,10 +28,12 @@ vasc-core vasc-ejb3 vasc-xpql - vasc-xpql-ejb3 + vasc-xpql-ejb3-server + vasc-xpql-ejb3-client vasc-backend vasc-frontend vasc-demo + vasc-test https://...vasc/ diff --git a/vasc-backend/vasc-backend-jdbc/.classpath b/vasc-backend/vasc-backend-jdbc/.classpath new file mode 100644 index 0000000..3c96d64 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/vasc-backend/vasc-backend-jdbc/.project b/vasc-backend/vasc-backend-jdbc/.project new file mode 100644 index 0000000..ff56a1a --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/.project @@ -0,0 +1,23 @@ + + + vasc-backend-jdbc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.core.resources.prefs b/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..dc734e5 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +#Sat Dec 31 04:21:23 CET 2011 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.jdt.core.prefs b/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..1fc168e --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,6 @@ +#Sat Dec 31 04:21:23 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.m2e.core.prefs b/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..6d08edf --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Sat Dec 31 04:21:23 CET 2011 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/vasc-backend/vasc-backend-jdbc/pom.xml b/vasc-backend/vasc-backend-jdbc/pom.xml new file mode 100644 index 0000000..a580377 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + + vasc-backend + net.forwardfire.vasc + 0.3.5-SNAPSHOT + .. + + vasc-backend-jdbc + vasc-backend-jdbc + vasc-backend-jdbc + + + net.forwardfire.vasc + vasc-core + ${project.version} + + + \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProvider.java b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProvider.java new file mode 100644 index 0000000..e670f22 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.jdbc; + +import java.sql.Connection; +import java.sql.SQLException; + + +/** + * + * @author Willem Cazander + * @version 1.0 Sep 5, 2008 + */ +public interface JdbcConnectionProvider { + + public Connection getJdbcConnection() throws SQLException; +} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProviderImpl.java b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProviderImpl.java new file mode 100644 index 0000000..2bf2295 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProviderImpl.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.jdbc; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 15, 2009 + */ +public class JdbcConnectionProviderImpl implements JdbcConnectionProvider { + + private String driverClassName = null; + private String dbUrl = null; + private String dbUser = null; + private String dbPassword = null; + private boolean loadedDriver = false; + + /** + * @see net.forwardfire.vasc.backend.jdbc.JdbcConnectionProvider#getJdbcConnection() + */ + public Connection getJdbcConnection() throws SQLException { + if (loadedDriver==false) { + try { + Class.forName(driverClassName); + loadedDriver = true; + } catch (ClassNotFoundException e) { + throw new SQLException("Could not load driver: "+driverClassName+" error: "+e.getMessage(),e); + } + } + Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPassword); + return connection; + } + + /** + * @return the driverClassName + */ + public String getDriverClassName() { + return driverClassName; + } + + /** + * @param driverClassName the driverClassName to set + */ + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } + + /** + * @return the dbUrl + */ + public String getDbUrl() { + return dbUrl; + } + + /** + * @param dbUrl the dbUrl to set + */ + public void setDbUrl(String dbUrl) { + this.dbUrl = dbUrl; + } + + /** + * @return the dbUser + */ + public String getDbUser() { + return dbUser; + } + + /** + * @param dbUser the dbUser to set + */ + public void setDbUser(String dbUser) { + this.dbUser = dbUser; + } + + /** + * @return the dbPassword + */ + public String getDbPassword() { + return dbPassword; + } + + /** + * @param dbPassword the dbPassword to set + */ + public void setDbPassword(String dbPassword) { + this.dbPassword = dbPassword; + } + + + +} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProviderJdniImpl.java b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProviderJdniImpl.java new file mode 100644 index 0000000..65a4570 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcConnectionProviderJdniImpl.java @@ -0,0 +1,108 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.jdbc; + +import java.sql.Connection; +import java.sql.SQLException; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 15, 2009 + */ +public class JdbcConnectionProviderJdniImpl implements JdbcConnectionProvider { + + /** The context in which database data sources are found. */ + private String dataSourceContext = "java:/"; + + private String dataSourceName = null; + + /** + * @see net.forwardfire.vasc.backend.jdbc.JdbcConnectionProvider#getJdbcConnection() + */ + public Connection getJdbcConnection() throws SQLException { + Connection connection = getDataSource(dataSourceName).getConnection(); + return connection; + } + + + /** + * Gets a DataSource out of the JNDI context. + *

+ * @param name The name of the data source in the JDNI context. + * @return The data source. + */ + private DataSource getDataSource(String name) throws SQLException { + + try { + Context initialContext = new InitialContext(); + if ( initialContext == null ) { + throw new SQLException("Cannot get Initial Context"); + } + DataSource datasource = (DataSource)initialContext.lookup(dataSourceContext+name); + if ( datasource == null ) { + throw new SQLException("Cannot lookup datasource: "+name); + } + return datasource; + } catch ( NamingException e ) { + throw new SQLException("Cannot get connection " + e,e); + } + } + + + /** + * @return the dataSourceContext + */ + public String getDataSourceContext() { + return dataSourceContext; + } + + + /** + * @param dataSourceContext the dataSourceContext to set + */ + public void setDataSourceContext(String dataSourceContext) { + this.dataSourceContext = dataSourceContext; + } + + + /** + * @return the dataSourceName + */ + public String getDataSourceName() { + return dataSourceName; + } + + + /** + * @param dataSourceName the dataSourceName to set + */ + public void setDataSourceName(String dataSourceName) { + this.dataSourceName = dataSourceName; + } +} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcVascBackend.java b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcVascBackend.java new file mode 100644 index 0000000..073a823 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcVascBackend.java @@ -0,0 +1,157 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.jdbc; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.forwardfire.vasc.backend.AbstractVascBackend; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue; +import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; +import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; + + + +/** + * + * @author Willem Cazander + * @version 1.0 Sep 5, 2008 + */ +public class JdbcVascBackend extends AbstractVascBackend { + + private JdbcConnectionProvider jdbcConnectionProvider = null; + private String sqlList = null; + private String idColumn = null; + private String sqlDelete = null; + private String sqlUpdate = null; + private String sqlInsert = null; + + /** + * @return the JdbcConnectionProvider + */ + public JdbcConnectionProvider getJdbcConnectionProvider() { + return jdbcConnectionProvider; + } + + /** + * @param JdbcConnectionProvider the JdbcConnectionProvider to set + */ + public void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) { + this.jdbcConnectionProvider = jdbcConnectionProvider; + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) + */ + public List execute(VascBackendState state) throws VascException { + JdbcConnectionProvider prov = getJdbcConnectionProvider(); + List result = new ArrayList(50); + Connection connection = null; + try { + connection = prov.getJdbcConnection(); + Statement s = connection.createStatement(); + s.execute(getSqlList()); + ResultSet rs = s.getResultSet(); + int cols = rs.getMetaData().getColumnCount(); + while (rs.next()) { + Map map = new HashMap(cols); + for (int i=1;i<=cols;i++) { + String columnName = rs.getMetaData().getColumnName(i); + Object columnObject = rs.getObject(i); + map.put(columnName, columnObject); + } + result.add(map); + } + } catch (Exception e) { + throw new VascException(e); + } finally { + if (connection!=null) { + try { + connection.close(); + } catch (Exception e) { + } + } + } + return result; + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object) + */ + public Object merge(Object object) throws VascException { + return object; + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object) + */ + public void persist(Object object) throws VascException { + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object) + */ + public void delete(Object object) throws VascException { + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) + */ + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return new MapVascEntryFieldValue(); + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) + */ + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return new MapVascEntryRecordCreator(); + } + + /** + * @return the sqlList + */ + public String getSqlList() { + return sqlList; + } + + /** + * @param sqlList the sqlList to set + */ + public void setSqlList(String sqlList) { + this.sqlList = sqlList; + } + + + +} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcVascBackendXpql.java b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcVascBackendXpql.java new file mode 100644 index 0000000..c821710 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/src/main/java/net/forwardfire/vasc/backend/jdbc/JdbcVascBackendXpql.java @@ -0,0 +1,163 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.jdbc; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.forwardfire.vasc.backend.AbstractVascBackend; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue; +import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; +import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; +import net.forwardfire.vasc.xpql.query.QueryParameterValue; + + + +/** + * + * @author Willem Cazander + * @version 1.0 Sep 5, 2008 + */ +public class JdbcVascBackendXpql extends AbstractVascBackend { + + private JdbcConnectionProvider jdbcConnectionProvider = null; + + private net.forwardfire.vasc.xpql.query.Query query = null; + + /** + * @return the JdbcConnectionProvider + */ + public JdbcConnectionProvider getJdbcConnectionProvider() { + return jdbcConnectionProvider; + } + + /** + * @param JdbcConnectionProvider the JdbcConnectionProvider to set + */ + public void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) { + this.jdbcConnectionProvider = jdbcConnectionProvider; + } + + /** + * @return the query + */ + public net.forwardfire.vasc.xpql.query.Query getQuery() { + return query; + } + + /** + * @param query the query to set + */ + public void setQuery(net.forwardfire.vasc.xpql.query.Query query) { + this.query = query; + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) + */ + public List execute(VascBackendState state) throws VascException { + // Copy parameters + for (String key:state.getDataParameterKeys()) { + Object value = state.getDataParameter(key); + query.setQueryParameter(key, value); + } + Connection c = null; + try { + c = getJdbcConnectionProvider().getJdbcConnection();; + PreparedStatement q = c.prepareStatement(query.toPreparedSQL(query)); + + List values = query.getOrderQueryParameterValues(); + int ii = 1; + for (QueryParameterValue value:values) { + q.setObject(ii,value.getValue()); + ii++; + } + q.execute(); + ResultSet rs = q.getResultSet(); + int cols = rs.getMetaData().getColumnCount(); + List result = new ArrayList(50); + while (rs.next()) { + Map map = new HashMap(cols); + for (int i=1;i<=cols;i++) { + String columnName = rs.getMetaData().getColumnName(i); + Object columnObject = rs.getObject(i); + map.put(columnName, columnObject); + } + result.add(map); + } + return result; + } catch (Exception e) { + throw new VascException(e); + } finally { + if (c!=null) { + try { + c.close(); + } catch (Exception e) { + } + } + } + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object) + */ + public Object merge(Object object) throws VascException { + return object; + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object) + */ + public void persist(Object object) throws VascException { + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object) + */ + public void delete(Object object) throws VascException { + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) + */ + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return new MapVascEntryFieldValue(); + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) + */ + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return new MapVascEntryRecordCreator(); + } +} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jdbc/src/main/resources/META-INF/vasc/vasc-backend-jdbc.eld b/vasc-backend/vasc-backend-jdbc/src/main/resources/META-INF/vasc/vasc-backend-jdbc.eld new file mode 100644 index 0000000..97ab68b --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/src/main/resources/META-INF/vasc/vasc-backend-jdbc.eld @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/vasc-backend/vasc-backend-jdbc/src/main/resources/META-INF/vasc/vasc-namespaces.xml b/vasc-backend/vasc-backend-jdbc/src/main/resources/META-INF/vasc/vasc-namespaces.xml new file mode 100644 index 0000000..1952301 --- /dev/null +++ b/vasc-backend/vasc-backend-jdbc/src/main/resources/META-INF/vasc/vasc-namespaces.xml @@ -0,0 +1,8 @@ + + + + + Vasc namespace for the jdbc backend + + vasc-backend-jdbc.eld + \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jpa/.project b/vasc-backend/vasc-backend-jpa/.project index 2c62ec8..c316f29 100644 --- a/vasc-backend/vasc-backend-jpa/.project +++ b/vasc-backend/vasc-backend-jpa/.project @@ -16,12 +16,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractHibernateVascBackend.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractHibernateVascBackend.java index 765b781..50045a3 100644 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractHibernateVascBackend.java +++ b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractHibernateVascBackend.java @@ -22,7 +22,7 @@ package net.forwardfire.vasc.backends.jpa; -import net.forwardfire.vasc.core.AbstractVascBackend; +import net.forwardfire.vasc.backend.AbstractVascBackend; import net.forwardfire.vasc.core.VascException; import org.hibernate.Session; diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractPersistenceVascBackend.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractPersistenceVascBackend.java index 825d295..8d08865 100644 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractPersistenceVascBackend.java +++ b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractPersistenceVascBackend.java @@ -26,7 +26,7 @@ import java.lang.reflect.Method; import javax.persistence.EntityManager; -import net.forwardfire.vasc.core.AbstractVascBackend; +import net.forwardfire.vasc.backend.AbstractVascBackend; import net.forwardfire.vasc.core.VascException; diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java index bd3fdf5..f142972 100644 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java +++ b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java @@ -24,9 +24,9 @@ package net.forwardfire.vasc.backends.jpa; import java.util.List; -import net.forwardfire.vasc.backends.BeanVascEntryFieldValue; -import net.forwardfire.vasc.backends.BeanVascEntryRecordCreator; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.backend.data.BeanVascEntryFieldValue; +import net.forwardfire.vasc.backend.data.BeanVascEntryRecordCreator; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; @@ -116,7 +116,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { } /** - * @see net.forwardfire.vasc.core.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { BeanVascEntryFieldValue result = new BeanVascEntryFieldValue(); @@ -124,7 +124,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { } /** - * @see net.forwardfire.vasc.core.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { return new BeanVascEntryRecordCreator(resultClass); @@ -187,7 +187,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackend#isPageable() + * @see net.forwardfire.vasc.backend.AbstractVascBackend#isPageable() */ @Override public boolean isPageable() { @@ -198,7 +198,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { } /** - * @see net.forwardfire.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#fetchTotalExecuteSize(VascBackendState state) */ public long fetchTotalExecuteSize(VascBackendState state) { Session s = getHibernateSession(); @@ -227,7 +227,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveDownById(java.lang.Object) + * @see net.forwardfire.vasc.backend.AbstractVascBackend#doRecordMoveDownById(java.lang.Object) */ @Override public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException { @@ -296,7 +296,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveUpById(java.lang.Object) + * @see net.forwardfire.vasc.backend.AbstractVascBackend#doRecordMoveUpById(java.lang.Object) */ @Override public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException { @@ -365,7 +365,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackend#isRecordMoveable() + * @see net.forwardfire.vasc.backend.AbstractVascBackend#isRecordMoveable() */ @Override public boolean isRecordMoveable() { diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlPersistanceVascBackend.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlPersistanceVascBackend.java index 343af01..180e4ce 100644 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlPersistanceVascBackend.java +++ b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlPersistanceVascBackend.java @@ -27,9 +27,9 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; -import net.forwardfire.vasc.backends.BeanVascEntryFieldValue; -import net.forwardfire.vasc.backends.BeanVascEntryRecordCreator; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.backend.data.BeanVascEntryFieldValue; +import net.forwardfire.vasc.backend.data.BeanVascEntryRecordCreator; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; @@ -121,7 +121,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend } /** - * @see net.forwardfire.vasc.core.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { VascEntryFieldValue result = new BeanVascEntryFieldValue(); @@ -129,7 +129,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend } /** - * @see net.forwardfire.vasc.core.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { VascEntryRecordCreator result = new BeanVascEntryRecordCreator(resultClass); @@ -193,7 +193,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend } /** - * @see net.forwardfire.vasc.core.AbstractVascBackend#isPageable() + * @see net.forwardfire.vasc.backend.AbstractVascBackend#isPageable() */ @Override public boolean isPageable() { @@ -204,7 +204,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend } /** - * @see net.forwardfire.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#fetchTotalExecuteSize(VascBackendState state) */ public long fetchTotalExecuteSize(VascBackendState state) { EntityManager em = getEntityManager(); @@ -359,7 +359,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend } /** - * @see net.forwardfire.vasc.core.AbstractVascBackend#isRecordMoveable() + * @see net.forwardfire.vasc.backend.AbstractVascBackend#isRecordMoveable() */ @Override public boolean isRecordMoveable() { @@ -423,7 +423,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend } /** - * @see net.forwardfire.vasc.core.VascBackend#isSearchable() + * @see net.forwardfire.vasc.backend.VascBackend#isSearchable() */ public boolean isSearchable() { if (query.getQueryParameterValue("text_search")==null) { diff --git a/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-backend-jpa.eld b/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-backend-jpa.eld new file mode 100644 index 0000000..2486703 --- /dev/null +++ b/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-backend-jpa.eld @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-namespaces.xml b/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-namespaces.xml new file mode 100644 index 0000000..815cd04 --- /dev/null +++ b/vasc-backend/vasc-backend-jpa/src/main/resources/META-INF/vasc/vasc-namespaces.xml @@ -0,0 +1,8 @@ + + + + + Vasc namespace for the jpa backend + + vasc-backend-jpa.eld + \ No newline at end of file diff --git a/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProvider.java b/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProvider.java new file mode 100644 index 0000000..7ae6d83 --- /dev/null +++ b/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProvider.java @@ -0,0 +1,35 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.ldap; + +import com.novell.ldap.LDAPConnection; + +/** + * + * @author Willem Cazander + * @version 1.0 Sep 4, 2008 + */ +public interface LdapConnectionProvider { + + public LDAPConnection getLdapConnection(); +} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProviderImpl.java b/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProviderImpl.java new file mode 100644 index 0000000..2b5d926 --- /dev/null +++ b/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProviderImpl.java @@ -0,0 +1,133 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.forwardfire.vasc.backend.ldap; + +import com.novell.ldap.LDAPConnection; + +/** + * + * @author Willem Cazander + * @version 1.0 Sep 4, 2008 + */ +public class LdapConnectionProviderImpl implements LdapConnectionProvider { + + private String ldapHost = "localhost"; + private int ldapPort = LDAPConnection.DEFAULT_PORT; + private int ldapVersion = LDAPConnection.LDAP_V3; + private String bindUser = null; + private String bindPass = null; + + /** + * @see net.forwardfire.vasc.backend.ldap.LdapConnectionProvider#getLdapConnection() + */ + public LDAPConnection getLdapConnection() { + try { + + // if ssl; + //Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); + //System.setProperty("javax.net.ssl.trustStore", "/tmp/somewhere/ldap.root.crt"); + //LDAPSocketFactory ssf = new LDAPJSSESecureSocketFactory(); + // Set the socket factory as the default for all future connections + //LDAPConnection.setSocketFactory(ssf); + + LDAPConnection lc = new LDAPConnection(); + lc.connect( ldapHost, ldapPort ); + if (bindUser!=null && bindPass!=null) { + lc.bind( ldapVersion, bindUser, bindPass.getBytes("UTF8") ); + } + return lc; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * @return the ldapHost + */ + public String getLdapHost() { + return ldapHost; + } + + /** + * @param ldapHost the ldapHost to set + */ + public void setLdapHost(String ldapHost) { + this.ldapHost = ldapHost; + } + + /** + * @return the ldapPort + */ + public int getLdapPort() { + return ldapPort; + } + + /** + * @param ldapPort the ldapPort to set + */ + public void setLdapPort(int ldapPort) { + this.ldapPort = ldapPort; + } + + /** + * @return the ldapVersion + */ + public int getLdapVersion() { + return ldapVersion; + } + + /** + * @param ldapVersion the ldapVersion to set + */ + public void setLdapVersion(int ldapVersion) { + this.ldapVersion = ldapVersion; + } + + /** + * @return the bindUser + */ + public String getBindUser() { + return bindUser; + } + + /** + * @param bindUser the bindUser to set + */ + public void setBindUser(String bindUser) { + this.bindUser = bindUser; + } + + + /** + * @return the bindPass + */ + public String getBindPass() { + return bindPass; + } + + /** + * @param bindPass the bindPass to set + */ + public void setBindPass(String bindPass) { + this.bindPass = bindPass; + } +} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapVascBackend.java b/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapVascBackend.java new file mode 100644 index 0000000..fd8da53 --- /dev/null +++ b/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapVascBackend.java @@ -0,0 +1,334 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.ldap; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import net.forwardfire.vasc.backend.AbstractVascBackend; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue; +import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; +import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; + + +import com.novell.ldap.LDAPAttribute; +import com.novell.ldap.LDAPAttributeSet; +import com.novell.ldap.LDAPConnection; +import com.novell.ldap.LDAPEntry; +import com.novell.ldap.LDAPModification; +import com.novell.ldap.LDAPSearchConstraints; +import com.novell.ldap.LDAPSearchResults; + +/** + * Provides backend for ldap. + * + * @author Willem Cazander + * @version 1.0 Sep 4, 2008 + */ +public class LdapVascBackend extends AbstractVascBackend { + + + private LdapConnectionProvider ldapConnectionProvider = null; + private String baseDN = null; + private String keyAttribute = null; + private String ldapFilter = null; + + + /** + * @return the ldapConnectionProvider + */ + public LdapConnectionProvider getLdapConnectionProvider() { + return ldapConnectionProvider; + } + + /** + * @param ldapConnectionProvider the ldapConnectionProvider to set + */ + public void setLdapConnectionProvider(LdapConnectionProvider ldapConnectionProvider) { + this.ldapConnectionProvider = ldapConnectionProvider; + } + + + + + /** + * @see net.forwardfire.vasc.backend.VascBackend#execute() + */ + public List execute(VascBackendState state) throws VascException { + LdapConnectionProvider prov = getLdapConnectionProvider(); + LDAPConnection connection = prov.getLdapConnection(); + List result = new ArrayList(50); + try { + + + LDAPSearchConstraints cons = new LDAPSearchConstraints(); + cons.setBatchSize( 0 ); + cons.setTimeLimit( 10000 ) ; + cons.setReferralFollowing(true); + connection.setConstraints(cons); + + int searchScope = LDAPConnection.SCOPE_ONE; + String searchBase = baseDN; + + //System.out.println("Reading object :" + searchBase + " with filter: " + ldapFilter); + LDAPSearchResults searchResults = connection.search( + searchBase, // object to read + searchScope, // scope - read single object + ldapFilter, // search filter + null, // return all attributes + false); // return attrs and values + + while (searchResults.hasMore()) { + LDAPEntry entry = searchResults.next(); + Map map = new HashMap(10); + + LDAPAttributeSet attributeSet = entry.getAttributeSet(); + Iterator i = attributeSet.iterator(); + while (i.hasNext()) { + LDAPAttribute attr = i.next(); + //System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue()); + String[] s = attr.getStringValueArray(); + if (s.length==1) { + map.put(attr.getName(), attr.getStringValue()); + } else { + List multiValue = new ArrayList(s.length); + for (String ss:s) { + multiValue.add(ss); + } + map.put(attr.getName(), multiValue ); + } + } + result.add(map); + } + } catch (Exception e) { + throw new VascException(e); + } finally { + if (connection!=null) { + connection.clone(); + } + } + return result; + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object) + */ + public Object merge(Object object) throws VascException { + LdapConnectionProvider prov = getLdapConnectionProvider(); + LDAPConnection connection = prov.getLdapConnection(); + try { + Map map = (Map)object; + String keyValue = (String)map.get(keyAttribute); + LDAPSearchConstraints cons = new LDAPSearchConstraints(); + cons.setBatchSize( 0 ); + cons.setTimeLimit( 10000 ) ; + cons.setReferralFollowing(true); + connection.setConstraints(cons); + + int searchScope = LDAPConnection.SCOPE_ONE; + String searchBase = baseDN; + String filter = "(&("+keyAttribute+"="+keyValue+"))"; + System.out.println("ldap filter: "+filter); + LDAPSearchResults searchResults = connection.search( + searchBase, // object to read + searchScope, // scope - read single object + filter, // search filter + null, // return all attributes + false); // return attrs and values + + if (searchResults.hasMore()==false) { + // no result to mod + return object; + } + LDAPEntry entry = searchResults.next(); + List mods = new ArrayList(20); + for (String key:map.keySet()) { + Object value = map.get(key); + LDAPAttribute attr = entry.getAttribute(key); + if (attr==null) { + LDAPModification mod = new LDAPModification(LDAPModification.ADD,new LDAPAttribute(key,(String)value)); + mods.add(mod); + continue; + } + String[] s = attr.getStringValueArray(); + if (s.length==1) { + String v = (String)value; + if (attr.getStringValue().equals(v)==false) { + LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,new LDAPAttribute(key,v)); + mods.add(mod); + } + map.put(attr.getName(), attr.getStringValue()); + } else { + List multiValue = new ArrayList(s.length); + for (String ss:s) { + multiValue.add(ss); + } + List v = null; + if (value instanceof String) { + v = new ArrayList(1); + v.add((String)value); + } else { + v = (List)value; + } + if (v.equals(multiValue)==false) { + LDAPAttribute a = new LDAPAttribute(key); + for (String vv:v) { + a.addValue(vv); + } + LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,a); + mods.add(mod); + } + } + } + + LDAPModification[] m = new LDAPModification[mods.size()]; + mods.toArray(m); + connection.modify(entry.getDN(), m); + return object; + } catch (Exception e) { + throw new VascException(e); + } finally { + if (connection!=null) { + connection.clone(); + } + } + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object) + */ + public void persist(Object object) throws VascException { + LdapConnectionProvider prov = getLdapConnectionProvider(); + LDAPConnection connection = prov.getLdapConnection(); + try { + LDAPEntry entry = new LDAPEntry(); + // entry.getAttributeSet(). + + connection.add(entry); + } catch (Exception e) { + throw new VascException(e); + } finally { + if (connection!=null) { + connection.clone(); + } + } + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object) + */ + public void delete(Object object) throws VascException { + LdapConnectionProvider prov = getLdapConnectionProvider(); + LDAPConnection connection = prov.getLdapConnection(); + try { + Map map = (Map)object; + String keyValue = (String)map.get(keyAttribute); + int searchScope = LDAPConnection.SCOPE_ONE; + String searchBase = baseDN; + String filter = "(&("+ldapFilter+")("+keyAttribute+"="+keyValue+"))"; + LDAPSearchResults searchResults = connection.search( + searchBase, // object to read + searchScope, // scope - read single object + filter, // search filter + null, // return all attributes + false); // return attrs and values + + if (searchResults.hasMore()==false) { + // no result to mod + return; + } + LDAPEntry entry = searchResults.next(); + connection.delete(entry.getDN()); + } catch (Exception e) { + throw new VascException(e); + } finally { + if (connection!=null) { + connection.clone(); + } + } + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) + */ + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return new MapVascEntryRecordCreator(); + } + + /** + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) + */ + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return new MapVascEntryFieldValue(); + } + + /** + * @return the baseDN + */ + public String getBaseDN() { + return baseDN; + } + + /** + * @param baseDN the baseDN to set + */ + public void setBaseDN(String baseDN) { + this.baseDN = baseDN; + } + + /** + * @return the keyAttribute + */ + public String getKeyAttribute() { + return keyAttribute; + } + + /** + * @param keyAttribute the keyAttribute to set + */ + public void setKeyAttribute(String keyAttribute) { + this.keyAttribute = keyAttribute; + } + + /** + * @return the ldapFilter + */ + public String getLdapFilter() { + return ldapFilter; + } + + /** + * @param ldapFilter the ldapFilter to set + */ + public void setLdapFilter(String ldapFilter) { + this.ldapFilter = ldapFilter; + } +} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-ldap/src/main/resources/META-INF/vasc/vasc-backend-ldap.eld b/vasc-backend/vasc-backend-ldap/src/main/resources/META-INF/vasc/vasc-backend-ldap.eld new file mode 100644 index 0000000..e5cb687 --- /dev/null +++ b/vasc-backend/vasc-backend-ldap/src/main/resources/META-INF/vasc/vasc-backend-ldap.eld @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/vasc-backend/vasc-backend-ldap/src/main/resources/META-INF/vasc/vasc-namespaces.xml b/vasc-backend/vasc-backend-ldap/src/main/resources/META-INF/vasc/vasc-namespaces.xml new file mode 100644 index 0000000..427106e --- /dev/null +++ b/vasc-backend/vasc-backend-ldap/src/main/resources/META-INF/vasc/vasc-namespaces.xml @@ -0,0 +1,8 @@ + + + + + Vasc namespace for the ldap backend + + vasc-backend-ldap.eld + \ No newline at end of file diff --git a/vasc-backend/vasc-backend-metamodel/.classpath b/vasc-backend/vasc-backend-metamodel/.classpath new file mode 100644 index 0000000..3c96d64 --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/vasc-backend/vasc-backend-metamodel/.project b/vasc-backend/vasc-backend-metamodel/.project new file mode 100644 index 0000000..24e2053 --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/.project @@ -0,0 +1,23 @@ + + + vasc-backend-metamodel + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.core.resources.prefs b/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..93e57cf --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +#Sat Dec 31 05:51:03 CET 2011 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.jdt.core.prefs b/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..d2d382f --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,6 @@ +#Sat Dec 31 05:51:03 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.m2e.core.prefs b/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..1611f69 --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Sat Dec 31 05:51:03 CET 2011 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/vasc-backend/vasc-backend-metamodel/pom.xml b/vasc-backend/vasc-backend-metamodel/pom.xml new file mode 100644 index 0000000..009c8fb --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + vasc-backend + net.forwardfire.vasc + 0.3.5-SNAPSHOT + .. + + vasc-backend-metamodel + vasc-backend-metamodel + vasc-backend-metamodel + + + net.forwardfire.vasc + vasc-core + ${project.version} + + + org.eobjects.metamodel + MetaModel-core + 2.1 + + + \ No newline at end of file diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java new file mode 100644 index 0000000..ce73785 --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java @@ -0,0 +1,97 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.metamodel; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eobjects.metamodel.DataContext; +import org.eobjects.metamodel.data.DataSet; +import org.eobjects.metamodel.data.Row; +import org.eobjects.metamodel.query.Query; +import org.eobjects.metamodel.query.SelectItem; +import org.eobjects.metamodel.schema.Schema; +import org.eobjects.metamodel.schema.Table; + +import net.forwardfire.vasc.backend.AbstractVascBackend; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue; +import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; +import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; + +/** + * Provides backend for metamodel. + * + * @author Willem Cazander + * @version 1.0 Dec 31, 2011 + */ +public class MetaModelVascBackend extends AbstractVascBackend { + + private DataContext dataContext = null; + private String table = null; + + public List execute(VascBackendState state) throws VascException { + Schema schema = dataContext.getDefaultSchema(); + Table t = schema.getTableByName(table); + //dataContext.query().from("").select("").where(""). + Query q = dataContext.query().from(t).select(t.getColumns()).toQuery(); + DataSet ds = dataContext.executeQuery(q); + List result = new ArrayList(50); + while (ds.next()) { + Row row = ds.getRow(); + SelectItem[] cols = row.getSelectItems(); + Map map = new HashMap(cols.length); + for (SelectItem col:cols) { + Object value = row.getValue(col); + map.put(col.getColumn().getName(), value); + } + result.add(map); + } + + return result; + } + + public void persist(Object object) throws VascException { + } + + public Object merge(Object object) throws VascException { + return object; + } + + public void delete(Object object) throws VascException { + } + + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return new MapVascEntryFieldValue(); + } + + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return new MapVascEntryRecordCreator(); + } +} diff --git a/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbConnectionProvider.java b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbConnectionProvider.java new file mode 100644 index 0000000..a2a878c --- /dev/null +++ b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbConnectionProvider.java @@ -0,0 +1,40 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.mongodb; + +import com.mongodb.DB; + +/** + * Provides an mongodb DB connection to the backend. + * + * @author Willem Cazander + * @version 1.0 Dec 30, 2011 + */ +public interface MongodbConnectionProvider { + + /** + * Returns a DB connection. + * @return An DB connection to mongodb + */ + public DB getMongodbConnection(); +} diff --git a/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbConnectionProviderImpl.java b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbConnectionProviderImpl.java new file mode 100644 index 0000000..11849a5 --- /dev/null +++ b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbConnectionProviderImpl.java @@ -0,0 +1,163 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.mongodb; + +import java.net.UnknownHostException; +import java.util.logging.Logger; + +import com.mongodb.DB; +import com.mongodb.Mongo; +import com.mongodb.MongoOptions; +import com.mongodb.ServerAddress; + +/** + * Provides an mongodb DB connection to the backend. + * + * @author Willem Cazander + * @version 1.0 Dec 30, 2011 + */ +public class MongodbConnectionProviderImpl implements MongodbConnectionProvider { + + private Logger logger = Logger.getLogger(MongodbConnectionProviderImpl.class.getName()); + private String hostname = "localhost"; + private int port = 27017; + private String database = null; + private String username = null; + private String password = null; + private boolean readonly = false; + + protected static Mongo mongo = null; + protected static DB db = null; + + public DB getMongodbConnection() { + if (db!=null) { + return db; + } + synchronized (this) { + ServerAddress server; + try { + server = new ServerAddress(hostname,port); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + MongoOptions options = new MongoOptions(); + mongo = new Mongo(server,options); + db = mongo.getDB(database); + if (username!=null && password!=null) { + boolean auth = db.authenticate(username, password.toCharArray()); + if (auth==false) { + throw new RuntimeException("Could not auth to db: "+database+" with username: "+username); + } + } + if (readonly) { + db.setReadOnly(true); + } + logger.info("Connection to: "+db.getName()); + } + return db; + } + + /** + * @return the hostname + */ + public String getHostname() { + return hostname; + } + + /** + * @param hostname the hostname to set + */ + public void setHostname(String hostname) { + this.hostname = hostname; + } + + /** + * @return the port + */ + public int getPort() { + return port; + } + + /** + * @param port the port to set + */ + public void setPort(int port) { + this.port = port; + } + + /** + * @return the database + */ + public String getDatabase() { + return database; + } + + /** + * @param database the database to set + */ + public void setDatabase(String database) { + this.database = database; + } + + /** + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * @param username the username to set + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + + /** + * @return the readonly + */ + public boolean isReadonly() { + return readonly; + } + + /** + * @param readonly the readonly to set + */ + public void setReadonly(boolean readonly) { + this.readonly = readonly; + } +} diff --git a/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascBackend.java b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascBackend.java new file mode 100644 index 0000000..005a603 --- /dev/null +++ b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascBackend.java @@ -0,0 +1,151 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.mongodb; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +import net.forwardfire.vasc.backend.AbstractVascBackend; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; +import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; + + +import com.mongodb.DB; +import com.mongodb.DBCollection; +import com.mongodb.DBCursor; +import com.mongodb.DBObject; +import com.mongodb.BasicDBObject; +import com.mongodb.WriteConcern; +import com.mongodb.WriteResult; + +/** + * Provides backend for mongodb. + * + * @author Willem Cazander + * @version 1.0 Dec 30, 2011 + */ +public class MongodbVascBackend extends AbstractVascBackend { + + private Logger logger = null; + private MongodbConnectionProvider connectionProvider = null; + private String collection = null; + private DB database = null; + + public MongodbVascBackend() { + logger = Logger.getLogger(MongodbVascBackend.class.getName()); + } + + public List execute(VascBackendState state) throws VascException { + DBCollection coll = getDBCollection(); + DBObject query = new BasicDBObject(); + for (String key:state.getDataParameterKeys()) { + Object value = state.getDataParameter(key); + query.put(key, value); + logger.finer("Setting query parameter key: '"+key+"' value: '"+value+"'"); + } + DBCursor cur = coll.find(query); + //cur.count(); + List result = new ArrayList(cur.count()); + while (cur.hasNext()) { + DBObject row = cur.next(); + result.add(row); + } + return result; + } + + public void persist(Object object) throws VascException { + DBCollection coll = getDBCollection(); + coll.insert((DBObject)object); + } + + public Object merge(Object object) throws VascException { + DBCollection coll = getDBCollection(); + DBObject row = (DBObject)object; + DBObject query = new BasicDBObject(); + query.put("_id",row.get("_id")); + WriteResult wr = coll.update(query,row,false,false,WriteConcern.SAFE); + logger.info("WriteResult: "+wr); + return object; + } + + public void delete(Object object) throws VascException { + DBCollection coll = getDBCollection(); + DBObject query = new BasicDBObject(); + query.put("_id",((DBObject)object).get("_id")); + coll.remove(query); // remove by _id + } + + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return new MongodbVascEntryFieldValue(); + } + + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return new MongodbVascEntryRecordCreator(); + } + + private DBCollection getDBCollection() { + if (database!=null) { + return database.getCollection(collection); + } + if (connectionProvider==null) { + throw new RuntimeException("Can't get DBCollection from null connectionProvider."); + } + synchronized (connectionProvider) { + database = connectionProvider.getMongodbConnection(); + } + return database.getCollection(collection); + } + + /** + * @return the connectionProvider + */ + public MongodbConnectionProvider getConnectionProvider() { + return connectionProvider; + } + + /** + * @param connectionProvider the connectionProvider to set + */ + public void setConnectionProvider(MongodbConnectionProvider connectionProvider) { + this.connectionProvider = connectionProvider; + } + + /** + * @return the collection + */ + public String getCollection() { + return collection; + } + + /** + * @param collection the collection to set + */ + public void setCollection(String collection) { + this.collection = collection; + } +} diff --git a/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascEntryFieldValue.java b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascEntryFieldValue.java new file mode 100644 index 0000000..a86b63d --- /dev/null +++ b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascEntryFieldValue.java @@ -0,0 +1,59 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.backend.mongodb; + +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; + + +import com.mongodb.BasicDBObject; + +/** + * Provides a mongodb field entry knowlege. + * + * @author Willem Cazander + * @version 1.0 Dec 30, 2011 + */ +public class MongodbVascEntryFieldValue implements VascEntryFieldValue { + + private static final long serialVersionUID = -7371273796529818557L; + + public Object getValue(VascEntryField field, Object record) throws VascException { + BasicDBObject row = (BasicDBObject)record; + Object r = row.get(field.getBackendName()); + if (r==null) { + return ""; // create new value, TODO + } + return r; + } + + public String getDisplayValue(VascEntryField field, Object record) throws VascException { + return ""+getValue(field,record); // not supported TODO + } + + public void setValue(VascEntryField field, Object record, Object value) throws VascException { + BasicDBObject row = (BasicDBObject)record; + row.put(field.getBackendName(), value); + } +} diff --git a/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascEntryRecordCreator.java b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascEntryRecordCreator.java new file mode 100644 index 0000000..b7bac6d --- /dev/null +++ b/vasc-backend/vasc-backend-mongodb/src/main/java/net/forwardfire/vasc/backend/mongodb/MongodbVascEntryRecordCreator.java @@ -0,0 +1,49 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +package net.forwardfire.vasc.backend.mongodb; + +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; + + +import com.mongodb.BasicDBObject; + +/** + * Provides a mongodb object to create a new row. + * + * @author Willem Cazander + * @version 1.0 Dec 30, 2011 + */ +public class MongodbVascEntryRecordCreator implements VascEntryRecordCreator { + + private static final long serialVersionUID = -9213830731796787384L; + + public Object newRecord(VascEntry entry) throws Exception { + return new BasicDBObject(); + } + + public Class getObjectClass() { + return BasicDBObject.class; + } +} diff --git a/vasc-backend/vasc-backend-mongodb/src/main/resources/META-INF/vasc/vasc-backend-mongodb.eld b/vasc-backend/vasc-backend-mongodb/src/main/resources/META-INF/vasc/vasc-backend-mongodb.eld new file mode 100644 index 0000000..60386c0 --- /dev/null +++ b/vasc-backend/vasc-backend-mongodb/src/main/resources/META-INF/vasc/vasc-backend-mongodb.eld @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vasc-backend/vasc-backend-mongodb/src/main/resources/META-INF/vasc/vasc-namespaces.xml b/vasc-backend/vasc-backend-mongodb/src/main/resources/META-INF/vasc/vasc-namespaces.xml new file mode 100644 index 0000000..b8c8f56 --- /dev/null +++ b/vasc-backend/vasc-backend-mongodb/src/main/resources/META-INF/vasc/vasc-namespaces.xml @@ -0,0 +1,8 @@ + + + + + Vasc namespace for the mongodb backend + + vasc-backend-mongodb.eld + \ No newline at end of file diff --git a/vasc-core/.project b/vasc-core/.project index d3b7808..2080da5 100644 --- a/vasc-core/.project +++ b/vasc-core/.project @@ -16,12 +16,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackend.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackend.java similarity index 71% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackend.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackend.java index e062a62..9f7dc74 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackend.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackend.java @@ -20,10 +20,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend; import java.util.Map; +import net.forwardfire.vasc.core.VascException; + /** * @@ -35,14 +37,14 @@ abstract public class AbstractVascBackend implements VascBackend { private String id = null; /** - * @see net.forwardfire.vasc.core.VascBackend#getId() + * @see net.forwardfire.vasc.backend.VascBackend#getId() */ public String getId() { return id; } /** - * @see net.forwardfire.vasc.core.VascBackend#setId(java.lang.String) + * @see net.forwardfire.vasc.backend.VascBackend#setId(java.lang.String) */ public void setId(String id) { if (id==null) { @@ -52,77 +54,77 @@ abstract public class AbstractVascBackend implements VascBackend { } /** - * @see net.forwardfire.vasc.core.VascBackend#isPageable() + * @see net.forwardfire.vasc.backend.VascBackend#isPageable() */ public boolean isPageable() { return false; } /** - * @see net.forwardfire.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#fetchTotalExecuteSize(VascBackendState state) */ public long fetchTotalExecuteSize(VascBackendState state) { return 0; } /** - * @see net.forwardfire.vasc.core.VascBackend#isSearchable() + * @see net.forwardfire.vasc.backend.VascBackend#isSearchable() */ public boolean isSearchable() { return false; } /** - * @see net.forwardfire.vasc.core.VascBackend#isSortable() + * @see net.forwardfire.vasc.backend.VascBackend#isSortable() */ public boolean isSortable() { return false; } /** - * @see net.forwardfire.vasc.core.VascBackend#isRecordMoveable() + * @see net.forwardfire.vasc.backend.VascBackend#isRecordMoveable() */ public boolean isRecordMoveable() { return false; } /** - * @see net.forwardfire.vasc.core.VascBackend#doRecordMoveDownById(java.lang.Object) + * @see net.forwardfire.vasc.backend.VascBackend#doRecordMoveDownById(java.lang.Object) */ public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException { return 0l; } /** - * @see net.forwardfire.vasc.core.VascBackend#doRecordMoveUpById(java.lang.Object) + * @see net.forwardfire.vasc.backend.VascBackend#doRecordMoveUpById(java.lang.Object) */ public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException { return 0l; } /** - * @see net.forwardfire.vasc.core.VascBackend#executePageSummary() + * @see net.forwardfire.vasc.backend.VascBackend#executePageSummary() */ public Map executePageSummary() { return null; } /** - * @see net.forwardfire.vasc.core.VascBackend#executeTotalSummary() + * @see net.forwardfire.vasc.backend.VascBackend#executeTotalSummary() */ public Map executeTotalSummary() { return null; } /** - * @see net.forwardfire.vasc.core.VascBackend#isPageSummary() + * @see net.forwardfire.vasc.backend.VascBackend#isPageSummary() */ public boolean isPageSummary() { return false; } /** - * @see net.forwardfire.vasc.core.VascBackend#isTotalSummary() + * @see net.forwardfire.vasc.backend.VascBackend#isTotalSummary() */ public boolean isTotalSummary() { return false; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackendState.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackendState.java similarity index 81% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackendState.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackendState.java index 19ad633..451b207 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackendState.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackendState.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend; import java.util.HashMap; import java.util.Map; @@ -60,70 +60,70 @@ abstract public class AbstractVascBackendState implements VascBackendState { } /** - * @see net.forwardfire.vasc.core.VascBackend#getPageIndex() + * @see net.forwardfire.vasc.backend.VascBackend#getPageIndex() */ public int getPageIndex() { return pageIndex; } /** - * @see net.forwardfire.vasc.core.VascBackend#setPageIndex(int) + * @see net.forwardfire.vasc.backend.VascBackend#setPageIndex(int) */ public void setPageIndex(int pageIndex) { this.pageIndex=pageIndex; } /** - * @see net.forwardfire.vasc.core.VascBackend#getPageSize() + * @see net.forwardfire.vasc.backend.VascBackend#getPageSize() */ public int getPageSize() { return pageSize; } /** - * @see net.forwardfire.vasc.core.VascBackend#setPageSize(int) + * @see net.forwardfire.vasc.backend.VascBackend#setPageSize(int) */ public void setPageSize(int pageSize) { this.pageSize=pageSize; } /** - * @see net.forwardfire.vasc.core.VascBackend#getSearchString() + * @see net.forwardfire.vasc.backend.VascBackend#getSearchString() */ public String getSearchString() { return searchString; } /** - * @see net.forwardfire.vasc.core.VascBackend#setSearchString(java.lang.String) + * @see net.forwardfire.vasc.backend.VascBackend#setSearchString(java.lang.String) */ public void setSearchString(String searchString) { this.searchString=searchString; } /** - * @see net.forwardfire.vasc.core.VascBackend#isSortAscending() + * @see net.forwardfire.vasc.backend.VascBackend#isSortAscending() */ public boolean isSortAscending() { return ascending; } /** - * @see net.forwardfire.vasc.core.VascBackend#setSortAscending(boolean) + * @see net.forwardfire.vasc.backend.VascBackend#setSortAscending(boolean) */ public void setSortAscending(boolean ascending) { this.ascending=ascending; } /** - * @see net.forwardfire.vasc.core.VascBackend#getSortField() + * @see net.forwardfire.vasc.backend.VascBackend#getSortField() */ public String getSortField() { return sortField; } /** - * @see net.forwardfire.vasc.core.VascBackend#setSortField(java.lang.String) + * @see net.forwardfire.vasc.backend.VascBackend#setSortField(java.lang.String) */ public void setSortField(String sortField) { this.sortField=sortField; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackend.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackend.java similarity index 95% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackend.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackend.java index 287fd0a..b423bf6 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackend.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackend.java @@ -20,11 +20,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend; import java.util.List; import java.util.Map; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendController.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendController.java similarity index 97% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendController.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendController.java index 641ae8c..2c694b8 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendController.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend; /** diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendControllerLocal.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendControllerLocal.java similarity index 97% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendControllerLocal.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendControllerLocal.java index 346bd0f..0cb6aa5 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendControllerLocal.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendControllerLocal.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend; /** diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendFilter.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendFilter.java similarity index 95% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendFilter.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendFilter.java index 47c2a05..101b683 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendFilter.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendFilter.java @@ -20,7 +20,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend; + +import net.forwardfire.vasc.core.VascEntry; /** diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendPageNumber.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendPageNumber.java similarity index 98% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendPageNumber.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendPageNumber.java index f3397c4..1e5a431 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendPageNumber.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendPageNumber.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend; import java.io.Serializable; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendState.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendState.java similarity index 98% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendState.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendState.java index dcf67d8..325a6be 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascBackendState.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendState.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend; import java.io.Serializable; import java.util.Set; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backends/BeanVascEntryFieldValue.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/data/BeanVascEntryFieldValue.java similarity index 98% rename from vasc-core/src/main/java/net/forwardfire/vasc/backends/BeanVascEntryFieldValue.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/data/BeanVascEntryFieldValue.java index 4c78c8a..6ddeab9 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backends/BeanVascEntryFieldValue.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/data/BeanVascEntryFieldValue.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.backends; +package net.forwardfire.vasc.backend.data; import net.forwardfire.vasc.core.VascEntryField; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backends/BeanVascEntryRecordCreator.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/data/BeanVascEntryRecordCreator.java similarity index 97% rename from vasc-core/src/main/java/net/forwardfire/vasc/backends/BeanVascEntryRecordCreator.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/data/BeanVascEntryRecordCreator.java index e75347d..ad647c5 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backends/BeanVascEntryRecordCreator.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/data/BeanVascEntryRecordCreator.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.backends; +package net.forwardfire.vasc.backend.data; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backends/MapVascEntryFieldValue.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/data/MapVascEntryFieldValue.java similarity index 82% rename from vasc-core/src/main/java/net/forwardfire/vasc/backends/MapVascEntryFieldValue.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/data/MapVascEntryFieldValue.java index 8676c63..fbd5b0e 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backends/MapVascEntryFieldValue.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/data/MapVascEntryFieldValue.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.backends; +package net.forwardfire.vasc.backend.data; import java.util.Map; @@ -43,19 +43,29 @@ public class MapVascEntryFieldValue implements VascEntryFieldValue { */ @SuppressWarnings("unchecked") public Object getValue(VascEntryField field, Object record) throws VascException { - Map map = (Map)record; - Object r = map.get(field.getBackendName()); - if (r==null) { - return ""; // create new value, ldap does not return data for field that an user does not have, but other do,... + if (field==null) { + throw new NullPointerException("Can't get value of null field."); } - return r; + if (field.getBackendName()==null) { + throw new NullPointerException("Can't get value of null backendName field."); + } + if (record==null) { + throw new NullPointerException("Can't get value of null object."); + } + Map map = (Map)record; + Object fieldValue = map.get(field.getBackendName()); + return fieldValue; } /** * @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#getDisplayValue(net.forwardfire.vasc.core.VascEntryField, java.lang.Object) */ public String getDisplayValue(VascEntryField field, Object record) throws VascException { - return ""+getValue(field,record); // not supported (this)ldap is already fully string based. + Object fieldValue = getValue(field,record); + if (fieldValue==null) { + fieldValue = ""; + } + return fieldValue.toString(); } /** diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backends/MapVascEntryRecordCreator.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/data/MapVascEntryRecordCreator.java similarity index 97% rename from vasc-core/src/main/java/net/forwardfire/vasc/backends/MapVascEntryRecordCreator.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/data/MapVascEntryRecordCreator.java index 037f695..69fd620 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backends/MapVascEntryRecordCreator.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/data/MapVascEntryRecordCreator.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.backends; +package net.forwardfire.vasc.backend.data; import java.util.HashMap; import java.util.Map; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackendProxy.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/AbstractVascBackendProxy.java similarity index 71% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackendProxy.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/AbstractVascBackendProxy.java index ace5eba..b451159 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascBackendProxy.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/AbstractVascBackendProxy.java @@ -20,16 +20,22 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.backend.proxy; import java.util.List; import java.util.Map; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; /** + * AbstractVascBackendProxy to implement missing features of the backend. * * @author Willem Cazander * @version 1.0 Apr 1, 2009 @@ -46,14 +52,14 @@ abstract public class AbstractVascBackendProxy implements VascBackend { } /** - * @see net.forwardfire.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#fetchTotalExecuteSize(VascBackendState state) */ public long fetchTotalExecuteSize(VascBackendState state) { return backend.fetchTotalExecuteSize(state); } /** - * @see net.forwardfire.vasc.core.VascBackend#isSortable() + * @see net.forwardfire.vasc.backend.VascBackend#isSortable() */ public boolean isSortable() { return backend.isSortable(); @@ -61,70 +67,70 @@ abstract public class AbstractVascBackendProxy implements VascBackend { /** * @throws Exception - * @see net.forwardfire.vasc.core.VascBackend#execute(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) */ public List execute(VascBackendState state) throws VascException { return backend.execute(state); } /** - * @see net.forwardfire.vasc.core.VascBackend#delete(java.lang.Object) + * @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object) */ public void delete(Object object) throws VascException { backend.delete(object); } /** - * @see net.forwardfire.vasc.core.VascBackend#isPageable() + * @see net.forwardfire.vasc.backend.VascBackend#isPageable() */ public boolean isPageable() { return backend.isPageable(); } /** - * @see net.forwardfire.vasc.core.VascBackend#isSearchable() + * @see net.forwardfire.vasc.backend.VascBackend#isSearchable() */ public boolean isSearchable() { return backend.isSearchable(); } /** - * @see net.forwardfire.vasc.core.VascBackend#merge(java.lang.Object) + * @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object) */ public Object merge(Object object) throws VascException { return backend.merge(object); } /** - * @see net.forwardfire.vasc.core.VascBackend#persist(java.lang.Object) + * @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object) */ public void persist(Object object) throws VascException { backend.persist(object); } /** - * @see net.forwardfire.vasc.core.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { return backend.provideVascEntryFieldValue(field); } /** - * @see net.forwardfire.vasc.core.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) + * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { return backend.provideVascEntryRecordCreator(vascEntry); } /** - * @see net.forwardfire.vasc.core.VascBackend#getId() + * @see net.forwardfire.vasc.backend.VascBackend#getId() */ public String getId() { return backend.getId(); } /** - * @see net.forwardfire.vasc.core.VascBackend#setId(java.lang.String) + * @see net.forwardfire.vasc.backend.VascBackend#setId(java.lang.String) */ public void setId(String id) { backend.setId(id); @@ -145,35 +151,35 @@ abstract public class AbstractVascBackendProxy implements VascBackend { } /** - * @see net.forwardfire.vasc.core.VascBackend#isRecordMoveable() + * @see net.forwardfire.vasc.backend.VascBackend#isRecordMoveable() */ public boolean isRecordMoveable() { return backend.isRecordMoveable(); } /** - * @see net.forwardfire.vasc.core.VascBackend#executePageSummary() + * @see net.forwardfire.vasc.backend.VascBackend#executePageSummary() */ public Map executePageSummary() { return backend.executePageSummary(); } /** - * @see net.forwardfire.vasc.core.VascBackend#executeTotalSummary() + * @see net.forwardfire.vasc.backend.VascBackend#executeTotalSummary() */ public Map executeTotalSummary() { return backend.executeTotalSummary(); } /** - * @see net.forwardfire.vasc.core.VascBackend#isPageSummary() + * @see net.forwardfire.vasc.backend.VascBackend#isPageSummary() */ public boolean isPageSummary() { return backend.isPageSummary(); } /** - * @see net.forwardfire.vasc.core.VascBackend#isTotalSummary() + * @see net.forwardfire.vasc.backend.VascBackend#isTotalSummary() */ public boolean isTotalSummary() { return backend.isTotalSummary(); diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyCache.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyCache.java similarity index 91% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyCache.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyCache.java index fb5b63d..d5edb4a 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyCache.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyCache.java @@ -20,15 +20,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.impl; +package net.forwardfire.vasc.backend.proxy; import java.util.HashMap; import java.util.List; import java.util.Map; -import net.forwardfire.vasc.core.AbstractVascBackendProxy; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascException; @@ -77,7 +76,7 @@ public class VascBackendProxyCache extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.VascBackend#execute(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) */ @Override public List execute(VascBackendState state) throws VascException { diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyEventExecutor.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyEventExecutor.java similarity index 83% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyEventExecutor.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyEventExecutor.java index 8189609..a55843d 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyEventExecutor.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyEventExecutor.java @@ -20,14 +20,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.impl; +package net.forwardfire.vasc.backend.proxy; import java.util.ArrayList; import java.util.List; -import net.forwardfire.vasc.core.AbstractVascBackendProxy; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.entry.VascEntryBackendEventListener; @@ -92,7 +91,7 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#delete(java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#delete(java.lang.Object) */ @Override public void delete(Object object) throws VascException { @@ -102,7 +101,7 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#doRecordMoveDownById(net.forwardfire.vasc.core.VascBackendState, java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveDownById(net.forwardfire.vasc.backend.VascBackendState, java.lang.Object) */ @Override public long doRecordMoveDownById(VascBackendState state, Object primaryId) throws VascException { @@ -113,7 +112,7 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#doRecordMoveUpById(net.forwardfire.vasc.core.VascBackendState, java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveUpById(net.forwardfire.vasc.backend.VascBackendState, java.lang.Object) */ @Override public long doRecordMoveUpById(VascBackendState state, Object primaryId) throws VascException { @@ -124,7 +123,7 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#execute(net.forwardfire.vasc.core.VascBackendState) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#execute(net.forwardfire.vasc.backend.VascBackendState) */ @Override public List execute(VascBackendState state) throws VascException { @@ -135,7 +134,7 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#fetchTotalExecuteSize(net.forwardfire.vasc.core.VascBackendState) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#fetchTotalExecuteSize(net.forwardfire.vasc.backend.VascBackendState) */ @Override public long fetchTotalExecuteSize(VascBackendState state) { @@ -146,7 +145,7 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#merge(java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#merge(java.lang.Object) */ @Override public Object merge(Object object) throws VascException { @@ -157,7 +156,7 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#persist(java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#persist(java.lang.Object) */ @Override public void persist(Object object) throws VascException { diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyFilter.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyFilter.java similarity index 88% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyFilter.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyFilter.java index e8e7327..8e81c62 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyFilter.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyFilter.java @@ -20,15 +20,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.impl; +package net.forwardfire.vasc.backend.proxy; import java.util.ArrayList; import java.util.List; -import net.forwardfire.vasc.core.AbstractVascBackendProxy; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendFilter; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendFilter; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascException; @@ -51,7 +50,7 @@ public class VascBackendProxyFilter extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.VascBackend#execute(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) */ @Override public List execute(VascBackendState state) throws VascException { diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyPaged.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyPaged.java similarity index 88% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyPaged.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyPaged.java index 054d23a..a93aef7 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyPaged.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyPaged.java @@ -20,14 +20,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.impl; +package net.forwardfire.vasc.backend.proxy; import java.util.ArrayList; import java.util.List; -import net.forwardfire.vasc.core.AbstractVascBackendProxy; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascException; @@ -48,7 +47,7 @@ public class VascBackendProxyPaged extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.VascBackend#isPageable() + * @see net.forwardfire.vasc.backend.VascBackend#isPageable() */ @Override public boolean isPageable() { @@ -56,7 +55,7 @@ public class VascBackendProxyPaged extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.VascBackend#execute(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) */ @Override public List execute(VascBackendState state) throws VascException { diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxySearch.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySearch.java similarity index 80% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxySearch.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySearch.java index f2f06cb..308efb8 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxySearch.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySearch.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.impl; +package net.forwardfire.vasc.backend.proxy; import java.lang.reflect.Method; import java.util.ArrayList; @@ -29,11 +29,12 @@ import java.util.List; import java.util.Map; import java.util.Set; -import net.forwardfire.vasc.core.AbstractVascBackendProxy; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; @@ -46,13 +47,15 @@ import net.forwardfire.vasc.core.VascException; public class VascBackendProxySearch extends AbstractVascBackendProxy { private long records = 0; + private VascEntry entry = null; public VascBackendProxySearch(VascBackend backend,VascEntry entry) { super(backend); + this.entry=entry; } /** - * @see net.forwardfire.vasc.core.VascBackend#isSearchable() + * @see net.forwardfire.vasc.backend.VascBackend#isSearchable() */ @Override public boolean isSearchable() { @@ -60,7 +63,7 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.VascBackend#execute(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) */ @Override public List execute(VascBackendState state) throws VascException { @@ -75,7 +78,18 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy { } String searchString = state.getSearchString().toLowerCase(); List search = new ArrayList(result.size()/4); - for (Object o:result) { + for (Object record:result) { + for (VascEntryField field:entry.getVascEntryFields()) { + VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field); + Object value = fieldValue.getValue(field, record); + String r = value.toString().toLowerCase(); + if (r.contains(searchString)) { + search.add(record); + break; + } + } + + /* for (Method method:o.getClass().getMethods()) { if (method.getName().startsWith("get")==false) { //a bit durty continue; @@ -110,6 +124,7 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy { break; } } + */ } records = search.size(); return search; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxySort.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySort.java similarity index 93% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxySort.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySort.java index 908c243..fdfe839 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxySort.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySort.java @@ -20,15 +20,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.impl; +package net.forwardfire.vasc.backend.proxy; import java.util.Collections; import java.util.Comparator; import java.util.List; -import net.forwardfire.vasc.core.AbstractVascBackendProxy; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; @@ -55,7 +54,7 @@ public class VascBackendProxySort extends AbstractVascBackendProxy { // sort stuff /** - * @see net.forwardfire.vasc.core.VascBackend#execute(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) */ @SuppressWarnings("unchecked") @Override diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyTimerLogger.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyTimerLogger.java similarity index 84% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyTimerLogger.java rename to vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyTimerLogger.java index 76ad099..2c2232a 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/VascBackendProxyTimerLogger.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxyTimerLogger.java @@ -20,15 +20,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.impl; +package net.forwardfire.vasc.backend.proxy; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import net.forwardfire.vasc.core.AbstractVascBackendProxy; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascException; @@ -50,7 +49,7 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.VascBackend#execute(VascBackendState state) + * @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state) */ @Override public List execute(VascBackendState state) throws VascException { @@ -75,7 +74,7 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#doRecordMoveDownById(net.forwardfire.vasc.core.VascBackendState, java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveDownById(net.forwardfire.vasc.backend.VascBackendState, java.lang.Object) */ @Override public long doRecordMoveDownById(VascBackendState state, Object primaryId) throws VascException { @@ -89,7 +88,7 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#doRecordMoveUpById(net.forwardfire.vasc.core.VascBackendState, java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveUpById(net.forwardfire.vasc.backend.VascBackendState, java.lang.Object) */ @Override public long doRecordMoveUpById(VascBackendState state, Object primaryId) throws VascException { @@ -103,7 +102,7 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#delete(java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#delete(java.lang.Object) */ @Override public void delete(Object object) throws VascException { @@ -117,7 +116,7 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#merge(java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#merge(java.lang.Object) */ @Override public Object merge(Object object) throws VascException { @@ -131,7 +130,7 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy { } /** - * @see net.forwardfire.vasc.core.AbstractVascBackendProxy#persist(java.lang.Object) + * @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#persist(java.lang.Object) */ @Override public void persist(Object object) throws VascException { diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryFieldType.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryFieldType.java index 9e5db13..8f6e3e5 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryFieldType.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryFieldType.java @@ -141,8 +141,11 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { /** * @see net.forwardfire.vasc.core.VascEntryFieldType#setAutoDetectClass(java.lang.Class) */ - public void setAutoDetectClass(Class autoDetectClass) { - this.autoDetectClass=autoDetectClass; + public void setAutoDetectClass(Class classObject) { + if (classObject==null) { + throw new NullPointerException("Can't add null classObject to fieldtype."); + } + autoDetectClass=classObject; } /** diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryState.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryState.java index 8b81fe6..0b364da 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryState.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryState.java @@ -27,6 +27,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; + /** * Holds all default state values * diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascController.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascController.java index e376ed0..cf0ed59 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascController.java @@ -22,6 +22,8 @@ package net.forwardfire.vasc.core; +import net.forwardfire.vasc.backend.VascBackendController; + /** * Resolvs all the resolvers. diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntry.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntry.java index c3c2920..c44774f 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntry.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntry.java @@ -25,10 +25,12 @@ package net.forwardfire.vasc.core; import java.io.Serializable; import java.util.List; +import net.forwardfire.vasc.backend.VascBackendFilter; import net.forwardfire.vasc.core.actions.ColumnVascAction; import net.forwardfire.vasc.core.actions.GlobalVascAction; import net.forwardfire.vasc.core.actions.RowVascAction; import net.forwardfire.vasc.core.entry.VascEntryFieldEventChannel; +import net.forwardfire.vasc.frontend.VascFrontendData; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryControllerLocal.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryControllerLocal.java index cd51598..d1c9374 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryControllerLocal.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryControllerLocal.java @@ -33,4 +33,6 @@ package net.forwardfire.vasc.core; public interface VascEntryControllerLocal extends VascEntryController { public void addVascEntry(VascEntry entry,VascController vascController) throws VascException; + + public VascEntry getMasterVascEntryById(String id); } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryState.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryState.java index 1c27aba..939b8e9 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryState.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryState.java @@ -26,6 +26,9 @@ import java.io.Serializable; import java.util.List; import java.util.Map; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; + /** * Holds all the data for state. * So we can jump forward or back to a state. diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascFrontend.java b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/AbstractVascFrontend.java similarity index 89% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascFrontend.java rename to vasc-core/src/main/java/net/forwardfire/vasc/frontend/AbstractVascFrontend.java index 1b4be81..cd68929 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascFrontend.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/AbstractVascFrontend.java @@ -20,10 +20,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.frontend; import java.util.logging.Logger; +import net.forwardfire.vasc.core.VascEntry; + /** * @@ -51,7 +53,7 @@ abstract public class AbstractVascFrontend implements VascFrontend { abstract protected void addUiComponents(); /** - * @see net.forwardfire.vasc.core.VascFrontend#initEntry(net.forwardfire.vasc.core.VascEntry) + * @see net.forwardfire.vasc.frontend.VascFrontend#initEntry(net.forwardfire.vasc.core.VascEntry) */ public void initEntry(VascEntry entry) throws Exception { if (entry.getVascFrontendData().getVascFrontend()==null) { @@ -67,14 +69,14 @@ abstract public class AbstractVascFrontend implements VascFrontend { } /** - * @see net.forwardfire.vasc.core.VascFrontend#getId() + * @see net.forwardfire.vasc.frontend.VascFrontend#getId() */ public String getId() { return id; } /** - * @see net.forwardfire.vasc.core.VascFrontend#setId(java.lang.String) + * @see net.forwardfire.vasc.frontend.VascFrontend#setId(java.lang.String) */ public void setId(String id) { this.id=id; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontend.java b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontend.java similarity index 95% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontend.java rename to vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontend.java index c7a1b7a..4bc362d 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontend.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontend.java @@ -20,8 +20,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.frontend; +import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.entry.VascEntryExporter; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendActions.java b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendActions.java new file mode 100644 index 0000000..d949e13 --- /dev/null +++ b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendActions.java @@ -0,0 +1,52 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.frontend; + +import net.forwardfire.vasc.core.VascEntryField; + +/** + * VascFrontendActions are the most common used actions in frontend implemention. + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2012 + */ +public interface VascFrontendActions { + + public void refreshData(); + + public Object createObject(); + + public void deleteObject(); + + public Object mergeObject(); + + public void sortAction(VascEntryField field); + + public void searchAction(String searchString); + + public void pageAction(Integer page); + + public void moveUpAction(Object object); + + public void moveDownAction(Object object); +} \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendData.java b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendData.java similarity index 80% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendData.java rename to vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendData.java index da1fb6a..8c6c579 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendData.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendData.java @@ -20,14 +20,20 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.frontend; import java.util.List; +import net.forwardfire.vasc.core.VascController; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascEntryState; +import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.entry.VascEntryFieldValidatorService; import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; import net.forwardfire.vasc.core.entry.VascEntryResourceImageResolver; import net.forwardfire.vasc.core.entry.VascEntryResourceResolver; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; import net.forwardfire.vasc.core.ui.VascUIComponent; @@ -50,6 +56,26 @@ public interface VascFrontendData { */ public void setVascFrontend(VascFrontend vascFrontend); + /** + * Gets the VascFrontendActions to make frontend actions simple. + */ + public VascFrontendActions getVascFrontendActions(); + + /** + * @param vascFrontendActions the vascFrontendActions to set + */ + public void setVascFrontendActions(VascFrontendActions vascFrontendActions); + + /** + * @return the vascFrontendPager + */ + public VascFrontendPager getVascFrontendPager(); + + /** + * @param vascFrontendPager the vascFrontendPager to set + */ + public void setVascFrontendPager(VascFrontendPager vascFrontendPager); + /** * @return the VascFrontendHelper */ @@ -104,4 +130,5 @@ public interface VascFrontendData { public void initFrontendListeners(VascEntry entry,String frontendType) throws InstantiationException, IllegalAccessException; public void addVascEntryFrontendEventListener(VascEntryFrontendEventListener listener); public List getVascEntryFrontendEventListener(VascEntryFrontendEventListener.VascFrontendEventType type); + public void fireVascFrontendEvent(VascEntry entry,VascFrontendEventType type,Object data); } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendExceptionHandler.java b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendExceptionHandler.java similarity index 95% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendExceptionHandler.java rename to vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendExceptionHandler.java index cedce2f..987fa51 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendExceptionHandler.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendExceptionHandler.java @@ -20,10 +20,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.frontend; import java.util.EventListener; +import net.forwardfire.vasc.core.VascEntry; + /** * diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendHelper.java b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendHelper.java similarity index 76% rename from vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendHelper.java rename to vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendHelper.java index dc3b0b9..87b79d1 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascFrontendHelper.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendHelper.java @@ -20,13 +20,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc.core; +package net.forwardfire.vasc.frontend; import java.util.List; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascLinkEntry; +import net.forwardfire.vasc.core.VascLinkEntryType; import net.forwardfire.vasc.core.actions.GlobalVascAction; import net.forwardfire.vasc.core.actions.RowVascAction; -import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; /** * Helper for frontend rederer @@ -47,20 +50,6 @@ public interface VascFrontendHelper { public Integer getTotalColumnsWidth(VascEntry entry); public List getVascLinkEntryByType(VascEntry entry,VascLinkEntryType type); - - /** - * Returns the total amount of pages - * @return - */ - public List getVascBackendPageNumbers(VascEntry entry); - - public void refreshData(VascEntry entry); - - public Object createObject(VascEntry entry); - - public void deleteObject(VascEntry entry); - - public Object mergeObject(VascEntry entry); public List validateObjectField(VascEntryField field); @@ -71,16 +60,11 @@ public interface VascFrontendHelper { public void editReadOnlyUIComponents(VascEntry entry); public void handleException(VascEntry entry,Exception exception); - - public void fireVascEvent(VascEntry entry,VascFrontendEventType type,Object data); - - public void sortAction(VascEntry entry,VascEntryField field); - - public void searchAction(VascEntry entry,String searchString); - - public void pageAction(VascEntry entry,Integer page); - - public void moveAction(VascEntry entry,Object object,boolean moveUp); - + public List getMultiRowActions(VascEntry entry); + + public String getSelectedDisplayName(VascEntry entry); + public String getParentSelectedDisplayName(VascEntry entry); + + } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendPager.java b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendPager.java new file mode 100644 index 0000000..a9261e3 --- /dev/null +++ b/vasc-core/src/main/java/net/forwardfire/vasc/frontend/VascFrontendPager.java @@ -0,0 +1,55 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.frontend; + +import java.util.List; + +import net.forwardfire.vasc.backend.VascBackendPageNumber; + +/** + * VascFrontendPager has some info about the pageing data models + * + * note all the get properties for different el parsers. + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2012 + */ +public interface VascFrontendPager { + + public long getPageStartCount(); + public long getPageStopCount(); + public long getPageSize(); + public long getPageTotalRecordCount(); + + public boolean getHasPageNextAction(); + public boolean getHasPagePreviousAction(); + public boolean getHasOnlySinglePage(); + public boolean getHasExtendedPageMode(); + public boolean getHasExtendedPageModeCenter(); + + public List getTablePagesFromBackend(); + public List getTablePagesNormal(); + public List getTablePagesExtendedBegin(); + public List getTablePagesExtendedCenter(); + public List getTablePagesExtendedEnd(); +} \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackedEntryFinalizer.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackedEntryFinalizer.java index e2cdac7..c2aa8af 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackedEntryFinalizer.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackedEntryFinalizer.java @@ -25,7 +25,7 @@ package net.forwardfire.vasc.impl; import java.util.Collections; import java.util.Comparator; -import net.forwardfire.vasc.core.VascBackend; +import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; @@ -244,12 +244,10 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { if (defValue != null) { for (String typeId: vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeIds()) { VascEntryFieldType type = vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeById(typeId); - - if (type.getAutoDetectClass()!=null) { - if (type.getAutoDetectClass().isAssignableFrom(defValue.getClass())) { - vef.setVascEntryFieldType(type); - break; - } + Class autoClass = type.getAutoDetectClass(); + if (autoClass!=null && autoClass.isAssignableFrom(defValue.getClass())) { + vef.setVascEntryFieldType(type); + break; } } } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendController.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendController.java index bf49839..363b185 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendController.java @@ -25,8 +25,8 @@ package net.forwardfire.vasc.impl; import java.util.HashMap; import java.util.Map; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendControllerLocal; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendControllerLocal; /** @@ -44,7 +44,7 @@ public class DefaultVascBackendController implements VascBackendControllerLocal } /** - * @see net.forwardfire.vasc.core.VascBackendController#getVascBackendById(java.lang.String) + * @see net.forwardfire.vasc.backend.VascBackendController#getVascBackendById(java.lang.String) */ public VascBackend getVascBackendById(String id) { return backends.get(id); diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendState.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendState.java index 68e7570..9cc2d73 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendState.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendState.java @@ -22,7 +22,7 @@ package net.forwardfire.vasc.impl; -import net.forwardfire.vasc.core.AbstractVascBackendState; +import net.forwardfire.vasc.backend.AbstractVascBackendState; /** * Holds the state for the backend diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascController.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascController.java index 377574f..cd26a07 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascController.java @@ -22,7 +22,7 @@ package net.forwardfire.vasc.impl; -import net.forwardfire.vasc.core.VascBackendController; +import net.forwardfire.vasc.backend.VascBackendController; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntryController; import net.forwardfire.vasc.core.VascEntryFieldTypeController; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntry.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntry.java index 9a960d1..906de1d 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntry.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntry.java @@ -27,17 +27,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import net.forwardfire.vasc.core.VascBackendFilter; +import net.forwardfire.vasc.backend.VascBackendFilter; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryFieldSet; -import net.forwardfire.vasc.core.VascFrontendData; import net.forwardfire.vasc.core.VascLinkEntry; import net.forwardfire.vasc.core.actions.ColumnVascAction; import net.forwardfire.vasc.core.actions.GlobalVascAction; import net.forwardfire.vasc.core.actions.RowVascAction; import net.forwardfire.vasc.core.actions.VascAction; import net.forwardfire.vasc.core.entry.VascEntryFieldEventChannel; +import net.forwardfire.vasc.frontend.VascFrontendData; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntryController.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntryController.java index e82d624..f39055e 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntryController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntryController.java @@ -70,7 +70,7 @@ public class DefaultVascEntryController implements VascEntryControllerLocal { } - public VascEntry getRealVascEntryById(String id) { + public VascEntry getMasterVascEntryById(String id) { VascEntry entry = entries.get(id); return entry; } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFactory.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFactory.java index 949a576..6531a59 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFactory.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFactory.java @@ -25,18 +25,30 @@ package net.forwardfire.vasc.impl; import java.util.Locale; import java.util.ResourceBundle; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendFilter; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendFilter; +import net.forwardfire.vasc.backend.proxy.VascBackendProxyCache; +import net.forwardfire.vasc.backend.proxy.VascBackendProxyEventExecutor; +import net.forwardfire.vasc.backend.proxy.VascBackendProxyFilter; +import net.forwardfire.vasc.backend.proxy.VascBackendProxyPaged; +import net.forwardfire.vasc.backend.proxy.VascBackendProxySearch; +import net.forwardfire.vasc.backend.proxy.VascBackendProxySort; +import net.forwardfire.vasc.backend.proxy.VascBackendProxyTimerLogger; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.VascFrontendData; +import net.forwardfire.vasc.frontend.VascFrontendData; +import net.forwardfire.vasc.impl.actions.AddRowAction; +import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction; +import net.forwardfire.vasc.impl.actions.DeleteRowAction; +import net.forwardfire.vasc.impl.actions.EditRowAction; +import net.forwardfire.vasc.impl.actions.RefreshDataGlobalAction; +import net.forwardfire.vasc.impl.actions.XMLExportGlobalAction; import net.forwardfire.vasc.impl.entry.DefaultVascEntryResourceResolver; import net.forwardfire.vasc.impl.entry.VascValidatorsValidatorService; import net.forwardfire.vasc.impl.type.DefaultVascEntryFieldTypeController; - - /** * Default Vasc Factory for creating some base object plumming for vasc useage. * @@ -72,15 +84,19 @@ public class DefaultVascFactory { } static public VascFrontendData getDefaultVascFrontendData(ResourceBundle resourceBundle) { - DefaultVascFrontendData vascFrontendData = new DefaultVascFrontendData(); // controller is set by vasc - vascFrontendData.setVascEntryResourceResolver(new DefaultVascEntryResourceResolver(resourceBundle)); - vascFrontendData.setVascFrontendHelper(new DefaultVascFrontendHelper()); - //vascFrontendData.setVascEntryResourceImageResolver(new ImageResources()); + // Create default frontend data obj where controller is set by vasc + DefaultVascFrontendData vascFrontendData = new DefaultVascFrontendData(); // vascFrontendData.setVascEntryState(new DefaultVascEntryState()); vascFrontendData.getVascEntryState().setVascBackendState(new DefaultVascBackendState()); vascFrontendData.getVascEntryState().getVascBackendState().setPageSize(100); // default page size is zero aka disabled vascFrontendData.getVascEntryState().getVascBackendState().setPageSizeMax(1000); // max 1k records on screen. - vascFrontendData.addVascValidatorService(new VascValidatorsValidatorService()); // normal vasc validators + + // init resource resultsers + vascFrontendData.setVascEntryResourceResolver(new DefaultVascEntryResourceResolver(resourceBundle)); + vascFrontendData.setVascFrontendHelper(new DefaultVascFrontendHelper()); + //vascFrontendData.setVascEntryResourceImageResolver(new ImageResources()); + + vascFrontendData.addVascValidatorService(new VascValidatorsValidatorService()); return vascFrontendData; } @@ -96,6 +112,9 @@ public class DefaultVascFactory { // logs all actions log logger backend = new VascBackendProxyTimerLogger(backend,entry); + // Fire event listeners before caching. + backend = new VascBackendProxyEventExecutor(backend,entry); + // only cached one result, checks for paramater differnce backend = new VascBackendProxyCache(backend,entry); @@ -116,4 +135,80 @@ public class DefaultVascFactory { // return the configed backend. return backend; } + + static public void fillVascControllerLocalEntries(VascEntryControllerLocal c,VascController con) throws VascException { + for (String id:c.getVascEntryIds()) { + VascEntry entry = c.getMasterVascEntryById(id); + if (entry.isVascDisplayOnly()==false) { + if (entry.isVascAdminCreate()) { + entry.addRowAction(new AddRowAction()); + } + if (entry.isVascAdminEdit()) { + entry.addRowAction(new EditRowAction()); + } + if (entry.isVascAdminDelete()) { + entry.addRowAction(new DeleteRowAction()); + } + } + entry.addGlobalAction(new XMLExportGlobalAction()); + entry.addGlobalAction(new CSVExportGlobalAction()); + entry.addGlobalAction(new RefreshDataGlobalAction()); + + /* + DefaultVascEntryResourceResolver t = new DefaultVascEntryResourceResolver(resourceBundle); + if (t.getTextValue(entry.getEditDescription()).equals(entry.getEditDescription())) { + entry.setEditDescription("generic.editDescription"); + } + if (t.getTextValue(entry.getDeleteDescription()).equals(entry.getDeleteDescription())) { + entry.setDeleteDescription("generic.deleteDescription"); + } + if (t.getTextValue(entry.getCreateDescription()).equals(entry.getCreateDescription())) { + entry.setCreateDescription("generic.createDescription"); + } + */ + + /* + for (String key:entry.getEntryParameterKeys()) { + Object value = entry.getEntryParameter(key); + if (value instanceof String==false) { + continue; + } + String paraValue = (String)value; + if (paraValue.startsWith("userPara")==false) { + continue; + } + String[] ps = paraValue.split(":"); + String type = ps[1]; + String paraTypeValue = ps[2]; + + SetParameterBackendListener listener = new SetParameterBackendListener(vui.userId,vui.username); + listener.setName(key); + listener.setType(type); + listener.setValue(paraTypeValue); + + entry.getVa + } + */ + + // hackje om deze manuale actions van i18n keys te voorzien; + // this is temp untill x4o templaing + DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer(); + f.finalizeVascEntry(entry, con); + + // execute backend event listeners NOTE: moved to default factory fillings + // VascBackend vb = c.getVascBackendController().getVascBackendById(entry.getBackendId()); + // vb = new VascBackendProxyEventExecutor(vb,entry); + // ((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(vb); + } + } + + static public void fillVascEntryFrontend(VascEntry entry,VascController vascController,VascFrontendData frontendData) { + frontendData.setVascController(vascController); + entry.setVascFrontendData(frontendData); + VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); + frontendData.getVascEntryState().setVascBackend(backend); + frontendData.getVascEntryState().setVascEntry(entry); + frontendData.setVascFrontendPager(new DefaultVascFrontendPager(entry)); + frontendData.setVascFrontendActions(new DefaultVascFrontendActions(entry)); + } } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendActions.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendActions.java new file mode 100644 index 0000000..5bd566a --- /dev/null +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendActions.java @@ -0,0 +1,290 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.impl; + +import java.util.Date; +import java.util.logging.Logger; + +import net.forwardfire.vasc.backend.VascBackendFilter; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; +import net.forwardfire.vasc.frontend.VascFrontendActions; + + +/** + * Default impl of default frontend actions + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2012 + */ +public class DefaultVascFrontendActions implements VascFrontendActions { + + private Logger logger = Logger.getLogger(DefaultVascFrontendActions.class.getName()); + private VascEntry entry = null; + + public DefaultVascFrontendActions(VascEntry entry) { + this.entry=entry; + } + + /** + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#initEditObject(net.forwardfire.vasc.core.VascEntry) + */ + public Object createObject() { + try { + entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PRE_CREATE, null); + Object object = entry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryRecordCreator(entry.clone()).newRecord(entry); + if (object==null) { + throw new IllegalStateException("Can't work with null object for backend storage."); + } + for (VascEntryField field:entry.getVascEntryFields()) { + if (field.getDefaultValue()==null) { + continue; // no default value to set. + } + Object value = field.getVascEntryFieldValue().getValue(field, object); + if (value!=null) { + continue; // value is already set by backend creator. + } + Object defaultValue = field.getDefaultValue(); + if (defaultValue instanceof String) { + String def = (String)defaultValue; + if (def.equals("now()")) { // TODO: add default string parsers + defaultValue = new Date(); + } + } + logger.finer("Setting default value for: "+field.getName()+" def: "+defaultValue); + field.getVascEntryFieldValue().setValue(field, object, defaultValue); + } + entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.POST_CREATE, object); + return object; + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e); + return null; /// ?? ,, + } + } + + protected int removeObjectFromDataList(Object object) { + int indexOld = entry.getVascFrontendData().getVascEntryState().getEntryDataList().indexOf(object); + if (entry.getVascFrontendData().getVascEntryState().getEntryDataList().remove(object)) { + return indexOld; // java worked well for use + } + + // remove only work on (jpa)beans with an overrided equals method. + // we lets do the search ourselfs here because we should know the primary key value + try { + VascEntryField field = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId()); + Object idObject = field.getVascEntryFieldValue().getValue(field, object); + + // is only null when creating objects + if (idObject!=null) { + int index = 0; + for (Object o:entry.getVascFrontendData().getVascEntryState().getEntryDataList()) { + field = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId()); + Object id = field.getVascEntryFieldValue().getValue(field, o); + if (idObject.equals(id)) { + break; + } + index++; + } + if (indexentry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()) { + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()); + } + + for (String key:entry.getEntryParameterKeys()) { + Object value = entry.getEntryParameter(key); + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setDataParameter(key, value); + } + entry.getVascFrontendData().getVascEntryState().setEntryDataList(entry.getVascFrontendData().getVascEntryState().getVascBackend().execute(entry.getVascFrontendData().getVascEntryState().getVascBackendState())); + + // also update total every time + Long total = entry.getVascFrontendData().getVascEntryState().getVascBackend().fetchTotalExecuteSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState()); + entry.getVascFrontendData().getVascEntryState().setTotalBackendRecords(total); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.POST_READ, null); + } + + + public void sortAction(VascEntryField field) { + String curSort = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getSortField(); + if (field.getBackendName().equals(curSort)) { + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSortAscending(!entry.getVascFrontendData().getVascEntryState().getVascBackendState().isSortAscending()); + } + String sortID = field.getBackendName(); + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSortField(sortID); + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(0); + entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.SORT, field); + + refreshData(); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void searchAction(String searchString) { + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSearchString(searchString); + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSortField(null); + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(0); + entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.SEARCH, searchString); + + refreshData(); + + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void pageAction(Integer pageIndex) { + if (pageIndex<1) { + pageIndex = 0; + } + Long total = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); // note: total is only null when pageAction is done before first refresh, which should never happen anyway. + if (total!=null && pageIndex>(total/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize())) { + pageIndex = new Long(total/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize()).intValue(); + } + + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(pageIndex); + entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PAGE, pageIndex); + + // lets load data; + refreshData(); + + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void moveUpAction(Object record) { + if (entry.getVascFrontendData().getVascEntryState().getVascBackend().isRecordMoveable()) { + try { + VascEntryField p = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId()); + Object primaryId = p.getVascEntryFieldValue().getValue(p, record); + entry.getVascFrontendData().getVascEntryState().getVascBackend().doRecordMoveUpById(entry.getVascFrontendData().getVascEntryState().getVascBackendState(),primaryId); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + + // lets load data; + refreshData(); + } + + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void moveDownAction(Object record) { + if (entry.getVascFrontendData().getVascEntryState().getVascBackend().isRecordMoveable()) { + try { + VascEntryField p = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId()); + Object primaryId = p.getVascEntryFieldValue().getValue(p, record); + entry.getVascFrontendData().getVascEntryState().getVascBackend().doRecordMoveDownById(entry.getVascFrontendData().getVascEntryState().getVascBackendState(),primaryId); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + // lets load data; + refreshData(); + } + + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } +} \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendData.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendData.java index e5ca94b..49a1344 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendData.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendData.java @@ -33,9 +33,6 @@ import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryFinalizer; import net.forwardfire.vasc.core.VascEntryState; import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.VascFrontend; -import net.forwardfire.vasc.core.VascFrontendData; -import net.forwardfire.vasc.core.VascFrontendHelper; import net.forwardfire.vasc.core.actions.ColumnVascAction; import net.forwardfire.vasc.core.actions.GlobalVascAction; import net.forwardfire.vasc.core.actions.RowVascAction; @@ -44,7 +41,13 @@ import net.forwardfire.vasc.core.entry.VascEntryFieldValidatorService; import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; import net.forwardfire.vasc.core.entry.VascEntryResourceImageResolver; import net.forwardfire.vasc.core.entry.VascEntryResourceResolver; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; import net.forwardfire.vasc.core.ui.VascUIComponent; +import net.forwardfire.vasc.frontend.VascFrontend; +import net.forwardfire.vasc.frontend.VascFrontendActions; +import net.forwardfire.vasc.frontend.VascFrontendData; +import net.forwardfire.vasc.frontend.VascFrontendHelper; +import net.forwardfire.vasc.frontend.VascFrontendPager; @@ -57,6 +60,8 @@ import net.forwardfire.vasc.core.ui.VascUIComponent; public class DefaultVascFrontendData implements VascFrontendData { private VascFrontend vascFrontend = null; + private VascFrontendActions vascFrontendActions = null; + private VascFrontendPager vascFrontendPager = null; private VascEntryFinalizer vascEntryFinalizer = null; private VascFrontendHelper vascFrontendHelper = null; private VascEntryResourceResolver vascEntryResourceResolver = null; @@ -92,7 +97,35 @@ public class DefaultVascFrontendData implements VascFrontendData { public void setVascFrontend(VascFrontend vascFrontend) { this.vascFrontend = vascFrontend; } - + + /** + * @return the vascFrontendActions + */ + public VascFrontendActions getVascFrontendActions() { + return vascFrontendActions; + } + + /** + * @param vascFrontendActions the vascFrontendActions to set + */ + public void setVascFrontendActions(VascFrontendActions vascFrontendActions) { + this.vascFrontendActions = vascFrontendActions; + } + + /** + * @return the vascFrontendPager + */ + public VascFrontendPager getVascFrontendPager() { + return vascFrontendPager; + } + + /** + * @param vascFrontendPager the vascFrontendPager to set + */ + public void setVascFrontendPager(VascFrontendPager vascFrontendPager) { + this.vascFrontendPager = vascFrontendPager; + } + /** * @see net.forwardfire.vasc.core.VascBackendData#getVascEntryFinalizer() */ @@ -159,14 +192,14 @@ public class DefaultVascFrontendData implements VascFrontendData { } /** - * @see net.forwardfire.vasc.core.VascFrontendData#getVascUIComponent(java.lang.String) + * @see net.forwardfire.vasc.frontend.VascFrontendData#getVascUIComponent(java.lang.String) */ public String getVascUIComponentClass(String rendererId) { return uiComponents.get(rendererId); } /** - * @see net.forwardfire.vasc.core.VascFrontendData#putVascUIComponent(java.lang.String, java.lang.String) + * @see net.forwardfire.vasc.frontend.VascFrontendData#putVascUIComponent(java.lang.String, java.lang.String) */ public void putVascUIComponent(String rendererId, String uiComponentClass) { uiComponents.put(rendererId, uiComponentClass); @@ -187,7 +220,7 @@ public class DefaultVascFrontendData implements VascFrontendData { } /** - * @see net.forwardfire.vasc.core.VascFrontendData#addFieldVascUIComponents(net.forwardfire.vasc.core.VascEntryField, net.forwardfire.vasc.core.ui.VascUIComponent, java.lang.Object) + * @see net.forwardfire.vasc.frontend.VascFrontendData#addFieldVascUIComponents(net.forwardfire.vasc.core.VascEntryField, net.forwardfire.vasc.core.ui.VascUIComponent, java.lang.Object) */ public void addFieldVascUIComponents(VascEntryField field,VascUIComponent uiComponent, Object editor) { fieldComps.put(field, uiComponent); @@ -200,14 +233,14 @@ public class DefaultVascFrontendData implements VascFrontendData { } /** - * @see net.forwardfire.vasc.core.VascFrontendData#getFieldRealRenderer(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.frontend.VascFrontendData#getFieldRealRenderer(net.forwardfire.vasc.core.VascEntryField) */ public Object getFieldRealRenderer(VascEntryField field) { return fieldEditors.get(field); } /** - * @see net.forwardfire.vasc.core.VascFrontendData#getFieldVascUIComponent(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.frontend.VascFrontendData#getFieldVascUIComponent(net.forwardfire.vasc.core.VascEntryField) */ public VascUIComponent getFieldVascUIComponent(VascEntryField field) { return fieldComps.get(field); @@ -228,14 +261,14 @@ public class DefaultVascFrontendData implements VascFrontendData { } /** - * @see net.forwardfire.vasc.core.VascFrontendData#addVascValidatorService(net.forwardfire.vasc.core.entry.VascEntryFieldValidatorService) + * @see net.forwardfire.vasc.frontend.VascFrontendData#addVascValidatorService(net.forwardfire.vasc.core.entry.VascEntryFieldValidatorService) */ public void addVascValidatorService(VascEntryFieldValidatorService validatorService) { validatorServices.add(validatorService); } /** - * @see net.forwardfire.vasc.core.VascFrontendData#getVascValidatorServices() + * @see net.forwardfire.vasc.frontend.VascFrontendData#getVascValidatorServices() */ public List getVascValidatorServices() { return validatorServices; @@ -322,4 +355,11 @@ public class DefaultVascFrontendData implements VascFrontendData { } return list; } + + public void fireVascFrontendEvent(VascEntry entry,VascFrontendEventType type, Object data) { + List list = getVascEntryFrontendEventListener(type); + for (VascEntryFrontendEventListener l:list) { + l.vascEvent(entry, data); + } + } } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendHelper.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendHelper.java index f1be4b0..f6ad502 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendHelper.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendHelper.java @@ -23,26 +23,24 @@ package net.forwardfire.vasc.impl; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.logging.Logger; -import net.forwardfire.vasc.core.VascBackendFilter; -import net.forwardfire.vasc.core.VascBackendPageNumber; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackendPageNumber; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.VascFrontendHelper; import net.forwardfire.vasc.core.VascLinkEntry; import net.forwardfire.vasc.core.VascLinkEntryType; import net.forwardfire.vasc.core.VascUserRoleController; import net.forwardfire.vasc.core.actions.GlobalVascAction; import net.forwardfire.vasc.core.actions.RowVascAction; import net.forwardfire.vasc.core.entry.VascEntryFieldValidatorService; -import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; import net.forwardfire.vasc.core.ui.VascUIComponent; +import net.forwardfire.vasc.frontend.VascFrontendHelper; @@ -56,7 +54,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { private Logger logger = Logger.getLogger(DefaultVascFrontendHelper.class.getName()); /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#renderView(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#renderView(net.forwardfire.vasc.core.VascEntryField) */ public boolean renderView(VascEntryField field) { if (field.getView()==false) { @@ -66,7 +64,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#renderCreate(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#renderCreate(net.forwardfire.vasc.core.VascEntryField) */ public boolean renderCreate(VascEntryField field) { if (renderView(field)==false) { @@ -83,7 +81,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#renderEdit(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#renderEdit(net.forwardfire.vasc.core.VascEntryField) */ public boolean renderEdit(VascEntryField field) { if (renderView(field)==false) { @@ -105,7 +103,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#renderEditReadOnly(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#renderEditReadOnly(net.forwardfire.vasc.core.VascEntryField) */ public boolean renderEditReadOnly(VascEntryField field) { if (renderView(field)==false) { @@ -122,7 +120,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#renderList(net.forwardfire.vasc.core.VascEntryField) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#renderList(net.forwardfire.vasc.core.VascEntryField) */ public boolean renderList(VascEntryField field) { if (renderView(field)==false) { @@ -139,31 +137,23 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#renderGlobalVascAction(net.forwardfire.vasc.core.actions.GlobalVascAction) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#renderGlobalVascAction(net.forwardfire.vasc.core.actions.GlobalVascAction) */ public boolean renderGlobalVascAction(GlobalVascAction action) { return true; } /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#renderRowVascAction(net.forwardfire.vasc.core.actions.RowVascAction) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#renderRowVascAction(net.forwardfire.vasc.core.actions.RowVascAction) */ public boolean renderRowVascAction(RowVascAction action) { return true; } - /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#fireVascEvent(net.forwardfire.vasc.core.entry.VascEntryEventListener.VascEventType, java.lang.Object) - */ - public void fireVascEvent(VascEntry entry,VascFrontendEventType type, Object data) { - List list = entry.getVascFrontendData().getVascEntryFrontendEventListener(type); - for (VascEntryFrontendEventListener l:list) { - l.vascEvent(entry, data); - } - } + /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#getTotalColumnsWidth(net.forwardfire.vasc.core.VascEntry) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#getTotalColumnsWidth(net.forwardfire.vasc.core.VascEntry) */ public Integer getTotalColumnsWidth(VascEntry entry) { int result = 0; @@ -192,186 +182,21 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } /** - * Returns the total amount of pages - * @return - */ - public List getVascBackendPageNumbers(VascEntry entry) { - List result = new ArrayList(30); - VascBackendState state = entry.getVascFrontendData().getVascEntryState().getVascBackendState(); - if (state.getPageSize()==0) { - return result; // paging disabled - } - Long total = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); - if (total==null) { - return result; // no pages - } - int pages = new Long(total/state.getPageSize()).intValue(); - for (int i=0;i<=pages;i++) { - VascBackendPageNumber pn = new VascBackendPageNumber(i); - if (state.getPageIndex()==i) { - pn.setSelected(true); - } - result.add(pn); - } - return result; - } - - /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#handleException(net.forwardfire.vasc.core.VascEntry,java.lang.Exception) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#handleException(net.forwardfire.vasc.core.VascEntry,java.lang.Exception) */ public void handleException(VascEntry entry,Exception exception) { - fireVascEvent(entry,VascFrontendEventType.EXCEPTION , exception); - } - - /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#initEditObject(net.forwardfire.vasc.core.VascEntry) - */ - public Object createObject(VascEntry entry) { - try { - fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PRE_CREATE, null); - Object object = entry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryRecordCreator(entry.clone()).newRecord(entry); - if (object==null) { - throw new IllegalStateException("Can't work with null object for backend storage."); - } - for (VascEntryField field:entry.getVascEntryFields()) { - if (field.getDefaultValue()==null) { - continue; // no default value to set. - } - Object value = field.getVascEntryFieldValue().getValue(field, object); - if (value!=null) { - continue; // value is already set by backend creator. - } - Object defaultValue = field.getDefaultValue(); - if (defaultValue instanceof String) { - String def = (String)defaultValue; - if (def.equals("now()")) { // TODO: add default string parsers - defaultValue = new Date(); - } - } - logger.finer("Setting default value for: "+field.getName()+" def: "+defaultValue); - field.getVascEntryFieldValue().setValue(field, object, defaultValue); - } - fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.POST_CREATE, object); - return object; - } catch (Exception e) { - handleException(entry,e); - return null; /// ?? ,, - } - } - - protected int removeObjectFromDataList(VascEntry entry,Object object) { - int indexOld = entry.getVascFrontendData().getVascEntryState().getEntryDataList().indexOf(object); - if (entry.getVascFrontendData().getVascEntryState().getEntryDataList().remove(object)) { - return indexOld; // java worked well for use - } - - // remove only work on (jpa)beans with an overrided equals method. - // we lets do the search ourselfs here because we should know the primary key value - try { - VascEntryField field = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId()); - Object idObject = field.getVascEntryFieldValue().getValue(field, object); - - // is only null when creating objects - if (idObject!=null) { - int index = 0; - for (Object o:entry.getVascFrontendData().getVascEntryState().getEntryDataList()) { - field = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId()); - Object id = field.getVascEntryFieldValue().getValue(field, o); - if (idObject.equals(id)) { - break; - } - index++; - } - if (indexentry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()) { - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()); - } - - for (String key:entry.getEntryParameterKeys()) { - Object value = entry.getEntryParameter(key); - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setDataParameter(key, value); - } - entry.getVascFrontendData().getVascEntryState().setEntryDataList(entry.getVascFrontendData().getVascEntryState().getVascBackend().execute(entry.getVascFrontendData().getVascEntryState().getVascBackendState())); - - // also update total every time - Long total = entry.getVascFrontendData().getVascEntryState().getVascBackend().fetchTotalExecuteSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState()); - entry.getVascFrontendData().getVascEntryState().setTotalBackendRecords(total); - } catch (Exception e) { - handleException(entry, e); - } - fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.POST_READ, null); + entry.getVascFrontendData().fireVascFrontendEvent(entry,VascFrontendEventType.EXCEPTION , exception); } public void headerOptionsCreatedFillData(VascEntry entry) { - entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + + // fix conv defs of options to object. ? + + entry.getVascFrontendData().getVascFrontendActions().refreshData(); } /** - * @see net.forwardfire.vasc.core.VascFrontendHelper#validateObjectField(net.forwardfire.vasc.core.VascEntryField, java.lang.Object) + * @see net.forwardfire.vasc.frontend.VascFrontendHelper#validateObjectField(net.forwardfire.vasc.core.VascEntryField, java.lang.Object) */ public List validateObjectField(VascEntryField field) { if (field==null) { @@ -463,64 +288,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } } } - - public void sortAction(VascEntry entry,VascEntryField field) { - String curSort = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getSortField(); - if (field.getBackendName().equals(curSort)) { - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSortAscending(!entry.getVascFrontendData().getVascEntryState().getVascBackendState().isSortAscending()); - } - String sortID = field.getBackendName(); - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSortField(sortID); - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(0); - fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.SORT, field); - - refreshData(entry); - } - - public void searchAction(VascEntry entry,String searchString) { - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSearchString(searchString); - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setSortField(null); - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(0); - fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.SEARCH, searchString); - refreshData(entry); - } - - public void pageAction(VascEntry entry,Integer pageIndex) { - if (pageIndex<1) { - pageIndex = 0; - } - Long total = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); // note: total is only null when pageAction is done before first refresh, which should never happen anyway. - if (total!=null && pageIndex>(total/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize())) { - pageIndex = new Long(total/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize()).intValue(); - } - - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(pageIndex); - fireVascEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PAGE, pageIndex); - - // lets load data; - refreshData(entry); - } - - public void moveAction(VascEntry entry,Object record,boolean moveUp) { - if (entry.getVascFrontendData().getVascEntryState().getVascBackend().isRecordMoveable()) { - try { - VascEntryField p = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId()); - Object primaryId = p.getVascEntryFieldValue().getValue(p, record); - if (moveUp) { - entry.getVascFrontendData().getVascEntryState().getVascBackend().doRecordMoveUpById(entry.getVascFrontendData().getVascEntryState().getVascBackendState(),primaryId); - } else { - entry.getVascFrontendData().getVascEntryState().getVascBackend().doRecordMoveDownById(entry.getVascFrontendData().getVascEntryState().getVascBackendState(),primaryId); - } - } catch (Exception e) { - handleException(entry, e); - } - - // lets load data; - refreshData(entry); - } - } - public List getMultiRowActions(VascEntry entry) { List result = new ArrayList(5); for (RowVascAction a:entry.getRowActions()) { @@ -530,4 +298,44 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } return result; } + + public String getSelectedDisplayName(VascEntry entry) { + Object row = entry.getVascFrontendData().getVascEntryState().getEntryDataObject(); + if (row==null) { + return "no-selection"; + } + VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId()); + VascEntryFieldValue ve = v.getVascEntryFieldValue(); + String result = "no-data"; + try { + result = ve.getDisplayValue(v, row); + } catch (VascException e) { + throw new RuntimeException("Could not get selected name DisplayValue: "+e.getMessage(),e); + } + return result; + } + + public String getParentSelectedDisplayName(VascEntry entry) { + if (entry.getVascFrontendData().getVascEntryState().getParent()==null) { + return ""; // no parent + } + + VascEntry parent = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); + Object row = entry.getVascFrontendData().getVascEntryState().getParent().getEntryDataObject(); + if (row==null) { + return "no-selection"; + } + VascEntryField v = parent.getVascEntryFieldById(parent.getDisplayNameFieldId()); + VascEntryFieldValue ve = v.getVascEntryFieldValue(); + String result = "no-data"; + try { + result = ve.getDisplayValue(v, row); + } catch (VascException e) { + throw new RuntimeException("Could not get parent name DisplayValue: "+e.getMessage(),e); + } + return result; + } + + + } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendPager.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendPager.java new file mode 100644 index 0000000..8188fcb --- /dev/null +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendPager.java @@ -0,0 +1,223 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.impl; + +import java.util.ArrayList; +import java.util.List; + +import net.forwardfire.vasc.backend.VascBackendPageNumber; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; +import net.forwardfire.vasc.frontend.VascFrontendPager; + + +/** + * Default impl of default frontend actions + * + * @author Willem Cazander + * @version 1.0 Jan 22, 2012 + */ +public class DefaultVascFrontendPager implements VascFrontendPager { + + //private Logger logger = Logger.getLogger(DefaultVascFrontendPager.class.getName()); + private VascEntry entry = null; + private List pagesAll = null; + + public DefaultVascFrontendPager(VascEntry entry) { + this.entry=entry; + pagesAll = new ArrayList(0); + entry.getVascFrontendData().addVascEntryFrontendEventListener(new DefaultVascFrontendPagerEventListener()); + } + + class DefaultVascFrontendPagerEventListener implements VascEntryFrontendEventListener { + private static final long serialVersionUID = -6667099892801941650L; + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ}; + return result; + } + public void vascEvent(VascEntry entry, Object data) { + pagesAll = getTablePagesFromBackend(); + } + } + + + public long getPageTotalRecordCount() { + long result = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); + return result; + } + public long getPageSize() { + long result = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize(); + return result; + } + public long getPageStartCount() { + int index = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + int pageSize = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize(); + long result = index*pageSize; + return result; + } + public long getPageStopCount() { + int index = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + int pageSize = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize(); + long result = (index*pageSize)+pageSize; + + // limit for small result sets. + if (result>entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords()) { + result = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); + } + return result; + } + + public boolean getHasPageNextAction() { + int pageIndex = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + pageIndex++; + // copyed from helper + Long total = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); + if (total!=null && pageIndex>(total/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize())) { + return false; + } + return true; + } + + public boolean getHasPagePreviousAction() { + int pageIndex = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + if (pageIndex==0) { + return false; + } + return true; + } + + public boolean getHasOnlySinglePage() { + int pages = pagesAll.size(); + if (pages==1) { + return true; + } + return false; + } + + public boolean getHasExtendedPageMode() { + int pages = pagesAll.size(); + if (pages>13) { + return true; + } + return false; + } + + public boolean getHasExtendedPageModeCenter() { + if (getHasExtendedPageMode()==false) { + return false; + } + int page = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + if (page<5) { + return false; + } + int pages = pagesAll.size(); + if (page>pages-6) { + return false; + } + return true; + } + + public List getTablePagesFromBackend() { + List result = new ArrayList(30); + VascBackendState state = entry.getVascFrontendData().getVascEntryState().getVascBackendState(); + if (state.getPageSize()==0) { + return result; // paging disabled + } + Long total = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); + if (total==null) { + return result; // no pages + } + int pages = new Long(total/state.getPageSize()).intValue(); + for (int i=0;i<=pages;i++) { + VascBackendPageNumber pn = new VascBackendPageNumber(i); + if (state.getPageIndex()==i) { + pn.setSelected(true); + } + result.add(pn); + } + return result; + } + + public List getTablePagesNormal() { + if (getHasExtendedPageMode()) { + return new ArrayList(0); + } else { + return pagesAll; + } + } + + public List getTablePagesExtendedBegin() { + List result = new ArrayList(6); + result.add(pagesAll.get(0)); + result.add(pagesAll.get(1)); + result.add(pagesAll.get(2)); + + int page = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + if (page==2 | page==3 | page==4) { + result.add(pagesAll.get(3)); + } + if (page==3 | page==4) { + result.add(pagesAll.get(4)); + } + if (page==4) { + result.add(pagesAll.get(5)); + } + return result; + } + + public List getTablePagesExtendedEnd() { + List result = new ArrayList(6); + int pages = pagesAll.size(); + int page = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + int off = pages-page; + + if (off==5) { + result.add(pagesAll.get(pages-6)); + } + if (off==4 | off==5) { + result.add(pagesAll.get(pages-5)); + } + if (off==3 | off==4 | off==5) { + result.add(pagesAll.get(pages-4)); + } + + if (pages>4) { + result.add(pagesAll.get(pages-3)); + result.add(pagesAll.get(pages-2)); + result.add(pagesAll.get(pages-1)); + } + return result; + } + + public List getTablePagesExtendedCenter() { + List result = new ArrayList(3); + int page = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + if (page>0) { + result.add(pagesAll.get(page-1)); + } + result.add(pagesAll.get(page)); + result.add(pagesAll.get(page+1)); + return result; + } +} \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/AddRowAction.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/AddRowAction.java index 665c7b2..3ed3f0b 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/AddRowAction.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/AddRowAction.java @@ -45,7 +45,7 @@ public class AddRowAction extends AbstractVascAction implements RowVascAction { public void doRowAction(VascEntry entry,Object rowObject) throws Exception { entry.getVascFrontendData().getVascEntryState().setEditCreate(true); - Object object = entry.getVascFrontendData().getVascFrontendHelper().createObject(entry); + Object object = entry.getVascFrontendData().getVascFrontendActions().createObject(); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(object); entry.getVascFrontendData().getVascFrontend().renderEdit(); } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/CSVExportGlobalAction.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/CSVExportGlobalAction.java index 588d586..84a455b 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/CSVExportGlobalAction.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/CSVExportGlobalAction.java @@ -65,7 +65,7 @@ public class CSVExportGlobalAction extends AbstractVascAction implements GlobalV int pages = total.intValue()/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize(); for (int page=0;page<=pages;page++) { entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(page); - entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + entry.getVascFrontendData().getVascFrontendActions().refreshData(); for (Object o:entry.getVascFrontendData().getVascEntryState().getEntryDataList()) { for (VascEntryField c:entry.getVascEntryFields()) { p.write(c.getVascEntryFieldValue().getDisplayValue(c, o)+"\t"); diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/EditRowAction.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/EditRowAction.java index 00d6902..167e8a3 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/EditRowAction.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/EditRowAction.java @@ -49,7 +49,7 @@ public class EditRowAction extends AbstractVascAction implements RowVascAction { return; // nothing selected } entry.getVascFrontendData().getVascEntryState().setEditCreate(false); - entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascFrontendEventType.SELECT, rowObject); + entry.getVascFrontendData().fireVascFrontendEvent(entry, VascFrontendEventType.SELECT, rowObject); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(rowObject); entry.getVascFrontendData().getVascFrontend().renderEdit(); } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/RefreshDataGlobalAction.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/RefreshDataGlobalAction.java index 0b02f35..d9b72a0 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/RefreshDataGlobalAction.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/RefreshDataGlobalAction.java @@ -44,6 +44,6 @@ public class RefreshDataGlobalAction extends AbstractVascAction implements Globa public void doGlobalAction(VascEntry entry) throws Exception { - entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); // this wil also fire the event + entry.getVascFrontendData().getVascFrontendActions().refreshData(); // this wil also fire the event } } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/XMLExportGlobalAction.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/XMLExportGlobalAction.java index 46fe789..97ee24a 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/XMLExportGlobalAction.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/actions/XMLExportGlobalAction.java @@ -62,7 +62,7 @@ public class XMLExportGlobalAction extends AbstractVascAction implements GlobalV int pages = total.intValue()/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize(); for (int page=0;page<=pages;page++) { entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageIndex(page); - entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + entry.getVascFrontendData().getVascFrontendActions().refreshData(); for (Object o:entry.getVascFrontendData().getVascEntryState().getEntryDataList()) { p.write("\t\n"); for (VascEntryField c:entry.getVascEntryFields()) { diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/entry/SetParameterBackendListener.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/entry/SetParameterBackendListener.java index b0f6ea2..e12b089 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/entry/SetParameterBackendListener.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/entry/SetParameterBackendListener.java @@ -22,7 +22,7 @@ package net.forwardfire.vasc.impl.entry; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.entry.VascEntryBackendEventListener; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelEntry.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelEntry.java new file mode 100644 index 0000000..9855d55 --- /dev/null +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelEntry.java @@ -0,0 +1,293 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.impl.ui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; +import net.forwardfire.vasc.core.ui.VascSelectItem; +import net.forwardfire.vasc.core.ui.VascSelectItemModel; +import net.forwardfire.vasc.impl.DefaultVascBackendState; +import net.forwardfire.vasc.impl.DefaultVascFactory; + + + + +/** +* The DefaultVascSelectItemModel +* +* @author Willem Cazander +* @version 1.0 Oct 27, 2007 +*/ +public class VascSelectItemModelEntry implements VascSelectItemModel { + + private static final long serialVersionUID = 1L; + private String entryId = null; + private String keyFieldId = null; + private String displayFieldId = null; + private String nullLabel = null; + private String nullKeyValue = null; + private Boolean returnKeyValue = null; + private Map entryParameterFieldIds = new HashMap(3); + private Boolean useParentFields = null; + + /** + * @see net.forwardfire.vasc.core.ui.VascSelectItemModel#getVascSelectItems(net.forwardfire.vasc.core.VascEntry) + */ + public List getVascSelectItems(VascEntry currentEntry) throws VascException { + List result = new ArrayList(100); + VascEntry entry = currentEntry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(entryId); + + if (keyFieldId==null) { + keyFieldId = entry.getPrimaryKeyFieldId(); + } + VascEntryField key = entry.getVascEntryFieldById(keyFieldId); + + if (displayFieldId==null) { + displayFieldId = entry.getDisplayNameFieldId(); + } + VascEntryField dis = entry.getVascEntryFieldById(displayFieldId); + if (key==null) { + throw new VascException("Could not find: "+keyFieldId+" from: "+entry.getId()); + } + if (dis==null) { + throw new VascException("Could not find: "+displayFieldId+" from: "+entry.getId()); + } + + // set frontend data for new clone, we need te get better lifecycle management for stats/entry/etc + entry.setVascFrontendData(currentEntry.getVascFrontendData()); + VascBackend back = DefaultVascFactory.getProxyVascBackend(entry); + try { + if (nullLabel!=null) { + if (nullKeyValue==null) { + nullKeyValue = "null"; + } + nullLabel = currentEntry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(nullLabel); + VascSelectItem item = new VascSelectItem(nullLabel,null,nullKeyValue); + result.add(item); + } + + // set def para + VascBackendState state = new DefaultVascBackendState(); + for (String key2:entry.getEntryParameterKeys()) { + Object value = entry.getEntryParameter(key2); + //System.out.println("Copy paras name: "+key2+" value: "+value+" class: "+value.getClass().getName()); + state.setDataParameter(key2, value); + } + + // set list para + for (VascEntryField vef:entry.getListOptions()) { + Object def = vef.getDefaultValue(); + if (def==null) { + continue; + } + String backendName = vef.getBackendName(); + state.setDataParameter(backendName, def); + } + + // set para from parent state entry + for (String paraName:entryParameterFieldIds.keySet()) { + + VascEntry fieldEntry = currentEntry; + if (useParentFields!=null && useParentFields==true) { + if (currentEntry.getVascFrontendData().getVascEntryState().getParent()==null) { + throw new IllegalStateException("Requested to use parent state field values but no parent state found."); + } + fieldEntry = currentEntry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); + } + + String paraValueId = entryParameterFieldIds.get(paraName); + VascEntryField fieldOrg = fieldEntry.getVascEntryFieldById(paraValueId); + if (fieldOrg==null) { + //System.out.println("could not find field: "+paraValueId); + continue; + } + VascEntryField field = fieldOrg.clone(); + field.getVascValidators().clear(); + VascEntryFieldValue v = fieldEntry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(field); + + Object record = fieldEntry.getVascFrontendData().getVascEntryState().getEntryDataObject(); + if (record==null) { + //System.out.println("could not get selected records from state."); + continue; + } + Object value = v.getValue(fieldOrg, record); + + //System.out.println("Set entry paras name: "+paraName+" value: "+value+" class: "+value.getClass().getName()); + state.setDataParameter(paraName, value); + } + + + // TODO: FIX >>>>>>>>>>>>>>>>>> + if (key.getVascEntryFieldValue()==null) { + // TODO: fix this for better remote support + VascEntryField fieldClone = key.clone(); + fieldClone.getVascValidators().clear(); + + VascEntryFieldValue v = currentEntry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(fieldClone); + key.setVascEntryFieldValue(v); + } + if (dis.getVascEntryFieldValue()==null) { + // TODO: fix this for better remote support + VascEntryField fieldClone = dis.clone(); + fieldClone.getVascValidators().clear(); + + VascEntryFieldValue v = currentEntry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(fieldClone); + dis.setVascEntryFieldValue(v); + } + + + // execute + for (Object o:back.execute(state)) { + Object keyId = key.getVascEntryFieldValue().getValue(key, o); + String nameId = dis.getVascEntryFieldValue().getDisplayValue(dis, o); + if (returnKeyValue!=null && true==returnKeyValue) { + VascSelectItem item = new VascSelectItem(nameId,keyId,""+keyId); + result.add(item); + } else { + VascSelectItem item = new VascSelectItem(nameId,o,""+keyId); + result.add(item); + } + } + } catch (Exception e) { + throw new VascException(e); + } + return result; + } + + /** + * @return the entryId + */ + public String getEntryId() { + return entryId; + } + + /** + * @param entryId the entryId to set + */ + public void setEntryId(String entryId) { + this.entryId = entryId; + } + + /** + * @return the keyFieldId + */ + public String getKeyFieldId() { + return keyFieldId; + } + + /** + * @param keyFieldId the keyFieldId to set + */ + public void setKeyFieldId(String keyFieldId) { + this.keyFieldId = keyFieldId; + } + + /** + * @return the displayFieldId + */ + public String getDisplayFieldId() { + return displayFieldId; + } + + /** + * @param displayFieldId the displayFieldId to set + */ + public void setDisplayFieldId(String displayFieldId) { + this.displayFieldId = displayFieldId; + } + + /** + * @return the nullLabel + */ + public String getNullLabel() { + return nullLabel; + } + + /** + * @param nullLabel the nullLabel to set + */ + public void setNullLabel(String nullLabel) { + this.nullLabel = nullLabel; + } + + /** + * @return the nullKeyValue + */ + public String getNullKeyValue() { + return nullKeyValue; + } + + /** + * @param nullKeyValue the nullKeyValue to set + */ + public void setNullKeyValue(String nullKeyValue) { + this.nullKeyValue = nullKeyValue; + } + + /** + * @return the returnKeyValue + */ + public Boolean getReturnKeyValue() { + return returnKeyValue; + } + + /** + * @param returnKeyValue the returnKeyValue to set + */ + public void setReturnKeyValue(Boolean returnKeyValue) { + this.returnKeyValue = returnKeyValue; + } + + public String getEntryParameterFieldId(String parameterName) { + return entryParameterFieldIds.get(parameterName); + } + public void addEntryParameterFieldId(String parameterName,String valueFieldId) { + entryParameterFieldIds.put(parameterName, valueFieldId); + } + public List getEntryParameterFieldIdKeys() { + return new ArrayList(entryParameterFieldIds.keySet()); + } + + /** + * @return the useParentFields + */ + public Boolean getUseParentFields() { + return useParentFields; + } + + /** + * @param useParentFields the useParentFields to set + */ + public void setUseParentFields(Boolean useParentFields) { + this.useParentFields = useParentFields; + } +} \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelStringEnum.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelStringEnum.java new file mode 100644 index 0000000..38deb48 --- /dev/null +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelStringEnum.java @@ -0,0 +1,146 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.impl.ui; + +import java.util.ArrayList; +import java.util.List; + +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.ui.VascSelectItem; +import net.forwardfire.vasc.core.ui.VascSelectItemModel; + + + + +/** +* The DefaultVascSelectItemModel +* +* @author Willem Cazander +* @version 1.0 Oct 27, 2007 +*/ +public class VascSelectItemModelStringEnum implements VascSelectItemModel { + + private static final long serialVersionUID = 1L; + private Object data = null; + private String nullLabel = null; + private String nullKeyValue = null; + private Boolean returnKeyValue = null; + private Boolean useParentFields = null; + + /** + * @see net.forwardfire.vasc.core.ui.VascSelectItemModel#getVascSelectItems(net.forwardfire.vasc.core.VascEntry) + */ + public List getVascSelectItems(VascEntry currentEntry) throws VascException { + List result = new ArrayList(100); + + if (data==null) { + return result; + } + if (data instanceof String) { + String[] values = ((String)data).split(","); + for (String value:values) { + result.add(new VascSelectItem(value,value,value)); + } + } else if (data instanceof List) { + List values = (List)data; + for (Object o:values) { + String value = ""+o; + result.add(new VascSelectItem(value,value,value)); + } + } + + return result; + } + + + /** + * @return the data + */ + public Object getData() { + return data; + } + + /** + * @param data the data to set + */ + public void setData(Object data) { + this.data = data; + } + + /** + * @return the nullLabel + */ + public String getNullLabel() { + return nullLabel; + } + + /** + * @param nullLabel the nullLabel to set + */ + public void setNullLabel(String nullLabel) { + this.nullLabel = nullLabel; + } + + /** + * @return the nullKeyValue + */ + public String getNullKeyValue() { + return nullKeyValue; + } + + /** + * @param nullKeyValue the nullKeyValue to set + */ + public void setNullKeyValue(String nullKeyValue) { + this.nullKeyValue = nullKeyValue; + } + + /** + * @return the returnKeyValue + */ + public Boolean getReturnKeyValue() { + return returnKeyValue; + } + + /** + * @param returnKeyValue the returnKeyValue to set + */ + public void setReturnKeyValue(Boolean returnKeyValue) { + this.returnKeyValue = returnKeyValue; + } + + /** + * @return the useParentFields + */ + public Boolean getUseParentFields() { + return useParentFields; + } + + /** + * @param useParentFields the useParentFields to set + */ + public void setUseParentFields(Boolean useParentFields) { + this.useParentFields = useParentFields; + } +} \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/AnnotationParserElement.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/AnnotationParserElement.java index 91b7835..5e90320 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/AnnotationParserElement.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/AnnotationParserElement.java @@ -325,23 +325,13 @@ public class AnnotationParserElement extends AbstractElement { // search for type if (methodCall!=null) { - Class retType = methodCall.getReturnType(); - + Class returnType = methodCall.getReturnType(); for (String typeId: vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeIds()) { VascEntryFieldType type = vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeById(typeId); - - //String auto = ""; - //if (type.getAutoDetectClass()!=null) { - // auto = type.getAutoDetectClass().getName(); - //} - //System.out.println("Check ret: "+retType.getName()+" type: "+type.getId()+" auto: "+auto); - - - if (type.getAutoDetectClass()!=null) { - if (type.getAutoDetectClass().isAssignableFrom(retType)) { - field.setVascEntryFieldType(type); - break; - } + Class autoClass = type.getAutoDetectClass(); + if (autoClass!=null && autoClass.isAssignableFrom(returnType)) { + field.setVascEntryFieldType(type); + break; } } } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascBackendElementConfigurator.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascBackendElementConfigurator.java index b3a4150..7e6a6de 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascBackendElementConfigurator.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascBackendElementConfigurator.java @@ -23,9 +23,9 @@ package net.forwardfire.vasc.impl.x4o; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendController; -import net.forwardfire.vasc.core.VascBackendControllerLocal; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendController; +import net.forwardfire.vasc.backend.VascBackendControllerLocal; import net.forwardfire.vasc.core.VascController; import org.x4o.xml.element.AbstractElementConfigurator; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldTypeAttributeConverter.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldConfigurator.java similarity index 64% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldTypeAttributeConverter.java rename to vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldConfigurator.java index 19d2292..c9e288d 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldTypeAttributeConverter.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldConfigurator.java @@ -22,36 +22,36 @@ package net.forwardfire.vasc.impl.x4o; - import net.forwardfire.vasc.core.VascController; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascEntryFieldType; -import org.x4o.xml.element.AbstractElementAttributeConverter; +import org.x4o.xml.element.AbstractElementConfigurator; import org.x4o.xml.element.Element; -import org.x4o.xml.element.ElementAttributeConverterException; +import org.x4o.xml.element.ElementConfiguratorException; /** - * Converts the type to the type object + * Maps the vasc * * @author Willem Cazander - * @version 1.0 Nov 16, 2008 + * @version 1.0 Jan 20, 2012 */ -public class VascEntryFieldTypeAttributeConverter extends AbstractElementAttributeConverter { - +public class VascEntryFieldConfigurator extends AbstractElementConfigurator { + /** - * @see org.x4o.xml.element.AbstractElementAttributeConverter#doConvertAttribute(org.x4o.xml.element.Element, java.lang.Object) + * @see org.x4o.xml.element.AbstractElementConfigurator#doConfigEndTag(org.x4o.xml.element.Element) */ - public Object doConvertAttribute(Element element, Object attributeValue) throws ElementAttributeConverterException { - if (attributeValue==null) { - throw new NullPointerException("can't convert null parameter"); + public void doConfigElement(Element element) throws ElementConfiguratorException { + String fieldID = element.getAttributes().get("vascEntryFieldType"); + if (fieldID==null) { + fieldID = ""; } - if ("".equals(attributeValue)) { - attributeValue = "TextField"; // ?? + if ("".equals(fieldID)) { + fieldID = "TextField"; // ?? } - String fieldID = attributeValue.toString(); - VascController controller = VascParser.getVascController(element.getElementContext()); - Object result = controller.getVascEntryFieldTypeController().getVascEntryFieldTypeById(fieldID); - return result; + VascEntryFieldType result = controller.getVascEntryFieldTypeController().getVascEntryFieldTypeById(fieldID); + ((VascEntryField)element.getElementObject()).setVascEntryFieldType(result); } } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldElement.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldElement.java index 4d29a40..1f1bc0f 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldElement.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldElement.java @@ -24,7 +24,6 @@ package net.forwardfire.vasc.impl.x4o; import java.util.logging.Logger; - import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; @@ -47,7 +46,7 @@ public class VascEntryFieldElement extends AbstractElement { * @see org.x4o.xml.element.AbstractElement#doElementRun() */ @Override - public void doElementRun() throws ElementException { + public void doElementRun() throws ElementException { String id = getAttributes().get("id"); VascEntry back = (VascEntry)getParent().getElementObject(); VascEntryField field = back.getVascEntryFieldById(id); diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldSetAttributeConverter.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldSetElement.java similarity index 72% rename from vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldSetAttributeConverter.java rename to vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldSetElement.java index 5de2118..36231da 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldSetAttributeConverter.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/x4o/VascEntryFieldSetElement.java @@ -25,9 +25,8 @@ package net.forwardfire.vasc.impl.x4o; import net.forwardfire.vasc.core.VascEntryFieldSet; -import org.x4o.xml.element.AbstractElementAttributeConverter; -import org.x4o.xml.element.Element; -import org.x4o.xml.element.ElementAttributeConverterException; +import org.x4o.xml.element.AbstractElement; +import org.x4o.xml.element.ElementException; /** @@ -36,25 +35,25 @@ import org.x4o.xml.element.ElementAttributeConverterException; * @author Willem Cazander * @version 1.0 Nov 17, 2008 */ -public class VascEntryFieldSetAttributeConverter extends AbstractElementAttributeConverter { +public class VascEntryFieldSetElement extends AbstractElement { /** - * @see org.x4o.xml.element.AbstractElementAttributeConverter#doConvertAttribute(org.x4o.xml.element.Element, java.lang.Object) + * @see org.x4o.xml.element.AbstractElement#doElementRun() */ - public Object doConvertAttribute(Element element, Object parameterValue) throws ElementAttributeConverterException { - + @Override + public void doElementRun() throws ElementException { + String parameterValue = getAttributes().get("vascEntryFieldIds"); if (parameterValue==null) { - throw new NullPointerException("can't convert null parameter"); + throw new ElementException("Must have vascEntryFieldIds attribute"); } if ("".equals(parameterValue)) { - return null; + throw new ElementException("Must have not empty vascEntryFieldIds attribute"); } String[] ids = parameterValue.toString().split(","); - VascEntryFieldSet set = (VascEntryFieldSet)element.getElementObject(); + VascEntryFieldSet set = (VascEntryFieldSet)getElementObject(); for (String id:ids) { set.addVascEntryFieldId(id); } - return null; } } \ No newline at end of file diff --git a/vasc-core/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld b/vasc-core/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld index 807c93a..e80ab3d 100644 --- a/vasc-core/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld +++ b/vasc-core/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld @@ -2,11 +2,15 @@ - + + + - + + + - + + + @@ -33,31 +35,23 @@ - - + + - + + + - + + - - - - - - - - - - - - + diff --git a/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.classpath b/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.classpath index 9cb821b..71a9d16 100644 --- a/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.classpath +++ b/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.classpath @@ -3,7 +3,11 @@ - + + + + + diff --git a/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.project b/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.project index 3d5a88f..2f745b9 100644 --- a/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.project +++ b/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.project @@ -5,6 +5,11 @@ + + org.eclipse.wst.common.project.facet.core.builder + + + org.eclipse.jdt.core.javabuilder @@ -20,10 +25,18 @@ + + org.eclipse.wst.validation.validationbuilder + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.m2e.core.maven2Nature org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature + org.eclipse.wst.common.project.facet.core.nature diff --git a/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.settings/org.eclipse.jdt.core.prefs b/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.settings/org.eclipse.jdt.core.prefs index 18b6a3b..4bc493a 100644 --- a/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.settings/org.eclipse.jdt.core.prefs +++ b/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,9 @@ -#Mon Mar 21 21:23:08 CET 2011 +#Sat Jan 14 05:41:29 CET 2012 eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.source=1.5 diff --git a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestTable.java b/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/SwingStartup.java similarity index 52% rename from vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestTable.java rename to vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/SwingStartup.java index fd0bb2f..621c0f1 100644 --- a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestTable.java +++ b/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/SwingStartup.java @@ -20,97 +20,115 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc; +package net.forwardfire.vasc.demo.swing; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; import java.io.FileOutputStream; import java.lang.reflect.Method; -import java.util.Locale; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendControllerLocal; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; + import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.core.VascEntryField; -import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.VascFrontendData; -import net.forwardfire.vasc.impl.DefaultVascBackedEntryFinalizer; +import net.forwardfire.vasc.frontends.swing.SwingVascFrontend; import net.forwardfire.vasc.impl.DefaultVascFactory; -import net.forwardfire.vasc.impl.DefaultVascFrontendData; -import net.forwardfire.vasc.impl.DefaultVascFrontendHelper; -import net.forwardfire.vasc.impl.VascBackendProxyPaged; -import net.forwardfire.vasc.impl.VascBackendProxySearch; -import net.forwardfire.vasc.impl.VascBackendProxySort; -import net.forwardfire.vasc.impl.actions.AddRowAction; -import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction; -import net.forwardfire.vasc.impl.actions.DeleteRowAction; -import net.forwardfire.vasc.impl.actions.EditRowAction; -import net.forwardfire.vasc.impl.actions.RefreshDataGlobalAction; -import net.forwardfire.vasc.impl.actions.XMLExportGlobalAction; import net.forwardfire.vasc.impl.x4o.VascParser; +public class SwingStartup { - -/** - * - * @author Willem Cazander - * @version 1.0 Aug 2, 2007 - */ -public class TestTable { + public static void main(String[] argu){ + JFrame.setDefaultLookAndFeelDecorated(false); + try { + VascEntry entry = getVascTable(); + + SwingStartup s = new SwingStartup(); + JFrame frame = s.viewEntry(entry); + + while (frame.isVisible()) { + Thread.sleep(100000); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public JFrame viewEntry(final VascEntry entry) throws Exception { + // get GUI + JFrame frame = new JFrame(); + frame.setTitle("Vasc Test - Swing - "+entry.getName()); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.setLocationRelativeTo(null); + + JMenuBar menubar = new JMenuBar(); + JMenu vascMenu = new JMenu("Vasc Entries"); + + for (final String id:entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryIds()) { + JMenuItem item = new JMenuItem(id); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + VascEntry ee = entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(id); + fill(ee,entry.getVascFrontendData().getVascController()); + viewEntry(ee); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + }); + vascMenu.add(item); + } + menubar.add(vascMenu); + frame.setJMenuBar(menubar); + + // define redering + JPanel panel = new JPanel(); + SwingVascFrontend render = new SwingVascFrontend(panel); + frame.add(panel); + + // render + render.initEntry(entry); + render.renderView(); + + // get data + entry.getVascFrontendData().getVascFrontendActions().refreshData(); + + // view + frame.pack(); + frame.setVisible(true); + + return frame; + } - static VascController getDefaultVascController() throws Exception { - VascController c = DefaultVascFactory.getDefaultVascController(1234L,"Nice UserName","user","role_admin"); - - // for test - TestModelVascDataSource backend = new TestModelVascDataSource(); - backend.setId("testBackend1"); - ((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backend); - - return c; - } + static public void fill(VascEntry entry,VascController vascController) { - - - VascFrontendData frontendData = DefaultVascFactory.getDefaultVascFrontendData(null); //DefaultVascFactory.getDefaultVascFrontendData("i18n.vasc", Locale.getDefault()); - frontendData.setVascController(vascController); - entry.setVascFrontendData(frontendData); - VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); - frontendData.getVascEntryState().setVascBackend(backend); - frontendData.getVascEntryState().setVascEntry(entry); - - - entry.addRowAction(new AddRowAction()); - entry.addRowAction(new EditRowAction()); - entry.addRowAction(new DeleteRowAction()); - - entry.addGlobalAction(new XMLExportGlobalAction()); - entry.addGlobalAction(new CSVExportGlobalAction()); - entry.addGlobalAction(new RefreshDataGlobalAction()); - - // hackje om deze manuale actions van i18n keys te voorzien; - // this is temp untill x4o templaing - DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer(); - try { - f.finalizeVascEntry(entry, vascController); - } catch (VascException e) { - e.printStackTrace(); - } + DefaultVascFactory.fillVascEntryFrontend(entry, vascController, DefaultVascFactory.getDefaultVascFrontendData(null)); + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(0); } static public VascEntry getVascTable() throws Exception { - VascController c = getDefaultVascController(); + VascController c = DefaultVascFactory.getDefaultVascController(2288L,"forwarddire.net","user","admin"); VascParser parser = new VascParser(c); File f = File.createTempFile("test-vasc", ".xml"); parser.setDebugOutputStream(new FileOutputStream(f)); - parser.parseResource("net/forwardfire/vasc/tables.xml"); + parser.parseResource("net/forwardfire/vasc/demo/swing/example/tables.xml"); - VascEntry entry = parser.getVascController().getVascEntryController().getVascEntryById("test1"); + DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) c.getVascEntryController(), c); + + VascEntry entry = parser.getVascController().getVascEntryController().getVascEntryById("users"); fill(entry,c); - return entry; } @@ -147,4 +165,4 @@ public class TestTable { } } } -} \ No newline at end of file +} diff --git a/vasc-demo/vasc-demo-swing/src/main/resources/net/forwardfire/vasc/demo/swing/example/tables.xml b/vasc-demo/vasc-demo-swing/src/main/resources/net/forwardfire/vasc/demo/swing/example/tables.xml new file mode 100644 index 0000000..3abcb5c --- /dev/null +++ b/vasc-demo/vasc-demo-swing/src/main/resources/net/forwardfire/vasc/demo/swing/example/tables.xml @@ -0,0 +1,263 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vasc-ejb3/.project b/vasc-ejb3/.project index 8e93fe2..d4d7137 100644 --- a/vasc-ejb3/.project +++ b/vasc-ejb3/.project @@ -21,12 +21,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/vasc-ejb3/src/main/java/net/forwardfire/vasc/ejb3/VascServiceManagerImpl.java b/vasc-ejb3/src/main/java/net/forwardfire/vasc/ejb3/VascServiceManagerImpl.java index d21e2d0..75a3d2e 100644 --- a/vasc-ejb3/src/main/java/net/forwardfire/vasc/ejb3/VascServiceManagerImpl.java +++ b/vasc-ejb3/src/main/java/net/forwardfire/vasc/ejb3/VascServiceManagerImpl.java @@ -22,10 +22,13 @@ package net.forwardfire.vasc.ejb3; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.ObjectOutputStream; import java.lang.reflect.Method; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; @@ -39,45 +42,26 @@ import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.ejb.Stateless; -import javax.el.ValueExpression; import javax.naming.InitialContext; import javax.persistence.EntityManager; - - - +import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.backends.jpa.EntityManagerProvider; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendControllerLocal; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; -import net.forwardfire.vasc.impl.DefaultVascBackedEntryFinalizer; -import net.forwardfire.vasc.impl.DefaultVascEntryController; +import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.impl.DefaultVascFactory; -import net.forwardfire.vasc.impl.VascBackendProxyEventExecutor; -import net.forwardfire.vasc.impl.actions.AddRowAction; -import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction; -import net.forwardfire.vasc.impl.actions.DeleteRowAction; -import net.forwardfire.vasc.impl.actions.EditRowAction; -import net.forwardfire.vasc.impl.actions.XMLExportGlobalAction; -import net.forwardfire.vasc.impl.entry.DefaultVascEntryResourceResolver; import net.forwardfire.vasc.impl.x4o.VascParser; import net.forwardfire.vasc.xpql.ejb3.XpqlQueryManager; import net.forwardfire.vasc.xpql.query.Query; -import org.x4o.xml.core.AbstractX4OPhaseHandler; -import org.x4o.xml.core.X4OPhase; -import org.x4o.xml.core.X4OPhaseException; -import org.x4o.xml.core.X4OPhaseHandler; -import org.x4o.xml.element.Element; -import org.x4o.xml.element.ElementContext; /** * * @author Willem Cazander * @version 1.0 13 Aug 2007 */ -@Stateless(name="ejb/vascSericeManager") +@Stateless(name="ejb/vascServiceManager") public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascServiceManager.ILocal { private Logger logger = Logger.getLogger(VascServiceManagerImpl.class.getName()); @@ -128,10 +112,13 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe String value = keys.get(key); if (key.startsWith("load")) { // TODO made reuse working. - new HackVascParser(c).parseResource(value); + VascParser vp = new VascParser(c); + vp.addGlobalELBean("xpqlController", new XpqlController()); + vp.addGlobalELBean("entityManagerProvider", new LocalEntityManagerProvider()); + vp.parseResource(value); } } - finalVascController(c); + DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) c.getVascEntryController(), c); sharedVascController = c; @@ -203,6 +190,9 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe public List getVascEntryIds() { VascController v = getVascController(); + if (v==null) { + return new ArrayList(0); + } return v.getVascEntryController().getVascEntryIds(); } @@ -212,16 +202,16 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe try { VascEntry result = ve.clone(); - //logger.info("Returning cloned ve."); - /* + logger.info("Returning cloned ve."); + ByteArrayOutputStream dataArray = new ByteArrayOutputStream(256); // it grows when needed ObjectOutputStream objOutstream = new ObjectOutputStream(dataArray); objOutstream.writeObject(ve); objOutstream.close(); int objectSize = dataArray.size(); - */ - //logger.info("Writing obj to data: "+objectSize); + + logger.info("Writing obj to data: "+objectSize); return result; } catch (CloneNotSupportedException e) { @@ -308,7 +298,7 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe } - class DatafeedsEntityManagerProvider implements EntityManagerProvider { + class LocalEntityManagerProvider implements EntityManagerProvider { /** * @see net.forwardfire.vasc.backends.jpa.EntityManagerProvider#getEntityManager() */ @@ -320,89 +310,4 @@ public class VascServiceManagerImpl implements VascServiceManager.IRemote,VascSe return false; } }; - - - class HackVascParser extends VascParser { - - public HackVascParser(VascController c) throws Exception { - super(c); - } - - @Override - protected X4OPhaseHandler getConfigOptionalPhase() { - final X4OPhaseHandler resultSuper = super.getConfigOptionalPhase(); - X4OPhaseHandler result = new AbstractX4OPhaseHandler() { - protected void setX4OPhase() { - phase = X4OPhase.configOptionalPhase; - } - @Override - public boolean isElementPhase() { - return false; - } - public void runElementPhase(Element element) throws X4OPhaseException { - } - public void runPhase(ElementContext elementContext) throws X4OPhaseException { - resultSuper.runPhase(elementContext); // this is needed !! - ValueExpression e1 = getElementContext().getExpressionFactory().createValueExpression(getElementContext().getELContext(),"${entityManagerProvider}", EntityManagerProvider.class); - e1.setValue(getElementContext().getELContext(), new DatafeedsEntityManagerProvider()); - - ValueExpression e2 = getElementContext().getExpressionFactory().createValueExpression(getElementContext().getELContext(),"${xpqlController}", XpqlController.class); - e2.setValue(getElementContext().getELContext(), new XpqlController()); - } - }; - return result; - } - } - - private void finalVascController(VascController c) { - try { - // fill stuff in all global entry'ies - for (String id:c.getVascEntryController().getVascEntryIds()) { - VascEntry entry = ((DefaultVascEntryController)c.getVascEntryController()).getRealVascEntryById(id); - if (entry.isVascDisplayOnly()==false) { - if (entry.isVascAdminCreate()) { - entry.addRowAction(new AddRowAction()); - } - if (entry.isVascAdminEdit()) { - entry.addRowAction(new EditRowAction()); - } - if (entry.isVascAdminDelete()) { - entry.addRowAction(new DeleteRowAction()); - } - } - entry.addGlobalAction(new XMLExportGlobalAction()); - entry.addGlobalAction(new CSVExportGlobalAction()); - //entry.addGlobalAction(new RefreshDataGlobalAction()); - - DefaultVascEntryResourceResolver t = new DefaultVascEntryResourceResolver(resourceBundle); - if (t.getTextValue(entry.getEditDescription()).equals(entry.getEditDescription())) { - entry.setEditDescription("generic.editDescription"); - } - if (t.getTextValue(entry.getDeleteDescription()).equals(entry.getDeleteDescription())) { - entry.setDeleteDescription("generic.deleteDescription"); - } - if (t.getTextValue(entry.getCreateDescription()).equals(entry.getCreateDescription())) { - entry.setCreateDescription("generic.createDescription"); - } - - // add global listener to make sure we have all LAZY properties of a bean before we goto edit mode. - //entry.addVascEntryEventListener(VascEventType.DATA_SELECT, new RefreshObjectForLazyPropertiesListener()); - - // hackje om deze manuale actions van i18n keys te voorzien; - // this is temp untill x4o templaing - DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer(); - f.finalizeVascEntry(entry, c); - - // execute backend event listeners - VascBackend vb = c.getVascBackendController().getVascBackendById(entry.getBackendId()); - vb = new VascBackendProxyEventExecutor(vb,entry); - ((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(vb); - } - - logger.finer("Done final config vascController: "+c); - } catch (Exception e) { - throw new RuntimeException(e); - } - - } } \ No newline at end of file diff --git a/vasc-frontend/vasc-frontend-swing/pom.xml b/vasc-frontend/vasc-frontend-swing/pom.xml index bbddea5..0507172 100644 --- a/vasc-frontend/vasc-frontend-swing/pom.xml +++ b/vasc-frontend/vasc-frontend-swing/pom.xml @@ -35,6 +35,12 @@ juel ${juel.version} test + + + net.forwardfire.vasc + vasc-test-frontend-data + ${project.version} + test \ No newline at end of file diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingActionPanel.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingActionPanel.java new file mode 100644 index 0000000..162e83a --- /dev/null +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingActionPanel.java @@ -0,0 +1,283 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.frontends.swing; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.ListCellRenderer; + +import net.forwardfire.vasc.backend.VascBackendPageNumber; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.actions.GlobalVascAction; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; + +/** + * SwingActionPanel renders some page and download actions. + * + * @author Willem Cazander + * @version 1.0 Jan 20, 2012 + */ +public class SwingActionPanel extends JPanel implements VascEntryFrontendEventListener,ActionListener { + + private static final long serialVersionUID = -6935210323705891740L; + private VascEntry vascEntry = null; + private JTextField rowNumberField = null; + private JComboBox gotoDirectPage = null; + private JComboBox gotoDownload = null; + private JLabel resultLabel = null; + private boolean init = false; + + public SwingActionPanel(VascEntry vascEntry) { + + this.vascEntry=vascEntry; + + JPanel result = this; //new JPanel(); + //result.setBackground(Color.pink); + //result.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + + result.add(new JLabel("Row Numbers: ")); + rowNumberField = new JTextField(6); + rowNumberField.addActionListener(this); + rowNumberField.setText(""+vascEntry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize()); + result.add(rowNumberField); + result.add(new JLabel("Go to: ")); + gotoDirectPage = new JComboBox(); + gotoDirectPage.addActionListener(this); + result.add(gotoDirectPage); + result.add(new JLabel("Download: ")); + gotoDownload = new JComboBox(); + gotoDownload.addActionListener(this); + gotoDownload.setRenderer(new DownloadListCellRenderer()); + result.add(gotoDownload); + + resultLabel = new JLabel(" "); + result.add(resultLabel); + + //add(result); + + vascEntry.getVascFrontendData().addVascEntryFrontendEventListener(this); + } + + class DownloadListCellRenderer extends JLabel implements ListCellRenderer { + private static final long serialVersionUID = -2143588238414900498L; + public Component getListCellRendererComponent(JList list, Object value,int index, boolean isSelected, boolean hasFocus) { + if (value==null) { + setText("null"); + } else { + setText(((GlobalVascAction)value).getName()); + } + return this; + } + } + + + public void actionPerformed(ActionEvent event) { + if (init) { + return; + } + if (rowNumberField.equals(event.getSource())) { + int pageSize = new Integer(rowNumberField.getText()); + vascEntry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(pageSize); + vascEntry.getVascFrontendData().getVascFrontendActions().refreshData(); + } + if (gotoDirectPage.equals(event.getSource())) { + if (gotoDirectPage.getSelectedIndex()==0) { + return; + } + vascEntry.getVascFrontendData().getVascFrontendActions().pageAction(gotoDirectPage.getSelectedIndex() - 1); + gotoDirectPage.setSelectedIndex(0); + } + if (gotoDownload.equals(event.getSource())) { + GlobalVascAction action = (GlobalVascAction)gotoDownload.getSelectedItem(); + if (action==null) { + return; + } + String id = (String)action.getId(); + if (id==null) { + return; + } + if ("null".equals(id)) { + return; + } + try { + action.doGlobalAction(vascEntry); + } catch (Exception e) { + vascEntry.getVascFrontendData().getVascFrontendHelper().handleException(vascEntry, e); + } + + // restore normal view for next request. + /* + comp.setRenderFacetState("listView"); + VascEntryExporter ex = getSelectedExporter(); + + if (ex==null) { + logger.fine("No exporter selected for download."); + return; + } + */ + gotoDownload.setSelectedIndex(0); + } + } + + + /** + * @see net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener#getEventTypes() + */ + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ}; + return result; + } + + public void vascEvent(VascEntry entry,Object dataNotUsed) { + + init = true; + + long pageSize = entry.getVascFrontendData().getVascFrontendPager().getPageSize(); + long pageStart = entry.getVascFrontendData().getVascFrontendPager().getPageStartCount(); + long pageStop = entry.getVascFrontendData().getVascFrontendPager().getPageStopCount(); + long pageTotalCount = entry.getVascFrontendData().getVascFrontendPager().getPageTotalRecordCount(); + String format = "Results %1$d-%2$d from %3$d rows"; + resultLabel.setText(String.format(format, pageStart, pageStop, pageTotalCount)); + rowNumberField.setText(""+pageSize); + + gotoDirectPage.removeAllItems(); + gotoDirectPage.addItem("Goto..."); + + List pages = vascEntry.getVascFrontendData().getVascFrontendPager().getTablePagesFromBackend(); + int i=0; + for (VascBackendPageNumber page:pages) { + //pages.setRowIndex(i); + //VascBackendPageNumber page = (VascBackendPageNumber)getTablePagesDataModel().getRowData(); + // = new SelectItem(); + //String name = i18nMap.get("generic.vasc.jsf.table.page.name"); + //String description = i18nMap.get("generic.vasc.jsf.table.page.description"); + /* + s.setLabel(name+page.getPageNumber()+" "+(i*pageSize)+"-"+((i*pageSize)+pageSize)); + s.setDescription(description+page.getPageNumber()); + s.setValue(page.getPageNumber()); + result.add(s); + */ + //if (page.getSelected()) { + // setSelectedItem(arg0) + // } + gotoDirectPage.addItem("page: "+page.getPageNumber()+" "+(i*pageSize)+"-"+((i*pageSize)+pageSize)); + i++; + } + + + /* + SelectItem s = new SelectItem(); + s.setLabel(i18nMap.get("generic.vasc.jsf.table.export.select")); + s.setDescription(i18nMap.get("generic.vasc.jsf.table.export.select.alt")); + s.setValue("null"); + result.add(s);*/ + gotoDownload.removeAllItems(); + + GlobalVascAction empty = new GlobalVascAction() { + + public void setName(String name) { + // TODO Auto-generated method stub + + } + + public void setImage(String image) { + // TODO Auto-generated method stub + + } + + public void setId(String id) { + // TODO Auto-generated method stub + + } + + public void setHelpId(String helpId) { + // TODO Auto-generated method stub + + } + + public void setDescription(String description) { + // TODO Auto-generated method stub + + } + + public String getName() { + return "..."; + } + + public String getImage() { + // TODO Auto-generated method stub + return null; + } + + public String getId() { + // TODO Auto-generated method stub + return null; + } + + public String getHelpId() { + // TODO Auto-generated method stub + return null; + } + + public String getDescription() { + // TODO Auto-generated method stub + return null; + } + + public void doGlobalAction(VascEntry vascEntry) throws Exception { + // TODO Auto-generated method stub + } + + public GlobalVascAction clone() { + return this; + } + }; + empty.setName("..."); + gotoDownload.addItem(empty); + + for (GlobalVascAction a:entry.getGlobalActions()) { + if (a.getId().contains("xport")) { + //s = new SelectItem(); + //s.setLabel(i18nMap.get(a.getName())); + //s.setDescription(i18nMap.get(a.getDescription())); + //s.setValue(a.getId()); + //result.add(s); + gotoDownload.addItem(a); + } + } + + + init = false; + } + + + +} diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPagerPanel.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPagerPanel.java new file mode 100644 index 0000000..4e048b2 --- /dev/null +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPagerPanel.java @@ -0,0 +1,164 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.frontends.swing; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import net.forwardfire.vasc.backend.VascBackendPageNumber; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; + +/** + * SwingPagerPanel renders dynamic pager for swing. + * + * @author Willem Cazander + * @version 1.0 Jan 21, 2012 + */ +public class SwingPagerPanel extends JPanel implements VascEntryFrontendEventListener,ActionListener { + + private static final long serialVersionUID = 2651163640840746196L; + private VascEntry vascEntry = null; + private JPanel result = null; + + public SwingPagerPanel(VascEntry vascEntry) { + this.vascEntry=vascEntry; + //result = this; + result = new JPanel(); + // result.setBackground(Color.green); + //result.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + + + add(result); + vascEntry.getVascFrontendData().addVascEntryFrontendEventListener(this); + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() instanceof JButton) { + JButton but = (JButton)e.getSource(); + Integer page = new Integer(but.getText()); + vascEntry.getVascFrontendData().getVascFrontendActions().pageAction(page); + } + } + + class NextAction implements ActionListener { + boolean next = true; + public NextAction(boolean next) { + this.next=next; + } + public void actionPerformed(ActionEvent e) { + int pageIndex = vascEntry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); + if (next) { + if (vascEntry.getVascFrontendData().getVascFrontendPager().getHasPageNextAction()) { + vascEntry.getVascFrontendData().getVascFrontendActions().pageAction(pageIndex+1); + } + } else { + if (vascEntry.getVascFrontendData().getVascFrontendPager().getHasPagePreviousAction()) { + vascEntry.getVascFrontendData().getVascFrontendActions().pageAction(pageIndex-1); + } + } + } + } + + public void vascEvent(VascEntry entry, Object data) { + + for(Component c:result.getComponents()) { + if (c instanceof JButton) { + ((JButton)c).removeActionListener(this); + } + } + result.removeAll(); + + + if (entry.getVascFrontendData().getVascFrontendPager().getHasExtendedPageMode()) { + JButton prev = new JButton("Previous"); + prev.addActionListener(new NextAction(false)); + prev.setEnabled(entry.getVascFrontendData().getVascFrontendPager().getHasPagePreviousAction()); + result.add(prev); + List pages = entry.getVascFrontendData().getVascFrontendPager().getTablePagesExtendedBegin(); + for(VascBackendPageNumber page:pages) { + JButton but = new JButton(""+page.getPageNumber()); + but.addActionListener(this); + if (page.getSelected()!=null && page.getSelected()) { + but.setEnabled(false); + } + result.add(but); + } + result.add(new JLabel("...")); + if (entry.getVascFrontendData().getVascFrontendPager().getHasExtendedPageModeCenter()) { + pages = entry.getVascFrontendData().getVascFrontendPager().getTablePagesExtendedCenter(); + for(VascBackendPageNumber page:pages) { + JButton but = new JButton(""+page.getPageNumber()); + but.addActionListener(this); + if (page.getSelected()!=null && page.getSelected()) { + but.setEnabled(false); + } + result.add(but); + } + result.add(new JLabel("...")); + } + pages = entry.getVascFrontendData().getVascFrontendPager().getTablePagesExtendedEnd(); + for(VascBackendPageNumber page:pages) { + JButton but = new JButton(""+page.getPageNumber()); + but.addActionListener(this); + if (page.getSelected()!=null && page.getSelected()) { + but.setEnabled(false); + } + result.add(but); + } + JButton next = new JButton("Next"); + next.setEnabled(entry.getVascFrontendData().getVascFrontendPager().getHasPageNextAction()); + next.addActionListener(new NextAction(true)); + result.add(next); + } else { + JButton prev = new JButton("Previous"); + prev.addActionListener(new NextAction(false)); + prev.setEnabled(entry.getVascFrontendData().getVascFrontendPager().getHasPagePreviousAction()); + result.add(prev); + List pages = entry.getVascFrontendData().getVascFrontendPager().getTablePagesNormal(); + for(VascBackendPageNumber page:pages) { + JButton but = new JButton(""+page.getPageNumber()); + but.addActionListener(this); + if (page.getSelected()!=null && page.getSelected()) { + but.setEnabled(false); + } + result.add(but); + } + JButton next = new JButton("Next"); + next.setEnabled(entry.getVascFrontendData().getVascFrontendPager().getHasPageNextAction()); + next.addActionListener(new NextAction(true)); + result.add(next); + } + } + + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ}; + return result; + } +} diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascEditDialog.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascEditDialog.java new file mode 100644 index 0000000..965f6a8 --- /dev/null +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascEditDialog.java @@ -0,0 +1,176 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.frontends.swing; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SpringLayout; + +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.ui.VascColumnValueModelListener; +import net.forwardfire.vasc.core.ui.VascUIComponent; +import net.forwardfire.vasc.core.ui.VascValueModel; + +/** + * SwingVascEditDialog renders vasc entry edit dialog + * + * @author Willem Cazander + * @version 1.0 Mar 21, 2007 + */ +public class SwingVascEditDialog extends JDialog { + + private static final long serialVersionUID = 10L; + private String headerText = null; + private String headerTextValue = null; + private Object result = null; + private Object bean = null; + private VascEntry entry = null; + private SwingVascFrontend swingFrontend = null; + + public SwingVascEditDialog(SwingVascFrontend swingFrontend,JComponent parent,VascEntry entry,Object bean,String beanValue) throws Exception { + super(); + this.headerText = "vasc.dialog.edit.message"; + this.headerTextValue = beanValue; + this.bean = bean; + this.entry = entry; + this.swingFrontend=swingFrontend; + + setTitle(swingFrontend.i18n("vasc.dialog.edit.title")); + setModal(true); + + JPanel pane = new JPanel(); + pane.setLayout(new BorderLayout()); + + JPanel header = new JPanel(); + createHeader(header); + pane.add(header,BorderLayout.NORTH); + + JPanel body = new JPanel(); + createBody(body); + pane.add(body,BorderLayout.CENTER); + + JPanel footer = new JPanel(); + createFooter(footer); + pane.add(footer,BorderLayout.SOUTH); + + add(pane); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + + //Ensure the text field always gets the first focus. + //addComponentListener(new ComponentAdapter() { + // public void componentShown(ComponentEvent ce) { + // textField.requestFocusInWindow(); + // } + /// }); + + pack(); + setLocationRelativeTo(parent); + setResizable(false); + } + + + public Object openDialog() { + setVisible(true); + return result; + } + + public void createHeader(JPanel header) { + JLabel l = new JLabel(); + l.setText(swingFrontend.i18n(headerText,headerTextValue)); + l.setFont(new Font(null,Font.BOLD, 14)); + //l.setToolTipText(i18n(headerText)); + header.add(l); + } + + public void createBody(JPanel body) throws Exception { + body.setLayout(new SpringLayout()); + int column = 0; + for (VascEntryField c:entry.getVascEntryFields()) { + if (c.getEdit()==false) { + continue; + } + + //if (c.isEditReadOnly()==true) { + + for (int i=0;i list = new ArrayList(); + for(VascEntryField c:entry.getVascEntryFields()) { + if (c.getList()==false) { + continue; + + } + list.add(c); + } + + VascEntryField vtc = list.get(columnIndex); + try { + //if (vtc.getVascColumnRenderer()!=null) { +// return vtc.getVascColumnRenderer().rendererColumn(vtc,bean); + //} else { + return ""+vtc.getVascEntryFieldValue().getValue(vtc,bean); + // } + } catch (Exception e) { + return "Error"; + } + } + + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascFrontendEventType.POST_UPDATE,VascFrontendEventType.POST_READ}; + return result; + } +} diff --git a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTest.java b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTest.java index 261254d..0f79fec 100644 --- a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTest.java +++ b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTest.java @@ -31,8 +31,12 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; +import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.frontends.swing.SwingVascFrontend; +import net.forwardfire.vasc.impl.DefaultVascFactory; +import net.forwardfire.vasc.test.frontend.data.TestModelEntry; @@ -46,6 +50,8 @@ import junit.framework.TestCase; */ public class SwingTest extends TestCase { + private TestModelEntry entry = null; + public void setUp() throws Exception { // enable all logs //InputStream loggingProperties = this.getClass().getResourceAsStream("META-INF/logging.properties"); @@ -62,19 +68,32 @@ public class SwingTest extends TestCase { } public static void main(String[] argu){ - JFrame.setDefaultLookAndFeelDecorated(false); - try { - VascEntry entry = TestTable.getVascTable(); - + JFrame.setDefaultLookAndFeelDecorated(false); SwingTest s = new SwingTest(); - JFrame frame = s.viewEntry(entry); + try { + s.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void open() throws Exception { + + entry = new TestModelEntry(); + VascController vc = entry.getTestVascController(); + + VascEntry ve = entry.createVascEntry(vc); + + ((VascEntryControllerLocal)vc.getVascEntryController()).addVascEntry(ve,vc); + DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vc.getVascEntryController(), vc); + + DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null)); + + JFrame frame = viewEntry(ve); while (frame.isVisible()) { - Thread.sleep(100000); - } - } catch (Exception e) { - e.printStackTrace(); - } + Thread.sleep(1000); + } } public JFrame viewEntry(final VascEntry entry) throws Exception { @@ -93,7 +112,7 @@ public class SwingTest extends TestCase { public void actionPerformed(ActionEvent e) { try { VascEntry ee = entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(id); - TestTable.fill(ee,entry.getVascFrontendData().getVascController()); + //TestModelEntry.fill(ee,entry.getVascFrontendData().getVascController()); viewEntry(ee); } catch (Exception e1) { e1.printStackTrace(); @@ -116,7 +135,7 @@ public class SwingTest extends TestCase { render.renderView(); // get data - entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + entry.getVascFrontendData().getVascFrontendActions().refreshData(); // view frame.pack(); diff --git a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestModelVascDataSource.java b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestModelVascDataSource.java deleted file mode 100644 index 28cb38c..0000000 --- a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestModelVascDataSource.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2007-2012 forwardfire.net All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package net.forwardfire.vasc; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import net.forwardfire.vasc.core.AbstractVascBackend; -import net.forwardfire.vasc.core.VascBackendState; -import net.forwardfire.vasc.core.VascEntry; -import net.forwardfire.vasc.core.VascEntryField; -import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.entry.VascEntryFieldValue; -import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; -import net.forwardfire.vasc.core.ui.VascSelectItem; -import net.forwardfire.vasc.core.ui.VascSelectItemModel; -import net.forwardfire.vasc.impl.entry.BeanPropertyVascEntryFieldValue; -import net.forwardfire.vasc.impl.entry.BeanVascEntryRecordCreator; - - - -/** - * - * @author Willem Cazander - * @version 1.0 Mar 21, 2007 - */ -public class TestModelVascDataSource extends AbstractVascBackend implements VascSelectItemModel { - - private List testModels = null; - private String nullLabel = null; - private String nullKeyValue = null; - - public TestModelVascDataSource() { - testModels = new ArrayList(2); - - TestModel t = new TestModel(); - t.setDate(new Date()); - t.setDescription("yoyo test"); - t.setName("this Name"); - t.setPrice(34.1f); - t.setActive(true); - t.setHexColor("#FF66EE"); - testModels.add(t); - - t = new TestModel(); - t.setDate(new Date()); - t.setDescription("Model2 test"); - t.setName("BeanSourde"); - t.setPrice(19.2f); - t.setActive(false); - t.setTestModel((TestModel)testModels.get(0)); - testModels.add(t); - } - public TestModelVascDataSource(List testModels) { - this.testModels=testModels; - } - - public List execute(VascBackendState state) throws VascException { - return testModels; - } - - public void persist(Object object) throws VascException { - testModels.add(object); - } - - public Object merge(Object object) throws VascException { - if(testModels.contains(object)==false) { - testModels.add(object); - } - return object; - } - - public void delete(Object object) throws VascException { - testModels.remove(object); - } - - public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - return new BeanPropertyVascEntryFieldValue(field.getBackendName()); - } - - public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return new BeanVascEntryRecordCreator(TestModel.class); - } - - // --- VascSelectItemModel interface - - public List getVascSelectItems(VascEntry entry) { - List res = new ArrayList(4); - for (Object o:testModels) { - TestModel t = (TestModel)o; - VascSelectItem i = new VascSelectItem(t.getName(),t); - res.add(i); - } - return res; - } - - /** - * @return the nullLabel - */ - public String getNullLabel() { - return nullLabel; - } - - /** - * @param nullLabel the nullLabel to set - */ - public void setNullLabel(String nullLabel) { - this.nullLabel = nullLabel; - } - - /** - * @return the nullKeyValue - */ - public String getNullKeyValue() { - return nullKeyValue; - } - - /** - * @param nullKeyValue the nullKeyValue to set - */ - public void setNullKeyValue(String nullKeyValue) { - this.nullKeyValue = nullKeyValue; - } -} \ No newline at end of file diff --git a/vasc-frontend/vasc-frontend-swt/pom.xml b/vasc-frontend/vasc-frontend-swt/pom.xml index 9f52458..9cd2d9f 100644 --- a/vasc-frontend/vasc-frontend-swt/pom.xml +++ b/vasc-frontend/vasc-frontend-swt/pom.xml @@ -64,8 +64,12 @@ ${project.version} test - - + + net.forwardfire.vasc + vasc-test-frontend-data + ${project.version} + test + diff --git a/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtActionPanel.java b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtActionPanel.java new file mode 100644 index 0000000..88d6d3c --- /dev/null +++ b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtActionPanel.java @@ -0,0 +1,154 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.frontends.swt; + +import java.util.List; + +import net.forwardfire.vasc.backend.VascBackendPageNumber; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.actions.GlobalVascAction; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; +import net.forwardfire.vasc.core.ui.VascSelectItem; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * SwtActionPanel renders action bar + * + * @author Willem Cazander + * @version 1.0 May 13, 2009 + */ +public class SwtActionPanel implements VascEntryFrontendEventListener { + + private static final long serialVersionUID = 3747573488962487970L; + private VascEntry entry = null; + private Text rowNumberField = null; + private Combo pageBox = null; + private Combo downloadBox = null; + private Label resultLabel = null; + private boolean vascEvent = false; + + public SwtActionPanel(VascEntry entry) { + this.entry=entry; + entry.getVascFrontendData().addVascEntryFrontendEventListener(this); + } + + public void createComposite(Composite parent) { + Composite actionRow = new Composite(parent, SWT.NONE); + GridLayout bodyLayout = new GridLayout(); + bodyLayout.numColumns = 8; + actionRow.setLayout(bodyLayout); + actionRow.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + //actionRow.setBackground(c); + + Label l = new Label(actionRow, SWT.CENTER); + l.setText("Row Numbers"); + rowNumberField = new Text(actionRow, SWT.NONE | SWT.BORDER); + rowNumberField.setText(""+entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize()+" "); + rowNumberField.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent arg0) { + if (vascEvent) { + return; + } + int pageSize = new Integer(rowNumberField.getText()); + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(pageSize); + entry.getVascFrontendData().getVascFrontendActions().refreshData(); + + } + }); + + l = new Label(actionRow, SWT.CENTER); + l.setText("Goto: "); + pageBox = new Combo(actionRow,SWT.SINGLE | SWT.BORDER); + pageBox.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + entry.getVascFrontendData().getVascFrontendActions().pageAction(pageBox.getSelectionIndex()-1); + pageBox.select(0); + } + }); + + l = new Label(actionRow, SWT.CENTER); + l.setText("Download: "); + downloadBox = new Combo(actionRow,SWT.SINGLE | SWT.BORDER); + downloadBox.add("..."); + for (GlobalVascAction a:entry.getGlobalActions()) { + if (a.getId().contains("xport")) { + downloadBox.add(a.getName()); + } + } + downloadBox.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + + downloadBox.select(0); + } + }); + + resultLabel = new Label(actionRow, SWT.CENTER); + resultLabel.setText("Result......................................"); + } + + + /** + * @see net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener#getEventTypes() + */ + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ}; + return result; + } + + public void vascEvent(VascEntry entry,Object dataNotUsed) { + vascEvent = true; + + long pageSize = entry.getVascFrontendData().getVascFrontendPager().getPageSize(); + long pageStart = entry.getVascFrontendData().getVascFrontendPager().getPageStartCount(); + long pageStop = entry.getVascFrontendData().getVascFrontendPager().getPageStopCount(); + long pageTotalCount = entry.getVascFrontendData().getVascFrontendPager().getPageTotalRecordCount(); + String format = "Results %1$d-%2$d from %3$d rows"; + resultLabel.setText(String.format(format, pageStart, pageStop, pageTotalCount)); + resultLabel.redraw(); + rowNumberField.setText(""+pageSize); + rowNumberField.redraw(); + + pageBox.removeAll(); + pageBox.add("Goto..."); + List pages = entry.getVascFrontendData().getVascFrontendPager().getTablePagesFromBackend(); + int i=0; + for (VascBackendPageNumber page:pages) { + pageBox.add("page: "+page.getPageNumber()+" "+(i*pageSize)+"-"+((i*pageSize)+pageSize)); + i++; + } + + vascEvent = false; + } +} diff --git a/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtPagerPanel.java b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtPagerPanel.java new file mode 100644 index 0000000..666f9d0 --- /dev/null +++ b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtPagerPanel.java @@ -0,0 +1,82 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.frontends.swt; + +import java.util.List; + +import net.forwardfire.vasc.backend.VascBackendPageNumber; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.actions.GlobalVascAction; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Text; + +/** + * SwtPagerPanel renders pager bar + * + * @author Willem Cazander + * @version 1.0 May 13, 2009 + */ +public class SwtPagerPanel implements VascEntryFrontendEventListener { + + private static final long serialVersionUID = 3747573488962487970L; + private VascEntry entry = null; + + public SwtPagerPanel(VascEntry entry) { + this.entry=entry; + entry.getVascFrontendData().addVascEntryFrontendEventListener(this); + } + + public void createComposite(Composite parent) { + Composite actionRow = new Composite(parent, SWT.NONE); + GridLayout bodyLayout = new GridLayout(); + bodyLayout.numColumns = 1; + actionRow.setLayout(bodyLayout); + actionRow.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + //actionRow.setBackground(c); + + Label l = new Label(actionRow, SWT.CENTER); + l.setText("Pagers"); + } + + + /** + * @see net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener#getEventTypes() + */ + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.POST_READ}; + return result; + } + + public void vascEvent(VascEntry entry,Object dataNotUsed) { + + } +} diff --git a/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascEditDialog.java b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascEditDialog.java index 2a8862a..6973846 100644 --- a/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascEditDialog.java +++ b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascEditDialog.java @@ -47,6 +47,7 @@ import org.eclipse.swt.widgets.Shell; /** + * SwtVascEditDialog renders swt edit dialog * * @author Willem Cazander * @version 1.0 May 13, 2009 @@ -206,7 +207,7 @@ public class SwtVascEditDialog extends Dialog { if (error) { return; } - entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry); + entry.getVascFrontendData().getVascFrontendActions().mergeObject(); shell.dispose(); } catch (Exception ee) { ee.printStackTrace(); diff --git a/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascFrontend.java b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascFrontend.java index 6e1fef9..0ead43a 100644 --- a/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascFrontend.java +++ b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascFrontend.java @@ -27,20 +27,19 @@ import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; -import net.forwardfire.vasc.core.AbstractVascFrontend; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.VascFrontendData; import net.forwardfire.vasc.core.actions.GlobalVascAction; import net.forwardfire.vasc.core.actions.RowVascAction; import net.forwardfire.vasc.core.entry.VascEntryExporter; import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; -import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; import net.forwardfire.vasc.core.ui.VascOptionValueModelListener; import net.forwardfire.vasc.core.ui.VascUIComponent; import net.forwardfire.vasc.core.ui.VascValueModel; import net.forwardfire.vasc.core.ui.VascValueModelListener; +import net.forwardfire.vasc.frontend.AbstractVascFrontend; +import net.forwardfire.vasc.frontend.VascFrontendData; import net.forwardfire.vasc.frontends.swt.ui.SwtBoolean; import net.forwardfire.vasc.frontends.swt.ui.SwtButton; import net.forwardfire.vasc.frontends.swt.ui.SwtLabel; @@ -86,6 +85,7 @@ import org.eclipse.swt.widgets.ToolItem; /** + * SwtVascFrontend Vasc swt frontend. * * @author Willem Cazander * @version 1.0 Mar 21, 2007 @@ -95,6 +95,7 @@ public class SwtVascFrontend extends AbstractVascFrontend { private Logger logger = null; private Composite parent = null; private boolean renderGlobalActions = true; + private boolean initOnce = false; public SwtVascFrontend(Composite parent) { logger = Logger.getLogger(SwtVascFrontend.class.getName()); @@ -102,7 +103,7 @@ public class SwtVascFrontend extends AbstractVascFrontend { } /** - * @see net.forwardfire.vasc.core.VascFrontend#getFrontendType() + * @see net.forwardfire.vasc.frontend.VascFrontend#getFrontendType() */ public String getFrontendType() { return "swt"; @@ -193,7 +194,7 @@ public class SwtVascFrontend extends AbstractVascFrontend { return; } // yes - entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); + entry.getVascFrontendData().getVascFrontendActions().deleteObject(); } private boolean askDelete(Shell shell) { @@ -209,6 +210,10 @@ public class SwtVascFrontend extends AbstractVascFrontend { } public void renderView() throws Exception { + if (initOnce) { + return; + } + GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; @@ -235,6 +240,8 @@ public class SwtVascFrontend extends AbstractVascFrontend { createHeader(header); createBody(body); createFooter(footer); + + initOnce = true; } @@ -325,7 +332,7 @@ public class SwtVascFrontend extends AbstractVascFrontend { model.setValue(null); model.addListener(new VascValueModelListener() { public void valueUpdate(VascValueModel model) throws VascException { - entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);// mm + entry.getVascFrontendData().getVascFrontendActions().refreshData();// mm } }); Object edit = editor.createComponent(entry,option,model,headerOptions); @@ -351,15 +358,21 @@ public class SwtVascFrontend extends AbstractVascFrontend { public void modifyText(ModifyEvent e) { String value = text.getText(); try { - entry.getVascFrontendData().getVascFrontendHelper().searchAction(entry, value); + entry.getVascFrontendData().getVascFrontendActions().searchAction(value); } catch (Exception ee) { entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee); } } }); + + SwtPagerPanel pagerBar = new SwtPagerPanel(entry); + pagerBar.createComposite(header); + + SwtActionPanel actionBar = new SwtActionPanel(entry); + actionBar.createComposite(header); entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry); - + } catch (Exception e) { e.printStackTrace(); } @@ -440,7 +453,7 @@ public class SwtVascFrontend extends AbstractVascFrontend { } table2.setSortDirection(dir); VascEntryField field = (VascEntryField)currentColumn.getData(); - entry.getVascFrontendData().getVascFrontendHelper().sortAction(entry, field); + entry.getVascFrontendData().getVascFrontendActions().sortAction(field); } }; @@ -529,6 +542,13 @@ public class SwtVascFrontend extends AbstractVascFrontend { public void createFooter(Composite footer) { logger.finest("Creating footer"); + + SwtActionPanel p = new SwtActionPanel(entry); + p.createComposite(footer); + + SwtPagerPanel pagerBar = new SwtPagerPanel(entry); + pagerBar.createComposite(footer); + for( RowVascAction action:entry.getRowActions()) { if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) { continue; diff --git a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/SWTTest.java b/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/SWTTest.java index a2e9213..2bf9d72 100644 --- a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/SWTTest.java +++ b/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/SWTTest.java @@ -22,11 +22,13 @@ package net.forwardfire.vasc; -import java.io.InputStream; -import java.util.logging.LogManager; +import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.frontends.swt.SwtVascFrontend; +import net.forwardfire.vasc.impl.DefaultVascFactory; +import net.forwardfire.vasc.test.frontend.data.TestModelEntry; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -43,13 +45,9 @@ import junit.framework.TestCase; */ public class SWTTest extends TestCase { + private TestModelEntry entry = null; + public void setUp() throws Exception { - // enable all logs - //InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties"); - //LogManager.getLogManager().readConfiguration( loggingProperties ); - //loggingProperties.close(); - - // load xtes queries } public void tearDown() throws Exception { @@ -72,10 +70,15 @@ public class SWTTest extends TestCase { // define redering and render SwtVascFrontend render = new SwtVascFrontend(shell); + entry = new TestModelEntry(); + VascController vc = entry.getTestVascController(); + VascEntry ve = entry.createVascEntry(vc); + ((VascEntryControllerLocal)vc.getVascEntryController()).addVascEntry(ve,vc); + DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vc.getVascEntryController(), vc); + DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null)); - VascEntry entry = TestTable.getVascTable(); - entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); - render.initEntry(entry); + ve.getVascFrontendData().getVascFrontendActions().refreshData(); + render.initEntry(ve); render.renderView(); // view diff --git a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestModel.java b/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestModel.java deleted file mode 100644 index 62e378c..0000000 --- a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestModel.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2007-2012 forwardfire.net All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package net.forwardfire.vasc; - -import java.util.Date; - -import net.forwardfire.vasc.annotations.VascDefaultValue; -import net.forwardfire.vasc.annotations.VascEntry; -import net.forwardfire.vasc.annotations.VascI18n; -import net.forwardfire.vasc.annotations.VascModelReference; -import net.forwardfire.vasc.annotations.VascStyle; -import net.forwardfire.vasc.validators.VascDateFuture; -import net.forwardfire.vasc.validators.VascObjectNotNull; -import net.forwardfire.vasc.validators.VascStringLength; - - -//import org.hibernate.validator.NotNull; -//import org.hibernate.validator.Max; - - -/** - * TestModel - * - * - * @author Willem Cazander - * @version 1.0 Mar 28, 2007 - */ -@VascEntry(headerName="En een tooltip op het model") -public class TestModel { - - private String name = null; - private String description = null; - private Float price = null; - private Boolean active = null; - private Date date = null; - private TestModel testModel = null; - private String hexColor = null; - //private Node nonEditorField = null; - - /** - * @return the date - */ - @VascDateFuture - public Date getDate() { - return date; - } - - /** - * @param date the date to set - */ - public void setDate(Date date) { - this.date = date; - } - - /** - * @return the description - */ - @VascI18n( name="omscheiving", - description="De omscrijving", - image="/resources/images/gabelfresser.gif", - helpId="help.id") - @VascDefaultValue(value="xxxxx") - @VascStyle(sizeList=200) -// @NotNull -// @Max(value=10) - @VascObjectNotNull - @VascStringLength(max=10) - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the price - */ - public Float getPrice() { - return price; - } - - /** - * @param price the price to set - */ - public void setPrice(Float price) { - this.price = price; - } - - -// @NotNull - @VascObjectNotNull - @VascModelReference - @VascI18n(image="/resources/images/gabelfresser.gif") - public TestModel getTestModel() { - return testModel; - } - - public void setTestModel(TestModel testModel) { - this.testModel = testModel; - } - - /** - * @return the active - */ - public Boolean getActive() { - return active; - } - - /** - * @param active the active to set - */ - public void setActive(Boolean active) { - this.active = active; - } - - /** - * @return the hexColor - */ - public String getHexColor() { - return hexColor; - } - - /** - * @param hexColor the hexColor to set - */ - public void setHexColor(String hexColor) { - this.hexColor = hexColor; - } -} \ No newline at end of file diff --git a/vasc-frontend/vasc-frontend-web-jsf/.project b/vasc-frontend/vasc-frontend-web-jsf/.project index 8617a88..bb5050f 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/.project +++ b/vasc-frontend/vasc-frontend-web-jsf/.project @@ -21,12 +21,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerBase.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerBase.java new file mode 100644 index 0000000..17c05ae --- /dev/null +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerBase.java @@ -0,0 +1,63 @@ +package net.forwardfire.vasc.frontends.web.jsf; + +import java.util.List; +import java.util.Map; + +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.core.VascController; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.frontend.VascFrontendData; +import net.forwardfire.vasc.impl.DefaultVascFactory; + +public abstract class AbstractJSFVascFacesControllerBase { + + abstract VascFrontendData getNewVascFrontendData(); + abstract VascController getVascController(); + + public void setVascController(VascController vascController) { + } + + /** + * + */ + public List executeVascList(String entryId,Map para) { + try { + // plug all object + VascEntry entry = getVascController().getVascEntryController().getVascEntryById(entryId); + DefaultVascFactory.fillVascEntryFrontend(entry, getVascController(), getNewVascFrontendData()); + + // set def para + VascBackendState state = entry.getVascFrontendData().getVascEntryState().getVascBackendState(); + for (String key2:entry.getEntryParameterKeys()) { + Object value = entry.getEntryParameter(key2); + state.setDataParameter(key2, value); + } + + // set list para + for (VascEntryField vef:entry.getListOptions()) { + Object def = vef.getDefaultValue(); + if (def==null) { + continue; + } + String backendName = vef.getBackendName(); + state.setDataParameter(backendName, def); + } + + // copy para + if (para!=null) { + for (String key:para.keySet()) { + entry.setEntryParameter(key, para.get(key)); + } + } + + // done, execute and return data. + entry.getVascFrontendData().getVascFrontendActions().refreshData(); + return entry.getVascFrontendData().getVascEntryState().getEntryDataList(); + } catch (Exception e) { + throw new RuntimeException("Could not execute list: "+e.getMessage(),e); + } + } + +} diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesController.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerEJB.java similarity index 86% rename from vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesController.java rename to vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerEJB.java index 0fabb32..3e45dbb 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesController.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerEJB.java @@ -38,23 +38,23 @@ import javax.faces.context.FacesContext; import javax.naming.Context; import javax.naming.InitialContext; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendControllerLocal; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendControllerLocal; +import net.forwardfire.vasc.backend.VascBackendState; +import net.forwardfire.vasc.backend.proxy.VascBackendProxyEventExecutor; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.VascFrontendData; import net.forwardfire.vasc.core.entry.VascEntryBackendEventListener; import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; import net.forwardfire.vasc.ejb3.VascServiceManager; +import net.forwardfire.vasc.frontend.VascFrontendData; import net.forwardfire.vasc.impl.DefaultVascBackedEntryFinalizer; import net.forwardfire.vasc.impl.DefaultVascFactory; -import net.forwardfire.vasc.impl.VascBackendProxyEventExecutor; import net.forwardfire.vasc.impl.entry.DefaultVascEntryResourceResolver; import net.forwardfire.vasc.impl.entry.SetParameterBackendListener; @@ -66,7 +66,7 @@ import net.forwardfire.vasc.impl.entry.SetParameterBackendListener; * @author Willem Cazander * @version 1.0 Sep 21, 2010 */ -abstract public class AbstractJSFVascFacesController { +abstract public class AbstractJSFVascFacesControllerEJB extends AbstractJSFVascFacesControllerBase { private VascController vascController = null; @@ -167,51 +167,7 @@ abstract public class AbstractJSFVascFacesController { return vascFrontendData; } - /** - * - */ - public List executeVascList(String entryId,Map para) { - try { - // plug all object - VascEntry entry = getVascController().getVascEntryController().getVascEntryById(entryId); - entry.setVascFrontendData(getNewVascFrontendData()); - entry.getVascFrontendData().setVascController(getVascController()); - VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); - entry.getVascFrontendData().getVascEntryState().setVascBackend(backend); - entry.getVascFrontendData().getVascEntryState().setVascEntry(entry); - - // set def para - VascBackendState state = entry.getVascFrontendData().getVascEntryState().getVascBackendState(); - for (String key2:entry.getEntryParameterKeys()) { - Object value = entry.getEntryParameter(key2); - //System.out.println("Copy paras name: "+key2+" value: "+value+" class: "+value.getClass().getName()); - state.setDataParameter(key2, value); - } - - // set list para - for (VascEntryField vef:entry.getListOptions()) { - Object def = vef.getDefaultValue(); - if (def==null) { - continue; - } - String backendName = vef.getBackendName(); - state.setDataParameter(backendName, def); - } - - // copy para - if (para!=null) { - for (String key:para.keySet()) { - entry.setEntryParameter(key, para.get(key)); - } - } - - // done, execute and return data. - entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); - return entry.getVascFrontendData().getVascEntryState().getEntryDataList(); - } catch (Exception e) { - throw new RuntimeException("Could not execute list: "+e.getMessage(),e); - } - } + class RemoteVascBackend implements VascBackend { @@ -445,7 +401,4 @@ abstract public class AbstractJSFVascFacesController { throw new RuntimeException("Could not create remote based vasc controller; "+e.getMessage(),e); } } - - public void setVascController(VascController vascController) { - } } diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerLocal.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerLocal.java new file mode 100644 index 0000000..da0dfca --- /dev/null +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerLocal.java @@ -0,0 +1,157 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.vasc.frontends.web.jsf; + + +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; + +import javax.faces.context.FacesContext; + +import net.forwardfire.vasc.core.VascController; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryControllerLocal; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; +import net.forwardfire.vasc.frontend.VascFrontendData; +import net.forwardfire.vasc.impl.DefaultVascFactory; +import net.forwardfire.vasc.impl.entry.DefaultVascEntryResourceResolver; +import net.forwardfire.vasc.impl.x4o.VascParser; + + + +/** + * Base faces session object for managing vasc entries. + * + * @author Willem Cazander + * @version 1.0 Sep 21, 2010 + */ +abstract public class AbstractJSFVascFacesControllerLocal extends AbstractJSFVascFacesControllerBase { + + protected VascController vascController = null; + protected Map vascGlobalELBeans = new HashMap(3); + + abstract public String getResourceBundleWEB(); + abstract public boolean getDisableI18N(); + abstract public VascUserInfo getVascUserInfo(); + abstract public String[] getVascParseResources(); + + public class VascUserInfo { + Long userId; + String username; + String[] roles; + public VascUserInfo(Long userId,String username,String[] roles) { + this.userId=userId; + this.username=username; + this.roles=roles; + } + } + + class MergedResourceBundle extends ResourceBundle { + Map data = new HashMap(500); + + public void addDateMap(Map dataMap) { + data.putAll(dataMap); + } + public void addDataBundle(ResourceBundle bundle) { + for (String key:bundle.keySet()) { + String value = bundle.getString(key); + data.put(key, value); + } + } + public Object handleGetObject(String key) { + return data.get(key); + } + + public Enumeration getKeys() { + return Collections.enumeration(data.keySet()); + } + } + + /** + * Config vasc frontend data object for jsf component to use. + * + * @return + */ + public VascFrontendData getNewVascFrontendData() { + Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); + MergedResourceBundle bundle = new MergedResourceBundle(); + bundle.addDataBundle(ResourceBundle.getBundle(getResourceBundleWEB(), locale)); + + VascFrontendData vascFrontendData = DefaultVascFactory.getDefaultVascFrontendData(bundle); + vascFrontendData.addVascEntryFrontendEventListener(new VascEntryFrontendEventListener() { + private static final long serialVersionUID = 1L; + public VascFrontendEventType[] getEventTypes() { + VascFrontendEventType[] result = {VascEntryFrontendEventListener.VascFrontendEventType.EXCEPTION}; + return result; + } + public void vascEvent(VascEntry entry, Object data) { + if (data instanceof Exception) { + ((Exception)data).printStackTrace(); + } + } + }); + + // config frontend data for ISF usage + if (getDisableI18N()) { + vascFrontendData.setVascEntryResourceResolver(new DefaultVascEntryResourceResolver()); + } else { + vascFrontendData.setVascEntryResourceResolver(new DefaultVascEntryResourceResolver(bundle)); + } + return vascFrontendData; + } + + /** + * @return the vascController + */ + public VascController getVascController() { + if (vascController!=null) { + return vascController; + } + try { + // get local jvm plugging controller + VascUserInfo vui = getVascUserInfo(); + VascController c = DefaultVascFactory.getDefaultVascController(vui.userId, vui.username, vui.roles); + + // Load vasc resources + for (String res:getVascParseResources()) { + VascParser vp = new VascParser(c); + for (String name:vascGlobalELBeans.keySet()) { + Object value = vascGlobalELBeans.get(name); + vp.addGlobalELBean(name, value); + } + vp.parseResource(res); + } + DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) c.getVascEntryController(), c); + + vascController = c; + return vascController; + } catch (Exception e) { + throw new RuntimeException("Could not create remote based vasc controller; "+e.getMessage(),e); + } + } + +} diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntryEventListener.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntryEventListener.java index 446e800..afb4bc0 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntryEventListener.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntryEventListener.java @@ -85,6 +85,6 @@ public class JSFVascEntryEventListener implements VascEntryFrontendEventListener ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".tableDataModel.wrappedData}", Object.class); ve2.setValue(FacesContext.getCurrentInstance().getELContext(), result); ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".tablePagesDataModel.wrappedData}", Object.class); - ve3.setValue(FacesContext.getCurrentInstance().getELContext(), entry.getVascFrontendData().getVascFrontendHelper().getVascBackendPageNumbers(entry)); + ve3.setValue(FacesContext.getCurrentInstance().getELContext(), entry.getVascFrontendData().getVascFrontendPager().getTablePagesFromBackend()); } } diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java index b4a76ad..0d8f3a1 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java @@ -47,18 +47,16 @@ import javax.faces.model.SelectItem; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendPageNumber; +import net.forwardfire.vasc.backend.VascBackend; +import net.forwardfire.vasc.backend.VascBackendPageNumber; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryState; -import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.VascLinkEntry; import net.forwardfire.vasc.core.VascLinkEntryType; import net.forwardfire.vasc.core.actions.GlobalVascAction; import net.forwardfire.vasc.core.actions.RowVascAction; import net.forwardfire.vasc.core.entry.VascEntryExporter; -import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.impl.actions.AddRowAction; import net.forwardfire.vasc.impl.actions.DeleteRowAction; import net.forwardfire.vasc.impl.actions.EditRowAction; @@ -106,7 +104,7 @@ public class JSFVascEntrySupportBean implements Serializable { editSelectItemModels = new HashMap(6); // cache some values - VascBackend backend = entry.getVascFrontendData().getVascEntryState().getVascBackend();; + VascBackend backend = entry.getVascFrontendData().getVascEntryState().getVascBackend(); backendPageable = backend.isPageable(); backendMoveable = backend.isRecordMoveable(); backendSearchable = backend.isSearchable(); @@ -136,40 +134,11 @@ public class JSFVascEntrySupportBean implements Serializable { } public String getParentSelectedDisplayName() { - if (entry.getVascFrontendData().getVascEntryState().getParent()==null) { - return ""; // no parent - } - - VascEntry parent = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); - Object row = entry.getVascFrontendData().getVascEntryState().getParent().getEntryDataObject(); - if (row==null) { - return "no-selection"; - } - VascEntryField v = parent.getVascEntryFieldById(parent.getDisplayNameFieldId()); - VascEntryFieldValue ve = v.getVascEntryFieldValue(); - String result = "no-data"; - try { - result = ve.getDisplayValue(v, row); - } catch (VascException e) { - throw new RuntimeException("Could not get parent name DisplayValue: "+e.getMessage(),e); - } - return result; + return entry.getVascFrontendData().getVascFrontendHelper().getParentSelectedDisplayName(entry); } public String getSelectedDisplayName() { - Object row = entry.getVascFrontendData().getVascEntryState().getEntryDataObject(); - if (row==null) { - return "no-selection"; - } - VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId()); - VascEntryFieldValue ve = v.getVascEntryFieldValue(); - String result = "no-data"; - try { - result = ve.getDisplayValue(v, row); - } catch (VascException e) { - throw new RuntimeException("Could not get selected name DisplayValue: "+e.getMessage(),e); - } - return result; + return entry.getVascFrontendData().getVascFrontendHelper().getSelectedDisplayName(entry); } public int getTotalColumnCount() { @@ -227,26 +196,14 @@ public class JSFVascEntrySupportBean implements Serializable { public long getPageTotalRecordCount() { - long result = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); - return result; + return entry.getVascFrontendData().getVascFrontendPager().getPageTotalRecordCount(); } public long getPageStartCount() { - int index = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); - int pageSize = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize(); - long result = index*pageSize; - return result; + return entry.getVascFrontendData().getVascFrontendPager().getPageStartCount(); } public long getPageStopCount() { - int index = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); - int pageSize = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize(); - long result = (index*pageSize)+pageSize; - - // limit for small result sets. - if (result>entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords()) { - result = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); - } - return result; + return entry.getVascFrontendData().getVascFrontendPager().getPageStopCount(); } public List getGlobalExportItems() { @@ -294,99 +251,27 @@ public class JSFVascEntrySupportBean implements Serializable { } public boolean getHasOnlySinglePage() { - int pages = getTablePagesDataModel().getRowCount(); - if (pages==1) { - return true; - } - return false; + return entry.getVascFrontendData().getVascFrontendPager().getHasOnlySinglePage(); } public boolean getHasExtendedPageMode() { - int pages = getTablePagesDataModel().getRowCount(); - if (pages>13) { - return true; - } - return false; + return entry.getVascFrontendData().getVascFrontendPager().getHasExtendedPageMode(); } public boolean getHasExtendedPageModeCenter() { - if (getHasExtendedPageMode()==false) { - return false; - } - int page = getVascEntry().getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); - if (page<5) { - return false; - } - int pages = getTablePagesDataModel().getRowCount(); - if (page>pages-6) { - return false; - } - return true; + return entry.getVascFrontendData().getVascFrontendPager().getHasExtendedPageModeCenter(); } public List getTablePagesExtendedBegin() { - List result = new ArrayList(6); - getTablePagesDataModel().setRowIndex(0); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - getTablePagesDataModel().setRowIndex(1); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - getTablePagesDataModel().setRowIndex(2); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - - int page = getVascEntry().getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); - if (page==2 | page==3 | page==4) { - getTablePagesDataModel().setRowIndex(3); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - } - if (page==3 | page==4) { - getTablePagesDataModel().setRowIndex(4); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - } - if (page==4) { - getTablePagesDataModel().setRowIndex(5); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - } - return result; + return entry.getVascFrontendData().getVascFrontendPager().getTablePagesExtendedBegin(); } public List getTablePagesExtendedEnd() { - List result = new ArrayList(6); - int pages = getTablePagesDataModel().getRowCount(); - int page = getVascEntry().getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); - int off = pages-page; - - if (off==5) { - getTablePagesDataModel().setRowIndex(pages-6); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - } - if (off==4 | off==5) { - getTablePagesDataModel().setRowIndex(pages-5); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - } - if (off==3 | off==4 | off==5) { - getTablePagesDataModel().setRowIndex(pages-4); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - } - - getTablePagesDataModel().setRowIndex(pages-3); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - getTablePagesDataModel().setRowIndex(pages-2); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - getTablePagesDataModel().setRowIndex(pages-1); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - return result; + return entry.getVascFrontendData().getVascFrontendPager().getTablePagesExtendedEnd(); } public List getTablePagesExtendedCenter() { - List result = new ArrayList(3); - int page = getVascEntry().getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); - getTablePagesDataModel().setRowIndex(page-1); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - getTablePagesDataModel().setRowIndex(page); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - getTablePagesDataModel().setRowIndex(page+1); - result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); - return result; + return entry.getVascFrontendData().getVascFrontendPager().getTablePagesExtendedCenter(); } private String getComponentType(UIComponent comp) { @@ -544,12 +429,7 @@ public class JSFVascEntrySupportBean implements Serializable { logger.fine("searchAction"); JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); - entry.getVascFrontendData().getVascFrontendHelper().searchAction(entry, searchString); - try { - entry.getVascFrontendData().getVascFrontend().renderView(); - } catch (Exception e) { - entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); - } + entry.getVascFrontendData().getVascFrontendActions().searchAction(searchString); } public void sortAction(ActionEvent event) { @@ -558,17 +438,9 @@ public class JSFVascEntrySupportBean implements Serializable { JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); VascEntryField field = entry.getVascEntryFieldById(fieldIdString); - - entry.getVascFrontendData().getVascFrontendHelper().sortAction(entry, field); - + entry.getVascFrontendData().getVascFrontendActions().sortAction(field); sortOrder = entry.getVascFrontendData().getVascEntryState().getVascBackendState().isSortAscending(); sortField = field.getId(); - - try { - entry.getVascFrontendData().getVascFrontend().renderView(); - } catch (Exception e) { - entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); - } } public boolean getRenderBackAction() { @@ -613,12 +485,7 @@ public class JSFVascEntrySupportBean implements Serializable { JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); selectedDirectPage=pageIndex+""; - entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, pageIndex); - try { - entry.getVascFrontendData().getVascFrontend().renderView(); - } catch (Exception e) { - entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); - } + entry.getVascFrontendData().getVascFrontendActions().pageAction(pageIndex); } public void pageNextAction(ActionEvent event) { @@ -629,7 +496,7 @@ public class JSFVascEntrySupportBean implements Serializable { int pageIndex = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); pageIndex++; selectedDirectPage=pageIndex+""; - entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, pageIndex); + entry.getVascFrontendData().getVascFrontendActions().pageAction(pageIndex); try { entry.getVascFrontendData().getVascFrontend().renderView(); } catch (Exception e) { @@ -645,7 +512,7 @@ public class JSFVascEntrySupportBean implements Serializable { int pageIndex = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); pageIndex--; selectedDirectPage=pageIndex+""; - entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, pageIndex); + entry.getVascFrontendData().getVascFrontendActions().pageAction(pageIndex); try { entry.getVascFrontendData().getVascFrontend().renderView(); } catch (Exception e) { @@ -654,25 +521,11 @@ public class JSFVascEntrySupportBean implements Serializable { } public boolean getHasPageNextAction() { - VascEntry entry = getVascEntry(); - int pageIndex = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); - pageIndex++; - // copyed from helper - Long total = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); - logger.finer("Checking has next action for next pageIndex"+pageIndex+" of total: "+total+" and pageSize: "+entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize()); - if (total!=null && pageIndex>(total/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize())) { - return false; - } - return true; + return entry.getVascFrontendData().getVascFrontendPager().getHasPageNextAction(); } public boolean getHasPagePreviousAction() { - VascEntry entry = getVascEntry(); - int pageIndex = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); - if (pageIndex==0) { - return false; - } - return true; + return entry.getVascFrontendData().getVascFrontendPager().getHasPagePreviousAction(); } @@ -751,15 +604,10 @@ public class JSFVascEntrySupportBean implements Serializable { JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); Object selected = comp.getSupportBean().getSelectedTableRecord().getRecord(); if ("up".equals(moveAction)) { - entry.getVascFrontendData().getVascFrontendHelper().moveAction(entry,selected,true); + entry.getVascFrontendData().getVascFrontendActions().moveUpAction(selected); } if ("down".equals(moveAction)) { - entry.getVascFrontendData().getVascFrontendHelper().moveAction(entry,selected,false); - } - try { - entry.getVascFrontendData().getVascFrontend().renderView(); - } catch (Exception e) { - entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + entry.getVascFrontendData().getVascFrontendActions().moveDownAction(selected); } } @@ -834,7 +682,7 @@ public class JSFVascEntrySupportBean implements Serializable { */ entry.getVascFrontendData().getVascEntryState().setEntryDataObject(selected.getRecord()); - entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry); + entry.getVascFrontendData().getVascFrontendActions().mergeObject(); try { entry.getVascFrontendData().getVascFrontend().renderView(); @@ -861,11 +709,11 @@ public class JSFVascEntrySupportBean implements Serializable { if (sels.isEmpty()==false) { for (Object row:sels) { entry.getVascFrontendData().getVascEntryState().setEntryDataObject(row); - entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); + entry.getVascFrontendData().getVascFrontendActions().deleteObject(); } state.getMultiActionSelection().clear(); // after down deselect all options } else { - entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); + entry.getVascFrontendData().getVascFrontendActions().deleteObject(); } try { @@ -956,7 +804,7 @@ public class JSFVascEntrySupportBean implements Serializable { //selectedDirectPage = "null"; try { - entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, new Integer(id)); + entry.getVascFrontendData().getVascFrontendActions().pageAction(new Integer(id)); entry.getVascFrontendData().getVascFrontend().renderView(); } catch (Exception e) { entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java index 8364f62..67a8fb1 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java @@ -28,9 +28,9 @@ import java.util.logging.Logger; import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; -import net.forwardfire.vasc.core.AbstractVascFrontend; -import net.forwardfire.vasc.core.VascFrontendData; import net.forwardfire.vasc.core.entry.VascEntryExporter; +import net.forwardfire.vasc.frontend.AbstractVascFrontend; +import net.forwardfire.vasc.frontend.VascFrontendData; import net.forwardfire.vasc.frontends.web.jsf.ui.JSFBoolean; import net.forwardfire.vasc.frontends.web.jsf.ui.JSFLabel; import net.forwardfire.vasc.frontends.web.jsf.ui.JSFList; @@ -58,7 +58,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser // Frontend Stuff /** - * @see net.forwardfire.vasc.core.VascFrontend#getFrontendType() + * @see net.forwardfire.vasc.frontend.VascFrontend#getFrontendType() */ public String getFrontendType() { return "jsf"; @@ -83,7 +83,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser } /** - * @see net.forwardfire.vasc.core.VascFrontend#renderDelete(java.lang.Object) + * @see net.forwardfire.vasc.frontend.VascFrontend#renderDelete(java.lang.Object) */ public void renderDelete() throws Exception { logger.finer("renderDelete"); @@ -93,7 +93,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser } /** - * @see net.forwardfire.vasc.core.VascFrontend#renderEdit(java.lang.Object) + * @see net.forwardfire.vasc.frontend.VascFrontend#renderEdit(java.lang.Object) */ public void renderEdit() throws Exception { logger.finer("renderEdit"); @@ -115,7 +115,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser } /** - * @see net.forwardfire.vasc.core.VascFrontend#renderExport(net.forwardfire.vasc.core.entry.VascEntryExporter) + * @see net.forwardfire.vasc.frontend.VascFrontend#renderExport(net.forwardfire.vasc.core.entry.VascEntryExporter) */ public void renderExport(VascEntryExporter exporter) throws Exception { logger.finer("renderExport"); @@ -126,7 +126,7 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser } /** - * @see net.forwardfire.vasc.core.VascFrontend#renderView() + * @see net.forwardfire.vasc.frontend.VascFrontend#renderView() */ public void renderView() throws Exception { logger.finer("renderView"); diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascUIComponent.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascUIComponent.java index b9ac0da..45878a0 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascUIComponent.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascUIComponent.java @@ -33,16 +33,16 @@ import javax.faces.component.UIComponent; import javax.faces.component.UIComponentBase; import javax.faces.context.FacesContext; -import net.forwardfire.vasc.core.VascBackend; +import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryState; import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.VascFrontendData; import net.forwardfire.vasc.core.VascLinkEntry; import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFrontendEventType; +import net.forwardfire.vasc.frontend.VascFrontendData; import net.forwardfire.vasc.frontends.web.jsf.ui.JSFListModel; import net.forwardfire.vasc.impl.DefaultVascFactory; @@ -241,7 +241,7 @@ public class JSFVascUIComponent extends UIComponentBase { try { VascEntry entry = supportBean.getVascEntry(); entry.getVascFrontendData().getVascEntryState().setEditCreate(false); - entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascFrontendEventType.SELECT, rowObject); + entry.getVascFrontendData().fireVascFrontendEvent(entry, VascFrontendEventType.SELECT, rowObject); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(rowObject); entry.getVascFrontendData().getVascFrontend().renderEdit(); } catch (Exception e) { @@ -339,10 +339,9 @@ public class JSFVascUIComponent extends UIComponentBase { if (entry==null) { throw new NullPointerException("Could not locate '"+entryName+"' from : "+vascController); } - frontendData.setVascFrontend(null); // reset data obj. todo rm this. - frontendData.setVascController(vascController); - entry.setVascFrontendData(frontendData); + DefaultVascFactory.fillVascEntryFrontend(entry, vascController, frontendData); + try { frontendData.initFrontendListeners(entry,"jsf"); } catch (InstantiationException e1) { @@ -352,9 +351,6 @@ public class JSFVascUIComponent extends UIComponentBase { // TODO Auto-generated catch block e1.printStackTrace(); } - VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); - frontendData.getVascEntryState().setVascBackend(backend); - frontendData.getVascEntryState().setVascEntry(entry); if (state!=null) { // copy prevois parent diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java index 5e214bc..f26767a 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java @@ -38,7 +38,6 @@ import javax.faces.component.UIColumn; import javax.faces.component.UIComponent; import javax.faces.component.UIInput; import javax.faces.component.UIOutput; -import javax.faces.component.UISelectMany; import javax.faces.component.UIViewRoot; import javax.faces.component.html.HtmlCommandLink; import javax.faces.component.html.HtmlInputText; @@ -177,12 +176,10 @@ public class JSFVascUIComponentRenderer extends Renderer { } String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); - int column = 0; for (VascEntryField c:entry.getVascEntryFields()) { if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) { continue; } - //System.out.println("Multi edit size: "+c.getVascEntryFieldType().getUIComponentCount(c)+" of: "+c.getVascEntryFieldType()); for (int i=0;i + + vasc-test + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/vasc-test/.settings/org.eclipse.core.resources.prefs b/vasc-test/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..b3c37a0 --- /dev/null +++ b/vasc-test/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Tue Jan 17 02:16:16 CET 2012 +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/vasc-test/.settings/org.eclipse.m2e.core.prefs b/vasc-test/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..1d34453 --- /dev/null +++ b/vasc-test/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Tue Jan 17 02:16:16 CET 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/vasc-test/pom.xml b/vasc-test/pom.xml new file mode 100644 index 0000000..f2019e1 --- /dev/null +++ b/vasc-test/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + + vasc + net.forwardfire.vasc + 0.3.5-SNAPSHOT + .. + + vasc-test + pom + vasc-test + vasc-test + + vasc-test-frontend-data + + \ No newline at end of file diff --git a/vasc-test/vasc-test-frontend-data/.classpath b/vasc-test/vasc-test-frontend-data/.classpath new file mode 100644 index 0000000..3c96d64 --- /dev/null +++ b/vasc-test/vasc-test-frontend-data/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/vasc-test/vasc-test-frontend-data/.project b/vasc-test/vasc-test-frontend-data/.project new file mode 100644 index 0000000..01f74f6 --- /dev/null +++ b/vasc-test/vasc-test-frontend-data/.project @@ -0,0 +1,23 @@ + + + vasc-test-frontend-data + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.core.resources.prefs b/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..da5750d --- /dev/null +++ b/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +#Tue Jan 17 02:17:53 CET 2012 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.jdt.core.prefs b/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9560ae8 --- /dev/null +++ b/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,6 @@ +#Tue Jan 17 02:17:53 CET 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.m2e.core.prefs b/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..58b978e --- /dev/null +++ b/vasc-test/vasc-test-frontend-data/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Tue Jan 17 02:17:52 CET 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/vasc-test/vasc-test-frontend-data/pom.xml b/vasc-test/vasc-test-frontend-data/pom.xml new file mode 100644 index 0000000..55dbeed --- /dev/null +++ b/vasc-test/vasc-test-frontend-data/pom.xml @@ -0,0 +1,17 @@ + + 4.0.0 + + vasc-test + net.forwardfire.vasc + 0.3.5-SNAPSHOT + .. + + vasc-test-frontend-data + + + net.forwardfire.vasc + vasc-core + ${project.version} + + + \ No newline at end of file diff --git a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestModel.java b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModel.java similarity index 98% rename from vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestModel.java rename to vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModel.java index a88ba9b..cad107f 100644 --- a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/TestModel.java +++ b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModel.java @@ -20,7 +20,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc; +package net.forwardfire.vasc.test.frontend.data; import java.util.Date; diff --git a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestTable.java b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelEntry.java similarity index 51% rename from vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestTable.java rename to vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelEntry.java index abbcd89..e610e5c 100644 --- a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestTable.java +++ b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelEntry.java @@ -20,100 +20,80 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc; +package net.forwardfire.vasc.test.frontend.data; -import java.io.File; -import java.io.FileOutputStream; import java.lang.reflect.Method; -import java.util.Locale; -import net.forwardfire.vasc.core.VascBackend; -import net.forwardfire.vasc.core.VascBackendControllerLocal; +import net.forwardfire.vasc.backend.VascBackendControllerLocal; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; -import net.forwardfire.vasc.core.VascException; -import net.forwardfire.vasc.core.VascFrontendData; -import net.forwardfire.vasc.impl.DefaultVascBackedEntryFinalizer; +import net.forwardfire.vasc.impl.DefaultVascEntry; +import net.forwardfire.vasc.impl.DefaultVascEntryField; import net.forwardfire.vasc.impl.DefaultVascFactory; -import net.forwardfire.vasc.impl.DefaultVascFrontendData; -import net.forwardfire.vasc.impl.DefaultVascFrontendHelper; -import net.forwardfire.vasc.impl.VascBackendProxyPaged; -import net.forwardfire.vasc.impl.VascBackendProxySearch; -import net.forwardfire.vasc.impl.VascBackendProxySort; -import net.forwardfire.vasc.impl.actions.AddRowAction; -import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction; -import net.forwardfire.vasc.impl.actions.DeleteRowAction; -import net.forwardfire.vasc.impl.actions.EditRowAction; -import net.forwardfire.vasc.impl.actions.RefreshDataGlobalAction; -import net.forwardfire.vasc.impl.actions.XMLExportGlobalAction; -import net.forwardfire.vasc.impl.x4o.VascParser; - - - /** * * @author Willem Cazander * @version 1.0 Aug 2, 2007 */ -public class TestTable { +public class TestModelEntry { - static VascController getDefaultVascController() throws Exception { - VascController c = DefaultVascFactory.getDefaultVascController(2288L,"vasc.forwardfire.net","user","admin"); + public VascController getTestVascController() throws Exception { + VascController c = DefaultVascFactory.getDefaultVascController(1234L,"Nice UserName","user","role_admin"); // for test TestModelVascDataSource backend = new TestModelVascDataSource(); - backend.setId("testBackend1"); + backend.generatorData(10876); + backend.setId("testBackend"); ((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backend); return c; } - - static public void fill(VascEntry entry,VascController vascController) { - - VascFrontendData frontendData = DefaultVascFactory.getDefaultVascFrontendData(null); - frontendData.setVascController(vascController); - entry.setVascFrontendData(frontendData); - VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); - frontendData.getVascEntryState().setVascBackend(backend); - frontendData.getVascEntryState().setVascEntry(entry); + public VascEntry createVascEntry(VascController vc) throws Exception { + VascEntry ve = new DefaultVascEntry(); + ve.setId("testEntry"); + ve.setBackendId("testBackend"); + + VascEntryField field = new DefaultVascEntryField(); + field.setId("name"); + ve.addVascEntryField(field); - - entry.addRowAction(new AddRowAction()); - entry.addRowAction(new EditRowAction()); - entry.addRowAction(new DeleteRowAction()); - - entry.addGlobalAction(new XMLExportGlobalAction()); - entry.addGlobalAction(new CSVExportGlobalAction()); - entry.addGlobalAction(new RefreshDataGlobalAction()); - - // hackje om deze manuale actions van i18n keys te voorzien; - // this is temp untill x4o templaing - DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer(); - try { - f.finalizeVascEntry(entry, vascController); - } catch (VascException e) { - e.printStackTrace(); - } + field = new DefaultVascEntryField(); + field.setId("description"); + ve.addVascEntryField(field); + + field = new DefaultVascEntryField(); + field.setId("active"); + field.setVascEntryFieldType(vc.getVascEntryFieldTypeController().getVascEntryFieldTypeById("BooleanField")); + ve.addVascEntryField(field); + + field = new DefaultVascEntryField(); + field.setId("date"); + field.setVascEntryFieldType(vc.getVascEntryFieldTypeController().getVascEntryFieldTypeById("DateField")); + ve.addVascEntryField(field); + + field = new DefaultVascEntryField(); + field.setId("hexColor"); + ve.addVascEntryField(field); + + field = new DefaultVascEntryField(); + field.setId("testModel"); + // LIST and vascEntryFieldType.dataObject="#{vascController.vascBackendControllerResolver.vascBackendController.vascBackendById('testBackend1')}" + ve.addVascEntryField(field); + + // table options + field = new DefaultVascEntryField(); + field.setId("active"); + field.setVascEntryFieldType(vc.getVascEntryFieldTypeController().getVascEntryFieldTypeById("BooleanField")); + field.setBackendName("active"); + field.setDefaultValue("true"); // obj does also work ! we are first need to fix string defaults. + ve.addListOption(field); + + return ve; } - static public VascEntry getVascTable() throws Exception { - - VascController c = getDefaultVascController(); - - VascParser parser = new VascParser(c); - File f = File.createTempFile("test-vasc", ".xml"); - parser.setDebugOutputStream(new FileOutputStream(f)); - parser.parseResource("vasc/tables.xml"); - - VascEntry entry = parser.getVascController().getVascEntryController().getVascEntryById("dg2_profiles"); - fill(entry,c); - - return entry; - } - static void printEntry(VascEntry e) throws Exception { System.out.println(""); diff --git a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestModelVascDataSource.java b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelVascDataSource.java similarity index 74% rename from vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestModelVascDataSource.java rename to vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelVascDataSource.java index 28cb38c..caefd3d 100644 --- a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/TestModelVascDataSource.java +++ b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelVascDataSource.java @@ -20,14 +20,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.forwardfire.vasc; +package net.forwardfire.vasc.test.frontend.data; import java.util.ArrayList; import java.util.Date; import java.util.List; -import net.forwardfire.vasc.core.AbstractVascBackend; -import net.forwardfire.vasc.core.VascBackendState; +import net.forwardfire.vasc.backend.AbstractVascBackend; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; @@ -47,46 +47,64 @@ import net.forwardfire.vasc.impl.entry.BeanVascEntryRecordCreator; */ public class TestModelVascDataSource extends AbstractVascBackend implements VascSelectItemModel { - private List testModels = null; + private List testModels = null; private String nullLabel = null; private String nullKeyValue = null; public TestModelVascDataSource() { - testModels = new ArrayList(2); - - TestModel t = new TestModel(); - t.setDate(new Date()); - t.setDescription("yoyo test"); - t.setName("this Name"); - t.setPrice(34.1f); - t.setActive(true); - t.setHexColor("#FF66EE"); - testModels.add(t); - - t = new TestModel(); - t.setDate(new Date()); - t.setDescription("Model2 test"); - t.setName("BeanSourde"); - t.setPrice(19.2f); - t.setActive(false); - t.setTestModel((TestModel)testModels.get(0)); - testModels.add(t); + testModels = new ArrayList(200); } - public TestModelVascDataSource(List testModels) { + + + public void generatorData(int size) { + for (int i=0;i testModels) { this.testModels=testModels; } public List execute(VascBackendState state) throws VascException { - return testModels; + if (state.getDataParameterKeys().contains("active")) { + List result = new ArrayList(testModels.size()/2); + for (TestModel tm:testModels) { + if (tm.getActive()!=null && tm.getActive().equals(state.getDataParameter("active"))) { + result.add(tm); + } + } + return result; + } else { + List result = new ArrayList(testModels.size()); + for (TestModel tm:testModels) { + result.add(tm); + } + return result; + } } public void persist(Object object) throws VascException { - testModels.add(object); + testModels.add((TestModel)object); } public Object merge(Object object) throws VascException { if(testModels.contains(object)==false) { - testModels.add(object); + testModels.add((TestModel)object); } return object; } diff --git a/vasc-xpql-ejb3-client/.classpath b/vasc-xpql-ejb3-client/.classpath new file mode 100644 index 0000000..3c96d64 --- /dev/null +++ b/vasc-xpql-ejb3-client/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/vasc-xpql-ejb3-client/.project b/vasc-xpql-ejb3-client/.project new file mode 100644 index 0000000..a7cf84a --- /dev/null +++ b/vasc-xpql-ejb3-client/.project @@ -0,0 +1,23 @@ + + + vasc-xpql-ejb3-client + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/vasc-xpql-ejb3-client/.settings/org.eclipse.core.resources.prefs b/vasc-xpql-ejb3-client/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..a023909 --- /dev/null +++ b/vasc-xpql-ejb3-client/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +#Wed Jan 11 23:36:06 CET 2012 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/vasc-xpql-ejb3-client/.settings/org.eclipse.jdt.core.prefs b/vasc-xpql-ejb3-client/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9016dda --- /dev/null +++ b/vasc-xpql-ejb3-client/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,6 @@ +#Wed Jan 11 23:36:06 CET 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/vasc-xpql-ejb3-client/.settings/org.eclipse.m2e.core.prefs b/vasc-xpql-ejb3-client/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..b3bbbfe --- /dev/null +++ b/vasc-xpql-ejb3-client/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Wed Jan 11 23:36:06 CET 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/vasc-xpql-ejb3-client/pom.xml b/vasc-xpql-ejb3-client/pom.xml new file mode 100644 index 0000000..5aae5ac --- /dev/null +++ b/vasc-xpql-ejb3-client/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + + vasc + net.forwardfire.vasc + 0.3.5-SNAPSHOT + .. + + vasc-xpql-ejb3-client + vasc-xpql-ejb3-client + xpql parsing client interface for ejb3 + + + net.forwardfire.vasc + vasc-xpql + ${project.version} + + + javax.ejb + ejb-api + 3.0 + provided + + + \ No newline at end of file diff --git a/vasc-xpql-ejb3/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManager.java b/vasc-xpql-ejb3-client/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManager.java similarity index 100% rename from vasc-xpql-ejb3/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManager.java rename to vasc-xpql-ejb3-client/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManager.java diff --git a/vasc-xpql-ejb3-client/src/main/java/net/forwardfire/vasc/xpql/ejb3/x4o/XpqlEjb3QueriesElement.java b/vasc-xpql-ejb3-client/src/main/java/net/forwardfire/vasc/xpql/ejb3/x4o/XpqlEjb3QueriesElement.java new file mode 100644 index 0000000..a7e3f6c --- /dev/null +++ b/vasc-xpql-ejb3-client/src/main/java/net/forwardfire/vasc/xpql/ejb3/x4o/XpqlEjb3QueriesElement.java @@ -0,0 +1,106 @@ +package net.forwardfire.vasc.xpql.ejb3.x4o; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.naming.Context; +import javax.naming.InitialContext; + + +import net.forwardfire.vasc.xpql.ejb3.XpqlQueryManager; +import net.forwardfire.vasc.xpql.query.Query; + +import org.x4o.xml.element.AbstractElement; +import org.x4o.xml.element.ElementException; + +public class XpqlEjb3QueriesElement extends AbstractElement { + + + @Override + public void doElementEnd() throws ElementException { + + // set queries map to element object + Map queries = new HashMap(100); + setElementObject(queries); + + String jndiName = getAttributes().get("jndi"); + if (jndiName==null) { + throw new ElementException("No 'jndi' attributes defined."); + } + if (jndiName.isEmpty()) { + throw new ElementException("Empty 'jndi' attributes can't load."); + } + + // load queries from ejb3 bean reference + XpqlQueryManager xpqlManager = null; + try { + Context context = new InitialContext(); + xpqlManager = (XpqlQueryManager)context.lookup( jndiName ); + } catch (Exception e) { + throw new ElementException("Could not get the ejb resource bundle: "+e.getMessage(),e); + } + if (xpqlManager==null) { + throw new ElementException("XpqlQueryManager ejb resource is null."); + } + XpqlController refBean = new XpqlController(xpqlManager); + setElementObject(refBean); + } + + class XpqlController implements Map { + private XpqlQueryManager xpqlManager = null; + + public XpqlController(XpqlQueryManager xpqlManager) { + this.xpqlManager=xpqlManager; + } + + public void clear() { + } + + public boolean containsKey(Object key) { + return true; + } + + public boolean containsValue(Object value) { + return true; + } + + public Set> entrySet() { + return null; + } + + public Query get(Object key) { + return xpqlManager.getQuery((String)key); + } + + public boolean isEmpty() { + return false; + } + + public Set keySet() { + return null; + } + + public Query put(String key, Query value) { + return null; + } + + @SuppressWarnings("unchecked") + public void putAll(Map m) { + } + + public Query remove(Object key) { + return null; + } + + public int size() { + return 0; + } + + public Collection values() { + return null; + } + + } +} diff --git a/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-namespaces.xml b/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-namespaces.xml new file mode 100644 index 0000000..b8dd4fd --- /dev/null +++ b/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-namespaces.xml @@ -0,0 +1,8 @@ + + + + + Vasc namespace for the xpql ejb3 backend + + vasc-xpql-ejb3.eld + \ No newline at end of file diff --git a/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-xpql-ejb3.eld b/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-xpql-ejb3.eld new file mode 100644 index 0000000..abea411 --- /dev/null +++ b/vasc-xpql-ejb3-client/src/main/resources/META-INF/vasc/vasc-xpql-ejb3.eld @@ -0,0 +1,4 @@ + + + + diff --git a/vasc-xpql-ejb3/.classpath b/vasc-xpql-ejb3-server/.classpath similarity index 100% rename from vasc-xpql-ejb3/.classpath rename to vasc-xpql-ejb3-server/.classpath diff --git a/vasc-xpql-ejb3/.project b/vasc-xpql-ejb3-server/.project similarity index 100% rename from vasc-xpql-ejb3/.project rename to vasc-xpql-ejb3-server/.project index 2c7d933..30c4131 100644 --- a/vasc-xpql-ejb3/.project +++ b/vasc-xpql-ejb3-server/.project @@ -16,12 +16,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/vasc-xpql-ejb3/.settings/org.eclipse.core.resources.prefs b/vasc-xpql-ejb3-server/.settings/org.eclipse.core.resources.prefs similarity index 100% rename from vasc-xpql-ejb3/.settings/org.eclipse.core.resources.prefs rename to vasc-xpql-ejb3-server/.settings/org.eclipse.core.resources.prefs diff --git a/vasc-xpql-ejb3/.settings/org.eclipse.jdt.core.prefs b/vasc-xpql-ejb3-server/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from vasc-xpql-ejb3/.settings/org.eclipse.jdt.core.prefs rename to vasc-xpql-ejb3-server/.settings/org.eclipse.jdt.core.prefs diff --git a/vasc-xpql-ejb3/.settings/org.eclipse.m2e.core.prefs b/vasc-xpql-ejb3-server/.settings/org.eclipse.m2e.core.prefs similarity index 100% rename from vasc-xpql-ejb3/.settings/org.eclipse.m2e.core.prefs rename to vasc-xpql-ejb3-server/.settings/org.eclipse.m2e.core.prefs diff --git a/vasc-xpql-ejb3/.settings/org.maven.ide.eclipse.prefs b/vasc-xpql-ejb3-server/.settings/org.maven.ide.eclipse.prefs similarity index 100% rename from vasc-xpql-ejb3/.settings/org.maven.ide.eclipse.prefs rename to vasc-xpql-ejb3-server/.settings/org.maven.ide.eclipse.prefs diff --git a/vasc-xpql-ejb3/pom.xml b/vasc-xpql-ejb3-server/pom.xml similarity index 69% rename from vasc-xpql-ejb3/pom.xml rename to vasc-xpql-ejb3-server/pom.xml index b8caac7..5a6122f 100644 --- a/vasc-xpql-ejb3/pom.xml +++ b/vasc-xpql-ejb3-server/pom.xml @@ -6,16 +6,16 @@ 0.3.5-SNAPSHOT net.forwardfire.vasc - vasc-xpql-ejb3 + vasc-xpql-ejb3-server 0.3.5-SNAPSHOT - vasc-xpql-ejb3 - xpql parsing service for ejb3 + vasc-xpql-ejb3-server + xpql parsing server impl for ejb3 net.forwardfire.vasc - vasc-xpql - 0.3.5-SNAPSHOT - + vasc-xpql-ejb3-client + ${project.version} + javax.ejb ejb-api @@ -29,10 +29,10 @@ provided - org.hibernate - hibernate-annotations - 3.4.0.GA - provided + javax.transaction + jta + 1.1 + provided \ No newline at end of file diff --git a/vasc-xpql-ejb3/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManagerImpl.java b/vasc-xpql-ejb3-server/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManagerImpl.java similarity index 100% rename from vasc-xpql-ejb3/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManagerImpl.java rename to vasc-xpql-ejb3-server/src/main/java/net/forwardfire/vasc/xpql/ejb3/XpqlQueryManagerImpl.java diff --git a/vasc-xpql-ejb3/src/main/resources/.empty b/vasc-xpql-ejb3-server/src/main/resources/.empty similarity index 100% rename from vasc-xpql-ejb3/src/main/resources/.empty rename to vasc-xpql-ejb3-server/src/main/resources/.empty diff --git a/vasc-xpql-ejb3/src/test/java/.empty b/vasc-xpql-ejb3-server/src/test/java/.empty similarity index 100% rename from vasc-xpql-ejb3/src/test/java/.empty rename to vasc-xpql-ejb3-server/src/test/java/.empty diff --git a/vasc-xpql-ejb3/src/test/resources/.empty b/vasc-xpql-ejb3-server/src/test/resources/.empty similarity index 100% rename from vasc-xpql-ejb3/src/test/resources/.empty rename to vasc-xpql-ejb3-server/src/test/resources/.empty diff --git a/vasc-xpql/.project b/vasc-xpql/.project index 6ecf3bc..c0679be 100644 --- a/vasc-xpql/.project +++ b/vasc-xpql/.project @@ -16,12 +16,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeAttributeConverter.java b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeObjectConverter.java similarity index 70% rename from vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeAttributeConverter.java rename to vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeObjectConverter.java index 1220e51..2103185 100644 --- a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeAttributeConverter.java +++ b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeObjectConverter.java @@ -22,11 +22,12 @@ package net.forwardfire.vasc.xpql.impl.x4o; +import java.util.Locale; + import net.forwardfire.vasc.xpql.query.QueryParameterValue.QueryParameterType; -import org.x4o.xml.element.AbstractElementAttributeConverter; -import org.x4o.xml.element.Element; -import org.x4o.xml.element.ElementAttributeConverterException; +import org.x4o.xml.converters.ObjectConverter; +import org.x4o.xml.converters.ObjectConverterException; /** @@ -34,16 +35,21 @@ import org.x4o.xml.element.ElementAttributeConverterException; * @author Willem Cazander * @version 1.0 Jan 21, 2007 */ -public class ParameterTypeAttributeConverter extends AbstractElementAttributeConverter { +public class ParameterTypeObjectConverter implements ObjectConverter { + + public Class getObjectClass() { + return QueryParameterType.class; + } - /** - * @see org.x4o.xml.element.AbstractElementClassParameterConverter#doConvertAttribute(org.x4o.xml.element.Element, java.lang.Object) - */ - public Object doConvertAttribute(Element arg0, Object value) throws ElementAttributeConverterException { + public String convertToString(Object obj, Locale locale) { + return ((QueryParameterType)obj).name(); + } + + public Object convertToObject(String str, Locale locale) throws ObjectConverterException { try { - return QueryParameterType.valueOf(""+value); + return QueryParameterType.valueOf(""+str); } catch (Exception ex) { - throw new ElementAttributeConverterException(this,"Could not convert to QueryParameterType value="+value,ex); + throw new ObjectConverterException(this,"Could not convert to QueryParameterType value="+str,ex); } } } \ No newline at end of file diff --git a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeAttributeConverter.java b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeObjectConverter.java similarity index 70% rename from vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeAttributeConverter.java rename to vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeObjectConverter.java index d355c7a..bafb224 100644 --- a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeAttributeConverter.java +++ b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeObjectConverter.java @@ -22,28 +22,33 @@ package net.forwardfire.vasc.xpql.impl.x4o; +import java.util.Locale; + import net.forwardfire.vasc.xpql.query.Query.QueryType; -import org.x4o.xml.element.AbstractElementAttributeConverter; -import org.x4o.xml.element.Element; -import org.x4o.xml.element.ElementAttributeConverterException; - +import org.x4o.xml.converters.ObjectConverter; +import org.x4o.xml.converters.ObjectConverterException; /** * * @author Willem Cazander * @version 1.0 Jan 21, 2007 */ -public class QueryTypeAttributeConverter extends AbstractElementAttributeConverter { +public class QueryTypeObjectConverter implements ObjectConverter { + + public Class getObjectClass() { + return QueryType.class; + } - /** - * @see org.x4o.xml.element.AbstractElementClassParameterConverter#doConvertAttribute(org.vasc.x4o.element.Element, java.lang.Object) - */ - public Object doConvertAttribute(Element arg0, Object value) throws ElementAttributeConverterException { + public String convertToString(Object obj, Locale locale) { + return ((QueryType)obj).name(); + } + + public Object convertToObject(String str, Locale locale) throws ObjectConverterException { try { - return QueryType.valueOf(""+value); + return QueryType.valueOf(""+str); } catch (Exception ex) { - throw new ElementAttributeConverterException(this,"Could not convert to QueryType value="+value,ex); - } + throw new ObjectConverterException(this,"Could not convert to QueryType value="+str,ex); + } } } \ No newline at end of file diff --git a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/x4o/XpqlLoadQueriesElement.java b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/x4o/XpqlLoadQueriesElement.java new file mode 100644 index 0000000..eb9cd4b --- /dev/null +++ b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/x4o/XpqlLoadQueriesElement.java @@ -0,0 +1,49 @@ +package net.forwardfire.vasc.xpql.x4o; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; + +import net.forwardfire.vasc.xpql.QueryStore; +import net.forwardfire.vasc.xpql.XPQLParser; +import net.forwardfire.vasc.xpql.query.Query; + +import org.x4o.xml.element.AbstractElement; +import org.x4o.xml.element.ElementException; + +public class XpqlLoadQueriesElement extends AbstractElement { + + private Logger logger = Logger.getLogger(XpqlLoadQueriesElement.class.getName()); + + @Override + public void doElementEnd() throws ElementException { + + // set queries map to element object + Map queries = new HashMap(100); + setElementObject(queries); + + String resource = getAttributes().get("resource"); + if (resource==null) { + throw new ElementException("No 'resource' attributes defined."); + } + if (resource.isEmpty()) { + throw new ElementException("Empty 'resource' attributes can't load."); + } + + // load queries from attributes + XPQLParser parser = new XPQLParser(); + logger.fine("Try loading: "+resource); + try { + parser.parseResource(resource); + } catch (Exception e) { + throw new RuntimeException("Could not load xpql resource: "+resource+" error: "+e.getMessage(),e); + } + QueryStore store = parser.getQueryStore(); + + for (String key:store.getQueryNames()) { + Query q = store.getQuery(key); + queries.put(q.getName(),q); + } + logger.info("Loaded xpql queries: "+store.getQueryNames().size()); + } +} diff --git a/vasc-xpql/src/main/resources/META-INF/vasc/vasc-namespaces.xml b/vasc-xpql/src/main/resources/META-INF/vasc/vasc-namespaces.xml new file mode 100644 index 0000000..d437c97 --- /dev/null +++ b/vasc-xpql/src/main/resources/META-INF/vasc/vasc-namespaces.xml @@ -0,0 +1,8 @@ + + + + + Vasc namespace for the vasc-xpql backend + + vasc-xpql.eld + \ No newline at end of file diff --git a/vasc-xpql/src/main/resources/META-INF/vasc/vasc-xpql.eld b/vasc-xpql/src/main/resources/META-INF/vasc/vasc-xpql.eld new file mode 100644 index 0000000..fcf26d7 --- /dev/null +++ b/vasc-xpql/src/main/resources/META-INF/vasc/vasc-xpql.eld @@ -0,0 +1,4 @@ + + + + diff --git a/vasc-xpql/src/main/resources/META-INF/xpql/xpql-lang.eld b/vasc-xpql/src/main/resources/META-INF/xpql/xpql-lang.eld index 3073d4d..6644463 100644 --- a/vasc-xpql/src/main/resources/META-INF/xpql/xpql-lang.eld +++ b/vasc-xpql/src/main/resources/META-INF/xpql/xpql-lang.eld @@ -6,8 +6,9 @@ - - + + + @@ -15,9 +16,12 @@ - - - + + + + + + diff --git a/vasc-xpql/src/test/resources/xpql/test-all.xml b/vasc-xpql/src/test/resources/xpql/test-all.xml index 8a1ef67..46cbf83 100644 --- a/vasc-xpql/src/test/resources/xpql/test-all.xml +++ b/vasc-xpql/src/test/resources/xpql/test-all.xml @@ -1,5 +1,5 @@ - @@ -84,4 +84,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/vasc-xpql/src/test/resources/xpql/test-meta.xml b/vasc-xpql/src/test/resources/xpql/test-meta.xml index 245cb2a..cfbf9d1 100644 --- a/vasc-xpql/src/test/resources/xpql/test-meta.xml +++ b/vasc-xpql/src/test/resources/xpql/test-meta.xml @@ -1,4 +1,4 @@ - + @@ -9,4 +9,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/vasc-xpql/src/test/resources/xpql/tests.xml b/vasc-xpql/src/test/resources/xpql/tests.xml index 8dc6774..f9454f2 100644 --- a/vasc-xpql/src/test/resources/xpql/tests.xml +++ b/vasc-xpql/src/test/resources/xpql/tests.xml @@ -1,5 +1,5 @@ - @@ -44,4 +44,4 @@ - \ No newline at end of file + \ No newline at end of file