My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Friday, December 28, 2012

Load Properties dynamically

Use Apache Commons Configuration and you can re-load property file dynamically.

Here is the complete code snippet for you


Java Code

import java.util.Arrays;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;

public class ApacheCommonsTest {

private static final String PROPERTIES_FILE_NAME = "C:\\sampleconfig\\reloadconfig.properties"; // you can use your own folder for this

/**
* @param args
*/
public static void main(String[] args) {
ApacheCommonsTest classObj = new ApacheCommonsTest();
try {
classObj.getBackground();
classObj.getPieColors();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}

private PropertiesConfiguration getPropertyConfig()
throws ConfigurationException {
PropertiesConfiguration config = null;
config = new PropertiesConfiguration(PROPERTIES_FILE_NAME);
config.setReloadingStrategy(new FileChangedReloadingStrategy());
config.setAutoSave(true);
return config;
}

private void readProperties() throws ConfigurationException {
PropertiesConfiguration config = getPropertyConfig();
config.load(PROPERTIES_FILE_NAME);
}

private void getPieColors() throws ConfigurationException {
readProperties();
String[] piecolors = getPropertyConfig().getStringArray("colors.pie");
System.out.println("colors.pie=" + Arrays.toString(piecolors));
}

private void getBackground() throws ConfigurationException {
readProperties();
String bgcolor = getPropertyConfig().getString("colors.background");
System.out.println("bgcolor=" + bgcolor);
}
}

Sample Property file
C:\\sampleconfig\\reloadconfig.properties


colors.pie=#FF0000,#00FF00,#0000FF,#123456
colors.background=#c53478


Jar files to run this program

You can get all the jar files from findjar.com

  1. commons-configuration-1.9.jar
  2. commons-lang-2.2.jar
  3. commons-logging-1.1.1.jar
Now no more reloading with server re-start


Thursday, December 27, 2012

Enable UML shapes in Visio


  • Stencil and Template for Visio 2010

Visio 2010 represents the first noticeable improvement in usability since Visio 2000, but no enhancement in the funtionality, upon which the UML 2.2 shapes are built upon. 
Therefore, the shapes for Visio 2010 are the same as for Visio 2007; there are minor changes in the template. 

Install: If you'd like the template to appear in the "Software and Database" category when you click File/New, together with Visio's own templates, 
create in any folder a subfolder called "Software and Database", for example, "...\My Documents\My Shapes\Software and Database". 

You could choose any folder, except of the Visio program folder, i.e., don't use C:\Program Files\Microsoft Office\Office14\Visio Content\1033. 

Unzip the stencils and template into "...\My Documents\My Shapes\Software and Database" or the folder you created. 

  1. Start Visio, 
  2. click the File tab, 
  3. click Options, 
  4. click Advanced, 
  5. and then, 
  6. under General at the very bottom, 
  7. click File Locations. 
  8. Type full path of this folder without the last segment "Software and Database" into the fields "Stencils" and "Templates". 
  9. That is, type in "C:\Document and Settings\<user name>\My Documents\My Shapes\" . 

The template "UML 2.2 Template (Visio 2010)" will appear in the category "Software and Database". 

If you'd like the UML 2.2 template to appear in another category, 
such as a "UML" category, use "UML" instead of "Software and Database" in the steps above.

The stencils and template are here: UML2.2-Visio2010.zip


  • Stencil and Template for Visio 2007

This stencil for Visio 2007 contains all the same shapes as the stencil for Visio 2003, 
as Visio 2007 has almost the same functionality as Visio 2003; there were only usability improvements.  

Install: If you'd like the template to appear in the "Software and Database" category 
when you click File/New, together with Visio's own templates, 
create in any folder a subfolder called "Software and Database", 
for example, "...\My Documents\My Shapes\Software and Database". 
You could choose any folder, except of the Visio program folder, 
i.e., don't use C:\Program Files\Microsoft Office\Office11\1033. 

Unzip the stencils and template into "...\My Documents\My Shapes\Software and Database" or the folder you created. 

  1. Start Visio, 
  2. click "Tools" 
  3. and "Options". 
  4. In the "Advanced" tab, 
  5. click "File Paths..." 
  6. and type full path of this folder, 
  7. without the last element "Software and Database" into the fields "Stencils" and "Templates", 
  8. that is insert "C:\Documents and Settings\<user name>\My Documents\My Shapes\".  
  9. Restart Visio. 
  10. The template "UML 2.2 Template (Visio 2007)" will appear in the category "Software and Database". 

If you'd like the UML 2.2 template to appear in another category, 
such as a "UML" category, use "UML" instead of "Software and Database" in the steps above.

The stencils and template are here: UML2.2-Visio2007.zip.