Source for file TopicMapSystemFactory.abstract.php

Documentation is available at TopicMapSystemFactory.abstract.php

  1. <?php
  2. /**
  3. * @package org.phptmapi.core
  4. */
  5. require_once('FactoryConfigurationException.exception.php');
  6. /**
  7. * abstract class TopicMapSystemFactory: This factory class provides access to a topic map system. A new TopicMapSystemInterface instance is created by invoking the newTopicMapSystem() method. Configuration properties for the new TopicMapSystemInterface instance can be set by calling the setFeature() and/or setProperty() methods prior to invoking newTopicMapSystem().
  8. *
  9. * @author Johannes Schmidt - t8d <kontakt@t8d.de>
  10. */
  11. abstract class TopicMapSystemFactory{
  12. /**
  13. * Constructor
  14. * @access public
  15. * @return void
  16. */
  17. abstract function __construct();
  18. /**
  19. * newInstance: This static method creates a new factory instance.
  20. * @access public
  21. * @return object TopicMapSystemFactory
  22. * @throws FactoryConfigurationException
  23. */
  24. public static function newInstance(){
  25. try{
  26. $class = self::getClassFromFile();
  27. if($class instanceof TopicMapSystemFactory){
  28. $instance = $class->newInstance();
  29. return $instance;
  30. }
  31. else throw new FactoryConfigurationException('Exception in '.__method__.': Cannot instantiate an implementation of TopicMapSystemFactory!');
  32. }
  33. catch(FactoryConfigurationException $e){
  34. $exception = $e->getCause();
  35. echo $exception->getMessage();
  36. }
  37. }
  38. /**
  39. * newTopicMapSystem: Creates a new TopicMapSystemInterface instance using the currently configured factory parameters.
  40. * @access public
  41. * @return object TopicMapSystemInterface
  42. * @throws TMAPIException if a topic map system cannot be created which satisfies the requested configuration.
  43. * <code>
  44. * public function newTopicMapSystem(){
  45. * throw new TMAPIException('Exception in '.__method__);
  46. * }
  47. * </code>
  48. */
  49. abstract function newTopicMapSystem();
  50. /**
  51. * setFeature: Sets a particular feature in the underlying implementation of TopicMapSystemInterface. A list of the core features can be found at http://tmapi.org/features/.
  52. * @param string $featureName The name of the feature to be set.
  53. * @param boolean $value True to enable the feature, false to disable it.
  54. * @access public
  55. * @return void
  56. * @throws FeatureNotRecognizedException if the underlying implementation does not recognize the named feature.
  57. * @throws FeatureNotSupportedException if the underlying implementation recognizes the named feature but does not support enabling or disabling it (as specified by the value parameter).
  58. * <code>
  59. * public function setFeature($featureName, $value){
  60. * throw new FeatureNotRecognizedException('Exception in '.__method__);
  61. * throw new FeatureNotSupportedException('Exception in '.__method__);
  62. * }
  63. * </code>
  64. */
  65. abstract function setFeature($featureName, $value);
  66. /**
  67. * Returns the particular feature requested for in the underlying implementation of TopicMapSystemInterface.
  68. * @param string $featureName The name of the feature to check.
  69. * @access public
  70. * @return boolean true if the named feature is enabled for TopicMapSystemInterface instances created by this factory; false if the named feature is disabled for TopicMapSystemInterface instances created by this factory.
  71. * @throws FeatureNotRecognizedException if the underlying implementation does not recognize the named feature.
  72. * <code>
  73. * public function getFeature($featureName){
  74. * throw new FeatureNotRecognizedException('Exception in '.__method__);
  75. * }
  76. * </code>
  77. */
  78. abstract function getFeature($featureName);
  79. /**
  80. * Returns if the particular feature is supported by the TopicMapSystemInterface. Opposite to getFeature() this method returns if the requested feature is generally available/supported by the underlying TopicMapSystemInterface and does not return the state (enabled/disabled) of the feature.
  81. * @param string $featureName The name of the feature to check.
  82. * @access public
  83. * @return boolean true if the requested feature is supported, otherwise false.
  84. */
  85. abstract function hasFeature($featureName);
  86. /**
  87. * Sets the properties in the underlying implementation of TopicMapSystemInterface.
  88. * @param array $props The properties to be used to initialise the system.
  89. * @access public
  90. * @return void
  91. * @see setProperty()
  92. */
  93. abstract function setProperties($props);
  94. /**
  95. * Sets a property in the underlying implementation of TopicMapSystemInterface. A list of the core properties defined by TMAPI can be found at http://tmapi.org/properties/. An implementation is free to support properties other than the core ones.
  96. * @param string $propertyName The name of the property to be set
  97. * @param string $value The value to be set of this property or null to remove the property from the current factory configuration.
  98. * @access public
  99. * @return void
  100. */
  101. abstract function setProperty($propertyName, $value);
  102. /**
  103. * Gets the value of a property in the underlying implementation of TopicMapSystemInterface.
  104. * A list of the core properties defined by TMAPI can be found at http://tmapi.org/properties/. An implementation is free to support properties other than the core ones.
  105. * @param string $propertyName The name of the property to retrieve.
  106. * @access public
  107. * @return string The value set for this property or null if no value is currently set for the property.
  108. */
  109. abstract function getProperty($propertyName);
  110. /**
  111. * getClassFromFile: Returns the TopicMapSystemFactory implementation using the discovery file.
  112. * @access private
  113. * @return object TopicMapSystemFactory
  114. * @throws FactoryConfigurationException
  115. */
  116. private static function getClassFromFile(){
  117. try{
  118. $dir = '../META/factory/';
  119. if($dh = opendir($dir)){
  120. while(($tempfile = readdir($dh)) !== false) {
  121. $file = $tempfile;
  122. }
  123. closedir($dh);
  124. if($pathToClass = file_get_contents($dir.$file)){
  125. require_once $pathToClass;
  126. $class = $file;
  127. $class = new $class;
  128. return $class;
  129. }
  130. else throw new FactoryConfigurationException('Exception in '.__method__.': Cannot read discovery file for the implementation of TopicMapSystemFactory!');
  131. }
  132. else throw new FactoryConfigurationException('Exception in '.__method__.': Cannot open directory that includes discovery file for the implementation of TopicMapSystemFactory!');
  133. }
  134. catch(FactoryConfigurationException $e){
  135. $exception = $e->getCause();
  136. echo $exception->getMessage();
  137. }
  138. }
  139. }
  140. ?>

Documentation generated on Fri, 30 Jun 2006 13:07:11 +0200 by phpDocumentor 1.3.0RC4