Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modified internal/scenario events to use separate namespace

  • Loading branch information...
commit f36f57821888c8bff5c65c8ce459057383b0ef94 1 parent f4585bc
@jmfee-usgs jmfee-usgs authored
Showing with 164 additions and 52 deletions.
  1. +2 −1  .classpath
  2. +21 −9 build.xml
  3. +49 −0 etc/quakeml_1.2/AnssEvent-0.1.xsd
  4. +12 −2 etc/quakeml_1.2/QuakeML-1.2.bindings.xml
  5. +5 −4 etc/quakeml_1.2/QuakeML-1.2_jaxb.xsd
  6. +0 −14 etc/quakeml_1.2/QuakeML-BED-1.2_jaxb.xsd
  7. +11 −1 etc/quakeml_1.2/generateBindings.py
  8. +1 −0  etc/test_messages/pt13320000_internal.quakeml
  9. BIN  lib/commons-beanutils-1.7.0.jar
  10. BIN  lib/commons-lang-2.2.jar
  11. BIN  lib/commons-logging-1.1.1.jar
  12. BIN  lib/javaparser-1.0.8.jar
  13. BIN  lib/jaxb-api.jar
  14. BIN  lib/{jaxb-impl.jar → jaxb-impl-2.2.5-2.jar}
  15. BIN  lib/{jaxb-xjc.jar → jaxb-xjc-2.2.5-2.jar}
  16. BIN  lib/jaxb2-basics-0.6.4.jar
  17. BIN  lib/jaxb2-basics-ant-0.6.4.jar
  18. BIN  lib/jaxb2-basics-runtime-0.6.4.jar
  19. BIN  lib/jaxb2-basics-testing-0.6.4.jar
  20. BIN  lib/jaxb2-basics-tools-0.6.4.jar
  21. BIN  lib/jsr173_1.0_api.jar
  22. +26 −6 src/gov/usgs/earthquake/event/ConverterTest.java
  23. +11 −7 src/gov/usgs/earthquake/event/CubeToQuakemlConverter.java
  24. +18 −6 src/gov/usgs/earthquake/event/QuakemlToCubeConverter.java
  25. +8 −2 src/gov/usgs/earthquake/quakeml/Quakeml_1_2_Parser.java
