[Index]

Property Collections and Registry


A PropertyCollection is holds a list of Property's.
It has access to PropertyIO.
There it is the center point from which to access and manage your properties.

There current model look like this:


Class Description Restrictions Examples Link
PropertyCollection Interface which all PropertyCollections must implement. None N/A JavaAPI Doc
PropertyListCollection Initializes the collection via list or array Property's provided in the constructor. None [LINK] JavaAPI Doc
PropertyFieldCollection Initializes the collection via reflection, look for members in a class of type Property which is accepted by the PropertyFieldFilter. None [LINK] JavaAPI Doc
PropertyExposedFieldCollection Initializes the collection via reflection, look members which is either "public"" or "protected" in a class of type Property. None [LINK] JavaAPI Doc
PropertyExposedFinalFieldCollection Initializes the collection via reflection, look for members in a class which is "final" and either "public" or "protected" of type Property. None [LINK] JavaAPI Doc
PropertyStaticCollection Initializes the collection via reflection, look for static members in a class of type Property. None [LINK] JavaAPI Doc


Initialization - Static fields VS None-Static field
When using the "PropertyStaticCollection" it is enough just to intialize with the constructor.
public class MyPropertiesDemo extends PropertyStaticCollection implements MyProperties {
	public MyPropertiesDemo(FilePropertyIO io)  {
		super(io);          
	}
} 
BUT if using NONE STATIC fields, then there is an extra STEP.
The reason is that the reflection code to find Property fields, can not see the none-static fields without an instance.
public class MyPropertiesDemo extends PropertyExposedFinalFieldCollection {

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

	public static MyPropertiesDemo getInstance() {
		return getInstance(new ManifestPropertyIO());
	}			
}


Registry
All implementations of PropertyCollections, must in their constructor call.
PropertyCollectionRegistry.register(this);

PropertyCollectionRegistry stores all PropertyCollections which has an instance, by the key.
collection.getClass().getName();
Via the static methods in PropertyCollectionRegistry you can access these PropertyCollections.

IMPORTANT: This registry will shared across the VM, so if different application or areas or not allowed to see eachother collections either
  • remove the collection in the constructor
  • or turn of collection registry
  • or implement the Collection with the MarkerNoPropertyCollectionRegistry interface.
  • or override "getRegistryTimeout" method on PropertyCollection. (timout<0 : no timeout | timeout=0 : do not register | timeout>0 : milliseconds)


Some PropertyIO isnt suitable for storing in PropertyCollectionRegistry, like
  • HttpCookiesPropertyIO
  • HttpRequestParamsPropertyIO
  • HttpRequestHeadersPropertyIO
  • HttpRequestPropertyIO
  • HttpResponseHeadersPropertyIO

Otherwise override the "getName()" method for the collection and include a thread name in it.

Example:
 	@Override
	public void preValidation() {			
		PropertyCollectionRegistry.removeRegister(this);
	}
 

Example:
	@Override
	public void preValidation() {			
		PropertyFrameworkGlobals.setAutoRegisterPropertyCollections(false);
	}

Example:
public class MyPropertiesDemo extends PropertyExposedFinalFieldCollection implements MarkerNoPropertyCollectionRegistry {

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

	public static MyPropertiesDemo getInstance() {
		return getInstance(new ManifestPropertyIO());
	}			
}

Example:
public class MyPropertiesDemo extends PropertyExposedFinalFieldCollection  {

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

	public static MyPropertiesDemo getInstance() {
		return getInstance(new ManifestPropertyIO());
	}	
	public long getRegistryTimeout() {
		return 0; 		
	}
Class Description Restrictions Link
PropertyCollectionRegistry Class where PropertyCollections is registered. None JavaAPI Doc
Notes
Remember you can always choose to override the method "public void postValidation() throws PropertyException".
After the PropertyCollection has validation the PropertyIO and all the Properties, it calls this method.
This is implemented empty in all the framework implementations, but can be overrride in the your on instance of a PropertyCollection.
This is use to make cross validation of Properties. If Property A is defined, than Property B,C and D must also be defined.
public class MyPropertiesDemo extends PropertyStaticCollection implements MyProperties {
	public MyPropertiesDemo(FilePropertyIO io)  {
		super(io);          
	}
	
