repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/WildFlyDataSource.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import javax.naming.InitialContext; import javax.sql.DataSource; import java.io.IOException; import java.io.PrintWriter; import java.io.Serializable; import java.sql.Connection; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.util.logging.Logger; /** * WildFly DataSource implementation * * @author <a href="[email protected]">Jesper Pedersen</a> */ public class WildFlyDataSource implements DataSource, Serializable { /** The serialVersionUID */ private static final long serialVersionUID = 1L; /** DataSource */ private transient DataSource delegate; /** Service name */ private transient String jndiName; /** * Constructor * @param delegate The datasource * @param jndiName The service name */ public WildFlyDataSource(DataSource delegate, String jndiName) { this.delegate = delegate; this.jndiName = jndiName; } @Override public Connection getConnection() throws SQLException { return delegate.getConnection(); } @Override public Connection getConnection(String username, String password) throws SQLException { return delegate.getConnection(username, password); } @Override public <T> T unwrap(Class<T> iface) throws SQLException { throw new SQLException("Unwrap not supported"); } @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { return false; } @Override public PrintWriter getLogWriter() throws SQLException { return delegate.getLogWriter(); } @Override public void setLogWriter(PrintWriter out) throws SQLException { delegate.setLogWriter(out); } @Override public void setLoginTimeout(int seconds) throws SQLException { delegate.setLoginTimeout(seconds); } @Override public int getLoginTimeout() throws SQLException { return delegate.getLoginTimeout(); } @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { return delegate.getParentLogger(); } private void writeObject(java.io.ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeObject(jndiName); } private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); jndiName = (String) in.readObject(); try { InitialContext context = new InitialContext(); DataSource originalDs = (DataSource) context.lookup(jndiName); this.delegate = originalDs; } catch (Exception e) { throw new IOException(e); } } }
3,832
28.945313
102
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/GetDataSourceClassInfoOperationHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.net.InetAddress; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.TreeMap; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.services.driver.InstalledDriver; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.server.Services; import org.jboss.as.server.moduleservice.ServiceModuleLoader; import org.jboss.dmr.ModelNode; import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoadException; import org.jboss.msc.service.ServiceRegistry; /** * Reads data-source and xa-data-source class information for a jdbc-driver. * * @author <a href="mailto:[email protected]">Lin Gao</a> */ @SuppressWarnings("deprecation") // ModuleIdentifier is used in InstalledDriver, which is deprecated. public class GetDataSourceClassInfoOperationHandler implements OperationStepHandler { public static final GetDataSourceClassInfoOperationHandler INSTANCE = new GetDataSourceClassInfoOperationHandler(); private GetDataSourceClassInfoOperationHandler() { } @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final String driverName = context.getCurrentAddressValue(); if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(false); DriverRegistry driverRegistry = (DriverRegistry)registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue(); ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader)registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue(); InstalledDriver driver = driverRegistry.getInstalledDriver(driverName); if (driver == null) { context.getResult().set(new ModelNode()); return; } ModelNode result = dsClsInfoNode(serviceModuleLoader, driver.getModuleName(), driver.getDataSourceClassName(), driver.getXaDataSourceClassName()); context.getResult().set(result); } }, OperationContext.Stage.RUNTIME); } } static ModelNode dsClsInfoNode(ServiceModuleLoader serviceModuleLoader, ModuleIdentifier mid, String dsClsName, String xaDSClsName) throws OperationFailedException { ModelNode result = new ModelNode(); if (dsClsName != null) { ModelNode dsNode = new ModelNode(); dsNode.get(dsClsName).set(findPropsFromCls(serviceModuleLoader, mid, dsClsName)); result.add(dsNode); } if (xaDSClsName != null) { ModelNode xaDSNode = new ModelNode(); xaDSNode.get(xaDSClsName).set(findPropsFromCls(serviceModuleLoader, mid, xaDSClsName)); result.add(xaDSNode); } return result; } private static ModelNode findPropsFromCls(ServiceModuleLoader serviceModuleLoader, ModuleIdentifier mid, String clsName) throws OperationFailedException { Class<?> cls = null; if (mid != null) { try { cls = Class.forName(clsName, true, serviceModuleLoader.loadModule(mid.toString()).getClassLoader()); } catch (ModuleLoadException | ClassNotFoundException e) { throw ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(clsName, e); } } if (cls == null) { try { cls = Class.forName(clsName); } catch (ClassNotFoundException e) { throw ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(clsName, e); } } Map<String, Type> methodsMap = new TreeMap<>(); for (Method method : possiblePropsSetters(cls)) { methodsMap.putIfAbsent(deCapitalize(method.getName().substring(3)), method.getParameterTypes()[0]); } final ModelNode result = new ModelNode(); for (Map.Entry<String, Type> prop: methodsMap.entrySet()) { result.get(prop.getKey()).set(prop.getValue().getTypeName()); } return result; } /** * Check whether the types that Jakarta Connectors Injection knows. * * @see Injection.findMethod() * @param clz the class * @return whether it is understandable */ private static boolean isTypeMatched(Class<?> clz) { if (clz.equals(String.class)) { return true; } else if (clz.equals(byte.class) || clz.equals(Byte.class)) { return true; } else if (clz.equals(short.class) || clz.equals(Short.class)) { return true; } else if (clz.equals(int.class) || clz.equals(Integer.class)) { return true; } else if (clz.equals(long.class) || clz.equals(Long.class)) { return true; } else if (clz.equals(float.class) || clz.equals(Float.class)) { return true; } else if (clz.equals(double.class) || clz.equals(Double.class)) { return true; } else if (clz.equals(boolean.class) || clz.equals(Boolean.class)) { return true; } else if (clz.equals(char.class) || clz.equals(Character.class)) { return true; } else if (clz.equals(InetAddress.class)) { return true; } else if (clz.equals(Class.class)) { return true; } else if (clz.equals(Properties.class)) { return true; } return false; } private static String deCapitalize(String str) { if (str.length() == 1) { return str.toLowerCase(Locale.US); } if (str.equals(str.toUpperCase(Locale.US))) { // all uppercase, just return return str; } return str.substring(0, 1).toLowerCase(Locale.US) + str.substring(1); } private static List<Method> possiblePropsSetters(Class<?> clz) { List<Method> hits = new ArrayList<>(); while (!clz.equals(Object.class)) { Method[] methods = clz.getMethods(); for (int i = 0; i < methods.length; i++) { final Method method = methods[i]; if (!Modifier.isStatic(method.getModifiers()) && method.getName().length() > 3 && method.getName().startsWith("set") && method.getParameterCount() == 1 && isTypeMatched(method.getParameterTypes()[0])) hits.add(method); } clz = clz.getSuperclass(); } return hits; } }
8,460
41.732323
160
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XMLXaDataSourceRuntimeHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import java.util.Map; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.common.XaPool; import org.jboss.jca.common.api.metadata.ds.DsXaPool; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import org.jboss.modules.ModuleClassLoader; /** * Runtime attribute handler for XA XML datasources * * @author Stuart Douglas */ public class XMLXaDataSourceRuntimeHandler extends AbstractXMLDataSourceRuntimeHandler<XaDataSource> { public static final XMLXaDataSourceRuntimeHandler INSTANCE = new XMLXaDataSourceRuntimeHandler(); @Override protected void executeReadAttribute(final String attributeName, final OperationContext context, final XaDataSource dataSource, final PathAddress address) { final String target = address.getLastElement().getKey(); if (target.equals(XA_DATASOURCE_PROPERTIES)) { handlePropertyAttribute(attributeName, context, dataSource, address.getLastElement().getValue()); } else if (target.equals(XA_DATA_SOURCE)) { handleDatasourceAttribute(attributeName, context, dataSource); } } private void handlePropertyAttribute(final String attributeName, final OperationContext context, final XaDataSource dataSource, final String propName) { if (attributeName.equals(ModelDescriptionConstants.VALUE)) { setStringIfNotNull(context, dataSource.getXaDataSourceProperty().get(propName)); } else { throw ConnectorLogger.ROOT_LOGGER.unknownAttribute(attributeName); } } private void handleDatasourceAttribute(final String attributeName, final OperationContext context, final XaDataSource dataSource) { if (attributeName.equals(Constants.XA_DATASOURCE_CLASS.getName())) { setStringIfNotNull(context, dataSource.getXaDataSourceClass()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME.getName())) { setStringIfNotNull(context, dataSource.getJndiName()); } else if (attributeName.equals(Constants.DATASOURCE_DRIVER.getName())) { setStringIfNotNull(context, dataSource.getDriver()); } else if (attributeName.equals(Constants.NEW_CONNECTION_SQL.getName())) { setStringIfNotNull(context, dataSource.getNewConnectionSql()); } else if (attributeName.equals(Constants.URL_DELIMITER.getName())) { setStringIfNotNull(context, dataSource.getUrlDelimiter()); } else if (attributeName.equals(Constants.URL_PROPERTY.getName())) { setStringIfNotNull(context, dataSource.getUrlProperty()); } else if (attributeName.equals(Constants.URL_SELECTOR_STRATEGY_CLASS_NAME.getName())) { setStringIfNotNull(context, dataSource.getUrlSelectorStrategyClassName()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT.getName())) { setBooleanIfNotNull(context, dataSource.isUseJavaContext()); } else if (attributeName.equals(Constants.ENABLED.getName())) { setBooleanIfNotNull(context, dataSource.isEnabled()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE.getName())) { if (dataSource.getXaPool() == null) { return; } setIntIfNotNull(context, dataSource.getXaPool().getMaxPoolSize()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE.getName())) { if (dataSource.getXaPool() == null) { return; } setIntIfNotNull(context, dataSource.getXaPool().getInitialPoolSize()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE.getName())) { if (dataSource.getXaPool() == null) { return; } setIntIfNotNull(context, dataSource.getXaPool().getMinPoolSize()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL.getName())) { if (dataSource.getXaPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getXaPool().isPrefill()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR.getName())) { if (dataSource.getXaPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getXaPool().isFair()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN.getName())) { if (dataSource.getXaPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getXaPool().isUseStrictMin()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY.getName())) { if (dataSource.getXaPool() == null) { return; } if (dataSource.getXaPool().getFlushStrategy() == null) { return; } setStringIfNotNull(context, dataSource.getXaPool().getFlushStrategy().getName()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS.getName())) { if (dataSource.getXaPool() == null || dataSource.getXaPool().getCapacity() == null || dataSource.getXaPool().getCapacity().getIncrementer() == null) { return; } setStringIfNotNull(context, dataSource.getXaPool().getCapacity().getIncrementer().getClassName()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS.getName())) { if (dataSource.getXaPool() == null || dataSource.getXaPool().getCapacity() == null || dataSource.getXaPool().getCapacity().getDecrementer() == null) { return; } setStringIfNotNull(context, dataSource.getXaPool().getCapacity().getDecrementer().getClassName()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES.getName())) { XaPool pool = dataSource.getXaPool(); if (pool == null || pool.getCapacity() == null || pool.getCapacity().getIncrementer() == null) return; final Map<String, String> propertiesMap = pool.getCapacity().getIncrementer().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES.getName())) { XaPool pool = dataSource.getXaPool(); if (pool == null || pool.getCapacity() == null || pool.getCapacity().getDecrementer() == null) return; final Map<String, String> propertiesMap = pool.getCapacity().getDecrementer().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.INTERLEAVING.getName())) { if(dataSource.getXaPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getXaPool().isInterleaving()); } else if (attributeName.equals(Constants.NO_TX_SEPARATE_POOL.getName())) { if(dataSource.getXaPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getXaPool().isNoTxSeparatePool()); } else if (attributeName.equals(Constants.PAD_XID.getName())) { if(dataSource.getXaPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getXaPool().isPadXid()); } else if (attributeName.equals(Constants.SAME_RM_OVERRIDE.getName())) { if(dataSource.getXaPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getXaPool().isSameRmOverride()); } else if (attributeName.equals(Constants.WRAP_XA_RESOURCE.getName())) { if(dataSource.getXaPool() == null) { return; } setBooleanIfNotNull(context, dataSource.getXaPool().isWrapXaResource()); } else if (attributeName.equals(Constants.PREPARED_STATEMENTS_CACHE_SIZE.getName())) { if (dataSource.getStatement() == null) { return; } setLongIfNotNull(context, dataSource.getStatement().getPreparedStatementsCacheSize()); } else if (attributeName.equals(Constants.SHARE_PREPARED_STATEMENTS.getName())) { if(dataSource.getStatement() == null) { return; } setBooleanIfNotNull(context, dataSource.getStatement().isSharePreparedStatements()); } else if (attributeName.equals(Constants.TRACK_STATEMENTS.getName())) { if(dataSource.getStatement() == null) { return; } if(dataSource.getStatement().getTrackStatements() == null) { return; } setStringIfNotNull(context, dataSource.getStatement().getTrackStatements().name()); } else if (attributeName.equals(Constants.ALLOCATION_RETRY.getName())) { if(dataSource.getTimeOut() == null) { return; } setIntIfNotNull(context, dataSource.getTimeOut().getAllocationRetry()); } else if (attributeName.equals(Constants.ALLOCATION_RETRY_WAIT_MILLIS.getName())) { if(dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getAllocationRetryWaitMillis()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS.getName())) { if(dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getBlockingTimeoutMillis()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES.getName())) { if(dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getIdleTimeoutMinutes()); } else if (attributeName.equals(Constants.XA_RESOURCE_TIMEOUT.getName())) { if(dataSource.getTimeOut() == null) { return; } setIntIfNotNull(context, dataSource.getTimeOut().getXaResourceTimeout()); } else if (attributeName.equals(Constants.RECOVERY_USERNAME.getName())) { if(dataSource.getRecovery() == null) { return; } if(dataSource.getRecovery().getCredential() == null) { return; } setStringIfNotNull(context, dataSource.getRecovery().getCredential().getUserName()); } else if (attributeName.equals(Constants.RECOVERY_PASSWORD.getName())) { //don't display the password } else if (attributeName.equals(Constants.RECOVERY_SECURITY_DOMAIN.getName())) { // no longer supported } else if (attributeName.equals(Constants.RECOVERY_ELYTRON_ENABLED.getName())) { setBooleanIfNotNull(context, true); } else if (attributeName.equals(Constants.RECOVERY_CREDENTIAL_REFERENCE.getName())) { //don't give out the credential-reference } else if (attributeName.equals(Constants.RECOVERY_AUTHENTICATION_CONTEXT.getName())) { if(dataSource.getRecovery() == null) { return; } if(dataSource.getRecovery().getCredential() == null) { return; } setStringIfNotNull(context, dataSource.getRecovery().getCredential().getSecurityDomain()); } else if (attributeName.equals(Constants.RECOVER_PLUGIN_CLASSNAME.getName())) { if(dataSource.getRecovery() == null) { return; } if(dataSource.getRecovery().getRecoverPlugin() == null) { return; } setStringIfNotNull(context, dataSource.getRecovery().getRecoverPlugin().getClassName()); } else if (attributeName.equals(Constants.RECOVER_PLUGIN_PROPERTIES.getName())) { if(dataSource.getRecovery() == null) { return; } if(dataSource.getRecovery().getRecoverPlugin() == null) { return; } final Map<String, String> propertiesMap = dataSource.getRecovery().getRecoverPlugin().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.NO_RECOVERY.getName())) { if(dataSource.getRecovery() == null) { return; } setBooleanIfNotNull(context, dataSource.getRecovery().getNoRecovery()); } else if (attributeName.equals(Constants.CHECK_VALID_CONNECTION_SQL.getName())) { if (dataSource.getValidation() == null) { return; } setStringIfNotNull(context, dataSource.getValidation().getCheckValidConnectionSql()); } else if (attributeName.equals(Constants.EXCEPTION_SORTER_CLASSNAME.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getExceptionSorter() == null) { return; } setStringIfNotNull(context, dataSource.getValidation().getExceptionSorter().getClassName()); } else if (attributeName.equals(Constants.EXCEPTION_SORTER_MODULE.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getExceptionSorter() == null) { return; } ClassLoader exceptionSorterClassLoader = dataSource.getValidation().getExceptionSorter().getClassLoader(); if (exceptionSorterClassLoader instanceof ModuleClassLoader) { setStringIfNotNull(context, ((ModuleClassLoader) exceptionSorterClassLoader).getModule().toString()); } } else if (attributeName.equals(Constants.EXCEPTION_SORTER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getExceptionSorter() == null) { return; } final Map<String, String> propertiesMap = dataSource.getValidation().getExceptionSorter().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_CLASSNAME.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getStaleConnectionChecker() == null) { return; } setStringIfNotNull(context, dataSource.getValidation().getStaleConnectionChecker().getClassName()); } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_MODULE.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getStaleConnectionChecker() == null) { return; } ClassLoader staleConnectionCheckerClassLoader = dataSource.getValidation().getStaleConnectionChecker().getClassLoader(); if (staleConnectionCheckerClassLoader instanceof ModuleClassLoader) { setStringIfNotNull(context, ((ModuleClassLoader) staleConnectionCheckerClassLoader).getModule().toString()); } } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getStaleConnectionChecker() == null) { return; } final Map<String, String> propertiesMap = dataSource.getValidation().getStaleConnectionChecker().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_CLASSNAME.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getValidConnectionChecker() == null) { return; } setStringIfNotNull(context, dataSource.getValidation().getValidConnectionChecker().getClassName()); } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_MODULE.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getValidConnectionChecker() == null) { return; } ClassLoader validConnectionCheckerClassLoader = dataSource.getValidation().getValidConnectionChecker().getClassLoader(); if (validConnectionCheckerClassLoader instanceof ModuleClassLoader) { setStringIfNotNull(context, ((ModuleClassLoader) validConnectionCheckerClassLoader).getModule().toString()); } } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return; } if (dataSource.getValidation().getValidConnectionChecker() == null) { return; } final Map<String, String> propertiesMap = dataSource.getValidation().getValidConnectionChecker().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS.getName())) { if (dataSource.getValidation() == null) { return; } setLongIfNotNull(context, dataSource.getValidation().getBackgroundValidationMillis()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION.getName())) { if (dataSource.getValidation() == null) { return; } setBooleanIfNotNull(context, dataSource.getValidation().isBackgroundValidation()); } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL.getName())) { if (dataSource.getValidation() == null) { return; } setBooleanIfNotNull(context, dataSource.getValidation().isUseFastFail()); } else if (attributeName.equals(Constants.VALIDATE_ON_MATCH.getName())) { if (dataSource.getValidation() == null) { return; } setBooleanIfNotNull(context, dataSource.getValidation().isValidateOnMatch()); } else if (attributeName.equals(Constants.USERNAME.getName())) { if (dataSource.getSecurity() == null) { return; } setStringIfNotNull(context, dataSource.getSecurity().getUserName()); } else if (attributeName.equals(Constants.PASSWORD.getName())) { //don't give out the password } else if (attributeName.equals(Constants.CREDENTIAL_REFERENCE.getName())) { //don't give out the credential-reference } else if (attributeName.equals(Constants.SECURITY_DOMAIN.getName())) { if (dataSource.getSecurity() == null) { return; } if (dataSource.getSecurity().getSecurityDomain() == null) { return; } throw new IllegalStateException(ConnectorLogger.ROOT_LOGGER.legacySecurityNotSupported()); } else if (attributeName.equals(Constants.ELYTRON_ENABLED.getName())) { setBooleanIfNotNull(context, true); } else if (attributeName.equals(Constants.AUTHENTICATION_CONTEXT.getName())) { setStringIfNotNull(context, dataSource.getSecurity().getSecurityDomain()); } else if (attributeName.equals(Constants.REAUTH_PLUGIN_CLASSNAME.getName())) { if (dataSource.getSecurity() == null) { return; } if (dataSource.getSecurity().getReauthPlugin() == null) { return; } setStringIfNotNull(context, dataSource.getSecurity().getReauthPlugin().getClassName()); } else if (attributeName.equals(Constants.REAUTHPLUGIN_PROPERTIES.getName())) { if (dataSource.getSecurity() == null) { return; } if (dataSource.getSecurity().getReauthPlugin() == null) { return; } final Map<String, String> propertiesMap = dataSource.getSecurity().getReauthPlugin().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.QUERY_TIMEOUT.getName())) { if (dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getQueryTimeout()); } else if (attributeName.equals(Constants.USE_TRY_LOCK.getName())) { if (dataSource.getTimeOut() == null) { return; } setLongIfNotNull(context, dataSource.getTimeOut().getUseTryLock()); } else if (attributeName.equals(Constants.SET_TX_QUERY_TIMEOUT.getName())) { if (dataSource.getTimeOut() == null) { return; } setBooleanIfNotNull(context, dataSource.getTimeOut().isSetTxQueryTimeout()); } else if (attributeName.equals(Constants.TRANSACTION_ISOLATION.getName())) { if (dataSource.getTransactionIsolation() == null) { return; } setStringIfNotNull(context, dataSource.getTransactionIsolation().name()); } else if (attributeName.equals(Constants.SPY.getName())) { setBooleanIfNotNull(context, dataSource.isSpy()); } else if (attributeName.equals(Constants.USE_CCM.getName())) { setBooleanIfNotNull(context, dataSource.isUseCcm()); } else if (attributeName.equals(Constants.JTA.getName())) { setBooleanIfNotNull(context, true); } else if (attributeName.equals(Constants.ALLOW_MULTIPLE_USERS.getName())) { XaPool pool = dataSource.getXaPool(); if (!(pool instanceof DsXaPool)) { return; } setBooleanIfNotNull(context, ((DsXaPool) pool).isAllowMultipleUsers()); } else if (attributeName.equals(Constants.CONNECTION_LISTENER_CLASS.getName())) { XaPool pool = dataSource.getXaPool(); if (!(pool instanceof DsXaPool) || ((DsXaPool) pool).getConnectionListener() == null) { return; } setStringIfNotNull(context, ((DsXaPool) pool).getConnectionListener().getClassName()); } else if (attributeName.equals(Constants.CONNECTION_LISTENER_PROPERTIES.getName())) { XaPool pool = dataSource.getXaPool(); if (!(pool instanceof DsXaPool) || ((DsXaPool) pool).getConnectionListener() == null) { return; } final Map<String, String> propertiesMap = ((DsXaPool) pool).getConnectionListener().getConfigPropertiesMap(); if (propertiesMap == null) { return; } for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) { context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty()); } } else if (attributeName.equals(Constants.CONNECTABLE.getName())) { //Just set to false context.getResult().set(false); } else if (attributeName.equals(Constants.STATISTICS_ENABLED.getName())) { //Just set to false context.getResult().set(false); } else if (attributeName.equals(Constants.TRACKING.getName())) { //Just return w/o setting a result return; } else if (attributeName.equals(Constants.MCP.getName())) { //Just return w/o setting a result return; } else if (attributeName.equals(Constants.ENLISTMENT_TRACE.getName())) { //Just return w/o setting a result return; } else { throw ConnectorLogger.ROOT_LOGGER.unknownAttribute(attributeName); } } }
28,116
52.658397
162
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/CommonDeploymentService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.jca.deployers.common.CommonDeployment; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; public class CommonDeploymentService implements Service<CommonDeployment> { private static final ServiceName SERVICE_NAME_BASE = ServiceName.JBOSS.append("data-source").append("common-deployment"); public static ServiceName getServiceName(ContextNames.BindInfo bindInfo) { return SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName().getCanonicalName()); } private CommonDeployment value; /** create an instance **/ public CommonDeploymentService(CommonDeployment value) { super(); this.value = value; } @Override public CommonDeployment getValue() throws IllegalStateException, IllegalArgumentException { return value; } @Override public void start(StartContext context) throws StartException { ROOT_LOGGER.debugf("Started CommonDeployment %s", context.getController().getName()); } @Override public void stop(StopContext context) { ROOT_LOGGER.debugf("Stopped CommonDeployment %s", context.getController().getName()); } }
2,521
36.641791
125
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XaDataSourceService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecovery; import org.jboss.jca.core.spi.transaction.recovery.XAResourceRecoveryRegistry; import org.jboss.msc.inject.Injector; import org.jboss.msc.value.InjectedValue; /** * XA data-source service implementation. * @author John Bailey * @author Stefano Maestri */ public class XaDataSourceService extends AbstractDataSourceService { private final InjectedValue<ModifiableXaDataSource> dataSourceConfig = new InjectedValue<ModifiableXaDataSource>(); public XaDataSourceService(final String dsName, final ContextNames.BindInfo jndiName, final ClassLoader classLoader) { super(dsName, jndiName, classLoader); } public XaDataSourceService(final String dsName, final ContextNames.BindInfo jndiName) { this(dsName, jndiName, null); } @Override protected synchronized void stopService() { if (deploymentMD != null && deploymentMD.getRecovery() != null && transactionIntegrationValue.getValue() != null && transactionIntegrationValue.getValue().getRecoveryRegistry() != null) { XAResourceRecoveryRegistry rr = transactionIntegrationValue.getValue().getRecoveryRegistry(); for (XAResourceRecovery recovery : deploymentMD.getRecovery()) { if (recovery != null) { try { recovery.shutdown(); } catch (Exception e) { ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER.errorDuringRecoveryShutdown(e); } finally { rr.removeXAResourceRecovery(recovery); } } } } super.stopService(); } @Override public AS7DataSourceDeployer getDeployer() throws ValidateException { return new AS7DataSourceDeployer(dataSourceConfig.getValue().getUnModifiableInstance()); } public Injector<ModifiableXaDataSource> getDataSourceConfigInjector() { return dataSourceConfig; } }
3,335
38.714286
122
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourcesSubsystemAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import org.jboss.as.connector.deployers.datasource.DefaultDataSourceBindingProcessor; import org.jboss.as.connector.deployers.datasource.DefaultDataSourceResourceReferenceProcessor; import org.jboss.as.connector.deployers.ds.DsDeploymentActivator; import org.jboss.as.controller.AbstractBoottimeAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.server.AbstractDeploymentChainStep; import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.as.server.deployment.Phase; import org.jboss.dmr.ModelNode; /** * Handler for adding the datasource subsystem. * * @author @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author John Bailey */ class DataSourcesSubsystemAdd extends AbstractBoottimeAddStepHandler { static final DataSourcesSubsystemAdd INSTANCE = new DataSourcesSubsystemAdd(); protected void populateModel(ModelNode operation, ModelNode model) { model.setEmptyObject(); } @Override protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final DsDeploymentActivator dsDeploymentActivator = new DsDeploymentActivator(); context.addStep(new AbstractDeploymentChainStep() { protected void execute(DeploymentProcessorTarget processorTarget) { dsDeploymentActivator.activateProcessors(processorTarget); processorTarget.addDeploymentProcessor(DataSourcesExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_DATASOURCE_RESOURCE_INJECTION, new DefaultDataSourceResourceReferenceProcessor()); processorTarget.addDeploymentProcessor(DataSourcesExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_DEFAULT_BINDINGS_DATASOURCE, new DefaultDataSourceBindingProcessor()); } }, OperationContext.Stage.RUNTIME); } }
3,055
46.75
207
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourceModelNodeUtil.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOCATION_RETRY; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOCATION_RETRY_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOW_MULTIPLE_USERS; import static org.jboss.as.connector.subsystems.datasources.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.datasources.Constants.CHECK_VALID_CONNECTION_SQL; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTABLE; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_LISTENER_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_LISTENER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_URL; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_DRIVER; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.INTERLEAVING; import static org.jboss.as.connector.subsystems.datasources.Constants.JTA; import static org.jboss.as.connector.subsystems.datasources.Constants.MCP; import static org.jboss.as.connector.subsystems.datasources.Constants.NEW_CONNECTION_SQL; import static org.jboss.as.connector.subsystems.datasources.Constants.NO_RECOVERY; import static org.jboss.as.connector.subsystems.datasources.Constants.NO_TX_SEPARATE_POOL; import static org.jboss.as.connector.subsystems.datasources.Constants.PAD_XID; import static org.jboss.as.connector.subsystems.datasources.Constants.PASSWORD; import static org.jboss.as.connector.subsystems.datasources.Constants.PREPARED_STATEMENTS_CACHE_SIZE; import static org.jboss.as.connector.subsystems.datasources.Constants.QUERY_TIMEOUT; import static org.jboss.as.connector.subsystems.datasources.Constants.REAUTHPLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.REAUTH_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_PASSWORD; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_USERNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVER_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVER_PLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.SAME_RM_OVERRIDE; import static org.jboss.as.connector.subsystems.datasources.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.datasources.Constants.SET_TX_QUERY_TIMEOUT; import static org.jboss.as.connector.subsystems.datasources.Constants.SHARE_PREPARED_STATEMENTS; import static org.jboss.as.connector.subsystems.datasources.Constants.SPY; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.TRACKING; import static org.jboss.as.connector.subsystems.datasources.Constants.TRACK_STATEMENTS; import static org.jboss.as.connector.subsystems.datasources.Constants.TRANSACTION_ISOLATION; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_DELIMITER; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_PROPERTY; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_SELECTOR_STRATEGY_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.USERNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.USE_CCM; import static org.jboss.as.connector.subsystems.datasources.Constants.USE_TRY_LOCK; import static org.jboss.as.connector.subsystems.datasources.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.WRAP_XA_RESOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_RESOURCE_TIMEOUT; import java.util.Collections; import java.util.Locale; import java.util.Map; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.metadata.api.ds.DsSecurity; import org.jboss.as.connector.metadata.common.CredentialImpl; import org.jboss.as.connector.metadata.ds.DsSecurityImpl; import org.jboss.as.connector.util.ModelNodeUtil; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.common.Capacity; import org.jboss.jca.common.api.metadata.common.Extension; import org.jboss.jca.common.api.metadata.common.FlushStrategy; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.ds.DsPool; import org.jboss.jca.common.api.metadata.ds.DsXaPool; import org.jboss.jca.common.api.metadata.ds.Statement; import org.jboss.jca.common.api.metadata.ds.TimeOut; import org.jboss.jca.common.api.metadata.ds.TransactionIsolation; import org.jboss.jca.common.api.metadata.ds.Validation; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.common.metadata.ds.DsPoolImpl; import org.jboss.jca.common.metadata.ds.DsXaPoolImpl; import org.jboss.jca.common.metadata.ds.StatementImpl; import org.jboss.jca.common.metadata.ds.TimeOutImpl; import org.jboss.jca.common.metadata.ds.ValidationImpl; import org.wildfly.common.function.ExceptionSupplier; import org.wildfly.security.credential.source.CredentialSource; /** * Utility used to help convert between JCA spi data-source instances and model * node representations and vice-versa. * @author John Bailey */ class DataSourceModelNodeUtil { static ModifiableDataSource from(final OperationContext operationContext, final ModelNode dataSourceNode, final String dsName, final ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier) throws OperationFailedException, ValidateException { final Map<String, String> connectionProperties= Collections.emptyMap(); final String connectionUrl = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, CONNECTION_URL); final String driverClass = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, DRIVER_CLASS); final String dataSourceClass = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, DATASOURCE_CLASS); final String jndiName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, JNDI_NAME); final String driver = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, DATASOURCE_DRIVER); final String newConnectionSql = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, NEW_CONNECTION_SQL); final String poolName = dsName; final String urlDelimiter = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_DELIMITER); final String urlSelectorStrategyClassName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_SELECTOR_STRATEGY_CLASS_NAME); final boolean useJavaContext = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_JAVA_CONTEXT); final boolean enabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ENABLED); final boolean connectable = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, CONNECTABLE); final Boolean tracking = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, TRACKING); final Boolean enlistmentTrace = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ENLISTMENT_TRACE); final String mcp = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, MCP); final boolean jta = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, JTA); final Integer maxPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, MAX_POOL_SIZE); final Integer minPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, MIN_POOL_SIZE); final Integer initialPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, INITIAL_POOL_SIZE); final boolean prefill = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_PREFILL); final boolean fair = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_FAIR); final boolean useStrictMin = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_USE_STRICT_MIN); final String flushStrategyString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, POOL_FLUSH_STRATEGY); final FlushStrategy flushStrategy = FlushStrategy.forName(flushStrategyString); // TODO relax case sensitivity final Boolean allowMultipleUsers = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ALLOW_MULTIPLE_USERS); Extension incrementer = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES); Extension decrementer = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES); final Capacity capacity = new Capacity(incrementer, decrementer); final Extension connectionListener = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CONNECTION_LISTENER_CLASS, CONNECTION_LISTENER_PROPERTIES); final DsPool pool = new DsPoolImpl(minPoolSize, initialPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy, allowMultipleUsers, capacity, fair, connectionListener); final String username = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, USERNAME); final String password = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, PASSWORD); final String securityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, SECURITY_DOMAIN); if (securityDomain != null) { throw new OperationFailedException(ConnectorLogger.DS_DEPLOYER_LOGGER.legacySecurityNotSupported()); } final String authenticationContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, AUTHENTICATION_CONTEXT); final Extension reauthPlugin = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, REAUTH_PLUGIN_CLASSNAME, REAUTHPLUGIN_PROPERTIES); final DsSecurity security = new DsSecurityImpl(username, password, authenticationContext, credentialSourceSupplier, reauthPlugin); final boolean sharePreparedStatements = SHARE_PREPARED_STATEMENTS.resolveModelAttribute(operationContext, dataSourceNode).asBoolean(); final Long preparedStatementsCacheSize = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, PREPARED_STATEMENTS_CACHE_SIZE); final String trackStatementsString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, TRACK_STATEMENTS); final Statement.TrackStatementsEnum trackStatements = Statement.TrackStatementsEnum.valueOf(trackStatementsString.toUpperCase(Locale.ENGLISH)); final Statement statement = new StatementImpl(sharePreparedStatements, preparedStatementsCacheSize, trackStatements); final Integer allocationRetry = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, ALLOCATION_RETRY); final Long allocationRetryWaitMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, ALLOCATION_RETRY_WAIT_MILLIS); final Long blockingTimeoutMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, BLOCKING_TIMEOUT_WAIT_MILLIS); final Long idleTimeoutMinutes = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, IDLETIMEOUTMINUTES); final Long queryTimeout = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, QUERY_TIMEOUT); final Integer xaResourceTimeout = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, XA_RESOURCE_TIMEOUT); final Long useTryLock = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, USE_TRY_LOCK); final boolean setTxQueryTimeout = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SET_TX_QUERY_TIMEOUT); final TimeOut timeOut = new TimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry, allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout, queryTimeout, useTryLock); final String transactionIsolationString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, TRANSACTION_ISOLATION); TransactionIsolation transactionIsolation = null; if (transactionIsolationString != null) { transactionIsolation = TransactionIsolation.forName(transactionIsolationString); // TODO relax case sensitivity if (transactionIsolation == null) { transactionIsolation = TransactionIsolation.customLevel(transactionIsolationString); } } final String checkValidConnectionSql = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, CHECK_VALID_CONNECTION_SQL); final Extension exceptionSorter = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, EXCEPTION_SORTER_CLASSNAME, EXCEPTION_SORTER_MODULE, EXCEPTION_SORTER_PROPERTIES); final Extension staleConnectionChecker = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, STALE_CONNECTION_CHECKER_CLASSNAME, STALE_CONNECTION_CHECKER_MODULE, STALE_CONNECTION_CHECKER_PROPERTIES); final Extension validConnectionChecker = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, VALID_CONNECTION_CHECKER_CLASSNAME, VALID_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_PROPERTIES); Long backgroundValidationMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, BACKGROUNDVALIDATIONMILLIS); final Boolean backgroundValidation = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, BACKGROUNDVALIDATION); boolean useFastFail = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_FAST_FAIL); final Boolean validateOnMatch = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, VALIDATE_ON_MATCH); final boolean spy = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SPY); final boolean useCcm = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_CCM); final Validation validation = new ValidationImpl(backgroundValidation, backgroundValidationMillis, useFastFail, validConnectionChecker, checkValidConnectionSql, validateOnMatch, staleConnectionChecker, exceptionSorter); return new ModifiableDataSource(connectionUrl, driverClass, dataSourceClass, driver, transactionIsolation, connectionProperties, timeOut, security, statement, validation, urlDelimiter, urlSelectorStrategyClassName, newConnectionSql, useJavaContext, poolName, enabled, jndiName, spy, useCcm, jta, connectable, tracking, mcp, enlistmentTrace, pool); } static ModifiableXaDataSource xaFrom(final OperationContext operationContext, final ModelNode dataSourceNode, final String dsName, final ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier, final ExceptionSupplier<CredentialSource, Exception> recoveryCredentialSourceSupplier) throws OperationFailedException, ValidateException { final Map<String, String> xaDataSourceProperty; xaDataSourceProperty = Collections.emptyMap(); final String xaDataSourceClass = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, XA_DATASOURCE_CLASS); final String jndiName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, JNDI_NAME); final String module = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, DATASOURCE_DRIVER); final String newConnectionSql = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, NEW_CONNECTION_SQL); final String poolName = dsName; final String urlDelimiter = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_DELIMITER); final String urlSelectorStrategyClassName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_SELECTOR_STRATEGY_CLASS_NAME); final Boolean useJavaContext = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_JAVA_CONTEXT); final Boolean enabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ENABLED); final boolean connectable = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, CONNECTABLE); final Boolean tracking = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, TRACKING); final Boolean enlistmentTrace = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ENLISTMENT_TRACE); final String mcp = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, MCP); final Integer maxPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, MAX_POOL_SIZE); final Integer minPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, MIN_POOL_SIZE); final Integer initialPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, INITIAL_POOL_SIZE); final Boolean prefill = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_PREFILL); final Boolean fair = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_FAIR); final Boolean useStrictMin = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_USE_STRICT_MIN); final Boolean interleaving = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, INTERLEAVING); final Boolean noTxSeparatePool = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, NO_TX_SEPARATE_POOL); final Boolean padXid = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, PAD_XID); final Boolean isSameRmOverride = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SAME_RM_OVERRIDE); final Boolean wrapXaDataSource = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, WRAP_XA_RESOURCE); final String flushStrategyString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, POOL_FLUSH_STRATEGY); final FlushStrategy flushStrategy = FlushStrategy.forName(flushStrategyString); // TODO relax case sensitivity final Boolean allowMultipleUsers = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ALLOW_MULTIPLE_USERS); Extension incrementer = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES); Extension decrementer = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES); final Capacity capacity = new Capacity(incrementer, decrementer); final Extension connectionListener = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CONNECTION_LISTENER_CLASS, CONNECTION_LISTENER_PROPERTIES); final DsXaPool xaPool = new DsXaPoolImpl(minPoolSize, initialPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy, isSameRmOverride, interleaving, padXid, wrapXaDataSource, noTxSeparatePool, allowMultipleUsers, capacity, fair, connectionListener); final String username = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, USERNAME); final String password= ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, PASSWORD); final String securityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, SECURITY_DOMAIN); if (securityDomain != null) { throw new OperationFailedException(ConnectorLogger.DS_DEPLOYER_LOGGER.legacySecurityNotSupported()); } final String authenticationContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, AUTHENTICATION_CONTEXT); final Extension reauthPlugin = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, REAUTH_PLUGIN_CLASSNAME, REAUTHPLUGIN_PROPERTIES); final DsSecurity security = new DsSecurityImpl(username, password, authenticationContext, credentialSourceSupplier, reauthPlugin); final boolean sharePreparedStatements = SHARE_PREPARED_STATEMENTS.resolveModelAttribute(operationContext, dataSourceNode).asBoolean(); final Long preparedStatementsCacheSize = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, PREPARED_STATEMENTS_CACHE_SIZE); final String trackStatementsString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, TRACK_STATEMENTS); final Statement.TrackStatementsEnum trackStatements = Statement.TrackStatementsEnum.valueOf(trackStatementsString.toUpperCase(Locale.ENGLISH)); final Statement statement = new StatementImpl(sharePreparedStatements, preparedStatementsCacheSize, trackStatements); final Integer allocationRetry = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, ALLOCATION_RETRY); final Long allocationRetryWaitMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, ALLOCATION_RETRY_WAIT_MILLIS); final Long blockingTimeoutMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, BLOCKING_TIMEOUT_WAIT_MILLIS); final Long idleTimeoutMinutes = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, IDLETIMEOUTMINUTES); final Long queryTimeout = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, QUERY_TIMEOUT); final Integer xaResourceTimeout = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, XA_RESOURCE_TIMEOUT); final Long useTryLock = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, USE_TRY_LOCK); final Boolean setTxQueryTimeout = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SET_TX_QUERY_TIMEOUT); final TimeOut timeOut = new TimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry, allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout, queryTimeout, useTryLock); final String transactionIsolationString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, TRANSACTION_ISOLATION); TransactionIsolation transactionIsolation = null; if (transactionIsolationString != null) { transactionIsolation = TransactionIsolation.forName(transactionIsolationString); // TODO relax case sensitivity if (transactionIsolation == null) { transactionIsolation = TransactionIsolation.customLevel(transactionIsolationString); } } final String checkValidConnectionSql = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, CHECK_VALID_CONNECTION_SQL); final Extension exceptionSorter = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, EXCEPTION_SORTER_CLASSNAME, EXCEPTION_SORTER_MODULE, EXCEPTION_SORTER_PROPERTIES); final Extension staleConnectionChecker = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, STALE_CONNECTION_CHECKER_CLASSNAME, STALE_CONNECTION_CHECKER_MODULE, STALE_CONNECTION_CHECKER_PROPERTIES); final Extension validConnectionChecker = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, VALID_CONNECTION_CHECKER_CLASSNAME, VALID_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_PROPERTIES); Long backgroundValidationMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, BACKGROUNDVALIDATIONMILLIS); final Boolean backgroundValidation = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, BACKGROUNDVALIDATION); boolean useFastFail = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_FAST_FAIL); final Boolean validateOnMatch = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, VALIDATE_ON_MATCH); final Boolean spy = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SPY); final Boolean useCcm = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_CCM); final Validation validation = new ValidationImpl(backgroundValidation, backgroundValidationMillis, useFastFail, validConnectionChecker, checkValidConnectionSql, validateOnMatch, staleConnectionChecker, exceptionSorter); final String recoveryUsername = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_USERNAME); final String recoveryPassword = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_PASSWORD); final String recoverySecurityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_SECURITY_DOMAIN); if(recoverySecurityDomain != null){ throw new OperationFailedException(ConnectorLogger.DS_DEPLOYER_LOGGER.legacySecurityNotSupported()); } final String recoveryAuthenticationContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_AUTHENTICATION_CONTEXT); Boolean noRecovery = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, NO_RECOVERY); final String urlProperty = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_PROPERTY); Recovery recovery = null; if ((recoveryUsername != null && (recoveryPassword != null || recoveryCredentialSourceSupplier != null)) || recoverySecurityDomain != null || noRecovery != null) { Credential credential = null; if ((recoveryUsername != null && (recoveryPassword != null || recoveryCredentialSourceSupplier != null)) || recoverySecurityDomain != null) credential = new CredentialImpl(recoveryUsername, recoveryPassword, recoveryAuthenticationContext, recoveryCredentialSourceSupplier); Extension recoverPlugin = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, RECOVER_PLUGIN_CLASSNAME, RECOVER_PLUGIN_PROPERTIES); if (noRecovery == null) noRecovery = Boolean.FALSE; recovery = new Recovery(credential, recoverPlugin, noRecovery); } return new ModifiableXaDataSource(transactionIsolation, timeOut, security, statement, validation, urlDelimiter, urlProperty, urlSelectorStrategyClassName, useJavaContext, poolName, enabled, jndiName, spy, useCcm, connectable, tracking, mcp, enlistmentTrace, xaDataSourceProperty, xaDataSourceClass, module, newConnectionSql, xaPool, recovery); } }
32,576
88.008197
262
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/ConnectionPropertyDefinition.java
/* * * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * / */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_PROPERTIES; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.transform.description.RejectAttributeChecker; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; /** * @author Stefabo Maestri */ public class ConnectionPropertyDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_CONNECTION_PROPERTY = PathElement.pathElement(CONNECTION_PROPERTIES.getName()); private final boolean deployed; ConnectionPropertyDefinition(final boolean deployed) { super(PATH_CONNECTION_PROPERTY, DataSourcesExtension.getResourceDescriptionResolver("data-source", "connection-properties"), deployed ? null : ConnectionPropertyAdd.INSTANCE, deployed ? null : ConnectionPropertyRemove.INSTANCE); this.deployed = deployed; } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { if (deployed) { SimpleAttributeDefinition runtimeAttribute = new SimpleAttributeDefinitionBuilder(Constants.CONNECTION_PROPERTY_VALUE).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLDataSourceRuntimeHandler.INSTANCE); } else { resourceRegistration.registerReadOnlyAttribute(Constants.CONNECTION_PROPERTY_VALUE, null); } } static void registerTransformers11x(ResourceTransformationDescriptionBuilder parentBuilder) { parentBuilder.addChildResource(PATH_CONNECTION_PROPERTY) .getAttributeBuilder() .addRejectCheck(RejectAttributeChecker.UNDEFINED, Constants.CONNECTION_PROPERTY_VALUE) .end(); } }
3,305
43.08
186
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/LocalDataSourceService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.msc.inject.Injector; import org.jboss.msc.value.InjectedValue; /** * Local data-source service implementation. * @author John Bailey * @author Stefano Maestri */ public class LocalDataSourceService extends AbstractDataSourceService { private final InjectedValue<ModifiableDataSource> dataSourceConfig = new InjectedValue<ModifiableDataSource>(); public LocalDataSourceService(final String dsName, final ContextNames.BindInfo jndiName, final ClassLoader classLoader) { super(dsName, jndiName, classLoader); } public LocalDataSourceService(final String dsName, final ContextNames.BindInfo jndiName) { super(dsName, jndiName, null); } @Override public AS7DataSourceDeployer getDeployer() throws ValidateException { return new AS7DataSourceDeployer(dataSourceConfig.getValue().getUnModifiableInstance()); } public Injector<ModifiableDataSource> getDataSourceConfigInjector() { return dataSourceConfig; } }
2,194
38.196429
125
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/Attribute.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import java.util.HashMap; import java.util.Map; /** * DataSource subsystem schema attributes. * * @author John Bailey */ public enum Attribute { /** always the first **/ UNKNOWN(null), MODULE("module"); private final String name; Attribute(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } private static final Map<String, Attribute> MAP; static { final Map<String, Attribute> map = new HashMap<String, Attribute>(); for (Attribute element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } public static Attribute forName(String localName) { final Attribute element = MAP.get(localName); return element == null ? UNKNOWN : element; } @Override public String toString() { return getLocalName(); } }
2,165
27.5
76
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/InstalledDriversListOperationHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ /** * */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_CLASS_INFO; import static org.jboss.as.connector.subsystems.datasources.Constants.DEPLOYMENT_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MAJOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MINOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MODULE_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_XA_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.INSTALLED_DRIVER_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.JDBC_COMPLIANT; import static org.jboss.as.connector.subsystems.datasources.Constants.MODULE_SLOT; import static org.jboss.as.connector.subsystems.datasources.Constants.PROFILE; import static org.jboss.as.connector.subsystems.datasources.GetDataSourceClassInfoOperationHandler.dsClsInfoNode; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.services.driver.InstalledDriver; import org.jboss.as.connector.services.driver.registry.DriverRegistry; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.registry.Resource; import org.jboss.as.server.Services; import org.jboss.as.server.moduleservice.ServiceModuleLoader; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceRegistry; /** * Reads the "installed-drivers" attribute. * @author Brian Stansberry (c) 2011 Red Hat Inc. */ public class InstalledDriversListOperationHandler implements OperationStepHandler { public static final InstalledDriversListOperationHandler INSTANCE = new InstalledDriversListOperationHandler(); private InstalledDriversListOperationHandler() { } public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(false); DriverRegistry driverRegistry = (DriverRegistry)registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue(); ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader)registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue(); Resource rootNode = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false); ModelNode rootModel = rootNode.getModel(); String profile = rootModel.hasDefined("profile-name") ? rootModel.get("profile-name").asString() : null; ModelNode result = context.getResult(); for (InstalledDriver driver : driverRegistry.getInstalledDrivers()) { ModelNode driverNode = new ModelNode(); driverNode.get(INSTALLED_DRIVER_NAME.getName()).set(driver.getDriverName()); if (driver.isFromDeployment()) { driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName()); driverNode.get(DRIVER_MODULE_NAME.getName()); driverNode.get(MODULE_SLOT.getName()); driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName()); driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()); } else { driverNode.get(DEPLOYMENT_NAME.getName()); driverNode.get(DRIVER_MODULE_NAME.getName()).set(driver.getModuleName().getName()); driverNode.get(MODULE_SLOT.getName()).set( driver.getModuleName() != null ? driver.getModuleName().getSlot() : ""); driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).set( driver.getDataSourceClassName() != null ? driver.getDataSourceClassName() : ""); driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).set( driver.getXaDataSourceClassName() != null ? driver.getXaDataSourceClassName() : ""); } driverNode.get(DATASOURCE_CLASS_INFO.getName()).set( dsClsInfoNode(serviceModuleLoader, driver.getModuleName(), driver.getDataSourceClassName(), driver.getXaDataSourceClassName())); driverNode.get(DRIVER_CLASS_NAME.getName()).set(driver.getDriverClassName()); driverNode.get(DRIVER_MAJOR_VERSION.getName()).set(driver.getMajorVersion()); driverNode.get(DRIVER_MINOR_VERSION.getName()).set(driver.getMinorVersion()); driverNode.get(JDBC_COMPLIANT.getName()).set(driver.isJdbcCompliant()); if (profile != null) { driverNode.get(PROFILE.getName()).set(profile); } result.add(driverNode); } } }, OperationContext.Stage.RUNTIME); } else { context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.noMetricsAvailable()); } } }
7,025
58.542373
160
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/Namespace.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import java.util.HashMap; import java.util.Map; /** * A Namespace. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public enum Namespace { // must be first UNKNOWN(null), DATASOURCES_1_1("urn:jboss:domain:datasources:1.1"), DATASOURCES_1_2("urn:jboss:domain:datasources:1.2"), DATASOURCES_2_0("urn:jboss:domain:datasources:2.0"), DATASOURCES_3_0("urn:jboss:domain:datasources:3.0"), DATASOURCES_4_0("urn:jboss:domain:datasources:4.0"), DATASOURCES_5_0("urn:jboss:domain:datasources:5.0"), DATASOURCES_6_0("urn:jboss:domain:datasources:6.0"), DATASOURCES_7_0("urn:jboss:domain:datasources:7.0"); /** * The current namespace version. */ public static final Namespace CURRENT = DATASOURCES_7_0; private final String name; Namespace(final String name) { this.name = name; } /** * Get the URI of this namespace. * @return the URI */ public String getUriString() { return name; } private static final Map<String, Namespace> MAP; static { final Map<String, Namespace> map = new HashMap<String, Namespace>(); for (Namespace namespace : values()) { final String name = namespace.getUriString(); if (name != null) map.put(name, namespace); } MAP = map; } public static Namespace forUri(String uri) { final Namespace element = MAP.get(uri); return element == null ? UNKNOWN : element; } }
2,635
28.954545
82
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourceEnableDisable.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION; import static org.jboss.as.controller.operations.common.Util.getWriteAttributeOperation; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; /** * Operation handler responsible for the legacy 'enable' and 'disable' ops used to enable or * disable an existing data-source. * * @author John Bailey */ public class DataSourceEnableDisable implements OperationStepHandler { static final DataSourceEnableDisable ENABLE = new DataSourceEnableDisable(true); static final DataSourceEnableDisable DISABLE = new DataSourceEnableDisable(false); private final boolean enabled; private DataSourceEnableDisable(final boolean enabled) { this.enabled = enabled; } public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // Log that this is deprecated ConnectorLogger.ROOT_LOGGER.legacyDisableEnableOperation(operation.get(OP).asString()); // Just delegate to write-attribute. ModelNode writeAttributeOp = getWriteAttributeOperation(context.getCurrentAddress(), Constants.ENABLED.getName(), enabled); OperationStepHandler writeHandler = context.getResourceRegistration().getOperationHandler(PathAddress.EMPTY_ADDRESS, WRITE_ATTRIBUTE_OPERATION); // set the addFirst param to 'true' so the write-attribute runs before any other steps already registered; // i.e. in the logically equivalent spot in the sequence to this step context.addStep(writeAttributeOp, writeHandler, OperationContext.Stage.MODEL, true); } }
3,056
45.318182
152
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourceAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_ATTRIBUTE; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_PROPERTIES_ATTRIBUTES; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * Operation handler responsible for adding a DataSource. * * @author Stefano Maestrioperation2.get(OP).set("write-attribute"); */ public class DataSourceAdd extends AbstractDataSourceAdd { static final DataSourceAdd INSTANCE = new DataSourceAdd(); private DataSourceAdd() { super(join(DATASOURCE_ATTRIBUTE, DATASOURCE_PROPERTIES_ATTRIBUTES)); } protected AbstractDataSourceService createDataSourceService(final String dsName,final String jndiName) throws OperationFailedException { return new LocalDataSourceService(dsName, ContextNames.bindInfoFor(jndiName)); } @Override protected boolean isXa() { return false; } @Override protected void startConfigAndAddDependency(ServiceBuilder<?> dataSourceServiceBuilder, AbstractDataSourceService dataSourceService, String jndiName, ServiceTarget serviceTarget, final ModelNode operation) throws OperationFailedException { final ServiceName dataSourceCongServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(jndiName); dataSourceServiceBuilder.addDependency(dataSourceCongServiceName, ModifiableDataSource.class, ((LocalDataSourceService) dataSourceService).getDataSourceConfigInjector()); } }
2,837
39.542857
140
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/EnlistmentTraceAttributeWriteHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import java.util.ArrayList; import java.util.List; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.management.DataSource; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.msc.service.ServiceController; /** * @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author <a href="mailto:[email protected]">Jeff Zhang</a> */ public class EnlistmentTraceAttributeWriteHandler extends AbstractWriteAttributeHandler<List<DataSource>> { protected EnlistmentTraceAttributeWriteHandler() { super(Constants.ENLISTMENT_TRACE); } @Override protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<DataSource>> handbackHolder) throws OperationFailedException { final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel() .get(org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME.getName()).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean(); try { final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue(); if (repository.getDataSources() != null) { for (DataSource dataSource : repository.getDataSources()) { if (jndiName.equalsIgnoreCase(dataSource.getJndiName())) { dataSource.setEnlistmentTrace(boolValue); } } List<DataSource> list = new ArrayList<>(); for (DataSource ds : repository.getDataSources()) { if (jndiName.equalsIgnoreCase(ds.getJndiName())) { list.add(ds); } } handbackHolder.setHandback(list); } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage())); } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String parameterName, ModelNode valueToRestore, ModelNode valueToRevert, List<DataSource> handback) throws OperationFailedException { Boolean value = Constants.ENLISTMENT_TRACE.resolveValue(context, valueToRestore).asBoolean(); if (handback != null) { for (DataSource ds : handback) { ds.setEnlistmentTrace(value); } } } }
4,421
40.327103
161
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourcesTransformers.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.transform.ExtensionTransformerRegistration; import org.jboss.as.controller.transform.SubsystemTransformerRegistration; import org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.DiscardAttributeChecker; import org.jboss.as.controller.transform.description.RejectAttributeChecker; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.TransformationDescription; import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_MODULE; import static org.jboss.as.connector.subsystems.datasources.DataSourceDefinition.PATH_DATASOURCE; import static org.jboss.as.connector.subsystems.datasources.DataSourcesExtension.SUBSYSTEM_NAME; import static org.jboss.as.connector.subsystems.datasources.XaDataSourceDefinition.PATH_XA_DATASOURCE; public class DataSourcesTransformers implements ExtensionTransformerRegistration { private static final ModelVersion EAP_7_4 = ModelVersion.create(6, 0, 0); @Override public String getSubsystemName() { return SUBSYSTEM_NAME; } @Override public void registerTransformers(SubsystemTransformerRegistration subsystemRegistration) { ChainedTransformationDescriptionBuilder chainedBuilder = TransformationDescriptionBuilder.Factory.createChainedSubystemInstance(subsystemRegistration.getCurrentSubsystemVersion()); get600TransformationDescription(chainedBuilder.createBuilder(subsystemRegistration.getCurrentSubsystemVersion(), EAP_7_4)); chainedBuilder.buildAndRegister(subsystemRegistration, new ModelVersion[]{ EAP_7_4 }); } private static TransformationDescription get600TransformationDescription(ResourceTransformationDescriptionBuilder parentBuilder) { ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_DATASOURCE); builder.getAttributeBuilder() .setDiscard(DiscardAttributeChecker.UNDEFINED, EXCEPTION_SORTER_MODULE, STALE_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_MODULE ) .addRejectCheck(RejectAttributeChecker.DEFINED, EXCEPTION_SORTER_MODULE, STALE_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_MODULE ) .end(); builder = parentBuilder.addChildResource(PATH_XA_DATASOURCE); builder.getAttributeBuilder() .setDiscard(DiscardAttributeChecker.UNDEFINED, EXCEPTION_SORTER_MODULE, STALE_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_MODULE ) .addRejectCheck(RejectAttributeChecker.DEFINED, EXCEPTION_SORTER_MODULE, STALE_CONNECTION_CHECKER_MODULE, VALID_CONNECTION_CHECKER_MODULE ) .end(); return parentBuilder.build(); } }
4,654
50.722222
188
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XaDataSourceAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE_ATTRIBUTE; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE_PROPERTIES_ATTRIBUTES; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * Operation handler responsible for adding a XA data-source. * * @author Stefano Maestri */ public class XaDataSourceAdd extends AbstractDataSourceAdd { static final XaDataSourceAdd INSTANCE = new XaDataSourceAdd(); private XaDataSourceAdd() { super(join(XA_DATASOURCE_ATTRIBUTE, XA_DATASOURCE_PROPERTIES_ATTRIBUTES)); } @Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { super.performRuntime(context, operation, model); } protected AbstractDataSourceService createDataSourceService(final String dsName, final String jndiName) throws OperationFailedException { return new XaDataSourceService(dsName, ContextNames.bindInfoFor(jndiName)); } @Override protected boolean isXa() { return true; } @Override protected void startConfigAndAddDependency(ServiceBuilder<?> dataSourceServiceBuilder, AbstractDataSourceService dataSourceService, String jndiName, ServiceTarget serviceTarget, final ModelNode operation) throws OperationFailedException { final ServiceName dataSourceCongServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(jndiName); dataSourceServiceBuilder.addDependency(dataSourceCongServiceName, ModifiableXaDataSource.class, ((XaDataSourceService) dataSourceService).getDataSourceConfigInjector()); } }
3,107
42.166667
177
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DisableRequiredWriteAttributeHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; public class DisableRequiredWriteAttributeHandler extends AbstractWriteAttributeHandler<Void> { public DisableRequiredWriteAttributeHandler(final AttributeDefinition... definitions) { super(definitions); } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> voidHandback) { ModelNode submodel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); //do the job return (submodel.hasDefined(Constants.ENABLED.getName()) && submodel.get(Constants.ENABLED.getName()).asBoolean()) || org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME.getName().equals(attributeName); } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode resolvedValue, Void handback) { // no-op } }
2,332
44.745098
197
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourcesExtension.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOCATION_RETRY; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOCATION_RETRY_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.datasources.Constants.ALLOW_MULTIPLE_USERS; import static org.jboss.as.connector.subsystems.datasources.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.datasources.Constants.CHECK_VALID_CONNECTION_SQL; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTABLE; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_LISTENER_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_LISTENER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.CONNECTION_URL; import static org.jboss.as.connector.subsystems.datasources.Constants.CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCES; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_DRIVER; import static org.jboss.as.connector.subsystems.datasources.Constants.DATA_SOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MAJOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MINOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MODULE_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_XA_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.EXCEPTION_SORTER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.INTERLEAVING; import static org.jboss.as.connector.subsystems.datasources.Constants.JDBC_DRIVER_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.JTA; import static org.jboss.as.connector.subsystems.datasources.Constants.MCP; import static org.jboss.as.connector.subsystems.datasources.Constants.MODULE_SLOT; import static org.jboss.as.connector.subsystems.datasources.Constants.NEW_CONNECTION_SQL; import static org.jboss.as.connector.subsystems.datasources.Constants.NO_RECOVERY; import static org.jboss.as.connector.subsystems.datasources.Constants.NO_TX_SEPARATE_POOL; import static org.jboss.as.connector.subsystems.datasources.Constants.PAD_XID; import static org.jboss.as.connector.subsystems.datasources.Constants.PASSWORD; import static org.jboss.as.connector.subsystems.datasources.Constants.PREPARED_STATEMENTS_CACHE_SIZE; import static org.jboss.as.connector.subsystems.datasources.Constants.QUERY_TIMEOUT; import static org.jboss.as.connector.subsystems.datasources.Constants.REAUTHPLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.REAUTH_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_PASSWORD; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVERY_USERNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVER_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.RECOVER_PLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.SAME_RM_OVERRIDE; import static org.jboss.as.connector.subsystems.datasources.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.datasources.Constants.SET_TX_QUERY_TIMEOUT; import static org.jboss.as.connector.subsystems.datasources.Constants.SHARE_PREPARED_STATEMENTS; import static org.jboss.as.connector.subsystems.datasources.Constants.SPY; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.STALE_CONNECTION_CHECKER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.STATISTICS_ENABLED; import static org.jboss.as.connector.subsystems.datasources.Constants.TRACKING; import static org.jboss.as.connector.subsystems.datasources.Constants.TRACK_STATEMENTS; import static org.jboss.as.connector.subsystems.datasources.Constants.TRANSACTION_ISOLATION; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_DELIMITER; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_PROPERTY; import static org.jboss.as.connector.subsystems.datasources.Constants.URL_SELECTOR_STRATEGY_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.USERNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.USE_CCM; import static org.jboss.as.connector.subsystems.datasources.Constants.USE_TRY_LOCK; import static org.jboss.as.connector.subsystems.datasources.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_CLASSNAME; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_MODULE; import static org.jboss.as.connector.subsystems.datasources.Constants.VALID_CONNECTION_CHECKER_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.WRAP_XA_RESOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.XADATASOURCE_PROPERTIES; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_DATASOURCE_CLASS; import static org.jboss.as.connector.subsystems.datasources.Constants.XA_RESOURCE_TIMEOUT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent; import java.util.List; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import org.jboss.as.controller.Extension; import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SubsystemRegistration; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; import org.jboss.as.controller.parsing.ExtensionParsingContext; import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; import org.jboss.dmr.Property; import org.jboss.jca.common.api.metadata.common.Capacity; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.DataSources; import org.jboss.jca.common.api.metadata.ds.Driver; import org.jboss.jca.common.api.metadata.ds.DsPool; import org.jboss.jca.common.api.metadata.ds.DsSecurity; import org.jboss.jca.common.api.metadata.ds.Validation; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLElementWriter; import org.jboss.staxmapper.XMLExtendedStreamReader; import org.jboss.staxmapper.XMLExtendedStreamWriter; /** * @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author <a href="mailto:[email protected]">Darran Lofthouse</a> * @author John Bailey */ public class DataSourcesExtension implements Extension { public static final String SUBSYSTEM_NAME = Constants.DATASOURCES; private static final String RESOURCE_NAME = DataSourcesExtension.class.getPackage().getName() + ".LocalDescriptions"; static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(6, 0, 0); static StandardResourceDescriptionResolver getResourceDescriptionResolver(final String... keyPrefix) { StringBuilder prefix = new StringBuilder(SUBSYSTEM_NAME); for (String kp : keyPrefix) { prefix.append('.').append(kp); } return new StandardResourceDescriptionResolver(prefix.toString(), RESOURCE_NAME, DataSourcesExtension.class.getClassLoader(), true, false); } @Override public void initialize(final ExtensionContext context) { SUBSYSTEM_DATASOURCES_LOGGER.debugf("Initializing Datasources Extension"); boolean registerRuntimeOnly = context.isRuntimeOnlyRegistrationValid(); // Register the remoting subsystem final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION); final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(DataSourcesSubsystemRootDefinition.createInstance(registerRuntimeOnly)); subsystem.registerXMLElementWriter(new DataSourceSubsystemParser()); if (registerRuntimeOnly) { subsystem.registerDeploymentModel(DataSourcesSubsystemRootDefinition.createDeployedInstance(registerRuntimeOnly)); } } @Override public void initializeParsers(final ExtensionParsingContext context) { context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DATASOURCES_1_1.getUriString(), DataSourceSubsystemParser::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DATASOURCES_1_2.getUriString(), DataSourceSubsystemParser::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DATASOURCES_2_0.getUriString(), DataSourceSubsystemParser::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DATASOURCES_3_0.getUriString(), DataSourceSubsystemParser::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DATASOURCES_4_0.getUriString(), DataSourceSubsystemParser::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DATASOURCES_5_0.getUriString(), DataSourceSubsystemParser::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DATASOURCES_6_0.getUriString(), DataSourceSubsystemParser::new); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.DATASOURCES_7_0.getUriString(), DataSourceSubsystemParser::new); } public static final class DataSourceSubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> { /** * {@inheritDoc} */ @Override public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { context.startSubsystemElement(Namespace.CURRENT.getUriString(), false); ModelNode node = context.getModelNode(); writer.writeStartElement(DATASOURCES); if (node.hasDefined(DATA_SOURCE) || node.hasDefined(XA_DATASOURCE)) { if (node.hasDefined(DATA_SOURCE)) { writeDS(writer, false, node.get(DATA_SOURCE)); } if (node.hasDefined(XA_DATASOURCE)) { writeDS(writer, true, node.get(XA_DATASOURCE)); } } if (node.hasDefined(JDBC_DRIVER_NAME)) { writer.writeStartElement(DataSources.Tag.DRIVERS.getLocalName()); ModelNode drivers = node.get(JDBC_DRIVER_NAME); for (String driverName : drivers.keys()) { ModelNode driver = drivers.get(driverName); writer.writeStartElement(DataSources.Tag.DRIVER.getLocalName()); writer.writeAttribute(Driver.Attribute.NAME.getLocalName(), driverName); if (has(driver, DRIVER_MODULE_NAME.getName())) { String moduleName = driver.get(DRIVER_MODULE_NAME.getName()).asString(); if (has(driver, MODULE_SLOT.getName())) { moduleName = moduleName + ":" + driver.get(MODULE_SLOT.getName()).asString(); } writer.writeAttribute(Driver.Attribute.MODULE.getLocalName(), moduleName); } writeAttributeIfHas(writer, driver, Driver.Attribute.MAJOR_VERSION, DRIVER_MAJOR_VERSION.getName()); writeAttributeIfHas(writer, driver, Driver.Attribute.MINOR_VERSION, DRIVER_MINOR_VERSION.getName()); writeElementIfHas(writer, driver, Driver.Tag.DRIVER_CLASS.getLocalName(), DRIVER_CLASS_NAME.getName()); writeElementIfHas(writer, driver, Driver.Tag.XA_DATASOURCE_CLASS.getLocalName(), DRIVER_XA_DATASOURCE_CLASS_NAME.getName()); writeElementIfHas(writer, driver, Driver.Tag.DATASOURCE_CLASS.getLocalName(), DRIVER_DATASOURCE_CLASS_NAME.getName()); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndElement(); } private void writeDS(XMLExtendedStreamWriter writer, boolean isXADataSource, ModelNode datasources) throws XMLStreamException { for (String dsName : datasources.keys()) { final ModelNode dataSourceNode = datasources.get(dsName); writer.writeStartElement(isXADataSource ? DataSources.Tag.XA_DATASOURCE.getLocalName() : DataSources.Tag.DATASOURCE.getLocalName()); JTA.marshallAsAttribute(dataSourceNode, writer); JNDI_NAME.marshallAsAttribute(dataSourceNode, writer); writer.writeAttribute("pool-name", dsName); ENABLED.marshallAsAttribute(dataSourceNode, writer); USE_JAVA_CONTEXT.marshallAsAttribute(dataSourceNode, writer); SPY.marshallAsAttribute(dataSourceNode, writer); USE_CCM.marshallAsAttribute(dataSourceNode, writer); CONNECTABLE.marshallAsAttribute(dataSourceNode, writer); TRACKING.marshallAsAttribute(dataSourceNode, writer); MCP.marshallAsAttribute(dataSourceNode, writer); ENLISTMENT_TRACE.marshallAsAttribute(dataSourceNode, writer); STATISTICS_ENABLED.marshallAsAttribute(dataSourceNode, writer); if (!isXADataSource) { CONNECTION_URL.marshallAsElement(dataSourceNode, writer); DRIVER_CLASS.marshallAsElement(dataSourceNode, writer); DATASOURCE_CLASS.marshallAsElement(dataSourceNode, writer); if (dataSourceNode.hasDefined(CONNECTION_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(CONNECTION_PROPERTIES.getName()).asPropertyList()) { writeProperty(writer, dataSourceNode, connectionProperty.getName(), connectionProperty .getValue().get("value").asString(), DataSource.Tag.CONNECTION_PROPERTY.getLocalName()); } } } if (isXADataSource) { if (dataSourceNode.hasDefined(XADATASOURCE_PROPERTIES.getName())) { for (Property prop : dataSourceNode.get(XADATASOURCE_PROPERTIES.getName()).asPropertyList()) { writeProperty(writer, dataSourceNode, prop.getName(), prop .getValue().get("value").asString(), XaDataSource.Tag.XA_DATASOURCE_PROPERTY.getLocalName()); } } XA_DATASOURCE_CLASS.marshallAsElement(dataSourceNode, writer); } DATASOURCE_DRIVER.marshallAsElement(dataSourceNode, writer); if (isXADataSource) { URL_DELIMITER.marshallAsElement(dataSourceNode, writer); URL_PROPERTY.marshallAsElement(dataSourceNode, writer); URL_SELECTOR_STRATEGY_CLASS_NAME.marshallAsElement(dataSourceNode, writer); } NEW_CONNECTION_SQL.marshallAsElement(dataSourceNode, writer); TRANSACTION_ISOLATION.marshallAsElement(dataSourceNode, writer); if (!isXADataSource) { URL_DELIMITER.marshallAsElement(dataSourceNode, writer); URL_SELECTOR_STRATEGY_CLASS_NAME.marshallAsElement(dataSourceNode, writer); } boolean poolRequired = INITIAL_POOL_SIZE.isMarshallable(dataSourceNode) || MIN_POOL_SIZE.isMarshallable(dataSourceNode) || MAX_POOL_SIZE.isMarshallable(dataSourceNode) || POOL_PREFILL.isMarshallable(dataSourceNode) || POOL_FAIR.isMarshallable(dataSourceNode) || POOL_USE_STRICT_MIN.isMarshallable(dataSourceNode) || POOL_FLUSH_STRATEGY.isMarshallable(dataSourceNode) || ALLOW_MULTIPLE_USERS.isMarshallable(dataSourceNode) || CONNECTION_LISTENER_CLASS.isMarshallable(dataSourceNode) || CONNECTION_LISTENER_PROPERTIES.isMarshallable(dataSourceNode); if (isXADataSource) { poolRequired = poolRequired || SAME_RM_OVERRIDE.isMarshallable(dataSourceNode) || INTERLEAVING.isMarshallable(dataSourceNode) || NO_TX_SEPARATE_POOL.isMarshallable(dataSourceNode) || PAD_XID.isMarshallable(dataSourceNode) || WRAP_XA_RESOURCE.isMarshallable(dataSourceNode); } final boolean capacityRequired = CAPACITY_INCREMENTER_CLASS.isMarshallable(dataSourceNode) || CAPACITY_INCREMENTER_PROPERTIES.isMarshallable(dataSourceNode) || CAPACITY_DECREMENTER_CLASS.isMarshallable(dataSourceNode) || CAPACITY_DECREMENTER_PROPERTIES.isMarshallable(dataSourceNode); poolRequired = poolRequired || capacityRequired; if (poolRequired) { writer.writeStartElement(isXADataSource ? XaDataSource.Tag.XA_POOL.getLocalName() : DataSource.Tag.POOL .getLocalName()); MIN_POOL_SIZE.marshallAsElement(dataSourceNode, writer); INITIAL_POOL_SIZE.marshallAsElement(dataSourceNode, writer); MAX_POOL_SIZE.marshallAsElement(dataSourceNode, writer); POOL_PREFILL.marshallAsElement(dataSourceNode, writer); POOL_FAIR.marshallAsElement(dataSourceNode, writer); POOL_USE_STRICT_MIN.marshallAsElement(dataSourceNode, writer); POOL_FLUSH_STRATEGY.marshallAsElement(dataSourceNode, writer); ALLOW_MULTIPLE_USERS.marshallAsElement(dataSourceNode, writer); if (dataSourceNode.hasDefined(CONNECTION_LISTENER_CLASS.getName())) { writer.writeStartElement(DsPool.Tag.CONNECTION_LISTENER.getLocalName()); writer.writeAttribute(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName(), dataSourceNode.get(CONNECTION_LISTENER_CLASS.getName()).asString()); if (dataSourceNode.hasDefined(CONNECTION_LISTENER_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(CONNECTION_LISTENER_PROPERTIES.getName()) .asPropertyList()) { writeProperty(writer, dataSourceNode, connectionProperty.getName(), connectionProperty .getValue().asString(), org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY .getLocalName()); } } writer.writeEndElement(); } if (capacityRequired) { writer.writeStartElement(DsPool.Tag.CAPACITY.getLocalName()); if (dataSourceNode.hasDefined(CAPACITY_INCREMENTER_CLASS.getName())) { writer.writeStartElement(Capacity.Tag.INCREMENTER.getLocalName()); CAPACITY_INCREMENTER_CLASS.marshallAsAttribute(dataSourceNode, writer); CAPACITY_INCREMENTER_PROPERTIES.marshallAsElement(dataSourceNode, writer); writer.writeEndElement(); } if (dataSourceNode.hasDefined(CAPACITY_DECREMENTER_CLASS.getName())) { writer.writeStartElement(Capacity.Tag.DECREMENTER.getLocalName()); CAPACITY_DECREMENTER_CLASS.marshallAsAttribute(dataSourceNode, writer); CAPACITY_DECREMENTER_PROPERTIES.marshallAsElement(dataSourceNode, writer); writer.writeEndElement(); } writer.writeEndElement(); } if (isXADataSource) { SAME_RM_OVERRIDE.marshallAsElement(dataSourceNode, writer); INTERLEAVING.marshallAsElement(dataSourceNode, writer); NO_TX_SEPARATE_POOL.marshallAsElement(dataSourceNode, writer); PAD_XID.marshallAsElement(dataSourceNode, writer); WRAP_XA_RESOURCE.marshallAsElement(dataSourceNode, writer); } writer.writeEndElement(); } boolean securityRequired = USERNAME.isMarshallable(dataSourceNode) || PASSWORD.isMarshallable(dataSourceNode) || CREDENTIAL_REFERENCE.isMarshallable(dataSourceNode) || SECURITY_DOMAIN.isMarshallable(dataSourceNode) || ELYTRON_ENABLED.isMarshallable(dataSourceNode) || REAUTH_PLUGIN_CLASSNAME.isMarshallable(dataSourceNode) || REAUTHPLUGIN_PROPERTIES.isMarshallable(dataSourceNode); if (securityRequired) { writer.writeStartElement(DataSource.Tag.SECURITY.getLocalName()); USERNAME.marshallAsElement(dataSourceNode, writer); PASSWORD.marshallAsElement(dataSourceNode, writer); SECURITY_DOMAIN.marshallAsElement(dataSourceNode, writer); CREDENTIAL_REFERENCE.marshallAsElement(dataSourceNode, writer); ELYTRON_ENABLED.marshallAsElement(dataSourceNode, writer); AUTHENTICATION_CONTEXT.marshallAsElement(dataSourceNode, writer); if (dataSourceNode.hasDefined(REAUTH_PLUGIN_CLASSNAME.getName())) { writer.writeStartElement(DsSecurity.Tag.REAUTH_PLUGIN.getLocalName()); writer.writeAttribute( org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName(), dataSourceNode.get(REAUTH_PLUGIN_CLASSNAME.getName()).asString()); if (dataSourceNode.hasDefined(REAUTHPLUGIN_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(REAUTHPLUGIN_PROPERTIES.getName()).asPropertyList()) { writeProperty(writer, dataSourceNode, connectionProperty.getName(), connectionProperty .getValue().asString(), org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY .getLocalName()); } } writer.writeEndElement(); } writer.writeEndElement(); } boolean recoveryRequired = RECOVERY_USERNAME.isMarshallable(dataSourceNode) || RECOVERY_PASSWORD.isMarshallable(dataSourceNode) || RECOVERY_SECURITY_DOMAIN.isMarshallable(dataSourceNode) || RECOVERY_ELYTRON_ENABLED.isMarshallable(dataSourceNode) || RECOVER_PLUGIN_CLASSNAME.isMarshallable(dataSourceNode) || RECOVERY_CREDENTIAL_REFERENCE.isMarshallable(dataSourceNode) || NO_RECOVERY.isMarshallable(dataSourceNode) || RECOVER_PLUGIN_PROPERTIES.isMarshallable(dataSourceNode); if (recoveryRequired && isXADataSource) { writer.writeStartElement(XaDataSource.Tag.RECOVERY.getLocalName()); NO_RECOVERY.marshallAsAttribute(dataSourceNode, writer); if (hasAnyOf(dataSourceNode, RECOVERY_USERNAME, RECOVERY_PASSWORD, RECOVERY_SECURITY_DOMAIN, RECOVERY_ELYTRON_ENABLED, RECOVERY_CREDENTIAL_REFERENCE)) { writer.writeStartElement(Recovery.Tag.RECOVER_CREDENTIAL.getLocalName()); RECOVERY_USERNAME.marshallAsElement(dataSourceNode, writer); RECOVERY_PASSWORD.marshallAsElement(dataSourceNode, writer); RECOVERY_ELYTRON_ENABLED.marshallAsElement(dataSourceNode, writer); RECOVERY_AUTHENTICATION_CONTEXT.marshallAsElement(dataSourceNode, writer); RECOVERY_SECURITY_DOMAIN.marshallAsElement(dataSourceNode, writer); RECOVERY_CREDENTIAL_REFERENCE.marshallAsElement(dataSourceNode, writer); writer.writeEndElement(); } if (hasAnyOf(dataSourceNode, RECOVER_PLUGIN_CLASSNAME)) { writer.writeStartElement(Recovery.Tag.RECOVER_PLUGIN.getLocalName()); writer.writeAttribute( org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName(), dataSourceNode.get(RECOVER_PLUGIN_CLASSNAME.getName()).asString()); if (dataSourceNode.hasDefined(RECOVER_PLUGIN_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(RECOVER_PLUGIN_PROPERTIES.getName()).asPropertyList()) { writeProperty(writer, dataSourceNode, connectionProperty.getName(), connectionProperty .getValue().asString(), org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY .getLocalName()); } } writer.writeEndElement(); } writer.writeEndElement(); } boolean validationRequired = VALID_CONNECTION_CHECKER_CLASSNAME.isMarshallable(dataSourceNode) || VALID_CONNECTION_CHECKER_MODULE.isMarshallable(dataSourceNode) || VALID_CONNECTION_CHECKER_PROPERTIES.isMarshallable(dataSourceNode) || CHECK_VALID_CONNECTION_SQL.isMarshallable(dataSourceNode) || VALIDATE_ON_MATCH.isMarshallable(dataSourceNode) || BACKGROUNDVALIDATION.isMarshallable(dataSourceNode) || BACKGROUNDVALIDATIONMILLIS.isMarshallable(dataSourceNode) || USE_FAST_FAIL.isMarshallable(dataSourceNode) || STALE_CONNECTION_CHECKER_CLASSNAME.isMarshallable(dataSourceNode) || STALE_CONNECTION_CHECKER_MODULE.isMarshallable(dataSourceNode) || STALE_CONNECTION_CHECKER_PROPERTIES.isMarshallable(dataSourceNode) || EXCEPTION_SORTER_CLASSNAME.isMarshallable(dataSourceNode) || EXCEPTION_SORTER_MODULE.isMarshallable(dataSourceNode) || EXCEPTION_SORTER_PROPERTIES.isMarshallable(dataSourceNode); if (validationRequired) { writer.writeStartElement(DataSource.Tag.VALIDATION.getLocalName()); if (dataSourceNode.hasDefined(VALID_CONNECTION_CHECKER_CLASSNAME.getName())) { writer.writeStartElement(Validation.Tag.VALID_CONNECTION_CHECKER.getLocalName()); writer.writeAttribute( org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName(), dataSourceNode.get(VALID_CONNECTION_CHECKER_CLASSNAME.getName()).asString()); if (dataSourceNode.hasDefined(VALID_CONNECTION_CHECKER_MODULE.getName())) { writer.writeAttribute( org.jboss.jca.common.api.metadata.common.Extension.Attribute.MODULE.getLocalName(), dataSourceNode.get(VALID_CONNECTION_CHECKER_MODULE.getName()).asString()); } if (dataSourceNode.hasDefined(VALID_CONNECTION_CHECKER_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(VALID_CONNECTION_CHECKER_PROPERTIES.getName()) .asPropertyList()) { writeProperty(writer, dataSourceNode, connectionProperty.getName(), connectionProperty .getValue().asString(), org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY .getLocalName()); } } writer.writeEndElement(); } CHECK_VALID_CONNECTION_SQL.marshallAsElement(dataSourceNode, writer); VALIDATE_ON_MATCH.marshallAsElement(dataSourceNode, writer); BACKGROUNDVALIDATION.marshallAsElement(dataSourceNode, writer); BACKGROUNDVALIDATIONMILLIS.marshallAsElement(dataSourceNode, writer); USE_FAST_FAIL.marshallAsElement(dataSourceNode, writer); if (dataSourceNode.hasDefined(STALE_CONNECTION_CHECKER_CLASSNAME.getName())) { writer.writeStartElement(Validation.Tag.STALE_CONNECTION_CHECKER.getLocalName()); writer.writeAttribute(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName(), dataSourceNode.get(STALE_CONNECTION_CHECKER_CLASSNAME.getName()).asString()); if (dataSourceNode.hasDefined(STALE_CONNECTION_CHECKER_MODULE.getName())) { writer.writeAttribute( org.jboss.jca.common.api.metadata.common.Extension.Attribute.MODULE.getLocalName(), dataSourceNode.get(STALE_CONNECTION_CHECKER_MODULE.getName()).asString()); } if (dataSourceNode.hasDefined(STALE_CONNECTION_CHECKER_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(STALE_CONNECTION_CHECKER_PROPERTIES.getName()) .asPropertyList()) { writeProperty(writer, dataSourceNode, connectionProperty.getName(), connectionProperty .getValue().asString(), org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY .getLocalName()); } } writer.writeEndElement(); } if (dataSourceNode.hasDefined(EXCEPTION_SORTER_CLASSNAME.getName())) { writer.writeStartElement(Validation.Tag.EXCEPTION_SORTER.getLocalName()); writer.writeAttribute( org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName(), dataSourceNode.get(EXCEPTION_SORTER_CLASSNAME.getName()).asString()); if (dataSourceNode.hasDefined(EXCEPTION_SORTER_MODULE.getName())) { writer.writeAttribute( org.jboss.jca.common.api.metadata.common.Extension.Attribute.MODULE.getLocalName(), dataSourceNode.get(EXCEPTION_SORTER_MODULE.getName()).asString()); } if (dataSourceNode.hasDefined(EXCEPTION_SORTER_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(EXCEPTION_SORTER_PROPERTIES.getName()) .asPropertyList()) { writeProperty(writer, dataSourceNode, connectionProperty.getName(), connectionProperty .getValue().asString(), org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY .getLocalName()); } } writer.writeEndElement(); } writer.writeEndElement(); } boolean timeoutRequired = BLOCKING_TIMEOUT_WAIT_MILLIS.isMarshallable(dataSourceNode) || IDLETIMEOUTMINUTES.isMarshallable(dataSourceNode) || SET_TX_QUERY_TIMEOUT.isMarshallable(dataSourceNode) || QUERY_TIMEOUT.isMarshallable(dataSourceNode) || USE_TRY_LOCK.isMarshallable(dataSourceNode) || ALLOCATION_RETRY.isMarshallable(dataSourceNode) || ALLOCATION_RETRY_WAIT_MILLIS.isMarshallable(dataSourceNode) || XA_RESOURCE_TIMEOUT.isMarshallable(dataSourceNode); if (timeoutRequired) { writer.writeStartElement(DataSource.Tag.TIMEOUT.getLocalName()); SET_TX_QUERY_TIMEOUT.marshallAsElement(dataSourceNode, writer); BLOCKING_TIMEOUT_WAIT_MILLIS.marshallAsElement(dataSourceNode, writer); IDLETIMEOUTMINUTES.marshallAsElement(dataSourceNode, writer); QUERY_TIMEOUT.marshallAsElement(dataSourceNode, writer); USE_TRY_LOCK.marshallAsElement(dataSourceNode, writer); ALLOCATION_RETRY.marshallAsElement(dataSourceNode, writer); ALLOCATION_RETRY_WAIT_MILLIS.marshallAsElement(dataSourceNode, writer); XA_RESOURCE_TIMEOUT.marshallAsElement(dataSourceNode, writer); writer.writeEndElement(); } boolean statementRequired = hasAnyOf(dataSourceNode, TRACK_STATEMENTS, PREPARED_STATEMENTS_CACHE_SIZE, SHARE_PREPARED_STATEMENTS); if (statementRequired) { writer.writeStartElement(DataSource.Tag.STATEMENT.getLocalName()); TRACK_STATEMENTS.marshallAsElement(dataSourceNode, writer); PREPARED_STATEMENTS_CACHE_SIZE.marshallAsElement(dataSourceNode, writer); SHARE_PREPARED_STATEMENTS.marshallAsElement(dataSourceNode, writer); writer.writeEndElement(); } writer.writeEndElement(); } } private void writeAttributeIfHas(final XMLExtendedStreamWriter writer, final ModelNode node, final Driver.Attribute attr, final String identifier) throws XMLStreamException { if (has(node, identifier)) { writer.writeAttribute(attr.getLocalName(), node.get(identifier).asString()); } } private void writeProperty(XMLExtendedStreamWriter writer, ModelNode node, String name, String value, String localName) throws XMLStreamException { writer.writeStartElement(localName); writer.writeAttribute("name", name); writer.writeCharacters(value); writer.writeEndElement(); } private void writeElementIfHas(XMLExtendedStreamWriter writer, ModelNode node, String localName, String identifier) throws XMLStreamException { if (has(node, identifier)) { writer.writeStartElement(localName); String content = node.get(identifier).asString(); if (content.indexOf('\n') > -1) { writer.writeCharacters(content); } else { // Use the method where staxmapper won't add new lines char[] chars = content.toCharArray(); writer.writeCharacters(chars, 0, chars.length); } writer.writeEndElement(); } } private boolean hasAnyOf(ModelNode node, SimpleAttributeDefinition... names) { for (SimpleAttributeDefinition current : names) { if (has(node, current.getName())) { return true; } } return false; } private boolean has(ModelNode node, String name) { return node.has(name) && node.get(name).isDefined(); } @Override public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException { final ModelNode address = new ModelNode(); address.add(ModelDescriptionConstants.SUBSYSTEM, DATASOURCES); address.protect(); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).set(address); list.add(subsystem); try { String localName = null; localName = reader.getLocalName(); Element element = Element.forName(reader.getLocalName()); SUBSYSTEM_DATASOURCES_LOGGER.tracef("%s -> %s", localName, element); switch (element) { case SUBSYSTEM: { final DsParser parser = new DsParser(); parser.parse(reader, list, address); requireNoContent(reader); break; } } } catch (Exception e) { throw new XMLStreamException(e); } } } }
43,693
63.445428
172
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/JdbcDriverDefinition.java
/* * * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. * / */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_CLASS_INFO; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.JDBC_DRIVER_NAME; import java.util.List; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReadResourceNameOperationStepHandler; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.access.constraint.ApplicationTypeConfig; import org.jboss.as.controller.access.management.AccessConstraintDefinition; import org.jboss.as.controller.access.management.ApplicationTypeAccessConstraintDefinition; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Stefano Maestri */ public class JdbcDriverDefinition extends SimpleResourceDefinition { protected static final PathElement PATH_DRIVER = PathElement.pathElement(JDBC_DRIVER_NAME); private final List<AccessConstraintDefinition> accessConstraints; JdbcDriverDefinition() { super(PATH_DRIVER, DataSourcesExtension.getResourceDescriptionResolver(JDBC_DRIVER_NAME), JdbcDriverAdd.INSTANCE, JdbcDriverRemove.INSTANCE); ApplicationTypeConfig atc = new ApplicationTypeConfig(DataSourcesExtension.SUBSYSTEM_NAME, JDBC_DRIVER_NAME); accessConstraints = new ApplicationTypeAccessConstraintDefinition(atc).wrapAsList(); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { for (AttributeDefinition attribute : Constants.JDBC_DRIVER_ATTRIBUTES) { resourceRegistration.registerReadOnlyAttribute(attribute, null); } resourceRegistration.registerReadOnlyAttribute(DRIVER_NAME, ReadResourceNameOperationStepHandler.INSTANCE); if (resourceRegistration.getProcessType().isServer()) { resourceRegistration.registerReadOnlyAttribute(DATASOURCE_CLASS_INFO, GetDataSourceClassInfoOperationHandler.INSTANCE); } } @Override public List<AccessConstraintDefinition> getAccessConstraints() { return accessConstraints; } }
3,365
43.289474
131
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/JdbcDriverRemove.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MAJOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MINOR_VERSION; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_MODULE_NAME; import static org.jboss.as.connector.subsystems.datasources.Constants.DRIVER_XA_DATASOURCE_CLASS_NAME; import static org.jboss.as.connector.subsystems.datasources.JdbcDriverAdd.startDriverServices; import java.lang.reflect.Constructor; import java.sql.Driver; import java.util.ServiceLoader; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.AbstractRemoveStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.jboss.modules.Module; import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoadException; import org.jboss.modules.ModuleNotFoundException; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; import org.jboss.msc.service.ServiceTarget; /** * Operation handler responsible for removing a jdbc driver. * * @author John Bailey */ public class JdbcDriverRemove extends AbstractRemoveStepHandler { static final JdbcDriverRemove INSTANCE = new JdbcDriverRemove(); protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final String driverName = context.getCurrentAddressValue(); final ServiceRegistry registry = context.getServiceRegistry(true); ServiceName jdbcServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")); ServiceController<?> jdbcServiceController = registry.getService(jdbcServiceName); context.removeService(jdbcServiceController); } protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) { final String driverName = context.getCurrentAddressValue(); final String moduleName = model.require(DRIVER_MODULE_NAME.getName()).asString(); final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? model.get(DRIVER_MAJOR_VERSION.getName()).asInt() : null; final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? model.get(DRIVER_MINOR_VERSION.getName()).asInt() : null; final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? model.get(DRIVER_CLASS_NAME.getName()).asString() : null; final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).asString() : null; final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? model.get( DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).asString() : null; final ServiceTarget target = context.getServiceTarget(); final ModuleIdentifier moduleId; final Module module; try { moduleId = ModuleIdentifier.fromString(moduleName); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) { context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage())); return; } catch (ModuleLoadException e) { context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName)); return; } if (driverClassName == null) { final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class); if (serviceLoader != null) for (Driver driver : serviceLoader) { startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName); } } else { try { final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName) .asSubclass(Driver.class); final Constructor<? extends Driver> constructor = driverClass.getConstructor(); final Driver driver = constructor.newInstance(); startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName); } catch (Exception e) { SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e); } } } }
6,111
52.147826
170
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/DataSourceConfigService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import java.util.Map; import java.util.function.Supplier; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> * @author @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public class DataSourceConfigService implements Service<ModifiableDataSource> { public static final ServiceName SERVICE_NAME_BASE = ServiceName.JBOSS.append("data-source-config"); private final ModifiableDataSource dataSourceConfig; private final Map<String, Supplier<String>> connectionProperties; public DataSourceConfigService(final ModifiableDataSource dataSourceConfig, final Map<String, Supplier<String>> connectionProperties) { this.dataSourceConfig = dataSourceConfig; this.connectionProperties = connectionProperties; } public void start(final StartContext startContext) throws StartException { for (Map.Entry<String, Supplier<String>> connectionProperty : connectionProperties.entrySet()) { dataSourceConfig.addConnectionProperty(connectionProperty.getKey(), connectionProperty.getValue().get()); } } public void stop(final StopContext stopContext) { } @Override public ModifiableDataSource getValue() { return dataSourceConfig; } }
2,556
38.953125
139
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/datasources/XaDataSourcePropertyRemove.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.datasources; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.controller.AbstractRemoveStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceName; /** * Operation handler responsible for removing a (XA)DataSource. * * @author Stefano Maestrioperation2.get(OP).set("write-attribute"); */ public class XaDataSourcePropertyRemove extends AbstractRemoveStepHandler { public static final XaDataSourcePropertyRemove INSTANCE = new XaDataSourcePropertyRemove(); @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { if (context.isResourceServiceRestartAllowed()) { final ModelNode address = operation.require(OP_ADDR); final PathAddress path = PathAddress.pathAddress(address); final String jndiName = path.getElement(path.size() - 2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName configPropertyServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(jndiName). append("xa-datasource-properties").append(configPropertyName); context.removeService(configPropertyServiceName); } else { context.reloadRequired(); } } }
2,680
40.246154
131
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/Constants.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.metadata.api.common.Security; import org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.AttributeMarshaller; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.ObjectListAttributeDefinition; import org.jboss.as.controller.ObjectTypeAttributeDefinition; import org.jboss.as.controller.PropertiesAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.StringListAttributeDefinition; import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition; import org.jboss.as.controller.client.helpers.MeasurementUnit; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.operations.validation.EnumValidator; import org.jboss.as.controller.operations.validation.StringLengthValidator; import org.jboss.as.controller.security.CredentialReference; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.dmr.ValueExpression; import org.jboss.jca.common.api.metadata.Defaults; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum; import org.jboss.jca.common.api.metadata.common.XaPool; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.TimeOut; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition; /** * Defines contants and attributes for resourceadapters subsystem. * * @author @author <a href="mailto:[email protected]">Stefano * Maestri</a> * @author Flavia Rainone */ public class Constants { private static final Boolean ELYTRON_MANAGED_SECURITY = Boolean.FALSE; private static final ModelVersion ELYTRON_BY_DEFAULT_VERSION = ModelVersion.create(6, 1, 0); public static final String RESOURCEADAPTER_NAME = "resource-adapter"; public static final String WORKMANAGER_NAME = "workmanager"; public static final String DISTRIBUTED_WORKMANAGER_NAME = "distributed-workmanager"; static final String RESOURCEADAPTERS_NAME = "resource-adapters"; public static final String IRONJACAMAR_NAME = "ironjacamar"; public static final String STATISTICS_NAME = "statistics"; public static final String CONNECTIONDEFINITIONS_NAME = "connection-definitions"; private static final String CLASS_NAME_NAME = "class-name"; static final String POOL_NAME_NAME = "pool-name"; private static final String ENABLED_NAME = "enabled"; private static final String CONNECTABLE_NAME = "connectable"; private static final String TRACKING_NAME = "tracking"; private static final String ALLOCATION_RETRY_NAME = "allocation-retry"; private static final String ALLOCATION_RETRY_WAIT_MILLIS_NAME = "allocation-retry-wait-millis"; private static final String XA_RESOURCE_TIMEOUT_NAME = "xa-resource-timeout"; private static final String USETRYLOCK_NAME = "use-try-lock"; private static final String SECURITY_DOMAIN_AND_APPLICATION_NAME = "security-domain-and-application"; private static final String SECURITY_DOMAIN_NAME = "security-domain"; private static final String ELYTRON_ENABLED_NAME = "elytron-enabled"; private static final String AUTHENTICATION_CONTEXT_NAME = "authentication-context"; private static final String AUTHENTICATION_CONTEXT_AND_APPLICATION_NAME = "authentication-context-and-application"; private static final String APPLICATION_NAME = "security-application"; private static final String USE_CCM_NAME = "use-ccm"; private static final String SHARABLE_NAME = "sharable"; private static final String ENLISTMENT_NAME = "enlistment"; private static final String ENLISTMENT_TRACE_NAME = "enlistment-trace"; private static final String MCP_NAME = "mcp"; private static final String CONFIG_PROPERTIES_NAME = "config-properties"; private static final String CONFIG_PROPERTY_VALUE_NAME = "value"; private static final String ARCHIVE_NAME = "archive"; private static final String MODULE_NAME = "module"; private static final String BOOTSTRAPCONTEXT_NAME = "bootstrap-context"; private static final String TRANSACTIONSUPPORT_NAME = "transaction-support"; private static final String WM_SECURITY_NAME = "wm-security"; private static final String WM_SECURITY_MAPPING_REQUIRED_NAME = "wm-security-mapping-required"; private static final String WM_SECURITY_DOMAIN_NAME = "wm-security-domain"; private static final String WM_ELYTRON_SECURITY_DOMAIN_NAME = "wm-elytron-security-domain"; private static final String WM_SECURITY_DEFAULT_PRINCIPAL_NAME = "wm-security-default-principal"; private static final String WM_SECURITY_DEFAULT_GROUP_NAME = "wm-security-default-group"; private static final String WM_SECURITY_DEFAULT_GROUPS_NAME = "wm-security-default-groups"; private static final String WM_SECURITY_MAPPING_FROM_NAME = "from"; private static final String WM_SECURITY_MAPPING_TO_NAME = "to"; private static final String WM_SECURITY_MAPPING_GROUP_NAME = "wm-security-mapping-group"; private static final String WM_SECURITY_MAPPING_GROUPS_NAME = "wm-security-mapping-groups"; private static final String WM_SECURITY_MAPPING_USER_NAME = "wm-security-mapping-user"; private static final String WM_SECURITY_MAPPING_USERS_NAME = "wm-security-mapping-users"; private static final String BEANVALIDATIONGROUPS_NAME = "beanvalidationgroups"; public static final String ADMIN_OBJECTS_NAME = "admin-objects"; private static final String INTERLEAVING_NAME = "interleaving"; private static final String NOTXSEPARATEPOOL_NAME = "no-tx-separate-pool"; private static final String PAD_XID_NAME = "pad-xid"; private static final String SAME_RM_OVERRIDE_NAME = "same-rm-override"; private static final String WRAP_XA_RESOURCE_NAME = "wrap-xa-resource"; private static final String RECOVERY_USERNAME_NAME = "recovery-username"; private static final String RECOVERY_PASSWORD_NAME = "recovery-password"; private static final String RECOVERY_CREDENTIAL_REFERENCE_NAME = "recovery-" + CredentialReference.CREDENTIAL_REFERENCE; private static final String RECOVERY_SECURITY_DOMAIN_NAME = "recovery-security-domain"; private static final String RECOVERY_ELYTRON_ENABLED_NAME = "recovery-elytron-enabled"; private static final String RECOVERY_AUTHENTICATION_CONTEXT_NAME = "recovery-authentication-context"; private static final String RECOVER_PLUGIN_CLASSNAME_NAME = "recovery-plugin-class-name"; private static final String RECOVER_PLUGIN_PROPERTIES_NAME = "recovery-plugin-properties"; private static final String NO_RECOVERY_NAME = "no-recovery"; public static final String ACTIVATE = "activate"; public static final String FLUSH_ALL_CONNECTION_IN_POOL = "flush-all-connection-in-pool"; public static final String FLUSH_IDLE_CONNECTION_IN_POOL = "flush-idle-connection-in-pool"; public static final String FLUSH_INVALID_CONNECTION_IN_POOL = "flush-invalid-connection-in-pool"; public static final String FLUSH_GRACEFULLY_CONNECTION_IN_POOL = "flush-gracefully-connection-in-pool"; public static final String TEST_CONNECTION_IN_POOL = "test-connection-in-pool"; public static final String CLEAR_STATISTICS = "clear-statistics"; public static final String REPORT_DIRECTORY_NAME = "report-directory"; static final SimpleAttributeDefinition CLASS_NAME = new SimpleAttributeDefinitionBuilder(CLASS_NAME_NAME, ModelType.STRING, false) .setXmlName(ConnectionDefinition.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); public static final SimpleAttributeDefinition CONFIG_PROPERTIES = new SimpleAttributeDefinitionBuilder(CONFIG_PROPERTIES_NAME, ModelType.STRING, true) .setXmlName(ConnectionDefinition.Tag.CONFIG_PROPERTY.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static final SimpleAttributeDefinition CONFIG_PROPERTY_VALUE = new SimpleAttributeDefinitionBuilder(CONFIG_PROPERTY_VALUE_NAME, ModelType.STRING, true) .setXmlName(ConnectionDefinition.Tag.CONFIG_PROPERTY.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static final SimpleAttributeDefinition ARCHIVE = SimpleAttributeDefinitionBuilder.create(ARCHIVE_NAME, ModelType.STRING) .setXmlName(Activation.Tag.ARCHIVE.getLocalName()) .setRequired(false) .setAllowExpression(false) .setMeasurementUnit(MeasurementUnit.NONE) .setAttributeMarshaller(new AttributeMarshaller() { @Override public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { if (resourceModel.hasDefined(attribute.getName())) { writer.writeStartElement(attribute.getXmlName()); String archive = resourceModel.get(attribute.getName()).asString(); writer.writeCharacters(archive); writer.writeEndElement(); } } }) .setAlternatives(MODULE_NAME) .setRestartAllServices() .build(); static final SimpleAttributeDefinition MODULE = SimpleAttributeDefinitionBuilder.create(MODULE_NAME, ModelType.STRING) .setXmlName(AS7ResourceAdapterTags.MODULE.getLocalName()) .setRequired(false) .setAllowExpression(false) .setMeasurementUnit(MeasurementUnit.NONE) .setAttributeMarshaller(new AttributeMarshaller() { @Override public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { if (resourceModel.hasDefined(attribute.getName())) { writer.writeStartElement(attribute.getXmlName()); String module = resourceModel.get(attribute.getName()).asString(); int separatorIndex = module.indexOf(":"); if (separatorIndex != -1) { writer.writeAttribute("slot", module.substring(separatorIndex + 1)); module = module.substring(0, separatorIndex); } else { if (marshallDefault) { writer.writeAttribute("slot", "main"); } } writer.writeAttribute("id", module); writer.writeEndElement(); } } }) .setAlternatives(ARCHIVE_NAME) .setRestartAllServices() .build(); static final SimpleAttributeDefinition BOOTSTRAP_CONTEXT = new SimpleAttributeDefinitionBuilder(BOOTSTRAPCONTEXT_NAME, ModelType.STRING, true) .setXmlName(Activation.Tag.BOOTSTRAP_CONTEXT.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static final SimpleAttributeDefinition TRANSACTION_SUPPORT = new SimpleAttributeDefinitionBuilder(TRANSACTIONSUPPORT_NAME, ModelType.STRING, true) .setXmlName(Activation.Tag.TRANSACTION_SUPPORT.getLocalName()) .setAllowExpression(true) .setValidator(EnumValidator.create(TransactionSupportEnum.class)) .setRestartAllServices() .build(); static SimpleAttributeDefinition STATISTICS_ENABLED = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.STATISTICS_ENABLED, ModelType.BOOLEAN) .setDefaultValue(ModelNode.FALSE) .setRequired(false) .setAllowExpression(true) .setRestartAllServices() .build(); static final SimpleAttributeDefinition WM_SECURITY = new SimpleAttributeDefinitionBuilder(WM_SECURITY_NAME, ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setXmlName(ResourceAdapterParser.Attribute.ENABLED.getLocalName()) .setRestartAllServices() .build(); static final SimpleAttributeDefinition WM_SECURITY_MAPPING_REQUIRED = new SimpleAttributeDefinitionBuilder(WM_SECURITY_MAPPING_REQUIRED_NAME, ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(ModelNode.FALSE) .setXmlName(WorkManagerSecurity.Tag.MAPPING_REQUIRED.getLocalName()) .setRestartAllServices() .build(); static final SimpleAttributeDefinition WM_SECURITY_DOMAIN = new SimpleAttributeDefinitionBuilder(WM_SECURITY_DOMAIN_NAME, ModelType.STRING, true) .setAllowExpression(true) .setDefaultValue(new ModelNode("other")) .setXmlName(WorkManagerSecurity.Tag.DOMAIN.getLocalName()) .setAlternatives(WM_ELYTRON_SECURITY_DOMAIN_NAME) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static final SimpleAttributeDefinition WM_ELYTRON_SECURITY_DOMAIN = new SimpleAttributeDefinitionBuilder(WM_ELYTRON_SECURITY_DOMAIN_NAME, ModelType.STRING, true) .setAllowExpression(true) .setXmlName(WorkManagerSecurity.Tag.ELYTRON_SECURITY_DOMAIN.getLocalName()) .setAlternatives(WM_SECURITY_DOMAIN_NAME) .setAccessConstraints(SensitiveTargetAccessConstraintDefinition.ELYTRON_SECURITY_DOMAIN_REF) .setRestartAllServices() .build(); static final SimpleAttributeDefinition WM_SECURITY_DEFAULT_PRINCIPAL = new SimpleAttributeDefinitionBuilder(WM_SECURITY_DEFAULT_PRINCIPAL_NAME, ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setXmlName(WorkManagerSecurity.Tag.DEFAULT_PRINCIPAL.getLocalName()) .setRestartAllServices() .build(); static final StringListAttributeDefinition WM_SECURITY_DEFAULT_GROUPS = (new StringListAttributeDefinition.Builder(WM_SECURITY_DEFAULT_GROUPS_NAME)) .setXmlName(WorkManagerSecurity.Tag.DEFAULT_GROUPS.getLocalName()) .setRequired(false) .setAllowExpression(true) .setElementValidator(new StringLengthValidator(1, false, true)) .setRestartAllServices() .build(); static final SimpleAttributeDefinition WM_SECURITY_DEFAULT_GROUP = new SimpleAttributeDefinitionBuilder(WM_SECURITY_DEFAULT_GROUP_NAME, ModelType.STRING, true) .setXmlName(WorkManagerSecurity.Tag.GROUP.getLocalName()) .setAllowExpression(true) .build(); static final SimpleAttributeDefinition WM_SECURITY_MAPPING_FROM = new SimpleAttributeDefinitionBuilder(WM_SECURITY_MAPPING_FROM_NAME, ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setXmlName(WorkManagerSecurity.Attribute.FROM.getLocalName()) .build(); static final SimpleAttributeDefinition WM_SECURITY_MAPPING_TO = new SimpleAttributeDefinitionBuilder(WM_SECURITY_MAPPING_TO_NAME, ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setXmlName(WorkManagerSecurity.Attribute.TO.getLocalName()) .build(); static final ObjectTypeAttributeDefinition WM_SECURITY_MAPPING_GROUP = ObjectTypeAttributeDefinition.Builder.of(WM_SECURITY_MAPPING_GROUP_NAME, WM_SECURITY_MAPPING_FROM, WM_SECURITY_MAPPING_TO).build(); static final ObjectListAttributeDefinition WM_SECURITY_MAPPING_GROUPS = ObjectListAttributeDefinition.Builder.of(WM_SECURITY_MAPPING_GROUPS_NAME, WM_SECURITY_MAPPING_GROUP) .setRequired(false) .setRestartAllServices() .build(); static final ObjectTypeAttributeDefinition WM_SECURITY_MAPPING_USER = ObjectTypeAttributeDefinition.Builder.of(WM_SECURITY_MAPPING_USER_NAME, WM_SECURITY_MAPPING_FROM, WM_SECURITY_MAPPING_TO).build(); static final ObjectListAttributeDefinition WM_SECURITY_MAPPING_USERS = ObjectListAttributeDefinition.Builder.of(WM_SECURITY_MAPPING_USERS_NAME, WM_SECURITY_MAPPING_USER) .setRequired(false) .setRestartAllServices() .build(); static final StringListAttributeDefinition BEANVALIDATION_GROUPS = (new StringListAttributeDefinition.Builder(BEANVALIDATIONGROUPS_NAME)) .setXmlName(Activation.Tag.BEAN_VALIDATION_GROUP.getLocalName()) .setRequired(false) .setAllowExpression(true) .setElementValidator(new StringLengthValidator(1, false, true)) .setRestartAllServices() .build(); static final SimpleAttributeDefinition BEANVALIDATIONGROUP = new SimpleAttributeDefinitionBuilder(BEANVALIDATIONGROUPS_NAME, ModelType.STRING, true) .setXmlName(Activation.Tag.BEAN_VALIDATION_GROUP.getLocalName()) .setAllowExpression(true) .build(); static SimpleAttributeDefinition ENABLED = new SimpleAttributeDefinitionBuilder(ENABLED_NAME, ModelType.BOOLEAN, true) .setXmlName(DataSource.Attribute.ENABLED.getLocalName()) .setDefaultValue(new ModelNode(Defaults.ENABLED)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition CONNECTABLE = new SimpleAttributeDefinitionBuilder(CONNECTABLE_NAME, ModelType.BOOLEAN) .setXmlName(DataSource.Attribute.CONNECTABLE.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(Defaults.CONNECTABLE)) .setRequired(false) .setRestartAllServices() .build(); static SimpleAttributeDefinition TRACKING = new SimpleAttributeDefinitionBuilder(TRACKING_NAME, ModelType.BOOLEAN) .setXmlName(DataSource.Attribute.TRACKING.getLocalName()) .setAllowExpression(true) .setRequired(false) .setRestartAllServices() .build(); static SimpleAttributeDefinition SECURITY_DOMAIN = new SimpleAttributeDefinitionBuilder(SECURITY_DOMAIN_NAME, ModelType.STRING, true) .setXmlName(Security.Tag.SECURITY_DOMAIN.getLocalName()) .setAllowExpression(true) .setAlternatives(SECURITY_DOMAIN_AND_APPLICATION_NAME, APPLICATION_NAME, AUTHENTICATION_CONTEXT_NAME, AUTHENTICATION_CONTEXT_AND_APPLICATION_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SECURITY_DOMAIN_REF) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static final SimpleAttributeDefinition SECURITY_DOMAIN_AND_APPLICATION = new SimpleAttributeDefinitionBuilder(SECURITY_DOMAIN_AND_APPLICATION_NAME, ModelType.STRING, true) .setXmlName(Security.Tag.SECURITY_DOMAIN_AND_APPLICATION.getLocalName()) .setAllowExpression(true) .setAlternatives(SECURITY_DOMAIN_NAME, APPLICATION_NAME, AUTHENTICATION_CONTEXT_NAME, AUTHENTICATION_CONTEXT_AND_APPLICATION_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SECURITY_DOMAIN_REF) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static SimpleAttributeDefinition ELYTRON_ENABLED = new SimpleAttributeDefinitionBuilder(ELYTRON_ENABLED_NAME, ModelType.BOOLEAN, true) .setXmlName(Security.Tag.ELYTRON_ENABLED.getLocalName()) .setAllowExpression(true) .setDefaultValue(new ModelNode(ELYTRON_MANAGED_SECURITY)) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setNullSignificant(false) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static SimpleAttributeDefinition AUTHENTICATION_CONTEXT = new SimpleAttributeDefinitionBuilder(AUTHENTICATION_CONTEXT_NAME, ModelType.STRING, true) .setXmlName(Security.Tag.AUTHENTICATION_CONTEXT.getLocalName()) .setAllowExpression(false) .setAlternatives(SECURITY_DOMAIN_NAME, SECURITY_DOMAIN_AND_APPLICATION_NAME, APPLICATION_NAME, AUTHENTICATION_CONTEXT_AND_APPLICATION_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.AUTHENTICATION_CLIENT_REF) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setRestartAllServices() .build(); static final SimpleAttributeDefinition AUTHENTICATION_CONTEXT_AND_APPLICATION = new SimpleAttributeDefinitionBuilder(AUTHENTICATION_CONTEXT_AND_APPLICATION_NAME, ModelType.STRING, true) .setXmlName(Security.Tag.AUTHENTICATION_CONTEXT_AND_APPLICATION.getLocalName()) .setAllowExpression(false) .setAlternatives(SECURITY_DOMAIN_NAME, SECURITY_DOMAIN_AND_APPLICATION_NAME, APPLICATION_NAME, AUTHENTICATION_CONTEXT_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.AUTHENTICATION_CLIENT_REF) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setRestartAllServices() .build(); static final SimpleAttributeDefinition APPLICATION = new SimpleAttributeDefinitionBuilder(APPLICATION_NAME, ModelType.BOOLEAN) .setXmlName(Security.Tag.APPLICATION.getLocalName()) .setDefaultValue(new ModelNode(Defaults.APPLICATION_MANAGED_SECURITY)) .setAllowExpression(true) .setRequired(false) .setMeasurementUnit(MeasurementUnit.NONE) .setAlternatives(SECURITY_DOMAIN_NAME, SECURITY_DOMAIN_AND_APPLICATION_NAME, AUTHENTICATION_CONTEXT_NAME, AUTHENTICATION_CONTEXT_AND_APPLICATION_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SECURITY_DOMAIN_REF) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static SimpleAttributeDefinition ALLOCATION_RETRY = new SimpleAttributeDefinitionBuilder(ALLOCATION_RETRY_NAME, ModelType.INT, true) .setXmlName(TimeOut.Tag.ALLOCATION_RETRY.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition ALLOCATION_RETRY_WAIT_MILLIS = new SimpleAttributeDefinitionBuilder(ALLOCATION_RETRY_WAIT_MILLIS_NAME, ModelType.LONG, true) .setXmlName(TimeOut.Tag.ALLOCATION_RETRY_WAIT_MILLIS.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition USE_CCM = new SimpleAttributeDefinitionBuilder(USE_CCM_NAME, ModelType.BOOLEAN, true) .setXmlName(DataSource.Attribute.USE_CCM.getLocalName()) .setDefaultValue(new ModelNode(Defaults.USE_CCM)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition SHARABLE = new SimpleAttributeDefinitionBuilder(SHARABLE_NAME, ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(new ModelNode(Defaults.SHARABLE)) .setXmlName(ConnectionDefinition.Attribute.SHARABLE.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition ENLISTMENT = new SimpleAttributeDefinitionBuilder(ENLISTMENT_NAME, ModelType.BOOLEAN) .setAllowExpression(true) .setRequired(false) .setDefaultValue(new ModelNode(Defaults.ENLISTMENT)) .setXmlName(ConnectionDefinition.Attribute.ENLISTMENT.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition ENLISTMENT_TRACE = new SimpleAttributeDefinitionBuilder(ENLISTMENT_TRACE_NAME, ModelType.BOOLEAN) .setAllowExpression(true) .setDefaultValue(ModelNode.FALSE) .setRequired(false) .setXmlName(ConnectionDefinition.Attribute.ENLISTMENT_TRACE.getLocalName()) .build(); static SimpleAttributeDefinition MCP = new SimpleAttributeDefinitionBuilder(MCP_NAME, ModelType.STRING) .setAllowExpression(true) .setRequired(false) .setXmlName(ConnectionDefinition.Attribute.MCP.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition INTERLEAVING = new SimpleAttributeDefinitionBuilder(INTERLEAVING_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.INTERLEAVING.getLocalName()) .setDefaultValue(new ModelNode(Defaults.INTERLEAVING)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition NOTXSEPARATEPOOL = new SimpleAttributeDefinitionBuilder(NOTXSEPARATEPOOL_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.NO_TX_SEPARATE_POOLS.getLocalName()) .setDefaultValue(new ModelNode(Defaults.NO_TX_SEPARATE_POOL)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition PAD_XID = new SimpleAttributeDefinitionBuilder(PAD_XID_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.PAD_XID.getLocalName()) .setDefaultValue(new ModelNode(Defaults.PAD_XID)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition SAME_RM_OVERRIDE = new SimpleAttributeDefinitionBuilder(SAME_RM_OVERRIDE_NAME, ModelType.BOOLEAN) .setRequired(false) .setAllowExpression(true) .setXmlName(XaPool.Tag.IS_SAME_RM_OVERRIDE.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition WRAP_XA_RESOURCE = new SimpleAttributeDefinitionBuilder(WRAP_XA_RESOURCE_NAME, ModelType.BOOLEAN, true) .setXmlName(XaPool.Tag.WRAP_XA_RESOURCE.getLocalName()) .setDefaultValue(new ModelNode(Defaults.WRAP_XA_RESOURCE)) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition XA_RESOURCE_TIMEOUT = new SimpleAttributeDefinitionBuilder(XA_RESOURCE_TIMEOUT_NAME, ModelType.INT, true) .setXmlName(TimeOut.Tag.XA_RESOURCE_TIMEOUT.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_USERNAME = new SimpleAttributeDefinitionBuilder(RECOVERY_USERNAME_NAME, ModelType.STRING, true) .setXmlName(Credential.Tag.USER_NAME.getLocalName()) .setDefaultValue(new ModelNode()) .setAllowExpression(true) .setMeasurementUnit(MeasurementUnit.NONE) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_PASSWORD = new SimpleAttributeDefinitionBuilder(RECOVERY_PASSWORD_NAME, ModelType.STRING, true) .setXmlName(Credential.Tag.PASSWORD.getLocalName()) .setDefaultValue(new ModelNode()) .setAllowExpression(true) .setMeasurementUnit(MeasurementUnit.NONE) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .addAlternatives(RECOVERY_CREDENTIAL_REFERENCE_NAME) .setRestartAllServices() .build(); static ObjectTypeAttributeDefinition RECOVERY_CREDENTIAL_REFERENCE = CredentialReference.getAttributeBuilder(RECOVERY_CREDENTIAL_REFERENCE_NAME, CredentialReference.CREDENTIAL_REFERENCE, true) .setMeasurementUnit(MeasurementUnit.NONE) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.CREDENTIAL) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .addAlternatives(RECOVERY_PASSWORD_NAME) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_SECURITY_DOMAIN = new SimpleAttributeDefinitionBuilder(RECOVERY_SECURITY_DOMAIN_NAME, ModelType.STRING, true) .setXmlName(Credential.Tag.SECURITY_DOMAIN.getLocalName()) .setAllowExpression(true) .setMeasurementUnit(MeasurementUnit.NONE) .setDefaultValue(new ModelNode()) .setAlternatives(RECOVERY_AUTHENTICATION_CONTEXT_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.SECURITY_DOMAIN_REF) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_ELYTRON_ENABLED = new SimpleAttributeDefinitionBuilder(RECOVERY_ELYTRON_ENABLED_NAME, ModelType.BOOLEAN, true) .setXmlName(Credential.Tag.ELYTRON_ENABLED.getLocalName()) .setAllowExpression(true) .setMeasurementUnit(MeasurementUnit.NONE) .setDefaultValue(new ModelNode(ELYTRON_MANAGED_SECURITY)) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setNullSignificant(false) .setDeprecated(ELYTRON_BY_DEFAULT_VERSION) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVERY_AUTHENTICATION_CONTEXT = new SimpleAttributeDefinitionBuilder(RECOVERY_AUTHENTICATION_CONTEXT_NAME, ModelType.STRING, true) .setXmlName(Credential.Tag.AUTHENTICATION_CONTEXT.getLocalName()) .setAllowExpression(false) .setAlternatives(RECOVERY_SECURITY_DOMAIN_NAME) .addAccessConstraint(SensitiveTargetAccessConstraintDefinition.AUTHENTICATION_CLIENT_REF) .addAccessConstraint(ResourceAdaptersExtension.RA_SECURITY_DEF) .setRestartAllServices() .build(); static SimpleAttributeDefinition NO_RECOVERY = new SimpleAttributeDefinitionBuilder(NO_RECOVERY_NAME, ModelType.BOOLEAN, true) .setXmlName(Recovery.Attribute.NO_RECOVERY.getLocalName()) .setDefaultValue(ModelNode.FALSE) .setAllowExpression(true) .setRestartAllServices() .build(); static SimpleAttributeDefinition RECOVER_PLUGIN_CLASSNAME = new SimpleAttributeDefinitionBuilder(RECOVER_PLUGIN_CLASSNAME_NAME, ModelType.STRING, true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Attribute.CLASS_NAME.getLocalName()) .setAllowExpression(true) .setRestartAllServices() .build(); static PropertiesAttributeDefinition RECOVER_PLUGIN_PROPERTIES = new PropertiesAttributeDefinition.Builder(RECOVER_PLUGIN_PROPERTIES_NAME, true) .setAllowExpression(true) .setXmlName(org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()) .setRestartAllServices() .build(); static SimpleAttributeDefinition REPORT_DIRECTORY = new SimpleAttributeDefinitionBuilder(REPORT_DIRECTORY_NAME, ModelType.STRING) .setXmlName("path") .setDefaultValue(new ModelNode(new ValueExpression("${jboss.server.log.dir}"))) .addArbitraryDescriptor(ModelDescriptionConstants.FILESYSTEM_PATH, ModelNode.TRUE) .setRequired(false) .setAllowExpression(true) .setRestartAllServices() .build(); static final String WORK_ACTIVE_NAME = "work-active"; static final String WORK_SUCEESSFUL_NAME = "work-successful"; static final String WORK_FAILED_NAME = "work-failed"; static final String DO_WORK_ACCEPTED_NAME = "dowork-accepted"; static final String DO_WORK_REJECTED_NAME = "dowork-rejected"; static final String SCHEDULED_WORK_ACCEPTED_NAME = "schedulework-accepted"; static final String SCHEDULED_WORK_REJECTED_NAME = "schedulework-rejected"; static final String START_WORK_ACCEPTED_NAME = "startwork-accepted"; static final String START_WORK_REJECTED_NAME = "startwork-rejected"; static SimpleAttributeDefinition WORK_ACTIVE = new SimpleAttributeDefinitionBuilder(WORK_ACTIVE_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); static SimpleAttributeDefinition WORK_SUCCESSFUL = new SimpleAttributeDefinitionBuilder(WORK_SUCEESSFUL_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); static SimpleAttributeDefinition WORK_FAILED = new SimpleAttributeDefinitionBuilder(WORK_FAILED_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); static SimpleAttributeDefinition DO_WORK_ACCEPTED = new SimpleAttributeDefinitionBuilder(DO_WORK_ACCEPTED_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); static SimpleAttributeDefinition DO_WORK_REJECTED = new SimpleAttributeDefinitionBuilder(DO_WORK_REJECTED_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); static SimpleAttributeDefinition SCHEDULED_WORK_ACCEPTED = new SimpleAttributeDefinitionBuilder(SCHEDULED_WORK_ACCEPTED_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); static SimpleAttributeDefinition SCHEDULED_WORK_REJECTED = new SimpleAttributeDefinitionBuilder(SCHEDULED_WORK_REJECTED_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); static SimpleAttributeDefinition START_WORK_ACCEPTED = new SimpleAttributeDefinitionBuilder(START_WORK_ACCEPTED_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); static SimpleAttributeDefinition START_WORK_REJECTED = new SimpleAttributeDefinitionBuilder(START_WORK_REJECTED_NAME, ModelType.INT) .setStorageRuntime() .setUndefinedMetricValue(ModelNode.ZERO) .build(); public static final SimpleAttributeDefinition[] WORKMANAGER_METRICS = new SimpleAttributeDefinition[]{WORK_ACTIVE, WORK_SUCCESSFUL, WORK_FAILED, DO_WORK_ACCEPTED, DO_WORK_REJECTED, SCHEDULED_WORK_ACCEPTED, SCHEDULED_WORK_REJECTED, START_WORK_ACCEPTED, START_WORK_REJECTED}; public static final String WORKMANAGER_STATISTICS_ENABLED_NAME = "workmanager-statistics-enabled"; public static final SimpleAttributeDefinition WORKMANAGER_STATISTICS_ENABLED = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.STATISTICS_ENABLED, ModelType.BOOLEAN) .setStorageRuntime() .build(); public static final SimpleAttributeDefinition WORKMANAGER_STATISTICS_ENABLED_DEPRECATED = new SimpleAttributeDefinitionBuilder(WORKMANAGER_STATISTICS_ENABLED_NAME, ModelType.BOOLEAN) .setStorageRuntime() .setDeprecated(ModelVersion.create(2)) .build(); public static final String DISTRIBUTED_STATISTICS_ENABLED_NAME = "distributed-workmanager-statistics-enabled"; public static final SimpleAttributeDefinition DISTRIBUTED_STATISTICS_ENABLED = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.STATISTICS_ENABLED, ModelType.BOOLEAN) .setStorageRuntime() .build(); public static final SimpleAttributeDefinition DISTRIBUTED_STATISTICS_ENABLED_DEPRECATED = new SimpleAttributeDefinitionBuilder(DISTRIBUTED_STATISTICS_ENABLED_NAME, ModelType.BOOLEAN) .setStorageRuntime() .setDeprecated(ModelVersion.create(2)) .build(); public static final String DOWORK_DISTRIBUTION_ENABLED_NAME = "dowork-distribution-enabled"; public static final SimpleAttributeDefinition DOWORK_DISTRIBUTION_ENABLED = new SimpleAttributeDefinitionBuilder(DOWORK_DISTRIBUTION_ENABLED_NAME, ModelType.BOOLEAN) .setStorageRuntime() .build(); public static final String SCHEDULEWORK_DISTRIBUTION_ENABLED_NAME = "schedulework-distribution-enabled"; public static final SimpleAttributeDefinition SCHEDULEWORK_DISTRIBUTION_ENABLED = new SimpleAttributeDefinitionBuilder(SCHEDULEWORK_DISTRIBUTION_ENABLED_NAME, ModelType.BOOLEAN) .setStorageRuntime() .build(); public static final String STARTWORK_DISTRIBUTION_ENABLED_NAME = "startwork-distribution-enabled"; public static final SimpleAttributeDefinition STARTWORK_DISTRIBUTION_ENABLED = new SimpleAttributeDefinitionBuilder(STARTWORK_DISTRIBUTION_ENABLED_NAME, ModelType.BOOLEAN) .setStorageRuntime() .build(); public static final SimpleAttributeDefinition[] WORKMANAGER_RW_ATTRIBUTES = new SimpleAttributeDefinition[]{ WORKMANAGER_STATISTICS_ENABLED, WORKMANAGER_STATISTICS_ENABLED_DEPRECATED }; public static final SimpleAttributeDefinition[] DISTRIBUTED_WORKMANAGER_RW_ATTRIBUTES = new SimpleAttributeDefinition[]{ DISTRIBUTED_STATISTICS_ENABLED, DISTRIBUTED_STATISTICS_ENABLED_DEPRECATED, DOWORK_DISTRIBUTION_ENABLED, SCHEDULEWORK_DISTRIBUTION_ENABLED, STARTWORK_DISTRIBUTION_ENABLED }; }
40,061
50.961089
206
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdaptersTransformers.java
/* * JBoss, Home of Professional Open Source. * Copyright 2023, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.transform.ExtensionTransformerRegistration; import org.jboss.as.controller.transform.SubsystemTransformerRegistration; import org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.DiscardAttributeChecker; import org.jboss.as.controller.transform.description.RejectAttributeChecker; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder; import org.kohsuke.MetaInfServices; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.REPORT_DIRECTORY_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTER_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY; import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersExtension.VERSION_6_0_0; import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersExtension.VERSION_6_1_0; /** * Resource Adapters Transformers used to transform current model version to legacy model versions for domain mode. * * @author <a href="[email protected]">Petr Beran</a> */ @MetaInfServices(ExtensionTransformerRegistration.class) public class ResourceAdaptersTransformers implements ExtensionTransformerRegistration { @Override public String getSubsystemName() { return ResourceAdaptersExtension.SUBSYSTEM_NAME; } @Override public void registerTransformers(SubsystemTransformerRegistration subsystemRegistration) { ModelVersion currentModel = subsystemRegistration.getCurrentSubsystemVersion(); ChainedTransformationDescriptionBuilder chainedBuilder = TransformationDescriptionBuilder.Factory.createChainedSubystemInstance(currentModel); register700Transformers(chainedBuilder.createBuilder(currentModel, VERSION_6_1_0)); // 7.0.0 to 6.1.0 transformer register610Transformers(chainedBuilder.createBuilder(VERSION_6_1_0, VERSION_6_0_0)); // 6.1.0 to 6.0.0 transformer chainedBuilder.buildAndRegister(subsystemRegistration, new ModelVersion[] { VERSION_6_1_0, VERSION_6_0_0 }); } private static void register700Transformers(ResourceTransformationDescriptionBuilder parentBuilder) { // 6.1.0 cannot resolve expressions introduced in 7.0.0 for WM_SECURITY parentBuilder.addChildResource(PathElement.pathElement(RESOURCEADAPTER_NAME)).getAttributeBuilder() .addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, WM_SECURITY); } private static void register610Transformers(ResourceTransformationDescriptionBuilder parentBuilder) { // 6.0.0 doesn't contain the report-directory attribute introduced in 6.1.0 parentBuilder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.ALWAYS, REPORT_DIRECTORY_NAME); } }
4,151
52.230769
150
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/RaAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.jca.Constants.DEFAULT_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ARCHIVE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MODULE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_ENABLED; import java.util.ArrayList; import java.util.List; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.services.resourceadapters.statistics.ResourceAdapterStatisticsService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; /** * Operation handler responsible for adding a Ra. * * @author maeste */ public class RaAdd extends AbstractAddStepHandler { static final RaAdd INSTANCE = new RaAdd(); @Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { for (final AttributeDefinition attribute : CommonAttributes.RESOURCE_ADAPTER_ATTRIBUTE) { attribute.validateAndSet(operation, model); } } @Override public void performRuntime(final OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException { final ModelNode model = resource.getModel(); // Compensating is remove final String name = context.getCurrentAddressValue(); final String archiveOrModuleName; final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean(); if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) { throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired(); } if (model.get(ARCHIVE.getName()).isDefined()) { archiveOrModuleName = model.get(ARCHIVE.getName()).asString(); } else { archiveOrModuleName = model.get(MODULE.getName()).asString(); } ModifiableResourceAdapter resourceAdapter = RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName); List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>(); if (model.get(ARCHIVE.getName()).isDefined()) { RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers); } else { RaOperationUtil.installRaServicesAndDeployFromModule(context, name, resourceAdapter, archiveOrModuleName, newControllers); if (context.isBooting()) { context.addStep(new OperationStepHandler() { public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException { //Next lines activate configuration on module deployed rar //in case there is 2 different resource-adapter config using same module deployed rar // a Deployment sercivice could be already present and need a restart to consider also this //newly added configuration ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name); if (restartedServiceName == null) { RaOperationUtil.activate(context, name, archiveOrModuleName); } context.completeStep(new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext context, ModelNode operation) { try { RaOperationUtil.removeIfActive(context, archiveOrModuleName, name); } catch (OperationFailedException e) { } } }); } }, OperationContext.Stage.RUNTIME); } } ServiceRegistry registry = context.getServiceRegistry(true); final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, name)); Activation raxml = (Activation) RaxmlController.getValue(); ServiceName serviceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, name); String bootStrapCtxName = DEFAULT_NAME; if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) { bootStrapCtxName = raxml.getBootstrapContext(); } ResourceAdapterStatisticsService raStatsService = new ResourceAdapterStatisticsService(context.getResourceRegistrationForUpdate(), name, statsEnabled); ServiceBuilder statsServiceBuilder = context.getServiceTarget().addService(ServiceName.of(ConnectorServices.RA_SERVICE, name).append(ConnectorServices.STATISTICS_SUFFIX), raStatsService); statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, raStatsService.getBootstrapContextInjector()) .addDependency(serviceName, Object.class, raStatsService.getResourceAdapterDeploymentInjector()) .setInitialMode(ServiceController.Mode.PASSIVE) .install(); PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended"); final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource(); resource.registerChild(peStats, statsResource); } }
7,308
50.111888
195
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/AS7ResourceAdapterTags.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import java.util.HashMap; import java.util.Map; /** * TODO class javadoc. * * @author Brian Stansberry (c) 2011 Red Hat Inc. */ public enum AS7ResourceAdapterTags { /** * always first */ UNKNOWN(null), /** * id tag */ ID("id"), /** * config-property tag */ CONFIG_PROPERTY("config-property"), /** * archive tag */ ARCHIVE("archive"), /** * module tag */ MODULE("module"), /** * bean-validation-groups tag */ BEAN_VALIDATION_GROUPS("bean-validation-groups"), /** * bean-validation-group tag */ BEAN_VALIDATION_GROUP("bean-validation-group"), /** * bootstrap-context tag */ BOOTSTRAP_CONTEXT("bootstrap-context"), /** * transaction-support tag */ TRANSACTION_SUPPORT("transaction-support"), /** * connection-definitions tag */ CONNECTION_DEFINITIONS("connection-definitions"), /** * connection-definition tag */ CONNECTION_DEFINITION("connection-definition"), /** * admin-objects tag */ ADMIN_OBJECTS("admin-objects"), /** * admin-objects tag */ ADMIN_OBJECT("admin-object"), WORKMANAGER("workmanager"); private String name; /** * Create a new Tag. * * @param name a name */ AS7ResourceAdapterTags(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } /** * {@inheritDoc} */ public String toString() { return name; } private static final Map<String, AS7ResourceAdapterTags> MAP; static { final Map<String, AS7ResourceAdapterTags> map = new HashMap<String, AS7ResourceAdapterTags>(); for (AS7ResourceAdapterTags element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } /** * Set the value * * @param v The name * @return The value */ AS7ResourceAdapterTags value(String v) { name = v; return this; } /** * Static method to get enum instance given localName string * * @param localName a string used as localname (typically tag name as defined in xsd) * @return the enum instance */ public static AS7ResourceAdapterTags forName(String localName) { final AS7ResourceAdapterTags element = MAP.get(localName); return element == null ? UNKNOWN.value(localName) : element; } }
3,791
22.552795
102
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/AdminObjectService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class AdminObjectService implements Service<ModifiableAdminObject> { private final ModifiableAdminObject value; private final InjectedValue<ModifiableResourceAdapter> ra = new InjectedValue<ModifiableResourceAdapter>(); /** create an instance **/ public AdminObjectService(ModifiableAdminObject value) { this.value = value; } @Override public ModifiableAdminObject getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { ra.getValue().addAdminObject(value); SUBSYSTEM_RA_LOGGER.debugf("Starting ResourceAdapters Service"); } @Override public void stop(StopContext context) { } public Injector<ModifiableResourceAdapter> getRaInjector() { return ra; } }
2,399
31.876712
111
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/CDConfigPropertiesService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class CDConfigPropertiesService implements Service<String> { private final String value; private final String name; private final InjectedValue<ModifiableConnDef> cd = new InjectedValue<ModifiableConnDef>(); /** create an instance **/ public CDConfigPropertiesService(String name, String value) { this.name = name; this.value = value; } @Override public String getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { cd.getValue().addConfigProperty(name,value); SUBSYSTEM_RA_LOGGER.debugf("Starting ResourceAdapters Service"); } @Override public void stop(StopContext context) { } public Injector<ModifiableConnDef> getRaInjector() { return cd; } }
2,495
32.28
99
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/Element.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import java.util.HashMap; import java.util.Map; /** * An Element. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public enum Element { /** always the first **/ UNKNOWN(null), SUBSYSTEM("subsystem"), RESOURCE_ADAPTERS("resource-adapters"), REPORT_DIRECTORY("report-directory"); private final String name; Element(final String name) { this.name = name; } /** * Get the local name of this element. * @return the local name */ public String getLocalName() { return name; } private static final Map<String, Element> MAP; static { final Map<String, Element> map = new HashMap<String, Element>(); for (Element element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } public static Element forName(String localName) { final Element element = MAP.get(localName); return element == null ? UNKNOWN : element; } }
2,165
30.852941
120
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ConfigPropertiesService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * A ResourceAdaptersService. * * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class ConfigPropertiesService implements Service<String> { private final String value; private final String name; private final InjectedValue<ModifiableResourceAdapter> ra = new InjectedValue<ModifiableResourceAdapter>(); /** * create an instance * */ public ConfigPropertiesService(String name, String value) { this.name = name; this.value = value; } @Override public String getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { ra.getValue().addConfigProperty(name, value); SUBSYSTEM_RA_LOGGER.debugf("Starting ResourceAdapters Service"); } @Override public void stop(StopContext context) { } public Injector<ModifiableResourceAdapter> getRaInjector() { return ra; } }
2,443
30.74026
111
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/IronJacamarResourceCreator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.common.pool.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CLASS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.INTERLEAVING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NOTXSEPARATEPOOL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NO_RECOVERY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.PAD_XID; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_PASSWORD; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_USERNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SAME_RM_OVERRIDE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SHARABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRACKING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_CCM; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_GROUP; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_USER; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WRAP_XA_RESOURCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.XA_RESOURCE_TIMEOUT; import java.util.Map; import org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity; import org.jboss.as.connector.services.mdr.AS7MetadataRepository; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinition; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.common.Credential; import org.jboss.jca.common.api.metadata.common.Extension; import org.jboss.jca.common.api.metadata.common.Pool; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.common.Security; import org.jboss.jca.common.api.metadata.common.TimeOut; import org.jboss.jca.common.api.metadata.common.Validation; import org.jboss.jca.common.api.metadata.common.XaPool; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.metadata.resourceadapter.AdminObject; import org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition; /** * Handler for exposing transaction logs * * @author <a href="[email protected]">Stefano Maestri</a> (c) 2011 Red Hat Inc. * @author <a href="[email protected]">Mike Musgrove</a> (c) 2012 Red Hat Inc. */ public class IronJacamarResourceCreator { public static final IronJacamarResourceCreator INSTANCE = new IronJacamarResourceCreator(); private void setAttribute(ModelNode model, SimpleAttributeDefinition node, String value) { if (value != null) { model.get(node.getName()).set(value); } } private void setAttribute(ModelNode model, SimpleAttributeDefinition node, Boolean value) { if (value != null) { model.get(node.getName()).set(value); } } private void setAttribute(ModelNode model, SimpleAttributeDefinition node, Integer value) { if (value != null) { model.get(node.getName()).set(value); } } private void setAttribute(ModelNode model, SimpleAttributeDefinition node, Long value) { if (value != null) { model.get(node.getName()).set(value); } } private void addConfigProperties(final Resource parent, String name, String value) { final Resource config = new IronJacamarResource.IronJacamarRuntimeResource(); final ModelNode model = config.getModel(); model.get(Constants.CONFIG_PROPERTY_VALUE.getName()).set(value); final PathElement element = PathElement.pathElement(Constants.CONFIG_PROPERTIES.getName(), name); parent.registerChild(element, config); } private void addConnectionDefinition(final Resource parent, ConnectionDefinition connDef) { final Resource connDefResource = new IronJacamarResource.IronJacamarRuntimeResource(); final ModelNode model = connDefResource.getModel(); setAttribute(model, JNDI_NAME, connDef.getJndiName()); if (connDef.getConfigProperties() != null) { for (Map.Entry<String, String> config : connDef.getConfigProperties().entrySet()) { addConfigProperties(connDefResource, config.getKey(), config.getValue()); } } setAttribute(model, CLASS_NAME, connDef.getClassName()); setAttribute(model, JNDI_NAME, connDef.getJndiName()); setAttribute(model, USE_JAVA_CONTEXT, connDef.isUseJavaContext()); setAttribute(model, ENABLED, connDef.isEnabled()); setAttribute(model, CONNECTABLE, connDef.isConnectable()); if (connDef.isTracking() != null) { setAttribute(model, TRACKING, connDef.isTracking()); } setAttribute(model, USE_CCM, connDef.isUseCcm()); setAttribute(model, SHARABLE, connDef.isSharable()); setAttribute(model, ENLISTMENT, connDef.isEnlistment()); final Pool pool = connDef.getPool(); if (pool != null) { setAttribute(model, MAX_POOL_SIZE, pool.getMaxPoolSize()); setAttribute(model, MIN_POOL_SIZE, pool.getMinPoolSize()); setAttribute(model, INITIAL_POOL_SIZE, pool.getInitialPoolSize()); if (pool.getCapacity() != null) { if (pool.getCapacity().getIncrementer() != null) { setAttribute(model, CAPACITY_INCREMENTER_CLASS, pool.getCapacity().getIncrementer().getClassName()); if (pool.getCapacity().getIncrementer().getConfigPropertiesMap() != null) { for (Map.Entry<String, String> config : pool.getCapacity().getIncrementer().getConfigPropertiesMap().entrySet()) { model.get(CAPACITY_INCREMENTER_PROPERTIES.getName(), config.getKey()).set(config.getValue()); } } } if (pool.getCapacity().getDecrementer() != null) { setAttribute(model, CAPACITY_DECREMENTER_CLASS, pool.getCapacity().getDecrementer().getClassName()); if (pool.getCapacity().getDecrementer().getConfigPropertiesMap() != null) { for (Map.Entry<String, String> config : pool.getCapacity().getDecrementer().getConfigPropertiesMap().entrySet()) { model.get(CAPACITY_DECREMENTER_PROPERTIES.getName(), config.getKey()).set(config.getValue()); } } } } setAttribute(model, POOL_USE_STRICT_MIN, pool.isUseStrictMin()); if (pool.getFlushStrategy() != null) setAttribute(model, POOL_FLUSH_STRATEGY, pool.getFlushStrategy().name()); setAttribute(model, POOL_PREFILL, pool.isPrefill()); setAttribute(model, POOL_FAIR, pool.isFair()); if (connDef.isXa()) { assert connDef.getPool() instanceof XaPool; XaPool xaPool = (XaPool) connDef.getPool(); setAttribute(model, WRAP_XA_RESOURCE, xaPool.isWrapXaResource()); setAttribute(model, SAME_RM_OVERRIDE, xaPool.isSameRmOverride()); setAttribute(model, PAD_XID, xaPool.isPadXid()); setAttribute(model, INTERLEAVING, xaPool.isInterleaving()); setAttribute(model, NOTXSEPARATEPOOL, xaPool.isNoTxSeparatePool()); } } final Security security = connDef.getSecurity(); if (security != null) { setAttribute(model, APPLICATION, security.isApplication()); setAttribute(model, ELYTRON_ENABLED, true); setAttribute(model, AUTHENTICATION_CONTEXT, security.getSecurityDomain()); setAttribute(model, AUTHENTICATION_CONTEXT_AND_APPLICATION, security.getSecurityDomainAndApplication()); } final TimeOut timeOut = connDef.getTimeOut(); if (timeOut != null) { setAttribute(model, ALLOCATION_RETRY, timeOut.getAllocationRetry()); setAttribute(model, ALLOCATION_RETRY_WAIT_MILLIS, timeOut.getAllocationRetryWaitMillis()); setAttribute(model, BLOCKING_TIMEOUT_WAIT_MILLIS, timeOut.getBlockingTimeoutMillis()); setAttribute(model, IDLETIMEOUTMINUTES, timeOut.getIdleTimeoutMinutes()); setAttribute(model, XA_RESOURCE_TIMEOUT, timeOut.getXaResourceTimeout()); } final Validation validation = connDef.getValidation(); if (validation != null) { setAttribute(model, BACKGROUNDVALIDATIONMILLIS, validation.getBackgroundValidationMillis()); setAttribute(model, BACKGROUNDVALIDATION, validation.isBackgroundValidation()); setAttribute(model, USE_FAST_FAIL, validation.isUseFastFail()); setAttribute(model, VALIDATE_ON_MATCH, validation.isValidateOnMatch()); } final Recovery recovery = connDef.getRecovery(); if (recovery != null) { setAttribute(model, NO_RECOVERY, recovery.getNoRecovery()); final Extension recoverPlugin = recovery.getRecoverPlugin(); if (recoverPlugin != null) { setAttribute(model, RECOVER_PLUGIN_CLASSNAME, recoverPlugin.getClassName()); if (recoverPlugin.getConfigPropertiesMap() != null) { for (Map.Entry<String, String> config : recoverPlugin.getConfigPropertiesMap().entrySet()) { model.get(RECOVER_PLUGIN_PROPERTIES.getName(), config.getKey()).set(config.getValue()); } } } final Credential recoveryCredential = recovery.getCredential(); if (recoveryCredential != null) { setAttribute(model, RECOVERY_PASSWORD, recoveryCredential.getPassword()); setAttribute(model, RECOVERY_ELYTRON_ENABLED, true); setAttribute(model, RECOVERY_AUTHENTICATION_CONTEXT, recoveryCredential.getSecurityDomain()); setAttribute(model, RECOVERY_USERNAME, recoveryCredential.getUserName()); } } final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource(); connDefResource.registerChild( PathElement.pathElement(Constants.STATISTICS_NAME, "local"), statsResource); final PathElement element = PathElement.pathElement(Constants.CONNECTIONDEFINITIONS_NAME, connDef.getJndiName()); parent.registerChild(element, connDefResource); } private void addAdminObject(final Resource parent, AdminObject adminObject) { final Resource adminObjectResource = new IronJacamarResource.IronJacamarRuntimeResource(); final ModelNode model = adminObjectResource.getModel(); setAttribute(model, CLASS_NAME, adminObject.getClassName()); setAttribute(model, JNDI_NAME, adminObject.getJndiName()); setAttribute(model, USE_JAVA_CONTEXT, adminObject.isUseJavaContext()); setAttribute(model, ENABLED, adminObject.isEnabled()); if (adminObject.getConfigProperties() != null) { for (Map.Entry<String, String> config : adminObject.getConfigProperties().entrySet()) { addConfigProperties(adminObjectResource, config.getKey(), config.getValue()); } } final PathElement element = PathElement.pathElement(Constants.ADMIN_OBJECTS_NAME, adminObject.getJndiName()); parent.registerChild(element, adminObjectResource); } private void addResourceAdapter(final Resource parent, String name, Activation ironJacamarMetadata) { final Resource ijResourceAdapter = new IronJacamarResource.IronJacamarRuntimeResource(); final ModelNode model = ijResourceAdapter.getModel(); model.get(Constants.ARCHIVE.getName()).set(name); setAttribute(model, Constants.BOOTSTRAP_CONTEXT, ironJacamarMetadata.getBootstrapContext()); if (ironJacamarMetadata.getTransactionSupport() != null) model.get(Constants.TRANSACTION_SUPPORT.getName()).set(ironJacamarMetadata.getTransactionSupport().name()); if (ironJacamarMetadata.getWorkManager() != null && ironJacamarMetadata.getWorkManager().getSecurity() != null) { org.jboss.jca.common.api.metadata.resourceadapter.WorkManagerSecurity security = ironJacamarMetadata.getWorkManager().getSecurity(); model.get(Constants.WM_SECURITY.getName()).set(true); if (security.getDefaultGroups() != null) { for (String group : security.getDefaultGroups()) { model.get(Constants.WM_SECURITY_DEFAULT_GROUPS.getName()).add(group); } } if (security.getDefaultPrincipal() != null) model.get(Constants.WM_SECURITY_DEFAULT_PRINCIPAL.getName()).set(security.getDefaultPrincipal()); model.get(Constants.WM_SECURITY_MAPPING_REQUIRED.getName()).set(security.isMappingRequired()); if (security instanceof WorkManagerSecurity) { model.get(Constants.WM_ELYTRON_SECURITY_DOMAIN.getName()).set(security.getDomain()); } if (security.getGroupMappings() != null) { for (Map.Entry<String, String> entry : security.getGroupMappings().entrySet()) { final Resource mapping = new IronJacamarResource.IronJacamarRuntimeResource(); final ModelNode subModel = mapping.getModel(); subModel.get(Constants.WM_SECURITY_MAPPING_FROM.getName()).set(entry.getKey()); subModel.get(Constants.WM_SECURITY_MAPPING_TO.getName()).set(entry.getKey()); final PathElement element = PathElement.pathElement(Constants.WM_SECURITY_MAPPING_GROUPS.getName(), WM_SECURITY_MAPPING_GROUP.getName()); ijResourceAdapter.registerChild(element, mapping); } } if (security.getUserMappings() != null) { for (Map.Entry<String, String> entry : security.getUserMappings().entrySet()) { final Resource mapping = new IronJacamarResource.IronJacamarRuntimeResource(); final ModelNode subModel = mapping.getModel(); subModel.get(Constants.WM_SECURITY_MAPPING_FROM.getName()).set(entry.getKey()); subModel.get(Constants.WM_SECURITY_MAPPING_TO.getName()).set(entry.getKey()); final PathElement element = PathElement.pathElement(Constants.WM_SECURITY_MAPPING_USERS.getName(), WM_SECURITY_MAPPING_USER.getName()); ijResourceAdapter.registerChild(element, mapping); } } } if (ironJacamarMetadata.getBeanValidationGroups() != null) { for (String bv : ironJacamarMetadata.getBeanValidationGroups()) { model.get(Constants.BEANVALIDATION_GROUPS.getName()).add(new ModelNode().set(bv)); } } if (ironJacamarMetadata.getConfigProperties() != null) { for (Map.Entry<String, String> config : ironJacamarMetadata.getConfigProperties().entrySet()) { addConfigProperties(ijResourceAdapter, config.getKey(), config.getValue()); } } if (ironJacamarMetadata.getConnectionDefinitions() != null) { for (ConnectionDefinition connDef : ironJacamarMetadata.getConnectionDefinitions()) { addConnectionDefinition(ijResourceAdapter, connDef); } } if (ironJacamarMetadata.getAdminObjects() != null) { for (AdminObject adminObject : ironJacamarMetadata.getAdminObjects()) { addAdminObject(ijResourceAdapter, adminObject); } } final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource(); ijResourceAdapter.registerChild( PathElement.pathElement(Constants.STATISTICS_NAME, "local"), statsResource); final PathElement element = PathElement.pathElement(Constants.RESOURCEADAPTER_NAME, name); parent.registerChild(element, ijResourceAdapter); } private Resource getIronJacamarResource(AS7MetadataRepository mdr, String name) { final Resource resource = Resource.Factory.create(); Activation activation = mdr.getIronJacamarMetaData(name); if (activation != null) addResourceAdapter(resource, name, activation); return resource; } public void execute(Resource parentResource, AS7MetadataRepository mdr, String name) { // Get the iron-jacamar resource final IronJacamarResource ironJacamarResource = new IronJacamarResource(); // Replace the current model with an updated one final Resource storeModel = getIronJacamarResource(mdr, name); ironJacamarResource.update(storeModel); PathElement ijPe = PathElement.pathElement(Constants.IRONJACAMAR_NAME, Constants.IRONJACAMAR_NAME); if (parentResource.getChild(ijPe) == null) { parentResource.registerChild(ijPe, ironJacamarResource); } } }
21,450
54.428941
157
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ConfigPropertyResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTIES; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * * @author <a href="[email protected]">Kabir Khan</a> */ public class ConfigPropertyResourceDefinition extends SimpleResourceDefinition { public ConfigPropertyResourceDefinition(AbstractAddStepHandler addHandler, OperationStepHandler removeHandler) { super(PathElement.pathElement(CONFIG_PROPERTIES.getName()), ResourceAdaptersExtension.getResourceDescriptionResolver(CONFIG_PROPERTIES.getName()), addHandler, removeHandler); } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerReadWriteAttribute(Constants.CONFIG_PROPERTY_VALUE, null, new ReloadRequiredWriteAttributeHandler(Constants.CONFIG_PROPERTY_VALUE)); } }
2,425
43.925926
182
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/AOConfigPropertiesService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class AOConfigPropertiesService implements Service<String> { private final String value; private final String name; private final InjectedValue<ModifiableAdminObject> ao = new InjectedValue<ModifiableAdminObject>(); /** create an instance **/ public AOConfigPropertiesService(String name, String value) { this.name = name; this.value = value; } @Override public String getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { ao.getValue().addConfigProperty(name,value); SUBSYSTEM_RA_LOGGER.debugf("Starting ResourceAdapters Service"); } @Override public void stop(StopContext context) { } public Injector<ModifiableAdminObject> getAOInjector() { return ao; } }
2,507
32.44
107
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ConnectionDefinitionResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTIONDEFINITIONS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_CREDENTIAL_REFERENCE; import org.jboss.as.connector.subsystems.common.pool.PoolConfigurationRWHandler; import org.jboss.as.connector.subsystems.common.pool.PoolOperations; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.SimpleOperationDefinition; import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.security.CredentialReferenceWriteAttributeHandler; /** * * @author <a href="[email protected]">Kabir Khan</a> */ public class ConnectionDefinitionResourceDefinition extends SimpleResourceDefinition { static final PathElement PATH = PathElement.pathElement(CONNECTIONDEFINITIONS_NAME); private static final ResourceDescriptionResolver RESOLVER = ResourceAdaptersExtension.getResourceDescriptionResolver(CONNECTIONDEFINITIONS_NAME); private static final OperationDefinition FLUSH__IDLE_DEFINITION = new SimpleOperationDefinitionBuilder(Constants.FLUSH_IDLE_CONNECTION_IN_POOL, RESOLVER) .setRuntimeOnly() .build(); private static final OperationDefinition FLUSH_ALL_DEFINITION = new SimpleOperationDefinitionBuilder(Constants.FLUSH_ALL_CONNECTION_IN_POOL, RESOLVER) .setRuntimeOnly() .build(); private static final SimpleOperationDefinition DUMP_QUEUED_THREADS = new SimpleOperationDefinitionBuilder("dump-queued-threads-in-pool", RESOLVER) .setReadOnly() .setRuntimeOnly() .build(); private static final OperationDefinition FLUSH_INVALID_DEFINITION = new SimpleOperationDefinitionBuilder(Constants.FLUSH_INVALID_CONNECTION_IN_POOL, RESOLVER) .setRuntimeOnly() .build(); private static final OperationDefinition FLUSH_GRACEFULY_DEFINITION = new SimpleOperationDefinitionBuilder(Constants.FLUSH_GRACEFULLY_CONNECTION_IN_POOL, RESOLVER) .setRuntimeOnly() .build(); private static final OperationDefinition TEST_DEFINITION = new SimpleOperationDefinitionBuilder(Constants.TEST_CONNECTION_IN_POOL, RESOLVER) .setRuntimeOnly() .build(); private final boolean readOnly; private final boolean runtimeOnlyRegistrationValid; public ConnectionDefinitionResourceDefinition(final boolean readOnly, final boolean runtimeOnlyRegistrationValid) { super(PATH, ResourceAdaptersExtension.getResourceDescriptionResolver(CONNECTIONDEFINITIONS_NAME), readOnly ? null : ConnectionDefinitionAdd.INSTANCE, readOnly ? null : ReloadRequiredRemoveStepHandler.INSTANCE); this.readOnly = readOnly; this.runtimeOnlyRegistrationValid = runtimeOnlyRegistrationValid; } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { for (final AttributeDefinition attribute : CommonAttributes.CONNECTION_DEFINITIONS_NODE_ATTRIBUTE) { if (readOnly) { resourceRegistration.registerReadOnlyAttribute(attribute, null); } else { if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) { resourceRegistration.registerReadWriteAttribute(attribute, null, PoolConfigurationRWHandler.RaPoolConfigurationWriteHandler.INSTANCE); } else if (attribute.equals(ENLISTMENT_TRACE)) { resourceRegistration.registerReadWriteAttribute(attribute, null, new EnlistmentTraceAttributeWriteHandler()); } else if (attribute.equals(RECOVERY_CREDENTIAL_REFERENCE)){ resourceRegistration.registerReadWriteAttribute(attribute, null, new CredentialReferenceWriteAttributeHandler(attribute)); } else { resourceRegistration.registerReadWriteAttribute(attribute, null, new ReloadRequiredWriteAttributeHandler(attribute)); } } } } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); if (runtimeOnlyRegistrationValid) { resourceRegistration.registerOperationHandler(FLUSH__IDLE_DEFINITION, PoolOperations.FlushIdleConnectionInPool.RA_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_ALL_DEFINITION, PoolOperations.FlushAllConnectionInPool.RA_INSTANCE); resourceRegistration.registerOperationHandler(DUMP_QUEUED_THREADS, PoolOperations.DumpQueuedThreadInPool.RA_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_INVALID_DEFINITION, PoolOperations.FlushInvalidConnectionInPool.RA_INSTANCE); resourceRegistration.registerOperationHandler(FLUSH_GRACEFULY_DEFINITION, PoolOperations.FlushGracefullyConnectionInPool.RA_INSTANCE); resourceRegistration.registerOperationHandler(TEST_DEFINITION, PoolOperations.TestConnectionInPool.RA_INSTANCE); } } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerSubModel(new ConfigPropertyResourceDefinition(readOnly ? null : CDConfigPropertyAdd.INSTANCE, readOnly ? null : ReloadRequiredRemoveStepHandler.INSTANCE)); } }
7,025
58.542373
192
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/AdminObjectResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ADMIN_OBJECTS_NAME; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * * @author <a href="[email protected]">Kabir Khan</a> */ public class AdminObjectResourceDefinition extends SimpleResourceDefinition { private final boolean readOnly; public AdminObjectResourceDefinition(boolean readOnly) { super(PathElement.pathElement(ADMIN_OBJECTS_NAME), ResourceAdaptersExtension.getResourceDescriptionResolver(ADMIN_OBJECTS_NAME), readOnly ? null : AdminObjectAdd.INSTANCE, readOnly ? null : ReloadRequiredRemoveStepHandler.INSTANCE); this.readOnly = readOnly; } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { for (final AttributeDefinition attribute : CommonAttributes.ADMIN_OBJECTS_NODE_ATTRIBUTE) { if (readOnly) { resourceRegistration.registerReadOnlyAttribute(attribute, null); } else { resourceRegistration.registerReadWriteAttribute(attribute, null, new ReloadRequiredWriteAttributeHandler(attribute)); } } } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerSubModel(new ConfigPropertyResourceDefinition(AOConfigPropertyAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE)); } }
2,822
43.809524
240
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ConnectionDefinitionService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; import org.wildfly.common.function.ExceptionSupplier; import org.wildfly.security.credential.source.CredentialSource; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class ConnectionDefinitionService implements Service<ModifiableConnDef> { private final InjectedValue<ModifiableConnDef> value = new InjectedValue<>(); private final InjectedValue<ExceptionSupplier<ModifiableConnDef, Exception>> connectionDefinitionSupplier = new InjectedValue<>(); private final InjectedValue<ModifiableResourceAdapter> ra = new InjectedValue<ModifiableResourceAdapter>(); private final InjectedValue<ExceptionSupplier<CredentialSource, Exception>> credentialSourceSupplier = new InjectedValue<>(); /** create an instance **/ public ConnectionDefinitionService() { } @Override public ModifiableConnDef getValue() throws IllegalStateException { return value.getValue(); } @Override public void start(StartContext context) throws StartException { createConnectionDefinition(); ra.getValue().addConnectionDefinition(getValue()); SUBSYSTEM_RA_LOGGER.debugf("Starting ResourceAdapters Service"); } @Override public void stop(StopContext context) { } public Injector<ModifiableResourceAdapter> getRaInjector() { return ra; } public InjectedValue<ExceptionSupplier<CredentialSource, Exception>> getCredentialSourceSupplier() { return credentialSourceSupplier; } public InjectedValue<ExceptionSupplier<ModifiableConnDef, Exception>> getConnectionDefinitionSupplierInjector() { return connectionDefinitionSupplier; } private void createConnectionDefinition() throws IllegalStateException { ExceptionSupplier<ModifiableConnDef, Exception> connDefSupplier = connectionDefinitionSupplier.getValue(); try { if (connDefSupplier != null) value.inject(connDefSupplier.get()); } catch (Exception e) { throw new IllegalStateException(e); } } }
3,555
36.431579
134
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ModifiableAdminObject.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.jboss.jca.common.api.metadata.resourceadapter.AdminObject; import org.jboss.jca.common.api.validator.ValidateException; public class ModifiableAdminObject implements AdminObject { /** * The serialVersionUID */ private static final long serialVersionUID = 8137442556861441967L; private final ConcurrentHashMap<String, String> configProperties; private final String className; private final String jndiName; private final String poolName; private final Boolean enabled; private final Boolean useJavaContext; /** * Create a new AdminObjectImpl. * * @param configProperties configProperties * @param className className * @param jndiName jndiName * @param poolName poolName * @param enabled enabled * @param useJavaContext useJavaContext */ public ModifiableAdminObject(Map<String, String> configProperties, String className, String jndiName, String poolName, Boolean enabled, Boolean useJavaContext) throws ValidateException { super(); if (configProperties != null) { this.configProperties = new ConcurrentHashMap<String, String>(configProperties.size()); this.configProperties.putAll(configProperties); } else { this.configProperties = new ConcurrentHashMap<String, String>(0); } this.className = className; this.jndiName = jndiName; this.poolName = poolName; this.enabled = enabled; this.useJavaContext = useJavaContext; } /** * Get the configProperties. * * @return the configProperties. */ @Override public final Map<String, String> getConfigProperties() { return Collections.unmodifiableMap(configProperties); } public String addConfigProperty(String key, String value) { return configProperties.put(key, value); } /** * Get the className. * * @return the className. */ @Override public final String getClassName() { return className; } /** * Get the jndiName. * * @return the jndiName. */ @Override public final String getJndiName() { return jndiName; } /** * Get the enabled. * * @return the enabled. */ @Override public final Boolean isEnabled() { return enabled; } /** * Get the useJavaContext. * * @return the useJavaContext. */ @Override public final Boolean isUseJavaContext() { return useJavaContext; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((className == null) ? 0 : className.hashCode()); result = prime * result + ((configProperties == null) ? 0 : configProperties.hashCode()); result = prime * result + ((enabled == null) ? 0 : enabled.hashCode()); result = prime * result + ((jndiName == null) ? 0 : jndiName.hashCode()); result = prime * result + ((poolName == null) ? 0 : poolName.hashCode()); result = prime * result + ((useJavaContext == null) ? 0 : useJavaContext.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof ModifiableAdminObject)) return false; ModifiableAdminObject other = (ModifiableAdminObject) obj; if (className == null) { if (other.className != null) return false; } else if (!className.equals(other.className)) return false; if (configProperties == null) { if (other.configProperties != null) return false; } else if (!configProperties.equals(other.configProperties)) return false; if (enabled == null) { if (other.enabled != null) return false; } else if (!enabled.equals(other.enabled)) return false; if (jndiName == null) { if (other.jndiName != null) return false; } else if (!jndiName.equals(other.jndiName)) return false; if (poolName == null) { if (other.poolName != null) return false; } else if (!poolName.equals(other.poolName)) return false; if (useJavaContext == null) { if (other.useJavaContext != null) return false; } else if (!useJavaContext.equals(other.useJavaContext)) return false; return true; } @Override public String toString() { StringBuilder sb = new StringBuilder(1024); sb.append("<admin-object"); if (className != null) sb.append(" ").append(Attribute.CLASS_NAME).append("=\"").append(className).append("\""); if (jndiName != null) sb.append(" ").append(Attribute.JNDI_NAME).append("=\"").append(jndiName).append("\""); if (enabled != null) sb.append(" ").append(Attribute.ENABLED).append("=\"").append(enabled).append("\""); if (useJavaContext != null) { sb.append(" ").append(Attribute.USE_JAVA_CONTEXT); sb.append("=\"").append(useJavaContext).append("\""); } if (poolName != null) sb.append(" ").append(Attribute.POOL_NAME).append("=\"").append(poolName).append("\""); sb.append(">"); if (configProperties != null && configProperties.size() > 0) { Iterator<Map.Entry<String, String>> it = configProperties.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> entry = it.next(); sb.append("<").append(Tag.CONFIG_PROPERTY); sb.append(" name=\"").append(entry.getKey()).append("\">"); sb.append(entry.getValue()); sb.append("</").append(Tag.CONFIG_PROPERTY).append(">"); } } sb.append("</admin-object>"); return sb.toString(); } /** * Get the poolName. * * @return the poolName. */ @Override public final String getPoolName() { return poolName; } }
7,622
30.630705
117
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdaptersSubsystemService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import org.jboss.as.connector.util.CopyOnWriteArrayListMultiMap; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import java.io.File; /** * A ResourceAdaptersSubsystem Service. * * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ public final class ResourceAdaptersSubsystemService implements Service<ResourceAdaptersSubsystemService> { public static final AttachmentKey<ResourceAdaptersSubsystemService> ATTACHMENT_KEY = AttachmentKey .create(ResourceAdaptersSubsystemService.class); private final CopyOnWriteArrayListMultiMap<String, ServiceName> adapters = new CopyOnWriteArrayListMultiMap<>(); private File reportDirectory; public ResourceAdaptersSubsystemService(final File reportDirectory){ this.reportDirectory = reportDirectory; } @Override public ResourceAdaptersSubsystemService getValue() throws IllegalStateException { return this; } @Override public void start(StartContext context) throws StartException { SUBSYSTEM_RA_LOGGER.debugf("Starting ResourceAdaptersSubsystem Service"); } @Override public void stop(StopContext context) { SUBSYSTEM_RA_LOGGER.debugf("Stopping ResourceAdaptersSubsystem Service"); } public CopyOnWriteArrayListMultiMap<String, ServiceName> getAdapters() { return adapters; } public File getReportDirectory() { return reportDirectory; } public void setReportDirectory(File reportDirectory) { this.reportDirectory = reportDirectory; } }
2,969
33.534884
116
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdaptersExtension.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTERS_NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import org.jboss.as.controller.Extension; import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.SubsystemRegistration; import org.jboss.as.controller.access.constraint.SensitivityClassification; import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; import org.jboss.as.controller.parsing.ExtensionParsingContext; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** more * @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author <a href="mailto:[email protected]">Jeff Zhang</a> */ public class ResourceAdaptersExtension implements Extension { static final ModelVersion VERSION_6_0_0 = ModelVersion.create(6,0,0); // EAP 7.4.0 static final ModelVersion VERSION_6_1_0 = ModelVersion.create(6,1,0); // WFLY 27.0 static final ModelVersion VERSION_7_0_0 = ModelVersion.create(7,0,0); // WFLY 28.0 public static final String SUBSYSTEM_NAME = RESOURCEADAPTERS_NAME; static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME); private static final ModelVersion CURRENT_MODEL_VERSION = VERSION_7_0_0; private static final String RESOURCE_NAME = ResourceAdaptersExtension.class.getPackage().getName() + ".LocalDescriptions"; static final SensitivityClassification RA_SECURITY = new SensitivityClassification(SUBSYSTEM_NAME, "resource-adapter-security", false, true, true); static final SensitiveTargetAccessConstraintDefinition RA_SECURITY_DEF = new SensitiveTargetAccessConstraintDefinition(RA_SECURITY); public static ResourceDescriptionResolver getResourceDescriptionResolver(final String keyPrefix) { return new StandardResourceDescriptionResolver(keyPrefix, RESOURCE_NAME, ResourceAdaptersExtension.class.getClassLoader(), true, false); } @Override public void initialize(final ExtensionContext context) { SUBSYSTEM_RA_LOGGER.debugf("Initializing ResourceAdapters Extension"); // Register the remoting subsystem final SubsystemRegistration registration = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION); registration.registerXMLElementWriter(ResourceAdapterSubsystemParser.INSTANCE); // Remoting subsystem description and operation handlers registration.registerSubsystemModel(new ResourceAdaptersRootResourceDefinition(context.isRuntimeOnlyRegistrationValid())); if (context.isRuntimeOnlyRegistrationValid()) { ManagementResourceRegistration deployments = registration.registerDeploymentModel(new SimpleResourceDefinition( new SimpleResourceDefinition.Parameters(SUBSYSTEM_PATH, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader())) .setFeature(false) .setRuntime())); deployments.registerSubModel(new IronJacamarResourceDefinition()); } } @Override public void initializeParsers(final ExtensionParsingContext context) { ResourceAdapterSubsystemParser resourceAdapterSubsystemParser = ResourceAdapterSubsystemParser.INSTANCE; context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_1_0.getUriString(), resourceAdapterSubsystemParser); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_1_1.getUriString(), resourceAdapterSubsystemParser); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_2_0.getUriString(), resourceAdapterSubsystemParser); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_3_0.getUriString(), resourceAdapterSubsystemParser); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_4_0.getUriString(), resourceAdapterSubsystemParser); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_5_0.getUriString(), resourceAdapterSubsystemParser); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_6_0.getUriString(), resourceAdapterSubsystemParser); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_6_1.getUriString(), resourceAdapterSubsystemParser); context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.RESOURCEADAPTERS_7_0.getUriString(), resourceAdapterSubsystemParser); } }
6,192
57.424528
144
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/CommonIronJacamarParser.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.common.pool.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CLASS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTY_VALUE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.INTERLEAVING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MCP; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NOTXSEPARATEPOOL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NO_RECOVERY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.PAD_XID; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.POOL_NAME_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_PASSWORD; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_USERNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SAME_RM_OVERRIDE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SHARABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRACKING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_CCM; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WRAP_XA_RESOURCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.XA_RESOURCE_TIMEOUT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import javax.xml.stream.XMLStreamException; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.metadata.api.common.Security; import org.jboss.as.connector.util.AbstractParser; import org.jboss.as.connector.util.ParserException; import org.jboss.as.controller.parsing.ParseUtils; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.CommonBundle; import org.jboss.jca.common.api.metadata.common.Capacity; import org.jboss.jca.common.api.metadata.common.Pool; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.common.TimeOut; import org.jboss.jca.common.api.metadata.common.Validation; import org.jboss.jca.common.api.metadata.common.XaPool; import org.jboss.jca.common.api.metadata.ds.DataSource; import org.jboss.jca.common.api.metadata.ds.DsPool; import org.jboss.jca.common.api.metadata.ds.XaDataSource; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.metadata.resourceadapter.AdminObject; import org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.logging.Messages; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * A CommonIronJacamarParser. * * @author <a href="[email protected]">Stefano Maestri</a> */ public abstract class CommonIronJacamarParser extends AbstractParser { /** * The bundle */ private static CommonBundle bundle = Messages.getBundle(CommonBundle.class); protected void parseConfigProperties(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map) throws XMLStreamException, ParserException { String name = rawAttributeText(reader, "name"); final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); String value = rawElementText(reader); CONFIG_PROPERTY_VALUE.parseAndSetParameter(value, operation, reader); if (map.containsKey(name)) { throw ParseUtils.unexpectedElement(reader); } map.put(name, operation); } /** * parse a single connection-definition tag * * @param reader the reader * @throws XMLStreamException * XMLStreamException * @throws ParserException ParserException * @throws ValidateException * ValidateException */ protected void parseConnectionDefinitions_3_0(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map, final Map<String, HashMap<String, ModelNode>> configMap, final boolean isXa) throws XMLStreamException, ParserException, ValidateException { final ModelNode connectionDefinitionNode = new ModelNode(); connectionDefinitionNode.get(OP).set(ADD); String poolName = null; String jndiName = null; int attributeSize = reader.getAttributeCount(); boolean poolDefined = Boolean.FALSE; for (int i = 0; i < attributeSize; i++) { ConnectionDefinition.Attribute attribute = ConnectionDefinition.Attribute.forName(reader.getAttributeLocalName(i)); String value = reader.getAttributeValue(i); switch (attribute) { case ENABLED: { ENABLED.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case CONNECTABLE: { CONNECTABLE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case TRACKING: { TRACKING.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case JNDI_NAME: { jndiName = value; JNDI_NAME.parseAndSetParameter(jndiName, connectionDefinitionNode, reader); break; } case POOL_NAME: { poolName = value; break; } case USE_JAVA_CONTEXT: { USE_JAVA_CONTEXT.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case USE_CCM: { USE_CCM.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case SHARABLE: { SHARABLE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case ENLISTMENT: { ENLISTMENT.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case CLASS_NAME: { CLASS_NAME.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } default: throw ParseUtils.unexpectedAttribute(reader, i); } } if (poolName == null || poolName.trim().equals("")) { if (jndiName != null && jndiName.trim().length() != 0) { if (jndiName.contains("/")) { poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1); } else { poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1); } } else { throw ParseUtils.missingRequired(reader, EnumSet.of(ConnectionDefinition.Attribute.JNDI_NAME)); } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.CONNECTION_DEFINITION) { map.put(poolName, connectionDefinitionNode); return; } else { if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (ConnectionDefinition.Tag.forName(reader.getLocalName())) { case CONFIG_PROPERTY: { if (!configMap.containsKey(poolName)) { configMap.put(poolName, new HashMap<String, ModelNode>(0)); } parseConfigProperties(reader, configMap.get(poolName)); break; } case SECURITY: { parseSecuritySettings(reader, connectionDefinitionNode); break; } case TIMEOUT: { parseTimeOut(reader, connectionDefinitionNode); break; } case VALIDATION: { parseValidation(reader, connectionDefinitionNode); break; } case XA_POOL: { if (!isXa) { throw ParseUtils.unexpectedElement(reader); } if (poolDefined) { throw new ParserException(bundle.multiplePools()); } parseXaPool(reader, connectionDefinitionNode); poolDefined = true; break; } case POOL: { if (isXa) { throw ParseUtils.unexpectedElement(reader); } if (poolDefined) { throw new ParserException(bundle.multiplePools()); } parsePool(reader, connectionDefinitionNode); poolDefined = true; break; } case RECOVERY: { parseRecovery(reader, connectionDefinitionNode); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } /** * parse a single connection-definition tag * * @param reader the reader * @throws XMLStreamException * XMLStreamException * @throws ParserException ParserException * @throws ValidateException * ValidateException */ protected void parseConnectionDefinitions_4_0(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map, final Map<String, HashMap<String, ModelNode>> configMap, final boolean isXa) throws XMLStreamException, ParserException, ValidateException { final ModelNode connectionDefinitionNode = new ModelNode(); connectionDefinitionNode.get(OP).set(ADD); String poolName = null; String jndiName = null; int attributeSize = reader.getAttributeCount(); boolean poolDefined = Boolean.FALSE; for (int i = 0; i < attributeSize; i++) { ConnectionDefinition.Attribute attribute = ConnectionDefinition.Attribute.forName(reader.getAttributeLocalName(i)); String value = reader.getAttributeValue(i); switch (attribute) { case ENABLED: { ENABLED.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case CONNECTABLE: { CONNECTABLE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case TRACKING: { TRACKING.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case JNDI_NAME: { jndiName = value; JNDI_NAME.parseAndSetParameter(jndiName, connectionDefinitionNode, reader); break; } case POOL_NAME: { poolName = value; break; } case USE_JAVA_CONTEXT: { USE_JAVA_CONTEXT.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case USE_CCM: { USE_CCM.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case SHARABLE: { SHARABLE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case ENLISTMENT: { ENLISTMENT.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case CLASS_NAME: { CLASS_NAME.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case MCP: { MCP.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case ENLISTMENT_TRACE: ENLISTMENT_TRACE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; default: throw ParseUtils.unexpectedAttribute(reader, i); } } if (poolName == null || poolName.trim().equals("")) { if (jndiName != null && jndiName.trim().length() != 0) { if (jndiName.contains("/")) { poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1); } else { poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1); } } else { throw ParseUtils.missingRequired(reader, EnumSet.of(ConnectionDefinition.Attribute.JNDI_NAME)); } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.CONNECTION_DEFINITION) { map.put(poolName, connectionDefinitionNode); return; } else { if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (ConnectionDefinition.Tag.forName(reader.getLocalName())) { case CONFIG_PROPERTY: { if (!configMap.containsKey(poolName)) { configMap.put(poolName, new HashMap<String, ModelNode>(0)); } parseConfigProperties(reader, configMap.get(poolName)); break; } case SECURITY: { parseSecuritySettings(reader, connectionDefinitionNode); break; } case TIMEOUT: { parseTimeOut(reader, connectionDefinitionNode); break; } case VALIDATION: { parseValidation(reader, connectionDefinitionNode); break; } case XA_POOL: { if (!isXa) { throw ParseUtils.unexpectedElement(reader); } if (poolDefined) { throw new ParserException(bundle.multiplePools()); } parseXaPool(reader, connectionDefinitionNode); poolDefined = true; break; } case POOL: { if (isXa) { throw ParseUtils.unexpectedElement(reader); } if (poolDefined) { throw new ParserException(bundle.multiplePools()); } parsePool(reader, connectionDefinitionNode); poolDefined = true; break; } case RECOVERY: { parseRecovery(reader, connectionDefinitionNode); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } /** * Parses connection attributes for version 5.0 * @param reader the xml reader * @param connectionDefinitionNode the connection definition add node * @return the pool name * @throws XMLStreamException */ private String parseConnectionAttributes_5_0(final XMLExtendedStreamReader reader, final ModelNode connectionDefinitionNode) throws XMLStreamException { String poolName = null; String jndiName = null; int attributeSize = reader.getAttributeCount(); for (int i = 0; i < attributeSize; i++) { ConnectionDefinition.Attribute attribute = ConnectionDefinition.Attribute.forName(reader.getAttributeLocalName(i)); String value = reader.getAttributeValue(i); switch (attribute) { case ENABLED: { ENABLED.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case CONNECTABLE: { CONNECTABLE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case TRACKING: { TRACKING.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case JNDI_NAME: { jndiName = value; JNDI_NAME.parseAndSetParameter(jndiName, connectionDefinitionNode, reader); break; } case POOL_NAME: { poolName = value; break; } case USE_JAVA_CONTEXT: { USE_JAVA_CONTEXT.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case USE_CCM: { USE_CCM.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case SHARABLE: { SHARABLE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case ENLISTMENT: { ENLISTMENT.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case CLASS_NAME: { CLASS_NAME.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case MCP: { MCP.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case ENLISTMENT_TRACE: ENLISTMENT_TRACE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; default: throw ParseUtils.unexpectedAttribute(reader, i); } } if (poolName == null || poolName.trim().equals("")) { if (jndiName != null && jndiName.trim().length() != 0) { if (jndiName.contains("/")) { poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1); } else { poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1); } } else { throw ParseUtils.missingRequired(reader, EnumSet.of(ConnectionDefinition.Attribute.JNDI_NAME)); } } return poolName; } /** * parse a single connection-definition tag * * @param reader the reader * @throws XMLStreamException * XMLStreamException * @throws ParserException ParserException * @throws ValidateException * ValidateException */ protected void parseConnectionDefinitions_5_0(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map, final Map<String, HashMap<String, ModelNode>> configMap, final boolean isXa) throws XMLStreamException, ParserException, ValidateException { final ModelNode connectionDefinitionNode = new ModelNode(); connectionDefinitionNode.get(OP).set(ADD); final String poolName = parseConnectionAttributes_5_0(reader, connectionDefinitionNode); boolean poolDefined = Boolean.FALSE; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.CONNECTION_DEFINITION) { map.put(poolName, connectionDefinitionNode); return; } else { if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (ConnectionDefinition.Tag.forName(reader.getLocalName())) { case CONFIG_PROPERTY: { if (!configMap.containsKey(poolName)) { configMap.put(poolName, new HashMap<String, ModelNode>(0)); } parseConfigProperties(reader, configMap.get(poolName)); break; } case SECURITY: { parseElytronSupportedSecuritySettings(reader, connectionDefinitionNode); break; } case TIMEOUT: { parseTimeOut(reader, connectionDefinitionNode); break; } case VALIDATION: { parseValidation(reader, connectionDefinitionNode); break; } case XA_POOL: { if (!isXa) { throw ParseUtils.unexpectedElement(reader); } if (poolDefined) { throw new ParserException(bundle.multiplePools()); } parseXaPool(reader, connectionDefinitionNode); poolDefined = true; break; } case POOL: { if (isXa) { throw ParseUtils.unexpectedElement(reader); } if (poolDefined) { throw new ParserException(bundle.multiplePools()); } parsePool(reader, connectionDefinitionNode); poolDefined = true; break; } case RECOVERY: { parseElytronSupportedRecovery(reader, connectionDefinitionNode); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } /** * parse a single connection-definition tag * * @param reader the reader * @throws XMLStreamException * XMLStreamException * @throws ParserException ParserException * @throws ValidateException * ValidateException */ protected void parseConnectionDefinitions_1_0(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map, final Map<String, HashMap<String, ModelNode>> configMap, final boolean isXa) throws XMLStreamException, ParserException, ValidateException { final ModelNode connectionDefinitionNode = new ModelNode(); connectionDefinitionNode.get(OP).set(ADD); String poolName = null; String jndiName = null; int attributeSize = reader.getAttributeCount(); boolean poolDefined = Boolean.FALSE; for (int i = 0; i < attributeSize; i++) { ConnectionDefinition.Attribute attribute = ConnectionDefinition.Attribute.forName(reader.getAttributeLocalName(i)); String value = reader.getAttributeValue(i); switch (attribute) { case ENABLED: { ENABLED.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case JNDI_NAME: { jndiName = value; JNDI_NAME.parseAndSetParameter(jndiName, connectionDefinitionNode, reader); break; } case POOL_NAME: { poolName = value; break; } case USE_JAVA_CONTEXT: { USE_JAVA_CONTEXT.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case USE_CCM: { USE_CCM.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case SHARABLE: { SHARABLE.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case ENLISTMENT: { ENLISTMENT.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } case CLASS_NAME: { CLASS_NAME.parseAndSetParameter(value, connectionDefinitionNode, reader); break; } default: throw ParseUtils.unexpectedAttribute(reader,i); } } if (poolName == null || poolName.trim().equals("")) { if (jndiName != null && jndiName.trim().length() != 0) { if (jndiName.contains("/")) { poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1); } else { poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1); } } else { throw ParseUtils.missingRequired(reader, EnumSet.of(ConnectionDefinition.Attribute.JNDI_NAME)); } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.CONNECTION_DEFINITION) { map.put(poolName, connectionDefinitionNode); return; } else { if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (ConnectionDefinition.Tag.forName(reader.getLocalName())) { case CONFIG_PROPERTY: { if (!configMap.containsKey(poolName)) { configMap.put(poolName, new HashMap<String, ModelNode>(0)); } parseConfigProperties(reader, configMap.get(poolName)); break; } case SECURITY: { parseSecuritySettings(reader, connectionDefinitionNode); break; } case TIMEOUT: { parseTimeOut(reader, connectionDefinitionNode); break; } case VALIDATION: { parseValidation(reader, connectionDefinitionNode); break; } case XA_POOL: { if (!isXa) { throw ParseUtils.unexpectedElement(reader); } if (poolDefined) { throw new ParserException(bundle.multiplePools()); } parseXaPool(reader, connectionDefinitionNode); poolDefined = true; break; } case POOL: { if (isXa) { throw ParseUtils.unexpectedElement(reader); } if (poolDefined) { throw new ParserException(bundle.multiplePools()); } parsePool(reader, connectionDefinitionNode); poolDefined = true; break; } case RECOVERY: { parseRecovery(reader, connectionDefinitionNode); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } private void parseValidation(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.VALIDATION) { return; } else { if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (Validation.Tag.forName(reader.getLocalName())) { case BACKGROUND_VALIDATION: { String value = rawElementText(reader); BACKGROUNDVALIDATION.parseAndSetParameter(value, node, reader); break; } case BACKGROUND_VALIDATION_MILLIS: { String value = rawElementText(reader); BACKGROUNDVALIDATIONMILLIS.parseAndSetParameter(value, node, reader); break; } case USE_FAST_FAIL: { String value = rawElementText(reader); USE_FAST_FAIL.parseAndSetParameter(value, node, reader); break; } case VALIDATE_ON_MATCH: { String value = rawElementText(reader); VALIDATE_ON_MATCH.parseAndSetParameter(value, node, reader); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } private void parseTimeOut(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.TIMEOUT) { return; } else { if (TimeOut.Tag.forName(reader.getLocalName()) == TimeOut.Tag.UNKNOWN) { throw ParseUtils.unexpectedElement(reader); } } break; } case START_ELEMENT: { String value = rawElementText(reader); switch (TimeOut.Tag.forName(reader.getLocalName())) { case ALLOCATION_RETRY: { ALLOCATION_RETRY.parseAndSetParameter(value, node, reader); break; } case ALLOCATION_RETRY_WAIT_MILLIS: { ALLOCATION_RETRY_WAIT_MILLIS.parseAndSetParameter(value, node, reader); break; } case BLOCKING_TIMEOUT_MILLIS: { BLOCKING_TIMEOUT_WAIT_MILLIS.parseAndSetParameter(value, node, reader); break; } case IDLE_TIMEOUT_MINUTES: { IDLETIMEOUTMINUTES.parseAndSetParameter(value, node, reader); break; } case XA_RESOURCE_TIMEOUT: { XA_RESOURCE_TIMEOUT.parseAndSetParameter(value, node, reader); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } protected void parseAdminObjects(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map, final Map<String, HashMap<String, ModelNode>> configMap) throws XMLStreamException, ParserException, ValidateException { final ModelNode adminObjectNode = new ModelNode(); adminObjectNode.get(OP).set(ADD); int attributeSize = reader.getAttributeCount(); String poolName = null; String jndiName = null; for (int i = 0; i < attributeSize; i++) { AdminObject.Attribute attribute = AdminObject.Attribute.forName(reader .getAttributeLocalName(i)); switch (attribute) { case ENABLED: { String value = rawAttributeText(reader, ENABLED.getXmlName()); if (value != null) { ENABLED.parseAndSetParameter(value, adminObjectNode, reader); } break; } case JNDI_NAME: { jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); if (jndiName != null) { JNDI_NAME.parseAndSetParameter(jndiName, adminObjectNode, reader); } break; } case POOL_NAME: { poolName = rawAttributeText(reader, POOL_NAME_NAME); break; } case USE_JAVA_CONTEXT: { String value = rawAttributeText(reader, USE_JAVA_CONTEXT.getXmlName()); if (value != null) { USE_JAVA_CONTEXT.parseAndSetParameter(value, adminObjectNode, reader); } break; } case CLASS_NAME: { String value = rawAttributeText(reader, CLASS_NAME.getXmlName()); if (value != null) { CLASS_NAME.parseAndSetParameter(value, adminObjectNode, reader); } break; } default: throw ParseUtils.unexpectedAttribute(reader, i); } } if (poolName == null || poolName.trim().equals("")) { if (jndiName != null && jndiName.trim().length() != 0) { if (jndiName.contains("/")) { poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1); } else { poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1); } } else { throw ParseUtils.missingRequired(reader, EnumSet.of(AdminObject.Attribute.JNDI_NAME)); } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.ADMIN_OBJECT) { map.put(poolName, adminObjectNode); return; } else { if (AdminObject.Tag.forName(reader.getLocalName()) == AdminObject.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (AdminObject.Tag.forName(reader.getLocalName())) { case CONFIG_PROPERTY: { if (!configMap.containsKey(poolName)) { configMap.put(poolName, new HashMap<String, ModelNode>(0)); } parseConfigProperties(reader, configMap.get(poolName)); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } /** * parse a {@link XaPool} object * * @param reader reader * @throws XMLStreamException XMLStreamException * @throws ParserException * @throws ValidateException ValidateException */ protected void parseXaPool(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.XA_POOL) { return; } else { if (XaPool.Tag.forName(reader.getLocalName()) == XaPool.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (XaPool.Tag.forName(reader.getLocalName())) { case MAX_POOL_SIZE: { String value = rawElementText(reader); MAX_POOL_SIZE.parseAndSetParameter(value, node, reader); break; } case MIN_POOL_SIZE: { String value = rawElementText(reader); MIN_POOL_SIZE.parseAndSetParameter(value, node, reader); break; } case INITIAL_POOL_SIZE: { String value = rawElementText(reader); INITIAL_POOL_SIZE.parseAndSetParameter(value, node, reader); break; } case PREFILL: { String value = rawElementText(reader); POOL_PREFILL.parseAndSetParameter(value, node, reader); break; } case FAIR: { String value = rawElementText(reader); POOL_FAIR.parseAndSetParameter(value, node, reader); break; } case USE_STRICT_MIN: { String value = rawElementText(reader); POOL_USE_STRICT_MIN.parseAndSetParameter(value, node, reader); break; } case FLUSH_STRATEGY: { String value = rawElementText(reader); POOL_FLUSH_STRATEGY.parseAndSetParameter(value, node, reader); break; } case INTERLEAVING: { String value = rawElementText(reader); //just presence means true value = value == null ? "true" : value; INTERLEAVING.parseAndSetParameter(value, node, reader); break; } case IS_SAME_RM_OVERRIDE: { String value = rawElementText(reader); SAME_RM_OVERRIDE.parseAndSetParameter(value, node, reader); break; } case NO_TX_SEPARATE_POOLS: { String value = rawElementText(reader); //just presence means true value = value == null ? "true" : value; NOTXSEPARATEPOOL.parseAndSetParameter(value, node, reader); break; } case PAD_XID: { String value = rawElementText(reader); PAD_XID.parseAndSetParameter(value, node, reader); break; } case WRAP_XA_RESOURCE: { String value = rawElementText(reader); WRAP_XA_RESOURCE.parseAndSetParameter(value, node, reader); break; } case CAPACITY: { parseCapacity(reader, node); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } protected void parsePool(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.POOL) { return; } else { if (Pool.Tag.forName(reader.getLocalName()) == Pool.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (Pool.Tag.forName(reader.getLocalName())) { case MAX_POOL_SIZE: { String value = rawElementText(reader); MAX_POOL_SIZE.parseAndSetParameter(value, node, reader); break; } case INITIAL_POOL_SIZE: { String value = rawElementText(reader); INITIAL_POOL_SIZE.parseAndSetParameter(value, node, reader); break; } case MIN_POOL_SIZE: { String value = rawElementText(reader); MIN_POOL_SIZE.parseAndSetParameter(value, node, reader); break; } case PREFILL: { String value = rawElementText(reader); POOL_PREFILL.parseAndSetParameter(value, node, reader); break; } case FAIR: { String value = rawElementText(reader); POOL_FAIR.parseAndSetParameter( value, node, reader ); break; } case USE_STRICT_MIN: { String value = rawElementText(reader); POOL_USE_STRICT_MIN.parseAndSetParameter(value, node, reader); break; } case FLUSH_STRATEGY: { String value = rawElementText(reader); POOL_FLUSH_STRATEGY.parseAndSetParameter(value, node, reader); break; } case CAPACITY: { parseCapacity(reader, node); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } private void parseCapacity(XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DsPool.Tag.forName(reader.getLocalName()) == DsPool.Tag.CAPACITY) { return; } else { if (Capacity.Tag.forName(reader.getLocalName()) == Capacity.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (Capacity.Tag.forName(reader.getLocalName())) { case INCREMENTER: { parseExtension(reader, reader.getLocalName(), operation, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES); break; } case DECREMENTER: { parseExtension(reader, reader.getLocalName(), operation, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } protected void parseRecovery(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { for (Recovery.Attribute attribute : Recovery.Attribute.values()) { switch (attribute) { case NO_RECOVERY: { String value = rawAttributeText(reader, NO_RECOVERY.getXmlName()); if (value != null) { NO_RECOVERY.parseAndSetParameter(value, node, reader); } break; } default: break; } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.RECOVERY) { return; } else { if (Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { Recovery.Tag tag = Recovery.Tag.forName(reader.getLocalName()); switch (tag) { case RECOVER_CREDENTIAL: { parseRecoveryCredential(reader, node); break; } case RECOVER_PLUGIN: { parseExtension(reader, tag.getLocalName(), node, RECOVER_PLUGIN_CLASSNAME, RECOVER_PLUGIN_PROPERTIES); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } protected void parseElytronSupportedRecovery(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { for (Recovery.Attribute attribute : Recovery.Attribute.values()) { switch (attribute) { case NO_RECOVERY: { String value = rawAttributeText(reader, NO_RECOVERY.getXmlName()); if (value != null) { NO_RECOVERY.parseAndSetParameter(value, node, reader); } break; } default: break; } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.RECOVERY) { return; } else { if (Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { Recovery.Tag tag = Recovery.Tag.forName(reader.getLocalName()); switch (tag) { case RECOVER_CREDENTIAL: { parseElytronSupportedRecoveryCredential(reader, node); break; } case RECOVER_PLUGIN: { parseExtension(reader, tag.getLocalName(), node, RECOVER_PLUGIN_CLASSNAME, RECOVER_PLUGIN_PROPERTIES); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } private void parseSecuritySettings(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { boolean securtyDomainMatched = false; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY) { return; } else { if (Security.Tag.forName(reader.getLocalName()) == Security.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (Security.Tag.forName(reader.getLocalName())) { case SECURITY_DOMAIN: { if (securtyDomainMatched) { throw ParseUtils.unexpectedElement(reader); } String value = rawElementText(reader); SECURITY_DOMAIN.parseAndSetParameter(value, node, reader); securtyDomainMatched = true; break; } case SECURITY_DOMAIN_AND_APPLICATION: { String value = rawElementText(reader); SECURITY_DOMAIN_AND_APPLICATION.parseAndSetParameter(value, node, reader); break; } case APPLICATION: { String value = rawElementText(reader); //just presence means true value = value == null ? "true" : value; APPLICATION.parseAndSetParameter(value, node, reader); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } private void parseElytronSupportedSecuritySettings(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { boolean securityDomainMatched = false; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY) { return; } else { if (Security.Tag.forName(reader.getLocalName()) == Security.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (Security.Tag.forName(reader.getLocalName())) { case SECURITY_DOMAIN: { if (securityDomainMatched) { throw ParseUtils.unexpectedElement(reader); } String value = rawElementText(reader); SECURITY_DOMAIN.parseAndSetParameter(value, node, reader); securityDomainMatched = true; break; } case SECURITY_DOMAIN_AND_APPLICATION: { String value = rawElementText(reader); SECURITY_DOMAIN_AND_APPLICATION.parseAndSetParameter(value, node, reader); break; } case ELYTRON_ENABLED: { String value = rawElementText(reader); value = value == null? "true": value; ELYTRON_ENABLED.parseAndSetParameter(value, node, reader); break; } case AUTHENTICATION_CONTEXT: { String value = rawElementText(reader); AUTHENTICATION_CONTEXT.parseAndSetParameter(value, node, reader); break; } case AUTHENTICATION_CONTEXT_AND_APPLICATION: { String value = rawElementText(reader); AUTHENTICATION_CONTEXT_AND_APPLICATION.parseAndSetParameter(value, node, reader); break; } case APPLICATION: { String value = rawElementText(reader); // just presence means true value = value == null ? "true" : value; APPLICATION.parseAndSetParameter(value, node, reader); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } private void parseRecoveryCredential(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY || Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.RECOVER_CREDENTIAL) { return; } else { if (Credential.Tag.forName(reader.getLocalName()) == Credential.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (Credential.Tag.forName(reader.getLocalName())) { case PASSWORD: { String value = rawElementText(reader); RECOVERY_PASSWORD.parseAndSetParameter(value, node, reader); break; } case USER_NAME: { String value = rawElementText(reader); RECOVERY_USERNAME.parseAndSetParameter(value, node, reader); break; } case CREDENTIAL_REFERENCE: { RECOVERY_CREDENTIAL_REFERENCE.getParser().parseElement(RECOVERY_CREDENTIAL_REFERENCE, reader, node); } case SECURITY_DOMAIN: { String value = rawElementText(reader); RECOVERY_SECURITY_DOMAIN.parseAndSetParameter(value, node, reader); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } private void parseElytronSupportedRecoveryCredential(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (DataSource.Tag.forName(reader.getLocalName()) == DataSource.Tag.SECURITY || Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.RECOVER_CREDENTIAL) { return; } else { if (Credential.Tag.forName(reader.getLocalName()) == Credential.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); } } break; } case START_ELEMENT: { switch (Credential.Tag.forName(reader.getLocalName())) { case PASSWORD: { String value = rawElementText(reader); RECOVERY_PASSWORD.parseAndSetParameter(value, node, reader); break; } case CREDENTIAL_REFERENCE: { RECOVERY_CREDENTIAL_REFERENCE.getParser().parseElement(RECOVERY_CREDENTIAL_REFERENCE, reader, node); break; } case USER_NAME: { String value = rawElementText(reader); RECOVERY_USERNAME.parseAndSetParameter(value, node, reader); break; } case SECURITY_DOMAIN: { String value = rawElementText(reader); RECOVERY_SECURITY_DOMAIN.parseAndSetParameter(value, node, reader); break; } case ELYTRON_ENABLED: { String value = rawElementText(reader); value = value == null? "true": value; RECOVERY_ELYTRON_ENABLED.parseAndSetParameter(value, node, reader); break; } case AUTHENTICATION_CONTEXT: { String value = rawElementText(reader); RECOVERY_AUTHENTICATION_CONTEXT.parseAndSetParameter(value, node, reader); break; } default: throw ParseUtils.unexpectedElement(reader); } break; } } } throw ParseUtils.unexpectedEndElement(reader); } }
69,665
44.032967
165
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/RaActivate.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ARCHIVE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MODULE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceName; /** * Operation handler responsible for disabling an existing data-source. * * @author Stefano Maestri */ public class RaActivate implements OperationStepHandler { static final RaActivate INSTANCE = new RaActivate(); public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode address = operation.require(OP_ADDR); final String idName = PathAddress.pathAddress(address).getLastElement().getValue(); ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); final String archiveOrModuleName; if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) { throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired(); } if (model.get(ARCHIVE.getName()).isDefined()) { archiveOrModuleName = model.get(ARCHIVE.getName()).asString(); } else { archiveOrModuleName = model.get(MODULE.getName()).asString(); } if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException { ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, idName); if (restartedServiceName == null) { RaOperationUtil.activate(context, idName, archiveOrModuleName); } context.completeStep(new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext context, ModelNode operation) { try { RaOperationUtil.removeIfActive(context, archiveOrModuleName, idName); } catch (OperationFailedException e) { } } }); } }, OperationContext.Stage.RUNTIME); } } }
3,795
43.139535
126
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ReportDirectoryWriteHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceRegistry; import java.io.File; public class ReportDirectoryWriteHandler extends AbstractWriteAttributeHandler<Void> { private final AttributeDefinition attributeDefinition; ReportDirectoryWriteHandler(final AttributeDefinition attributeDefinition) { super(attributeDefinition); this.attributeDefinition = attributeDefinition; } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException { final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); updateReportDirectory(context, model); return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Void handback) throws OperationFailedException { final ModelNode restored = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().clone(); restored.get(attributeName).set(valueToRestore); updateReportDirectory(context, restored); } void updateReportDirectory(final OperationContext context, final ModelNode model) throws OperationFailedException { final String reportDirectoryName = this.attributeDefinition.resolveModelAttribute(context, model).asString(); final File reportDirectory = new File(reportDirectoryName); if(!reportDirectory.exists()){ throw ConnectorLogger.SUBSYSTEM_RA_LOGGER.reportDirectoryDoesNotExist(reportDirectoryName); } final ServiceRegistry registry = context.getServiceRegistry(true); final ServiceController<?> ejbNameServiceController = registry.getService(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE); ResourceAdaptersSubsystemService service = (ResourceAdaptersSubsystemService) ejbNameServiceController.getValue(); service.setReportDirectory(reportDirectory); } }
3,740
47.584416
162
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ConfigPropertyAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTY_VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * Adds a recovery-environment to the Transactions subsystem * */ public class ConfigPropertyAdd extends AbstractAddStepHandler { public static final ConfigPropertyAdd INSTANCE = new ConfigPropertyAdd(); @Override protected void populateModel(ModelNode operation, ModelNode modelNode) throws OperationFailedException { CONFIG_PROPERTY_VALUE.validateAndSet(operation, modelNode); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = CONFIG_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String archiveName = path.getElement(path.size() -2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, configPropertyName); ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName); final ServiceTarget serviceTarget = context.getServiceTarget(); final ConfigPropertiesService service = new ConfigPropertiesService(configPropertyName, configPropertyValue); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector() ) .install(); } }
3,352
45.569444
142
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/CDConfigPropertyAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTY_VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * Adds a recovery-environment to the Transactions subsystem * */ public class CDConfigPropertyAdd extends AbstractAddStepHandler { public static final CDConfigPropertyAdd INSTANCE = new CDConfigPropertyAdd(); @Override protected void populateModel(ModelNode operation, ModelNode modelNode) throws OperationFailedException { CONFIG_PROPERTY_VALUE.validateAndSet(operation, modelNode); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = CONFIG_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String archiveName = path.getElement(path.size() -3).getValue(); final String cfName = path.getElement(path.size() -2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, cfName, configPropertyName); ServiceName cfServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, cfName); final ServiceTarget serviceTarget = context.getServiceTarget(); final CDConfigPropertiesService service = new CDConfigPropertiesService(configPropertyName, configPropertyValue); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(cfServiceName, ModifiableConnDef.class, service.getRaInjector() ) .install(); } }
3,444
46.191781
142
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdapterSubsystemParser.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.common.pool.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ADMIN_OBJECTS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ARCHIVE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BEANVALIDATION_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BOOTSTRAP_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CLASS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTIES; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTIONDEFINITIONS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.INTERLEAVING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MCP; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MODULE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NOTXSEPARATEPOOL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NO_RECOVERY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.PAD_XID; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_PASSWORD; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_USERNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.REPORT_DIRECTORY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.REPORT_DIRECTORY_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTERS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTER_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SAME_RM_OVERRIDE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SHARABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRACKING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRANSACTION_SUPPORT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_CCM; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_ELYTRON_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_GROUP; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_PRINCIPAL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_FROM; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_REQUIRED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_TO; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_USERS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WRAP_XA_RESOURCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.XA_RESOURCE_TIMEOUT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import java.util.List; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.dmr.Property; import org.jboss.jca.common.api.metadata.common.Capacity; import org.jboss.jca.common.api.metadata.common.Pool; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.metadata.resourceadapter.Activations; import org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition; import org.jboss.jca.common.api.metadata.resourceadapter.WorkManager; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLElementWriter; import org.jboss.staxmapper.XMLExtendedStreamReader; import org.jboss.staxmapper.XMLExtendedStreamWriter; /** * @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2012 Red Hat Inc. */ public final class ResourceAdapterSubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> { static final ResourceAdapterSubsystemParser INSTANCE = new ResourceAdapterSubsystemParser(); /** {@inheritDoc} */ @Override public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { ModelNode node = context.getModelNode(); boolean resourceAdaptersDefined = node.hasDefined(RESOURCEADAPTER_NAME) && node.get(RESOURCEADAPTER_NAME).asPropertyList().size() > 0; boolean reportDirectoryDefined = node.hasDefined(REPORT_DIRECTORY_NAME); boolean hasChildren = resourceAdaptersDefined || reportDirectoryDefined; context.startSubsystemElement(Namespace.CURRENT.getUriString(), !hasChildren); if (hasChildren) { if(resourceAdaptersDefined) { writer.writeStartElement(Element.RESOURCE_ADAPTERS.getLocalName()); ModelNode ras = node.get(RESOURCEADAPTER_NAME); for (String name : ras.keys()) { final ModelNode ra = ras.get(name); writeRaElement(writer, ra, name); } writer.writeEndElement(); } if (reportDirectoryDefined) { writer.writeStartElement(Element.REPORT_DIRECTORY.getLocalName()); REPORT_DIRECTORY.marshallAsAttribute(node, writer); writer.writeEndElement(); } // Close the subsystem element writer.writeEndElement(); } } private void writeRaElement(XMLExtendedStreamWriter streamWriter, ModelNode ra, final String name) throws XMLStreamException { streamWriter.writeStartElement(Activations.Tag.RESOURCE_ADAPTER.getLocalName()); streamWriter.writeAttribute(ResourceAdapterParser.Attribute.ID.getLocalName(), name); STATISTICS_ENABLED.marshallAsAttribute(ra, streamWriter); ARCHIVE.marshallAsElement(ra, streamWriter); MODULE.marshallAsElement(ra, streamWriter); if (ra.hasDefined(BEANVALIDATION_GROUPS.getName())) { streamWriter.writeStartElement(Activation.Tag.BEAN_VALIDATION_GROUPS.getLocalName()); for (ModelNode bvg : ra.get(BEANVALIDATION_GROUPS.getName()).asList()) { streamWriter.writeStartElement(BEANVALIDATION_GROUPS.getXmlName()); streamWriter.writeCharacters(bvg.asString()); streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } BOOTSTRAP_CONTEXT.marshallAsElement(ra, streamWriter); writeNewConfigProperties(streamWriter, ra); TRANSACTION_SUPPORT.marshallAsElement(ra, streamWriter); TransactionSupportEnum transactionSupport = ra.hasDefined(TRANSACTION_SUPPORT.getName()) ? TransactionSupportEnum .valueOf(ra.get(TRANSACTION_SUPPORT.getName()).resolve().asString()) : null; boolean isXa = false; if (transactionSupport == TransactionSupportEnum.XATransaction) { isXa = true; } if (ra.hasDefined(WM_SECURITY.getName()) && (ra.get(WM_SECURITY.getName()).getType().equals(ModelType.EXPRESSION) || ra.get(WM_SECURITY.getName()).asBoolean())) { streamWriter.writeStartElement(Activation.Tag.WORKMANAGER.getLocalName()); streamWriter.writeStartElement(WorkManager.Tag.SECURITY.getLocalName()); WM_SECURITY.marshallAsAttribute(ra, streamWriter); WM_SECURITY_MAPPING_REQUIRED.marshallAsElement(ra, streamWriter); WM_SECURITY_DOMAIN.marshallAsElement(ra, streamWriter); WM_ELYTRON_SECURITY_DOMAIN.marshallAsElement(ra, streamWriter); WM_SECURITY_DEFAULT_PRINCIPAL.marshallAsElement(ra, streamWriter); if (ra.hasDefined(WM_SECURITY_DEFAULT_GROUPS.getName())) { streamWriter.writeStartElement(WM_SECURITY_DEFAULT_GROUPS.getXmlName()); for (ModelNode group : ra.get(WM_SECURITY_DEFAULT_GROUPS.getName()).asList()) { streamWriter.writeStartElement(WM_SECURITY_DEFAULT_GROUP.getXmlName()); streamWriter.writeCharacters(group.asString()); streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } if (ra.hasDefined(WM_SECURITY_MAPPING_USERS.getName()) || ra.hasDefined(WM_SECURITY_MAPPING_GROUPS.getName())) { streamWriter.writeStartElement(WorkManagerSecurity.Tag.MAPPINGS.getLocalName()); if (ra.hasDefined(WM_SECURITY_MAPPING_USERS.getName())) { streamWriter.writeStartElement(WorkManagerSecurity.Tag.USERS.getLocalName()); for (ModelNode node : ra.get(WM_SECURITY_MAPPING_USERS.getName()).asList()) { streamWriter.writeStartElement(WorkManagerSecurity.Tag.MAP.getLocalName()); WM_SECURITY_MAPPING_FROM.marshallAsAttribute(node, streamWriter); WM_SECURITY_MAPPING_TO.marshallAsAttribute(node, streamWriter); streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } if (ra.hasDefined(WM_SECURITY_MAPPING_GROUPS.getName())) { streamWriter.writeStartElement(WorkManagerSecurity.Tag.GROUPS.getLocalName()); for (ModelNode node : ra.get(WM_SECURITY_MAPPING_GROUPS.getName()).asList()) { streamWriter.writeStartElement(WorkManagerSecurity.Tag.MAP.getLocalName()); WM_SECURITY_MAPPING_FROM.marshallAsAttribute(node, streamWriter); WM_SECURITY_MAPPING_TO.marshallAsAttribute(node, streamWriter); streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } streamWriter.writeEndElement(); streamWriter.writeEndElement(); } if (ra.hasDefined(CONNECTIONDEFINITIONS_NAME)) { streamWriter.writeStartElement(Activation.Tag.CONNECTION_DEFINITIONS.getLocalName()); for (Property conDef : ra.get(CONNECTIONDEFINITIONS_NAME).asPropertyList()) { writeConDef(streamWriter, conDef.getValue(), conDef.getName(), isXa); } streamWriter.writeEndElement(); } if (ra.hasDefined(ADMIN_OBJECTS_NAME)) { streamWriter.writeStartElement(Activation.Tag.ADMIN_OBJECTS.getLocalName()); for (Property adminObject : ra.get(ADMIN_OBJECTS_NAME).asPropertyList()) { writeAdminObject(streamWriter, adminObject.getValue(), adminObject.getName()); } streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } private void writeNewConfigProperties(XMLExtendedStreamWriter streamWriter, ModelNode ra) throws XMLStreamException { if (ra.hasDefined(CONFIG_PROPERTIES.getName())) { for (Property connectionProperty : ra.get(CONFIG_PROPERTIES.getName()).asPropertyList()) { writeProperty(streamWriter, ra, connectionProperty.getName(), connectionProperty .getValue().get("value").asString(), Activation.Tag.CONFIG_PROPERTY.getLocalName()); } } } private void writeProperty(XMLExtendedStreamWriter writer, ModelNode node, String name, String value, String localName) throws XMLStreamException { writer.writeStartElement(localName); writer.writeAttribute("name", name); // TODO if WFCORE-4625 goes in, use the util method. if (value.indexOf('\n') > -1) { // Multiline content. Use the overloaded variant that staxmapper will format writer.writeCharacters(value); } else { // Staxmapper will just output the chars without adding newlines if this is used char[] chars = value.toCharArray(); writer.writeCharacters(chars, 0, chars.length); } writer.writeEndElement(); } private void writeAdminObject(XMLExtendedStreamWriter streamWriter, ModelNode adminObject, final String poolName) throws XMLStreamException { streamWriter.writeStartElement(Activation.Tag.ADMIN_OBJECT.getLocalName()); CLASS_NAME.marshallAsAttribute(adminObject, streamWriter); JNDI_NAME.marshallAsAttribute(adminObject, streamWriter); ENABLED.marshallAsAttribute(adminObject, streamWriter); USE_JAVA_CONTEXT.marshallAsAttribute(adminObject, streamWriter); streamWriter.writeAttribute("pool-name", poolName); writeNewConfigProperties(streamWriter, adminObject); streamWriter.writeEndElement(); } private void writeConDef(XMLExtendedStreamWriter streamWriter, ModelNode conDef, final String poolName, final boolean isXa) throws XMLStreamException { streamWriter.writeStartElement(Activation.Tag.CONNECTION_DEFINITION.getLocalName()); CLASS_NAME.marshallAsAttribute(conDef, streamWriter); JNDI_NAME.marshallAsAttribute(conDef, streamWriter); ENABLED.marshallAsAttribute(conDef, streamWriter); CONNECTABLE.marshallAsAttribute(conDef, streamWriter); TRACKING.marshallAsAttribute(conDef, streamWriter); USE_JAVA_CONTEXT.marshallAsAttribute(conDef, streamWriter); streamWriter.writeAttribute("pool-name", poolName); USE_CCM.marshallAsAttribute(conDef, streamWriter); SHARABLE.marshallAsAttribute(conDef, streamWriter); ENLISTMENT.marshallAsAttribute(conDef, streamWriter); MCP.marshallAsAttribute(conDef, streamWriter); ENLISTMENT_TRACE.marshallAsAttribute(conDef, streamWriter); writeNewConfigProperties(streamWriter, conDef); boolean poolRequired = INITIAL_POOL_SIZE.isMarshallable(conDef) || MAX_POOL_SIZE.isMarshallable(conDef) || MIN_POOL_SIZE.isMarshallable(conDef) || POOL_USE_STRICT_MIN.isMarshallable(conDef) || POOL_PREFILL.isMarshallable(conDef) || POOL_FAIR.isMarshallable(conDef) || POOL_FLUSH_STRATEGY.isMarshallable(conDef); final boolean capacityRequired = CAPACITY_INCREMENTER_CLASS.isMarshallable(conDef) || CAPACITY_INCREMENTER_PROPERTIES.isMarshallable(conDef) || CAPACITY_DECREMENTER_CLASS.isMarshallable(conDef) || CAPACITY_DECREMENTER_PROPERTIES.isMarshallable(conDef); poolRequired = poolRequired || capacityRequired; if (poolRequired) { if (isXa) { streamWriter.writeStartElement(ConnectionDefinition.Tag.XA_POOL.getLocalName()); MIN_POOL_SIZE.marshallAsElement(conDef, streamWriter); INITIAL_POOL_SIZE.marshallAsElement(conDef, streamWriter); MAX_POOL_SIZE.marshallAsElement(conDef, streamWriter); POOL_PREFILL.marshallAsElement(conDef, streamWriter); POOL_FAIR.marshallAsElement(conDef, streamWriter); POOL_USE_STRICT_MIN.marshallAsElement(conDef, streamWriter); POOL_FLUSH_STRATEGY.marshallAsElement(conDef, streamWriter); SAME_RM_OVERRIDE.marshallAsElement(conDef, streamWriter); if (conDef.hasDefined(INTERLEAVING.getName()) && conDef.get(INTERLEAVING.getName()).getType().equals(ModelType.BOOLEAN) && conDef.get(INTERLEAVING.getName()).asBoolean()) { streamWriter.writeEmptyElement(INTERLEAVING.getXmlName()); } else { INTERLEAVING.marshallAsElement(conDef, streamWriter); } if (conDef.hasDefined(NOTXSEPARATEPOOL.getName()) && conDef.get(NOTXSEPARATEPOOL.getName()).getType().equals(ModelType.BOOLEAN) && conDef.get(NOTXSEPARATEPOOL.getName()).asBoolean()) { streamWriter.writeEmptyElement(NOTXSEPARATEPOOL.getXmlName()); } else { NOTXSEPARATEPOOL.marshallAsElement(conDef, streamWriter); } PAD_XID.marshallAsElement(conDef, streamWriter); WRAP_XA_RESOURCE.marshallAsElement(conDef, streamWriter); } else { streamWriter.writeStartElement(ConnectionDefinition.Tag.POOL.getLocalName()); MIN_POOL_SIZE.marshallAsElement(conDef, streamWriter); INITIAL_POOL_SIZE.marshallAsElement(conDef, streamWriter); MAX_POOL_SIZE.marshallAsElement(conDef, streamWriter); POOL_PREFILL.marshallAsElement(conDef, streamWriter); POOL_USE_STRICT_MIN.marshallAsElement(conDef, streamWriter); POOL_FLUSH_STRATEGY.marshallAsElement(conDef, streamWriter); } if (capacityRequired) { streamWriter.writeStartElement(Pool.Tag.CAPACITY.getLocalName()); if (conDef.hasDefined(CAPACITY_INCREMENTER_CLASS.getName())) { streamWriter.writeStartElement(Capacity.Tag.INCREMENTER.getLocalName()); CAPACITY_INCREMENTER_CLASS.marshallAsAttribute(conDef, streamWriter); CAPACITY_INCREMENTER_PROPERTIES.marshallAsElement(conDef, streamWriter); streamWriter.writeEndElement(); } if (conDef.hasDefined(CAPACITY_DECREMENTER_CLASS.getName())) { streamWriter.writeStartElement(Capacity.Tag.DECREMENTER.getLocalName()); CAPACITY_DECREMENTER_CLASS.marshallAsAttribute(conDef, streamWriter); CAPACITY_DECREMENTER_PROPERTIES.marshallAsElement(conDef, streamWriter); streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } if (conDef.hasDefined(APPLICATION.getName()) || conDef.hasDefined(SECURITY_DOMAIN.getName()) || conDef.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()) || conDef.hasDefined(ELYTRON_ENABLED.getName())) { streamWriter.writeStartElement(ConnectionDefinition.Tag.SECURITY.getLocalName()); if (conDef.hasDefined(APPLICATION.getName()) && conDef.get(APPLICATION.getName()).getType().equals(ModelType.BOOLEAN) && conDef.get(APPLICATION.getName()).asBoolean()) { streamWriter.writeEmptyElement(APPLICATION.getXmlName()); } else { APPLICATION.marshallAsElement(conDef, streamWriter); } SECURITY_DOMAIN.marshallAsElement(conDef, streamWriter); SECURITY_DOMAIN_AND_APPLICATION.marshallAsElement(conDef, streamWriter); ELYTRON_ENABLED.marshallAsElement(conDef, streamWriter); AUTHENTICATION_CONTEXT.marshallAsElement(conDef, streamWriter); AUTHENTICATION_CONTEXT_AND_APPLICATION.marshallAsElement(conDef, streamWriter); streamWriter.writeEndElement(); } if (conDef.hasDefined(BLOCKING_TIMEOUT_WAIT_MILLIS.getName()) || conDef.hasDefined(IDLETIMEOUTMINUTES.getName()) || conDef.hasDefined(ALLOCATION_RETRY.getName()) || conDef.hasDefined(ALLOCATION_RETRY_WAIT_MILLIS.getName()) || conDef.hasDefined(XA_RESOURCE_TIMEOUT.getName())) { streamWriter.writeStartElement(ConnectionDefinition.Tag.TIMEOUT.getLocalName()); BLOCKING_TIMEOUT_WAIT_MILLIS.marshallAsElement(conDef, streamWriter); IDLETIMEOUTMINUTES.marshallAsElement(conDef, streamWriter); ALLOCATION_RETRY.marshallAsElement(conDef, streamWriter); ALLOCATION_RETRY_WAIT_MILLIS.marshallAsElement(conDef, streamWriter); XA_RESOURCE_TIMEOUT.marshallAsElement(conDef, streamWriter); streamWriter.writeEndElement(); } if (conDef.hasDefined(BACKGROUNDVALIDATION.getName()) || conDef.hasDefined(BACKGROUNDVALIDATIONMILLIS.getName()) || conDef.hasDefined(USE_FAST_FAIL.getName()) || conDef.hasDefined(VALIDATE_ON_MATCH.getName())) { streamWriter.writeStartElement(ConnectionDefinition.Tag.VALIDATION.getLocalName()); BACKGROUNDVALIDATION.marshallAsElement(conDef, streamWriter); BACKGROUNDVALIDATIONMILLIS.marshallAsElement(conDef, streamWriter); USE_FAST_FAIL.marshallAsElement(conDef, streamWriter); VALIDATE_ON_MATCH.marshallAsElement(conDef, streamWriter); streamWriter.writeEndElement(); } if (conDef.hasDefined(RECOVERY_USERNAME.getName()) || conDef.hasDefined(RECOVERY_PASSWORD.getName()) || conDef.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()) || conDef.hasDefined(RECOVER_PLUGIN_CLASSNAME.getName()) || conDef.hasDefined(RECOVER_PLUGIN_PROPERTIES.getName()) || conDef.hasDefined(NO_RECOVERY.getName()) || conDef.hasDefined(ELYTRON_ENABLED.getName())) { streamWriter.writeStartElement(ConnectionDefinition.Tag.RECOVERY.getLocalName()); NO_RECOVERY.marshallAsAttribute(conDef, streamWriter); if (conDef.hasDefined(RECOVERY_USERNAME.getName()) || conDef.hasDefined(RECOVERY_PASSWORD.getName()) || conDef.hasDefined(RECOVERY_CREDENTIAL_REFERENCE.getName()) || conDef.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()) || conDef.hasDefined(RECOVERY_ELYTRON_ENABLED.getName())) { streamWriter.writeStartElement(Recovery.Tag.RECOVER_CREDENTIAL.getLocalName()); RECOVERY_USERNAME.marshallAsElement(conDef, streamWriter); RECOVERY_PASSWORD.marshallAsElement(conDef, streamWriter); RECOVERY_CREDENTIAL_REFERENCE.marshallAsElement(conDef, streamWriter); RECOVERY_SECURITY_DOMAIN.marshallAsElement(conDef, streamWriter); RECOVERY_ELYTRON_ENABLED.marshallAsElement(conDef, streamWriter); RECOVERY_AUTHENTICATION_CONTEXT.marshallAsElement(conDef, streamWriter); streamWriter.writeEndElement(); } if (conDef.hasDefined(RECOVER_PLUGIN_CLASSNAME.getName()) || conDef.hasDefined(RECOVER_PLUGIN_PROPERTIES.getName())) { streamWriter.writeStartElement(Recovery.Tag.RECOVER_PLUGIN.getLocalName()); RECOVER_PLUGIN_CLASSNAME.marshallAsAttribute(conDef, streamWriter); if (conDef.hasDefined(RECOVER_PLUGIN_PROPERTIES.getName())) { for (Property property : conDef.get(RECOVER_PLUGIN_PROPERTIES.getName()).asPropertyList()) { writeProperty(streamWriter, conDef, property.getName(), property .getValue().asString(), org.jboss.jca.common.api.metadata.common.Extension.Tag.CONFIG_PROPERTY.getLocalName()); } } streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } streamWriter.writeEndElement(); } @Override public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException { final ModelNode address = new ModelNode(); address.add(ModelDescriptionConstants.SUBSYSTEM, RESOURCEADAPTERS_NAME); address.protect(); final ModelNode subsystem = new ModelNode(); subsystem.get(OP).set(ADD); subsystem.get(OP_ADDR).set(address); list.add(subsystem); try { switch (Namespace.forUri(reader.getNamespaceURI())) { case UNKNOWN: break; default: { String localName = reader.getLocalName(); final Element element = Element.forName(reader.getLocalName()); SUBSYSTEM_RA_LOGGER.tracef("%s -> %s", localName, element); switch (element) { case SUBSYSTEM: { ResourceAdapterParser parser = new ResourceAdapterParser(); parser.parse(reader, subsystem, list, address); //ParseUtils.requireNoContent(reader); break; } } break; } } } catch (Exception e) { throw new XMLStreamException(e); } } }
30,476
59.112426
181
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ModifiableConnDef.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.jboss.jca.common.api.metadata.common.Pool; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.common.Security; import org.jboss.jca.common.api.metadata.common.TimeOut; import org.jboss.jca.common.api.metadata.common.Validation; import org.jboss.jca.common.api.metadata.common.XaPool; import org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition; import org.jboss.jca.common.api.validator.ValidateException; public class ModifiableConnDef implements ConnectionDefinition { /** * The serialVersionUID */ private static final long serialVersionUID = -7109775624169563102L; private final ConcurrentHashMap<String, String> configProperties; private final String className; private final String jndiName; private final String poolName; private final Boolean enabled; private final Boolean useJavaContext; private final Boolean useCcm; private final Pool pool; private final TimeOut timeOut; private final Validation validation; private final Security security; private final Recovery recovery; private final Boolean sharable; private final Boolean enlistment; private final Boolean connectable; private final Boolean tracking; private final Boolean enlistmentTrace; private final String mcp; /** * Create a new ConnectionDefinition. * * @param configProperties configProperties * @param className className * @param jndiName jndiName * @param poolName poolName * @param enabled enabled * @param useJavaContext useJavaContext * @param useCcm useCcm * @param pool pool * @param timeOut timeOut * @param validation validation * @param security security * @param recovery recovery */ public ModifiableConnDef(Map<String, String> configProperties, String className, String jndiName, String poolName, Boolean enabled, Boolean useJavaContext, Boolean useCcm, Pool pool, TimeOut timeOut, Validation validation, Security security, Recovery recovery, Boolean sharable, Boolean enlistment, final Boolean connectable, final Boolean tracking, final String mcp, Boolean enlistmentTrace) throws ValidateException { super(); if (configProperties != null) { this.configProperties = new ConcurrentHashMap<String, String>(configProperties.size()); this.configProperties.putAll(configProperties); } else { this.configProperties = new ConcurrentHashMap<String, String>(0); } this.className = className; this.jndiName = jndiName; this.poolName = poolName; this.enabled = enabled; this.useJavaContext = useJavaContext; this.useCcm = useCcm; this.pool = pool; this.timeOut = timeOut; this.validation = validation; this.security = security; this.recovery = recovery; this.sharable = sharable; this.enlistment = enlistment; this.connectable = connectable; this.tracking = tracking; this.mcp = mcp; this.enlistmentTrace = enlistmentTrace; } /** * Get the configProperties. * * @return the configProperties. */ @Override public final Map<String, String> getConfigProperties() { return Collections.unmodifiableMap(configProperties); } public String addConfigProperty(String key, String value) { return configProperties.put(key, value); } /** * Get the className. * * @return the className. */ @Override public final String getClassName() { return className; } /** * Get the jndiName. * * @return the jndiName. */ @Override public final String getJndiName() { return jndiName; } /** * Get the poolName. * * @return the poolName. */ @Override public final String getPoolName() { return poolName; } /** * Get the enabled. * * @return the enabled. */ @Override public final Boolean isEnabled() { return enabled; } /** * Get the useJavaContext. * * @return the useJavaContext. */ @Override public final Boolean isUseJavaContext() { return useJavaContext; } /** * Get the useCcm. * * @return the useCcm. */ @Override public final Boolean isUseCcm() { return useCcm; } /** * Get the pool. * * @return the pool. */ @Override public final Pool getPool() { return pool; } /** * Get the timeOut. * * @return the timeOut. */ @Override public final TimeOut getTimeOut() { return timeOut; } /** * Get the validation. * * @return the validation. */ @Override public final Validation getValidation() { return validation; } /** * Get the security. * * @return the security. */ @Override public final Security getSecurity() { return security; } @Override public final Boolean isXa() { return (pool instanceof XaPool); } /** * Get the recovery. * * @return the recovery. */ @Override public final Recovery getRecovery() { return recovery; } @Override public Boolean isSharable() { return sharable; } @Override public Boolean isEnlistment() { return enlistment; } @Override public Boolean isConnectable() { return connectable; } @Override public Boolean isTracking() { return tracking; } @Override public String getMcp() { return mcp; } @Override public Boolean isEnlistmentTrace() { return enlistmentTrace; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((className == null) ? 0 : className.hashCode()); result = prime * result + ((configProperties == null) ? 0 : configProperties.hashCode()); result = prime * result + ((enabled == null) ? 0 : enabled.hashCode()); result = prime * result + ((jndiName == null) ? 0 : jndiName.hashCode()); result = prime * result + ((pool == null) ? 0 : pool.hashCode()); result = prime * result + ((poolName == null) ? 0 : poolName.hashCode()); result = prime * result + ((recovery == null) ? 0 : recovery.hashCode()); result = prime * result + ((security == null) ? 0 : security.hashCode()); result = prime * result + ((timeOut == null) ? 0 : timeOut.hashCode()); result = prime * result + ((useJavaContext == null) ? 0 : useJavaContext.hashCode()); result = prime * result + ((useCcm == null) ? 0 : useCcm.hashCode()); result = prime * result + ((validation == null) ? 0 : validation.hashCode()); result = prime * result + ((isXa() == null) ? 0 : isXa().hashCode()); result = prime * result + ((sharable == null) ? 0 : sharable.hashCode()); result = prime * result + ((enlistment == null) ? 0 : enlistment.hashCode()); result = prime * result + ((connectable == null) ? 0 : connectable.hashCode()); result = prime * result + ((tracking == null) ? 0 : tracking.hashCode()); result = prime * result + ((mcp == null) ? 0 : mcp.hashCode()); result = prime * result + ((enlistmentTrace == null) ? 0 : enlistmentTrace.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof ModifiableConnDef)) return false; ModifiableConnDef other = (ModifiableConnDef) obj; if (className == null) { if (other.className != null) return false; } else if (!className.equals(other.className)) return false; if (configProperties == null) { if (other.configProperties != null) return false; } else if (!configProperties.equals(other.configProperties)) return false; if (enabled == null) { if (other.enabled != null) return false; } else if (!enabled.equals(other.enabled)) return false; if (jndiName == null) { if (other.jndiName != null) return false; } else if (!jndiName.equals(other.jndiName)) return false; if (pool == null) { if (other.pool != null) return false; } else if (!pool.equals(other.pool)) return false; if (poolName == null) { if (other.poolName != null) return false; } else if (!poolName.equals(other.poolName)) return false; if (recovery == null) { if (other.recovery != null) return false; } else if (!recovery.equals(other.recovery)) return false; if (security == null) { if (other.security != null) return false; } else if (!security.equals(other.security)) return false; if (timeOut == null) { if (other.timeOut != null) return false; } else if (!timeOut.equals(other.timeOut)) return false; if (useJavaContext == null) { if (other.useJavaContext != null) return false; } else if (!useJavaContext.equals(other.useJavaContext)) return false; if (useCcm == null) { if (other.useCcm != null) return false; } else if (!useCcm.equals(other.useCcm)) return false; if (validation == null) { if (other.validation != null) return false; } else if (!validation.equals(other.validation)) return false; if (isXa() == null) { if (other.isXa() != null) return false; } else if (!isXa().equals(other.isXa())) return false; if (sharable == null) { if (other.sharable != null) return false; } else if (!sharable.equals(other.sharable)) return false; if (enlistment == null) { if (other.enlistment != null) return false; } else if (!enlistment.equals(other.enlistment)) return false; if (connectable == null) { if (other.connectable != null) return false; } else if (!connectable.equals(other.connectable)) return false; if (tracking == null) { if (other.tracking != null) return false; } else if (!tracking.equals(other.tracking)) return false; if (mcp == null) { if (other.mcp != null) return false; } else if (!mcp.equals(other.mcp)) return false; if (enlistmentTrace == null) { if (other.enlistmentTrace != null) return false; } else if (!enlistmentTrace.equals(other.enlistmentTrace)) return false; return true; } @Override public String toString() { StringBuilder sb = new StringBuilder(1024); sb.append("<connection-definition"); if (className != null) sb.append(" ").append(Attribute.CLASS_NAME).append("=\"").append(className).append("\""); if (jndiName != null) sb.append(" ").append(Attribute.JNDI_NAME).append("=\"").append(jndiName).append("\""); if (enabled != null) sb.append(" ").append(Attribute.ENABLED).append("=\"").append(enabled).append("\""); if (useJavaContext != null) { sb.append(" ").append(Attribute.USE_JAVA_CONTEXT); sb.append("=\"").append(useJavaContext).append("\""); } if (poolName != null) sb.append(" ").append(Attribute.POOL_NAME).append("=\"").append(poolName).append("\""); if (useCcm != null) sb.append(" ").append(Attribute.USE_CCM).append("=\"").append(useCcm).append("\""); if (sharable != null) sb.append(" ").append(Attribute.SHARABLE).append("=\"").append(sharable).append("\""); if (enlistment != null) sb.append(" ").append(Attribute.ENLISTMENT).append("=\"").append(enlistment).append("\""); if (connectable != null) sb.append(" ").append(Attribute.CONNECTABLE).append("=\""). append(connectable).append("\""); if (tracking != null) sb.append(" ").append(Attribute.TRACKING).append("=\"").append(tracking).append("\""); if (mcp != null) sb.append(" ").append(Attribute.MCP).append("=\"").append(mcp).append("\""); if (enlistmentTrace != null) sb.append(" ").append(Attribute.ENLISTMENT_TRACE).append("=\"") .append(enlistmentTrace).append("\""); sb.append(">"); if (configProperties != null && configProperties.size() > 0) { Iterator<Map.Entry<String, String>> it = configProperties.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> entry = it.next(); sb.append("<").append(Tag.CONFIG_PROPERTY); sb.append(" name=\"").append(entry.getKey()).append("\">"); sb.append(entry.getValue()); sb.append("</").append(Tag.CONFIG_PROPERTY).append(">"); } } if (pool != null) sb.append(pool); if (security != null) sb.append(security); if (timeOut != null) sb.append(timeOut); if (validation != null) sb.append(validation); if (recovery != null) sb.append(recovery); sb.append("</connection-definition>"); return sb.toString(); } }
15,637
29.662745
149
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/WorkManagerRuntimeAttributeReadHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.workmanager.DistributedWorkManager; import org.jboss.jca.core.api.workmanager.WorkManager; import org.jboss.jca.core.api.workmanager.WorkManagerStatistics; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; public class WorkManagerRuntimeAttributeReadHandler implements OperationStepHandler { private final WorkManagerStatistics wmStat; private final WorkManager wm; private final boolean distributed; public WorkManagerRuntimeAttributeReadHandler(WorkManager wm, final WorkManagerStatistics wmStat, boolean distributed) { this.wm = wm; this.wmStat = wmStat; this.distributed = distributed; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { context.addStep(new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(NAME).asString(); try { final ModelNode result = context.getResult(); switch (attributeName) { case Constants.WORK_ACTIVE_NAME: { result.set(wmStat.getWorkActive()); break; } case Constants.WORK_FAILED_NAME: { result.set(wmStat.getWorkFailed()); break; } case Constants.WORK_SUCEESSFUL_NAME: { result.set(wmStat.getWorkSuccessful()); break; } case Constants.DO_WORK_ACCEPTED_NAME: { result.set(wmStat.getDoWorkAccepted()); break; } case Constants.DO_WORK_REJECTED_NAME: { result.set(wmStat.getDoWorkRejected()); break; } case Constants.SCHEDULED_WORK_ACCEPTED_NAME: { result.set(wmStat.getScheduleWorkAccepted()); break; } case Constants.SCHEDULED_WORK_REJECTED_NAME: { result.set(wmStat.getScheduleWorkRejected()); break; } case Constants.START_WORK_ACCEPTED_NAME: { result.set(wmStat.getStartWorkAccepted()); break; } case Constants.START_WORK_REJECTED_NAME: { result.set(wmStat.getStartWorkRejected()); break; } case ModelDescriptionConstants.STATISTICS_ENABLED: { if (distributed) { result.set(((DistributedWorkManager) wm).isDistributedStatisticsEnabled()); } else { result.set(wm.isStatisticsEnabled()); } break; } case Constants.WORKMANAGER_STATISTICS_ENABLED_NAME: { result.set(wm.isStatisticsEnabled()); break; } case Constants.DISTRIBUTED_STATISTICS_ENABLED_NAME: { result.set(((DistributedWorkManager) wm).isDistributedStatisticsEnabled()); break; } case Constants.DOWORK_DISTRIBUTION_ENABLED_NAME: { result.set(((DistributedWorkManager) wm).isDoWorkDistributionEnabled()); break; } case Constants.STARTWORK_DISTRIBUTION_ENABLED_NAME: { result.set(((DistributedWorkManager) wm).isStartWorkDistributionEnabled()); break; } case Constants.SCHEDULEWORK_DISTRIBUTION_ENABLED_NAME: { result.set(((DistributedWorkManager) wm).isScheduleWorkDistributionEnabled()); break; } } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } }, OperationContext.Stage.RUNTIME); } } }
6,601
47.903704
132
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/AOConfigPropertyAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTY_VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; /** * Adds a recovery-environment to the Transactions subsystem * */ public class AOConfigPropertyAdd extends AbstractAddStepHandler { public static final AOConfigPropertyAdd INSTANCE = new AOConfigPropertyAdd(); @Override protected void populateModel(ModelNode operation, ModelNode modelNode) throws OperationFailedException { CONFIG_PROPERTY_VALUE.validateAndSet(operation, modelNode); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = CONFIG_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String archiveName = path.getElement(path.size() -3).getValue(); final String aoName = path.getElement(path.size() -2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, aoName, configPropertyName); ServiceName aoServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, aoName); final ServiceTarget serviceTarget = context.getServiceTarget(); final AOConfigPropertiesService service = new AOConfigPropertiesService(configPropertyName, configPropertyValue); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(aoServiceName, ModifiableAdminObject.class, service.getAOInjector() ) .install(); } }
3,447
46.888889
142
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/RaOperationUtil.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector._private.Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY; import static org.jboss.as.connector._private.Capabilities.ELYTRON_SECURITY_DOMAIN_CAPABILITY; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.common.pool.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BEANVALIDATION_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BOOTSTRAP_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CLASS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.INTERLEAVING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MCP; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NOTXSEPARATEPOOL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NO_RECOVERY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.PAD_XID; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_PASSWORD; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_USERNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SAME_RM_OVERRIDE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SHARABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRACKING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRANSACTION_SUPPORT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_CCM; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_ELYTRON_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_PRINCIPAL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_FROM; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_REQUIRED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_TO; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_USERS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WRAP_XA_RESOURCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.XA_RESOURCE_TIMEOUT; import java.io.Closeable; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jboss.as.connector.deployers.ra.processors.IronJacamarDeploymentParsingProcessor; import org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor; import org.jboss.as.connector.deployers.ra.processors.RaDeploymentParsingProcessor; import org.jboss.as.connector.deployers.ra.processors.RaNativeProcessor; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.metadata.common.CredentialImpl; import org.jboss.as.connector.metadata.common.SecurityImpl; import org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl; import org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor; import org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor; import org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService; import org.jboss.as.connector.services.resourceadapters.deployment.ResourceAdapterXmlDeploymentService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.connector.util.ModelNodeUtil; import org.jboss.as.connector.util.RaServicesFactory; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.UninterruptibleCountDownLatch; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.annotation.ResourceRootIndexer; import org.jboss.as.server.deployment.module.MountHandle; import org.jboss.as.server.deployment.module.ResourceRoot; import org.jboss.as.server.deployment.module.TempFileProviderService; import org.jboss.dmr.ModelNode; import org.jboss.jandex.Index; import org.jboss.jca.common.api.metadata.common.Capacity; import org.jboss.jca.common.api.metadata.common.Extension; import org.jboss.jca.common.api.metadata.common.FlushStrategy; import org.jboss.jca.common.api.metadata.common.Pool; import org.jboss.jca.common.api.metadata.common.Recovery; import org.jboss.jca.common.api.metadata.common.Security; import org.jboss.jca.common.api.metadata.common.TimeOut; import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum; import org.jboss.jca.common.api.metadata.common.Validation; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.metadata.resourceadapter.AdminObject; import org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition; import org.jboss.jca.common.api.metadata.resourceadapter.WorkManager; import org.jboss.jca.common.api.metadata.resourceadapter.WorkManagerSecurity; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.common.metadata.common.PoolImpl; import org.jboss.jca.common.metadata.common.TimeOutImpl; import org.jboss.jca.common.metadata.common.ValidationImpl; import org.jboss.jca.common.metadata.common.XaPoolImpl; import org.jboss.jca.common.metadata.resourceadapter.WorkManagerImpl; import org.jboss.modules.Module; import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoadException; import org.jboss.modules.ModuleNotFoundException; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; import org.jboss.msc.service.ServiceTarget; import org.jboss.vfs.VFS; import org.jboss.vfs.VirtualFile; import org.jboss.vfs.VisitorAttributes; import org.jboss.vfs.util.SuffixMatchFilter; import org.wildfly.common.function.ExceptionSupplier; import org.wildfly.security.auth.client.AuthenticationContext; import org.wildfly.security.auth.server.SecurityDomain; import org.wildfly.security.credential.source.CredentialSource; public class RaOperationUtil { private static final ServiceName SECURITY_DOMAIN_SERVICE = ServiceName.JBOSS.append("security", "security-domain"); public static final ServiceName RAR_MODULE = ServiceName.of("rarinsidemodule"); public static ModifiableResourceAdapter buildResourceAdaptersObject(final String id, final OperationContext context, ModelNode operation, String archiveOrModule) throws OperationFailedException { Map<String, String> configProperties = new HashMap<>(0); List<ConnectionDefinition> connectionDefinitions = new ArrayList<>(0); List<AdminObject> adminObjects = new ArrayList<>(0); String transactionSupportResolved = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, TRANSACTION_SUPPORT); TransactionSupportEnum transactionSupport = operation.hasDefined(TRANSACTION_SUPPORT.getName()) ? TransactionSupportEnum .valueOf(ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, TRANSACTION_SUPPORT)) : null; String bootstrapContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, BOOTSTRAP_CONTEXT); List<String> beanValidationGroups = BEANVALIDATION_GROUPS.unwrap(context, operation); boolean wmSecurity = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, operation, WM_SECURITY); WorkManager workManager = null; if (wmSecurity) { final boolean mappingRequired = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, operation, WM_SECURITY_MAPPING_REQUIRED); String domain; final String elytronDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, WM_ELYTRON_SECURITY_DOMAIN); if (elytronDomain != null) { domain = elytronDomain; } else { throw new OperationFailedException(SUBSYSTEM_RA_LOGGER.legacySecurityNotSupported()); } final String defaultPrincipal = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, WM_SECURITY_DEFAULT_PRINCIPAL); final List<String> defaultGroups = WM_SECURITY_DEFAULT_GROUPS.unwrap(context, operation); final Map<String, String> groups = ModelNodeUtil.extractMap(operation, WM_SECURITY_MAPPING_GROUPS, WM_SECURITY_MAPPING_FROM, WM_SECURITY_MAPPING_TO); final Map<String, String> users = ModelNodeUtil.extractMap(operation, WM_SECURITY_MAPPING_USERS, WM_SECURITY_MAPPING_FROM, WM_SECURITY_MAPPING_TO); workManager = new WorkManagerImpl(new WorkManagerSecurityImpl(mappingRequired, domain, elytronDomain != null, defaultPrincipal, defaultGroups, users, groups)); } ModifiableResourceAdapter ra; ra = new ModifiableResourceAdapter(id, archiveOrModule, transactionSupport, connectionDefinitions, adminObjects, configProperties, beanValidationGroups, bootstrapContext, workManager); return ra; } public static ModifiableConnDef buildConnectionDefinitionObject(final OperationContext context, final ModelNode connDefModel, final String poolName, final boolean isXa, ExceptionSupplier<CredentialSource, Exception> recoveryCredentialSourceSupplier) throws OperationFailedException, ValidateException { Map<String, String> configProperties = new HashMap<String, String>(0); String className = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, CLASS_NAME); String jndiName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, JNDI_NAME); boolean enabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, ENABLED); boolean connectable = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, CONNECTABLE); Boolean tracking = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, TRACKING); boolean useJavaContext = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, USE_JAVA_CONTEXT); boolean useCcm = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, USE_CCM); boolean sharable = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, SHARABLE); boolean enlistment = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, ENLISTMENT); final String mcp = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, MCP); final Boolean enlistmentTrace = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, ENLISTMENT_TRACE); int maxPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(context, connDefModel, MAX_POOL_SIZE); int minPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(context, connDefModel, MIN_POOL_SIZE); Integer initialPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(context, connDefModel, INITIAL_POOL_SIZE); boolean prefill = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, POOL_PREFILL); boolean fair = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, POOL_FAIR); boolean useStrictMin = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, POOL_USE_STRICT_MIN); String flushStrategyString = POOL_FLUSH_STRATEGY.resolveModelAttribute(context, connDefModel).asString(); final FlushStrategy flushStrategy = FlushStrategy.forName(flushStrategyString); Boolean isSameRM = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, SAME_RM_OVERRIDE); boolean interlivng = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, INTERLEAVING); boolean padXid = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, PAD_XID); boolean wrapXaResource = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, WRAP_XA_RESOURCE); boolean noTxSeparatePool = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, NOTXSEPARATEPOOL); Integer allocationRetry = ModelNodeUtil.getIntIfSetOrGetDefault(context, connDefModel, ALLOCATION_RETRY); Long allocationRetryWaitMillis = ModelNodeUtil.getLongIfSetOrGetDefault(context, connDefModel, ALLOCATION_RETRY_WAIT_MILLIS); Long blockingTimeoutMillis = ModelNodeUtil.getLongIfSetOrGetDefault(context, connDefModel, BLOCKING_TIMEOUT_WAIT_MILLIS); Long idleTimeoutMinutes = ModelNodeUtil.getLongIfSetOrGetDefault(context, connDefModel, IDLETIMEOUTMINUTES); Integer xaResourceTimeout = ModelNodeUtil.getIntIfSetOrGetDefault(context, connDefModel, XA_RESOURCE_TIMEOUT); TimeOut timeOut = new TimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry, allocationRetryWaitMillis, xaResourceTimeout); Extension incrementer = ModelNodeUtil.extractExtension(context, connDefModel, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES); Extension decrementer = ModelNodeUtil.extractExtension(context, connDefModel, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES); final Capacity capacity = new Capacity(incrementer, decrementer); Pool pool; if (isXa) { pool = new XaPoolImpl(minPoolSize, initialPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy, capacity, fair, isSameRM, interlivng, padXid, wrapXaResource, noTxSeparatePool); } else { pool = new PoolImpl(minPoolSize, initialPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy, capacity, fair); } String securityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, SECURITY_DOMAIN); String securityDomainAndApplication = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, SECURITY_DOMAIN_AND_APPLICATION); if (securityDomain != null || securityDomainAndApplication != null) { throw new OperationFailedException(SUBSYSTEM_RA_LOGGER.legacySecurityNotSupported()); } String authenticationContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, AUTHENTICATION_CONTEXT); String authenticationContextAndApplication = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, AUTHENTICATION_CONTEXT_AND_APPLICATION); boolean application = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, APPLICATION); Security security = null; if (authenticationContext != null || authenticationContextAndApplication != null || application) { security = new SecurityImpl(authenticationContext, authenticationContextAndApplication, application); } Long backgroundValidationMillis = ModelNodeUtil.getLongIfSetOrGetDefault(context, connDefModel, BACKGROUNDVALIDATIONMILLIS); Boolean backgroundValidation = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, BACKGROUNDVALIDATION); boolean useFastFail = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, USE_FAST_FAIL); final Boolean validateOnMatch = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, VALIDATE_ON_MATCH ); Validation validation = new ValidationImpl(validateOnMatch, backgroundValidation, backgroundValidationMillis, useFastFail); final String recoveryUsername = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, RECOVERY_USERNAME); final String recoveryPassword = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, RECOVERY_PASSWORD); final String recoverySecurityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, RECOVERY_SECURITY_DOMAIN); if (recoverySecurityDomain != null) { throw new OperationFailedException(SUBSYSTEM_RA_LOGGER.legacySecurityNotSupported()); } final String recoveryAuthenticationContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, connDefModel, RECOVERY_AUTHENTICATION_CONTEXT); Boolean noRecovery = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, connDefModel, NO_RECOVERY); Recovery recovery = null; if ((recoveryUsername != null && (recoveryPassword != null || recoveryCredentialSourceSupplier != null)) || recoveryAuthenticationContext != null || noRecovery != null) { Credential credential = null; if ((recoveryUsername != null && (recoveryPassword != null || recoveryCredentialSourceSupplier != null)) || recoveryAuthenticationContext != null) credential = new CredentialImpl(recoveryUsername, recoveryPassword, recoveryAuthenticationContext, recoveryCredentialSourceSupplier); Extension recoverPlugin = ModelNodeUtil.extractExtension(context, connDefModel, RECOVER_PLUGIN_CLASSNAME, RECOVER_PLUGIN_PROPERTIES); if (noRecovery == null) noRecovery = Boolean.FALSE; recovery = new Recovery(credential, recoverPlugin, noRecovery); } ModifiableConnDef connectionDefinition = new ModifiableConnDef(configProperties, className, jndiName, poolName, enabled, useJavaContext, useCcm, pool, timeOut, validation, security, recovery, sharable, enlistment, connectable, tracking, mcp, enlistmentTrace); return connectionDefinition; } public static ModifiableAdminObject buildAdminObjects(final OperationContext context, ModelNode operation, final String poolName) throws OperationFailedException, ValidateException { Map<String, String> configProperties = new HashMap<String, String>(0); String className = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, CLASS_NAME); String jndiName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, JNDI_NAME); boolean enabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, operation, ENABLED); boolean useJavaContext = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, operation, USE_JAVA_CONTEXT); ModifiableAdminObject adminObject = new ModifiableAdminObject(configProperties, className, jndiName, poolName, enabled, useJavaContext); return adminObject; } public static ServiceName restartIfPresent(OperationContext context, final String raName, final String id) throws OperationFailedException { final ServiceName raDeploymentServiceName = ConnectorServices.getDeploymentServiceName(raName, id); final ServiceRegistry registry = context.getServiceRegistry(true); ServiceController raServiceController = registry.getService(raDeploymentServiceName); if (raServiceController != null) { final ServiceController.Mode originalMode = raServiceController.getMode(); final UninterruptibleCountDownLatch latch = new UninterruptibleCountDownLatch(1); raServiceController.addListener(new LifecycleListener() { @Override public void handleEvent(ServiceController controller, LifecycleEvent event) { latch.awaitUninterruptibly(); if (event == LifecycleEvent.DOWN) { try { final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, id)); Activation raxml = (Activation) RaxmlController.getValue(); ((ResourceAdapterXmlDeploymentService) controller.getService()).setRaxml(raxml); controller.compareAndSetMode(ServiceController.Mode.NEVER, originalMode); } finally { controller.removeListener(this); } } } }); try { raServiceController.setMode(ServiceController.Mode.NEVER); } finally { latch.countDown(); } return raDeploymentServiceName; } else { return null; } } public static boolean removeIfActive(OperationContext context, String raName, String id ) throws OperationFailedException { boolean wasActive = false; final ServiceName raDeploymentServiceName; if (raName == null) { raDeploymentServiceName = ConnectorServices.getDeploymentServiceName(id); } else { raDeploymentServiceName = ConnectorServices.getDeploymentServiceName(raName, id); } if(context.getServiceRegistry(true).getService(raDeploymentServiceName) != null){ context.removeService(raDeploymentServiceName); wasActive = true; } return wasActive; } public static void activate(OperationContext context, String raName, String archiveName) throws OperationFailedException { ServiceRegistry registry = context.getServiceRegistry(true); ServiceController<?> inactiveRaController = registry.getService(ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(archiveName)); final CapabilityServiceSupport support = context.getCapabilityServiceSupport(); if (inactiveRaController == null) { inactiveRaController = registry.getService(ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(raName)); if (inactiveRaController == null) { throw ConnectorLogger.ROOT_LOGGER.RARNotYetDeployed(raName); } } InactiveResourceAdapterDeploymentService.InactiveResourceAdapterDeployment inactive = (InactiveResourceAdapterDeploymentService.InactiveResourceAdapterDeployment) inactiveRaController.getValue(); final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName)); Activation raxml = (Activation) RaxmlController.getValue(); RaServicesFactory.createDeploymentService(inactive.getRegistration(), inactive.getConnectorXmlDescriptor(), inactive.getModule(), inactive.getServiceTarget(), archiveName, inactive.getDeploymentUnitServiceName(), inactive.getDeployment(), raxml, inactive.getResource(), registry, support); } public static ServiceName installRaServices(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, final List<ServiceController<?>> newControllers) { final ServiceTarget serviceTarget = context.getServiceTarget(); final ServiceController<?> resourceAdaptersService = context.getServiceRegistry(false).getService( ConnectorServices.RESOURCEADAPTERS_SERVICE); if (resourceAdaptersService == null) { newControllers.add(serviceTarget.addService(ConnectorServices.RESOURCEADAPTERS_SERVICE, new ResourceAdaptersService()).setInitialMode(ServiceController.Mode.ACTIVE).install()); } ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, name); final ServiceController<?> service = context.getServiceRegistry(true).getService(raServiceName); if (service == null) { ResourceAdapterService raService = new ResourceAdapterService(resourceAdapter, name); ServiceBuilder builder = serviceTarget.addService(raServiceName, raService).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(ConnectorServices.RESOURCEADAPTERS_SERVICE, ResourceAdaptersService.ModifiableResourceAdaptors.class, raService.getResourceAdaptersInjector()) .addDependency(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, ResourceAdaptersSubsystemService.class, raService.getResourceAdaptersSubsystemInjector()); // add dependency on security domain service if applicable for recovery config for (ConnectionDefinition cd : resourceAdapter.getConnectionDefinitions()) { Security security = cd.getSecurity(); if (security != null) { if (security.getSecurityDomain() != null) { builder.requires(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, security.getSecurityDomain(), AuthenticationContext.class)); } if (security.getSecurityDomainAndApplication() != null) { builder.requires(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, security.getSecurityDomainAndApplication(), AuthenticationContext.class)); } if (cd.getRecovery() != null && cd.getRecovery().getCredential() != null && cd.getRecovery().getCredential().getSecurityDomain() != null) { builder.requires(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, cd.getRecovery().getCredential().getSecurityDomain(), AuthenticationContext.class)); } } } if (resourceAdapter.getWorkManager() != null) { final WorkManagerSecurity workManagerSecurity = resourceAdapter.getWorkManager().getSecurity(); if (workManagerSecurity != null) { final String securityDomainName = workManagerSecurity.getDomain(); if (securityDomainName != null) { builder.requires(context.getCapabilityServiceName(ELYTRON_SECURITY_DOMAIN_CAPABILITY, securityDomainName, SecurityDomain.class)); } } } newControllers.add(builder.install()); } return raServiceName; } public static void installRaServicesAndDeployFromModule(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, String fullModuleName, final List<ServiceController<?>> newControllers) throws OperationFailedException{ ServiceName raServiceName = installRaServices(context, name, resourceAdapter, newControllers); final boolean resolveProperties = true; final ServiceTarget serviceTarget = context.getServiceTarget(); final String moduleName; final CapabilityServiceSupport support = context.getCapabilityServiceSupport(); //load module String slot = "main"; if (fullModuleName.contains(":")) { slot = fullModuleName.substring(fullModuleName.indexOf(":") + 1); moduleName = fullModuleName.substring(0, fullModuleName.indexOf(":")); } else { moduleName = fullModuleName; } Module module; try { ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.raModuleNotFound(moduleName, e.getMessage()), e); } catch (ModuleLoadException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName, e.getMessage()), e); } URL path = module.getExportedResource("META-INF/ra.xml"); Closeable closable = null; try { VirtualFile child; if (path.getPath().contains("!")) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.compressedRarNotSupportedInModuleRA(moduleName)); } else { child = VFS.getChild(path.getPath().split("META-INF")[0]); closable = VFS.mountReal(new File(path.getPath().split("META-INF")[0]), child); } //final Closeable closable = VFS.mountZip((InputStream) new JarInputStream(new FileInputStream(path.getPath().split("!")[0].split(":")[1])), path.getPath().split("!")[0].split(":")[1], child, TempFileProviderService.provider()); final MountHandle mountHandle = MountHandle.create(closable); final ResourceRoot resourceRoot = new ResourceRoot(child, mountHandle); final VirtualFile deploymentRoot = resourceRoot.getRoot(); if (deploymentRoot == null || !deploymentRoot.exists()) return; ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolveProperties, deploymentRoot, null, name); IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRoot, resolveProperties); RaNativeProcessor.process(deploymentRoot); Map<ResourceRoot, Index> annotationIndexes = new HashMap<ResourceRoot, Index>(); ResourceRootIndexer.indexResourceRoot(resourceRoot); Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX); if (index != null) { annotationIndexes.put(resourceRoot, index); } final List<VirtualFile> jarChildren = deploymentRoot.getChildren(new SuffixMatchFilter(".jar", VisitorAttributes.LEAVES_ONLY)); for (VirtualFile subJarRoot: jarChildren) { Closeable subClosable = VFS.mountZip(subJarRoot, subJarRoot, TempFileProviderService.provider()); ResourceRoot subResRoot = new ResourceRoot(subJarRoot, MountHandle.create(subClosable)); ResourceRootIndexer.indexResourceRoot(subResRoot); Index subIndex = subResRoot.getAttachment(Attachments.ANNOTATION_INDEX); if (subIndex != null) { annotationIndexes.put(subResRoot, subIndex); } } if (ironJacamarXmlDescriptor != null) { ConnectorLogger.SUBSYSTEM_RA_LOGGER.forceIJToNull(); ironJacamarXmlDescriptor = null; } final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName()); final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName); if (deployerService == null) { ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptor, ironJacamarXmlDescriptor, module.getClassLoader(), serviceTarget, annotationIndexes, RAR_MODULE.append(name), null, null, support, false); builder.requires(raServiceName); newControllers.add(builder.setInitialMode(ServiceController.Mode.ACTIVE).install()); } String rarName = resourceAdapter.getArchive(); if (fullModuleName.equals(rarName)) { ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(name); InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, name, name, RAR_MODULE.append(name), null, serviceTarget, null); newControllers.add(serviceTarget .addService(serviceName, service) .setInitialMode(ServiceController.Mode.ACTIVE).install()); } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName, e.getMessage()), e); } finally { if (closable != null) { try { closable.close(); } catch (IOException e) { } } } } }
37,100
65.728417
246
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/CommonAttributes.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION; import static org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS; import static org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES; import static org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES; import static org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL; import static org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN; import static org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL; import static org.jboss.as.connector.subsystems.common.pool.Constants.VALIDATE_ON_MATCH; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ALLOCATION_RETRY_WAIT_MILLIS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ARCHIVE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BEANVALIDATION_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BOOTSTRAP_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CLASS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ENLISTMENT_TRACE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.INTERLEAVING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MCP; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MODULE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NOTXSEPARATEPOOL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.NO_RECOVERY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.PAD_XID; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_CLASSNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVER_PLUGIN_PROPERTIES; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_ELYTRON_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_PASSWORD; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_USERNAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SAME_RM_OVERRIDE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SHARABLE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRANSACTION_SUPPORT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRACKING; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_CCM; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_ELYTRON_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_PRINCIPAL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_REQUIRED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_USERS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WRAP_XA_RESOURCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.XA_RESOURCE_TIMEOUT; import org.jboss.as.controller.AttributeDefinition; /** * @author @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public class CommonAttributes { static final AttributeDefinition[] RESOURCE_ADAPTER_ATTRIBUTE = { ARCHIVE, MODULE, TRANSACTION_SUPPORT, BOOTSTRAP_CONTEXT, BEANVALIDATION_GROUPS, WM_SECURITY, WM_SECURITY_MAPPING_REQUIRED, WM_SECURITY_DOMAIN, WM_ELYTRON_SECURITY_DOMAIN, WM_SECURITY_DEFAULT_PRINCIPAL, WM_SECURITY_DEFAULT_GROUPS, WM_SECURITY_MAPPING_GROUPS, WM_SECURITY_MAPPING_USERS, STATISTICS_ENABLED }; static final AttributeDefinition[] CONNECTION_DEFINITIONS_NODE_ATTRIBUTE = { CLASS_NAME, JNDI_NAME, USE_JAVA_CONTEXT, ENABLED, CONNECTABLE, TRACKING, MAX_POOL_SIZE, INITIAL_POOL_SIZE, MIN_POOL_SIZE, POOL_USE_STRICT_MIN, POOL_FLUSH_STRATEGY, SECURITY_DOMAIN_AND_APPLICATION, APPLICATION, SECURITY_DOMAIN, ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, AUTHENTICATION_CONTEXT_AND_APPLICATION, ALLOCATION_RETRY, ALLOCATION_RETRY_WAIT_MILLIS, BLOCKING_TIMEOUT_WAIT_MILLIS, IDLETIMEOUTMINUTES, XA_RESOURCE_TIMEOUT, BACKGROUNDVALIDATIONMILLIS, BACKGROUNDVALIDATION, USE_FAST_FAIL, VALIDATE_ON_MATCH, USE_CCM, SHARABLE, ENLISTMENT, ENLISTMENT_TRACE, MCP, RECOVER_PLUGIN_CLASSNAME, RECOVER_PLUGIN_PROPERTIES, RECOVERY_PASSWORD, RECOVERY_CREDENTIAL_REFERENCE, RECOVERY_SECURITY_DOMAIN, RECOVERY_ELYTRON_ENABLED, RECOVERY_AUTHENTICATION_CONTEXT, RECOVERY_USERNAME, NO_RECOVERY, WRAP_XA_RESOURCE, SAME_RM_OVERRIDE, PAD_XID, POOL_FAIR, POOL_PREFILL, INTERLEAVING, NOTXSEPARATEPOOL, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES }; static final AttributeDefinition[] ADMIN_OBJECTS_NODE_ATTRIBUTE = new AttributeDefinition[]{ CLASS_NAME, JNDI_NAME, USE_JAVA_CONTEXT, ENABLED }; static final AttributeDefinition[] CONNECTION_DEFINITIONS_NODE_ATTRIBUTE_2_0 = new AttributeDefinition[] {INITIAL_POOL_SIZE, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES}; public static final String RESOURCE_NAME = CommonAttributes.class.getPackage().getName() + ".LocalDescriptions"; }
10,116
57.819767
134
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/WorkManagerRuntimeAttributeWriteHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.workmanager.DistributedWorkManager; import org.jboss.jca.core.api.workmanager.WorkManager; public class WorkManagerRuntimeAttributeWriteHandler extends AbstractWriteAttributeHandler<Void> { private final WorkManager wm; private final boolean distributed; public WorkManagerRuntimeAttributeWriteHandler(final WorkManager wm, boolean distributed, final AttributeDefinition... definitions) { super(definitions); this.distributed = distributed; this.wm = wm; } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> voidHandback) { switch (attributeName) { case ModelDescriptionConstants.STATISTICS_ENABLED: { if (distributed) { ((DistributedWorkManager) wm).setDistributedStatisticsEnabled(resolvedValue.asBoolean()); } else { wm.setStatisticsEnabled(resolvedValue.asBoolean()); } break; } case Constants.WORKMANAGER_STATISTICS_ENABLED_NAME: { wm.setStatisticsEnabled(resolvedValue.asBoolean()); break; } case Constants.DISTRIBUTED_STATISTICS_ENABLED_NAME: { ((DistributedWorkManager) wm).setDistributedStatisticsEnabled(resolvedValue.asBoolean()); break; } case Constants.DOWORK_DISTRIBUTION_ENABLED_NAME: { ((DistributedWorkManager) wm).setDoWorkDistributionEnabled(resolvedValue.asBoolean()); break; } case Constants.STARTWORK_DISTRIBUTION_ENABLED_NAME: { ((DistributedWorkManager) wm).setStartWorkDistributionEnabled(resolvedValue.asBoolean()); break; } case Constants.SCHEDULEWORK_DISTRIBUTION_ENABLED_NAME: { ((DistributedWorkManager) wm).setScheduleWorkDistributionEnabled(resolvedValue.asBoolean()); break; } } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode resolvedValue, Void handback) { // no-op } }
3,754
42.662791
197
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ConnectionDefinitionAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import static org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME; import static org.jboss.as.connector.subsystems.common.jndi.Constants.USE_JAVA_CONTEXT; import static org.jboss.as.connector.subsystems.jca.Constants.DEFAULT_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.CommonAttributes.CONNECTION_DEFINITIONS_NODE_ATTRIBUTE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ARCHIVE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.AUTHENTICATION_CONTEXT_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MODULE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_AUTHENTICATION_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_CREDENTIAL_REFERENCE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERY_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.SECURITY_DOMAIN_AND_APPLICATION; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_ENABLED; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.security.CredentialReference.handleCredentialReferenceUpdate; import static org.jboss.as.controller.security.CredentialReference.rollbackCredentialStoreUpdate; import org.jboss.as.connector._private.Capabilities; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.services.resourceadapters.statistics.ConnectionDefinitionStatisticsService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.Resource; import org.jboss.as.controller.security.CredentialReference; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; import org.jboss.msc.service.ServiceTarget; import org.wildfly.security.auth.client.AuthenticationContext; /** * Adds a recovery-environment to the Transactions subsystem */ public class ConnectionDefinitionAdd extends AbstractAddStepHandler { public static final ConnectionDefinitionAdd INSTANCE = new ConnectionDefinitionAdd(); @Override protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException { super.populateModel(context, operation, resource); final ModelNode model = resource.getModel(); handleCredentialReferenceUpdate(context, model.get(RECOVERY_CREDENTIAL_REFERENCE.getName()), RECOVERY_CREDENTIAL_REFERENCE.getName()); } @Override protected void populateModel(ModelNode operation, ModelNode modelNode) throws OperationFailedException { for (AttributeDefinition attribute : CONNECTION_DEFINITIONS_NODE_ATTRIBUTE) { attribute.validateAndSet(operation, modelNode); } } @Override protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException { final ModelNode address = operation.require(OP_ADDR); PathAddress path = context.getCurrentAddress(); final String jndiName = JNDI_NAME.resolveModelAttribute(context, operation).asString(); final String raName = path.getParent().getLastElement().getValue(); final String archiveOrModuleName; ModelNode raModel = context.readResourceFromRoot(path.getParent(), false).getModel(); final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean(); if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) { throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired(); } ModelNode resourceModel = resource.getModel(); // add extra security validation: legacy security configuration should not be used if (resourceModel.hasDefined(SECURITY_DOMAIN.getName())) throw SUBSYSTEM_RA_LOGGER.legacySecurityAttributeNotSupported(SECURITY_DOMAIN.getName()); else if (resourceModel.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName())) throw SUBSYSTEM_RA_LOGGER.legacySecurityAttributeNotSupported(SECURITY_DOMAIN_AND_APPLICATION.getName()); else if (resourceModel.hasDefined(APPLICATION.getName())) throw SUBSYSTEM_RA_LOGGER.legacySecurityAttributeNotSupported(APPLICATION.getName()); // do the same for recovery security attributes if (resourceModel.hasDefined(RECOVERY_SECURITY_DOMAIN.getName())) throw SUBSYSTEM_RA_LOGGER.legacySecurityAttributeNotSupported(RECOVERY_SECURITY_DOMAIN.getName()); final ModelNode credentialReference = RECOVERY_CREDENTIAL_REFERENCE.resolveModelAttribute(context, resourceModel); // add extra security validation: legacy security configuration should not be used boolean hasSecurityDomain = resourceModel.hasDefined(SECURITY_DOMAIN.getName()); boolean hasSecurityDomainAndApp = resourceModel.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()); if (hasSecurityDomain) { throw SUBSYSTEM_RA_LOGGER.legacySecurityAttributeNotSupported(SECURITY_DOMAIN.getName()); } else if (hasSecurityDomainAndApp) { throw SUBSYSTEM_RA_LOGGER.legacySecurityAttributeNotSupported(SECURITY_DOMAIN_AND_APPLICATION.getName()); } boolean hasRecoverySecurityDomain = resourceModel.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()); if (hasRecoverySecurityDomain) { throw SUBSYSTEM_RA_LOGGER.legacySecurityAttributeNotSupported(RECOVERY_SECURITY_DOMAIN.getName()); } if (raModel.get(ARCHIVE.getName()).isDefined()) { archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString(); } else { archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString(); } final String poolName = PathAddress.pathAddress(address).getLastElement().getValue(); try { ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName); ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName); final ModifiableResourceAdapter ravalue = ((ModifiableResourceAdapter) context.getServiceRegistry(false).getService(raServiceName).getValue()); boolean isXa = ravalue.getTransactionSupport() == TransactionSupportEnum.XATransaction; final ServiceTarget serviceTarget = context.getServiceTarget(); final ConnectionDefinitionService service = new ConnectionDefinitionService(); service.getConnectionDefinitionSupplierInjector().inject( () -> RaOperationUtil.buildConnectionDefinitionObject(context, resourceModel, poolName, isXa, service.getCredentialSourceSupplier().getOptionalValue()) ); final ServiceBuilder<ModifiableConnDef> cdServiceBuilder = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector()); // Add a dependency to the required authentication-contexts. These will be looked in the ElytronSecurityFactory // and this should be changed to use a proper capability in the future. if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT.getName())) { cdServiceBuilder.requires(context.getCapabilityServiceName( Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class)); } else if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName())) { cdServiceBuilder.requires(context.getCapabilityServiceName( Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT_AND_APPLICATION.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class)); } if (resourceModel.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName())) { cdServiceBuilder.requires(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, RECOVERY_AUTHENTICATION_CONTEXT.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class)); } if (credentialReference.isDefined()) { service.getCredentialSourceSupplier().inject( CredentialReference.getCredentialSourceSupplier(context, RECOVERY_CREDENTIAL_REFERENCE, resourceModel, cdServiceBuilder)); } // Install the ConnectionDefinitionService cdServiceBuilder.install(); ServiceRegistry registry = context.getServiceRegistry(true); final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName)); Activation raxml = (Activation) RaxmlController.getValue(); ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName); String bootStrapCtxName = DEFAULT_NAME; if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) { bootStrapCtxName = raxml.getBootstrapContext(); } final boolean useJavaContext = USE_JAVA_CONTEXT.resolveModelAttribute(context, raModel).asBoolean(); ConnectionDefinitionStatisticsService connectionDefinitionStatisticsService = new ConnectionDefinitionStatisticsService(context.getResourceRegistrationForUpdate(), jndiName, useJavaContext, poolName, statsEnabled); ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), connectionDefinitionStatisticsService); statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, connectionDefinitionStatisticsService.getBootstrapContextInjector()) .addDependency(deploymentServiceName, Object.class, connectionDefinitionStatisticsService.getResourceAdapterDeploymentInjector()) .setInitialMode(ServiceController.Mode.PASSIVE) .install(); PathElement peCD = PathElement.pathElement(Constants.STATISTICS_NAME, "pool"); final Resource cdResource = new IronJacamarResource.IronJacamarRuntimeResource(); resource.registerChild(peCD, cdResource); PathElement peExtended = PathElement.pathElement(Constants.STATISTICS_NAME, "extended"); final Resource extendedResource = new IronJacamarResource.IronJacamarRuntimeResource(); resource.registerChild(peExtended, extendedResource); } catch (Exception e) { throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("ConnectionDefinition", operation, e.getLocalizedMessage()))); } } @Override protected void rollbackRuntime(OperationContext context, final ModelNode operation, final Resource resource) { rollbackCredentialStoreUpdate(RECOVERY_CREDENTIAL_REFERENCE, context, resource); } }
13,679
58.478261
226
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/Namespace.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import java.util.HashMap; import java.util.Map; /** * A Namespace. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public enum Namespace { // must be first UNKNOWN(null), RESOURCEADAPTERS_1_0("urn:jboss:domain:resource-adapters:1.0"), RESOURCEADAPTERS_1_1("urn:jboss:domain:resource-adapters:1.1"), RESOURCEADAPTERS_2_0("urn:jboss:domain:resource-adapters:2.0"), RESOURCEADAPTERS_3_0("urn:jboss:domain:resource-adapters:3.0"), RESOURCEADAPTERS_4_0("urn:jboss:domain:resource-adapters:4.0"), RESOURCEADAPTERS_5_0("urn:jboss:domain:resource-adapters:5.0"), RESOURCEADAPTERS_6_0("urn:jboss:domain:resource-adapters:6.0"), RESOURCEADAPTERS_6_1("urn:jboss:domain:resource-adapters:6.1"), RESOURCEADAPTERS_7_0("urn:jboss:domain:resource-adapters:7.0"); /** * The current namespace version. */ public static final Namespace CURRENT = RESOURCEADAPTERS_7_0; private final String name; Namespace(final String name) { this.name = name; } /** * Get the URI of this namespace. * @return the URI */ public String getUriString() { return name; } private static final Map<String, Namespace> MAP; static { final Map<String, Namespace> map = new HashMap<String, Namespace>(); for (Namespace namespace : values()) { final String name = namespace.getUriString(); if (name != null) map.put(name, namespace); } MAP = map; } public static Namespace forUri(String uri) { final Namespace element = MAP.get(uri); return element == null ? UNKNOWN : element; } }
2,802
30.144444
82
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdaptersService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import java.util.Collections; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.metadata.resourceadapter.Activations; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ public final class ResourceAdaptersService implements Service<ResourceAdaptersService.ModifiableResourceAdaptors> { private final ModifiableResourceAdaptors value = new ModifiableResourceAdaptors(); @Override public ModifiableResourceAdaptors getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { SUBSYSTEM_RA_LOGGER.debugf("Starting ResourceAdapters Service"); } @Override public void stop(StopContext context) { SUBSYSTEM_RA_LOGGER.debugf("Stopping ResourceAdapters Service"); } public static final class ModifiableResourceAdaptors implements Activations { private static final long serialVersionUID = 9096011997958619051L; private final List<Activation> resourceAdapters = new CopyOnWriteArrayList<>(); /** * Get the resourceAdapters. * * @return the resourceAdapters. */ @Override public List<Activation> getActivations() { return Collections.unmodifiableList(resourceAdapters); } public boolean addActivation(Activation ra) { return resourceAdapters.add(ra); } public boolean removeActivation(Activation ra) { return resourceAdapters.remove(ra); } } }
3,082
34.034091
115
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdaptersRootResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.ResourceAdaptersExtension.SUBSYSTEM_NAME; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.RuntimePackageDependency; /** * * @author <a href="[email protected]">Kabir Khan</a> */ public class ResourceAdaptersRootResourceDefinition extends SimpleResourceDefinition { private final boolean runtimeOnlyRegistrationValid; @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerReadWriteAttribute(Constants.REPORT_DIRECTORY, null, new ReportDirectoryWriteHandler(Constants.REPORT_DIRECTORY)); } public ResourceAdaptersRootResourceDefinition(boolean runtimeOnlyRegistrationValid) { super(ResourceAdaptersExtension.SUBSYSTEM_PATH, ResourceAdaptersExtension.getResourceDescriptionResolver(SUBSYSTEM_NAME), ResourceAdaptersSubsystemAdd.INSTANCE, ReloadRequiredRemoveStepHandler.INSTANCE); this.runtimeOnlyRegistrationValid = runtimeOnlyRegistrationValid; } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); resourceRegistration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE); } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerSubModel(new ResourceAdapterResourceDefinition(false, runtimeOnlyRegistrationValid)); } @Override public void registerAdditionalRuntimePackages(final ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerAdditionalRuntimePackages(RuntimePackageDependency.required("jakarta.jms.api")); } }
3,173
47.090909
211
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdapterResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector._private.Capabilities.RESOURCE_ADAPTER_CAPABILITY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTER_NAME; import java.util.List; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.access.constraint.ApplicationTypeConfig; import org.jboss.as.controller.access.management.AccessConstraintDefinition; import org.jboss.as.controller.access.management.ApplicationTypeAccessConstraintDefinition; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * * @author <a href="[email protected]">Kabir Khan</a> */ public class ResourceAdapterResourceDefinition extends SimpleResourceDefinition { private static final ResourceDescriptionResolver RESOLVER = ResourceAdaptersExtension.getResourceDescriptionResolver(RESOURCEADAPTER_NAME); private static final OperationDefinition ACTIVATE_DEFINITION = new SimpleOperationDefinitionBuilder(Constants.ACTIVATE, RESOLVER).build(); // The ManagedConnectionPool implementation used by default by versions < 4.0.0 (WildFly 10) private final boolean readOnly; private final boolean runtimeOnlyRegistrationValid; private final List<AccessConstraintDefinition> accessConstraints; public ResourceAdapterResourceDefinition(boolean readOnly, boolean runtimeOnlyRegistrationValid) { super(getParameters(readOnly)); this.readOnly = readOnly; this.runtimeOnlyRegistrationValid = runtimeOnlyRegistrationValid; ApplicationTypeConfig atc = new ApplicationTypeConfig(ResourceAdaptersExtension.SUBSYSTEM_NAME, RESOURCEADAPTER_NAME); accessConstraints = new ApplicationTypeAccessConstraintDefinition(atc).wrapAsList(); } private static Parameters getParameters(boolean readOnly) { Parameters parameters = new Parameters(PathElement.pathElement(RESOURCEADAPTER_NAME), RESOLVER); if (!readOnly) { parameters.setAddHandler(RaAdd.INSTANCE) .setRemoveHandler(RaRemove.INSTANCE) .setCapabilities(RESOURCE_ADAPTER_CAPABILITY); } return parameters; } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); resourceRegistration.registerOperationHandler(ACTIVATE_DEFINITION, RaActivate.INSTANCE); } @Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { for (final AttributeDefinition attribute : CommonAttributes.RESOURCE_ADAPTER_ATTRIBUTE) { if (readOnly) { resourceRegistration.registerReadOnlyAttribute(attribute, null); } else { resourceRegistration.registerReadWriteAttribute(attribute, null, new ReloadRequiredWriteAttributeHandler(attribute)); } } } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerSubModel(new ConfigPropertyResourceDefinition(readOnly ? null : ConfigPropertyAdd.INSTANCE, readOnly ? null : ReloadRequiredRemoveStepHandler.INSTANCE)); resourceRegistration.registerSubModel(new ConnectionDefinitionResourceDefinition(readOnly, runtimeOnlyRegistrationValid)); resourceRegistration.registerSubModel(new AdminObjectResourceDefinition(readOnly)); } @Override public List<AccessConstraintDefinition> getAccessConstraints() { return accessConstraints; } }
5,078
46.46729
190
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdapterParser.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ADMIN_OBJECTS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ARCHIVE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BEANVALIDATIONGROUP; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BEANVALIDATION_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.BOOTSTRAP_CONTEXT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONFIG_PROPERTIES; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.CONNECTIONDEFINITIONS_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MODULE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.REPORT_DIRECTORY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTER_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_ENABLED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.TRANSACTION_SUPPORT; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_ELYTRON_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_GROUP; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DEFAULT_PRINCIPAL; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_DOMAIN; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_FROM; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_GROUPS; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_REQUIRED; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_TO; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.WM_SECURITY_MAPPING_USERS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity; import org.jboss.as.connector.metadata.resourceadapter.WorkManagerSecurityImpl; import org.jboss.as.connector.util.ParserException; import org.jboss.as.controller.AttributeDefinition; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.CommonBundle; import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.metadata.resourceadapter.Activations; import org.jboss.jca.common.api.metadata.resourceadapter.WorkManager; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.jca.common.metadata.resourceadapter.WorkManagerImpl; import org.jboss.logging.Messages; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * A ResourceAdapterParser. * * @author <a href="[email protected]">Stefano Maestri</a> */ public class ResourceAdapterParser extends CommonIronJacamarParser { /** * The bundle */ private static final CommonBundle bundle = Messages.getBundle(CommonBundle.class); public void parse(final XMLExtendedStreamReader reader, final ModelNode subsystemAddOperation, final List<ModelNode> list, ModelNode parentAddress) throws Exception { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: return; case START_ELEMENT: { switch (Tag.forName(reader.getLocalName())) { case RESOURCE_ADAPTERS: parseResourceAdapters(reader, list, parentAddress); break; case REPORT_DIRECTORY: parseReportDirectory(reader, subsystemAddOperation); break; default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } default: throw new IllegalStateException(); } } } private void parseResourceAdapters(final XMLExtendedStreamReader reader, final List<ModelNode> list, ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Tag.forName(reader.getLocalName()) == Tag.RESOURCE_ADAPTERS) { return; } else { if (Activations.Tag.forName(reader.getLocalName()) == Activations.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (Activations.Tag.forName(reader.getLocalName())) { case RESOURCE_ADAPTER: { parseResourceAdapter(reader, list, parentAddress); break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } private void parseResourceAdapter(final XMLExtendedStreamReader reader, final List<ModelNode> list, ModelNode parentAddress) throws XMLStreamException, ParserException, ValidateException { final ModelNode raAddress = parentAddress.clone(); final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); String archiveOrModuleName = null; HashMap<String, ModelNode> configPropertiesOperations = new HashMap<>(); HashMap<String, ModelNode> connectionDefinitionsOperations = new HashMap<>(); HashMap<String, HashMap<String, ModelNode>> cfConfigPropertiesOperations = new HashMap<>(); HashMap<String, ModelNode> adminObjectsOperations = new HashMap<>(); HashMap<String, HashMap<String, ModelNode>> aoConfigPropertiesOperations = new HashMap<>(); boolean archiveOrModuleMatched = false; boolean txSupportMatched = false; boolean isXa = false; String id = null; int attributeSize = reader.getAttributeCount(); for (int i = 0; i < attributeSize; i++) { Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); String value = reader.getAttributeValue(i); switch (attribute) { case ID: { id = value; break; } case STATISTICS_ENABLED: STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); break; default: break; } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Activations.Tag.forName(reader.getLocalName()) == Activations.Tag.RESOURCE_ADAPTER) { if (!archiveOrModuleMatched) { throw new ParserException(bundle.requiredElementMissing(ARCHIVE.getName(), RESOURCEADAPTER_NAME)); } if (id != null) { raAddress.add(RESOURCEADAPTER_NAME, id); } else { raAddress.add(RESOURCEADAPTER_NAME, archiveOrModuleName); } raAddress.protect(); operation.get(OP_ADDR).set(raAddress); list.add(operation); for (Map.Entry<String, ModelNode> entry : configPropertiesOperations.entrySet()) { final ModelNode env = raAddress.clone(); env.add(CONFIG_PROPERTIES.getName(), entry.getKey()); env.protect(); entry.getValue().get(OP_ADDR).set(env); list.add(entry.getValue()); } for (Map.Entry<String, ModelNode> entry : connectionDefinitionsOperations.entrySet()) { final ModelNode env = raAddress.clone(); env.add(CONNECTIONDEFINITIONS_NAME, entry.getKey()); env.protect(); entry.getValue().get(OP_ADDR).set(env); list.add(entry.getValue()); final HashMap<String, ModelNode> properties = cfConfigPropertiesOperations.get(entry.getKey()); if (properties != null) { for (Map.Entry<String, ModelNode> configEntry : properties.entrySet()) { final ModelNode configEnv = env.clone(); configEnv.add(CONFIG_PROPERTIES.getName(), configEntry.getKey()); configEnv.protect(); configEntry.getValue().get(OP_ADDR).set(configEnv); list.add(configEntry.getValue()); } } } for (Map.Entry<String, ModelNode> entry : adminObjectsOperations.entrySet()) { final ModelNode env = raAddress.clone(); env.add(ADMIN_OBJECTS_NAME, entry.getKey()); env.protect(); entry.getValue().get(OP_ADDR).set(env); list.add(entry.getValue()); final HashMap<String, ModelNode> aoProperties = aoConfigPropertiesOperations.get(entry.getKey()); if (aoProperties != null) { for (Map.Entry<String, ModelNode> configEntry : aoProperties.entrySet()) { final ModelNode configEnv = env.clone(); configEnv.add(CONFIG_PROPERTIES.getName(), configEntry.getKey()); configEnv.protect(); configEntry.getValue().get(OP_ADDR).set(configEnv); list.add(configEntry.getValue()); } } } return; } else { if (AS7ResourceAdapterTags.forName(reader.getLocalName()) == AS7ResourceAdapterTags.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (AS7ResourceAdapterTags.forName(reader.getLocalName())) { case ADMIN_OBJECTS: case CONNECTION_DEFINITIONS: case BEAN_VALIDATION_GROUPS: { //ignore it,we will parse bean-validation-group,admin_object and connection_definition directly break; } case ADMIN_OBJECT: { parseAdminObjects(reader, adminObjectsOperations, aoConfigPropertiesOperations); break; } case CONNECTION_DEFINITION: { switch (Namespace.forUri(reader.getNamespaceURI())) { case RESOURCEADAPTERS_1_0: case RESOURCEADAPTERS_1_1: case RESOURCEADAPTERS_2_0: parseConnectionDefinitions_1_0(reader, connectionDefinitionsOperations, cfConfigPropertiesOperations, isXa); break; case RESOURCEADAPTERS_3_0: parseConnectionDefinitions_3_0(reader, connectionDefinitionsOperations, cfConfigPropertiesOperations, isXa); break; case RESOURCEADAPTERS_4_0: parseConnectionDefinitions_4_0(reader, connectionDefinitionsOperations, cfConfigPropertiesOperations, isXa); break; default: parseConnectionDefinitions_5_0(reader, connectionDefinitionsOperations, cfConfigPropertiesOperations, isXa); break; } break; } case BEAN_VALIDATION_GROUP: { String value = rawElementText(reader); operation.get(BEANVALIDATION_GROUPS.getName()).add(parse(BEANVALIDATIONGROUP, value, reader)); break; } case BOOTSTRAP_CONTEXT: { String value = rawElementText(reader); BOOTSTRAP_CONTEXT.parseAndSetParameter(value, operation, reader); break; } case CONFIG_PROPERTY: { parseConfigProperties(reader, configPropertiesOperations); break; } case TRANSACTION_SUPPORT: { if (txSupportMatched) { throw new ParserException(bundle.unexpectedElement(TRANSACTION_SUPPORT.getXmlName())); } String value = rawElementText(reader); TRANSACTION_SUPPORT.parseAndSetParameter(value, operation, reader); ModelNode transactionSupport = parse(TRANSACTION_SUPPORT, value, reader); // so we need to know the transaction support level to give a chance to throw XMLStreamException for // unexpectedElement when parsing connection-definitions in CommonIronJacamarParser ? String transactionSupportResolved = transactionSupport.resolve().asString(); isXa = value != null && TransactionSupportEnum.valueOf(transactionSupportResolved) == TransactionSupportEnum.XATransaction; txSupportMatched = true; break; } case WORKMANAGER: { parseWorkManager(operation, reader); break; } case ARCHIVE: { if (archiveOrModuleMatched) { throw new ParserException(bundle.unexpectedElement(ARCHIVE.getXmlName())); } archiveOrModuleName = rawElementText(reader); ARCHIVE.parseAndSetParameter(archiveOrModuleName, operation, reader); archiveOrModuleMatched = true; break; } case MODULE: { if (archiveOrModuleMatched) { throw new ParserException(bundle.unexpectedElement(MODULE.getXmlName())); } String moduleId = rawAttributeText(reader, "id"); String moduleSlot = rawAttributeText(reader, "slot", "main"); archiveOrModuleName = moduleId + ":" + moduleSlot; MODULE.parseAndSetParameter(archiveOrModuleName, operation, reader); archiveOrModuleMatched = true; break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } protected WorkManager parseWorkManager(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException { WorkManagerSecurity security = null; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.WORKMANAGER) { return new WorkManagerImpl(security); } else { if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (WorkManager.Tag.forName(reader.getLocalName())) { case SECURITY: { switch (Namespace.forUri(reader.getNamespaceURI())) { case RESOURCEADAPTERS_1_0: case RESOURCEADAPTERS_1_1: case RESOURCEADAPTERS_2_0: case RESOURCEADAPTERS_3_0: case RESOURCEADAPTERS_4_0: security = parseWorkManagerSecurity(operation, reader); break; case RESOURCEADAPTERS_5_0: case RESOURCEADAPTERS_6_0: case RESOURCEADAPTERS_6_1: security = parseWorkManagerSecurity_5_0(operation, reader); break; default: // If the switch statement contains a default it does not need to be revisited each time a new schema is added unless it actually affects it. security = parseWorkManagerSecurity_7_0(operation, reader); } break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } protected WorkManagerSecurity parseWorkManagerSecurity(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException { boolean mappingRequired = false; String domain = null; String defaultPrincipal = null; List<String> defaultGroups = null; Map<String, String> userMappings = null; Map<String, String> groupMappings = null; boolean userMappingEnabled = false; WM_SECURITY.parseAndSetParameter("true", operation, reader); while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (WorkManager.Tag.forName(reader.getLocalName()) == WorkManager.Tag.SECURITY) { return new WorkManagerSecurityImpl(mappingRequired, domain,false, defaultPrincipal, defaultGroups, userMappings, groupMappings); } else { if (WorkManagerSecurity.Tag.forName(reader.getLocalName()) == WorkManagerSecurity.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (WorkManagerSecurity.Tag.forName(reader.getLocalName())) { case DEFAULT_GROUPS: case MAPPINGS: { // Skip break; } case MAPPING_REQUIRED: { String value = rawElementText(reader); WM_SECURITY_MAPPING_REQUIRED.parseAndSetParameter(value, operation, reader); break; } case DOMAIN: { String value = domain = rawElementText(reader); WM_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader); break; } case DEFAULT_PRINCIPAL: { String value = rawElementText(reader); WM_SECURITY_DEFAULT_PRINCIPAL.parseAndSetParameter(value, operation, reader); break; } case GROUP: { String value = rawElementText(reader); operation.get(WM_SECURITY_DEFAULT_GROUPS.getName()).add(parse(WM_SECURITY_DEFAULT_GROUP, value, reader)); break; } case USERS: { userMappingEnabled = true; break; } case GROUPS: { userMappingEnabled = false; break; } case MAP: { if (userMappingEnabled) { String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName()); if (from == null || from.trim().equals("")) throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName())); String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName()); if (to == null || to.trim().equals("")) throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName())); ModelNode object = new ModelNode(); WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader); WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader); operation.get(WM_SECURITY_MAPPING_USERS.getName()).add(object); } else { String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName()); if (from == null || from.trim().equals("")) throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName())); String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName()); if (to == null || to.trim().equals("")) throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName())); ModelNode object = new ModelNode(); WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader); WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader); operation.get(WM_SECURITY_MAPPING_GROUPS.getName()).add(object); } break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } protected WorkManagerSecurity parseWorkManagerSecurity_5_0(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException { WM_SECURITY.parseAndSetParameter("true", operation, reader); return parseWorkManagerSecurityElements(operation, reader); } protected WorkManagerSecurity parseWorkManagerSecurity_7_0(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException { for (int i = 0; i < reader.getAttributeCount(); i++) { Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: { String value = reader.getAttributeValue(i); WM_SECURITY.parseAndSetParameter(value, operation, reader); break; } default: throw new ParserException(bundle.unexpectedAttribute(reader.getAttributeLocalName(i), reader.getLocalName())); } } return parseWorkManagerSecurityElements(operation, reader); } /** * Parses the common elements of Work Manager Security of the Resource Adapter subsystem version 5.0, 6.0, 6.1 and 7.0 */ private WorkManagerSecurity parseWorkManagerSecurityElements(final ModelNode operation, final XMLStreamReader reader) throws XMLStreamException, ParserException { boolean mappingRequired = false; String domain = null; boolean elytronEnabled = false; boolean userMappingEnabled = false; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (WorkManager.Tag.forName(reader.getLocalName()) == WorkManager.Tag.SECURITY) { return new WorkManagerSecurityImpl(mappingRequired, domain, elytronEnabled, null, null, null, null); } else { if (WorkManagerSecurity.Tag.forName(reader.getLocalName()) == WorkManagerSecurity.Tag.UNKNOWN) { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } } break; } case START_ELEMENT: { switch (WorkManagerSecurity.Tag.forName(reader.getLocalName())) { case DEFAULT_GROUPS: case MAPPINGS: { // Skip break; } case MAPPING_REQUIRED: { String value = rawElementText(reader); WM_SECURITY_MAPPING_REQUIRED.parseAndSetParameter(value, operation, reader); break; } case DOMAIN: { String value = domain = rawElementText(reader); WM_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader); break; } case ELYTRON_SECURITY_DOMAIN: { elytronEnabled = true; String value = domain = rawElementText(reader); WM_ELYTRON_SECURITY_DOMAIN.parseAndSetParameter(value, operation, reader); break; } case DEFAULT_PRINCIPAL: { String value = rawElementText(reader); WM_SECURITY_DEFAULT_PRINCIPAL.parseAndSetParameter(value, operation, reader); break; } case GROUP: { String value = rawElementText(reader); operation.get(WM_SECURITY_DEFAULT_GROUPS.getName()).add(parse(WM_SECURITY_DEFAULT_GROUP, value, reader)); break; } case USERS: { userMappingEnabled = true; break; } case GROUPS: { userMappingEnabled = false; break; } case MAP: { String from = rawAttributeText(reader, WorkManagerSecurity.Attribute.FROM.getLocalName()); if (from == null || from.trim().equals("")) throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.FROM.getLocalName(), reader.getLocalName())); String to = rawAttributeText(reader, WorkManagerSecurity.Attribute.TO.getLocalName()); if (to == null || to.trim().equals("")) throw new ParserException(bundle.requiredAttributeMissing(WorkManagerSecurity.Attribute.TO.getLocalName(), reader.getLocalName())); ModelNode object = new ModelNode(); WM_SECURITY_MAPPING_FROM.parseAndSetParameter(from, object, reader); WM_SECURITY_MAPPING_TO.parseAndSetParameter(to, object, reader); if (userMappingEnabled) { operation.get(WM_SECURITY_MAPPING_USERS.getName()).add(object); } else { operation.get(WM_SECURITY_MAPPING_GROUPS.getName()).add(object); } break; } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } break; } } } throw new ParserException(bundle.unexpectedEndOfDocument()); } protected void parseReportDirectory(final XMLStreamReader reader, final ModelNode subsystemAddOperation) throws XMLStreamException, ParserException { for (int i = 0; i < reader.getAttributeCount(); i++) { Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); String value = reader.getAttributeValue(i); switch (attribute) { case PATH: REPORT_DIRECTORY.parseAndSetParameter(value, subsystemAddOperation, reader); break; default: throw new ParserException(bundle.unexpectedAttribute(attribute.getLocalName(), reader.getLocalName())); } } while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: if (Tag.forName(reader.getLocalName()) == Tag.REPORT_DIRECTORY) { return; } else { throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName())); } default: throw new ParserException(bundle.unexpectedElement(reader.getLocalName())); } } } private static ModelNode parse(AttributeDefinition ad, String value, XMLStreamReader reader) throws XMLStreamException { return ad.getParser().parse(ad, value, reader); } /** * A Tag. * * @author <a href="[email protected]">Stefano Maestri</a> */ public enum Tag { /** * always first */ UNKNOWN(null), /** * jboss-ra tag name */ RESOURCE_ADAPTERS("resource-adapters"), REPORT_DIRECTORY("report-directory"); private final String name; /** * Create a new Tag. * * @param name a name */ Tag(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } private static final Map<String, Tag> MAP; static { final Map<String, Tag> map = new HashMap<>(); for (Tag element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } /** * Static method to get enum instance given localName string * * @param localName a string used as localname (typically tag name as defined in xsd) * @return the enum instance */ public static Tag forName(String localName) { final Tag element = MAP.get(localName); return element == null ? UNKNOWN : element; } } /** * An Attribute. * * @author <a href="[email protected]">Stefano Maestri</a> */ public enum Attribute { /** * always first */ UNKNOWN(null), /** * id attribute */ ID("id"), /** * statistics-enabled attribute */ STATISTICS_ENABLED("statistics-enabled"), /** * path */ PATH("path"), /** * enabled attribute */ ENABLED("enabled"); private String name; /** * Create a new Tag. * * @param name a name */ Attribute(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } /** * {@inheritDoc} */ public String toString() { return name; } private static final Map<String, Attribute> MAP; static { final Map<String, Attribute> map = new HashMap<>(); for (Attribute element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } /** * Set the value * * @param v The name * @return The value */ Attribute value(String v) { name = v; return this; } /** * Static method to get enum instance given localName XsdString * * @param localName a XsdString used as localname (typically tag name as defined in xsd) * @return the enum instance */ public static Attribute forName(String localName) { final Attribute element = MAP.get(localName); return element == null ? UNKNOWN.value(localName) : element; } } }
38,167
46.472637
182
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/EnlistmentTraceAttributeWriteHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import java.util.LinkedList; import java.util.List; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractWriteAttributeHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.jca.core.api.management.ConnectionManager; import org.jboss.jca.core.api.management.Connector; import org.jboss.jca.core.api.management.ManagementRepository; import org.jboss.msc.service.ServiceController; /** * @author <a href="mailto:[email protected]">Stefano Maestri</a> * @author <a href="mailto:[email protected]">Jeff Zhang</a> */ public class EnlistmentTraceAttributeWriteHandler extends AbstractWriteAttributeHandler<List<ConnectionManager>> { protected EnlistmentTraceAttributeWriteHandler() { super(Constants.ENLISTMENT_TRACE); } @Override protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<ConnectionManager>> handbackHolder) throws OperationFailedException { final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel() .get(org.jboss.as.connector.subsystems.common.jndi.Constants.JNDI_NAME.getName()).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean(); try { final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue(); if (repository.getConnectors() != null) { List<ConnectionManager> handback = new LinkedList<>(); for (Connector connector : repository.getConnectors()) { for (ConnectionManager cm : connector.getConnectionManagers()) { if (jndiName.equalsIgnoreCase(cm.getUniqueId())) { cm.setEnlistmentTrace(boolValue); handback.add(cm); } } } handbackHolder.setHandback(handback); } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage())); } return false; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String parameterName, ModelNode valueToRestore, ModelNode valueToRevert, List<ConnectionManager> handback) throws OperationFailedException { Boolean value = Constants.ENLISTMENT_TRACE.resolveValue(context, valueToRestore).asBoolean(); if (handback != null) { for (ConnectionManager ds : handback) { ds.setEnlistmentTrace(value); } } } }
4,456
41.855769
168
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/AdminObjectAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.jca.Constants.DEFAULT_NAME; import static org.jboss.as.connector.subsystems.resourceadapters.CommonAttributes.ADMIN_OBJECTS_NODE_ATTRIBUTE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ARCHIVE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MODULE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_ENABLED; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.services.resourceadapters.statistics.AdminObjectStatisticsService; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; import org.jboss.msc.service.ServiceTarget; /** * Adds a recovery-environment to the Transactions subsystem */ public class AdminObjectAdd extends AbstractAddStepHandler { static final AdminObjectAdd INSTANCE = new AdminObjectAdd(); private AdminObjectAdd() { } @Override protected void populateModel(ModelNode operation, ModelNode modelNode) throws OperationFailedException { for (AttributeDefinition attribute : ADMIN_OBJECTS_NODE_ATTRIBUTE) { attribute.validateAndSet(operation, modelNode); } } @Override protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException { final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String raName = context.getCurrentAddress().getParent().getLastElement().getValue(); final String archiveOrModuleName; ModelNode raModel = context.readResourceFromRoot(path.subAddress(0, path.size() - 1), false).getModel(); final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean(); if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) { throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired(); } if (raModel.get(ARCHIVE.getName()).isDefined()) { archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString(); } else { archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString(); } final String poolName = PathAddress.pathAddress(address).getLastElement().getValue(); final ModifiableAdminObject adminObjectValue; try { adminObjectValue = RaOperationUtil.buildAdminObjects(context, operation, poolName); } catch (ValidateException e) { throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("AdminObject", operation, e.getLocalizedMessage()))); } ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName); ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName); final ServiceTarget serviceTarget = context.getServiceTarget(); final AdminObjectService service = new AdminObjectService(adminObjectValue); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE) .addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector()) .install(); ServiceRegistry registry = context.getServiceRegistry(true); final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName)); Activation raxml = (Activation) RaxmlController.getValue(); ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName); String bootStrapCtxName = DEFAULT_NAME; if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) { bootStrapCtxName = raxml.getBootstrapContext(); } AdminObjectStatisticsService adminObjectStatisticsService = new AdminObjectStatisticsService(context.getResourceRegistrationForUpdate(), poolName, statsEnabled); ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), adminObjectStatisticsService); statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, adminObjectStatisticsService.getBootstrapContextInjector()) .addDependency(deploymentServiceName, Object.class, adminObjectStatisticsService.getResourceAdapterDeploymentInjector()) .setInitialMode(ServiceController.Mode.PASSIVE) .install(); PathElement peAO = PathElement.pathElement(Constants.STATISTICS_NAME, "extended"); final Resource aoResource = new IronJacamarResource.IronJacamarRuntimeResource(); resource.registerChild(peAO, aoResource); } }
6,823
50.308271
185
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/IronJacamarResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * * @author <a href="[email protected]">Kabir Khan</a> */ public class IronJacamarResourceDefinition extends SimpleResourceDefinition { public IronJacamarResourceDefinition() { super(PathElement.pathElement(Constants.IRONJACAMAR_NAME, Constants.IRONJACAMAR_NAME), ResourceAdaptersExtension.getResourceDescriptionResolver(Constants.IRONJACAMAR_NAME)); } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); resourceRegistration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE); } @Override public void registerChildren(ManagementResourceRegistration resourceRegistration) { resourceRegistration.registerSubModel(new ResourceAdapterResourceDefinition(false, true)); } }
2,228
42.705882
181
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/RaRemove.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.ARCHIVE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.MODULE; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RESOURCEADAPTERS_NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import java.util.LinkedList; import java.util.List; import org.jboss.as.connector._private.Capabilities; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.operations.common.Util; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; /** * @author @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ public class RaRemove implements OperationStepHandler { static final RaRemove INSTANCE = new RaRemove(); public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode opAddr = operation.require(OP_ADDR); final String idName = PathAddress.pathAddress(opAddr).getLastElement().getValue(); final boolean isModule; // Compensating is add final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel(); final String archiveOrModuleName; if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) { throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired(); } if (model.get(ARCHIVE.getName()).isDefined()) { isModule = false; archiveOrModuleName = model.get(ARCHIVE.getName()).asString(); } else { isModule = true; archiveOrModuleName = model.get(MODULE.getName()).asString(); } final ModelNode compensating = Util.getEmptyOperation(ADD, opAddr); if (model.hasDefined(RESOURCEADAPTERS_NAME)) { for (ModelNode raNode : model.get(RESOURCEADAPTERS_NAME).asList()) { ModelNode raCompensatingNode = raNode.clone(); compensating.get(RESOURCEADAPTERS_NAME).add(raCompensatingNode); } } context.removeResource(PathAddress.EMPTY_ADDRESS); context.deregisterCapability(Capabilities.RESOURCE_ADAPTER_CAPABILITY.getDynamicName(context.getCurrentAddress())); if (context.isDefaultRequiresRuntime()) { context.addStep(new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final boolean wasActive; wasActive = RaOperationUtil.removeIfActive(context, archiveOrModuleName, idName); if (wasActive && !context.isResourceServiceRestartAllowed()) { context.reloadRequired(); context.completeStep(new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext context, ModelNode operation) { context.revertReloadRequired(); } }); return; } ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, idName); ServiceController<?> serviceController = context.getServiceRegistry(false).getService(raServiceName); final ModifiableResourceAdapter resourceAdapter; if (serviceController != null) { resourceAdapter = (ModifiableResourceAdapter) serviceController.getValue(); } else { resourceAdapter = null; } final List<ServiceName> serviceNameList = context.getServiceRegistry(false).getServiceNames(); for (ServiceName name : serviceNameList) { if (raServiceName.isParentOf(name)) { context.removeService(name); } } if (model.get(MODULE.getName()).isDefined()) { //ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(model.get(MODULE.getName()).asString(),raId); //context.removeService(deploymentServiceName); ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(idName); context.removeService(deployerServiceName); ServiceName inactiveServiceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(idName); context.removeService(inactiveServiceName); } context.removeService(raServiceName); context.completeStep(new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext context, ModelNode operation) { if (resourceAdapter != null) { List<ServiceController<?>> newControllers = new LinkedList<ServiceController<?>>(); if (model.get(ARCHIVE.getName()).isDefined()) { RaOperationUtil.installRaServices(context, idName, resourceAdapter, newControllers); } else { try { RaOperationUtil.installRaServicesAndDeployFromModule(context, idName, resourceAdapter, archiveOrModuleName, newControllers); } catch (OperationFailedException e) { } } try { if (wasActive) { RaOperationUtil.activate(context, idName, archiveOrModuleName); } } catch (OperationFailedException e) { } } } }); } }, OperationContext.Stage.RUNTIME); } } }
7,885
47.981366
164
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdapterService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import static org.jboss.as.connector.logging.ConnectorLogger.SUBSYSTEM_RA_LOGGER; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; /** * A ResourceAdaptersService. * @author <a href="mailto:[email protected]">Stefano * Maestri</a> */ final class ResourceAdapterService implements Service<Activation> { private final Activation value; private final String name; private final InjectedValue<ResourceAdaptersService.ModifiableResourceAdaptors> resourceAdapters = new InjectedValue<ResourceAdaptersService.ModifiableResourceAdaptors>(); private final InjectedValue<ResourceAdaptersSubsystemService> resourceAdaptersSubsystemService = new InjectedValue<>(); /** create an instance **/ public ResourceAdapterService(ModifiableResourceAdapter value, String name) { this.value = value; this.name = name; } @Override public Activation getValue() throws IllegalStateException { return value; } @Override public void start(StartContext context) throws StartException { resourceAdapters.getValue().addActivation(value); resourceAdaptersSubsystemService.getValue().getAdapters().putIfAbsent(value.getArchive(), ServiceName.of(ConnectorServices.RA_SERVICE, name)); SUBSYSTEM_RA_LOGGER.debugf("Starting ResourceAdapter Service"); } @Override public void stop(StopContext context) { resourceAdapters.getValue().removeActivation(value); resourceAdaptersSubsystemService.getValue().getAdapters().remove(value.getArchive()); SUBSYSTEM_RA_LOGGER.debugf("Stopping ResourceAdapter Service"); } public Injector<ResourceAdaptersService.ModifiableResourceAdaptors> getResourceAdaptersInjector() { return resourceAdapters; } public Injector<ResourceAdaptersSubsystemService> getResourceAdaptersSubsystemInjector() { return resourceAdaptersSubsystemService; } }
3,400
39.488095
175
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/IronJacamarResource.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import java.util.Collections; import java.util.Set; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.AbstractModelResource; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; /** * Resource maintaining the sub-tree for the iron-jacamar * * @author Stefano Maestri */ public class IronJacamarResource implements Resource { private volatile Resource delegate = Factory.create(); protected void update(final Resource updated) { delegate = updated; } @Override public ModelNode getModel() { return delegate.getModel(); } @Override public void writeModel(ModelNode newModel) { delegate.writeModel(newModel); } @Override public boolean isModelDefined() { return delegate.isModelDefined(); } @Override public boolean hasChild(PathElement element) { return delegate.hasChild(element); } @Override public Resource getChild(PathElement element) { return delegate.getChild(element); } @Override public Resource requireChild(PathElement element) { return delegate.requireChild(element); } @Override public boolean hasChildren(String childType) { return delegate.hasChildren(childType); } @Override public Resource navigate(PathAddress address) { return delegate.navigate(address); } @Override public Set<String> getChildTypes() { return delegate.getChildTypes(); } @Override public Set<String> getChildrenNames(String childType) { return delegate.getChildrenNames(childType); } @Override public Set<ResourceEntry> getChildren(String childType) { return delegate.getChildren(childType); } @Override public void registerChild(PathElement address, Resource resource) { assert resource instanceof IronJacamarRuntimeResource; delegate.registerChild(address, resource); } @Override public void registerChild(PathElement address, int index, Resource resource) { throw ConnectorLogger.ROOT_LOGGER.indexedChildResourceRegistrationNotAvailable(address); } @Override public Resource removeChild(PathElement address) { return delegate.removeChild(address); } @Override public Set<String> getOrderedChildTypes() { return Collections.emptySet(); } @Override public boolean isRuntime() { return false; } @Override public boolean isProxy() { return false; } @Override public Resource clone() { return this; } public static class IronJacamarRuntimeResource extends AbstractModelResource { private volatile ModelNode model = new ModelNode(); public IronJacamarRuntimeResource() { } @Override public ModelNode getModel() { return model; } @Override public void writeModel(final ModelNode newModel) { model = newModel; } @Override public boolean isModelDefined() { return model.isDefined(); } @Override public Resource clone() { return this; } @Override public boolean isRuntime() { return true; } } }
4,555
25.33526
96
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ResourceAdaptersSubSystemAdd.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.util.ConnectorServices; import org.jboss.as.connector.util.CopyOnWriteArrayListMultiMap; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import java.io.File; import static org.jboss.as.connector.subsystems.resourceadapters.Constants.*; /** * Handler for adding the resource adapters subsystem. * * @author @author <a href="mailto:[email protected]">Stefano * Maestri</a> * @author John Bailey */ class ResourceAdaptersSubsystemAdd extends AbstractAddStepHandler { static final ResourceAdaptersSubsystemAdd INSTANCE = new ResourceAdaptersSubsystemAdd(); protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { Constants.REPORT_DIRECTORY.validateAndSet(operation, model); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final Resource subsystemResource = context.readResourceFromRoot(PathAddress.pathAddress(ResourceAdaptersExtension.SUBSYSTEM_PATH)); final String reportDirectoryName = Constants.REPORT_DIRECTORY.resolveModelAttribute(context, operation).asString(); final File reportDirectory = new File(reportDirectoryName); if (!reportDirectory.exists()) { throw ConnectorLogger.SUBSYSTEM_RA_LOGGER.reportDirectoryDoesNotExist(reportDirectoryName); } ResourceAdaptersSubsystemService service = new ResourceAdaptersSubsystemService(reportDirectory); CopyOnWriteArrayListMultiMap<String, ServiceName> value = service.getValue().getAdapters(); for (Resource.ResourceEntry re : subsystemResource.getChildren(RESOURCEADAPTER_NAME)) { value.putIfAbsent(re.getModel().get(ARCHIVE.getName()).asString(), ConnectorServices.RA_SERVICE.append(re.getName())); } final ServiceBuilder<?> builder = context.getServiceTarget().addService(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, service); builder.setInitialMode(ServiceController.Mode.ACTIVE).install(); } }
3,614
45.948052
143
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/subsystems/resourceadapters/ModifiableResourceAdapter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.subsystems.resourceadapters; import java.util.List; import java.util.Map; import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum; import org.jboss.jca.common.api.metadata.resourceadapter.AdminObject; import org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition; import org.jboss.jca.common.api.metadata.resourceadapter.WorkManager; import org.jboss.jca.common.metadata.resourceadapter.ActivationImpl; import org.jboss.msc.service.ServiceName; public class ModifiableResourceAdapter extends ActivationImpl { private volatile ServiceName raXmlDeploymentServiceName = null; public ModifiableResourceAdapter(String id, String archive, TransactionSupportEnum transactionSupport, List<ConnectionDefinition> connectionDefinitions, List<AdminObject> adminObjects, Map<String, String> configProperties, List<String> beanValidationGroups, String bootstrapContext, WorkManager workmanager) { super(id, archive, transactionSupport, connectionDefinitions, adminObjects, configProperties, beanValidationGroups, bootstrapContext, workmanager); } public synchronized void addConfigProperty(String name, String value) { configProperties.put(name, value); } public synchronized void addConnectionDefinition(ConnectionDefinition value) { connectionDefinitions.add(value); } public synchronized int connectionDefinitionSize() { return connectionDefinitions.size(); } public synchronized void addAdminObject(AdminObject value) { adminObjects.add(value); } public synchronized int adminObjectSize() { return adminObjects.size(); } public ServiceName getRaXmlDeploymentServiceName() { return raXmlDeploymentServiceName; } public void setRaXmlDeploymentServiceName(ServiceName raXmlDeploymentServiceName) { this.raXmlDeploymentServiceName = raXmlDeploymentServiceName; } }
3,062
39.302632
156
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/ds/DsSecurityImpl.java
/* * Copyright 2017 Red Hat, Inc. * * 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.as.connector.metadata.ds; import java.util.Objects; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.as.connector.metadata.api.ds.DsSecurity; import org.jboss.as.connector.metadata.common.CredentialImpl; import org.jboss.jca.common.api.metadata.common.Extension; import org.jboss.jca.common.api.validator.ValidateException; import org.wildfly.common.function.ExceptionSupplier; import org.wildfly.security.credential.source.CredentialSource; /** * Extension of {@link org.jboss.jca.common.metadata.ds.DsSecurityImpl} with added Elytron support. * * @author Flavia Rainone */ public class DsSecurityImpl extends CredentialImpl implements DsSecurity, Credential { private static final long serialVersionUID = 312322268048179001L; private final Extension reauthPlugin; /** * Create a new DsSecurityImpl. * * @param userName user name * @param password user password * @param securityContext specific information used by implementation to define in which context this user/password info * belongs * @param reauthPlugin reauthentication plugin * @param credentialSourceSupplier an Elytron credentia supplier * @throws ValidateException in case of validation error */ public DsSecurityImpl(final String userName, final String password, final String securityContext, final ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier, Extension reauthPlugin) throws ValidateException { super(userName, password, securityContext, credentialSourceSupplier); this.reauthPlugin = reauthPlugin; this.validate(); } public Extension getReauthPlugin() { return this.reauthPlugin; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; DsSecurityImpl that = (DsSecurityImpl) o; return Objects.equals(reauthPlugin, that.reauthPlugin); } @Override public int hashCode() { return Objects.hash(super.hashCode(), reauthPlugin); } @Override public String toString() { return "DsSecurityImpl{" + "userName='" + getUserName() + '\'' + ", password='" + getPassword() + '\'' + ", securityDomain='" + getSecurityDomain() + '\'' + "reauthPlugin=" + reauthPlugin + '}'; } }
3,179
34.730337
155
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/resourceadapter/WorkManagerSecurityImpl.java
/* * Copyright 2017 Red Hat, Inc. * * 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.as.connector.metadata.resourceadapter; import java.util.List; import java.util.Map; import org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity; /** * Extension of {@link org.jboss.jca.common.metadata.resourceadapter.WorkManagerSecurityImpl} with added Elytron support. * * @author Flavia Rainone */ public class WorkManagerSecurityImpl extends org.jboss.jca.common.metadata.resourceadapter.WorkManagerSecurityImpl implements WorkManagerSecurity { private static final long serialVersionUID = -6928615726774510406L; // indicates if Elytron is enabled. In this case, securityContext, defined as securityDomain in super class, // refers to Elytron authenticationContext private final boolean elytronEnabled; /** * Constructor. * * @param mappingRequired is mapping required * @param securityContext specific information used by implementation to define in which context this security info * belongs * @param elytronEnabled indicates if Elytron is responsible for taking care of work manager security * @param defaultPrincipal default principal * @param defaultGroups default groups * @param userMappings user mappings * @param groupMappings group mappings */ public WorkManagerSecurityImpl(boolean mappingRequired, String securityContext, boolean elytronEnabled, String defaultPrincipal, List<String> defaultGroups, Map<String, String> userMappings, Map<String, String> groupMappings) { super(mappingRequired, securityContext, defaultPrincipal, defaultGroups, userMappings, groupMappings); this.elytronEnabled = elytronEnabled; } /** * {@inheritDoc} */ public boolean isElytronEnabled() { return elytronEnabled; } /** * {@inheritDoc} */ @Override public int hashCode() { int result = super.hashCode(); if (elytronEnabled) { result += 31; } return result; } /** * {@inheritDoc} */ @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (!(o instanceof WorkManagerSecurityImpl)) return false; WorkManagerSecurityImpl other = (WorkManagerSecurityImpl) o; return other.elytronEnabled == elytronEnabled && super.equals(o); } /** * {@inheritDoc} */ @Override public String toString() { if (!elytronEnabled) { return super.toString(); } StringBuilder sb = new StringBuilder(1024); sb.append("<security>"); sb.append("<").append(WorkManagerSecurity.Tag.MAPPING_REQUIRED).append(">"); sb.append(isMappingRequired()); sb.append("</").append(WorkManagerSecurity.Tag.MAPPING_REQUIRED).append(">"); if (getDomain() != null) { if (elytronEnabled) { sb.append("<").append(WorkManagerSecurity.Tag.ELYTRON_SECURITY_DOMAIN).append(">"); sb.append(getDomain()); sb.append("</").append(WorkManagerSecurity.Tag.ELYTRON_SECURITY_DOMAIN).append(">"); } else { sb.append("<").append(WorkManagerSecurity.Tag.DOMAIN).append(">"); sb.append(getDomain()); sb.append("</").append(WorkManagerSecurity.Tag.DOMAIN).append(">"); } } if (getDefaultPrincipal() != null) { sb.append("<").append(WorkManagerSecurity.Tag.DEFAULT_PRINCIPAL).append(">"); sb.append(getDefaultPrincipal()); sb.append("</").append(WorkManagerSecurity.Tag.DEFAULT_PRINCIPAL).append(">"); } if (getDefaultGroups() != null && !getDefaultGroups().isEmpty()) { sb.append("<").append(WorkManagerSecurity.Tag.DEFAULT_GROUPS).append(">"); for (String group : getDefaultGroups()) { sb.append("<").append(WorkManagerSecurity.Tag.GROUP).append(">"); sb.append(group); sb.append("</").append(WorkManagerSecurity.Tag.GROUP).append(">"); } sb.append("</").append(WorkManagerSecurity.Tag.DEFAULT_GROUPS).append(">"); } if ((getUserMappings() != null && getUserMappings().size() > 0) || (getGroupMappings() != null && getGroupMappings().size() > 0)) { sb.append("<").append(WorkManagerSecurity.Tag.MAPPINGS).append(">"); if (getUserMappings() != null && getUserMappings().size() > 0) { sb.append("<").append(WorkManagerSecurity.Tag.USERS).append(">"); for (Map.Entry<String, String> entry : getUserMappings().entrySet()) { sb.append("<").append(WorkManagerSecurity.Tag.MAP); sb.append(" ").append(Attribute.FROM).append("=\""); sb.append(entry.getKey()).append("\""); sb.append(" ").append(Attribute.TO).append("=\""); sb.append(entry.getValue()).append("\""); sb.append("/>"); } sb.append("</").append(WorkManagerSecurity.Tag.USERS).append(">"); } if (getGroupMappings() != null && getGroupMappings().size() > 0) { sb.append("<").append(WorkManagerSecurity.Tag.GROUPS).append(">"); for (Map.Entry<String, String> entry : getGroupMappings().entrySet()) { sb.append("<").append(WorkManagerSecurity.Tag.MAP); sb.append(" ").append(Attribute.FROM).append("=\""); sb.append(entry.getKey()).append("\""); sb.append(" ").append(Attribute.TO).append("=\""); sb.append(entry.getValue()).append("\""); sb.append("/>"); } sb.append("</").append(WorkManagerSecurity.Tag.GROUPS).append(">"); } sb.append("</").append(WorkManagerSecurity.Tag.MAPPINGS).append(">"); } sb.append("</security>"); return sb.toString(); } }
6,883
35.42328
137
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/common/CredentialImpl.java
/* * Copyright 2017 Red Hat, Inc. * * 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.as.connector.metadata.common; import java.util.Objects; import org.jboss.as.connector.logging.ConnectorLogger; import org.jboss.as.connector.metadata.api.common.Credential; import org.jboss.jca.common.CommonBundle; import org.jboss.jca.common.api.validator.ValidateException; import org.jboss.logging.Messages; import org.wildfly.common.function.ExceptionSupplier; import org.wildfly.security.credential.PasswordCredential; import org.wildfly.security.credential.source.CredentialSource; import org.wildfly.security.password.interfaces.ClearPassword; /** * Extension of {@link org.jboss.jca.common.metadata.common.CredentialImpl} with added Elytron support. * * @author Flavia Rainone */ public class CredentialImpl implements Credential { private static final long serialVersionUID = 7990943957924515091L; private static CommonBundle bundle = (CommonBundle) Messages.getBundle(CommonBundle.class); private final String userName; private final String password; private final String securityDomain; private final ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier; /** * Create a new CredentialImpl. * * @param userName user name * @param password user password * @param securityContext specific information that helps implementation define which context this Credential belongs to * @throws ValidateException ValidateException in case of validation error */ public CredentialImpl(final String userName, final String password, final String securityContext, final ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier) throws ValidateException { this.userName = userName; this.password = password; this.securityDomain = securityContext; this.credentialSourceSupplier = credentialSourceSupplier; } public void validate() throws ValidateException { if (this.userName != null && this.securityDomain != null) { throw new ValidateException(bundle.invalidSecurityConfiguration()); } } public final String getSecurityDomain() { return this.securityDomain; } public final String resolveSecurityDomain() { return this.getSecurityDomain(); } public final String getUserName() { return this.userName; } public final String getPassword() { if (credentialSourceSupplier != null) { try { return new String( credentialSourceSupplier.get().getCredential(PasswordCredential.class).getPassword(ClearPassword.class).getPassword()); } catch (Exception e) { throw ConnectorLogger.DEPLOYMENT_CONNECTOR_LOGGER.invalidCredentialSourceSupplier(e); } } return this.password; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CredentialImpl that = (CredentialImpl) o; return Objects.equals(userName, that.userName) && Objects.equals(password, that.password) && Objects.equals(securityDomain, that.securityDomain) && Objects.equals(credentialSourceSupplier, that.credentialSourceSupplier); } @Override public int hashCode() { return Objects.hash(userName, password, securityDomain, credentialSourceSupplier); } @Override public String toString() { return "CredentialImpl{" + "userName='" + userName + '\'' + ", password='" + password + '\'' + ", securityDomain='" + securityDomain + '\'' + ", credentialSourceSupplier=" + credentialSourceSupplier + '}'; } }
4,458
36.158333
143
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/common/SecurityImpl.java
/* * Copyright 2017 Red Hat, Inc. * * 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.as.connector.metadata.common; import org.jboss.as.connector.metadata.api.common.Security; import org.jboss.jca.common.api.validator.ValidateException; /** * Extension of {@link org.jboss.jca.common.metadata.common.SecurityImpl} with added Elytron support. * * @author Flavia Rainone */ public class SecurityImpl extends org.jboss.jca.common.metadata.common.SecurityImpl implements Security { private static final long serialVersionUID = -4549127155646451392L; /** * Deprecated. Elytron is enabled by default and this field is ignored. */ private boolean elytronEnabled; /** * Constructor * * @param securityDomain security domain managed authentication. Security domain will refer to * an Elytron authentication context * @param securityDomainAndApplication securityDomain and application managed authentication. This field will refer * to an Elytron authentication context * @param applicationManaged application managed authentication * @throws ValidateException ValidateException in case of a validation error */ public SecurityImpl(String securityDomain, String securityDomainAndApplication, boolean applicationManaged) throws ValidateException { super(securityDomain, securityDomainAndApplication, applicationManaged); } /** * {@inheritDoc} */ @Override public int hashCode() { return super.hashCode() + (elytronEnabled? 1: 0); } /** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof SecurityImpl) { SecurityImpl other = (SecurityImpl) obj; if (elytronEnabled != other.elytronEnabled) return false; } return super.equals(obj); } /** * {@inheritDoc} */ @Override public String toString() { StringBuilder sb = new StringBuilder(1024); sb.append("<security>"); if (getSecurityDomain() != null) { sb.append("<").append(Security.Tag.AUTHENTICATION_CONTEXT).append("/>"); sb.append(getSecurityDomain()); sb.append("</").append(Security.Tag.AUTHENTICATION_CONTEXT).append("/>"); } else { sb.append("<").append(Security.Tag.AUTHENTICATION_CONTEXT_AND_APPLICATION).append("/>"); sb.append(getSecurityDomainAndApplication()); sb.append("</").append(Security.Tag.AUTHENTICATION_CONTEXT_AND_APPLICATION).append("/>"); } sb.append("</security>"); return sb.toString(); } }
3,389
33.948454
138
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/api/ds/DsSecurity.java
/* * Copyright 2017 Red Hat, Inc. * * 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.as.connector.metadata.api.ds; import org.jboss.jca.common.api.metadata.common.SecurityMetadata; /** * Extension of {@link org.jboss.jca.common.api.metadata.ds.DsSecurity} with added Elytron support. * * @author Flavia Rainone */ public interface DsSecurity extends org.jboss.jca.common.api.metadata.ds.DsSecurity, SecurityMetadata { /** * * A Tag. * */ enum Tag { // elytron tags /** * elytron-enabled tag */ ELYTRON_ENABLED("elytron-enabled"), /** * authentication-context tag */ AUTHENTICATION_CONTEXT("authentication-context"), /** * credential-reference tag */ CREDENTIAL_REFERENCE("credential-reference"), // other tags, copied from original tag enum /** always first * */ UNKNOWN(null), /** * userName tag */ USER_NAME("user-name"), /** * password tag */ PASSWORD("password"), /** * security-domain tag */ SECURITY_DOMAIN("security-domain"), /** * reauth-plugin tag */ REAUTH_PLUGIN("reauth-plugin"); private String name; /** * * Create a new Tag. * * @param name a name */ Tag(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } /** * {@inheritDoc} */ public String toString() { return name; } private static final java.util.Map<String, Tag> MAP; static { final java.util.Map<String, Tag> map = new java.util.HashMap<>(); for (Tag element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } /** * Set the value * @param v The name * @return The value */ Tag value(String v) { name = v; return this; } /** * * Static method to get enum instance given localName XsdString * * @param localName a XsdString used as localname (typically tag name as defined in xsd) * @return the enum instance */ public static Tag forName(String localName) { final Tag element = MAP.get(localName); return element == null ? UNKNOWN.value(localName) : element; } } }
3,206
22.580882
103
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/api/resourceadapter/WorkManagerSecurity.java
/* * Copyright 2017 Red Hat, Inc. * * 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.as.connector.metadata.api.resourceadapter; import java.util.HashMap; import java.util.Map; /** * Extension of {@link org.jboss.jca.common.api.metadata.resourceadapter.WorkManagerSecurity} with added Elytron support. * * @author Flavia Rainone */ public interface WorkManagerSecurity extends org.jboss.jca.common.api.metadata.resourceadapter.WorkManagerSecurity { /** * Indicates if Elytron is enabled. In this case, {@link #getDomain()}, refers to an Elytron authentication context * * @return {@code true} if is Elytron enabled */ boolean isElytronEnabled(); /** * A Tag. * */ enum Tag { // Elytron Tags /** * Is Elytron enabled */ ELYTRON_SECURITY_DOMAIN("elytron-security-domain"), /* Tags copied from super class */ /** always first * */ UNKNOWN(null), /** * mapping-required tag */ MAPPING_REQUIRED("mapping-required"), /** * domain tag */ DOMAIN("domain"), /** * default-principal tag */ DEFAULT_PRINCIPAL("default-principal"), /** * default-groups tag */ DEFAULT_GROUPS("default-groups"), /** * group tag */ GROUP("group"), /** * mappings tag */ MAPPINGS("mappings"), /** * users tag */ USERS("users"), /** * groups tag */ GROUPS("groups"), /** * map tag */ MAP("map"); private String name; /** * * Create a new Tag. * * @param name a name */ Tag(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } /** * {@inheritDoc} */ public String toString() { return name; } private static final Map<String, Tag> MAPE; static { final Map<String, Tag> map = new HashMap<>(); for (Tag element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAPE = map; } /** * Set the value * @param v The name * @return The value */ Tag value(String v) { name = v; return this; } /** * * Static method to get enum instance given localName string * * @param localName a string used as localname (typically tag name as defined in xsd) * @return the enum instance */ public static Tag forName(String localName) { final Tag element = MAPE.get(localName); return element == null ? UNKNOWN.value(localName) : element; } } }
3,768
22.409938
121
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/api/common/Credential.java
/* * Copyright 2017 Red Hat, Inc. * * 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.as.connector.metadata.api.common; import org.jboss.as.controller.security.CredentialReference; import org.jboss.jca.common.api.metadata.common.SecurityMetadata; /** * Extension of {@link org.jboss.jca.common.api.metadata.common.Credential} with added Elytron support. * * @author Flavia Rainone */ public interface Credential extends org.jboss.jca.common.api.metadata.common.Credential, SecurityMetadata { /** * * A Tag. * */ enum Tag { // new Elytron tag /** * elytron-enabled tag */ ELYTRON_ENABLED("elytron-enabled"), /** * authentication-context tag */ AUTHENTICATION_CONTEXT("authentication-context"), /** * credential-reference tag */ CREDENTIAL_REFERENCE(CredentialReference.CREDENTIAL_REFERENCE), // tags copied from original tag class /** always first * */ UNKNOWN(null), /** * userName tag */ USER_NAME("user-name"), /** * password tag */ PASSWORD("password"), /** * security-domain tag */ SECURITY_DOMAIN("security-domain"); private String name; /** * * Create a new Tag. * * @param name a name */ Tag(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } /** * {@inheritDoc} */ public String toString() { return name; } private static final java.util.Map<String, Tag> MAP; static { final java.util.Map<String, Tag> map = new java.util.HashMap<>(); for (Tag element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } /** * Set the value * @param v The name * @return The value */ Tag value(String v) { name = v; return this; } /** * * Static method to get enum instance given localName XsdString * * @param localName a XsdString used as localname (typically tag name as defined in xsd) * @return the enum instance */ public static Tag forName(String localName) { final Tag element = MAP.get(localName); return element == null ? UNKNOWN.value(localName) : element; } } }
3,212
22.977612
107
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/api/common/Security.java
/* * Copyright 2017 Red Hat, Inc. * * 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.as.connector.metadata.api.common; import org.jboss.jca.common.api.metadata.common.SecurityMetadata; import java.util.HashMap; import java.util.Map; /** * Extension of {@link org.jboss.jca.common.api.metadata.common.Security} with added Elytron support. * * @author Flavia Rainone */ public interface Security extends org.jboss.jca.common.api.metadata.common.Security, SecurityMetadata { /** * * A Tag. * */ enum Tag { // new Elytron tags /** * elytron-enabled tag */ ELYTRON_ENABLED("elytron-enabled"), /** * authentication-context TAG */ AUTHENTICATION_CONTEXT("authentication-context"), /** * authentication-context-and-application TAG */ AUTHENTICATION_CONTEXT_AND_APPLICATION("authentication-context-and-application"), // tags copied from original tag class /** always first * */ UNKNOWN(null), /** * security-domain tag */ SECURITY_DOMAIN("security-domain"), /** * security-domain-and-application TAG */ SECURITY_DOMAIN_AND_APPLICATION("security-domain-and-application"), /** * application */ APPLICATION("application"); private String name; /** * * Create a new Tag. * * @param name a name */ Tag(final String name) { this.name = name; } /** * Get the local name of this element. * * @return the local name */ public String getLocalName() { return name; } /** * {@inheritDoc} */ public String toString() { return name; } private static final Map<String, Tag> MAP; static { final Map<String, Tag> map = new HashMap<>(); for (Tag element : values()) { final String name = element.getLocalName(); if (name != null) map.put(name, element); } MAP = map; } /** * Set the value * @param v The name * @return The value */ Tag value(String v) { name = v; return this; } /** * * Static method to get enum instance given localName XsdString * * @param localName a XsdString used as localname (typically tag name as defined in xsd) * @return the enum instance */ public static Tag forName(String localName) { final Tag element = MAP.get(localName); return element == null ? UNKNOWN.value(localName) : element; } } }
3,274
22.905109
103
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/deployment/ResourceAdapterDeployment.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.metadata.deployment; import org.jboss.jca.deployers.common.CommonDeployment; import org.jboss.msc.service.ServiceName; /** * A resource adapter deployment * @author <a href="mailto:[email protected]">Jesper Pedersen</a> */ public final class ResourceAdapterDeployment { private final CommonDeployment deployment; private final String raName; private final ServiceName raServiceName; /** * Create an instance * @param deployment The deployment * @param raName the resource-adapter name * @param raServiceName service name for this resource-adapter */ public ResourceAdapterDeployment(final CommonDeployment deployment, final String raName, final ServiceName raServiceName) { this.deployment = deployment; this.raName = raName; this.raServiceName = raServiceName; } /** * Get the deployment * @return The deployment */ public CommonDeployment getDeployment() { return deployment; } /** * String representation * @return The string */ public String toString() { StringBuilder sb = new StringBuilder(100); sb.append("ResourceAdapterDeployment@").append(Integer.toHexString(System.identityHashCode(this))); sb.append("[deployment=").append(deployment); sb.append("]"); return sb.toString(); } public String getRaName() { return raName; } public ServiceName getRaServiceName() { return raServiceName; } }
2,585
30.156627
127
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/xmldescriptors/IronJacamarXmlDescriptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.metadata.xmldescriptors; import java.io.Serializable; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.jca.common.api.metadata.resourceadapter.Activation; /** * A RaXmlDescriptor. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public final class IronJacamarXmlDescriptor implements Serializable { private static final long serialVersionUID = 3148478338698997486L; public static final AttachmentKey<IronJacamarXmlDescriptor> ATTACHMENT_KEY = AttachmentKey .create(IronJacamarXmlDescriptor.class); private final Activation ironJacamar; /** * Create a new RaXmlDescriptor. * @param ironJacamar */ public IronJacamarXmlDescriptor(Activation ironJacamar) { super(); this.ironJacamar = ironJacamar; } /** * Get the resource adapters. * @return the resource adapters. */ public Activation getIronJacamar() { return ironJacamar; } }
2,053
32.672131
94
java
null
wildfly-main/connector/src/main/java/org/jboss/as/connector/metadata/xmldescriptors/ConnectorXmlDescriptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.connector.metadata.xmldescriptors; import java.io.File; import java.io.Serializable; import java.net.URL; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.jca.common.api.metadata.spec.Connector; /** * A ConnectorXmlDescriptor. * @author <a href="mailto:[email protected]">Stefano Maestri</a> */ public final class ConnectorXmlDescriptor implements Serializable { private static final long serialVersionUID = 3148478338698997486L; public static final AttachmentKey<ConnectorXmlDescriptor> ATTACHMENT_KEY = AttachmentKey .create(ConnectorXmlDescriptor.class); private final Connector connector; private final File root; private final URL url; private final String deploymentName; /** * Create a new ConnectorXmlDescriptor. * @param connector */ public ConnectorXmlDescriptor(Connector connector, File root, URL url, String deploymentName) { super(); this.connector = connector; this.root = root; this.url = url; this.deploymentName = deploymentName; } /** * Get the connector. * @return the connector. */ public Connector getConnector() { return connector; } /** * get file root of this deployment * @return the root directory */ public File getRoot() { return root; } /** * get url for this deployment * @return the url of deployment */ public URL getUrl() { return url; } /** * return this deployment name * @return the deployment name */ public String getDeploymentName() { return deploymentName; } }
2,743
28.505376
99
java
depends
depends-master/src/test/java/depends/addons/DV8MappingFileBuilderTest.java
package depends.addons; import java.util.ArrayList; import org.junit.Test; public class DV8MappingFileBuilderTest { @Test public void test() { DV8MappingFileBuilder b = new DV8MappingFileBuilder(new ArrayList<>()); b.create("/tmp/depends-dv8-mapping.json"); } }
274
16.1875
73
java
depends
depends-master/src/test/java/depends/matrix/MatrixLevelReducerTest.java
package depends.matrix; import static org.junit.Assert.*; import org.junit.Test; import depends.matrix.transform.MatrixLevelReducer; public class MatrixLevelReducerTest { @Test public void test_MatrixLevelReducer_1() { String node = ".maven.maven-parent.16.maven-parent-16_pom"; assertEquals(".maven", MatrixLevelReducer.calcuateNodeAtLevel(node, 1)); } @Test public void test_MatrixLevelReducer_2() { String node = "maven.maven-parent.16.maven-parent-16_pom"; assertEquals("maven", MatrixLevelReducer.calcuateNodeAtLevel(node, 1)); } @Test public void test_MatrixLevelReducer_3() { String node = ".maven.maven-parent.16.maven-parent-16_pom"; assertEquals(".maven.maven-parent.16.maven-parent-16_pom", MatrixLevelReducer.calcuateNodeAtLevel(node, 100)); } @Test public void test_MatrixLevelReducer_4() { String node = "maven.maven-parent....16.maven-parent-16_pom"; assertEquals("maven.maven-parent.16", MatrixLevelReducer.calcuateNodeAtLevel(node, 3)); } @Test public void test_MatrixLevelReducer_5() { String node = "maven/maven-parent/16/maven-parent-16.pom"; assertEquals("maven", MatrixLevelReducer.calcuateNodeAtLevel(node, 1)); } @Test public void test_MatrixLevelReducer_6() { String node = "/maven/maven-parent/16/maven-parent-16.pom"; assertEquals("/maven", MatrixLevelReducer.calcuateNodeAtLevel(node, 1)); } }
1,403
25.490566
63
java
depends
depends-master/src/test/java/depends/extractor/ParserTest.java
package depends.extractor; import depends.entity.ContainerEntity; import depends.entity.Entity; import depends.entity.FunctionEntity; import depends.entity.VarEntity; import depends.entity.repo.EntityRepo; import depends.relations.BindingResolver; import depends.relations.IBindingResolver; import depends.relations.Relation; import depends.relations.RelationCounter; import multilang.depends.util.file.TemporaryFile; import java.util.ArrayList; import java.util.Collection; import java.util.Set; import static org.junit.Assert.fail; public abstract class ParserTest { protected EntityRepo entityRepo ; protected IBindingResolver bindingResolver; protected AbstractLangProcessor langProcessor; protected void init(){ entityRepo = langProcessor.getEntityRepo(); bindingResolver = new BindingResolver(langProcessor,true,false); langProcessor.bindingResolver = bindingResolver; TemporaryFile.reset(); } protected void init(boolean duckTypingDeduce){ entityRepo = langProcessor.getEntityRepo(); bindingResolver = new BindingResolver(langProcessor,false,duckTypingDeduce); langProcessor.bindingResolver = bindingResolver; TemporaryFile.reset(); } public Set<UnsolvedBindings> resolveAllBindings() { Set<UnsolvedBindings> result = bindingResolver.resolveAllBindings(langProcessor.isEagerExpressionResolve()); new RelationCounter(entityRepo,langProcessor, bindingResolver).computeRelations(); return result; } protected Set<UnsolvedBindings> resolveAllBindings(boolean callAsImpl) { Set<UnsolvedBindings> result = bindingResolver.resolveAllBindings(langProcessor.isEagerExpressionResolve()); new RelationCounter(entityRepo,langProcessor, bindingResolver).computeRelations(); return result; } protected void assertNotContainsRelation(Entity inEntity, String dependencyType, String dependedEntityFullName) { for (Relation r:inEntity.getRelations()) { if (r.getType().equals(dependencyType)) { if (r.getEntity().getQualifiedName().equals(dependedEntityFullName)) { fail("found unexpected relation: type = " + dependencyType + " to entity " + dependedEntityFullName); } } } } protected void assertContainsRelation(Entity inEntity, String dependencyType, String dependedEntityFullName) { Relation relation = null; for (Relation r:inEntity.getRelations()) { if (r.getType().equals(dependencyType)) { relation = r; if (r.getEntity()==null) continue; if (r.getEntity().getQualifiedName().equals(dependedEntityFullName)) return; } } if (relation==null) { fail("cannot found relation type of "+ dependencyType); }else { fail("cannot found relation type of " + dependencyType + " to entity " + dependedEntityFullName); } } protected void assertContainsVarWithRawName(Entity entity, String name) { ContainerEntity container = (ContainerEntity)entity; ArrayList<VarEntity> vars = container.getVars(); for (VarEntity var:vars) { if (var.getRawName().uniqName().equals(name)) { return; } } fail("cannot found var with rawname " + name); } protected void assertContainsParametersWithRawName(FunctionEntity function, String name) { Collection<VarEntity> vars = function.getParameters(); for (VarEntity var:vars) { if (var.getRawName().uniqName().equals(name)) { return; } } fail("cannot found parameter with rawname " + name); } protected void assertContainReturnType(FunctionEntity function, String name) { Collection<Entity> types = function.getReturnTypes(); for (Entity type:types) { if (type.getRawName().uniqName().equals(name)) { return; } } fail("cannot found return type with rawname " + name); } }
3,735
32.963636
114
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyParserTest.java
package depends.extractor.ruby; import depends.extractor.FileParser; import depends.extractor.IncludedFileLocator; import depends.extractor.ParserCreator; import depends.extractor.ParserTest; import depends.extractor.ruby.jruby.JRubyFileParser; import java.util.ArrayList; import java.util.List; public abstract class RubyParserTest extends ParserTest implements ParserCreator{ public void init() { langProcessor = new RubyProcessor(); super.init(true); } public FileParser createFileParser() { return new JRubyFileParser(entityRepo, new IncludedFileLocator(includePaths()), bindingResolver, this); } private List<String> includePaths() { return new ArrayList<>(); } }
688
26.56
105
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyReturnTypeDedudceTest.java
package depends.extractor.ruby; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.FunctionEntity; import depends.extractor.FileParser; public class RubyReturnTypeDedudceTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_deduce_type_of_return() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/deducetype_return.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("Class.test")); this.assertContainReturnType(function,"Class"); function = (FunctionEntity)(entityRepo.getEntity("Class.implicitReturn")); this.assertContainReturnType(function,"Class1"); } }
910
24.305556
84
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubySingletonMethodTest.java
package depends.extractor.ruby; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.ContainerEntity; import depends.entity.VarEntity; import depends.extractor.FileParser; import multilang.depends.util.file.FileUtil; public class RubySingletonMethodTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_singleton_method_should_created_in_var() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/singleton_method.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } ContainerEntity file = (ContainerEntity)(entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0]))); VarEntity var = file.lookupVarLocally("var2"); assertEquals(1,var.getFunctions().size()); } }
950
24.702703
100
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyObjectCreationTest.java
package depends.extractor.ruby; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.extractor.FileParser; public class RubyObjectCreationTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/object_creation.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); super.assertContainsRelation(entityRepo.getEntity("T.foo"), DependencyType.CREATE, "M"); } }
715
21.375
93
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyVCallTest.java
package depends.extractor.ruby; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.FileParser; public class RubyVCallTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_vcall() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/vcall.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("called_from")); this.assertContainsRelation(function, DependencyType.CALL, "called"); } @Test public void test_continuous_call() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/continuous_func_call.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("test")); this.assertContainsRelation(function, DependencyType.CALL, "foo"); this.assertContainsRelation(function, DependencyType.CALL, "bar"); } }
1,356
24.603774
85
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyModuleLevelsTest.java
package depends.extractor.ruby; import static org.junit.Assert.assertNotNull; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.PackageEntity; import depends.extractor.FileParser; public class RubyModuleLevelsTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_parameter_should_be_created() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/ruby_modules.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } PackageEntity module = (PackageEntity)(entityRepo.getEntity("A.B")); assertNotNull(module); module = (PackageEntity)(entityRepo.getEntity("X.Y.Z")); assertNotNull(module); module = (PackageEntity)(entityRepo.getEntity("L.M.N")); assertNotNull(module); } }
934
23.605263
73
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyNameIBindingResolverTest.java
package depends.extractor.ruby; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.FileParser; public class RubyNameIBindingResolverTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_infer_function_in_multiple_module() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/ruby_name_infer.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("M1.test")); this.assertContainsRelation(function, DependencyType.CALL, "M1.f1"); this.assertContainsRelation(function, DependencyType.CALL, "M1.f2"); } @Test public void test_infer_function_should_distinguish_global_and_local() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/ruby_name_infer_with_range.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("M2.M1.test2")); this.assertContainsRelation(function, DependencyType.CALL, "M2.M1.f1"); function = (FunctionEntity)(entityRepo.getEntity("M2.M1.test1")); this.assertContainsRelation(function, DependencyType.CALL, "M1.f1"); } }
1,599
29.188679
91
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyVariableCallTest.java
package depends.extractor.ruby; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.FileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class RubyVariableCallTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_variable_call_should_be_resoved_in_case_of_new() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/variable_call.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("test")); this.assertContainsRelation(function, DependencyType.CALL, "Class.function"); } }
856
24.205882
87
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyRaiseTypeDedudceTest.java
package depends.extractor.ruby; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.FileParser; public class RubyRaiseTypeDedudceTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_deduce_type_of_raise() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/deducetype_raise.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("Class.test")); this.assertContainsRelation(function, DependencyType.THROW, "Class1"); } }
837
22.277778
84
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyVarInvocationRecordTest.java
package depends.extractor.ruby; import depends.entity.ContainerEntity; import depends.entity.VarEntity; import depends.extractor.FileParser; import multilang.depends.util.file.FileUtil; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; public class RubyVarInvocationRecordTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_singleton_method_should_created_in_var() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/var_invocation_record.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } ContainerEntity file = (ContainerEntity)(entityRepo.getEntity(FileUtil.uniqFilePath(srcs[0]))); VarEntity var = file.lookupVarLocally("var"); assertEquals(1,var.getCalledFunctions().size()); } } //class Class //def foo //end //end // //var = Class.new //var.foo
1,032
21.955556
100
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyClassMethodcallTest.java
package depends.extractor.ruby; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.entity.FunctionEntity; import depends.extractor.FileParser; public class RubyClassMethodcallTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_class_method_call() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/class_method_call.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("called_from")); this.assertContainsRelation(function, DependencyType.CALL, "Foo1.bar"); this.assertContainsRelation(function, DependencyType.CALL, "Foo2.bar"); this.assertContainsRelation(function, DependencyType.CALL, "Foo3.bar"); } }
990
25.783784
85
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyVarTest.java
package depends.extractor.ruby; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.ContainerEntity; import depends.entity.FunctionEntity; import depends.entity.TypeEntity; import depends.entity.repo.EntityRepo; import depends.extractor.FileParser; public class RubyVarTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_parameter_should_be_created() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("method1")); assertEquals(1,function.getParameters().size()); assertContainsParametersWithRawName(function, "param1"); } @Test public void test_var_should_be_created_if_not_declared() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("method_with_local_var")); assertEquals(1,function.getVars().size()); assertContainsVarWithRawName(function, "var_1"); } @Test public void test_var_should_only_create_once() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("method_with_local_var_2times")); assertEquals(1,function.getVars().size()); } @Test public void test_var_should_not_be_created_if_it_actually_parameter() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("method_without_local_var_and_param")); assertEquals(0,function.getVars().size()); } @Test public void test_var_should_not_be_created_if_it_actually_a_file_level_var() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("method_access_file_level_var")); assertEquals(0,function.getVars().size()); } @Test public void test_var_should_not_be_created_with_a_lot_of_levels() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("M.C.method")); assertEquals(1,function.getVars().size()); } @Test public void test_var_should_not_be_created_not_in_scope() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("M.C.method2")); assertEquals(1,function.getVars().size()); } @Test public void test_var_should_created_at_class_level() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } TypeEntity c = (TypeEntity)(entityRepo.getEntity("M.C")); assertEquals(3,c.getVars().size()); assertContainsVarWithRawName(c,"class_level_var"); assertContainsVarWithRawName(c,"class_var"); assertContainsVarWithRawName(c,"instance_var"); } @Test public void test_var_in_block() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } ContainerEntity c = (ContainerEntity)(entityRepo.getEntity("Block")); assertEquals(1,c.getVars().size()); assertContainsVarWithRawName(c,"a"); } @Test public void test_global_var()throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/auto_var.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } ContainerEntity c = (ContainerEntity)(entityRepo.getEntity(EntityRepo.GLOBAL_SCOPE_NAME)); assertEquals(1,c.getVars().size()); assertContainsVarWithRawName(c,"global_var"); } }
5,268
29.456647
108
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyRequireTest.java
package depends.extractor.ruby; import java.io.File; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.extractor.FileParser; public class RubyRequireTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_require_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/require_1.rb", "./src/test/resources/ruby-code-examples/require_2.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); File f = new File(srcs[0]); File f2 = new File(srcs[1]); super.assertContainsRelation(entityRepo.getEntity(f.getCanonicalPath()), DependencyType.IMPORT, f2.getCanonicalPath()); } }
907
24.942857
127
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyParameterTypeDedudceTest.java
package depends.extractor.ruby; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.CandidateTypes; import depends.entity.FunctionEntity; import depends.entity.TypeEntity; import depends.entity.VarEntity; import depends.extractor.FileParser; public class RubyParameterTypeDedudceTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_deduce_type_of_return() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/deducetype_parameter.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("test")); VarEntity var = function.lookupVarLocally("t1"); TypeEntity type = var.getType(); assertTrue(type instanceof CandidateTypes); assertEquals(2,((CandidateTypes)type).getCandidateTypes().size()); } }
1,129
25.904762
78
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyNameTest.java
package depends.extractor.ruby; import static org.junit.Assert.assertNotNull; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.entity.PackageEntity; import depends.extractor.FileParser; public class RubyNameTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_parameter_should_be_created() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/ruby_name.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } PackageEntity module = (PackageEntity)(entityRepo.getEntity("A.B.C")); assertNotNull(module); } }
748
19.805556
75
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyMixinTest.java
package depends.extractor.ruby; import java.io.IOException; import org.junit.Before; import org.junit.Test; import depends.deptypes.DependencyType; import depends.extractor.FileParser; public class RubyMixinTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_mixin_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/mix_in.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); assertContainsRelation(entityRepo.getEntity("MixedIn"),DependencyType.MIXIN,"ToBeMixin"); } }
703
21
94
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyAssignedVariableTypeDedudceTest.java
package depends.extractor.ruby; import depends.entity.FunctionEntity; import depends.entity.TypeEntity; import depends.entity.VarEntity; import depends.extractor.FileParser; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; public class RubyAssignedVariableTypeDedudceTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_variable_call_should_be_resoved_in_case_of_new() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/variable_assignment.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("Class.test")); VarEntity var = function.lookupVarLocally("var_int"); assertEquals(TypeEntity.buildInType.getRawName(),var.getType().getRawName()); var = function.lookupVarLocally("var_c"); assertEquals("Class",var.getType().getRawName().uniqName()); TypeEntity classEntity = (TypeEntity)(entityRepo.getEntity("Class")); var = classEntity.lookupVarLocally("inst_var"); assertEquals("Class",var.getType().getRawName().uniqName()); var = classEntity.lookupVarLocally("class_var"); assertEquals("Class",var.getType().getRawName().uniqName()); } @Test public void test_compose_expression_with_operator() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/variable_assignment.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); FunctionEntity function = (FunctionEntity)(entityRepo.getEntity("Class.operator_is_call")); VarEntity var = function.lookupVarLocally("var_compose"); assertEquals(TypeEntity.buildInType.getRawName(),var.getType().getRawName()); var = function.lookupVarLocally("var_1"); assertEquals(TypeEntity.buildInType.getRawName(),var.getType().getRawName()); var = function.lookupVarLocally("var_2"); assertEquals(TypeEntity.buildInType.getRawName(),var.getType().getRawName()); var = function.lookupVarLocally("var_3"); assertEquals(TypeEntity.buildInType.getRawName(),var.getType().getRawName()); var = function.lookupVarLocally("var_4"); assertEquals(TypeEntity.buildInType.getRawName(),var.getType().getRawName()); var = function.lookupVarLocally("var_5"); assertEquals(TypeEntity.buildInType.getRawName(),var.getType().getRawName()); var = function.lookupVarLocally("var_6"); assertEquals(TypeEntity.buildInType.getRawName(),var.getType().getRawName()); } }
2,834
33.156627
96
java
depends
depends-master/src/test/java/depends/extractor/ruby/RubyInheritTest.java
package depends.extractor.ruby; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import depends.deptypes.DependencyType; import depends.extractor.FileParser; import depends.relations.Relation; public class RubyInheritTest extends RubyParserTest { @Before public void setUp() { super.init(); } @Test public void test_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/extends.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("Cat"), DependencyType.INHERIT, "Animal"); } @Test public void test_relation_of_included_file() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/extends_animal.rb", "./src/test/resources/ruby-code-examples/extends_cat.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("Cat"), DependencyType.INHERIT, "Animal"); } @Ignore public void test_relation_with_cpath_1() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/extends_with_cpath.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); super.assertContainsRelation(entityRepo.getEntity("Cat"), DependencyType.INHERIT, "Animal"); } @Test public void test_relation_with_cpath_2() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/extends_with_cpath.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); super.assertContainsRelation(entityRepo.getEntity("ZooCat"), DependencyType.INHERIT, "Zoo.Animal"); } @Test public void test_relation_with_cpath_3() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/extends_with_cpath.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("Zoo.Cow"), DependencyType.INHERIT, "Zoo.Animal"); } @Ignore public void test_relation_with_alias() throws IOException { String[] srcs = new String[] { "./src/test/resources/ruby-code-examples/extends_with_alias.rb", }; for (String src:srcs) { FileParser parser = createFileParser(); parser.parse(src); } resolveAllBindings(); assertEquals(1,entityRepo.getEntity("Cat").getRelations().size()); Relation r = entityRepo.getEntity("Cat").getRelations().get(0); assertEquals(DependencyType.INHERIT,r.getType()); assertEquals("Zoo.Animal",r.getEntity().getQualifiedName()); } }
3,219
28.541284
104
java
depends
depends-master/src/test/java/depends/extractor/pom/DependencyWithoutVersionTest.java
package depends.extractor.pom; import depends.deptypes.DependencyType; import org.junit.Before; import org.junit.Test; import java.io.IOException; public class DependencyWithoutVersionTest extends MavenParserTest{ @Before public void setUp() { super.init(); } @Test public void should_extract_dep_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/dependencyWithoutVersion/from.pom", "./src/test/resources/maven-code-examples/dependencyWithoutVersion/a-dep-group/a-artifact/0.2/to.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("testgroup.test_1.0_"), DependencyType.PomDependency, "a-dep-group.a-artifact_0.2_"); } @Test public void should_extract_plugin_relation() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/dependencyWithoutVersion/from.pom", "./src/test/resources/maven-code-examples/dependencyWithoutVersion/aplugins/aplugin/0.1/plugin.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); this.assertContainsRelation(entityRepo.getEntity("testgroup.test_1.0_"), DependencyType.PomPlugin, "aplugins.aplugin_0.1_"); } }
1,473
31.755556
139
java
depends
depends-master/src/test/java/depends/extractor/pom/EntityExtractTest.java
package depends.extractor.pom; import org.junit.Before; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class EntityExtractTest extends MavenParserTest{ @Before public void setUp() { super.init(); } @Test public void use_package_contains() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/simple/log4j.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertEquals(0,entityRepo.getEntity("org.log4j-test.log4j_1.2.12_").getRelations().size()); } @Test public void should_use_parent_groupId() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/use_parent_groupId_and_version.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); assertNotNull(entityRepo.getEntity("org.apache.maven.surefire.surefire-junit4_2.12.4_")); } @Test public void should_parse_properties_in_same_pom() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/properties-test1.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); PomArtifactEntity entity = (PomArtifactEntity)(entityRepo.getEntity("properties-test.test_1_")); /* <project.version>1.00</project.version> <activeio-version>3.1.4</activeio-version> <projectName>Apache ActiveMQ</projectName> <siteId>activemq-${project.version}</siteId> */ assertEquals("1.00",entity.getProperty("project.version")); assertEquals("activemq-1.00",entity.getProperty("siteId")); } @Test public void should_parse_multiple_properties_in_same_pom() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/properties-test1.pom", }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); PomArtifactEntity entity = (PomArtifactEntity)(entityRepo.getEntity("properties-test.test_1_")); /* <project.version>1.00</project.version> <activeio-version>3.1.4</activeio-version> <projectName>Apache ActiveMQ</projectName> <anotherId>activemq-${project.version}--${activeio-version}</anotherId> */ assertEquals("activemq-1.00-3.1.4",entity.getProperty("anotherId")); } @Test public void should_parse_multiple_properties_in_parent_pom() throws IOException { String[] srcs = new String[] { "./src/test/resources/maven-code-examples/properties-test-child.pom" }; for (String src:srcs) { PomFileParser parser = createParser(); parser.parse(src); } resolveAllBindings(); PomArtifactEntity entity = (PomArtifactEntity)(entityRepo.getEntity("properties-test.test_1_")); assertEquals("13",entity.getProperty("project.version")); } }
3,294
31.623762
104
java