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:49:25 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/177#discussion_r18043995
  
    --- Diff: core/src/main/java/brooklyn/entity/rebind/transformer/CompoundTransformer.java
---
    @@ -0,0 +1,159 @@
    +package brooklyn.entity.rebind.transformer;
    +
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.util.Collection;
    +import java.util.Map;
    +
    +import brooklyn.entity.rebind.BrooklynObjectType;
    +import brooklyn.entity.rebind.RebindExceptionHandler;
    +import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToObjectStore;
    +import brooklyn.entity.rebind.transformer.impl.XsltTransformer;
    +import brooklyn.entity.rebind.transformer.impl.XsltTransformerTest;
    +import brooklyn.mementos.BrooklynMementoRawData;
    +import brooklyn.util.ResourceUtils;
    +import brooklyn.util.collections.MutableMap;
    +import brooklyn.util.text.TemplateProcessor;
    +
    +import com.google.api.client.repackaged.com.google.common.annotations.VisibleForTesting;
    +import com.google.common.annotations.Beta;
    +import com.google.common.collect.ArrayListMultimap;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.Multimap;
    +
    +@Beta
    +public class CompoundTransformer {
    +    
    +    public static final CompoundTransformer NOOP = builder().build();
    +    
    +    // TODO Does not yet handle BrooklynMementoTransformer, for changing an entire BrooklynMemento.
    +    // Need to do refactoring in RebindManager and BrooklynMementoPersisterToObjectStore
to convert 
    +    // from a BrooklynMementoRawData to a BrooklynMemento.
    +    
    +    public static Builder builder() {
    +        return new Builder();
    +    }
    +
    +    public static class Builder {
    +        private final Multimap<BrooklynObjectType, RawDataTransformer> rawDataTransformers
= ArrayListMultimap.<BrooklynObjectType, RawDataTransformer>create();
    +        
    +        public Builder rawDataTransformer(RawDataTransformer val) {
    +            for (BrooklynObjectType type : BrooklynObjectType.values()) {
    +                rawDataTransformer(type, val);
    +            }
    +            return this;
    +        }
    +        public Builder rawDataTransformer(BrooklynObjectType type, RawDataTransformer
val) {
    +            rawDataTransformers.put(checkNotNull(type, "type"), checkNotNull(val, "val"));
    +            return this;
    +        }
    +        public Builder renameType(String oldVal, String newVal) {
    +            // xstream format for inner classes is like <brooklyn.entity.rebind.transformer.CompoundTransformerTest_-OrigType>
    +            oldVal = toXstreamClassnameFormat(oldVal);
    +            newVal = toXstreamClassnameFormat(newVal);
    +            
    +            String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/renameType.xslt");
    +            String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of("old_val",
oldVal, "new_val", newVal));
    +            return xsltTransformer(xslt);
    +        }
    +        public Builder renameClass(String oldVal, String newVal) {
    --- End diff --
    
    the `<` in `Transofr<merTest` is a typo right?


---
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