microsoft.exchange.webservices.data.core
Class EwsUtilities

java.lang.Object
  extended by microsoft.exchange.webservices.data.core.EwsUtilities

public final class EwsUtilities
extends Object

EWS utilities.


Field Summary
static String AutodiscoverSoapNamespace
          The Constant AutodiscoverSoapNamespace.
static String AutodiscoverSoapNamespacePrefix
          The Constant AutodiscoverSoapNamespacePrefix.
static String DomainRegex
          Regular expression for legal domain names.
static LazyMember<Map<Class<?>,Map<String,String>>> ENUM_TO_SCHEMA_DICTIONARIES
          Dictionary of enum type to enum-value-to-schema-name maps.
static String EwsErrorsNamespace
          The Constant EwsErrorsNamespace.
static String EwsErrorsNamespacePrefix
          The Constant EwsErrorsNamespacePrefix.
static String EwsMessagesNamespace
          The Constant EwsMessagesNamespace.
static String EwsMessagesNamespacePrefix
          The Constant EwsMessagesNamespacePrefix.
static String EwsSoap12Namespace
          The Constant EwsSoap12Namespace.
static String EwsSoapNamespace
          The Constant EwsSoapNamespace.
static String EwsSoapNamespacePrefix
          The Constant EwsSoapNamespacePrefix.
static String EwsTypesNamespace
          The Constant EwsTypesNamespace.
static String EwsTypesNamespacePrefix
          The Constant EwsTypesNamespacePrefix.
static String EwsXmlSchemaInstanceNamespace
          The Constant EwsXmlSchemaInstanceNamespace.
static String EwsXmlSchemaInstanceNamespacePrefix
          The Constant EwsXmlSchemaInstanceNamespacePrefix.
static String PassportSoapFaultNamespace
          The Constant PassportSoapFaultNamespace.
static String PassportSoapFaultNamespacePrefix
          The Constant PassportSoapFaultNamespacePrefix.
static String WSAddressingNamespace
          The Constant WSAddressingNamespace.
static String WSAddressingNamespacePrefix
          The Constant WSAddressingNamespacePrefix.
static String WSSecuritySecExtNamespace
           
static String WSSecuritySecExtNamespacePrefix
          The Constant WSSecuritySecExtNamespacePrefix.
static String WSSecurityUtilityNamespace
           
static String WSSecurityUtilityNamespacePrefix
          The Constant WSSecurityUtilityNamespacePrefix.
static String WSTrustFebruary2005Namespace
          The Constant WSTrustFebruary2005Namespace.
static String WSTrustFebruary2005NamespacePrefix
          The Constant WSTrustFebruary2005NamespacePrefix.
static String XSFalse
          The Constant XSFalse.
static String XSTrue
          The Constant XSTrue.
 
Method Summary
static String boolToXSBool(Boolean value)
          Convert bool to XML Schema bool.
static int countMatchingChars(String str, IPredicate<Character> charPredicate)
          Count characters in string that match a condition.
static
<TServiceObject extends ServiceObject>
TServiceObject
createEwsObjectFromXmlElementName(Class<?> itemClass, ExchangeService service, String xmlElementName)
          Creates the ews object from xml element name.
static Item createItemFromItemClass(ItemAttachment itemAttachment, Class<?> itemClass, boolean isNew)
          Creates the item from item class.
static Item createItemFromXmlElementName(ItemAttachment itemAttachment, String xmlElementName)
          Creates the item from xml element name.
static String dateTimeToXSDate(Date date)
          Convert DateTime to XML Schema date.
static String dateTimeToXSDateTime(Date date)
          Dates the DateTime into an XML schema date time.
static String domainFromEmailAddress(String emailAddress)
          Gets the domain name from an email address.
static void ewsAssert(boolean condition, String caller, String message)
          Asserts that the specified condition if true.
static
<TItem extends Item>
TItem
findFirstItemOfType(Class<TItem> cls, Iterable<Item> items)
          Finds the first item of type TItem (not a descendant type) in the specified collection.
static
<T> void
forEach(Iterable<T> collection, IAction<T> action)
          Call an action for each member of a collection.
