[PEAK] Re: first draft of a webdemo
Phillip J. Eby
pje at telecommunity.com
Thu Feb 26 19:27:49 EST 2004
At 12:41 AM 2/27/04 +0100, Ulrich Eck wrote:
> > > > [Files *.pwt]
> > > > file_factory = xslskins.StyleWrapperFactory(
> > > > style_pattern="%s_style",
> > > > factory="peak.web.resources.TemplateResource" )
>
>are you sure that this is possible a.t.m ??
>
>[snippet from ResourceDirectory::__getitem__]
>
> # look up factory for name
> path = os.path.join(self.filename, filename)
> if os.path.isdir(path):
> factory = DIR_FACTORY.of(self)[prop]
> else:
> factory = FILE_FACTORY.of(self)[prop]
>
> # create a reference, and dereference it
> ref = naming.Reference(factory,
>addresses=[FileURL.fromFilename(path)])
> obj = ref.restore(self,None)
> obj.setParentComponent(self, filename)
> self.cache[name] = obj
> return obj
Aagh. I forgot that I did it this way.
>a naming.Reference takes a factoryName as first argument,
>that is restored like this:
>
> def restore(self, context, name):
> factory = importObject(FACTORY_PREFIX.of(context)[self.factoryName])
> factory = adapt(factory, IObjectFactory)
> return factory.getObjectInstance(context, self, name)
>
>i haven't tried it, but i assume that your example would break with a
>key-error for peak.naming.schemes.<instance of StyleWrapperFactory>
>
>am i right ?
Yes, you are. I'm going to have to fix this. I'm not sure how, yet. I
can't really make Reference() take a non-string, because the point of a
reference is to be persistable/serializable in a simple format. On the
other hand, I don't want to create a whole new factory interface just for
resources, so I'd still like to be able to use Reference().
What I may do is change ResourceDirectory to check whether 'factory'
supports naming.IObjectFactory, and if so, use it directly instead of
asking the reference to restore itself. Maybe there should be a naming API
to do that, since this seems a use case that will appear other places.
More information about the PEAK
mailing list