??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲人成影院午夜网站,精品久久久久亚洲,亚洲gay片在线gv网站http://www.tkk7.com/sshwsfc/阅读本Blog误备塑料袋一?/description>zh-cnFri, 09 May 2025 20:07:31 GMTFri, 09 May 2025 20:07:31 GMT60Google Developer Day 收获http://www.tkk7.com/sshwsfc/archive/2008/06/15/208023.html差沙差沙Sun, 15 Jun 2008 05:03:00 GMThttp://www.tkk7.com/sshwsfc/archive/2008/06/15/208023.htmlhttp://www.tkk7.com/sshwsfc/comments/208023.htmlhttp://www.tkk7.com/sshwsfc/archive/2008/06/15/208023.html#Feedback4http://www.tkk7.com/sshwsfc/comments/commentRss/208023.htmlhttp://www.tkk7.com/sshwsfc/services/trackbacks/208023.html E后的OpenSocial专题topic中了解到了更多有关OpenSocial的信息,主要是Shindig? 前一天还在跟白衣提议用ss做一个类似Shindig的东西,主要是做一个OpenSocial的实玎ͼ当时想q玩意估计有了,但是没想到是host到apache了,在apache的孵化器中大家可以自己找找。会议的时候逮住了一个google的h问了一堆问题,q后才知道原来是google中国sns的负责h?br /> 最大的收获实在是太意外了,在中午休息的时候,走过q道到楼下吃饭,H然发现一个熟悉的w媄坐在角落里一个h在玩电脑Q我晕是Andy RubinQAndroid的老大。居然就坐在那里Q而且旁边的h没有人在意他Q要知道听android topic的h可不呀Q居然每一个h认出他来的。我叫了朋友认一下,准备上前打招呹{刚上去打了个招|握了个手Q又来了一个hQ他一下认出AndyQƈ且跟Andy短的交谈了一下。我提议先照个相Q照相后短聊下那个hp了。过后Andy说那个h是Google中国负责android的老大邸烁博士Q我狂晕呀两位老大都让我给C了。稍候跟Andy聊了一下Android的发展,随后他掏Z个android的原型机Q就是google IO大会上的那种机器。这里要说明的是Q不在模拟器上android的表现如何,在真Z你的体验l对l对是不一LQ太COOL了。尤其是W二屏的widget效果Q还有那个street view效果Q真机拿在手上体验就是不一样呀~~~~ 随后又了解到了一些android目前的发展情况,q里可以告诉大家的是Qandroid是绝对值得期待的~Q!Q?



差沙 2008-06-15 13:03 发表评论
]]>
Android上的MSN初见成效~~Q!http://www.tkk7.com/sshwsfc/archive/2008/03/21/187605.html差沙差沙Thu, 20 Mar 2008 17:59:00 GMThttp://www.tkk7.com/sshwsfc/archive/2008/03/21/187605.htmlhttp://www.tkk7.com/sshwsfc/comments/187605.htmlhttp://www.tkk7.com/sshwsfc/archive/2008/03/21/187605.html#Feedback2http://www.tkk7.com/sshwsfc/comments/commentRss/187605.htmlhttp://www.tkk7.com/sshwsfc/services/trackbacks/187605.htmll过两天的努力,l于在Android上面跑v来MSN了。现在实C基本的聊天功能,打算陆箋的把其他功能完善Q万事开头难Q相信以后的工作会很利?/p>


Gtalk的功能由于有官方支持Q早弄了跟q个差不多的版本?/p>


另外Q这个Y件目前是以插件的形式开发,多一个协议就是多一个apkQ实C些intent卛_。官方的IM包里面有很多支持Q可惜文档没有提及?/p>

 

Android中文论坛原帖



