KIE Remote Services :: Services 6.1.0.CR2

org.kie.remote.services.rest.jaxb
Class DynamicJaxbContext

java.lang.Object
  extended by javax.xml.bind.JAXBContext
      extended by org.kie.remote.services.rest.jaxb.DynamicJaxbContext

@ApplicationScoped
public class DynamicJaxbContext
extends JAXBContext

READ THIS BEFORE WORKING ON THIS CLASS!

There are a couple of hidden issues that this class deals this:

  1. JAXBContext instances are cached by the REST framework. This means that we can not provide multiple JAXBContext instances, but must make sure that an instance of this class is cached. When the extended methods are called (JAXBContext.createMarshaller() for example), we then look at the internal cache to retrieve the correct JAXBContext).
  2. Different deployments may have different version of the same class. This means that We can not use 1 JAXBContext instance to deal with all deployments. Tests have been specifically created to test this issue.
  3. Concurrency: this is an application scoped class that is being acted on by multiple REST request threads. Fortunately, we just handle normal REST requests (no comet, for example), so the requests themselves (with regards to the serializaiton logic) are all handled in one thread.
Regardless, please preserve existing tests when modifying this class!


Field Summary
 
Fields inherited from class javax.xml.bind.JAXBContext
JAXB_CONTEXT_FACTORY
 
Constructor Summary
DynamicJaxbContext()
           
 
Method Summary
 void cleanUpOnUndeploy(DeploymentProcessedEvent event)
          Removes the cached JAXBContext and deployment lock object It's VERY important that the cached JAXBContext instance be removed!
static void clearDeploymentJaxbContext()
           
 Marshaller createMarshaller()
           
 Unmarshaller createUnmarshaller()
           
 Validator createValidator()
           
static void setDeploymentJaxbContext(String deploymentId)
           
 void setupDeploymentJaxbContext(DeploymentProcessedEvent event)
          Adds a deployment lock object.
 
Methods inherited from class javax.xml.bind.JAXBContext
createBinder, createBinder, createJAXBIntrospector, generateSchema, newInstance, newInstance, newInstance, newInstance, newInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicJaxbContext

public DynamicJaxbContext()
Method Detail

setDeploymentJaxbContext

public static void setDeploymentJaxbContext(String deploymentId)

clearDeploymentJaxbContext

public static void clearDeploymentJaxbContext()

createUnmarshaller

public Unmarshaller createUnmarshaller()
                                throws JAXBException
Specified by:
createUnmarshaller in class JAXBContext
Throws:
JAXBException

createMarshaller

public Marshaller createMarshaller()
                            throws JAXBException
Specified by:
createMarshaller in class JAXBContext
Throws:
JAXBException

createValidator

public Validator createValidator()
                          throws JAXBException
Specified by:
createValidator in class JAXBContext
Throws:
JAXBException

setupDeploymentJaxbContext

public void setupDeploymentJaxbContext(@Observes
                                       DeploymentProcessedEvent event)
Adds a deployment lock object.

Parameters:
event - The DeploymentEvent fired on deployment

cleanUpOnUndeploy

public void cleanUpOnUndeploy(@Observes
                              DeploymentProcessedEvent event)
Removes the cached JAXBContext and deployment lock object

It's VERY important that the cached JAXBContext instance be removed! The new deployment may contain a different version of a class with the same name. Keeping the old class definition will cause problems!

Parameters:
event - The DeploymentEvent fired on an undeploy of a deployment

KIE Remote Services :: Services 6.1.0.CR2

Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.