示例#1
0
 /**
  * Generate a new BigDecimal Object.
  * @param <int|string|float|blaze\lang\Number> $value Is a native String, with scale and algebric sign
  * @param <type> $scale If value has no scale you can define the scale
  */
 public function __construct($value, $scale = null)
 {
     if (($class = Number::getNumberClass($value)) !== null) {
         $className = $class->getName()->toNative();
         $value = $className::asNative($value);
     } else {
         if (!self::isNativeType($value)) {
             throw new \blaze\lang\NumberFormatException('Not a valid representation of BigDecimal!');
         }
     }
     $this->value = String::asNative($value);
     if ($scale != null) {
         $this->scale = $scale;
     } else {
         $ar = explode('.', $this->value);
         $count = count($ar);
         if ($count > 2) {
             throw new \blaze\lang\NumberFormatException('Not a valid representation of BigDecimal!');
         }
         if ($count == 2) {
             $this->scale = strlen($ar[1]);
         } else {
             $this->scale = 0;
         }
     }
 }
示例#2
0
 /**
  * Returns an instance of TypeChecker for the specified type.
  *
  * @param string|blaze\lang\String|blaze\lang\ClassWrapper $type
  * @return blaze\collections\TypeChecker
  */
 public static function getInstance($type)
 {
     if ($type === null) {
         throw new blaze\lang\NullPointerException();
     }
     $class = null;
     $type = null;
     $typeName = null;
     if ($type instanceof \blaze\lang\ClassWrapper) {
         $class = $type;
         $typeName = $type->getName();
     } else {
         $type = \blaze\lang\String::asNative($type);
         if (in_array($type, self::$basicTypes)) {
             $type = $type;
             $typeName = new \blaze\lang\String($type);
         } else {
             $class = \blaze\lang\ClassWrapper::forName($type);
             $typeName = $class->getName();
         }
     }
     if (!array_key_exists($typeName, self::$typeCheckers)) {
         self::$typeCheckers[$typeName] = new TypeChecker($type, $class, $typeName);
     }
     return self::$typeCheckers[$typeName];
 }
 public function next()
 {
     if ($this->hasNext()) {
         $this->returnObj = $this->rsd->getResultClassInstance();
         foreach ($this->rsd->getFieldMappings() as $column => $propertyPath) {
             $classesPath = $propertyPath->getClassesPath();
             $namesPath = $propertyPath->getNamesPath();
             for ($i = 0; $i < count($namesPath); $i++) {
                 switch (\blaze\lang\String::asNative($classesPath[$i])) {
                     case 'int':
                         $this->setObjectValue($this->returnObj, $namesPath, $this->rs->getInt($column));
                         break;
                     case 'blaze\\lang\\String':
                         $this->setObjectValue($this->returnObj, $namesPath, $this->rs->getString($column));
                         break;
                     case 'blaze\\util\\Date':
                         $this->setObjectValue($this->returnObj, $namesPath, $this->rs->getDate($column));
                         break;
                     default:
                         $this->setObjectValue($this->returnObj, $namesPath, null);
                         break;
                 }
             }
         }
     } else {
         $this->returnObj = null;
     }
     $this->hasNext = null;
     return $this->returnObj;
 }
 /**
  * Returns the login timeout in seconds.
  *
  * @return int The timeout in seconds.
  */
 public function unregisterDriver($protocol)
 {
     $protocol = String::asNative($protocol);
     if (array_key_exists($protocol, $this->drivers)) {
         unset($this->drivers[$protocol]);
     }
 }
 public function save(\blaze\persistence\cfg\Configuration $config, $file)
 {
     $f = null;
     if ($file instanceof \blaze\io\File) {
         $f = $file;
     } else {
         $f = new \blaze\io\File(\blaze\lang\String::asNative($file));
     }
 }
示例#6
0
 public function __construct($value)
 {
     if (($class = Number::getNumberClass($value)) !== null) {
         $value = $class->getMethod('asNative')->invoke(null, $value);
     } else {
         if (!self::isNativeType($value)) {
             throw new \blaze\lang\NumberFormatException('Not a valid representation of BigInteger!');
         }
     }
     $this->value = String::asNative($value);
 }
