/* * * 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:48 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.parameters; import org.apache.log4j.Logger; import org.jdom.Content; 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.Custom; import kr.ac.kaist.resl.ltk.generated.parameters.FrequencyRSSILevelEntry; import kr.ac.kaist.resl.ltk.generated.parameters.ROSpecID; import kr.ac.kaist.resl.ltk.generated.parameters.SpecIndex; import org.llrp.ltk.types.LLRPBitList; import org.llrp.ltk.types.LLRPMessage; import org.llrp.ltk.types.SignedShort; import org.llrp.ltk.types.TLVParameter; import org.llrp.ltk.types.TVParameter; import org.llrp.ltk.types.UnsignedShort; import java.util.LinkedList; import java.util.List; /** * This describes the content of the RF Survey Report. See also {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=85&view=fit">LLRP Specification Section 13.2.4</a>} and {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=147&view=fit">LLRP Specification Section 16.2.7.4</a>} */ /** * This describes the content of the RF Survey Report. See also {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=85&view=fit">LLRP Specification Section 13.2.4</a>} and {@link <a href="http://www.epcglobalinc.org/standards/llrp/llrp_1_0_1-standard-20070813.pdf#page=147&view=fit">LLRP Specification Section 16.2.7.4</a>} . */ public class RFSurveyReportData extends TLVParameter { public static final SignedShort TYPENUM = new SignedShort(242); private static final Logger LOGGER = Logger.getLogger(RFSurveyReportData.class); protected ROSpecID rOSpecID; protected SpecIndex specIndex; protected List<FrequencyRSSILevelEntry> frequencyRSSILevelEntryList = new LinkedList<FrequencyRSSILevelEntry>(); protected List<Custom> customList = new LinkedList<Custom>(); /** * empty constructor to create new parameter. */ public RFSurveyReportData() { } /** * Constructor to create parameter from binary encoded parameter * calls decodeBinary to decode parameter. * @param list to be decoded */ public RFSurveyReportData(LLRPBitList list) { decodeBinary(list); } /** * Constructor to create parameter from xml encoded parameter * calls decodeXML to decode parameter. * @param element to be decoded */ public RFSurveyReportData(Element element) throws InvalidLLRPMessageException { decodeXML(element); } /** * {@inheritDoc} */ public LLRPBitList encodeBinarySpecific() { LLRPBitList resultBits = new LLRPBitList(); if (rOSpecID == null) { // optional parameter, may be null LOGGER.info(" rOSpecID not set"); } else { resultBits.append(rOSpecID.encodeBinary()); } if (specIndex == null) { // optional parameter, may be null LOGGER.info(" specIndex not set"); } else { resultBits.append(specIndex.encodeBinary()); } if (frequencyRSSILevelEntryList == null) { LOGGER.warn(" frequencyRSSILevelEntryList not set"); //parameter has to be set - throw exception throw new MissingParameterException( " frequencyRSSILevelEntryList not set"); } else { for (FrequencyRSSILevelEntry field : frequencyRSSILevelEntryList) { resultBits.append(field.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 Content encodeXML(String name, Namespace ns) { // element in namespace defined by parent element Element element = new Element(name, ns); // child element are always in default LLRP namespace ns = Namespace.getNamespace("llrp", LLRPConstants.LLRPNAMESPACE); //parameters if (rOSpecID == null) { LOGGER.info("rOSpecID not set"); } else { element.addContent(rOSpecID.encodeXML(rOSpecID.getClass() .getSimpleName(), ns)); } if (specIndex == null) { LOGGER.info("specIndex not set"); } else { element.addContent(specIndex.encodeXML(specIndex.getClass() .getSimpleName(), ns)); } if (frequencyRSSILevelEntryList == null) { LOGGER.warn(" frequencyRSSILevelEntryList not set"); throw new MissingParameterException( " frequencyRSSILevelEntryList not set"); } for (FrequencyRSSILevelEntry field : frequencyRSSILevelEntryList) { element.addContent(field.encodeXML(field.getClass().getName() .replaceAll(field.getClass() .getPackage() .getName() + ".", ""), ns)); } if (customList == null) { LOGGER.info("customList not set"); } else { for (Custom field : customList) { element.addContent(field.encodeXML(field.getClass().getName() .replaceAll(field.getClass() .getPackage() .getName() + ".", ""), ns)); } } return element; } /** * {@inheritDoc} */ protected void decodeBinarySpecific(LLRPBitList binary) { int position = 0; int tempByteLength; int tempLength = 0; int count; SignedShort type; int fieldCount; Custom custom; // 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( "RFSurveyReportData misses optional parameter of type ROSpecID"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = rOSpecID.length(); } if ((type != null) && type.equals(ROSpecID.TYPENUM)) { rOSpecID = new ROSpecID(binary.subList(position, tempLength)); position += tempLength; LOGGER.debug(" rOSpecID is instantiated with ROSpecID with length" + tempLength); } else { LOGGER.info( "RFSurveyReportData misses optional parameter of type ROSpecID"); } // 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( "RFSurveyReportData misses optional parameter of type SpecIndex"); } if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = specIndex.length(); } if ((type != null) && type.equals(SpecIndex.TYPENUM)) { specIndex = new SpecIndex(binary.subList(position, tempLength)); position += tempLength; LOGGER.debug( " specIndex is instantiated with SpecIndex with length" + tempLength); } else { LOGGER.info( "RFSurveyReportData misses optional parameter of type SpecIndex"); } // list of parameters frequencyRSSILevelEntryList = new LinkedList<FrequencyRSSILevelEntry>(); LOGGER.debug("decoding parameter frequencyRSSILevelEntryList "); while (position < binary.length()) { // store if one parameter matched boolean atLeastOnce = false; // look ahead to see type 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(FrequencyRSSILevelEntry.TYPENUM)) { if (binary.get(position)) { // length can statically be determined for TV Parameters tempLength = FrequencyRSSILevelEntry.length(); } frequencyRSSILevelEntryList.add(new FrequencyRSSILevelEntry( binary.subList(position, tempLength))); LOGGER.debug( "adding FrequencyRSSILevelEntry to frequencyRSSILevelEntryList "); 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 (frequencyRSSILevelEntryList.isEmpty()) { LOGGER.warn( "encoded message does not contain parameter for non optional frequencyRSSILevelEntryList"); throw new MissingParameterException( "RFSurveyReportData misses non optional parameter of type FrequencyRSSILevelEntry"); } // 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 (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)); // custom parameters for this parameter // RFSurveyReportData //end 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(Element element) throws InvalidLLRPMessageException { List<Element> tempList = null; boolean atLeastOnce = false; Custom custom; Element temp = null; // child element are always in default LLRP namespace Namespace ns = Namespace.getNamespace(LLRPConstants.LLRPNAMESPACE); //parameter - not choices - no special actions needed temp = element.getChild("ROSpecID", ns); if (temp != null) { rOSpecID = new ROSpecID(temp); LOGGER.info( "setting parameter rOSpecID for parameter RFSurveyReportData"); } if (temp == null) { LOGGER.info( "RFSurveyReportData misses optional parameter of type rOSpecID"); } element.removeChild("ROSpecID", ns); //parameter - not choices - no special actions needed temp = element.getChild("SpecIndex", ns); if (temp != null) { specIndex = new SpecIndex(temp); LOGGER.info( "setting parameter specIndex for parameter RFSurveyReportData"); } if (temp == null) { LOGGER.info( "RFSurveyReportData misses optional parameter of type specIndex"); } element.removeChild("SpecIndex", ns); //parameter - not choices - no special actions needed //we expect a list of parameters frequencyRSSILevelEntryList = new LinkedList<FrequencyRSSILevelEntry>(); tempList = element.getChildren("FrequencyRSSILevelEntry", ns); if ((tempList == null) || tempList.isEmpty()) { LOGGER.warn( "RFSurveyReportData misses non optional parameter of type frequencyRSSILevelEntryList"); throw new MissingParameterException( "RFSurveyReportData misses non optional parameter of type frequencyRSSILevelEntryList"); } else { for (Element e : tempList) { frequencyRSSILevelEntryList.add(new FrequencyRSSILevelEntry(e)); LOGGER.debug( "adding FrequencyRSSILevelEntry to frequencyRSSILevelEntryList "); } } element.removeChildren("FrequencyRSSILevelEntry", ns); //parameter - not choices - no special actions needed //we expect a list of parameters customList = new LinkedList<Custom>(); tempList = element.getChildren("Custom", ns); if ((tempList == null) || tempList.isEmpty()) { LOGGER.info( "RFSurveyReportData misses optional parameter of type customList"); } else { for (Element e : tempList) { customList.add(new Custom(e)); LOGGER.debug("adding Custom to customList "); } } element.removeChildren("Custom", ns); //custom parameter tempList = element.getChildren("Custom", ns); for (Element e : tempList) { customList.add(new Custom(e)); atLeastOnce = true; LOGGER.debug("adding custom parameter"); } element.removeChildren("Custom", ns); //end custom if (element.getChildren().size() > 0) { String message = "RFSurveyReportData has unknown element " + ((Element) element.getChildren().get(0)).getName(); throw new InvalidLLRPMessageException(message); } } //setters /** * set rOSpecID of type ROSpecID. * @param rOSpecID to be set */ public void setROSpecID(final ROSpecID rOSpecID) { this.rOSpecID = rOSpecID; } /** * set specIndex of type SpecIndex. * @param specIndex to be set */ public void setSpecIndex(final SpecIndex specIndex) { this.specIndex = specIndex; } /** * set frequencyRSSILevelEntryList of type List <FrequencyRSSILevelEntry>. * @param frequencyRSSILevelEntryList to be set */ public void setFrequencyRSSILevelEntryList( final List<FrequencyRSSILevelEntry> frequencyRSSILevelEntryList) { this.frequencyRSSILevelEntryList = frequencyRSSILevelEntryList; } /** * 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 rOSpecID of type ROSpecID . * @return ROSpecID */ public ROSpecID getROSpecID() { return rOSpecID; } /** * get specIndex of type SpecIndex . * @return SpecIndex */ public SpecIndex getSpecIndex() { return specIndex; } /** * get frequencyRSSILevelEntryList of type List <FrequencyRSSILevelEntry> . * @return List <FrequencyRSSILevelEntry> */ public List<FrequencyRSSILevelEntry> getFrequencyRSSILevelEntryList() { return frequencyRSSILevelEntryList; } /** * get customList of type List <Custom> . * @return List <Custom> */ public List<Custom> getCustomList() { return customList; } // end getters //add methods /** * add element frequencyRSSILevelEntry of type FrequencyRSSILevelEntry . * @param frequencyRSSILevelEntry of type FrequencyRSSILevelEntry */ public void addToFrequencyRSSILevelEntryList( FrequencyRSSILevelEntry frequencyRSSILevelEntry) { if (this.frequencyRSSILevelEntryList == null) { this.frequencyRSSILevelEntryList = new LinkedList<FrequencyRSSILevelEntry>(); } this.frequencyRSSILevelEntryList.add(frequencyRSSILevelEntry); } /** * 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 /** * For TLV Parameter length can not be determined at compile time. This method therefore always returns 0. * @return Integer always zero */ public static Integer length() { return 0; } /** * {@inheritDoc} */ public SignedShort getTypeNum() { return TYPENUM; } /** * {@inheritDoc} */ public String getName() { return "RFSurveyReportData"; } /** * return string representation. All field values but no parameters are included * @return String */ public String toString() { String result = "RFSurveyReportData: "; result = result.replaceFirst(", ", ""); return result; } }