*/
package org.opendaylight.yangtools.yang.parser.builder.impl;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Collections2;
+import com.google.common.io.ByteSource;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
-
import org.apache.commons.io.IOUtils;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Collections2;
-import com.google.common.io.ByteSource;
-
public final class BuilderUtils {
private static final Logger LOG = LoggerFactory.getLogger(BuilderUtils.class);
});
}
- /**
- * Set string representation of source to ModuleBuilder.
- *
- * @param sourceToBuilder
- * source to module mapping
- */
- public static void setSourceToBuilder(final Map<ByteSource, ModuleBuilder> sourceToBuilder) throws IOException {
- for (Map.Entry<ByteSource, ModuleBuilder> entry : sourceToBuilder.entrySet()) {
- ModuleBuilder builder = entry.getValue();
- ByteSource source = entry.getKey();
-
- String content = null;
- InputStream stream = null;
- try {
- stream = source.openStream();
- content = IOUtils.toString(stream);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- /*
- * Failed stream close does not prevent us from
- * continuing to work correctly, we just report that and
- * continue.
- */
- LOG.warn("Failed to close stream {}. Leaving stream unclosed.", stream, e);
- }
- }
- }
- builder.setSource(content);
- }
- }
-
/**
* Create new SchemaPath from given path and qname.
*
*/
@Deprecated
public static SchemaPath createSchemaPath(final SchemaPath schemaPath, final QName... qname) {
- List<QName> path = new ArrayList<>(schemaPath.getPath());
- path.addAll(Arrays.asList(qname));
- return SchemaPath.create(path, schemaPath.isAbsolute());
+ return schemaPath.createChild(qname);
}
/**
* prefix associated with import
* @return ModuleImport based on given prefix
*/
- public static ModuleImport getModuleImport(final ModuleBuilder builder, final String prefix) {
+ private static ModuleImport getModuleImport(final ModuleBuilder builder, final String prefix) {
for (ModuleImport mi : builder.getModuleImports()) {
if (mi.getPrefix().equals(prefix)) {
return mi;
*/
public static ModuleBuilder findModuleFromBuilders(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module, final String prefix, final int line) {
- ModuleBuilder dependentModule = null;
- Date dependentModuleRevision = null;
+ ModuleBuilder dependentModule;
+ Date dependentModuleRevision;
if (prefix == null) {
dependentModule = module;
}
}
- Module result = null;
+ Module result;
if (dependentModuleRevision == null) {
result = modulesByRevision.get(modulesByRevision.firstKey());
} else {
public static SchemaPath parseXPathString(final String xpathString) {
final boolean absolute = xpathString.indexOf('/') == 0;
- final List<QName> path = new ArrayList<QName>();
+ final List<QName> path = new ArrayList<>();
for (String pathElement : SLASH_SPLITTER.split(xpathString)) {
if (pathElement.length() > 0) {
final Iterator<String> it = COLON_SPLITTER.split(pathElement).iterator();
* @param config
* new config value
*/
- public static void setNodeConfig(final DataSchemaNodeBuilder node, final Boolean config) {
+ private static void setNodeConfig(final DataSchemaNodeBuilder node, final Boolean config) {
if (node instanceof ContainerSchemaNodeBuilder || node instanceof LeafSchemaNodeBuilder
|| node instanceof LeafListSchemaNodeBuilder || node instanceof ListSchemaNodeBuilder
|| node instanceof ChoiceBuilder || node instanceof AnyXmlBuilder) {
while (!(parent instanceof ModuleBuilder)) {
parent = parent.getParent();
}
- Preconditions.checkState(parent instanceof ModuleBuilder);
ModuleBuilder parentModule = (ModuleBuilder) parent;
if (parentModule.isSubmodule()) {
parentModule = parentModule.getParent();
Set<TypeDefinitionBuilder> result = new HashSet<>();
for (TypeDefinition<?> node : nodes) {
QName qname = new QName(ns, rev, pref, node.getQName().getLocalName());
- List<QName> path = new ArrayList<>(parentPath.getPath());
- path.add(qname);
- SchemaPath schemaPath = SchemaPath.create(path, parentPath.isAbsolute());
+ SchemaPath schemaPath = parentPath.createChild(qname);
result.add(new TypeDefinitionBuilderImpl(moduleName, line, qname, schemaPath, ((ExtendedType) node)));
}
return result;
List<UnknownSchemaNodeBuilderImpl> result = new ArrayList<>();
for (UnknownSchemaNode node : nodes) {
QName qname = new QName(ns, rev, pref, node.getQName().getLocalName());
- List<QName> path = new ArrayList<>(parentPath.getPath());
- path.add(qname);
- SchemaPath schemaPath = SchemaPath.create(path, parentPath.isAbsolute());
+ SchemaPath schemaPath = parentPath.createChild(qname);
result.add(new UnknownSchemaNodeBuilderImpl(moduleName, line, qname, schemaPath, node));
}
return result;