Skip to content

Commit

Permalink
Now the Descriptor is mandatory in DeploymentDescriptorNode
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Sep 18, 2022
1 parent cca9280 commit 7a63886
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;

import org.glassfish.apf.AnnotatedElementHandler;
import org.glassfish.apf.AnnotationHandlerFor;
Expand All @@ -51,7 +52,6 @@

@Service
@AnnotationHandlerFor(ManagedBean.class)
@SuppressWarnings("deprecation")
public class ManagedBeanHandler extends AbstractHandler {

public ManagedBeanHandler() {
Expand Down Expand Up @@ -92,10 +92,7 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo element) throws
// annotation processing reflectively to avoid dependency on jakarta.interceptor from
// DOL module.

// TODO refactor jakarta.interceptor annotation handlers to support both ejb and non-ejb
// related interceptors

Annotation interceptorsAnn = getClassAnnotation(managedBeanClass, "jakarta.interceptor.Interceptors");
Annotation interceptorsAnn = getClassAnnotation(managedBeanClass, Interceptors.class.getName());
if (interceptorsAnn != null) {
try {
Method m = interceptorsAnn.annotationType().getDeclaredMethod("value");
Expand Down Expand Up @@ -194,8 +191,7 @@ private void processForAnnotations(AnnotationInfo element, AccessibleObject o,
} else {
// If the method or constructor excludes
// class-level interceptors, explicitly set method-level to an empty list.
boolean excludeClassInterceptors = (getMethodAnnotation(o,
"jakarta.interceptor.ExcludeClassInterceptors") != null);
boolean excludeClassInterceptors = getMethodAnnotation(o, ExcludeClassInterceptors.class.getName()) != null;
if (excludeClassInterceptors) {
MethodDescriptor mDesc = getMethodDescriptor(o, managedBeanClass);
if (mDesc != null) {
Expand Down Expand Up @@ -297,13 +293,17 @@ private Annotation getMethodAnnotation(AccessibleObject o, String annotationClas


private boolean methodOverridden(final Method m, final Class<?> declaringSuperClass, final Class<?> leafClass) {
logger.log(Level.FINEST, "Checking if {0} of {1} overrides same method in {2}",
new Object[] {m.getName(), leafClass, declaringSuperClass});
if (Modifier.isPrivate(m.getModifiers())) {
return false;
}
Class<?> nextClass = leafClass;
while (nextClass != declaringSuperClass && nextClass != Object.class) {
for (final Method nextMethod : nextClass.getDeclaredMethods()) {
if (!Modifier.isPrivate(nextMethod.getModifiers()) && TypeUtil.sameMethodSignature(m, nextMethod)) {
logger.log(Level.FINEST, "Method {0} of {1} overrides same method in {2}",
new Object[] {m.getName(), leafClass, nextClass});
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
* @param <T> Deployment {@link Descriptor} type.
* @author Jerome Dochez
*/
public abstract class DeploymentDescriptorNode<T> implements XMLNode<T> {
public abstract class DeploymentDescriptorNode<T extends Descriptor> implements XMLNode<T> {

private static final Logger LOG = DOLUtils.getDefaultLogger();
protected static final LocalStringManagerImpl I18N_NODE = new LocalStringManagerImpl(DeploymentDescriptorNode.class);
Expand Down Expand Up @@ -151,7 +151,7 @@ public T getDescriptor() {


protected T createDescriptor() {
return (T) DescriptorFactory.getDescriptor(getXMLPath());
return DescriptorFactory.getDescriptor(getXMLPath());
}


Expand Down Expand Up @@ -325,9 +325,7 @@ private Class<?> getExtensionHandler(final XMLElement element) {
return extNode.getClass();
}

/**
* SAX Parser API implementation, we don't really care for now.
*/

@Override
public void startElement(XMLElement element, Attributes attributes) {
if (!this.getXMLRootTag().equals(element)) {
Expand All @@ -347,6 +345,7 @@ public void startElement(XMLElement element, Attributes attributes) {
}
}


/**
* parsed an attribute of an element
*
Expand Down Expand Up @@ -637,7 +636,7 @@ public Node writeSubDescriptors(Node node, String nodeName, Descriptor descripto
// write all occurences of this sub node under
// the parent node
try {
DeploymentDescriptorNode subNode = (DeploymentDescriptorNode) handlerClass
DeploymentDescriptorNode<?> subNode = (DeploymentDescriptorNode<?>) handlerClass
.getDeclaredConstructor().newInstance();
subNode.setParentNode(this);
subNode.writeDescriptors(node, subElementName, descriptor);
Expand Down Expand Up @@ -1098,11 +1097,8 @@ protected void addNamespaceDeclaration(Element node, Descriptor descriptor) {
*/
@Override
public void addPrefixMapping(String prefix, String uri) {
Object o = getDescriptor();
if (o instanceof Descriptor) {
Descriptor descriptor = (Descriptor) o;
descriptor.addPrefixMapping(prefix, uri);
}
Descriptor descriptor = getDescriptor();
descriptor.addPrefixMapping(prefix, uri);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static void registerBundleNode(BundleNode bundleNode, String bundleTagNam
* entry to the rootNodes map.
*/
if (mappingStuff.mBundleRegistrationStatus.containsKey(bundleTagName)) {
LOG.log(Level.FINEST, "Mapping already contains entry for tag {0}, returning.", bundleTagName);
return;
}

Expand Down Expand Up @@ -160,6 +161,8 @@ public static void registerBundleNode(BundleNode bundleNode, String bundleTagNam
mappingStuff.mMapping.put(publicID, systemIDResolution);
}
}
LOG.log(Level.FINER, "Final mapping keys for root node key {0}:\n {1}",
new Object[] {rootNodeKey, mappingStuff.mMapping.keySet()});

// This node might know of elements which should permit empty values,
// or elements for which we should preserve white space. Track them.
Expand Down Expand Up @@ -210,10 +213,8 @@ public InputSource resolveEntity(String publicID, String systemID) throws SAXExc
new Object[] {publicID, systemID, fileName});
return new InputSource(fileName);
} catch (SAXException e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
throw e;
} catch (Exception ioe) {
LOG.log(Level.SEVERE, ioe.getMessage(), ioe);
throw new SAXException(ioe);
}
}
Expand Down Expand Up @@ -281,16 +282,14 @@ public static String getSchemaURLFor(String schemaSystemID) throws IOException {
* @param schemaSystemID the system id for the schema
*/
public static File getSchemaFileFor(String schemaSystemID) throws IOException {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Getting Schema " + schemaSystemID);
}
LOG.log(Level.FINE, "Getting Schema {0}", schemaSystemID);
String schemaLoc = DTDRegistry.SCHEMA_LOCATION.replace('/', File.separatorChar);
File f = new File(schemaLoc + File.separatorChar + schemaSystemID);
if (!f.exists()) {
LOG.fine("Cannot find schema " + schemaSystemID);
return null;
if (f.exists()) {
return f;
}
return f;
LOG.log(Level.INFO, "Cannot find the schema file {0}", f);
return null;
}


Expand Down Expand Up @@ -431,9 +430,7 @@ public void startElement(String uri, String localName, String qName, Attributes
} else {
try {
node = (XMLNode<?>) rootNodeClass.getDeclaredConstructor().newInstance();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Instanciating " + node);
}
LOG.log(Level.FINE, "Instantiating {0}", node);
if (node instanceof RootXMLNode) {
if (publicID != null) {
((RootXMLNode) node).setDocType(publicID);
Expand All @@ -449,7 +446,7 @@ public void startElement(String uri, String localName, String qName, Attributes
}
}
} else {
node = nodes.get(nodes.size()-1);
node = nodes.get(nodes.size() - 1);
}
if (node != null) {
XMLElement element = new XMLElement(qName, namespaces);
Expand All @@ -459,7 +456,7 @@ public void startElement(String uri, String localName, String qName, Attributes
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Asking for new handler for " + element + " to " + node);
}
XMLNode newNode = node.getHandlerFor(element);
XMLNode<?> newNode = node.getHandlerFor(element);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Got " + newNode);
}
Expand Down

0 comments on commit 7a63886

Please sign in to comment.