1 package org.starobjects.tested.fitnesse.internal; 2 3 import java.util.Collection; 4 import java.util.Collections; 5 import java.util.HashMap; 6 import java.util.List; 7 import java.util.Map; 8 9 import org.nakedobjects.metamodel.adapter.NakedObject; 10 import org.nakedobjects.runtime.context.NakedObjectsContext; 11 import org.nakedobjects.runtime.persistence.PersistenceSession; 12 import org.nakedobjects.runtime.session.NakedObjectSession; 13 14 public class ServiceRegistry { 15 16 private final Map<String, String> serviceClassNamesByAliasAs = new HashMap<String, String>(); 17 private boolean registeredServiceAliases = false; 18 19 public void registerServiceAliasAsIfRequired( 20 final AliasesRegistry aliasAsRegistry) { 21 if (registeredServiceAliases) { 22 return; 23 } 24 final List<NakedObject> serviceAdapters = ServiceRegistry 25 .getPersistenceSession().getServices(); 26 for (final Map.Entry<String, String> serviceClassNameByAliasAs : serviceClassNamesByAliasAs 27 .entrySet()) { 28 for (final NakedObject serviceAdapter : serviceAdapters) { 29 if (serviceAdapter.getSpecification().getFullName().equals( 30 serviceClassNameByAliasAs.getValue())) { 31 final String aliasAs = serviceClassNameByAliasAs.getKey(); 32 aliasAsRegistry.put(aliasAs, serviceAdapter); 33 } 34 } 35 } 36 registeredServiceAliases = true; 37 } 38 39 public void addService(final String holdAs, final String className) { 40 serviceClassNamesByAliasAs.put(holdAs, className); 41 } 42 43 public Collection<String> getServiceClassNames() { 44 return Collections.unmodifiableCollection(serviceClassNamesByAliasAs 45 .values()); 46 } 47 48 private static PersistenceSession getPersistenceSession() { 49 return ServiceRegistry.getSession().getPersistenceSession(); 50 } 51 52 private static NakedObjectSession getSession() { 53 return NakedObjectsContext.getSession(); 54 } 55 56 }