Package com.arjuna.common.util.exceptions

Examples of com.arjuna.common.util.exceptions.SavePropertiesException


  {
        uri = uri != null ? null : pcm.getUri();

        if ( uri == null )
        {
            throw new SavePropertiesException("No uri is associated with this property manager");
        }

        Properties props = pcm.getLocalProperties();

        try
    {
      String filename = FileLocator.locateFile(uri);
      Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filename);
      Element root = doc.getDocumentElement();
      String depends = null;

      /** Remove the properties node for this property manager from the tree **/
            NodeList propertiesNodes = root.getElementsByTagName(PROPERTIES_ELEMENT_NAME);

      for (int count=0;count<propertiesNodes.getLength();count++)
      {
        Element propertiesElement = (Element)propertiesNodes.item(count);
        String propertiesName = propertiesElement.getAttributeNode(NAME_ATTRIBUTE_NAME).getNodeValue();

        /** If this is the properties node we are looking for remove it **/
        if ( propertiesName.equals(pcm.getName()) )
        {
          root.removeChild(propertiesElement);
          depends = propertiesElement.getAttributeNode(DEPENDS_ATTRIBUTE_NAME).getNodeValue();
          break;
        }
      }

      /** Now add the new properties node **/
      Element newPropertiesElement = doc.createElement(PROPERTIES_ELEMENT_NAME);

      newPropertiesElement.setAttribute(NAME_ATTRIBUTE_NAME, pcm.getName());

      if ( depends != null)
      {
        newPropertiesElement.setAttribute(DEPENDS_ATTRIBUTE_NAME, depends);
      }

      for (Enumeration e = props.keys();e.hasMoreElements();)
      {
        String key = (String)e.nextElement();
        String value = props.getProperty(key);

        Element newPropertyElement = doc.createElement(PROPERTY_ELEMENT_NAME);
        newPropertyElement.setAttribute(NAME_ATTRIBUTE_NAME, key);
        newPropertyElement.setAttribute(VALUE_ATTRIBUTE_NAME, value);

        newPropertiesElement.appendChild(newPropertyElement);
      }

      root.appendChild(newPropertiesElement);

      /** Output new properties file **/
      FileOutputStream out;
      OutputFormat of = new OutputFormat(doc);
      of.setIndenting(true);
          XMLSerializer srl = new XMLSerializer(out = new FileOutputStream(filename), of);

      srl.serialize(doc);

      out.close();
    }
    catch (java.io.IOException e)
    {
      throw e;
    }
    catch (Exception e)
    {
      throw new SavePropertiesException("Unexpected exception: "+e);
    }
  }
View Full Code Here


      throw e;
    }
        catch (Exception e)
    {
      e.printStackTrace(System.err);
      throw new SavePropertiesException("Failed to instantiate plugin: "+e);
    }
  }
View Full Code Here

  {
        uri = uri != null ? null : pcm.getUri();

        if ( uri == null )
        {
            throw new SavePropertiesException("No uri is associated with this property manager");
        }

        Properties props = pcm.getLocalProperties();

        try
    {
      String filename = FileLocator.locateFile(uri);
      Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filename);
      Element root = doc.getDocumentElement();
      String depends = null;

      /** Remove the properties node for this property manager from the tree **/
            NodeList propertiesNodes = root.getElementsByTagName(PROPERTIES_ELEMENT_NAME);

      for (int count=0;count<propertiesNodes.getLength();count++)
      {
        Element propertiesElement = (Element)propertiesNodes.item(count);
        String propertiesName = propertiesElement.getAttributeNode(NAME_ATTRIBUTE_NAME).getNodeValue();

        /** If this is the properties node we are looking for remove it **/
        if ( propertiesName.equals(pcm.getName()) )
        {
          root.removeChild(propertiesElement);
          depends = propertiesElement.getAttributeNode(DEPENDS_ATTRIBUTE_NAME).getNodeValue();
          break;
        }
      }

      /** Now add the new properties node **/
      Element newPropertiesElement = doc.createElement(PROPERTIES_ELEMENT_NAME);

      newPropertiesElement.setAttribute(NAME_ATTRIBUTE_NAME, pcm.getName());

      if ( depends != null)
      {
        newPropertiesElement.setAttribute(DEPENDS_ATTRIBUTE_NAME, depends);
      }

      for (Enumeration e = props.keys();e.hasMoreElements();)
      {
        String key = (String)e.nextElement();
        String value = props.getProperty(key);

        Element newPropertyElement = doc.createElement(PROPERTY_ELEMENT_NAME);
        newPropertyElement.setAttribute(NAME_ATTRIBUTE_NAME, key);
        newPropertyElement.setAttribute(VALUE_ATTRIBUTE_NAME, value);

        newPropertiesElement.appendChild(newPropertyElement);
      }

      root.appendChild(newPropertiesElement);

      /** Output new properties file **/
      FileOutputStream out;
      OutputFormat of = new OutputFormat(doc);
      of.setIndenting(true);
          XMLSerializer srl = new XMLSerializer(out = new FileOutputStream(filename), of);

      srl.serialize(doc);

      out.close();
    }
    catch (java.io.IOException e)
    {
      throw e;
    }
    catch (Exception e)
    {
      throw new SavePropertiesException("Unexpected exception: "+e);
    }
  }
View Full Code Here

/* 404 */       throw e;
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 408 */       e.printStackTrace(System.err);
/* 409 */       throw new SavePropertiesException("Failed to instantiate plugin: " + e);
/*     */     }
/*     */   }
View Full Code Here