差沙 2008-03-21 01:59 发表评论
]]>
Air+Ext试一?/title><link>http://www.tkk7.com/sshwsfc/archive/2008/02/26/182206.html</link><dc:creator>差沙</dc:creator><author>差沙</author><pubDate>Tue, 26 Feb 2008 05:49:00 GMT</pubDate><guid>http://www.tkk7.com/sshwsfc/archive/2008/02/26/182206.html</guid><wfw:comment>http://www.tkk7.com/sshwsfc/comments/182206.html</wfw:comment><comments>http://www.tkk7.com/sshwsfc/archive/2008/02/26/182206.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.tkk7.com/sshwsfc/comments/commentRss/182206.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sshwsfc/services/trackbacks/182206.html</trackback:ping><description><![CDATA[<p>今天看到Air1.0和Ext2.0.2的发布消息,很是兴奋Q要知道Ext的每个版本升U都是很实惠的?/p> <p>Ext2.0.2的这ơ升U主要是针对Air的支持,看来他们的关pL来近了,我也借机试了一下Air?/p> <p>单说说Air的开发过E:<br></p> <p>1.先要下蝲jre ?airSDK</p> <p>2.jre׃说了QairSDK也是单的解压一下便可?/p> <blockquote> <p>可以看看SDK下面的bin目录Q一׃文gQ一个adl一个adtQadl是用来测试的Qadt使用~辑发布的(ADT怎么让我惌v来android了)</p></blockquote> <p>3.创徏一个普通的目录作ؓ目目录。OKQ可以写面了。就是写html js flash什么的Q都可?/p> <p>4.~写一个xml文gQ名字不限。内容嘛~~~~</p> <blockquote> <p>看看q个文gQairSDK\templates\descriptor-template.xml 里面有详l的解释Q拿q来Ҏ卛_Q给一个例子:</p> <hr> <pre><span style="color: #0000ff"><?</span>xml version="1.0" encoding="UTF-8"<span style="color: #0000ff">?></span> <span style="color: #0000ff"><</span><span style="color: #800000">application</span> <span style="color: #ff0000">xmlns</span>=<span style="color: #0000ff">"http://ns.adobe.com/air/application/1.0.M6"</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">id</span><span style="color: #0000ff">></span>examples.html.HelloWorld<span style="color: #0000ff"></</span><span style="color: #800000">id</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">version</span><span style="color: #0000ff">></span>0.1<span style="color: #0000ff"></</span><span style="color: #800000">version</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">filename</span><span style="color: #0000ff">></span>HelloWorld<span style="color: #0000ff"></</span><span style="color: #800000">filename</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">initialWindow</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">content</span><span style="color: #0000ff">></span>HelloWorld.html<span style="color: #0000ff"></</span><span style="color: #800000">content</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">visible</span><span style="color: #0000ff">></span>true<span style="color: #0000ff"></</span><span style="color: #800000">visible</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">width</span><span style="color: #0000ff">></span>400<span style="color: #0000ff"></</span><span style="color: #800000">width</span><span style="color: #0000ff">></span> <span style="color: #0000ff"><</span><span style="color: #800000">height</span><span style="color: #0000ff">></span>200<span style="color: #0000ff"></</span><span style="color: #800000">height</span><span style="color: #0000ff">></span> <span style="color: #0000ff"></</span><span style="color: #800000">initialWindow</span><span style="color: #0000ff">></span> <span style="color: #0000ff"></</span><span style="color: #800000">application</span><span style="color: #0000ff">></span></pre> <p> <hr> <p></p></blockquote> <p>5.q行airSDK\bin\adl.exe (那个创徏的xml文g?Q运行即可?/p> <p>PS:我一般用eclipse来编辑,用外部命令的工具来运行adlQ很方便?/p> <p>单的说了一下Air的开发方法后Q我们来单的看一下Ext都对Air提供了什么支持?/p> <p>1.Ext.air.FileProvider</p> <blockquote> <p>Ext提供状态保存的功能Q在对AIr的支持中Ext实现了一个ProviderQ这个Provider把状态保存在本地目录的一个文仉。用方法如下:</p> <hr> <pre><span style="color: #008000">// Initialize the state provider</span> Ext.state.Manager.setProvider(<span style="color: #0000ff">new</span> Ext.air.FileProvider({ file: 'ext.state', <span style="color: #008000">// if first time running</span> defaultState : { mainWindow : { width:400, height:200, x:10, y:10 } } }));</pre> <p> <hr> <p></p> <p>制定Provider为Ext.air.FileProvider卛_Q这个操作一般在onReady里面执行。当焉要你先创Z个ext.state文本文gQ在E序根目录下卛_。这样ext的应用运行时Q窗口等大小的调_位置之类的调整都能保存下来了。很方便?/p> <p>q里包装的Air代码主要是:</p> <p>air.File.applicationStorageDirectory.resolvePath</p> <p>air.FileStream</p> <p>{?/p></blockquote> <p>2.Ext.air.NativeWindow</p> <blockquote> <p>Ext可以调用Air实现Native的窗口。用方法如下:</p> <hr> <pre> <span style="color: #0000ff">var</span> win = <span style="color: #0000ff">new</span> Ext.air.NativeWindow({ id: 'mainWindow', instance: <span style="color: #0000ff">window</span>.nativeWindow, minimizeToTray: <span style="color: #0000ff">true</span>, trayIcon: 'ext-air/resources/icons/extlogo16.png', trayTip: 'Simple Tasks', trayMenu : [{ text: 'Open Simple Tasks', handler: <span style="color: #0000ff">function</span>(){ win.activate(); } }, '-', { text: 'Exit', handler: <span style="color: #0000ff">function</span>(){ air.NativeApplication.nativeApplication.exit(); } }] });</pre> <p> <hr> <p></p> <p>我们可以看到Q其中最吸引人的是系l托盘的功能Q可以方便的指定pȝ托盘的各U属性?/p> <p>q里包装的主要是Q?/p> <p>window.runtime.flash.html.HTMLLoader.createRootWindow</p> <p>air.Screen.mainScreen.visibleBounds</p></blockquote> <p>3.Ext.sql.Connection</p> <blockquote> <p>q个是重头戏Q对db的支持,我们知道Air的DB是采用sqlite3来实现的。Ext装了Air的db操作Q简化统一了一些,而且提供了Store的支持,非常强大Q?/p> <p>让我们简单看一下用法:</p> <p><strong><em>首先取得connection</em></strong></p> <p>var conn = Ext.sql.Connection.getInstance();</p> <p><strong><em>而后打开db</em></strong></p> <p>conn.open('ext.db');//q里的文件如果不存在会自动创?/p> <p><strong><em>创徏Table</em></strong></p> <hr> <pre> conn.createTable({ <span style="color: #0000ff">name</span>: 'user', key: 'userId', fields: [ {<span style="color: #0000ff">name</span>: 'userId', type:'string'}, {<span style="color: #0000ff">name</span>: '<span style="color: #0000ff">name</span>', type:'string'}, {<span style="color: #0000ff">name</span>: 'pwd', type:'string'}, {<span style="color: #0000ff">name</span>: 'email', type:'string'} ] });</pre> <hr> </blockquote> <blockquote dir="ltr" style="margin-right: 0px"> <p><strong><em>取得一个Table</em></strong></p> <p>var userDao = conn.getTable('user','userId');</p> <p><strong><em>查询</em></strong></p> <p>var users = userDao.select();//q里可以写条件式</p> <p><strong><em>d</em></strong></p> <hr> <pre><span style="color: #0000ff">var</span> newuser = { userId : 'sshw', <span style="color: #0000ff">name</span> : 'sshwsfc', pwd : 'test', email : 'sshwsfc@gmail.com' } userDao.insert(newuser);</pre> <p> <hr> <p></p> <p>感觉使用上还是蛮不错的,大家可以一点点试试看?/p> <p>值得一提的是,在源码中发现Connectionq里设计成了工厂的模式,Connection是一个伪接口Q实现除了Air的还有GoogleGear的,会根据所处环境选择Q灰常的好?/p></blockquote> <p dir="ltr">功能q在研究中,有心得了一点点l大家分享,</p> <p dir="ltr">PS:打算搞一个iphone的信息管理Y件练l手。反正都是sqlite?/p> <img src ="http://www.tkk7.com/sshwsfc/aggbug/182206.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sshwsfc/" target="_blank">差沙</a> 2008-02-26 13:49 <a href="http://www.tkk7.com/sshwsfc/archive/2008/02/26/182206.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django什么情?1) -- Model?amp;ldquo;造Class&rdquo;概述http://www.tkk7.com/sshwsfc/archive/2008/02/02/179019.html差沙差沙Sat, 02 Feb 2008 09:32:00 GMThttp://www.tkk7.com/sshwsfc/archive/2008/02/02/179019.htmlhttp://www.tkk7.com/sshwsfc/comments/179019.htmlhttp://www.tkk7.com/sshwsfc/archive/2008/02/02/179019.html#Feedback1http://www.tkk7.com/sshwsfc/comments/commentRss/179019.htmlhttp://www.tkk7.com/sshwsfc/services/trackbacks/179019.html在朋友和同事的极力推荐下最q开始看上了python,其实主要是还是因为python?007q度语言,怎么的也要与时俱q呀.最q一路看来有些心?希望能与大家分n,弟其实也只接触不到一周的python,有说错的地方q望大家指出Ҏ.

不打从py的语法基说v?直接说说对django的心?

接触django首先需要了解可能就是他那个modelQ徏立一个model׃么都有了Q这对于搞java得h员来说还是挺有吸引力的(当然貌似对于动态语aq都是小儿科Q,那么让我们先看一个model的例子:

h了,直接拿django-admin里面的User出来?/p>


class User(models.Model): 
    username = models.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric])) 
    first_name = models.CharField(_('first name'), maxlength=30, blank=True) 
    last_name = models.CharField(_('last name'), maxlength=30, blank=True) 
    email = models.EmailField(_('e-mail address'), blank=True) 
    password = models.CharField(_('password'), maxlength=128)) 
    class Meta: 
        ordering = ('username',)

