From 24223ea0b7563b41334361646e88c0d69845e2cd Mon Sep 17 00:00:00 2001
From: Purodha <bli00@hostsharing.net>
Date: Wed, 20 Feb 2013 11:37:36 +0100
Subject: [PATCH] Another step of handling the annotation of selectableValues.

---
 hsarback/src/de/hsadmin/core/model/AnnFieldIO.java         |    1 +
 hsarback/src/de/hsadmin/remote/ModulePropertiesRemote.java |   27 +++++++++++++++++++--------
 hsarback/src/de/hsadmin/mods/dom/Domain.java               |    2 +-
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/hsarback/src/de/hsadmin/core/model/AnnFieldIO.java b/hsarback/src/de/hsadmin/core/model/AnnFieldIO.java
index 3e534d6..105eaee 100644
--- a/hsarback/src/de/hsadmin/core/model/AnnFieldIO.java
+++ b/hsarback/src/de/hsadmin/core/model/AnnFieldIO.java
@@ -11,5 +11,6 @@
 	String validation() default "[A-Za-z0-9\\_\\-]*";
 	ReadWriteAccess rw() default ReadWriteAccess.WRITEONCE;
 	Class<?> referTo() default Void.class;
+	Class<? extends DefaultSelectableValues> selectableValues() default DefaultSelectableValues.class;
 	String[] referredProps() default { };
 }
diff --git a/hsarback/src/de/hsadmin/mods/dom/Domain.java b/hsarback/src/de/hsadmin/mods/dom/Domain.java
index 6342282..c84f734 100644
--- a/hsarback/src/de/hsadmin/mods/dom/Domain.java
+++ b/hsarback/src/de/hsadmin/mods/dom/Domain.java
@@ -56,7 +56,7 @@
 	@Column(name = "domain_dns_master", columnDefinition = "character varying(64)")
 	private String dnsMaster;
 
-	@AnnFieldIO(validation="[a-zA-Z0-9\\-\\.]*", rw=ReadWriteAccess.READWRITE, referTo=DomainOption.class)
+	@AnnFieldIO(validation="[a-zA-Z0-9\\-\\.]*", rw=ReadWriteAccess.READWRITE, referTo=DomainOption.class, selectableValues=DomainOptionValues.class)
 	@ManyToMany(fetch=FetchType.EAGER, cascade=CascadeType.PERSIST)
 	@JoinTable(name="domain__domain_option", 
 		joinColumns={@JoinColumn(name="domain_id", referencedColumnName="domain_id")},
diff --git a/hsarback/src/de/hsadmin/remote/ModulePropertiesRemote.java b/hsarback/src/de/hsadmin/remote/ModulePropertiesRemote.java
index e2313be..dc304d9 100644
--- a/hsarback/src/de/hsadmin/remote/ModulePropertiesRemote.java
+++ b/hsarback/src/de/hsadmin/remote/ModulePropertiesRemote.java
@@ -13,6 +13,7 @@
 import de.hsadmin.core.model.AuthenticationException;
 import de.hsadmin.core.model.HSAdminException;
 import de.hsadmin.core.model.ReadWriteAccess;
+import de.hsadmin.core.model.SelectableValue;
 import de.hsadmin.core.model.Transaction;
 
 public class ModulePropertiesRemote implements IRemote {
@@ -42,7 +43,7 @@
 						for (Field f: entityClass.getDeclaredFields()) {
 							HashMap<String, Object> propertyProperties = new HashMap<String, Object>();
 							AnnFieldIO fieldIO = f.getAnnotation(AnnFieldIO.class);
-							if (fieldIO != null){
+							if (fieldIO != null) {
 								String fieldName = f.getName();
 								propertyProperties.put("property", fieldName);
 								String regExp = fieldIO.validation();
@@ -50,14 +51,24 @@
 								ReadWriteAccess rw = fieldIO.rw();
 								propertyProperties.put("rw", rw.name());
 								String[] referredProps = fieldIO.referredProps();
-								propertyProperties.put("referredProps", referredProps);							
-				//				Class<?> declaringClass = f.getDeclaringClass();					
+								propertyProperties.put("referredProps", referredProps);						
+				//				Class<?> declaringClass = f.getDeclaringClass();
 				//				         declaringClass = f.getDeclaringClass();
-								for(String s : referredProps){					
-									String fullPropertyName = fieldName+"."+s;			
+								for(String s : referredProps) {					
+									String fullPropertyName = fieldName+"."+s;
 									propertiesList.add(createReferredPropertyInfo(fullPropertyName, f, s));
 								}
-								AddCommonPropertyInfo(propertyProperties, f);
+								ArrayList<Map<String,Object>> selectableValueslist = new ArrayList<Map<String,Object>>();
+								List<SelectableValue> selectableValues = fieldIO.selectableValues().newInstance().get();
+								propertyProperties.put("selectableValues", selectableValueslist);	
+			  					for( SelectableValue s : selectableValues) {					
+									String SelectableValueName = s.getName();			
+									Object SelectableValues = s.getValues();
+									Map<String, Object> m = new HashMap<String, Object>();
+									m.put(SelectableValueName, SelectableValues); 
+									selectableValueslist.add(m);
+								}
+								addCommonPropertyInfo(propertyProperties, f);
 								propertiesList.add(propertyProperties);
 							}
 						}											
@@ -105,11 +116,11 @@
 //			trace = trace + " TF=" + field.getName();
 			remainingPart = remainingPart.substring(indexOfDot + 1);
 		}
-		AddCommonPropertyInfo(result, field);
+		addCommonPropertyInfo(result, field);
 		return result;
 	}
 
-	private void AddCommonPropertyInfo(Map<String, Object> propertyInfo, Field sourceField) {
+	private void addCommonPropertyInfo(Map<String, Object> propertyInfo, Field sourceField) {
 			propertyInfo.put("type", sourceField.getType().getName());
 	}
 

--
Gitblit v1.9.0-SNAPSHOT