Skip to content

Commit

Permalink
Minor cleanups, generics
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 20, 2022
1 parent c97b99d commit 445579b
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 538 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public XMLNode<?> getRootNode() {
* @param element XMLElement is the XML tag this XMLNode will handle
* @param handler the class implemenenting the XMLNode interface
*/
protected void registerElementHandler(XMLElement element, Class<?> handler) {
protected final void registerElementHandler(XMLElement element, Class<?> handler) {
if (handlers == null) {
handlers = new Hashtable<>();
}
Expand All @@ -265,7 +265,7 @@ protected void registerElementHandler(XMLElement element, Class<?> handler) {
* @param addMethodName is the method name for adding the descriptor
* extracted by the handler node to the current descriptor
*/
public void registerElementHandler(XMLElement element, Class<?> handler, String addMethodName) {
public final void registerElementHandler(XMLElement element, Class<?> handler, String addMethodName) {
registerElementHandler(element, handler);
if (addMethods == null) {
addMethods = new Hashtable<>();
Expand Down Expand Up @@ -617,9 +617,7 @@ public Node writeSubDescriptors(Node node, String nodeName, Descriptor descripto
.getNodeMappings(nodeName);
if (elementToNodeMappings != null) {
Set<Map.Entry<String, Class<?>>> entrySet = elementToNodeMappings.entrySet();
Iterator<Map.Entry<String, Class<?>>> entryIt = entrySet.iterator();
while (entryIt.hasNext()) {
Entry<String, Class<?>> entry = entryIt.next();
for (Entry<String, Class<?>> entry : entrySet) {
String subElementName = entry.getKey();
// skip if it's the element itself and not the subelement
if (subElementName.equals(nodeName)) {
Expand Down Expand Up @@ -1082,9 +1080,7 @@ protected void addNamespaceDeclaration(Element node, Descriptor descriptor) {
Map<String, String> prefixMapping = descriptor == null ? null : descriptor.getPrefixMapping();
if (prefixMapping != null) {
Set<Map.Entry<String, String>> entrySet = prefixMapping.entrySet();
Iterator<Map.Entry<String, String>> entryIt = entrySet.iterator();
while (entryIt.hasNext()) {
Map.Entry<String, String> entry = entryIt.next();
for (Entry<String, String> entry : entrySet) {
String prefix = entry.getKey();
String namespaceURI = entry.getValue();
setAttributeNS(node, prefix, namespaceURI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -94,9 +93,7 @@ public void writeLocalizedInfo(Node parentNode, Descriptor descriptor) {
}
if (smallIcons != null) {
Set<Entry<String, String>> entrySet = smallIcons.entrySet();
Iterator<Entry<String, String>> entryIt = entrySet.iterator();
while (entryIt.hasNext()) {
Entry<String, String> entry = entryIt.next();
for (Entry<String, String> entry : entrySet) {
String lang = entry.getKey();
String smallIconUri = entry.getValue();
String largeIconUri = null;
Expand All @@ -108,9 +105,7 @@ public void writeLocalizedInfo(Node parentNode, Descriptor descriptor) {
}
if (largeIcons != null) {
Set<Entry<String, String>> entrySet = largeIcons.entrySet();
Iterator<Entry<String, String>> entryIt = entrySet.iterator();
while (entryIt.hasNext()) {
Entry<String, String> entry = entryIt.next();
for (Entry<String, String> entry : entrySet) {
String lang = entry.getKey();
String largeIconUri = entry.getValue();
if (smallIcons != null && smallIcons.get(lang) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
import org.w3c.dom.Node;
import org.xml.sax.Attributes;

import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
* This class is responsible for handling the xml lang attribute of
* an xml element
* This class is responsible for handling the xml lang attribute of an xml element
*
* @author Jerome Dochez
*/
Expand All @@ -41,12 +39,6 @@ public class LocalizedNode extends DeploymentDescriptorNode<Descriptor> {
private String lang;
private String localizedValue;

@Override
public Descriptor getDescriptor() {
// return getParentNode().getDescriptor();
return null;
}


protected String getLang() {
return lang;
Expand Down Expand Up @@ -98,9 +90,7 @@ public void writeLocalizedMap(Node parentNode, String tagName, Map<String, Strin
return;
}
Set<Entry<String, String>> entrySet = localizedMap.entrySet();
Iterator<Entry<String, String>> entryIt = entrySet.iterator();
while (entryIt.hasNext()) {
Entry<String, String> entry = entryIt.next();
for (Entry<String, String> entry : entrySet) {
String entryLang = entry.getKey();
Element aLocalizedNode = (Element) appendTextChild(parentNode, tagName, entry.getValue());
if (aLocalizedNode != null && Locale.getDefault().getLanguage().equals(entryLang)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.deployment.xml.TagNames;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;

import org.glassfish.ejb.deployment.EjbTagNames;
import org.glassfish.ejb.deployment.descriptor.EjbApplicationExceptionInfo;
import org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl;
import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
Expand All @@ -53,6 +50,22 @@
import org.jvnet.hk2.annotations.Service;
import org.w3c.dom.Node;

import static org.glassfish.ejb.deployment.EjbTagNames.APPLICATION_EXCEPTION;
import static org.glassfish.ejb.deployment.EjbTagNames.ASSEMBLY_DESCRIPTOR;
import static org.glassfish.ejb.deployment.EjbTagNames.CONTAINER_TRANSACTION;
import static org.glassfish.ejb.deployment.EjbTagNames.EJBS;
import static org.glassfish.ejb.deployment.EjbTagNames.EJB_BUNDLE_TAG;
import static org.glassfish.ejb.deployment.EjbTagNames.EJB_CLIENT_JAR;
import static org.glassfish.ejb.deployment.EjbTagNames.ENTITY;
import static org.glassfish.ejb.deployment.EjbTagNames.EXCLUDE_LIST;
import static org.glassfish.ejb.deployment.EjbTagNames.INTERCEPTOR;
import static org.glassfish.ejb.deployment.EjbTagNames.INTERCEPTORS;
import static org.glassfish.ejb.deployment.EjbTagNames.INTERCEPTOR_BINDING;
import static org.glassfish.ejb.deployment.EjbTagNames.MESSAGE_DRIVEN;
import static org.glassfish.ejb.deployment.EjbTagNames.METHOD_PERMISSION;
import static org.glassfish.ejb.deployment.EjbTagNames.RELATIONSHIPS;
import static org.glassfish.ejb.deployment.EjbTagNames.SESSION;

/**
* This class handles ejb bundle xml files
*
Expand All @@ -62,7 +75,7 @@
@Service
public class EjbBundleNode extends AbstractBundleNode<EjbBundleDescriptorImpl> {

private static final XMLElement tag = new XMLElement(EjbTagNames.EJB_BUNDLE_TAG);
private static final XMLElement tag = new XMLElement(EJB_BUNDLE_TAG);
private static final String PUBLIC_DTD_ID = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN";
private static final String PUBLIC_DTD_ID_12 = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN";

Expand All @@ -75,8 +88,8 @@ public class EjbBundleNode extends AbstractBundleNode<EjbBundleDescriptorImpl> {
private static final String SCHEMA_ID_32 = "ejb-jar_3_2.xsd";
private static final String SCHEMA_ID = "ejb-jar_4_0.xsd";
public static final String SPEC_VERSION = "4.0";
private final static List<String> systemIDs = initSystemIDs();

private static final List<String> SYSTEM_IDS = List.of(
SCHEMA_ID, SCHEMA_ID_32, SCHEMA_ID_31, SCHEMA_ID_30, SCHEMA_ID_21);

// Descriptor class we are using
private EjbBundleDescriptorImpl descriptor;
Expand Down Expand Up @@ -104,36 +117,27 @@ public Map<String, Class<?>> registerRuntimeBundle(
return result;
}

private static List<String> initSystemIDs() {
ArrayList<String> systemIDs = new ArrayList<>(5);
systemIDs.add(SCHEMA_ID);
systemIDs.add(SCHEMA_ID_32);
systemIDs.add(SCHEMA_ID_31);
systemIDs.add(SCHEMA_ID_30);
systemIDs.add(SCHEMA_ID_21);
return Collections.unmodifiableList(systemIDs);
}

public EjbBundleNode() {
// register sub XMLNodes
registerElementHandler(new XMLElement(EjbTagNames.SESSION), EjbSessionNode.class);
registerElementHandler(new XMLElement(EjbTagNames.ENTITY), EjbEntityNode.class);
registerElementHandler(new XMLElement(EjbTagNames.MESSAGE_DRIVEN), MessageDrivenBeanNode.class);
registerElementHandler(new XMLElement(EjbTagNames.METHOD_PERMISSION), MethodPermissionNode.class);
registerElementHandler(new XMLElement(SESSION), EjbSessionNode.class);
registerElementHandler(new XMLElement(ENTITY), EjbEntityNode.class);
registerElementHandler(new XMLElement(MESSAGE_DRIVEN), MessageDrivenBeanNode.class);
registerElementHandler(new XMLElement(METHOD_PERMISSION), MethodPermissionNode.class);
registerElementHandler(new XMLElement(TagNames.ROLE), SecurityRoleNode.class, "addRole");
registerElementHandler(new XMLElement(EjbTagNames.CONTAINER_TRANSACTION), ContainerTransactionNode.class);
registerElementHandler(new XMLElement(EjbTagNames.EXCLUDE_LIST), ExcludeListNode.class);
registerElementHandler(new XMLElement(EjbTagNames.RELATIONSHIPS), RelationshipsNode.class);
registerElementHandler(new XMLElement(CONTAINER_TRANSACTION), ContainerTransactionNode.class);
registerElementHandler(new XMLElement(EXCLUDE_LIST), ExcludeListNode.class);
registerElementHandler(new XMLElement(RELATIONSHIPS), RelationshipsNode.class);
registerElementHandler(new XMLElement(TagNames.MESSAGE_DESTINATION), MessageDestinationNode.class,
"addMessageDestination");
registerElementHandler(new XMLElement(EjbTagNames.APPLICATION_EXCEPTION), EjbApplicationExceptionNode.class,
registerElementHandler(new XMLElement(APPLICATION_EXCEPTION), EjbApplicationExceptionNode.class,
"addApplicationException");
registerElementHandler(new XMLElement(EjbTagNames.INTERCEPTOR), EjbInterceptorNode.class, "addInterceptor");
registerElementHandler(new XMLElement(INTERCEPTOR), EjbInterceptorNode.class, "addInterceptor");

registerElementHandler(new XMLElement(EjbTagNames.INTERCEPTOR_BINDING), InterceptorBindingNode.class,
registerElementHandler(new XMLElement(INTERCEPTOR_BINDING), InterceptorBindingNode.class,
"appendInterceptorBinding");

SaxParserHandler.registerBundleNode(this, EjbTagNames.EJB_BUNDLE_TAG);
SaxParserHandler.registerBundleNode(this, EJB_BUNDLE_TAG);
}


Expand Down Expand Up @@ -183,55 +187,58 @@ public EjbBundleDescriptorImpl getDescriptor() {
return descriptor;
}


@Override
protected XMLElement getXMLRootTag() {
return tag;
}


@Override
protected Map getDispatchTable() {
protected Map<String, String> getDispatchTable() {
// no need to be synchronized for now
Map<String, String> table = super.getDispatchTable();
table.put(EjbTagNames.EJB_CLIENT_JAR, "setEjbClientJarUri");
table.put(EJB_CLIENT_JAR, "setEjbClientJarUri");
return table;
}


@Override
public Node writeDescriptor(Node parent, EjbBundleDescriptorImpl ejbDesc) {
Node jarNode = super.writeDescriptor(parent, ejbDesc);
Node entrepriseBeansNode = appendChild(jarNode, EjbTagNames.EJBS);
Node entrepriseBeansNode = appendChild(jarNode, EJBS);
for (EjbDescriptor ejb : ejbDesc.getEjbs()) {
if (com.sun.enterprise.deployment.EjbSessionDescriptor.TYPE.equals(ejb.getType())) {
EjbSessionNode subNode = new EjbSessionNode();
subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.SESSION, (EjbSessionDescriptor) ejb);
subNode.writeDescriptor(entrepriseBeansNode, SESSION, (EjbSessionDescriptor) ejb);
} else if (EjbEntityDescriptor.TYPE.equals(ejb.getType())) {
EjbEntityNode subNode = new EjbEntityNode();
subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.ENTITY, (EjbEntityDescriptor) ejb);
subNode.writeDescriptor(entrepriseBeansNode, ENTITY, (EjbEntityDescriptor) ejb);
} else if (com.sun.enterprise.deployment.EjbMessageBeanDescriptor.TYPE.equals(ejb.getType())) {
MessageDrivenBeanNode subNode = new MessageDrivenBeanNode();
subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.MESSAGE_DRIVEN, (EjbMessageBeanDescriptor) ejb);
subNode.writeDescriptor(entrepriseBeansNode, MESSAGE_DRIVEN, (EjbMessageBeanDescriptor) ejb);
} else {
throw new IllegalStateException("Unknow ejb type " + ejb.getType());
}
}

if (ejbDesc.hasInterceptors()) {
Node interceptorsNode = appendChild(jarNode, EjbTagNames.INTERCEPTORS);
Node interceptorsNode = appendChild(jarNode, INTERCEPTORS);
EjbInterceptorNode interceptorNode = new EjbInterceptorNode();
for (EjbInterceptor next : ejbDesc.getInterceptors()) {
interceptorNode.writeDescriptor(interceptorsNode, EjbTagNames.INTERCEPTOR, next);
interceptorNode.writeDescriptor(interceptorsNode, INTERCEPTOR, next);
}
}

// relationships*
if (ejbDesc.hasRelationships()) {
RelationshipsNode.writeRelationships(jarNode, EjbTagNames.RELATIONSHIPS, ejbDesc);
RelationshipsNode.writeRelationships(jarNode, RELATIONSHIPS, ejbDesc);
}

// assembly-descriptor
writeAssemblyDescriptor(jarNode, ejbDesc);

appendTextChild(jarNode, EjbTagNames.EJB_CLIENT_JAR, ejbDesc.getEjbClientJarUri());
appendTextChild(jarNode, EJB_CLIENT_JAR, ejbDesc.getEjbClientJarUri());
return jarNode;
}

Expand All @@ -250,7 +257,7 @@ public String getSystemID() {

@Override
public List<String> getSystemIDs() {
return systemIDs;
return SYSTEM_IDS;
}


Expand All @@ -264,7 +271,7 @@ public String getSpecVersion() {
* Write assembly-descriptor related xml information to the DOM tree
*/
private void writeAssemblyDescriptor(Node parentNode, EjbBundleDescriptorImpl bundleDescriptor) {
Node assemblyNode = parentNode.getOwnerDocument().createElement(EjbTagNames.ASSEMBLY_DESCRIPTOR);
Node assemblyNode = parentNode.getOwnerDocument().createElement(ASSEMBLY_DESCRIPTOR);

// security-role*
SecurityRoleNode roleNode = new SecurityRoleNode();
Expand All @@ -291,7 +298,7 @@ private void writeAssemblyDescriptor(Node parentNode, EjbBundleDescriptorImpl bu

// container-transaction*
for (EjbDescriptor ejbDesc : bundleDescriptor.getEjbs()) {
ContainerTransactionNode.writeContainerTransactions(assemblyNode, EjbTagNames.CONTAINER_TRANSACTION,
ContainerTransactionNode.writeContainerTransactions(assemblyNode, CONTAINER_TRANSACTION,
ejbDesc.getName(), ejbDesc.getMethodContainerTransactions());
}

Expand All @@ -308,7 +315,7 @@ private void writeAssemblyDescriptor(Node parentNode, EjbBundleDescriptorImpl bu

// exclude-list*
if (!excludedMethodsByEjb.isEmpty()) {
Node excludeListNode = DeploymentDescriptorNode.appendChild(assemblyNode, EjbTagNames.EXCLUDE_LIST);
Node excludeListNode = DeploymentDescriptorNode.appendChild(assemblyNode, EXCLUDE_LIST);
for (Entry<EjbDescriptor, Vector<MethodDescriptor>> entry : excludedMethodsByEjb.entrySet()) {
EjbDescriptor ejbDesc = entry.getKey();
Vector<MethodDescriptor> excludedMethods = entry.getValue();
Expand All @@ -321,7 +328,7 @@ private void writeAssemblyDescriptor(Node parentNode, EjbBundleDescriptorImpl bu

for (EjbApplicationExceptionInfo next : bundleDescriptor.getApplicationExceptions().values()) {
EjbApplicationExceptionNode node = new EjbApplicationExceptionNode();
node.writeDescriptor(assemblyNode, EjbTagNames.APPLICATION_EXCEPTION, next);
node.writeDescriptor(assemblyNode, APPLICATION_EXCEPTION, next);
}

if (assemblyNode.hasChildNodes()) {
Expand Down Expand Up @@ -349,7 +356,7 @@ private void addMethodPermissions(
MethodPermissionDescriptor mpd = new MethodPermissionDescriptor();
mpd.addMethodPermission(mp);
mpd.addMethods(mpToMethods.get(mp));
mpNode.writeDescriptor(assemblyNode, EjbTagNames.METHOD_PERMISSION, mpd, ejb);
mpNode.writeDescriptor(assemblyNode, METHOD_PERMISSION, mpd, ejb);
}
}
}
Expand Down

0 comments on commit 445579b

Please sign in to comment.