[Index]

PropertyIO Overview


The class hierarchy for PropertyIO's jar.


The only requirement for a new PropertyIO is that it implements the interface PropertyIO.
See PropertyIO API Doc for the methods that has to be implemented.
The basic implementation is AbstractPropertyIO which I will recommend to extend see AbstractPropertyIO API Doc.



Abstract Class Parent class Description Restrictions Version Javadoc
AbstractPropertyIO PropertyIO Implements the method that stored the cached values in a hashTable.
This included the method for reload and the attributes for caching and readonly.
- 1.0 (1.9) API Doc
AbstractHttpPropertyIO AbstractPropertyIO Abstract class for handling properties via HttpServletRequest. - 1.8 API Doc
AbstractJDBCPropertyIO AbstractPropertyIO This handles all the SQL generation and for the tables and fields provided.
The only thing missing is the getConnection() method and getName().
- 1.0 API Doc
AbstractURLPropertyIO AbstractPropertyIO Abstract PropertyIO which gets Properties from an URL location. - 1.9 API Doc
AbstractXMLInputStreamPropertyIO AbstractPropertyIO Abstract input stream class for loading properties stored somewhere in a XML file. Readonly 1.3 API Doc
AbstractFilePropertyIO AbstractPropertyIO Abstract PropertyIO which gets Properties from an file location. - 2.0 API Doc
AbstractXMLFilePropertyIO AbstractFilePropertyIO Abstract file class for loading and saving properties stored somewhere in a XML file.
This included the method for reload and the attributes for caching and readonly.
- 1.9 API Doc
Abstract Class Parent class Description Restrictions Version Javadoc


Concrete Class Parent class Description Restrictions Version Javadoc Example
CompositePropertyIO AbstractPropertyIO Implements the Composite pattern and gets properties from multiple PropertyIO's. The CompositePropertyIOFactory can assist in construction. - 1.0 API Doc Examples
FilePropertyIO AbstractFilePropertyIO Load and saves the property to a file which is provided in the constructor. - 1.0 API Doc Examples
InputStreamPropertyIO AbstractPropertyIO Loads the properties for an InputStream. Readonly 1.3 API Doc Examples
JBossSystemPropertiesPropertyIO AbstractPropertyIO Specialized IO - Implements the AbstractPropertyIO class and gets properties from the <system-properties> which is standard in fx. JBoss standalone.xml. - 1.3 (1.9) API Doc Examples
ManifestPropertyIO AbstractPropertyIO Loads simple properties from a MANIFEST.MF file. Either from resource, file, jar, war, ear, zip or url. Readonly 1.9 API Doc Examples
MemoryPropertyIO AbstractPropertyIO This implementation can be base on another PropertyIO or java.util.Properties. This is mainly used for testing purposes.
But there is potential use in several other places for this IO.
- 1.0 API Doc Examples
ResourceBundlePropertyIO AbstractPropertyIO Gets the properties using the class loader ResourceBundle.getBundle() which is transfered to Properties. Locale can be provided as well in constructor. Readonly 2.0 API Doc Examples
ResourceStreamPropertyIO AbstractPropertyIO Gets the properties using the class loader getResourceAsStream(). This can be provided in several ways in the constructor. Readonly 1.0 (2.0) API Doc Examples
ServletContextPropertyIO AbstractPropertyIO Loads the property file from a file, resolving the path with getServletContext().getRealPath(getResourceName()). - 1.0 API Doc Examples
WebContextParamsPropertyIO AbstractPropertyIO Loads the InitParameters defined by the ServletContext.getInitParameterNames() into a memory stored Properties instance. Readonly 1.1 API Doc Examples
HttpCookiesPropertyIO AbstractHttpPropertyIO Communicate with Cookie data from the HttpServletRequest and HttpServletResponse. - 1.6 (1.8) API Doc Examples
HttpRequestParamsPropertyIO AbstractHttpPropertyIO Loads the properties for HttpServletRequest parameters. Readonly 1.8 API Doc Examples
HttpRequestHeadersPropertyIO AbstractHttpPropertyIO Loads the properties for HttpServletRequest headers. Readonly 1.8 API Doc Examples
HttpRequestPropertyIO AbstractHttpPropertyIO Loads the properties for HttpServletRequest headers and HttpServletRequest parameters. Readonly 1.8 API Doc Examples
HttpResponseHeadersPropertyIO AbstractHttpPropertyIO Load and writes the properties for HttpServletResponse headers. - 1.8 API Doc Examples
DatasourceJDBCPropertyIO AbstractJDBCPropertyIO Gets the connection by a datasource name which is provided in the constructor. - 1.0 API Doc Examples
UrlJDBCPropertyIO AbstractJDBCPropertyIO Gets the connection by a driver, url, username and password which is provided in the constructor. - 1.0 API Doc Examples
XMLParsedFilePropertyIO AbstractXMLFilePropertyIO Loads and saves via a XMLPropertiesParser implementation. - 1.9 API Doc Examples
Concrete Class Parent class Description Restrictions Version Javadoc Example




