Esempio n. 1
0
 def lowerCasePrefix(self, v):
     if v is None:
         raise ModelProcessingError(
             'Cannot lower case %s on %s' % (v, self.name))
     match = config.PREFIX_CASE_REGEX.match(v)
     if match is None:
         raise ModelProcessingError(
             'No prefix match for %s on %s' % (v, self.name))
     prefix, = filter(None, match.groups())
     return prefix.lower() + v[len(prefix):]
Esempio n. 2
0
def parse(opts):
    """
    Entry point for XML Schema parsing into an OME Model.
    """
    # The following two statements are required to "prime" the generateDS
    # code and ensure we have reasonable namespace support.
    filenames = opts.args
    namespace = opts.namespace

    logging.debug("Namespace: %s" % namespace)
    set_type_constants(namespace)
    generateDS.generateDS.XsdNameSpace = namespace
    logging.debug("Type map: %s" % opts.lang.type_map)

    parser = sax.make_parser()
    ch = XschemaHandler()
    parser.setContentHandler(ch)
    for filename in filenames:
        parser.parse(filename)

    root = ch.getRoot()
    if root is None:
        raise ModelProcessingError(
            "No model objects found, have you set the correct namespace?")
    root.annotate()
    return OMEModel.process(ch, opts)
Esempio n. 3
0
 def generatedFilename(self, name, type):
     gen_name = None
     if type == TYPE_SOURCE and self.source_suffix is not None:
         gen_name = name + self.source_suffix
     else:
         raise ModelProcessingError(
             "Invalid language/filetype combination: %s/%s" %
             (self.name, type))
     return gen_name
Esempio n. 4
0
    def _get_langType(self):
        name = None

        if self.hasUnitsCompanion:
            name = self.unitsType

        # Hand back the type of enumerations
        if self.isEnumeration:
            langType = self.name
            if len(self.delegate.values) == 0:
                # As we have no directly defined possible values we have
                # no reason to qualify our type explicitly.
                name = self.type
            elif langType == "Type":
                # One of the OME XML unspecific "Type" properties which
                # can only be qualified by the parent.
                if self.type.endswith("string"):
                    # We've been defined entirely inline, prefix our
                    # type name with the parent type's name.
                    name = "%s%s" % (self.parent.name, langType)
                else:
                    # There's another type which describes us, use its name
                    # as our type name.
                    name = self.type
            else:
                name = langType
            # Handle XML Schema types that directly map to language types and
            # handle cases where the type is prefixed by a namespace
            # definition. (ex. OME:NonNegativeInt).
        else:
            # This sets name only for those types mentioned in the type_map
            # for the generated language. All other cases set name to None
            # so the following if block is executed
            name = self.model.opts.lang.type(self.type.replace('OME:', ''))

        if name is None:
            # Hand back the type of references or complex types with the
            # useless OME XML 'Ref' suffix removed.
            if (self.isBackReference or
                    (not self.isAttribute and self.delegate.isComplex())):
                name = config.REF_REGEX.sub('', self.type)
            # Hand back the type of complex types
            elif not self.isAttribute and self.delegate.isComplex():
                name = self.type
            elif not self.isEnumeration:
                # We have a property whose type was defined by a top level
                # simpleType.
                simpleTypeName = self.type
                name = self.resolveLangTypeFromSimpleType(simpleTypeName)
            else:
                logging.debug("%s dump: %s" % (self, self.__dict__))
                logging.debug("%s delegate dump: %s"
                              % (self, self.delegate.__dict__))
                raise ModelProcessingError(
                    "Unable to find %s type for %s" % (self.name, self.type))
        return name
Esempio n. 5
0
def create(language, namespace, templatepath):
    """
    Create a language by name.
    """

    lang = None

    if language == "Java":
        lang = Java(namespace, templatepath)
    else:
        raise ModelProcessingError("Invalid language: %s" % language)

    return lang
Esempio n. 6
0
 def isComplex(self):
     """
     Returns whether or not the property has a "complex" content type.
     """
     if self.isAttribute:
         raise ModelProcessingError(
             "This property is an attribute and has no content model!")
     # FIXME: This hack is in place because of the incorrect content
     # model in the XML Schema document itself for the "Description"
     # element.
     if self.name == "Description":
         return False
     return self.delegate.isComplex()
Esempio n. 7
0
 def addObject(self, element, obj):
     elementName = element.getName()
     if element in self.objects:
         raise ModelProcessingError("Element %s has been processed!" %
                                    element)
     if elementName in self.elementNameObjectMap:
         if (elementName == "EmissionFilterRef"
                 or elementName == "ExcitationFilterRef"):
             pass
         else:
             logging.warn("Element %s has duplicate object with same name,"
                          " skipping!" % element)
         return
     self.elementNameObjectMap[element.getName()] = obj
     self.objects[element] = obj