Runtime support library for JAXB2 Basics plugins that provides strategic pattern implementations for equals, hashCode, toString, copying, and merging operations on JAXB-generated classes
npx @tessl/cli install tessl/maven-org-jvnet-jaxb2_commons--jaxb2-basics-runtime@1.11.0Runtime 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.
pom.xml:
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>1.11.1</version>
</dependency>import org.jvnet.jaxb2_commons.lang.*;
import org.jvnet.jaxb2_commons.locator.*;For JAXB lifecycle callbacks:
import org.jvnet.jaxb2_commons.xml.bind.*;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);
}
}The library is built around the Strategy Pattern, providing pluggable implementations for common object operations:
This architecture enables consistent, high-performance operations across complex JAXB object hierarchies while maintaining full type safety and providing detailed error reporting capabilities.
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);
}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);
}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);
}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();
}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);
}