static String formatHttpRequestHeaders(HttpWebRequest request)
          Format request HTTP headers.
static String formatHttpResponseHeaders(HttpWebRequest response)
          Format http response headers.
static String formatLogMessage(String entryKind, String logEntry)
          .
static String formatLogMessageWithXmlContent(String traceTypeStr, ByteArrayOutputStream stream)
          Format XML content in a MemoryStream for message.
static String getBuildVersion()
          Gets the builds the version.
static int getDim(Object array)
           
static
<T> Object
getEnumeratedObjectAt(Iterable<T> objects, int index)
          Gets the enumerated object at.
static
<T> int
getEnumeratedObjectCount(Iterator<T> objects)
          Gets the enumerated object count.
static Class<?> getItemTypeFromXmlElementName(String xmlElementName)
           
static XmlNamespace getNamespaceFromUri(String namespaceUri)
          Gets the namespace from uri.
static String getNamespacePrefix(XmlNamespace xmlNamespace)
          Gets the namespace prefix from an XmlNamespace enum value.
static String getNamespaceUri(XmlNamespace xmlNamespace)
          Gets the namespace URI from an XmlNamespace enum value.
static String getTimeSpanToXSDuration(TimeSpan timeOffset)
          Takes a System.TimeSpan structure and converts it into an xs:duration string as defined by the W3 Consortiums Recommendation "XML Schema Part 2: Datatypes Second Edition", http://www.w3.org/TR/xmlschema-2/#duration
static TimeSpan getXSDurationToTimeSpan(String xsDuration)
          Takes an xs:duration string as defined by the W3 Consortiums Recommendation "XML Schema Part 2: Datatypes Second Edition", http://www.w3.org/TR/xmlschema-2/#duration, and converts it into a System.TimeSpan structure This method uses the following approximations: 1 year = 365 days 1 month = 30 days Additionally, it only allows for four decimal points of seconds precision.
static
<T> T
parse(Class<T> cls, String value)
          Parses the.
static
<T extends Enum<?>>
void
parseEnumValueList(Class<T> c, List<T> list, String value, char... separators)
          Parses an enum value list.
static String serializeEnum(Object value)
          Converts an enum to a string, using the mapping dictionaries if appropriate.
static String timeSpanToXSTime(TimeSpan timeSpan)
          Time span to xs time.
static
<T> boolean
trueForAll(Iterable<T> collection, IPredicate<T> predicate)
          Determines whether every element in the collection matches the conditions defined by the specified predicate.
static void validateClassVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String className)
          Validates class version against the request version.
static void validateDomainNameAllowNull(String domainName, String paramName)
          Validates domain name (null value allowed)
static void validateEnumVersionValue(Enum<?> enumValue, ExchangeVersion requestVersion)
          Validate enum version value.
static void validateMethodVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String methodName)
          Validate method version.
static void validateNonBlankStringParam(String param, String paramName)
          Validates string parameter to be non-empty string (null value not allowed).
static void validateNonBlankStringParamAllowNull(String param, String paramName)
          Validates string parameter to be non-empty string (null value allowed).
static void validateParam(Object param, String paramName)
          Validates parameter (null value not allowed).
static void validateParamAllowNull(Object param, String paramName)
          Validates parameter (and allows null value).
static void validateParamCollection(EventType[] eventTypes, String paramName)
          Validate param collection.
static
<T> void
validateParamCollection(Iterator<T> collection, String paramName)
          Validates parameter collection.
static void validatePropertyVersion(ExchangeService service, ExchangeVersion minimumServerVersion, String propertyName)
          Validates property version against the request version.
static void validateServiceObjectVersion(ServiceObject serviceObject, ExchangeVersion requestVersion)
          Validates service object version against the request version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XSFalse

public static final String XSFalse
The Constant XSFalse.

See Also:
Constant Field Values

XSTrue

public static final String XSTrue
The Constant XSTrue.

See Also:
Constant Field Values

EwsTypesNamespacePrefix

public static final String EwsTypesNamespacePrefix
The Constant EwsTypesNamespacePrefix.

