@@ -0,0 +1,2962 @@
+package org.objectweb.proactive.core.descriptor.util;%0A%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A%0Aimport org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;%0Aimport org.objectweb.proactive.core.descriptor.data.VirtualNode;%0Aimport org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;%0Aimport org.objectweb.proactive.core.mop.Utils;%0A%0A%0Apublic class RefactorPAD %7B%0A%0A%0A    /**%0A     * returns a deep copy of the pad%0A     * used by all other methods before doing changes%0A     * @param pad%0A     * @return ProActiveDescriptor%0A%09 * @throws IOException%0A%09 */%0A    private static ProActiveDescriptor makeDeepCopy(ProActiveDescriptor pad)%0A        throws IOException %7B%0A        ProActiveDescriptor padCopy = (ProActiveDescriptor) Utils.makeDeepCopy(pad);%0A        return padCopy;%0A    %7D%0A%0A    /**%0A     * return a copy of the pad after having removed all the %22main%22 information%0A     * @param pad%0A     * @return refactored pad%0A     * @throws IOException%0A     */%0A    public static ProActiveDescriptor buildNoMainPAD(ProActiveDescriptor pad)%0A        throws IOException %7B%0A        ProActiveDescriptor noMain = makeDeepCopy(pad);%0A%0A        // first remove all main definitions references by clearing the map%0A        noMain.getMainDefinitionMapping().clear();%0A%0A        // then get the virtualnodemapping%0A        Map virtualNodesMapping = noMain.getVirtualNodeMapping();%0A%0A        Set set = virtualNodesMapping.keySet();%0A%0A        // do a copy of the keyList in a list to avoid concurrent problems with iter.next() when removing%0A        List keyList = new ArrayList();%0A        for (Iterator iter = set.iterator(); iter.hasNext();) %7B%0A            String id = (String) iter.next();%0A            keyList.add(id);%0A        %7D%0A%0A        //System.out.println(%22*** VN number before refactor : %22 +%0A        //    virtualNodesMapping.size());%0A        // for all nodes, if the current node is a main node, remove it%0A        for (int i = 0; i %3C keyList.size(); i++) %7B%0A            String id = (String) keyList.get(i);%0A%0A            //System.out.println(%22*** VN searched : %22 + id);%0A            VirtualNode vn = (VirtualNode) virtualNodesMapping.get(id);%0A%0A            //System.out.println(%22*** VN found : %22 + vn.getName());%0A            // test if the node is a virtual node lookup%0A            if (!vn.isLookup()) %7B%0A                // if not so it is a virtual node impl, so downcasting to check if main vn%0A                if (((VirtualNodeImpl) vn).isMainVirtualNode()) %7B%0A                    virtualNodesMapping.remove(id);%0A                    //System.out.println(%22*** VN to remove : %22 + vn.getName());%0A                %7D%0A            %7D else %7B%0A                //System.out.println(%22a VirtualNode lookup cannot be a main VN%22);%0A            %7D%0A        %7D%0A%0A        //System.out.println(%22*** VN number after refactor : %22 +%0A        //    virtualNodesMapping.size());%0A        return noMain;%0A    %7D%0A%7D%0A

refactor a pad