]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
For one library class, list all library instances from all packages in workspace.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
index 12dd2fd4453ac086629e177aa64f16e21d7213ec..b54715b877b59818e794350476983db9db1bc764 100644 (file)
@@ -91,6 +91,11 @@ public class FpdFileContents {
     \r
     private HashMap<String, String> defaultPcdValue = new HashMap<String, String>();\r
     \r
+    private String itemType (String pcdInfo) {\r
+        \r
+        return pcdInfo.substring(pcdInfo.lastIndexOf(" ") + 1);\r
+    }\r
+    \r
     /**\r
      * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.\r
      */\r
@@ -251,12 +256,22 @@ public class FpdFileContents {
     }\r
     \r
     public ModuleSADocument.ModuleSA getModuleSA(String key) {\r
-        String[] s = key.split(" ");\r
+        \r
         if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {\r
             removeElement(getfpdFrameworkModules());\r
             fpdFrameworkModules = null;\r
             return null;\r
         }\r
+        String[] s = key.split(" ");\r
+        String archsInKey = "";\r
+        if (s.length > 4) {\r
+            for (int i = 4; i < s.length; ++i) {\r
+                archsInKey += s[i];\r
+                archsInKey += " ";\r
+            }\r
+            archsInKey = archsInKey.trim();\r
+        }\r
+        \r
         ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r
         while(li.hasNext()) {\r
             ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();\r
@@ -271,13 +286,17 @@ public class FpdFileContents {
                         continue;\r
                     }\r
                 }\r
-                //ToDo add arch check for s[4]\r
+                //ToDo add arch check .\r
                 if (moduleSa.getSupArchList() != null) {\r
-                    if (!listToString(moduleSa.getSupArchList()).equals(s[4])) {\r
-                        continue;\r
+                    if (listToString(moduleSa.getSupArchList()).equals(archsInKey)) {\r
+                        return moduleSa;\r
+                    }\r
+                }\r
+                else {\r
+                    if (archsInKey.length() == 0) {\r
+                        return moduleSa;\r
                     }\r
                 }\r
-                return moduleSa;\r
             }\r
         }\r
         return null;\r
@@ -360,17 +379,22 @@ public class FpdFileContents {
         getLibraryInstances(moduleKey, saaLib);\r
         ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);\r
         Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();\r
+        //\r
+        // create vector for module & library instance MIs.\r
+        //\r
         vMi.add(mi);\r
+        for (int j = 0; j < saaLib.length; ++j) {\r
+            String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];\r
+            ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);\r
+            vMi.add(libMi);\r
+        }\r
+        \r
         try {\r
     nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {\r
-                if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], mi)){\r
-                    continue;\r
-                }\r
-                for (int j = 0; j < saaLib.length; ++j) {\r
-                    String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];\r
-                    ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);\r
-                    vMi.add(libMi);\r
-                    if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], libMi)) {\r
+\r
+                for (int j = 0; j < vMi.size(); ++j) {\r
+                    ModuleIdentification nextMi = vMi.get(j);\r
+                    if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], nextMi)) {\r
                         continue nextPcd;\r
                     }\r
                 }\r
@@ -379,7 +403,7 @@ public class FpdFileContents {
             }\r
         }\r
         catch (Exception e) {\r
-            \r
+            throw e;\r
         }\r
         //\r
         // add new Pcd from MSA file to ModuleSA.\r
@@ -405,9 +429,6 @@ public class FpdFileContents {
                         }\r
                     }\r
                     \r
