Class AbstractInternalContext

java.lang.Object
org.castor.xml.AbstractInternalContext
All Implemented Interfaces:
InternalContext, PropertyChangeProvider
Direct Known Subclasses:
BackwardCompatibilityContext

public abstract class AbstractInternalContext extends Object implements InternalContext
The internal context is meant as center piece providing (and keeping) all information that is required by Marshaller, Unmarshaller, SourceGenerator, MappingTool, SchemaReader and SchemaWriter. It is created, filled with initial data and put into all other parts of Castor by XMLContext. It is NOT meant to be directly instantiated by user implementations! For all other objects it provides access to Castor state information (e.g. known descriptors) and configuration values.
Since:
1.1.2
Author:
Joachim Grueneis
  • Constructor Details

    • AbstractInternalContext

      public AbstractInternalContext()
  • Method Details

    • addMapping

      public void addMapping(Mapping mapping) throws MappingException
      Description copied from interface: InternalContext
      Instructs Castor to load class descriptors from the mapping given.
      Specified by:
      addMapping in interface InternalContext
      Parameters:
      mapping - Castor XML mapping (file), from which the required class descriptors will be derived.
      Throws:
      MappingException - If the Mapping cannot be loaded and analyzed successfully.
    • addClass

      public void addClass(Class<?> clazz) throws ResolverException
      Description copied from interface: InternalContext
      Loads the class descriptor for the class instance specified. The use of this method is useful when no mapping is used, as happens when the domain classes has been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).
      Specified by:
      addClass in interface InternalContext
      Parameters:
      clazz - the class for which the associated descriptor should be loaded.
      Throws:
      ResolverException - in case that resolving the Class fails fatally
    • addClasses

      public void addClasses(Class<?>[] clazzes) throws ResolverException
      Description copied from interface: InternalContext
      Loads the class descriptor for the class instance specified. The use of this method is useful when no mapping is used, as happens when the domain classes hase been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).
      Specified by:
      addClasses in interface InternalContext
      Parameters:
      clazzes - the classes for which the associated descriptor should be loaded.
      Throws:
      ResolverException - in case that resolving the Class fails fatally
    • addPackage

      public void addPackage(String packageName) throws ResolverException
      Description copied from interface: InternalContext
      Loads class descriptors from the package specified. The use of this method is useful when no mapping is used, as happens when the domain classes hase been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).

      Please note that this functionality will work only if you provide the .castor.cdr file with your generated classes (as generated by the XML code generator).

      Specified by:
      addPackage in interface InternalContext
      Parameters:
      packageName - The package name for the (descriptor) classes
      Throws:
      ResolverException - If there's a problem loading class descriptors for the given package.
    • addPackages

      public void addPackages(String[] packageNames) throws ResolverException
      Description copied from interface: InternalContext
      Loads class descriptors from the packages specified. The use of this method is useful when no mapping is used, as happens when the domain classes hase been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).

      Please note that this functionality will work only if you provide the .castor.cdr files with your generated classes (as generated by the XML code generator).

      Specified by:
      addPackages in interface InternalContext
      Parameters:
      packageNames - The package names for the (descriptor) classes
      Throws:
      ResolverException - If there's a problem loading class descriptors for the given package.
    • setResolver

      public void setResolver(XMLClassDescriptorResolver xmlClassDescriptorResolver)
      Description copied from interface: InternalContext
      Sets an application-specific XMLClassDescriptorResolver instance.
      Specified by:
      setResolver in interface InternalContext
      Parameters:
      xmlClassDescriptorResolver - the resolver to use
    • setProperty

      public void setProperty(String propertyName, Object value)
      Description copied from interface: InternalContext
      To set properties for marshalling and unmarshalling behavior.
      Specified by:
      setProperty in interface InternalContext
      Parameters:
      propertyName - name of the property to set
      value - the value to set to
    • getProperty

      public Object getProperty(String propertyName)
      Description copied from interface: InternalContext
      To get the value of a specific property.
      Specified by:
      getProperty in interface InternalContext
      Parameters:
      propertyName - name of the Property
      Returns:
      the value (Object) of the property
    • getXMLNaming

      public XMLNaming getXMLNaming()
      Description copied from interface: InternalContext
      Returns the naming conventions to use for the XML framework.
      Specified by:
      getXMLNaming in interface InternalContext
      Returns:
      the naming conventions to use for the XML framework
    • getXMLNaming

      public XMLNaming getXMLNaming(ClassLoader classLoader)
      Deprecated.
      Makes no sence!
      Description copied from interface: InternalContext
      Returns the naming conventions to use for the XML framework.
      Specified by:
      getXMLNaming in interface InternalContext
      Parameters:
      classLoader - the class loader to be used when instantiating a new naming instance
      Returns:
      the naming conventions to use for the XML framework
    • getJavaNaming

      public JavaNaming getJavaNaming()
      Description copied from interface: InternalContext
      The JavaNaming instance to be used.
      Specified by:
      getJavaNaming in interface InternalContext
      Returns:
      JavaNaming instance to be used.
    • getParser

      public Parser getParser()
      Description copied from interface: InternalContext
      Return an XML document parser implementing the feature list specified in the configuration file.
      Specified by:
      getParser in interface InternalContext
      Returns:
      A suitable XML parser
    • getParser

      public Parser getParser(String features)
      Description copied from interface: InternalContext
      Returns an XML document parser implementing the requested set of features. The feature list is a comma separated list of features that parser may or may not support. No errors are generated for unsupported features. If the feature list is not null, it overrides the default feature list specified in the configuration file, including validation and Namespaces.
      Specified by:
      getParser in interface InternalContext
      Parameters:
      features - The requested feature list, null for the defaults
      Returns:
      A suitable XML parser
    • getXMLReader

      public XMLReader getXMLReader()
      Description copied from interface: InternalContext
      Returns an XML document parser implementing the requested set of features. The feature list is a comma separated list of features that parser may or may not support. No errors are generated for unsupported features. If the feature list is not null, it overrides the default feature list specified in the configuration file, including validation and Namespaces.
      Specified by:
      getXMLReader in interface InternalContext
      Returns:
      A suitable XML parser
    • getXMLReader

      public XMLReader getXMLReader(String features)
      Description copied from interface: InternalContext
      Returns an XML document parser implementing the requested set of features. The feature list is a comma separated list of features that parser may or may not support. No errors are generated for unsupported features. If the feature list is not null, it overrides the default feature list specified in the configuration file, including validation and Namespaces.
      Specified by:
      getXMLReader in interface InternalContext
      Parameters:
      features - the name of feature to set
      Returns:
      A suitable XML parser
    • getPrimitiveNodeType

      public NodeType getPrimitiveNodeType()
      Description copied from interface: InternalContext
      Returns the NodeType to use for Java primitives. A null value will be returned if no NodeType was specified, indicating the default NodeType should be used.
      Specified by:
      getPrimitiveNodeType in interface InternalContext
      Returns:
      the NodeType assigned to Java primitives, or null if no NodeType was specified.
    • getRegExpEvaluator

      public RegExpEvaluator getRegExpEvaluator()
      Description copied from interface: InternalContext
      Returns a new instance of the specified Regular Expression Evaluator, or null if no validator was specified.
      Specified by:
      getRegExpEvaluator in interface InternalContext
      Returns:
      the regular expression evaluator,
    • getSerializer

      public Serializer getSerializer()
      Description copied from interface: InternalContext
      Returns a default serializer for producing an XML document. The caller can specify an alternative output format, may reuse this serializer across several streams, and may serialize both DOM and SAX events. If such control is not required, it is recommended to call one of the other two methods.
      Specified by:
      getSerializer in interface InternalContext
      Returns:
      A suitable serializer
    • getOutputFormat

      public OutputFormat getOutputFormat()
      Description copied from interface: InternalContext
      Returns the default OutputFormat for use with a Serializer.
      Specified by:
      getOutputFormat in interface InternalContext
      Returns:
      the default OutputFormat
    • getSerializerFactory

      protected XMLSerializerFactory getSerializerFactory(String serializerFactoryName)
      Returns the currently configured XMLSerializerFactory instance.
      Parameters:
      serializerFactoryName - the class name of the serializer factory
      Returns:
      XMLSerializerFactory to use by Castor
    • getSerializer

      public DocumentHandler getSerializer(OutputStream output) throws IOException
      Description copied from interface: InternalContext
      Returns a default serializer for producing an XML document to the designated output stream using the default serialization format.
      Specified by:
      getSerializer in interface InternalContext
      Parameters:
      output - The output stream
      Returns:
      A suitable serializer
      Throws:
      IOException - if instantiation of the serializer fails
    • getSerializer

      public DocumentHandler getSerializer(Writer output) throws IOException
      Description copied from interface: InternalContext
      Returns a default serializer for producing an XML document to the designated output stream using the default serialization format.
      Specified by:
      getSerializer in interface InternalContext
      Parameters:
      output - The output stream
      Returns:
      A suitable serializer
      Throws:
      IOException - if instantiation of serializer fails
    • getXMLClassDescriptorResolver

      public XMLClassDescriptorResolver getXMLClassDescriptorResolver()
      Description copied from interface: InternalContext
      To get the XMLClassdescriptorResolver instance hold in the context.
      Specified by:
      getXMLClassDescriptorResolver in interface InternalContext
      Returns:
      the XMLClassdescriptorResolver instance hold in the context
    • getIntrospector

      public Introspector getIntrospector()
      Description copied from interface: InternalContext
      To get the Introspector assigned to this XMLContext.
      Specified by:
      getIntrospector in interface InternalContext
      Returns:
      the Introspector assigned to this XMLContext
    • getResolverStrategy

      public ResolverStrategy getResolverStrategy()
      Description copied from interface: InternalContext
      To get the XMLClassDescriptor resolver strategy to be used when resolving classes into class descriptors.
      Specified by:
      getResolverStrategy in interface InternalContext
      Returns:
      the ResolverStrategy to use
    • setResolverStrategy

      public void setResolverStrategy(ResolverStrategy resolverStrategy)
      Description copied from interface: InternalContext
      To set the XMLClassDescriptor resolver strategy to be used.
      Specified by:
      setResolverStrategy in interface InternalContext
      Parameters:
      resolverStrategy - the ResolverStrategy to use
    • setMappingLoader

      public void setMappingLoader(MappingLoader mappingLoader)
      Description copied from interface: InternalContext
      To set the MappingLoader to be used in this Castor session.
      Specified by:
      setMappingLoader in interface InternalContext
      Parameters:
      mappingLoader - the MappingLoader to use
    • getMappingLoader

      public MappingLoader getMappingLoader()
      Description copied from interface: InternalContext
      To get the MappingLoader specified to be used in this Castor session.
      Specified by:
      getMappingLoader in interface InternalContext
      Returns:
      the MappingLoader to use
    • setJavaNaming

      public void setJavaNaming(JavaNaming javaNaming)
      Description copied from interface: InternalContext
      To set the JavaNaming?property.
      Specified by:
      setJavaNaming in interface InternalContext
      Parameters:
      javaNaming - the JavaNaming to use
    • setJavaNaming

      public void setJavaNaming(String javaNamingProperty)
    • setXMLNaming

      public void setXMLNaming(XMLNaming xmlNaming)
      Description copied from interface: InternalContext
      To set the XMLNaming property.
      Specified by:
      setXMLNaming in interface InternalContext
      Parameters:
      xmlNaming - the XMLNaming to use
    • setXMLNaming

      public void setXMLNaming(String xmlNamingProperty)
      This XMLNaming setter is meant to be used when working in property style instead of setting an XMLNaming implementation.
      Parameters:
      xmlNamingProperty - to set the XMLNaming property as read from configuration
    • setProperty

      public void setProperty(String propertyName, boolean value)
      Description copied from interface: InternalContext
      To set any boolean property.
      Specified by:
      setProperty in interface InternalContext
      Parameters:
      propertyName - name of the property to set
      value - boolean value to set
    • getBooleanProperty

      public Boolean getBooleanProperty(String propertyName)
      Description copied from interface: InternalContext
      Providing access to Boolean properties of the configuration.
      Specified by:
      getBooleanProperty in interface InternalContext
      Parameters:
      propertyName - name of the property
      Returns:
      null if property is not set or whichever value is set
    • getStringProperty

      public String getStringProperty(String propertyName)
      Description copied from interface: InternalContext
      Providing access to String properties of the configuration.
      Specified by:
      getStringProperty in interface InternalContext
      Parameters:
      propertyName - name of the property
      Returns:
      null if the property is not set or whichever value is set
    • setClassLoader

      public void setClassLoader(ClassLoader classLoader)
      Description copied from interface: InternalContext
      To set the class loader to be used in all further marshalling, unmarshalling and other actions.
      Specified by:
      setClassLoader in interface InternalContext
      Parameters:
      classLoader - the ClassLoader instance to use
    • setXMLClassDescriptorResolver

      public void setXMLClassDescriptorResolver(XMLClassDescriptorResolver xmlClassDescriptorResolver)
      Description copied from interface: InternalContext
      To set the XMLClassDescriptorResolver to be used. Be aware, that the XMLClassDescriptorResolver instance holds a descriptor cache!! Maybe change it to have the descriptor cache as part of the context?
      Specified by:
      setXMLClassDescriptorResolver in interface InternalContext
      Parameters:
      xmlClassDescriptorResolver - the XMLClassDescriptorResolver to use
    • setIntrospector

      public void setIntrospector(Introspector introspector)
      Description copied from interface: InternalContext
      To specify which Introspector?is to be used.
      Specified by:
      setIntrospector in interface InternalContext
      Parameters:
      introspector - Introspector to be used
    • getClassLoader

      public ClassLoader getClassLoader()
      Description copied from interface: InternalContext
      To get the ClassLoader to use for loading resources.
      Specified by:
      getClassLoader in interface InternalContext
      Returns:
      the ClassLoader to use
    • getLenientIdValidation

      public boolean getLenientIdValidation()
      Description copied from interface: InternalContext
      Get lenient id validation flag.
      Specified by:
      getLenientIdValidation in interface InternalContext
      Returns:
      lenient id validation flag
    • getLenientSequenceOrder

      public boolean getLenientSequenceOrder()
      Description copied from interface: InternalContext
      Get lenient sequence order flag.
      Specified by:
      getLenientSequenceOrder in interface InternalContext
      Returns:
      lenient sequence order flag
    • getLoadPackageMapping

      public Boolean getLoadPackageMapping()
      Description copied from interface: InternalContext
      Get load package mapping flag.
      Specified by:
      getLoadPackageMapping in interface InternalContext
      Returns:
      load package mapping flag
    • setLoadPackageMapping

      public void setLoadPackageMapping(Boolean loadPackageMapping)
      Description copied from interface: InternalContext
      To set the load package mapping flag.
      Specified by:
      setLoadPackageMapping in interface InternalContext
      Parameters:
      loadPackageMapping - the load package mapping flag
    • getUseIntrospector

      public Boolean getUseIntrospector()
      Description copied from interface: InternalContext
      To get use-introspection flag.
      Specified by:
      getUseIntrospector in interface InternalContext
      Returns:
      use-introspection flag
    • setUseIntrospector

      public void setUseIntrospector(Boolean useIntrospector)
      Description copied from interface: InternalContext
      To set use-introspection flag.
      Specified by:
      setUseIntrospector in interface InternalContext
      Parameters:
      useIntrospector - use-introspection flag
    • marshallingValidation

      public boolean marshallingValidation()
      Description copied from interface: InternalContext
      To get marshalling-validation flag.
      Specified by:
      marshallingValidation in interface InternalContext
      Returns:
      marshalling-validation flag
    • strictElements

      public boolean strictElements()
      Description copied from interface: InternalContext
      To get strict-element flag.
      Specified by:
      strictElements in interface InternalContext
      Returns:
      strict-element flag
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      Specified by:
      addPropertyChangeListener in interface PropertyChangeProvider
    • addPropertyChangeListener

      public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
      Specified by:
      addPropertyChangeListener in interface PropertyChangeProvider
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener listener)
      Specified by:
      removePropertyChangeListener in interface PropertyChangeProvider
    • removePropertyChangeListener

      public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
      Specified by:
      removePropertyChangeListener in interface PropertyChangeProvider