Skip to content

Commit

Permalink
Static write methods when original method did not use anything from o…
Browse files Browse the repository at this point in the history
…wn object

- original code was confusing to read, caused inconsistencies when I improved
  generics, and led to unwanted usages. Also initiated maps which later
  weren't used at all.
- applied some conventions - removed copypasted javadoc of parent, public
  static methods first, don't set variables which you don't use any more...

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Sep 18, 2022
1 parent bd087ea commit d3071b5
Show file tree
Hide file tree
Showing 18 changed files with 465 additions and 794 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,27 @@ public static Element appendChild(Node parent, String elementName) {
}


/**
* <p>
* Append a new text child
* </p>
*
* @param parent for the new child element
* @param elementName is the new element tag name
* @param content object to be printed via {@link String#toString()} to the text content of
* the new element
* @return the newly create child node
*/
public static Node appendTextChild(Node parent, String elementName, Object content) {
if (content == null) {
return null;
}
Node child = appendChild(parent, elementName);
child.appendChild(getOwnerDocument(child).createTextNode(content.toString()));
return child;
}


/**
* <p>
* Append a new text child
Expand Down Expand Up @@ -770,7 +791,7 @@ protected void writeEnvEntryDescriptors(Node parentNode, Iterator envEntries) {
return;
}
EnvEntryNode subNode = new EnvEntryNode();
for (; envEntries.hasNext();) {
while (envEntries.hasNext()) {
EnvironmentProperty envProp = (EnvironmentProperty) envEntries.next();
subNode.writeDescriptor(parentNode, TagNames.ENVIRONMENT_PROPERTY, envProp);
}
Expand Down Expand Up @@ -831,7 +852,7 @@ protected void writeResourceRefDescriptors(Node parentNode, Iterator resRefs) {
return;
}
ResourceRefNode subNode = new ResourceRefNode();
for (; resRefs.hasNext();) {
while (resRefs.hasNext()) {
ResourceReferenceDescriptor aResRef = (ResourceReferenceDescriptor) resRefs.next();
subNode.writeDescriptor(parentNode, TagNames.RESOURCE_REFERENCE, aResRef);
}
Expand All @@ -843,13 +864,13 @@ protected void writeResourceRefDescriptors(Node parentNode, Iterator resRefs) {
* @param parentNode parent node for the DOM tree
* @param resRefs the iterator over the descriptors to write
*/
protected void writeResourceEnvRefDescriptors(Node parentNode, Iterator resRefs) {
protected void writeResourceEnvRefDescriptors(Node parentNode, Iterator<ResourceEnvReferenceDescriptor> resRefs) {
if (resRefs == null || !resRefs.hasNext()) {
return;
}
ResourceEnvRefNode subNode = new ResourceEnvRefNode();
for (; resRefs.hasNext();) {
ResourceEnvReferenceDescriptor aResRef = (ResourceEnvReferenceDescriptor) resRefs.next();
while (resRefs.hasNext()) {
ResourceEnvReferenceDescriptor aResRef = resRefs.next();
subNode.writeDescriptor(parentNode, TagNames.RESOURCE_ENV_REFERENCE, aResRef);
}
}
Expand All @@ -866,7 +887,7 @@ protected void writeMessageDestinationRefDescriptors(Node parentNode, Iterator m
return;
}
MessageDestinationRefNode subNode = new MessageDestinationRefNode();
for (; msgDestRefs.hasNext();) {
while (msgDestRefs.hasNext()) {
MessageDestinationReferenceDescriptor next = (MessageDestinationReferenceDescriptor) msgDestRefs.next();
subNode.writeDescriptor(parentNode, TagNames.MESSAGE_DESTINATION_REFERENCE, next);
}
Expand All @@ -883,7 +904,7 @@ protected void writeEntityManagerReferenceDescriptors(Node parentNode, Iterator
return;
}
EntityManagerReferenceNode subNode = new EntityManagerReferenceNode();
for (;entityMgrRefs.hasNext();) {
while (entityMgrRefs.hasNext()) {
EntityManagerReferenceDescriptor aEntityMgrRef = (EntityManagerReferenceDescriptor)entityMgrRefs.next();
subNode.writeDescriptor(parentNode, TagNames.PERSISTENCE_CONTEXT_REF, aEntityMgrRef);
}
Expand All @@ -902,7 +923,7 @@ protected void writeEntityManagerFactoryReferenceDescriptors(Node parentNode,
return;
}
EntityManagerFactoryReferenceNode subNode = new EntityManagerFactoryReferenceNode();
for (; entityMgrFactoryRefs.hasNext();) {
while (entityMgrFactoryRefs.hasNext()) {
EntityManagerFactoryReferenceDescriptor aEntityMgrFactoryRef = entityMgrFactoryRefs.next();
subNode.writeDescriptor(parentNode, TagNames.PERSISTENCE_UNIT_REF, aEntityMgrFactoryRef);
}
Expand Down Expand Up @@ -944,7 +965,7 @@ protected void writeResourceDescriptors(Node parentNode, Iterator<ResourceDescri
JMSConnectionFactoryDefinitionNode jmsConnectionFactoryDefinitionNode = new JMSConnectionFactoryDefinitionNode();
JMSDestinationDefinitionNode jmsDestinationDefinitionNode = new JMSDestinationDefinitionNode();

for (; descriptorIterator.hasNext();) {
while (descriptorIterator.hasNext()) {
ResourceDescriptor descriptor = descriptorIterator.next();

if (descriptor.getResourceType().equals(JavaEEResourceType.DSD)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@
public class AppClientNode extends AbstractBundleNode<ApplicationClientDescriptor> {

//app client 1.2
public final static String PUBLIC_DTD_ID_12 = "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN";
public final static String SYSTEM_ID_12 = "http://java.sun.com/dtd/application-client_1_2.dtd";
private static final String PUBLIC_DTD_ID_12 = "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN";
private static final String SYSTEM_ID_12 = "http://java.sun.com/dtd/application-client_1_2.dtd";

//app client 1.3
public final static String PUBLIC_DTD_ID = "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN";
public final static String SYSTEM_ID = "http://java.sun.com/dtd/application-client_1_3.dtd";
private static final String PUBLIC_DTD_ID = "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN";
private static final String SYSTEM_ID = "http://java.sun.com/dtd/application-client_1_3.dtd";

public final static String SCHEMA_ID_14 = "application-client_1_4.xsd";
private static final String SCHEMA_ID_14 = "application-client_1_4.xsd";

public final static String SCHEMA_ID_15 = "application-client_5.xsd";
public final static String SCHEMA_ID_16 = "application-client_6.xsd";
public final static String SCHEMA_ID_17 = "application-client_7.xsd";
public final static String SCHEMA_ID_18 = "application-client_8.xsd";
public final static String SCHEMA_ID = "application-client_9.xsd";
public final static String SPEC_VERSION = "9";
private static final String SCHEMA_ID_15 = "application-client_5.xsd";
private static final String SCHEMA_ID_16 = "application-client_6.xsd";
private static final String SCHEMA_ID_17 = "application-client_7.xsd";
private static final String SCHEMA_ID_18 = "application-client_8.xsd";
private static final String SCHEMA_ID = "application-client_9.xsd";
public static final String SPEC_VERSION = "9";
private final static List<String> systemIDs = initSystemIDs();

public final static XMLElement tag = new XMLElement(ApplicationClientTagNames.APPLICATION_CLIENT_TAG);
private static final XMLElement tag = new XMLElement(ApplicationClientTagNames.APPLICATION_CLIENT_TAG);

private static List<String> initSystemIDs() {
final ArrayList<String> systemIDs = new ArrayList<>();
Expand All @@ -96,8 +96,7 @@ private static List<String> initSystemIDs() {


public AppClientNode() {
registerElementHandler(new XMLElement(TagNames.ENVIRONMENT_PROPERTY), EnvEntryNode.class,
"addEnvironmentProperty");
registerElementHandler(new XMLElement(TagNames.ENVIRONMENT_PROPERTY), EnvEntryNode.class, "addEnvironmentProperty");
registerElementHandler(new XMLElement(TagNames.EJB_REFERENCE), EjbReferenceNode.class);
registerElementHandler(new XMLElement(TagNames.EJB_LOCAL_REFERENCE), EjbLocalReferenceNode.class);
JndiEnvRefNode<?> serviceRefNode = serviceLocator.getService(JndiEnvRefNode.class, WebServicesTagNames.SERVICE_REF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,21 @@ public class ActivationSpecNode extends DeploymentDescriptorNode<MessageListener

private MessageListener msgListener;

public static Node writeMessageListener(Node parent, MessageListener msgListener) {
Node actSpecNode = appendChild(parent, ConnectorTagNames.ACTIVATION_SPEC);
appendTextChild(actSpecNode, ConnectorTagNames.ACTIVATION_SPEC_CLASS, msgListener.getActivationSpecClass());
RequiredConfigNode.write(actSpecNode, msgListener);
ConfigPropertyNode.write(actSpecNode, msgListener);
return parent;
}


public ActivationSpecNode() {
registerElementHandler(new XMLElement(ConnectorTagNames.REQUIRED_CONFIG_PROP), RequiredConfigNode.class);
registerElementHandler(new XMLElement(ConnectorTagNames.CONFIG_PROPERTY), ConfigPropertyNode.class);
}

/**
* all sub-implementation of this class can use a dispatch table to map xml element to
* method name on the descriptor class for setting the element value.
*
* @return the map with the element name as a key, the setter method as a value
*/
@Override
protected Map<String, String> getDispatchTable() {
Map<String, String> table = super.getDispatchTable();
table.put(ConnectorTagNames.ACTIVATION_SPEC_CLASS, "setActivationSpecClass");
return table;
}

/**
* @return the descriptor instance to associate with this XMLNode
*/
@Override
public MessageListener getDescriptor() {
if (msgListener == null) {
Expand All @@ -66,12 +60,7 @@ public MessageListener getDescriptor() {
return msgListener;
}

/**
* Adds a new DOL descriptor instance to the descriptor instance associated with
* this XMLNode
*
* @param descriptor the new descriptor
*/

@Override
public void addDescriptor(Object descriptor) {
if (descriptor instanceof ConnectorConfigProperty) {
Expand All @@ -83,11 +72,9 @@ public void addDescriptor(Object descriptor) {


@Override
public Node writeDescriptor(Node parent, MessageListener msgListener) {
Node actSpecNode = appendChild(parent, ConnectorTagNames.ACTIVATION_SPEC);
appendTextChild(actSpecNode, ConnectorTagNames.ACTIVATION_SPEC_CLASS, msgListener.getActivationSpecClass());
RequiredConfigNode.write(actSpecNode, msgListener);
ConfigPropertyNode.write(actSpecNode, msgListener);
return parent;
protected Map<String, String> getDispatchTable() {
Map<String, String> table = super.getDispatchTable();
table.put(ConnectorTagNames.ACTIVATION_SPEC_CLASS, "setActivationSpecClass");
return table;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

import com.sun.enterprise.deployment.AdminObject;
import com.sun.enterprise.deployment.ConnectorConfigProperty;
import com.sun.enterprise.deployment.ConnectorDescriptor;
import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
import com.sun.enterprise.deployment.node.DescriptorFactory;
import com.sun.enterprise.deployment.node.XMLElement;
import com.sun.enterprise.deployment.xml.ConnectorTagNames;
import org.glassfish.deployment.common.Descriptor;

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

import org.w3c.dom.Node;

Expand All @@ -40,47 +38,22 @@ public class AdminObjectNode extends DeploymentDescriptorNode<AdminObject> {

private AdminObject adminObject;

public AdminObjectNode() {
register();
public static Node writeAdminObjects(Node parent, Set<AdminObject> adminObjects) {
for (AdminObject element : adminObjects) {
Node adminObjectNode = appendChild(parent, ConnectorTagNames.ADMIN_OBJECT);
appendTextChild(adminObjectNode, ConnectorTagNames.ADMIN_OBJECT_INTERFACE, element.getAdminObjectInterface());
appendTextChild(adminObjectNode, ConnectorTagNames.ADMIN_OBJECT_CLASS, element.getAdminObjectClass());
ConfigPropertyNode.write(adminObjectNode, element);
}
return parent;
}

/**
* method for registering the handlers with the various tags
*/
private void register() {
registerElementHandler(new XMLElement(ConnectorTagNames.CONFIG_PROPERTY), ConfigPropertyNode.class);
}

/**
* all sub-implementation of this class can use a dispatch table to map xml element to
* method name on the descriptor class for setting the element value.
*
* @return the map with the element name as a key, the setter method as a value
*/
@Override
protected Map<String, String> getDispatchTable() {
Map<String, String> table = super.getDispatchTable();
table.put(ConnectorTagNames.ADMIN_OBJECT_INTERFACE, "setAdminObjectInterface");
table.put(ConnectorTagNames.ADMIN_OBJECT_CLASS, "setAdminObjectClass");
return table;
public AdminObjectNode() {
registerElementHandler(new XMLElement(ConnectorTagNames.CONFIG_PROPERTY), ConfigPropertyNode.class);
}

/**
* Adds a new DOL descriptor instance to the descriptor instance associated with
* this XMLNode
*
* @param descriptor the new descriptor
*/
@Override
public void addDescriptor(Object descriptor) {
if (descriptor instanceof ConnectorConfigProperty) {
adminObject.addConfigProperty((ConnectorConfigProperty)descriptor);
}
}

/**
* @return the descriptor instance to associate with this XMLNode
*/
@Override
public AdminObject getDescriptor() {
if (adminObject == null) {
Expand All @@ -89,28 +62,20 @@ public AdminObject getDescriptor() {
return adminObject;
}

/**
* write the descriptor class to a DOM tree and return it
*
* @param parent node for the DOM tree
* @param descriptor to write
* @return the DOM tree top node
*/
public Node writeDescriptor(Node parent, Descriptor descriptor) {
if (!(descriptor instanceof ConnectorDescriptor)) {
throw new IllegalArgumentException(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
}

//adminObject info
for (Iterator adminObjects = ((ConnectorDescriptor)descriptor).getAdminObjects().iterator(); adminObjects.hasNext();) {
AdminObject adminObject = (AdminObject) adminObjects.next();
Node adminObjectNode = appendChild(parent, ConnectorTagNames.ADMIN_OBJECT);
appendTextChild(adminObjectNode, ConnectorTagNames.ADMIN_OBJECT_INTERFACE, adminObject.getAdminObjectInterface());
appendTextChild(adminObjectNode, ConnectorTagNames.ADMIN_OBJECT_CLASS, adminObject.getAdminObjectClass());

ConfigPropertyNode.write(adminObjectNode, element);
@Override
public void addDescriptor(Object descriptor) {
if (descriptor instanceof ConnectorConfigProperty) {
adminObject.addConfigProperty((ConnectorConfigProperty) descriptor);
}
}

return parent;

@Override
protected Map<String, String> getDispatchTable() {
Map<String, String> table = super.getDispatchTable();
table.put(ConnectorTagNames.ADMIN_OBJECT_INTERFACE, "setAdminObjectInterface");
table.put(ConnectorTagNames.ADMIN_OBJECT_CLASS, "setAdminObjectClass");
return table;
}
}

0 comments on commit d3071b5

Please sign in to comment.