Note: The DemoProperties is the interface when you have defined the Property's is static members, see example Getting Started.


Examples



Example : CompositePropertyIO

public class CompositeDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private CompositeDemoProperties(PropertyIO[] ios) {
		super(new CompositePropertyIO(ios);
		
	}
	static {
		PropertyIO[] ios = {
			new MemoryPropertyIO(System.getProperties(),true),
			new ResourceStreamPropertyIO(ResourceStreamProperties.class)
		};
			
		new CompositeDemoProperties(ios);
	}

}


Example : FilePropertyIO

public class FileDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private FileDemoProperties(boolean readonly, boolean cached) {
		super(new FilePropertyIO(new File("c:/app/resources/properties/app.properties",readonly,cached));
	}

	static {
		new FileDemoProperties(false, true);
	}

}


Example : InputStreamPropertyIO

public class InputStreamPropertiesDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private JBossSystemPropertiesDemoProperties() {
		super(new InputStreamPropertyIO(new FileInputStream(new File("c:/app/resources/properties/standalone.xml")));
	}

	static {
		new InputStreamPropertiesDemoProperties();
	}

}


Example : JBossSystemPropertiesPropertyIO

public class JBossSystemPropertiesDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private JBossSystemPropertiesDemoProperties(boolean readonly, boolean cached) {
		super(new JBossSystemPropertiesPropertyIO(new File("c:/app/resources/properties/standalone.xml",readonly,cached));
	}

	static {
		new JBossSystemPropertiesDemoProperties(false, true);
	}

}


Example : ManifestPropertyIO

public class MyManifestCollection extends ManifestMainCollection {

	private MyManifestCollection(ManifestPropertyIO io) {
		super(io);
	}	
	
	public static ManifestMainCollection getInstance(ManifestPropertyIO io) {
		ManifestMainCollection collection = new ManifestMainCollection(io);
		PropertyFieldCollection.initialize(collection);
		return collection;
	}
	
	public static ManifestMainCollection getInstance() {
		return getInstance(new ManifestPropertyIO);
	}	
			
}


Example : MemoryPropertyIO

public class MemoryDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private MemoryDemoProperties(boolean readonly) {
		super(new MemoryPropertyIO(System.getProperties(),readonly));
	}

	static {
		new MemoryDemoProperties(true);
	}

}


Example 01 : ResourceBundlePropertyIO

public class ResourceBundleDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private ResourceBundleDemoProperties(boolean readonly) {
		super(new ResourceBundlePropertyIO("resourcebundle.properties"));		
	}

	static {
		new ResourceBundleDemoProperties(true);
	}

}

Example 02 : ResourceBundlePropertyIO

