1 package net.sf.invicta.type; 2 3 import java.io.File ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 9 import net.sf.invicta.InvictaConstants; 10 11 15 public class TypeManager { 16 protected Map typeFiles = new HashMap (); 17 protected Map types = new HashMap (); 18 protected TypeDefinitionLoader typeLoader = new TypeDefinitionLoader(); 19 20 24 public TypeManager(List typeFilesList) { 25 super(); 26 prepareFilesMap(typeFilesList); 27 } 28 29 37 public TypeDefinition getTypeDefinition(String typeName) throws InvictaTypeException { 38 return getTypeDefinition(typeName, 0); 39 } 40 41 46 protected void prepareFilesMap(List typeFilesList) { 47 48 for (Iterator iter = typeFilesList.iterator(); iter.hasNext();) { 49 String fullPath = (String ) iter.next(); 50 File fullPathFile = new File (fullPath); 51 String fileName = fullPathFile.getName(); 52 int extensionIndex = fileName.lastIndexOf(InvictaConstants.DEFINITION_FILE_EXTENSION); 53 String typeName = fileName.substring(0, extensionIndex); 54 this.typeFiles.put(typeName, fullPath); 55 } 56 } 57 58 61 protected TypeDefinition getTypeDefinition(String typeName, int level) throws InvictaTypeException { 62 TypeDefinition typeDefinition = (TypeDefinition) this.types.get(typeName); 63 if (typeDefinition != null) 64 return typeDefinition; 65 66 if (level > InvictaConstants.MAX_RESOLVE_LEVEL) 68 throw InvictaTypeException.typeInheritanceCycle(typeName); 69 70 String typeFilePath = (String )this.typeFiles.get(typeName); 72 73 if (typeFilePath == null) 75 throw InvictaTypeException.typeDefinitionNotFound(typeName); 76 77 typeDefinition = 79 this.typeLoader.load(typeFilePath); 80 81 if (!typeDefinition.getName().equals(typeName)) 83 System.out.println("** Warning: Type name '" + typeDefinition.getName() + "' does not match the file name '" + typeName); 84 85 typeDefinition.resolve(this, level); 86 87 this.types.put(typeName, typeDefinition); 89 90 return typeDefinition; 91 } 92 93 } 94 95 | Popular Tags |