or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdjaxb-lifecycle.mdjaxb-model.mdobject-locators.mdstrategic-patterns.mdutilities.md
tile.json

tessl/maven-org-jvnet-jaxb2_commons--jaxb2-basics-runtime

Runtime support library for JAXB2 Basics plugins that provides strategic pattern implementations for equals, hashCode, toString, copying, and merging operations on JAXB-generated classes

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.jvnet.jaxb2_commons/jaxb2-basics-runtime@1.11.x

To install, run

npx @tessl/cli install tessl/maven-org-jvnet-jaxb2_commons--jaxb2-basics-runtime@1.11.0

index.mddocs/

JAXB2 Basics Runtime

Runtime support library for JAXB2 Basics plugins that provides strategic pattern implementations for equals, hashCode, toString, copying, and merging operations on JAXB-generated classes. This library enables reflection-free, high-performance implementations of common object operations while maintaining full compatibility with XML binding semantics.

Package Information

  • Package Name: jaxb2-basics-runtime
  • Package Type: maven
  • Language: Java
  • Installation: Add to Maven pom.xml:
    <dependency>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics-runtime</artifactId>
      <version>1.11.1</version>
    </dependency>

Core Imports

import org.jvnet.jaxb2_commons.lang.*;
import org.jvnet.jaxb2_commons.locator.*;

For JAXB lifecycle callbacks:

import org.jvnet.jaxb2_commons.xml.bind.*;

Basic Usage

import org.jvnet.jaxb2_commons.lang.*;
import org.jvnet.jaxb2_commons.locator.*;

// Example JAXB-generated class using strategic patterns
public class Person implements Equals2, HashCode2, ToString2, CopyTo2 {
    private String name;
    private int age;
    
    // Strategic equals implementation
    @Override
    public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, 
                         Object object, EqualsStrategy2 strategy) {
        if (!(object instanceof Person)) {
            return false;
        }
        Person that = (Person) object;
        return strategy.equals(LocatorUtils.property(thisLocator, "name", this.name),
                              LocatorUtils.property(thatLocator, "name", that.name),
                              this.name, that.name, true, true) &&
               strategy.equals(LocatorUtils.property(thisLocator, "age", this.age),
                              LocatorUtils.property(thatLocator, "age", that.age),
                              this.age, that.age, true, true);
    }
    
    // Strategic hashCode implementation  
    @Override
    public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) {
        int hashCode = 1;
        hashCode = strategy.hashCode(LocatorUtils.property(locator, "name", this.name),
                                    hashCode, this.name, true);
        hashCode = strategy.hashCode(LocatorUtils.property(locator, "age", this.age),
                                    hashCode, this.age, true);
        return hashCode;
    }
    
    // Use default JAXB strategies
    @Override
    public boolean equals(Object object) {
        return Equals2.DefaultEqualsStrategy.INSTANCE.equals(
            new DefaultRootObjectLocator(this),
            new DefaultRootObjectLocator(object),
            object, JAXBEqualsStrategy.INSTANCE);
    }
    
    @Override
    public int hashCode() {
        return HashCode2.DefaultHashCodeStrategy.INSTANCE.hashCode(
            new DefaultRootObjectLocator(this), JAXBHashCodeStrategy.INSTANCE);
    }
}

Architecture

The library is built around the Strategy Pattern, providing pluggable implementations for common object operations:

  • Behavioral Interfaces: Core interfaces (Equals2, HashCode2, ToString2, CopyTo2, MergeFrom2) that JAXB-generated classes implement
  • Strategy Interfaces: Define how operations are performed (EqualsStrategy2, HashCodeStrategy2, etc.)
  • Default Implementations: Provide standard behavior for all Java types
  • JAXB Implementations: Provide XML-aware behavior for JAXB types (JAXBElement, Collections)
  • Object Locators: Track object navigation paths for debugging and error reporting
  • Model Abstraction: Comprehensive abstraction layer over JAXB model metadata

