Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace simple-xml with JAXB #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.7.1</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand All @@ -83,6 +77,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
* the GNU Lesser General Public License along with this program; if not, see
* <http://www.gnu.org/licenses/>.
*/
import java.util.List;

import org.cups4j.ipp.attributes.AttributeGroup;
import org.cups4j.ipp.attributes.Tag;

import java.util.List;

public interface IIppAttributeProvider {
public final static String TAG_LIST_FILENAME = "config/ippclient/ipp-list-of-tag.xml";
public final static String ATTRIBUTE_LIST_FILENAME = "config/ippclient/ipp-list-of-attributes.xml";
public final static String CONTEXT = "ch.ethz.vppserver.schema.ippclient";
String TAG_LIST_FILENAME = "config/ippclient/ipp-list-of-tag.xml";
String ATTRIBUTE_LIST_FILENAME = "config/ippclient/ipp-list-of-attributes.xml";
String CONTEXT = "ch.ethz.vppserver.schema.ippclient";

public List<Tag> getTagList();
List<Tag> getTagList();

public List<AttributeGroup> getAttributeGroupList();
List<AttributeGroup> getAttributeGroupList();
}
59 changes: 32 additions & 27 deletions src/main/java/ch/ethz/vppserver/ippclient/IppAttributeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,63 @@
* the GNU Lesser General Public License along with this program; if not, see
* <http://www.gnu.org/licenses/>.
*/
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.cups4j.ipp.attributes.AttributeGroup;
import org.cups4j.ipp.attributes.AttributeList;
import org.cups4j.ipp.attributes.Tag;
import org.cups4j.ipp.attributes.TagList;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

