FileDocCategorySizeDatePackage
WSSchemaLocation.javaAPI DocGlassfish v2 API9991Fri May 04 22:34:16 BST 2007com.sun.enterprise.tools.verifier.tests.webservices

WSSchemaLocation

public class WSSchemaLocation extends WSTest implements WSCheck

Fields Summary
String
myValue
String[]
reqSchemaLocation
int
i
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.WebServiceEndpoint descriptor)

param
descriptor the WebServices descriptor
return
Result the results for this assertion

                      
         

        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
        String[] reqSchemaLocationSub1 =
                    {"http://java.sun.com/xml/ns/j2ee", "http://java.sun.com/xml/ns/javaee"};
        String[] reqSchemaLocationSub2 =
                    {"http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd",
                     "http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd"};
        boolean rslt = false;
        String schemaVersion = getVerifierContext().getSchemaVersion();
        Document wsdoc=getVerifierContext().getWebServiceDocument();
        //with jax-ws it is not mandatory to define webservices.xml deployment descriptor
        if (wsdoc == null && schemaVersion.compareTo("1.1") > 0) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString(getClass().getName() + ".passed1",
                    "Webservices deployment descriptor is not defined for this archive"));
            return result;
        }

        try {
           if (wsdoc.getDocumentElement().hasAttributes()) {
               getNode(wsdoc);
               if ( myValue != null) {
                   for(i=0; i<reqSchemaLocation.length; i++) {
                       rslt = verifySchema(myValue, reqSchemaLocation[i],
                               reqSchemaLocationSub1[i], reqSchemaLocationSub2[i]);
                       if(rslt) break;
                   }
               }
           }
           if (rslt) {
              result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
                                   "For [ {0} ]", new Object[] {compName.toString()}));
              result.passed(smh.getLocalString (getClass().getName() + ".passed",
                          "The schemaLocation in the webservices.xml file for [{0}] matches the schema file requirement",
                           new Object[] {compName.toString()}));
            }
            else {
             result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
                                   "For [ {0} ]", new Object[] {compName.toString()}));
             result.failed(smh.getLocalString (getClass().getName() + ".failed",
               "The schemaLocation in the webservices.xml file for [{0}] does not match the schema file requirement",
                new Object[] {compName.toString()}));
            }
        }catch (Exception e) {
            //result.fail
            result.failed(smh.getLocalString
                (getClass().getName() + ".failed",
               "The schemaLocation in the webservices.xml file for [{0}] does not match the schema file requirement",
                new Object[] {compName.toString()}));
            result.addErrorDetails(smh.getLocalString
               ("com.sun.enterprise.tools.verifier.tests.webservices.Error",
                "Error: Unexpected error occurred [ {0} ]",
                new Object[] {e.getMessage()}));
        }
        return result;
    
private booleancheckSubString(java.lang.String str, int off1, int off2, int len)

                if (reqSchemaLocation[i].regionMatches(off1, str, off2, len)) {
                        return true;
                }
                return false;
           
public voidgetNode(org.w3c.dom.Node node)


    String name = node.getNodeName(); 
    int myType = node.getNodeType();
    // type 1 = Element
    if ( ( myType == 1 ) & (name.equals("webservices") )) {
       Element e = (Element)node;
       myValue = e.getAttribute("xsi:schemaLocation");
       return;
    }
    if (node.hasChildNodes()) {
      Node firstChild = node.getFirstChild();
      getNode(firstChild);
    }
    Node nextNode = node.getNextSibling();
    if (nextNode != null) getNode(nextNode);
    return ;
  
private booleanverifySchema(java.lang.String nodeval, java.lang.String reqSchemaLocation, java.lang.String reqSchemaLocationSub1, java.lang.String reqSchemaLocationSub2)

      try {
           int off1 = reqSchemaLocation.indexOf("http", reqSchemaLocationSub1.length());
           int off2 = nodeval.indexOf("http",reqSchemaLocationSub1.length());
           // 1. separate into 2 substrings and verify
           if (  checkSubString(nodeval, 0,0,reqSchemaLocationSub1.length())
                 && checkSubString(nodeval, off1,off2,reqSchemaLocationSub2.length()) ) {
                    ; // ok so far  
           }
           else {
                // no need to go further,  strings are not correct
                return false; 
           }

           // 2. make sure that there is at least a space between the 2 substrings
           if ( reqSchemaLocation.length() > nodeval.length())
              return false;

          // 3. Make sure that there is only whitespace as separation between the two substrings
          // java whitespace is one of the following:
          /*
          It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or
          PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007',
          '\u202F').

          It is '\u0009', HORIZONTAL TABULATION.
          It is '\u000A', LINE FEED.
          It is '\u000B', VERTICAL TABULATION.
          It is '\u000C', FORM FEED.
          It is '\u000D', CARRIAGE RETURN.
          It is '\u001C', FILE SEPARATOR.
          It is '\u001D', GROUP SEPARATOR.
          It is '\u001E', RECORD SEPARATOR.
          It is '\u001F', UNIT SEPARATOR.

          */

         for ( int i = reqSchemaLocationSub1.length(); i < off2; i++) {
            if ( !(Character.isWhitespace(nodeval.charAt(i))) ) {
              return false;
            } 
          }

    }catch (Exception e) {
            e.toString();
            e.printStackTrace();
    } 
    return true;