// 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")) {
String name = styleElements[i].getAttribute("name");
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;
}
Map classToStyleMap = (Map) namedStyleMap.get(name);
DerivedMutableStyle style = (DerivedMutableStyle) classToStyleMap.get(componentClass);
String baseName = styleElements[i].getAttribute("base-name");
classToStyleMap = (Map) namedStyleMap.get(baseName);
if (classToStyleMap == null) {
throw new ComponentXmlException("Invalid base style name for style name " + name + ".", null);
}
Style baseStyle = (Style) classToStyleMap.get(componentClass);
while (baseStyle == null && componentClass != Object.class) {
componentClass = componentClass.getSuperclass();
baseStyle = (Style) classToStyleMap.get(componentClass);
}
if (baseStyle == null) {
throw new ComponentXmlException("Invalid base style name for style name " + name + ".", null);
}
style.setParentStyle(baseStyle);
}
}
return styleSheet;
}