2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.confignetconfconnector.util;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.config.yang.store.api.YangStoreException;
13 import org.opendaylight.controller.config.yang.store.api.YangStoreService;
14 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
15 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
16 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
17 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
18 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
20 import java.text.ParseException;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
24 public final class Util {
27 * Used for date <-> xml serialization
29 private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
31 public static String writeDate(final Date date) {
32 return dateFormat.format(date);
35 public static Date readDate(final String s) throws ParseException {
36 return dateFormat.parse(s);
39 public static void checkType(final Object value, final Class<?> clazz) {
40 Preconditions.checkArgument(clazz.isAssignableFrom(value.getClass()), "Unexpected type " + value.getClass()
41 + " should be " + clazz);
44 // TODO: add message and proper error types
45 public static YangStoreSnapshot getYangStore(final YangStoreService yangStoreService)
46 throws NetconfDocumentedException {
48 return yangStoreService.getYangStoreSnapshot();
49 } catch (final YangStoreException e) {
50 throw new NetconfDocumentedException("TODO", e, ErrorType.application, ErrorTag.bad_attribute,