public class ResourceBundleDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private ResourceBundleDemoProperties(boolean readonly) {
		super(new ResourceBundlePropertyIO("properties/Horse",Locale.FRENCH));		
	}

	static {
		new ResourceBundleDemoProperties(true);
	}

}


Example 01 : ResourceStreamPropertyIO

public class ResourceStreamDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private ResourceStreamDemoProperties(boolean readonly) {
		super(new ResourceStreamPropertyIO("dk/heick/properties/io/demo/resourcefile.properties");
		
	}
	static {
		new ResourceStreamDemoProperties(true);
	}

}


Example 02 : ResourceStreamPropertyIO

public class ResourceStreamDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private ResourceStreamDemoProperties(boolean readonly) {
		super(new ResourceStreamPropertyIO(ResourceFileProperties.class);
		
	}
	static {
		new ResourceStreamDemoProperties(true);
	}

}


Example : ServletContextPropertyIO

Defined a ServletContextListener.
	public class WebContext implements ServletContextListener {
		@Override
		public void contextDestroyed(ServletContextEvent arg0) {
			//		
		}
		@Override
		public void contextInitialized(ServletContextEvent context) {		
			WebDemoProperties.getInstance(context.getServletContext());			
		}
	}
Configure it in "web.xml".
	<listener>
		<listener-class>dk.heick.properties.webdemo.WebContext</listener-class>
	</listener>
Your properties file is stored in your WAR file in
	[WAR_File.war]/config/demo.app.properties
Define your properties and your initialization.
	public class WebDemoProperties extends PropertyStaticCollection implements MarkerNoPropertyCollectionRegistry {
		//your property final static definitions
	
		private static WebDemoProperties instance = null;
		private final static String FILENAME_PROPERTIES="config/demo.app.properties";
	
		public WebDemoProperties(ServletContext context) {
			super(new ServletContextPropertyIO(context,FILENAME_PROPERTIES));
		}
		
		public static WebDemoProperties getInstance(ServletContext context) {		
			if (instance==null) {			
				try {				
					instance = new WebDemoProperties(context);				
				} catch (Throwable t) {
					t.printStackTrace();
				}
			}
			return instance;		
		}
		
		public static WebDemoProperties getInstance() {
			return instance;		
		}		
	}


Example : WebContextParamsPropertyIO

public class WebContextParamsDemoProperties extends PropertyStaticCollection implements DemoProperties,MarkerNoPropertyCollectionRegistry {
	
	public WebContextParamsDemoProperties(ServletContext servletContext) {
		super(new WebContextParamsPropertyIO(servletContext);		
	}


}


Example : HttpCookiesPropertyIO

public class MyServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//Will properly only load this one time an store in HttpSession.
		
		Property<String> name1 = new Property<String>("name1",new StringPropertyType());
		Property<Double> name2 = new Property<Double>("name2",new DoublePropertyType());
		Property<Date> name3 = new Property<Date>("name3",new DateTimePropertyType());
		//
		Log log = LogFactory.getLog(MyServlet.class);
		HttpCookiesPropertyIO io = new HttpCookiesPropertyIO(request,response);
		PropertyListCollection collection = new PropertyListCollection(io, log, new LoggingPropertyValidationHandler(), name1,name2,name3);
		
		String value1 = name1.getTypedValue();
		Double value2 = name2.getTypedValue();
		Date value3 = name3.getTypedValue();
		//
		value3.setTypedValue(new Date());
		//
		Cookie cookie2 = io.getCookie(name2);
		//
		Cookie cookie1 = io.getCookieForUpdate("name1");
		cookie1.setMaxAge(60*60*24*365);  			
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response)
	}	
}
Alternative
public class MyServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Property<String> name1 = new Property<String>("name1",new StringPropertyType());
		Property<Double> name2 = new Property<Double>("name2",new DoublePropertyType());
		Property<Date> name3 = new Property<Date>("name3",new DateTimePropertyType());
		//
		HttpCookiesPropertyIO io = HttpPropertyIOFactory.constructForCookies(request,response,name1,name2,name3);
		//			
		String value1 = name1.getTypedValue();
		Double value2 = name2.getTypedValue();
		Date value3 = name3.getTypedValue();
		//
		value3.setTypedValue(new Date());
		//
		Cookie cookie2 = io.getCookie(name2);
		//
		Cookie cookie1 = io.getCookieForUpdate("name1");
		cookie1.setMaxAge(60*60*24*365);  			
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response)
	}	
}


