Azure Core provides shared primitives, abstractions, and helpers for modern Java Azure SDK client libraries
—
Essential data models including Cloud Events, geographic objects, Azure cloud configurations, and common model patterns used across Azure services.
Implementation of the Cloud Events specification for standardized event data representation.
/**
* Represents a CloudEvent conforming to the CloudEvents specification.
*/
class CloudEvent {
/**
* Creates a CloudEvent.
* @param source Identifies the context in which an event happened
* @param type The type of event related to the originating occurrence
*/
public CloudEvent(String source, String type);
/**
* Creates a CloudEvent.
* @param source Identifies the context in which an event happened
* @param type The type of event related to the originating occurrence
* @param data Event payload data
* @param dataContentType Content type of the data value
* @param subject The subject of the event in the context of the event producer
*/
public CloudEvent(String source, String type, BinaryData data, String dataContentType, String subject);
/**
* Gets the event ID.
* @return Event identifier
*/
public String getId();
/**
* Gets the source of the event.
* @return Event source
*/
public String getSource();
/**
* Gets the type of the event.
* @return Event type
*/
public String getType();
/**
* Gets the data content type.
* @return Content type of the event data
*/
public String getDataContentType();
/**
* Gets the data schema URL.
* @return Schema URL for the event data
*/
public String getDataSchema();
/**
* Gets the subject of the event.
* @return Event subject
*/
public String getSubject();
/**
* Gets the time the event was generated.
* @return Event timestamp
*/
public OffsetDateTime getTime();
/**
* Gets the event data as BinaryData.
* @return Event payload data
*/
public BinaryData getData();
/**
* Gets extension attributes.
* @return Map of extension attributes
*/
public Map<String, Object> getExtensionAttributes();
/**
* Sets the subject of the event.
* @param subject Event subject
* @return Updated CloudEvent
*/
public CloudEvent setSubject(String subject);
/**
* Sets the data schema URL.
* @param dataSchema Schema URL
* @return Updated CloudEvent
*/
public CloudEvent setDataSchema(String dataSchema);
/**
* Sets the time of the event.
* @param time Event timestamp
* @return Updated CloudEvent
*/
public CloudEvent setTime(OffsetDateTime time);
/**
* Sets the event data.
* @param data Event payload data
* @return Updated CloudEvent
*/
public CloudEvent setData(BinaryData data);
/**
* Sets the data content type.
* @param dataContentType Content type of the data
* @return Updated CloudEvent
*/
public CloudEvent setDataContentType(String dataContentType);
/**
* Adds an extension attribute.
* @param name Extension attribute name
* @param value Extension attribute value
* @return Updated CloudEvent
*/
public CloudEvent addExtensionAttribute(String name, Object value);
}Enumeration of supported data formats for Cloud Events.
/**
* The format that the event data is encoded in.
*/
enum CloudEventDataFormat {
/**
* Event data is in JSON format.
*/
JSON,
/**
* Event data is in XML format.
*/
XML,
/**
* Event data is in plain text format.
*/
TEXT,
/**
* Event data is in binary format.
*/
BYTES;
/**
* Creates a CloudEventDataFormat from a string value.
* @param value String representation of the format
* @return Corresponding CloudEventDataFormat
*/
public static CloudEventDataFormat fromString(String value);
}Enumeration of Azure cloud environments with their specific endpoints and configurations.
/**
* An enumeration of available Azure clouds.
*/
enum AzureCloud {
/**
* Azure global cloud.
*/
AZURE,
/**
* Azure operated by 21Vianet in China.
*/
AZURE_CHINA,
/**
* Azure Germany cloud.
*/
AZURE_GERMANY,
/**
* Azure US Government cloud.
*/
AZURE_US_GOVERNMENT;
/**
* Gets the Azure Active Directory endpoint for this cloud.
* @return AAD endpoint URL
*/
public String getActiveDirectoryEndpoint();
/**
* Gets the Azure Resource Manager endpoint for this cloud.
* @return ARM endpoint URL
*/
public String getResourceManagerEndpoint();
/**
* Gets the Microsoft Graph endpoint for this cloud.
* @return Microsoft Graph endpoint URL
*/
public String getMicrosoftGraphEndpoint();
/**
* Gets the Key Vault DNS suffix for this cloud.
* @return Key Vault DNS suffix
*/
public String getKeyVaultDnsSuffix();
/**
* Gets the Storage endpoint suffix for this cloud.
* @return Storage endpoint suffix
*/
public String getStorageEndpointSuffix();
/**
* Gets the SQL Database DNS suffix for this cloud.
* @return SQL Database DNS suffix
*/
public String getSqlDatabaseDnsSuffix();
}Base classes and implementations for representing geographic data structures.
/**
* Abstract base class for all geographic objects.
*/
abstract class GeoObject {
/**
* Gets the GeoJSON type of the object.
* @return GeoJSON type
*/
public abstract String getType();
/**
* Gets the bounding box of the geographic object.
* @return Bounding box or null if not set
*/
public GeoBoundingBox getBoundingBox();
/**
* Sets the bounding box of the geographic object.
* @param boundingBox Bounding box to set
* @return Updated GeoObject
*/
public GeoObject setBoundingBox(GeoBoundingBox boundingBox);
/**
* Gets additional properties.
* @return Map of additional properties
*/
public Map<String, Object> getAdditionalProperties();
/**
* Sets additional properties.
* @param additionalProperties Map of properties to set
* @return Updated GeoObject
*/
public GeoObject setAdditionalProperties(Map<String, Object> additionalProperties);
}
/**
* Represents a geometric point.
*/
class GeoPoint extends GeoObject {
/**
* Creates a GeoPoint.
* @param position The position coordinates
*/
public GeoPoint(GeoPosition position);
/**
* Creates a GeoPoint.
* @param longitude Longitude coordinate
* @param latitude Latitude coordinate
*/
public GeoPoint(double longitude, double latitude);
/**
* Creates a GeoPoint.
* @param longitude Longitude coordinate
* @param latitude Latitude coordinate
* @param altitude Altitude coordinate
*/
public GeoPoint(double longitude, double latitude, Double altitude);
/**
* Gets the position of the point.
* @return Position coordinates
*/
public GeoPosition getCoordinates();
@Override
public String getType() {
return "Point";
}
}
/**
* Represents a line string geometry.
*/
class GeoLineString extends GeoObject {
/**
* Creates a GeoLineString.
* @param positions List of positions forming the line
*/
public GeoLineString(List<GeoPosition> positions);
/**
* Gets the positions that form the line string.
* @return List of positions
*/
public List<GeoPosition> getCoordinates();
@Override
public String getType() {
return "LineString";
}
}
/**
* Represents a polygon geometry.
*/
class GeoPolygon extends GeoObject {
/**
* Creates a GeoPolygon.
* @param exteriorRing The exterior boundary of the polygon
*/
public GeoPolygon(GeoLinearRing exteriorRing);
/**
* Creates a GeoPolygon.
* @param exteriorRing The exterior boundary of the polygon
* @param holes Interior holes in the polygon
*/
public GeoPolygon(GeoLinearRing exteriorRing, List<GeoLinearRing> holes);
/**
* Gets the exterior ring of the polygon.
* @return Exterior linear ring
*/
public GeoLinearRing getExteriorRing();
/**
* Gets the holes (interior rings) of the polygon.
* @return List of interior linear rings
*/
public List<GeoLinearRing> getHoles();
/**
* Gets the coordinates as a list of linear rings.
* @return List of linear rings (first is exterior, rest are holes)
*/
public List<List<GeoPosition>> getCoordinates();
@Override
public String getType() {
return "Polygon";
}
}
/**
* Represents a collection of geographic objects.
*/
class GeoCollection extends GeoObject {
/**
* Creates a GeoCollection.
* @param geometries List of geometric objects in the collection
*/
public GeoCollection(List<GeoObject> geometries);
/**
* Gets the geometries in the collection.
* @return List of geometric objects
*/
public List<GeoObject> getGeometries();
@Override
public String getType() {
return "GeometryCollection";
}
}/**
* Represents a position with longitude, latitude, and optional altitude.
*/
class GeoPosition {
/**
* Creates a GeoPosition.
* @param longitude Longitude coordinate
* @param latitude Latitude coordinate
*/
public GeoPosition(double longitude, double latitude);
/**
* Creates a GeoPosition.
* @param longitude Longitude coordinate
* @param latitude Latitude coordinate
* @param altitude Altitude coordinate
*/
public GeoPosition(double longitude, double latitude, Double altitude);
/**
* Gets the longitude.
* @return Longitude coordinate
*/
public double getLongitude();
/**
* Gets the latitude.
* @return Latitude coordinate
*/
public double getLatitude();
/**
* Gets the altitude.
* @return Altitude coordinate or null if not set
*/
public Double getAltitude();
/**
* Gets all coordinates as an array.
* @return Array of coordinates [longitude, latitude, altitude?]
*/
public double[] getCoordinates();
}
/**
* Represents a linear ring (closed line string).
*/
class GeoLinearRing {
/**
* Creates a GeoLinearRing.
* @param positions List of positions forming the ring (must be closed)
*/
public GeoLinearRing(List<GeoPosition> positions);
/**
* Gets the positions forming the linear ring.
* @return List of positions
*/
public List<GeoPosition> getCoordinates();
}
/**
* Represents a bounding box for geographic objects.
*/
class GeoBoundingBox {
/**
* Creates a GeoBoundingBox.
* @param west Western boundary
* @param south Southern boundary
* @param east Eastern boundary
* @param north Northern boundary
*/
public GeoBoundingBox(double west, double south, double east, double north);
/**
* Creates a GeoBoundingBox with altitude.
* @param west Western boundary
* @param south Southern boundary
* @param minAltitude Minimum altitude
* @param east Eastern boundary
* @param north Northern boundary
* @param maxAltitude Maximum altitude
*/
public GeoBoundingBox(double west, double south, double minAltitude,
double east, double north, double maxAltitude);
/**
* Gets the western boundary.
* @return Western longitude
*/
public double getWest();
/**
* Gets the southern boundary.
* @return Southern latitude
*/
public double getSouth();
/**
* Gets the eastern boundary.
* @return Eastern longitude
*/
public double getEast();
/**
* Gets the northern boundary.
* @return Northern latitude
*/
public double getNorth();
/**
* Gets the minimum altitude.
* @return Minimum altitude or null if not set
*/
public Double getMinAltitude();
/**
* Gets the maximum altitude.
* @return Maximum altitude or null if not set
*/
public Double getMaxAltitude();
}/**
* Represents multiple points.
*/
class GeoMultiPoint extends GeoObject {
/**
* Creates a GeoMultiPoint.
* @param points List of points
*/
public GeoMultiPoint(List<GeoPoint> points);
/**
* Gets the points in the multi-point.
* @return List of points
*/
public List<GeoPoint> getPoints();
/**
* Gets the coordinates as a list of positions.
* @return List of positions
*/
public List<GeoPosition> getCoordinates();
@Override
public String getType() {
return "MultiPoint";
}
}
/**
* Represents multiple line strings.
*/
class GeoMultiLineString extends GeoObject {
/**
* Creates a GeoMultiLineString.
* @param lineStrings List of line strings
*/
public GeoMultiLineString(List<GeoLineString> lineStrings);
/**
* Gets the line strings in the multi-line string.
* @return List of line strings
*/
public List<GeoLineString> getLineStrings();
/**
* Gets the coordinates as a list of position lists.
* @return List of position lists
*/
public List<List<GeoPosition>> getCoordinates();
@Override
public String getType() {
return "MultiLineString";
}
}
/**
* Represents multiple polygons.
*/
class GeoMultiPolygon extends GeoObject {
/**
* Creates a GeoMultiPolygon.
* @param polygons List of polygons
*/
public GeoMultiPolygon(List<GeoPolygon> polygons);
/**
* Gets the polygons in the multi-polygon.
* @return List of polygons
*/
public List<GeoPolygon> getPolygons();
/**
* Gets the coordinates as a nested list structure.
* @return List of polygon coordinate lists
*/
public List<List<List<GeoPosition>>> getCoordinates();
@Override
public String getType() {
return "MultiPolygon";
}
}/**
* Represents an array of geographic objects.
*/
class GeoArray {
/**
* Creates a GeoArray.
* @param geoObjects List of geographic objects
*/
public GeoArray(List<GeoObject> geoObjects);
/**
* Gets the geographic objects in the array.
* @return List of geographic objects
*/
public List<GeoObject> getGeoObjects();
/**
* Gets the number of objects in the array.
* @return Array size
*/
public int size();
/**
* Gets the object at the specified index.
* @param index Array index
* @return Geographic object at index
*/
public GeoObject get(int index);
}
/**
* Collection of GeoPoint objects.
*/
class GeoPointCollection {
/**
* Creates a GeoPointCollection.
* @param points List of points
*/
public GeoPointCollection(List<GeoPoint> points);
/**
* Gets the points in the collection.
* @return List of points
*/
public List<GeoPoint> getPoints();
}
/**
* Collection of GeoLineString objects.
*/
class GeoLineStringCollection {
/**
* Creates a GeoLineStringCollection.
* @param lineStrings List of line strings
*/
public GeoLineStringCollection(List<GeoLineString> lineStrings);
/**
* Gets the line strings in the collection.
* @return List of line strings
*/
public List<GeoLineString> getLineStrings();
}
/**
* Collection of GeoPolygon objects.
*/
class GeoPolygonCollection {
/**
* Creates a GeoPolygonCollection.
* @param polygons List of polygons
*/
public GeoPolygonCollection(List<GeoPolygon> polygons);
/**
* Gets the polygons in the collection.
* @return List of polygons
*/
public List<GeoPolygon> getPolygons();
}import com.azure.core.models.CloudEvent;
import com.azure.core.util.BinaryData;
import java.time.OffsetDateTime;
import java.util.Map;
// Create a basic Cloud Event
CloudEvent event = new CloudEvent("https://example.com/source", "User.Created");
// Add event data
User newUser = new User("Alice", "alice@example.com");
BinaryData userData = BinaryData.fromObject(newUser);
CloudEvent userEvent = new CloudEvent("https://api.example.com/users", "User.Created")
.setSubject("users/alice")
.setData(userData)
.setDataContentType("application/json")
.setTime(OffsetDateTime.now())
.addExtensionAttribute("correlationId", "12345")
.addExtensionAttribute("priority", "high");
// Access event properties
System.out.println("Event ID: " + userEvent.getId());
System.out.println("Source: " + userEvent.getSource());
System.out.println("Type: " + userEvent.getType());
System.out.println("Subject: " + userEvent.getSubject());
System.out.println("Time: " + userEvent.getTime());
// Work with event data
BinaryData eventData = userEvent.getData();
User deserializedUser = eventData.toObject(User.class);
// Access extension attributes
Map<String, Object> extensions = userEvent.getExtensionAttributes();
String correlationId = (String) extensions.get("correlationId");import com.azure.core.models.*;
// Create geographic points
GeoPoint point1 = new GeoPoint(-122.3, 47.6); // Seattle
GeoPoint point2 = new GeoPoint(-74.0, 40.7); // New York
GeoPoint point3 = new GeoPoint(-87.6, 41.9); // Chicago
// Create a line string connecting cities
List<GeoPosition> positions = List.of(
new GeoPosition(-122.3, 47.6), // Seattle
new GeoPosition(-87.6, 41.9), // Chicago
new GeoPosition(-74.0, 40.7) // New York
);
GeoLineString route = new GeoLineString(positions);
// Create a polygon representing a region
List<GeoPosition> exteriorRing = List.of(
new GeoPosition(-122.0, 47.0),
new GeoPosition(-122.0, 48.0),
new GeoPosition(-121.0, 48.0),
new GeoPosition(-121.0, 47.0),
new GeoPosition(-122.0, 47.0) // Close the ring
);
GeoLinearRing ring = new GeoLinearRing(exteriorRing);
GeoPolygon region = new GeoPolygon(ring);
// Create a multi-point for multiple locations
GeoMultiPoint cities = new GeoMultiPoint(List.of(point1, point2, point3));
// Set bounding box
GeoBoundingBox boundingBox = new GeoBoundingBox(-125.0, 45.0, -120.0, 50.0);
region.setBoundingBox(boundingBox);
// Create a geometry collection
GeoCollection collection = new GeoCollection(List.of(point1, route, region));import com.azure.core.models.AzureCloud;
// Get endpoints for different Azure clouds
AzureCloud publicCloud = AzureCloud.AZURE;
String aadEndpoint = publicCloud.getActiveDirectoryEndpoint();
String armEndpoint = publicCloud.getResourceManagerEndpoint();
String graphEndpoint = publicCloud.getMicrosoftGraphEndpoint();
System.out.println("AAD Endpoint: " + aadEndpoint);
System.out.println("ARM Endpoint: " + armEndpoint);
System.out.println("Graph Endpoint: " + graphEndpoint);
// Work with different cloud environments
AzureCloud govCloud = AzureCloud.AZURE_US_GOVERNMENT;
String govStorageSuffix = govCloud.getStorageEndpointSuffix();
String govKeyVaultSuffix = govCloud.getKeyVaultDnsSuffix();
// Configure services based on cloud environment
switch (publicCloud) {
case AZURE:
// Configure for public cloud
break;
case AZURE_CHINA:
// Configure for China cloud
break;
case AZURE_US_GOVERNMENT:
// Configure for US Government cloud
break;
case AZURE_GERMANY:
// Configure for Germany cloud
break;
}import com.azure.core.models.*;
// Create a complex polygon with holes
List<GeoPosition> exterior = List.of(
new GeoPosition(0, 0),
new GeoPosition(10, 0),
new GeoPosition(10, 10),
new GeoPosition(0, 10),
new GeoPosition(0, 0)
);
List<GeoPosition> hole1 = List.of(
new GeoPosition(2, 2),
new GeoPosition(4, 2),
new GeoPosition(4, 4),
new GeoPosition(2, 4),
new GeoPosition(2, 2)
);
List<GeoPosition> hole2 = List.of(
new GeoPosition(6, 6),
new GeoPosition(8, 6),
new GeoPosition(8, 8),
new GeoPosition(6, 8),
new GeoPosition(6, 6)
);
GeoLinearRing exteriorRing = new GeoLinearRing(exterior);
List<GeoLinearRing> holes = List.of(
new GeoLinearRing(hole1),
new GeoLinearRing(hole2)
);
GeoPolygon complexPolygon = new GeoPolygon(exteriorRing, holes);
// Work with 3D coordinates (altitude)
GeoPosition point3D = new GeoPosition(-122.3, 47.6, 100.0); // Seattle at 100m altitude
GeoPoint elevatedPoint = new GeoPoint(point3D);
// Create bounding box with altitude
GeoBoundingBox bbox3D = new GeoBoundingBox(-123.0, 47.0, 0.0, -122.0, 48.0, 200.0);
elevatedPoint.setBoundingBox(bbox3D);import com.azure.core.models.CloudEvent;
import java.util.Map;
// Create event with custom extensions
CloudEvent event = new CloudEvent("https://ecommerce.example.com", "Order.Placed")
.addExtensionAttribute("customerid", "cust-12345")
.addExtensionAttribute("ordervalue", 299.99)
.addExtensionAttribute("paymentmethod", "credit-card")
.addExtensionAttribute("region", "us-west-2");
// Access extension attributes
Map<String, Object> extensions = event.getExtensionAttributes();
String customerId = (String) extensions.get("customerid");
Double orderValue = (Double) extensions.get("ordervalue");
// Iterate over all extensions
extensions.forEach((key, value) -> {
System.out.println("Extension " + key + ": " + value);
});
// Check if specific extension exists
if (extensions.containsKey("priority")) {
String priority = (String) extensions.get("priority");
System.out.println("Event priority: " + priority);
}Install with Tessl CLI
npx tessl i tessl/maven-com-azure--azure-core