1 18 package org.apache.beehive.netui.compiler.model.validation; 19 20 import org.apache.beehive.netui.compiler.model.schema.validator11.FormsetDocument; 21 import org.apache.beehive.netui.compiler.model.schema.validator11.FormDocument; 22 23 import java.util.Locale ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import java.util.Iterator ; 27 28 public class LocaleSet 29 { 30 private Locale _locale; 31 private Map _entities = new HashMap (); 32 33 34 public LocaleSet() 35 { 36 _locale = null; } 38 39 public LocaleSet( Locale locale ) 40 { 41 _locale = locale; 42 } 43 44 public Locale getLocale() 45 { 46 return _locale; 47 } 48 49 public ValidatableEntity getEntity( String entityName ) 50 { 51 return ( ValidatableEntity ) _entities.get( entityName ); 52 } 53 54 public void addValidatableEntity( ValidatableEntity entity ) 55 { 56 _entities.put( entity.getEntityName(), entity ); 57 } 58 59 public void writeToXMLBean( FormsetDocument.Formset formset ) 60 { 61 if ( _locale != null ) 62 { 63 formset.setLanguage( _locale.getLanguage() ); 64 if ( _locale.getCountry().length() > 0 ) 65 { 66 formset.setCountry( _locale.getCountry() ); 67 if ( _locale.getVariant().length() > 0 ) 68 { 69 formset.setVariant( _locale.getVariant() ); 70 } 71 } 72 } 73 74 FormDocument.Form[] existingFormElements = formset.getFormArray(); 75 for ( Iterator i = _entities.values().iterator(); i.hasNext(); ) 76 { 77 ValidatableEntity entity = ( ValidatableEntity ) i.next(); 78 String entityName = entity.getEntityName(); 79 80 FormDocument.Form formElementToUse = null; 84 85 for ( int j = 0; j < existingFormElements.length; j++ ) 86 { 87 FormDocument.Form formElement = existingFormElements[j]; 88 89 if ( entityName.equals( formElement.getName() ) ) 90 { 91 formElementToUse = formElement; 92 break; 93 } 94 } 95 96 if ( formElementToUse == null ) 97 { 98 formElementToUse = formset.addNewForm(); 99 formElementToUse.setName( entityName ); 100 } 101 102 entity.writeToXMLBean( formElementToUse ); 103 } 104 } 105 } 106 | Popular Tags |