forked from brekka/stillingar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Taylor
committed
Sep 2, 2012
1 parent
d6cc0fb
commit 33a8edd
Showing
5 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/target | ||
/.classpath | ||
/.project | ||
/.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.brekka.stillingar</groupId> | ||
<artifactId>stillingar</artifactId> | ||
<version>1.0</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>stillingar-jaxb</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<name>Stillingar - JAXB</name> | ||
|
||
<inceptionYear>2012</inceptionYear> | ||
|
||
<url>https://github.com/brekka/stillingar/wiki</url> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<scm> | ||
<url>https://github.com/brekka/stillingar.git</url> | ||
<connection>https://github.com/brekka/stillingar.git</connection> | ||
</scm> | ||
|
||
<developers> | ||
<developer> | ||
<name>Andrew Taylor</name> | ||
<email>[email protected]</email> | ||
<timezone>GMT</timezone> | ||
</developer> | ||
</developers> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.brekka.stillingar</groupId> | ||
<artifactId>stillingar-core</artifactId> | ||
<version>${stillingar-core-version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit-version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<encoding>utf-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.1.2</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>jar-no-fork</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<properties> | ||
<stillingar-core-version>1.0.0-SNAPSHOT</stillingar-core-version> | ||
<junit-version>4.8.2</junit-version> | ||
<spring-release-version>3.0.5.RELEASE</spring-release-version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
</project> |
93 changes: 93 additions & 0 deletions
93
jaxb/src/main/java/org/brekka/stillingar/jaxb/JAXBConfigurationSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.brekka.stillingar.jaxb; | ||
|
||
import java.util.List; | ||
|
||
import org.brekka.stillingar.core.ConfigurationSource; | ||
|
||
/** | ||
* TODO Description of JAXBConfigurationSource | ||
* | ||
* @author Andrew Taylor ([email protected]) | ||
*/ | ||
public class JAXBConfigurationSource implements ConfigurationSource { | ||
|
||
private final Object object; | ||
|
||
/** | ||
* @param object | ||
*/ | ||
public JAXBConfigurationSource(Object object) { | ||
this.object = object; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.brekka.stillingar.core.ConfigurationSource#isAvailable(java.lang.String) | ||
*/ | ||
@Override | ||
public boolean isAvailable(String expression) { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.brekka.stillingar.core.ConfigurationSource#isAvailable(java.lang.Class) | ||
*/ | ||
@Override | ||
public boolean isAvailable(Class<?> valueType) { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.brekka.stillingar.core.ConfigurationSource#retrieve(java.lang.String, java.lang.Class) | ||
*/ | ||
@Override | ||
public <T> T retrieve(String expression, Class<T> valueType) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.brekka.stillingar.core.ConfigurationSource#retrieve(java.lang.Class) | ||
*/ | ||
@Override | ||
public <T> T retrieve(Class<T> valueType) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.brekka.stillingar.core.ConfigurationSource#retrieveList(java.lang.String, java.lang.Class) | ||
*/ | ||
@Override | ||
public <T> List<T> retrieveList(String expression, Class<T> valueType) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.brekka.stillingar.core.ConfigurationSource#retrieveList(java.lang.Class) | ||
*/ | ||
@Override | ||
public <T> List<T> retrieveList(Class<T> valueType) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
jaxb/src/main/java/org/brekka/stillingar/jaxb/JAXBSnapshotLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.brekka.stillingar.jaxb; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.nio.charset.Charset; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.Unmarshaller; | ||
import javax.xml.transform.Source; | ||
import javax.xml.validation.Schema; | ||
import javax.xml.validation.SchemaFactory; | ||
|
||
import org.brekka.stillingar.core.ConfigurationException; | ||
import org.brekka.stillingar.core.ConfigurationSource; | ||
import org.brekka.stillingar.core.ConfigurationSourceLoader; | ||
import org.xml.sax.SAXException; | ||
|
||
/** | ||
* Snapshot loader of XML files using JAXB | ||
* | ||
* @author Andrew Taylor ([email protected]) | ||
*/ | ||
public class JAXBSnapshotLoader implements ConfigurationSourceLoader { | ||
|
||
/** | ||
* The context path in which to look for the JAXB beans. | ||
*/ | ||
private final String contextPath; | ||
|
||
/** | ||
* Schemas to use to validate. | ||
*/ | ||
private final Schema schema; | ||
|
||
/** | ||
* @param contextPath | ||
*/ | ||
public JAXBSnapshotLoader(String contextPath, List<URL> schemas) { | ||
this.contextPath = contextPath; | ||
if (schemas.isEmpty()) { | ||
this.schema = null; | ||
} else { | ||
SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); | ||
List<Source> sources = new ArrayList<Source>(); | ||
for (URL url : schemas) { | ||
// TODO open and close streams | ||
// Source source = new StreamSource(); | ||
} | ||
try { | ||
this.schema = sf.newSchema(sources.toArray(new Source[schemas.size()])); | ||
} catch (SAXException e) { | ||
throw new ConfigurationException(String.format( | ||
"Failed to generate schemas for path '%s' from %s", contextPath, schemas), e); | ||
} | ||
} | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.brekka.stillingar.core.ConfigurationSourceLoader#parse(java.io.InputStream, java.nio.charset.Charset) | ||
*/ | ||
@Override | ||
public synchronized ConfigurationSource parse(InputStream sourceStream, Charset encoding) throws ConfigurationException, | ||
IOException { | ||
try { | ||
|
||
JAXBContext jc = JAXBContext.newInstance(this.contextPath); | ||
Unmarshaller u = jc.createUnmarshaller(); | ||
u.setSchema( this.schema ); | ||
Object jaxbObject = u.unmarshal(sourceStream); | ||
return new JAXBConfigurationSource(jaxbObject); | ||
|
||
} catch (JAXBException e) { | ||
throw new ConfigurationException(String.format( | ||
"Failed to establish new JAXB context for path '%s'", this.contextPath), e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters