Xml 担心在扩展JodaTime';的类型上使用java2ws不会出现参数构造函数问题;s可变区间
首先,我已经看过这里:Xml 担心在扩展JodaTime';的类型上使用java2ws不会出现参数构造函数问题;s可变区间,xml,jaxb,cxf,jodatime,java2wsdl,Xml,Jaxb,Cxf,Jodatime,Java2wsdl,首先,我已经看过这里: 有关使用JAXB处理JodaTime类的一些可能帮助 我继承了一个代码库,其类的impl(和XML适配器)如下所示 当尝试为java2ws使用Apache CXF v2.7.2 Maven插件生成WSDL和客户端时,我得到以下结果: Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions org.joda.t
JAXB
处理JodaTime
类的一些可能帮助
我继承了一个代码库,其类的impl(和XML适配器)如下所示
当尝试为java2ws
使用Apache CXF v2.7.2 Maven插件生成WSDL
和客户端时,我得到以下结果:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
org.joda.time.base.BaseInterval does not have a no-arg default constructor.
this problem is related to the following location:
at org.joda.time.base.BaseInterval
at org.joda.time.MutableInterval
at com.etp.commons.persistence.model.time.Period
好的,Period
(以下)扩展了MutableInterval
extendsBaseInterval
extendsAbstractInterval
,它在JodaTime v2.1
中有一个受保护的无参数构造函数Period
有一个公共的无参数构造函数,该构造函数调用MutableInterval
的构造函数变量,并传入一些默认值
有关于如何进行的提示吗
package com.etp.commons.persistence.model.time;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.MutableInterval;
import org.joda.time.ReadableInstant;
import org.joda.time.ReadableInterval;
import com.etp.commons.persistence.model.jaxb.XMLPeriodAdapter;
import com.etp.commons.time.services.core.TimeDispatcher;
@XmlType
@XmlJavaTypeAdapter(value=XMLPeriodAdapter.class)
public class Period extends MutableInterval implements Comparable<Period>{
private static final long serialVersionUID = 1L;
public static boolean endpointInclusive = true;
public static DateTime defaultEffectiveInstant = new DateTime(1900,1,1,0,0,0,0, DateTimeZone.forID("GMT"));
public static DateTime defaultTerminationInstant = new DateTime(9999,12,31,0,0,0,0, DateTimeZone.forID("GMT"));
public static Period defaultEffectiveInterval = new Period();
@Override
public boolean contains(ReadableInstant time){
if (endpointInclusive){
return this.getStartMillis() < time.getMillis() && this.getEndMillis() >= time.getMillis();
}else{
return super.contains(time);
}
}
@Override
public boolean contains(long time){
if (endpointInclusive){
return this.getStartMillis() < time && this.getEndMillis() >= time;
}else{
return super.contains(time);
}
}
@Override
public boolean containsNow(){
long time = TimeDispatcher.defaultTimeDispatcher.getCurrentTimeMillis();
if (endpointInclusive){
return this.getStartMillis() < time && this.getEndMillis() >= time;
}else{
return super.contains(time);
}
}
public DateTime getInclusiveTerminalInstant(){
if (endpointInclusive){
return this.getEnd();
}else{
return this.getStart();
}
}
public Period getOverlap(Period period){
if (!this.overlaps(period)){
return null;
}else if (this.contains(period)){
return new Period(period);
}else if (period.contains(this)){
return new Period(this);
}else{
if (this.getStartMillis() < period.getStartMillis()){
return new Period(period.getStart(),this.getEnd());
}else{
return new Period(this.getStart(),period.getEnd());
}
}
}
public Period offsetByJodaPeriod(org.joda.time.Period period, boolean reverse){
Period p = null;
if (reverse){
p = new Period(getStart().minus(period),getEnd().minus(period));
}else{
p = new Period(getStart().plus(period),getEnd().plus(period));
}
return p;
}
public static List<Period> merge(List<Period> periods){
List<Period> result = new ArrayList<Period>();
periods = getDistinctPeriods(periods);
Collections.sort(periods);
DateTime start = null;
DateTime end = null;
for (Period period : periods){
if (start == null){
start = period.getStart();
end = period.getEnd();
}else{
if (period.getStart().isEqual(end)){
end = period.getEnd();
}else{
result.add(new Period(start,end));
start = period.getStart();
end = period.getEnd();
}
}
}
if (start != null){
result.add(new Period(start,end));
}
return result;
}
public static Period getExtentPeriod(Collection<Period> periods){
DateTime start = null;
DateTime end = null;
for (Period period : periods){
if (start == null || start.getMillis() > period.getStartMillis()){
start = period.getStart();
}
if (end == null || end.getMillis() < period.getEndMillis()){
end = period.getEnd();
}
}
return new Period(start,end);
}
public static Period getEnclosingPeriod(DateTime instant, FrequencyUnitType unit){
DateTime start = unit.truncate(instant);
DateTime end = start.plus(unit.getJodaPeriod());
return new Period(start,end);
}
public Period subtractOverlap(Period period){
if (this.overlaps(period)){
if (period.contains(this)){
return null;
}else if (this.contains(period)){
throw new IllegalArgumentException("Period contains target period. More than one period would result from subtract");
}else if (this.getStartMillis() < period.getStartMillis()){
return new Period(this.getStart(),period.getStart());
}else if (this.getEndMillis() > period.getStartMillis()){
return new Period(period.getEnd(),this.getEnd());
}
}
return this;
}
public Period subtractOverhang(Period period){
if (this.overlaps(period)){
if (period.contains(this)){
return this;
}else if (this.contains(period)){
return new Period(period.getStart(),period.getEnd());
}else if (this.getStartMillis() < period.getStartMillis()){
return new Period(period.getStart(),this.getEnd());
}else if (this.getEndMillis() > period.getStartMillis()){
return new Period(this.getStart(),period.getEnd());
}
}
return null;
}
/**
* Returns the smallest period that is common to all of the passed periods and contains the passed time.
*
* @param periods
* @param time
* @return
*/
public static Period getSmallestCommonIntersection(Collection<Period> periods, DateTime time){
Period smallest = new Period();
for (Period period : periods){
if (!period.contains(time)){
return null;
}
if (smallest.getStartMillis() < period.getStartMillis()){
smallest.setStart(period.getStart());
}
if (smallest.getEndMillis() > period.getEndMillis()){
smallest.setEnd(period.getEnd());
}
}
return smallest;
}
public static List<? extends PeriodDatedObject> getCollectionWithinPeriod(Collection<? extends PeriodDatedObject> collection, Period effectivePeriod){
List<PeriodDatedObject> effectiveObs = new ArrayList<PeriodDatedObject>();
for (PeriodDatedObject ob : collection){
if (ob.getPeriod().overlaps(effectivePeriod)){
effectiveObs.add(ob);
}
}
return effectiveObs;
}
public static List<? extends PeriodDatedObject> getCollectionAtInstant(Collection<? extends PeriodDatedObject> collection, DateTime effectiveInstant){
List<PeriodDatedObject> effectiveObs = new ArrayList<PeriodDatedObject>();
for (PeriodDatedObject ob : collection){
if (ob.getPeriod().contains(effectiveInstant)){
effectiveObs.add(ob);
}
}
return effectiveObs;
}
public static PeriodDatedObject getMemberAtInstant(Collection<? extends PeriodDatedObject> collection, DateTime effectiveInstant){
for (PeriodDatedObject ob : collection){
if (ob.getPeriod().contains(effectiveInstant)){
return ob;
}
}
return null;
}
public List<Period> getGaps(List<Period> periods){
Collections.sort(periods);
List<Period> gaps = new ArrayList<Period>();
DateTime contiguousTo = this.getStart();
for (Period period : periods){
if (period.getStart().getMillis() <= this.getStart().getMillis()){
contiguousTo = period.getEnd();
}else if (period.getStart().isEqual(contiguousTo)){
contiguousTo = period.getEnd();
}else if (period.getStartMillis() > contiguousTo.getMillis()){
Period gap = new Period(contiguousTo, period.getStart());
contiguousTo = period.getEnd();
gaps.add(gap);
}
}
if (contiguousTo.getMillis() < this.getEnd().getMillis()){
Period gap = new Period(contiguousTo, this.getEnd());
gaps.add(gap);
}
return gaps;
}
/**
* Returns a list of distinct periods that results from overlaying the list
* of input periods. Non-contiguous periods will not be returned
*
* @param periods
* @return
*/
public static List<Period> getDistinctPeriods(Collection<Period> periods){
Set<Long> instants = new HashSet<Long>();
for (Period period : periods){
instants.add(period.getStart().getMillis());
instants.add(period.getEnd().getMillis());
}
List<Long> sorted = new ArrayList<Long>(instants);
Collections.sort(sorted);
List<Period> distinctPeriods = new ArrayList<Period>();
Period period = null;
for (int i=0;i<sorted.size();i++){
if (period != null){
period.setEnd(new DateTime(sorted.get(i)));
distinctPeriods.add(period);
}
period = new Period();
period.setStart(new DateTime(sorted.get(i)));
}
List<Period> emptyPeriods = new ArrayList<Period>();
for (Period distinctPeriod : distinctPeriods){
boolean empty = true;
for (Period actualPeriod : periods){
if (actualPeriod.contains(distinctPeriod)){
empty = false;
break;
}
}
if (empty){
emptyPeriods.add(distinctPeriod);
}
}
distinctPeriods.removeAll(emptyPeriods);
return distinctPeriods;
}
public boolean abuts(Period period){
return this.getStartMillis() == period.getEndMillis() || this.getEndMillis() == period.getStartMillis();
}
public DateTime getStartDate(){
return this.getStart();
}
public void setStartDate(DateTime date){
this.setStart(date);
}
public DateTime getEndDate(){
return this.getEnd();
}
public void setEndDate(DateTime date){
this.setEnd(date);
}
public Period(){
super(defaultEffectiveInstant,defaultTerminationInstant);
}
public Period(DateTime start, DateTime end){
super(start,end);
}
public Period(long start, long end) {
super(start,end);
}
public Period(ReadableInterval period) {
super(period.getStart(),period.getEnd());
}
@Override
public int hashCode() {
final int prime = 31;
int result = prime;
result = prime * result + new Long(this.getStartMillis()).hashCode();
result = prime * result + new Long(this.getEndMillis()).hashCode();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!Period.class.isAssignableFrom(obj.getClass()))
return false;
Period other = (Period) obj;
if (this.getEnd() == null) {
if (other.getEnd() != null)
return false;
} else if (!this.getEnd().isEqual(other.getEnd()))
return false;
if (this.getStart() == null) {
if (other.getStart() != null)
return false;
} else if (!this.getStart().isEqual(other.getStart()))
return false;
return true;
}
public int compareByEnd(Period o) {
return o.getEnd().compareTo(this.getEnd());
}
@Override
public int compareTo(Period o) {
int compare = this.getStart().compareTo(o.getStart());
return compare;
}
public String toString(){
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZZ");
return fmt.format(this.getStart().toDate()) + "-" + fmt.format(this.getEnd().toDate());
}
public String toString(String format){
SimpleDateFormat fmt = new SimpleDateFormat(format);
return fmt.format(this.getStart().toDate()) + "-" + fmt.format(this.getEnd().toDate());
}
public boolean containsIncludingEndpoints(DateTime next) {
return contains(next) || getStart().isEqual(next) || getEnd().isEqual(next);
}
}
package com.etp.commons.persistence.model.time;
导入java.text.simpleDataFormat;
导入java.util.ArrayList;
导入java.util.Collection;
导入java.util.Collections;
导入java.util.HashSet;
导入java.util.List;
导入java.util.Set;
导入javax.xml.bind.annotation.XmlType;
导入javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
导入org.joda.time.DateTime;
导入org.joda.time.DateTimeZone;
导入org.joda.time.MutableInterval;
导入org.joda.time.ReadableInstant;
导入org.joda.time.ReadableInterval;
导入com.etp.commons.persistence.model.jaxb.XMLPeriodAdapter;
导入com.etp.commons.time.services.core.TimeDispatcher;
@XmlType
@XmlJavaTypeAdapter(值=XMLPeriodAdapter.class)
公共类周期扩展了可变间隔{
私有静态最终长serialVersionUID=1L;
公共静态布尔endpointInclusive=true;
public static DateTime defaultEffectiveInstant=新的日期时间(1900,1,1,0,0,0,DateTimeZone.forID(“GMT”);
public static DateTime defaultterminationstant=new DateTime(9999,12,31,0,0,0,DateTimeZone.forID(“GMT”);
公共静态期间defaultEffectiveInterval=新期间();
@凌驾
公共布尔包含(ReadableInstant time){
如果(包括端点){
返回this.getStartMillis()=time.getMillis();
}否则{
返回super.contains(时间);
}
}
@凌驾
公共布尔包含(长时间){
如果(包括端点){
返回this.getStartMillis()