[stringtemplate-interest] Composing Model Adapters
Terence Parr
parrt at cs.usfca.edu
Tue May 3 16:46:32 PDT 2011
Hi Collin,It's probably okay; to make it go faster, make sure that OMA it is throwing the same exception object over and over. stack trace creation is very expensive.
Ter
On Apr 17, 2011, at 11:55 AM, Collin Fagan wrote:
> Hi Everyone,
>
> As I've been working on Strum I have run into the reoccurring question of 'Should this model adapter inherit from ObjectModelAdapter?'. In some cases it seems right to pass it to OMA when the custom model adapter fails to find a property. Other times it seems like one might want to try OMA first .. then go ahead with the 'special case' of the custom model adapter. Eventually I wanted to just compose a group of model adapters into a hierarchy. This is where I run to an issue with getProperty(). Since it throws STNoSuchPropertyException to signal it's failure to find a property I end up using execptions for flow control, which is a bad idea right?
>
> Example:
>
> public class MultiModelAdapter implements ModelAdaptor {
>
> private List<ModelAdaptor> adaptors = new ArrayList<ModelAdaptor>();
>
> @Override
> public Object getProperty(Interpreter interp, ST self, Object o,
> Object property, String propertyName) throws STNoSuchPropertyException {
>
> Object value = null;
> boolean found = false;
> for(ModelAdaptor adaptor: adaptors){
> try{
> value = adaptor.getProperty(interp, self, adaptor, property, propertyName);
> found = true;
> }catch(STNoSuchPropertyException exception){
> continue;
> }
> }
> if(!found){
> throw new STNoSuchPropertyException();
> }
> return value;
> }
>
> }
>
> Is there a way around this or is MA just not meant to be composed like this?
>
> Collin
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110503/ffcc817d/attachment.html
More information about the stringtemplate-interest
mailing list