Subversion Repository Public Repository

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 com.temp.client.foundation.pavment;

import com.temp.shared.utils.StringUtils;

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 StringUtils.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 : StringUtils.noEmpty( s.substring( 0, s.length() - 5 ) );
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/pavment/PlaceIdExtractor.java

Diff revisions: vs.
Revision Author Commited Message
626 GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000