Back to index

plone3  3.1.7
Classes | Functions | Variables
Archetypes.ApeSupport Namespace Reference

Classes

class  ArcheSerializer
class  RemainingState

Functions

def AtType2ApeType
def AtSchema2ApeSchema
def constructGateway
def constructSerializer
def ec_issubclass
def ec_isinstance

Variables

dictionary typemap

Detailed Description

\
Bring generic Ape Support to Archetypes.

The goal of this module is to implement generic mapping of Archetypes Schema
to real tables with real columns for each field in the schema.

**Experimental**

This code works with Ape 1.0

Whats working so far:

 - The following types are handled so far:

  - string,

  - int.

Whats not working so far:

 - References,images are not yet supported

 - Renaming of objects generates errors

ArchGenXML has support for APE:

 When you invoke ArchGenXML with the option --ape-support the outline_od.xmi
 sample works with APE correctly all ape_config and the serializer/gateway
 stuff is generated for you.
 
ApeSupport is tested with Ape 1.0 and PostgreSQL

Function Documentation

Definition at line 78 of file ApeSupport.py.

00078 
00079 def AtSchema2ApeSchema(atschema):
00080     schema=RowSequenceSchema()
00081     column_defs=[]
00082     for f in atschema.fields():
00083         if f.isMetadata:
00084             continue
00085         pk=0
00086         name = f.getName()
00087         t = AtType2ApeType(f)
00088         if not t: # then dont add it to the schema
00089             continue
00090         if name=='id':pk=1
00091         schema.add(name, t, pk)
00092         column_defs.append((name,t,pk))
00093 
00094     #print schema,tuple(column_defs)
00095     return schema,tuple(column_defs)
00096 
00097 # creates a generic gateway instance based on
# the klass's Schema

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 65 of file ApeSupport.py.

00065 
00066 def AtType2ApeType(f):
00067     t=f._properties['type']
00068     if t=='reference':
00069         #print 'REF:',f.getName(),f.multiValued
00070         if f.multiValued:
00071             return 'string'
00072         else:
00073             return 'string'
00074     if t=='computed':
00075         return None
00076 
00077     return typemap.get(t,t)

Here is the caller graph for this function:

Definition at line 98 of file ApeSupport.py.

00098 
00099 def constructGateway(klass):
00100     table_name = klass.__name__.lower()
00101     schema, column_defs = AtSchema2ApeSchema(klass.schema)
00102     res=SQLFixedProperties('db', table_name, schema)
00103     return res
00104 
00105 # creates a generic serializer instance based on
# the klass's Schema

Here is the call graph for this function:

Definition at line 106 of file ApeSupport.py.

00106 
00107 def constructSerializer(klass):
00108     res=ArcheSerializer()
00109     res.klass=klass
00110     res.schema=AtSchema2ApeSchema(klass.schema)[0]
00111     return res
00112 
00113 
00114 # generic Serializer class
# which reflects the class's Schema

Here is the call graph for this function:

def Archetypes.ApeSupport.ec_isinstance (   object,
  klass 
)
A version of 'isinstance' that works with extension classes
as well as regular Python classes.

Definition at line 291 of file ApeSupport.py.

00291 
00292 def ec_isinstance (object, klass):
00293     """A version of 'isinstance' that works with extension classes
00294     as well as regular Python classes."""
00295 
00296     if type(klass) is ClassType:
00297         return isinstance(object, klass)
00298     elif hasattr(object, '__class__'):
00299         return ec_issubclass(object.__class__, klass)
00300     else:
00301         return 0

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ApeSupport.ec_issubclass (   class1,
  class2 
)
A version of 'issubclass' that works with extension classes
as well as regular Python classes.

Definition at line 252 of file ApeSupport.py.

00252 
00253 def ec_issubclass (class1, class2):
00254     """A version of 'issubclass' that works with extension classes
00255     as well as regular Python classes.
00256     """
00257 
00258     # Both class objects are regular Python classes, so use the
00259     # built-in 'issubclass()'.
00260     if type(class1) is ClassType and type(class2) is ClassType:
00261         return __builtin__.issubclass(class1, class2)
00262 
00263     # Both so-called class objects have a '__bases__' attribute: ie.,
00264     # they aren't regular Python classes, but they sure look like them.
00265     # Assume they are extension classes and reimplement what the builtin
00266     # 'issubclass()' does behind the scenes.
00267     elif hasattr(class1, '__bases__') and hasattr(class2, '__bases__'):
00268         # XXX it appears that "ec.__class__ is type(ec)" for an
00269         # extension class 'ec': could we/should we use this as an
00270         # additional check for extension classes?
00271 
00272         # Breadth-first traversal of class1's superclass tree.  Order
00273         # doesn't matter because we're just looking for a "yes/no"
00274         # answer from the tree; if we were trying to resolve a name,
00275         # order would be important!
00276         stack = [class1]
00277         while stack:
00278             if stack[0] is class2:
00279                 return 1
00280             stack.extend(list(stack[0].__bases__))
00281             del stack[0]
00282         else:
00283             return 0
00284 
00285     # Not a regular class, not an extension class: blow up for consistency
00286     # with builtin 'issubclass()"
00287     else:
00288         raise TypeError, "arguments must be class or ExtensionClass objects"
00289 
00290 # ec_issubclass ()

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 {
00002     'text':'string',
00003     'datetime':'string',
00004     'boolean':'int',
00005     'integer':'int',
00006     #'reference':'string:list',
00007     'computed':'string' #ouch!!
00008 }

Definition at line 56 of file ApeSupport.py.