use of javax.xml.datatype.DatatypeFactory in project cxf by apache.
the class XsDateTimeFormat method parseObject.
public Object parseObject(String pString, ParsePosition pParsePosition) {
if (pString == null) {
throw new NullPointerException("The String argument must not be null.");
}
if (pParsePosition == null) {
throw new NullPointerException("The ParsePosition argument must not be null.");
}
int offset = pParsePosition.getIndex();
int idxSpc = pString.indexOf(' ', offset);
int idxCom = pString.indexOf(',', offset);
if (idxCom != -1 && idxCom < idxSpc) {
idxSpc = idxCom;
}
String newVal = null;
if (idxSpc == -1) {
newVal = pString.substring(offset);
} else {
newVal = pString.substring(offset, idxSpc);
}
DatatypeFactory factory;
try {
factory = DatatypeFactory.newInstance();
XMLGregorianCalendar cal = factory.newXMLGregorianCalendar(newVal);
pParsePosition.setIndex(idxSpc);
return cal.toGregorianCalendar();
} catch (DatatypeConfigurationException e) {
pParsePosition.setErrorIndex(offset);
}
return null;
}
use of javax.xml.datatype.DatatypeFactory in project Payara by payara.
the class ScheduledTimerNode method writeDescriptor.
@Override
public Node writeDescriptor(Node parent, String nodeName, ScheduledTimerDescriptor desc) {
Node timerNode = super.writeDescriptor(parent, nodeName, descriptor);
Node scheduleNode = appendChild(timerNode, EjbTagNames.TIMER_SCHEDULE);
appendTextChild(scheduleNode, EjbTagNames.TIMER_SECOND, desc.getSecond());
appendTextChild(scheduleNode, EjbTagNames.TIMER_MINUTE, desc.getMinute());
appendTextChild(scheduleNode, EjbTagNames.TIMER_HOUR, desc.getHour());
appendTextChild(scheduleNode, EjbTagNames.TIMER_DAY_OF_MONTH, desc.getDayOfMonth());
appendTextChild(scheduleNode, EjbTagNames.TIMER_MONTH, desc.getMonth());
appendTextChild(scheduleNode, EjbTagNames.TIMER_DAY_OF_WEEK, desc.getDayOfWeek());
appendTextChild(scheduleNode, EjbTagNames.TIMER_YEAR, desc.getYear());
try {
DatatypeFactory dFactory = DatatypeFactory.newInstance();
GregorianCalendar cal = new GregorianCalendar();
if (desc.getStart() != null) {
cal.setTime(desc.getStart());
XMLGregorianCalendar xmlGreg = dFactory.newXMLGregorianCalendar(cal);
appendTextChild(timerNode, EjbTagNames.TIMER_START, xmlGreg.toXMLFormat());
}
if (desc.getEnd() != null) {
cal.setTime(desc.getEnd());
XMLGregorianCalendar xmlGreg = dFactory.newXMLGregorianCalendar(cal);
appendTextChild(timerNode, EjbTagNames.TIMER_END, xmlGreg.toXMLFormat());
}
} catch (Exception e) {
DOLUtils.getDefaultLogger().log(Level.WARNING, e.getMessage(), e);
}
MethodNode methodNode = new MethodNode();
methodNode.writeJavaMethodDescriptor(timerNode, EjbTagNames.TIMEOUT_METHOD, desc.getTimeoutMethod());
appendTextChild(timerNode, EjbTagNames.TIMER_PERSISTENT, Boolean.toString(desc.getPersistent()));
String tz = desc.getTimezone();
if (tz != null) {
appendTextChild(timerNode, EjbTagNames.TIMER_TIMEZONE, tz);
}
String info = desc.getInfo();
if (info != null) {
appendTextChild(timerNode, EjbTagNames.TIMER_INFO, info);
}
return timerNode;
}
Aggregations