See Also:
Constant Field Values

EwsMessagesNamespacePrefix

public static final String EwsMessagesNamespacePrefix
The Constant EwsMessagesNamespacePrefix.

See Also:
Constant Field Values

EwsErrorsNamespacePrefix

public static final String EwsErrorsNamespacePrefix
The Constant EwsErrorsNamespacePrefix.

See Also:
Constant Field Values

EwsSoapNamespacePrefix

public static final String EwsSoapNamespacePrefix
The Constant EwsSoapNamespacePrefix.

See Also:
Constant Field Values

EwsXmlSchemaInstanceNamespacePrefix

public static final String EwsXmlSchemaInstanceNamespacePrefix
The Constant EwsXmlSchemaInstanceNamespacePrefix.

See Also:
Constant Field Values

PassportSoapFaultNamespacePrefix

public static final String PassportSoapFaultNamespacePrefix
The Constant PassportSoapFaultNamespacePrefix.

See Also:
Constant Field Values

WSTrustFebruary2005NamespacePrefix

public static final String WSTrustFebruary2005NamespacePrefix
The Constant WSTrustFebruary2005NamespacePrefix.

See Also:
Constant Field Values

WSAddressingNamespacePrefix

public static final String WSAddressingNamespacePrefix
The Constant WSAddressingNamespacePrefix.

See Also:
Constant Field Values

AutodiscoverSoapNamespacePrefix

public static final String AutodiscoverSoapNamespacePrefix
The Constant AutodiscoverSoapNamespacePrefix.

See Also:
Constant Field Values

WSSecurityUtilityNamespacePrefix

public static final String WSSecurityUtilityNamespacePrefix
The Constant WSSecurityUtilityNamespacePrefix.

See Also:
Constant Field Values

WSSecuritySecExtNamespacePrefix

public static final String WSSecuritySecExtNamespacePrefix
The Constant WSSecuritySecExtNamespacePrefix.

See Also:
Constant Field Values

EwsTypesNamespace

public static final String EwsTypesNamespace
The Constant EwsTypesNamespace.

See Also:
Constant Field Values

EwsMessagesNamespace

public static final String EwsMessagesNamespace
The Constant EwsMessagesNamespace.

See Also:
Constant Field Values

EwsErrorsNamespace

public static final String EwsErrorsNamespace
The Constant EwsErrorsNamespace.

See Also:
Constant Field Values

EwsSoapNamespace

public static final String EwsSoapNamespace
The Constant EwsSoapNamespace.

See Also:
Constant Field Values

EwsSoap12Namespace

public static final String EwsSoap12Namespace
The Constant EwsSoap12Namespace.

See Also:
Constant Field Values

EwsXmlSchemaInstanceNamespace

public static final String EwsXmlSchemaInstanceNamespace
The Constant EwsXmlSchemaInstanceNamespace.

See Also:
Constant Field Values

PassportSoapFaultNamespace

public static final String PassportSoapFaultNamespace
The Constant PassportSoapFaultNamespace.

See Also:
Constant Field Values

WSTrustFebruary2005Namespace

public static final String WSTrustFebruary2005Namespace
The Constant WSTrustFebruary2005Namespace.

See Also:
Constant Field Values

WSAddressingNamespace

public static final String WSAddressingNamespace
The Constant WSAddressingNamespace.

See Also:
Constant Field Values

AutodiscoverSoapNamespace

public static final String AutodiscoverSoapNamespace
The Constant AutodiscoverSoapNamespace.

See Also:
Constant Field Values

WSSecurityUtilityNamespace

public static final String WSSecurityUtilityNamespace
See Also:
Constant Field Values

WSSecuritySecExtNamespace

public static final String WSSecuritySecExtNamespace
See Also:
Constant Field Values

ENUM_TO_SCHEMA_DICTIONARIES

public static final LazyMember<Map<Class<?>,Map<String,String>>> ENUM_TO_SCHEMA_DICTIONARIES
Dictionary of enum type to enum-value-to-schema-name maps.


DomainRegex

