Skip to content

Commit

Permalink
Review notes applied. Copyright headers fixed.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus committed Sep 20, 2021
1 parent b7a0c3d commit c03a07f
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -19,8 +19,6 @@
import org.eclipse.persistence.internal.helper.*;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.logging.AbstractSessionLog;
import org.eclipse.persistence.logging.SessionLog;

/**
* <p><b>Purpose</b>: IntegrityChecker is used for catching all the descriptor exceptions,
Expand Down Expand Up @@ -150,7 +148,6 @@ public Vector getTables() {
* This method will throw the exception or add the exceptions into a vector depending on the value of shouldCatchExceptions.
*/
public void handleError(RuntimeException runtimeException) {
SessionLog log = AbstractSessionLog.getLog();
if (!shouldCatchExceptions()) {
throw runtimeException;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
requires java.desktop;
requires java.naming;
requires java.xml;
requires java.logging;

requires transitive jakarta.xml.bind;
requires jakarta.activation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,6 @@ static class ContextPathInput extends JAXBContextInput {

@Override
protected JAXBContextState createContextState() throws jakarta.xml.bind.JAXBException {
SessionLog log = AbstractSessionLog.getLog();
boolean foundMetadata = false;
List<Class> classes = new ArrayList<>();

Expand Down Expand Up @@ -934,24 +933,11 @@ protected JAXBContextState createContextState() throws jakarta.xml.bind.JAXBExce
return new JAXBContextState(xmlContext);
} catch (Exception exception) {
sessionLoadingException = exception;
log.log(SessionLog.INFO, "EROR -- XMLContext");
Throwable curr = exception;
int count = 0;
while(curr != null && count++ < 10) {
log.log(SessionLog.INFO, curr.getMessage());
StackTraceElement[] els = curr.getStackTrace();
for (StackTraceElement el : els) {
log.log(SessionLog.INFO, String.format(" - %s", el.toString()));
}
curr = curr.getCause();
}

}
JAXBException jaxbException = JAXBException.noObjectFactoryOrJaxbIndexInPath(contextPath);
if (sessionLoadingException != null) {
jaxbException.setInternalException(sessionLoadingException);
}
log.logThrowable(SessionLog.INFO, jaxbException);
throw new jakarta.xml.bind.JAXBException(jaxbException);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -35,12 +35,12 @@ public class JAXBContextProperties {
* Default {@code JAXBContextFactory} will be used when this property
* is not set.
*/
public static final String MOXY_FACTORY_TYPE = "eclipselink.moxy.factory.type";
public static final String MOXY_FACTORY = "eclipselink.moxy.factory";

/**
* Supported values of {@code eclipselink.moxy.factory.type} property.
* Supported values of {@code eclipselink.moxy.factory} property.
*/
public static final class FactoryType {
public static final class Factory {
/** Use default {@code JAXBContextFactory} for context creation. */
public static final String DEFAULT = "default";
/** Use {@code DynamicJAXBContextFactory} for context creation. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,50 @@ public XMLBindingContextFactory() {
//no-op
}

@FunctionalInterface
private interface ContextSupplier {
JAXBContext get() throws JAXBException;
}

// PERF: null check is much faster than instanceof for missing property
@SuppressWarnings({"SwitchStatementWithTooFewBranches", "ConditionCoveredByFurtherCondition"})
private static JAXBContext context(final Map<String, ?> map,
final ContextSupplier defaultValue, final ContextSupplier dynamicValue) throws JAXBException {
Object value = map.get(JAXBContextProperties.MOXY_FACTORY_TYPE);
if (value == null || !String.class.isInstance(value)) {
return defaultValue.get();
}
// More suppliers may be added here
switch ((String) value) {
case JAXBContextProperties.FactoryType.DYNAMIC:
return dynamicValue.get();
default:
return defaultValue.get();
}
}

@Override
public JAXBContext createContext(Class<?>[] types, Map<String, ?> map) throws JAXBException {
return context(map,
() -> JAXBContextFactory.createContext(types, map),
() -> DynamicJAXBContextFactory.createContext(types, (Map<String, Object>) map)
);
Object value = map != null ? map.get(JAXBContextProperties.MOXY_FACTORY) : null;
// Property vas not set, use default factory
if (value == null) {
return JAXBContextFactory.createContext(types, map);
}
// Handle valid String properties
if (String.class.isInstance(value)) {
switch ((String) value) {
case JAXBContextProperties.Factory.DEFAULT:
return JAXBContextFactory.createContext(types, map);
case JAXBContextProperties.Factory.DYNAMIC:
return DynamicJAXBContextFactory.createContext(types, (Map<String, Object>) map);
default:
throw new JAXBException(String.format("Property eclipselink.moxy.factory value \"%s\" is invalid", value));
}
// Non String values are invalid
} else {
throw new JAXBException(String.format("Property eclipselink.moxy.factory value \"%s\" is invalid", value.toString()));
}
}

@Override
public JAXBContext createContext(String string, ClassLoader cl, Map<String, ?> map) throws JAXBException {
return context(map,
() -> JAXBContextFactory.createContext(string, cl, map),
() -> DynamicJAXBContextFactory.createContext(string, cl, (Map<String, Object>) map)
);
Object value = map != null ? map.get(JAXBContextProperties.MOXY_FACTORY) : null;
// Property vas not set, use default factory
if (value == null) {
return JAXBContextFactory.createContext(string, cl, map);
}
// Handle valid String properties
if (String.class.isInstance(value)) {
switch ((String) value) {
case JAXBContextProperties.Factory.DEFAULT:
return JAXBContextFactory.createContext(string, cl, map);
case JAXBContextProperties.Factory.DYNAMIC:
return DynamicJAXBContextFactory.createContext(string, cl, (Map<String, Object>) map);
default:
throw new JAXBException(String.format("Property eclipselink.moxy.factory value \"%s\" is invalid", value));
}
// Non String values are invalid
} else {
throw new JAXBException(String.format("Property eclipselink.moxy.factory value \"%s\" is invalid", value.toString()));
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -3809,7 +3809,7 @@ private JavaClass processXmlElementDecl(JavaClass type, JavaMethod next, Package
String url;
String localName;
String defaultValue = null;
Class<XmlElementDecl.GLOBAL> scopeClass = jakarta.xml.bind.annotation.XmlElementDecl.GLOBAL.class;
Class<?> scopeClass = jakarta.xml.bind.annotation.XmlElementDecl.GLOBAL.class;

if (xmlEltDecl != null) {
url = xmlEltDecl.getNamespace();
Expand Down Expand Up @@ -3841,7 +3841,7 @@ private JavaClass processXmlElementDecl(JavaClass type, JavaMethod next, Package
XmlElementDecl elementDecl = (XmlElementDecl) helper.getAnnotation(next, XmlElementDecl.class);
url = elementDecl.namespace();
localName = elementDecl.name();
scopeClass = (Class<XmlElementDecl.GLOBAL>) elementDecl.scope();
scopeClass = elementDecl.scope();
if (!elementDecl.substitutionHeadName().equals(EMPTY_STRING)) {
String subHeadLocal = elementDecl.substitutionHeadName();
String subHeadNamespace = elementDecl.substitutionHeadNamespace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void testNewInstanceXSDExternalBinding() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(DynamicJAXBContextFactory.XML_SCHEMA_KEY, xsdSource);
properties.put(DynamicJAXBContextFactory.EXTERNAL_BINDINGS_KEY, xjbSource);
properties.put(JAXBContextProperties.MOXY_FACTORY_TYPE, JAXBContextProperties.FactoryType.DYNAMIC);
properties.put(JAXBContextProperties.MOXY_FACTORY, JAXBContextProperties.Factory.DYNAMIC);

// Have to include a path to a jaxb.properties, so just reusing a context path that does contain one.
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.eclipse.persistence.testing.jaxb.dynamic", classLoader, properties);
Expand Down Expand Up @@ -311,7 +311,7 @@ public void testNewInstanceXSDExternalBindings() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(DynamicJAXBContextFactory.XML_SCHEMA_KEY, xsdSource);
properties.put(DynamicJAXBContextFactory.EXTERNAL_BINDINGS_KEY, extBindings);
properties.put(JAXBContextProperties.MOXY_FACTORY_TYPE, JAXBContextProperties.FactoryType.DYNAMIC);
properties.put(JAXBContextProperties.MOXY_FACTORY, JAXBContextProperties.Factory.DYNAMIC);

// Have to include a path to a jaxb.properties, so just reusing a context path that does contain one.
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.eclipse.persistence.testing.jaxb.dynamic", classLoader, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
// rbarkhouse - 2010-03-04 12:22:11 - initial implementation
package org.eclipse.persistence.testing.jaxb.dynamic;

import java.net.URL;
import java.util.*;

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.internal.dynamic.DynamicEntityImpl;
import org.eclipse.persistence.internal.helper.Helper;
Expand All @@ -30,7 +22,24 @@
import org.eclipse.persistence.oxm.NamespaceResolver;
import org.eclipse.persistence.oxm.XMLRoot;
import org.eclipse.persistence.testing.jaxb.JAXBTestCases;
import org.w3c.dom.*;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

public class DynamicJAXBFromSessionsXMLTestCases extends JAXBTestCases {

Expand Down Expand Up @@ -63,7 +72,7 @@ public class DynamicJAXBFromSessionsXMLTestCases extends JAXBTestCases {

private static final Map<String, Object> PROPERTIES = new HashMap<>(1);
static {
PROPERTIES.put(JAXBContextProperties.MOXY_FACTORY_TYPE, JAXBContextProperties.FactoryType.DYNAMIC);
PROPERTIES.put(JAXBContextProperties.MOXY_FACTORY, JAXBContextProperties.Factory.DYNAMIC);
}

protected ArrayList objectsAlreadyCheckedForEquality;
Expand All @@ -73,7 +82,7 @@ public DynamicJAXBFromSessionsXMLTestCases(String name) throws Exception {

setControlDocument(XML_RESOURCE);

// Calling newInstance requires eclipselink.moxy.factory.type="dynamic" to end up in DynamicJAXBContextFactory.createContext
// Calling newInstance requires eclipselink.moxy.factory="dynamic" to end up in DynamicJAXBContextFactory.createContext
jaxbContext = DynamicJAXBContext.newInstance(SESSION_NAMES, Thread.currentThread().getContextClassLoader(), PROPERTIES);
jaxbMarshaller = jaxbContext.createMarshaller();
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -21,16 +21,16 @@
import junit.framework.TestCase;

import org.eclipse.persistence.exceptions.XMLMarshalException;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jaxb.JAXBValidator;
import org.eclipse.persistence.jaxb.XMLBindingContextFactory;
import org.eclipse.persistence.platform.xml.XMLPlatformException;

public class NoSchemaRefTestCases extends TestCase {

public void testValidateRootNoSchemaReference() {
try {
Class[] classes = {Address.class};
JAXBContext jc = (JAXBContext) JAXBContextFactory.createContext(classes, null);
Class<?>[] classes = {Address.class};
JAXBContext jc = (JAXBContext) new XMLBindingContextFactory().createContext(classes, null);
JAXBValidator validator = jc.createValidator();
validator.validateRoot(new Address());
} catch(ValidationException e) {
Expand All @@ -45,8 +45,8 @@ public void testValidateRootNoSchemaReference() {

public void testValidateNoSchemaReference() throws JAXBException {
try {
Class[] classes = {Address.class};
JAXBContext jc = (JAXBContext) JAXBContextFactory.createContext(classes, null);
Class<?>[] classes = {Address.class};
JAXBContext jc = (JAXBContext) new XMLBindingContextFactory().createContext(classes, null);
JAXBValidator validator = jc.createValidator();
validator.validate(new Address());
} catch (ValidationException e) {
Expand Down

0 comments on commit c03a07f

Please sign in to comment.