Skip to content

Commit

Permalink
import object based on new parser (preparing interfaces)..
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Apr 22, 2014
1 parent b61e1d1 commit dfaf6de
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Expand Up @@ -267,6 +267,20 @@ public List<PrismObject<? extends Objectable>> parseObjects(File file) throws Sc
}
return objects;
}

public Collection<XNode> parseObjects(InputStream stream, String language) throws SchemaException, IOException {
Parser parser = getParserNotNull(language);
Collection<XNode> nodes = parser.parseCollection(stream);
return nodes;
// Iterator<XNode> nodesIterator = nodes.iterator();
// List<PrismObject<? extends Objectable>> objects = new ArrayList<PrismObject<? extends Objectable>>();
// while (nodesIterator.hasNext()){
// XNode node = nodesIterator.next();
// PrismObject object = xnodeProcessor.parseObject(node);
// objects.add(object);
// }
// return objects;
}
//endregion

//region Parsing prism containers
Expand Down
Expand Up @@ -67,6 +67,12 @@ public Collection<XNode> parseCollection(String dataString) throws SchemaExcepti
throw new UnsupportedOperationException("Parse objects not supported for json and yaml.");
}

@Override
public Collection<XNode> parseCollection(InputStream stream) throws SchemaException, IOException {
// TODO Auto-generated method stub
return null;
}

@Override
public XNode parse(File file) throws SchemaException, IOException {
JsonParser parser = createParser(file);
Expand Down
Expand Up @@ -69,6 +69,16 @@ public DomParser(SchemaRegistry schemaRegistry) {
@Override
public Collection<XNode> parseCollection(File file) throws SchemaException, IOException {
Document document = DOMUtil.parseFile(file);
return parseCollection(document);
}

@Override
public Collection<XNode> parseCollection(InputStream stream) throws SchemaException, IOException {
Document document = DOMUtil.parse(stream);
return parseCollection(document);
}

private Collection<XNode> parseCollection(Document document) throws SchemaException{
Element root = DOMUtil.getFirstChildElement(document);
// TODO: maybe some check if this is a collection of other objects???
List<Element> children = DOMUtil.listChildElements(root);
Expand All @@ -79,7 +89,7 @@ public Collection<XNode> parseCollection(File file) throws SchemaException, IOEx
}
return nodes;
}

@Override
public Collection<XNode> parseCollection(String dataString) throws SchemaException {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -451,4 +461,6 @@ public Element serializeSingleElementMapToElement(MapXNode xmap) throws SchemaEx
Element parent = serializeToElement(xmap, subEntry.getKey());
return DOMUtil.getFirstChildElement(parent);
}


}
Expand Up @@ -40,6 +40,8 @@ public interface Parser {

Collection<XNode> parseCollection(File file) throws SchemaException, IOException;

Collection<XNode> parseCollection(InputStream stream) throws SchemaException, IOException;

Collection<XNode> parseCollection(String dataString) throws SchemaException;

boolean canParse(File file) throws IOException;
Expand Down

0 comments on commit dfaf6de

Please sign in to comment.