Example usage for org.apache.commons.lang BooleanUtils toBoolean

List of usage examples for org.apache.commons.lang BooleanUtils toBoolean

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils toBoolean.

Prototype

public static boolean toBoolean(String str) 

Source Link

Document

Converts a String to a boolean (optimised for performance).

'true', 'on' or 'yes' (case insensitive) will return true.

Usage

From source file:org.mule.config.DefaultMuleConfiguration.java

/**
 * Apply any settings which come from the JVM system properties.
 *//*from   w  ww .  ja  v  a 2  s.  com*/
protected void applySystemProperties() {
    String p;

    p = System.getProperty(MuleProperties.MULE_ENCODING_SYSTEM_PROPERTY);
    if (p != null) {
        encoding = p;
    } else {
        System.setProperty(MuleProperties.MULE_ENCODING_SYSTEM_PROPERTY, encoding);
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "endpoints.synchronous");
    if (p != null) {
        synchronous = BooleanUtils.toBoolean(p);
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "systemModelType");
    if (p != null) {
        systemModelType = p;
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "timeout.synchronous");
    if (p != null) {
        responseTimeout = NumberUtils.toInt(p);
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "timeout.transaction");
    if (p != null) {
        defaultTransactionTimeout = NumberUtils.toInt(p);
    }

    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "workingDirectory");
    if (p != null) {
        workingDirectory = p;
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "clientMode");
    if (p != null) {
        clientMode = BooleanUtils.toBoolean(p);
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "serverId");
    if (p != null) {
        id = p;
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "domainId");
    if (p != null) {
        domainId = p;
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "message.cacheBytes");
    if (p != null) {
        cacheMessageAsBytes = BooleanUtils.toBoolean(p);
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "message.cacheOriginal");
    if (p != null) {
        cacheMessageOriginalPayload = BooleanUtils.toBoolean(p);
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "streaming.enable");
    if (p != null) {
        enableStreaming = BooleanUtils.toBoolean(p);
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "transform.autoWrap");
    if (p != null) {
        autoWrapMessageAwareTransform = BooleanUtils.toBoolean(p);
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "stacktrace.full");
    if (p != null) {
        fullStackTraces = false;
    }
    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "stacktrace.filter");
    if (p != null) {
        stackTraceFilter = p.split(",");
    }

    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "verbose.exceptions");
    if (p != null) {
        verboseExceptions = BooleanUtils.toBoolean(p);
    } else {
        verboseExceptions = logger.isDebugEnabled();
    }

    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "validate.expressions");
    if (p != null) {
        validateExpressions = Boolean.valueOf(p);
    }

    p = System.getProperty(MuleProperties.SYSTEM_PROPERTY_PREFIX + "timeout.disable");
    if (p != null) {
        disableTimeouts = Boolean.valueOf(p);
    }
}

From source file:org.mule.ibeans.internal.IBeansMethodHeaderPropertyEntryPointResolver.java

public InvocationResult invoke(Object component, MuleEventContext context) throws Exception {
    // Transports such as SOAP need to ignore the method property
    boolean ignoreMethod = BooleanUtils.toBoolean(
            context.getMessage().<Boolean>getInboundProperty(MuleProperties.MULE_IGNORE_METHOD_PROPERTY));

    if (ignoreMethod) {
        //TODO: Removed once we have property scoping
        InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED);
        result.setErrorMessage("Property: " + MuleProperties.MULE_IGNORE_METHOD_PROPERTY
                + " was set so skipping this resolver");
        return result;
    }// www . ja  v  a 2 s.  c  o  m

    // MULE-4874: this is needed in order to execute the transformers before determining the methodProp
    Object[] payload = getPayloadFromMessage(context);

    //TODO MULE-4953 I don't think the VM transport if managing invocation properties correctly, or maybe it is and this
    //is valid
    //Here I have to remove the 'method' property rather than just read it
    Object methodProp = context.getMessage().removeProperty(getMethodProperty(), PropertyScope.INVOCATION);
    if (methodProp == null) {
        methodProp = context.getMessage().getInboundProperty(getMethodProperty());
    }
    if (methodProp == null) {
        InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
        // no method for the explicit method header
        result.setErrorMessage(CoreMessages.propertyIsNotSetOnEvent(getMethodProperty()).toString());
        return result;
    }

    Method method;
    String methodName;
    if (methodProp instanceof Method) {
        method = (Method) methodProp;
        methodName = method.getName();
    } else {
        methodName = methodProp.toString();
        method = getMethodByName(component, methodName, context);
    }

    if (method != null && method.getParameterTypes().length == 0) {
        return invokeMethod(component, method, ClassUtils.NO_ARGS_TYPE);
    }

    if (method == null) {
        Class<?>[] classTypes = ClassUtils.getClassTypes(payload);

        method = ClassUtils.getMethod(component.getClass(), methodName, classTypes);

        if (method == null) {
            for (Method m : component.getClass().getMethods()) {
                if (m.getName().equals(methodName)) {
                    method = m;
                    break;
                }
            }
            if (method != null && method.getParameterTypes().length == 1) {
                List<Transformer> t = context.getMuleContext().getRegistry().lookupTransformers(
                        context.getMessage().getPayload().getClass(), method.getParameterTypes()[0]);
                if (t.size() == 1) {
                    Object result = t.get(0).transform(context.getMessage());
                    if (result.getClass().isArray()) {
                        payload = (Object[]) result;
                    } else {
                        payload = new Object[] { result };
                    }
                    return invokeMethod(component, method, payload);
                } else {
                    InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
                    result.setErrorNoMatchingMethods(component, classTypes);
                    return result;
                }
            } else {
                InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
                result.setErrorNoMatchingMethods(component, classTypes);
                return result;
            }
        }

    }

    validateMethod(component, method);
    addMethodByName(component, method, context);

    return invokeMethod(component, method, payload);
}

