KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > AttrAddress


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.config.serverbeans.validation;
25
26 import java.util.Vector JavaDoc;
27 import java.net.InetAddress JavaDoc;
28 import java.net.UnknownHostException JavaDoc;
29 import com.sun.enterprise.config.serverbeans.validation.tests.StaticTest;
30
31 /**
32    Class which contains Meta data for all types of attributes which is present in Validation Descriptor
33    * XML File
34    *
35    * Sample
36    * <attribute name=<Name> type="address" />
37    * <attribute name=<Name> type="integer" range="low,high" />
38    * <attribute name=<Name> type="string" max-length="length" />
39     
40    @author Srinivas Krishnan
41    @version 2.0
42 */

43
44 /* Class for attribute type address (IP Address) */
45
46 public class AttrAddress extends AttrType {
47     
48     public AttrAddress(String JavaDoc name, String JavaDoc type, boolean optional) {
49         super(name,type, optional);
50     }
51     
52     public void validate(Object JavaDoc o, ValidationContext valCtx) {
53         super.validate(o, valCtx); // call to common validator first
54
String JavaDoc address = null;
55         if(o == null)
56             return;
57         if(o.equals("")) {
58             valCtx.result.failed(valCtx.smh.getLocalString(getClass().getName() + ".invalidNullStrAddress",
59                                                              "Attribute({0}=null) : Null address not permitted", new Object JavaDoc[]{valCtx.attrName}));
60             return;
61         }
62         address = (String JavaDoc)o;
63         try {
64             StaticTest.checkIPAddress(address);
65         } catch(UnknownHostException JavaDoc u) {
66             valCtx.result.failed(valCtx.smh.getLocalString(getClass().getName() + ".invalidAddress",
67                                                              "Attribute({0}={1}) : Invalid address syntax - {1}",
68                                                              new Object JavaDoc[]{valCtx.attrName,address}));
69         }
70     }
71     
72 }
73
Popular Tags