public class IlvPrototypeLibrary extends Object implements IlvPersistentObject, Serializable
IlvPrototypeLibrary
is used to organize, load, and
save prototypes.
A prototype library contains a set of prototypes. All the prototypes used in an application are identified by the name of the library to which they belong and by their name. This identification is unique.
Prototype libraries can be automatically loaded when a Perforce JViews file
containing prototype instances is read. This means that an application which
just loads panels will not need to use the IlvPrototypeLibrary
class directly.
To load a prototype explicitly, you can use the getPrototype
method as shown below:
IlvPrototype proto = IlvPrototypeLibrary.getPrototype("mylib", "myproto");
Prototype libraries are saved to normal Perforce JViews files. Library
files are searched using a path that you can define with the
addToPath
method.
The other methods of the class are intended to be used by applications that need to define new prototypes and prototype libraries.
IlvPrototype
,
Serialized FormConstructor and Description |
---|
IlvPrototypeLibrary(IlvInputStream in)
Reads a prototype library from a stream.
|
IlvPrototypeLibrary(String name)
Creates a new prototype library with the specified name.
|
Modifier and Type | Method and Description |
---|---|
void |
addPrototype(IlvPrototype prototype)
Adds a prototype to this library.
|
static void |
addToPath(String dirname)
Adds a directory to the path used to locate prototypes.
|
static void |
addToPath(URL url)
Adds a URL to the path used to locate prototypes.
|
static Enumeration |
getAllLibraries()
Returns all the prototype libraries currently loaded or created.
|
static IlvPrototypeLibrary |
getLibrary(String libName)
Loads a prototype library.
|
String |
getName()
Returns the name of this library.
|
static URL[] |
getPath()
Returns the path used to locate prototype library files.
|
IlvPrototype |
getPrototype(String protoName)
Gets the prototype whose name is specified.
|
static IlvPrototype |
getPrototype(String prototypeURL,
Class jarClass)
Reads a prototype from a URL, or from a JAR archive.
|
static IlvPrototype |
getPrototype(String libName,
String protoName)
Loads a prototype from a library name and a prototype name.
|
Enumeration |
getPrototypes()
Returns the prototypes that this library contains.
|
URL |
getURL()
Returns the location from which the library was loaded.
|
static IlvPrototypeLibrary[] |
read(String filename)
Reads the prototype libraries contained in a Perforce JViews formatted
file.
|
static IlvPrototypeLibrary[] |
read(URL url)
Reads the prototype libraries contained in a Perforce JViews formatted
file.
|
static void |
registerEditor(IlvPrototypeLibraryEditor editor)
Registers an
IlvPrototypeLibraryEditor . |
void |
removePrototype(IlvPrototype prototype)
Removes a prototype from this library.
|
void |
replacePrototype(IlvPrototype oldPrototype,
IlvPrototype prototype)
Replaces a prototype of this library with a new one.
|
void |
setName(String name)
Changes the name of this prototype library.
|
void |
setURL(URL url)
Sets the location from which the library was loaded.
|
void |
write(IlvOutputStream out)
Writes this prototype library to an output stream.
|
void |
write(String filename)
Writes a prototype library to a specified file.
|
public IlvPrototypeLibrary(String name)
name
- the name of the new library.public IlvPrototypeLibrary(IlvInputStream in) throws IlvReadFileException
in
- the input stream.IlvReadFileException
- if an I/O error occurs or if the file format is incorrect.public void write(IlvOutputStream out) throws IOException
IlvPersistentObject
interface, but it should not be called directly by applications.write
in interface IlvPersistentObject
out
- the output stream.IOException
- if an I/O error occurs.public String getName()
public void setName(String name)
name
- the new library name.public void addPrototype(IlvPrototype prototype)
prototype
- the prototype to be added.public void removePrototype(IlvPrototype prototype)
prototype
- the prototype to be removed.public void replacePrototype(IlvPrototype oldPrototype, IlvPrototype prototype)
oldPrototype
- the prototype to replace.prototype
- the new prototype to add instead of oldPrototype
.public Enumeration getPrototypes()
IlvPrototype
objects.getPrototype(java.lang.String, java.lang.String)
public static IlvPrototypeLibrary[] read(URL url) throws IOException, IlvReadFileException
This method is intended to be used by GUI editors. Other applications will
normally use the getLibrary
or getPrototype
methods to fetch prototypes.
url
- the location of the library file to be loaded.IOException
- if an I/O error occurs.IlvReadFileException
- if the library file format is wrong.getPrototype(java.lang.String, java.lang.String)
,
getLibrary(java.lang.String)
public static IlvPrototypeLibrary[] read(String filename) throws IOException, IlvReadFileException
This method creates a URL from the specified file name and calls
read(URL)
.
filename
- the file name.IOException
- if an I/O error occurs.IlvReadFileException
- if the library file format is wrong.read(java.net.URL)
public void write(String filename) throws IOException
filename
- the file where the library will be saved.IOException
- if an I/O error occurs.public static IlvPrototypeLibrary getLibrary(String libName) throws IlvReadFileException
If the prototype library specified is not already loaded, its file is
searched for in the prototype search path (for details, see the
addToPath
methods). The prototype library file has the
.ilv
extension (libName.ivl
) and is located in
the directory or in the subdirectory indicated in the path (for example,
libName/libName.ivl
).
If the file of the prototype library is found, it is read with the
read
method, and all the prototypes contained in the file are
stored in the library.
libName
- the name of the prototype library.IlvReadFileException
- if the library file could not be found.addToPath(java.net.URL)
,
addToPath(java.lang.String)
public static IlvPrototype getPrototype(String libName, String protoName) throws IlvReadFileException
If required, this method calls getLibrary
to load the library.
Then it calls getPrototype
to get the prototype specified.
libName
- the name of the prototype library.protoName
- the name of the prototype.IlvReadFileException
- if the library or the prototype could not be found.public IlvPrototype getPrototype(String protoName)
protoName
- the name of the prototype.null
if it
does not exist or if it could not be loaded.public static void addToPath(URL url)
url
- the URL to be added to the prototype access path.public static void addToPath(String dirname) throws MalformedURLException
dirname
- the directory to be added to the prototype access path. The
directory name must end with a path separator (slash or
backslash).MalformedURLException
- if the directory name could not be translated to a valid URL.public static URL[] getPath()
public static void registerEditor(IlvPrototypeLibraryEditor editor)
IlvPrototypeLibraryEditor
. This object will be
notified every time a new prototype library is loaded.
This method is intended to be used by GUI editors.
editor
- the new IlvPrototypeLibraryEditor
object to be
registered.IlvPrototypeLibraryEditor
public URL getURL()
public void setURL(URL url)
public static Enumeration getAllLibraries()
IlvPrototypeLibrary
objects.public static IlvPrototype getPrototype(String prototypeURL, Class jarClass) throws MalformedURLException, IlvReadFileException, IOException
The URL is of the form http://host/dir/library.ivl#proto
,
where library.ivl
is the name of the prototype library file,
and proto
is the name of the prototype. If the prototype name
is omitted, the first prototype of the library is returned. If the URL is a
relative URL with a protocol of "file"
and if
jarClass
is not null, the method tries to find the library in
the JAR archive from which the class was loaded.
If the prototype library has already been loaded, it is not reloaded.
prototypeURL
- A URL of the form http://host/dir/library.ivl#proto
.jarClass
- The class used to find the library in a JAR.MalformedURLException
- if the URL is not correct.IlvReadFileException
- if the library file is not correctly formatted, or if the library
or the prototype is not found.IOException
- on input errors.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.