1 28 29 package com.caucho.config.core; 30 31 import com.caucho.config.Config; 32 import com.caucho.config.ConfigELContext; 33 import com.caucho.config.ConfigException; 34 import com.caucho.config.SchemaBean; 35 import com.caucho.config.types.FileSetType; 36 import com.caucho.loader.Environment; 37 import com.caucho.log.Log; 38 import com.caucho.util.L10N; 39 import com.caucho.vfs.Depend; 40 import com.caucho.vfs.Path; 41 42 import javax.annotation.PostConstruct; 43 import javax.el.ELContext; 44 import java.util.ArrayList ; 45 import java.util.logging.Logger ; 46 47 50 public class ResinImport extends ResinControl 51 { 52 private static final L10N L = new L10N(ResinImport.class); 53 private static final Logger log = Log.open(ResinImport.class); 54 55 private Path _path; 56 private FileSetType _fileSet; 57 private boolean _isOptional; 58 59 62 public void setPath(Path path) 63 { 64 _path = path; 65 } 66 67 70 public void setFileset(FileSetType fileSet) 71 { 72 _fileSet = fileSet; 73 } 74 75 78 public void setOptional(boolean optional) 79 { 80 _isOptional = optional; 81 } 82 83 @PostConstruct 84 public void init() 85 throws Exception 86 { 87 if (_path == null) { 88 if (_fileSet == null) 89 throw new ConfigException(L.l("'path' attribute missing from resin:import.")); 90 } 91 else if (_path.canRead() && ! _path.isDirectory()) { 92 } 93 else if (_isOptional) { 94 log.finer(L.l("resin:import '{0}' is not readable.", _path)); 95 96 Environment.addDependency(new Depend(_path)); 97 return; 98 } 99 else { 100 throw new ConfigException(L.l("Required file '{0}' can not be read for resin:import.", 101 _path.getNativePath())); 102 } 103 104 Object object = getObject(); 105 106 String schema = null; 107 if (object instanceof SchemaBean) { 109 schema = ((SchemaBean) object).getSchema(); 110 } 111 112 ArrayList <Path> paths; 113 114 if (_fileSet != null) 115 paths = _fileSet.getPaths(); 116 else { 117 paths = new ArrayList <Path>(); 118 paths.add(_path); 119 } 120 121 for (int i = 0; i < paths.size(); i++) { 122 Path path = paths.get(i); 123 124 log.config(L.l("resin:import '{0}'", path.getNativePath())); 125 126 Environment.addDependency(new Depend(path)); 127 128 Config config = new Config(); 129 132 ELContext elContext = Config.getEnvironment(); 133 if (elContext instanceof ConfigELContext) { 134 config.setELContext((ConfigELContext) elContext); 135 } 136 137 config.configureBean(object, path, schema); 138 } 139 } 140 } 141 142 | Popular Tags |