diff --git a/.classpath b/.classpath index 4ce1b82..ba9359e 100644 --- a/.classpath +++ b/.classpath @@ -1,7 +1,7 @@ - - + + @@ -19,5 +19,6 @@ - + + diff --git a/.mymetadata b/.mymetadata new file mode 100644 index 0000000..d053dbb --- /dev/null +++ b/.mymetadata @@ -0,0 +1,13 @@ + + + + + + + diff --git a/.project b/.project index 7d4a4b1..e78fd34 100644 --- a/.project +++ b/.project @@ -5,13 +5,40 @@ + + com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder + + + org.eclipse.jdt.core.javabuilder + + com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator + + + + + com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator + + + + + org.eclipse.wst.validation.validationbuilder + + + + + com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder + + + + com.genuitec.eclipse.ast.deploy.core.deploymentnature + com.genuitec.eclipse.j2eedt.core.webnature org.eclipse.jem.workbench.JavaEMFNature org.eclipse.jdt.core.javanature org.eclipse.jem.beaninfo.BeanInfoNature diff --git a/lib/idcanet-x4o-bin.jar b/lib/idcanet-x4o-bin.jar index bb27fcb..9d465c7 100644 Binary files a/lib/idcanet-x4o-bin.jar and b/lib/idcanet-x4o-bin.jar differ diff --git a/src/META-INF/fieldtype-lang.eld b/src/META-INF/fieldtype-lang.eld index 235da1e..0167ca3 100644 --- a/src/META-INF/fieldtype-lang.eld +++ b/src/META-INF/fieldtype-lang.eld @@ -1,18 +1,27 @@ - - - + - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/META-INF/fieldtypes.xml b/src/META-INF/fieldtypes.xml index f2dd20f..16b6d8d 100644 --- a/src/META-INF/fieldtypes.xml +++ b/src/META-INF/fieldtypes.xml @@ -7,144 +7,113 @@ - - + - - + + + + + - + + + + + + + + + + + + + + + - - + + + + + + + - + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + - - - - - - - - - --> \ No newline at end of file diff --git a/src/META-INF/vasc-lang.eld b/src/META-INF/vasc-lang.eld index 4f3ba4a..9d7b1e8 100644 --- a/src/META-INF/vasc-lang.eld +++ b/src/META-INF/vasc-lang.eld @@ -3,7 +3,7 @@ - + @@ -16,9 +16,23 @@ --> - - - + + + + + + + + + + + + + + + + + diff --git a/src/com/idcanet/vasc/backends/ldap/LdapVascBackend.java b/src/com/idcanet/vasc/backends/ldap/LdapVascBackend.java index 9f66d42..8841c7a 100644 --- a/src/com/idcanet/vasc/backends/ldap/LdapVascBackend.java +++ b/src/com/idcanet/vasc/backends/ldap/LdapVascBackend.java @@ -26,7 +26,10 @@ package com.idcanet.vasc.backends.ldap; +import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -36,6 +39,12 @@ import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.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.LDAPSearchConstraints; +import com.novell.ldap.LDAPSearchResults; /** * @@ -46,6 +55,10 @@ public class LdapVascBackend extends AbstractVascBackend { private LdapConnectionProvider ldapConnectionProvider = null; + private String baseDN = null; + private String keyAttribute = null; + private String ldapFilter = null; + /** * @return the ldapConnectionProvider @@ -68,26 +81,98 @@ public class LdapVascBackend extends AbstractVascBackend { * @see com.idcanet.vasc.core.VascBackend#execute() */ public List execute() throws Exception { - return null; + LdapConnectionProvider prov = getLdapConnectionProvider(); + LDAPConnection connection = prov.getLdapConnection(); + List result = new ArrayList(50); + try { + + + LDAPSearchConstraints cons = new LDAPSearchConstraints(); + cons.setBatchSize( 0 ); + cons.setTimeLimit( 10000 ) ; + + int searchScope = LDAPConnection.SCOPE_ONE; + String searchBase = baseDN; + + System.out.println("\n\tReading 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 + + System.out.println("Got object :" + searchResults.getCount()); + while (searchResults.hasMore()) { + LDAPEntry entry = searchResults.next(); + System.out.println("We found "+entry.getDN()); + Map map = new HashMap(10); + + LDAPAttributeSet attributeSet = entry.getAttributeSet(); + Iterator i = attributeSet.iterator(); + while (i.hasNext()) { + LDAPAttribute attr = (LDAPAttribute)i.next(); + //System.out.println("ATTR: "+attr.getName()+" ... "); + + map.put(attr.getName(), attr.getStringValueArray()); + } + result.add(map); + } + } finally { + if (connection!=null) { + connection.clone(); + } + } + return result; } /** * @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object) */ public Object merge(Object object) throws Exception { - return object; + LdapConnectionProvider prov = getLdapConnectionProvider(); + LDAPConnection connection = prov.getLdapConnection(); + try { + + return object; + } finally { + if (connection!=null) { + connection.clone(); + } + } } /** * @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object) */ - public void persist(Object object) throws Exception { + public void persist(Object object) throws Exception { + LdapConnectionProvider prov = getLdapConnectionProvider(); + LDAPConnection connection = prov.getLdapConnection(); + try { + LDAPEntry entry = new LDAPEntry(); + // entry.getAttributeSet(). + + connection.add(entry); + } finally { + if (connection!=null) { + connection.clone(); + } + } } /** * @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object) */ public void delete(Object object) throws Exception { + LdapConnectionProvider prov = getLdapConnectionProvider(); + LDAPConnection connection = prov.getLdapConnection(); + try { + + } finally { + if (connection!=null) { + connection.clone(); + } + } } /** @@ -117,7 +202,11 @@ public class LdapVascBackend extends AbstractVascBackend { @SuppressWarnings("unchecked") public Object getValue(VascEntryField field, Object record) throws VascException { Map map = (Map)record; - return map.get(field.getBackendName()); + String[] r = (String[])map.get(field.getBackendName()); + if (r.length==1) { + return r[0]; + } + return r; } /** @@ -131,4 +220,46 @@ public class LdapVascBackend extends AbstractVascBackend { }; return result; } + + /** + * @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/src/com/idcanet/vasc/backends/ldap/SimpleLdapConnectionProvider.java b/src/com/idcanet/vasc/backends/ldap/SimpleLdapConnectionProvider.java index b353a88..b14df75 100644 --- a/src/com/idcanet/vasc/backends/ldap/SimpleLdapConnectionProvider.java +++ b/src/com/idcanet/vasc/backends/ldap/SimpleLdapConnectionProvider.java @@ -35,7 +35,6 @@ import com.novell.ldap.LDAPConnection; */ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { - private String ldapHost = "localhost"; private int ldapPort = LDAPConnection.DEFAULT_PORT; private int ldapVersion = LDAPConnection.LDAP_V3; @@ -73,7 +72,6 @@ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { return ldapHost; } - /** * @param ldapHost the ldapHost to set */ @@ -81,7 +79,6 @@ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { this.ldapHost = ldapHost; } - /** * @return the ldapPort */ @@ -89,7 +86,6 @@ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { return ldapPort; } - /** * @param ldapPort the ldapPort to set */ @@ -97,7 +93,6 @@ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { this.ldapPort = ldapPort; } - /** * @return the ldapVersion */ @@ -105,7 +100,6 @@ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { return ldapVersion; } - /** * @param ldapVersion the ldapVersion to set */ @@ -113,7 +107,6 @@ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { this.ldapVersion = ldapVersion; } - /** * @return the bindUser */ @@ -121,7 +114,6 @@ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { return bindUser; } - /** * @param bindUser the bindUser to set */ @@ -137,11 +129,10 @@ public class SimpleLdapConnectionProvider implements LdapConnectionProvider { 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/src/com/idcanet/vasc/core/AbstractVascEntryFieldType.java b/src/com/idcanet/vasc/core/AbstractVascEntryFieldType.java index 7ca3811..89ab19d 100644 --- a/src/com/idcanet/vasc/core/AbstractVascEntryFieldType.java +++ b/src/com/idcanet/vasc/core/AbstractVascEntryFieldType.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.core.ui.VascValueModel; import com.idcanet.vasc.validators.VascValidator; /** @@ -42,10 +43,11 @@ import com.idcanet.vasc.validators.VascValidator; abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { private String id = null; - private List> autoDetectionClasses = null; + private Class autoDetectClass = null; private List vascValidators = null; private Map properties = null; + private Object dataObject = null; private String uiComponentId = null; private String inputMask = null; @@ -89,6 +91,20 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { return new ArrayList(properties.keySet()); } + /** + * @return the dataObject + */ + public Object getDataObject() { + return dataObject; + } + + /** + * @param dataObject the dataObject to set + */ + public void setDataObject(Object dataObject) { + this.dataObject = dataObject; + } + /** * @see com.idcanet.vasc.core.VascEntryFieldType#getVascValidators() */ @@ -111,17 +127,17 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { } /** - * @see com.idcanet.vasc.core.VascEntryFieldType#addAutoDetectionClass(java.lang.Class) + * @see com.idcanet.vasc.core.VascEntryFieldType#getAutoDetectClass() */ - public void addAutoDetectionClass(Class classObject) { - autoDetectionClasses.add(classObject); + public Class getAutoDetectClass() { + return autoDetectClass; } /** - * @see com.idcanet.vasc.core.VascEntryFieldType#getAutoDetectionClasses() + * @see com.idcanet.vasc.core.VascEntryFieldType#setAutoDetectClass(java.lang.Class) */ - public List> getAutoDetectionClasses() { - return autoDetectionClasses; + public void setAutoDetectClass(Class autoDetectClass) { + this.autoDetectClass=autoDetectClass; } /** @@ -155,7 +171,7 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { /** * @see com.idcanet.vasc.core.VascEntryFieldType#getUIComponentCount() */ - public int getUIComponentCount() { + public int getUIComponentCount(VascEntryField entryField) throws VascException { return 1; } @@ -163,42 +179,32 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { * @see com.idcanet.vasc.core.VascEntryFieldType#provideEditorUIComponent(int) */ public VascUIComponent provideEditorUIComponent(int index,VascEntryField entryField) throws VascException { - if (index!=0) { - return null; - } ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = entryField.getClass().getClassLoader(); // fallback } String compId = getUIComponentId(); if (compId==null) { - compId = VascUIComponent.VASC_TEXT; // ??? mmmm + compId = VascUIComponent.VASC_TEXT; } - String componentClass = entryField.getVascEntry().getVascFrontendData().getVascUIComponent(compId); - try { - return (VascUIComponent)cl.loadClass(componentClass).newInstance(); - } catch (Exception e) { - throw new VascException(); - } + return entryField.getVascEntry().getVascFrontendData().getVascUIComponent(compId); } /** * @see com.idcanet.vasc.core.VascEntryFieldType#provideLabelUIComponent(int) */ public VascUIComponent provideLabelUIComponent(int index,VascEntryField entryField) throws VascException { - if (index!=0) { - return null; - } - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = entryField.getClass().getClassLoader(); // fallback - } - String componentClass = entryField.getVascEntry().getVascFrontendData().getVascUIComponent(VascUIComponent.VASC_LABEL); - try { - return (VascUIComponent)cl.loadClass(componentClass).newInstance(); - } catch (Exception e) { - throw new VascException(); - } + return entryField.getVascEntry().getVascFrontendData().getVascUIComponent(VascUIComponent.VASC_LABEL); } + /** + * @see com.idcanet.vasc.core.VascEntryFieldType#provideEditorVascValueModel() + */ + public VascValueModel provideEditorVascValueModel(int index,VascEntryField entryField) throws VascException { + if (index>0) { + throw new IllegalArgumentException("You have to override provideEditorVascValueModel if multi editor support is needed"); + } + VascValueModel model = new VascValueModel(); + return model; + } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/ui/AbstractVascUIComponent.java b/src/com/idcanet/vasc/core/VascBackendControllerLocal.java similarity index 79% rename from src/com/idcanet/vasc/core/ui/AbstractVascUIComponent.java rename to src/com/idcanet/vasc/core/VascBackendControllerLocal.java index 889b13b..2249590 100644 --- a/src/com/idcanet/vasc/core/ui/AbstractVascUIComponent.java +++ b/src/com/idcanet/vasc/core/VascBackendControllerLocal.java @@ -24,28 +24,15 @@ * should not be interpreted as representing official policies, either expressed or implied, of IDCA. */ -package com.idcanet.vasc.core.ui; +package com.idcanet.vasc.core; + /** * * @author Willem Cazander - * @version 1.0 Aug 12, 2007 + * @version 1.0 Nov 17, 2008 */ -abstract public class AbstractVascUIComponent implements VascUIComponent { +public interface VascBackendControllerLocal extends VascBackendController { - private VascUIComponent wrapper = null; - - /** - * @return the wrapper - */ - public VascUIComponent getWrapper() { - return wrapper; - } - - /** - * @param wrapper the wrapper to set - */ - public void setWrapper(VascUIComponent wrapper) { - this.wrapper = wrapper; - } + public void addVascBackend(VascBackend backend); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascController.java b/src/com/idcanet/vasc/core/VascController.java index f413eeb..cda2fc1 100644 --- a/src/com/idcanet/vasc/core/VascController.java +++ b/src/com/idcanet/vasc/core/VascController.java @@ -51,4 +51,10 @@ public interface VascController { * @return Returns the VascEntryFieldControllerResolver */ public VascEntryFieldTypeControllerResolver getVascEntryFieldTypeControllerResolver(); + + /** + * + * @return Returns the VascEventChannelControllerResolver + */ + public VascEventChannelControllerResolver getVascEventChannelControllerResolver(); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascEntryControllerLocal.java b/src/com/idcanet/vasc/core/VascEntryControllerLocal.java new file mode 100644 index 0000000..3c38f4f --- /dev/null +++ b/src/com/idcanet/vasc/core/VascEntryControllerLocal.java @@ -0,0 +1,40 @@ +/* + * Copyright 2004-2007 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.core; + + +/** + * The local interface which is not used in controllers. + * But is needed to be able to add entry in a safe way. + * + * @author Willem Cazander + * @version 1.0 Nov 16, 2008 + */ +public interface VascEntryControllerLocal extends VascEntryController { + + public void addVascEntry(VascEntry entry,VascController vascController) throws VascException; +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascEntryFieldType.java b/src/com/idcanet/vasc/core/VascEntryFieldType.java index 26524a0..069506a 100644 --- a/src/com/idcanet/vasc/core/VascEntryFieldType.java +++ b/src/com/idcanet/vasc/core/VascEntryFieldType.java @@ -29,6 +29,7 @@ package com.idcanet.vasc.core; import java.util.List; import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.core.ui.VascValueModel; import com.idcanet.vasc.validators.VascValidator; @@ -48,8 +49,8 @@ public interface VascEntryFieldType { public String getInputMask(); public void setInputMask(String inputMask); - public List> getAutoDetectionClasses(); - public void addAutoDetectionClass(Class classObject); + public Class getAutoDetectClass(); + public void setAutoDetectClass(Class classObject); public void addVascValidator(VascValidator vascValidator); public void removeVascValidator(VascValidator vascValidator); @@ -59,7 +60,11 @@ public interface VascEntryFieldType { public String getProperty(String name); public List getPropertyNames(); - public int getUIComponentCount(); + public void setDataObject(Object data); + public Object getDataObject(); + + public int getUIComponentCount(VascEntryField entryField) throws VascException; public VascUIComponent provideLabelUIComponent(int index,VascEntryField entryField) throws VascException; public VascUIComponent provideEditorUIComponent(int index,VascEntryField entryField) throws VascException; -} \ No newline at end of file + public VascValueModel provideEditorVascValueModel(int index,VascEntryField entryField) throws VascException; +} diff --git a/src/com/idcanet/vasc/core/ui/VascList.java b/src/com/idcanet/vasc/core/VascEventChannelController.java similarity index 66% rename from src/com/idcanet/vasc/core/ui/VascList.java rename to src/com/idcanet/vasc/core/VascEventChannelController.java index 6e304a2..2e3bf54 100644 --- a/src/com/idcanet/vasc/core/ui/VascList.java +++ b/src/com/idcanet/vasc/core/VascEventChannelController.java @@ -24,36 +24,15 @@ * should not be interpreted as representing official policies, either expressed or implied, of IDCA. */ -package com.idcanet.vasc.core.ui; - -import com.idcanet.vasc.core.VascEntry; -import com.idcanet.vasc.core.VascEntryField; +package com.idcanet.vasc.core; /** * * @author Willem Cazander - * @version 1.0 Aug 12, 2007 + * @version 1.0 Oct 27, 2008 */ -public class VascList extends VascUIComponentImplLoader { +public interface VascEventChannelController { - private VascSelectItemModel vascSelectItemModel = null; - public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws Exception { - return loadAndCreateComponent(this, entry, model, gui); - } - - /** - * @return the vascSelectItemModel - */ - public VascSelectItemModel getVascSelectItemModel() { - return vascSelectItemModel; - } - - /** - * @param vascSelectItemModel the vascSelectItemModel to set - */ - public void setVascSelectItemModel(VascSelectItemModel vascSelectItemModel) { - this.vascSelectItemModel = vascSelectItemModel; - } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascEventChannelControllerResolver.java b/src/com/idcanet/vasc/core/VascEventChannelControllerResolver.java new file mode 100644 index 0000000..774c4ee --- /dev/null +++ b/src/com/idcanet/vasc/core/VascEventChannelControllerResolver.java @@ -0,0 +1,38 @@ +/* + * Copyright 2004-2007 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.core; + + +/** + * + * @author Willem Cazander + * @version 1.0 Oct 27, 2008 + */ +public interface VascEventChannelControllerResolver { + + public VascEventChannelController getVascEventChannelController(); +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/VascException.java b/src/com/idcanet/vasc/core/VascException.java index b8e614d..2a26e34 100644 --- a/src/com/idcanet/vasc/core/VascException.java +++ b/src/com/idcanet/vasc/core/VascException.java @@ -40,6 +40,10 @@ public class VascException extends Exception { public VascException() { } + public VascException(String message) { + super(message); + } + public VascException(Exception e) { super(e); } diff --git a/src/com/idcanet/vasc/core/VascFrontendData.java b/src/com/idcanet/vasc/core/VascFrontendData.java index 52b6ee6..245281f 100644 --- a/src/com/idcanet/vasc/core/VascFrontendData.java +++ b/src/com/idcanet/vasc/core/VascFrontendData.java @@ -29,6 +29,7 @@ package com.idcanet.vasc.core; import java.util.List; import com.idcanet.vasc.core.entry.VascEntryResourceResolver; +import com.idcanet.vasc.core.ui.VascUIComponent; /** @@ -37,17 +38,7 @@ import com.idcanet.vasc.core.entry.VascEntryResourceResolver; * @version 1.0 Mar 21, 2007 */ public interface VascFrontendData { - - /** - * @return the vascBackend - */ - public VascBackend getVascBackend(); - - /** - * @param vascBackend the vascBackend to set - */ - public void setVascBackend(VascBackend vascBackend); - + /** * @return the entryDataList */ @@ -101,5 +92,14 @@ public interface VascFrontendData { public void putVascUIComponent(String rendererId,String uiComponentClass); - public String getVascUIComponent(String rendererId); + public VascUIComponent getVascUIComponent(String rendererId) throws VascException; + public String getVascUIComponentClass(String rendererId); + + public void setVascController(VascController vascController); + + public VascController getVascController(); + + public void addFieldVascUIComponents(VascEntryField field,VascUIComponent uiComponent,Object editor); + public VascUIComponent getFieldVascUIComponent(VascEntryField field); + public Object getFieldRealRenderer(VascEntryField field); } \ No newline at end of file diff --git a/src/com/idcanet/vasc/core/ui/VascUIComponent.java b/src/com/idcanet/vasc/core/ui/VascUIComponent.java index bed5eda..f38960d 100644 --- a/src/com/idcanet/vasc/core/ui/VascUIComponent.java +++ b/src/com/idcanet/vasc/core/ui/VascUIComponent.java @@ -40,16 +40,15 @@ public interface VascUIComponent { static public final String VASC_LABEL = "VascLabel"; static public final String VASC_TEXT = "VascText"; static public final String VASC_LIST = "VascList"; + static public final String VASC_BUTTON = "VascButton"; // optional ui Components static public final String VASC_TEXTAREA = "VascTextArea"; static public final String VASC_BOOLEAN = "VascBoolean"; static public final String VASC_DATE = "VascDate"; + static public final String VASC_COLOR = "VascColor"; - static public final String[] requiredUIComponents = {VASC_LABEL,VASC_TEXT,VASC_LIST}; - - public void setWrapper(VascUIComponent wrapper); - public VascUIComponent getWrapper(); + static public final String[] requiredUIComponents = {VASC_LABEL,VASC_TEXT,VASC_LIST,VASC_BUTTON}; public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws Exception; diff --git a/src/com/idcanet/vasc/core/ui/VascValueModel.java b/src/com/idcanet/vasc/core/ui/VascValueModel.java index 8b077ee..adc5ddb 100644 --- a/src/com/idcanet/vasc/core/ui/VascValueModel.java +++ b/src/com/idcanet/vasc/core/ui/VascValueModel.java @@ -41,17 +41,29 @@ public class VascValueModel { private Object value = null; private List listeners = null; + private VascValueModel parentModel = null; public VascValueModel() { listeners = new ArrayList(2); } + public VascValueModel(VascValueModel parentModel) { + this(); + this.parentModel=parentModel; + } public Object getValue() throws VascException { + if (parentModel!=null) { + return parentModel.getValue(); + } return value; } public void setValue(Object value) throws VascException { - this.value = value; + if (parentModel!=null) { + parentModel.setValue(value); + } else { + this.value = value; + } fireListeners(); } diff --git a/src/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java b/src/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java index eec3e97..f638935 100644 --- a/src/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java +++ b/src/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java @@ -31,8 +31,6 @@ import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Font; -import java.awt.Image; -import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -79,6 +77,8 @@ import com.idcanet.vasc.core.ui.VascColumnValueModelListener; import com.idcanet.vasc.core.ui.VascUIComponent; import com.idcanet.vasc.core.ui.VascValueModel; import com.idcanet.vasc.frontends.swing.ui.SwingBoolean; +import com.idcanet.vasc.frontends.swing.ui.SwingButton; +import com.idcanet.vasc.frontends.swing.ui.SwingColorChooser; import com.idcanet.vasc.frontends.swing.ui.SwingDate; import com.idcanet.vasc.frontends.swing.ui.SwingLabel; import com.idcanet.vasc.frontends.swing.ui.SwingList; @@ -110,11 +110,13 @@ public class SwingVascFrontend extends AbstractVascFrontend { vfd.putVascUIComponent(VascUIComponent.VASC_LABEL,SwingLabel.class.getName()); vfd.putVascUIComponent(VascUIComponent.VASC_TEXT, SwingText.class.getName()); vfd.putVascUIComponent(VascUIComponent.VASC_LIST, SwingList.class.getName()); + vfd.putVascUIComponent(VascUIComponent.VASC_BUTTON, SwingButton.class.getName()); // optional UI components vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwingBoolean.class.getName()); vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwingDate.class.getName()); vfd.putVascUIComponent(VascUIComponent.VASC_TEXTAREA, SwingTextArea.class.getName()); + vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwingColorChooser.class.getName()); } public ImageIcon getImageIcon(String imageResource) { @@ -188,7 +190,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { , null // Default button's label ); if (response==JOptionPane.YES_OPTION) { - entry.getVascFrontendData().getVascBackend().delete(rowBean); + entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()).delete(rowBean); entry.getVascFrontendData().getEntryDataList().remove(rowBean); entry.getVascFrontendData().setEntryDataObject(null); //entry.getVascFrontendController().getVascFrontendHelper().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean); @@ -262,9 +264,11 @@ public class SwingVascFrontend extends AbstractVascFrontend { if (c.isEdit()==false) { continue; } - column++; - for (int i=0;i"); + writer.append(" Today is: " + new Date()); + writer.append("

"); + + + HtmlInputText inputText = new HtmlInputText(); + inputText.setParent(this); + // inputText.setId(this.getId() + ":_text1"); + inputText.encodeBegin(context); + inputText.encodeEnd(context); + + if (inputText.getRendersChildren()) { + for (UIComponent child:inputText.getChildren()) { + child.encodeBegin(context); + child.encodeEnd(context); + } + } + + } + + + public void restoreState(FacesContext context, Object state) { + this.state = (Object[]) state; + super.restoreState(context, this.state[0]); + bar = (String) this.state[1]; + } + + public Object saveState(FacesContext context) { + if (state == null) { + state = new Object[2]; + } + state[0] = super.saveState(context); + state[1] = bar; + return state; + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java b/src/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java new file mode 100644 index 0000000..4383c47 --- /dev/null +++ b/src/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java @@ -0,0 +1,79 @@ +/* + * Copyright 2004-2007 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.frontends.web.jsf; + +import javax.el.ValueExpression; +import javax.faces.component.UIComponent; +import javax.faces.component.UIComponentBase; +import javax.faces.context.FacesContext; +import javax.faces.context.ResponseWriter; +import javax.faces.render.Renderer; +import javax.faces.webapp.UIComponentTag; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Nov 16, 2008 + */ +public class VascUIComponentTag extends UIComponentTag { + + protected ValueExpression bar; + + public String getComponentType() { + return VascUIComponent.COMPONENT_TYPE; + } + + public String getRendererType() { + return VascUIComponent.COMPONENT_TYPE; + } + + public ValueExpression getBar() { + return bar; + } + + protected void setProperties(UIComponent component) { + super.setProperties(component); + VascUIComponent download = null; + try { + //foo = (VascUIComponent) component; + } catch (ClassCastException cce) { + throw new IllegalStateException("Component " + component.toString() + + " not expected type. Expected: com.foo.Foo. Perhaps you're missing a tag?"); + } + + if (bar != null) { + //foo.setValueExpression("bar", bar); + } + } + + public void release() { + super.release(); + bar = null; + } + +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java b/src/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java index 7553483..eb8576c 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java +++ b/src/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java @@ -26,12 +26,12 @@ package com.idcanet.vasc.impl; -import java.util.Date; - +import com.idcanet.vasc.core.VascBackend; import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascEntryFieldSet; +import com.idcanet.vasc.core.VascEntryFieldType; import com.idcanet.vasc.core.VascEntryFinalizer; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascLinkEntry; @@ -67,6 +67,13 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { } } + // Check if backendId is valid + VascBackend back = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() ); + if (back==null) { + throw new IllegalArgumentException("The VascEntry backendId is not found in backends: '"+entry.getBackendId()+"'"); + } + + // Fill up all not field i18n keys String id = entry.getId(); @@ -183,18 +190,26 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { //vef.setStyleList("vasc.entry."+id+"."+vid+".styleEdit"); } if (vef.getVascEntryFieldValue()==null) { - vef.setVascEntryFieldValue( vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() ).provideVascEntryFieldValue(vef) ); + VascBackend back2 = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() ); + vef.setVascEntryFieldValue(back2.provideVascEntryFieldValue(vef)); } - if (vef.getVascEntryFieldType()==null) { - - - vef.setVascEntryFieldType(vascController.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("TextField")); - - if (vef.getDefaultValue() instanceof Boolean) { - ///vef.setVascEntryFieldType(vascEntryFieldType); - } else if (vef.getDefaultValue() instanceof Date) { - } else { + if (vef.getVascEntryFieldType()==null) { + Object defValue = vef.getDefaultValue(); + if (defValue != null) { + for (String typeId: vascController.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeIds()) { + VascEntryFieldType type = vascController.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById(typeId); + + if (type.getAutoDetectClass()!=null) { + if (type.getAutoDetectClass().isAssignableFrom(defValue.getClass())) { + vef.setVascEntryFieldType(type); + break; + } + } + } + } + if (vef.getVascEntryFieldType()==null) { + vef.setVascEntryFieldType(vascController.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("TextField")); } //vef.setStyleList("vasc.entry."+id+"."+vid+".styleEdit"); } diff --git a/src/com/idcanet/vasc/impl/DefaultVascBackendController.java b/src/com/idcanet/vasc/impl/DefaultVascBackendController.java index c52c9ce..451a031 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascBackendController.java +++ b/src/com/idcanet/vasc/impl/DefaultVascBackendController.java @@ -30,7 +30,7 @@ import java.util.HashMap; import java.util.Map; import com.idcanet.vasc.core.VascBackend; -import com.idcanet.vasc.core.VascBackendController; +import com.idcanet.vasc.core.VascBackendControllerLocal; /** * @@ -38,7 +38,7 @@ import com.idcanet.vasc.core.VascBackendController; * @author Willem Cazander * @version 1.0 Sep 18, 2008 */ -public class DefaultVascBackendController implements VascBackendController { +public class DefaultVascBackendController implements VascBackendControllerLocal { private Map backends = null; @@ -53,6 +53,9 @@ public class DefaultVascBackendController implements VascBackendController { return backends.get(id); } + /** + * Local + */ public void addVascBackend(VascBackend backend) { if (backend==null) { throw new NullPointerException("backend must not be null."); diff --git a/src/com/idcanet/vasc/impl/DefaultVascController.java b/src/com/idcanet/vasc/impl/DefaultVascController.java index 92f5508..aa370b3 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascController.java +++ b/src/com/idcanet/vasc/impl/DefaultVascController.java @@ -30,6 +30,7 @@ import com.idcanet.vasc.core.VascBackendControllerResolver; import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntryControllerResolver; import com.idcanet.vasc.core.VascEntryFieldTypeControllerResolver; +import com.idcanet.vasc.core.VascEventChannelControllerResolver; /** * @@ -42,7 +43,23 @@ public class DefaultVascController implements VascController { private VascBackendControllerResolver vascBackendControllerResolver = null; private VascEntryControllerResolver vascEntryControllerResolver = null; private VascEntryFieldTypeControllerResolver vascEntryFieldTypeControllerResolver = null; + private VascEventChannelControllerResolver vascEventChannelControllerResolver = null; + /** + * @return the vascEventChannelControllerResolver + */ + public VascEventChannelControllerResolver getVascEventChannelControllerResolver() { + return vascEventChannelControllerResolver; + } + + /** + * @param vascEventChannelControllerResolver the vascEventChannelControllerResolver to set + */ + public void setVascEventChannelControllerResolver( + VascEventChannelControllerResolver vascEventChannelControllerResolver) { + this.vascEventChannelControllerResolver = vascEventChannelControllerResolver; + } + /** * @return the vascBackendControllerResolver */ diff --git a/src/com/idcanet/vasc/impl/DefaultVascEntryController.java b/src/com/idcanet/vasc/impl/DefaultVascEntryController.java index 59b2372..39367fe 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascEntryController.java +++ b/src/com/idcanet/vasc/impl/DefaultVascEntryController.java @@ -33,7 +33,7 @@ import java.util.Map; import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntry; -import com.idcanet.vasc.core.VascEntryController; +import com.idcanet.vasc.core.VascEntryControllerLocal; import com.idcanet.vasc.core.VascException; /** @@ -42,7 +42,7 @@ import com.idcanet.vasc.core.VascException; * @author Willem Cazander * @version 1.0 Sep 18, 2008 */ -public class DefaultVascEntryController implements VascEntryController { +public class DefaultVascEntryController implements VascEntryControllerLocal { private Map entries = null; diff --git a/src/com/idcanet/vasc/impl/DefaultVascEntryField.java b/src/com/idcanet/vasc/impl/DefaultVascEntryField.java index 86d3b61..108d830 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascEntryField.java +++ b/src/com/idcanet/vasc/impl/DefaultVascEntryField.java @@ -95,7 +95,7 @@ public class DefaultVascEntryField implements VascEntryField { } public DefaultVascEntryField(String id) { - super(); + this(); setId(id); } diff --git a/src/com/idcanet/vasc/impl/DefaultVascEntryFieldSet.java b/src/com/idcanet/vasc/impl/DefaultVascEntryFieldSet.java index 1a9b6af..918bf1a 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascEntryFieldSet.java +++ b/src/com/idcanet/vasc/impl/DefaultVascEntryFieldSet.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.impl; +import java.util.ArrayList; import java.util.List; import com.idcanet.vasc.core.VascEntryFieldSet; @@ -52,6 +53,10 @@ public class DefaultVascEntryFieldSet implements VascEntryFieldSet { private List vascEntryFieldIds = null; + public DefaultVascEntryFieldSet() { + vascEntryFieldIds = new ArrayList(10); + } + /** * @return the id */ diff --git a/src/com/idcanet/vasc/impl/DefaultVascFrontendData.java b/src/com/idcanet/vasc/impl/DefaultVascFrontendData.java index 2c745fc..26c9fa1 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascFrontendData.java +++ b/src/com/idcanet/vasc/impl/DefaultVascFrontendData.java @@ -31,12 +31,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascController; +import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascEntryFinalizer; +import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascFrontend; import com.idcanet.vasc.core.VascFrontendData; import com.idcanet.vasc.core.VascFrontendHelper; import com.idcanet.vasc.core.entry.VascEntryResourceResolver; +import com.idcanet.vasc.core.ui.VascUIComponent; /** @@ -46,7 +49,6 @@ import com.idcanet.vasc.core.entry.VascEntryResourceResolver; */ public class DefaultVascFrontendData implements VascFrontendData { - private VascBackend vascBackend = null; private List entryDataList = null; private Object entryDataObject = null; private VascFrontend vascFrontend = null; @@ -54,26 +56,19 @@ public class DefaultVascFrontendData implements VascFrontendData { private VascFrontendHelper vascFrontendHelper = null; private VascEntryResourceResolver vascEntryResourceResolver = null; private Map uiComponents = null; + private VascController vascController = null; + + private Map fieldComps = null; + private Map fieldEditors = null; public DefaultVascFrontendData() { entryDataList = new ArrayList(0); uiComponents = new HashMap(8); + + fieldComps = new HashMap(8); + fieldEditors = new HashMap(8); } - - /** - * @return the vascBackend - */ - public VascBackend getVascBackend() { - return vascBackend; - } - - /** - * @param vascBackend the vascBackend to set - */ - public void setVascBackend(VascBackend vascBackend) { - this.vascBackend = vascBackend; - } - + /** * @return the entryDataList */ @@ -158,10 +153,27 @@ public class DefaultVascFrontendData implements VascFrontendData { this.vascEntryResourceResolver = vascEntryResourceResolver; } + + public VascUIComponent getVascUIComponent(String rendererId) throws VascException { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl == null) { + cl = rendererId.getClass().getClassLoader(); // fallback + } + String componentClass = getVascUIComponentClass(rendererId); + if (componentClass==null) { + throw new VascException("No component Class found for frontend UIComponent: "+rendererId); + } + try { + return (VascUIComponent)cl.loadClass(componentClass).newInstance(); + } catch (Exception e) { + throw new VascException(e); + } + } + /** * @see com.idcanet.vasc.core.VascFrontendData#getVascUIComponent(java.lang.String) */ - public String getVascUIComponent(String rendererId) { + public String getVascUIComponentClass(String rendererId) { return uiComponents.get(rendererId); } @@ -171,4 +183,40 @@ public class DefaultVascFrontendData implements VascFrontendData { public void putVascUIComponent(String rendererId, String uiComponentClass) { uiComponents.put(rendererId, uiComponentClass); } + + /** + * @return the vascController + */ + public VascController getVascController() { + return vascController; + } + + /** + * @param vascController the vascController to set + */ + public void setVascController(VascController vascController) { + this.vascController = vascController; + } + + /** + * @see com.idcanet.vasc.core.VascFrontendData#addFieldVascUIComponents(com.idcanet.vasc.core.VascEntryField, com.idcanet.vasc.core.ui.VascUIComponent, java.lang.Object) + */ + public void addFieldVascUIComponents(VascEntryField field,VascUIComponent uiComponent, Object editor) { + fieldComps.put(field, uiComponent); + fieldEditors.put(field, editor); + } + + /** + * @see com.idcanet.vasc.core.VascFrontendData#getFieldRealRenderer(com.idcanet.vasc.core.VascEntryField) + */ + public Object getFieldRealRenderer(VascEntryField field) { + return fieldEditors.get(field); + } + + /** + * @see com.idcanet.vasc.core.VascFrontendData#getFieldVascUIComponent(com.idcanet.vasc.core.VascEntryField) + */ + public VascUIComponent getFieldVascUIComponent(VascEntryField field) { + return fieldComps.get(field); + } } \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java b/src/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java index f431651..099742f 100644 --- a/src/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java +++ b/src/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java @@ -34,6 +34,8 @@ import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascFrontendHelper; import com.idcanet.vasc.core.entry.VascEntryEventListener; import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.validators.VascValidator; /** @@ -117,7 +119,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { if (object!=null) { return object; } - object = entry.getVascFrontendData().getVascBackend().provideVascEntryRecordCreator(entry).newRecord(entry); + object = entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()).provideVascEntryRecordCreator(entry).newRecord(entry); //fireVascEvent(VascEventListener.VascEventType.BEAN_INIT, object); return object; } @@ -143,7 +145,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { public Object mergeObject(VascEntry entry, Object object) { Object result = null; try { - object = entry.getVascFrontendData().getVascBackend().merge(object); + object = entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()).merge(object); //fireVascEvent(VascEventListener.VascEventType.BEAN_MERGE,object); // todo: make faster // add to table at position old old object @@ -162,7 +164,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { */ public void refreshData(VascEntry entry) throws Exception { entry.getVascFrontendData().setEntryDataObject(null); - entry.getVascFrontendData().setEntryDataList(entry.getVascFrontendData().getVascBackend().execute()); + entry.getVascFrontendData().setEntryDataList(entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()).execute()); //fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, null); } @@ -197,6 +199,32 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { //logger.fine("Got invaliled value: "+ival.length); for(VascEntryField col:entry.getVascEntryFields()) { + + try { + Object object = col.getVascEntryFieldValue().getValue(col, bean); + VascUIComponent comp = entry.getVascFrontendData().getFieldVascUIComponent(col); + + for (VascValidator val:col.getVascEntryFieldType().getVascValidators()) { + if (val.isObjectValid(object)==false) { + comp.setErrorText("error"); + error = true; + } else { + comp.setErrorText(null); + } + } + + for (VascValidator val:col.getVascValidators()) { + if (val.isObjectValid(object)==false) { + comp.setErrorText("error"); + error = true; + } else { + comp.setErrorText(null); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + /* if(col.getVascUIComponent()==null) { continue; // we only DISPLAY user input errors !! diff --git a/src/com/idcanet/vasc/impl/DefaultVascLinkEntry.java b/src/com/idcanet/vasc/impl/DefaultVascLinkEntry.java new file mode 100644 index 0000000..607b829 --- /dev/null +++ b/src/com/idcanet/vasc/impl/DefaultVascLinkEntry.java @@ -0,0 +1,55 @@ +/* + * Copyright 2004-2008 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.impl; + +import com.idcanet.vasc.core.VascLinkEntry; + + +/** + * The DefaultVascLinkEntry + * + * @author Willem Cazander + * @version 1.0 Oct 27, 2007 + */ +public class DefaultVascLinkEntry implements VascLinkEntry { + + private String vascEntryName = null; + + /** + * @return the vascEntryName + */ + public String getVascEntryName() { + return vascEntryName; + } + + /** + * @param vascEntryName the vascEntryName to set + */ + public void setVascEntryName(String vascEntryName) { + this.vascEntryName = vascEntryName; + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/type/MultiTextVascEntryFieldType.java b/src/com/idcanet/vasc/impl/type/MultiTextVascEntryFieldType.java new file mode 100644 index 0000000..87c9c52 --- /dev/null +++ b/src/com/idcanet/vasc/impl/type/MultiTextVascEntryFieldType.java @@ -0,0 +1,131 @@ +/* + * Copyright 2004-2007 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.impl.type; + +import java.util.List; + +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.ui.VascValueModel; + + +/** + * Custem FieldType for multi text values. + * + * @author Willem Cazander + * @version 1.0 Nov 17, 2008 + */ +public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType { + + private Object getIndexValue(VascEntryField entryField,int index) throws VascException { + Object record = entryField.getVascEntry().getVascFrontendData().getEntryDataObject(); + Object value = entryField.getVascEntryFieldValue().getValue(entryField, record); + + if (value instanceof List) { + return ((List)value).get(index); + } + if (value instanceof String[]) { + if (index >= ((String[])value).length ) { + return ""; + } + return ((String[])value)[index]; + } + if (value instanceof String) { + return ((String)value); + } + throw new VascException("Unknown object type"); + } + + private void setIndexValue(VascEntryField entryField,int index,Object newValue) throws VascException { + Object record = entryField.getVascEntry().getVascFrontendData().getEntryDataObject(); + Object value = entryField.getVascEntryFieldValue().getValue(entryField, record); + + if (value instanceof List) { + ((List)value).set(index, newValue); + return; + } + if (value instanceof String[]) { + + if (index+1 > ((String[])value).length ) { + String[] n = new String[index+1]; + for (int i=0;i<((String[])value).length;i++) { + n[i]= ((String[])value)[i]; + } + value = n; + } + ((String[])value)[index] = newValue.toString(); + return; + } + if (value instanceof String) { + value = new String[] { (String)value }; + return; + } + throw new VascException("Unknown object type: "+value); + } + + /** + * @see com.idcanet.vasc.core.AbstractVascEntryFieldType#getUIComponentCount(com.idcanet.vasc.core.VascEntryField) + */ + @Override + public int getUIComponentCount(VascEntryField entryField) throws VascException { + + + Object record = entryField.getVascEntry().getVascFrontendData().getEntryDataObject(); + Object value = entryField.getVascEntryFieldValue().getValue(entryField, record); + + if (value instanceof List) { + return ((List)value).size()+1; + } + if (value instanceof String[]) { + return ((String[])value).length+1; + } + if (value instanceof String) { + return 1+1; + } + throw new VascException("Unknown object type: "+value); + } + + /** + * @see com.idcanet.vasc.core.AbstractVascEntryFieldType#provideEditorVascValueModel(int, com.idcanet.vasc.core.VascEntryField) + */ + @Override + public VascValueModel provideEditorVascValueModel(final int index,final VascEntryField entryField) { + VascValueModel model = new VascValueModel() { + public Object getValue() throws VascException { + Object value = getIndexValue(entryField,index); + return value; + } + + public void setValue(Object value) throws VascException { + setIndexValue(entryField,index,value); + super.setValue(value); + } + }; + + return model; + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/x4o/VascBackendElementConfigurator.java b/src/com/idcanet/vasc/impl/x4o/VascBackendElementConfigurator.java new file mode 100644 index 0000000..6fa28a7 --- /dev/null +++ b/src/com/idcanet/vasc/impl/x4o/VascBackendElementConfigurator.java @@ -0,0 +1,68 @@ +/* + * Copyright 2004-2008 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.impl.x4o; + +import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascBackendController; +import com.idcanet.vasc.core.VascBackendControllerLocal; +import com.idcanet.vasc.core.VascController; + +import com.idcanet.x4o.element.AbstractElementConfigurator; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementConfiguratorException; + + +/** + * Adds the backend to the local controller + * + * @author Willem Cazander + * @version 1.0 Nov 16, 2008 + */ +public class VascBackendElementConfigurator extends AbstractElementConfigurator { + + /** + * @see com.idcanet.x4o.element.AbstractElementConfigurator#doConfigEndTag(com.idcanet.x4o.element.Element) + */ + @Override + public void doConfigEndTag(Element element) throws ElementConfiguratorException { + + VascBackend backend = (VascBackend)element.getElementObject(); + + VascController vascController = VascParser.getVascController(element.getElementContext()); + VascBackendController backendController = vascController.getVascBackendControllerResolver().getVascBackendController(); + + if (backendController instanceof VascBackendControllerLocal) { + try { + ((VascBackendControllerLocal)backendController).addVascBackend(backend); + } catch (Exception e) { + throw new ElementConfiguratorException(this,"Couln't add backend: "+e.getMessage(),e); + } + } else { + throw new ElementConfiguratorException(this,"Can not add backend '"+backend.getId()+"' to VascBackendController because we have no access to VascBackendControllerLocal interface."); + } + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/x4o/VascEntryElementConfigurator.java b/src/com/idcanet/vasc/impl/x4o/VascEntryElementConfigurator.java new file mode 100644 index 0000000..93fde9c --- /dev/null +++ b/src/com/idcanet/vasc/impl/x4o/VascEntryElementConfigurator.java @@ -0,0 +1,68 @@ +/* + * Copyright 2004-2008 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.impl.x4o; + +import com.idcanet.vasc.core.VascController; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryController; +import com.idcanet.vasc.core.VascEntryControllerLocal; +import com.idcanet.vasc.core.VascException; +import com.idcanet.x4o.element.AbstractElementConfigurator; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementConfiguratorException; + + +/** + * Converts the type to the type object + * + * @author Willem Cazander + * @version 1.0 Nov 16, 2008 + */ +public class VascEntryElementConfigurator extends AbstractElementConfigurator { + + /** + * @see com.idcanet.x4o.element.AbstractElementConfigurator#doConfigEndTag(com.idcanet.x4o.element.Element) + */ + @Override + public void doConfigEndTag(Element element) throws ElementConfiguratorException { + + VascEntry entry = (VascEntry)element.getElementObject(); + + VascController vascController = VascParser.getVascController(element.getElementContext()); + VascEntryController entryController = vascController.getVascEntryControllerResolver().getVascEntryController(); + + if (entryController instanceof VascEntryControllerLocal) { + try { + ((VascEntryControllerLocal)entryController).addVascEntry(entry, vascController); + } catch (VascException e) { + throw new ElementConfiguratorException(this,"Couln't add entry: "+e.getMessage(),e); + } + } else { + throw new ElementConfiguratorException(this,"Can not add entry '"+entry.getId()+"' to VascEntryController because we have no access to VascEntryControllerLocal interface."); + } + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java b/src/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java new file mode 100644 index 0000000..60655b6 --- /dev/null +++ b/src/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java @@ -0,0 +1,63 @@ +/* + * Copyright 2004-2008 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.impl.x4o; + +import com.idcanet.vasc.core.VascEntryFieldSet; +import com.idcanet.x4o.element.AbstractElementParameterConverter; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementParameterConverterException; + + +/** + * Converts the VascEntryFieldSet parameter + * + * @author Willem Cazander + * @version 1.0 Nov 17, 2008 + */ +public class VascEntryFieldSetParameterConverter extends AbstractElementParameterConverter { + + /** + * @see com.idcanet.x4o.element.AbstractElementParameterConverter#doConvertParameter(com.idcanet.x4o.element.Element, java.lang.Object) + */ + @Override + public Object doConvertParameter(Element element, Object parameterValue) throws ElementParameterConverterException { + + if (parameterValue==null) { + throw new NullPointerException("can't convert null parameter"); + } + if ("".equals(parameterValue)) { + return null; + } + String[] ids = parameterValue.toString().split(","); + + VascEntryFieldSet set = (VascEntryFieldSet)element.getElementObject(); + for (String id:ids) { + set.addVascEntryFieldId(id); + } + return null; + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java b/src/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java new file mode 100644 index 0000000..1e60f03 --- /dev/null +++ b/src/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java @@ -0,0 +1,62 @@ +/* + * Copyright 2004-2008 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.impl.x4o; + +import com.idcanet.vasc.core.VascController; +import com.idcanet.x4o.element.AbstractElementParameterConverter; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementParameterConverterException; + + +/** + * Converts the type to the type object + * + * @author Willem Cazander + * @version 1.0 Nov 16, 2008 + */ +public class VascEntryFieldTypeParameterConverter extends AbstractElementParameterConverter { + + /** + * @see com.idcanet.x4o.element.AbstractElementParameterConverter#doConvertParameter(com.idcanet.x4o.element.Element, java.lang.Object) + */ + @Override + public Object doConvertParameter(Element element, Object parameterValue) throws ElementParameterConverterException { + + if (parameterValue==null) { + throw new NullPointerException("can't convert null parameter"); + } + if ("".equals(parameterValue)) { + parameterValue = "TextField"; // ?? + } + String fieldID = parameterValue.toString(); + + VascController controller = VascParser.getVascController(element.getElementContext()); + Object result = controller.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById(fieldID); + + return result; + } +} \ No newline at end of file diff --git a/src/com/idcanet/vasc/impl/x4o/VascParser.java b/src/com/idcanet/vasc/impl/x4o/VascParser.java new file mode 100644 index 0000000..b796ea9 --- /dev/null +++ b/src/com/idcanet/vasc/impl/x4o/VascParser.java @@ -0,0 +1,79 @@ +/* + * Copyright 2004-2008 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.impl.x4o; + +import java.io.IOException; +import javax.el.ValueExpression; +import javax.xml.parsers.ParserConfigurationException; +import org.xml.sax.SAXException; + +import com.idcanet.vasc.core.VascController; +import com.idcanet.x4o.core.X4OParser; +import com.idcanet.x4o.element.ElementContext; + +/** + * Parses the vasc xml streams + * + * + * + * @author Willem Cazander + * @version 1.0 Oct 27, 2008 + */ +public class VascParser extends X4OParser { + + static public String VASC_LANGUAGE = "vasc"; + private VascController vascController = null; + + /** + * @see X4OParser#X4OParser(String) + */ + public VascParser(VascController vascController) throws Exception { + super(VASC_LANGUAGE); + if (vascController==null) { + throw new NullPointerException("vascController may not be null"); + } + this.vascController=vascController; + } + + public VascController getVascController() { + return vascController; + } + + static public VascController getVascController(ElementContext context) { + ValueExpression ee = context.getExpressionFactory().createValueExpression(context.getELContext(),"${vascController}", VascController.class); + VascController con = (VascController)ee.getValue(context.getELContext()); + return con; + } + + protected void preStartParsing() throws ParserConfigurationException,SAXException,IOException { + super.preStartParsing(); + + // Add the controller to EL + ValueExpression ee = getElementContext().getExpressionFactory().createValueExpression(getElementContext().getELContext(),"${vascController}", VascController.class); + ee.setValue(getElementContext().getELContext(), vascController); + } +} \ No newline at end of file diff --git a/tests/META-INF/vasc-lang.eld b/tests/META-INF/vasc-lang.eld deleted file mode 100644 index c19c954..0000000 --- a/tests/META-INF/vasc-lang.eld +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/META-INF/vasc-namespaces.xml b/tests/META-INF/vasc-namespaces.xml deleted file mode 100644 index 01ac3aa..0000000 --- a/tests/META-INF/vasc-namespaces.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - Vasc namespace for x4o vasc state/table/column language - - META-INF/vasc-lang.eld - \ No newline at end of file diff --git a/tests/com/idcanet/vasc/SwingTest.java b/tests/com/idcanet/vasc/SwingTest.java index 5df6d2e..657a27f 100644 --- a/tests/com/idcanet/vasc/SwingTest.java +++ b/tests/com/idcanet/vasc/SwingTest.java @@ -26,10 +26,15 @@ package com.idcanet.vasc; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.InputStream; import java.util.logging.LogManager; import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.JPanel; import com.idcanet.vasc.core.VascEntry; @@ -57,16 +62,43 @@ public class SwingTest extends TestCase { public void testAll() throws Exception { JFrame.setDefaultLookAndFeelDecorated(false); + VascEntry entry = TestTable.getVascTable(); + JFrame frame = viewEntry(entry); + while (frame.isVisible()) { + Thread.sleep(1000); + } + } + + public JFrame viewEntry(final VascEntry entry) throws Exception { // get GUI JFrame frame = new JFrame(); - frame.setTitle("Vasc Test - Swing"); + frame.setTitle("Vasc Test - Swing - "+entry.getName()); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationRelativeTo(null); - - // get table - VascEntry entry = TestTable.getVascTable(); - + + JMenuBar menubar = new JMenuBar(); + JMenu vascMenu = new JMenu("Vasc Entries"); + + for (final String id:entry.getVascFrontendData().getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryIds()) { + JMenuItem item = new JMenuItem(id); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + VascEntry ee = entry.getVascFrontendData().getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryById(id); + TestTable.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); @@ -74,18 +106,12 @@ public class SwingTest extends TestCase { // render render.initEntry(entry); - - //table.getTableColumns().get(0).set - - //render.renderEdit(table.getTableData().get(0)); render.renderView(); // view frame.pack(); frame.setVisible(true); - while (frame.isVisible()) { - Thread.sleep(1000); - } + return frame; } } \ No newline at end of file diff --git a/tests/com/idcanet/vasc/TestTable.java b/tests/com/idcanet/vasc/TestTable.java index bf79968..dc50243 100644 --- a/tests/com/idcanet/vasc/TestTable.java +++ b/tests/com/idcanet/vasc/TestTable.java @@ -32,7 +32,6 @@ import java.util.Date; import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; -import com.idcanet.vasc.core.ui.VascList; import com.idcanet.vasc.impl.DefaultVascBackedEntryFinalizer; import com.idcanet.vasc.impl.DefaultVascBackendController; import com.idcanet.vasc.impl.DefaultVascBackendControllerResolver; @@ -50,12 +49,9 @@ 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; -import com.idcanet.vasc.impl.entry.BeanVascEntryRecordCreator; -import com.idcanet.vasc.impl.entry.BeanPropertyVascEntryFieldValue; -import com.idcanet.vasc.impl.entry.DefaultVascEntryResourceResolver; import com.idcanet.vasc.impl.type.DefaultVascEntryFieldTypeController; import com.idcanet.vasc.impl.type.DefaultVascEntryFieldTypeControllerResolver; -import com.idcanet.vasc.models.TestModel; +import com.idcanet.vasc.impl.x4o.VascParser; /** @@ -69,7 +65,7 @@ public class TestTable { // for test TestModelVascDataSource backend = new TestModelVascDataSource(); - backend.setId("testBackend"); + backend.setId("testBackend1"); // config full controller for local jvm use DefaultVascController c = new DefaultVascController(); @@ -87,6 +83,7 @@ public class TestTable { DefaultVascEntryFieldTypeControllerResolver vascEntryFieldTypeControllerResolver = new DefaultVascEntryFieldTypeControllerResolver(); DefaultVascEntryFieldTypeController vascEntryFieldTypeController = new DefaultVascEntryFieldTypeController(); + //vascEntryFieldTypeController. vascEntryFieldTypeControllerResolver.setVascEntryFieldTypeController(vascEntryFieldTypeController); c.setVascEntryFieldTypeControllerResolver(vascEntryFieldTypeControllerResolver); @@ -94,19 +91,10 @@ public class TestTable { } - - static public VascEntry getVascTable() throws Exception { - - VascController c = getDefaultVascController(); - - // config table - VascEntry entry = new DefaultVascEntry(); - entry.setId("test1"); - entry.setBackendId("testBackend"); - + static public void fill(VascEntry entry,VascController c) { DefaultVascFrontendData vascFrontendData = new DefaultVascFrontendData(); - vascFrontendData.setVascBackend(c.getVascBackendControllerResolver().getVascBackendController().getVascBackendById("testBackend")); - + vascFrontendData.setVascController(c); + VascI18nTextValue vascEntryResourceResolver = new VascI18nTextValue();// new DefaultVascEntryResourceResolver(); vascFrontendData.setVascEntryResourceResolver(vascEntryResourceResolver); @@ -114,7 +102,7 @@ public class TestTable { vascFrontendData.setVascFrontendHelper(vascFrontendHelper); entry.setVascFrontendData(vascFrontendData); - + entry.addRowAction(new AddRowAction()); entry.addRowAction(new EditRowAction()); entry.addRowAction(new DeleteRowAction()); @@ -122,7 +110,28 @@ public class TestTable { entry.addGlobalAction(new XMLExportGlobalAction()); entry.addGlobalAction(new CSVExportGlobalAction()); entry.addGlobalAction(new RefreshDataGlobalAction()); + } + + static public VascEntry getVascTable() throws Exception { + VascController c = getDefaultVascController(); + + VascParser parser = new VascParser(c); + parser.parseResource("resources/vasc/tables.xml"); + + VascEntry entry = parser.getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryById("test1"); + fill(entry,c); + + + // config table + + //VascEntry entry = new DefaultVascEntry(); + //entry.setId("test1"); + //entry.setBackendId("testBackend"); + + + + /* //table.addUserOptions(userOption); //table.addColumnActions(new GraphColumnAction()); @@ -131,6 +140,7 @@ public class TestTable { entry.addVascEntryField(field); field = new DefaultVascEntryField("description"); + field.setVascEntryFieldType(c.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("EmailField")); entry.addVascEntryField(field); field = new DefaultVascEntryField("active"); @@ -142,19 +152,14 @@ public class TestTable { entry.addVascEntryField(field); field = new DefaultVascEntryField("testModel"); - //field.setVascEntryFieldType(c.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("TextField")); - //field.getVascEntryFieldType() - VascList list = new VascList(); - list.setVascSelectItemModel((TestModelVascDataSource)c.getVascBackendControllerResolver().getVascBackendController().getVascBackendById("testBackend")); - //field.setVascUIComponent(list); + field.setVascEntryFieldType(c.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("ListField")); + field.getVascEntryFieldType().setDataObject(c.getVascBackendControllerResolver().getVascBackendController().getVascBackendById("testBackend")); entry.addVascEntryField(field); field = new DefaultVascEntryField("hexColor"); + field.setVascEntryFieldType(c.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("ColorField")); field.setDefaultValue("#FF3355"); - //VascColorChooser ui = new VascColorChooser(); - //ui.setHexSwingEncoding(true); - //field.setVascUIComponent(ui); entry.addVascEntryField(field); printEntry(entry); @@ -165,6 +170,7 @@ public class TestTable { DefaultVascFrontendEntryFinalizer f2 = new DefaultVascFrontendEntryFinalizer(); entry = f2.finalizeVascEntry(entry,c); //printEntry(entry); + */ return entry; } diff --git a/tests/resources/vasc/tables.xml b/tests/resources/vasc/tables.xml index 488cf20..f56a572 100644 --- a/tests/resources/vasc/tables.xml +++ b/tests/resources/vasc/tables.xml @@ -2,6 +2,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (&(objectClass=sudoRole)) - ${baseDn},cn=%s - sudoRole,top - - - - - - - - \ No newline at end of file diff --git a/www/META-INF/MANIFEST.MF b/www/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/www/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/www/META-INF/vasc-jsf.taglib.xml b/www/META-INF/vasc-jsf.taglib.xml new file mode 100644 index 0000000..fa8b340 --- /dev/null +++ b/www/META-INF/vasc-jsf.taglib.xml @@ -0,0 +1,15 @@ + + + + + http://foo.com/foo + + foo + + com.foo.Foo + com.foo.component.Foo + + + \ No newline at end of file diff --git a/www/WEB-INF/faces-config.xml b/www/WEB-INF/faces-config.xml new file mode 100644 index 0000000..cfd6c98 --- /dev/null +++ b/www/WEB-INF/faces-config.xml @@ -0,0 +1,31 @@ + + + + + + Vasc + vasc-jsf + com.idcanet.vasc.frontends.web.jsf.VascUIComponent + + + + + + \ No newline at end of file diff --git a/www/WEB-INF/vasc-jsf.tld b/www/WEB-INF/vasc-jsf.tld new file mode 100644 index 0000000..2421927 --- /dev/null +++ b/www/WEB-INF/vasc-jsf.tld @@ -0,0 +1,27 @@ + + + + 1.0 + vasc + http://vasc.idcanet.com/jsf + + + vasc + com.idcanet.vasc.frontends.web.jsf.VascUIComponentTag + JSP + + + id + false + true + + + + bar + false + java.lang.Object + + + \ No newline at end of file diff --git a/www/WEB-INF/web.xml b/www/WEB-INF/web.xml new file mode 100644 index 0000000..5715804 --- /dev/null +++ b/www/WEB-INF/web.xml @@ -0,0 +1,81 @@ + + + + index.jsp + + + + facelets.SKIP_COMMENTS + true + + + + javax.faces.STATE_SAVING_METHOD + server + + + com.sun.faces.validateXml + true + + + com.sun.faces.verifyObjects + true + + + javax.faces.DEFAULT_SUFFIX + .jsp + + + + + facelets.VIEW_MAPPINGS + *.xhtml + + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + + + Faces Servlet + /faces/* + + + Faces Servlet + *.jsf + + + + + + diff --git a/www/index.jsp b/www/index.jsp new file mode 100644 index 0000000..db9befe --- /dev/null +++ b/www/index.jsp @@ -0,0 +1,12 @@ + + + TEST INDEX.JSP + \ No newline at end of file diff --git a/www/vasc_test1.jsp b/www/vasc_test1.jsp new file mode 100644 index 0000000..cb446ca --- /dev/null +++ b/www/vasc_test1.jsp @@ -0,0 +1,24 @@ + + + + + + + +

TEST vasc1

+

The HelloWorld UI Component:

+ +
+ + +
+
\ No newline at end of file