示例#7
0
 public static function asNative($value)
 {
     if (static::isWrapperType($value)) {
         return $value->toNative();
     } else {
         if (static::isNativeType($value)) {
             return $value;
         } else {
             return String::asNative($value);
         }
     }
 }
 public function write($str, $off = 0, $len = -1)
 {
     $str = \blaze\lang\String::asNative($str);
     if ($off > 0) {
         if ($len > 0) {
             $str = substr($str, $off, $len);
         } else {
             $str = substr($str, $off);
         }
     }
     return $this->out->write(serialize($str));
 }
 public function addFieldMapping(SingleFieldDescriptor $fieldDescriptor, $columnAlias = null)
 {
     if ($columnAlias === null) {
         $columnAlias = $fieldDescriptor->getColumnDescriptor()->getName();
     }
     if ($columnAlias === null) {
         throw new \blaze\lang\Exception('No column name available');
     }
     $columnAlias = \blaze\lang\String::asNative($columnAlias);
     $propPath = new PropertyPath();
     $propPath->addPathStep($fieldDescriptor->getType(), $fieldDescriptor->getName());
     $this->columnAliasToPropertyPathMapping[$columnAlias] = $propPath;
 }
 public function write($str, $off = 0, $len = -1)
 {
     $str = \blaze\lang\String::asNative($str);
     if ($off > 0) {
         if ($len > 0) {
             $str = substr($str, $off, $len);
         } else {
             $str = substr($str, $off);
         }
     }
     if (fwrite($this->stream, $str) === false) {
         throw new \blaze\io\IOException('Error writing to stream.');
     }
 }
示例#11
0
 /**
  * Checks the key and returns it as native string when wrapper is false, otherwise as blaze\lang\String.
  * @return string|blaze\lang\String
  */
 private static function getCheckedKey($key, $wrapper = false)
 {
     if ($wrapper) {
         $key = \blaze\lang\String::asWrapper($key);
         if ($key->length() < 1) {
             throw new CacheException('The length of the key must be at least one char!');
         }
     } else {
         $key = \blaze\lang\String::asNative($key);
         if (strlen($key) < 1) {
             throw new CacheException('The length of the key must be at least one char!');
         }
     }
     return $key;
 }
示例#12
0
 public static function getTableDescriptor($name)
 {
     $name = \blaze\lang\String::asNative($name);
     if (self::$tableDescriptors === null) {
         self::$tableDescriptors = array();
     }
     //new \blaze\collections\map\HashMap();
     $td = isset(self::$tableDescriptors[$name]) ? self::$tableDescriptors[$name] : null;
     //self::$tableDescriptors->get($name);
     if ($td === null) {
         $td = new TableDescriptor();
         $td->setName($name);
         self::$tableDescriptors[$name] = $td;
         //self::$tableDescriptors->put($name, $td);
     }
     return $td;
 }
示例#13
0
 /**
  *
  * @return FileSystem
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         switch (String::asNative(\blaze\lang\System::getProperty('host.fs'))) {
             case 'UNIX':
                 self::$instance = new UnixFileSystem();
                 break;
             case 'WIN32':
                 self::$instance = new Win32FileSystem();
                 break;
             case 'WINNT':
                 self::$instance = new WinNTFileSystem();
                 break;
             default:
                 throw new \blaze\lang\Exception('Host uses unsupported filesystem, unable to proceed');
         }
     }
     return self::$instance;
 }
示例#14
0
 private function getValueFromContext($key)
 {
     $ctx = \blaze\web\application\BlazeContext::getCurrentInstance();
     $key = \blaze\lang\String::asNative($key);
     $val = $this->context->getContext(ELContext::SCOPE_REQUEST)->get($ctx, $key);
     if ($val != null) {
         return $val;
     }
     $val = $this->context->getContext(ELContext::SCOPE_VIEW)->get($ctx, $key);
     if ($val != null) {
         return $val;
     }
     $val = $this->context->getContext(ELContext::SCOPE_SESSION)->get($ctx, $key);
     if ($val != null) {
         return $val;
     }
     $val = $this->context->getContext(ELContext::SCOPE_APPLICATION)->get($ctx, $key);
     if ($val != null) {
         return $val;
     }
     return null;
 }
 public function setString($identifier, $value)
 {
     $this->set($identifier, \blaze\lang\String::asNative($value), \PDO::PARAM_STR);
     return $this;
 }
示例#16
0
 public function setCursorName($cursorName)
 {
     $this->checkClosed();
     $this->stmt->setAttribute(\PDO::ATTR_CURSOR_NAME, \blaze\lang\String::asNative($cursorName));
 }
示例#17
0
 /**
  *
  * @param string|blaze\lang\String $name
  */
 public function removeAttribute($name)
 {
     unset($this->attributes[\blaze\lang\String::asNative($name)]);
 }
