/* * * This file was generated by LLRP Code Generator * see http://llrp-toolkit.cvs.sourceforge.net/llrp-toolkit * for more information * Generated on: Mon Mar 10 14:26:47 KST 2014; * */ /* * Copyright 2007 ETH Zurich * * Licensed under 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.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions * and limitations under the License. * */ package kr.ac.kaist.resl.ltk.generated.messages; import org.apache.log4j.Logger; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.llrp.ltk.exceptions.InvalidLLRPMessageException; import org.llrp.ltk.exceptions.MissingParameterException; import kr.ac.kaist.resl.ltk.generated.LLRPConstants; import kr.ac.kaist.resl.ltk.generated.parameters.AccessReportSpec; import kr.ac.kaist.resl.ltk.generated.parameters.AntennaConfiguration; import kr.ac.kaist.resl.ltk.generated.parameters.AntennaProperties; import kr.ac.kaist.resl.ltk.generated.parameters.Custom; import kr.ac.kaist.resl.ltk.generated.parameters.EventsAndReports; import kr.ac.kaist.resl.ltk.generated.parameters.GPIPortCurrentState; import kr.ac.kaist.resl.ltk.generated.parameters.GPOWriteData; import kr.ac.kaist.resl.ltk.generated.parameters.KeepaliveSpec; import kr.ac.kaist.resl.ltk.generated.parameters.ROReportSpec; import kr.ac.kaist.resl.ltk.generated.parameters.ReaderEventNotificationSpec; import org.llrp.ltk.types.Bit; import org.llrp.ltk.types.BitList; import org.llrp.ltk.types.LLRPBitList; import org.llrp.ltk.types.LLRPMessage; import org.llrp.ltk.types.SignedShort; import org.llrp.ltk.types.UnsignedInteger; import org.llrp.ltk.types.UnsignedShort; import java.util.LinkedList; import java.util.List; /** * This command is issued by the Client to the Reader. This command sets the Reader configuration using the parameters specified in this command. Values passed by the SET_READER_CONFIG SHALL apply for the duration of the LLRP connection, or until the values are changed by additional SET_READER_CONFIG messages.For example, ROReportSpec defines the reporting of ROReport format and trigger for a ROSpec. ROReportSpec sent as part of SET_READER_CONFIG becomes the default ROReportSpec for the Reader. A ROReportSpec sent as part of ROSpec in the ADD_ROSPEC command overrides the default value for that ROSpec. However, in cases where there is no ROReportSpec specified in a ROSpec sent as part of ADD_ROSPEC, that particular ROSpec inherits the default ROReportSpec.The data field ResetToFactoryDefault informs the Reader to set all configurable values to factory defaults before applying the remaining parameters. See also {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=69&view=fit">LLRP Specification Section 12.1.3</a>} and {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=127&view=fit">LLRP Specification Section 16.1.38</a>} */ public class SET_READER_CONFIG extends LLRPMessage { public static final SignedShort TYPENUM = new SignedShort(3); private static final Logger LOGGER = Logger.getLogger(SET_READER_CONFIG.class); public static final String RESPONSETYPE = "SET_READER_CONFIG_RESPONSE"; protected Bit resetToFactoryDefault; protected BitList reserved0 = new BitList(7); protected ReaderEventNotificationSpec readerEventNotificationSpec; protected List<AntennaProperties> antennaPropertiesList = new LinkedList<AntennaProperties>(); protected List<AntennaConfiguration> antennaConfigurationList = new LinkedList<AntennaConfiguration>(); protected ROReportSpec rOReportSpec; protected AccessReportSpec accessReportSpec; protected KeepaliveSpec keepaliveSpec; protected List<GPOWriteData> gPOWriteDataList = new LinkedList<GPOWriteData>(); protected List<GPIPortCurrentState> gPIPortCurrentStateList = new LinkedList<GPIPortCurrentState>(); protected EventsAndReports eventsAndReports; protected List<Custom> customList = new LinkedList<Custom>(); /** * empty constructor to create new message * with LLRP version set to 1.0 (0x1). */ public SET_READER_CONFIG() { setVersion(new BitList(0, 0, 1)); } /** * Constructor to create message from binary encoded message * calls decodeBinary to decode message. * @param list to be decoded */ public SET_READER_CONFIG(final LLRPBitList list) throws InvalidLLRPMessageException { decodeBinary(list.toByteArray()); } /** * Constructor to create message from binary encoded message * calls decodeBinary to decode message. * @param byteArray representing message */ public SET_READER_CONFIG(final byte[] byteArray) throws InvalidLLRPMessageException { decodeBinary(byteArray); } /** * Constructor to create message from xml encoded message * calls decodeXML to decode message. * @param document to be decoded */ public SET_READER_CONFIG(final Document document) throws InvalidLLRPMessageException { decodeXML(document); } /** * {@inheritDoc} */ protected LLRPBitList encodeBinarySpecific() throws InvalidLLRPMessageException { LLRPBitList resultBits = new LLRPBitList(); if (resetToFactoryDefault == null) { LOGGER.warn(" resetToFactoryDefault not set"); throw new InvalidLLRPMessageException( " resetToFactoryDefault not set for Parameter of Type SET_READER_CONFIG"); } resultBits.append(resetToFactoryDefault.encodeBinary()); resultBits.append(reserved0.encodeBinary()); if (readerEventNotificationSpec == null) { // optional parameter, may be null LOGGER.info(" readerEventNotificationSpec not set"); } else { resultBits.append(readerEventNotificationSpec.encodeBinary()); } if (antennaPropertiesList == null) { //just warn - it is optional LOGGER.info(" antennaPropertiesList not set"); } else { for (AntennaProperties field : antennaPropertiesList) { resultBits.append(field.encodeBinary()); } } if (antennaConfigurationList == null) { //just warn - it is optional LOGGER.info(" antennaConfigurationList not set"); } else { for (AntennaConfiguration field : antennaConfigurationList) { resultBits.append(field.encodeBinary()); } } if (rOReportSpec == null) { // optional parameter, may be null LOGGER.info(" rOReportSpec not set"); } else { resultBits.append(rOReportSpec.encodeBinary()); } if (accessReportSpec == null) { // optional parameter, may be null LOGGER.info(" accessReportSpec not set"); } else { resultBits.append(accessReportSpec.encodeBinary()); } if (keepaliveSpec == null) { // optional parameter, may be null LOGGER.info(" keepaliveSpec not set"); } else { resultBits.append(keepaliveSpec.encodeBinary()); } if (gPOWriteDataList == null) { //just warn - it is optional LOGGER.info(" gPOWriteDataList not set"); } else { for (GPOWriteData field : gPOWriteDataList) { resultBits.append(field.encodeBinary()); } } if (gPIPortCurrentStateList == null) { //just warn - it is optional LOGGER.info(" gPIPortCurrentStateList not set"); } else { for (GPIPortCurrentState field : gPIPortCurrentStateList) { resultBits.append(field.encodeBinary()); } } if (eventsAndReports == null) { // optional parameter, may be null LOGGER.info(" eventsAndReports not set"); } else { resultBits.append(eventsAndReports.encodeBinary()); } if (customList == null) { //just warn - it is optional LOGGER.info(" customList not set"); } else { for (Custom field : customList) { resultBits.append(field.encodeBinary()); } } return resultBits; } /** * {@inheritDoc} */ public Document encodeXML() throws InvalidLLRPMessageException { try { Namespace ns = Namespace.getNamespace("llrp", LLRPConstants.LLRPNAMESPACE); Element root = new Element("SET_READER_CONFIG", ns); // Element root = new Element("SET_READER_CONFIG"); root.addNamespaceDeclaration(Namespace.getNamespace("llrp", LLRPConstants.LLRPNAMESPACE)); if (version == null) { throw new InvalidLLRPMessageException("Version not set"); } else { root.setAttribute("Version", version.toInteger().toString()); } if (messageID == null) { throw new InvalidLLRPMessageException("MessageID not set"); } else { root.setAttribute("MessageID", messageID.toString(10)); } if (resetToFactoryDefault == null) { LOGGER.warn(" resetToFactoryDefault not set"); throw new MissingParameterException( " resetToFactoryDefault not set"); } else { root.addContent(resetToFactoryDefault.encodeXML( "ResetToFactoryDefault", ns)); } //root.addContent(reserved0.encodeXML("reserved",ns)); //parameters if (readerEventNotificationSpec == null) { LOGGER.info("readerEventNotificationSpec not set"); } else { root.addContent(readerEventNotificationSpec.encodeXML( readerEventNotificationSpec.getClass().getSimpleName(), ns)); } if (antennaPropertiesList == null) { LOGGER.info("antennaPropertiesList not set"); } else { for (AntennaProperties field : antennaPropertiesList) { root.addContent(field.encodeXML(field.getClass().getName() .replaceAll(field.getClass() .getPackage() .getName() + ".", ""), ns)); } } if (antennaConfigurationList == null) { LOGGER.info("antennaConfigurationList not set"); } else { for (AntennaConfiguration field : antennaConfigurationList) { root.addContent(field.encodeXML(field.getClass().getName() .replaceAll(field.getClass() .getPackage() .getName() + ".", ""), ns)); } } if (rOReportSpec == null) { LOGGER.info("rOReportSpec not set"); } else { root.addContent(rOReportSpec.encodeXML( rOReportSpec.getClass().getSimpleName(), ns)); } if (accessReportSpec == null) { LOGGER.info("accessReportSpec not set"); } else { root.addContent(accessReportSpec.encodeXML( accessReportSpec.getClass().getSimpleName(), ns)); } if (keepaliveSpec == null) { LOGGER.info("keepaliveSpec not set"); } else { root.addContent(keepaliveSpec.encodeXML( keepaliveSpec.getClass().getSimpleName(), ns)); } if (gPOWriteDataList == null) { LOGGER.info("gPOWriteDataList not set"); } else { for (GPOWriteData field : gPOWriteDataList) { root.addContent(field.encodeXML(field.getClass().getName() .replaceAll(field.getClass() .getPackage() .getName() + ".", ""), ns)); } } if (gPIPortCurrentStateList == null) { LOGGER.info("gPIPortCurrentStateList not set"); } else { for (GPIPortCurrentState field : gPIPortCurrentStateList) { root.addContent(field.encodeXML(field.getClass().getName() .replaceAll(field.getClass() .getPackage() .getName() + ".", ""), ns)); } } if (eventsAndReports == null) { LOGGER.info("eventsAndReports not set"); } else { root.addContent(eventsAndReports.encodeXML( eventsAndReports.getClass().getSimpleName(), ns)); } if (customList == null) { LOGGER.info("customList not set"); } else { for (Custom field : customList) { root.addContent(field.encodeXML(field.getClass().getName() .replaceAll(field.getClass() .getPackage() .getName() + ".", ""), ns)); } } Document doc = new Document(root); if (isValidXMLMessage(doc, LLRPConstants.LLRPMESSAGESCHEMAPATH)) { return doc; } else { return null; } } catch (IllegalArgumentException e) { throw new InvalidLLRPMessageException(e.getMessage()); } catch (MissingParameterException e) { throw new InvalidLLRPMessageException(e.getMessage()); } } /** * {@inheritDoc} */ protected void decodeBinarySpecific(LLRPBitList binary) throws InvalidLLRPMessageException { int position = 0; int tempByteLength; int tempLength = 0; int count; SignedShort type; int fieldCount; Custom custom; resetToFactoryDefault = new Bit(binary.subList(position, Bit.length())); position += Bit.length(); position += reserved0.length(); // look ahead to see type // may be optional or exactly once type = null; tempByteLength = 0; tempLength = 0; try { // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } } catch (IllegalArgumentException le) { // if an IllegalArgumentException is thrown, list was not long enough so the parameter is missing LOGGER.info( "SET_READER_CONFIG misses optional parameter of type ReaderEventNotificationSpec"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = readerEventNotificationSpec.length(); } if ((type != null) && type.equals(ReaderEventNotificationSpec.TYPENUM)) { readerEventNotificationSpec = new ReaderEventNotificationSpec(binary.subList( position, tempLength)); position += tempLength; LOGGER.debug( " readerEventNotificationSpec is instantiated with ReaderEventNotificationSpec with length" + tempLength); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type ReaderEventNotificationSpec"); } // list of parameters antennaPropertiesList = new LinkedList<AntennaProperties>(); LOGGER.debug("decoding parameter antennaPropertiesList "); while (position < binary.length()) { // store if one parameter matched boolean atLeastOnce = false; // look ahead to see type // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } //add parameter to list if type number matches if ((type != null) && type.equals(AntennaProperties.TYPENUM)) { //if first bit is 1 it is a TV Parameter if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = AntennaProperties.length(); } antennaPropertiesList.add(new AntennaProperties(binary.subList( position, tempLength))); LOGGER.debug( "adding AntennaProperties to antennaPropertiesList "); atLeastOnce = true; position += tempLength; } if (!atLeastOnce) { //no parameter matched therefore we jump out of the loop break; } } //if list is still empty no parameter matched if (antennaPropertiesList.isEmpty()) { LOGGER.info( "encoded message does not contain parameter for optional antennaPropertiesList"); } // list of parameters antennaConfigurationList = new LinkedList<AntennaConfiguration>(); LOGGER.debug("decoding parameter antennaConfigurationList "); while (position < binary.length()) { // store if one parameter matched boolean atLeastOnce = false; // look ahead to see type // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } //add parameter to list if type number matches if ((type != null) && type.equals(AntennaConfiguration.TYPENUM)) { //if first bit is 1 it is a TV Parameter if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = AntennaConfiguration.length(); } antennaConfigurationList.add(new AntennaConfiguration( binary.subList(position, tempLength))); LOGGER.debug( "adding AntennaConfiguration to antennaConfigurationList "); atLeastOnce = true; position += tempLength; } if (!atLeastOnce) { //no parameter matched therefore we jump out of the loop break; } } //if list is still empty no parameter matched if (antennaConfigurationList.isEmpty()) { LOGGER.info( "encoded message does not contain parameter for optional antennaConfigurationList"); } // look ahead to see type // may be optional or exactly once type = null; tempByteLength = 0; tempLength = 0; try { // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } } catch (IllegalArgumentException le) { // if an IllegalArgumentException is thrown, list was not long enough so the parameter is missing LOGGER.info( "SET_READER_CONFIG misses optional parameter of type ROReportSpec"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = rOReportSpec.length(); } if ((type != null) && type.equals(ROReportSpec.TYPENUM)) { rOReportSpec = new ROReportSpec(binary.subList(position, tempLength)); position += tempLength; LOGGER.debug( " rOReportSpec is instantiated with ROReportSpec with length" + tempLength); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type ROReportSpec"); } // look ahead to see type // may be optional or exactly once type = null; tempByteLength = 0; tempLength = 0; try { // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } } catch (IllegalArgumentException le) { // if an IllegalArgumentException is thrown, list was not long enough so the parameter is missing LOGGER.info( "SET_READER_CONFIG misses optional parameter of type AccessReportSpec"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = accessReportSpec.length(); } if ((type != null) && type.equals(AccessReportSpec.TYPENUM)) { accessReportSpec = new AccessReportSpec(binary.subList(position, tempLength)); position += tempLength; LOGGER.debug( " accessReportSpec is instantiated with AccessReportSpec with length" + tempLength); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type AccessReportSpec"); } // look ahead to see type // may be optional or exactly once type = null; tempByteLength = 0; tempLength = 0; try { // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } } catch (IllegalArgumentException le) { // if an IllegalArgumentException is thrown, list was not long enough so the parameter is missing LOGGER.info( "SET_READER_CONFIG misses optional parameter of type KeepaliveSpec"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = keepaliveSpec.length(); } if ((type != null) && type.equals(KeepaliveSpec.TYPENUM)) { keepaliveSpec = new KeepaliveSpec(binary.subList(position, tempLength)); position += tempLength; LOGGER.debug( " keepaliveSpec is instantiated with KeepaliveSpec with length" + tempLength); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type KeepaliveSpec"); } // list of parameters gPOWriteDataList = new LinkedList<GPOWriteData>(); LOGGER.debug("decoding parameter gPOWriteDataList "); while (position < binary.length()) { // store if one parameter matched boolean atLeastOnce = false; // look ahead to see type // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } //add parameter to list if type number matches if ((type != null) && type.equals(GPOWriteData.TYPENUM)) { //if first bit is 1 it is a TV Parameter if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = GPOWriteData.length(); } gPOWriteDataList.add(new GPOWriteData(binary.subList(position, tempLength))); LOGGER.debug("adding GPOWriteData to gPOWriteDataList "); atLeastOnce = true; position += tempLength; } if (!atLeastOnce) { //no parameter matched therefore we jump out of the loop break; } } //if list is still empty no parameter matched if (gPOWriteDataList.isEmpty()) { LOGGER.info( "encoded message does not contain parameter for optional gPOWriteDataList"); } // list of parameters gPIPortCurrentStateList = new LinkedList<GPIPortCurrentState>(); LOGGER.debug("decoding parameter gPIPortCurrentStateList "); while (position < binary.length()) { // store if one parameter matched boolean atLeastOnce = false; // look ahead to see type // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } //add parameter to list if type number matches if ((type != null) && type.equals(GPIPortCurrentState.TYPENUM)) { //if first bit is 1 it is a TV Parameter if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = GPIPortCurrentState.length(); } gPIPortCurrentStateList.add(new GPIPortCurrentState( binary.subList(position, tempLength))); LOGGER.debug( "adding GPIPortCurrentState to gPIPortCurrentStateList "); atLeastOnce = true; position += tempLength; } if (!atLeastOnce) { //no parameter matched therefore we jump out of the loop break; } } //if list is still empty no parameter matched if (gPIPortCurrentStateList.isEmpty()) { LOGGER.info( "encoded message does not contain parameter for optional gPIPortCurrentStateList"); } // look ahead to see type // may be optional or exactly once type = null; tempByteLength = 0; tempLength = 0; try { // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } } catch (IllegalArgumentException le) { // if an IllegalArgumentException is thrown, list was not long enough so the parameter is missing LOGGER.info( "SET_READER_CONFIG misses optional parameter of type EventsAndReports"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = eventsAndReports.length(); } if ((type != null) && type.equals(EventsAndReports.TYPENUM)) { eventsAndReports = new EventsAndReports(binary.subList(position, tempLength)); position += tempLength; LOGGER.debug( " eventsAndReports is instantiated with EventsAndReports with length" + tempLength); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type EventsAndReports"); } // list of parameters customList = new LinkedList<Custom>(); LOGGER.debug("decoding parameter customList "); while (position < binary.length()) { // store if one parameter matched boolean atLeastOnce = false; // look ahead to see type // if first bit is one it is a TV Parameter if (binary.get(position)) { // do not take the first bit as it is always 1 type = new SignedShort(binary.subList(position + 1, 7)); } else { type = new SignedShort(binary.subList(position + RESERVEDLENGTH, TYPENUMBERLENGTH)); tempByteLength = new UnsignedShort(binary.subList(position + RESERVEDLENGTH + TYPENUMBERLENGTH, UnsignedShort.length())).toShort(); tempLength = 8 * tempByteLength; } // custom if ((type != null) && type.equals(Custom.TYPENUM)) { Custom cus = new Custom(binary.subList(position, tempLength)); //allowed custom parameters for this parameter //end allowed parameters //if none matched continue wasn't called and we add just cus as we found no specific vendor implementation customList.add(cus); position += tempLength; atLeastOnce = true; } if (!atLeastOnce) { //no parameter matched therefore we jump out of the loop break; } } //if list is still empty no parameter matched if (customList.isEmpty()) { LOGGER.info( "encoded message does not contain parameter for optional customList"); } } /** * {@inheritDoc} */ public void decodeXML(final Document document) throws InvalidLLRPMessageException { Element temp = null; Custom custom; // child element are always in default LLRP namespace Namespace ns = Namespace.getNamespace(LLRPConstants.LLRPNAMESPACE); try { isValidXMLMessage(document, LLRPConstants.LLRPMESSAGESCHEMAPATH); Element root = (Element) document.getRootElement().clone(); List<Element> tempList = null; // the version field is always 3 bit long // if the version attribute is not set in the LTK-XML message, // it is set to version 001 String versionAttribute = root.getAttributeValue("Version"); if (versionAttribute != null) { version = new BitList(3); version.setValue(new Integer(versionAttribute)); } else { version = new BitList(0, 0, 1); } messageID = new UnsignedInteger(root.getAttributeValue("MessageID")); temp = root.getChild("ResetToFactoryDefault", root.getNamespace()); //check if this element exist if (temp != null) { resetToFactoryDefault = new Bit(temp); } else { LOGGER.warn( "Element resetToFactoryDefault not provided in xml as child of " + root.getName()); throw new MissingParameterException( "Element resetToFactoryDefault not provided"); } root.removeChild("ResetToFactoryDefault", root.getNamespace()); //parameter - not choices - no special actions needed temp = root.getChild("ReaderEventNotificationSpec", ns); if (temp != null) { readerEventNotificationSpec = new ReaderEventNotificationSpec(temp); LOGGER.info( "setting parameter readerEventNotificationSpec for parameter SET_READER_CONFIG"); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type readerEventNotificationSpec"); } root.removeChild("ReaderEventNotificationSpec", ns); //parameter - not choices - no special actions needed //we expect a list of parameters antennaPropertiesList = new LinkedList<AntennaProperties>(); tempList = root.getChildren("AntennaProperties", ns); if ((tempList == null) || tempList.isEmpty()) { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type antennaPropertiesList"); } else { for (Element e : tempList) { antennaPropertiesList.add(new AntennaProperties(e)); LOGGER.debug( "adding AntennaProperties to antennaPropertiesList "); } } root.removeChildren("AntennaProperties", ns); //parameter - not choices - no special actions needed //we expect a list of parameters antennaConfigurationList = new LinkedList<AntennaConfiguration>(); tempList = root.getChildren("AntennaConfiguration", ns); if ((tempList == null) || tempList.isEmpty()) { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type antennaConfigurationList"); } else { for (Element e : tempList) { antennaConfigurationList.add(new AntennaConfiguration(e)); LOGGER.debug( "adding AntennaConfiguration to antennaConfigurationList "); } } root.removeChildren("AntennaConfiguration", ns); //parameter - not choices - no special actions needed temp = root.getChild("ROReportSpec", ns); if (temp != null) { rOReportSpec = new ROReportSpec(temp); LOGGER.info( "setting parameter rOReportSpec for parameter SET_READER_CONFIG"); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type rOReportSpec"); } root.removeChild("ROReportSpec", ns); //parameter - not choices - no special actions needed temp = root.getChild("AccessReportSpec", ns); if (temp != null) { accessReportSpec = new AccessReportSpec(temp); LOGGER.info( "setting parameter accessReportSpec for parameter SET_READER_CONFIG"); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type accessReportSpec"); } root.removeChild("AccessReportSpec", ns); //parameter - not choices - no special actions needed temp = root.getChild("KeepaliveSpec", ns); if (temp != null) { keepaliveSpec = new KeepaliveSpec(temp); LOGGER.info( "setting parameter keepaliveSpec for parameter SET_READER_CONFIG"); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type keepaliveSpec"); } root.removeChild("KeepaliveSpec", ns); //parameter - not choices - no special actions needed //we expect a list of parameters gPOWriteDataList = new LinkedList<GPOWriteData>(); tempList = root.getChildren("GPOWriteData", ns); if ((tempList == null) || tempList.isEmpty()) { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type gPOWriteDataList"); } else { for (Element e : tempList) { gPOWriteDataList.add(new GPOWriteData(e)); LOGGER.debug("adding GPOWriteData to gPOWriteDataList "); } } root.removeChildren("GPOWriteData", ns); //parameter - not choices - no special actions needed //we expect a list of parameters gPIPortCurrentStateList = new LinkedList<GPIPortCurrentState>(); tempList = root.getChildren("GPIPortCurrentState", ns); if ((tempList == null) || tempList.isEmpty()) { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type gPIPortCurrentStateList"); } else { for (Element e : tempList) { gPIPortCurrentStateList.add(new GPIPortCurrentState(e)); LOGGER.debug( "adding GPIPortCurrentState to gPIPortCurrentStateList "); } } root.removeChildren("GPIPortCurrentState", ns); //parameter - not choices - no special actions needed temp = root.getChild("EventsAndReports", ns); if (temp != null) { eventsAndReports = new EventsAndReports(temp); LOGGER.info( "setting parameter eventsAndReports for parameter SET_READER_CONFIG"); } else { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type eventsAndReports"); } root.removeChild("EventsAndReports", ns); //parameter - not choices - no special actions needed //we expect a list of parameters customList = new LinkedList<Custom>(); tempList = root.getChildren("Custom", ns); if ((tempList == null) || tempList.isEmpty()) { LOGGER.info( "SET_READER_CONFIG misses optional parameter of type customList"); } else { for (Element e : tempList) { customList.add(new Custom(e)); LOGGER.debug("adding Custom to customList "); } } root.removeChildren("Custom", ns); //custom parameter //end custom if (root.getChildren().size() > 0) { String message = "SET_READER_CONFIG has unknown element " + ((Element) root.getChildren().get(0)).getName(); throw new InvalidLLRPMessageException(message); } } catch (IllegalArgumentException e) { throw new InvalidLLRPMessageException(e.getMessage()); } catch (MissingParameterException e) { throw new InvalidLLRPMessageException(e.getMessage()); } } //setters /** * set resetToFactoryDefault of type Bit . * @param resetToFactoryDefault to be set */ public void setResetToFactoryDefault(final Bit resetToFactoryDefault) { this.resetToFactoryDefault = resetToFactoryDefault; } /** * set readerEventNotificationSpec of type ReaderEventNotificationSpec. * @param readerEventNotificationSpec to be set */ public void setReaderEventNotificationSpec( final ReaderEventNotificationSpec readerEventNotificationSpec) { this.readerEventNotificationSpec = readerEventNotificationSpec; } /** * set antennaPropertiesList of type List <AntennaProperties>. * @param antennaPropertiesList to be set */ public void setAntennaPropertiesList( final List<AntennaProperties> antennaPropertiesList) { this.antennaPropertiesList = antennaPropertiesList; } /** * set antennaConfigurationList of type List <AntennaConfiguration>. * @param antennaConfigurationList to be set */ public void setAntennaConfigurationList( final List<AntennaConfiguration> antennaConfigurationList) { this.antennaConfigurationList = antennaConfigurationList; } /** * set rOReportSpec of type ROReportSpec. * @param rOReportSpec to be set */ public void setROReportSpec(final ROReportSpec rOReportSpec) { this.rOReportSpec = rOReportSpec; } /** * set accessReportSpec of type AccessReportSpec. * @param accessReportSpec to be set */ public void setAccessReportSpec(final AccessReportSpec accessReportSpec) { this.accessReportSpec = accessReportSpec; } /** * set keepaliveSpec of type KeepaliveSpec. * @param keepaliveSpec to be set */ public void setKeepaliveSpec(final KeepaliveSpec keepaliveSpec) { this.keepaliveSpec = keepaliveSpec; } /** * set gPOWriteDataList of type List <GPOWriteData>. * @param gPOWriteDataList to be set */ public void setGPOWriteDataList(final List<GPOWriteData> gPOWriteDataList) { this.gPOWriteDataList = gPOWriteDataList; } /** * set gPIPortCurrentStateList of type List <GPIPortCurrentState>. * @param gPIPortCurrentStateList to be set */ public void setGPIPortCurrentStateList( final List<GPIPortCurrentState> gPIPortCurrentStateList) { this.gPIPortCurrentStateList = gPIPortCurrentStateList; } /** * set eventsAndReports of type EventsAndReports. * @param eventsAndReports to be set */ public void setEventsAndReports(final EventsAndReports eventsAndReports) { this.eventsAndReports = eventsAndReports; } /** * set customList of type List <Custom>. * @param customList to be set */ public void setCustomList(final List<Custom> customList) { this.customList = customList; } // end setter //getters /** * get resetToFactoryDefault of type Bit. * @return type Bit to be set */ public Bit getResetToFactoryDefault() { return this.resetToFactoryDefault; } /** * get readerEventNotificationSpec of type ReaderEventNotificationSpec . * @return ReaderEventNotificationSpec */ public ReaderEventNotificationSpec getReaderEventNotificationSpec() { return readerEventNotificationSpec; } /** * get antennaPropertiesList of type List <AntennaProperties> . * @return List <AntennaProperties> */ public List<AntennaProperties> getAntennaPropertiesList() { return antennaPropertiesList; } /** * get antennaConfigurationList of type List <AntennaConfiguration> . * @return List <AntennaConfiguration> */ public List<AntennaConfiguration> getAntennaConfigurationList() { return antennaConfigurationList; } /** * get rOReportSpec of type ROReportSpec . * @return ROReportSpec */ public ROReportSpec getROReportSpec() { return rOReportSpec; } /** * get accessReportSpec of type AccessReportSpec . * @return AccessReportSpec */ public AccessReportSpec getAccessReportSpec() { return accessReportSpec; } /** * get keepaliveSpec of type KeepaliveSpec . * @return KeepaliveSpec */ public KeepaliveSpec getKeepaliveSpec() { return keepaliveSpec; } /** * get gPOWriteDataList of type List <GPOWriteData> . * @return List <GPOWriteData> */ public List<GPOWriteData> getGPOWriteDataList() { return gPOWriteDataList; } /** * get gPIPortCurrentStateList of type List <GPIPortCurrentState> . * @return List <GPIPortCurrentState> */ public List<GPIPortCurrentState> getGPIPortCurrentStateList() { return gPIPortCurrentStateList; } /** * get eventsAndReports of type EventsAndReports . * @return EventsAndReports */ public EventsAndReports getEventsAndReports() { return eventsAndReports; } /** * get customList of type List <Custom> . * @return List <Custom> */ public List<Custom> getCustomList() { return customList; } // end getters //add methods /** * add element antennaProperties of type AntennaProperties . * @param antennaProperties of type AntennaProperties */ public void addToAntennaPropertiesList(AntennaProperties antennaProperties) { if (this.antennaPropertiesList == null) { this.antennaPropertiesList = new LinkedList<AntennaProperties>(); } this.antennaPropertiesList.add(antennaProperties); } /** * add element antennaConfiguration of type AntennaConfiguration . * @param antennaConfiguration of type AntennaConfiguration */ public void addToAntennaConfigurationList( AntennaConfiguration antennaConfiguration) { if (this.antennaConfigurationList == null) { this.antennaConfigurationList = new LinkedList<AntennaConfiguration>(); } this.antennaConfigurationList.add(antennaConfiguration); } /** * add element gPOWriteData of type GPOWriteData . * @param gPOWriteData of type GPOWriteData */ public void addToGPOWriteDataList(GPOWriteData gPOWriteData) { if (this.gPOWriteDataList == null) { this.gPOWriteDataList = new LinkedList<GPOWriteData>(); } this.gPOWriteDataList.add(gPOWriteData); } /** * add element gPIPortCurrentState of type GPIPortCurrentState . * @param gPIPortCurrentState of type GPIPortCurrentState */ public void addToGPIPortCurrentStateList( GPIPortCurrentState gPIPortCurrentState) { if (this.gPIPortCurrentStateList == null) { this.gPIPortCurrentStateList = new LinkedList<GPIPortCurrentState>(); } this.gPIPortCurrentStateList.add(gPIPortCurrentState); } /** * add element custom of type Custom . * @param custom of type Custom */ public void addToCustomList(Custom custom) { if (this.customList == null) { this.customList = new LinkedList<Custom>(); } this.customList.add(custom); } // end add @Override public String getResponseType() { return RESPONSETYPE; } @Override public String getName() { return "SET_READER_CONFIG"; } /** * return uniuque type number. * @return SignedShort holding unique type number */ public SignedShort getTypeNum() { return TYPENUM; } }