Package org.glassfish.resource.common

Examples of org.glassfish.resource.common.ResourceStatus


    public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties,
                                 String target) throws Exception {
        setAttributes(attributes, target);

        ResourceStatus validationStatus = isValid(resources, true, target);
        if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
            return validationStatus;
        }
        try {
            ConfigSupport.apply(new SingleConfigCode<Resources>() {

                public Object run(Resources param) throws PropertyVetoException,
                        TransactionFailure {

                    return createResource(param, properties);
                }
            }, resources);

            resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
        } catch (TransactionFailure tfe) {
            String msg = localStrings.getLocalString(
                    "create.jndi.resource.fail",
                    "Unable to create jndi resource {0}.", jndiName) +
                    " " + tfe.getLocalizedMessage();
            return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
        }

        String msg = localStrings.getLocalString(
                "create.jndi.resource.success",
                "jndi resource {0} created.", jndiName);
        return new ResourceStatus(ResourceStatus.SUCCESS, msg, true);
    }
View Full Code Here


                "jndi resource {0} created.", jndiName);
        return new ResourceStatus(ResourceStatus.SUCCESS, msg, true);
    }

    private ResourceStatus isValid(Resources resources, boolean validateResourceRef, String target) {
        ResourceStatus status ;
        if (resType == null) {
            String msg = localStrings.getLocalString(
                    "create.jndi.resource.noResType",
                    "No type defined for JNDI resource.");
            return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
        }

        if (factoryClass == null) {
            String msg = localStrings.getLocalString(
                    "create.jndi.resource.noFactoryClassName",
                    "No Factory class name defined for JNDI resource.");
            return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
        }

        if (jndiLookupName == null) {
            String msg = localStrings.getLocalString(
                    "create.jndi.resource.noJndiLookupName",
                    "No Jndi Lookup name defined for JNDI resource.");
            return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
        }

        status = resourcesHelper.validateBindableResourceForDuplicates(resources, jndiName, validateResourceRef,
                target, AdminObjectResource.class);
        if(status.getStatus() == ResourceStatus.FAILURE){
            return status;
        }

        return status;
    }
View Full Code Here

    }

    public Resource createConfigBean(Resources resources, HashMap attributes, Properties properties, boolean validate)
            throws Exception {
        setAttributes(attributes, null);
        ResourceStatus status = null;
        if (!validate) {
            status = new ResourceStatus(ResourceStatus.SUCCESS, "");
        } else {
            status = isValid(resources, false, null);
        }
        if (status.getStatus() == ResourceStatus.SUCCESS) {
            return createConfigBean(resources, properties);
        } else {
            throw new ResourceException(status.getMessage());
        }
    }
