package org.jboss.windup.config.operation.ruleelement;

import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import org.apache.commons.lang.StringUtils;
import org.jboss.forge.furnace.services.Imported;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.selectables.SelectionFactory;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.GraphUtil;
import org.jboss.windup.graph.model.ArchiveModel;
import org.jboss.windup.graph.model.ArchiveModelPointer;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.ocpsoft.rewrite.context.EvaluationContext;

public class ConfigureArchiveTypes extends AbstractIterationOperator<ArchiveModel>
{
    private @Inject Imported<ArchiveModelPointer> archiveModelPointers;
    
    private HashMap<String, Class> suffixToModelClass;
    
    
    public ConfigureArchiveTypes(String variableName)
    {
        super(ArchiveModel.class, variableName);
        
        initTypes();
    }

    
    public static ConfigureArchiveTypes forVar(String variableName)
    {
        return new ConfigureArchiveTypes(variableName);
    }

    
    @Override
    public void perform(GraphRewrite event, EvaluationContext context, ArchiveModel archiveModel)
    {
        GraphContext graphContext = event.getGraphContext();
        String filename = archiveModel.getArchiveName();
        WindupVertexFrame newFrame = null;
        
        for( Map.Entry<String, Class> entry : suffixToModelClass.entrySet() ) {
            if( StringUtils.endsWith( filename, entry.getKey() ) ){
                newFrame = GraphUtil.addTypeToModel(graphContext, archiveModel, entry.getValue());
            }
        }
        
        /*
        if (StringUtils.endsWith(filename, ".jar"))
        {
            newFrame = GraphUtil.addTypeToModel(graphContext, archiveModel, JarArchiveModel.class);
        }
        else if (StringUtils.endsWith(filename, ".war"))
        {
            newFrame = GraphUtil.addTypeToModel(graphContext, archiveModel, WarArchiveModel.class);
        }
        else if (StringUtils.endsWith(filename, ".ear"))
        {
            newFrame = GraphUtil.addTypeToModel(graphContext, archiveModel, EarArchiveModel.class);
        }/**/
        
        if (newFrame != null)
        {
            SelectionFactory.instance(event).setCurrentPayload(getVariableName(), newFrame);
        }
    }


    private void initTypes() {
        for( ArchiveModelPointer ptr : this.archiveModelPointers ) {
            this.suffixToModelClass.put( ptr.getArchiveFileSuffix(), ptr.getModelClass() );
        }
    }
}

@@ -169,16 +169,56 @@
 gUtils;%0A
+import org.jboss.forge.furnace.Furnace;%0A
 import o
@@ -752,24 +752,26 @@
 odel%3E%0A%7B%0A    
+//
 private @Inj
@@ -827,24 +827,66 @@
 nters;%0A    %0A
+    private @Inject Furnace furnace;%0A    %0A
     private 
@@ -1051,38 +1051,8 @@
 e);%0A
-        %0A        initTypes();%0A
     
@@ -2509,21 +2509,25 @@
         
-for( 
+Imported%3C
 ArchiveM
@@ -2541,33 +2541,137 @@
 nter
+%3E
  p
-tr : this.archiveModelP
+ointers = furnace.getAddonRegistry().getServices(ArchiveModelPointer.class);%0A        %0A        for( ArchiveModelPointer ptr : p
 oint

Use Furnace's getServices() to get ArchiveModelPointer