00001 <?php
00024 class SMWDataItemException extends MWException {
00025 }
00026
00044 abstract class SMWDataItem {
00045
00047 const TYPE_NOTYPE = 0;
00049 const TYPE_NUMBER = 1;
00051 const TYPE_STRING = 2;
00053 const TYPE_BLOB = 3;
00055 const TYPE_BOOLEAN = 4;
00057 const TYPE_URI = 5;
00059 const TYPE_TIME = 6;
00061 const TYPE_GEO = 7;
00063 const TYPE_CONTAINER = 8;
00065 const TYPE_WIKIPAGE = 9;
00067 const TYPE_CONCEPT = 10;
00069 const TYPE_PROPERTY = 11;
00071 const TYPE_ERROR = 12;
00072
00079 abstract public function getDIType();
00080
00100 abstract public function getSortKey();
00101
00109 public function getSortKeyDataItem() {
00110 $sortkey = $this->getSortKey();
00111 if ( is_numeric( $sortkey ) ) {
00112 return new SMWDINumber( $sortkey );
00113 } else {
00114 return new SMWDIBlob( $sortkey );
00115 }
00116 }
00117
00125 abstract public function getSerialization();
00126
00133 public function getHash() {
00134 return $this->getSerialization();
00135 }
00136
00147 public static function newFromSerialization( $diType, $serialization ) {
00148 $diClass = self::getDataItemClassNameForId( $diType );
00149 return call_user_func( array( $diClass, 'doUnserialize' ), $serialization );
00150 }
00151
00161 public static function getDataItemClassNameForId( $diType ) {
00162 switch ( $diType ) {
00163 case self::TYPE_NUMBER: return 'SMWDINumber';
00164 case self::TYPE_STRING: return 'SMWDIString';
00165 case self::TYPE_BLOB: return 'SMWDIBlob';
00166 case self::TYPE_BOOLEAN: return 'SMWDIBoolean';
00167 case self::TYPE_URI: return 'SMWDIUri';
00168 case self::TYPE_TIME: return 'SMWDITime';
00169 case self::TYPE_GEO: return 'SMWDIGeoCoord';
00170 case self::TYPE_CONTAINER: return 'SMWDIContainer';
00171 case self::TYPE_WIKIPAGE: return 'SMWDIWikiPage';
00172 case self::TYPE_CONCEPT: return 'SMWDIConcept';
00173 case self::TYPE_PROPERTY: return 'SMWDIProperty';
00174 case self::TYPE_ERROR: return 'SMWDIError';
00175 case self::TYPE_NOTYPE: default:
00176 throw new InvalidArgumentException( "The value \"$diType\" is not a valid dataitem ID." );
00177 }
00178 }
00179
00180 }