/*
@see org.springframework.transaction.compensating.support.AbstractCompensatingTransactionManagerDelegate#closeTargetResource(org.springframework.transaction.compensating.support.CompensatingTransactionHolderSupport)
18584
protected void closeTargetResource(
            CompensatingTransactionHolderSupport transactionHolderSupport) {
        DirContextHolder contextHolder = (DirContextHolder) transactionHolderSupport;
        DirContext ctx = contextHolder.getCtx();

        try {
            LOG.debug("Closing target context");
            ctx.close();
        } catch (NamingException e) {
            LOG.warn("Failed to close target context", e);
        }
    }
654387
private static String[] toResources(final Object[] args) {
        val object = args[0];
        if (object instanceof AuthenticationTransaction) {
            val transaction = AuthenticationTransaction.class.cast(object);
            return new String[]{SUPPLIED_CREDENTIALS + transaction.getCredentials()};
        }
        return new String[]{SUPPLIED_CREDENTIALS + CollectionUtils.wrap(object)};
    }
196650
function getAdapter(serviceInfo, resource, moduleStack) {
        var adapterName = serviceInfo.adapterName;

        // if adapter name is 'service' and there is a default, switch to the default
        if (adapterName === 'service' && resource.adapters[this.injector.container]) {
            adapterName = serviceInfo.adapterName = resource.adapters[this.injector.container];
            serviceInfo.adapterImpl = this.injector.adapterMap[adapterName];
            serviceInfo.serviceName = utils.getCamelCase(serviceInfo.resourceName + '.' +
                serviceInfo.adapterName + '.service');
        }

        // if that doesn't work, we will assume the adapter is in the current codebase, so go get it
        var overridePath = '/resources/' + serviceInfo.resourceName + '/' + serviceInfo.resourceName + '.' +
            (adapterName === 'service' ? adapterName : adapterName + '.service');
        var adapterPath = '/adapters/' + adapterName + '/' +
            serviceInfo.adapterImpl + '.' + adapterName + '.adapter';

        // if override exists, use that one, else use the lower level adapter
        var Adapter =
            this.loadIfExists(overridePath, moduleStack, null) ||
            this.injector.adapters[serviceInfo.adapterImpl] ||
            this.loadIfExists(adapterPath, moduleStack, null);

        // if still no adapter found, then there is an issue
        if (!Adapter) {
            throw new Error('ServiceFactory could not find adapter ' + adapterName +
            ' paths ' + overridePath + ' and ' + adapterPath);
        }

        return new Adapter(resource);
    }
736006
protected CmsAccessControlEntry getImportAccessControlEntry(
        CmsResource res,
        String id,
        String allowed,
        String denied,
        String flags) {

        return new CmsAccessControlEntry(
            res.getResourceId(),
            new CmsUUID(id),
            Integer.parseInt(allowed),
            Integer.parseInt(denied),
            Integer.parseInt(flags));
    }
403580
@Override
    public CmsResource getResource(CmsObject cms, CmsListItem item) {

        CmsResource res = null;

        CmsUUID id = new CmsUUID(item.getId());
        if (!id.isNullUUID()) {
            try {
                res = cms.readResource(id, CmsResourceFilter.ALL);
            } catch (CmsException e) {
                // should never happen
                if (LOG.isErrorEnabled()) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }
        }

        return res;
    }
25024
public void onResourceLaunched(final ResourceLaunchEvent resourceLaunchEvent) {
    String id = resourceLaunchEvent.getIdentifier();
    LOG.log(Level.FINEST, "Got ResourceLaunchEvent for Id: {0} in AzureBatchResourceManager", id);
    final int evaluatorMemory = this.containerRequests.get(id).getMemorySize().get();
    String launchCommand = this.launchCommandBuilder.buildEvaluatorCommand(resourceLaunchEvent,
        evaluatorMemory, this.jvmHeapFactor);
    String evaluatorConfigurationString = this.configurationSerializer.toString(resourceLaunchEvent.getEvaluatorConf());
    this.evaluatorShimManager.onResourceLaunched(resourceLaunchEvent, launchCommand, evaluatorConfigurationString);
  }
496246
@Override
    public T addAsWebInfResource(final File resource, final String target) throws IllegalArgumentException {
        Validate.notNull(resource, "Resource should be specified");
        Validate.notNullOrEmpty(target, "Target should be specified");

        return addAsWebInfResource(new FileAsset(resource), target);
    }
201224
public static void rcvXAForget(CommsByteBuffer request, Conversation conversation,
                                  int requestNumber, boolean allocatedFromBufferPool,
                                  boolean partOfExchange)
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "rcvXAForget",
                                           new Object[]
                                           {
                                              request,
                                              conversation,
                                              ""+requestNumber,
                                              ""+allocatedFromBufferPool,
                                              ""+partOfExchange
                                            });

      ConversationState convState = (ConversationState) conversation.getAttachment();
      ServerLinkLevelState linkState = (ServerLinkLevelState) conversation.getLinkLevelAttachment();

      try
      {
         int clientTransactionId = request.getInt();
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
         {
            SibTr.debug(tc, "XAResource Object ID", clientTransactionId);
         }

         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(tc, "Getting Xid");
         XidProxy xid = (XidProxy) request.getXid();
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(tc, "Completed:", xid);

         boolean requiresMSResource = false;
         if (conversation.getHandshakeProperties().getFapLevel() >= JFapChannelConstants.FAP_VERSION_5)
         {
            requiresMSResource = request.get() == 0x01;
         }

         // Get the transaction out of the table
         SITransaction tran = linkState.getTransactionTable().getResourceForGlobalTransactionBranch(clientTransactionId, xid);

         if (tran == IdToTransactionTable.INVALID_TRANSACTION)
         {
            // If the UOW was never created (because we were running with the
            // optimization that gets an XAResource and enlists it as part of the
            // first piece of transacted work and this failed) then simply
            // remove any reference of the UOW from out table.
            linkState.getTransactionTable().removeGlobalTransactionBranch(clientTransactionId, xid);
         }
         else
         {
            // Get the actual transaction ...
            SIXAResource xaResource = getResourceFromTran(tran, convState, requiresMSResource);

            // Now call the method on the XA resource
            xaResource.forget(xid);

            // If the transaction was in the in-flight table - remove it.
            if (tran != null)
            {
               linkState.getTransactionTable().removeGlobalTransactionBranch(clientTransactionId, xid);
            }
         }

         try
         {
            conversation.send(poolManager.allocate(),
                              JFapChannelConstants.SEG_XAFORGET_R,
                              requestNumber,
                              JFapChannelConstants.PRIORITY_MEDIUM,
                              true,
                              ThrottlingPolicy.BLOCK_THREAD,
                              null);
         }
         catch (SIException e)
         {
            FFDCFilter.processException(e,
                                        CLASS_NAME + ".rcvXAForget",
                                        CommsConstants.STATICCATXATRANSACTION_XAFORGET_01);

            SibTr.error(tc, "COMMUNICATION_ERROR_SICO2027", e);
         }
      }
      catch (XAException e)
      {
         FFDCFilter.processException(e,
                                     CLASS_NAME + ".rcvXAForget",
                                     CommsConstants.STATICCATXATRANSACTION_XAFORGET_02);

         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(tc, "XAException - RC: " + e.errorCode, e);

         StaticCATHelper.sendExceptionToClient(e,
                                               CommsConstants.STATICCATXATRANSACTION_XAFORGET_02,
                                               conversation, requestNumber);
      }

      request.release(allocatedFromBufferPool);

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "rcvXAForget");
   }
680456
@Override
    public T addAsWebInfResource(final Asset resource, final ArchivePath target) throws IllegalArgumentException {
        Validate.notNull(resource, "Resource should be specified");
        Validate.notNull(target, "Target should be specified");

        final ArchivePath location = new BasicPath(getWebInfPath(), target);
        return add(resource, location);
    }
1237188
public BeanDefinitionHolder decorate(Node source,
                                         BeanDefinitionHolder holder,
                                         ParserContext context) {

        boolean enabled = getBooleanAttributeValue(source);
        if (enabled) {
            registerProxyCreator(source, holder, context);
        }

        return holder;
    }
830517
protected RRSGlobalTransactionWrapper getRRSGlobalTransactionWrapper() throws ResourceException {

        final boolean isTracingEnabled = TraceComponent.isAnyTracingEnabled();

        if (isTracingEnabled && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "getRRSGlobalTransactionWrapper");
        }

        if (rrsGlobalTranWrapper == null) {
            rrsGlobalTranWrapper = new RRSGlobalTransactionWrapper(this);
        }

        if (state == STATE_ACTIVE_INUSE) {
            state = STATE_TRAN_WRAPPER_INUSE;
            tranWrapperInUse = RRSGLOBALTXWRAPPER;
        } else { // state not STATE_ACTIVE_INUSE

            if (state != STATE_TRAN_WRAPPER_INUSE) {
                IllegalStateException e = new IllegalStateException("getRRSGlobalTransactionWrapper: illegal state exception. State = " + getStateString() + " MCW = "
                                                                    + mcWrapperObject_hexString);
                Object[] parms = new Object[] { "getRRSGlobalTransactionWrapper", e };
                Tr.error(tc, "ILLEGAL_STATE_EXCEPTION_J2CA0079", parms);
                throw e;
            } else { // state is STATE_TRAN_WRAPPER_INUSE
                if (tranWrapperInUse == NONE) {
                    tranWrapperInUse = RRSGLOBALTXWRAPPER;
                } else { //tranWrapperInUse is NOT NONE
                    if (tranWrapperInUse != RRSGLOBALTXWRAPPER) {
                        // Need RAS and Trace here.
                        IllegalStateException e = new IllegalStateException("getRRSGlobalTransactionWrapper: illegal transaction state exception. State = "
                                                                            + getTranWrapperString());
                        Object[] parms = new Object[] { "getRRSGlobalTransactionWrapper", e };
                        Tr.error(tc, "ILLEGAL_STATE_EXCEPTION_J2CA0079", parms);
                        throw e;
                    }
                }
            }

        }

        if (isTracingEnabled && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "getRRSGlobalTransactionWrapper");
        }

        return rrsGlobalTranWrapper;

    }
250302
final void delistRRSXAResource(XAResource xaResource) throws Exception {
        RRSXAResourceFactory xaFactory = (RRSXAResourceFactory) pm.connectorSvc.rrsXAResFactorySvcRef.getService();

        // Make sure that the bundle is active.
        if (xaFactory == null) {
            throw new IllegalStateException("Native service for RRS transactional support is not active or available. Resource delistment is rejected.");
        }

        UOWCurrent currentUOW = (UOWCurrent) pm.connectorSvc.transactionManager;
        UOWCoordinator uowCoord = currentUOW.getUOWCoord();

        // If delisting for cleanup, notify the factory that the resource has been
        // delisted for cleanup with the transaction manager.
        if (!uowCoord.isGlobal()) {
            LocalTransactionCoordinator ltCoord = (LocalTransactionCoordinator) uowCoord;
            if (!ltCoord.isContainerResolved()) {
                ltCoord.delistFromCleanup((OnePhaseXAResource) xaResource);
                xaFactory.delist(uowCoord, xaResource);
            }
        }
    }
1213085
protected SITransaction getTransaction() throws ResourceException
    {
        final String methodName = "getTransaction";
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled())
        {
            SibTr.entry(this, TRACE, methodName);
        }

        final SITransaction transaction = getXaResource();

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled())
        {
            SibTr.exit(this, TRACE, methodName, transaction);
        }
        return transaction;
    }
133950
public CompensatingTransactionOperationExecutor recordOperation(
            Object[] args) {
        Assert.notNull(args);
        Name dn = LdapTransactionUtils.getFirstArgumentAsName(args);
        if (args.length != 2 || !(args[1] instanceof ModificationItem[])) {
            throw new IllegalArgumentException(
                    "Unexpected arguments to ModifyAttributes operation");
        }

        ModificationItem[] incomingModifications = (ModificationItem[]) args[1];

        Set<String> set = new HashSet<String>();
        for (ModificationItem incomingModification : incomingModifications) {
            set.add(incomingModification.getAttribute().getID());
        }

        // Get the current values of all referred Attributes.
        String[] attributeNameArray = set.toArray(new String[set.size()]);

        // LDAP-234: We need to explicitly an IncrementalAttributesMapper in
        // case we're working against AD and there are too many attribute values to be returned
        // by one query.
        IncrementalAttributesMapper<?> attributesMapper = getAttributesMapper(attributeNameArray);
        while (attributesMapper.hasMore()) {
            ldapOperations.lookup(dn, attributesMapper.getAttributesForLookup(), attributesMapper);
        }

        Attributes currentAttributes = attributesMapper.getCollectedAttributes();

        // Get a compensating ModificationItem for each of the incoming
        // modification.
        ModificationItem[] rollbackItems = new ModificationItem[incomingModifications.length];
        for (int i = 0; i < incomingModifications.length; i++) {
            rollbackItems[i] = getCompensatingModificationItem(
                    currentAttributes, incomingModifications[i]);
        }

        return new ModifyAttributesOperationExecutor(ldapOperations, dn,
                incomingModifications, rollbackItems);
    }
1333747
@Override
    public T addAsApplicationResources(Package resourcePackage, String... resourceNames)
        throws IllegalArgumentException {
        Validate.notNull(resourcePackage, "ResourcePackage must be specified");
        Validate.notNullAndNoNullValues(resourceNames,
            "ResourceNames must be specified and can not container null values");
        for (String resourceName : resourceNames) {
            addAsApplicationResource(resourcePackage, resourceName);
        }
        return covarientReturn();
    }
1108103
@Override
	public boolean getIfNewer(String resourceName, File destination,
			long timestamp) throws TransferFailedException,
			ResourceDoesNotExistException, AuthorizationException {
		throw new UnsupportedOperationException( "Not currently supported: getIfNewer" );
	}
881302
public DatabaseAccessConfiguration swap(final DataSource dataSource) {
        DataSourcePropertyProvider provider = DataSourcePropertyProviderLoader.getProvider(dataSource);
        try {
            String url = (String) findGetterMethod(dataSource, provider.getURLPropertyName()).invoke(dataSource);
            String username = (String) findGetterMethod(dataSource, provider.getUsernamePropertyName()).invoke(dataSource);
            String password = (String) findGetterMethod(dataSource, provider.getPasswordPropertyName()).invoke(dataSource);
            return new DatabaseAccessConfiguration(url, username, password);
        } catch (final ReflectiveOperationException ex) {
            throw new ShardingException("Cannot swap data source type: `%s`, please provide an implementation from SPI `%s`", 
                    dataSource.getClass().getName(), DataSourcePropertyProvider.class.getName());
        }
    }