public static final String DomainRegex
Regular expression for legal domain names.

See Also:
Constant Field Values
Method Detail

getBuildVersion

public static String getBuildVersion()
Gets the builds the version.

Returns:
the builds the version

ewsAssert

public static void ewsAssert(boolean condition,
                             String caller,
                             String message)
Asserts that the specified condition if true.

Parameters:
condition - Assertion.
caller - The caller.
message - The message to use if assertion fails.

getNamespacePrefix

public static String getNamespacePrefix(XmlNamespace xmlNamespace)
Gets the namespace prefix from an XmlNamespace enum value.

Parameters:
xmlNamespace - The XML namespace
Returns:
Namespace prefix string.

getNamespaceUri

public static String getNamespaceUri(XmlNamespace xmlNamespace)
Gets the namespace URI from an XmlNamespace enum value.

Parameters:
xmlNamespace - The XML namespace.
Returns:
Uri as string

getNamespaceFromUri

public static XmlNamespace getNamespaceFromUri(String namespaceUri)
Gets the namespace from uri.

Parameters:
namespaceUri - the namespace uri
Returns:
the namespace from uri

createEwsObjectFromXmlElementName

public static <TServiceObject extends ServiceObject> TServiceObject createEwsObjectFromXmlElementName(Class<?> itemClass,
                                                                                                      ExchangeService service,
                                                                                                      String xmlElementName)
                                                                              throws Exception
Creates the ews object from xml element name.

Type Parameters:
TServiceObject - the generic type
Parameters:
itemClass - the item class
service - the service
xmlElementName - the xml element name
Returns:
the t service object
Throws:
Exception - the exception

createItemFromItemClass

public static Item createItemFromItemClass(ItemAttachment itemAttachment,
                                           Class<?> itemClass,
                                           boolean isNew)
                                    throws Exception
Creates the item from item class.

Parameters:
itemAttachment - the item attachment
itemClass - the item class
isNew - the is new
Returns:
the item
Throws:
Exception - the exception

createItemFromXmlElementName

public static Item createItemFromXmlElementName(ItemAttachment itemAttachment,
                                                String xmlElementName)
                                         throws Exception
Creates the item from xml element name.

Parameters:
itemAttachment - the item attachment
xmlElementName - the xml element name
Returns:
the item
Throws:
Exception - the exception

getItemTypeFromXmlElementName

public static Class<?> getItemTypeFromXmlElementName(String xmlElementName)

findFirstItemOfType

public static <TItem extends Item> TItem findFirstItemOfType(Class<TItem> cls,
                                                             Iterable<Item> items)
Finds the first item of type TItem (not a descendant type) in the specified collection.

Type Parameters:
TItem - TItem is the type of the item to find.
Parameters:
cls - the cls
items - the item
Returns:
A TItem instance or null if no instance of TItem could be found.

formatLogMessage

public static String formatLogMessage(String entryKind,
                                      String logEntry)
                               throws XMLStreamException,
                                      IOException
.

Parameters:
entryKind - the entry kind
logEntry - the log entry
Returns:
the string
Throws:
XMLStreamException - the XML stream exception
IOException - signals that an I/O exception has occurred.

formatHttpResponseHeaders

public static String formatHttpResponseHeaders(HttpWebRequest response)
                                        throws EWSHttpException
Format http response headers.

Parameters:
response - the response
Returns:
the string
Throws:
EWSHttpException - the EWS http exception

formatHttpRequestHeaders

public static String formatHttpRequestHeaders(HttpWebRequest request)
                                       throws URISyntaxException,
                                              EWSHttpException
Format request HTTP headers.

Parameters:
request - The HTTP request.
Throws:
URISyntaxException
EWSHttpException

formatLogMessageWithXmlContent

public static String formatLogMessageWithXmlContent(String traceTypeStr,
                                                    ByteArrayOutputStream stream)
Format XML content in a MemoryStream for message.

Parameters:
traceTypeStr - Kind of the entry.
stream - The memory stream.
Returns:
XML log entry as a string.

boolToXSBool

public static String boolToXSBool(Boolean value)
Convert bool to XML Schema bool.

