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