public static RepositoryReader create(InputStream input) { return new RepositoryXMLReader(input); }
private void readAttributesAndDirectives(XMLStreamReader reader, Map<String, Object> atts, Map<String, String> dirs) throws XMLStreamException { while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { Element element = Element.forName(reader.getLocalName()); switch (element) { case ATTRIBUTE: { readAttributeElement(reader, atts); break; } case DIRECTIVE: { readDirectiveElement(reader, dirs); break; } } } }
switch (element) { case CAPABILITY: { readCapabilityElement(reader, builder); break; readRequirementElement(reader, builder); break;
private void readRequirementElement(XMLStreamReader reader, XResourceBuilder<XResource> builder) throws XMLStreamException { String namespace = reader.getAttributeValue(null, Attribute.NAMESPACE.toString()); Map<String, Object> atts = new HashMap<String, Object>(); Map<String, String> dirs = new HashMap<String, String>(); readAttributesAndDirectives(reader, atts, dirs); try { builder.addRequirement(namespace, atts, dirs); } catch (RuntimeException ex) { throw MESSAGES.cannotReadResourceElement(ex, reader.getLocation()); } }
@Override public XResource nextResource() { try { while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { Element element = Element.forName(reader.getLocalName()); switch (element) { case RESOURCE: { return readResourceElement(reader); } } } } catch (XMLStreamException ex) { throw MESSAGES.cannotReadResourceElement(ex, reader.getLocation()); } return null; }
public FileBasedRepositoryStorage(XRepository repository, File storageDir, ConfigurationPropertyProvider propProvider) { super(repository); if (storageDir == null) throw MESSAGES.illegalArgumentNull("storageDir"); if (propProvider == null) throw MESSAGES.illegalArgumentNull("propProvider"); this.storageDir = storageDir; String filename = propProvider.getProperty(XRepository.PROPERTY_REPOSITORY_STORAGE_FILE, REPOSITORY_XML_NAME); repoFile = new File(storageDir.getAbsolutePath() + File.separator + filename).getAbsoluteFile(); // Initialize repository content if (repoFile.exists()) { RepositoryReader reader; try { reader = RepositoryXMLReader.create(new FileInputStream(repoFile)); } catch (IOException ex) { throw MESSAGES.cannotInitializeRepositoryReader(ex); } String incatt = reader.getRepositoryAttributes().get(Attribute.INCREMENT.getLocalName()); Long increment = new Long(incatt != null ? incatt : "0"); XResource res = reader.nextResource(); while(res != null) { addResourceInternal(res, false); res = reader.nextResource(); } long delta = increment - getResourceIndex().get(); getResourceIndex().addAndGet(delta); reader.close(); } }
private void readCapabilityElement(XMLStreamReader reader, XResourceBuilder<XResource> builder) throws XMLStreamException { String namespace = reader.getAttributeValue(null, Attribute.NAMESPACE.toString()); Map<String, Object> atts = new HashMap<String, Object>(); Map<String, String> dirs = new HashMap<String, String>(); readAttributesAndDirectives(reader, atts, dirs); try { builder.addCapability(namespace, atts, dirs); } catch (RuntimeException ex) { throw MESSAGES.cannotReadResourceElement(ex, reader.getLocation()); } }