From: Julio G. <ju...@us...> - 2004-06-15 16:30:16
|
Update of /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/componentdescription In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12726/smartfrog/src/org/smartfrog/sfcore/componentdescription Modified Files: ComponentDescriptionImpl.java Log Message: added method to read system properties and add them to a component description. Index: ComponentDescriptionImpl.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/componentdescription/ComponentDescriptionImpl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ComponentDescriptionImpl.java 8 Apr 2004 10:20:53 -0000 1.8 --- ComponentDescriptionImpl.java 15 Jun 2004 16:30:03 -0000 1.9 *************** *** 27,30 **** --- 27,31 ---- import java.util.Enumeration; import java.util.Vector; + import java.util.Properties; import org.smartfrog.sfcore.common.SmartFrogCoreKeys; *************** *** 562,565 **** --- 563,593 ---- } + /** + * Adds system properties to component description. + * Uses startWith parameter as filter. + * + * @param startWith system property label (ex. org.smartfrog) + * @param compDesc configuration description where to add system properties. + * @return this configuration description with system properties added. + */ + public static ComponentDescription addSystemProperties(String startWith, + ComponentDescription compDesc) { + Properties props = System.getProperties(); + for (Enumeration e = props.keys(); e.hasMoreElements(); ) { + String key = e.nextElement().toString(); + if (key.startsWith(startWith)) { + Object value = props.get(key); + try { + // convert to number + value = Double.valueOf((String)value); + } catch (Exception ex) { + // ignore, value is not a number + } + String cxtKey = key.substring(startWith.length()); + compDesc.getContext().put(cxtKey, value); + } + } + return compDesc; + } } |