Skip to content

Commit

Permalink
[#309] Merge annox
Browse files Browse the repository at this point in the history
NOTE: po project still not functional due to need for modernization in testing
  • Loading branch information
mattrpav committed Aug 17, 2023
1 parent f4071fc commit d74d648
Show file tree
Hide file tree
Showing 214 changed files with 10,246 additions and 159 deletions.
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Copyright (c) 2021-2023, Matt Pavlovich.
Copyright (c) 2005-2021, Alexey Valikov.

All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand All @@ -21,4 +23,3 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,25 @@ JAXB2 Basics can only be used with Java 1.8 and above.
## Credits ##

* Many thanks to **James Annesley** for his ideas and help with the [SimpleEquals Plugin](https://github.com/highsource/jaxb2-basics/wiki/JAXB2-SimpleEquals-Plugin) and the [SimpleHashCode Plugin](https://github.com/highsource/jaxb2-basics/wiki/JAXB2-SimpleHashCode-Plugin).


Annox
=====

Parse Java annotations from text or XML resources.

```java
// Parse annotation from the string
XAnnotation<XmlRootElement> xannotation =
(XAnnotation<XmlRootElement>) XAnnotationParser.INSTANCE.parse
("@javax.xml.bind.annotation.XmlRootElement(name=\"foo\")");

// Create an instance of the annotation
XmlRootElement xmlRootElement = xannotation.getResult();
assertEquals("foo", xmlRootElement.name());
assertEquals("##default", xmlRootElement.namespace());

// Analyze the structure of the annotation
assertEquals(String.class, xannotation.getFieldsMap().get("name").getType());
assertEquals("##default", xannotation.getFieldsMap().get("namespace").getResult());
```
4 changes: 4 additions & 0 deletions jaxb-annox-parent/jaxb-annox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
.settings
.project
.classpath
1 change: 1 addition & 0 deletions jaxb-annox-parent/jaxb-annox/META-INF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/MANIFEST.MF
29 changes: 29 additions & 0 deletions jaxb-annox-parent/jaxb-annox/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Created-By: 17.0.3.1 (Oracle Corporation)
Tool: Bnd-1.15.0
Bnd-LastModified: 1692302035692
Export-Package: org.jvnet.annox,org.jvnet.annox.annotation;uses:="org.ap
ache.commons.lang3",org.jvnet.annox.io,org.jvnet.annox.model;uses:="org
.apache.commons.lang3,org.jvnet.annox.parser,org.jvnet.annox.reflect,or
g.apache.commons.lang3.builder",org.jvnet.annox.parser;uses:="org.jvnet
.annox.model,org.jvnet.annox.util,org.jvnet.annox.annotation,org.jvnet.
annox,org.apache.commons.lang3",org.jvnet.annox.reader;uses:="org.jvnet
.annox.model,org.jvnet.annox.reflect",org.jvnet.annox.reader.resourced;
uses:="org.apache.commons.lang3,org.jvnet.annox.io,org.jvnet.annox.mode
l,org.jvnet.annox.util,org.jvnet.annox.parser,org.jvnet.annox.reflect,o
rg.jvnet.annox.reader",org.jvnet.annox.reflect;uses:="org.jvnet.annox.r
eader.resourced,org.jvnet.annox.model,org.apache.commons.lang3,org.jvne
t.annox.reader",org.jvnet.annox.util;uses:="org.jvnet.annox,org.apache.
commons.lang3",org.jvnet.annox.xml.bind;uses:="org.jvnet.annox.reflect"
Import-Package: org.apache.commons.lang3;version="3.2.1",org.apache.comm
ons.lang3.builder;version="3.2.1"
Bundle-Version: 2.0.5.SNAPSHOT
Bundle-SymbolicName: org.jvnet.jaxb.annox
Bundle-License: https://github.com/highsource/jaxb-tools/blob/master/LIC
ENSE
Bundle-Description: JAXB Annox is a part of JAXB Tools project which imp
lements support for reading and writing XML annotations.
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Name: JAXB Tools :: JAXB Annox

107 changes: 107 additions & 0 deletions jaxb-annox-parent/jaxb-annox/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-annox-parent</artifactId>
<version>2.0.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-annox</artifactId>
<packaging>jar</packaging>
<name>JAXB Tools :: JAXB Annox</name>
<properties>
<annox.osgi.version>${project.version}</annox.osgi.version>
<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.google.code.javaparser</groupId>
<artifactId>javaparser</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>3.0.0.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.2.0</version>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
</supportedProjectTypes>
<manifestLocation>META-INF</manifestLocation>
<instructions>
<Bundle-Version>${annox.osgi.version}</Bundle-Version>
<Import-Package>
org.apache.commons.lang3;version="3.2.1",
org.apache.commons.lang3.builder;version="3.2.1"
</Import-Package>
<Export-Package>
org.jvnet.annox,
org.jvnet.annox.annotation,
org.jvnet.annox.io,
org.jvnet.annox.model,
org.jvnet.annox.parser,
org.jvnet.annox.reader,
org.jvnet.annox.reader.resourced,
org.jvnet.annox.reflect,
org.jvnet.annox.util,
org.jvnet.annox.xml.bind
</Export-Package>
<Bundle-RequiredExecutionEnvironment>J2SE-1.5</Bundle-RequiredExecutionEnvironment>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestFile>META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>

</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jvnet.annox;

public class Constants {

public static final String NAMESPACE_URI = "http://annox.dev.java.net";

public static final String NAMESPACE_URI_PREFIX = NAMESPACE_URI + "/";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jvnet.annox.annotation;

import org.apache.commons.lang3.Validate;

public class AnnotationClassNotFoundException extends Exception {

private static final long serialVersionUID = 1L;

private String className;

public AnnotationClassNotFoundException(String className, Throwable cause) {
super("Annotation class [" + className + "] could not be found.", cause);
Validate.notNull(className);
this.className = className;
}

public String getClassName() {
return className;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jvnet.annox.annotation;

import java.lang.annotation.Annotation;

public class NoSuchAnnotationFieldException extends Exception {

private static final long serialVersionUID = 1L;

private final Class<? extends Annotation> annotationType;

private final String name;

public NoSuchAnnotationFieldException(
final Class<? extends Annotation> annotationType,
final String name, Throwable cause) {
super("No such annotation field [" + name + "] in annotation class ["
+ (annotationType == null ? "null" : annotationType.getName())
+ "].", cause);
this.annotationType = annotationType;
this.name = name;
}

public Class<? extends Annotation> getAnnotationType() {
return annotationType;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jvnet.annox.io;

import java.io.IOException;

public class NestedIOException extends IOException {

private static final long serialVersionUID = 1L;

public NestedIOException(Throwable cause) {
super();
initCause(cause);
}

public NestedIOException(String msg, Throwable cause) {
super(msg);
initCause(cause);
}

public String getMessage() {
return buildMessage(super.getMessage(), getCause());
}

public static String buildMessage(String message, Throwable cause) {
if (cause != null) {
StringBuffer buf = new StringBuffer();
if (message != null) {
buf.append(message).append("; ");
}
buf.append("nested exception is ").append(cause);
return buf.toString();
} else {
return message;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.jvnet.annox.japa.parser;

import japa.parser.JavaParser;
import japa.parser.ParseException;
import japa.parser.ast.CompilationUnit;
import japa.parser.ast.body.ClassOrInterfaceDeclaration;
import japa.parser.ast.body.TypeDeclaration;
import japa.parser.ast.expr.AnnotationExpr;

import java.io.StringReader;
import java.text.MessageFormat;
import java.util.List;

import org.apache.commons.lang3.Validate;

public class AnnotationExprParser {

public List<AnnotationExpr> parse(String text) throws ParseException {
Validate.notNull(text);
final String classText = text + "\n" + "public class Dummy{}";
final StringReader reader = new StringReader(classText);
final CompilationUnit compilationUnit = JavaParser.parse(reader, true);
final List<TypeDeclaration> typeDeclarations = compilationUnit
.getTypes();
if (typeDeclarations.size() > 1) {
throw new ParseException(
MessageFormat
.format("Annotation [{0}] could not be parsed, it contains an unexpected type declaration.",
text));
}
final TypeDeclaration typeDeclaration = typeDeclarations.get(0);
if (!(typeDeclaration instanceof ClassOrInterfaceDeclaration)) {
throw new ParseException(MessageFormat.format(
"Expected [{0}] as type declaration.",
ClassOrInterfaceDeclaration.class.getName()));
}
final ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) typeDeclaration;
if (!"Dummy".equals(classDeclaration.getName())) {
throw new ParseException(MessageFormat.format(
"Expected [{0}] as type declaration.", "Dummy"));
}

final List<AnnotationExpr> annotations = typeDeclaration
.getAnnotations();

if (annotations == null || annotations.isEmpty()) {
throw new ParseException(
MessageFormat
.format("Annotation [{0}] could not be parsed, it does not seem to contain an annotation declaration.",
text));
}
return annotations;
}
}
Loading

0 comments on commit d74d648

Please sign in to comment.