PropertyLoader propertyLoader = PropertyLoader.forClassLoader(classLoader);
Map namedStyleMap = new HashMap();
MutableStyleSheet styleSheet = new MutableStyleSheet();
Element styleSheetElement = document.getDocumentElement();
Element[] styleElements = DomUtil.getChildElementsByTagName(styleSheetElement, "style");
// First pass, load style information.
for (int i = 0; i < styleElements.length; ++i) {
String name = styleElements[i].getAttribute("name");
if (!styleElements[i].hasAttribute("type")) {
throw new ComponentXmlException("Component type not specified in style: " + name, null);
}
String type = styleElements[i].getAttribute("type");
Class componentClass;
try {
componentClass = Class.forName(type, true, classLoader);
} catch (ClassNotFoundException ex) {
// StyleSheet contains reference to Component which does not exist in this ClassLoader,
// and thus should be ignored.
continue;
}
DerivedMutableStyle style = new DerivedMutableStyle();
Element propertiesElement = DomUtil.getChildElementByTagName(styleElements[i], "properties");
Style propertyStyle = propertyLoader.createStyle(propertiesElement, type);
style.addStyleContent(propertyStyle);
Map classToStyleMap = (Map) namedStyleMap.get(name);
if (classToStyleMap == null) {
classToStyleMap = new HashMap();
namedStyleMap.put(name, classToStyleMap);
}
classToStyleMap.put(componentClass, style);
styleSheet.addStyle(componentClass, name, style);
}
// Second pass, bind derived styles to base styles where applicable.
for (int i = 0; i < styleElements.length; ++i) {
if (styleElements[i].hasAttribute("base-name")) {