1 28 29 package org.objectweb.fractal.explorer.context; 30 31 import java.util.Enumeration ; 32 import java.util.Hashtable ; 33 34 import org.objectweb.fractal.api.Component; 35 import org.objectweb.fractal.api.Interface; 36 import org.objectweb.fractal.api.type.InterfaceType; 37 import org.objectweb.fractal.explorer.FcExplorer; 38 import org.objectweb.util.explorer.api.Context; 39 import org.objectweb.util.explorer.api.Entry; 40 import org.objectweb.util.explorer.core.common.api.ContextContainer; 41 import org.objectweb.util.explorer.core.naming.lib.DefaultEntry; 42 43 48 public class ComponentContextForService 49 implements Context 50 { 51 57 58 protected ContextContainer controllers_ = null; 59 60 66 72 75 protected boolean isClient(Interface ir) { 76 InterfaceType it = (InterfaceType) ir.getFcItfType(); 77 return it.isFcClientItf(); 78 } 79 80 83 protected boolean isClientCollection(Interface ir) { 84 InterfaceType it = (InterfaceType)ir.getFcItfType(); 85 return (it.isFcClientItf() && it.isFcCollectionItf()); 86 } 87 88 91 protected boolean isController(Interface itf) { 92 return (itf.getFcItfName().endsWith("-controller")||itf.getFcItfName().endsWith("factory")); 93 } 94 95 101 105 public Entry[] getEntries(Object object) { 106 Component ci = (Component)object; 107 108 Hashtable collectionInterfaces = new Hashtable (); 109 java.util.List values = new java.util.ArrayList (); 110 111 controllers_ = new ControllerContainer(); 112 Object [] fcItfs = (Object [])ci.getFcInterfaces(); 113 114 for (int i=0 ; i<fcItfs.length ; i++) { 115 if (!ci.equals(fcItfs[i])) { 116 Interface itf = (Interface)fcItfs[i]; 117 if (isController(itf)) { 118 controllers_.addEntry(FcExplorer.getName(itf),itf); 119 } else if (isClientCollection(itf)) { 120 InterfaceType it = (InterfaceType)itf.getFcItfType(); 121 String name = FcExplorer.getName(itf); 122 if(!collectionInterfaces.containsKey(it.getFcItfName())){ 123 ContextContainer cc = new ClientCollectionInterfaceContainer(itf); 124 cc.addEntry(name,new ClientCollectionInterfaceWrapper(itf)); 125 collectionInterfaces.put(it.getFcItfName(),cc); 126 } else { 127 ((ContextContainer)collectionInterfaces.get(it.getFcItfName())).addEntry(name, 128 new ClientInterfaceWrapper(itf)); 129 } 130 } else if(isClient(itf)) { 131 values.add(new DefaultEntry(FcExplorer.getName(itf), new ClientInterfaceWrapper(itf))); 132 } else { 133 values.add(new DefaultEntry(FcExplorer.getName(itf), itf)); 134 } 135 } 136 } 137 Enumeration keys,elements; 139 keys = collectionInterfaces.keys(); 140 elements = collectionInterfaces.elements(); 141 for (int i = 0 ; i < collectionInterfaces.size() ; i++) { 142 values.add(new DefaultEntry((String ) keys.nextElement(),elements.nextElement())); 143 } 144 145 return (Entry[])values.toArray(new Entry[0]); 146 } 147 148 } 149 150 151 152 153 154 155 | Popular Tags |