org/objectweb/proactive/core/descriptor/util/RefactorPAD.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.descriptor.util;
00032 
00033 import java.io.IOException;
00034 import java.util.ArrayList;
00035 import java.util.Iterator;
00036 import java.util.List;
00037 import java.util.Map;
00038 import java.util.Set;
00039 
00040 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00041 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00042 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;
00043 import org.objectweb.proactive.core.mop.Utils;
00044 
00045 
00052 public class RefactorPAD {
00053 
00061     private static ProActiveDescriptor makeDeepCopy(ProActiveDescriptor pad)
00062         throws IOException {
00063         ProActiveDescriptor padCopy = (ProActiveDescriptor) Utils.makeDeepCopy(pad);
00064         return padCopy;
00065     }
00066 
00073     public static ProActiveDescriptor buildNoMainPAD(ProActiveDescriptor pad)
00074         throws IOException {
00075         ProActiveDescriptor noMain = makeDeepCopy(pad);
00076 
00077         // first remove all main definitions references by clearing the map
00078         noMain.getMainDefinitionMapping().clear();
00079 
00080         // then get the virtualnodemapping
00081         Map virtualNodesMapping = noMain.getVirtualNodeMapping();
00082 
00083         Set set = virtualNodesMapping.keySet();
00084 
00085         // do a copy of the keyList in a list to avoid concurrent problems with iter.next() when removing
00086         List<String> keyList = new ArrayList<String>();
00087         for (Iterator iter = set.iterator(); iter.hasNext();) {
00088             String id = (String) iter.next();
00089             keyList.add(id);
00090         }
00091 
00092         //System.out.println("*** VN number before refactor : " +
00093         //    virtualNodesMapping.size());
00094         // for all nodes, if the current node is a main node, remove it
00095         for (int i = 0; i < keyList.size(); i++) {
00096             String id = keyList.get(i);
00097 
00098             //System.out.println("*** VN searched : " + id);
00099             VirtualNode vn = (VirtualNode) virtualNodesMapping.get(id);
00100 
00101             //System.out.println("*** VN found : " + vn.getName());
00102             // test if the node is a virtual node lookup
00103             if (!vn.isLookup()) {
00104                 // if not so it is a virtual node impl, so downcasting to check if main vn
00105                 if (((VirtualNodeImpl) vn).isMainVirtualNode()) {
00106                     virtualNodesMapping.remove(id);
00107                     //System.out.println("*** VN to remove : " + vn.getName());
00108                 }
00109             } else {
00110                 //System.out.println("a VirtualNode lookup cannot be a main VN");
00111             }
00112         }
00113         noMain.setMainDefined(false);
00114         //System.out.println("*** VN number after refactor : " +
00115         //    virtualNodesMapping.size());
00116         return noMain;
00117     }
00118 }

Generated on Mon Jan 22 15:16:07 2007 for ProActive by  doxygen 1.5.1