Package org.criticalfailure.torchlight.core.application.data

Examples of org.criticalfailure.torchlight.core.application.data.DataCreationException


        }
        catch(Exception e)
        {
            logger.error("Exception while creating new object: " + e.getLocalizedMessage(), e);
           
            throw new DataCreationException(e);
        }

        // call initialize method, if one exists
        try
        {
            Method m = objClass.getMethod("initialize", (Class[])null);
            logger.trace("m: " + m);

            logger.debug("invoking initialize method");
            m.invoke(obj, (Object[])null);
        }
        catch(Exception e)
        {
            logger.warn("Unable to initialize object: " + e.getLocalizedMessage());
        }
       
        // call setCampaign method, if one exists
        try
        {
            Method m = objClass.getMethod("setCampaign", Campaign.class);
            logger.trace("m: " + m);

            logger.debug("invoking setCampaign method");
            m.invoke(obj, campaign);
        }
        catch(Exception e)
        {
            logger.warn("Unable to set campaign on object: " + e.getLocalizedMessage());
        }
       
        // save the object
        if(save)
        {
            try
            {
                logger.info("Saving: " + obj);
                dataStore.saveObject(obj, null);
            }
            catch(Exception e)
            {
                logger.error("Exception while saving object: " + e.getLocalizedMessage(), e);

                throw new DataCreationException("Unable to persist object: " + obj, e);
            }
        }

        // run the wizard, if requested
        if(runWizard)
        {
            logger.debug("running wizard");

            try
            {
                // find a wizard for this object
                IConfigurationElement[] cels = Platform.getExtensionRegistry().getConfigurationElementsFor(IDataCreationWizard.ID);
                logger.debug("cels: " + cels);

                for(IConfigurationElement cel : cels)
                {
                    logger.debug("cel: " + cel);

                    IConfigurationElement[] objCels = cel.getChildren("object");
                    logger.trace("objCels: " + objCels);

                    for(IConfigurationElement objCel : objCels)
                    {
                        logger.debug("objCel: " + objCel);

                        String className = objCel.getAttribute("class");
                        logger.trace("className: " + className);

                        if(objClass.getName().equals(className))
                        {
                            logger.debug("found a matching class");

                            IDataCreationWizard wizard = (IDataCreationWizard)cel.createExecutableExtension("class");
                            logger.debug("wizard: " + wizard);

                            logger.debug("set object and params for wizard: " + obj);
                            wizard.setCampaign(campaign);
                            wizard.setObject(obj);
                            wizard.setParams(params);

                            logger.debug("tell wizard to setup");
                            wizard.setup();

                            logger.debug("tell wizard to run");
                            wizard.run();

                            if(wizard.isCanceled())
                            {
                                logger.debug("wizard canceled");
                                return null;
                            }

                            return obj;
                        }
                    }
                }
            }
            catch(Exception e)
            {
                logger.error("Exception while running wizard: " + e.getLocalizedMessage(), e);

                throw new DataCreationException(e);
            }
        }

        logger.debug("returning object: " + obj);
        return obj;
View Full Code Here

TOP

Related Classes of org.criticalfailure.torchlight.core.application.data.DataCreationException

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.