use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ConfigClassRegistryTest method testGenerateFromClassPathActionScript.
@Test
public void testGenerateFromClassPathActionScript() throws Exception {
setUp("somewhere.else.config", "/expected", "/ext-as");
ConfigClass configClass = getConfigClassRegistry().getConfigClassByName("testNamespace.config.testComponent");
Assert.assertNotNull(configClass);
Assert.assertEquals("testNamespace.config", configClass.getPackageName());
Assert.assertEquals("testPackage.TestComponent", configClass.getComponentClassName());
Assert.assertEquals(14, configClass.getCfgs().size());
}
use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ExmlToConfigClassParser method parseExmlToConfigClass.
public ConfigClass parseExmlToConfigClass(File source) throws IOException {
ConfigClass configClass = new ConfigClass();
//read exml data and write it into the config class
ExmlMetadataHandler metadataHandler = new ExmlMetadataHandler(configClass);
parseFileWithHandler(source, metadataHandler);
return configClass;
}
use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ExmlToModelParser method fillModelAttributesFromSubElements.
private void fillModelAttributesFromSubElements(ExmlModel model, JsonObject jsonObject, Element componentNode, ConfigClass configClass) {
List<Element> childNodes = getChildElements(componentNode);
for (Element element : childNodes) {
String elementName = element.getLocalName();
if (ExmlUtils.isExmlNamespace(element.getNamespaceURI()) && "mixins".equals(elementName)) {
for (Element mixinElement : getChildElements(element)) {
String mixinClassName = createFullConfigClassNameFromNode(mixinElement);
ConfigClass mixinConfigClass = getConfigClassByName(mixinClassName, mixinElement);
fillModelAttributes(model, jsonObject, mixinElement, mixinConfigClass);
}
continue;
}
boolean isConfigTypeArray = isConfigTypeArray(configClass, elementName);
String configMode = isConfigTypeArray ? element.getAttribute(Exmlc.EXML_MODE_ATTRIBUTE) : "";
// Special case: if an EXML element representing a config property has attributes, it is treated as
// having an untyped object value. Exception: it is an Array-typed property and the sole attribute is "mode".
int attributeCount = element.getAttributes().getLength();
if (attributeCount > 1 || attributeCount == 1 && configMode.length() == 0) {
// it's an untyped complex object with attributes and sub-properties
parseJavaScriptObjectProperty(jsonObject, element);
} else {
// derive the corresponding "at" value from the specified config mode (if any):
Code atValue = CONFIG_MODE_TO_AT_VALUE.get(configMode);
if (atValue != null) {
isConfigTypeArray = true;
if (!configClass.isExmlGenerated()) {
throw new ExmlcException("Non-EXML class " + configClass.getComponentClassName() + " does not support config modes.", getLineNumber(element));
}
}
String directTextContent = getDirectTextContent(element);
if (directTextContent != null) {
ConfigAttribute configAttribute = getCfgByName(configClass, elementName);
final Object attributeValue = getAttributeValue(directTextContent, configAttribute == null ? null : configAttribute.getType());
jsonObject.set(elementName, attributeValue);
} else {
// it seems to be an array or an object
fillJsonObjectProperty(model, jsonObject, elementName, isConfigTypeArray, getChildElements(element));
ifContainerDefaultsThenExtractXtype(jsonObject, configClass, elementName);
}
// if any "at" value is specified, set the extra mode attribute (...$at):
if (atValue != null) {
jsonObject.set(elementName + CONFIG_MODE_AT_SUFFIX, atValue);
}
// empty properties are omitted if the type is not fixed to Array
}
}
}
use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ExmlToModelParser method getCfgByName.
private ConfigAttribute getCfgByName(ConfigClass configClass, String attributeName) {
ConfigClass current = configClass;
while (current != null) {
ConfigAttribute configAttribute = current.getCfgByName(attributeName);
if (configAttribute != null) {
return configAttribute;
}
String superClassName = current.getSuperClassName();
if (superClassName == null || superClassName.equals("Object")) {
break;
}
current = registry.getConfigClassByName(superClassName);
}
return null;
}
use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ExmlToModelParser method parse.
/**
* Parses the exml file into an ExmlModel
* @param file the file to parse
* @return the parsed model
* @throws IOException if the input stream could not be read
* @throws SAXException if the XML was not well-formed
*/
public ExmlModel parse(File file) throws IOException, SAXException {
ExmlModel model = new ExmlModel();
String qName = CompilerUtils.qNameFromFile(registry.getConfig().findSourceDir(file), file);
String className = CompilerUtils.className(qName);
model.setClassName(ExmlUtils.createComponentClassName(className));
ConfigClass configClassByName = registry.getConfigClassByName(registry.getConfig().getConfigClassPackage() + "." + ConfigClass.createConfigClassName(className));
model.setConfigClass(configClassByName);
model.setPackageName(CompilerUtils.packageName(qName));
BufferedInputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(file));
parse(inputStream, model);
} finally {
if (inputStream != null) {
inputStream.close();
}
}
return model;
}
Aggregations