Search in sources :

Example 1 with HasDependentResources

use of com.dexels.navajo.mapping.HasDependentResources in project navajo by Dexels.

the class TslCompiler method checkDependentFieldResource.

private final void checkDependentFieldResource(Class localContextClass, String fieldName, List<String> expressionValues, List<Dependency> deps) {
    if (!(HasDependentResources.class.isAssignableFrom(localContextClass))) {
        return;
    }
    if (expressionValues == null) {
        return;
    }
    for (int all = 0; all < expressionValues.size(); all++) {
        String expressionValue = expressionValues.get(all);
        DependentResource[] dependentFields = instantiatedAdapters.get(localContextClass);
        if (dependentFields == null && HasDependentResources.class.isAssignableFrom(localContextClass)) {
            try {
                HasDependentResources hr = (HasDependentResources) localContextClass.getDeclaredConstructor().newInstance();
                dependentFields = hr.getDependentResourceFields();
            } catch (Throwable t) {
                logger.error("Dependency detection problem:", t);
            }
            instantiatedAdapters.put(localContextClass, dependentFields);
        }
        if (dependentFields == null) {
            return;
        }
        for (int i = 0; i < dependentFields.length; i++) {
            if (fieldName.equals(dependentFields[i].getValue())) {
                if (dependentFields[i] instanceof GenericMultipleDependentResource) {
                    Class<? extends AdapterFieldDependency> depClass = dependentFields[i].getDependencyClass();
                    try {
                        Constructor c = depClass.getConstructor(long.class, String.class, String.class, String.class);
                        AdapterFieldDependency afd = (AdapterFieldDependency) c.newInstance(-1, localContextClass.getName(), dependentFields[i].getType(), expressionValue);
                        deps.add(afd);
                        AdapterFieldDependency[] allDeps = (AdapterFieldDependency[]) afd.getMultipleDependencies();
                        for (int a = 0; a < allDeps.length; a++) {
                            addDependency("dependentObjects.add( new " + depClass.getName() + "(-1, \"" + allDeps[a].getJavaClass() + "\", \"" + allDeps[a].getType() + "\", \"" + allDeps[a].getId() + "\"));\n", "FIELD" + allDeps[a].getJavaClass() + ";" + allDeps[a].getType() + ";" + fieldName + ";" + allDeps[a].getId());
                            deps.add(allDeps[a]);
                        }
                    } catch (Exception e) {
                        logger.info("Error adding dependency, wasn't logged before so reduced level to info. ", e);
                    }
                } else {
                    addDependency("dependentObjects.add( new AdapterFieldDependency(-1, \"" + localContextClass.getName() + "\", \"" + dependentFields[i].getType() + "\", \"" + expressionValue + "\"));\n", "FIELD" + localContextClass.getName() + ";" + dependentFields[i].getType() + ";" + fieldName + ";" + expressionValue);
                    Dependency d = new AdapterFieldDependency(-1, localContextClass.getName(), dependentFields[i].getType(), expressionValue);
                    deps.add(d);
                }
            }
        }
    }
}
Also used : GenericMultipleDependentResource(com.dexels.navajo.mapping.GenericMultipleDependentResource) DependentResource(com.dexels.navajo.mapping.DependentResource) AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) HasDependentResources(com.dexels.navajo.mapping.HasDependentResources) Constructor(java.lang.reflect.Constructor) ExpressionValueDependency(com.dexels.navajo.mapping.compiler.meta.ExpressionValueDependency) ExtendDependency(com.dexels.navajo.mapping.compiler.meta.ExtendDependency) AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) IncludeDependency(com.dexels.navajo.mapping.compiler.meta.IncludeDependency) JavaDependency(com.dexels.navajo.mapping.compiler.meta.JavaDependency) Dependency(com.dexels.navajo.script.api.Dependency) UserException(com.dexels.navajo.script.api.UserException) TransformerException(javax.xml.transform.TransformerException) MappingException(com.dexels.navajo.script.api.MappingException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) ParseException(com.dexels.navajo.parser.compiled.ParseException) KeywordException(com.dexels.navajo.mapping.compiler.meta.KeywordException) MetaCompileException(com.dexels.navajo.mapping.compiler.meta.MetaCompileException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException) CompilationException(com.dexels.navajo.script.api.CompilationException) GenericMultipleDependentResource(com.dexels.navajo.mapping.GenericMultipleDependentResource)

Aggregations

TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)1 DependentResource (com.dexels.navajo.mapping.DependentResource)1 GenericMultipleDependentResource (com.dexels.navajo.mapping.GenericMultipleDependentResource)1 HasDependentResources (com.dexels.navajo.mapping.HasDependentResources)1 AdapterFieldDependency (com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency)1 ExpressionValueDependency (com.dexels.navajo.mapping.compiler.meta.ExpressionValueDependency)1 ExtendDependency (com.dexels.navajo.mapping.compiler.meta.ExtendDependency)1 IncludeDependency (com.dexels.navajo.mapping.compiler.meta.IncludeDependency)1 JavaDependency (com.dexels.navajo.mapping.compiler.meta.JavaDependency)1 KeywordException (com.dexels.navajo.mapping.compiler.meta.KeywordException)1 MetaCompileException (com.dexels.navajo.mapping.compiler.meta.MetaCompileException)1 ParseException (com.dexels.navajo.parser.compiled.ParseException)1 CompilationException (com.dexels.navajo.script.api.CompilationException)1 Dependency (com.dexels.navajo.script.api.Dependency)1 MappingException (com.dexels.navajo.script.api.MappingException)1 SystemException (com.dexels.navajo.script.api.SystemException)1 UserException (com.dexels.navajo.script.api.UserException)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 TransformerException (javax.xml.transform.TransformerException)1