FileDocCategorySizeDatePackage
ServerMgr.javaAPI DocGlassfish v2 API15195Fri May 04 22:34:10 BST 2007com.sun.enterprise.admin.verifier

ServerMgr

public class ServerMgr extends Object implements com.sun.enterprise.config.ConfigContextEventListener
ServerMgr reads all TestCases and verifies it with server.xml file

NOT THREAD SAFE: mutable instance variables with stomp: 'result'

Fields Summary
static final Logger
_logger
public final String
testFileName
public static final HashMap
testCases
public static volatile String
fileUrl
public volatile String
description
public final boolean
debug
public volatile com.sun.enterprise.admin.verifier.Result
result
public final com.sun.enterprise.util.LocalStringManagerImpl
smh
Constructors Summary
public ServerMgr()
Creates a new instance of ServerCheck

    
           
      
        debug = false;
    
public ServerMgr(boolean verbose)

        debug = true;
    
Methods Summary
public booleancheck(com.sun.enterprise.config.ConfigContextEvent ccce)

        String name = ccce.getName();
        Object value = ccce.getObject();
        ConfigContext context = ccce.getConfigContext();
        String choice = ccce.getChoice();
        String beanName = ccce.getBeanName();
        
        if(name == null && beanName == null)
                return true;
        boolean retValue = false;
        if(testCases.isEmpty())
            loadTestInfo();
        TestInformation ti = (TestInformation)testCases.get(name);
        if(ti == null && beanName != null)
                    ti =(TestInformation)testCases.get(beanName);
        String testClass;
        try {
            testClass = ti.getClassName();
        }
        catch(Exception e){
               return true;
        }

        try {
            Class test = Class.forName(testClass);
            ServerCheck tester = (ServerCheck)test.newInstance();
            result = tester.check(ccce);
            if (result.getStatus() == Result.PASSED)
                retValue = true;
            else
                retValue = false;
        }
        catch(Throwable tt) {
            // Logger
            _logger.log(Level.FINE, "serverxmlverifier.error_check", tt);
            retValue = true;
        }
        return retValue;
    
private java.io.FilegetFileFromCP(java.lang.String name)

        File cand = null;
        String classPath = System.getProperty("java.class.path");
        String classPathSep = File.pathSeparator;
        StringTokenizer tokens = new StringTokenizer(classPath,classPathSep);
        while(tokens.hasMoreTokens()) {
            String fileName = tokens.nextToken();
            if(fileName.endsWith("appserv-rt.jar")) {
                // File Path separator in classpath set in server.xml is
                // always forward-slash (/), so trying forward slash first
                int slashPos = fileName.lastIndexOf('/");
                if (slashPos == -1) {
                    slashPos = fileName.lastIndexOf(File.separator);
                }
                if (slashPos != -1) {
                    String libPath = fileName.substring(0, slashPos);
                    cand = new File(libPath,name);
                }
                break;
            }
        }
        return cand;
    
private java.io.FilegetTestFile(java.lang.String name)

        
        String iasHome = System.getProperty("s1as.home");
        if(iasHome!=null) {
            File temp = new File(iasHome,"lib");
            temp = new File(temp,name);
            if(temp.exists())
                return temp;
            else
                return null;
        }
        else
            return getFileFromCP(name);
    
public java.util.HashMapgetTests()

        return testCases;
    
public booleanloadTestInfo()

        boolean allIsWell = true;
        
        if(testCases.isEmpty()) {
            if (debug) {
                // Logging
                _logger.log(Level.INFO, "serverxmlverifier.getting_testnamefrom_propertyfile");
            }  
            File inputFile = getTestFile(testFileName);
            try {
                // parse the xml file
                DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document doc = db.parse(inputFile);
                NodeList list = doc.getElementsByTagName("description");
                if (list.getLength()>0) {
                    Element e = (Element) list.item(0);
                    description = e.getFirstChild().getNodeValue().trim();
                }

                list = doc.getElementsByTagName("test");
                for (int i=0;i<list.getLength();i++) {
                    Element e = (Element) list.item(i);
                    NodeList nl = e.getChildNodes();
                    TestInformation ti = new TestInformation();
                    String testName = "";
                    for (int j=0;j<nl.getLength();j++) {
                        String nodeName = nl.item(j).getNodeName();
                        if("test-name".equals(nodeName.trim())) {
                            Node el = (Node)nl.item(j);
                            testName = el.getFirstChild().getNodeValue().trim();
                        }
                        if ("test-class".equals(nodeName.trim())) {
                            Node el = (Node) nl.item(j);
                            ti.setClassName(el.getFirstChild().getNodeValue().trim());
                        }
                        if ("minimum-version".equals(nodeName.trim())) {
                            Node el = (Node) nl.item(j);
                            ti.setMinimumVersion(el.getFirstChild().getNodeValue().trim());
                        }                                        
                        if ("maximum-version".equals(nodeName.trim())) {
                            Node el = (Node) nl.item(j);
                            ti.setMaximumVersion(el.getFirstChild().getNodeValue().trim());
                        }   
                    }
                    testCases.put(testName,ti);
                }            
            } catch (ParserConfigurationException e) {
                // Logging
                _logger.log(Level.WARNING, "serverxmlverifier.parser_error", e);
                allIsWell = false;
            } catch (org.xml.sax.SAXException e) {
                // Logging
                _logger.log(Level.WARNING, "serverxmlverifier.sax_error", e);
                allIsWell = false;            
            } catch (IOException e) {
                // Logging
                _logger.log(Level.WARNING, "serverxmlverifier.error_loading_xmlfile");
                allIsWell = false;
            } 
        }
        
        return allIsWell;
    
public voidpostAccessNotification(com.sun.enterprise.config.ConfigContextEvent ccce)
after config add, delete, set, update or flush. type is in ccce

    
public voidpostChangeNotification(com.sun.enterprise.config.ConfigContextEvent ccce)
after config add, delete, set, update or flush. type is in ccce

    
public voidpreAccessNotification(com.sun.enterprise.config.ConfigContextEvent ccce)
before config add, delete, set, update or flush. type is in ccce

    
public voidpreChangeNotification(com.sun.enterprise.config.ConfigContextEvent ccce)
before config add, delete, set, update or flush. type is in ccce

         if(! check(ccce))
                throw new AFRuntimeException(result.getErrorDetails().toString());
    
public static voidsetFile(java.lang.String file)

        fileUrl = file;