litesoft
@ 947
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.forms.server; import java.util.*; import org.litesoft.GWT.eventbus.client.*; import org.litesoft.GWT.forms.client.rpc.*; import org.litesoft.GWT.forms.server.support.nonpublic.*; import org.litesoft.*; import org.litesoft.ui_1_5.*; import org.litesoft.sequences.*; public class FormServicePeerFactory implements FormComponentBusConstants { public static final ExternalizationInterface DEFAULT_EXTERNALIZATION = DeCamelExternalization.INSTANCE; public static final FormAccessControlFactory DEFAULT_FAC_FACTORY = FormAccessControlFactory.NULL; public static final SequenceSource DEFAULT_SEQ_SRC = SequenceSource.NULL; public static final ISystemUserResolver DEFAULT_USER_RESOLVER = ISystemUserResolver.NULL; private static ExternalizationInterface sExternalization = DEFAULT_EXTERNALIZATION; private static FormAccessControlFactory sFACfactory = DEFAULT_FAC_FACTORY; private static SequenceSource sSeqSrcForUniqueFormID = DEFAULT_SEQ_SRC; private static ISystemUserResolver sSystemUserResolver = DEFAULT_USER_RESOLVER; public static ExternalizationInterface getExternalization() { return sExternalization; } public static void setExternalization( ExternalizationInterface pExternalization ) { sExternalization = (pExternalization != null) ? pExternalization : DEFAULT_EXTERNALIZATION; } public static FormAccessControlFactory getFACfactory() { return sFACfactory; } public static void setFACfactory( FormAccessControlFactory pFACfactory ) { sFACfactory = (pFACfactory != null) ? pFACfactory : DEFAULT_FAC_FACTORY; } public static SequenceSource getUniqueFormIdNumberSequenceSource() { return sSeqSrcForUniqueFormID; } public static void setUniqueFormIdNumberSequenceSource( SequenceSource pSequenceSource ) { sSeqSrcForUniqueFormID = (pSequenceSource != null) ? pSequenceSource : DEFAULT_SEQ_SRC; } public static ISystemUserResolver getSystemUserResolver() { return sSystemUserResolver; } public static void setSystemUserResolver( ISystemUserResolver pSystemUserResolver ) { sSystemUserResolver = (pSystemUserResolver != null) ? pSystemUserResolver : DEFAULT_USER_RESOLVER; } // Note use of Syncronized Map private static Map<String, Class<? extends FormServicePeer>> mServicePeers = new Hashtable<String, Class<? extends FormServicePeer>>(); public static void add( String pFormServicePeerName, Class<? extends FormServicePeer> pFormServicePeerClass ) { mServicePeers.put( pFormServicePeerName, pFormServicePeerClass ); } private static FormServicePeer createFormServicePeer( String pFormServicePeerName ) throws UnsupportedOperationException { Class<? extends FormServicePeer> aClass = mServicePeers.get( pFormServicePeerName ); if ( aClass != null ) { try { return aClass.newInstance(); } catch ( InstantiationException e ) { throw new UnsupportedOperationException( "InstantiationException creating: " + aClass, e ); } catch ( IllegalAccessException e ) { throw new UnsupportedOperationException( "IllegalAccessException creating: " + aClass, e ); } } throw new UnsupportedOperationException( "No FormServicePeer registered for : '" + pFormServicePeerName + "'" ); } public static void addEventListenersForNewClient( EventSubscriptionCollector pCollector ) { pCollector.subscribe( FormServicePeerFactory, new MyEventPackageListener() ); } private static class MyEventPackageListener implements EventPackageListener { public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus ) { FormCreationRequestPackage zPackage = (FormCreationRequestPackage) pEventPackage; FormServicePeer peer; try { peer = createFormServicePeer( zPackage.getType() ); } catch ( UnsupportedOperationException e ) { FormServicePeer.LOGGER.error.log( e ); pEventBus.publish( new FormCreationResponsePackage( zPackage.getTargetName(), // zPackage.getSourceName(), // e.getMessage() ) ); return; } long zUniqueFormServicePeerID = sSeqSrcForUniqueFormID.getNextSequenceNumber( "UniqueFormServicePeerID" ); new FormServicePeerPushInterfaceBusAdapter( pEventBus, peer, sSystemUserResolver, zUniqueFormServicePeerID, zPackage, sExternalization, sFACfactory ); } } } |