-                    Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
-                    m.put("ModuleSurfaceArea", msa);\r
-                    SurfaceAreaQuery.setDoc(m);\r
                     PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i));\r
                     PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
                     if (spdPcd == null) {\r
@@ -541,6 +562,9 @@ public class FpdFileContents {
             do {\r
                 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
                 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
+                    //\r
+                    // change item type while not updating dynPcdData????\r
+                    //\r
                     pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));\r
                     if(pcdData.getDatumType().equals("VOID*")) {\r
                         pcdData.setMaxDatumSize(new Integer(maxSize));\r
@@ -988,7 +1012,9 @@ public class FpdFileContents {
             \r
             if (opt.getSupArchList() != null){\r
                 saa[i][4] = listToString(opt.getSupArchList());\r
-\r
+            }\r
+            else {\r
+                saa[i][4] = "";\r
             }\r
             \r
             saa[i][5] = opt.getStringValue();\r
@@ -1175,8 +1201,8 @@ public class FpdFileContents {
         // Using existing Pcd type, if this pcd already exists in other ModuleSA\r
         //\r
         if (pcdConsumer.size() > 0) {\r
-            String[] valPart = pcdConsumer.get(0).split(" ");\r
-            itemType = valPart[5];\r
+            \r
+            itemType = itemType (pcdConsumer.get(0));\r
         }\r
         String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() \r
         + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList())\r
@@ -2589,10 +2615,22 @@ public class FpdFileContents {
     }\r
     \r
     public void getFvImagesFvImageFvImageNames (Vector<String> vImageNames) {\r
+        FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();\r
+        if (fis == null || fis.getFvImageList() == null) {\r
+            return;\r
+        }\r
         \r
+        ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();\r
+        while (li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = li.next();\r
+            if (fi.getType().toString().equals("ImageName")) {\r
+                vImageNames.addAll(fi.getFvImageNamesList());\r
+                return;\r
+            }\r
+        }\r
     }\r
     \r
-    public void AddFvImageFvImageNames (String[] fvNames) {\r
+    public void addFvImageFvImageNames (String[] fvNames) {\r
         FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();\r
         if (fis == null || fis.getFvImageList() == null) {\r
             genFvImagesFvImage (fvNames, "ImageName", null);\r
@@ -2603,14 +2641,35 @@ public class FpdFileContents {
         while (li.hasNext()) {\r
             FvImagesDocument.FvImages.FvImage fi = li.next();\r
             if (fi.getType().toString().equals("ImageName")) {\r
-                for (int i = 0; i < fvNames.length; ++i) {\r
-                    fi.addFvImageNames(fvNames[i]);\r
-                }\r
+                addFvImageNamesInFvImage (fi, fvNames);\r
                 return;\r
             }\r
         }\r
-        genFvImagesFvImage (fvNames, "ImageName", null);\r
+        genFvImagesFvImage (fvNames, "ImageName", null);    \r
+    }\r
+    \r
+    public void addFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String[] fvNames) {\r
         \r
+        for (int i = 0; i < fvNames.length; ++i) {\r
+            fi.addFvImageNames(fvNames[i]);\r
+        }\r
+    }\r
+    \r
+    public void addFvImageNamesInFvImage (int i, String[] fvNames) {\r
+        XmlObject o = getfpdFlash().getFvImages();\r
+        if (o == null) {\r
+            return;\r
+        }\r
+        XmlCursor cursor = o.newCursor();\r
+        QName qFvImage = new QName(xmlNs, "FvImage");\r
+        if (cursor.toChild(qFvImage)) {\r
+            for (int j = 0; j < i; ++j) {\r
+                cursor.toNextSibling(qFvImage);\r
+            }\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
+            addFvImageNamesInFvImage(fi, fvNames);\r
+        }\r
+        cursor.dispose();\r
     }\r
     \r
     public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {\r
@@ -2672,6 +2731,10 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
+    /**\r
+     * @param oldFvName\r
+     * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.\r
+     */\r
     public void updateFvImageNameAll (String oldFvName, String newFvName) {\r
         if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
             return;\r
@@ -2680,17 +2743,47 @@ public class FpdFileContents {
         while (li.hasNext()) {\r
             FvImagesDocument.FvImages.FvImage fi = li.next();\r
             updateFvImageNamesInFvImage (fi, oldFvName, newFvName);\r
+            if (fi.getFvImageNamesList().size() == 0) {\r
+                li.remove();\r
+            }\r
         }\r
     }\r
     \r
+    public void updateFvImageNamesInFvImage (int i, String oldFvName, String newFvName) {\r
+        XmlObject o = getfpdFlash().getFvImages();\r
+        if (o == null) {\r
+            return;\r
+        }\r
+        XmlCursor cursor = o.newCursor();\r
+        QName qFvImage = new QName(xmlNs, "FvImage");\r
+        if (cursor.toChild(qFvImage)) {\r
+            for (int j = 0; j < i; ++j) {\r
+                cursor.toNextSibling(qFvImage);\r
+            }\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
+            updateFvImageNamesInFvImage (fi, oldFvName, newFvName);\r
+        }\r
+        cursor.dispose();\r
+    }\r
+    /**\r
+     * @param fi\r
+     * @param oldFvName The FV Name to be replaced.\r
+     * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.\r
+     */\r
     public void updateFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String oldFvName, String newFvName) {\r
         QName qFvImageNames = new QName(xmlNs, "FvImageNames");\r
         XmlCursor cursor = fi.newCursor();\r
         \r
         if (cursor.toChild(qFvImageNames)) {\r
             do {\r
-                if (cursor.getTextValue().equals(oldFvName)){\r
-                    cursor.setTextValue(newFvName);\r
+                String xmlValue = cursor.getTextValue();\r
+                if (xmlValue.equals(oldFvName)){\r
+                    if (newFvName != null) {\r
+                        cursor.setTextValue(newFvName);\r
+                    }\r
+                    else {\r
+                        cursor.removeXml();\r
+                    }\r
                 }\r
             }while (cursor.toNextSibling(qFvImageNames));\r
         }\r
@@ -2698,6 +2791,27 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
+    /**update the Type attribute of ith FvImage with new type.\r
+     * @param i\r
+     * @param type\r
+     */\r
+    public void updateFvImagesFvImageType (int i, String type) {\r
+        XmlObject o = getfpdFlash().getFvImages();\r
+        if (o == null) {\r
+            return;\r
+        }\r
+        XmlCursor cursor = o.newCursor();\r
+        QName qFvImage = new QName(xmlNs, "FvImage");\r
+        if (cursor.toChild(qFvImage)) {\r
+            for (int j = 0; j < i; ++j) {\r
+                cursor.toNextSibling(qFvImage);\r
+            }\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
+            fi.setType(FvImageTypes.Enum.forString(type));\r
+        }\r
+        cursor.dispose();\r
+    }\r
+    \r
     public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){\r
            \r
         XmlObject o = getfpdFlash().getFvImages();\r
@@ -2738,18 +2852,50 @@ public class FpdFileContents {
         cursor.dispose();\r
     }\r
     \r
-    public int getFvImagesFvImageCount() {\r
+    public int getFvImagesFvImageCount(String type) {\r
         \r
         if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
             return 0;\r
         }\r
-        return getfpdFlash().getFvImages().getFvImageList().size();\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        ListIterator li = l.listIterator();\r
+        int i = 0;\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            \r
+            ++i;\r
+        }\r
+        \r
+        return i;\r
     }\r
     \r
-    /**Only Get Fv image setting - name and type.\r
+    public Vector<FvImagesDocument.FvImages.FvImage> getFvImagesFvImageWithName (String fvName, String type) {\r
+        Vector<FvImagesDocument.FvImages.FvImage> vFvImage = new Vector<FvImagesDocument.FvImages.FvImage>();\r
+        if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
+            return vFvImage;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            if (fi.getFvImageNamesList().contains(fvName)) {\r
+                vFvImage.add(fi);\r
+            }\r
+        }\r
+        \r
+        return vFvImage;\r
+    }\r
+    /**\r
      * @param saa\r
+     * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.\r
      */\r
-    public void getFvImagesFvImages(String[][] saa) {\r
+    public void getFvImagesFvImages(String[][] saa, String type) {\r
     \r
         if (getfpdFlash().getFvImages() == null) {\r
             return;\r
@@ -2762,6 +2908,9 @@ public class FpdFileContents {
         int i = 0;\r
         while(li.hasNext()) {\r
             FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
             //\r
             // get FvImageNames array, space separated\r
             //\r
@@ -2780,6 +2929,224 @@ public class FpdFileContents {
         }\r
     }\r
     \r
+    public void removeFvImageNameValue (int i, String attributeName) {\r
+        XmlObject o = getfpdFlash().getFvImages();\r
+        if (o == null) {\r
+            return;\r
+        }\r
+        XmlCursor cursor = o.newCursor();\r
+        QName qFvImage = new QName(xmlNs, "FvImage");\r
+        if (cursor.toChild(qFvImage)) {\r
+            for (int j = 0; j < i; ++j) {\r
+                cursor.toNextSibling(qFvImage);\r
+            }\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
+            removeFvImageNameValue (fi, attributeName);\r
+        }\r
+        cursor.dispose();\r
+    }\r
+    /**Remove from fi the attribute pair with attributeName in FvImageOptions.\r
+     * @param fi\r
+     * @param attributeName\r
+     */\r
+    public void removeFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String attributeName) {\r
+        if (fi.getFvImageOptions() != null && fi.getFvImageOptions().getNameValueList() != null) {\r
+            ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();\r
+            while (li.hasNext()) {\r
+                FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();\r
+                if (nv.getName().equals(attributeName)) {\r
+                    li.remove();\r
+                }\r
+            }\r
+        }\r
+    }\r
+    \r
+    public void removeTypedNamedFvImageNameValue (String fvName, String type, String optName) {\r
+        Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName(fvName, type);\r
+        for (int i = 0; i < vFvImage.size(); ++i) {\r
+            FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);\r
+            removeFvImageNameValue (fi, optName);\r
+        }\r
+    }\r
+    \r
+    /**Add name-value pair to FvImage element with type.\r
+     * @param fvName FV name to add name-value pair.\r
+     * @param type FvImage attribute.\r
+     * @param name\r
+     * @param value\r
+     */\r
+    public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) {\r
+        boolean fvImageExists = false;\r
+        if (getfpdFlash().getFvImages() == null) {\r
+            return;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        if (l == null) {\r
+            return;\r
+        }\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            if (!fi.getFvImageNamesList().contains(fvName)) {\r
+                continue;\r
+            }\r
+            fvImageExists = true;\r
+            setFvImagesFvImageNameValue (fi, name, value, null);\r
+        }\r
+        \r
+        if (!fvImageExists) {\r
+            HashMap<String, String> map = new HashMap<String, String>();\r
+            map.put(name, value);\r
+            genFvImagesFvImage(new String[]{fvName}, type, map);\r
+        }\r
+    }\r
+    \r
+    /**Add to all FvImage elements with type, the name-value pair.\r
+     * @param type\r
+     * @param name\r
+     * @param value\r
+     */\r
+    public void setTypedFvImageNameValue (String type, String name, String value) {\r
+        if (getfpdFlash().getFvImages() == null) {\r
+            return;\r
+        }\r
+        List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
+        if (l == null) {\r
+            return;\r
+        }\r
+        ListIterator li = l.listIterator();\r
+        while(li.hasNext()) {\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
+            if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {\r
+                continue;\r
+            }\r
+            setFvImagesFvImageNameValue (fi, name, value, null);\r
+        }\r
+        \r
+    }\r
+    \r
+    public void setFvImagesFvImageNameValue (int i, String name, String value) {\r
+        XmlObject o = getfpdFlash().getFvImages();\r
+        if (o == null) {\r
+            return;\r
+        }\r
+        XmlCursor cursor = o.newCursor();\r
+        QName qFvImage = new QName(xmlNs, "FvImage");\r
+        if (cursor.toChild(qFvImage)) {\r
+            for (int j = 0; j < i; ++j) {\r
+                cursor.toNextSibling(qFvImage);\r
+            }\r
+            FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
+            setFvImagesFvImageNameValue (fi, name, value, null);\r
+        }\r
+        cursor.dispose();\r
+    }\r
+    \r
+    /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.\r
+     * @param fi\r
+     * @param name\r
+     * @param value\r
+     * @param newName\r
+     */\r
+    public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) {\r
+        if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {\r
+            FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue();\r
+            nv.setName(name);\r
+            nv.setValue(value);\r
+            if (newName != null) {\r
+                nv.setName(newName);\r
+            }\r
+            return;\r
+        }\r
+        \r
+        XmlCursor cursor = fi.getFvImageOptions().newCursor();\r
+        if (cursor.toFirstChild()) {\r
+            do {\r
+                FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject();\r
+                if (nv.getName().equals(name)) {\r
+                    nv.setValue(value);\r
+                    if (newName != null) {\r
+                        nv.setName(newName);\r
+                    }\r
+                    cursor.dispose();\r
+                    return;\r
+                }\r
+            }while (cursor.toNextSibling());\r
+        }\r
+        \r
+        FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();\r
+        nv.setName(name);\r
+        nv.setValue(value);\r
+        if (newName != null) {\r
+            nv.setName(newName);\r
+        }\r
+        cursor.dispose();\r
+    }\r
+    \r
+    public void getFvImagesFvImageOptions (String fvName, Map<String, String> m) {\r
+        Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName (fvName, "Options");\r
+        for (int i = 0; i < vFvImage.size(); ++i) {\r
+            FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);\r
+            if (fi == null || fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {\r
+                continue;\r
+            }\r
+\r
+            ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions()\r
+                                                                                            .getNameValueList()\r
+                                                                                            .listIterator();\r
+            while (li.hasNext()) {\r
+                FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();\r
+                m.put(nv.getName(), nv.getValue());\r
+            }\r
+        }\r
+    }\r
+    \r
+    public int getFvImagePosInFvImages (String fvNameList, String type) {\r
+        XmlObject o = getfpdFlash().getFvImages();\r
+        if (o == null) {\r
+            return -1;\r
+        }\r
+        \r
+        int pos = -1;\r
+        String[] fvNameArray = fvNameList.trim().split(" ");\r
+        Vector<String> vFvNames = new Vector<String>();\r
+        \r
+        \r
+        XmlCursor cursor = o.newCursor();\r
+        QName qFvImage = new QName(xmlNs, "FvImage");\r
+        if (cursor.toChild(qFvImage)) {\r
+            do {\r
+                pos++;\r
+                vFvNames.removeAllElements();\r
+                for (int i = 0; i < fvNameArray.length; ++i) {\r
+                    vFvNames.add(fvNameArray[i]);\r
+                }\r
+                FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
+                if (!fi.getType().toString().equals(type)) {\r
+                    continue;\r
+                }\r
+                if (fi.getFvImageNamesList() == null || fi.getFvImageNamesList().size() != vFvNames.size()) {\r
+                    continue;\r
+                }\r
+                ListIterator<String> li = fi.getFvImageNamesList().listIterator();\r
+                while (li.hasNext()) {\r
+                    String name = li.next();\r
+                    vFvNames.remove(name);\r
+                }\r
+                if (vFvNames.size() == 0) {\r
+                    cursor.dispose();\r
+                    return pos;\r
+                }\r
+                \r
+            }while (cursor.toNextSibling(qFvImage));\r
+           \r
+        }\r
+        cursor.dispose();\r
+        return -1;\r
+    }\r
     /**Get FvImage Options for FvImage i\r
      * @param i the ith FvImage\r
      */\r
@@ -2796,6 +3163,7 @@ public class FpdFileContents {
             }\r
             FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
             if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){\r
+                cursor.dispose();\r
                 return;\r
             }\r
             ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();\r
@@ -2804,6 +3172,7 @@ public class FpdFileContents {
                 m.put(nv.getName(), nv.getValue());\r
             }\r
         }\r
+        cursor.dispose();\r
     }\r
     \r
     /**\r