每个属性就是一个库表的字段Q定义v来非常简单明了,models里面提供了很多种cȝFieldcM上面的EmailField。不同的Field有不同的讄Q可以看相应的原来来了解相关的设|.

在model class内部q有一个class MetaQ这个Class的属性制定了q个表的一些存取策略,例如q里的ordering。MetaClass里面的属性可以用model的_meta属性取得。OKQ那么这样一个model怎么p实现Ҏ据库表的灉|操作了呢。让我们来看看吧?/p>

首先先分析一?django/django/db/models/base.pyq个文gQ其中包含了models.Modelq类的定义:

看看class定义的第一行吧Q第一行就够我琢磨一阵子的了Q?/p>


class Model(object):
    __metaclass__ = ModelBase

Model采用了new style class定义Q关于这个内容大家可以放狗看一下,W一行是一个__metaclass__属性的定义Q该属性的值是ModelBaseQ这是一个类。__metaclass__的意思是Q指定一个classQ这个class的实例就是本classQ相信您已经晕了。那么就拿这个Model的例子来说明一下,如果没有__metaclass__q个属性,产生一个实例就是正常的程Q有了这个属性流E会有改变:

首先调用BaseModel.__new__(cls, name, bases, attrs)q个ҎQ回q回的值是一个classcdQ然后用q个class来创建实例。其实BaseModel是Model的元c,来制定Modelq个cȝ最l样子。关于元cȝ更多信息Lq里

那么我们的目光一下{UdBaseModelq个cMQ我有种直觉QMetaq个class最后可以用_meta来取是在这里做的手脚,看一下BaseModel的定义吧Q有炚wQ?/p>


class ModelBase(type):
    "Metaclass for all models"
    def __new__(cls, name, bases, attrs):
        # If this isn't a subclass of Model, don't do anything special.
        if name == 'Model' or not filter(lambda b: issubclass(b, Model), bases):    #1
            return super(ModelBase, cls).__new__(cls, name, bases, attrs)

        # Create the class.
        new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})    #2
        new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))     #3
        new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))

        # Build complete list of parents                                      #4
        for base in bases:
            # TODO: Checking for the presence of '_meta' is hackish.
            if '_meta' in dir(base):
                new_class._meta.parents.append(base)
                new_class._meta.parents.extend(base._meta.parents)

        model_module = sys.modules[new_class.__module__]

        if getattr(new_class._meta, 'app_label', None) is None:
            # Figure out the app_label by looking one level up.
            # For 'django.contrib.sites.models', this would be 'sites'.
            new_class._meta.app_label = model_module.__name__.split('.')[-2]  #5

        # Bail out early if we have already created this class.
        m = get_model(new_class._meta.app_label, name, False)                 #6
        if m is not None:
            return m

        # Add all attributes to the class.
        for obj_name, obj in attrs.items():
            new_class.add_to_class(obj_name, obj)                             #7

        # Add Fields inherited from parents
        for parent in new_class._meta.parents:
            for field in parent._meta.fields:
                # Only add parent fields if they aren't defined for this class.
                try:
                    new_class._meta.get_field(field.name)
                except FieldDoesNotExist:
                    field.contribute_to_class(new_class, field.name)          #8

        new_class._prepare()

        register_models(new_class._meta.app_label, new_class)                 #9
        # Because of the way imports happen (recursively), we may or may not be
        # the first class for this model to register with the framework. There
        # should only be one class for each model, so we must always return the
        # registered version.
        return get_model(new_class._meta.app_label, name, False)              #10


单分析一下这个代码:

1. 查class是否为Model的子c,不是的话Q不做Q何处理,直接传给父类处理Q也q当于正常的处理了classQ注意super在多重承的时候应该严g?

2. 用type来创建类Q创建的是正常的ModelClass

3. q句很重要,add_to_class是Model里面的classҎQ这个方法其实就是传入name和valueQ给Modeldclass属?看到了,原来奇的_meta是q么来的. 提到add_to_classҎQ简单看一下它的代码:


    def add_to_class(cls, name, value):
        if name == 'Admin':
            assert type(value) == types.ClassType, "%r attribute of %s model must be a class, not a %s object" % (name, cls.__name__, type(value))
            value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_')]))
        if hasattr(value, 'contribute_to_class'):
            value.contribute_to_class(cls, name)
        else:
            setattr(cls, name, value)
    add_to_class = classmethod(add_to_class)


最后一句是制定q个Ҏ是classҎQ特点就是方法的W一个参数是本classQ其实classmethod是一个装饰器Q在2?之后可以使用@来简写。这里不得不提的是他对Admin的特D处理,虽然AdminOption不是在admin模块里面的,但是q么做还是跟一个Admin的东东绑定v来了Q在java的世界解耦是一件大事,看到下面q有?contribute_to_class'q个Ҏ的特D处理,django为啥不弄的解耦点呢。而且同样是包装成OptionQ一个是在BaseModel里面弄(那个Meta的包装)Q一个在add_to_classҎ里面弄,实在有点不优雅,可能q没了解太多Q不知道他的深度用意吧?/p>

4. Meta的集成,Option的这个类提供l承Ҏ

5. 取得applabelQ就是把model的名字分割取到数W二个,我很喜欢-2q样的设?/p>

6. get_modelҎ取得~存里面的东ѝ?/p>

7. 把所有的class attr拿出来搞一遍,一般的属性就setattr弄回MQ要是这个属性有contribute_to_classq个callable属性,那就执行之(Admin的处理完全也可以q样Q其实我们常用的objects是用这个方法弄的)

8. 每个Field调用自己的contribute_to_classҎ来进行特D的处理

9. q入~存Q,暂且叫缓存吧Q里面的东西大家看看很简?文g?/django/django/db/models/loading.py 里面q是有很多内容的

10.看注释说的很清楚了,我们一定要在缓存里面拿model?/p>

 

其中需要指出的是,new_class._prepare() q个ҎQ简单列出片D:


    def _prepare(cls):
        # Creates some methods once self._meta has been populated.
        opts = cls._meta
        opts._prepare(cls)

        Q.Q.

        dispatcher.send(signal=signals.class_prepared, sender=cls)

中间省略了一些代码,不是我没看懂的就是没意思的Q关键要看这个dispatcher呀。这里是监听者模式,dispatcher.send(signal=signals.class_prepared, sender=cls)放松了一个包含特定信L事gQ让监听的h可以做相应的处理。这L信号q有很多U,我们可以很简单的截获信号Q处理相应的内容。也许您q记得,在我们创建db的时候,会提C创Z个超U用P其实是用这个方法来弄的?/p>

那我Z么要把这个单独拿出来说呢Q因为监听这个事件的Z是别人,?objects"Q!Q在文g/django/django/db/models/manager.py的开头就有这L代码Q?/p>


