FileDocCategorySizeDatePackage
ASEntBeanPmDescriptors.javaAPI DocGlassfish v2 API20741Fri May 04 22:34:04 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.runtime

ASEntBeanPmDescriptors

public class ASEntBeanPmDescriptors extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck
enterprise-beans pm-descriptors ? pm-descriptor pm-identifier [String] pm-version [String] pm-config ? [String] pm-class-generator ? 2.0 / pm-class-generator 2.1 [String] pm-mapping-factory ? [String] pm-inuse pm-identifier [String] pm-version [String] The pm-descriptors element contains one or more pm-descriptor elements The pm-descriptor describes the properties for the persistence manager associated with the entity bean. The pm-identifier and pm-version fields are required and should not be null. the pm-config should be a valid ias-cmp-mapping descriptor The pm-inuse identifies the persistence manager in use at a particular time. The pm-identifier and pm-version should be from the pm-descriptor element.
author
Irfan Ahmed

Fields Summary
private boolean
oneFailed
private boolean
oneWarning
ComponentNameConstructor
compName
Constructors Summary
Methods Summary
public Resultcheck(com.sun.enterprise.deployment.EjbDescriptor descriptor)


    
        
	Result result = getInitializedResult();
	compName = getVerifierContext().getComponentNameConstructor();
//        String value=null;
        int count = 0;
        try{
            count = getCountNodeSet("sun-ejb-jar/enterprise-beans/pm-descriptors");
            if (count>0){
                Map<String, String> pmIdVer = new HashMap<String, String>();
                count = getCountNodeSet("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor");
                if (count>0){
                    for(int i=0;i<count;i++){
                        testPmDescriptor(i, result, pmIdVer, descriptor);
                    }
                    count = getCountNodeSet("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-inuse");
                    if (count >0){
                        String pmIdentifier = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-inuse/pm-identifier");
                        String pmVersion = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-inuse/pm-version");
                        if (pmIdentifier!=null){
                            if (pmVersion!=null){
                                if(pmIdVer.containsKey(pmIdentifier)){
                                    result.addGoodDetails(smh.getLocalString
                                        ("tests.componentNameConstructor",
                                        "For [ {0} ]",
                                        new Object[] {compName.toString()}));
                                    result.passed(smh.getLocalString(getClass().getName()+".passed",
                                        "PASSED [AS-EJB pm-inuse] : pm-identifier {0} is valid"
                                        ,new Object[]{pmIdentifier}));
                                    String testVersion = (String)pmIdVer.get(pmIdentifier);
                                    if(testVersion.equals(pmVersion))
                                    {
                                        result.addGoodDetails(smh.getLocalString
                                            ("tests.componentNameConstructor",
                                            "For [ {0} ]",
                                            new Object[] {compName.toString()}));
                                        result.passed(smh.getLocalString(getClass().getName()+".passed1",
                                            "PASSED [AS-EJB pm-inuse] : pm-version {0} is valid", 
                                            new Object[]{pmVersion}));
                                    }else{
                                        // <addition> srini@sun.com Bug: 4698038
                                        //result.failed(smh.getLocalString(getClass().getName()+".failed",
                                        //  "FAILED [AS-EJB pm-inuse] : pm-version {0} for pm-identifier {0} not defined in pm-descriptors"
                                        //, new Object[]{pmVersion, pmIdentifier}));
                                        result.addErrorDetails(smh.getLocalString
		                            ("tests.componentNameConstructor",
				            "For [ {0} ]",
				            new Object[] {compName.toString()}));
                                        result.failed(smh.getLocalString(getClass().getName()+".failed5",
                                            "FAILED [AS-EJB pm-inuse] : pm-version {0} for pm-identifier {1} not defined in pm-descriptors"
                                            , new Object[]{pmVersion, pmIdentifier}));
                                        // </addition> Bug: 4698038
                                        oneFailed=true;
                                    }
                                }else{
                                    result.addErrorDetails(smh.getLocalString
				        ("tests.componentNameConstructor",
				        "For [ {0} ]",
				        new Object[] {compName.toString()}));
                                    result.failed(smh.getLocalString(getClass().getName()+".failed1",
                                        "FAILED [AS-EJB pm-inuse] : pm-identifier {0} is not defined in pm-descriptors"
                                        , new Object[]{pmIdentifier}));
                                    oneFailed=true;
                                }
                            }else{
                                result.addErrorDetails(smh.getLocalString
				    ("tests.componentNameConstructor",
				    "For [ {0} ]",
				    new Object[] {compName.toString()}));
                                result.failed(smh.getLocalString(getClass().getName()+".failed12",
                                    "FAILED [AS-EJB pm-inuse] : pm-version {0} is not defined in pm-inuse"
                                    , new Object[]{pmIdentifier}));
                                oneFailed=true;
                            }
                        }else{
                                result.addErrorDetails(smh.getLocalString
				   ("tests.componentNameConstructor",
				    "For [ {0} ]",
				    new Object[] {compName.toString()}));
                                result.failed(smh.getLocalString(getClass().getName()+".failed14",
                                    "FAILED [AS-EJB pm-inuse] : pm-identifier {0} is not defined in pm-inuse"
                                    , new Object[]{pmIdentifier}));
                                oneFailed=true;
                        }
                    }else{
                        result.addErrorDetails(smh.getLocalString
			            ("tests.componentNameConstructor",
				    "For [ {0} ]",
				    new Object[] {compName.toString()}));
                        result.failed(smh.getLocalString(getClass().getName()+".failed10",
                            "FAILED [AS-EJB pm-descriptors] : pm-inuse {0} is not defined in pm-descriptors"));
                        oneFailed=true;
                    }
                }else{
                    result.addErrorDetails(smh.getLocalString
                        ("tests.componentNameConstructor",
			"For [ {0} ]",
			new Object[] {compName.toString()}));
                    result.failed(smh.getLocalString(getClass().getName()+".failed11",
                        "FAILED [AS-EJB pm-descriptors] : pm-descriptor is not defined in pm-descriptors"));
                    oneFailed=true;
                }
            }else{
                result.addNaDetails(smh.getLocalString
		    ("tests.componentNameConstructor",
		    "For [ {0} ]",
		    new Object[] {compName.toString()}));
                result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
                    "NOT APPLICABLE [AS-EJB enterprise-beans] : pm-descriptors Element not defined"));
            }
            if(oneFailed)
                result.setStatus(Result.FAILED);
            else if(oneWarning)
                result.setStatus(Result.WARNING);
        }catch(Exception ex){
            result.addErrorDetails(smh.getLocalString
                ("tests.componentNameConstructor",
		"For [ {0} ]",
		new Object[] {compName.toString()}));
            result.failed(smh.getLocalString(getClass().getName()+".notRun",
                "NOT RUN [AS-EJB] Could not create descriptor Object."));
        }
        return result;
    
