KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.config.serverbeans.validation.tests.StaticTest;
27 import java.io.File JavaDoc;
28
29 /**
30     Class which contains Meta data for all types of attributes which is present in Validation Descriptor
31  * XML File
32  *
33  * Sample
34  * <attribute name=<Name> type="address" />
35  * <attribute name=<Name> type="integer" range="low,high" />
36  * <attribute name=<Name> type="string" max-length="length" />
37     
38     @author Srinivas Krishnan
39     @version 2.0
40 */

41
42 /* Class for attribute type file */
43
44 public class AttrFile extends AttrType {
45     
46     boolean checkExists;
47     
48     public AttrFile(String JavaDoc name, String JavaDoc type, boolean optional) {
49         super(name,type, optional);
50         checkExists = false;
51     }
52     
53     public void setCheckExists(boolean flag) {
54         checkExists = flag;
55     }
56     
57     public void validate(Object JavaDoc o, ValidationContext valCtx) {
58         super.validate(o, valCtx); // call to common validator first
59
if(o == null || o.equals(""))
60         return;
61         if(checkExists || StaticTest.fileCheck) {
62             File JavaDoc f = new File JavaDoc((String JavaDoc)o);
63             if(!f.exists())
64                valCtx.result.failed(valCtx.smh.getLocalString(getClass().getName() + ".fileNotExists",
65                                             "Attribute({0}={1}) : {2} : Does not exists", new Object JavaDoc[] {valCtx.attrName, o, o}));
66             else if(!f.canRead())
67                valCtx.result.failed(valCtx.smh.getLocalString(getClass().getName() + ".filecannotRead",
68                                             "Attribute({0}={1}) : {2} : Does not have read permission", new Object JavaDoc[] {valCtx.attrName, o, o}));
69         }
70     }
71 }
72
Popular Tags