From source file:org.mule.model.resolvers.MethodHeaderPropertyEntryPointResolver.java

public InvocationResult invoke(Object component, MuleEventContext context) throws Exception {
    // Transports such as SOAP need to ignore the method property
    boolean ignoreMethod = BooleanUtils.toBoolean(
            context.getMessage().<Boolean>getInboundProperty(MuleProperties.MULE_IGNORE_METHOD_PROPERTY));

    if (ignoreMethod) {
        //TODO: Removed once we have property scoping
        InvocationResult result = new InvocationResult(this, InvocationResult.State.NOT_SUPPORTED);
        result.setErrorMessage("Property: " + MuleProperties.MULE_IGNORE_METHOD_PROPERTY
                + " was set so skipping this resolver");
        return result;
    }// ww w  .  j  av  a  2s.co m

    // MULE-4874: this is needed in order to execute the transformers before determining the methodProp
    Object[] payload = getPayloadFromMessage(context);

    //TODO MULE-4953 I don't think the VM transport if managing invocation properties correctly, or maybe it is and this
    //is valid
    //Here I have to remove the 'method' property rather than just read it
    Object methodProp = context.getMessage().removeProperty(getMethodProperty(), PropertyScope.INVOCATION);
    if (methodProp == null) {
        methodProp = context.getMessage().getInboundProperty(getMethodProperty());
    }
    if (methodProp == null) {
        InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
        // no method for the explicit method header
        result.setErrorMessage(CoreMessages.propertyIsNotSetOnEvent(getMethodProperty()).toString());
        return result;
    }

    Method method;
    String methodName;
    if (methodProp instanceof Method) {
        method = (Method) methodProp;
        methodName = method.getName();
    } else {
        methodName = methodProp.toString();
        method = getMethodByName(component, methodName, context);
    }

    if (method != null && method.getParameterTypes().length == 0) {
        return invokeMethod(component, method, ClassUtils.NO_ARGS_TYPE);
    }

    if (method == null) {
        Class<?>[] classTypes = ClassUtils.getClassTypes(payload);

        method = ClassUtils.getMethod(component.getClass(), methodName, classTypes);

        if (method == null) {
            InvocationResult result = new InvocationResult(this, InvocationResult.State.FAILED);
            result.setErrorNoMatchingMethods(component, classTypes);
            return result;
        }

    }

    validateMethod(component, method);
    addMethodByName(component, method, context);

    return invokeMethod(component, method, payload);
}

From source file:org.mule.module.launcher.descriptor.PropertiesDescriptorParser.java

public ApplicationDescriptor parse(File descriptor) throws IOException {
    final Properties p = PropertiesUtils.loadProperties(new FileInputStream(descriptor));

    ApplicationDescriptor d = new ApplicationDescriptor();
    d.setEncoding(p.getProperty(PROPERTY_ENCODING));
    d.setConfigurationBuilder(p.getProperty(PROPERTY_CONFIG_BUILDER));
    d.setDomain(p.getProperty(PROPERTY_DOMAIN));
    d.setPackagesToScan(p.getProperty(PROPERTY_SCAN_PACKAGES));

    final String resProps = p.getProperty(PROPERTY_CONFIG_RESOURCES);
    String[] urls;/* w ww.j av  a  2 s. c  o m*/
    if (StringUtils.isBlank(resProps)) {
        urls = new String[] { ApplicationDescriptor.DEFAULT_CONFIGURATION_RESOURCE };
    } else {
        urls = resProps.split(",");
    }
    d.setConfigResources(urls);

    // supports true (case insensitive), yes, on as positive values
    d.setRedeploymentEnabled(
            BooleanUtils.toBoolean(p.getProperty(PROPERTY_REDEPLOYMENT_ENABLED, Boolean.TRUE.toString())));

    final String overrideString = p.getProperty(PROPERTY_LOADER_OVERRIDE);
    if (StringUtils.isNotBlank(overrideString)) {
        Set<String> values = new HashSet<String>();
        final String[] overrides = overrideString.split(",");
        Collections.addAll(values, overrides);
        d.setLoaderOverride(values);
    }

    return d;
}

From source file:org.mule.module.magento.api.AbstractMagentoClient.java

protected static boolean fromIntegerString(String value) {
    return BooleanUtils.toBoolean(Integer.parseInt(value));
}

From source file:org.mule.module.magento.api.order.AxisMagentoOrderClient.java

