org.eclipse.datatools.sqltools.sqleditor.internal.templates
Class SQLTemplateReaderWriter

java.lang.Object
  extended by org.eclipse.datatools.sqltools.sqleditor.internal.templates.SQLTemplateReaderWriter

public class SQLTemplateReaderWriter
extends java.lang.Object

This class is refactored from TemplateReaderWriter to support intelligence template. Serializes templates as character or byte stream and reads the same format back.

Clients may instantiate this class, it is not intended to be subclassed.

Since:
3.0
Author:
lihuang

Constructor Summary
SQLTemplateReaderWriter()
          Create a new instance.
 
Method Summary
 org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] read(java.io.InputStream stream, java.util.ResourceBundle bundle)
          Reads templates from a stream and adds them to the templates.
 org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] read(java.io.Reader reader)
          Reads templates from a reader and returns them.
 org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] read(java.io.Reader reader, java.util.ResourceBundle bundle)
          Reads templates from a stream and adds them to the templates.
 org.eclipse.jface.text.templates.persistence.TemplatePersistenceData readSingle(java.io.Reader reader, java.lang.String id)
          Reads the template with identifier id from a reader and returns it.
 void save(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] templates, java.io.OutputStream stream)
          Saves the templates as XML, encoded as UTF-8 onto the given byte stream.
 void save(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] templates, java.io.Writer writer)
          Saves the templates as XML.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLTemplateReaderWriter

public SQLTemplateReaderWriter()
Create a new instance.

Method Detail

read

public org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] read(java.io.Reader reader)
                                                                            throws java.io.IOException
Reads templates from a reader and returns them. The reader must present a serialized form as produced by the save method.

Parameters:
reader - the reader to read templates from
Returns:
the read templates, encapsulated in instances of TemplatePersistenceData
Throws:
java.io.IOException - if reading from the stream fails

readSingle

public org.eclipse.jface.text.templates.persistence.TemplatePersistenceData readSingle(java.io.Reader reader,
                                                                                       java.lang.String id)
                                                                                throws java.io.IOException
Reads the template with identifier id from a reader and returns it. The reader must present a serialized form as produced by the save method.

Parameters:
reader - the reader to read templates from
id - the id of the template to return
Returns:
the read template, encapsulated in an instances of TemplatePersistenceData
Throws:
java.io.IOException - if reading from the stream fails
Since:
3.1

read

public org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] read(java.io.Reader reader,
                                                                                   java.util.ResourceBundle bundle)
                                                                            throws java.io.IOException
Reads templates from a stream and adds them to the templates.

Parameters:
reader - the reader to read templates from
bundle - a resource bundle to use for translating the read templates, or null if no translation should occur
Returns:
the read templates, encapsulated in instances of TemplatePersistenceData
Throws:
java.io.IOException - if reading from the stream fails

read

public org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] read(java.io.InputStream stream,
                                                                                   java.util.ResourceBundle bundle)
                                                                            throws java.io.IOException
Reads templates from a stream and adds them to the templates.

Parameters:
stream - the byte stream to read templates from
bundle - a resource bundle to use for translating the read templates, or null if no translation should occur
Returns:
the read templates, encapsulated in instances of TemplatePersistenceData
Throws:
java.io.IOException - if reading from the stream fails

save

public void save(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] templates,
                 java.io.OutputStream stream)
          throws java.io.IOException
Saves the templates as XML, encoded as UTF-8 onto the given byte stream.

Parameters:
templates - the templates to save
stream - the byte output to write the templates to in XML
Throws:
java.io.IOException - if writing the templates fails

save

public void save(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData[] templates,
                 java.io.Writer writer)
          throws java.io.IOException
Saves the templates as XML.

Parameters:
templates - the templates to save
writer - the writer to write the templates to in XML
Throws:
java.io.IOException - if writing the templates fails