Parameters:
value - Bool value.
Returns:
String representing bool value in XML Schema.

parseEnumValueList

public static <T extends Enum<?>> void parseEnumValueList(Class<T> c,
                                                          List<T> list,
                                                          String value,
                                                          char... separators)
Parses an enum value list.

Type Parameters:
T - the generic type
Parameters:
c - the c
list - the list
value - the value
separators - the separators

serializeEnum

public static String serializeEnum(Object value)
Converts an enum to a string, using the mapping dictionaries if appropriate.

Parameters:
value - The enum value to be serialized
Returns:
String representation of enum to be used in the protocol

parse

public static <T> T parse(Class<T> cls,
                          String value)
               throws ParseException
Parses the.

Type Parameters:
T - the generic type
Parameters:
cls - the cls
value - the value
Returns:
the t
Throws:
ParseException - the parse exception

validateParamCollection

public static void validateParamCollection(EventType[] eventTypes,
                                           String paramName)
                                    throws Exception
Validate param collection.

Parameters:
eventTypes - the event types
paramName - the param name
Throws:
Exception - the exception

dateTimeToXSDate

public static String dateTimeToXSDate(Date date)
Convert DateTime to XML Schema date.

Parameters:
date - the date
Returns:
String representation of DateTime.

dateTimeToXSDateTime

public static String dateTimeToXSDateTime(Date date)
Dates the DateTime into an XML schema date time.

Parameters:
date - the date
Returns:
String representation of DateTime.

getTimeSpanToXSDuration

public static String getTimeSpanToXSDuration(TimeSpan timeOffset)
Takes a System.TimeSpan structure and converts it into an xs:duration string as defined by the W3 Consortiums Recommendation "XML Schema Part 2: Datatypes Second Edition", http://www.w3.org/TR/xmlschema-2/#duration

Parameters:
timeOffset - structure to convert
Returns:
xs:duration formatted string

getXSDurationToTimeSpan

public static TimeSpan getXSDurationToTimeSpan(String xsDuration)
Takes an xs:duration string as defined by the W3 Consortiums Recommendation "XML Schema Part 2: Datatypes Second Edition", http://www.w3.org/TR/xmlschema-2/#duration, and converts it into a System.TimeSpan structure This method uses the following approximations: 1 year = 365 days 1 month = 30 days Additionally, it only allows for four decimal points of seconds precision.

Parameters:
xsDuration - xs:duration string to convert
Returns:
System.TimeSpan structure

timeSpanToXSTime

public static String timeSpanToXSTime(TimeSpan timeSpan)
Time span to xs time.

Parameters:
timeSpan - the time span
Returns:
the string

domainFromEmailAddress

public static String domainFromEmailAddress(String emailAddress)
                                     throws FormatException
Gets the domain name from an email address.

Parameters:
emailAddress - The email address.
Returns:
Domain name.
Throws:
FormatException - the format exception

getDim

public static int getDim(Object array)

validateParamAllowNull

public static void validateParamAllowNull(Object param,
                                          String paramName)
                                   throws Exception
Validates parameter (and allows null value).

Parameters:
param - The param.
paramName - Name of the param.
Throws:
Exception - the exception

validateParam

public static void validateParam(Object param,
                                 String paramName)
                          throws Exception
Validates parameter (null value not allowed).

Parameters:
param - The param.
paramName - Name of the param.
Throws:
Exception - the exception

validateParamCollection

public static <T> void validateParamCollection(Iterator<T> collection,
                                               String paramName)
                                    throws Exception
Validates parameter collection.

Type Parameters:
T - the generic type
Parameters:
collection - The collection.
paramName - Name of the param.
Throws:
Exception - the exception

validateNonBlankStringParamAllowNull

public static void validateNonBlankStringParamAllowNull(String param,
                                                        String paramName)
                                                 throws ArgumentException,
                                                        ServiceLocalException
Validates string parameter to be non-empty string (null value allowed).

Parameters:
param - The string parameter.
paramName - Name of the parameter.
Throws:
ArgumentException
ServiceLocalException