public void unholdOrder(@NotNull String orderId) throws RemoteException {
    Validate.notNull(orderId);// w ww .  j av a  2s .c om
    BooleanUtils.toBoolean(getPort().salesOrderUnhold(getSessionId(), orderId));
}

From source file:org.mule.modules.slack.SlackConnector.java

/**
 * This processor posts a message to a channel.
 * <p/>/* w ww .  ja  v a  2  s  .c  om*/
 * {@sample.xml ../../../doc/slack-connector.xml.sample
 * slack:post-message}
 *
 * @param message   Message to post
 * @param channelId ID of the channel to post the message
 * @param username  Name to show in the message
 * @param iconURL   Icon URL of the icon to show in the message
 * @param asUser    Boolean indicating if the message is showed as a User or as a Bot
 * @return MessageResponse
 */
@OAuthProtected
@Processor(friendlyName = "Chat - Post message")
@MetaDataScope(AllChannelCategory.class)
public MessageResponse postMessage(String message,
        @FriendlyName("Channel ID") @MetaDataKeyParam String channelId,
        @Optional @FriendlyName("Name to show") String username,
        @Optional @FriendlyName("Icon URL") String iconURL, @Optional Boolean asUser) {
    return slack().sendMessage(message, channelId, username, iconURL, BooleanUtils.toBoolean(asUser));
}

From source file:org.mule.modules.slack.SlackConnector.java

/**
 * /**//from   w w  w. java2s.co  m
 * This processor post a message with attachments in a channel.
 * <p/>
 * {@sample.xml ../../../doc/slack-connector.xml.sample
 * slack:post-message-with-attachment}
 *
 * @param message            Message to post
 * @param channelId          ID of the channel to post the message
 * @param username           Name to show in the message
 * @param iconURL            Icon URL of the icon to show in the message
 * @param chatAttachmentList List of attachments to be sent in the message
 * @param asUser             Boolean indicating if the message is showed as a User or as a Bot
 * @return MessageResponse
 */
@OAuthProtected
@Processor(friendlyName = "Chat - Post message with attachment")
@MetaDataScope(AllChannelCategory.class)
public MessageResponse postMessageWithAttachment(@Optional String message,
        @FriendlyName("Channel ID") @MetaDataKeyParam String channelId,
        @Optional @FriendlyName("Name to show") String username,
        @Optional @FriendlyName("Icon URL") String iconURL,
        @FriendlyName("Attachment List") @Default("#[payload]") List<ChatAttachment> chatAttachmentList,
        @Optional Boolean asUser) {
    return slack().sendMessageWithAttachment(message, channelId, username, iconURL, chatAttachmentList,
            BooleanUtils.toBoolean(asUser));
}

From source file:org.mule.routing.requestreply.AbstractReplyToPropertyRequestReplyReplier.java

@Override
public MuleEvent process(MuleEvent event) throws MuleException {
    MuleEvent resultEvent;//from w  w  w. ja v a  2s.c om
    if (shouldProcessEvent(event)) {
        Object replyTo = event.getReplyToDestination();
        ReplyToHandler replyToHandler = event.getReplyToHandler();

        resultEvent = processNext(event);

        // Allow components to stop processing of the ReplyTo property (e.g. CXF)
        final String replyToStop = resultEvent.getMessage()
                .getInvocationProperty(MuleProperties.MULE_REPLY_TO_STOP_PROPERTY);
        if (resultEvent != null && !VoidMuleEvent.getInstance().equals(resultEvent)
                && !BooleanUtils.toBoolean(replyToStop)) {
            // reply-to processing should not resurrect a dead event
            processReplyTo(event, resultEvent, replyToHandler, replyTo);
        }
    } else {
        resultEvent = processNext(event);
    }
    return resultEvent;
}

From source file:org.mule.service.processor.ServiceInternalMessageProcessor.java

/**
 * We do all this together here rather than chaining them in order to conserve
 * 2.x exception handling behaviour/*www .j av a2 s .  co  m*/
 */
public MuleEvent process(MuleEvent event) throws MuleException {
    MuleEvent resultEvent;
    try {

        resultEvent = service.getComponent().process(event);
        resultEvent = processNext(resultEvent);

        if (!event.getExchangePattern().hasResponse()) {

            Object replyTo = event.getReplyToDestination();
            ReplyToHandler replyToHandler = event.getReplyToHandler();

            // Allow components to stop processing of the ReplyTo property (e.g.
            // CXF)
            if (resultEvent != null && !VoidMuleEvent.getInstance().equals(resultEvent) && replyTo != null) {
                String replyToStop = resultEvent.getMessage()
                        .getInvocationProperty(MuleProperties.MULE_REPLY_TO_STOP_PROPERTY);
                if (!event.getExchangePattern().hasResponse() || !BooleanUtils.toBoolean(replyToStop)) {
                    processReplyTo(event, resultEvent, replyToHandler, replyTo);
                }
            }
        }
        return resultEvent;
    } catch (Exception e) {
        event.getSession().setValid(false);
        if (e instanceof MuleException) {
            throw (MuleException) e;
        } else {
            throw new MessagingException(event, e, this);
        }
    }
}