Package org.openbp.common.io.xml

Examples of org.openbp.common.io.xml.XMLDriver


  {
    // Use the class loader that loaded the OpenBP core to resolve XML mappings
    XMLDriver.setDefaultClassLoader(getClass().getClassLoader());

    // Load standard mappings
    XMLDriver driver = XMLDriver.getInstance();
    String encoding = SettingUtil.getStringSetting(XML_ENCODING_PROP);
    if (encoding != null)
    {
      driver.setEncoding(encoding);
    }
    boolean prettyPrint = SettingUtil.getBooleanSetting(XML_PRETTYPRINT_PROP, false);
    driver.setPrettyPrint(prettyPrint);
    if (!driver.loadMappings(mappedClasses))
      throw new OpenBPException("Initialization.Mapping", "Errors occurred while loading the core mappings. See the log file for details.");
  }
View Full Code Here


   * This directory contains a sub directory for each plugin.
   * Each sub directory contains a plugin profile ending with '.plugin.xml' and any jar files needed by the plugin.
   */
  public void loadPluginsFromResource()
  {
    XMLDriver xmlDriver = XMLDriver.getInstance();
    try
    {
      Class [] profileClasses = { PluginProfile.class, };
      xmlDriver.loadMappings(profileClasses);
    }
    catch (XMLDriverException e)
    {
      ExceptionUtil.printTrace(e);
      return;
    }

    ResourceMgr resMgr = ResourceMgr.getDefaultInstance();
    String resourcePattern = CockpitConstants.PLUGIN + "/*/*.plugin.xml";
    Resource[] resources = null;

    try
    {
      resources = resMgr.findResources(resourcePattern);
    }
    catch (ResourceMgrException e)
    {
      return;
    }

    for (int i = 0; i < resources.length; i++)
    {
      PluginProfile profile = null;
      try
      {
        profile = (PluginProfile) xmlDriver.deserializeResource(PluginProfile.class, resources[i]);
      }
      catch (XMLDriverException e)
      {
        LogUtil.error(getClass(), "Error reading plugin profile $0.", resources[i].getDescription(), e);
        continue;
View Full Code Here

   * Loads all generator descriptors.
   */
  private void loadGenerators()
  {
    // Load the standard mappings for the standard XML driver
    XMLDriver xmlDriver = XMLDriver.getInstance();
    try
    {
      xmlDriver.loadMappings(standardMappedClasses);
    }
    catch (XMLDriverException e)
    {
      ExceptionUtil.printTrace(e);
      return;
    }

    generatorList = new ArrayList();

    ClassLoader classLoader = getClass().getClassLoader();
    String classesDir = Application.getRootDir() + StringUtil.FOLDER_SEP + CockpitConstants.GENERATOR + StringUtil.FOLDER_SEP + "classes";
    if (new File(classesDir).isDirectory())
    {
      // Generator classes directory exists, set up class loader
      XClassLoaderConfiguration config = new XClassLoaderConfiguration();
      config.setName("Generator template class loader");
      config.setParentClassLoader(getClass().getClassLoader());
      config.addRepository(classesDir);
      try
      {
        classLoader = new XClassLoader(config);
      }
      catch (Exception e)
      {
        ExceptionUtil.printTrace(e);
        return;
      }
    }

    ResourceMgr resMgr = ResourceMgr.getDefaultInstance();
    String resourcePattern = CockpitConstants.GENERATOR + "/*.xml";
    Resource[] resources = null;

    try
    {
      resources = resMgr.findResources(resourcePattern);
    }
    catch (ResourceMgrException e)
    {
      return;
    }
    if (resources.length == 0)
      return;

    for (int i = 0; i < resources.length; i++)
    {
      Generator generator = null;
      try
      {
        generator = (Generator) xmlDriver.deserializeResource(Generator.class, resources[i]);
      }
      catch (XMLDriverException e)
      {
        ExceptionUtil.printTrace(e);
        continue;
      }
      generator.setGeneratorMgr(this);
      generator.setClassLoader(classLoader);

      // Create a generator-local XML driver and load the standard mappings
      XMLDriver generatorXmlDriver = new XMLDriver(classLoader);
      try
      {
        generatorXmlDriver.loadMappings(standardMappedClasses);
        generator.setXmlDriver(generatorXmlDriver);
      }
      catch (XMLDriverException e)
      {
        ExceptionUtil.printTrace(e);
        continue;
      }

      // Create the customizer if required
      try
      {
        generator.createCustomizer();
      }
      catch (Exception e)
      {
        ExceptionUtil.printTrace(e);
        continue;
      }

      // Load the XML files specified by the customizer
      try
      {
        // Load the mapping for specific generator settings defined by the customizer of the generator
        GeneratorCustomizer customizer = generator.getCustomizer();
        if (customizer != null)
        {
          Class [] dependentClasses = customizer.getDependentSettingsClasses();
          if (dependentClasses != null)
          {
            for (int iClasses = 0; iClasses < dependentClasses.length; ++iClasses)
            {
              generatorXmlDriver.loadMapping(dependentClasses [iClasses]);
            }
          }

          Class settingsClass = customizer.getSettingsClass();
          if (settingsClass != null)
          {
            generatorXmlDriver.loadMapping(settingsClass);
          }
        }
      }
      catch (XMLDriverException e)
      {
View Full Code Here

    }

    if (resources.length == 0)
      throw new ModelException("MissingItemTypeDescriptors", "No item type files found matching '" + resourcePattern + "'.");

    XMLDriver driver = XMLDriver.getInstance();
    ItemTypeDescriptor itd;

    for (int i = 0; i < resources.length; i++)
    {
      // Deserialize item descriptor file
      try
      {
        itd = (ItemTypeDescriptor) driver.deserializeResource(ItemTypeDescriptor.class, resources[i]);
      }
      catch (XMLDriverException pe)
      {
        throw new ModelException("Initialization", "Error reading component type descriptor resource '" + resources[i].getDescription()
          + "': " + pe.getMessage());
View Full Code Here

   * Loads all skin files in the $OpenBP/cockpit/skin directory.
   */
  private void loadSkins()
  {
    // Load mappings for generic skin descriptor files
    XMLDriver xmlDriver = XMLDriver.getInstance();
    xmlDriver.loadMapping(org.openbp.cockpit.modeler.figures.generic.XFigureDescriptor.class);
    xmlDriver.loadMapping(org.openbp.cockpit.modeler.skins.LinkDescriptor.class);
    xmlDriver.loadMapping(org.openbp.cockpit.modeler.skins.SymbolDescriptor.class);
    xmlDriver.loadMapping(org.openbp.cockpit.modeler.skins.Skin.class);

    ResourceMgr resMgr = ResourceMgr.getDefaultInstance();
    String resourcePattern = CockpitConstants.SKIN + "/*.xml";
    Resource[] resources = null;

    try
    {
      resources = resMgr.findResources(resourcePattern);
    }
    catch (ResourceMgrException e)
    {
      throw new ModelException("MissingItemTypeDescriptors", "No item type files found matching '" + resourcePattern + "'.");
    }

    if (resources.length == 0)
      throw new ModelException("MissingItemTypeDescriptors", "No skin definitions found in resource path '" + CockpitConstants.SKIN + "'.");

    ArrayList errorMsgs = new ArrayList();
    for (int i = 0; i < resources.length; i++)
    {
      Skin skin = null;

      // Load the descriptor
      try
      {
        skin = (Skin) xmlDriver.deserializeResource(Skin.class, resources[i]);
      }
      catch (XMLDriverException e)
      {
        ExceptionUtil.printTrace(e);
        continue;
View Full Code Here

    {
      // No descriptors present
      return;
    }

    XMLDriver xmlDriver = XMLDriver.getInstance();

    // Load the descriptors from the descriptor directory
    for (int i = 0; i < resources.length; i++)
    {
      ObjectDescriptor descriptor = null;
      String resourceName = resources[i].getDescription().toString();

      // Load the descriptor
      try
      {
        descriptor = (ObjectDescriptor) xmlDriver.deserializeFile(ObjectDescriptor.class, resourceName);
      }
      catch (XMLDriverException e)
      {
        LogUtil.error(getClass(), "Error loading custom object descriptor $0.", resourceName, e);
        continue;
      }

      // Load the descriptor
      try
      {
        descriptor = (ObjectDescriptor) xmlDriver.deserializeResource(ObjectDescriptor.class, resources[i]);
      }
      catch (XMLDriverException e)
      {
        LogUtil.error(getClass(), "Error loading custom object descriptor $0.", resourceName, e);
        continue;
View Full Code Here

  /**
   * Constructor.
   */
  public ExternalAssociationPlugin()
  {
    XMLDriver xmlDriver = XMLDriver.getInstance();

    // Load mappings for the association beans
    try
    {
      xmlDriver.loadMapping(org.openbp.cockpit.plugins.association.AssociationBean.class);
      xmlDriver.loadMapping(org.openbp.cockpit.plugins.association.MimeTypeAssociation.class);
    }
    catch (XMLDriverException e)
    {
      ExceptionUtil.printTrace(e);
      return;
View Full Code Here

   * @param modelDescriptorResource Resource that identifies the model descriptor file
   * @return The new model or null (error messages go to the message container)
   */
  protected Model readModelDescriptor(Resource modelDescriptorResource)
  {
    XMLDriver driver = XMLDriver.getInstance();

    // Deserialize model descriptor file (model.xml)
    Model model = null;
    try
    {
      model = (Model) driver.deserializeResource(ModelImpl.class, modelDescriptorResource);
    }
    catch (XMLDriverException pe)
    {
      getMsgContainer().addMsg(model, "Error reading model descriptor file $0 in model manager $1.", new Object[]
      {
View Full Code Here

   * @param itemDescriptorResource Resource that identifies the item descriptor file
   * @return The new item or null (error messages go to the message container)
   */
  protected Item readItemDescriptor(Model model, ItemTypeDescriptor itd, Resource itemDescriptorResource)
  {
    XMLDriver driver = XMLDriver.getInstance();

    Item item = null;

    // Deserialize item descriptor file
    try
    {
      if (itd.isContainedItem())
      {
        // Item is wrapped by a container class in its xml file
        ItemContainer container = (ItemContainer) driver.deserializeResource(ItemContainer.class, itemDescriptorResource);
        item = container.getItem();
      }
      else
      {
        item = (Item) driver.deserializeResource(itd.getItemClass(), itemDescriptorResource);
      }
    }
    catch (XMLDriverException pe)
    {
      getMsgContainer().addMsg(model, "Error reading component descriptor file $0 in model manager $1.", new Object[]
View Full Code Here

TOP

Related Classes of org.openbp.common.io.xml.XMLDriver

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.