Revision 10878

View differences:

trunk/libraries/libDwg/src/com/iver/cit/jdwglib/dwg/DwgFile.java
68 68
 * @author azabala
69 69
 */
70 70
public class DwgFile {
71
	
72
	public static final String DWG_ACAD2000 = "AC1015";
73
	public static final String DWG_ACAD14 = "AC1014";
74
	public static final String DWG_ACAD_PRE_14 = "AC1013";
75
	public static final String DWG_ACAD13 = "AC1012";
76
	public static final String DWG_ACAD12 = "AC1009";
77
	
71 78
	/**
72 79
	 * It has all known DWG version's header.
73 80
	 * Extracted from Autodesk web.
......
79 86
		acadVersions.put("AC1007", "Autocad pre-R11");
80 87
		acadVersions.put("AC1007", "Autocad pre-R11");
81 88
		acadVersions.put("AC1008", "Autocad pre-R11b");
82
		acadVersions.put("AC1009", "Autocad R12");
89
		acadVersions.put(DWG_ACAD12, "Autocad R12");
83 90
		acadVersions.put("AC1010", "Autocad pre-R13 a");
84 91
		acadVersions.put("AC1011", "Autocad pre-R13 b");
85
		acadVersions.put("AC1012", "Autocad R13");
86
		acadVersions.put("AC1013", "Autocad pre-R14");
87
		acadVersions.put("AC1014", "Autocad R14");
92
		acadVersions.put(DWG_ACAD13, "Autocad R13");
93
		acadVersions.put(DWG_ACAD_PRE_14, "Autocad pre-R14");
94
		acadVersions.put(DWG_ACAD14, "Autocad R14");
88 95
		acadVersions.put("AC1500", "Autocad pre-2000");
89
		acadVersions.put("AC1015", "Autocad R2000, R2000i, R2002");
96
		acadVersions.put(DWG_ACAD2000, "Autocad R2000, R2000i, R2002");
90 97
		acadVersions.put("AC402a", "Autocad pre-2004a");
91 98
		acadVersions.put("AC402b", "Autocad pre-2004b");
92 99
		acadVersions.put("AC1018", "Autocad R2004, R2005, R2006");
93 100
		acadVersions.put("AC1021", "Autocad R2007");
101
	}
94 102
	
103
	
104
	/**
105
	 * Registry of file readers
106
	 * */
107
	private static HashMap acadReaders = new HashMap();
108
	static{
109
		acadReaders.put(DWG_ACAD2000,DwgFileV15Reader.class);
110
		acadReaders.put(DWG_ACAD_PRE_14,DwgFileV14Reader.class);
111
		acadReaders.put(DWG_ACAD14,DwgFileV14Reader.class);
112
		acadReaders.put(DWG_ACAD13,DwgFileV14Reader.class);
113
		acadReaders.put(DWG_ACAD12,DwgFileV12Reader.class);
95 114
	}
96 115
	
116
	public static Class getReaderForVersion(String dwgVersion){
117
		return (Class) acadReaders.get(dwgVersion);
118
	}
119
	
120
	public static void registerDwgReader(String version, Class dwgReaderClazz){
121
		if( IDwgFileReader.class.isAssignableFrom(dwgReaderClazz)){
122
			if(!acadReaders.containsKey(version)){
123
				acadReaders.put(version, dwgReaderClazz);
124
			}else{
125
				logger.warn("Ya hay un reader registrado para la version "+version);
126
			}
127
		}else{
128
			logger.warn("La clase "+dwgReaderClazz.getName()+" no es una implementacion valida de IDwgFileReader");
129
		}
130
	}
131
	/**
132
	 * Returns an iterator over all the string that represents
133
	 * dwg version for we have a registered reader
134
	 * */
135
	public static Iterator getRegisteredVersions(){
136
		return acadReaders.keySet().iterator();
137
	}
138
	
97 139
	private static Logger logger = Logger.getLogger(DwgFile.class
98 140
			.getName());
141
	
99 142
	/**
100 143
	 * Path and name of the dwg file
101 144
	 * */
......
196 239
		return dwgVersion;
197 240
	}
198 241
	
242
	
199 243
	/**
200 244
	 * Reads a DWG file and put its objects in the dwgObjects Vector
201 245
	 * This method is version independent
......
206 250
				DwgVersionNotSupportedException
207 251
	{
208 252
		setDwgVersion();
253
		
254
		//main readers (not configurable)
209 255
		if (dwgVersion.equalsIgnoreCase("Autocad R2000, R2000i, R2002")) {
210 256
			dwgReader = new DwgFileV15Reader();
211 257
		}else if (dwgVersion.equalsIgnoreCase("Autocad pre-R14")|| 
......
221 267
					isR13 = false;
222 268
			dwgReader = new DwgFileV12Reader(isR13);
223 269
		}else {
224
			DwgVersionNotSupportedException exception = 
225
				new DwgVersionNotSupportedException("Version de DWG no soportada");
226
			exception.setDwgVersion(dwgVersion);
227
			throw exception;
270
			
271
			//look for registered readers
272
			Class iReader = getReaderForVersion(dwgVersion);
273
			if(iReader == null){
274
				DwgVersionNotSupportedException exception = 
275
					new DwgVersionNotSupportedException("Version de DWG no soportada");
276
				exception.setDwgVersion(dwgVersion);
277
				throw exception;
278
			} else
279
				try {
280
					dwgReader = (IDwgFileReader) iReader.newInstance();
281
				} catch (Exception e) {
282
					DwgVersionNotSupportedException exception = 
283
						new DwgVersionNotSupportedException("Version de DWG no soportada");
284
					exception.setDwgVersion(dwgVersion);
285
					throw exception;
286
				} 
228 287
		}
288
		
229 289
		try{
230
		dwgReader.read(this, bb);
290
			dwgReader.read(this, bb);
231 291
		}catch(Throwable t){
232 292
			t.printStackTrace();
233 293
			throw new IOException("Error leyendo dwg");

Also available in: Unified diff