litesoft
@ 948
litesoft / trunk / GWT_Sandbox / MultiModule / common / src / org / litesoft / sandbox / infrastructure / client / ActivityFactoryRegistry.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
package org.litesoft.sandbox.infrastructure.client; import com.google.gwt.place.shared.*; import com.google.gwt.user.client.ui.*; import java.util.*; public class ActivityFactoryRegistry { public static <CommonActivityParam extends CommonActivityParameter, View extends IsWidget, APlace extends Place> void register( ActivityFactory.Synchronous<CommonActivityParam, View, APlace> pFactory ) { add( pFactory ); } public static <CommonActivityParam extends CommonActivityParameter, View extends IsWidget, APlace extends Place> void register( ActivityFactory.Asynchronous<CommonActivityParam, View, APlace> pFactory ) { add( pFactory ); } private static final Map<String, ActivityFactory> PLACEID2ACTIVITYFACTORIES = new HashMap<String, ActivityFactory>(); protected static synchronized ActivityFactory get( String pPlaceId ) { return PLACEID2ACTIVITYFACTORIES.get( pPlaceId ); } protected static synchronized boolean replace( ActivityFactory.Asynchronous pExistingFactory, ActivityFactory pNewSyncFactory ) { if ( pNewSyncFactory != null ) { String zPlaceId = pNewSyncFactory.getPlaceId(); if ( !pExistingFactory.getPlaceId().equals( zPlaceId ) ) { throw new IllegalStateException( "New Sync Factory for '" + zPlaceId + "', not '" + pExistingFactory.getPlaceId() + "'" ); } ActivityFactory zPreviousFactory = PLACEID2ACTIVITYFACTORIES.put( zPlaceId, pNewSyncFactory ); if ( pExistingFactory != zPreviousFactory ) { throw new IllegalStateException( "Existing Async Factory (" + pExistingFactory.getClass() + ") already replaced by (" + zPreviousFactory.getClass() + ") for: " + zPlaceId ); } return true; } return false; } private static synchronized void add( ActivityFactory pFactory ) { if ( pFactory != null ) { String zPlaceId = pFactory.getPlaceId(); ActivityFactory zPreviousFactory = PLACEID2ACTIVITYFACTORIES.put( zPlaceId, pFactory ); if ( (zPreviousFactory != null) && (zPreviousFactory == pFactory) ) { throw new IllegalStateException( "Duplicate registration for '" + zPlaceId + "', previous (" + zPreviousFactory.getClass() + "), new (" + pFactory.getClass() + ")" ); } } } } |