KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > orbutil > fsm > NameBase


1 /*
2  * @(#)NameBase.java 1.6 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.orbutil.fsm ;
9
10 import com.sun.corba.se.spi.orbutil.fsm.Action ;
11 import com.sun.corba.se.spi.orbutil.fsm.State ;
12 import com.sun.corba.se.spi.orbutil.fsm.Guard ;
13 import com.sun.corba.se.spi.orbutil.fsm.Input ;
14
15 import java.util.StringTokenizer JavaDoc ;
16
17 public class NameBase {
18     private String JavaDoc name ;
19     private String JavaDoc toStringName ;
20
21     // Return just the name of the class, not the full qualified name.
22
private String JavaDoc getClassName()
23     {
24     String JavaDoc fqn = this.getClass().getName() ;
25     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( fqn, "." ) ;
26     String JavaDoc token = st.nextToken() ;
27     while (st.hasMoreTokens())
28         token = st.nextToken() ;
29     return token ;
30     }
31
32     private String JavaDoc getPreferredClassName()
33     {
34     if (this instanceof Action)
35         return "Action" ;
36     if (this instanceof State)
37         return "State" ;
38     if (this instanceof Guard)
39         return "Guard" ;
40     if (this instanceof Input)
41         return "Input" ;
42     return getClassName() ;
43     }
44
45     public NameBase( String JavaDoc name )
46     {
47     this.name = name ;
48     toStringName = getPreferredClassName() + "[" + name + "]" ;
49     }
50
51     public String JavaDoc getName()
52     {
53     return name ;
54     }
55
56     public String JavaDoc toString() {
57     return toStringName ;
58     }
59 }
60
61
Popular Tags