01: /*
02: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.romaframework.core.schema;
18:
19: import java.io.File;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.romaframework.core.Utility;
24: import org.romaframework.core.config.RomaApplicationContext;
25: import org.romaframework.core.schema.config.FileSystemSchemaConfiguration;
26:
27: /**
28: * Handle Entity schema descriptor loading.
29: *
30: * @author Luca Garulli (luca.garulli@assetdata.it)
31: */
32: public class SchemaConfigurationLoader {
33:
34: /**
35: * Load XML descriptor using Apache XMLBeans. Entities are cached.
36: *
37: * @param iEntityName
38: * @return Entity instance read from XML descriptor
39: */
40: public FileSystemSchemaConfiguration getXmlFileSystemSchemaConfiguration(
41: String iEntityName) {
42: FileSystemSchemaConfiguration descr = null;
43: String filePath = "<unsetted>";
44: try {
45: filePath = RomaApplicationContext.getInstance().getBean(
46: SchemaClassResolver.class).getEntityDescriptor(
47: iEntityName);
48: if (filePath == null)
49: return null;
50:
51: String containerFilePath = Utility
52: .getContainerFile(filePath);
53:
54: // TRY TO LOAD RESOURCE BY CLASS LOADER
55: if (log.isDebugEnabled())
56: log
57: .debug("[SchemaConfigurationLoader.getSchema] Loading schema from file: "
58: + getClass().getResource(filePath)
59: .getFile());
60: descr = new FileSystemSchemaConfiguration(
61: new File(getClass().getResource(containerFilePath)
62: .getFile()), filePath);
63: } catch (Exception e) {
64: log.error(
65: "[SchemaConfigurationLoader.getSchema] Error on loading resource: "
66: + filePath, e);
67: }
68: return descr;
69: }
70:
71: private static Log log = LogFactory
72: .getLog(SchemaConfigurationLoader.class);
73: }
|