package org.openprovenance.prov.xml;
import java.util.List;
import java.util.LinkedList;

import javax.xml.namespace.QName;
import java.util.Hashtable;
import javax.xml.bind.JAXBElement;

public class AttributeProcessor {

    final private Hashtable<String,Hashtable<String,List<Object>>> namespaceIndex=
        new Hashtable<String,Hashtable<String,List<Object>>>();
    
    
    final private List<Object> attributes;

    public AttributeProcessor(List attributes) {
        this.attributes=attributes;
    }
              
    /* Processing of attributes */
    
    Hashtable<String,List<Object>> attributesWithNamespace(String namespace) {


        Hashtable<String,List<Object>> result=namespaceIndex.get(namespace);
        if (result==null) {
            result=new Hashtable<String,List<Object>>();
            namespaceIndex.put(namespace,result);
        }

        for (Object attribute: attributes) {
            if (attribute instanceof JAXBElement) {
                @SuppressWarnings("rawtypes")
				JAXBElement je=(JAXBElement) attribute;
                QName name=je.getName();
                if (namespace.equals(name.getNamespaceURI())) {
                    List<Object> ll=result.get(name.getLocalPart());
                    if (ll==null) {
                        List<Object> tmp=new LinkedList<Object>();
                        tmp.add(je.getValue());
                        result.put(name.getLocalPart(),tmp);
                    } else {
                        ll.add(je.getValue());                        
                    }
                }
            }
        }
        return result;
    }
}
@@ -273,22 +273,25 @@
 ng,List%3C
-Object
+Attribute
 %3E%3E%3E name
@@ -353,22 +353,25 @@
 ng,List%3C
-Object
+Attribute
 %3E%3E%3E();%0A 
@@ -402,22 +402,25 @@
 te List%3C
-Object
+Attribute
 %3E attrib
@@ -460,16 +460,27 @@
 sor(List
+%3CAttribute%3E
  attribu
@@ -609,22 +609,25 @@
 ng,List%3C
-Object
+Attribute
 %3E%3E attri
@@ -697,22 +697,25 @@
 ng,List%3C
-Object
+Attribute
 %3E%3E resul
@@ -820,22 +820,25 @@
 ng,List%3C
-Object
+Attribute
 %3E%3E();%0A  
@@ -913,24 +913,17 @@
 or (
-Object a
+A
 ttribute
 : at
@@ -922,9 +922,8 @@
 bute
-:
  att
@@ -932,159 +932,37 @@
 bute
-s) %7B%0A            if (attribute instanceof JAXBElement) %7B%0A                @SuppressWarnings(%22rawtypes%22)%0A%09%09%09%09JAXBElement je=(JAXBElement) attribute;%0A    
+: attributes) %7B%0A            %0A
     
@@ -980,21 +980,35 @@
 me name=
-je.ge
+attribute.getElemen
 tName();
@@ -1004,28 +1004,24 @@
 mentName();%0A
-    
             
@@ -1084,31 +1084,30 @@
         
-    
 List%3C
-Object
+Attribute
 %3E ll=res
@@ -1132,28 +1132,24 @@
 calPart());%0A
-    
             
@@ -1192,23 +1192,22 @@
     
-    
 List%3C
-Object
+Attribute
 %3E tm
@@ -1227,23 +1227,22 @@
 ist%3C
-Object
+Attribute
 %3E();%0A
-    
     
@@ -1269,28 +1269,20 @@
 add(
-je.getValue());%0A    
+attribute);%0A
     
@@ -1350,20 +1350,16 @@
         
-   
- 
 %7D else %7B
@@ -1383,32 +1383,24 @@
     
-    
 ll.add(
-je.getValue()
+attribute
 );  
@@ -1426,30 +1426,8 @@
    %0A
-                    %7D%0A
     

Support for Attribute in prov-n and round trip testing (usage and generation)