brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Feature: transform state
Date Thu, 25 Sep 2014 16:02:27 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/177#discussion_r18041059
  
    --- Diff: core/src/main/java/brooklyn/entity/rebind/transformer/CompoundTransformerLoader.java
---
    @@ -0,0 +1,65 @@
    +package brooklyn.entity.rebind.transformer;
    +
    +import java.util.Map;
    +
    +import brooklyn.entity.rebind.transformer.CompoundTransformer.Builder;
    +import brooklyn.entity.rebind.transformer.impl.XsltTransformerTest;
    +import brooklyn.util.ResourceUtils;
    +import brooklyn.util.exceptions.Exceptions;
    +import brooklyn.util.text.TemplateProcessor;
    +import brooklyn.util.yaml.Yamls;
    +
    +import com.google.common.annotations.Beta;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.Iterables;
    +
    +@Beta
    +public class CompoundTransformerLoader {
    +
    +    // TODO Improve error handing so get nicer errors.
    +    // TODO Improve names (e.g. always camel case?)
    +    // TODO Pass in classloader for reflectively loading rawDataTransformer?
    +    
    +    public static CompoundTransformer load(String contents) {
    +        CompoundTransformer.Builder builder = CompoundTransformer.builder();
    +        Iterable<Object> toplevel = Yamls.parseAll(contents);
    +        Map<String, Map<?,?>> rules = (Map<String, Map<?,?>>)
((Map<?,?>)Iterables.getOnlyElement(toplevel));
    +        for (Map.Entry<String, Map<?,?>> entry : rules.entrySet()) {
    +            addRule(builder, entry.getKey(), entry.getValue());
    +        }
    +        return builder.build();
    +    }
    +
    +    private static void addRule(Builder builder, String name, Map<?,?> args) {
    +        if (name.equals("renameClass")) {
    +            String oldVal = (String) args.get("old_val");
    +            String newVal = (String) args.get("new_val");
    +            builder.renameClass(oldVal, newVal);
    +        } else if (name.equals("renameType")) {
    +            String oldVal = (String) args.get("old_val");
    +            String newVal = (String) args.get("new_val");
    +            builder.renameType(oldVal, newVal);
    +        } else if (name.equals("renameField")) {
    +            String clazz = (String) args.get("class_name");
    +            String oldVal = (String) args.get("old_val");
    +            String newVal = (String) args.get("new_val");
    +            builder.renameField(clazz, oldVal, newVal);
    +        } else if (name.equals("xslt")) {
    +            String url = (String) args.get("url");
    +            Map<String,?> substitutions = (Map<String, ?>) args.get("substitutions");
    +            String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString(url);
    +            String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, substitutions
== null ? ImmutableMap.<String, String>of() : substitutions);
    +            builder.xsltTransformer(xslt);
    --- End diff --
    
    I'm on the fence here.  Our freemarker support is pretty good here, we can set that up
to access entity config, etc.  So that seems pragmatic.
    
    OTOH parameters is the normal way with xslt, so that's standard.
    
    I'm not sure what params we need here, I think that would sway me.  For now however I
lean towards keeping it as is, with a TODO (which I'll add).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message