1 23 24 package org.objectweb.fractal.gui.repository.lib; 25 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 import org.objectweb.fractal.api.control.BindingController; 31 import org.objectweb.fractal.gui.graph.model.GraphModel; 32 import org.objectweb.fractal.gui.model.Component; 33 import org.objectweb.fractal.gui.model.Factory; 34 import org.objectweb.fractal.gui.model.Interface; 35 import org.objectweb.fractal.gui.repository.api.Repository; 36 import org.objectweb.fractal.gui.repository.api.Storage; 37 38 43 44 public class BasicRepository implements Repository, BindingController { 45 46 50 51 public final static String STORAGE_BINDING = "storage"; 52 53 56 57 public final static String DEFINITION_FACTORY_BINDING = "definition-factory"; 58 59 64 65 public final static String CONFIGURATION_FACTORY_BINDING = "configuration-factory"; 66 67 70 71 private Storage storage; 72 73 76 77 private org.objectweb.fractal.adl.Factory definitionFactory; 78 79 82 83 private Factory configurationFactory; 84 85 89 public String [] listFc () { 90 return new String [] { 91 STORAGE_BINDING, 92 DEFINITION_FACTORY_BINDING, 93 CONFIGURATION_FACTORY_BINDING 94 }; 95 } 96 97 public Object lookupFc (final String clientItfName) { 98 if (STORAGE_BINDING.equals(clientItfName)) { 99 return storage; 100 } else if (DEFINITION_FACTORY_BINDING.equals(clientItfName)) { 101 return definitionFactory; 102 } else if (CONFIGURATION_FACTORY_BINDING.equals(clientItfName)) { 103 return configurationFactory; 104 } 105 return null; 106 } 107 108 public void bindFc ( 109 final String clientItfName, 110 final Object serverItf) 111 { 112 if (STORAGE_BINDING.equals(clientItfName)) { 113 storage = (Storage)serverItf; 114 } else if (DEFINITION_FACTORY_BINDING.equals(clientItfName)) { 115 definitionFactory = (org.objectweb.fractal.adl.Factory)serverItf; 116 } else if (CONFIGURATION_FACTORY_BINDING.equals(clientItfName)) { 117 configurationFactory = (Factory)serverItf; 118 } 119 } 120 121 public void unbindFc (final String clientItfName) { 122 if (STORAGE_BINDING.equals(clientItfName)) { 123 storage = null; 124 } else if (DEFINITION_FACTORY_BINDING.equals(clientItfName)) { 125 definitionFactory = null; 126 } else if (CONFIGURATION_FACTORY_BINDING.equals(clientItfName)) { 127 configurationFactory = null; 128 } 129 } 130 131 135 public Component loadComponent ( 136 final String name, 137 final GraphModel graph) throws Exception 138 { 139 Map context = new HashMap (); 140 context.put("factory", configurationFactory); 141 if (graph != null) { 142 context.put("graph", graph); 143 } 144 Component c = (Component)definitionFactory.newComponent(name, context); 145 removeGeneratedNames(c); 146 return c; 147 } 148 149 public String storeComponent ( 150 final Component component, 151 final GraphModel graph, 152 final Object hints) throws Exception 153 { 154 FractalAdlWriter writer = new FractalAdlWriter(); 155 writer.storage = storage; 156 writer.forceInternal = "inline".equals(hints); 157 return writer.saveTemplate(component, graph); 158 } 159 160 private void removeGeneratedNames (Component c) { 161 if (c.getName().startsWith("GENERATED-")) { 162 c.setName(""); 163 } 164 List l = c.getClientInterfaces(); 165 for (int i = 0; i < l.size(); ++i) { 166 Interface itf = (Interface)l.get(i); 167 if (itf.getName().startsWith("GENERATED-")) { 168 itf.setName(""); 169 } 170 } 171 l = c.getServerInterfaces(); 172 for (int i = 0; i < l.size(); ++i) { 173 Interface itf = (Interface)l.get(i); 174 if (itf.getName().startsWith("GENERATED-")) { 175 itf.setName(""); 176 } 177 } 178 l = c.getSubComponents(); 179 for (int i = 0; i < l.size(); ++i) { 180 removeGeneratedNames((Component)l.get(i)); 181 } 182 } 183 } 184 | Popular Tags |