public class IppAttributeProvider implements IIppAttributeProvider {

private static IppAttributeProvider INSTANCE = new IppAttributeProvider();
private List<Tag> tagList = new ArrayList<Tag>();
private List<AttributeGroup> attributeGroupList = new ArrayList<AttributeGroup>();
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class IppAttributeProvider implements IIppAttributeProvider {
private static final IppAttributeProvider INSTANCE = new IppAttributeProvider();
private final List<Tag> tagList = new ArrayList<>();
private final List<AttributeGroup> attributeGroupList = new ArrayList<>();

public static IppAttributeProvider getInstance() {
return INSTANCE;
}

private IppAttributeProvider() {
ClassLoader classLoader = IppAttributeProvider.class.getClassLoader();
try {
InputStream tagListStream = IIppAttributeProvider.class.getClassLoader().getResourceAsStream(TAG_LIST_FILENAME);
InputStream attListStream = IIppAttributeProvider.class.getClassLoader().getResourceAsStream(
ATTRIBUTE_LIST_FILENAME);

Serializer serializer = new Persister();
TagList tList = serializer.read(TagList.class, tagListStream);
tagList = tList.getTag();

AttributeList aList = serializer.read(AttributeList.class, attListStream);
attributeGroupList = aList.getAttributeGroup();
JAXBContext tagListContext = JAXBContext.newInstance(TagList.class);
Unmarshaller tagListUnmarshaller = tagListContext.createUnmarshaller();

InputStream tagListStream = classLoader.getResourceAsStream(TAG_LIST_FILENAME);
TagList tList = (TagList) tagListUnmarshaller.unmarshal(tagListStream);
this.tagList.addAll(tList.getTag());
} catch (Exception e) {
throw new RuntimeException("Error unmarshalling tag list", e);
}

try {
JAXBContext attListContext = JAXBContext.newInstance(AttributeList.class);
Unmarshaller attListUnmarshaller = attListContext.createUnmarshaller();
InputStream attListStream = classLoader.getResourceAsStream(ATTRIBUTE_LIST_FILENAME);
AttributeList aList = (AttributeList) attListUnmarshaller.unmarshal(attListStream);
List<AttributeGroup> attributeGroups = aList.getAttributeGroup();
this.attributeGroupList.addAll(attributeGroups);
} catch (Exception e) {
throw new RuntimeException(e);
throw new RuntimeException("Error unmarshalling attribute groups", e);
}
}

/**
*
* @return
* @return tag list
*/
public List<Tag> getTagList() {
return tagList;
}

/**
*
* @return
* @return attribute groups
*/
public List<AttributeGroup> getAttributeGroupList() {
return attributeGroupList;
}

}
16 changes: 8 additions & 8 deletions src/main/java/org/cups4j/ipp/attributes/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

package org.cups4j.ipp.attributes;

import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import java.util.ArrayList;
import java.util.List;

@Root(name = "attribute")
@XmlType(name = "attribute")
public class Attribute {

@ElementList(entry = "attribute-value", inline = true)
@XmlElement(name ="attribute-value")
protected List<AttributeValue> attributeValue;
@org.simpleframework.xml.Attribute(required = true)
@XmlAttribute(required = true)
protected String name;
@org.simpleframework.xml.Attribute(required = false)
@XmlAttribute
protected String description;

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ public class Attribute {
*/
public List<AttributeValue> getAttributeValue() {
if (attributeValue == null) {
attributeValue = new ArrayList<AttributeValue>();
attributeValue = new ArrayList<>();
}
return this.attributeValue;
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/cups4j/ipp/attributes/AttributeGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

package org.cups4j.ipp.attributes;

import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import java.util.ArrayList;
import java.util.List;

@Root(name = "attribute-group")
@XmlType(name = "attribute-group")
public class AttributeGroup {
@ElementList(entry = "attribute", inline = true)
@XmlElement(name ="attribute")
protected List<Attribute> attribute;
@org.simpleframework.xml.Attribute(required = true)
@XmlAttribute(required = true)
protected String tag;
@org.simpleframework.xml.Attribute(name = "tag-name", required = true)
@XmlAttribute(name = "tag-name", required = true)
protected String tagName;
@org.simpleframework.xml.Attribute(required = false)
@XmlAttribute
protected String description;

/**
Expand All @@ -48,7 +48,7 @@ public class AttributeGroup {
*/
public List<Attribute> getAttribute() {
if (attribute == null) {
attribute = new ArrayList<Attribute>();
attribute = new ArrayList<>();
}
return this.attribute;
}
Expand Down
41 changes: 28 additions & 13 deletions src/main/java/org/cups4j/ipp/attributes/AttributeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@

package org.cups4j.ipp.attributes;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

@Root(name = "attribute-list")
@XmlRootElement(name = "attribute-list")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AttributeList {
@Attribute

protected String schemaLocation;

@ElementList(entry = "attribute-group", inline = true, required = true)

protected List<AttributeGroup> attributeGroup;

@org.simpleframework.xml.Attribute(required = false)

protected String description;


@XmlAttribute
public String getSchemaLocation() {
return schemaLocation;
}

public void setSchemaLocation(String schemaLocation) {
this.schemaLocation = schemaLocation;
}

/**
* Gets the value of the attributeGroup property.
*
Expand All @@ -48,19 +57,25 @@ public class AttributeList {
*
*
*/
@XmlElement(name = "attribute-group")
public List<AttributeGroup> getAttributeGroup() {
if (attributeGroup == null) {
attributeGroup = new ArrayList<AttributeGroup>();
attributeGroup = new ArrayList<>();
}
return this.attributeGroup;
}


public void setAttributeGroup(List<AttributeGroup> attributeGroup) {
this.attributeGroup = attributeGroup;
}

/**
* Gets the value of the description property.
*
* @return possible object is {@link String }
*
*/
@XmlAttribute
public String getDescription() {
return description;
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/org/cups4j/ipp/attributes/AttributeValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@

package org.cups4j.ipp.attributes;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@Root(name = "attribute-value")
@XmlType(name = "attribute-value")
public class AttributeValue {

@Element(name = "set-of-keyword", required = false)
@XmlElement(name = "set-of-keyword")
protected SetOfKeyword setOfKeyword;
@Element(name = "set-of-enum", required = false)
@XmlElement(name = "set-of-enum")
protected SetOfEnum setOfEnum;
@org.simpleframework.xml.Attribute(required = true)
@XmlAttribute(required = true)
protected String tag;
@org.simpleframework.xml.Attribute(name = "tag-name", required = true)
@XmlAttribute(name = "tag-name", required = true)
protected String tagName;
@org.simpleframework.xml.Attribute(required = false)
@XmlAttribute
protected String value;
@org.simpleframework.xml.Attribute(required = false)
@XmlAttribute
protected String description;

/**
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/cups4j/ipp/attributes/Enum.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

package org.cups4j.ipp.attributes;

import org.simpleframework.xml.Root;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

@Root(name = "enum")
@XmlType(name = "enum")
public class Enum {

@org.simpleframework.xml.Attribute(required = true)
@XmlAttribute(required = true)
protected String name;
@org.simpleframework.xml.Attribute(required = true)
@XmlAttribute(required = true)
protected String value;
@org.simpleframework.xml.Attribute(required = false)
@XmlAttribute
protected String description;

/**
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/cups4j/ipp/attributes/Keyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

package org.cups4j.ipp.attributes;

import org.simpleframework.xml.Root;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

@Root(name = "keyword")
@XmlType(name = "keyword")
public class Keyword {

@org.simpleframework.xml.Attribute(required = true)
@XmlAttribute(required = true)
protected String value;
@org.simpleframework.xml.Attribute(required = false)
@XmlAttribute
protected String description;

/**
Expand Down
Loading