Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:14:55+00:00 2026-06-17T09:14:55+00:00

I’m currently trying to model the Spring LDAP Filters in my XML schema. This

  • 0

I’m currently trying to model the Spring LDAP Filters in my XML schema. This involves polymorphic types, which can be arbitrarily nested:

<andFilter>
  <notFilter>
     <equalsFilter name="mail" value="asfd@example.com" />
  </notFilter>
  <likeFilter name="mail" value="asdf*" />
</andFilter>

This is how I’m defining the above filters in my xsd (I actually have some intermediate abstract types defined, but left them out for simplicity):

<xsd:complexType name="baseFilterType" abstract="true" />
<xsd:element name="filter" type="tns:baseFilterType" />

<xsd:complexType name="andFilterType">
  <xsd:sequence>
    <xsd:element ref="tns:filter" minOccurs="1" maxOccurs="unbounded" />
  </xsd:sequence>
</xsd:complexType>
<xsd:element name="andFilter" type="tns:andFilterType" substitutionGroup="tns:filter" />

<xsd:complexType name="notFilterType">
  <xsd:sequence>
    <xsd:element ref="tns:filter" />
  </xsd:sequence>
</xsd:complexType>
<xsd:element name="notFilter" type="tns:notFilterType" substitutionGroup="tns:filter" />

<xsd:complexType name="likeFilterType">
  <xsd:sequence>
    <xsd:element ref="tns:attributeName" />
    <xsd:element ref="tns:value" />
  </xsd:sequence>
</xsd:complexType>
<xsd:element name="likeFilter" type="tns:likeFilterType" substitutionGroup="tns:filter" />

<xsd:complexType name="equalsFilterType">
  <xsd:sequence>
    <xsd:element ref="tns:attributeName" />
    <xsd:element ref="tns:value" />
  </xsd:sequence>
</xsd:complexType>
<xsd:element name="equalsFilter" type="tns:equalsFilterType" substitutionGroup="tns:filter" />

I’ve extended each of the filter classes with some custom behavior (to implement the visitor pattern), but I can’t figure out how to have JAXB bind to those instead of JAXBElement<? extends BaseFilterType> that’s used throughout the generated classes.

The JAXB model classes are generated at build time, and so I can’t modify them directly — I must use external custom bindings for any customizations. I’ve tried the implClass and baseClass customizations but haven’t been able to figure out how to do it.

Can anyone help?

Edit: I’m using Spring’s Jaxb2Marshaller with contextPaths set for marshalling and unmarshalling. I expected this to utilize ObjectFactory for object instantiation, but that doesn’t seem to be the case.

Edit 2: The filter elements are referenced by the top-level element as well as by each other, like:

<xsd:element name="GetAttributesRequest">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element ref="filter:filter" />
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

So, the GetAttributesRequest object will be marked with @XmlRootElement while the filter classes themselves will not be. However, even the top-level GetAttributesRequest object isn’t being instantiated by ObjectFactory…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:14:56+00:00Added an answer on June 17, 2026 at 9:14 am

    Edit :

    Solution used by question author :

    I ended up using JAXB binding customizations to make the ObjectFactory
    produce instances of my classes, and then set the
    com.sun.xml.internal.bind.ObjectFactory (note the internal)
    unmarshaller property on Spring’s Jaxb2Marshaller to force it to use
    the factory.


    Original answer :

    Yes, it’s possible to add behaviors to the generated classes. You want to have a look at the related documentation

    Here’s a simple example from the documentation :

    JAXB Generated Code

    package org.acme.foo;
    
    @XmlRootElement
    class Person {
      private String name;
    
      public String getName() { return name; }
      public void setName(String) { this.name=name; }
    }
    
    @XmlRegistry
    class ObjectFactory {
      Person createPerson() { ... }
    }
    

    Extended class

    package org.acme.foo.impl;

    class PersonEx extends Person {
      @Override
      public void setName(String name) {
        if(name.length()<3) throw new IllegalArgumentException();
        super.setName(name);
      }
    }
    
    @XmlRegistry
    class ObjectFactoryEx extends ObjectFactory {
      @Override
      Person createPerson() {
        return new PersonEx();
      }
    }
    

    Example of Unmarshalling

    Unmarshaller u = context.createUnmarshaller();
    u.setProperty("com.sun.xml.bind.ObjectFactory",new ObjectFactoryEx());
    PersonEx p = (PersonEx)u.unmarshal(new StringReader("<person />"));
    

    More info here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.