/*     */   {
/* 267 */     uri = uri != null ? null : pcm.getUri();
/*     */
/* 269 */     if (uri == null)
/*     */     {
/* 271 */       throw new SavePropertiesException("No uri is associated with this property manager");
/*     */     }
/*     */
/* 274 */     Properties props = pcm.getLocalProperties();
/*     */     try
/*     */     {
/* 278 */       String filename = FileLocator.locateFile(uri);
/* 279 */       Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filename);
/* 280 */       Element root = doc.getDocumentElement();
/* 281 */       String depends = null;
/*     */
/* 284 */       NodeList propertiesNodes = root.getElementsByTagName("properties");
/*     */
/* 286 */       for (int count = 0; count < propertiesNodes.getLength(); count++)
/*     */       {
/* 288 */         Element propertiesElement = (Element)propertiesNodes.item(count);
/* 289 */         String propertiesName = propertiesElement.getAttributeNode("name").getNodeValue();
/*     */
/* 292 */         if (!propertiesName.equals(pcm.getName()))
/*     */           continue;
/* 294 */         root.removeChild(propertiesElement);
/* 295 */         depends = propertiesElement.getAttributeNode("depends").getNodeValue();
/* 296 */         break;
/*     */       }
/*     */
/* 301 */       Element newPropertiesElement = doc.createElement("properties");
/*     */
/* 303 */       newPropertiesElement.setAttribute("name", pcm.getName());
/*     */
/* 305 */       if (depends != null)
/*     */       {
/* 307 */         newPropertiesElement.setAttribute("depends", depends);
/*     */       }
/*     */
/* 310 */       for (Enumeration e = props.keys(); e.hasMoreElements(); )
/*     */       {
/* 312 */         String key = (String)e.nextElement();
/* 313 */         String value = props.getProperty(key);
/*     */
/* 315 */         Element newPropertyElement = doc.createElement("property");
/* 316 */         newPropertyElement.setAttribute("name", key);
/* 317 */         newPropertyElement.setAttribute("value", value);
/*     */
/* 319 */         newPropertiesElement.appendChild(newPropertyElement);
/*     */       }
/*     */
/* 322 */       root.appendChild(newPropertiesElement);
/*     */
/* 326 */       OutputFormat of = new OutputFormat(doc);
/* 327 */       of.setIndenting(true);
/*     */       FileOutputStream out;
/* 328 */       XMLSerializer srl = new XMLSerializer(out = new FileOutputStream(filename), of);
/*     */
/* 330 */       srl.serialize(doc);
/*     */
/* 332 */       out.close();
/*     */     }
/*     */     catch (IOException e)
/*     */     {
/* 336 */       throw e;
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 340 */       throw new SavePropertiesException("Unexpected exception: " + e);
/*     */     }
/*     */   }
View Full Code Here

  {
        uri = uri != null ? null : pcm.getUri();

        if ( uri == null )
        {
            throw new SavePropertiesException("No uri is associated with this property manager");
        }

        Properties props = pcm.getLocalProperties();

        try
    {
      String filename = FileLocator.locateFile(uri);
      Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filename);
      Element root = doc.getDocumentElement();
      String depends = null;

      /** Remove the properties node for this property manager from the tree **/
            NodeList propertiesNodes = root.getElementsByTagName(PROPERTIES_ELEMENT_NAME);

      for (int count=0;count<propertiesNodes.getLength();count++)
      {
        Element propertiesElement = (Element)propertiesNodes.item(count);
        String propertiesName = propertiesElement.getAttributeNode(NAME_ATTRIBUTE_NAME).getNodeValue();

        /** If this is the properties node we are looking for remove it **/
        if ( propertiesName.equals(pcm.getName()) )
        {
          root.removeChild(propertiesElement);
          depends = propertiesElement.getAttributeNode(DEPENDS_ATTRIBUTE_NAME).getNodeValue();
          break;
        }
      }

      /** Now add the new properties node **/
      Element newPropertiesElement = doc.createElement(PROPERTIES_ELEMENT_NAME);

      newPropertiesElement.setAttribute(NAME_ATTRIBUTE_NAME, pcm.getName());

      if ( depends != null)
      {
        newPropertiesElement.setAttribute(DEPENDS_ATTRIBUTE_NAME, depends);
      }

      for (Enumeration e = props.keys();e.hasMoreElements();)
      {
        String key = (String)e.nextElement();
        String value = props.getProperty(key);

        Element newPropertyElement = doc.createElement(PROPERTY_ELEMENT_NAME);
        newPropertyElement.setAttribute(NAME_ATTRIBUTE_NAME, key);
        newPropertyElement.setAttribute(VALUE_ATTRIBUTE_NAME, value);

        newPropertiesElement.appendChild(newPropertyElement);
      }

      root.appendChild(newPropertiesElement);

      /** Output new properties file **/
      FileOutputStream out;
      OutputFormat of = new OutputFormat(doc);
      of.setIndenting(true);
          XMLSerializer srl = new XMLSerializer(out = new FileOutputStream(filename), of);

      srl.serialize(doc);

      out.close();
    }
    catch (java.io.IOException e)
    {
      throw e;
    }
    catch (Exception e)
    {
      throw new SavePropertiesException("Unexpected exception: "+e);
    }
  }
View Full Code Here

      throw e;
    }
        catch (Exception e)
    {
      e.printStackTrace(System.err);
      throw new SavePropertiesException("Failed to instantiate plugin: "+e);
    }
  }
View Full Code Here

TOP

Related Classes of com.arjuna.common.util.exceptions.SavePropertiesException

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.