1 16 package org.apache.cocoon.forms.binding; 17 18 import java.util.Locale ; 19 20 import org.apache.cocoon.forms.FormsConstants; 21 import org.apache.cocoon.forms.datatype.convertor.Convertor; 22 import org.apache.cocoon.forms.util.DomHelper; 23 import org.apache.cocoon.i18n.I18nUtils; 24 import org.w3c.dom.Element ; 25 26 42 public class MultiValueJXPathBindingBuilder 43 extends JXPathBindingBuilderBase { 44 45 public JXPathBindingBase buildBinding( 46 Element bindingElem, 47 JXPathBindingManager.Assistant assistant) throws BindingException { 48 49 try { 50 CommonAttributes commonAtts = JXPathBindingBuilderBase.getCommonAttributes(bindingElem); 51 52 String multiValueId = DomHelper.getAttribute(bindingElem, "id", null); 53 String parentPath = DomHelper.getAttribute(bindingElem, "parent-path", null); 54 String rowPath = DomHelper.getAttribute(bindingElem, "row-path", null); 55 56 57 Convertor convertor = null; 58 Locale convertorLocale = Locale.US; 59 Element convertorEl = DomHelper.getChildElement(bindingElem, FormsConstants.DEFINITION_NS, "convertor"); 60 if (convertorEl != null) { 61 String datatype = DomHelper.getAttribute(convertorEl, "datatype", null); 62 String localeStr = DomHelper.getAttribute(convertorEl, "locale", null); 63 if (localeStr != null) { 64 convertorLocale = I18nUtils.parseLocale(localeStr); 65 } 66 67 convertor = assistant.getDatatypeManager().createConvertor(datatype, convertorEl); 68 } 69 70 MultiValueJXPathBinding existingBinding = (MultiValueJXPathBinding)assistant.getContext().getSuperBinding(); 71 JXPathBindingBase[] existingBindings = new JXPathBindingBase[0]; 72 if(existingBinding != null) { 73 commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(existingBinding.getCommonAtts(),commonAtts); 74 existingBindings = existingBinding.getUpdateBinding().getChildBindings(); 75 76 if(multiValueId == null) 77 multiValueId = existingBinding.getId(); 78 if(parentPath == null) 79 parentPath = existingBinding.getMultiValuePath(); 80 if(rowPath == null) 81 rowPath = existingBinding.getRowPath(); 82 83 if(convertor == null) { 84 convertor = existingBinding.getConvertor(); 85 convertorLocale = existingBinding.getLocale(); 86 } 87 } 88 89 Element updateWrapElement = 90 DomHelper.getChildElement(bindingElem, BindingManager.NAMESPACE, "on-update"); 91 JXPathBindingBase[] updateBindings = assistant.makeChildBindings(updateWrapElement,existingBindings); 92 93 94 return new MultiValueJXPathBinding( commonAtts, multiValueId, parentPath, rowPath, 95 updateBindings, convertor, convertorLocale); 96 } catch (BindingException e) { 97 throw e; 98 } catch (Exception e) { 99 throw new BindingException("Error building multi value binding defined at " + DomHelper.getLocation(bindingElem), e); 100 } 101 } 102 } 103 | Popular Tags |