def _get_parser(): rgc = RemoveGraphicalClasses() rgc.remove("ptolemy.vergil.kernel.attributes.TextAttribute") MoMLParser.setMoMLFilters([rgc]) parser = MoMLParser() parser.reset() return parser
def from_moml(self, moml, filters=[]): """ Attempts to create a model from a string containing MoML code. Keyword attributes: moml -- the MoML string filters -- a list of MoMLFilter objects """ # apply the RemoveGraphicalClasses MoMLFilter # but remove the TextAttribute class from the filter # such that annotations don't get removed from the model rgc = RemoveGraphicalClasses() rgc.remove('ptolemy.vergil.kernel.attributes.TextAttribute') rgc.remove('ptolemy.actor.lib.gui.Display') rgc.remove('ptolemy.actor.lib.gui.TimedPlotter') # create a new list for the filters, and use # MoMLParser.setMoMLFilters with the new list. setMoMLFitlers is # used because the MoML filters object inside MoMLParser is # static, the only filtering on addMoMLFilter is memory address # filtering, and the filters specific to hydrant are only used # when executing a workflow, and no removeMoMLFilter object is # present. This is simply the easiest way to ensure nothing # goes wrong. f = [rgc] # add backwards compatibility filters f.extend(BackwardCompatibility().allFilters()) f.extend(filters) MoMLParser.setMoMLFilters(f) messages = utils.check_moml_dependencies(moml) # If a list is returned by validateMoML an error has occured # during validation, and we shouldn't continue. if messages is []: raise Exception('VALIDATION ERRORS') parser = MoMLParser() parser.reset() try: self.proxied_entity = parser.parse(moml) except java.lang.ExceptionInInitializerError, e: e.printStackTrace() raise