Example : HttpRequestParamsPropertyIO

HttpRequestParamsPropertyIO io = new HttpRequestParamsPropertyIO(httpServletRequest);


Example : HttpRequestHeadersPropertyIO

public class HttpRequestHeadersProperties extends PropertyExposedFinalFieldCollection implements MarkerNoPropertyCollectionRegistry {

	public final Property<String> HOST = new Property<String>("host",new StringPropertyType());
	public final Property<String> CONNECTION = new Property<String>("connection",new StringPropertyType());
	public final Property<String> ACCEPT = new Property<String>("accept",new StringPropertyType());
	public final Property<String> USER_AGENT = new Property<String>("user-agent",new StringPropertyType());
	public final Property<URL> REFERER = new Property<URL>("referer",new URLPropertyType(URLPropertyType.NO_URL_TEST));
	public final Property<String> ACCEPT_LANGUAGE = new Property<String>("accept-language",new StringPropertyType());

	private HttpRequestProperties(HttpServletRequest request) {
		super(new HttpRequestHeadersPropertyIO(request));
	}
	
	public static HttpRequestProperties getInstance(HttpServletRequest request) {
		HttpRequestProperties collection = new HttpRequestProperties(request);
		PropertyFieldCollection.initialize(collection);
		return collection;
	}
	
	

}
	
public class MyServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpRequestHeadersProperties headers = HttpRequestHeadersProperties.getInstance(request);
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response)
	}
}


Example : HttpRequestPropertyIO

HttpRequestPropertyIO io = new HttpRequestPropertyIO(httpServletRequest);


Example : HttpResponseHeadersPropertyIO

HttpResponseHeadersPropertyIO io = new HttpResponseHeadersPropertyIO(httpServletRequest,httpServletResponse);


Example : DatasourceJDBCPropertyIO

public class DatasourceJDBCDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	public static String JNDI_NAME="java:/comp/env/jdbc/nameofmyjdbcresource";

	private DatasourceJDBCDemoProperties(boolean readonly, boolean cached) {
		super(new DatasourceJDBCPropertyIO(
				JNDI_NAME, 
				"MYCONFIG", 
				"NAME",
				"VALUE", 
				readonly, 
				cached));
	}

	static {
		new DatasourceJDBCDemoProperties(false, true);
	}

}


Example : UrlJDBCPropertyIO

public class UrlJDBCDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private UrlJDBCDemoProperties(boolean readonly,boolean cached) {
		super(new UrlJDBCPropertyIO(
				DaoTestingFramework.DRIVER, 
				DaoTestingFramework.URL, 
				DaoTestingFramework.USER, 
				DaoTestingFramework.PASS, 
				"MYCONFIG", 
				"NAME", 
				"VALUE", 
				readonly, 
				cached)
			);
	}
	
	static  {		
		new UrlJDBCDemoProperties(false,true);		
	}
}


Example : XMLParsedFilePropertyIO

public class XmlFileDemoProperties extends PropertyStaticCollection implements DemoProperties {
	
	private XmlFileDemoProperties (boolean readonly,boolean cached) {
		super(new XMLParsedFilePropertyIO(new File ("src/test/resources/jboss_expected.xml"),new JBossSystemPropertiesXMLParser()));
	}
	
	static  {		
		new XmlFileDemoProperties (false,true);		
	}
}