Search in sources :

Example 1 with Dependency

use of com.dexels.navajo.script.api.Dependency in project navajo by Dexels.

the class CompiledTestScript2 method getDependentObjects.

@Override
public ArrayList<Dependency> getDependentObjects() {
    ArrayList<Dependency> deps = new ArrayList<Dependency>();
    deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestAdapter3", "whatever", "id2"));
    return deps;
}
Also used : AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) ArrayList(java.util.ArrayList) AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) Dependency(com.dexels.navajo.script.api.Dependency)

Example 2 with Dependency

use of com.dexels.navajo.script.api.Dependency in project navajo by Dexels.

the class CompiledTestScript method getDependentObjects.

@Override
public ArrayList<Dependency> getDependentObjects() {
    ArrayList<Dependency> deps = new ArrayList<Dependency>();
    deps.add(new ExpressionValueDependency(1, "mies", "noot"));
    deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestAdapter", "whatever", "'id1'"));
    deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestAdapter", "whatever", "'id2'"));
    deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestDoesNotExistAdapter", "whatever", "'id3'"));
    deps.add(new ExpressionValueDependency(1, "aap", "noot"));
    deps.add(new AdapterFieldDependency(-1, "com.dexels.navajo.server.resource.ResourceTestAdapter2", "whatever", "'id4'"));
    return deps;
}
Also used : AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) ExpressionValueDependency(com.dexels.navajo.mapping.compiler.meta.ExpressionValueDependency) ArrayList(java.util.ArrayList) AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) ExpressionValueDependency(com.dexels.navajo.mapping.compiler.meta.ExpressionValueDependency) Dependency(com.dexels.navajo.script.api.Dependency)

Example 3 with Dependency

use of com.dexels.navajo.script.api.Dependency 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)

Example 4 with Dependency

use of com.dexels.navajo.script.api.Dependency in project navajo by Dexels.

the class ScriptCompiler method processDependencies.

private Set<String> processDependencies(List<Dependency> dependencies) {
    Set<String> dependentResources = new HashSet<>();
    for (Dependency d : dependencies) {
        if ("resource".equals(d.getType()) && (d instanceof AdapterFieldDependency)) {
            final AdapterFieldDependency adapterFieldDep = (AdapterFieldDependency) d;
            logger.info("ID: {}. It's an aadapter field. with multiple: {} type {}", adapterFieldDep.getId(), adapterFieldDep.hasMultipleDependencies(), adapterFieldDep.getClass());
            Operand op = expressionEvaluator.evaluate(adapterFieldDep.getId(), null, Optional.empty(), Optional.empty());
            if (op != null && op.value instanceof String) {
                logger.debug("Succeeded evaluation of id: {}", ((String) op.value));
                dependentResources.add((String) op.value);
            }
            logger.info("Resource dependency detected: {} type: {} dependency id: {}", d.getClass().getName(), d.getType(), d.getId());
            Dependency[] subs = adapterFieldDep.getMultipleDependencies();
            if (subs != null) {
                for (Dependency dependency : subs) {
                    logger.info("Nested dependency detected: {}, type {}", dependency.getClass().getName(), dependency.getType());
                }
            }
        }
    }
    return dependentResources;
}
Also used : AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) Operand(com.dexels.navajo.document.Operand) ExtendDependency(com.dexels.navajo.mapping.compiler.meta.ExtendDependency) AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) IncludeDependency(com.dexels.navajo.mapping.compiler.meta.IncludeDependency) Dependency(com.dexels.navajo.script.api.Dependency) HashSet(java.util.HashSet)

Example 5 with Dependency

use of com.dexels.navajo.script.api.Dependency in project navajo by Dexels.

the class ResourceChecker method init.

@SuppressWarnings({ "rawtypes", "unchecked" })
public final void init() {
    if (myCompiledScript.getDependentObjects() == null) {
        logger.warn("ResourceChecker: Could not find dependent objects for: {}", myCompiledScript.getClass());
        return;
    }
    Iterator<Dependency> dependencies = myCompiledScript.getDependentObjects().iterator();
    while (dependencies.hasNext()) {
        Dependency dep = dependencies.next();
        if (AdapterFieldDependency.class.isAssignableFrom(dep.getClass())) {
            AdapterFieldDependency afd = (AdapterFieldDependency) dep;
            if (!afd.getType().equals(GenericDependentResource.SERVICE_DEPENDENCY)) {
                try {
                    Class c = Class.forName(afd.getJavaClass(), true, myCompiledScript.getClass().getClassLoader());
                    Method m = c.getMethod("getResourceManager", String.class);
                    if (m != null) {
                        managedResources.put(afd, m);
                    }
                } catch (Throwable e) {
                }
            } else {
                // Script dependency
                scriptDependencies.add(evaluateResourceId(afd.getId()));
            }
        }
    }
    initialized = true;
}
Also used : AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) Dependency(com.dexels.navajo.script.api.Dependency) Method(java.lang.reflect.Method)

Aggregations

Dependency (com.dexels.navajo.script.api.Dependency)10 AdapterFieldDependency (com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency)9 ArrayList (java.util.ArrayList)6 ExtendDependency (com.dexels.navajo.mapping.compiler.meta.ExtendDependency)4 IncludeDependency (com.dexels.navajo.mapping.compiler.meta.IncludeDependency)4 ExpressionValueDependency (com.dexels.navajo.mapping.compiler.meta.ExpressionValueDependency)2 SystemException (com.dexels.navajo.script.api.SystemException)2 File (java.io.File)2 Operand (com.dexels.navajo.document.Operand)1 CaseSensitiveXMLElement (com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement)1 XMLElement (com.dexels.navajo.document.nanoimpl.XMLElement)1 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 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