Search in sources :

Example 11 with ConfigClass

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());
}
Also used : ConfigClass(net.jangaroo.exml.model.ConfigClass) Test(org.junit.Test)

Example 12 with ConfigClass

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;
}
Also used : ConfigClass(net.jangaroo.exml.model.ConfigClass)

Example 13 with 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
        }
    }
}
Also used : ConfigClass(net.jangaroo.exml.model.ConfigClass) ConfigAttribute(net.jangaroo.exml.model.ConfigAttribute) Element(org.w3c.dom.Element) ExmlcException(net.jangaroo.exml.api.ExmlcException) JsonObject(net.jangaroo.exml.json.JsonObject) Code(net.jangaroo.exml.json.Code)

Example 14 with ConfigClass

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;
}
Also used : ConfigClass(net.jangaroo.exml.model.ConfigClass) ConfigAttribute(net.jangaroo.exml.model.ConfigAttribute)

Example 15 with ConfigClass

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;
}
Also used : ConfigClass(net.jangaroo.exml.model.ConfigClass) ExmlModel(net.jangaroo.exml.model.ExmlModel) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream)

Aggregations

ConfigClass (net.jangaroo.exml.model.ConfigClass)16 Test (org.junit.Test)8 File (java.io.File)3 ConfigAttribute (net.jangaroo.exml.model.ConfigAttribute)3 Element (org.w3c.dom.Element)3 ArrayList (java.util.ArrayList)2 ExmlcException (net.jangaroo.exml.api.ExmlcException)2 JsonObject (net.jangaroo.exml.json.JsonObject)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 HashSet (java.util.HashSet)1 ExmlConfiguration (net.jangaroo.exml.config.ExmlConfiguration)1 Code (net.jangaroo.exml.json.Code)1 AnnotationAt (net.jangaroo.exml.model.AnnotationAt)1 ConfigClassRegistry (net.jangaroo.exml.model.ConfigClassRegistry)1 Declaration (net.jangaroo.exml.model.Declaration)1 ExmlModel (net.jangaroo.exml.model.ExmlModel)1 PublicApiMode (net.jangaroo.exml.model.PublicApiMode)1