/**
     * @static
     * @return XIDGeneratorFactory
     */
    public static function getInstance() {
        if (!isset(self::$factory)) {
            self::$factory = new DefaultXIDGeneratorFactory();
        }

        return self::$factory;
    }
    public function newXID() {
        $generator = XIDGeneratorFactory::getInstance()->getGenerator();

        $formatId = $generator->getFormatId();
        if ($formatId == XID_FORMAT_NULL) {
            throw new IllegalArgumentException(t('Unsupported XID format identifier: @formatId', array('@formatId' => $formatId)));
        }

        $globalTransactionId = $generator->generateGlobalTransactionId();
        if (strlen($globalTransactionId) > MAXGTRIDSIZE) {
            throw new IllegalArgumentException(t(
                'Global transaction identifier is too long. Max length is @globalTransactionIdLength bytes',
                array('@globalTransactionIdLength' => MAXGTRIDSIZE)));
        }

        $branchQualifier = $generator->generateBranchQualifier();
        if (strlen($branchQualifier) > MAXBQUALSIZE) {
            throw new IllegalArgumentException(t(
                'Global transaction branch qualifier is too long. Max length is @branchQualifierLength bytes',
                array('@branchQualifierLength' => MAXBQUALSIZE)));
        }

        $xid = new XID();
        $xid->formatId = $formatId;
        $xid->globalTransactionId = $globalTransactionId;
        $xid->branchQualifier = $branchQualifier;

        return $xid;
    }