1 28 29 package org.objectweb.util.browser.plugins.fractal.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.util.browser.api.Entry; 38 import org.objectweb.util.browser.core.api.ContextContainer; 39 import org.objectweb.util.browser.core.naming.AbstractContext; 40 import org.objectweb.util.browser.core.naming.DefaultEntry; 41 import org.objectweb.util.browser.core.naming.DefaultName; 42 import org.objectweb.util.browser.plugins.fractal.FcBrowser; 43 44 49 public class ComponentContextForService 50 extends AbstractContext 51 { 52 58 59 protected Component ci_ = null; 60 61 62 protected ContextContainer controllers_ = null; 63 64 70 76 79 protected boolean isClient(Interface ir) { 80 InterfaceType it = (InterfaceType) ir.getFcItfType(); 81 return it.isFcClientItf(); 82 } 83 84 87 protected boolean isClientCollection(Interface ir) { 88 InterfaceType it = (InterfaceType)ir.getFcItfType(); 89 return (it.isFcClientItf() && it.isFcCollectionItf()); 90 } 91 92 95 protected boolean isController(Interface itf) { 96 return (itf.getFcItfName().endsWith("-controller")||itf.getFcItfName().endsWith("factory")); 97 } 98 99 105 109 public Entry[] getEntries() { 110 Hashtable collectionInterfaces = new Hashtable (); 111 java.util.List values = new java.util.ArrayList (); 112 113 controllers_ = new ControllerContainer(); 114 Object [] fcItfs = (Object [])ci_.getFcInterfaces(); 115 116 for (int i=0 ; i<fcItfs.length ; i++) { 117 if (!ci_.equals(fcItfs[i])) { 118 Interface itf = (Interface)fcItfs[i]; 119 if (isController(itf)) { 120 controllers_.addEntry(FcBrowser.getName(itf),itf); 121 } else if (isClientCollection(itf)) { 122 InterfaceType it = (InterfaceType)itf.getFcItfType(); 123 String name = FcBrowser.getName(itf); 124 if(!collectionInterfaces.containsKey(it.getFcItfName())){ 125 ContextContainer cc = new ClientCollectionInterfaceContainer(itf); 126 cc.addEntry(name,new ClientCollectionInterfaceWrapper(itf)); 127 collectionInterfaces.put(it.getFcItfName(),cc); 128 } else { 129 ((ContextContainer)collectionInterfaces.get(it.getFcItfName())).addEntry(name, 130 new ClientInterfaceWrapper(itf)); 131 } 132 } else if(isClient(itf)) { 133 values.add(new DefaultEntry(new ClientInterfaceWrapper(itf), 134 new DefaultName(FcBrowser.getName(itf)), 135 this)); 136 } else { 137 values.add(new DefaultEntry(itf, 138 new DefaultName(FcBrowser.getName(itf)), 139 this)); 140 } 141 } 142 } 143 Enumeration keys,elements; 145 keys = collectionInterfaces.keys(); 146 elements = collectionInterfaces.elements(); 147 for (int i = 0 ; i < collectionInterfaces.size() ; i++) { 148 values.add(createEntry(elements.nextElement(),(String ) keys.nextElement())); 149 } 150 151 return (Entry[])values.toArray(new Entry[0]); 152 } 153 154 160 164 public void setWrapped(Object object) { 165 ci_ = (Component) object; 166 } 167 168 172 public Object getWrapped() { 173 return ci_; 174 } 175 176 } 177 178 179 180 181 182 183 | Popular Tags |