1 28 29 package org.jibx.binding.model; 30 31 import java.io.IOException ; 32 import java.io.InputStream ; 33 import java.net.URL ; 34 35 import org.jibx.binding.util.StringArray; 36 import org.jibx.runtime.IUnmarshallingContext; 37 import org.jibx.runtime.JiBXException; 38 39 51 52 public class IncludeElement extends NestingElementBase 53 { 54 55 public static final StringArray s_allowedAttributes = 56 new StringArray(new String [] { "path" }); 57 58 59 private String m_includePath; 60 61 62 private BindingElement m_binding; 63 64 67 public IncludeElement() { 68 super(INCLUDE_ELEMENT); 69 } 70 71 76 public void setIncludePath(String path) { 77 m_includePath = path; 78 } 79 80 85 public String getIncludePath() { 86 return m_includePath; 87 } 88 89 95 public BindingElement getBinding() { 96 return m_binding; 97 } 98 99 102 108 private void preSet(IUnmarshallingContext uctx) throws JiBXException { 109 validateAttributes(uctx, s_allowedAttributes); 110 } 111 112 115 public void prevalidate(ValidationContext vctx) { 116 if (m_includePath == null) { 117 vctx.addFatal("No include path specified"); 118 } else { 119 try { 120 121 BindingElement root = vctx.getBindingRoot(); 123 URL base = root.getBaseUrl(); 124 URL url = new URL (base, m_includePath); 125 String path = url.toExternalForm(); 126 if (root.addIncludePath(path)) { 127 128 int split = path.lastIndexOf('/'); 130 String fname = path; 131 if (split >= 0) { 132 fname = fname.substring(split+1); 133 } 134 135 InputStream is = url.openStream(); 137 m_binding = BindingElement.readBinding(is, fname, vctx); 138 m_binding.setBaseUrl(url); 139 } 140 141 } catch (JiBXException e) { 142 vctx.addFatal(e.getMessage()); 143 } catch (IOException e) { 144 vctx.addFatal("Error accessing included binding with path \"" + 145 m_includePath + "\": " + e.getMessage()); 146 } 147 } 148 } 149 } | Popular Tags |