Skip to content

Commit

Permalink
typetools/TTime: lazy DataTypeFactory initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Ketoth Xupack <ketoth.xupack@gmail.com>
  • Loading branch information
KetothXupack committed Oct 22, 2013
1 parent 6ef9209 commit 3c01acc
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions projects/typetools/src/main/java/org/nohope/typetools/TTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
*/
public final class TTime {
public static final String UTC_ID = "UTC";
private static final DatatypeFactory datatypeFactory;

static {
try {
datatypeFactory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
throw new RuntimeException(e);
}
}

private TTime() {
}
Expand Down Expand Up @@ -123,6 +114,24 @@ public static XMLGregorianCalendar toXmlCalendar(final Date date, final String t
final GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeZone(TimeZone.getTimeZone(timezoneId));
calendar.setTime(date);
return datatypeFactory.newXMLGregorianCalendar(calendar);
return LazyDataTypeFactorySingleton.getFactory().newXMLGregorianCalendar(calendar);
}

public static class LazyDataTypeFactorySingleton {
private static final DatatypeFactory datatypeFactory;
static {
try {
datatypeFactory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
throw new IllegalStateException("Unable to create DataTypeFactory instance", e);
}
}

private LazyDataTypeFactorySingleton() {
}

public static DatatypeFactory getFactory() {
return LazyDataTypeFactorySingleton.datatypeFactory;
}
}
}

0 comments on commit 3c01acc

Please sign in to comment.