public class TemplateContextType extends Object
TemplateVariableResolver
s. A
TemplateBuffer
can be resolved in a
TemplateContext
using the
resolve(TemplateBuffer, TemplateContext)
method.
Clients may extend this class.
Constructor and Description |
---|
TemplateContextType()
Creates a context type with a
null identifier. |
TemplateContextType(String id)
Creates a context type with an identifier.
|
TemplateContextType(String id,
String name)
Creates a context type with an identifier.
|
Modifier and Type | Method and Description |
---|---|
void |
addResolver(TemplateVariableResolver resolver)
Adds a variable resolver to the context type.
|
String |
getId()
Returns the id of the context type.
|
String |
getName()
Returns the name of the context type.
|
protected TemplateVariableResolver |
getResolver(String type)
Returns the resolver for the given type.
|
void |
removeAllResolvers()
Removes all template variables from the context type.
|
void |
removeResolver(TemplateVariableResolver resolver)
Removes a template variable from the context type.
|
void |
resolve(TemplateBuffer buffer,
TemplateContext context)
Resolves the variables in
buffer within context
and edits the template buffer to reflect the resolved variables. |
void |
resolve(TemplateVariable variable,
TemplateContext context)
Resolves a single variable in a context.
|
Iterator |
resolvers()
Returns an iterator for the variables known to the context type.
|
void |
setId(String id)
Sets the id of this context.
|
void |
setName(String name)
Sets the name of the context type.
|
void |
validate(String pattern)
Validates a pattern, a
TemplateException is thrown if
validation fails. |
protected void |
validateVariables(TemplateVariable[] variables)
Validates the variables in this context type.
|
public TemplateContextType(String id)
id
- the unique identifier of the context typepublic TemplateContextType(String id, String name)
id
- the unique identifier of the context typename
- the name of the context typepublic TemplateContextType()
null
identifier.
This is a framework-only constructor that exists only so that context
types can be contributed via an extension point and that should not be
called in client code except for subclass constructors; use
TemplateContextType(String)
instead.
public String getId()
public String getName()
public final void setId(String id) throws RuntimeException
This is a framework-only method that exists solely so that context types
can be contributed via an extension point and that should not be called
in client code; use TemplateContextType(String)
instead.
id
- the identifier of this contextRuntimeException
- an unspecified exception if the id has already
been set on this context typepublic final void setName(String name)
This is a framework-only method that exists solely so that context types
can be contributed via an extension point and that should not be called
in client code; use TemplateContextType(String, String)
instead.
name
- the name of the context typepublic void addResolver(TemplateVariableResolver resolver)
resolver
.resolver
- the resolver to be added under its namepublic void removeResolver(TemplateVariableResolver resolver)
resolver
- the variable to be removedpublic void removeAllResolvers()
public Iterator resolvers()
TemplateVariableResolver
)protected TemplateVariableResolver getResolver(String type)
type
- the type for which a resolver is needednull
if none is registeredpublic void validate(String pattern) throws TemplateException
TemplateException
is thrown if
validation fails.pattern
- the template pattern to validateTemplateException
- if the pattern is invalidprotected void validateVariables(TemplateVariable[] variables) throws TemplateException
TemplateException
is thrown.
The default implementation does nothing.
variables
- the variables to validateTemplateException
- if one of the variables is not valid in this
context typepublic void resolve(TemplateBuffer buffer, TemplateContext context) throws MalformedTreeException, BadLocationException
buffer
within context
and edits the template buffer to reflect the resolved variables.buffer
- the template buffercontext
- the template contextMalformedTreeException
- if the positions in the buffer overlapBadLocationException
- if the buffer cannot be successfully modifiedpublic void resolve(TemplateVariable variable, TemplateContext context)
variable
- the variable to resolvecontext
- the context in which to resolve the variable
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.