KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > tests > DeployableAppTest


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.tests;
25
26 import java.util.logging.Level JavaDoc;
27
28 import com.sun.enterprise.config.ConfigException;
29 import com.sun.enterprise.config.ConfigContextEvent;
30 import com.sun.enterprise.config.ConfigBean;
31 import com.sun.enterprise.config.serverbeans.validation.Result;
32 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
33 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
34
35 /**
36    Instances of this class represent applications taht can be
37    deployed. They provide a deeper validation by supplying the ability
38    to validate their object type attribute - updates and deletions are
39    only allowed if this attribute has the value 'user'
40  */

41 abstract class DeployableAppTest extends GenericValidator
42 {
43
44     DeployableAppTest(final ValidationDescriptor desc){
45         super(desc);
46     }
47
48     public Result validate(ConfigContextEvent cce) {
49         Result result = super.validate(cce); // Before doing custom
50
// validation do basic
51
// validation
52
try{
53             if(cce.getChoice().equals(StaticTest.UPDATE) || cce.getChoice().equals(StaticTest.DELETE)) {
54             
55                 if(!getObjectType(cce).equals("user"))
56                     result.failed(smh.getLocalString(getClass().getName()+".systemAppNotChangeable",
57                                                      "System Application, Attribute Not Changeable"));
58             }
59         }
60         catch (final ConfigException ce){
61             _logger.log(Level.WARNING, "domainxmlverifier.exception", ce);
62         }
63         return result;
64     }
65
66         /**
67            Return the object type given the config bean of the
68            deployable app.
69            @param app the application whose object type we want
70            @return the value of the object-type attribute
71         */

72     protected abstract String JavaDoc getObjectType(final ConfigBean app);
73     
74         /**
75            Return the object type from the receiver's class object.
76          */

77         // Implementor's note - this is only valid for operations
78
// other than SET - if the operation is a SET operation then
79
// the value object can be an array of config beans, and this
80
// isn't implemented.
81
private String JavaDoc getObjectType(final ConfigContextEvent cce) throws ConfigException{
82         return getObjectType(getApp(cce));
83     }
84
85     private ConfigBean getApp(final ConfigContextEvent cce) throws ConfigException{
86         return (ConfigBean) cce.getValidationTarget();
87     }
88
89         
90 }
91
92
93         
94
Popular Tags