1 23 24 31 32 package com.sun.enterprise.admin.verifier.tests; 33 34 import javax.management.ObjectName ; 37 import javax.management.MalformedObjectNameException ; 38 39 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 ; 47 import java.io.IOException ; 48 49 import java.util.logging.Logger ; 51 import java.util.logging.Level ; 52 import com.sun.logging.LogDomains; 53 54 import com.sun.enterprise.config.serverbeans.*; 55 56 57 60 61 public class StaticTest { 62 63 static Logger _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER); 65 66 67 71 72 73 public static final String ADD = "ADD"; 74 75 public static final String DELETE = "DELETE"; 76 77 public static final String UPDATE = "UPDATE"; 78 79 public static final String SET = "SET"; 80 81 public static final String IAS_NAME = "com.sun.appserv:name="; 82 public static final String XML_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <xml>"; 83 public static final String XML_2 = "</xml>"; 84 86 public StaticTest() { 87 } 88 89 public static boolean isPortValid(int i){ 91 if(i > 0 && i <= 65535) 92 return true; 93 else 94 return false; 95 } 96 97 public static boolean checkAddress(String 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 111 public static boolean checkObjectName(String id) throws MalformedObjectNameException { 112 String name = IAS_NAME + id; 113 ObjectName validObjectName = new ObjectName (name); 114 return true; 115 } 116 117 120 public static boolean checkObjectName(String id, Result result) { 121 try { 122 return checkObjectName(id); 123 } catch(MalformedObjectNameException ex) { 124 _logger.log(Level.FINE, "serverxmlverifier.exception", ex); 125 result.failed(ex.getMessage()); 126 return false; 127 } 128 } 129 130 135 public static boolean checkXMLName(String name) throws SAXParseException, SAXException, 136 IOException , 137 ParserConfigurationException { 138 String xml = XML_1 + name + XML_2; 140 ByteArrayInputStream bais = new ByteArrayInputStream (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 153 public static boolean checkXMLName(String name, Result result) throws SAXParseException { 154 try { 155 return checkXMLName(name); 156 } catch (Exception s) { 157 _logger.log(Level.FINE, "serverxmlverifier.exception", s); 158 result.failed(s.getMessage()); 159 return false; 160 } 161 } 162 163 164 public static Config getConfig(ConfigContext context) { 166 167 Config mConfig=null; 168 try { 169 mConfig = ServerBeansFactory.getConfigBean(context); 170 } catch(Exception e) { 171 } 172 return mConfig; 173 } 174 } 175 | Popular Tags |