View Full Code Here

        attributes.put(ResourceConstants.MAIL_TRANS_PROTO_CLASS, transportProtocolClass);
        attributes.put(ResourceConstants.MAIL_DEBUG, debug.toString());
        attributes.put(ResourceConstants.ENABLED, enabled.toString());
        attributes.put(ServerTags.DESCRIPTION, description);

        ResourceStatus rs;

        try {
            rs = mailResMgr.create(domain.getResources(), attributes, properties, target);
        } catch(Exception e) {
            Logger.getLogger(CreateJavaMailResource.class.getName()).log(Level.SEVERE,
                    "Unable to create Mail Resource " + jndiName, e);
            String def = "Mail resource: {0} could not be created";
            report.setMessage(localStrings.getLocalString("create.mail.resource.fail",
                    def, jndiName) + " " + e.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
        ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
        if (rs.getStatus() == ResourceStatus.FAILURE) {
            ec = ActionReport.ExitCode.FAILURE;
            if (rs.getMessage() == null) {
                 report.setMessage(localStrings.getLocalString("create.mail.resource.fail",
                    "Unable to create Mail Resource {0}.", jndiName));
               
            }
            if (rs.getException() != null)
                report.setFailureCause(rs.getException());
        }
        if(rs.getMessage() != null){
            report.setMessage(rs.getMessage());
        }
        report.setActionExitCode(ec);
    }
View Full Code Here

        attrList.put(RESOURCE_ADAPTER_CONFIG_NAME, raName);
        //attrList.put("name", name);
        attrList.put(THREAD_POOL_IDS, threadPoolIds);
        attrList.put(ServerTags.OBJECT_TYPE, objectType);

        ResourceStatus rs;

        //TODO ASR : need similar validation while creating app-scoped-resource of resource-adapter-config
        String appName = raName;
        if (!ConnectorsUtil.isStandAloneRA(raName)) {
            appName = ConnectorsUtil.getApplicationNameOfEmbeddedRar(raName);

            Application application = applications.getApplication(appName);
            if(application != null){
                //embedded RAR
                String resourceAdapterName = ConnectorsUtil.getRarNameFromApplication(raName);
                Module module = application.getModule(resourceAdapterName);
                if(module != null){
                    Resources msr = module.getResources();
                    if(msr != null){
                        if(hasDuplicate(msr, report)) return;
                    }
                }
            }
        }else{
            //standalone RAR
            Application application = applications.getApplication(appName);
            if(application != null){
                Resources appScopedResources = application.getResources();
                if(appScopedResources != null){
                    if(hasDuplicate(appScopedResources, report)) return;
                }
            }
        }

        ResourceAdapterConfigManager resAdapterConfigMgr = new ResourceAdapterConfigManager();
        try {
            rs = resAdapterConfigMgr.create(domain.getResources(), attrList, properties, target);
        } catch (Exception ex) {
            Logger.getLogger(CreateResourceAdapterConfig.class.getName()).log(
                    Level.SEVERE,
                    "Unable to create resource adapter config for " + raName, ex);
            String def = "Resource adapter config: {0} could not be created, reason: {1}";
            report.setMessage(localStrings.getLocalString("create.resource.adapter.config.fail",
                    def, raName) + " " + ex.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(ex);
            return;
        }
        ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
        if (rs.getStatus() == ResourceStatus.FAILURE) {
            ec = ActionReport.ExitCode.FAILURE;
            if (rs.getMessage() != null) {
                report.setMessage(rs.getMessage());
            } else {
                 report.setMessage(localStrings.getLocalString("create.resource.adapter.config.fail",
                    "Resource adapter config {0} creation failed", raName, ""));
            }
            if (rs.getException() != null)
                report.setFailureCause(rs.getException());
        }
        report.setActionExitCode(ec);
    }
View Full Code Here

        attrList.put(RESOURCE_ADAPTER_CONFIG_NAME, raName);
        //attrList.put("name", name);
        attrList.put(THREAD_POOL_IDS, threadPoolIds);
        attrList.put(ServerTags.OBJECT_TYPE, objectType);

        ResourceStatus rs;

        //TODO ASR : need similar validation while creating app-scoped-resource of resource-adapter-config
        String appName = raName;
        if (!ConnectorsUtil.isStandAloneRA(raName)) {
            appName = ConnectorsUtil.getApplicationNameOfEmbeddedRar(raName);

            Application application = applications.getApplication(appName);
            if(application != null){
                //embedded RAR
                String resourceAdapterName = ConnectorsUtil.getRarNameFromApplication(raName);
                Module module = application.getModule(resourceAdapterName);
                if(module != null){
                    Resources msr = module.getResources();
                    if(msr != null){
                        if(hasDuplicate(msr, report)) return;
                    }
                }
            }
        }else{
            //standalone RAR
            Application application = applications.getApplication(appName);
            if(application != null){
                Resources appScopedResources = application.getResources();
                if(appScopedResources != null){
                    if(hasDuplicate(appScopedResources, report)) return;
                }
            }
        }

        ResourceAdapterConfigManager resAdapterConfigMgr = new ResourceAdapterConfigManager();
        try {
            rs = resAdapterConfigMgr.create(domain.getResources(), attrList, properties, target);
        } catch (Exception ex) {
            Logger.getLogger(CreateResourceAdapterConfig.class.getName()).log(
                    Level.SEVERE,
                    "Unable to create resource adapter config for " + raName, ex);
            String def = "Resource adapter config: {0} could not be created, reason: {1}";
            report.setMessage(localStrings.getLocalString("create.resource.adapter.config.fail",
                    def, raName) + " " + ex.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(ex);
            return;
        }
        ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
        if (rs.getStatus() == ResourceStatus.FAILURE) {
            ec = ActionReport.ExitCode.FAILURE;
            if (rs.getMessage() != null) {
                report.setMessage(rs.getMessage());
            } else {
                 report.setMessage(localStrings.getLocalString("create.resource.adapter.config.fail",
                    "Resource adapter config {0} creation failed", raName, ""));
            }
            if (rs.getException() != null)
                report.setFailureCause(rs.getException());
        }
        report.setActionExitCode(ec);
    }
View Full Code Here

        attrList.put("res-type", resType);
        attrList.put(ResourceConstants.ENABLED, enabled.toString());
        attrList.put(JNDI_NAME, jndiName);
        attrList.put(ServerTags.DESCRIPTION, description);

        ResourceStatus rs;

        try {
            rs = customResMgr.create(domain.getResources(), attrList, properties, target);
        } catch(Exception e) {
            Logger.getLogger(CreateCustomResource.class.getName()).log(Level.SEVERE,
                    "Unable to create custom resource " + jndiName, e);
            String def = "Custom resource: {0} could not be created, reason: {1}";
            report.setMessage(localStrings.getLocalString("create.custom.resource.fail",
                    def, jndiName) + " " + e.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
        ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
        if (rs.getStatus() == ResourceStatus.FAILURE) {
            ec = ActionReport.ExitCode.FAILURE;
            if (rs.getMessage() == null) {
                 report.setMessage(localStrings.getLocalString("create.custom.resource.fail",
                    "Custom resource {0} creation failed", jndiName, ""));
            }
            if (rs.getException() != null)
                report.setFailureCause(rs.getException());
        }
        if(rs.getMessage() != null){
            report.setMessage(rs.getMessage());
        }
        report.setActionExitCode(ec);
    }
View Full Code Here

TOP

Related Classes of org.glassfish.resource.common.ResourceStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.