diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ApiFluentTest.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ApiFluentTest.java new file mode 100644 index 00000000..3057f01e --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ApiFluentTest.java @@ -0,0 +1,16 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +public class ApiFluentTest { + + public void checkAPI() { + Factory factory = null; + ConnectorDescriptor descr = null; + +// +// descr.setIcon(factory.Icon().largeIcon("").smallIcon("")) +// .setLicense(factory.License().description("").licenseRequired("true")) +// .setResourceadapter(factory.Resourceadapter().addAuthenticationMechanism( +// factory.AuthenticationMechanism().credentialInterface("").description(""))); + + } +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/AuthenticationMechanism.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/AuthenticationMechanism.java new file mode 100644 index 00000000..fdbf0a8e --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/AuthenticationMechanism.java @@ -0,0 +1,21 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +/** + * This interface defines the contract for the authentication-mechanism xsd type + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public interface AuthenticationMechanism { + + public AuthenticationMechanism authenticationMechanismType(String authenticationMechanismType); + public String getAuthenticationMechanismType(); + public AuthenticationMechanism removeAuthenticationMechanismType(); + + public AuthenticationMechanism description(String description); + public String getDescription(); + public AuthenticationMechanism removeDescription(); + + public AuthenticationMechanism credentialInterface(String credentialInterface); + public String getCredentialInterface(); + public AuthenticationMechanism removeCredentialInterface(); +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ConfigProperty.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ConfigProperty.java new file mode 100644 index 00000000..c4deeece --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ConfigProperty.java @@ -0,0 +1,27 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +/** + * This interface defines the contract for the config-property xsd type + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public interface ConfigProperty { + + public ConfigProperty configPropertyValue(String configPropertyValue); + public String getConfigPropertyValue(); + public ConfigProperty removeConfigPropertyValue(); + + public ConfigProperty description(String description); + public String getDescription(); + public ConfigProperty removeDescription(); + + + public ConfigProperty configPropertyName(String configPropertyName); + public String getConfigPropertyName(); + public ConfigProperty removeConfigPropertyName(); + + + public ConfigProperty configPropertyType(String configPropertyType); + public String getConfigPropertyType(); + public ConfigProperty removeConfigPropertyType(); +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ConnectorDescriptor.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ConnectorDescriptor.java new file mode 100644 index 00000000..f2db5523 --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/ConnectorDescriptor.java @@ -0,0 +1,45 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +import org.jboss.shrinkwrap.descriptor.api.Descriptor; +import org.jboss.shrinkwrap.descriptor.api.DescriptorNamespace; + +public interface ConnectorDescriptor extends Descriptor, DescriptorNamespace { + +// public ConnectorDescriptor specVersion(String specVersion); +// public String getSpecVersion(); +// public ConnectorDescriptor removeSpecVersion(); +// +// public ConnectorDescriptor setIcon(final Icon icon); +// public Icon getIcon(); +// public ConnectorDescriptor removeIcon(); + +// public ConnectorDescriptor displayName(String displayName); +// public String getDisplayName(); +// public ConnectorDescriptor removeDisplayName(); +// +// public ConnectorDescriptor vendorName(String vendorName); +// public String getVendorName(); +// public ConnectorDescriptor removeVendorName(); + + public Factory getFactory(); + + public ConnectorDescriptor description(String description); + public String getDescription(); + public ConnectorDescriptor removeDescription(); + +// public ConnectorDescriptor eisType(String eisType); +// public String getEisType(); +// public ConnectorDescriptor removeEisType(); +// +// public ConnectorDescriptor setLicense(final License license); +// public License getLicence(); +// public ConnectorDescriptor removeLicense(); + + public ConnectorDescriptor setResourceadapter(final Resourceadapter resourceadapter); + public Resourceadapter getResourceadapter(); + public ConnectorDescriptor removeResourceadapter(); + +// public ConnectorDescriptor version(String version); +// public String getVersion(); +// public ConnectorDescriptor removeVersion(); +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Factory.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Factory.java new file mode 100644 index 00000000..1f4943e8 --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Factory.java @@ -0,0 +1,11 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +public interface Factory { + +// public AuthenticationMechanism AuthenticationMechanism(); + public ConfigProperty configProperty(); +// public Icon Icon(); +// public License License(); + public Resourceadapter resourceadapter(); +// public SecurityPermission SecurityPermission(); +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Icon.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Icon.java new file mode 100644 index 00000000..67ace625 --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Icon.java @@ -0,0 +1,18 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +/** + * This interface defines the contract for the icon xsd type + * + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public interface Icon { + + public Icon smallIcon(String smallIcon); + public String getSmallIcon(); + public Icon removeSmallIcon(); + + public Icon largeIcon(String largeIcon); + public String getLargeIcon(); + public Icon removeLargeIcon(); +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/License.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/License.java new file mode 100644 index 00000000..23df90ae --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/License.java @@ -0,0 +1,17 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +/** + * This interface defines the contract for the license xsd type + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public interface License { + + public License description(String description); + public String getDescription(); + public License removeDescription(); + + public License licenseRequired(String licenseRequired); + public String getLicenseRequired(); + public License removeLicenseRequired(); +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Resourceadapter.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Resourceadapter.java new file mode 100644 index 00000000..b94add3b --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/Resourceadapter.java @@ -0,0 +1,54 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +import java.util.List; + +/** + * This interface defines the contract for the resourceadapter + * xsd type + * + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public interface Resourceadapter { + + public Resourceadapter connectionInterface(String connectionInterface); + public String getConnectionInterface(); + public Resourceadapter removeConnectionInterface(); + + public Resourceadapter addConfigProperty(final ConfigProperty configProperty); + public List getAllConfigProperty(); + public Resourceadapter removeAllConfigProperty(); + + public Resourceadapter connectionImplClass(String connectionImplClass); + public String getConnectionImplClass(); + public Resourceadapter removeConnectionImplClass(); + + public Resourceadapter connectionfactoryInterface(String connectionfactoryInterface); + public String getConnectionfactoryInterface(); + public Resourceadapter removeConnectionfactoryInterface(); + + public Resourceadapter reauthenticationSupport(String reauthenticationSupport); + public String getReauthenticationSupport(); + public Resourceadapter removeReauthenticationSupport(); + +// +// public Resourceadapter addAuthenticationMechanism(final AuthenticationMechanism authenticationMechanism); +// public List getAllAuthenticationMechanism(); +// public Resourceadapter removeAllAuthenticationMechanism(); + + public Resourceadapter managedconnectionfactoryClass(String managedconnectionfactoryClass); + public String getManagedconnectionfactoryClass(); + public Resourceadapter removeManagedconnectionfactoryClass(); + + public Resourceadapter connectionfactoryImplClass(String connectionfactoryImplClass); + public String getConnectionfactoryImplClass(); + public Resourceadapter removeConnectionfactoryImplClass(); + + public Resourceadapter transactionSupport(String transactionSupport); + public String getTransactionSupport(); + public Resourceadapter removeTransactionSupport(); +// +// public Resourceadapter addSecurityPermission(final SecurityPermission securityPermission); +// public List getAllSecurityPermission(); +// public Resourceadapter removeAllSecurityPermission(); +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/SecurityPermission.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/SecurityPermission.java new file mode 100644 index 00000000..8aa6ab1e --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/SecurityPermission.java @@ -0,0 +1,17 @@ +package org.jboss.shrinkwrap.descriptor.api.connector10; + +/** + * This interface defines the contract for the security-permission xsd type + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public interface SecurityPermission { + + public SecurityPermission securityPermissionSpec(String securityPermissionSpec); + public String getSecurityPermissionSpec(); + public SecurityPermission removeSecurityPermissionSpec(); + + public SecurityPermission description(String description); + public String getDescription(); + public SecurityPermission removeDescription(); +} diff --git a/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/package-info.java b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/package-info.java new file mode 100644 index 00000000..e272bab7 --- /dev/null +++ b/api-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/api/connector10/package-info.java @@ -0,0 +1,5 @@ + /** + * Provides the interfaces and enumeration types as defined in the schema + */ + +package org.jboss.shrinkwrap.descriptor.api.connector10; diff --git a/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ChildNodeInitializer.java b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ChildNodeInitializer.java new file mode 100644 index 00000000..69d65743 --- /dev/null +++ b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ChildNodeInitializer.java @@ -0,0 +1,10 @@ +package org.jboss.shrinkwrap.descriptor.impl.connector10; + +import org.jboss.shrinkwrap.descriptor.spi.node.Node; + +public interface ChildNodeInitializer { + + public void initialize(String nodeName, Node node); + + public void assign(String nodeName, Node node); +} diff --git a/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ConfigPropertyImpl.java b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ConfigPropertyImpl.java new file mode 100644 index 00000000..829cd1ec --- /dev/null +++ b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ConfigPropertyImpl.java @@ -0,0 +1,175 @@ +package org.jboss.shrinkwrap.descriptor.impl.connector10; + +import org.jboss.shrinkwrap.descriptor.api.connector10.ConfigProperty; +import org.jboss.shrinkwrap.descriptor.spi.node.Node; + +/** + * This class implements the config-property xsd type + * + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public class ConfigPropertyImpl implements ConfigProperty, ChildNodeInitializer { + private boolean isDetached = true; + private Node detachedNode; + private Node childNode; + + public void initialize(String nodeName, Node node) { + if (isDetached) { + if (detachedNode != null) { + childNode = node.createChild(nodeName); + Node.copyFromTo(detachedNode, childNode); // setters already called + } else { + childNode = node.createChild(nodeName); // just created no setters called + } + isDetached = false; + } else { + throw new IllegalArgumentException(); + } + } + + public void assign(String nodeName, Node node) { + childNode = node; + isDetached = false; + } + + + /** + * Sets the config-property-value element + * + * @param configPropertyValue + * the value for the element config-property-value + * @return the current instance of ConfigProperty + */ + public ConfigProperty configPropertyValue(String configPropertyValue) { + getNode().getOrCreate("config-property-value").text(configPropertyValue); + return this; + } + + /** + * Returns the config-property-value element + * + * @return the node defined for the element + * config-property-value + */ + public String getConfigPropertyValue() { + return getNode().getTextValueForPatternName("config-property-value"); + } + + /** + * Removes the config-property-value element + * + * @return the current instance of ConfigProperty + */ + public ConfigProperty removeConfigPropertyValue() { + getNode().removeChildren("config-property-value"); + return this; + } + + /** + * Sets the description element + * + * @param description + * the value for the element description + * @return the current instance of ConfigProperty + */ + public ConfigProperty description(String description) { + getNode().getOrCreate("description").text(description); + return this; + } + + /** + * Returns the description element + * + * @return the node defined for the element description + */ + public String getDescription() { + return getNode().getTextValueForPatternName("description"); + } + + /** + * Removes the description element + * + * @return the current instance of ConfigProperty + */ + public ConfigProperty removeDescription() { + getNode().removeChildren("description"); + return this; + } + + /** + * Sets the config-property-name element + * + * @param configPropertyName + * the value for the element config-property-name + * @return the current instance of ConfigProperty + */ + public ConfigProperty configPropertyName(String configPropertyName) { + getNode().getOrCreate("config-property-name").text(configPropertyName); + return this; + } + + /** + * Returns the config-property-name element + * + * @return the node defined for the element + * config-property-name + */ + public String getConfigPropertyName() { + return getNode().getTextValueForPatternName("config-property-name"); + } + + /** + * Removes the config-property-name element + * + * @return the current instance of ConfigProperty + */ + public ConfigProperty removeConfigPropertyName() { + getNode().removeChildren("config-property-name"); + return this; + } + + /** + * Sets the config-property-type element + * + * @param configPropertyType + * the value for the element config-property-type + * @return the current instance of ConfigProperty + */ + public ConfigProperty configPropertyType(String configPropertyType) { + getNode().getOrCreate("config-property-type").text(configPropertyType); + return this; + } + + /** + * Returns the config-property-type element + * + * @return the node defined for the element + * config-property-type + */ + public String getConfigPropertyType() { + return getNode().getTextValueForPatternName("config-property-type"); + } + + /** + * Removes the config-property-type element + * + * @return the current instance of ConfigProperty + */ + public ConfigProperty removeConfigPropertyType() { + getNode().removeChildren("config-property-type"); + return this; + } + + private Node getNode() { + if (!isDetached) { + return childNode; + } + + if (detachedNode == null) { + detachedNode = new Node("DetachedNode"); + } + + return detachedNode; + } +} diff --git a/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ConnectorDescriptorImpl.java b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ConnectorDescriptorImpl.java new file mode 100644 index 00000000..7b1680cf --- /dev/null +++ b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ConnectorDescriptorImpl.java @@ -0,0 +1,168 @@ +package org.jboss.shrinkwrap.descriptor.impl.connector10; + +import java.util.ArrayList; +import java.util.List; + +import org.jboss.shrinkwrap.descriptor.api.DescriptorNamespace; +import org.jboss.shrinkwrap.descriptor.api.connector10.ConnectorDescriptor; +import org.jboss.shrinkwrap.descriptor.api.connector10.Factory; +import org.jboss.shrinkwrap.descriptor.api.connector10.Icon; +import org.jboss.shrinkwrap.descriptor.api.connector10.License; +import org.jboss.shrinkwrap.descriptor.api.connector10.Resourceadapter; +import org.jboss.shrinkwrap.descriptor.spi.node.Node; +import org.jboss.shrinkwrap.descriptor.spi.node.NodeDescriptorImplBase; + +/** + *

+ * This deployment descriptor provides the functionalities as described in the + * specification + *

+ * Example: + *

+ * + * ConnectorDescriptor descriptor = Descriptors.create(ConnectorDescriptor.class); + * + * + * + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public class ConnectorDescriptorImpl extends NodeDescriptorImplBase implements + DescriptorNamespace, ConnectorDescriptor { + // -------------------------------------------------------------------------------------|| + // Instance Members + // -------------------------------------------------------------------------------------|| + + private Node model; + + // -------------------------------------------------------------------------------------|| + // Constructor + // -------------------------------------------------------------------------------------|| + + public ConnectorDescriptorImpl(String descriptorName) { + this(descriptorName, new Node("connector")); + } + + public ConnectorDescriptorImpl(String descriptorName, Node node) { + super(descriptorName); + this.model = node; + addDefaultNamespaces(); + } + + // -------------------------------------------------------------------------------------|| + // Methods + // -------------------------------------------------------------------------------------|| + + public Node getRootNode() { + return model; + } + + // -------------------------------------------------------------------------------------|| + // Namespace + // -------------------------------------------------------------------------------------|| + + /** + * Adds the default namespaces as defined in the specification + * + * @return the current instance of ConnectorDescriptor + */ + public ConnectorDescriptor addDefaultNamespaces() { + return this; + } + + /** + * Adds a new namespace + * + * @return the current instance of ConnectorDescriptor + */ + public ConnectorDescriptor addNamespace(String name, String value) { + model.attribute(name, value); + return this; + } + + /** + * Returns all defined namespaces. + * + * @return all defined namespaces + */ + public List getNamespaces() { + List namespaceList = new ArrayList(); + java.util.Map attributes = model.getAttributes(); + for (String name : attributes.keySet()) { + String value = attributes.get(name); + if (value != null && value.startsWith("http://")) { + namespaceList.add(name + "=" + value); + } + } + return namespaceList; + } + + /** + * Removes all existing namespaces. + * + * @return the current instance of ConnectorDescriptor + */ + public ConnectorDescriptor removeAllNamespaces() { + List nameSpaceKeys = new ArrayList(); + java.util.Map attributes = model.getAttributes(); + for (String name : attributes.keySet()) { + String value = attributes.get(name); + if (value != null && value.startsWith("http://")) { + nameSpaceKeys.add(name); + } + } + for (String name : nameSpaceKeys) { + model.removeAttribute(name); + } + return this; + } + + @Override + public Factory getFactory() { + return new FactoryImpl(); + } + + @Override + public ConnectorDescriptor description(String description) { + model.getOrCreate("description").text(description); + return this; + } + + @Override + public String getDescription() { + return model.getTextValueForPatternName("description"); + } + + @Override + public ConnectorDescriptor removeDescription() { + model.removeChildren("description"); + return this; + } + + @Override + public ConnectorDescriptor setResourceadapter(Resourceadapter resourceadapter) { + if (resourceadapter instanceof ChildNodeInitializer) { + if (model.getSingle("resourceadapter") == null) { + ((ChildNodeInitializer)resourceadapter).initialize("resourceadapter", model); + } else { + throw new IllegalArgumentException("Single child already assigned"); + } + } + return this; + } + + @Override + public Resourceadapter getResourceadapter() { + final Node node = model.getSingle("resourceadapter"); + final ResourceadapterImpl resourceadapter = new ResourceadapterImpl(); + resourceadapter.assign("resourceadapter", node); + return resourceadapter; + } + + @Override + public ConnectorDescriptor removeResourceadapter() { + model.removeChildren("resourceadapter"); + return this; + } + +} diff --git a/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/FactoryImpl.java b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/FactoryImpl.java new file mode 100644 index 00000000..43d36f57 --- /dev/null +++ b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/FactoryImpl.java @@ -0,0 +1,18 @@ +package org.jboss.shrinkwrap.descriptor.impl.connector10; + +import org.jboss.shrinkwrap.descriptor.api.connector10.Factory; + +public class FactoryImpl implements Factory { + + + @Override + public org.jboss.shrinkwrap.descriptor.api.connector10.ConfigProperty configProperty() { + return new ConfigPropertyImpl(); + } + + @Override + public org.jboss.shrinkwrap.descriptor.api.connector10.Resourceadapter resourceadapter() { + return new ResourceadapterImpl(); + } + +} diff --git a/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ResourceadapterImpl.java b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ResourceadapterImpl.java new file mode 100644 index 00000000..cf9cd4f3 --- /dev/null +++ b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/ResourceadapterImpl.java @@ -0,0 +1,238 @@ +package org.jboss.shrinkwrap.descriptor.impl.connector10; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.jboss.shrinkwrap.descriptor.api.connector10.ConfigProperty; +import org.jboss.shrinkwrap.descriptor.api.connector10.Resourceadapter; +import org.jboss.shrinkwrap.descriptor.spi.node.Node; + +/** + * This class implements the resourceadapter xsd type + * + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public class ResourceadapterImpl implements Resourceadapter, ChildNodeInitializer { + private boolean isDetached = true; + private Node detachedNode; + private Node childNode; + + public void initialize(String nodeName, Node node) { + if (isDetached) { + if (detachedNode != null) { + childNode = node.createChild(nodeName); + Node.copyFromTo(detachedNode, childNode); // setters already called + } else { + childNode = node.createChild(nodeName); // just created no setters called + } + isDetached = false; + } else { + throw new IllegalArgumentException(); + } + } + + public void assign(String nodeName, Node node) { + childNode = node; + isDetached = false; + } + + /** + * Creates a new config-property element + * + * @return the new created instance of ConfigProperty + */ + public Resourceadapter addConfigProperty(ConfigProperty configProperty) { + if (configProperty instanceof ChildNodeInitializer) { + ((ChildNodeInitializer)configProperty).initialize("config-property", getNode()); + } + return this; + } + + /** + * Returns all config-property elements + * + * @return list of config-property + */ + public List getAllConfigProperty() { + List list = new ArrayList(); + List nodeList = childNode.get("config-property"); + for (Node node : nodeList) { + ConfigPropertyImpl type = new ConfigPropertyImpl(); + type.assign("config-property", getNode()); + list.add(type); + } + return list; + } + + /** + * Removes all config-property elements + * + * @return the current instance of ConfigProperty + */ + public Resourceadapter removeAllConfigProperty() { + getNode().removeChildren("config-property"); + return this; + } + + private Node getNode() { + if (!isDetached) { + return childNode; + } + + if (detachedNode == null) { + detachedNode = new Node("DetachedNode"); + } + + return detachedNode; + } + + //-----------------------------------------------------------------------|| + //-- TransactionSupport -------------------------------------------------|| + //-----------------------------------------------------------------------|| + + @Override + public Resourceadapter transactionSupport(String transactionSupport) { + childNode.getOrCreate("transaction-support").text(transactionSupport); + return this; + } + + @Override + public String getTransactionSupport() { + return childNode.getTextValueForPatternName("transaction-support"); + } + + @Override + public Resourceadapter removeTransactionSupport() { + childNode.removeChildren("transaction-support"); + return this; + } + + //-----------------------------------------------------------------------|| + //-- ConnectionFactory -------------------------------------------------|| + //-----------------------------------------------------------------------|| + + @Override + public Resourceadapter connectionfactoryImplClass(String connectionfactoryImplClass) { + childNode.getOrCreate("connectionfactory-impl-class").text(connectionfactoryImplClass); + return this; + } + + @Override + public String getConnectionfactoryImplClass() { + return childNode.getTextValueForPatternName("connectionfactory-impl-class"); + } + + @Override + public Resourceadapter removeConnectionfactoryImplClass() { + childNode.removeChildren("connectionfactory-impl-class"); + return this; + } + + //-----------------------------------------------------------------------|| + //-- ConnectionImplClass ------------------------------------------------|| + //-----------------------------------------------------------------------|| + + @Override + public Resourceadapter connectionImplClass(String connectionImplClass) { + childNode.getOrCreate("connection-impl-class").text(connectionImplClass); + return this; + } + + @Override + public String getConnectionImplClass() { + return childNode.getTextValueForPatternName("connection-impl-class"); + } + + @Override + public Resourceadapter removeConnectionImplClass() { + childNode.removeChildren("connection-impl-class"); + return this; + } + + //-----------------------------------------------------------------------|| + //-- ConnectionInterface ------------------------------------------------|| + //-----------------------------------------------------------------------|| + + @Override + public Resourceadapter connectionInterface(String connectionInterface) { + childNode.getOrCreate("connection-interface").text(connectionInterface); + return this; + } + + @Override + public String getConnectionInterface() { + return childNode.getTextValueForPatternName("connection-interface"); + } + + @Override + public Resourceadapter removeConnectionInterface() { + childNode.removeChildren("connection-interface"); + return this; + } + + //-----------------------------------------------------------------------|| + //-- ConnectionInterface ------------------------------------------------|| + //-----------------------------------------------------------------------|| + + @Override + public Resourceadapter connectionfactoryInterface(String connectionfactoryInterface) { + childNode.getOrCreate("connectionfactory-interface").text(connectionfactoryInterface); + return this; + } + + @Override + public String getConnectionfactoryInterface() { + return childNode.getTextValueForPatternName("connectionfactory-interface"); + } + + @Override + public Resourceadapter removeConnectionfactoryInterface() { + childNode.removeChildren("connectionfactory-interface"); + return this; + } + + //-----------------------------------------------------------------------|| + //-- ReauthenticationSupport --------------------------------------------|| + //-----------------------------------------------------------------------|| + + @Override + public Resourceadapter reauthenticationSupport(String reauthenticationSupport) { + childNode.getOrCreate("reauthentication-support").text(reauthenticationSupport); + return this; + } + + @Override + public String getReauthenticationSupport() { + return childNode.getTextValueForPatternName("reauthentication-support"); + } + + @Override + public Resourceadapter removeReauthenticationSupport() { + childNode.removeChildren("reauthentication-support"); + return this; + } + + //-----------------------------------------------------------------------|| + //-- ManagedconnectionfactoryClass --------------------------------------|| + //-----------------------------------------------------------------------|| + + @Override + public Resourceadapter managedconnectionfactoryClass(String managedconnectionfactoryClass) { + childNode.getOrCreate("managedconnectionfactory-class").text(managedconnectionfactoryClass); + return this; + } + + @Override + public String getManagedconnectionfactoryClass() { + return childNode.getTextValueForPatternName("managedconnectionfactory-class"); + } + + @Override + public Resourceadapter removeManagedconnectionfactoryClass() { + childNode.removeChildren("managedconnectionfactory-class"); + return this; + } +} diff --git a/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/decorators/ConcreteConfigPropertyImpl.java b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/decorators/ConcreteConfigPropertyImpl.java new file mode 100644 index 00000000..750b5202 --- /dev/null +++ b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/decorators/ConcreteConfigPropertyImpl.java @@ -0,0 +1,64 @@ +package org.jboss.shrinkwrap.descriptor.impl.connector10.decorators; + +import org.jboss.shrinkwrap.descriptor.api.connector10.ConfigProperty; + +/** + * This class implements the config-property xsd type + * + * @author Ralf Battenfeld + * @author Andrew Lee Rubinger + */ +public class ConcreteConfigPropertyImpl extends ConfigfPropertyDecorator { + + public ConcreteConfigPropertyImpl(ConfigProperty configProperty) { + super(configProperty); + } + + public ConfigProperty configPropertyValue(String configPropertyValue) { + return configProperty.configPropertyValue(configPropertyValue); + } + + public String getConfigPropertyValue() { + return configProperty.getConfigPropertyValue(); + } + + public ConfigProperty removeConfigPropertyValue() { + return configProperty.removeConfigPropertyValue(); + } + + public ConfigProperty description(String description) { + return configProperty.description(description); + } + + public String getDescription() { + return configProperty.getDescription(); + } + + public ConfigProperty removeDescription() { + return configProperty.removeDescription(); + } + + public ConfigProperty configPropertyName(String configPropertyName) { + return configProperty.configPropertyName(configPropertyName); + } + + public String getConfigPropertyName() { + return configProperty.getConfigPropertyName(); + } + + public ConfigProperty removeConfigPropertyName() { + return configProperty.removeConfigPropertyName(); + } + + public ConfigProperty configPropertyType(String configPropertyType) { + return configProperty.configPropertyType(configPropertyType); + } + + public String getConfigPropertyType() { + return configProperty.getConfigPropertyType(); + } + + public ConfigProperty removeConfigPropertyType() { + return configProperty.removeConfigPropertyType(); + } +} diff --git a/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/decorators/ConfigfPropertyDecorator.java b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/decorators/ConfigfPropertyDecorator.java new file mode 100644 index 00000000..0fece138 --- /dev/null +++ b/impl-javaee-prototype/src/main/java/org/jboss/shrinkwrap/descriptor/impl/connector10/decorators/ConfigfPropertyDecorator.java @@ -0,0 +1,23 @@ +package org.jboss.shrinkwrap.descriptor.impl.connector10.decorators; + +import org.jboss.shrinkwrap.descriptor.api.connector10.ConfigProperty; +import org.jboss.shrinkwrap.descriptor.impl.connector10.ChildNodeInitializer; +import org.jboss.shrinkwrap.descriptor.spi.node.Node; + + +public abstract class ConfigfPropertyDecorator implements ConfigProperty, ChildNodeInitializer { + protected ConfigProperty configProperty; + protected Node childNode; + + public ConfigfPropertyDecorator (ConfigProperty configProperty) { + this.configProperty = configProperty; + } + + public void initialize(String nodeName, Node node) { + this.childNode = node.createChild(nodeName); + } + + public void assign(String nodeName, Node node) { + this.childNode = node; + } +} diff --git a/impl-javaee-prototype/src/main/resources/META-INF/services/org.jboss.shrinkwrap.descriptor.api.connector10.ConnectorDescriptor b/impl-javaee-prototype/src/main/resources/META-INF/services/org.jboss.shrinkwrap.descriptor.api.connector10.ConnectorDescriptor new file mode 100644 index 00000000..5bd7e38c --- /dev/null +++ b/impl-javaee-prototype/src/main/resources/META-INF/services/org.jboss.shrinkwrap.descriptor.api.connector10.ConnectorDescriptor @@ -0,0 +1,3 @@ +implClass=org.jboss.shrinkwrap.descriptor.impl.connector10.ConnectorDescriptorImpl +importerClass=org.jboss.shrinkwrap.descriptor.spi.node.dom.XmlDomNodeDescriptorImporterImpl +defaultName=ra.xml \ No newline at end of file diff --git a/impl-javaee-prototype/src/test/java/org/jboss/shrinkwrap/descriptor/test/connector10/ConnectorDescriptorTestCase.java b/impl-javaee-prototype/src/test/java/org/jboss/shrinkwrap/descriptor/test/connector10/ConnectorDescriptorTestCase.java new file mode 100644 index 00000000..a55aa844 --- /dev/null +++ b/impl-javaee-prototype/src/test/java/org/jboss/shrinkwrap/descriptor/test/connector10/ConnectorDescriptorTestCase.java @@ -0,0 +1,134 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2009, Red Hat Middleware LLC, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.shrinkwrap.descriptor.test.connector10; + +import java.util.List; + +import org.jboss.shrinkwrap.descriptor.api.Descriptors; +import org.jboss.shrinkwrap.descriptor.api.connector10.ConfigProperty; +import org.jboss.shrinkwrap.descriptor.api.connector10.ConnectorDescriptor; +import org.jboss.shrinkwrap.descriptor.api.connector10.Factory; +import org.jboss.shrinkwrap.descriptor.api.connector10.Resourceadapter; +import org.jboss.shrinkwrap.descriptor.impl.connector10.ChildNodeInitializer; +import org.jboss.shrinkwrap.descriptor.impl.connector10.ResourceadapterImpl; +import org.jboss.shrinkwrap.descriptor.spi.node.Node; +import org.junit.Test; + +public class ConnectorDescriptorTestCase { + + @Test + public void testFactory() throws Exception { + final ConnectorDescriptor jca10Generated = create(); + final Factory factory = jca10Generated.getFactory(); + + jca10Generated + .description("It is a sample resource adapter") + .setResourceadapter(factory.resourceadapter() + .addConfigProperty(factory.configProperty() + .configPropertyName("Input") + .configPropertyType("java.lang.String") + .configPropertyValue("test messages"))); + + String generatedRaXml = jca10Generated.exportAsString(); + System.out.println(generatedRaXml); + } + + @Test + public void testDetachedMode() throws Exception { + final ConnectorDescriptor jca10Generated = create(); + final Factory factory = jca10Generated.getFactory(); + + final Resourceadapter resourceAdapter = factory.resourceadapter(); + + final ConfigProperty property = factory.configProperty() + .configPropertyName("Input") + .configPropertyType("java.lang.String") + .configPropertyValue("test messages"); + + jca10Generated + .description("It is a sample resource adapter") + .setResourceadapter(resourceAdapter.addConfigProperty(property)); + + String generatedRaXml = jca10Generated.exportAsString(); + System.out.println(generatedRaXml); + } + + + @Test + public void testConvenientResourceAdapter() throws Exception { + final ConnectorDescriptor jca10Generated = create(); + final Factory factory = jca10Generated.getFactory(); + + final ConvenientResourceAdapter resourceAdapter = new ConvenientResourceAdapter(); + + final ConfigProperty property = factory.configProperty() + .configPropertyName("Input") + .configPropertyType("java.lang.String") + .configPropertyValue("test messages"); + + jca10Generated + .description("It is a sample resource adapter") + .setResourceadapter(resourceAdapter.addConfigProperty(property)); + + String generatedRaXml = jca10Generated.exportAsString(); + System.out.println(generatedRaXml); + } + + // -------------------------------------------------------------------------------------|| + // Internal Helper --------------------------------------------------------------------|| + // -------------------------------------------------------------------------------------|| + + private ConnectorDescriptor create() { + return Descriptors.create(ConnectorDescriptor.class); + } + + private class ConvenientResourceAdapter implements Resourceadapter, ChildNodeInitializer { + final ResourceadapterImpl resourceAdapter = new ResourceadapterImpl(); + + @Override + public void initialize(String nodeName, Node node) { + node.attribute("attr", "val"); + final Node myNode = node.createChild("my-node"); + myNode.attribute("my-attribute", "great"); + myNode.text("my-text"); + resourceAdapter.initialize(nodeName, node); + } + + @Override + public void assign(String nodeName, Node node) { + resourceAdapter.assign(nodeName, node); + } + + @Override + public Resourceadapter addConfigProperty(ConfigProperty configProperty) { + resourceAdapter.addConfigProperty(configProperty); + return this; + } + + @Override + public List getAllConfigProperty() { + return resourceAdapter.getAllConfigProperty(); + } + + @Override + public Resourceadapter removeAllConfigProperty() { + resourceAdapter.removeAllConfigProperty(); + return this; + } + + } +} diff --git a/spi/src/main/java/org/jboss/shrinkwrap/descriptor/spi/node/Node.java b/spi/src/main/java/org/jboss/shrinkwrap/descriptor/spi/node/Node.java index 2e5c5c7d..68599d6e 100644 --- a/spi/src/main/java/org/jboss/shrinkwrap/descriptor/spi/node/Node.java +++ b/spi/src/main/java/org/jboss/shrinkwrap/descriptor/spi/node/Node.java @@ -510,7 +510,32 @@ public Node deepCopy() { // Return return newRoot; } + + public static void copyFromTo(final Node fromNode, final Node toNode){ + // Precondition checks + assert toNode != null : "Node to copy information into must be specified"; + + // Set attributes + final Map attributes = fromNode.getAttributes(); + final Set attributeKeys = attributes.keySet(); + for (final String key : attributeKeys) { + final String value = attributes.get(key); + toNode.attribute(key, value); + } + + // Set text + toNode.text(fromNode.getText()); + + // Set children + final List children = fromNode.getChildren(); + for (final Node child : children) { + final Node newChild = toNode.createChild(child.getName()); + // Recurse in + copyFromTo(child, newChild); + } + } + /** * Copies this reference to the specified {@link Node} * @param copyTarget