1 16 package org.apache.cocoon.woody.binding; 17 18 import org.apache.avalon.framework.logger.LogEnabled; 19 import org.apache.avalon.framework.logger.Logger; 20 import org.apache.cocoon.woody.util.DomHelper; 21 import org.w3c.dom.Element ; 22 23 35 public abstract class JXPathBindingBuilderBase implements LogEnabled { 36 37 private Logger logger; 38 39 42 public void enableLogging(Logger logger) { 43 this.logger = logger; 44 if (logger.isDebugEnabled()) { 45 logger.debug("JXPathBindingBuilderBase got logger..."); 46 } 47 } 48 49 53 protected Logger getLogger() { 54 return this.logger; 55 } 56 57 66 public abstract JXPathBindingBase buildBinding( 67 Element bindingElm, 68 JXPathBindingManager.Assistant assistant) throws BindingException; 69 70 93 static CommonAttributes getCommonAttributes(Element bindingElm) throws BindingException { 94 try { 95 if (DomHelper.getAttributeAsBoolean(bindingElm, "readonly", false)) { 98 throw new BindingException("Error in binding file " + DomHelper.getLocation(bindingElm) 99 + "\nThe usage of the attribute @readonly has been deprecated in favour of @direction."); 100 } 101 if (DomHelper.getAttributeAsBoolean(bindingElm, "read-only", false)) { 102 throw new BindingException("Error in binding file " + DomHelper.getLocation(bindingElm) 103 + "\nThe usage of the attribute @read-only has been deprecated in favour of @direction."); 104 } 105 106 String direction = DomHelper.getAttribute(bindingElm, "direction", "both"); 107 108 String leniency = DomHelper.getAttribute(bindingElm, "lenient", null); 109 110 return new CommonAttributes(direction, leniency); 111 } catch (BindingException e) { 112 throw e; 113 } catch (Exception e) { 114 throw new BindingException("Error building binding defined at " + DomHelper.getLocation(bindingElm), e); 115 } 116 } 117 118 123 static class CommonAttributes{ 124 127 final boolean loadEnabled; 128 131 final boolean saveEnabled; 132 final Boolean leniency; 133 134 final static CommonAttributes DEFAULT = new CommonAttributes(true, true, null); 135 136 CommonAttributes(String direction, String leniency){ 137 this(isLoadEnabled(direction), isSaveEnabled(direction), decideLeniency(leniency)); 138 } 139 140 CommonAttributes(boolean loadEnabled, boolean saveEnabled, Boolean leniency){ 141 this.loadEnabled = loadEnabled; 142 this.saveEnabled = saveEnabled; 143 this.leniency = leniency; 144 } 145 146 151 private static boolean isLoadEnabled(String direction) { 152 return "both".equals(direction) || "load".equals(direction); 153 } 154 155 160 private static boolean isSaveEnabled(String direction) { 161 return "both".equals(direction) || "save".equals(direction); 162 } 163 164 165 171 private static Boolean decideLeniency(String leniency) { 172 if (leniency == null) { 173 return null; 174 } 175 return new Boolean (leniency); 176 } 177 } 178 } 179 | Popular Tags |