|
@@ -1,35 +1,35 @@ |
1 |
|
- |
package org.litesoft.GWT.client.pavsupport.internal; |
2 |
|
- |
|
3 |
|
- |
import org.litesoft.GWT.client.pavsupport.*; |
4 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
5 |
|
- |
|
6 |
|
- |
import com.google.gwt.place.shared.*; |
7 |
|
- |
|
8 |
|
- |
/** |
9 |
|
- |
* Code to support extracting a PlaceId from either a PlaceTokenizer or a Place. |
10 |
|
- |
* <p/> |
11 |
|
- |
* If the Place or PlaceTokenizer does NOT implement 'HasPlaceId', then class name magic is used |
12 |
|
- |
* (the Place classes name must end with 'Place', and the Tokenizer(s) MUST be a static inner class of it's Place). |
13 |
|
- |
*/ |
14 |
|
- |
public class PlaceIdExtractor { |
15 |
|
- |
public static String getPlaceId( PlaceTokenizer<? extends Place> pTokenizer ) { |
16 |
|
- |
return extractPlaceId( pTokenizer ); |
17 |
|
- |
} |
18 |
|
- |
|
19 |
|
- |
public static String getPlaceId( Place pPlace ) { |
20 |
|
- |
return extractPlaceId( pPlace ); |
21 |
|
- |
} |
22 |
|
- |
|
23 |
|
- |
private static String extractPlaceId( Object pObject ) { |
24 |
|
- |
if ( pObject instanceof HasPlaceId ) { |
25 |
|
- |
return Strings.noEmpty( ((HasPlaceId) pObject).getPlaceId() ); |
26 |
|
- |
} |
27 |
|
- |
if ( pObject == null ) { |
28 |
|
- |
return null; |
29 |
|
- |
} |
30 |
|
- |
String s = "." + pObject.getClass().getName() + "$"; // find the String between the last '.' and the first '$' |
31 |
|
- |
s = s.substring( 0, s.indexOf( '$' ) ); |
32 |
|
- |
s = s.substring( s.lastIndexOf( '.' ) ); |
33 |
|
- |
return !s.endsWith( "Place" ) ? null : Strings.noEmpty( s.substring( 0, s.length() - 5 ) ); |
34 |
|
- |
} |
35 |
|
- |
} |
|
1 |
+ |
package org.litesoft.GWT.client.pavsupport.internal; |
|
2 |
+ |
|
|
3 |
+ |
import org.litesoft.GWT.client.pavsupport.*; |
|
4 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
5 |
+ |
|
|
6 |
+ |
import com.google.gwt.place.shared.*; |
|
7 |
+ |
|
|
8 |
+ |
/** |
|
9 |
+ |
* Code to support extracting a PlaceId from either a PlaceTokenizer or a Place. |
|
10 |
+ |
* <p/> |
|
11 |
+ |
* If the Place or PlaceTokenizer does NOT implement 'HasPlaceId', then class name magic is used |
|
12 |
+ |
* (the Place classes name must end with 'Place', and the Tokenizer(s) MUST be a static inner class of it's Place). |
|
13 |
+ |
*/ |
|
14 |
+ |
public class PlaceIdExtractor { |
|
15 |
+ |
public static String getPlaceId( PlaceTokenizer<? extends Place> pTokenizer ) { |
|
16 |
+ |
return extractPlaceId( pTokenizer ); |
|
17 |
+ |
} |
|
18 |
+ |
|
|
19 |
+ |
public static String getPlaceId( Place pPlace ) { |
|
20 |
+ |
return extractPlaceId( pPlace ); |
|
21 |
+ |
} |
|
22 |
+ |
|
|
23 |
+ |
private static String extractPlaceId( Object pObject ) { |
|
24 |
+ |
if ( pObject instanceof HasPlaceId ) { |
|
25 |
+ |
return ConstrainTo.significantOrNull( ((HasPlaceId) pObject).getPlaceId() ); |
|
26 |
+ |
} |
|
27 |
+ |
if ( pObject == null ) { |
|
28 |
+ |
return null; |
|
29 |
+ |
} |
|
30 |
+ |
String s = "." + pObject.getClass().getName() + "$"; // find the String between the last '.' and the first '$' |
|
31 |
+ |
s = s.substring( 0, s.indexOf( '$' ) ); |
|
32 |
+ |
s = s.substring( s.lastIndexOf( '.' ) ); |
|
33 |
+ |
return !s.endsWith( "Place" ) ? null : ConstrainTo.significantOrNull( s.substring( 0, s.length() - 5 ) ); |
|
34 |
+ |
} |
|
35 |
+ |
} |