commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r5519 - in trunk/gnue-common/src/logic: . adapters


From: johannes
Subject: r5519 - in trunk/gnue-common/src/logic: . adapters
Date: Fri, 26 Mar 2004 03:52:37 -0600 (CST)

Author: johannes
Date: 2004-03-26 03:52:36 -0600 (Fri, 26 Mar 2004)
New Revision: 5519

Added:
   trunk/gnue-common/src/logic/language.py
Removed:
   trunk/gnue-common/src/logic/language/
Modified:
   trunk/gnue-common/src/logic/GTrigger.py
   trunk/gnue-common/src/logic/adapters/python.py
Log:
Rebuilt the language engine stuff (continuation). VirtualCode now uses
parameters.


Modified: trunk/gnue-common/src/logic/GTrigger.py
===================================================================
--- trunk/gnue-common/src/logic/GTrigger.py     2004-03-26 09:47:32 UTC (rev 
5518)
+++ trunk/gnue-common/src/logic/GTrigger.py     2004-03-26 09:52:36 UTC (rev 
5519)
@@ -37,7 +37,7 @@
 from gnue.common.formatting import GTypecast
 from xml.sax import saxutils
 from gnue.common.definitions.GParserHelpers import GContent
-from gnue.common.logic.language.Base import loadLanguageEngine, 
LangIfRuntimeError
+from gnue.common.logic.language import getLanguageAdapter, RuntimeError
 
 
 class TriggerError(StandardError):
@@ -50,8 +50,6 @@
 class TriggerSuccess:
   pass
 
-runtime_list = {}
-
 #######################################################################
 #
 # Trigger instance classes
@@ -71,7 +69,8 @@
 # Class used to implement triggers
 #
 class GTrigger(GObj):
-  def __init__(self, parent=None, type=None, name=None, src=None, text=None, 
language='python'):
+  def __init__(self, parent=None, type=None, name=None, src=None, text=None, 
+               language='python'):
 
     GObj.__init__(self, parent, 'GCTrigger')
 
@@ -126,18 +125,17 @@
     self._text = text
     self.language = language
 
-    if not runtime_list.has_key(language):
-      runtime_list[language] = loadLanguageEngine(language)
+    engine = getLanguageAdapter (self.language)
+    cx = engine.createNewContext ()
     
-    cx=runtime_list[language].createNewContext()
-    
     # define global namespace ('global' directive in python)
-    cx.defineNamespace(self._globalns, globalns=1)
+    cx.defineNamespace (self._globalns, asGlobal = True)
 
     # define local trigger namespace
-    cx.defineNamespace(self._triggerns)
+    cx.defineNamespace (self._triggerns)
 
-    # Build the name of an object, has to be integrated with the namespace 
creation
+    # Build the name of an object, has to be integrated with the namespace
+    # creation
     path=""
     p = self
     delim = ""
@@ -152,7 +150,8 @@
       else:
         p=p._parent
       
-    method = cx.buildMethod(path, self._text)
+    print "BUILD:", path
+    method = cx.buildFunction (path, self._text)
     self.__call__ = method
 
   def dummyFunction(self, myself):
@@ -292,7 +291,7 @@
           #   function.updateNamespace()
           try:
             function(self)
-          except LangIfRuntimeError, msg:
+          except RuntimeError, msg:
             # call my own exceptionHandler here.
             print "Runtime Error occured:\n %s" % msg
       else:

Modified: trunk/gnue-common/src/logic/adapters/python.py
===================================================================
--- trunk/gnue-common/src/logic/adapters/python.py      2004-03-26 09:47:32 UTC 
(rev 5518)
+++ trunk/gnue-common/src/logic/adapters/python.py      2004-03-26 09:52:36 UTC 
(rev 5519)
@@ -23,8 +23,7 @@
 from string import join
 from copy import copy
 
-import gnue.common.logic.language
-from gnue.common.logic.language.adapters import Base
+from gnue.common.logic.adapters import Base
 
 # =============================================================================
 # Implementation of a language adapter for python
@@ -60,7 +59,7 @@
   # ---------------------------------------------------------------------------
 
   def __init__ (self, runtime = None):
-    BaseExecutionContext.__init__ (self, runtime)
+    Base.BaseExecutionContext.__init__ (self, runtime)
 
     self._globalNS = {}
     self._localNS  = {}

Added: trunk/gnue-common/src/logic/language.py
===================================================================
--- trunk/gnue-common/src/logic/language.py     2004-03-26 09:47:32 UTC (rev 
5518)
+++ trunk/gnue-common/src/logic/language.py     2004-03-26 09:52:36 UTC (rev 
5519)
@@ -0,0 +1,90 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2001-2004 Free Software Foundation
+#
+# $Id: $
+
+from gnue.common.utils.FileUtils import dyn_import
+
+adapters = {}
+
+
+# =============================================================================
+# Exceptions
+# =============================================================================
+
+# -----------------------------------------------------------------------------
+# Python module not available
+# -----------------------------------------------------------------------------
+class AdapterNotFoundError (gException):
+  """
+  The language adapter for the requested language cannot be imported.
+  """
+  def __init__ (self, language):
+    msg = u_("No adapter available for language '%s'") % language
+    gException.__init__ (self, msg)
+
+
+# -----------------------------------------------------------------------------
+# Abstract method not implemented
+# -----------------------------------------------------------------------------
+class ImplementationError (gException):
+  """
+  Exception raised if an abstract method isn't implemented by a descendant.
+  """
+  def __init__ (self, classname, method):
+    msg = u_("The class '%(class)s' has no implementation for '%(method)s'") \
+           % {"class" : classname,
+              "method": method}
+    gException.__init__ (self, msg)
+
+# -----------------------------------------------------------------------------
+# Virtual code exceptions
+# -----------------------------------------------------------------------------
+class CompileError (gException):
+  pass
+
+class RuntimeError (gException):
+  pass
+
+
+
+# -----------------------------------------------------------------------------
+# Get or create an instance of a given language adapter
+# -----------------------------------------------------------------------------
+
+def getLanguageAdapter (language):
+  """
+  This function returns an execution context factory for the given language.
+  AdapterNotFoundError will be raised, if the language adapter cannot be
+  imported.
+  """
+  global adapters
+  lang = language.lower ()
+
+  if not adapters.has_key (lang):
+    try:
+      adapter = dyn_import ('gnue.common.logic.adapters.%s' % lang)
+      adapters [lang] = adapter.LanguageAdapter ()
+
+    except ImportError:
+      raise AdapterNotFoundError, language
+
+  return adapters [language]
+


Property changes on: trunk/gnue-common/src/logic/language.py
___________________________________________________________________
Name: svn:keywords
   + svn:Id





reply via email to

[Prev in Thread] Current Thread [Next in Thread]