This architecture enables consistent, high-performance operations across complex JAXB object hierarchies while maintaining full type safety and providing detailed error reporting capabilities.

Capabilities

Strategic Pattern Implementations

Core behavioral interfaces and strategy implementations for equals, hashCode, toString, copy, and merge operations. These form the foundation that JAXB2 Basics plugins use to generate efficient, reflection-free method implementations.

// Main behavioral interfaces (current API with value set tracking)
interface Equals2 {
    boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, 
                  Object object, EqualsStrategy2 strategy);
}

interface HashCode2 {
    int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy);
}

interface ToString2 {
    StringBuilder append(ObjectLocator locator, StringBuilder buffer, 
                        ToStringStrategy2 strategy);
    StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, 
                              ToStringStrategy2 strategy);
}

interface CopyTo2 {
    Object createNewInstance();
    Object copyTo(Object target);
    Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy);
}

interface MergeFrom2 {
    Object createNewInstance();
    void mergeFrom(Object left, Object right);
    void mergeFrom(ObjectLocator leftLocator, ObjectLocator rightLocator, 
                  Object left, Object right, MergeStrategy2 strategy);
}

Strategic Patterns

Object Location Tracking

Object locator system for tracking navigation paths through object hierarchies. Essential for debugging, error reporting, and providing context during strategic operations.

interface ObjectLocator extends ValidationEventLocator, Reportable {
    ObjectLocator getParentLocator();
    ObjectLocator[] getPath();
    String getPathAsString();
    PropertyObjectLocator property(String propertyName, Object propertyValue);
    ItemObjectLocator item(int itemIndex, Object itemValue);
}

class DefaultRootObjectLocator implements RootObjectLocator {
    public DefaultRootObjectLocator(Object rootObject);
}

Object Locators

JAXB Lifecycle Integration

Callback interfaces for integrating with JAXB marshalling and unmarshalling lifecycle events, enabling custom processing during XML binding operations.

interface BeforeMarshallCallback {
    void beforeMarshall(Marshaller marshaller);
}

interface AfterMarshallCallback {
    void afterMarshall(Marshaller marshaller);
}

interface BeforeUnmarshallCallback {
    void beforeUnmarshal(Unmarshaller unmarshaller, Object parent);
}

interface AfterUnmarshallCallback {
    void afterUnmarshal(Unmarshaller unmarshaller, Object parent);
}

JAXB Lifecycle

JAXB Model Abstraction

Comprehensive abstraction layer over JAXB model information providing vendor-neutral access to type metadata, property information, and schema details through visitor pattern support.

interface MModelInfo<T, C extends T> extends MCustomizable {
    Collection<MBuiltinLeafInfo<T, C>> getBuiltinLeafInfos();
    Collection<MClassInfo<T, C>> getClassInfos();
    MClassInfo<T, C> getClassInfo(String name);
    Collection<MEnumLeafInfo<T, C>> getEnumLeafInfos();
    Collection<MTypeInfo<T, C>> getTypeInfos();
    MTypeInfo<T, C> getTypeInfo(QName typeNam);
    Collection<MElementInfo<T, C>> getElementInfos();
    MElementInfo<T, C> getGlobalElementInfo(QName elementName);
}

interface MClassInfo<T, C> extends MClassTypeInfo<T, C> {
    List<MPropertyInfo<T, C>> getProperties();
    MPropertyInfo<T, C> getProperty(String publicName);
    QName getElementName();
}

JAXB Model Abstraction

Utility Classes

Essential utility classes for string manipulation, class name handling, validation, JAXB context management, and XML Schema constants.

class StringUtils {
    static boolean isEmpty(String str);
    static String[] split(String str, char separatorChar);
    static String join(Iterator iterator, String separator);
}

class ClassUtils {
    static String getShortClassName(Class cls);
    static String getShortClassName(String className);
}

class ContextUtils {
    static String getContextPath(Class<?>... classes);
    static String toString(JAXBContext context, Object object);
}

Utilities