class NamespaceDictionaryBuilder(object): def __init__(self, namespaceFileName): self.namespaceFileName = namespaceFileName self.namespaceDict = NamespaceDictionary() ## # Open the file and return whether the operation was # succesful. ## def openFile(self): fileExists = os.path.exists(self.namespaceFileName) if fileExists: self.namespaceFile = open(self.namespaceFileName, 'r') return fileExists ## # Seam to enable subclasses to stub file operations. ## def closeFile(self): self.namespaceFile.close() def build(self): fileOpenedSuccessful = self.openFile() if not fileOpenedSuccessful: return None for line in self.namespaceFile: self.currentLine = line.strip() self.buildCurrentEntity() self.closeFile() ## # Create a NamespaceEntity for the # self.currentLine. ## def buildCurrentEntity(self): added = False self.currentEntity = None if isValidNamespaceDeclarationLine(self.currentLine): self.currentEntity = NamespaceEntity(self.currentLine) added = self.namespaceDict.add(self.currentEntity) return added def getNamespaceDictionary(self): return self.namespaceDict
class NamespaceDictionaryBuilder(object): def __init__(self, namespaceFileName): self.namespaceFileName = namespaceFileName self.namespaceDict = NamespaceDictionary() ## # Open the file and return whether the operation was # succesful. ## def openFile(self): fileExists = os.path.exists(self.namespaceFileName) if fileExists: self.namespaceFile=open(self.namespaceFileName, 'r') return fileExists ## # Seam to enable subclasses to stub file operations. ## def closeFile(self): self.namespaceFile.close() def build(self): fileOpenedSuccessful = self.openFile() if not fileOpenedSuccessful: return None for line in self.namespaceFile: self.currentLine = line.strip() self.buildCurrentEntity() self.closeFile() ## # Create a NamespaceEntity for the # self.currentLine. ## def buildCurrentEntity(self): added = False self.currentEntity = None if isValidNamespaceDeclarationLine(self.currentLine): self.currentEntity = NamespaceEntity(self.currentLine) added = self.namespaceDict.add(self.currentEntity) return added def getNamespaceDictionary(self): return self.namespaceDict
def __init__(self, namespaceFileName): self.namespaceFileName = namespaceFileName self.namespaceDict = NamespaceDictionary()