def ensure_default_manager(sender):
    cls = sender
    if not hasattr(cls, '_default_manager'):
        # Create the default manager, if needed.
        try:
            cls._meta.get_field('objects')
            raise ValueError, "Model %s must specify a custom Manager, because it has a field named 'objects'" % cls.__name__
        except FieldDoesNotExist:
            pass
        cls.add_to_class('objects', Manager())

dispatcher.connect(ensure_default_manager, signal=signals.class_prepared)


定义了一个callableQ然后监听signals.class_prepared信号Q呵呵,q上了吧Q只要Class准备好了Q就调用q个Ҏ。简单判断有没有_default_manager'属性和meta里面的objects后,开始插入objects。cls.add_to_class('objects', Manager()) 很熟悉吧Q前面讲q不多说了?/p>

PSQ写到这里不由得感叹Qؓ啥同h往Class里面加入东东Q要搞这么多的花样呢Q我以前也写q一个Rails配置加蝲q程?a href="http://www.tkk7.com/sshwsfc/archive/2006/11/20/82401.html" target="_blank">分析文档Q虽然一个简单的加蝲配置把所有动态语a玩个遍,但是q也太不规范了吧Q可能不q么玩就不算“动?#8221;语言了吧Q哈哈?/p>

 

l于Model的Class造好了,怿大家以后造自qClass也能玩出更多的花栗那么可以开始下一步了。我到老家后再写吧Q打讲讲神奇的objectsQ也是ManagerQ其实就是玩QuerySet。。那里有很多的__xxx__ҎQ很好很强大



差沙 2008-02-02 17:32 发表评论
]]>
Android发布, Android中国|站正式成立, Ƣ迎讉Khttp://www.tkk7.com/sshwsfc/archive/2007/11/15/160736.html差沙差沙Thu, 15 Nov 2007 05:41:00 GMThttp://www.tkk7.com/sshwsfc/archive/2007/11/15/160736.htmlhttp://www.tkk7.com/sshwsfc/comments/160736.htmlhttp://www.tkk7.com/sshwsfc/archive/2007/11/15/160736.html#Feedback0http://www.tkk7.com/sshwsfc/comments/commentRss/160736.htmlhttp://www.tkk7.com/sshwsfc/services/trackbacks/160736.htmlAndroid是google为手机开发的操作pȝ, ZLinux2.6内核.


2007q?1?2?北美旉), Android的APP SDK公布, 开始了google手机?a class="external text" title="http://code.google.com/android" rel="nofollow">开发大?/a>. 我们致力于Android的开发文档翻? 开发技术交等工作, 希望为Androidq_在中国的推广贡献自己的力?


Andorid的SDK是完全针对java设计? 甚至提供eclipse的插? 作ؓ一个javaer不研I实在可?

现在中文文档已经有了初步q展,  大家译的热情都很高? 论坛里的讨论也十分热? Ƣ迎您的讉K.

我们的网? http://www.androidcn.net

中文文档计划:

http://www.androidcn.net/wiki

PS: 理员您? 不知道这个符不符合首发布的规则, 要是不妥我会撤下, 我们都想为Android中文化A献力?/span>

差沙 2007-11-15 13:41 发表评论
]]>
Ext的组件结构分?附Extlgl构?/title><link>http://www.tkk7.com/sshwsfc/archive/2007/10/20/154539.html</link><dc:creator>差沙</dc:creator><author>差沙</author><pubDate>Sat, 20 Oct 2007 12:01:00 GMT</pubDate><guid>http://www.tkk7.com/sshwsfc/archive/2007/10/20/154539.html</guid><wfw:comment>http://www.tkk7.com/sshwsfc/comments/154539.html</wfw:comment><comments>http://www.tkk7.com/sshwsfc/archive/2007/10/20/154539.html#Feedback</comments><slash:comments>25</slash:comments><wfw:commentRss>http://www.tkk7.com/sshwsfc/comments/commentRss/154539.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sshwsfc/services/trackbacks/154539.html</trackback:ping><description><![CDATA[     摘要: 怿大家看了Ext2.0? 印象最q应该是Ext的组件模?很好的规范了lg设计,用Manager的统一理,也是很好的方?下面单分析一下Ext的组件结?  <a href='http://www.tkk7.com/sshwsfc/archive/2007/10/20/154539.html'>阅读全文</a><img src ="http://www.tkk7.com/sshwsfc/aggbug/154539.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sshwsfc/" target="_blank">差沙</a> 2007-10-20 20:01 <a href="http://www.tkk7.com/sshwsfc/archive/2007/10/20/154539.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JBPM的Token路径问题http://www.tkk7.com/sshwsfc/archive/2007/04/24/113217.html差沙差沙Tue, 24 Apr 2007 08:04:00 GMThttp://www.tkk7.com/sshwsfc/archive/2007/04/24/113217.htmlhttp://www.tkk7.com/sshwsfc/comments/113217.htmlhttp://www.tkk7.com/sshwsfc/archive/2007/04/24/113217.html#Feedback1http://www.tkk7.com/sshwsfc/comments/commentRss/113217.htmlhttp://www.tkk7.com/sshwsfc/services/trackbacks/113217.htmlProcessInstance里面有一个findToken(String tokenPath)Ҏ。这里面写的是tokenPath?tokenPath跟文件系l的规则差不多。类?/fork1/fork2 q样的?br>
那么Q怎么到fork2下的一个分支token Q?br>
token自己也有findTokenq个ҎQ不同的是ProcessInstance的是以rootTokenv点,token自己的是以自׃ؓL。那么取到token2下面的分?br>
token2.findToken("token")
如果有返回tokenQ没有返回null


至于token的名字,我刚才查源码才发玎ͼ只有在Fork节点才会ltoken赋予名字。。?

那么token2.findToken("token") q里"token"那里?

命名的规则,如下。?nbsp;

    String tokenName = null;
    
if ( transitionName != null ) {
      
if ( ! parent.hasChild( transitionName ) ) {
        tokenName 
= transitionName;
      }
 else {
        
int i = 2;
        tokenName 
= transitionName + Integer.toString( i );
        
while ( parent.hasChild( tokenName ) ) {
          i
++;
          tokenName 
= transitionName + Integer.toString( i );
        }

      }

    }
 else // no transition name
      int size = ( parent.getChildren()!=null ? parent.getChildren().size()+1 : 1 );
      tokenName 
= Integer.toString(size);
    }

    
return tokenName; 



q里"token"那里来?q个token名字Q你自己可以Ҏ命名规则得到 。看到这里应该很明了?

token的命名规则;首先ҎtransitionName的名字命名,q个transitionName的名字是你自q写的你不可能不知道?如果transitionName的名字重名了Q加自然数区?当然Q如果transitionName没有名字Q用分支的个?1作ؓ名字?

应该比较清楚了?

PSQ这个是qq聊天记录的整理版Q所以说话比较诡异。ؓ的是记录下来避免忘记Q也感谢里的朋友。发C相解决问题是提高水^的一个捷径。?/p>

