private void addClassToDeployedUnit(Class deploymentClass, DeployedUnitImpl deployedUnit) { if (deploymentClass != null) { DeploymentUnit unit = deployedUnit.getDeploymentUnit(); Boolean limitClasses = false; if (unit != null) { DeploymentDescriptor depDesc = ((KModuleDeploymentUnit) unit).getDeploymentDescriptor(); if (depDesc != null) { limitClasses = depDesc.getLimitSerializationClasses(); } } if (limitClasses != null && limitClasses) { filterClassesAddedToDeployedUnit(deployedUnit, deploymentClass); } else { logger.debug( "Loaded {} onto the classpath from deployment {}", deploymentClass.getName(), unit.getIdentifier()); deployedUnit.addClass(deploymentClass); } } }
/** * This method is used to filter classes that are added to the {@link DeployedUnit}. When this * method is used, only classes that are meant to be used with serialization are added to the * deployment. This feature can be used to, for example, make sure that * non-serialization-compatible classes (such as interfaces), do not complicate the use of a * deployment with the remote services (REST/JMS/WS). Note to other developers, it's possible that * classpath problems may arise, because of either classloader or lazy class resolution problems: * I simply don't know enough about the inner workings of the JAXB implementations (plural!) to * figure this out. * * @param deployedUnit The {@link DeployedUnit} to which the classes are added. The {@link * DeployedUnit} to which the classes are added. The {@link DeployedUnit} to which the classes * are added. * @param classToAdd The class to add to the {@link DeployedUnit}. */ private static void filterClassesAddedToDeployedUnit( DeployedUnit deployedUnit, Class classToAdd) { if (classToAdd.isInterface() || classToAdd.isAnnotation() || classToAdd.isLocalClass() || classToAdd.isMemberClass()) { return; } boolean jaxbClass = false; boolean remoteableClass = false; // @XmlRootElement and @XmlType may be used with inheritance for (Annotation anno : classToAdd.getAnnotations()) { if (XmlRootElement.class.equals(anno.annotationType())) { jaxbClass = true; break; } if (XmlType.class.equals(anno.annotationType())) { jaxbClass = true; break; } } // @Remotable is not inheritable, and may not be used as such for (Annotation anno : classToAdd.getDeclaredAnnotations()) { if (Remotable.class.equals(anno.annotationType())) { remoteableClass = true; break; } } if (jaxbClass || remoteableClass) { DeployedUnitImpl deployedUnitImpl = (DeployedUnitImpl) deployedUnit; deployedUnitImpl.addClass(classToAdd); } }