def callback(instanceClass): class InstanceFactory: def __init__(self, protocolClass): pass def buildInstance(self): return instanceClass() components.registerAdapter(InstanceFactory, typeClass, igwt.IInstanceFactory) annotation.registerTypeAdapter(typeClass, instanceClass) return instanceClass
""" implements(IChange) class ChangeType(annotation.Object): superType = annotation.Object() def getTypeName(self): """Return type name. """ return 'test.Change' annotation.registerTypeProtocol(ChangeType, IChange) # register the type so that adaptation to IType works annotation.registerTypeAdapter(ChangeType, Change) class IFuture(IChange): baz = annotation.RemoteAttribute(annotation.Short(), "baz") xy = annotation.RemoteAttribute(annotation.Integer(), "xy") class FutureType(annotation.Object): superType = ChangeType() def getTypeName(self): """Return type name. """ return 'test.Future'
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)