KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > verifier > tests > StaticTest


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 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31
32 package com.sun.enterprise.admin.verifier.tests;
33
34 // <addition> srini@sun.com Bug : 4698687
35
// JMX Imports
36
import javax.management.ObjectName JavaDoc;
37 import javax.management.MalformedObjectNameException JavaDoc;
38
39 // 8.0 XML Verifier
40
//import com.sun.enterprise.tools.verifier.Result;
41
import com.sun.enterprise.admin.verifier.Result;
42 import com.sun.enterprise.config.ConfigContext;
43
44 import javax.xml.parsers.*;
45 import org.xml.sax.*;
46 import java.io.ByteArrayInputStream JavaDoc;
47 import java.io.IOException JavaDoc;
48
49 // Logging
50
import java.util.logging.Logger JavaDoc;
51 import java.util.logging.Level JavaDoc;
52 import com.sun.logging.LogDomains;
53
54 import com.sun.enterprise.config.serverbeans.*;
55
56
57 /* Test to check the Port validity
58  * Author : srini@sun.com
59  **/

60
61 public class StaticTest {
62     
63      // Logging
64
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
65
66     
67     //<addition author="irfan@sun.com" [bug/rfe]-id="4704985" >
68
/* Adding various constants to this file. This should remove the hard coded values that
69      * we are using in various tests.
70      */

71     
72     /** Represents the ADD configbean request*/
73     public static final String JavaDoc ADD = "ADD";
74     /** Represents the DELETE configbean request*/
75     public static final String JavaDoc DELETE = "DELETE";
76     /** Represents the UPDATE configbean request*/
77     public static final String JavaDoc UPDATE = "UPDATE";
78     /** Represents the SET configbean request*/
79     public static final String JavaDoc SET = "SET";
80     
81     public static final String JavaDoc IAS_NAME = "com.sun.appserv:name=";
82     public static final String JavaDoc XML_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <xml>";
83     public static final String JavaDoc XML_2 = "</xml>";
84     //</addition>
85

86     public StaticTest() {
87     }
88     
89     // check if port is within the range of 2^16
90
public static boolean isPortValid(int i){
91         if(i > 0 && i <= 65535)
92             return true;
93         else
94             return false;
95     }
96     
97     // Function added to check address if it needs to be resolved
98
// Bug : 4697248
99
public static boolean checkAddress(String JavaDoc address) {
100         if(address.equalsIgnoreCase("ANY") || address.equalsIgnoreCase("INADDR_ANY") ||
101                                 address.equalsIgnoreCase("localhost"))
102             return false;
103         else
104             return true;
105     }
106     
107     // Utility Function added Bug No. : 4698687
108
/**
109      * should just take in the id. construct the name inside this method
110      */

111     public static boolean checkObjectName(String JavaDoc id) throws MalformedObjectNameException JavaDoc {
112         String JavaDoc name = IAS_NAME + id;
113         ObjectName JavaDoc validObjectName = new ObjectName JavaDoc(name);
114         return true;
115     }
116     
117     /**
118      * method to be called by verifier
119      */

120     public static boolean checkObjectName(String JavaDoc id, Result result) {
121         try {
122             return checkObjectName(id);
123         } catch(MalformedObjectNameException JavaDoc ex) {
124             _logger.log(Level.FINE, "serverxmlverifier.exception", ex);
125             result.failed(ex.getMessage());
126             return false;
127         }
128     }
129     
130     /**
131      *external method to be called by instller, etc for checking if the string
132      * is a valid xml string
133      * This is a very expensive test. Be prudent in using it.
134      */

135     public static boolean checkXMLName(String JavaDoc name) throws SAXParseException, SAXException,
136                             IOException JavaDoc,
137                             ParserConfigurationException {
138             //Construct a valid xml string
139
String JavaDoc xml = XML_1 + name + XML_2;
140             ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(xml.getBytes());
141             InputSource is = new InputSource(bais);
142             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
143             dbf.setValidating(false);
144             DocumentBuilder db = dbf.newDocumentBuilder();
145             db.parse(is);
146             return true;
147     }
148     
149     /**
150      * method called by verifier for checking for a valid xml string
151      * This is a very expensive test. Be prudent in using it.
152      */

153     public static boolean checkXMLName(String JavaDoc name, Result result) throws SAXParseException {
154         try {
155             return checkXMLName(name);
156         } catch (Exception JavaDoc s) {
157             _logger.log(Level.FINE, "serverxmlverifier.exception", s);
158             result.failed(s.getMessage());
159             return false;
160         }
161     }
162     
163     /* Method to get the reference to config */
164     // 8.0 XML Verifier
165
public static Config getConfig(ConfigContext context) {
166         
167         Config mConfig=null;
168         try {
169             mConfig = ServerBeansFactory.getConfigBean(context);
170         } catch(Exception JavaDoc e) {
171         }
172         return mConfig;
173     }
174 }
175
Popular Tags