	//Optional implementation of this method
	public void preValidation()  {
		//Typical where you setup global parameters.
	}

	//Optional implementation of this method
	public void postValidation() throws PropertyException {
		ActivationValidator activator = new ActivationValidator();
		activator.given(MyProperties.PORT_NUMBER.getTypedValue()==443,MyProperties.A_SSL_CONFIG);
		activator.given(MyProperties.PORT_NUMBER.getTypedValue(),443,MyProperties.A_SSL_CONFIG);
		activator.given(MyProperties.MY_STRING,MyProperties.MY_NUMBER_A,MyProperties.MY_NUMBER_B,MyProperties.MY_NUMBER_C,MyProperties.MY_NUMBER_D);
	}
      
}
 


Example : PropertyListCollection

		Property<String> p1 = new Property<String>("p1",new StringPropertyType());
		Property<URL> p2 = new Property<URL>("p2",new URLPropertyType());
		Property<Integer> p3 = new Property<Integer>("p3",new IntegerPropertyType());
		List<Property<?>> propertyList = new ArrayList<Property<?>>();
		propertyList.add(p1);
		propertyList.add(p2);
		propertyList.add(p3);

		MemoryPropertyIO io = new MemoryPropertyIO(System.getProperties());
		Logger logger = Logger.getLogger(this.getClass());
		//
		PropertyListCollection collection = new PropertyListCollection(io, logger, propertyList,new LoggingPropertyValidationHandler());



Example : PropertyFieldCollection

	public class MyCollectionAllFields extends PropertyFieldCollection {
	
		public final Property<Boolean> P_BOOLEAN = new Property<Boolean>("p.boolean", new BooleanPropertyType());
		public final Property<Class<?>> P_CLASSNAME = new Property<Class<?>>("p.classname", new ClassnamePropertyType(null,A.class,new Class[]{I1.class,I2.class}));
		public final Property<Date> P_DATETME = new Property<Date>("p.datetime", new DateTimePropertyType(DateTimePropertyType.DEFAULT_DATETIME_FORMAT));
		public Property<Date> P_DATETME2 = new Property<Date>("p.datetime", new DateTimePropertyType(DateTimePropertyType.DEFAULT_DATETIME_FORMAT));
		public final static Property<Date> P_DATETME2 = new Property<Date>("p.datetime", new DateTimePropertyType(DateTimePropertyType.DEFAULT_DATETIME_FORMAT));
		
		private MyCollectionAllFields(Properties p) {
			super(PropertyFieldFilterFactory.getAllFields(),new MemoryPropertyIO(p));
		}
		
		public static MyCollectionAllFields getInstance(Properties p) {
			MyCollectionAllFields collection = new MyCollectionAllFields(p);
			PropertyFieldCollection.initialize(collection); 
			return collection;
		}
	}		


Example : PropertyExposedFieldCollection

	
	public class MyCollectionPublic extends PropertyExposedFieldCollection {
	
		public final Property<Boolean> P_BOOLEAN = new Property<Boolean>("p.boolean", new BooleanPropertyType());
		public final Property<Class<?>> P_CLASSNAME = new Property<Class<?>>("p.classname", new ClassnamePropertyType(null,A.class,new Class[]{I1.class,I2.class}));
		public final Property<Date> P_DATETME = new Property<Date>("p.datetime", new DateTimePropertyType(DateTimePropertyType.DEFAULT_DATETIME_FORMAT));
		public Property<Date> P_DATETME2 = new Property<Date>("p.datetime", new DateTimePropertyType(DateTimePropertyType.DEFAULT_DATETIME_FORMAT));
	
			
		private MyCollectionPublic(Properties p) {
			super(new MemoryPropertyIO(p));
		}
		
