package com.vaadin.components.gwt.polymer.client;

import java.util.HashSet;
import java.util.Set;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.vaadin.components.gwt.polymer.client.element.ImportsMap;

public class Polymer {
    
    private static Polymer instance = new Polymer();

    private static Set<String> urlImported = new HashSet<>();
    
    /*
	 * Injects the correspondent html template to page head section.
	 */
    public static void ensureHTMLImport(Class<?> clazz) {
        String tagName = computeTagName(clazz);
        GWT.log(tagName);
        ensureHTMLImport(tagName);
    }

    public static void ensureHTMLImport(String tagName) {
        String href = "bower_components/" + ImportsMap.getInstance().get(tagName);
        if (!urlImported.contains(href)) {
            Element head = Document.get().getElementsByTagName("head").getItem(0);
            Element htmlImport = Document.get().createLinkElement();
            htmlImport.setAttribute("rel", "import");
            htmlImport.setAttribute("href", GWT.getModuleBaseForStaticFiles() + href);
            head.appendChild(htmlImport);
            urlImported.add(href);
        }
    }

    private static String computeTagName(Class<?> clazz) {
        return clazz.getSimpleName().replaceAll("([A-Z])", "-$1").replaceFirst("^-+", "").toLowerCase();
    }

    public static Polymer getInstance() {
        return instance;
    }

    private Polymer() {
    }
}

@@ -297,78 +297,30 @@
 lic 
-class Polymer %7B%0A    %0A    private static Polymer instance = new
+abstract class
  Polymer
 ();%0A
@@ -315,19 +315,18 @@
  Polymer
-();
+ %7B
 %0A%0A    pr
@@ -385,264 +385,138 @@
 ();%0A
-    
 %0A    /
-*%0A%09 * Injects the correspondent html template to page head section.%0A%09 */%0A    public static void ensureHTMLImport(Class%3C?%3E clazz) %7B%0A        String tagName = computeTagName(clazz);%0A        GWT.log(tagName);%0A        ensureHTMLI
+/ Ensures that the tagName has been registered, otherwise injects%0A    // the appropriate %3Ci
 mport
-(tagName);%0A    %7D%0A
+%3E tag in the document header
 %0A   
@@ -720,101 +720,12 @@
 ent 
-head = Document.get().getElementsByTagName(%22head%22).getItem(0);%0A            Element htmlImport
+link
  = D
@@ -767,34 +767,28 @@
             
-htmlImport
+link
 .setAttribut
@@ -819,26 +819,20 @@
         
-htmlImport
+link
 .setAttr
@@ -900,20 +900,40 @@
         
-h
+Document.get().getH
 ead
+()
 .appendC
@@ -941,18 +941,12 @@
 ild(
-htmlImport
+link
 );%0A 
@@ -1000,281 +1000,6 @@
  %7D%0A%0A
-    private static String computeTagName(Class%3C?%3E clazz) %7B%0A        return clazz.getSimpleName().replaceAll(%22(%5BA-Z%5D)%22, %22-$1%22).replaceFirst(%22%5E-+%22, %22%22).toLowerCase();%0A    %7D%0A%0A    public static Polymer getInstance() %7B%0A        return instance;%0A    %7D%0A%0A    private Polymer() %7B%0A    %7D%0A
 %7D%0A

Remove unused methods and make the class static