org/objectweb/proactive/core/component/adl/vnexportation/LinkedVirtualNode.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.component.adl.vnexportation;
00032 
00033 import java.util.ArrayList;
00034 import java.util.Iterator;
00035 import java.util.List;
00036 
00037 
00055 public class LinkedVirtualNode {
00056     private List composingVirtualNodes;
00057     private LinkedVirtualNode composer = null;
00058     private String componentName;
00059     private String virtualNodeName;
00060     private boolean isMultiple = false;
00061     boolean isLeaf = false;
00062 
00063     //    /private boolean selfExported = false;
00064     public final static String EMPTY_COMPONENT_NAME = "component_name";
00065     public final static String EMPTY_VIRTUAL_NODE_NAME = "virtual_node_name";
00066 
00072     public LinkedVirtualNode(String componentName, String virtualNodeName) {
00073         this.componentName = componentName;
00074         this.virtualNodeName = virtualNodeName;
00075         composingVirtualNodes = new ArrayList();
00076     }
00077 
00078     void setComposer(LinkedVirtualNode composer) {
00079         this.composer = composer;
00080     }
00081 
00087     public boolean addComposingVirtualNode(LinkedVirtualNode vn) {
00088         //        System.out.println("ADDING " + vn.toString() + " \nTO : " + toString());
00089         setMultiple(vn.isMultiple());
00090         if (!composingVirtualNodes.contains(vn)) {
00091             composingVirtualNodes.add(vn);
00092             vn.setComposer(this);
00093             return true;
00094         }
00095         return false;
00096     }
00097 
00102     public List getComposingVirtualNodes() {
00103         return composingVirtualNodes;
00104     }
00105 
00110     public String getComposingVirtualNodesAsString() {
00111         Iterator iter = getComposingVirtualNodes().iterator();
00112         StringBuffer buff = new StringBuffer();
00113         while (iter.hasNext()) {
00114             LinkedVirtualNode element = (LinkedVirtualNode) iter.next();
00115             if (element.getDefiningComponentName().equals(EMPTY_COMPONENT_NAME) ||
00116                     element.getVirtualNodeName().equals(EMPTY_VIRTUAL_NODE_NAME)) {
00117                 continue;
00118             }
00119             buff.append(element.getDefiningComponentName() + "." +
00120                 element.getVirtualNodeName());
00121             buff.append(";");
00122         }
00123         return buff.toString();
00124     }
00125 
00130     public String getVirtualNodeName() {
00131         return virtualNodeName;
00132     }
00133 
00138     public String getCompleteNameBeforeComposition() {
00139         return componentName + '.' + virtualNodeName;
00140     }
00141 
00146     public String getExportedVirtualNodeNameAfterComposition() {
00147         return ((composer == null) ? virtualNodeName
00148                                    : composer.getExportedVirtualNodeNameAfterComposition());
00149     }
00150 
00155     public String getExportedVirtualNodeNameBeforeComposition() {
00156         return ((composer == null) ? virtualNodeName
00157                                    : composer.getVirtualNodeName());
00158     }
00159 
00164     public void setMultiple(boolean yes) {
00165         if (yes) {
00166             isMultiple = true;
00167         }
00168     }
00169 
00174     public boolean isMultiple() {
00175         return isMultiple;
00176     }
00177 
00182     public boolean isExported() {
00183         return composingVirtualNodes.size() > 0;
00184     }
00185 
00190     public String getDefiningComponentName() {
00191         return componentName;
00192     }
00193 
00199     //    public void setSelfExported() {
00200     //        selfExported=true;
00201     //    }
00202 
00206     public boolean isSelfExported() {
00207         if (composer == null) {
00208             return false;
00209         }
00210 
00211         // FIXME find a better way
00212         return (isLeaf ||
00213         composer.getDefiningComponentName().equals(getDefiningComponentName()));
00214     }
00215 
00222     public boolean isComposedFrom(String componentName, String virtualNodeName) {
00223         Iterator it = composingVirtualNodes.iterator();
00224         while (it.hasNext()) {
00225             LinkedVirtualNode lvn = (LinkedVirtualNode) it.next();
00226             if (lvn.getDefiningComponentName().equals(componentName)) {
00227                 if (lvn.getVirtualNodeName().equals(virtualNodeName)) {
00228                     return true;
00229                 }
00230             }
00231         }
00232         return false;
00233     }
00234 
00239     public LinkedVirtualNode getComposer() {
00240         return composer;
00241     }
00242 
00243     public void setIsLeaf() {
00244         isLeaf = true;
00245     }
00246 
00247     public boolean isLeaf() {
00248         return isLeaf;
00249     }
00250 
00251     public String toString() {
00252         StringBuffer buffer = new StringBuffer();
00253         if (composer == this) {
00254             buffer.append(getDefiningComponentName() + "." +
00255                 getVirtualNodeName() + "<--" + componentName + "." +
00256                 virtualNodeName + "-->{");
00257         } else if (composer != null) {
00258             buffer.append(composer.getDefiningComponentName() + "." +
00259                 composer.getVirtualNodeName() + "<--" + componentName + "." +
00260                 virtualNodeName + "-->{");
00261         }
00262         Iterator it = composingVirtualNodes.iterator();
00263         while (it.hasNext()) {
00264             LinkedVirtualNode lvn = (LinkedVirtualNode) it.next();
00265             if (lvn == this) {
00266                 continue;
00267             }
00268             buffer.append(lvn.toString());
00269         }
00270         return buffer.append("}").toString();
00271     }
00272 }

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