CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-jetty--jetty-xml

XML-based configuration utilities for Eclipse Jetty providing IoC mechanism for component configuration.

Pending
Overview
Eval results
Files

xml-configuration.mddocs/

XML Configuration Processing

Core functionality for loading XML configuration files and applying them to Java objects through reflection-based dependency injection. The XmlConfiguration class serves as the main entry point for the IoC container functionality.

Capabilities

XmlConfiguration Class

The primary class for processing XML configuration files and applying them to Java objects.

/**
 * Configures objects from XML files conforming to configure.dtd DTD
 */
class XmlConfiguration {
    /**
     * Create configuration from a resource
     * @param resource XML configuration resource
     */
    XmlConfiguration(Resource resource);
    
    /**
     * Create configuration with shared state
     * @param resource XML configuration resource
     * @param idMap shared map of object IDs between configurations
     * @param properties shared properties for parameterization
     */
    XmlConfiguration(Resource resource, Map<String, Object> idMap, Map<String, String> properties);
}

Configuration Execution

Apply XML configuration to create or configure objects.

/**
 * Apply XML configuration script, creating new objects as needed
 * @return the configured object
 * @throws Exception if configuration fails
 */
Object configure() throws Exception;

/**
 * Apply XML configuration to an existing object
 * @param obj the object to configure
 * @return the configured object
 * @throws Exception if configuration fails
 */
Object configure(Object obj) throws Exception;

/**
 * Hook for initializing object defaults (override point)
 * @param object the object to initialize
 */
void initializeDefaults(Object object);

State Management

Manage shared state between multiple configuration instances.

/**
 * Get modifiable map of ID strings to objects for sharing between configurations
 * @return map of object IDs
 */
Map<String, Object> getIdMap();

/**
 * Get modifiable map of properties for parameterizing configuration
 * @return properties map
 */
Map<String, String> getProperties();

/**
 * Set standard Jetty IDs and properties
 * @param server the server object
 * @param webapp path to webapp
 */
void setJettyStandardIdsAndProperties(Object server, Path webapp);

Utility Methods

Helper methods for configuration processing.

/**
 * Get an XML parser instance
 * @return XmlParser instance
 */
XmlParser getXmlParser();

/**
 * Normalize URI by removing trailing slash
 * @param uri the URI to normalize
 * @return normalized URI
 */
static String normalizeURI(String uri);

/**
 * Resolve path against directory
 * @param dir base directory
 * @param destPath destination path
 * @return resolved path
 */
static String resolvePath(String dir, String destPath);

Main Application Support

Run XML configurations as standalone applications.

/**
 * Run XML configurations as main application with property and XML file support
 * @param args command line arguments
 */
static void main(String... args);

Usage Examples

Basic Configuration

import org.eclipse.jetty.xml.XmlConfiguration;
import org.eclipse.jetty.util.resource.Resource;

// Load XML configuration
Resource configXml = Resource.newResource("server-config.xml");
XmlConfiguration config = new XmlConfiguration(configXml);

// Apply configuration to create objects
Object server = config.configure();

Configure Existing Object

// Configure an existing object
MyServer server = new MyServer();
XmlConfiguration config = new XmlConfiguration(Resource.newResource("server.xml"));
config.configure(server);

Multi-File Configuration with Shared State

// First configuration
XmlConfiguration config1 = new XmlConfiguration(Resource.newResource("base-config.xml"));
Object baseServer = config1.configure();

// Second configuration sharing IDs and properties
XmlConfiguration config2 = new XmlConfiguration(
    Resource.newResource("additional-config.xml"),
    config1.getIdMap(),      // Share object registry
    config1.getProperties()  // Share properties
);

// Objects in config2 can reference IDs from config1
Object enhancedServer = config2.configure();

Property Parameterization

XmlConfiguration config = new XmlConfiguration(Resource.newResource("parameterized.xml"));

// Set properties for substitution in XML
config.getProperties().put("server.port", "8080");
config.getProperties().put("server.host", "localhost");

Object server = config.configure();

Command Line Usage

# Run XML configuration as main application
java -cp jetty-xml.jar org.eclipse.jetty.xml.XmlConfiguration server.xml

# With properties
java -Dserver.port=8080 -cp jetty-xml.jar org.eclipse.jetty.xml.XmlConfiguration server.xml

# Multiple files
java -cp jetty-xml.jar org.eclipse.jetty.xml.XmlConfiguration base.xml additional.xml

XML Configuration Format

The library uses a DTD-based XML format for configuration:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" 
    "https://www.eclipse.org/jetty/configure_12_0.dtd">

<Configure class="com.example.Server">
  <!-- Set properties -->
  <Set name="port"><Property name="server.port" default="8080"/></Set>
  <Set name="host"><Property name="server.host" default="localhost"/></Set>
  
  <!-- Create and configure nested objects -->
  <Call name="addConnector">
    <Arg>
      <New class="com.example.Connector">
        <Set name="port"><Ref refid="server.port"/></Set>
      </New>
    </Arg>
  </Call>
  
  <!-- Reference objects by ID -->
  <New id="handler" class="com.example.Handler"/>
  <Call name="setHandler">
    <Arg><Ref refid="handler"/></Arg>
  </Call>
</Configure>

Configuration Elements

  • Configure: Root element specifying target class
  • Set: Call setter method
  • Get: Call getter method
  • Call: Call arbitrary method
  • New: Create new object instance
  • Ref: Reference object by ID
  • Property: Property value substitution
  • Arg: Method/constructor argument
  • Array: Create array values

Error Handling

Configuration errors are wrapped in XmlConfigurationException:

try {
    Object result = config.configure();
} catch (XmlConfigurationException e) {
    // Handle configuration-specific errors
    Throwable cause = e.getCause();
    String message = e.getMessage();
}

Constants

/**
 * Comparator for ranking methods and constructors by parameter compatibility
 */
static final Comparator<Executable> EXECUTABLE_COMPARATOR;

Install with Tessl CLI

npx tessl i tessl/maven-org-eclipse-jetty--jetty-xml

docs

configuration-extension.md

index.md

xml-configuration.md

xml-generation.md

xml-parser.md

tile.json