KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.logging.Level JavaDoc;
26
27 import com.sun.enterprise.config.ConfigContextEvent;
28 import com.sun.enterprise.config.ConfigException;
29 import com.sun.enterprise.config.serverbeans.MessageSecurityConfig;
30 import com.sun.enterprise.config.serverbeans.ProviderConfig;
31 import com.sun.enterprise.config.serverbeans.ServerTags;
32 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
33 import com.sun.enterprise.config.serverbeans.validation.Result;
34 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
35
36 public class ProviderConfigTest extends GenericValidator {
37     
38     private static final char [] illegalChars = {'*', ',', ':'};
39
40     public ProviderConfigTest (ValidationDescriptor desc) {
41         super(desc);
42     }
43
44     public Result validate(ConfigContextEvent cce) {
45
46         Result result = super.validate(cce);
47         try {
48             if (cce.getChoice().equals(StaticTest.DELETE)){
49                 if (isReferencedByParent(cce)){
50                     result.failed(
51                         smh.getLocalString(
52                             getClass().getName() + ".cannotDeleteReferencedProviderConfig",
53                             "provider config (provider-id={0}) can not be removed. It is referenced by its parent message-security-config",
54                             new Object JavaDoc[]{getProviderConfig(cce).getProviderId()}));
55                 }
56             }
57         }
58         catch (Exception JavaDoc e){
59             _logger.log(Level.FINE, "domainxmlverifier.exception", e);
60         }
61             
62         return result;
63     }
64
65     private final boolean isReferencedByParent(final ConfigContextEvent cce) throws ConfigException {
66         final ProviderConfig pc = getProviderConfig(cce);
67         final MessageSecurityConfig msc = (MessageSecurityConfig) pc.parent().parent();
68         return msc.getDefaultProvider() != null && msc.getDefaultProvider().equals(pc.getProviderId());
69     }
70
71     private ProviderConfig getProviderConfig(final ConfigContextEvent cce) throws ConfigException {
72         return (ProviderConfig) cce.getValidationTarget();
73     }
74     
75 }
76
Popular Tags