Source for file Type.php

Documentation is available at Type.php

  1. <?php
  2.  
  3. require_once(HARMONI."Primitives/Objects/SObject.class.php");
  4. /**
  5. * The Type class captures the fundamental concept of categorizing an object.
  6. * Type are designed to be shared among various OSIDs and Managers. The exact
  7. * meaning of a particular type is left to the developers who use a given Type
  8. * subclass. The form of the Type class enables categorization. There are
  9. * four Strings that make up the Type class: authority, domain, keyword, and
  10. * description. The first three of these Strings are used by the isEqual
  11. * method to determine if two instance of the Type class are equal. The
  12. * fourth String, description, is used to clarify the semantic meaning of the
  13. * instance.
  14. *
  15. * <p>
  16. * An example of a FunctionType instance:
  17. * </p>
  18. *
  19. * <p>
  20. * <br> - authority is "higher ed"
  21. * <br> - domain is "authorization
  22. * <br> - keyword is "writing checks"
  23. * <br> - description is "This is the FunctionType for writing checks"
  24. * </p>
  25. *
  26. * <p>
  27. * This Type could be used with the authorization OSID. It could also be used
  28. * with the dictionary OSID to determine the text to display for a given
  29. * locale (for example, CANADA_FRENCH). The dictionary OSID could use the
  30. * FunctionType instance as a key to find the display text, but it could also
  31. * use just the keyword string from the FunctionType as a key. By using the
  32. * keyword the same display text could then be used for other FunctionTypes
  33. * such as:
  34. * <br> - authority is "mit"
  35. * <br> - domain is "accounting"
  36. * <br> - keyword is "writing checks"
  37. * <br> - description is "A/P check writing type"
  38. * <br>An instance of the Type class can be used in a variety of ways to
  39. * categorize information either as a complete object or as one of its parts
  40. * (ie authority, domain, keyword).
  41. * </p>
  42. *
  43. * <p>
  44. * OSID Version: 2.0
  45. * </p>
  46. *
  47. * <p>
  48. * Licensed under the {@link org.osid.SidImplementationLicenseMIT MIT}
  49. * O.K.I&#46; OSID Definition License}.
  50. * </p>
  51. *
  52. * @package org.osid.shared
  53. */
  54. class Type
  55. extends SObject
  56. {
  57. /**
  58. *
  59. * @param object Type $type2
  60. *
  61. * @return boolean
  62. *
  63. * @access public
  64. */
  65. function isEqualTo ( $type2 )
  66. {
  67. if ((null != $type2) && (null != $type2->getDomain()) &&
  68. (null != $type2->getAuthority()) && (null != $type2->getKeyword()) &&
  69. (null != $this->getDomain()) && (null != $this->getAuthority()) &&
  70. (null != $this->getKeyword())) {
  71. return ($this->getDomain() == $type2->getDomain()
  72. && $this->getAuthority() == $type2->getAuthority()
  73. && $this->getKeyword() == $type2->getKeyword()
  74. )?TRUE:FALSE;
  75. }
  76.  
  77. return false;
  78. }
  79. /**
  80. *
  81. * @param object Type $type2
  82. *
  83. * @return boolean
  84. *
  85. * @access public
  86. */
  87. function isEqual ( $type2 )
  88. {
  89. return $this->isEqualTo($type2);
  90. }
  91.  
  92. /**
  93. *
  94. * @return string
  95. *
  96. * @access public
  97. */
  98. function getAuthority ()
  99. {
  100. return $this->authority;
  101. }
  102.  
  103. /**
  104. *
  105. * @return string
  106. *
  107. * @access public
  108. */
  109. function getDomain ()
  110. {
  111. return $this->domain;
  112. }
  113.  
  114. /**
  115. *
  116. * @return string
  117. *
  118. * @access public
  119. */
  120. function getKeyword ()
  121. {
  122. return $this->keyword;
  123. }
  124.  
  125. /**
  126. *
  127. * @return string
  128. *
  129. * @access public
  130. */
  131. function getDescription ()
  132. {
  133. return $this->description;
  134. }
  135.  
  136.  
  137. /**
  138. * Constructor
  139. *
  140. * @param string $domain
  141. * @param string $authority
  142. * @param string $keyword
  143. * @param optional string $description
  144. *
  145. * @return object
  146. */
  147. function Type ( $domain, $authority, $keyword, $description = "" ) {
  148. if (!$domain) {
  149. printDebugBacktrace();
  150. die ("Error: Domain not specified in function Type::Type()");
  151. }
  152. if (!$authority) {
  153. printDebugBacktrace();
  154. die ("Error: Authority not specified in function Type::Type()");
  155. }
  156. if (!$keyword) {
  157. printDebugBacktrace();
  158. die ("Error: Keyword not specified in function Type::Type()");
  159. }
  160. $this->domain = $domain;
  161. $this->authority = $authority;
  162. $this->keyword = $keyword;
  163. $this->description = $description;
  164. }
  165. /**
  166. * Return a printable string
  167. *
  168. * @return string
  169. * @access public
  170. * @since 7/13/05
  171. */
  172. function printableString () {
  173. return $this->getDomain()."::".$this->getAuthority()."::".$this->getKeyword();
  174. }
  175.  
  176. /**
  177. * Convert an OKI Type to a delimited string
  178. *
  179. * @param object Type $aType
  180. * @param string $glue
  181. * @return string
  182. * @access public
  183. * @since 6/1/05
  184. * @static
  185. */
  186. function typeToString($aType, $glue="::") {
  187. ArgumentValidator::validate($aType, ExtendsValidatorRule::getRule("Type"));
  188. return $aType->getDomain() . $glue . $aType->getAuthority() . $glue . $aType->getKeyword();
  189. }
  190.  
  191. /**
  192. * Convert a delimited string to an OKI Type
  193. *
  194. * @param string $aString
  195. * @param string $glue
  196. * @return object Type
  197. * @access public
  198. * @since 6/1/05
  199. * @static
  200. */
  201. function fromString($aString, $glue = "::") {
  202. ArgumentValidator::validate($aString, StringValidatorRule::getRule());
  203.  
  204. $parts = explode($glue, $aString);
  205.  
  206. $obj = new Type($parts[0], $parts[1], $parts[2]);
  207.  
  208. return $obj;
  209. }
  210. }
  211.  
  212. ?>

Documentation generated on Wed, 19 Sep 2007 10:27:35 -0400 by phpDocumentor 1.3.0RC3