View
3  .classpath
@@ -5,6 +5,7 @@
<classpathentry kind="src" path="gensrc"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="lib/junit-4.7.jar"/>
- <classpathentry kind="lib" path="lib/jaxb-impl.jar"/>
+ <classpathentry kind="lib" path="lib/jaxb-impl-2.2.5-2.jar"/>
+ <classpathentry kind="lib" path="lib/jaxb2-basics-runtime-0.6.4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
30 build.xml
@@ -20,10 +20,8 @@
<fileset id="lib.jars" dir="${lib}">
- <include name="*.jar" />
- <!-- only need this for compilation -->
- <exclude name="jaxb-xjc.jar" />
- <exclude name="junit-4.7.jar" />
+ <include name="jaxb-impl-2.2.5-2.jar"/>
+ <include name="jaxb2-basics-runtime-0.6.4.jar"/>
</fileset>
<path id="classpath">
@@ -39,12 +37,13 @@
<!-- for auto generating classes from xml schema -->
- <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
+ <taskdef name="xjc" classname="org.jvnet.jaxb2_commons.xjc.XJC2Task">
<classpath>
- <pathelement location="${lib}/jaxb-xjc.jar" />
- <pathelement location="${lib}/jaxb-api.jar" />
- <pathelement location="${lib}/jaxb-impl.jar" />
- <pathelement location="${lib}/jsr173_1.0_api.jar" />
+ <fileset dir="${lib}">
+ <include name="jaxb-impl-*.jar"/>
+ <include name="jaxb-xjc-*.jar"/>
+ <include name="jaxb2-basics-ant-*.jar"/>
+ </fileset>
</classpath>
</taskdef>
@@ -83,6 +82,19 @@
<schema dir="${etc}/quakeml_1.2" includes="*_jaxb.xsd" />
<produces dir="${gensrc}/org/quakeml1_2" includes="*" />
<arg value="-enableIntrospection"/>
+ <!-- Wildcard plugin, supports parsing of InternalEvent and ScenarioEvent from non-quakeml namespace -->
+ <arg value="-Xwildcard"/>
+ <classpath>
+ <fileset dir="${basedir}/lib">
+ <!-- JAXB2 Basics library -->
+ <include name="jaxb2-basics-*.jar"/>
+ <!-- JAXB2 Basics library dependencies -->
+ <include name="javaparser-*.jar"/>
+ <include name="commons-beanutils-*.jar"/>
+ <include name="commons-lang-*.jar"/>
+ <include name="commons-logging-*.jar"/>
+ </fileset>
+ </classpath>
</xjc>
<!-- QuakeML RT 1.2 -->
View
49 etc/quakeml_1.2/AnssEvent-0.1.xsd
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://anss.org/xmlns/event/0.1"
+ xmlns="http://anss.org/xmlns/event/0.1"
+ xmlns:bed="http://quakeml.org/xmlns/bed/1.2"
+ elementFormDefault="qualified"
+ attributeFormDefault="qualified">
+
+
+ <xs:annotation>
+ <xs:documentation xml:lang="en">
+ ANSS Internal and Scenario events for use with quakeml 1.2.
+
+ Jeremy Fee &lt;jmfee@usgs.gov&gt;
+ 2013-11-21
+ </xs:documentation>
+ </xs:annotation>
+
+ <!-- include Quakeml BED namespace, so bed:Event can be extended -->
+ <xs:import namespace="http://quakeml.org/xmlns/bed/1.2" schemaLocation="QuakeML-BED-1.2_jaxb.xsd"/>
+
+ <xs:complexType name="InternalEvent">
+ <xs:complexContent>
+ <xs:extension base="bed:Event">
+ <xs:annotation>
+ <xs:documentation>
+ Internal events represent preliminary solutions for actual events.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="ScenarioEvent">
+ <xs:complexContent>
+ <xs:extension base="bed:Event">
+ <xs:annotation>
+ <xs:documentation>
+ Scenario events represent hypothetical events used for planning purposes.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="internalEvent" type="InternalEvent"/>
+ <xs:element name="scenarioEvent" type="ScenarioEvent"/>
+
+</xs:schema>
View
14 etc/quakeml_1.2/QuakeML-1.2.bindings.xml
@@ -1,8 +1,9 @@
-<bindings version="2.0"
+<bindings version="2.1"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
- extensionBindingPrefixes="xjc">
+ xmlns:wildcard="http://jaxb2-commons.dev.java.net/basic/wildcard"
+ extensionBindingPrefixes="xjc wildcard">
<globalBindings
fixedAttributeAsConstantProperty="true"
@@ -36,6 +37,8 @@
<!-- bindings for QuakeML-BED -->
<bindings schemaLocation="QuakeML-BED-1.2_jaxb.xsd" node="/xs:schema">
+ <wildcard:lax/>
+
<schemaBindings map="true">
<package name="org.quakeml_1_2"/>
</schemaBindings>
@@ -85,5 +88,12 @@
</bindings>
+ <!-- bindings for AnssEvent -->
+ <bindings schemaLocation="AnssEvent-0.1.xsd" node="/xs:schema">
+ <schemaBindings>
+ <package name="org.quakeml_1_2"/>
+ </schemaBindings>
+ </bindings>
+
</bindings>
View
9 etc/quakeml_1.2/QuakeML-1.2_jaxb.xsd
@@ -20,16 +20,17 @@ Jeremy Fee <jmfee@usgs.gov>
2013-03-01
-->
-
+
<xs:import namespace="http://quakeml.org/xmlns/bed/1.2" schemaLocation="QuakeML-BED-1.2_jaxb.xsd"/>
-
+ <xs:import namespace="http://anss.org/xmlns/event/0.1" schemaLocation="AnssEvent-0.1.xsd"/>
+
<xs:complexType name="Quakeml">
<xs:all>
<xs:element ref="bed:eventParameters" minOccurs="0" maxOccurs="1"/>
</xs:all>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
-
+
<xs:element name="quakeml" type="Quakeml"/>
-
+
</xs:schema>
View
14 etc/quakeml_1.2/QuakeML-BED-1.2_jaxb.xsd
@@ -723,20 +723,6 @@ even if less elegant than putting them in a separate namespace
<xs:sequence>
<xs:element name="comment" type="bed:Comment" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="event" type="bed:Event" minOccurs="0" maxOccurs="unbounded"/>
- <xs:element name="internalEvent" type="bed:Event" minOccurs="0" maxOccurs="unbounded">
- <xs:annotation>
- <xs:documentation>
- Internal events represent preliminary solutions for actual events.
- </xs:documentation>
- </xs:annotation>
- </xs:element>
- <xs:element name="scenarioEvent" type="bed:Event" minOccurs="0" maxOccurs="unbounded">
- <xs:annotation>
- <xs:documentation>
- Scenario events represent hypothetical events used for planning purposes.
- </xs:documentation>
- </xs:annotation>
- </xs:element>
<xs:element name="description" minOccurs="0" maxOccurs="1" type="xs:string"/>
<xs:element name="creationInfo" minOccurs="0" maxOccurs="1" type="bed:CreationInfo"/>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
View
12 etc/quakeml_1.2/generateBindings.py
@@ -44,7 +44,8 @@
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
- extensionBindingPrefixes="xjc">
+ xmlns:wildcard="http://jaxb2-commons.dev.java.net/basic/wildcard"
+ extensionBindingPrefixes="xjc wildcard">
<globalBindings
fixedAttributeAsConstantProperty="true"
@@ -78,6 +79,8 @@
<!-- bindings for QuakeML-BED -->
<bindings schemaLocation="QuakeML-BED-1.2_jaxb.xsd" node="/xs:schema">
+ <wildcard:lax/>
+
<schemaBindings map="true">
<package name="org.quakeml_1_2"/>
</schemaBindings>
@@ -100,5 +103,12 @@
print """
</bindings>
+ <!-- bindings for AnssEvent -->
+ <bindings schemaLocation="AnssEvent-0.1.xsd" node="/xs:schema">
+ <schemaBindings>
+ <package name="org.quakeml_1_2"/>
+ </schemaBindings>
+ </bindings>
+
</bindings>
"""
View
1  etc/test_messages/pt13320000_internal.quakeml
@@ -0,0 +1 @@
+<q:quakeml xmlns="http://quakeml.org/xmlns/bed/1.2" xmlns:catalog="http://anss.org/xmlns/catalog/0.1" xmlns:q="http://quakeml.org/xmlns/quakeml/1.2" xmlns:anss="http://anss.org/xmlns/event/0.1"><eventParameters publicID="quakeml:pt.anss.org/eventParameters/13320000/1384573331365"><anss:internalEvent publicID="quakeml:pt.anss.org/event/13320000" catalog:datasource="pt" catalog:eventsource="pt" catalog:eventid="13320000"><magnitude publicID="quakeml:pt.anss.org/magnitude/13320000/Mi"><mag><value>7.4</value></mag><type>Mi</type><originID>quakeml:pt.anss.org/origin/13320000</originID><methodID>quakeml:anss.org/cube/magnitudeType/I</methodID><stationCount>6</stationCount></magnitude><origin publicID="quakeml:pt.anss.org/origin/13320000"><time><value>2013-11-16T03:34:31.000Z</value></time><longitude><value>-46.915</value></longitude><latitude><value>-60.44</value></latitude><depth><value>23000</value></depth><methodID>quakeml:anss.org/cube/locationMethod/z</methodID><quality><usedStationCount>7</usedStationCount><standardError>0.56</standardError><azimuthalGap>183.6</azimuthalGap></quality><evaluationMode>manual</evaluationMode></origin><preferredOriginID>quakeml:pt.anss.org/origin/13320000</preferredOriginID><preferredMagnitudeID>quakeml:pt.anss.org/magnitude/13320000/Mi</preferredMagnitudeID><type>earthquake</type><creationInfo><agencyID>pt</agencyID><creationTime>2013-11-16T03:42:11.365Z</creationTime><version>A</version></creationInfo></anss:internalEvent><creationInfo><creationTime>2013-11-16T03:42:11.365Z</creationTime></creationInfo></eventParameters></q:quakeml>
View
BIN  lib/commons-beanutils-1.7.0.jar
Binary file not shown
View
BIN  lib/commons-lang-2.2.jar
Binary file not shown
View
BIN  lib/commons-logging-1.1.1.jar
Binary file not shown
View
BIN  lib/javaparser-1.0.8.jar
Binary file not shown
View
BIN  lib/jaxb-api.jar
Binary file not shown
View
BIN  lib/jaxb-impl.jar → lib/jaxb-impl-2.2.5-2.jar
Binary file not shown
View
BIN  lib/jaxb-xjc.jar → lib/jaxb-xjc-2.2.5-2.jar
Binary file not shown
View
BIN  lib/jaxb2-basics-0.6.4.jar
Binary file not shown
View
BIN  lib/jaxb2-basics-ant-0.6.4.jar
Binary file not shown
View
BIN  lib/jaxb2-basics-runtime-0.6.4.jar
Binary file not shown
View
BIN  lib/jaxb2-basics-testing-0.6.4.jar
Binary file not shown
View
BIN  lib/jaxb2-basics-tools-0.6.4.jar
Binary file not shown
View
BIN  lib/jsr173_1.0_api.jar
Binary file not shown
View
32 src/gov/usgs/earthquake/event/ConverterTest.java
@@ -15,6 +15,7 @@
import gov.usgs.earthquake.cube.CubeMessage;
import gov.usgs.earthquake.util.IOUtil;
+import org.quakeml_1_2.InternalEvent;
import org.quakeml_1_2.Quakeml;
/**
@@ -82,13 +83,13 @@ public void convertCubeString(final String cubeString) throws Exception {
/**
* Test using a specific message from nevada.
- *
+ *
* This message was expected to convert from EQXML to CUBE and then Quakeml.
- *
+ *
* This test is designed to reproduce 2 separate issues: 1) implicit origin
* preferredFlag, when omitted should still imply preferred. 2) magnitude
* type without Cube_Code comment, should convert.
- *
+ *
* @throws Exception
*/
@Test
@@ -120,15 +121,34 @@ public void testPtwcInternalEQXML() throws Exception {
EQMessage eqxml = converter.getEQMessage(in);
System.err.println(converter.getString(eqxml));
CubeEvent cube = (CubeEvent) converter.getCubeMessage(eqxml);
- Assert.assertTrue("message has internal flag set", cube.isInternal());
+ Assert.assertTrue("message has internal flag set",
+ cube.isInternal());
System.err.println(converter.getString(cube));
Quakeml quakeml = converter.getQuakeml(eqxml);
Assert.assertNotNull("message converts to quakeml", quakeml);
System.err.println(converter.getString(quakeml));
- Assert.assertTrue("quakeml has internalEvent",
- quakeml.getEventParameters().getInternalEvents().size() != 0);
+ Assert.assertTrue("quakeml event is InternalEvent",
+ quakeml.getEventParameters().getAnies().get(0) instanceof InternalEvent);
+ } finally {
+ in.close();
+ }
+ }
+
+ @Test
+ public void testPtwcInternalQuakeml() throws Exception {
+ Converter converter = new Converter();
+ InputStream in = IOUtil.getInputStream(new File(
+ "etc/test_messages/pt13320000_internal.quakeml"));
+ try {
+ Quakeml quakeml = converter.getQuakeml(in);
+ Assert.assertNotNull("message converts to quakeml", quakeml);
+ System.err.println(converter.getString(quakeml));
+ Assert.assertTrue("quakeml event is InternalEvent",
+ quakeml.getEventParameters().getAnies().get(0) instanceof InternalEvent);
} finally {
in.close();
}
+
}
+
}
View
18 src/gov/usgs/earthquake/event/CubeToQuakemlConverter.java
@@ -15,6 +15,7 @@
import org.quakeml_1_2.Event;
import org.quakeml_1_2.EventParameters;
import org.quakeml_1_2.EventType;
+import org.quakeml_1_2.InternalEvent;
import org.quakeml_1_2.Magnitude;
import org.quakeml_1_2.OriginDepthType;
import org.quakeml_1_2.OriginQuality;
@@ -139,7 +140,16 @@ public Quakeml convertCubeEvent(CubeEvent message) throws Exception {
quakeml.setEventParameters(eventParameters);
// event container
- Event event = new Event();
+ Event event = null;
+ if (message.isInternal()) {
+ // add InternalEvent in anss namespace
+ event = new InternalEvent();
+ eventParameters.getAnies().add(event);
+ } else {
+ // add Event in quakeml namespace
+ event = new Event();
+ eventParameters.getEvents().add(event);
+ }
event.setPublicID(getQuakemlId(message.getSource(), message.getCode(),
"event", null));
@@ -148,12 +158,6 @@ public Quakeml convertCubeEvent(CubeEvent message) throws Exception {
event.setEventsource(message.getSource());
event.setEventid(message.getCode());
- if (message.isInternal()) {
- eventParameters.getInternalEvents().add(event);
- } else {
- eventParameters.getEvents().add(event);
- }
-
// version and sent timestamp in event creation info
CreationInfo creationInfo = new CreationInfo();
creationInfo.setAgencyID(message.getSource());
View
24 src/gov/usgs/earthquake/event/QuakemlToCubeConverter.java
@@ -6,6 +6,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
@@ -15,6 +16,7 @@
import org.quakeml_1_2.EvaluationMode;
import org.quakeml_1_2.Event;
import org.quakeml_1_2.EventType;
+import org.quakeml_1_2.InternalEvent;
import org.quakeml_1_2.Magnitude;
import org.quakeml_1_2.Origin;
import org.quakeml_1_2.OriginDepthType;
@@ -50,12 +52,22 @@
public CubeMessage convertQuakeml(final Quakeml message) throws Exception {
EventParameters eventParameters = message.getEventParameters();
- boolean internal = false;
List<Event> events = eventParameters.getEvents();
if (events.size() == 0) {
- // no regular events, check for internal
- events = eventParameters.getInternalEvents();
- internal = true;
+ events = new ArrayList<Event>();
+
+ // no events found, check for internalEvents
+ List<Object> anies = eventParameters.getAnies();
+ Iterator<Object> anyIter = anies.iterator();
+ while (anyIter.hasNext()) {
+ Object object = anyIter.next();
+ if (object instanceof InternalEvent) {
+ // found internal event
+ events.add((InternalEvent) object);
+ // done
+ break;
+ }
+ }
}
if (events.size() > 0) {
@@ -65,8 +77,8 @@ public CubeMessage convertQuakeml(final Quakeml message) throws Exception {
return convertQuakemlDeleteMessage(message, event, eventParameters);
} else {
CubeEvent cubeEvent = convertQuakemlEventMessage(message, event, eventParameters);
- if (cubeEvent != null) {
- cubeEvent.setInternal(internal);
+ if (cubeEvent != null && event instanceof InternalEvent) {
+ cubeEvent.setInternal(true);
}
return cubeEvent;
}
View
10 src/gov/usgs/earthquake/quakeml/Quakeml_1_2_Parser.java
@@ -23,9 +23,9 @@
import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
/**
- * Parse Quakeml 1.2rc3 messages.
+ * Parse Quakeml 1.2 messages.
*
- * @see org.quakeml_1_2rc3.Quakeml
+ * @see org.quakeml_1_2.Quakeml
*/
public class Quakeml_1_2_Parser extends NamespacePrefixMapper {
@@ -48,6 +48,10 @@
public static final String ANSS_EVENTID_NAMESPACE = "http://anss.org/xmlns/catalog/0.1";
public static final String ANSS_EVENTID_PREFIX = "catalog";
+ /** Event namespace. */
+ public static final String ANSS_EVENT_NAMESPACE = "http://anss.org/xmlns/event/0.1";
+ public static final String ANSS_EVENT_PREFIX = "anss";
+
/** JAXB Context for parsing. */
public static final JAXBContext CONTEXT;
static {
@@ -201,6 +205,8 @@ public String getPreferredPrefix(String namespaceUri, String suggestion,
return QUAKEML_1_2_BED_PREFIX;
} else if (ANSS_EVENTID_NAMESPACE.equals(namespaceUri)) {
return ANSS_EVENTID_PREFIX;
+ } else if (ANSS_EVENT_NAMESPACE.equals(namespaceUri)) {
+ return ANSS_EVENT_PREFIX;
} else {
return suggestion;
}
Please sign in to comment.
Something went wrong with that request. Please try again.