idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
3,700
private void showNext ( final JRebirthEvent event ) { this . timeFrame ++ ; callCommand ( ProcessEventCommand . class , WBuilder . waveData ( EditorWaves . EVENT , event ) ) ; }
Show next element .
3,701
public void doStop ( final Wave wave ) { for ( int i = this . timeFrame ; i >= 0 ; i -- ) { hideCurrent ( this . eventList . get ( this . timeFrame ) ) ; } }
Call when event stop button is pressed .
3,702
public void registerBall ( final BallModel ballModel ) { if ( ! this . ballMap . containsKey ( ballModel . getEventModel ( ) . target ( ) ) ) { this . ballMap . put ( ballModel . getEventModel ( ) . target ( ) , ballModel ) ; view ( ) . getPanel ( ) . getChildren ( ) . add ( ballModel . node ( ) ) ; } }
Register a ball model .
3,703
public void unregisterBall ( final BallModel ballModel ) { this . ballMap . remove ( ballModel . getEventModel ( ) . target ( ) ) ; view ( ) . getPanel ( ) . getChildren ( ) . remove ( ballModel . node ( ) ) ; }
Unregister a ball model .
3,704
public void runIntoJTP ( final JRebirthRunnable runnable ) { if ( getFacade ( ) . executorService ( ) . checkAvailability ( runnable . priority ( ) ) ) { getFacade ( ) . executorService ( ) . execute ( runnable ) ; LOGGER . log ( JTP_QUEUED , runnable . toString ( ) ) ; } else { getFacade ( ) . highPriorityExecutorService ( ) . execute ( runnable ) ; LOGGER . log ( HPTP_QUEUED , runnable . toString ( ) ) ; } }
Run into thread pool .
3,705
private void manageStyleSheetReloading ( final Scene scene ) { if ( CoreParameters . DEVELOPER_MODE . get ( ) && scene != null ) { for ( final String styleSheet : scene . getStylesheets ( ) ) { getFacade ( ) . serviceFacade ( ) . retrieve ( StyleSheetTrackerService . class ) . listen ( styleSheet , this . application . scene ( ) ) ; } getFacade ( ) . serviceFacade ( ) . retrieve ( StyleSheetTrackerService . class ) . start ( ) ; } }
Manage style sheet reloading by using a custom service provide by JRebirth Core .
3,706
public void bootUp ( ) throws JRebirthThreadException { final List < Wave > chainedWaveList = new ArrayList < > ( ) ; final List < Wave > preBootList = getApplication ( ) . preBootWaveList ( ) ; if ( preBootList != null && ! preBootList . isEmpty ( ) ) { chainedWaveList . addAll ( preBootList ) ; } final Wave firstViewWave = getLaunchFirstViewWave ( ) ; if ( firstViewWave != null ) { chainedWaveList . add ( firstViewWave ) ; } final List < Wave > postBootList = getApplication ( ) . postBootWaveList ( ) ; if ( postBootList != null && ! postBootList . isEmpty ( ) ) { chainedWaveList . addAll ( postBootList ) ; } if ( ! chainedWaveList . isEmpty ( ) ) { getFacade ( ) . notifier ( ) . sendWave ( WBuilder . chainWaveCommand ( chainedWaveList ) ) ; } }
Attach the first view and run pre and post command .
3,707
public void close ( ) { if ( this . infiniteLoop . get ( ) ) { this . infiniteLoop . set ( false ) ; } else { this . forceClose . set ( true ) ; this . processingTasks . clear ( ) ; } }
This method can be called a lot of time while application is running .
3,708
private void shutdown ( ) { try { this . facade . stop ( ) ; this . facade = null ; destroyInstance ( ) ; } catch ( final CoreException e ) { LOGGER . log ( SHUTDOWN_ERROR , e ) ; } }
Release all resources .
3,709
protected Wave getLaunchFirstViewWave ( ) { Wave firstWave = null ; if ( this . application != null && this . application . rootNode ( ) != null && this . application . firstModelClass ( ) != null ) { final UniqueKey < ? extends Model > modelKey = Key . create ( this . application . firstModelClass ( ) , this . application . firstModelOptionalData ( ) , this . application . firstModelKeyParts ( ) ) ; firstWave = WBuilder . callCommand ( ShowModelCommand . class ) . waveBean ( DisplayModelWaveBean . create ( ) . childrenPlaceHolder ( this . application . rootNode ( ) . getChildren ( ) ) . showModelKey ( modelKey ) ) ; } return firstWave ; }
Launch the first view by adding it into the root node .
3,710
private void createSPIFile ( String moduleName ) { try { final FileObject fo = this . processingEnv . getFiler ( ) . createResource ( StandardLocation . CLASS_OUTPUT , "" , MODULE_STARTER_SPI_PATH ) ; this . processingEnv . getMessager ( ) . printMessage ( Diagnostic . Kind . NOTE , "creating spi file: " + fo . toUri ( ) ) ; final Writer writer = fo . openWriter ( ) ; writer . write ( moduleName ) ; writer . close ( ) ; } catch ( final IOException e ) { e . printStackTrace ( ) ; throw new RuntimeException ( e ) ; } }
Creates SPI file to expose the module stater
3,711
private String createModuleStarter ( final Map < Class < ? > , Set < ? extends Element > > annotationMap , ProcessingEnvironment processingEnv ) { String moduleName ; try { moduleName = getModuleStarterName ( processingEnv ) ; final String starterName = moduleName . substring ( moduleName . lastIndexOf ( '.' ) + 1 ) ; final String pkg = moduleName . substring ( 0 , moduleName . lastIndexOf ( '.' ) ) ; final JavaClassSource javaClass = Roaster . create ( JavaClassSource . class ) ; javaClass . setPackage ( pkg ) . setName ( starterName ) ; javaClass . extendSuperType ( AbstractModuleStarter . class ) ; final StringBuilder body = new StringBuilder ( ) ; appendRegistrationPoints ( javaClass , body , annotationMap . get ( RegistrationPoint . class ) ) ; appendRegistrations ( javaClass , body , annotationMap . get ( Register . class ) ) ; appendPreload ( javaClass , body , annotationMap . get ( Preload . class ) ) ; appendBootComponent ( javaClass , body , annotationMap . get ( BootComponent . class ) ) ; if ( ! javaClass . hasMethodSignature ( "start" ) ) { final MethodSource < ? > method = javaClass . addMethod ( ) . setName ( "start" ) . setPublic ( ) . setBody ( body . toString ( ) ) . setReturnTypeVoid ( ) ; method . getJavaDoc ( ) . setFullText ( "{@inheritDoc}" ) ; method . addAnnotation ( Override . class ) ; } else { javaClass . getMethod ( "start" ) . setBody ( javaClass . getMethod ( "start" ) . getBody ( ) + body . toString ( ) ) ; } final Properties prefs = new Properties ( ) ; prefs . load ( this . getClass ( ) . getResourceAsStream ( FORMATTER_PROPERTIES_FILE ) ) ; final String formattedSource = Formatter . format ( prefs , javaClass ) ; final JavaFileObject jfo = this . processingEnv . getFiler ( ) . createSourceFile ( moduleName ) ; this . processingEnv . getMessager ( ) . printMessage ( Diagnostic . Kind . NOTE , "creating source file: " + jfo . toUri ( ) ) ; final Writer writer = jfo . openWriter ( ) ; writer . write ( formattedSource ) ; writer . close ( ) ; } catch ( final Exception e ) { e . printStackTrace ( ) ; throw new RuntimeException ( e ) ; } return moduleName ; }
Creates module stater class according to the annotations
3,712
public void listen ( final String styleSheetPath , final Scene scene ) { final File file = new File ( styleSheetPath ) ; file . lastModified ( ) ; }
Listen new style sheet path .
3,713
private String getWaveTypesString ( final WaveType [ ] waveTypes ) { final StringBuilder sb = new StringBuilder ( ) ; for ( final WaveType waveType : waveTypes ) { sb . append ( waveType . toString ( ) ) . append ( " " ) ; } return sb . toString ( ) ; }
Return the human - readable list of Wave Type .
3,714
private Wave sendWaveIntoJit ( final Wave wave ) { CheckerUtility . checkWave ( wave ) ; wave . status ( Status . Sent ) ; final PriorityLevel priority = wave . contains ( JRebirthItems . priority ) ? wave . get ( JRebirthItems . priority ) : PriorityLevel . Normal ; final RunType runType = wave . contains ( JRebirthItems . runSynchronously ) && wave . get ( JRebirthItems . runSynchronously ) ? RunType . JIT_SYNC : RunType . JIT ; final Long timeout = wave . contains ( JRebirthItems . syncTimeout ) ? wave . get ( JRebirthItems . syncTimeout ) : SyncRunnable . DEFAULT_TIME_OUT ; JRebirth . run ( runType , SEND_WAVE . getText ( wave . toString ( ) ) , priority , ( ) -> getNotifier ( ) . sendWave ( wave ) , timeout ) ; return wave ; }
Send the given wave using the JRebirth Thread .
3,715
private Wave createWave ( final WaveGroup waveGroup , final WaveType waveType , final Class < ? > componentClass , final WaveData < ? > ... waveData ) { final Wave wave = wave ( ) . waveGroup ( waveGroup ) . waveType ( waveType ) . fromClass ( this . getClass ( ) ) . componentClass ( componentClass ) . addDatas ( waveData ) ; localFacade ( ) . globalFacade ( ) . trackEvent ( JRebirthEventType . CREATE_WAVE , this . getClass ( ) , wave . getClass ( ) ) ; return wave ; }
Build a wave object .
3,716
private Wave createWave ( final WaveGroup waveGroup , final WaveType waveType , final Class < ? > componentClass , final WaveBean waveBean , final WaveBean ... waveBeans ) { final List < WaveBean > waveBeanList = new ArrayList < > ( ) ; waveBeanList . add ( waveBean ) ; if ( waveBeans . length > 0 ) { waveBeanList . addAll ( Arrays . asList ( waveBeans ) ) ; } final Wave wave = wave ( ) . waveGroup ( waveGroup ) . waveType ( waveType ) . fromClass ( this . getClass ( ) ) . componentClass ( componentClass ) . waveBeanList ( waveBeanList ) ; localFacade ( ) . globalFacade ( ) . trackEvent ( JRebirthEventType . CREATE_WAVE , this . getClass ( ) , wave . getClass ( ) ) ; return wave ; }
Build a wave object with its dedicated WaveBean .
3,717
private void callAnnotatedMethod ( final Class < ? extends Annotation > annotationClass ) { if ( this . lifecycleMethod . get ( annotationClass . getName ( ) ) != null ) { for ( final Method method : this . lifecycleMethod . get ( annotationClass . getName ( ) ) ) { try { ClassUtility . callMethod ( method , this ) ; } catch ( final CoreException e ) { LOGGER . error ( CALL_ANNOTATED_METHOD_ERROR , e ) ; } } } }
Call annotated methods corresponding at given lifecycle annotation .
3,718
private void internalRelease ( ) { callAnnotatedMethod ( OnRelease . class ) ; if ( localFacade ( ) != null ) { localFacade ( ) . unregister ( key ( ) ) ; } if ( getInnerComponentMap ( ) . isPresent ( ) ) { final List < Component < ? > > toRemove = new ArrayList < > ( ) ; for ( final Component < ? > innerComponent : getInnerComponentMap ( ) . get ( ) . values ( ) ) { innerComponent . release ( ) ; toRemove . add ( innerComponent ) ; } for ( final Component < ? > innerComponent : toRemove ) { getInnerComponentMap ( ) . get ( ) . remove ( innerComponent . key ( ) ) ; } } }
Perform the internal release .
3,719
public synchronized void close ( ) { if ( endHandler != null ) { endHandler . handle ( null ) ; } closed = true ; if ( listener != null && handleCalled ) { listener . sessionClosed ( ) ; } }
Yes SockJS is weird but it s hard to work out expected server behaviour when there s no spec
3,720
private void doClose ( ) { super . close ( ) ; if ( heartbeatID != - 1 ) { vertx . cancelTimer ( heartbeatID ) ; } if ( timeoutTimerID != - 1 ) { vertx . cancelTimer ( timeoutTimerID ) ; } if ( id != null ) { sessions . remove ( id ) ; } if ( ! closed ) { closed = true ; if ( endHandler != null ) { endHandler . handle ( null ) ; } } }
Yes I know it s weird but that s the way SockJS likes it .
3,721
public void doEventsLoaded ( final List < JRebirthEvent > eventList , final Wave wave ) { view ( ) . activateButtons ( ! eventList . isEmpty ( ) ) ; }
Call when event are loaded .
3,722
private void handle401 ( final YokeRequest request , final Handler < Object > next ) { YokeResponse response = request . response ( ) ; response . putHeader ( "WWW-Authenticate" , "Basic realm=\"" + getRealm ( request ) + "\"" ) ; response . setStatusCode ( 401 ) ; next . handle ( "No authorization token" ) ; }
Handle all forbidden errors in this case we need to add a special header to the response
3,723
void activateButtons ( final boolean enable ) { this . unloadButton . setDisable ( ! enable ) ; this . playPauseButton . setDisable ( ! enable ) ; this . backwardButton . setDisable ( ! enable ) ; this . forwardButton . setDisable ( ! enable ) ; this . stopButton . setDisable ( ! enable ) ; }
Change activation of all buttons .
3,724
private FXMLComponent buildFXMLComponent ( final FXML fxmlParam ) { return FXMLUtils . loadFXML ( null , fxmlParam . getFxmlPath ( ) + FXML . FXML_EXT , fxmlParam . getBundlePath ( ) ) ; }
Build a FXML component that embed a node and its FXML controller .
3,725
public void stackUp ( final Undoable command ) { this . commandStack . add ( command ) ; this . commandStack . get ( this . commandStack . size ( ) - 1 ) . run ( WBuilder . wave ( ) . addDatas ( WBuilder . waveData ( UndoRedoWaves . UNDO_REDO , false ) ) ) ; }
Stack up a command .
3,726
public void undo ( ) { if ( this . commandStack . size ( ) > 0 ) { this . undoneStack . add ( this . commandStack . get ( this . commandStack . size ( ) - 1 ) ) ; this . commandStack . remove ( this . commandStack . get ( this . commandStack . size ( ) - 1 ) ) ; this . undoneStack . get ( this . undoneStack . size ( ) - 1 ) . run ( WBuilder . wave ( ) . addDatas ( WBuilder . waveData ( UndoRedoWaves . UNDO_REDO , true ) ) ) ; } else { LOGGER . info ( "No more command to undo, begin of stack" ) ; } }
Undo the last command .
3,727
public void redo ( ) { if ( this . undoneStack . size ( ) > 0 ) { this . commandStack . add ( this . undoneStack . get ( this . undoneStack . size ( ) - 1 ) ) ; this . undoneStack . remove ( this . undoneStack . size ( ) - 1 ) ; this . commandStack . get ( this . commandStack . size ( ) - 1 ) . run ( WBuilder . wave ( ) . addDatas ( WBuilder . waveData ( UndoRedoWaves . UNDO_REDO , false ) ) ) ; } else { LOGGER . info ( "No more command to redo, end of stack" ) ; } }
Redo the last command that was undo - ed .
3,728
public static void removeRegistrationId ( Context context ) { final SharedPreferences prefs = getGcmPreferences ( context ) ; prefs . edit ( ) . remove ( PROPERTY_REG_ID ) . remove ( PROPERTY_APP_VERSION ) . apply ( ) ; }
Removes the current registration id effectively forcing the app to register again .
3,729
private void onCreate ( Context context ) { if ( GcmUtils . checkCanAndShouldRegister ( context ) ) { context . startService ( GcmRegistrationService . createGcmRegistrationIntent ( context ) ) ; } }
Registers the application defined by a context activity to GCM in case the registration has not been done already . The method can be called anytime but typically at app startup . The registration itself is guaranteed to only run once .
3,730
void onSuccessfulRegistration ( Context context , String regId ) { getGcmListener ( context ) . sendRegistrationIdToBackend ( regId ) ; storeRegistrationId ( context , regId ) ; }
Called from an IntentService background thread
3,731
protected void define ( final Class < ? extends Component < ? > > interfaceClass , final boolean exclusive , final boolean reverse ) { preloadClass ( interfaceClass ) ; getFacade ( ) . componentFactory ( ) . define ( RegistrationPointItemBase . create ( ) . interfaceClass ( interfaceClass ) . exclusive ( exclusive ) . reverse ( reverse ) ) ; }
Define a new component interface definition .
3,732
@ SuppressWarnings ( "unchecked" ) protected void bootComponent ( final Class < ? extends Component < ? > > componentClass ) { preloadClass ( componentClass ) ; try { if ( Command . class . isAssignableFrom ( componentClass ) ) { getFacade ( ) . commandFacade ( ) . retrieve ( ( Class < Command > ) componentClass ) ; } else if ( Service . class . isAssignableFrom ( componentClass ) ) { getFacade ( ) . serviceFacade ( ) . retrieve ( ( Class < Service > ) componentClass ) ; } else if ( Model . class . isAssignableFrom ( componentClass ) ) { getFacade ( ) . uiFacade ( ) . retrieve ( ( Class < Model > ) componentClass ) ; } } catch ( final CoreRuntimeException e ) { LOGGER . error ( BOOT_COMPONENT_ERROR , e , componentClass . getName ( ) ) ; } }
Boot component by retrieving it from its facade .
3,733
protected void preloadClass ( final Class < ? > objectClass ) { try { Class . forName ( objectClass . getName ( ) ) ; } catch ( final ClassNotFoundException e ) { LOGGER . error ( CLASS_NOT_FOUND , e , objectClass . getName ( ) ) ; } }
Preload class useful to preload field initialized with JRebirth Builder .
3,734
public Middleware init ( final Yoke yoke , final String mount ) { try { super . init ( yoke , mount ) ; if ( path == null ) { icon = new Icon ( Utils . readResourceToBuffer ( getClass ( ) , "favicon.ico" ) ) ; } else { icon = new Icon ( fileSystem ( ) . readFileBlocking ( path ) ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return this ; }
Loads the icon from the file system once we get a reference to Vert . x
3,735
private URL buildUrl ( final String styleSheetPath , final boolean skipStylesFolder ) { URL cssResource = null ; final List < String > stylePaths = skipStylesFolder ? Collections . singletonList ( "" ) : ResourceParameters . STYLE_FOLDER . get ( ) ; for ( int i = 0 ; i < stylePaths . size ( ) && cssResource == null ; i ++ ) { String stylePath = stylePaths . get ( i ) ; if ( ! stylePath . isEmpty ( ) ) { stylePath += Resources . PATH_SEP ; } cssResource = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( stylePath + styleSheetPath ) ; } if ( cssResource == null ) { LOGGER . error ( "Style Sheet : {} not found into base folder: {}" , styleSheetPath , ResourceParameters . STYLE_FOLDER . get ( ) ) ; } return cssResource ; }
Get a style sheet URL .
3,736
public long lastModified ( final String filename ) { LRUCache . CacheEntry < String , T > cacheEntry = cache . get ( filename ) ; if ( cacheEntry == null ) { return - 1 ; } return cacheEntry . lastModified ; }
Returns the last modified time for the cache entry
3,737
@ SuppressWarnings ( "unchecked" ) public < R > R get ( final String name ) { Object o = context . get ( name ) ; if ( o instanceof Map ) { return ( R ) new JsonObject ( ( Map ) o ) ; } if ( o instanceof List ) { return ( R ) new JsonArray ( ( List ) o ) ; } return ( R ) o ; }
Allow getting properties in a generified way .
3,738
public < R > R get ( final String name , R defaultValue ) { if ( context . containsKey ( name ) ) { return get ( name ) ; } else { return defaultValue ; } }
Allow getting properties in a generified way and return defaultValue if the key does not exist .
3,739
@ SuppressWarnings ( "unchecked" ) public < R > R put ( final String name , R value ) { if ( value == null ) { return ( R ) context . remove ( name ) ; } return ( R ) context . put ( name , value ) ; }
Allows putting a value into the context
3,740
public YokeCookie getCookie ( final String name ) { if ( cookies != null ) { for ( YokeCookie c : cookies ) { if ( name . equals ( c . name ( ) ) ) { return c ; } } } return null ; }
Allow getting Cookie by name .
3,741
public List < YokeCookie > getAllCookies ( final String name ) { List < YokeCookie > foundCookies = new ArrayList < > ( ) ; if ( cookies != null ) { for ( YokeCookie c : cookies ) { if ( name . equals ( c . name ( ) ) ) { foundCookies . add ( c ) ; } } } return foundCookies ; }
Allow getting all Cookie by name .
3,742
public long contentLength ( ) { String contentLengthHeader = headers ( ) . get ( "content-length" ) ; if ( contentLengthHeader != null ) { return Long . parseLong ( contentLengthHeader ) ; } else { return - 1 ; } }
Returns the content length of this request setBody or - 1 if header is not present .
3,743
@ SuppressWarnings ( "unchecked" ) public < V > V body ( ) { if ( body != null ) { if ( body instanceof Map ) { return ( V ) new JsonObject ( ( Map ) body ) ; } if ( body instanceof List ) { return ( V ) new JsonArray ( ( List ) body ) ; } } return ( V ) body ; }
The request body and eventually a parsed version of it in json or map
3,744
public YokeFileUpload getFile ( final String name ) { if ( files == null ) { return null ; } return files . get ( name ) ; }
Get an uploaded file
3,745
public void destroySession ( ) { JsonObject session = get ( "session" ) ; if ( session == null ) { return ; } String sessionId = session . getString ( "id" ) ; put ( "session" , null ) ; if ( sessionId == null ) { return ; } store . destroy ( sessionId , new Handler < Object > ( ) { public void handle ( Object error ) { if ( error != null ) { System . err . println ( error ) ; } } } ) ; }
Destroys a session from the request context and also from the storage engine .
3,746
public void loadSession ( final String sessionId , final Handler < Object > handler ) { if ( sessionId == null ) { handler . handle ( null ) ; return ; } store . get ( sessionId , new Handler < JsonObject > ( ) { public void handle ( JsonObject session ) { if ( session != null ) { put ( "session" , session ) ; } response ( ) . headersHandler ( new Handler < Void > ( ) { public void handle ( Void event ) { int responseStatus = response ( ) . getStatusCode ( ) ; if ( responseStatus >= 200 && responseStatus < 400 ) { JsonObject session = get ( "session" ) ; if ( session != null ) { store . set ( sessionId , session , new Handler < Object > ( ) { public void handle ( Object error ) { if ( error != null ) { System . err . println ( error ) ; } } } ) ; } } } } ) ; handler . handle ( null ) ; } } ) ; }
Loads a session given its session id and sets the session property in the request context .
3,747
public JsonObject createSession ( final String sessionId ) { final JsonObject session = new JsonObject ( ) . put ( "id" , sessionId ) ; put ( "session" , session ) ; response ( ) . headersHandler ( new Handler < Void > ( ) { public void handle ( Void event ) { int responseStatus = response ( ) . getStatusCode ( ) ; if ( responseStatus >= 200 && responseStatus < 400 ) { JsonObject session = get ( "session" ) ; if ( session != null ) { store . set ( sessionId , session , new Handler < Object > ( ) { public void handle ( Object error ) { if ( error != null ) { System . err . println ( error ) ; } } } ) ; } } } } ) ; return session ; }
Create a new Session with custom Id and store it with the underlying storage . Internally create a entry in the request context under the name session and add a end handler to save that object once the execution is terminated . Custom session id could be used with external auth provider like mod - auth - mgr .
3,748
public List < String > sortedHeader ( final String header ) { String accept = getHeader ( header ) ; if ( accept == null ) { return Collections . emptyList ( ) ; } String [ ] items = accept . split ( " *, *" ) ; Arrays . sort ( items , ACCEPT_X_COMPARATOR ) ; List < String > list = new ArrayList < > ( items . length ) ; for ( String item : items ) { int space = item . indexOf ( ';' ) ; if ( space != - 1 ) { list . add ( item . substring ( 0 , space ) ) ; } else { list . add ( item ) ; } } return list ; }
Returns the array of accept - ? ordered by quality .
3,749
public String getParam ( final String name , String defaultValue ) { String value = getParam ( name ) ; if ( value == null ) { return defaultValue ; } return value ; }
Allow getting parameters in a generified way and return defaultValue if the key does not exist .
3,750
public String getFormAttribute ( final String name , String defaultValue ) { String value = request . formAttributes ( ) . get ( name ) ; if ( value == null ) { return defaultValue ; } return value ; }
Allow getting form parameters in a generified way and return defaultValue if the key does not exist .
3,751
public List < String > getFormParameterList ( final String name ) { return request . formAttributes ( ) . getAll ( name ) ; }
Allow getting form parameters in a generified way .
3,752
public Locale locale ( ) { String languages = getHeader ( "Accept-Language" ) ; if ( languages != null ) { String [ ] acceptLanguages = languages . split ( " *, *" ) ; Arrays . sort ( acceptLanguages , ACCEPT_X_COMPARATOR ) ; String bestLanguage = acceptLanguages [ 0 ] ; int idx = bestLanguage . indexOf ( ';' ) ; if ( idx != - 1 ) { bestLanguage = bestLanguage . substring ( 0 , idx ) . trim ( ) ; } String [ ] parts = bestLanguage . split ( "_|-" ) ; switch ( parts . length ) { case 3 : return new Locale ( parts [ 0 ] , parts [ 1 ] , parts [ 2 ] ) ; case 2 : return new Locale ( parts [ 0 ] , parts [ 1 ] ) ; case 1 : return new Locale ( parts [ 0 ] ) ; } } return Locale . getDefault ( ) ; }
Read the default locale for this request
3,753
public static < M extends Model > FXMLComponentBase loadFXML ( final M model , final String fxmlPath ) { return loadFXML ( model , fxmlPath , null ) ; }
Load a FXML component without resource bundle .
3,754
@ SuppressWarnings ( "unchecked" ) public static < M extends Model > FXMLComponentBase loadFXML ( final M model , final String fxmlPath , final String bundlePath ) { final FXMLLoader fxmlLoader = new FXMLLoader ( ) ; final Callback < Class < ? > , Object > fxmlControllerFactory = ( Callback < Class < ? > , Object > ) ParameterUtility . buildCustomizableClass ( ExtensionParameters . FXML_CONTROLLER_FACTORY , DefaultFXMLControllerFactory . class , FXMLControllerFactory . class ) ; if ( fxmlControllerFactory instanceof FXMLControllerFactory ) { ( ( FXMLControllerFactory ) fxmlControllerFactory ) . relatedModel ( model ) ; } fxmlLoader . setControllerFactory ( fxmlControllerFactory ) ; fxmlLoader . setLocation ( convertFxmlUrl ( model , fxmlPath ) ) ; try { if ( bundlePath != null ) { fxmlLoader . setResources ( ResourceBundle . getBundle ( bundlePath ) ) ; } } catch ( final MissingResourceException e ) { LOGGER . log ( MISSING_RESOURCE_BUNDLE , e , bundlePath ) ; } Node node = null ; boolean error = false ; try { error = fxmlLoader . getLocation ( ) == null ; if ( error ) { node = TextBuilder . create ( ) . text ( FXML_ERROR_NODE_LABEL . getText ( fxmlPath ) ) . build ( ) ; } else { node = ( Node ) fxmlLoader . load ( fxmlLoader . getLocation ( ) . openStream ( ) ) ; } } catch ( final IOException e ) { throw new CoreRuntimeException ( FXML_NODE_DOESNT_EXIST . getText ( fxmlPath ) , e ) ; } final FXMLController < M , ? > fxmlController = ( FXMLController < M , ? > ) fxmlLoader . getController ( ) ; if ( fxmlController != null ) { if ( ! error && ! ( fxmlLoader . getController ( ) instanceof AbstractFXMLController ) ) { throw new CoreRuntimeException ( BAD_FXML_CONTROLLER_ANCESTOR . getText ( fxmlLoader . getController ( ) . getClass ( ) . getCanonicalName ( ) ) ) ; } fxmlController . model ( model ) ; } return new FXMLComponentBase ( node , fxmlController ) ; }
Load a FXML component .
3,755
private static < M extends Model > URL convertFxmlUrl ( final M model , final String fxmlPath ) { URL fxmlUrl = null ; if ( model != null ) { fxmlUrl = model . getClass ( ) . getResource ( fxmlPath ) ; } if ( fxmlUrl == null ) { fxmlUrl = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( fxmlPath ) ; } return fxmlUrl ; }
Convert The url of fxml files to allow local and path loading .
3,756
public void waitEnd ( final long ... timeout ) { long start = System . currentTimeMillis ( ) ; if ( timeout . length == 1 ) { start += timeout [ 0 ] ; } else { start += DEFAULT_TIME_OUT ; } while ( ! this . hasRun . get ( ) ) { try { Thread . sleep ( SLEEP_TIME ) ; } catch ( final InterruptedException e ) { break ; } if ( System . currentTimeMillis ( ) > start ) { break ; } } }
Wait the end of the runnable .
3,757
private String getMessage ( Object error ) { if ( error instanceof Throwable ) { String message = ( ( Throwable ) error ) . getMessage ( ) ; if ( message == null ) { if ( fullStack ) { message = error . getClass ( ) . getName ( ) ; } } return message ; } else if ( error instanceof String ) { return ( String ) error ; } else if ( error instanceof Integer ) { return HttpResponseStatus . valueOf ( ( Integer ) error ) . reasonPhrase ( ) ; } else if ( error instanceof JsonObject ) { return ( ( JsonObject ) error ) . getString ( "message" ) ; } else if ( error instanceof Map ) { return ( String ) ( ( Map ) error ) . get ( "message" ) ; } else { return error . toString ( ) ; } }
Extracts a single message from a error Object . This will handle Throwables Strings and Numbers . In case of numbers these are handled as Http error codes .
3,758
private int getErrorCode ( Object error ) { if ( error instanceof Number ) { return ( ( Number ) error ) . intValue ( ) ; } else if ( error instanceof YokeException ) { return ( ( YokeException ) error ) . getErrorCode ( ) . intValue ( ) ; } else if ( error instanceof JsonObject ) { return ( ( JsonObject ) error ) . getInteger ( "errorCode" , 500 ) ; } else if ( error instanceof Map ) { Integer tmp = ( Integer ) ( ( Map ) error ) . get ( "errorCode" ) ; return tmp != null ? tmp : 500 ; } else { return 500 ; } }
Extracts a single error code from a error Object . This will handle Throwables Strings and Numbers .
3,759
private List < String > getStackTrace ( Object error ) { if ( fullStack && error instanceof Throwable ) { List < String > stackTrace = new ArrayList < > ( ) ; for ( StackTraceElement t : ( ( Throwable ) error ) . getStackTrace ( ) ) { stackTrace . add ( t . toString ( ) ) ; } return stackTrace ; } else { return Collections . emptyList ( ) ; } }
Convert the stack trace to a List in order to be rendered in the error template .
3,760
void onMouseClicked ( final MouseEvent event ) { LOGGER . debug ( "Start button clicked => Call Comparison Service" ) ; model ( ) . object ( ) . pLastResult ( ) . clear ( ) ; model ( ) . returnData ( ComparatorService . class , ComparatorService . DO_COMPARE , WBuilder . waveData ( JRebirthWaves . PROGRESS_BAR , view ( ) . getProgressBar ( ) ) , WBuilder . waveData ( JRebirthWaves . TASK_TITLE , view ( ) . getProgressTitle ( ) ) , WBuilder . waveData ( JRebirthWaves . TASK_MESSAGE , view ( ) . getProgressMessage ( ) ) , WBuilder . waveData ( ComparatorService . SOURCE , model ( ) . object ( ) . sourcePath ( ) ) , WBuilder . waveData ( ComparatorService . TARGET , model ( ) . object ( ) . targetPath ( ) ) ) ; }
Manage Mouse click of widget that have annotation .
3,761
private int convertLevel ( final JRLevel level ) { int logbackLevel = 0 ; switch ( level ) { case Trace : logbackLevel = LocationAwareLogger . TRACE_INT ; break ; case Debug : logbackLevel = LocationAwareLogger . DEBUG_INT ; break ; case Warn : logbackLevel = LocationAwareLogger . WARN_INT ; break ; case Error : logbackLevel = LocationAwareLogger . ERROR_INT ; break ; case Info : logbackLevel = LocationAwareLogger . INFO_INT ; break ; default : break ; } return logbackLevel ; }
Convert JRebirth LogLevel to Logback one .
3,762
public String getServiceHandlerName ( ) { final StringBuilder sb = new StringBuilder ( ) ; sb . append ( this . service . getClass ( ) . getSimpleName ( ) ) . append ( "." ) ; sb . append ( this . method . getName ( ) ) . append ( "(" ) ; for ( final Class < ? > parameterType : this . method . getParameterTypes ( ) ) { sb . append ( parameterType . getSimpleName ( ) ) . append ( ", " ) ; } sb . append ( ")" ) ; return sb . toString ( ) ; }
Return the full service handler name .
3,763
private void handleException ( final Throwable e ) { if ( e instanceof ServiceException ) { final ServiceException se = ( ServiceException ) e ; LOGGER . log ( SERVICE_TASK_EXCEPTION , se , se . getExplanation ( ) , getServiceHandlerName ( ) ) ; } else { LOGGER . log ( SERVICE_TASK_ERROR , e , getServiceHandlerName ( ) ) ; } this . wave . status ( Status . Failed ) ; final Class < ? extends Throwable > managedException = e instanceof ServiceException ? e . getCause ( ) . getClass ( ) : e . getClass ( ) ; final Wave exceptionHandlerWave = this . wave . waveType ( ) . waveExceptionHandler ( ) . get ( managedException ) ; if ( exceptionHandlerWave != null ) { exceptionHandlerWave . fromClass ( this . service . getClass ( ) ) . add ( JRebirthItems . exceptionItem , e ) . add ( JRebirthItems . waveItem , this . wave ) . relatedWave ( this . wave ) ; LOGGER . log ( SERVICE_TASK_HANDLE_EXCEPTION , e , e . getClass ( ) . getSimpleName ( ) , getServiceHandlerName ( ) ) ; this . service . sendWave ( exceptionHandlerWave ) ; } else { LOGGER . log ( SERVICE_TASK_NOT_MANAGED_EXCEPTION , e , e . getClass ( ) . getSimpleName ( ) , getServiceHandlerName ( ) ) ; } }
Handle all exception occurred while doing the task .
3,764
@ SuppressWarnings ( "unchecked" ) private void sendReturnWave ( final T res ) throws CoreException { Wave returnWave = null ; final WaveType responseWaveType = this . wave . waveType ( ) . returnWaveType ( ) ; final Class < ? extends Command > responseCommandClass = this . wave . waveType ( ) . returnCommandClass ( ) ; if ( responseWaveType != null ) { final WaveItemBase < T > resultWaveItem ; if ( responseWaveType != JRebirthWaves . RETURN_VOID_WT && responseWaveType . items ( ) . isEmpty ( ) ) { LOGGER . log ( NO_RETURNED_WAVE_ITEM ) ; throw new CoreException ( NO_RETURNED_WAVE_ITEM ) ; } else { resultWaveItem = ( WaveItemBase < T > ) responseWaveType . items ( ) . get ( 0 ) ; } if ( responseCommandClass != null ) { returnWave = WBuilder . wave ( ) . waveGroup ( WaveGroup . CALL_COMMAND ) . fromClass ( this . service . getClass ( ) ) . componentClass ( responseCommandClass ) ; } else { returnWave = WBuilder . wave ( ) . waveType ( responseWaveType ) . fromClass ( this . service . getClass ( ) ) ; } if ( resultWaveItem != null ) { returnWave . addDatas ( WBuilder . waveData ( resultWaveItem , res ) ) ; } returnWave . relatedWave ( this . wave ) ; returnWave . addWaveListener ( new RelatedWaveListener ( ) ) ; this . service . sendWave ( returnWave ) ; } else { LOGGER . log ( NO_RETURNED_WAVE_TYPE_DEFINED , this . wave . waveType ( ) ) ; throw new CoreException ( NO_RETURNED_WAVE_ITEM , this . wave . waveType ( ) ) ; } }
Send a wave that will carry the service result .
3,765
public boolean checkProgressRatio ( final double newWorkDone , final double totalWork , final double amountThreshold ) { double currentRatio ; synchronized ( this ) { currentRatio = this . localWorkDone >= 0 ? 100 * this . localWorkDone / totalWork : 0.0 ; } final double newRatio = 100 * newWorkDone / totalWork ; return newRatio - currentRatio > amountThreshold ; }
Check if the task has enough progressed according to the given threshold .
3,766
@ SuppressWarnings ( "unchecked" ) public < R > R getHeader ( String name ) { return ( R ) headers ( ) . get ( name ) ; }
Allow getting headers in a generified way .
3,767
public void initFilter ( FunDapterFilter < T > filter ) { if ( filter == null ) throw new IllegalArgumentException ( "Cannot pass a null filter to FunDapter" ) ; this . funDapterFilter = filter ; mFilter = new Filter ( ) { protected void publishResults ( CharSequence constraint , FilterResults results ) { @ SuppressWarnings ( "unchecked" ) List < T > list = ( List < T > ) results . values ; if ( results . count == 0 ) { resetData ( ) ; } else { mDataItems = list ; } notifyDataSetChanged ( ) ; } protected FilterResults performFiltering ( CharSequence constraint ) { FilterResults results = new FilterResults ( ) ; if ( constraint == null || constraint . length ( ) == 0 ) { results . values = mOrigDataItems ; results . count = mOrigDataItems . size ( ) ; } else { List < T > filter = funDapterFilter . filter ( constraint . toString ( ) , mOrigDataItems ) ; results . count = filter . size ( ) ; results . values = filter ; } return results ; } } ; }
Use this method to enable filtering in the adapter .
3,768
public void doInsertTab ( int idx , final Dockable tab , final Wave wave ) { if ( idx < 0 ) { idx = object ( ) . tabs ( ) . isEmpty ( ) ? 0 : object ( ) . tabs ( ) . size ( ) ; } object ( ) . tabs ( ) . add ( idx , tab ) ; }
Insert tab .
3,769
private String getMessageFromCode ( final int messageCode ) { String res = "" ; switch ( messageCode ) { case 100 : res = "Initializing" ; break ; case 200 : res = "" ; break ; case 300 : res = "" ; break ; case 400 : res = "Loading Messages Properties" ; break ; case 500 : res = "Loading Parameters Properties" ; break ; case 600 : res = "Preparing Core Engine" ; break ; case 700 : res = "Preloading Resources" ; break ; case 800 : res = "Preloading Modules" ; break ; case 900 : res = "" ; break ; case 1000 : res = "Starting" ; break ; default : } return res ; }
Gets the message from code .
3,770
protected void throwError ( final MessageItem messageItem , final Throwable t , final Object ... parameters ) { if ( messageItem . getLevel ( ) == JRLevel . Exception || messageItem . getLevel ( ) == JRLevel . Error && CoreParameters . DEVELOPER_MODE . get ( ) ) { throw new CoreRuntimeException ( messageItem , t , parameters ) ; } }
If an error is logged when running in Developer Mode Throw a Runtime Exception .
3,771
final void innerRun ( final Wave wave ) throws CommandException { beforePerform ( wave ) ; perform ( wave ) ; afterPerform ( wave ) ; }
Run the inner task .
3,772
protected void fireConsumed ( final Wave wave ) { LOGGER . trace ( this . getClass ( ) . getSimpleName ( ) + " consumes " + wave . toString ( ) ) ; wave . status ( Wave . Status . Consumed ) ; }
Fire a consumed event for command listeners .
3,773
protected void fireHandled ( final Wave wave ) { LOGGER . trace ( this . getClass ( ) . getSimpleName ( ) + " handles " + wave . toString ( ) ) ; wave . status ( Wave . Status . Handled ) ; }
Fire an handled event for command listeners .
3,774
protected void fireFailed ( final Wave wave ) { LOGGER . trace ( this . getClass ( ) . getSimpleName ( ) + " has failed " + wave . toString ( ) ) ; wave . status ( Wave . Status . Failed ) ; }
Fire a failed event for command listeners .
3,775
private void writeHeaders ( final YokeRequest request , final FileProps props ) { MultiMap headers = request . response ( ) . headers ( ) ; if ( ! headers . contains ( "etag" ) ) { headers . set ( "etag" , "\"" + props . size ( ) + "-" + props . lastModifiedTime ( ) + "\"" ) ; } if ( ! headers . contains ( "date" ) ) { headers . set ( "date" , format ( new Date ( ) ) ) ; } if ( ! headers . contains ( "cache-control" ) ) { headers . set ( "cache-control" , "public, max-age=" + maxAge / 1000 ) ; } if ( ! headers . contains ( "last-modified" ) ) { headers . set ( "last-modified" , format ( new Date ( props . lastModifiedTime ( ) ) ) ) ; } }
Create all required header so content can be cache by Caching servers or Browsers
3,776
private void sendFile ( final YokeRequest request , final String file , final FileProps props ) { String contentType = MimeType . getMime ( file ) ; String charset = MimeType . getCharset ( contentType ) ; request . response ( ) . setContentType ( contentType , charset ) ; request . response ( ) . putHeader ( "Content-Length" , Long . toString ( props . size ( ) ) ) ; if ( HttpMethod . HEAD . equals ( request . method ( ) ) ) { request . response ( ) . end ( ) ; } else { request . response ( ) . sendFile ( file ) ; } }
Write a file into the response body
3,777
private boolean isFresh ( final YokeRequest request ) { boolean etagMatches = true ; boolean notModified = true ; String modifiedSince = request . getHeader ( "if-modified-since" ) ; String noneMatch = request . getHeader ( "if-none-match" ) ; String [ ] noneMatchTokens = null ; String lastModified = request . response ( ) . getHeader ( "last-modified" ) ; String etag = request . response ( ) . getHeader ( "etag" ) ; if ( modifiedSince == null && noneMatch == null ) { return false ; } if ( noneMatch != null ) { noneMatchTokens = noneMatch . split ( " *, *" ) ; } if ( noneMatchTokens != null ) { etagMatches = false ; for ( String s : noneMatchTokens ) { if ( etag . equals ( s ) || "*" . equals ( noneMatchTokens [ 0 ] ) ) { etagMatches = true ; break ; } } } if ( modifiedSince != null ) { try { Date modifiedSinceDate = parse ( modifiedSince ) ; Date lastModifiedDate = parse ( lastModified ) ; notModified = lastModifiedDate . getTime ( ) <= modifiedSinceDate . getTime ( ) ; } catch ( ParseException e ) { notModified = false ; } } return etagMatches && notModified ; }
Verify if a resource is fresh fresh means that its cache headers are validated against the local resource and etags last - modified headers are still the same .
3,778
@ SuppressWarnings ( "unchecked" ) private < E extends R > List < E > getReadyObjectList ( final UniqueKey < E > uniqueKey ) { List < E > readyObjectList = null ; synchronized ( this . componentMap ) { if ( exists ( uniqueKey ) ) { readyObjectList = new ArrayList < > ( ( Set < E > ) this . componentMap . get ( uniqueKey ) ) ; } } return readyObjectList ; }
Check the presence of the Object and return it if possible otherwise return null .
3,779
@ SuppressWarnings ( "unchecked" ) protected < E extends R > List < E > buildComponentList ( final UniqueKey < E > uniqueKey ) throws CoreException { final List < E > readyObjectList = globalFacade ( ) . componentFactory ( ) . buildComponents ( uniqueKey . classField ( ) ) ; for ( final E readyObject : readyObjectList ) { JRebirthEventType type = JRebirthEventType . NONE ; if ( readyObject instanceof Model ) { type = JRebirthEventType . CREATE_MODEL ; } else if ( readyObject instanceof Service ) { type = JRebirthEventType . CREATE_SERVICE ; } else if ( readyObject instanceof Command ) { type = JRebirthEventType . CREATE_COMMAND ; } globalFacade ( ) . trackEvent ( type , this . getClass ( ) , readyObject . getClass ( ) ) ; readyObject . localFacade ( this ) ; UniqueKey < E > readyKey = null ; if ( uniqueKey instanceof MultitonKey ) { final Object keyPart = ( ( MultitonKey < ? > ) uniqueKey ) . value ( ) ; readyKey = ( UniqueKey < E > ) Key . createMulti ( readyObject . getClass ( ) , keyPart instanceof List ? ( ( List < ? > ) keyPart ) . toArray ( ) : new Object [ ] { keyPart } , uniqueKey . optionalData ( ) . toArray ( ) ) ; } else if ( uniqueKey instanceof ClassKey ) { readyKey = ( UniqueKey < E > ) Key . createSingle ( readyObject . getClass ( ) , uniqueKey . optionalData ( ) . toArray ( ) ) ; } readyKey . registrationKey ( uniqueKey ) ; readyObject . key ( ( UniqueKey < R > ) readyKey ) ; } return readyObjectList ; }
Build a new instance of the ready object class .
3,780
private boolean checkPriority ( final PriorityLevel taskPriority ) { boolean highPriority = false ; synchronized ( this . pending ) { for ( final JRebirthRunnable jr : this . pending ) { highPriority |= taskPriority . level ( ) > jr . priority ( ) . level ( ) ; } } return ! highPriority ; }
Check given priority with current pending list .
3,781
protected < T > void listenObject ( ObjectProperty < T > objectProperty , Consumer < T > consumeOld , Consumer < T > consumeNew ) { objectProperty . addListener ( ( final ObservableValue < ? extends T > ov , final T old_val , final T new_val ) -> { if ( old_val != null && consumeOld != null ) { consumeOld . accept ( old_val ) ; } if ( new_val != null && consumeNew != null ) { consumeNew . accept ( new_val ) ; } } ) ; }
Listen object change .
3,782
@ SuppressWarnings ( "unchecked" ) protected V buildView ( ) throws CoreException { return ( V ) ClassUtility . findAndBuildGenericType ( this . getClass ( ) , View . class , NullView . class , this ) ; }
Create the view it was null .
3,783
public void setStyle ( final JRebirthEventType eventType ) { switch ( eventType ) { case CREATE_APPLICATION : this . circle . setFill ( BallColors . APPLICATION . get ( ) ) ; this . label . setText ( "App" ) ; break ; case CREATE_NOTIFIER : this . circle . setFill ( BallColors . NOTIFIER . get ( ) ) ; this . label . setText ( "N" ) ; break ; case CREATE_GLOBAL_FACADE : this . circle . setFill ( BallColors . GLOBAL_FACADE . get ( ) ) ; this . label . setText ( "GF" ) ; break ; case CREATE_UI_FACADE : this . circle . setFill ( BallColors . UI_FACADE . get ( ) ) ; this . label . setText ( "UF" ) ; break ; case CREATE_SERVICE_FACADE : this . circle . setFill ( BallColors . SERVICE_FACADE . get ( ) ) ; this . label . setText ( "SF" ) ; break ; case CREATE_COMMAND_FACADE : this . circle . setFill ( BallColors . COMMAND_FACADE . get ( ) ) ; this . label . setText ( "CF" ) ; break ; case CREATE_SERVICE : this . circle . setFill ( BallColors . SERVICE . get ( ) ) ; this . label . setText ( "S" ) ; break ; case CREATE_MODEL : this . circle . setFill ( BallColors . MODEL . get ( ) ) ; this . label . setText ( "M" ) ; break ; case CREATE_COMMAND : this . circle . setFill ( BallColors . COMMAND . get ( ) ) ; this . label . setText ( "C" ) ; break ; case CREATE_VIEW : this . circle . setFill ( BallColors . VIEW . get ( ) ) ; this . label . setText ( "V" ) ; break ; default : } }
Define the ball style .
3,784
public void resetScale ( ) { ScaleTransitionBuilder . create ( ) . duration ( Duration . millis ( 400 ) ) . node ( node ( ) ) . toX ( 1f ) . toY ( 1f ) . cycleCount ( 1 ) . autoReverse ( false ) . build ( ) . play ( ) ; }
To complete .
3,785
private double getX ( ) { double res ; switch ( model ( ) . getEventModel ( ) . eventType ( ) ) { case CREATE_APPLICATION : case CREATE_COMMAND : case CREATE_COMMAND_FACADE : res = 0 ; break ; case CREATE_GLOBAL_FACADE : case CREATE_NOTIFIER : res = 70 ; break ; case CREATE_SERVICE_FACADE : case CREATE_SERVICE : res = - 200 * Math . cos ( Math . PI / 6 ) ; break ; case CREATE_UI_FACADE : case CREATE_MODEL : res = 200 * Math . cos ( Math . PI / 6 ) ; break ; default : res = 50 ; } return res ; }
Return the x coordinate .
3,786
private double getY ( ) { double res ; switch ( model ( ) . getEventModel ( ) . eventType ( ) ) { case CREATE_COMMAND_FACADE : case CREATE_COMMAND : res = - 200 * Math . sin ( Math . PI / 2 ) ; break ; case CREATE_GLOBAL_FACADE : case CREATE_APPLICATION : case CREATE_NOTIFIER : res = 0 ; break ; case CREATE_SERVICE_FACADE : case CREATE_UI_FACADE : case CREATE_MODEL : case CREATE_SERVICE : res = + 200 * Math . sin ( Math . PI / 6 ) ; break ; default : res = 50 ; } return res ; }
Return the y coordinate .
3,787
public String getItems ( ) { final StringBuilder sb = new StringBuilder ( ) ; boolean first = true ; for ( final WaveItem < ? > waveItem : items ( ) ) { if ( first ) { first = false ; } else { sb . append ( ", " ) ; } String fullName = waveItem . type ( ) instanceof ParameterizedType ? ( ( ParameterizedType ) waveItem . type ( ) ) . toString ( ) : ( ( Class < ? > ) waveItem . type ( ) ) . getName ( ) ; sb . append ( fullName ) . append ( " " ) ; fullName = fullName . replaceAll ( "[<>]" , "" ) ; if ( waveItem . name ( ) == null || waveItem . name ( ) . isEmpty ( ) ) { sb . append ( ObjectUtility . lowerFirstChar ( fullName . substring ( fullName . lastIndexOf ( '.' ) + 1 ) ) ) ; } else { sb . append ( waveItem . name ( ) ) ; } } return sb . toString ( ) ; }
Return the required method parameter list to handle this WaveType .
3,788
private < E extends Event > EventHandler < E > wrapbuildHandler ( final EventAdapter eventAdapter , final Class < ? extends EventAdapter > adapterClass , final Class < ? extends EventHandler < E > > handlerClass ) throws CoreException { try { return handlerClass . getDeclaredConstructor ( adapterClass ) . newInstance ( eventAdapter ) ; } catch ( InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e ) { throw new CoreException ( "Impossible to build event handler " + handlerClass . getName ( ) + " for the class " + this . getClass ( ) . getName ( ) , e ) ; } }
Build an event handler by reflection to wrap the event adapter given .
3,789
private < E extends Event > EventHandler < E > buildEventHandler ( final Class < ? extends EventAdapter > adapterClass , final Class < ? extends EventHandler < E > > handlerClass ) throws CoreException { EventHandler < E > eventHandler = null ; if ( adapterClass . isAssignableFrom ( this . getClass ( ) ) ) { eventHandler = wrapbuildHandler ( this , adapterClass , handlerClass ) ; } else { throw new CoreException ( this . getClass ( ) . getName ( ) + " must implement " + adapterClass . getName ( ) + " interface" ) ; } return eventHandler ; }
Build an event handler by reflection using the Controller object as eventAdapter .
3,790
private boolean isEventType ( final EventType < ? extends Event > testEventType , final EventType < ? extends Event > anyEventType ) { return testEventType . equals ( anyEventType ) || testEventType . getSuperType ( ) . equals ( anyEventType ) ; }
Check the event type given and check the super level if necessary to always return the ANy event type .
3,791
private boolean waveBeanContains ( WaveItem < ? > waveItem ) { return waveBeanList ( ) . stream ( ) . flatMap ( wb -> Stream . of ( wb . getClass ( ) . getDeclaredFields ( ) ) ) . map ( f -> f . getName ( ) ) . anyMatch ( n -> waveItem . name ( ) . equals ( n ) ) ; }
Check if this item is contained into on Wave bean .
3,792
private Object waveBeanGet ( WaveItem < ? > waveItem ) { for ( final WaveBean wb : waveBeanList ( ) ) { final Object o = Stream . of ( wb . getClass ( ) . getDeclaredFields ( ) ) . filter ( f -> waveItem . name ( ) . equals ( f . getName ( ) ) ) . map ( f -> ClassUtility . getFieldValue ( f , wb ) ) . findFirst ( ) . get ( ) ; if ( o != null ) { return o ; } } return null ; }
Retrieve the field value from wave bean
3,793
private Map < Class < ? extends WaveBean > , WaveBean > getWaveBeanMap ( ) { if ( this . waveBeanMap == null ) { this . waveBeanMap = new HashMap < > ( ) ; } return this . waveBeanMap ; }
Get the Wave Bean map . Create it if it hasn t been done before .
3,794
private void fireStatusChanged ( ) { for ( final WaveListener waveListener : this . waveListeners ) { switch ( this . statusProperty . get ( ) ) { case Created : waveListener . waveCreated ( this ) ; break ; case Sent : waveListener . waveSent ( this ) ; break ; case Processing : waveListener . waveProcessed ( this ) ; break ; case Consumed : waveListener . waveConsumed ( this ) ; break ; case Handled : waveListener . waveHandled ( this ) ; break ; case Failed : waveListener . waveFailed ( this ) ; break ; case Cancelled : waveListener . waveCancelled ( this ) ; break ; case Destroyed : waveListener . waveDestroyed ( this ) ; break ; default : break ; } } }
Fire a wave status change .
3,795
private Method retrieveCustomMethod ( final Wave wave ) { Method customMethod = null ; customMethod = this . defaultMethod == null ? ClassUtility . retrieveMethodList ( getWaveReady ( ) . getClass ( ) , wave . waveType ( ) . toString ( ) ) . stream ( ) . filter ( m -> CheckerUtility . checkMethodSignature ( m , wave . waveType ( ) . items ( ) ) ) . findFirst ( ) . orElse ( null ) : this . defaultMethod ; if ( customMethod == null ) { LOGGER . info ( CUSTOM_METHOD_NOT_FOUND ) ; } return customMethod ; }
Retrieve the custom wave handler method .
3,796
private void performHandle ( final Wave wave , final Method method ) throws WaveException { final List < Object > parameterValues = new ArrayList < > ( ) ; if ( ! AbstractComponent . PROCESS_WAVE_METHOD_NAME . equals ( method . getName ( ) ) ) { for ( final WaveData < ? > wd : wave . waveDatas ( ) ) { if ( wd . key ( ) . isParameter ( ) ) { parameterValues . add ( wd . value ( ) ) ; } } } parameterValues . add ( wave ) ; try { ClassUtility . callMethod ( method , getWaveReady ( ) , parameterValues . toArray ( ) ) ; } catch ( final CoreException e ) { LOGGER . error ( WAVE_DISPATCH_ERROR , e ) ; throw new WaveException ( wave , e ) ; } }
Perform the handle independently of thread used .
3,797
public static WaveType getWaveType ( final String action ) { WaveType waveType = null ; if ( waveTypeMap . containsKey ( action ) ) { waveType = waveTypeMap . get ( action ) ; } return waveType ; }
Retrieve a WaveType according to its unique action name .
3,798
private Image buildWebImage ( final WebImage jrImage ) { final String url = jrImage . getUrl ( ) ; Image image = null ; if ( url == null || url . isEmpty ( ) ) { LOGGER . error ( "Image : {} not found !" , url ) ; } else { image = new Image ( url ) ; } return image ; }
Build a web image with its url parameters .
3,799
private Image loadImage ( final String resourceName , final boolean skipImagesFolder ) { Image image = null ; final List < String > imagePaths = skipImagesFolder ? Collections . singletonList ( "" ) : ResourceParameters . IMAGE_FOLDER . get ( ) ; for ( int i = 0 ; i < imagePaths . size ( ) && image == null ; i ++ ) { String imagePath = imagePaths . get ( i ) ; if ( ! imagePath . isEmpty ( ) ) { imagePath += Resources . PATH_SEP ; } final InputStream imageInputStream = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( imagePath + resourceName ) ; if ( imageInputStream != null ) { image = new Image ( imageInputStream ) ; } } if ( image == null ) { LOGGER . error ( "Image : {} not found into base folder: {}" , resourceName , ResourceParameters . IMAGE_FOLDER . get ( ) ) ; } return image ; }
Load an image .