		public static MyCollectionPublic getInstance(Properties p) {
			MyCollectionPublic collection = new MyCollectionPublic(p);
			PropertyFieldCollection.initialize(collection); 
			return collection;
		}
	}		


Example : PropertyExposedFinalFieldCollection

		public class MyCollectionPublicFinal extends PropertyExposedFinalFieldCollection {			

			public final Property<Boolean> P_BOOLEAN = new Property<Boolean>("p.boolean", new BooleanPropertyType());
			public final Property<Class<?>> P_CLASSNAME = new Property<Class<?>>("p.classname", new ClassnamePropertyType(null,A.class,new Class[]{I1.class,I2.class}));
			public final Property<Date> P_DATETME = new Property<Date>("p.datetime", new DateTimePropertyType(DateTimePropertyType.DEFAULT_DATETIME_FORMAT));

			
			private MyCollectionPublicFinal(Properties p) {
				super(new MemoryPropertyIO(p));
			}
	
			public static MyCollectionPublicFinal getInstance(Properties p) {
				MyCollectionPublicFinal collection = new MyCollectionPublicFinal(p);
				PropertyFieldCollection.initialize(collection); 
				return collection;
			}
		}


Example : PropertyStaticCollection

		public class SingleDemoProperties extends PropertyStaticCollection {
			
			
			public final static Property<Boolean> P_BOOLEAN                      = new Property<Boolean>("p.boolean" , new BooleanPropertyType());
			public final static Property<Class<?>> P_CLASSNAME             	     = new Property<Class<?>>("p.classname", new ClassnamePropertyType(null,A.class,new Class[]{I1.class,I2.class}));
			public final static Property<Date> P_DATETIME                        = new Property<Date>("p.datetime", new DateTimePropertyType(DateTimePropertyType.DEFAULT_DATETIME_FORMAT));
			public final static Property<File> P_DIRECTORY                       = new Property<File>("p.directory", new DirectoryPropertyType());
			public final static Property<Double> P_DOUBLE                        = new Property<Double>("p.double", new DoublePropertyType(0,50));
			public final static Property<String> P_EMAIL                         = new Property<String>("p.email", new EmailPropertyType("heick.dk"));
			public final static Property<MyColors> P_ENUM_MYCOLORS               = new Property<MyColors>("p.enum.mycolors", new EnumPropertyType<MyColors>(MyColors.class));
			public final static Property<WildCardFilenameFilter> P_FILEFILTER    = new Property<WildCardFilenameFilter>("p.filefilter", new FilenameFilterPropertyType());
			public final static Property<File> P_FILE                            = new Property<File>("p.file", new FilePropertyType());
			public final static Property<HourIntervalsVO> P_HOURSPERIODS         = new Property<HourIntervalsVO>("p.hourperiods", new HourIntervalsPropertyType());
			public final static Property<Integer> P_INTEGER                      = new Property<Integer>("p.integer", new IntegerPropertyType(0,20000));
			public final static Property<List<URL>> P_LIST_URLS                  = new Property<List<URL>>("p.list.urls", new ListPropertyType<URL>(new URLPropertyType("http")));
			public final static Property<Long> P_LONG                            = new Property<Long>("p.long", new LongPropertyType(0L,null));
			public final static Property<PasswordTypeVO> P_PASSWORD_AES          = new Property<PasswordTypeVO>("p.password.aes", new PasswordAESPropertyType());
			public final static Property<PasswordTypeVO> P_PASSWORD_MD5          = new Property<PasswordTypeVO>("p.password.md5", new PasswordMD5PropertyType());
			public final static Property<String> P_STRING                        = new Property<String>("p.string", new StringPropertyType(80));
			public final static Property<URL> P_URL                              = new Property<URL>("p.url", new URLPropertyType("http"));
			public final static Property<Color> P_COLOR                          = new Property<Color>("p.color", new ColorPropertyType());
				
			protected SingleDemoProperties() {
				super(new FilePropertyIO(new File("resources/demo/demoalltypes.properties")));
			}
			
			static {
				new SingleDemoProperties();
			}
		
		}