1 18 package org.apache.beehive.netui.compiler.model.validation; 19 20 import org.apache.beehive.netui.compiler.model.schema.validator11.Arg0Document; 21 import org.apache.beehive.netui.compiler.model.schema.validator11.FieldDocument; 22 import org.apache.beehive.netui.compiler.model.schema.validator11.MsgDocument; 23 24 import java.lang.reflect.InvocationTargetException ; 25 26 public class ValidatableFieldOld extends ValidatableField 27 { 28 public ValidatableFieldOld( String propertyName, String displayName, String displayNameKey ) 29 { 30 super( propertyName, displayName, displayNameKey ); 31 } 32 33 37 void setDefaultArg0Element( String displayName, boolean displayNameIsResource, FieldDocument.Field fieldElement ) 38 { 39 Arg0Document.Arg0[] arg0Array = fieldElement.getArg0Array(); 40 Arg0Document.Arg0 defaultArg0Element = null; 41 42 for ( int i = 0; i < arg0Array.length; i++ ) 43 { 44 Arg0Document.Arg0 arg0 = arg0Array[i]; 45 if ( arg0.getName() == null ) 46 { 47 defaultArg0Element = arg0; 48 break; 49 } 50 } 51 52 if ( defaultArg0Element == null && _rules.size() > 0 ) 53 { 54 defaultArg0Element = fieldElement.addNewArg0(); 55 } 56 57 if ( defaultArg0Element != null ) 58 { 59 defaultArg0Element.setKey( displayName ); 60 defaultArg0Element.setResource( Boolean.toString( displayNameIsResource ) ); 61 } 62 } 63 64 void setRuleMessage( ValidatorRule rule, FieldDocument.Field fieldElement ) 65 { 66 String messageKey = rule.getMessageKey(); 67 String message = rule.getMessage(); 68 69 if ( messageKey != null || message != null ) 70 { 71 MsgDocument.Msg[] existingMsgElements = fieldElement.getMsgArray(); 72 MsgDocument.Msg msgElementToUse = null; 73 74 for ( int j = 0; j < existingMsgElements.length; j++ ) 75 { 76 MsgDocument.Msg existingMsgElement = existingMsgElements[j]; 77 if ( rule.getRuleName().equals( existingMsgElement.getName() ) ) 78 { 79 msgElementToUse = existingMsgElement; 80 break; 81 } 82 } 83 84 if ( msgElementToUse == null ) 85 { 86 msgElementToUse = fieldElement.addNewMsg(); 87 msgElementToUse.setName( rule.getRuleName() ); 88 } 89 90 if ( messageKey != null ) 91 { 92 msgElementToUse.setKey( messageKey ); 93 msgElementToUse.setResource( Boolean.TRUE.toString() ); 94 } 95 else { 97 msgElementToUse.setKey( ValidatorConstants.EXPRESSION_KEY_PREFIX + message ); 101 msgElementToUse.setResource( Boolean.TRUE.toString() ); 102 } 103 } 104 } 105 106 111 void setRuleArg( ValidatorRule rule, int argNum, FieldDocument.Field fieldElement, String altMessageVar ) 112 { 113 try 114 { 115 Class fieldElementClass = fieldElement.getClass(); 116 ValidatorRule.MessageArg arg = rule.getArg( new Integer ( argNum ) ); 117 118 String ruleName = rule.getRuleName(); 119 Object argElementToUse = null; 120 Object [] existingArgElements = 121 ( Object [] ) fieldElementClass.getMethod( "getArg" + argNum + "Array", null ).invoke( fieldElement, null ); 122 123 for ( int i = 0; i < existingArgElements.length; i++ ) 124 { 125 Object existingElement = existingArgElements[i]; 126 if ( ruleName.equals( existingElement.getClass().getMethod( "getName", null ).invoke( existingElement, null ) ) ) 127 { 128 argElementToUse = existingElement; 129 break; 130 } 131 } 132 133 if ( arg != null || altMessageVar != null ) 134 { 135 if ( argElementToUse == null ) 136 { 137 argElementToUse = fieldElementClass.getMethod( "addNewArg" + argNum, null ).invoke( fieldElement, null ); 138 } 139 140 Class argElementToUseClass = argElementToUse.getClass(); 141 142 if ( arg != null ) 143 { 144 String argMessage = arg.getMessage(); 145 String key = arg.isKey() ? argMessage : ValidatorConstants.EXPRESSION_KEY_PREFIX + argMessage; 146 argElementToUseClass.getMethod( "setKey", new Class []{ String .class } ).invoke( argElementToUse, new Object []{ key } ); 147 String isResource = Boolean.TRUE.toString(); 148 argElementToUseClass.getMethod( "setResource", new Class []{ String .class } ).invoke( argElementToUse, new Object []{ isResource } ); 149 argElementToUseClass.getMethod( "setName", new Class []{ String .class } ).invoke( argElementToUse, new Object []{ ruleName } ); 150 } 151 else 152 { 153 altMessageVar = "${var:" + altMessageVar + '}'; 154 argElementToUseClass.getMethod( "setKey", new Class []{ String .class } ).invoke( argElementToUse, new Object []{ altMessageVar } ); 155 argElementToUseClass.getMethod( "setResource", new Class []{ String .class } ).invoke( argElementToUse, new Object []{ "false" } ); 156 argElementToUseClass.getMethod( "setName", new Class []{ String .class } ).invoke( argElementToUse, new Object []{ ruleName } ); 157 } 158 } 159 } 160 catch ( NoSuchMethodException e ) 161 { 162 assert false : e; } 164 catch ( IllegalAccessException e ) 165 { 166 assert false : e; } 168 catch ( InvocationTargetException e ) 169 { 170 assert false : e; } 172 } 173 } 174 | Popular Tags |