001: package org.objectweb.celtix.tools.common;
002:
003: import java.io.*;
004: import java.util.*;
005: import org.xml.sax.InputSource;
006: import org.objectweb.celtix.tools.utils.PropertyUtil;
007: import org.objectweb.celtix.tools.utils.URIParserUtil;
008:
009: public class ProcessorEnvironment {
010:
011: private Map<String, Object> paramMap;
012: private String packageName;
013: private Map<String, String> namespacePackageMap = new HashMap<String, String>();
014: private Map<String, String> excludeNamespacePackageMap = new HashMap<String, String>();
015: private final Map<String, InputSource> jaxbBindingFiles = new HashMap<String, InputSource>();
016:
017: public ProcessorEnvironment() {
018: }
019:
020: public void loadDefaultNS2Pck() {
021: try {
022: PropertyUtil properties = new PropertyUtil();
023: properties
024: .load(getResourceAsStream("toolspec/toolspecs/namespace2package.cfg"));
025: namespacePackageMap.putAll(properties.getMaps());
026: } catch (IOException e) {
027: e.printStackTrace();
028: }
029: }
030:
031: public void loadDefaultExcludes() {
032: try {
033: PropertyUtil properties = new PropertyUtil();
034: properties
035: .load(getResourceAsStream("toolspec/toolspecs/wsdltojavaexclude.cfg"));
036: excludeNamespacePackageMap.putAll(properties.getMaps());
037: } catch (IOException e) {
038: e.printStackTrace();
039: }
040: }
041:
042: private InputStream getResourceAsStream(String file)
043: throws IOException {
044: return ProcessorEnvironment.class.getResourceAsStream(file);
045: }
046:
047: public void setParameters(Map<String, Object> map) {
048: this .paramMap = map;
049: }
050:
051: public boolean containsKey(String key) {
052: return (paramMap == null) ? false : paramMap.containsKey(key);
053: }
054:
055: public Object get(String key) {
056: return (paramMap == null) ? null : paramMap.get(key);
057: }
058:
059: public Object get(String key, Object defaultValue) {
060: if (!optionSet(key)) {
061: return defaultValue;
062: } else {
063: return get(key);
064: }
065: }
066:
067: public boolean getBooleanValue(String key, String defaultValue) {
068: return Boolean.valueOf((String) get(key, defaultValue))
069: .booleanValue();
070: }
071:
072: public void put(String key, Object value) {
073: if (paramMap == null) {
074: paramMap = new HashMap<String, Object>();
075: }
076: paramMap.put(key, value);
077: }
078:
079: public void remove(String key) {
080: if (paramMap == null) {
081: return;
082: }
083: paramMap.remove(key);
084: }
085:
086: public boolean optionSet(String key) {
087: return (get(key) == null) ? false : true;
088: }
089:
090: public boolean isVerbose() {
091: if (get(ToolConstants.CFG_VERBOSE) == null) {
092: return false;
093: } else {
094: return get(ToolConstants.CFG_VERBOSE) == ToolConstants.CFG_VERBOSE;
095: }
096: }
097:
098: public boolean validateWSDL() {
099: return get(ToolConstants.CFG_VALIDATE_WSDL) != null;
100:
101: }
102:
103: public void addNamespacePackageMap(String namespace, String pn) {
104: this .namespacePackageMap.put(namespace, pn);
105: }
106:
107: private String mapNamespaceToPackageName(String ns) {
108: return this .namespacePackageMap.get(ns);
109: }
110:
111: public boolean hasNamespace(String ns) {
112: return this .namespacePackageMap.containsKey(ns);
113: }
114:
115: public void addExcludeNamespacePackageMap(String namespace,
116: String pn) {
117: this .excludeNamespacePackageMap.put(namespace, pn);
118: }
119:
120: public boolean hasExcludeNamespace(String ns) {
121: return this .excludeNamespacePackageMap.containsKey(ns);
122: }
123:
124: public String getExcludePackageName(String ns) {
125: return this .excludeNamespacePackageMap.get(ns);
126: }
127:
128: public void setPackageName(String pkgName) {
129: this .packageName = pkgName;
130: }
131:
132: public String getPackageName() {
133: return this .packageName;
134: }
135:
136: public String mapPackageName(String ns) {
137: if (hasNamespace(ns)) {
138: return mapNamespaceToPackageName(ns);
139: } else {
140: return getPackageName();
141: }
142: }
143:
144: public String getCustomizedNS(String ns) {
145: return URIParserUtil.getNamespace(mapPackageName(ns));
146: }
147:
148: public void addJaxbBindingFile(String location, InputSource is) {
149: this .jaxbBindingFiles.put(location, is);
150: }
151:
152: public Map<String, InputSource> getJaxbBindingFile() {
153: return this .jaxbBindingFiles;
154: }
155:
156: public boolean isExcludeNamespaceEnabled() {
157: return excludeNamespacePackageMap.size() > 0;
158: }
159: }
|