示例#18
0
 public function hashCode()
 {
     if ($this->key instanceof Object) {
         return String::asNative($this->key->hashCode());
     } else {
         return String::asNative(Integer::hexStringToInt(md5($this->key)));
     }
 }
 public function getComposedNativeType()
 {
     $type = $this->getNativeType();
     switch (\blaze\lang\String::asNative($type)) {
         case 'bigint':
         case 'tinyint':
         case 'smallint':
         case 'mediumint':
         case 'int':
             $type .= '(' . $this->getLength() . ')' . $this->isSigned() ? '' : 'UNSIGNED';
             break;
         case 'char':
         case 'varchar':
         case 'binary':
             $type .= '(' . $this->getLength() . ')';
             break;
         case 'real':
         case 'double':
         case 'float':
         case 'numeric':
         case 'decimal':
             $type .= '(' . $this->getLength() . ',' . $this->getPrecision() . ')';
             break;
     }
     return \blaze\lang\String::asWrapper($type);
 }
示例#20
0
 /**
  *
  * @param blaze\lang\String|string|int $identifier
  *
  */
 protected function get($identifier)
 {
     if (!is_array($this->actRow)) {
         throw new \blaze\ds\DataSourceException('No valid result.');
     }
     if (is_int($identifier)) {
         if (!array_key_exists($identifier, $this->actRowIndex)) {
             throw new \blaze\ds\DataSourceException('Index ' . $identifier . ' was not found.');
         }
         return $this->actRowIndex[$identifier];
     } else {
         if (!array_key_exists(String::asNative($identifier), $this->actRow)) {
             throw new \blaze\ds\DataSourceException('Index ' . $identifier . ' was not found.');
         }
         return $this->actRow[String::asNative($identifier)];
     }
 }
示例#21
0
 /**
  * Sets the value of the buffer at the position $off to the given value.
  * If the size of given string is greater than 1, then every char after the
  * position $off is overwritten.
  * If $off is negative an IndexOutOfBoundsException is thrown.
  *
  * @param blaze\lang\String|string $str
  * @param int $off
  * @return blaze\lang\StringBuffer
  * @throws blaze\lang\IndexOutOfBoundsException Is thrown when $len is negative
  * @todo Test what happens when $newStart == $this->count, maybe need ($newStart >= $this->count)
  */
 public function setStringAt($str, \int $off)
 {
     $str = String::asNative($str);
     if ($off < 0) {
         throw new IndexOutOfBoundsException($off);
     }
     $newStart = $off + strlen($str);
     if ($newStart > $this->count) {
         $this->string = substr($this->string, 0, $off) . $str;
     } else {
         $this->string = substr($this->string, 0, $off) . $str . substr($this->string, $newStart);
     }
     $this->count = strlen($this->string);
     return $this;
 }
示例#22
0
 /**
  *
  * @param blaze\io\File|blaze\lang\String|string $file The File-Object or path of the parent.
  * @param boolean $direct
  * @return boolean
  */
 public function isParentOf($file, $direct = false)
 {
     if (!$file instanceof File) {
         $file = new File(String::asNative($file));
     }
     return $file->isChildOf($this, $direct);
 }
示例#23
0
 private function hash($key)
 {
     return String::asNative($key->hashCode());
 }