validateNonBlankStringParam

public static void validateNonBlankStringParam(String param,
                                               String paramName)
                                        throws ArgumentNullException,
                                               ArgumentException,
                                               ServiceLocalException
Validates string parameter to be non-empty string (null value not allowed).

Parameters:
param - The string parameter.
paramName - Name of the parameter.
Throws:
ArgumentNullException
ArgumentException
ServiceLocalException

validateEnumVersionValue

public static void validateEnumVersionValue(Enum<?> enumValue,
                                            ExchangeVersion requestVersion)
                                     throws ServiceVersionException
Validate enum version value.

Parameters:
enumValue - the enum value
requestVersion - the request version
Throws:
ServiceVersionException - the service version exception

validateServiceObjectVersion

public static void validateServiceObjectVersion(ServiceObject serviceObject,
                                                ExchangeVersion requestVersion)
                                         throws ServiceVersionException
Validates service object version against the request version.

Parameters:
serviceObject - The service object.
requestVersion - The request version.
Throws:
ServiceVersionException - Raised if this service object type requires a later version of Exchange.

validatePropertyVersion

public static void validatePropertyVersion(ExchangeService service,
                                           ExchangeVersion minimumServerVersion,
                                           String propertyName)
                                    throws ServiceVersionException
Validates property version against the request version.

Parameters:
service - The Exchange service.
minimumServerVersion - The minimum server version
propertyName - The property name
Throws:
ServiceVersionException - The service version exception

validateMethodVersion

public static void validateMethodVersion(ExchangeService service,
                                         ExchangeVersion minimumServerVersion,
                                         String methodName)
                                  throws ServiceVersionException
Validate method version.

Parameters:
service - the service
minimumServerVersion - the minimum server version
methodName - the method name
Throws:
ServiceVersionException - the service version exception

validateClassVersion

public static void validateClassVersion(ExchangeService service,
                                        ExchangeVersion minimumServerVersion,
                                        String className)
                                 throws ServiceVersionException
Validates class version against the request version.

Parameters:
service - the service
minimumServerVersion - The minimum server version that supports the method.
className - Name of the class.
Throws:
ServiceVersionException

validateDomainNameAllowNull

public static void validateDomainNameAllowNull(String domainName,
                                               String paramName)
                                        throws ArgumentException
Validates domain name (null value allowed)

Parameters:
domainName - Domain name.
paramName - Parameter name.
Throws:
ArgumentException

getEnumeratedObjectCount

public static <T> int getEnumeratedObjectCount(Iterator<T> objects)
Gets the enumerated object count.

Type Parameters:
T - the generic type
Parameters:
objects - The objects.
Returns:
Count of objects in iterator.

getEnumeratedObjectAt

public static <T> Object getEnumeratedObjectAt(Iterable<T> objects,
                                               int index)
Gets the enumerated object at.

Type Parameters:
T - the generic type
Parameters:
objects - the objects
index - the index
Returns:
the enumerated object at

countMatchingChars

public static int countMatchingChars(String str,
                                     IPredicate<Character> charPredicate)
                              throws ServiceLocalException
Count characters in string that match a condition.

Parameters:
str - The string.
charPredicate - Predicate to evaluate for each character in the string.
Returns:
Count of characters that match condition expressed by predicate.
Throws:
ServiceLocalException

trueForAll

public static <T> boolean trueForAll(Iterable<T> collection,
                                     IPredicate<T> predicate)
                          throws ServiceLocalException
Determines whether every element in the collection matches the conditions defined by the specified predicate.

Type Parameters:
T - Entry type.
Parameters:
collection - The collection.
predicate - Predicate that defines the conditions to check against the elements.
Returns:
True if every element in the collection matches the conditions defined by the specified predicate; otherwise, false.
Throws:
ServiceLocalException

forEach

public static <T> void forEach(Iterable<T> collection,
                               IAction<T> action)
Call an action for each member of a collection.

Type Parameters:
T - Collection element type.
Parameters:
collection - The collection.
action - The action to apply.


Copyright © 2012–2015 Microsoft. All rights reserved.