Skip to content

Commit

Permalink
ResourcePropertyNode,writeDescriptor renamed to write and made static
Browse files Browse the repository at this point in the history
- it did not use any instance's methods nor attributes
- writeDescriptor must accept just T as it is designed

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Sep 18, 2022
1 parent 25cd3bf commit 88292e8
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 229 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -20,29 +21,44 @@
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.deployment.xml.TagNames;

import org.glassfish.logging.annotation.LogMessageInfo;
import org.w3c.dom.Node;

import java.util.Map;
import java.util.logging.Level;

import org.glassfish.logging.annotation.LogMessageInfo;
import org.w3c.dom.Node;

/**
* This class handles all information related to the administered-object xml tag
*
* @author Dapeng Hu
* @version
* @author Dapeng Hu
*/

public class AdministeredObjectDefinitionNode extends DeploymentDescriptorNode<AdministeredObjectDefinitionDescriptor> {
public final static XMLElement tag = new XMLElement(TagNames.ADMINISTERED_OBJECT);

private AdministeredObjectDefinitionDescriptor descriptor = null;
@LogMessageInfo(
message = "For administered-object resource: {0}, there is no application part in its resource adapter name: {1}.",
level = "WARNING",
cause = "For embedded resource adapter, its internal format of resource adapter name should contains application name.",
comment = "For the method writeDescriptor of com.sun.enterprise.deployment.node.AdministeredObjectDefinitionNode.")
private static final String RESOURCE_ADAPTER_NAME_INVALID = "AS-DEPLOYMENT-00022";

private AdministeredObjectDefinitionDescriptor descriptor;

public AdministeredObjectDefinitionNode() {
registerElementHandler(new XMLElement(TagNames.ADMINISTERED_OBJECT_PROPERTY), ResourcePropertyNode.class,
"addAdministeredObjectPropertyDescriptor");
"addAdministeredObjectPropertyDescriptor");
}


@Override
public AdministeredObjectDefinitionDescriptor getDescriptor() {
if (descriptor == null) {
descriptor = new AdministeredObjectDefinitionDescriptor();
}
return descriptor;
}