示例#24
0
 /**
  *
  * @param string|\blaze\lang\String|\blaze\persistence\ooql\Statement $query
  * @return \blaze\persistence\meta\ResultSetDescriptor
  */
 private function buildResultSetDescriptor($query)
 {
     $rsd = null;
     //if($query instanceof \blaze\persistence\ooql\Statement)
     if ($query instanceof \blaze\persistence\ooql\FromStatement) {
         $fromables = $query->getFromClause()->getFromables();
         $aliasMapping = array();
         // Fields which will occur in the ResultSet
         $fields = array();
         $collectionFields = array();
         // Just to check for name duplicates
         $fieldsGlobal = array();
         if (count($fromables) < 1) {
             throw new \Exception('Invalid Query, nothing set in the from-clause!');
         }
         // This loop is to check if there are any name duplicates
         // and to set up a alias to field mapping
         foreach ($fromables as $fromable) {
             if ($fromable instanceof \blaze\persistence\ooql\Entity) {
                 $classMeta = $this->em->getEntityManagerFactory()->getClassDescriptor($fromable->getName());
                 if ($classMeta === null) {
                     throw new \blaze\lang\Exception('Entity "' . $fromable->getName() . '" does not exist!');
                 }
                 if ($fromable->getAlias() !== null) {
                     $alias = \blaze\lang\String::asNative($fromable->getAlias());
                     if (array_search($alias, $aliasMapping) !== false) {
                         throw new \blaze\lang\Exception('The alias ' . $alias . ' already exists!');
                     }
                     $aliasMapping[$alias] = $classMeta;
                     foreach ($classMeta->getIdentifiers() as $field) {
                         $fields[$alias][] = $field->getFieldDescriptor();
                     }
                     foreach ($classMeta->getSingleFields() as $field) {
                         $fields[$alias][] = $field;
                     }
                     foreach ($classMeta->getCollectionFields() as $field) {
                         $collectionFields[$alias][] = $field;
                     }
                 } else {
                     $alias = \blaze\lang\String::asNative($fromable->getName());
                     if (array_search($alias, $aliasMapping) !== false) {
                         throw new \blaze\lang\Exception('The alias ' . $alias . ' already exists!');
                     }
                     $aliasMapping[$alias] = $classMeta;
                     foreach ($classMeta->getIdentifiers() as $field) {
                         $val = $field->getFieldDescriptor();
                         if (array_search($val->getName(), $fieldsGlobal) !== false) {
                             throw new \blaze\lang\Exception('The attribute ' . $val->getName() . ' of ' . $classMeta->getName() . ' is already in the global scope, you need to use a alias!');
                         }
                         $fieldsGlobal[] = $val->getName();
                         $fields[$alias][] = $val;
                     }
                     foreach ($classMeta->getSingleFields() as $field) {
                         $val = $field;
                         if (array_search($val->getName(), $fieldsGlobal) !== false) {
                             throw new \blaze\lang\Exception('The attribute ' . $val->getName() . ' of ' . $classMeta->getName() . ' is already in the global scope, you need to use a alias!');
                         }
                         $fieldsGlobal[] = $val->getName();
                         $fields[$alias][] = $val;
                     }
                     foreach ($classMeta->getCollectionFields() as $field) {
                         $val = $field->getFieldDescriptor();
                         if (array_search($val->getName(), $fieldsGlobal) !== false) {
                             throw new \blaze\lang\Exception('The attribute ' . $val->getName() . ' of ' . $classMeta->getName() . ' is already in the global scope, you need to use a alias!');
                         }
                         $fieldsGlobal[] = $val->getName();
                         $collectionFields[$alias][] = $field;
                     }
                 }
             } else {
                 if ($fromable instanceof \blaze\persistence\ooql\Join) {
                     // Not supported at the moment
                 } else {
                     if ($fromable instanceof \blaze\persistence\ooql\Subselect) {
                         // Not supported at the moment
                     }
                 }
             }
         }
         if ($query instanceof \blaze\persistence\ooql\SelectStatement) {
             $clause = $query->getSelectClause();
             $selectables = $clause->getSelectables();
             $selectFields = array();
             if (count($selectables) < 1) {
                 throw new \blaze\lang\Exception('Nothing to select given!');
             }
             foreach ($selectables as $selectable) {
             }
             if (count($selectables) == 1) {
                 // Check the selectable to be able to set the return class
                 if ($selectables[0] instanceof \blaze\persistence\ooql\Formula) {
                     $rsd = new \blaze\persistence\meta\ResultSetDescriptor($selectables[0]->getReturnType());
                 } else {
                     $propNameParts = \blaze\lang\String::asWrapper($selectables[0]->getPropertyName())->split('.');
                     $alias = $propNameParts[count($propNameParts) - 1];
                     if ($selectables[0]->getPropertyAlias() !== null) {
                         $alias = $selectables[0]->getPropertyAlias();
                     }
                     $propPath = new \blaze\persistence\meta\PropertyPath();
                     // Check every field if the name is equal to the selectable
                     foreach ($fields as $fieldGroup) {
                         foreach ($fieldGroup as $field) {
                             if ($field instanceof \blaze\persistence\meta\SingleFieldDescriptor) {
                                 if ($field->getName()->compareTo($propNameParts[0]) == 0) {
                                     $rsd = new \blaze\persistence\meta\ResultSetDescriptor($field->getType());
                                     break;
                                 }
                             } else {
                                 if ($field->getFieldDescriptor()->getName()->compareTo($propNameParts[0]) == 0) {
                                     // Collection
                                     //$rsd = new \blaze\persistence\meta\ResultSetDescriptor($field->getType());
                                     break;
                                 }
                             }
                         }
                         if ($rsd !== null) {
                             break;
                         }
                     }
                 }
             } else {
                 // Return class is an Object[]
                 $rsd = new \blaze\persistence\meta\ResultSetDescriptor('blaze\\lang\\Object', true);
             }
         } else {
             if (count($fromables) > 1) {
                 throw new \blaze\lang\Exception('You need to specify what to select!');
             } else {
                 // Assume that the only object in fromables has to be selected
                 $classDesc = $aliasMapping[\blaze\lang\String::asNative($fromables[0]->getAlias())];
                 $rsd = new \blaze\persistence\meta\ResultSetDescriptor($classDesc->getFullName());
                 foreach ($fields[\blaze\lang\String::asNative($fromables[0]->getAlias())] as $field) {
                     $rsd->addFieldMapping($field);
                 }
                 foreach ($collectionFields[\blaze\lang\String::asNative($fromables[0]->getAlias())] as $field) {
                     $rsd->addCollectionMapping($field);
                 }
             }
         }
     }
     return $rsd;
 }
