Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.Map;
 
 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_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.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.CLASS_NAME;
 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.JNDINAME;
 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.RECOVERLUGIN_CLASSNAME;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.RECOVERLUGIN_PROPERTIES;
 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.USE_CCM;
 import static org.jboss.as.connector.subsystems.resourceadapters.Constants.USE_JAVA_CONTEXT;
 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;

Handler for exposing transaction logs

Author(s):
Stefano Maestri (c) 2011 Red Hat Inc.
Mike Musgrove (c) 2012 Red Hat Inc.
 
 public class IronJacamarResourceCreator {
 
     public static final IronJacamarResourceCreator INSTANCE = new IronJacamarResourceCreator();
 
 
     private void setAttribute(ModelNode modelSimpleAttributeDefinition nodeString value) {
         if (value != null) {
            model.get(node.getName()).set(value);
        }
    }
    private void setAttribute(ModelNode modelSimpleAttributeDefinition nodeBoolean value) {
        if (value != null) {
            model.get(node.getName()).set(value);
        }
    }
    private void setAttribute(ModelNode modelSimpleAttributeDefinition nodeInteger value) {
        if (value != null) {
            model.get(node.getName()).set(value);
        }
    }
    private void setAttribute(ModelNode modelSimpleAttributeDefinition nodeLong value) {
        if (value != null) {
            model.get(node.getName()).set(value);
        }
    }
    private void addConfigProperties(final Resource parentString nameString value) {
        final Resource config = new IronJacamarResource.IronJacamarRuntimeResource();
        final ModelNode model = config.getModel();
        model.get(..getName()).set(value);
        final PathElement element = PathElement.pathElement(..getName(), name);
        parent.registerChild(elementconfig);
    }
    private void addConnectionDefinition(final Resource parentorg.jboss.jca.common.api.metadata.common.CommonConnDef connDef) {
        final Resource connDefResource = new IronJacamarResource.IronJacamarRuntimeResource();
        final ModelNode model = connDefResource.getModel();
        setAttribute(model.connDef.getJndiName());
        if (connDef.getConfigProperties() != null) {
            for (Map.Entry<StringStringconfig : connDef.getConfigProperties().entrySet()) {
                addConfigProperties(connDefResourceconfig.getKey(), config.getValue());
            }
        }
        setAttribute(modelconnDef.getClassName());
        setAttribute(modelconnDef.getJndiName());
        setAttribute(modelconnDef.isUseJavaContext());
        setAttribute(modelconnDef.isEnabled());
        setAttribute(modelconnDef.isUseCcm());
        if (connDef instanceof org.jboss.jca.common.api.metadata.common.v11.CommonConnDef) {
            setAttribute(model, ((org.jboss.jca.common.api.metadata.common.v11.CommonConnDefconnDef).isSharable());
            setAttribute(model, ((org.jboss.jca.common.api.metadata.common.v11.CommonConnDefconnDef).isEnlistment());
        }
        final CommonPool pool = connDef.getPool();
        if (pool != null) {
            setAttribute(modelpool.getMaxPoolSize());
            setAttribute(modelpool.getMinPoolSize());
            if (pool instanceof ConnDefPool) {
                setAttribute(model, ((ConnDefPoolpool).getInitialPoolSize());
                if (((ConnDefPoolpool).getCapacity() != null) {
                    if (((ConnDefPoolpool).getCapacity().getIncrementer() != null) {
                        setAttribute(model, ((ConnDefPoolpool).getCapacity().getIncrementer().getClassName());
                        if (((ConnDefPoolpool).getCapacity().getIncrementer().getConfigPropertiesMap() != null) {
                            for (Map.Entry<StringStringconfig : ((ConnDefPoolpool).getCapacity().getIncrementer().getConfigPropertiesMap().entrySet()) {
                                model.get(.getName(), config.getKey()).set(config.getValue());
                            }
                        }
                    }
                    if (((ConnDefPoolpool).getCapacity().getDecrementer() != null) {
                        setAttribute(model, ((ConnDefPoolpool).getCapacity().getDecrementer().getClassName());
                        if (((ConnDefPoolpool).getCapacity().getDecrementer().getConfigPropertiesMap() != null) {
                            for (Map.Entry<StringStringconfig : ((ConnDefPoolpool).getCapacity().getDecrementer().getConfigPropertiesMap().entrySet()) {
                                model.get(.getName(), config.getKey()).set(config.getValue());
                            }
                        }
                    }
                }
            }
            setAttribute(modelpool.isUseStrictMin());
            if (pool.getFlushStrategy() != null)
                setAttribute(modelpool.getFlushStrategy().name());
            setAttribute(modelpool.isPrefill());
            if (connDef.isXa()) {
                assert connDef.getPool() instanceof CommonXaPool;
                CommonXaPool xaPool = (CommonXaPoolconnDef.getPool();
                setAttribute(modelxaPool.isWrapXaResource());
                setAttribute(modelxaPool.isSameRmOverride());
                setAttribute(modelxaPool.isPadXid());
                setAttribute(modelxaPool.isInterleaving());
                setAttribute(modelxaPool.isNoTxSeparatePool());
            }
        }
        final CommonSecurity security = connDef.getSecurity();
        if (security != null) {
            setAttribute(modelsecurity.isApplication());
            setAttribute(modelsecurity.getSecurityDomain());
        }
        final CommonTimeOut timeOut = connDef.getTimeOut();
        if (timeOut != null) {
            setAttribute(modeltimeOut.getAllocationRetry());
            setAttribute(modeltimeOut.getAllocationRetryWaitMillis());
            setAttribute(modeltimeOut.getBlockingTimeoutMillis());
            setAttribute(modeltimeOut.getIdleTimeoutMinutes());
            setAttribute(modeltimeOut.getXaResourceTimeout());
        }
        final CommonValidation validation = connDef.getValidation();
        if (validation != null) {
            setAttribute(modelvalidation.getBackgroundValidationMillis());
            setAttribute(modelvalidation.isBackgroundValidation());
            setAttribute(modelvalidation.isUseFastFail());
        }
        final Recovery recovery = connDef.getRecovery();
        if (recovery != null) {
            setAttribute(modelrecovery.getNoRecovery());
            final Extension recoverPlugin = recovery.getRecoverPlugin();
            if (recoverPlugin != null) {
                setAttribute(modelrecoverPlugin.getClassName());
                if (recoverPlugin.getConfigPropertiesMap() != null) {
                    for (Map.Entry<StringStringconfig : recoverPlugin.getConfigPropertiesMap().entrySet()) {
                        model.get(.getName(), config.getKey()).set(config.getValue());
                    }
                }
            }
            final Credential recoveryCredential = recovery.getCredential();
            if (recoveryCredential != null) {
                setAttribute(modelrecoveryCredential.getPassword());
                setAttribute(modelrecoveryCredential.getSecurityDomain());
                setAttribute(modelrecoveryCredential.getUserName());
            }
        }
        final PathElement element = PathElement.pathElement(.connDef.getJndiName());
        parent.registerChild(elementconnDefResource);
    }
    private void addAdminObject(final Resource parentCommonAdminObject adminObject) {
        final Resource adminObjectResource = new IronJacamarResource.IronJacamarRuntimeResource();
        final ModelNode model = adminObjectResource.getModel();
        setAttribute(modeladminObject.getClassName());
        setAttribute(modeladminObject.getJndiName());
        setAttribute(modeladminObject.isUseJavaContext());
        setAttribute(modeladminObject.isEnabled());
        if (adminObject.getConfigProperties() != null) {
            for (Map.Entry<StringStringconfig : adminObject.getConfigProperties().entrySet()) {
                addConfigProperties(adminObjectResourceconfig.getKey(), config.getValue());
            }
        }
        final PathElement element = PathElement.pathElement(.adminObject.getJndiName());
        parent.registerChild(elementadminObjectResource);
    }
    private void addResourceAdapter(final Resource parentString nameIronJacamar ironJacamarMetadata) {
        final Resource ijResourceAdapter = new IronJacamarResource.IronJacamarRuntimeResource();
        final ModelNode model = ijResourceAdapter.getModel();
        model.get(..getName()).set(name);
        setAttribute(model.ironJacamarMetadata.getBootstrapContext());
        if (ironJacamarMetadata.getTransactionSupport() != null)
            model.get(..getName()).set(ironJacamarMetadata.getTransactionSupport().name());
        if (ironJacamarMetadata instanceof org.jboss.jca.common.api.metadata.ironjacamar.v11.IronJacamar) {
            org.jboss.jca.common.api.metadata.ironjacamar.v11.IronJacamar ij11 = (org.jboss.jca.common.api.metadata.ironjacamar.v11.IronJacamarironJacamarMetadata;
            if (ij11.getWorkManager() != null && ij11.getWorkManager().getSecurity() != null) {
                WorkManagerSecurity security = ij11.getWorkManager().getSecurity();
                model.get(..getName()).set(true);
                if (security.getDefaultGroups() != null) {
                    for (String group : security.getDefaultGroups()) {
                        model.get(..getName()).add(group);
                    }
                }
                if (security.getDefaultPrincipal() != null)
                    model.get(..getName()).set(security.getDefaultPrincipal());
                model.get(..getName()).set(security.isMappingRequired());
                model.get(..getName()).set(security.getDomain());
                if (security.getGroupMappings() != null) {
                    for (Map.Entry<StringStringentry : security.getGroupMappings().entrySet()) {
                        final Resource mapping = new IronJacamarResource.IronJacamarRuntimeResource();
                        final ModelNode subModel = mapping.getModel();
                        subModel.get(..getName()).set(entry.getKey());
                        subModel.get(..getName()).set(entry.getKey());
                        final PathElement element = PathElement.pathElement(..getName(), .getName());
                        ijResourceAdapter.registerChild(elementmapping);
                    }
                }
                if (security.getUserMappings() != null) {
                    for (Map.Entry<StringStringentry : security.getUserMappings().entrySet()) {
                        final Resource mapping = new IronJacamarResource.IronJacamarRuntimeResource();
                        final ModelNode subModel = mapping.getModel();
                        subModel.get(..getName()).set(entry.getKey());
                        subModel.get(..getName()).set(entry.getKey());
                        final PathElement element = PathElement.pathElement(..getName(), .getName());
                        ijResourceAdapter.registerChild(elementmapping);
                    }
                }
            }
        }
        if (ironJacamarMetadata.getBeanValidationGroups() != null) {
            for (String bv : ironJacamarMetadata.getBeanValidationGroups()) {
                model.get(..getName()).add(new ModelNode().set(bv));
            }
        }
        if (ironJacamarMetadata.getConfigProperties() != null) {
            for (Map.Entry<StringStringconfig : ironJacamarMetadata.getConfigProperties().entrySet()) {
                addConfigProperties(ijResourceAdapterconfig.getKey(), config.getValue());
            }
        }
        if (ironJacamarMetadata.getConnectionDefinitions() != null) {
            for (org.jboss.jca.common.api.metadata.common.CommonConnDef connDef : ironJacamarMetadata.getConnectionDefinitions()) {
                addConnectionDefinition(ijResourceAdapterconnDef);
            }
        }
        if (ironJacamarMetadata.getAdminObjects() != null) {
            for (CommonAdminObject adminObject : ironJacamarMetadata.getAdminObjects()) {
                addAdminObject(ijResourceAdapteradminObject);
            }
        }
        final PathElement element = PathElement.pathElement(.name);
        parent.registerChild(elementijResourceAdapter);
    }
        final Resource resource = Resource.Factory.create();
        for (String name : mdr.getResourceAdaptersWithIronJacamarMetadata()) {
            addResourceAdapter(resourcenamemdr.getIronJcamarMetaData(name));
        }
        return resource;
    }
    public void execute(Resource parentResourceAS7MetadataRepository mdr) {
        // Get the iron-jacamar resource
        final IronJacamarResource ironJacamarResource = new IronJacamarResource();
        // Replace the current model with an updated one
        final Resource storeModel = getIronJacamarResource(mdr);
        ironJacamarResource.update(storeModel);
        if (parentResource.getChild(ijPe) == null) {
            parentResource.registerChild(ijPeironJacamarResource);
        }
    }
New to GrepCode? Check out our FAQ X