2 * Copyright (c) 2013, 2015 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.config.yangjmxgenerator.plugin.java;
11 import static com.google.common.base.Preconditions.checkNotNull;
13 import com.google.common.base.Optional;
14 import com.google.common.collect.Maps;
15 import com.google.common.io.Files;
17 import java.io.IOException;
18 import java.nio.charset.StandardCharsets;
19 import java.util.Map.Entry;
20 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
22 public class GeneratedObject {
24 private final FullyQualifiedName fqn;
25 private final String content;
27 public GeneratedObject(FullyQualifiedName fqn, String content) {
28 this.fqn = checkNotNull(fqn);
29 this.content = StringUtil.formatJavaSource(checkNotNull(content));
32 public FullyQualifiedName getFQN(){
36 public String getContent() {
40 public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory, boolean overwrite) throws IOException {
41 File dstFile = fqn.toFile(srcDirectory);
42 if (overwrite || !dstFile.exists()) {
43 Files.createParentDirs(dstFile);
45 Files.write(content, dstFile, StandardCharsets.UTF_8);
46 return Optional.of(Maps.immutableEntry(fqn, dstFile));
48 return Optional.absent();
52 public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory) throws IOException {
53 return persist(srcDirectory, true);
57 public String toString() {
58 return getClass().getSimpleName() + "{" +
64 public boolean equals(Object o) {
68 if (o == null || getClass() != o.getClass()) {
72 GeneratedObject that = (GeneratedObject) o;
74 return fqn.equals(that.fqn);
79 public int hashCode() {
80 return fqn.hashCode();