/*
 * Copyright 2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.bremersee.comparator;

import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;

import java.util.Collection;
import java.util.List;
import javax.xml.bind.annotation.XmlSchema;
import org.bremersee.comparator.model.ObjectFactory;
import org.bremersee.xml.JaxbContextData;
import org.bremersee.xml.JaxbContextDataProvider;

/**
 * The comparator jaxb context data provider.
 *
 * @author Christian Bremer
 */
public class ComparatorJaxbContextDataProvider implements JaxbContextDataProvider {

  /**
   * Gets namespace.
   *
   * @return the namespace
   */
  public static String getNamespace() {
    XmlSchema xmlSchema = findAnnotation(ObjectFactory.class.getPackage(), XmlSchema.class);
    if (xmlSchema != null && xmlSchema.namespace().trim().length() > 0) {
      return xmlSchema.namespace().trim();
    }
    throw new IllegalStateException("Comparator model is missing xml namespace.");
  }

  @Override
  public Collection<JaxbContextData> getJaxbContextData() {
    return List.of(new JaxbContextData(ObjectFactory.class.getPackage()));
  }
}

@@ -780,16 +780,43 @@
 l.List;%0A
+import java.util.Optional;%0A
 import j
@@ -1280,30 +1280,35 @@
     
-XmlSchema xmlSchema = 
+return Optional.ofNullable(
 find
@@ -1372,17 +1372,25 @@
 ass)
-;
+)
 %0A    
-if 
+    .filter
 (xml
@@ -1400,18 +1400,10 @@
 ema 
-!= null &&
+-%3E
  xml
@@ -1445,23 +1445,34 @@
 %3E 0)
- %7B
 %0A      
-return
+  .map(xmlSchema -%3E
  xml
@@ -1500,25 +1500,36 @@
 im()
-;
+)
 %0A    
-%7D%0A
     
-throw
+.orElseThrow(() -%3E
  new
@@ -1551,16 +1551,29 @@
 ception(
+%0A            
 %22Compara
@@ -1609,16 +1609,17 @@
 space.%22)
+)
 ;%0A  %7D%0A%0A 

Version 3.0.0-SNAPSHOT