use of org.apache.felix.scr.impl.xml.XmlHandler in project felix by apache.
the class BundleComponentActivator method loadDescriptor.
private void loadDescriptor(final URL descriptorURL) {
// simple path for log messages
final String descriptorLocation = descriptorURL.getPath();
InputStream stream = null;
try {
stream = descriptorURL.openStream();
BufferedReader in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
XmlHandler handler = new XmlHandler(m_bundle, this, getConfiguration().isFactoryEnabled(), getConfiguration().keepInstances());
KXml2SAXParser parser;
parser = new KXml2SAXParser(in);
parser.parseXML(handler);
// or one or more component elements embedded in a larger document
for (Object o : handler.getComponentMetadataList()) {
ComponentMetadata metadata = (ComponentMetadata) o;
ComponentRegistryKey key = null;
try {
// check and reserve the component name (if not null)
if (metadata.getName() != null) {
key = m_componentRegistry.checkComponentName(m_bundle, metadata.getName());
}
// validate the component metadata
metadata.validate(this);
// Request creation of the component manager
ComponentHolder<?> holder = m_componentRegistry.createComponentHolder(this, metadata);
// register the component after validation
m_componentRegistry.registerComponentHolder(key, holder);
m_holders.add(holder);
log(LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] ComponentHolder created for {1}", new Object[] { m_bundle.getBundleId(), metadata.getName() }, null, null, null);
} catch (Throwable t) {
// There is a problem with this particular component, we'll log the error
// and proceed to the next one
log(LogService.LOG_ERROR, "Cannot register Component", metadata, null, t);
// make sure the name is not reserved any more
if (key != null) {
m_componentRegistry.unregisterComponentHolder(key);
}
}
}
} catch (IOException ex) {
// 112.4.1 If an XML document specified by the header cannot be located in the bundle and its attached
// fragments, SCR must log an error message with the Log Service, if present, and continue.
log(LogService.LOG_ERROR, "Problem reading descriptor entry ''{0}''", new Object[] { descriptorLocation }, null, null, ex);
} catch (Exception ex) {
log(LogService.LOG_ERROR, "General problem with descriptor entry ''{0}''", new Object[] { descriptorLocation }, null, null, ex);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException ignore) {
}
}
}
}
use of org.apache.felix.scr.impl.xml.XmlHandler in project felix by apache.
the class XmlHandlerTest method readMetadata.
// ---------- helper
private List readMetadata(final Reader reader) throws IOException, ComponentException, XmlPullParserException, Exception {
try {
final KXml2SAXParser parser = new KXml2SAXParser(reader);
XmlHandler handler = new XmlHandler(new MockBundle(), logger, false, false);
parser.parseXML(handler);
return handler.getComponentMetadataList();
} finally {
try {
reader.close();
} catch (IOException ignore) {
}
}
}
Aggregations