protected voidtestPmDescriptor(int i, Result result, java.util.Map idVerMap, com.sun.enterprise.deployment.EjbDescriptor descriptor)

param
i int
param
result Result
param
idVerMap Map
param
descriptor EjbDescriptor

        try{
            String value = null;
            //pm-identifier
            String pmIdentifier = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\""+i+"\"]/pm-identifier");
            if(pmIdentifier==null || pmIdentifier.length()==0){
                result.addErrorDetails(smh.getLocalString
                    ("tests.componentNameConstructor",
		    "For [ {0} ]",
		    new Object[] {compName.toString()}));
                result.failed(smh.getLocalString(getClass().getName()+".failed2",
                    "FAILED [AS-EJB pm-descriptor] : pm-identifier cannot be an empty string"));
                oneFailed=true;
            }else{
                result.addGoodDetails(smh.getLocalString
                    ("tests.componentNameConstructor",
                    "For [ {0} ]",
                    new Object[] {compName.toString()}));
                result.passed(smh.getLocalString(getClass().getName()+".passed2",
                    "PASSED [AS-EJB pm-descriptor] : pm-identifier is {0}",
                    new Object[]{pmIdentifier}));
            }
            
            //pm-version
            String pmVersion = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\""+i+"\"]/pm-version");
            if(pmVersion==null || pmVersion.length()==0){
                result.addErrorDetails(smh.getLocalString
                        ("tests.componentNameConstructor",
			"For [ {0} ]",
			new Object[] {compName.toString()}));
                result.failed(smh.getLocalString(getClass().getName()+".failed3",
                    "FAILED [AS-EJB pm-descritor] : pm-version cannot be an empty string"));
                oneFailed=true;
            }else{
                result.addGoodDetails(smh.getLocalString
                    ("tests.componentNameConstructor",
                    "For [ {0} ]",
                    new Object[] {compName.toString()}));
                result.passed(smh.getLocalString(getClass().getName()+".passed3",
                    "PASSED [AS-EJB pm-descriptor] : pm-version is {0}",
                    new Object[]{pmVersion}));
            }

            if (pmIdentifier!=null && pmVersion!=null)
                idVerMap.put(pmIdentifier,pmVersion);
        
            //pm-config
            value = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\""+i+"\"]/pm-config");
            if(value!=null){
                //////  //4698035
                if(value.length()==0){
                    result.addErrorDetails(smh.getLocalString
                        ("tests.componentNameConstructor",
			            "For [ {0} ]",
			            new Object[] {compName.toString()}));
                    oneFailed = true;
                    result.failed(smh.getLocalString(getClass().getName()+".failed4",
                        "FAILED [AS-EJB pm-descritor] : pm-config cannot be an empty string"));
                }else{
//                    File f = Verifier.getArchiveFile(descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri());
                    JarFile jarFile = null;
                    InputStream deploymentEntry=null;
                    try{
//                        if (f==null){
                            String uri = getAbstractArchiveUri(descriptor);
                            try {
                                FileArchive arch = new FileArchive();
                                arch.open(uri);
                                deploymentEntry = arch.getEntry(value);
                            }catch (Exception e) { }
//                        }else{
//                            try{
//                            jarFile = new JarFile(f);
//                            ZipEntry deploymentEntry1 = jarFile.getEntry(value);
//                            if (deploymentEntry1 != null)
//                                deploymentEntry = jarFile.getInputStream(deploymentEntry1);
//                            }catch (Exception e) { }
//                        }

                        if(deploymentEntry !=null){
                            result.addGoodDetails(smh.getLocalString
                                ("tests.componentNameConstructor",
                                "For [ {0} ]",
                                new Object[] {compName.toString()}));
                            result.passed(smh.getLocalString(getClass().getName()+".passed4",
                                "PASSED [AS-EJB pm-descriptor] : pm-config is {0}",
                                new Object[]{value}));
                        }else{
                            result.addWarningDetails(smh.getLocalString
                                ("tests.componentNameConstructor",
                                "For [ {0} ]",
                                new Object[] {compName.toString()}));
                            oneWarning=true;
                            result.warning(smh.getLocalString(getClass().getName()+".warning3",
                                "WARNING [AS-EJB pm-descriptor] : config file {0} pointed in pm-config is not present in the jar file",
                                new Object[]{value}));
                        }
                    }catch(Exception e){}
                    finally{
                        try {
                            if (jarFile != null)
                                jarFile.close();
                            if (deploymentEntry != null)
                                deploymentEntry.close();
                        }catch (Exception x) {}
                    }

                }
                /////////
            }

            //pm-class-generator
            value = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\""+i+"\"]/pm-class-generator");
            if (value==null || value.length()==0 ){
                //check for spec version accordingly give error or warning
                Float specVer = getRuntimeSpecVersion();
		        if ((Float.compare(specVer.floatValue(), (new Float("2.1")).floatValue()) >= 0)) {
                    oneFailed=true;
                    result.addErrorDetails(smh.getLocalString
                        ("tests.componentNameConstructor",
			            "For [ {0} ]",
			            new Object[] {compName.toString()}));
                    result.failed(smh.getLocalString(getClass().getName()+".failed13",
                        "FAILED [AS-EJB pm-descriptor] : pm-class-generator cannot be empty."));
                }
            }else{
                if(value.trim().indexOf(" ") != -1){
                    oneFailed=true;
                    result.addErrorDetails(smh.getLocalString
                        ("tests.componentNameConstructor",
			            "For [ {0} ]",
			            new Object[] {compName.toString()}));
                    result.failed(smh.getLocalString(getClass().getName()+".failed7",
                        "FAILED [AS-EJB pm-descriptor] : pm-class-generator class name is invalid"));
                }else{
                    result.addGoodDetails(smh.getLocalString
                        ("tests.componentNameConstructor",
                        "For [ {0} ]",
                        new Object[] {compName.toString()}));
                    result.passed(smh.getLocalString(getClass().getName()+".passed5",
                        "PASSED [AS-EJB pm-descriptor] : pm-class-generator is {0}",
                        new Object[]{value}));
                }
            }

            //pm-mapping-factory
            value = getXPathValue("sun-ejb-jar/enterprise-beans/pm-descriptors/pm-descriptor[\""+i+"\"]/pm-mapping-factory");
            if (value != null){
                if(value.trim().indexOf(" ") != -1){
                    result.addErrorDetails(smh.getLocalString
                        ("tests.componentNameConstructor",
			            "For [ {0} ]",
			            new Object[] {compName.toString()}));
                    oneFailed=true;
                    result.failed(smh.getLocalString(getClass().getName()+".failed8",
                        "FAILED [AS-EJB pm-descriptor] : pm-mapping-factory class name is invalid"));
                }else{
                    if(value.trim().length()==0){
                        result.addErrorDetails(smh.getLocalString
                            ("tests.componentNameConstructor",
			                "For [ {0} ]",
			                new Object[] {compName.toString()}));
                        oneFailed=true;
                        result.failed(smh.getLocalString(getClass().getName()+".failed6",
                            "FAILED [AS-EJB pm-descritor] : pm-pm-mapping-factory cannot be an empty string"));
                    }else{
                        result.addGoodDetails(smh.getLocalString
                            ("tests.componentNameConstructor",
                            "For [ {0} ]",
                            new Object[] {compName.toString()}));
                        result.passed(smh.getLocalString(getClass().getName()+".passed6",
                            "PASSED [AS-EJB pm-descriptor] : pm-mapping-factory is {0}",
                            new Object[]{value}));
                    }
                }
            }
        }catch(Exception ex){
            oneFailed = true;
            result.failed(smh.getLocalString(getClass().getName()+".notRun",
                "NOT RUN [AS-EJB] Could not create descriptor Object."));
        }finally{
        }