差沙 2007-04-24 16:04 发表评论
]]>
说说Rails吧,config的幕后工?/title><link>http://www.tkk7.com/sshwsfc/archive/2006/11/21/82487.html</link><dc:creator>差沙</dc:creator><author>差沙</author><pubDate>Tue, 21 Nov 2006 04:10:00 GMT</pubDate><guid>http://www.tkk7.com/sshwsfc/archive/2006/11/21/82487.html</guid><wfw:comment>http://www.tkk7.com/sshwsfc/comments/82487.html</wfw:comment><comments>http://www.tkk7.com/sshwsfc/archive/2006/11/21/82487.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.tkk7.com/sshwsfc/comments/commentRss/82487.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sshwsfc/services/trackbacks/82487.html</trackback:ping><description><![CDATA[ <p>说ruby是怪异的语法有点不妥当Q动态语a里面不乏q样的语法出现。但是看了一些源码后发现Q用ruby的用法真的各有不同,像大家以前说的Qruby每个人写出来的可能都不同?/p> <p>现来说Rails里面如何加蝲config的吧?/p> <p>在java里面configl对是一个resource文gQ然后通过d配置的工具加入进来,在分析处理?/p> <p>在ROR里面完全不是q么回事?/p> <p>1.首先大家要了解的是,在我们启?ruby script/server 的时候,rails做了一pd的处理,最后他执行?font face="Arial">environment.rb</font></p> <div id="xlfdbdn" class="code_title"> <em> <font color="#990033">ruby 代码</font> </em> <br /> </div> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #000000">Rails::Initializer.run do </span> <span style="COLOR: #000000">|</span> <span style="COLOR: #000000">config</span> <span style="COLOR: #000000">|</span> <span style="COLOR: #000000">    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  </span> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000"> q里能插入我们自q配置。   ?/span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">  </span> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000"> config. 之类    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">end   </span> </div> <p class="alt">q里的config其实是Initializer内部的一个变量,掌控全局的配|信息,我们可以使用q个config来配|我们想要的?span><span>Rails::Initializer.run的源码是q样的,yield再一ơ显CZ他的威力Q让我们在配|文件中得以配置config。然后实例化了一个initializer 之后Q把config作ؓ参数传入了?/span></span></p> <div id="rvbrddn" class="code_title"> <em> <font color="#990033">ruby 代码</font> </em> <br /> </div> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff">def</span> <span style="COLOR: #000000"> self.run(command </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> :process, configuration </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> Configuration.new)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  </span> <span style="COLOR: #0000ff">yield</span> <span style="COLOR: #000000"> configuration </span> <span style="COLOR: #0000ff">if</span> <span style="COLOR: #000000"> block_given?    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  initializer </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> new configuration    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  initializer.send(command)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  initializer    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end   </span> </div> <p class="alt">我们接着往下走Q可以看到initializer 做了一pd的初始化工作Q包括load_path的设定,路由的初始化Q和activerecord的初始化。我们关心的q是配置如何起作用,那么来看?font face="Arial">environments目录下面的配|文件是如何导入的吧?/font></p> <div id="dxxtldp" class="code_title"> <em> <font color="#990033">ruby 代码</font> </em> </div> <div id="llthnnf" class="dp-highlighter"> <div id="nfrnhxn" class="bar"> </div> </div> <p> <span id="vxhdxdv" class="builtin"> </span> </p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff">def</span> <span style="COLOR: #000000"> load_environment    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  silence_warnings do   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    config </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> configuration    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    constants </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> self.</span> <span style="COLOR: #0000ff">class</span> <span style="COLOR: #000000">.constants    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    eval(IO.read(configuration.environment_path), binding)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    (self.</span> <span style="COLOR: #0000ff">class</span> <span style="COLOR: #000000">.constants </span> <span style="COLOR: #000000">-</span> <span style="COLOR: #000000"> constants).each do </span> <span style="COLOR: #000000">|</span> <span style="COLOR: #000000">const</span> <span style="COLOR: #000000">|</span> <span style="COLOR: #000000">    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />      Object.const_set(const, self.</span> <span style="COLOR: #0000ff">class</span> <span style="COLOR: #000000">.const_get(const))    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span> </div> <p>IO<span>.read(configuration.environment_path) Q,q里׃使用什么回调不回调了,而是q脆IO拿出来eval一把,q里也是吃了一惊,q样也可以呀~~~~~~~然后Q我们可以看看,他处理常量的ҎQ把自己配置文g中的帔R全部攑օObject里面Qv到全局帔R的目的?/span></p> <p> <span>最l的q是<font face="Arial">initialize_framework_settingsQ用了有一个ruby的技巧?/font></span> </p> <span> <div id="nxjvpfv" class="code_title"> <em> <font color="#990033">ruby 代码</font> </em> </div> <div id="ppbnzpf" class="bar"> </div> <p class="alt"> </p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff">def</span> <span style="COLOR: #000000"> initialize_framework_settings    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  configuration.frameworks.each do </span> <span style="COLOR: #000000">|</span> <span style="COLOR: #000000">framework</span> <span style="COLOR: #000000">|</span> <span style="COLOR: #000000">    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    base_class </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> framework.to_s.camelize.constantize.const_get(</span> <span style="COLOR: #800000">"</span> <span style="COLOR: #800000">Base</span> <span style="COLOR: #800000">"</span> <span style="COLOR: #000000">)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    configuration.send(framework).each do </span> <span style="COLOR: #000000">|</span> <span style="COLOR: #000000">setting, value</span> <span style="COLOR: #000000">|</span> <span style="COLOR: #000000">    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />      base_class.send(</span> <span style="COLOR: #800000">"</span> <span style="COLOR: #800000">#{setting}=</span> <span style="COLOR: #800000">"</span> <span style="COLOR: #000000">, value)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end   </span> </div> <p>configuration.frameworks里面存放的是rails个个lg的名字,比方说active_record之类。然后把q个名字大写转换Q然后用constantize取得ActiveRecordq个Module(注意Q这些东襉K在activesupport里面呢,activesupport/lib/active_support/core_ext/string/inflections.rb )。然后用const_get取得q个模块的Basec,也就是ActiveRecord::Baseq个cMQ下面都叫做Basec)Q所有的Rails的组仉是这个命名规则改天我们自己想要做一个Rails的组件加q来Q也可以q样Q但是要E微修改一个源码)?/p> <p>然后Q我们吧config里面的内容给BasecRconfiguration.send(framework)是调用一个组件名U的ҎQ比方说active_recordQ就是去的config里面的active_record属性(q是最基本的)Q通过后面的do我们可以看到configq回的是一个hashQ然后把hash中每一个key作ؓ变量QvalueZ入|传入BasecR。。这里大家应该没什么问题了Q看看我们的config文g是怎么写的吧?/p> <div id="bbnrjzh" class="code_title"> <em> <font color="#990033">ruby 代码</font> </em> <br /> </div> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000"> Settings specified here will take precedence over those in config/environment.rb    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000"> In the development environment your application's code is reloaded on    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />#</span> <span style="COLOR: #008000"> every request.  This slows down response time but is perfect for development    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />#</span> <span style="COLOR: #008000"> since you don't have to restart the webserver when you make code changes.    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">config.cache_classes </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> false   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000"> Log error messages when you accidentally call methods on nil.    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">config.whiny_nils </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> true   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000"> Enable the breakpoint server that script/breakpointer connects to    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">config.breakpoint_server </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> true   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000"> Show full error reports and disable caching    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">config.action_controller.consider_all_requests_local </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> true   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />config.action_controller.perform_caching             </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> false   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />config.action_view.cache_template_extensions         </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> false   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />config.action_view.debug_rjs                         </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> true   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000"> Don't care if the mailer can't send    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">config.action_mailer.raise_delivery_errors </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> false   </span> </div> <p class="alt">哦,看着很晕吧,config是我们的配|对象,按照我们上面的说法,config.action_view之类framework的变量应该是一个hash才对呀Q如果是hash的话Q不应该用这L方式传入Q可能会?config.action_view = {:debug_rjs => true}来传入?/p> <p>OK.我们来看q个变量到底是什么样的hash?/p> <div id="rrdptbh" class="code_title"> <em> <font color="#990033">ruby 代码</font> </em> </div> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff">def</span> <span style="COLOR: #000000"> initialize    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <img src="http://www.tkk7.com/images/dot.gif" />.    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  <img src="http://www.tkk7.com/images/dot.gif" />.    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  </span> <span style="COLOR: #0000ff">for</span> <span style="COLOR: #000000"> framework </span> <span style="COLOR: #0000ff">in</span> <span style="COLOR: #000000"> default_frameworks    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    self.send(</span> <span style="COLOR: #800000">"</span> <span style="COLOR: #800000">#{framework}=</span> <span style="COLOR: #800000">"</span> <span style="COLOR: #000000">, OrderedOptions.new)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end   </span> </div> <p class="alt">在初始化q些变量的时候,Railsl他赋gؓOrderedOptions.<span id="ldztnld" class="keyword">new。这个特D的cd可能是关键?/span></p> <span id="zlnrltr" class="keyword"> <div id="dfrtvvb" class="code_title"> <em> <font color="#990033">ruby 代码</font> </em> <br /> </div> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff">class</span> <span style="COLOR: #000000"> OrderedOptions </span> <span style="COLOR: #000000"><</span> <span style="COLOR: #000000"> OrderedHash </span> <span style="COLOR: #008000">#</span> <span style="COLOR: #008000">:nodoc:    </span> <span style="COLOR: #008000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">  </span> <span style="COLOR: #0000ff">def</span> <span style="COLOR: #000000"> []</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">(key, value)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    super(key.to_sym, value)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />      <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  </span> <span style="COLOR: #0000ff">def</span> <span style="COLOR: #000000"> [](key)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    super(key.to_sym)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  </span> <span style="COLOR: #0000ff">def</span> <span style="COLOR: #000000"> method_missing(name, </span> <span style="COLOR: #000000">*</span> <span style="COLOR: #000000">args)    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    </span> <span style="COLOR: #0000ff">if</span> <span style="COLOR: #000000"> name.to_s </span> <span style="COLOR: #000000">=~</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">/</span> <span style="COLOR: #000000">(.</span> <span style="COLOR: #000000">*</span> <span style="COLOR: #000000">)</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">$</span> <span style="COLOR: #000000">/</span> <span style="COLOR: #000000">    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />      self[$</span> <span style="COLOR: #000000">1</span> <span style="COLOR: #000000">.to_sym] </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> args.first    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    </span> <span style="COLOR: #0000ff">else</span> <span style="COLOR: #000000">   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />      self[name]    <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  end   <br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end   </span> </div> <p class="alt">看到其中的玄妙了么,method_missing~~~Q! 如果调用一?*=的方?Q就像当用传入一个HASH的|key是Ҏ的名字?/p> <p>也就是:<span>config.action_view.debug_rjs  = </span><span id="zbnhbjx" class="keyword">true</span><span> 相当?span>config.action_view[:debug_rjs] = true</span></span></p> <p> <span> <span>OK Q大体上描述了一下,可以看到单的一个Rails初始化已l给我们展示了几乎全部ruby的靓丽之处,q能说明Q这个亮点肯定是贯穿rails的基本,在以后的深入研究中我们就能看C?/span> </span> </p> </span> </span> <img src ="http://www.tkk7.com/sshwsfc/aggbug/82487.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sshwsfc/" target="_blank">差沙</a> 2006-11-21 12:10 <a href="http://www.tkk7.com/sshwsfc/archive/2006/11/21/82487.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>说说Rails吧,启动开始?/title><link>http://www.tkk7.com/sshwsfc/archive/2006/11/20/82401.html</link><dc:creator>差沙</dc:creator><author>差沙</author><pubDate>Mon, 20 Nov 2006 15:43:00 GMT</pubDate><guid>http://www.tkk7.com/sshwsfc/archive/2006/11/20/82401.html</guid><wfw:comment>http://www.tkk7.com/sshwsfc/comments/82401.html</wfw:comment><comments>http://www.tkk7.com/sshwsfc/archive/2006/11/20/82401.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/sshwsfc/comments/commentRss/82401.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/sshwsfc/services/trackbacks/82401.html</trackback:ping><description><![CDATA[ <p>Z记录自己看Rails源码的过E,全程记录无废话?br /><br />我们看看script/server都干了什?/p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #000000">require File.dirname(__FILE__) </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">'</span> <span style="COLOR: #000000">/../config/boot</span> <span style="COLOR: #000000">'</span> <span style="COLOR: #000000"> <br /> <img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />require </span> <span style="COLOR: #000000">'</span> <span style="COLOR: #000000">commands/server</span> <span style="COLOR: #000000">'</span> </div> <br />引用了boot.rbq个文g。看来这个文件是rails启动的入口,来看看怎么回事吧?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">unless defined?(RAILS_ROOT)<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  root_path </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> File.join(File.dirname(</span><span style="COLOR: #800080">__FILE__</span><span style="COLOR: #000000">), </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">..</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">)<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  unless RUBY_PLATFORM </span><span style="COLOR: #000000">=~</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">mswin32</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    require </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">pathname</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    root_path </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Pathname.new(root_path).cleanpath(true).to_s<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  end<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  RAILS_ROOT </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> root_path<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end</span></div>q一部分定义了RAILS_ROOTq个pȝ的全局变量Q指定了目的根目录Q大家可以在以后华丽的用了?br /><br />下一部分是找到railsQ粗略看一下?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> File.directory?(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">#{RAILS_ROOT}/vendor/rails</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">)<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    require </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">#{RAILS_ROOT}/vendor/rails/railties/lib/initializer</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    require </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">rubygems</span><span style="COLOR: #800000">'</span></div>q里能看刎ͼ他先跑到<font color="#800000">vendor/rails<font color="#000000">Lrails了,q就是我们ؓ什么能在插仉用rails是原因。如果没有那么gems的干zR?br />接下来是初始化一下load_pathQ没什么看的了。boot.rbpL吧?br /><br />回到script/server的第二行Q包含了<span style="COLOR: #000000">'</span><span style="COLOR: #000000">commands/server</span><span style="COLOR: #000000">'q个文gQ这个文件是什么?Rails的源码里面找吧。我们在Rails的源码里面找到这个文件?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">require </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">active_support</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />require </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">fileutils</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />begin<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  require_library_or_gem </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">fcgi</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />rescue Exception<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  </span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> FCGI not available</span><span style="COLOR: #008000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">end<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />server </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> case ARGV.first<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  when </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">lighttpd</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    ARGV.shift<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  when </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">webrick</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    ARGV.shift<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> RUBY_PLATFORM !</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">mswin</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000"> !silence_stderr { `lighttpd </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">version` }.blank? </span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000"> defined?(FCGI)<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />      </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">lighttpd</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />      </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">webrick</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />    end<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> server </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">webrick</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  puts </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">=> Booting WEBrick<img src="http://www.tkk7.com/images/dot.gif" /></span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  puts </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">=> Booting lighttpd (use 'script/server webrick' to force WEBrick)</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />FileUtils.mkdir_p(</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">w( tmp</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">sessions tmp</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">cache tmp</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">sockets ))<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />require </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">commands/servers/#{server}</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span></div></span></font></font>没想到ActiveRecord居然是在q里引用的,q个ActiveRecord里面扩展了很对Ruby的既有类型,所以我们看源码的时候如果发现有不熟悉的ҎQ就来这里找找,当然Q看Rails的API是最好的选择?br /><br />从参C目了Ӟ我们可以传入server的名字,<span style="COLOR: #800000">lighttpd?span style="COLOR: #800000">webrick<font color="#000000">Q根据不同的server选择不同的server文g来读取。我们还是看?span style="COLOR: #800000">webrick<font color="#000000">的吧?br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">require </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">webrick</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />require </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">optparse</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />OPTIONS </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> {<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :port            </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3000</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :ip              </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">0.0.0.0</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :environment     </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> (ENV[</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">RAILS_ENV</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">development</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">).dup,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :server_root     </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> File.expand_path(RAILS_ROOT </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">/public/</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">),<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :server_type     </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> WEBrick::SimpleServer,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :charset         </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">UTF-8</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :mime_types      </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> WEBrick::HTTPUtils::DefaultMimeTypes<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />ARGV.options do </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000">opts</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  script_name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> File.basename($0)<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.banner </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Usage: ruby #{script_name} [options]</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.separator </span><span style="COLOR: #800000">""</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.on(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">-p</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">--port=port</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, Integer,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Runs Rails on the specified port.</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Default: 3000</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">) { </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000">v</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> OPTIONS[:port] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> v }<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.on(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">-b</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">--binding=ip</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, String,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Binds Rails to the specified ip.</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Default: 0.0.0.0</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">) { </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000">v</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> OPTIONS[:ip] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> v }<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.on(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">-e</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">--environment=name</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, String,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Specifies the environment to run this server under (test/development/production).</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Default: development</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">) { </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000">v</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> OPTIONS[:environment] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> v }<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.on(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">-m</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">--mime-types=filename</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, String,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />                  </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Specifies an Apache style mime.types configuration file to be used for mime types</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />                  </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Default: none</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">) { </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000">mime_types_file</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> OPTIONS[:mime_types] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> WEBrick::HTTPUtils::load_mime_types(mime_types_file) }<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.on(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">-d</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">--daemon</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Make Rails run as a Daemon (only works if fork is available -- meaning on *nix).</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          ) { OPTIONS[:server_type] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> WEBrick::Daemon }<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.on(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">-c</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">--charset=charset</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, String,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Set default charset for output.</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Default: UTF-8</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">) { </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000">v</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> OPTIONS[:charset] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> v }<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.separator </span><span style="COLOR: #800000">""</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.on(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">-h</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">--help</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />          </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Show this help message.</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">) { puts opts; exit }<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  opts.parse!<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />end<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />ENV[</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">RAILS_ENV</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> OPTIONS[:environment]<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />RAILS_ENV.replace(OPTIONS[:environment]) </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> defined?(RAILS_ENV)<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />require RAILS_ROOT </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">/config/environment</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />require </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">webrick_server</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />OPTIONS[</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">working_directory</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> File.expand_path(RAILS_ROOT)<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />puts </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />puts </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">=> Ctrl-C to shutdown server; call with --help for options</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> OPTIONS[:server_type] </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> WEBrick::SimpleServer<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />DispatchServlet.dispatch(OPTIONS)<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" /></span></div></font></span></font></span></span>本来不想把大D늚代码贴上来,但是q里面的内容可能大家都比较关心,涉及到server的启动参数?br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :port            <span style="COLOR: #000000">=></span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">端口</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :ip              </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> server ip</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :environment     </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000">q行环境</span><span style="COLOR: #000000">,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :server_root     </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> web讉K的目录,Q很多h问这个怎么改)</span><span style="COLOR: #000000"><br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :server_type     </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> WEBrick::SimpleServer,<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :charset         </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">UTF-8</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, ~码<br /><img src="http://www.tkk7.com/images/OutliningIndicators/None.gif" align="top" />  :mime_types      </span><span style="COLOR: #000000">=></span><span style="COLOR: #000000"> WEBrick::HTTPUtils::DefaultMimeTypes<br /><br />后面的require 引入了两个文Ӟ一个是<span style="COLOR: #800000">'</span><span style="COLOR: #800000">webrick_server</span><span style="COLOR: #800000">'<font color="#000000">Q别看,是他。另外一个是</font><font color="#800000">config/environment</font><font color="#000000">Q这个文件是pȝ的全局配置文gQ很重要Q我们还是下ơ看看这个文件去吧。里面还真挺有意思?br /><br />Q不知道blogjava让不让写ROR的文章,看到有h写了所以放在首了Q如果不妥,我会快删除Q?/font></span></span><img src ="http://www.tkk7.com/sshwsfc/aggbug/82401.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/sshwsfc/" target="_blank">差沙</a> 2006-11-20 23:43 <a href="http://www.tkk7.com/sshwsfc/archive/2006/11/20/82401.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>U逗的JBPMhttp://www.tkk7.com/sshwsfc/archive/2006/08/24/65446.html差沙差沙Thu, 24 Aug 2006 03:07:00 GMThttp://www.tkk7.com/sshwsfc/archive/2006/08/24/65446.htmlhttp://www.tkk7.com/sshwsfc/comments/65446.htmlhttp://www.tkk7.com/sshwsfc/archive/2006/08/24/65446.html#Feedback7http://www.tkk7.com/sshwsfc/comments/commentRss/65446.htmlhttp://www.tkk7.com/sshwsfc/services/trackbacks/65446.html
U?。无中生?/strong>

