litesoft
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
|
package org.litesoft.sandbox.infrastructure.client;
import org.litesoft.sandbox.anywhere.util.*;
import com.google.gwt.place.shared.*;
/**
* Code to support extracting a PlaceId from either a PlaceTokenizer or a Place.
* <p/>
* If the Place or PlaceTokenizer does NOT implement 'HasPlaceId', then class name magic is used
* (the Place classes name must end with 'Place', and the Tokenizer(s) MUST be a static inner class of it's Place).
*/
public class PlaceIdExtractor
{
public static String getPlaceId( PlaceTokenizer<? extends Place> pTokenizer )
{
return extractPlaceId( pTokenizer );
}
public static String getPlaceId( Place pPlace )
{
return extractPlaceId( pPlace );
}
private static String extractPlaceId( Object pObject )
{
if ( pObject instanceof HasPlaceId )
{
return UtilsCommon.noEmpty( ((HasPlaceId) pObject).getPlaceId() );
}
if ( pObject == null )
{
return null;
}
String s = "." + pObject.getClass().getName() + "$"; // find the String between the last '.' and the first '$'
s = s.substring( 0, s.indexOf( '$' ) );
s = s.substring( s.lastIndexOf( '.' ) );
return !s.endsWith( "Place" ) ? null : UtilsCommon.noEmpty( s.substring( 0, s.length() - 5 ) );
}
}
|
Revision |
Author |
Commited |
Message |
540
|
GeorgeS
|
Mon 03 Oct, 2011 04:22:28 +0000 |
|