Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 Agrosense <> Licensed under the Eclipse Public License - v 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 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 nl.cloudfarming.client.isobus.model;
 import java.util.List;
UnMarshaller to unMarshall iso 11783-10 messages

Merijn Zengers & Gerben Feenstra
     "isobus.error.isobus_unmarshaller.exception=The isobus file {0} could not be read!",
     "isobus.error.isobus_unmarshaller.timelog_not_found=File {0} cannot be found!",
     "isobus.error.isobus_unmarshaller.xml_cannot_be_null=the XMLFile provided cannot be null"
 public class IsobusUnMarshaller {
     private static final AppLogger LOG = AppLogFactory.getLogger(IsobusUnMarshaller.class);
     private final String PACKAGE_NAME = "nl.cloudfarming.client.isobus.model";

UnMarshal File containing XML to an IsobusTaskData object

xmlFile The File object which contains the XML
An IsobusTaskData object
     public IsobusTaskData unMarshall(FileObject xmlFilethrows IllegalArgumentException {
         // XML should not be null
         if (xmlFile == null) {
             throw new IllegalArgumentException(NbBundle.getMessage(IsobusUnMarshaller.class"isobus.error.isobus_unmarshaller.xml_cannot_be_null"));
         // Unmarshall XML
         IsobusTaskData isobusTaskData = null;
         try {
             isobusTaskData = unMarshallIsobusTaskData(xmlFile.getInputStream());
         } catch (FileNotFoundException ex) {
         // Retrieve timeLogs into isobusTaskData
         if (isobusTaskData != null) {
         return isobusTaskData;

Unmarshall the specified InputStream to an IsobusTaskData object. Do not use, PROTECTED for testing only!

taskdata Taskdata as inputstream
IsobusTaskData Unmarshalled isobus taskdata object
     protected IsobusTaskData unMarshallIsobusTaskData(InputStream taskdata) {
         JAXBContext jc;
         try {
             jc = JAXBContext.newInstance();
             Unmarshaller unmarshaller = jc.createUnmarshaller();
             IsobusTaskData isobusTaskData = (IsobusTaskDataunmarshaller.unmarshal(taskdata);
             return isobusTaskData;
         } catch (JAXBException ex) {
             .error("Failed to convert xml"ex);
         return null;

Will read Time objects from binary file + xml file. Will get timeLog property from the tasks When TimeLog.getFileName is not null a new TimeLogReader will be created The FileName and the Directory which must contain a XML file header and a binary file will be parsed to the TimeLogReader. The FileName of the XML file must be TimeLog.fileName with a extension of .xml or .XML The FileName of the binary file must be TimeLog.fileName with a extension of .bin or .BIN

isobusTask the Isobus object containing the tasks and in turn the TimeLog objects
xmlFile The XML-file, needed to retrieve timelog from the same folder.
a List of times read from the XML and binary files combined.
    private void addTimelogs(IsobusTaskData isobusTaskDataFileObject xmlFile) {
        String timeLogFileName = "";
        FileObject parentDir = xmlFile.getParent();
        for (IsobusTask isobusTask : isobusTaskData.getTSK()) {
            List<IsobusTimetimes = new ArrayList<>();
            try {
                for (TimeLog timeLog : isobusTask.getTLG()) {
                    timeLogFileName = timeLog.getFilename();
                    if (timeLogFileName != null && !timeLogFileName.equals("")) {
                        TimeLogReader timeLogReader = new TimeLogReader(timeLogFileNameparentDirisobusTaskData);
            } catch(FileNotFoundException ex){
                .error(NbBundle.getMessage(IsobusUnMarshaller.class"isobus.error.isobus_unmarshaller.timelog_not_found"timeLogFileName) + ex);
            } catch (IOException | SAXException | ParserConfigurationException ex) {
                throw new IsobusUnmarshallingException(NbBundle.getMessage(IsobusUnMarshaller.class"isobus.error.isobus_unmarshaller.exception"xmlFile.getName()) + ex);
New to GrepCode? Check out our FAQ X