use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ExmlToModelParser method parseChildObjects.
private List<Object> parseChildObjects(ExmlModel model, List<Element> elements) {
List<Object> childObjects = new ArrayList<Object>();
for (Element arrayItemNode : elements) {
Object value;
if (ExmlUtils.isExmlNamespace(arrayItemNode.getNamespaceURI()) && Exmlc.EXML_OBJECT_NODE_NAME.equals(arrayItemNode.getLocalName())) {
value = parseExmlObjectNode(arrayItemNode);
} else {
String arrayItemClassName = createFullConfigClassNameFromNode(arrayItemNode);
ConfigClass configClass = getConfigClassByName(arrayItemClassName, arrayItemNode);
JsonObject arrayItemJsonObject = new JsonObject();
if (configClass.getType().getExtTypeAttribute() != null && EXT_CONFIG_PACKAGE.equals(configClass.getPackageName())) {
// Ext classes are always loaded. We can use the type string directly.
arrayItemJsonObject.set(configClass.getType().getExtTypeAttribute(), configClass.getTypeValue());
} else if (configClass.getType().isCreatedViaConfigObject()) {
arrayItemJsonObject.settingWrapperClass(configClass.getFullName());
model.addImport(configClass.getFullName());
model.addImport(configClass.getComponentClassName());
} else {
// Everything not a component, plugin or layout must be created immediately
// by using net.jangaroo.ext.create() with its configClass and the config:
arrayItemJsonObject.settingConfigClass(configClass.getFullName());
model.addImport(configClass.getFullName());
model.addImport(configClass.getComponentClassName());
model.addImport(JsonObject.NET_JANGAROO_EXT_CREATE);
}
fillModelAttributes(model, arrayItemJsonObject, arrayItemNode, configClass);
value = arrayItemJsonObject;
}
if (value != null) {
childObjects.add(value);
}
}
return childObjects;
}
use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ExmlToModelParser method parse.
/**
* Parse the input stream content into a model.
* Close the input stream after reading.
*
* @param inputStream the input stream
* @param model the model
* @throws IOException if the input stream could not be read
* @throws SAXException if the XML was not well-formed
*/
private void parse(InputStream inputStream, ExmlModel model) throws IOException, SAXException {
Document document = buildDom(inputStream);
Node root = document.getFirstChild();
validateRootNode(root);
NamedNodeMap attributes = root.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr attribute = (Attr) attributes.item(i);
// baseClass attribute has been specified, so the super class of the component is actually that
if (Exmlc.EXML_BASE_CLASS_ATTRIBUTE.equals(attribute.getLocalName())) {
model.setSuperClassName(attribute.getValue());
} else if (Exmlc.EXML_PUBLIC_API_ATTRIBUTE.equals(attribute.getLocalName())) {
PublicApiMode publicApiMode = Exmlc.parsePublicApiMode(attribute.getValue());
switch(publicApiMode) {
case TRUE:
model.addAnnotation(Jooc.PUBLIC_API_INCLUSION_ANNOTATION_NAME);
// fall through!
case CONFIG:
model.getConfigClass().addAnnotation(Jooc.PUBLIC_API_INCLUSION_ANNOTATION_NAME);
}
}
}
NodeList childNodes = root.getChildNodes();
Element componentNode = null;
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (ExmlUtils.isExmlNamespace(node.getNamespaceURI())) {
Element element = (Element) node;
if (Exmlc.EXML_IMPORT_NODE_NAME.equals(node.getLocalName())) {
String importedClassName = element.getAttribute(Exmlc.EXML_IMPORT_CLASS_ATTRIBUTE);
if (importedClassName == null || importedClassName.equals("")) {
int lineNumber = getLineNumber(componentNode);
throw new ExmlcException("<exml:import> element must contain a non-empty class attribute", lineNumber);
}
model.addImport(importedClassName);
} else if (Exmlc.EXML_ANNOTATION_NODE_NAME.equals(node.getLocalName())) {
AnnotationAt annotationAt = Exmlc.parseAnnotationAtValue(element.getAttribute(Exmlc.EXML_ANNOTATION_AT_ATTRIBUTE));
if (annotationAt != AnnotationAt.CONFIG) {
model.addAnnotation(element.getTextContent());
}
} else if (Exmlc.EXML_CONSTANT_NODE_NAME.equals(node.getLocalName())) {
String constantTypeName = element.getAttribute(Exmlc.EXML_DECLARATION_TYPE_ATTRIBUTE);
model.addImport(constantTypeName);
} else if (Exmlc.EXML_DESCRIPTION_NODE_NAME.equals(node.getLocalName())) {
model.setDescription(node.getTextContent());
} else if (Exmlc.EXML_VAR_NODE_NAME.equals(node.getLocalName())) {
Declaration var = createDeclaration(element, model);
if (!model.getVars().contains(var)) {
model.addVar(var);
}
} else if (Exmlc.EXML_CFG_NODE_NAME.equals(node.getLocalName())) {
String cfgName = element.getAttribute(Exmlc.EXML_CFG_NAME_ATTRIBUTE);
String cfgType = element.getAttribute(Exmlc.EXML_CFG_TYPE_ATTRIBUTE);
String cfgDefault = element.getAttribute(Exmlc.EXML_CFG_DEFAULT_ATTRIBUTE);
Element defaultValueElement = findChildElement(element, Exmlc.EXML_NAMESPACE_URI, Exmlc.EXML_CFG_DEFAULT_NODE_NAME);
if (cfgDefault.length() != 0 && defaultValueElement != null) {
throw new ExmlcException("<exml:cfg> default value must be specified as either an attribute or a sub-element, not both for config '" + cfgName + "'.", getLineNumber(element));
}
if (cfgDefault.length() > 0) {
model.getCfgDefaults().set(cfgName, getAttributeValue(cfgDefault, cfgType));
model.addImport(cfgType);
} else if (defaultValueElement != null) {
model.getCfgDefaults().set(cfgName, parseValue(model, "Array".equals(cfgType), getChildElements(defaultValueElement)));
}
}
} else {
if (componentNode != null) {
int lineNumber = getLineNumber(componentNode);
throw new ExmlcException("root node of EXML contained more than one component definition", lineNumber);
}
componentNode = (Element) node;
}
}
}
if (componentNode == null) {
return;
}
String superFullClassName = createFullConfigClassNameFromNode(componentNode);
if (superFullClassName.equals(model.getConfigClass().getFullName())) {
int lineNumber = getLineNumber(componentNode);
throw new ExmlcException("Cyclic inheritance error: super class and this component are the same.", lineNumber);
}
ConfigClass superConfigClass = getConfigClassByName(superFullClassName, componentNode);
String superComponentClassName = superConfigClass.getComponentClassName();
if (model.getSuperClassName() == null) {
model.setSuperClassName(superComponentClassName);
}
// but we still need the import
model.addImport(superComponentClassName);
fillModelAttributes(model, model.getJsonObject(), componentNode, superConfigClass);
}
use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class MxmlLibraryManifestGeneratorTest method testCreateManifestFile.
@Test
public void testCreateManifestFile() throws Exception {
ExmlConfiguration exmlConfiguration = mock(ExmlConfiguration.class);
when(exmlConfiguration.getSourcePath()).thenReturn(Collections.singletonList(temporaryFolder.newFolder("out")));
ConfigClass configClass1 = mock(ConfigClass.class);
when(configClass1.getFullName()).thenReturn("foo");
when(configClass1.getType()).thenReturn(ConfigClassType.CLASS);
when(configClass1.getComponentClassName()).thenReturn("Foo");
ConfigClass configClass2 = mock(ConfigClass.class);
when(configClass2.getFullName()).thenReturn("bar");
when(configClass2.getType()).thenReturn(ConfigClassType.CLASS);
when(configClass2.getComponentClassName()).thenReturn("Bar");
ConfigClass configClass3 = mock(ConfigClass.class);
when(configClass3.getFullName()).thenReturn("comp");
when(configClass3.getType()).thenReturn(ConfigClassType.COMPONENT);
when(configClass3.getComponentClassName()).thenReturn("Comp");
ConfigClassRegistry configClassRegistry = mock(ConfigClassRegistry.class);
when(configClassRegistry.getConfig()).thenReturn(exmlConfiguration);
when(configClassRegistry.getSourceConfigClasses()).thenReturn(asList(configClass1, configClass2, configClass3));
File manifest = new MxmlLibraryManifestGenerator(configClassRegistry).createManifestFile();
assertEquals(IOUtils.toString(getClass().getResourceAsStream("/expected/manifest.xml")), readFileToString(manifest));
}
use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ConfigClassBuilder method visitCompilationUnit.
@Override
public void visitCompilationUnit(CompilationUnit compilationUnit) throws IOException {
configClass = new ConfigClass();
compilationUnit.getPackageDeclaration().visit(this);
for (AstNode node : compilationUnit.getDirectives()) {
node.visit(new ClassAnnotationsVisitor());
}
compilationUnit.getPrimaryDeclaration().visit(this);
}
use of net.jangaroo.exml.model.ConfigClass in project jangaroo-tools by CoreMedia.
the class ConfigClassRegistryTest method testGenerateFromLocalActionScript.
@Test
public void testGenerateFromLocalActionScript() 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());
}
Aggregations