示例#25
0
 public function getConstant($name)
 {
     try {
         return new Method($this->reflectionClass->getConstant(String::asNative($name)));
     } catch (\ReflectionException $e) {
         throw new NoSuchFieldException($e->getMessage(), $e->getCode());
     }
 }
示例#26
0
 private function checkId($id)
 {
     if ($id == null) {
         return;
     }
     $str = \blaze\lang\String::asNative($id);
     if (strlen($str) == 0) {
         throw new \blaze\lang\IllegalArgumentException('Component id must have a length of at least one character');
     }
     $firstChar = $str[0];
     if ($firstChar != '_' && !\blaze\lang\Character::isLetter($firstChar)) {
         throw new \blaze\lang\IllegalArgumentException('Component id\'s first character must be a letter or underscore (_) and not ' . $firstChar);
     }
     if (!preg_match('/^..[a-zA-Z0-9\\-\\_]*$/', $str)) {
         throw new \blaze\lang\IllegalArgumentException('Component id\'s may only contain digits, letters, underscores(_) and dashes(-)');
     }
 }
示例#27
0
 /**
  *
  * @param \blaze\persistence\meta\ClassDescriptor $config
  * @param File $file
  */
 public function save(\blaze\persistence\meta\ClassDescriptor $config, $file)
 {
     $f = null;
     if ($file instanceof \blaze\io\File) {
         $f = $file;
     } else {
         $f = new \blaze\io\File(\blaze\lang\String::asNative($file));
     }
     $doc = new \DOMDocument();
     $root = $doc->createElement('persistence-mapping');
     $doc->appendChild($root);
     $node = $doc->createElement('class');
     $root->appendChild($node);
     AttributeUtil::set($node, 'package', $config->getPackage());
     AttributeUtil::set($node, 'name', $config->getName());
     AttributeUtil::set($node, 'schema', $config->getTableDescriptor()->getSchema());
     AttributeUtil::set($node, 'table', $config->getTableDescriptor()->getName());
     foreach ($config->getIdentifiers() as $member) {
         $this->saveId($node, $doc, $member);
     }
     foreach ($config->getSingleFields() as $member) {
         $this->saveField($node, $doc, $member);
     }
     foreach ($config->getCollectionFields() as $member) {
         $this->saveCollection($node, $doc, $member);
     }
     $doc->save($f->getAbsolutePath());
 }
示例#28
0
 public function dropColumn($columnName)
 {
     $columnName = \blaze\lang\String::asNative($columnName);
     if (!$this->initialized && array_key_exists($columnName, $this->notInitializedColumns)) {
         unset($this->notInitializedColumns[$columnName]);
     } else {
     }
 }