2007-08-02 04:48:34 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright 2004-2006 IDCA. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
|
|
|
|
* following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
|
|
|
|
* the following disclaimer.
|
|
|
|
|
* 2. 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 IDCA 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 IDCA 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.
|
|
|
|
|
*
|
|
|
|
|
* The views and conclusions contained in the software and documentation are those of the authors and
|
|
|
|
|
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.idcanet.vasc;
|
|
|
|
|
|
2009-04-13 19:19:48 +02:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
2008-09-15 00:00:09 +02:00
|
|
|
import java.lang.reflect.Method;
|
2007-09-21 02:42:04 +02:00
|
|
|
|
2009-08-11 20:31:29 +02:00
|
|
|
import com.idcanet.vasc.core.VascBackend;
|
2008-09-13 17:04:49 +02:00
|
|
|
import com.idcanet.vasc.core.VascController;
|
2008-09-08 02:07:46 +02:00
|
|
|
import com.idcanet.vasc.core.VascEntry;
|
|
|
|
|
import com.idcanet.vasc.core.VascEntryField;
|
2009-08-11 20:31:29 +02:00
|
|
|
import com.idcanet.vasc.core.VascException;
|
|
|
|
|
import com.idcanet.vasc.impl.DefaultVascBackedEntryFinalizer;
|
2008-09-21 13:30:50 +02:00
|
|
|
import com.idcanet.vasc.impl.DefaultVascBackendController;
|
|
|
|
|
import com.idcanet.vasc.impl.DefaultVascBackendControllerResolver;
|
|
|
|
|
import com.idcanet.vasc.impl.DefaultVascEntryController;
|
|
|
|
|
import com.idcanet.vasc.impl.DefaultVascEntryControllerResolver;
|
2008-09-13 17:04:49 +02:00
|
|
|
import com.idcanet.vasc.impl.DefaultVascController;
|
2008-09-15 00:00:09 +02:00
|
|
|
import com.idcanet.vasc.impl.DefaultVascFrontendData;
|
|
|
|
|
import com.idcanet.vasc.impl.DefaultVascFrontendHelper;
|
2009-04-13 19:19:48 +02:00
|
|
|
import com.idcanet.vasc.impl.DefaultVascUserRoleController;
|
|
|
|
|
import com.idcanet.vasc.impl.DefaultVascUserRoleControllerResolver;
|
2009-08-11 20:31:29 +02:00
|
|
|
import com.idcanet.vasc.impl.VascBackendProxyPaged;
|
|
|
|
|
import com.idcanet.vasc.impl.VascBackendProxySearch;
|
|
|
|
|
import com.idcanet.vasc.impl.VascBackendProxySort;
|
2007-08-02 04:48:34 +02:00
|
|
|
import com.idcanet.vasc.impl.actions.AddRowAction;
|
|
|
|
|
import com.idcanet.vasc.impl.actions.CSVExportGlobalAction;
|
|
|
|
|
import com.idcanet.vasc.impl.actions.DeleteRowAction;
|
|
|
|
|
import com.idcanet.vasc.impl.actions.EditRowAction;
|
|
|
|
|
import com.idcanet.vasc.impl.actions.RefreshDataGlobalAction;
|
|
|
|
|
import com.idcanet.vasc.impl.actions.XMLExportGlobalAction;
|
2008-09-15 00:00:09 +02:00
|
|
|
import com.idcanet.vasc.impl.type.DefaultVascEntryFieldTypeController;
|
|
|
|
|
import com.idcanet.vasc.impl.type.DefaultVascEntryFieldTypeControllerResolver;
|
2008-11-18 22:04:23 +01:00
|
|
|
import com.idcanet.vasc.impl.x4o.VascParser;
|
2007-08-02 04:48:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Willem Cazander
|
|
|
|
|
* @version 1.0 Aug 2, 2007
|
|
|
|
|
*/
|
|
|
|
|
public class TestTable {
|
|
|
|
|
|
2008-09-15 00:00:09 +02:00
|
|
|
static VascController getDefaultVascController() throws Exception {
|
|
|
|
|
|
2008-09-21 13:30:50 +02:00
|
|
|
// for test
|
|
|
|
|
TestModelVascDataSource backend = new TestModelVascDataSource();
|
2008-11-18 22:04:23 +01:00
|
|
|
backend.setId("testBackend1");
|
2008-09-15 00:00:09 +02:00
|
|
|
|
2008-09-21 13:30:50 +02:00
|
|
|
// config full controller for local jvm use
|
|
|
|
|
DefaultVascController c = new DefaultVascController();
|
2008-09-15 00:00:09 +02:00
|
|
|
|
2008-09-21 13:30:50 +02:00
|
|
|
DefaultVascBackendControllerResolver vascBackendControllerResolver = new DefaultVascBackendControllerResolver();
|
|
|
|
|
DefaultVascBackendController vascBackendController = new DefaultVascBackendController();
|
|
|
|
|
vascBackendController.addVascBackend(backend);
|
|
|
|
|
vascBackendControllerResolver.setVascBackendController(vascBackendController);
|
|
|
|
|
c.setVascBackendControllerResolver(vascBackendControllerResolver);
|
2008-09-15 00:00:09 +02:00
|
|
|
|
2008-09-21 13:30:50 +02:00
|
|
|
DefaultVascEntryControllerResolver vascEntryControllerResolver = new DefaultVascEntryControllerResolver();
|
|
|
|
|
DefaultVascEntryController vascEntryController = new DefaultVascEntryController();
|
|
|
|
|
vascEntryControllerResolver.setVascEntryController(vascEntryController);
|
|
|
|
|
c.setVascEntryControllerResolver(vascEntryControllerResolver);
|
2008-09-15 00:00:09 +02:00
|
|
|
|
|
|
|
|
DefaultVascEntryFieldTypeControllerResolver vascEntryFieldTypeControllerResolver = new DefaultVascEntryFieldTypeControllerResolver();
|
|
|
|
|
DefaultVascEntryFieldTypeController vascEntryFieldTypeController = new DefaultVascEntryFieldTypeController();
|
|
|
|
|
vascEntryFieldTypeControllerResolver.setVascEntryFieldTypeController(vascEntryFieldTypeController);
|
|
|
|
|
c.setVascEntryFieldTypeControllerResolver(vascEntryFieldTypeControllerResolver);
|
2008-09-13 17:04:49 +02:00
|
|
|
|
2009-04-13 19:19:48 +02:00
|
|
|
|
|
|
|
|
DefaultVascUserRoleControllerResolver vascUserRoleControllerResolver = new DefaultVascUserRoleControllerResolver();
|
|
|
|
|
DefaultVascUserRoleController vascUserRoleController = new DefaultVascUserRoleController(2288L,"idca.nl","user","admin");
|
|
|
|
|
vascUserRoleControllerResolver.setVascUserRoleController(vascUserRoleController);
|
|
|
|
|
c.setVascUserRoleControllerResolver(vascUserRoleControllerResolver);
|
|
|
|
|
|
2008-09-13 17:04:49 +02:00
|
|
|
return c;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-18 22:04:23 +01:00
|
|
|
static public void fill(VascEntry entry,VascController c) {
|
2009-04-13 19:19:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-15 00:00:09 +02:00
|
|
|
DefaultVascFrontendData vascFrontendData = new DefaultVascFrontendData();
|
2008-11-18 22:04:23 +01:00
|
|
|
vascFrontendData.setVascController(c);
|
|
|
|
|
|
2008-09-21 13:30:50 +02:00
|
|
|
VascI18nTextValue vascEntryResourceResolver = new VascI18nTextValue();// new DefaultVascEntryResourceResolver();
|
2008-09-15 00:00:09 +02:00
|
|
|
vascFrontendData.setVascEntryResourceResolver(vascEntryResourceResolver);
|
|
|
|
|
|
|
|
|
|
DefaultVascFrontendHelper vascFrontendHelper = new DefaultVascFrontendHelper();
|
|
|
|
|
vascFrontendData.setVascFrontendHelper(vascFrontendHelper);
|
|
|
|
|
|
2009-04-13 19:19:48 +02:00
|
|
|
// hack
|
|
|
|
|
if (entry.getVascFrontendData()!=null) {
|
|
|
|
|
entry.setVascFrontendData(vascFrontendData);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
entry.setVascFrontendData(vascFrontendData);
|
|
|
|
|
}
|
2009-08-11 20:31:29 +02:00
|
|
|
|
|
|
|
|
VascBackend backend = entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId());
|
|
|
|
|
if (backend.isSearchable()==false) {
|
|
|
|
|
backend = new VascBackendProxySearch(backend,entry);
|
|
|
|
|
}
|
|
|
|
|
if (backend.isPageable()==false) {
|
|
|
|
|
backend = new VascBackendProxyPaged(backend,entry);
|
|
|
|
|
}
|
|
|
|
|
if (backend.isSortable()==false) {
|
|
|
|
|
backend = new VascBackendProxySort(backend,entry);
|
|
|
|
|
}
|
|
|
|
|
vascFrontendData.setVascBackend(backend);
|
2009-04-13 19:19:48 +02:00
|
|
|
|
|
|
|
|
|
2008-09-08 02:07:46 +02:00
|
|
|
entry.addRowAction(new AddRowAction());
|
|
|
|
|
entry.addRowAction(new EditRowAction());
|
|
|
|
|
entry.addRowAction(new DeleteRowAction());
|
2007-08-02 04:48:34 +02:00
|
|
|
|
2008-09-08 02:07:46 +02:00
|
|
|
entry.addGlobalAction(new XMLExportGlobalAction());
|
|
|
|
|
entry.addGlobalAction(new CSVExportGlobalAction());
|
|
|
|
|
entry.addGlobalAction(new RefreshDataGlobalAction());
|
2009-08-11 20:31:29 +02:00
|
|
|
|
|
|
|
|
// hackje om deze manuale actions van i18n keys te voorzien;
|
|
|
|
|
// this is temp untill x4o templaing
|
|
|
|
|
DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer();
|
|
|
|
|
try {
|
|
|
|
|
f.finalizeVascEntry(entry, c);
|
|
|
|
|
} catch (VascException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2008-11-18 22:04:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public VascEntry getVascTable() throws Exception {
|
|
|
|
|
|
|
|
|
|
VascController c = getDefaultVascController();
|
|
|
|
|
|
|
|
|
|
VascParser parser = new VascParser(c);
|
2009-04-13 19:19:48 +02:00
|
|
|
File f = File.createTempFile("test-vasc", ".xml");
|
|
|
|
|
parser.setDebugOutputStream(new FileOutputStream(f));
|
2008-12-07 19:26:44 +01:00
|
|
|
parser.parseResource("vasc/tables.xml");
|
2008-11-18 22:04:23 +01:00
|
|
|
|
|
|
|
|
VascEntry entry = parser.getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryById("test1");
|
|
|
|
|
fill(entry,c);
|
2009-04-13 19:19:48 +02:00
|
|
|
|
2008-09-08 02:07:46 +02:00
|
|
|
return entry;
|
2007-08-02 04:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
2008-09-15 00:00:09 +02:00
|
|
|
static void printEntry(VascEntry e) throws Exception {
|
|
|
|
|
|
|
|
|
|
System.out.println("");
|
|
|
|
|
System.out.println("=== Printing entry ===");
|
|
|
|
|
System.out.println("");
|
|
|
|
|
|
|
|
|
|
for (Method m:e.getClass().getMethods()) {
|
|
|
|
|
if (m.getName().startsWith("get")==false) { //a bit dirty
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (m.getParameterTypes().length>0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-04-13 19:19:48 +02:00
|
|
|
System.out.println("prop: "+m.getName()+" -> "+m.invoke(e));
|
2008-09-15 00:00:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("");
|
|
|
|
|
System.out.println("=== Fields ===");
|
|
|
|
|
for (VascEntryField vef:e.getVascEntryFields()) {
|
|
|
|
|
|
|
|
|
|
System.out.println("=== Field: "+vef.getId());
|
|
|
|
|
|
|
|
|
|
for (Method m:vef.getClass().getMethods()) {
|
|
|
|
|
if (m.getName().startsWith("get")==false) { //a bit dirty
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (m.getParameterTypes().length>0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-04-13 19:19:48 +02:00
|
|
|
System.out.println("prop: "+m.getName()+" -> "+m.invoke(vef));
|
2008-09-15 00:00:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-02 04:48:34 +02:00
|
|
|
}
|