X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=misc%2Fenv%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fmisc%2Fenv%2Fimpl%2FBasicEnv.java;h=e65f4e85d942e3711f10d7a4be1b58c9005981fc;hb=ff1417ff60baee231a28272f9a16ef2c9c8ea0a2;hp=2a3628d3d85e834c8f153941341bc9a02e11efff;hpb=c6b83856d26666396085f6cfb7be3dbbae3b3cd7;p=aaf%2Fauthz.git diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java index 2a3628d3..e65f4e85 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java @@ -57,296 +57,296 @@ import org.onap.aaf.misc.env.util.Split; * */ public class BasicEnv extends StoreImpl implements EnvJAXB, TransCreate{ - protected LogTarget fatal=LogTarget.SYSERR; - protected LogTarget error=LogTarget.SYSERR; - protected LogTarget audit=LogTarget.SYSOUT; - protected LogTarget init=LogTarget.SYSOUT; - protected LogTarget warn=LogTarget.SYSERR; - protected LogTarget info=LogTarget.SYSOUT; - protected LogTarget debug=LogTarget.NULL; - protected LogTarget trace=LogTarget.NULL; -// protected Map props; - -// private boolean sysprops; - - public BasicEnv(String ... args) { - super(null,args); - } - - public BasicEnv(String tag, String[] args) { - super(tag, args); - } - - - /** - * Suitable for use in Applets... obtain all the values - * listed for the variable String arg "tags" - */ - public BasicEnv(Applet applet, String ... tags) { - super(null, tags); -// props = new HashMap(); -// String value; -// for(int i=0;i=0) { - sb.append(" size: "); - sb.append(Long.toString(size)); - } - } - } - }; - } - - // @Override - public String getProperty(String key) { - return get(staticSlot(key),null); - } - - public Properties getProperties(String ... filter) { - Properties props = new Properties(); - boolean yes; - for(String key : existingStaticSlotNames()) { - if(filter.length>0) { - yes = false; - for(String f : filter) { - if(key.startsWith(f)) { - yes = true; - break; - } - } - } else { - yes = true; - } - if(yes) { - String value = getProperty(key); - if(value!=null) { - props.put(key, value); - } - } - } - return props; - } - - // @Override - public String getProperty(String key, String defaultValue) { - return get(staticSlot(key),defaultValue); - } - - // @Override - public String setProperty(String key, String value) { - put(staticSlot(key),value==null?null:value.trim()); - return value; - } - - protected Decryptor decryptor = Decryptor.NULL; - protected Encryptor encryptor = Encryptor.NULL; - - - public Decryptor decryptor() { - return decryptor; - } - - public void set(Decryptor newDecryptor) { - decryptor = newDecryptor; - } - - public Encryptor encryptor() { - return encryptor; - } - - public void set(Encryptor newEncryptor) { - encryptor = newEncryptor; - } - - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(Class... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this,classes); - } - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this, schema, classes); - } - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this, qName, classes); - } - - // @Override - public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException { - return new JAXBDF(this, schema, qName, classes); - } - - // @Override - public BasicTrans newTrans() { - return new BasicTrans(this); - } - - public void loadFromSystemPropsStartsWith(String ... str) { - for(String name : System.getProperties().stringPropertyNames()) { - for(String s : str) { - if(name.startsWith(s)) { - setProperty(name, System.getProperty(name)); - } - } - } - } - - /** - * - * - */ - public void loadToSystemPropsStartsWith(String ... str) { - String value; - for(String name : existingStaticSlotNames()) { - for(String s : str) { - if(name.startsWith(s)) { - if((value = getProperty(name))!=null) - System.setProperty(name,value); - } - } - } - } - - public void loadPropFiles(String tag, ClassLoader classloader) throws IOException { - String propfiles = getProperty(tag); - if(propfiles!=null) { - for(String pf : Split.splitTrim(File.pathSeparatorChar, propfiles)) { - InputStream is = classloader==null?null:classloader.getResourceAsStream(pf); - if(is==null) { - File f = new File(pf); - if(f.exists()) { - is = new FileInputStream(f); - } - } - if(is!=null) { - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - try { - String line; - while((line=br.readLine())!=null) { - line = line.trim(); - if(!line.startsWith("#")) { - String[] tv = Split.splitTrim('=', line); - if(tv.length==2) { - setProperty(tv[0],tv[1]); - } - } - } - } finally { - try { - br.close(); - } catch (IOException e) { - error().log(e); - } - } - } - } - } - } - - /** - * Create a StaticSlot, and load it from existing Properties - * - * @param name - * @param propName - * @return - */ - public synchronized StaticSlot staticSlot(String name, final String propName) { - StaticSlot ss = staticSlot(name); - put(ss,getProperty(propName)); - return ss; - } + protected LogTarget fatal=LogTarget.SYSERR; + protected LogTarget error=LogTarget.SYSERR; + protected LogTarget audit=LogTarget.SYSOUT; + protected LogTarget init=LogTarget.SYSOUT; + protected LogTarget warn=LogTarget.SYSERR; + protected LogTarget info=LogTarget.SYSOUT; + protected LogTarget debug=LogTarget.NULL; + protected LogTarget trace=LogTarget.NULL; +// protected Map props; + +// private boolean sysprops; + + public BasicEnv(String ... args) { + super(null,args); + } + + public BasicEnv(String tag, String[] args) { + super(tag, args); + } + + + /** + * Suitable for use in Applets... obtain all the values + * listed for the variable String arg "tags" + */ + public BasicEnv(Applet applet, String ... tags) { + super(null, tags); +// props = new HashMap<>(); +// String value; +// for (int i=0;i=0) { + sb.append(" size: "); + sb.append(Long.toString(size)); + } + } + } + }; + } + + // @Override + public String getProperty(String key) { + return get(staticSlot(key),null); + } + + public Properties getProperties(String ... filter) { + Properties props = new Properties(); + boolean yes; + for (String key : existingStaticSlotNames()) { + if (filter.length>0) { + yes = false; + for (String f : filter) { + if (key.startsWith(f)) { + yes = true; + break; + } + } + } else { + yes = true; + } + if (yes) { + String value = getProperty(key); + if (value!=null) { + props.put(key, value); + } + } + } + return props; + } + + // @Override + public String getProperty(String key, String defaultValue) { + return get(staticSlot(key),defaultValue); + } + + // @Override + public String setProperty(String key, String value) { + put(staticSlot(key),value==null?null:value.trim()); + return value; + } + + protected Decryptor decryptor = Decryptor.NULL; + protected Encryptor encryptor = Encryptor.NULL; + + + public Decryptor decryptor() { + return decryptor; + } + + public void set(Decryptor newDecryptor) { + decryptor = newDecryptor; + } + + public Encryptor encryptor() { + return encryptor; + } + + public void set(Encryptor newEncryptor) { + encryptor = newEncryptor; + } + + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(Class... classes) throws APIException { +// if (String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this,classes); + } + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { +// if (String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this, schema, classes); + } + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException { +// if (String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this, qName, classes); + } + + // @Override + public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException { + return new JAXBDF(this, schema, qName, classes); + } + + // @Override + public BasicTrans newTrans() { + return new BasicTrans(this); + } + + public void loadFromSystemPropsStartsWith(String ... str) { + for (String name : System.getProperties().stringPropertyNames()) { + for (String s : str) { + if (name.startsWith(s)) { + setProperty(name, System.getProperty(name)); + } + } + } + } + + /** + * + * + */ + public void loadToSystemPropsStartsWith(String ... str) { + String value; + for (String name : existingStaticSlotNames()) { + for (String s : str) { + if (name.startsWith(s)) { + if ((value = getProperty(name))!=null) + System.setProperty(name,value); + } + } + } + } + + public void loadPropFiles(String tag, ClassLoader classloader) throws IOException { + String propfiles = getProperty(tag); + if (propfiles!=null) { + for (String pf : Split.splitTrim(File.pathSeparatorChar, propfiles)) { + InputStream is = classloader==null?null:classloader.getResourceAsStream(pf); + if (is==null) { + File f = new File(pf); + if (f.exists()) { + is = new FileInputStream(f); + } + } + if (is!=null) { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + try { + String line; + while ((line=br.readLine())!=null) { + line = line.trim(); + if (!line.startsWith("#")) { + String[] tv = Split.splitTrim('=', line); + if (tv.length==2) { + setProperty(tv[0],tv[1]); + } + } + } + } finally { + try { + br.close(); + } catch (IOException e) { + error().log(e); + } + } + } + } + } + } + + /** + * Create a StaticSlot, and load it from existing Properties + * + * @param name + * @param propName + * @return + */ + public synchronized StaticSlot staticSlot(String name, final String propName) { + StaticSlot ss = staticSlot(name); + put(ss,getProperty(propName)); + return ss; + } }