看到最核心的JpdlXmlReader代码真实Ʋ哭无泪Q如果好好精_Q至能t掉1/3的代码。而其中甚x些无中生有的代码Q?br />
if ( (actorId!=null)
           
|| (pooledActors!=null
         ) 
{
        assignmentDelegation.setProcessDefinition(processDefinition);
        assignmentDelegation.setClassName(
"org.jbpm.taskmgmt.assignment.ActorAssignmentHandler");
        String configuration 
= "";
我们看到Q如果符合之前的条gQ就用代理类来代?span style="COLOR: #000000">org.jbpm.taskmgmt.assignment.ActorAssignmentHandlerq个c,但是找了好半天也没有扑ֈq个cR。。?N是让用户在自q目中用q个cMQ还是ؓ了兼容原来的E序Q,q是其中一U,但是Q可但是Q这个条件根本就不可能满I也就是说q是D废话,而且q无中生有的出来个ActorAssignmentHandler。?br />
U?。画蛇添?/strong>

应该是我的基本功不都扎实Q实在是高不明白下面的代码在q什么。。?br />
  public void setActorId(String actorId) {
    DefaultAuthenticationService authenticationService 
= (DefaultAuthenticationService) services.getAuthenticationService();
    DefaultAuthenticationService defaultAuthenticationService 
= (DefaultAuthenticationService) authenticationService;
    defaultAuthenticationService.setActorId(actorId);
  }
先强制{换成DefaultAuthenticationServiceQ然后再强制转换成DefaultAuthenticationService。。。?br />而且q里q么设计基本上就把DefaultAuthenticationService实现的AuthenticationService接口晑֜那里了,Ҏ是应该用AuthenticationServiceq个接口来说话才寏Vjbpm的service设计的扩展性很强,可自己配制。但如果q么用service的话Q再怎么扩展也没用?br />
U?。莫“名”其?/strong>

Jbpm中变量的名字真的莫名其妙Q很多明明是Map的类型他叫xxListQ而不是Map的类型,他却叫xxMap。这个地Ҏ怿应该是能体现出程序员~写E序的严谨性的地方Q而Jbpm作的q不够好?br />
U?。固若金?/strong>

Jbpm的扩展性诏I始l,但是在最重要的泳道的扩展上却家子气h。看看泳道类代理的扩展代码?br />
if (expression!=null){
        assignmentDelegation.setProcessDefinition(processDefinition);
        assignmentDelegation.setClassName(
"org.jbpm.identity.assignment.ExpressionAssignmentHandler");
        assignmentDelegation.setConfiguration(
"<expression>"+expression+"</expression>");
      
    }
写的很明,如果泳道使用表达式来表示的那么就用代理类来代理处理表辑ּ。。我本想Q太好了Q写我自q表达式,然后代理交给Acegi来根据表辑ּ分配ActorIdQ但是,可是Q但可是。他的代理类居然是写ȝQ写得就是自qjava.identity包里面的东西Q不是说java.identity设计的不好,但是一个综合系l的用户角色理pȝ是不可能跟着你的jbpm走的。强行要加入的java.identity的设计有点保护自我的意思,真的金汤Q让我结合acegi的想法又是难上加难。(不过q是有办法的。大家自己找扄Q?br />
U?。口径不一

口径不一是指两个程序部分的l合不一致。这U例子很多,我D一个程序和xsd的冲H的例子?br />Instantiator是jbpm代理里面一个比较不错的概念。代理功能之一是生成代理的cȝ实例Q而Instantiator则是负责生成实例的机Ӟq个Instantiator设计的不错,可以在配制文件中的config-type属性来扩展。看E序?br />
      // find the instantiator
      instantiator = (Instantiator) instantiatorCache.get(configType);
      
if (instantiator == null{
        
// load the instantiator class
        Class instantiatorClass = classLoader.loadClass(configType);
        
// instantiate the instantiator with the default constructor
        instantiator = (Instantiator) instantiatorClass.newInstance();
        instantiatorCache.put(configType, instantiator);
      }
q里的设计很人性化Q可以根据configType来用自己的构造器Q但是xsd却不q么惟?br />
      <xs:attribute name="config-type" default="field">
        
<xs:simpleType>
          
<xs:restriction base="xs:string">
            
<xs:enumeration value="field"/>
            
<xs:enumeration value="bean"/>
            
<xs:enumeration value="constructor"/>
            
<xs:enumeration value="configuration-property"/>
          
</xs:restriction>
        
</xs:simpleType>
      
</xs:attribute>
可以看到它限制了4U类型,别说使用自己的构造器了,p他自qXmlInstantiator都不再考虑范围之内Q真是大义灭亲呀。?br />
构造器来这里的作用很大Q我写了自己的spring构造器Q构造的时候用beanFactory来构造,q样q是存在数据库里面的class也能当作spring的bean来处理。但是如果用xsd的话׃D交验错误Q所以烦性把xsdL了,q好一切正常,是感觉别扭炏V?br />
U逗N。。?能够看得出来Jbpm需要提高的地方q很多。但是这些问题应该是一些开发h员的疏忽,怿在以后的版本中可以改q。不再怎么U逗,Jbpm在工作流中仍然保有着强劲的地位,对BPM模型的实C作的最为全面。而jbpm的par热部|和IDE也是整个pȝ中的两大亮点Q这些优炚w是不可不提的Q所以我仍旧支持JbpmQ希望他能更加迅速的发展壮大h。。。?br />
PSQ文中错误之处还望大家指出,我希望有些“秀逗”是我自q逗了?img src ="http://www.tkk7.com/sshwsfc/aggbug/65446.html" width = "1" height = "1" />

差沙 2006-08-24 11:07 发表评论
]]>
վ֩ģ壺 91߹ۿ| ޸һ| avպavav| ձһձһ岻 | aëƬѹۿƵ| ޾Ʒһ| ˬָ߳ëƬѿ| þþƷר| ͵ԾƷʮ| ޾ҹþþþþ| ܻƺܻƵվѵ| ëƬѹۿȫ| ҹþþþþ| þù޾ƷӰԺ| 91ƷӾʢ| ѹۿ| 㽶߹ۿ| ޾Ʒþþþ| ѹۿŮվ| þþƵ| Ƶվ߲| þþþ޾Ʒ| www.91| ëƬۿ| ߹ۿƵ| þþƷav٤| ҹһ| ƷۺϾþĻ| 19ѹۿ| 67194츾ѹۿ| aëƬƵ| ɪɪվվ| ձ޾ƷɫӰԺ| ޴ŮAVպƷ| ޾Ʒ岻| ѻɫһëƬ| 㻨ۿ| 99re߾ƷƵ| avվyy| VƬ߹ۿ| ͵͵޸|