All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.fedora.server.journal.xmlhelpers.BindingMapXmlReader Maven / Gradle / Ivy

Go to download

The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.

The newest version!
/*
 * -----------------------------------------------------------------------------
 *
 * 

License and Copyright: The contents of this file are subject to the * Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at * http://www.fedora-commons.org/licenses.

* *

Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License.

* *

The entire file consists of original code.

*

Copyright © 2008 Fedora Commons, Inc.
*

Copyright © 2002-2007 The Rector and Visitors of the University of * Virginia and Cornell University
* All rights reserved.

* * ----------------------------------------------------------------------------- */ package fedora.server.journal.xmlhelpers; import java.util.ArrayList; import java.util.List; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; import fedora.server.journal.JournalException; import fedora.server.storage.types.DSBinding; import fedora.server.storage.types.DSBindingMap; /** *

* Title: BindingMapXmlReader.java *

*

* Description: Reads an entire DSBindingMap from the * Journal file. *

* * @author [email protected] * @version $Id: BindingMapXmlReader.java 5166 2006-10-25 11:05:45 +0000 (Wed, * 25 Oct 2006) eddie $ */ public class BindingMapXmlReader extends AbstractXmlReader { public DSBindingMap readBindingMap(XMLEventReader reader) throws JournalException, XMLStreamException { DSBindingMap map = readBindingMapStartTag(reader); map.dsBindings = readBindingsUntilEndOfMap(reader); return map; } /** * The start tag of the binding map must contain the four required * attributes. */ private DSBindingMap readBindingMapStartTag(XMLEventReader reader) throws XMLStreamException, JournalException { DSBindingMap map = new DSBindingMap(); XMLEvent event = reader.nextTag(); if (!isStartTagEvent(event, QNAME_TAG_DS_BINDING_MAP)) { throw getNotStartTagException(QNAME_TAG_DS_BINDING_MAP, event); } StartElement start = event.asStartElement(); map.dsBindMapID = getRequiredAttributeValue(start, QNAME_ATTR_DS_BIND_MAP_ID); map.dsBindMechanismPID = getRequiredAttributeValue(start, QNAME_ATTR_DS_BIND_MECHANISM_PID); map.dsBindMapLabel = getRequiredAttributeValue(start, QNAME_ATTR_DS_BIND_MAP_LABEL); map.state = getRequiredAttributeValue(start, QNAME_ATTR_STATE); return map; } /** * Read binding tags until we reach the end of the bindings map. */ private DSBinding[] readBindingsUntilEndOfMap(XMLEventReader reader) throws XMLStreamException, JournalException { List bindings = new ArrayList(); while (true) { XMLEvent event = reader.nextTag(); if (isStartTagEvent(event, QNAME_TAG_DS_BINDING)) { bindings.add(readBinding(reader, event.asStartElement())); } else if (isEndTagEvent(event, QNAME_TAG_DS_BINDING_MAP)) { break; } else { throw getNotNextMemberOrEndOfGroupException(QNAME_TAG_DS_BINDING_MAP, QNAME_TAG_DS_BINDING, event); } } return bindings.toArray(new DSBinding[bindings.size()]); } /** * A binding consists of a start tag with attributes, followed by an end * tag. */ private DSBinding readBinding(XMLEventReader reader, StartElement start) throws JournalException, XMLStreamException { DSBinding binding = new DSBinding(); binding.bindKeyName = getRequiredAttributeValue(start, QNAME_ATTR_BIND_KEY_NAME); binding.bindLabel = getRequiredAttributeValue(start, QNAME_ATTR_BIND_LABEL); binding.datastreamID = getRequiredAttributeValue(start, QNAME_ATTR_DATASTREAM_ID); binding.seqNo = getRequiredAttributeValue(start, QNAME_ATTR_SEQ_NO); XMLEvent endTag = reader.nextTag(); if (!isEndTagEvent(endTag, QNAME_TAG_DS_BINDING)) { throw getNotEndTagException(QNAME_TAG_DS_BINDING, endTag); } return binding; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy