1   /***************************************************************/
2   /* This class was generated by ds-to-spi-annotations-processor */
3   /***************************************************************/
4   
5   package org.daisy.pipeline.html.impl;
6   
7   public class HtmlDocumentBuilder_SPI
8          implements org.daisy.common.spi.ServiceWithProperties
9                   , org.daisy.common.xml.DocumentBuilder
10  {
11  	
12  	private static final org.slf4j.Logger spi_log = org.slf4j.LoggerFactory.getLogger(HtmlDocumentBuilder_SPI.class);
13  	
14  	private final java.util.Map spi_props;
15  	private boolean spi_deactivated = false;
16  	
17  	private final org.daisy.pipeline.html.impl.HtmlDocumentBuilder delegate;
18  
19  	public HtmlDocumentBuilder_SPI() {
20  		delegate = new org.daisy.pipeline.html.impl.HtmlDocumentBuilder();
21  		spi_log.trace("Creating HtmlDocumentBuilder");
22  		spi_props = new java.util.HashMap();
23  		spi_props.put("component.name", "html-document-builder");
24  		{
25  			spi_log.trace("Binding org.daisy.common.xml.DocumentBuilder services...");
26  			// cardinality: 0..n
27  			int minRef = 0;
28  			int maxRef = -1;
29  			int refCount = 0;
30  			try {
31  				java.util.Iterator<org.daisy.common.xml.DocumentBuilder> services
32  					= org.daisy.common.spi.ServiceLoader.load(org.daisy.common.xml.DocumentBuilder.class).iterator();
33  				while (services.hasNext()) {
34  					try {
35  						org.daisy.common.xml.DocumentBuilder service = services.next();
36  						delegate.setXmlParser(service);
37  						spi_log.trace("Bound org.daisy.common.xml.DocumentBuilder service: "
38  						              + service.getClass().getName() + "@"
39  						              + Integer.toHexString(System.identityHashCode(service)));
40  						refCount++;
41  						if (maxRef > 0 && refCount == maxRef)
42  							break;
43  					} catch (Throwable e) {
44  						spi_log.error("Error while binding org.daisy.common.xml.DocumentBuilder service", e);
45  					}
46  				}
47  			} catch (Throwable e) {
48  				spi_log.error("Error while binding org.daisy.common.xml.DocumentBuilder services", e);
49  			}
50  			if (refCount < minRef) {
51  				spi_log.warn("No org.daisy.common.xml.DocumentBuilder found");
52  				throw new RuntimeException("No org.daisy.common.xml.DocumentBuilder found");
53  			} else {
54  				spi_log.trace("Bound " + refCount + " org.daisy.common.xml.DocumentBuilder services.");
55  			}
56  		}
57  		{
58  			spi_log.trace("Binding javax.xml.transform.URIResolver services...");
59  			// cardinality: 1..1
60  			int minRef = 1;
61  			int maxRef = 1;
62  			int refCount = 0;
63  			try {
64  				java.util.Iterator<javax.xml.transform.URIResolver> services
65  					= org.daisy.common.spi.ServiceLoader.load(javax.xml.transform.URIResolver.class).iterator();
66  				while (services.hasNext()) {
67  					try {
68  						javax.xml.transform.URIResolver service = services.next();
69  						delegate.setURIResolver(service);
70  						spi_log.trace("Bound javax.xml.transform.URIResolver service: "
71  						              + service.getClass().getName() + "@"
72  						              + Integer.toHexString(System.identityHashCode(service)));
73  						refCount++;
74  						if (maxRef > 0 && refCount == maxRef)
75  							break;
76  					} catch (Throwable e) {
77  						spi_log.error("Error while binding javax.xml.transform.URIResolver service", e);
78  					}
79  				}
80  			} catch (Throwable e) {
81  				spi_log.error("Error while binding javax.xml.transform.URIResolver services", e);
82  			}
83  			if (refCount < minRef) {
84  				spi_log.warn("No javax.xml.transform.URIResolver found");
85  				throw new RuntimeException("No javax.xml.transform.URIResolver found");
86  			} else {
87  				spi_log.trace("Bound " + refCount + " javax.xml.transform.URIResolver services.");
88  			}
89  		}
90  		{
91  			spi_log.trace("Binding org.xml.sax.EntityResolver services...");
92  			// cardinality: 1..1
93  			int minRef = 1;
94  			int maxRef = 1;
95  			int refCount = 0;
96  			try {
97  				java.util.Iterator<org.xml.sax.EntityResolver> services
98  					= org.daisy.common.spi.ServiceLoader.load(org.xml.sax.EntityResolver.class).iterator();
99  				while (services.hasNext()) {
100 					try {
101 						org.xml.sax.EntityResolver service = services.next();
102 						delegate.setEntityResolver(service);
103 						spi_log.trace("Bound org.xml.sax.EntityResolver service: "
104 						              + service.getClass().getName() + "@"
105 						              + Integer.toHexString(System.identityHashCode(service)));
106 						refCount++;
107 						if (maxRef > 0 && refCount == maxRef)
108 							break;
109 					} catch (Throwable e) {
110 						spi_log.error("Error while binding org.xml.sax.EntityResolver service", e);
111 					}
112 				}
113 			} catch (Throwable e) {
114 				spi_log.error("Error while binding org.xml.sax.EntityResolver services", e);
115 			}
116 			if (refCount < minRef) {
117 				spi_log.warn("No org.xml.sax.EntityResolver found");
118 				throw new RuntimeException("No org.xml.sax.EntityResolver found");
119 			} else {
120 				spi_log.trace("Bound " + refCount + " org.xml.sax.EntityResolver services.");
121 			}
122 		}
123 		{
124 			spi_log.trace("Binding net.sf.saxon.s9api.Processor services...");
125 			// cardinality: 1..1
126 			int minRef = 1;
127 			int maxRef = 1;
128 			int refCount = 0;
129 			try {
130 				java.util.Iterator<net.sf.saxon.s9api.Processor> services
131 					= org.daisy.common.spi.ServiceLoader.load(net.sf.saxon.s9api.Processor.class).iterator();
132 				while (services.hasNext()) {
133 					try {
134 						net.sf.saxon.s9api.Processor service = services.next();
135 						delegate.setSaxonProcessor(service);
136 						spi_log.trace("Bound net.sf.saxon.s9api.Processor service: "
137 						              + service.getClass().getName() + "@"
138 						              + Integer.toHexString(System.identityHashCode(service)));
139 						refCount++;
140 						if (maxRef > 0 && refCount == maxRef)
141 							break;
142 					} catch (Throwable e) {
143 						spi_log.error("Error while binding net.sf.saxon.s9api.Processor service", e);
144 					}
145 				}
146 			} catch (Throwable e) {
147 				spi_log.error("Error while binding net.sf.saxon.s9api.Processor services", e);
148 			}
149 			if (refCount < minRef) {
150 				spi_log.warn("No net.sf.saxon.s9api.Processor found");
151 				throw new RuntimeException("No net.sf.saxon.s9api.Processor found");
152 			} else {
153 				spi_log.trace("Bound " + refCount + " net.sf.saxon.s9api.Processor services.");
154 			}
155 		}
156 	}
157 	
158 	public void spi_deactivate() {
159 	}
160 	
161 	public java.util.Map spi_getProperties() {
162 		return spi_props;
163 	}
164 
165 	@Override
166 	public boolean supportsContentType(
167 		java.lang.String arg1
168 	) {
169 		return delegate.supportsContentType(
170 			arg1
171 		);
172 	}
173 
174 	@Override
175 	public org.w3c.dom.Document parse(
176 		org.xml.sax.InputSource arg1
177 	) throws org.xml.sax.SAXException
178 	       , java.io.IOException {
179 		return delegate.parse(
180 			arg1
181 		);
182 	}
183 
184 	@Override
185 	public String toString() {
186 		return delegate.toString();
187 	}
188 
189 	@Override
190 	public int hashCode() {
191 		return delegate.hashCode();
192 	}
193 
194 	@Override
195 	public boolean equals(Object o) {
196 		return delegate.equals(o);
197 	}
198 }