@Override
protected Map<String, String> getDispatchTable() {
// no need to be synchronized for now
Map<String, String> table = super.getDispatchTable();
Expand All @@ -54,14 +70,8 @@ protected Map<String, String> getDispatchTable() {
return table;
}

@LogMessageInfo(
message = "For administered-object resource: {0}, there is no application part in its resource adapter name: {1}.",
level="WARNING",
cause = "For embedded resource adapter, its internal format of resource adapter name should contains application name.",
comment = "For the method writeDescriptor of com.sun.enterprise.deployment.node.AdministeredObjectDefinitionNode."
)
private static final String RESOURCE_ADAPTER_NAME_INVALID = "AS-DEPLOYMENT-00022";

@Override
public Node writeDescriptor(Node parent, String nodeName, AdministeredObjectDefinitionDescriptor desc) {
Node node = appendChild(parent, nodeName);
appendTextChild(node, TagNames.ADMINISTERED_OBJECT_DESCRIPTION, desc.getDescription());
Expand All @@ -72,30 +82,20 @@ public Node writeDescriptor(Node parent, String nodeName, AdministeredObjectDefi
// change the resource adapter name from internal format to standard format
String resourceAdapterName = desc.getResourceAdapter();
int poundIndex = resourceAdapterName.indexOf("#");
if(poundIndex > 0){
// the internal format of resource adapter name is "appName#raName", remove the appName part
resourceAdapterName = resourceAdapterName.substring(poundIndex);
if (poundIndex > 0) {
// the internal format of resource adapter name is "appName#raName", remove the appName
// part
resourceAdapterName = resourceAdapterName.substring(poundIndex);

}else if(poundIndex == 0){
} else if (poundIndex == 0) {
// the resource adapter name should not be the standard format "#raName" here
DOLUtils.getDefaultLogger().log(Level.WARNING, RESOURCE_ADAPTER_NAME_INVALID,
new Object[] { desc.getName(), desc.getResourceAdapter() });
}else{
new Object[] {desc.getName(), desc.getResourceAdapter()});
} else {
// the resource adapter name represent the standalone RA in this case.
}
appendTextChild(node, TagNames.ADMINISTERED_OBJECT_ADAPTER, resourceAdapterName);

ResourcePropertyNode propertyNode = new ResourcePropertyNode();
propertyNode.writeDescriptor(node, desc);

return node;
return ResourcePropertyNode.write(node, desc);
}

public AdministeredObjectDefinitionDescriptor getDescriptor() {
if(descriptor == null){
descriptor = new AdministeredObjectDefinitionDescriptor();
}
return descriptor;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private final static List<String> initSystemIDs() {
* @return the doctype tag name
*/
@Override
public String registerBundle(Map publicIDToDTD) {
public String registerBundle(Map<String, String> publicIDToDTD) {
publicIDToDTD.put(PUBLIC_DTD_ID, SYSTEM_ID);
publicIDToDTD.put(PUBLIC_DTD_ID_12, SYSTEM_ID_12);
return tag.getQName();
Expand All @@ -113,7 +113,7 @@ public String registerBundle(Map publicIDToDTD) {
public Map<String, Class<?>> registerRuntimeBundle(final Map<String, String> publicIDToDTD,
Map<String, List<Class<?>>> versionUpgrades) {
final Map<String, Class<?>> result = new HashMap<>();
for (ConfigurationDeploymentDescriptorFile confDD : DOLUtils
for (ConfigurationDeploymentDescriptorFile<?> confDD : DOLUtils
.getConfigurationDeploymentDescriptorFiles(serviceLocator, EarType.ARCHIVE_TYPE)) {
confDD.registerBundle(result, publicIDToDTD, versionUpgrades);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -20,22 +21,39 @@
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.deployment.xml.TagNames;

import org.glassfish.logging.annotation.LogMessageInfo;
import org.w3c.dom.Node;

import java.util.Map;
import java.util.logging.Level;

import org.glassfish.logging.annotation.LogMessageInfo;
import org.w3c.dom.Node;

public class ConnectionFactoryDefinitionNode extends DeploymentDescriptorNode<ConnectionFactoryDefinitionDescriptor> {
public final static XMLElement tag = new XMLElement(TagNames.CONNECTION_FACTORY);

private ConnectionFactoryDefinitionDescriptor descriptor = null;
@LogMessageInfo(
message = "For connection-factory resource: {0}, there is no application part in its resource adapter name: {1}.",
level = "WARNING",
cause = "For embedded resource adapter, its internal format of resource adapter name should contains application name.",
comment = "For the method writeDescriptor of com.sun.enterprise.deployment.node.ConnectionFactoryDefinitionNode.")
private static final String RESOURCE_ADAPTER_NAME_INVALID = "AS-DEPLOYMENT-00023";

private ConnectionFactoryDefinitionDescriptor descriptor;

public ConnectionFactoryDefinitionNode() {
registerElementHandler(new XMLElement(TagNames.RESOURCE_PROPERTY), ResourcePropertyNode.class,
"addConnectionFactoryPropertyDescriptor");
"addConnectionFactoryPropertyDescriptor");
}


@Override
public ConnectionFactoryDefinitionDescriptor getDescriptor() {
if (descriptor == null) {
descriptor = new ConnectionFactoryDefinitionDescriptor();
}
return descriptor;
}


@Override
protected Map<String, String> getDispatchTable() {
// no need to be synchronized for now
Map<String, String> table = super.getDispatchTable();
Expand All @@ -49,14 +67,8 @@ protected Map<String, String> getDispatchTable() {
return table;
}

@LogMessageInfo(
message = "For connection-factory resource: {0}, there is no application part in its resource adapter name: {1}.",
level="WARNING",
cause = "For embedded resource adapter, its internal format of resource adapter name should contains application name.",
comment = "For the method writeDescriptor of com.sun.enterprise.deployment.node.ConnectionFactoryDefinitionNode."
)
private static final String RESOURCE_ADAPTER_NAME_INVALID = "AS-DEPLOYMENT-00023";

@Override
public Node writeDescriptor(Node parent, String nodeName, ConnectionFactoryDefinitionDescriptor desc) {
Node node = appendChild(parent, nodeName);
appendTextChild(node, TagNames.CONNECTION_FACTORY_DESCRIPTION, desc.getDescription());
Expand All @@ -66,15 +78,16 @@ public Node writeDescriptor(Node parent, String nodeName, ConnectionFactoryDefin
// change the resource adapter name from internal format to standard format
String resourceAdapterName = desc.getResourceAdapter();
int poundIndex = resourceAdapterName.indexOf("#");
if(poundIndex > 0){
// the internal format of resource adapter name is "appName#raName", remove the appName part
resourceAdapterName = resourceAdapterName.substring(poundIndex);
if (poundIndex > 0) {
// the internal format of resource adapter name is "appName#raName", remove the appName
// part
resourceAdapterName = resourceAdapterName.substring(poundIndex);

}else if(poundIndex == 0){
} else if (poundIndex == 0) {
// the resource adapter name should not be the standard format "#raName" here
DOLUtils.getDefaultLogger().log(Level.WARNING, RESOURCE_ADAPTER_NAME_INVALID,
new Object[] { desc.getName(), desc.getResourceAdapter() });
}else{
new Object[] {desc.getName(), desc.getResourceAdapter()});
} else {
// the resource adapter name represent the standalone RA in this case.
}
appendTextChild(node, TagNames.CONNECTION_FACTORY_ADAPTER, resourceAdapterName);
Expand All @@ -83,17 +96,6 @@ public Node writeDescriptor(Node parent, String nodeName, ConnectionFactoryDefin
appendTextChild(node, TagNames.CONNECTION_FACTORY_MIN_POOL_SIZE, desc.getMinPoolSize());
appendTextChild(node, TagNames.CONNECTION_FACTORY_TRANSACTION_SUPPORT, desc.getTransactionSupport());

ResourcePropertyNode propertyNode = new ResourcePropertyNode();
propertyNode.writeDescriptor(node, desc);

return node;
return ResourcePropertyNode.write(node, desc);
}

public ConnectionFactoryDefinitionDescriptor getDescriptor() {
if(descriptor == null){
descriptor = new ConnectionFactoryDefinitionDescriptor();
}
return descriptor;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -13,43 +14,43 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.enterprise.deployment.node;

import static com.sun.enterprise.deployment.xml.TagNames.RESOURCE_PROPERTY;
package com.sun.enterprise.deployment.node;

import java.util.Map;

import org.omnifaces.concurrent.deployment.ContextServiceDefinitionDescriptor;
import org.omnifaces.concurrent.node.ContextServiceDefinitionNodeDelegate;
import org.w3c.dom.Node;

import static com.sun.enterprise.deployment.xml.TagNames.RESOURCE_PROPERTY;

public class ContextServiceDefinitionNode extends DeploymentDescriptorNode<ContextServiceDefinitionDescriptor> {
public final static XMLElement tag = new XMLElement(ContextServiceDefinitionNodeDelegate.getQname());

ContextServiceDefinitionNodeDelegate delegate = new ContextServiceDefinitionNodeDelegate();
private final ContextServiceDefinitionNodeDelegate delegate = new ContextServiceDefinitionNodeDelegate();

public ContextServiceDefinitionNode() {
registerElementHandler(
new XMLElement(RESOURCE_PROPERTY),
ResourcePropertyNode.class,
registerElementHandler(new XMLElement(RESOURCE_PROPERTY), ResourcePropertyNode.class,
delegate.getHandlerAdMethodName());
}


@Override
protected Map<String, String> getDispatchTable() {
return delegate.getDispatchTable(super.getDispatchTable());
public ContextServiceDefinitionDescriptor getDescriptor() {
return delegate.getDescriptor();
}

@Override
public Node writeDescriptor(Node parent, String nodeName, ContextServiceDefinitionDescriptor contextServiceDefinitionDescriptor) {
Node node = delegate.getDescriptor(parent, nodeName, contextServiceDefinitionDescriptor);
new ResourcePropertyNode().writeDescriptor(node, contextServiceDefinitionDescriptor);

return node;
@Override
protected Map<String, String> getDispatchTable() {
return delegate.getDispatchTable(super.getDispatchTable());
}


@Override
public ContextServiceDefinitionDescriptor getDescriptor() {
return delegate.getDescriptor();
public Node writeDescriptor(Node parent, String nodeName,
ContextServiceDefinitionDescriptor contextServiceDefinitionDescriptor) {
Node node = delegate.getDescriptor(parent, nodeName, contextServiceDefinitionDescriptor);
return ResourcePropertyNode.write(node, contextServiceDefinitionDescriptor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@

package com.sun.enterprise.deployment.node;

import org.w3c.dom.Node;

import com.sun.enterprise.deployment.xml.TagNames;
import com.sun.enterprise.deployment.DataSourceDefinitionDescriptor;
import com.sun.enterprise.deployment.xml.TagNames;

import java.util.Map;

import org.w3c.dom.Node;

public class DataSourceDefinitionNode extends DeploymentDescriptorNode<DataSourceDefinitionDescriptor> {

public final static XMLElement tag = new XMLElement(TagNames.DATA_SOURCE);
private DataSourceDefinitionDescriptor descriptor;

public DataSourceDefinitionNode() {
Expand All @@ -35,6 +34,15 @@ public DataSourceDefinitionNode() {
}


@Override
public DataSourceDefinitionDescriptor getDescriptor() {
if (descriptor == null) {
descriptor = new DataSourceDefinitionDescriptor();
}
return descriptor;
}


@Override
protected Map<String, String> getDispatchTable() {
// no need to be synchronized for now
Expand Down Expand Up @@ -65,7 +73,6 @@ protected Map<String, String> getDispatchTable() {

@Override
public Node writeDescriptor(Node parent, String nodeName, DataSourceDefinitionDescriptor dataSourceDesc) {

Node node = appendChild(parent, nodeName);
appendTextChild(node, TagNames.DATA_SOURCE_DESCRIPTION, dataSourceDesc.getDescription());
appendTextChild(node, TagNames.DATA_SOURCE_NAME, dataSourceDesc.getName());
Expand All @@ -77,15 +84,14 @@ public Node writeDescriptor(Node parent, String nodeName, DataSourceDefinitionDe
appendTextChild(node, TagNames.DATA_SOURCE_USER, dataSourceDesc.getUser());
appendTextChild(node, TagNames.DATA_SOURCE_PASSWORD, dataSourceDesc.getPassword());

ResourcePropertyNode propertyNode = new ResourcePropertyNode();
propertyNode.writeDescriptor(node, dataSourceDesc);
ResourcePropertyNode.write(node, dataSourceDesc);

appendTextChild(node, TagNames.DATA_SOURCE_LOGIN_TIMEOUT, String.valueOf(dataSourceDesc.getLoginTimeout()));
appendTextChild(node, TagNames.DATA_SOURCE_TRANSACTIONAL, String.valueOf(dataSourceDesc.isTransactional()));
//DD specified Enumeration values are String
//Annotation uses integer values and hence this mapping is needed
// DD specified Enumeration values are String
// Annotation uses integer values and hence this mapping is needed
String isolationLevelString = dataSourceDesc.getIsolationLevelString();
if(isolationLevelString != null){
if (isolationLevelString != null) {
appendTextChild(node, TagNames.DATA_SOURCE_ISOLATION_LEVEL, isolationLevelString);
}
appendTextChild(node, TagNames.DATA_SOURCE_INITIAL_POOL_SIZE, dataSourceDesc.getInitialPoolSize());
Expand All @@ -96,13 +102,4 @@ public Node writeDescriptor(Node parent, String nodeName, DataSourceDefinitionDe

return node;
}


@Override
public DataSourceDefinitionDescriptor getDescriptor() {
if(descriptor == null){
descriptor = new DataSourceDefinitionDescriptor();
}
return descriptor;
}
}

0 comments on commit 88292e8

Please sign in to comment.