Skip to content

Commit

Permalink
Code optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
CesarCoelho committed Oct 8, 2024
1 parent 08868de commit 5617d47
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,27 +446,29 @@ private static XsdSpecification loadXsdSpecification(final File file) throws IOE
}

private void loadGenerators(final org.apache.maven.plugin.logging.Log logger) {
if (!generatorsLoaded) {
generatorsLoaded = true;

final Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forClassLoader())
.setScanners(new SubTypesScanner()));

final Set<Class<? extends Generator>> classes = reflections.getSubTypesOf(Generator.class);

for (Class<? extends Generator> cls : classes) {
final int mods = cls.getModifiers();
if (!Modifier.isAbstract(mods)) {
try {
final Generator g = (Generator) cls.getConstructor(new Class[]{
org.apache.maven.plugin.logging.Log.class
}).newInstance(new Object[]{logger});

GENERATOR_MAP.put(g.getShortName().toLowerCase(), g);
} catch (Exception ex) {
logger.warn("Could not construct generator : " + cls.getName());
}
if (generatorsLoaded) {
return;
}

generatorsLoaded = true;

final Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forClassLoader())
.setScanners(new SubTypesScanner()));

final Set<Class<? extends Generator>> classes = reflections.getSubTypesOf(Generator.class);

for (Class<? extends Generator> cls : classes) {
final int mods = cls.getModifiers();
if (!Modifier.isAbstract(mods)) {
try {
final Generator g = (Generator) cls.getConstructor(new Class[]{
org.apache.maven.plugin.logging.Log.class
}).newInstance(new Object[]{logger});

GENERATOR_MAP.put(g.getShortName().toLowerCase(), g);
} catch (Exception ex) {
logger.warn("Could not construct generator : " + cls.getName());
}
}
}
Expand Down Expand Up @@ -501,7 +503,7 @@ private void processWithGenerator(final Generator generator,
// Load the XSD specifications
for (XsdSpecification spec : refXsd) {
try {
generator.loadXSD(spec.getSchema());
generator.loadXSD(spec);
} catch (Exception ex) {
ex.printStackTrace();
throw new MojoExecutionException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
package esa.mo.tools.stubgen;

import esa.mo.xsd.util.XmlSpecification;
import esa.mo.xsd.util.XsdSpecification;
import java.io.IOException;
import java.util.Map;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import w3c.xsd.Schema;

/**
* Interface class for a language generator.
Expand Down Expand Up @@ -98,12 +98,12 @@ void postinit(String destinationFolderName,
/**
* Load an XSD specification in the type definitions.
*
* @param spec The schema spec to process.
* @param xsd The sd schema spec to process.
* @throws IOException If there are problems reading the file.
* @throws JAXBException If there are problems reading any XML Schema
* definitions.
*/
void loadXSD(Schema spec) throws IOException, JAXBException;
void loadXSD(XsdSpecification xsd) throws IOException, JAXBException;

/**
* Generates the specification into the appropriate form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import esa.mo.tools.stubgen.writers.TargetWriter;
import esa.mo.xsd.*;
import esa.mo.xsd.util.XmlSpecification;
import esa.mo.xsd.util.XsdSpecification;
import java.io.IOException;
import java.util.*;
import javax.xml.bind.JAXBElement;
Expand Down Expand Up @@ -128,7 +129,8 @@ public void loadXML(XmlSpecification xml) throws IOException, JAXBException {
}

@Override
public void loadXSD(Schema spec) throws IOException, JAXBException {
public void loadXSD(XsdSpecification xsd) throws IOException, JAXBException {
Schema spec = xsd.getSchema();
// load in types
if (spec.getSimpleTypeOrComplexTypeOrGroup() != null) {
loadTypesFromXsdList(StdStrings.XML, spec.getTargetNamespace(),
Expand Down

0 comments on commit 5617d47

Please sign in to comment.