示例#1
0
文件: gwt.py 项目: jrydberg/edgy
def registerRemoteClass(cls, remoteName=None, superClassName=None):
    """
    Register class C{cls} so that it can be identified as remote class
    C{remoteName}.
    """
    if remoteName is None:
        try:
            remoteName = cls.__remote_name__
        except AttributeError:
            pass
    if remoteName is None:
        raise Exception("remote name wasn't specified")

    _superType = None
    bases = cls.__bases__
    if len(bases) != 0:
        superClassNames = list()
        if superClassName is not None:
            superClassNames.append(superClassName)
        for base in bases:
            if base in classRegistry:
                superClassNames.append(classRegistry[base])
        if superClassNames:
            superClass = annotation.getTypeClassByTypeName(
                superClassNames[0]
                )
            _superType = superClass()
    else:
        _superType = annotation.Object()

    classRegistry[cls] = remoteName
    #print "superType", _superType
    
    class type_class(annotation.Type):
        @staticmethod
        def getTypeName():
            return remoteName
        superType = _superType

    annotation.registerTypeClass(type_class)

    
    attributes = {}
    for attribute in getAttributes(cls, recurse=False):
        attributes[attribute.name] = attribute

    print "class", remoteName, "has attributes", attributes.keys()

    class protocol_class(object):
        @staticmethod
        def names():
            return sorted(attributes.keys())
        @staticmethod
        def get(name):
            return annotation.RemoteAttribute(
                igwt.IType(attributes[name]))
    #annotation.typeProtocolRegistry.register(cls, protocol_class)
    annotation.registerTypeProtocol(type_class, protocol_class)

    class factory_class(object):
        def __init__(self, protocol_class):
            pass
        def buildInstance(self):
            return cls(_do_not_finalize=True)
    components.registerAdapter(factory_class, type_class,
                               igwt.IInstanceFactory)
    annotation.registerTypeAdapter(type_class, cls)
示例#2
0
文件: binder.py 项目: jrydberg/edgy
 def _gatherModelAttributes(self, obj):
     mas = {}
     for ma in getAttributes(obj.__class__, recurse=True):
         mas[ma.name] = ma
     return mas