The jaxb2-maven-plugin wraps and adapts the JAXB reference implementation
3 | * to be useful within the Maven build process.
4 | *
The plugin's code is divided into 3 main blocks, each placed within a separate package structure:
5 | *
6 | *
7 | *
javageneration. Contains code involved in creating java code from XSD or DTDs.
8 | * This package structure adapts the plugin to using the XJC ("Xml-to-Java-Compiler") from the
9 | * JAXB reference implementation.
10 | *
schemageneration. Contains code involved in creating XSDs from annotated Java classes.
11 | * This package structure adapts the plugin to using the schemagen tool from the JDK. (Typically found in the
12 | * bin directory of the java installation).
13 | *
shared. Contains shared utility classes used by both the java- and xsd-generation
14 | * structure classes.
The jaxb2-maven-plugin wraps and adapts the JAXB reference implementation
3 | * to be useful within the Maven build process.
4 | *
The schemageneneration package (including subpackages) contains Mojos for generating XSD files from
5 | * annotated Java classes. It also contains subpackages for post-processing the results of the schemagen tool,
6 | * to create XSDs with better usability than the XSDs generated by default.
7 | *
8 | * @author Lennart Jörelid
9 | * @see The JAXB Reference Implementation
10 | */
11 | package org.codehaus.mojo.jaxb2.schemageneration;
12 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/NodeProcessor.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.schemageneration.postprocessing;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | import org.w3c.dom.Node;
23 |
24 | /**
25 | * Processor/visitor pattern specification for DOM Nodes.
26 | *
27 | * @author Lennart Jörelid
28 | * @since 1.4
29 | */
30 | public interface NodeProcessor {
31 |
32 | /**
33 | * Defines if this visitor should process the provided node.
34 | *
35 | * @param aNode The DOM node to process.
36 | * @return true if the provided Node should be processed by this NodeProcessor.
37 | */
38 | boolean accept(Node aNode);
39 |
40 | /**
41 | * Processes the provided DOM Node.
42 | *
43 | * @param aNode The DOM Node to process.
44 | */
45 | void process(Node aNode);
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/NoAuthorJavaDocRenderer.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | /**
23 | *
Default JavaDocRenderer implementation which provides a plain JavaDocData rendering, while skipping
24 | * output from the {@code author} tag, on the form:
30 | *
31 | * @author Lennart Jörelid, jGuru Europe AB
32 | * @since 2.3
33 | */
34 | public class NoAuthorJavaDocRenderer extends DefaultJavaDocRenderer {
35 |
36 | /**
37 | * The author key.
38 | */
39 | private static final String AUTHOR_KEY = "author";
40 |
41 | /**
42 | * {@inheritDoc}
43 | */
44 | @Override
45 | protected String renderJavaDocTag(final String name, final String value, final SortableLocation location) {
46 |
47 | // Don't render the author
48 | if (AUTHOR_KEY.equalsIgnoreCase(name)) {
49 | return "";
50 | }
51 |
52 | // Delegate.
53 | return super.renderJavaDocTag(name, value, location);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/schemageneration/postprocessing/javadoc/SortableLocation.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | import jakarta.xml.bind.annotation.XmlAttribute;
23 | import jakarta.xml.bind.annotation.XmlElement;
24 | import jakarta.xml.bind.annotation.XmlType;
25 |
26 | /**
27 | * Common specification for a JavaDoc location which can be compared and sorted.
28 | * JavaDoc locations must be comparable and also convert-able to unique strings.
29 | *
30 | * @author Lennart Jörelid, jGuru Europe AB
31 | * @since 2.0
32 | */
33 | public interface SortableLocation extends Comparable {
34 |
35 | /**
36 | * Validates if the supplied path is equal to this SortableLocation.
37 | *
38 | * @param path The non-null path to compare to this SortableLocation.
39 | * @return {@code true} if this SortableLocation is equal to the supplied path.
40 | */
41 | boolean isEqualToPath(final String path);
42 |
43 | /**
44 | * Retrieves the path of this SortableLocation. The path must uniquely correspond to each unique SortableLocation,
45 | * implying that SortableLocations could be sorted and compared for equality using the path property.
46 | *
47 | * @return the path of this SortableLocation. Never null.
48 | */
49 | String getPath();
50 |
51 | /**
52 | * Retrieves the value of the name attribute provided by a JAXB annotation, implying that
53 | * the XSD type should use another name than the default.
54 | *
55 | * @return the value of the name attribute provided by a JAXB annotation relevant to this {@link SortableLocation}.
56 | * @see XmlElement#name()
57 | * @see XmlAttribute#name()
58 | * @see XmlType#name()
59 | */
60 | String getAnnotationRenamedTo();
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/JavaVersion.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | /**
23 | * Helper to extract the runtime Java version from the System.properties.
24 | *
25 | * @author Lennart Jörelid
26 | * @since 2.4
27 | */
28 | public final class JavaVersion {
29 |
30 | private static final String JAVA_VERSION_PROPERTY = "java.specification.version";
31 |
32 | /**
33 | * Retrieves the major java runtime version as an integer.
34 | *
35 | * @return the major java runtime version as an integer.
36 | */
37 | public static int getJavaMajorVersion() {
38 |
39 | final String[] versionElements =
40 | System.getProperty(JAVA_VERSION_PROPERTY).split("\\.");
41 | final int[] versionNumbers = new int[versionElements.length];
42 |
43 | for (int i = 0; i < versionElements.length; i++) {
44 | try {
45 | versionNumbers[i] = Integer.parseInt(versionElements[i]);
46 | } catch (NumberFormatException e) {
47 | versionNumbers[i] = 0;
48 | }
49 | }
50 |
51 | /*
52 | Java versions 1 - 8 (i.e. jdk 1.1 through 1.8) yields the structure 1.8
53 | Java versions 9 - yields the structure 10
54 |
55 | JDK 10
56 | ======
57 | [java.specification.version]: 10
58 |
59 | JDK 8
60 | =====
61 | [java.specification.version]: 1.8
62 |
63 | JDK 7
64 | =====
65 | [java.specification.version]: 1.7
66 | */
67 | return versionNumbers[0] == 1 ? versionNumbers[1] : versionNumbers[0];
68 | }
69 |
70 | /**
71 | * Checks if the runtime java version is JDK 8 or lower.
72 | *
73 | * @return true if the runtime java version is JDK 8 or lower.
74 | */
75 | public static boolean isJdk8OrLower() {
76 | return getJavaMajorVersion() <= 8;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/environment/AbstractLogAwareFacet.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared.environment;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | import org.apache.maven.plugin.logging.Log;
23 | import org.codehaus.mojo.jaxb2.shared.Validate;
24 |
25 | /**
26 | * Abstract EnvironmentFacet which sports a non-null Maven Log for use by subclasses.
27 | *
28 | * @author Lennart Jörelid, jGuru Europe AB
29 | * @since 2.1
30 | */
31 | public abstract class AbstractLogAwareFacet implements EnvironmentFacet {
32 |
33 | // Internal state
34 | protected Log log;
35 |
36 | /**
37 | * Creates an AbstractLogAwareFacet wrapping the supplied, non-null Log.
38 | *
39 | * @param log The active Maven Log.
40 | */
41 | public AbstractLogAwareFacet(final Log log) {
42 |
43 | // Check sanity
44 | Validate.notNull(log, "log");
45 |
46 | // Assign internal state
47 | this.log = log;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/environment/EnvironmentFacet.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared.environment;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | /**
23 | *
Specification for an Environment controller, which can infer a temporary and reversible change
24 | * to the environment of an executing task. Any changes performed by this Environment
25 | * must be reversible, and should be restored to their original values in the {@code restore()} method.
26 | *
EnvironmentFacets are required since the JDK tools (XJC, SchemaGen, JXC) expect certain configuration
27 | * or setup to be present during their execution. For improved usability within the JAXB2-Maven-Plugin, we
28 | * would like to supply all configuration to the plugin, and delegate the setting of various system-, thread-,
29 | * logging- or environment properties to explicit EnvironmentFacet implementations.
30 | *
31 | * @author Lennart Jörelid, jGuru Europe AB
32 | * @since 2.1
33 | */
34 | public interface EnvironmentFacet {
35 |
36 | /**
37 | * Sets up this Environment, inferring temporary changes to environment variables or conditions.
38 | * The changes must be reversible, and should be restored to their original values in the {@code restore()} method.
39 | */
40 | void setup();
41 |
42 | /**
43 | * Restores the original Environment, implying that the change performed in {@code setup()}
44 | * method are restored to the state before the setup method was called.
45 | */
46 | void restore();
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/environment/classloading/ThreadContextClassLoaderHolder.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared.environment.classloading;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | /**
23 | *
Specification for how to restore the original ThreadContext ClassLoader to a Thread.
24 | * When we support JDK 1.7, this should really be an extension of AutoCloseable instead,
25 | * to support the try-with-resources pattern. Typical use:
47 | *
48 | * @author Lennart Jörelid, jGuru Europe AB
49 | * @since 2.0
50 | */
51 | public interface ThreadContextClassLoaderHolder {
52 |
53 | /**
54 | * Restores the original ThreadContext ClassLoader, and nullifies
55 | * any references to the Thread which had its ThreadContext
56 | * ClassLoader altered.
57 | */
58 | void restoreClassLoaderAndReleaseThread();
59 |
60 | /**
61 | * Retrieves the ClassPath held by this ThreadContextClassLoaderHolder as a
62 | * {@code File.pathSeparatorChar}-separated string. This is directly usable as a String argument by
63 | * any external process.
64 | *
65 | * @return the ClassPath as an argument to external processes such as XJC.
66 | */
67 | String getClassPathAsArgument();
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/environment/sysprops/SystemPropertySaveEnvironmentFacet.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared.environment.sysprops;
2 |
3 | import org.apache.maven.plugin.logging.Log;
4 | import org.codehaus.mojo.jaxb2.shared.environment.AbstractLogAwareFacet;
5 |
6 | /**
7 | * EnvironmentFacet which saves the value of a system property for the duration
8 | * of executing a tool. This may be required for tools (such as the XJC tool) which
9 | * may overwrite property values for its own purpose.
10 | *
11 | * Unlike {@link SystemPropertyChangeEnvironmentFacet}, this does not a set a new
12 | * property value itself, just saves the old value and later restores or clears it.
13 | *
14 | * This facet accepts the key of the property to save.
15 | *
16 | * @author Svein Elgstøen
17 | * @since 2.5
18 | */
19 | public final class SystemPropertySaveEnvironmentFacet extends AbstractLogAwareFacet {
20 | private final String key;
21 | private final String originalValue;
22 |
23 | /**
24 | * Creates a SystemPropertySave which will remember the original value of the
25 | * supplied system property for the duration of this SystemPropertySave.
26 | *
27 | * @param key A non-null key.
28 | * @param log The active Maven Log.
29 | */
30 | public SystemPropertySaveEnvironmentFacet(final String key, final Log log) {
31 | // Delegate
32 | super(log);
33 |
34 | // Assign internal state
35 | this.key = key;
36 | this.originalValue = System.getProperty(key);
37 | }
38 |
39 | /**
40 | * {@inheritDoc}
41 | */
42 | @Override
43 | public void restore() {
44 | if (originalValue != null) {
45 | System.setProperty(key, originalValue);
46 | } else {
47 | System.clearProperty(key);
48 | }
49 |
50 | if (log.isDebugEnabled()) {
51 | log.debug("Restored " + toString());
52 | }
53 | }
54 |
55 | /**
56 | * {@inheritDoc}
57 | */
58 | @Override
59 | public void setup() {
60 | // Do nothing, value is saved in constructor
61 |
62 | if (log.isDebugEnabled()) {
63 | log.debug("Setup " + toString());
64 | }
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "SysProp key [" + key + "], saved value: [" + originalValue + "]";
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/filters/Filter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared.filters;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | import org.apache.maven.plugin.logging.Log;
23 |
24 | /**
25 | * Generic Filter specification, whose implementations define if candidate objects should be accepted or not.
26 | *
27 | * @author Lennart Jörelid, jGuru Europe AB
28 | * @since 2.0
29 | */
30 | public interface Filter {
31 |
32 | /**
33 | * Initializes this Filter, and assigns the supplied Log for use by this Filter.
34 | *
35 | * @param log The non-null Log which should be used by this Filter to emit log messages.
36 | */
37 | void initialize(Log log);
38 |
39 | /**
40 | * @return {@code true} if this Filter has been properly initialized (by a call to the {@code initialize} method).
41 | */
42 | boolean isInitialized();
43 |
44 | /**
45 | *
Method that is invoked to determine if a candidate instance should be accepted or not.
46 | * Implementing classes should be prepared to handle {@code null} candidate objects.
47 | *
48 | * @param candidate The candidate that should be tested for acceptance by this Filter.
49 | * @return {@code true} if the candidate is accepted by this Filter and {@code false} otherwise.
50 | * @throws java.lang.IllegalStateException if this Filter is not initialized by a call to the
51 | * initialize method before calling this matchAtLeastOnce method.
52 | */
53 | boolean accept(T candidate) throws IllegalStateException;
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/FileFilterAdapter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared.filters.pattern;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | import java.io.File;
23 | import java.io.FileFilter;
24 |
25 | import org.codehaus.mojo.jaxb2.shared.Validate;
26 | import org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter;
27 | import org.codehaus.mojo.jaxb2.shared.filters.Filter;
28 |
29 | /**
30 | * Filter implementation adapting a FileFilter instance to the Filter interface.
31 | * Delegates the {@link #onCandidate(File)} call to the supplied {@link FileFilter} delegate.
32 | *
33 | * @author Lennart Jörelid, jGuru Europe AB
34 | * @since 2.3
35 | */
36 | public class FileFilterAdapter extends AbstractFilter implements Filter, FileFilter {
37 |
38 | // Internal state
39 | private FileFilter delegate;
40 |
41 | /**
42 | * Compound constructor, creating a FileFilterAdapter using the supplied {@link FileFilter} to determine if
43 | * candidate Files should be accepted.
44 | *
45 | * @param delegate The delegate FileFilter.
46 | */
47 | public FileFilterAdapter(final FileFilter delegate) {
48 | setDelegate(delegate);
49 | }
50 |
51 | /**
52 | * {@inheritDoc}
53 | */
54 | @Override
55 | public boolean isInitialized() {
56 | return super.isInitialized() && delegate != null;
57 | }
58 |
59 | /**
60 | * Assigns the supplied FileFilter delegate.
61 | *
62 | * @param delegate A non-null FileFilter instance.
63 | */
64 | public void setDelegate(final FileFilter delegate) {
65 |
66 | // Check sanity
67 | Validate.notNull(delegate, "delegate");
68 |
69 | // Assign internal state
70 | this.delegate = delegate;
71 | }
72 |
73 | /**
74 | * {@inheritDoc}
75 | */
76 | @Override
77 | protected boolean onCandidate(final File nonNullCandidate) {
78 | return delegate.accept(nonNullCandidate);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/StringConverter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared.filters.pattern;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | /**
23 | * Specification for a converter rendering a T object as a String.
24 | *
25 | * @author Lennart Jörelid, jGuru Europe AB
26 | * @since 2.0
27 | */
28 | public interface StringConverter {
29 |
30 | /**
31 | * Converts the supplied T object to a String.
32 | *
33 | * @param toConvert The T object to convert to a string. Not {@code null}.
34 | * @return The string form of the toConvert object.
35 | */
36 | String convert(T toConvert);
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/filters/pattern/ToStringConverter.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.jaxb2.shared.filters.pattern;
2 |
3 | /*
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | /**
23 | * Trivial converter using the {@code toString()} method to convert a T object to a String.
24 | *
25 | * @author Lennart Jörelid, jGuru Europe AB
26 | * @since 2.0
27 | */
28 | public class ToStringConverter implements StringConverter {
29 |
30 | /**
31 | * {@inheritDoc}
32 | */
33 | @Override
34 | public String convert(final T toConvert) {
35 | return toConvert.toString();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/jaxb2/shared/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
The jaxb2-maven-plugin wraps and adapts the JAXB reference implementation
3 | * to be useful within the Maven build process.
4 | *
The shared package (including subpackages) contains utility classes used by both the java- and
5 | * xsd-generation Mojos.