List of usage examples for javax.xml.bind JAXBException printStackTrace
public void printStackTrace()
From source file:ox.softeng.gel.filereceive.FileReceive.java
public static void main(String[] args) { if (hasSimpleOptions(args)) System.exit(0);// ww w . ja va 2 s .c o m try { // parse the command line arguments CommandLine line = parser.parse(defineMainOptions(), args); long start = System.currentTimeMillis(); try { FileReceive fr = new FileReceive(line.getOptionValue('c'), line.getOptionValue('r'), (Integer) line.getParsedOptionValue("p"), line.getOptionValue('u', ConnectionFactory.DEFAULT_USER), line.getOptionValue('w', ConnectionFactory.DEFAULT_PASS), line.getOptionValue('e'), line.getOptionValue('b'), (Long) line.getParsedOptionValue("t")); fr.startMonitors(); logger.info("File receiver started in {}ms", System.currentTimeMillis() - start); } catch (JAXBException ex) { logger.error("Could not create file receiver because of JAXBException: {}", ex.getLinkedException().getMessage()); } catch (IOException | TimeoutException ex) { logger.error("Could not create file receiver because: {}", ex.getMessage()); ex.printStackTrace(); } } catch (ParseException exp) { logger.error("Could not start file-receiver because of ParseException: " + exp.getMessage()); help(); } }
From source file:parser.serverData.spawns.SpawnLoader.java
public static Map<Integer, List<SpawnGroup>> load() { int spawnCount = 0; File dir = new File("xml/spawns"); Collection<File> files = listFiles(dir, true); Map<Integer, List<SpawnGroup>> spawnGroups = new HashMap<Integer, List<SpawnGroup>>(); try {/*ww w. j a v a 2s. c o m*/ for (File file : files) { System.out.println("SpawnFile: " + file.getPath()); JAXBContext jc = JAXBContext.newInstance("parser.serverData.spawns"); Unmarshaller unmarshaller = jc.createUnmarshaller(); Spawns collection = (Spawns) unmarshaller.unmarshal(file); for (SpawnGroup spawnGroup : collection.getSpawn()) { spawnCount += spawnGroup.getObject().size(); if (!spawnGroups.containsKey(spawnGroup.getMap())) spawnGroups.put(spawnGroup.getMap(), new ArrayList<SpawnGroup>()); spawnGroups.get(spawnGroup.getMap()).add(spawnGroup); } } System.out.println("Size of spawns relations: " + spawnCount); return spawnGroups; } catch (JAXBException e) { e.printStackTrace(); } return null; }
From source file:playground.meisterk.org.matsim.run.facilities.ShopsOf2005ToFacilities.java
private static void transformGeocodedKMLToFacilities(Config config) { ActivityFacilitiesImpl shopsOf2005 = new ActivityFacilitiesImpl("shopsOf2005"); JAXBElement<KmlType> kmlElement = null; try {/*from w w w. j ava2 s . co m*/ JAXBContext jaxbContext = JAXBContext.newInstance("net.opengis.kml._2"); Unmarshaller unMarshaller = jaxbContext.createUnmarshaller(); kmlElement = (JAXBElement<KmlType>) unMarshaller .unmarshal(new FileInputStream(config.facilities().getInputFile())); } catch (JAXBException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } KmlType kml = kmlElement.getValue(); DocumentType document = (DocumentType) kml.getAbstractFeatureGroup().getValue(); System.out.println(document.getName()); // recursively search the KML for placemarks, transform it into a matsim facility // and place it in the list of facilities or in the quadtree, respectively List<JAXBElement<? extends AbstractFeatureType>> featureGroup = document.getAbstractFeatureGroup(); Iterator<JAXBElement<? extends AbstractFeatureType>> it = featureGroup.iterator(); while (it.hasNext()) { JAXBElement<AbstractFeatureType> feature = (JAXBElement<AbstractFeatureType>) (it.next()); if (feature.getValue().getClass().equals(FolderType.class)) { //System.out.println("Going into folder..."); ShopsOf2005ToFacilities.extractPlacemarks((FolderType) feature.getValue(), shopsOf2005); } else if (feature.getValue().getClass().equals(PlacemarkType.class)) { //System.out.println("There is a placemark!"); } } ShopsOf2005ToFacilities.addOpentimesToFacilities(shopsOf2005); System.out.println("Writing facilities xml file... "); FacilitiesWriter facilities_writer = new FacilitiesWriter(shopsOf2005); facilities_writer.write(null /* filename not specified */); System.out.println("Writing facilities xml file...done."); }
From source file:playground.meisterk.org.matsim.run.facilities.ShopsOf2005ToFacilities.java
private static void setUp() { try {//from w w w .ja v a 2 s.c o m jaxbContext = JAXBContext.newInstance("net.opengis.kml._2"); } catch (JAXBException e) { e.printStackTrace(); } myKML = kmlObjectFactory.createKmlType(); myKMLDocument = kmlObjectFactory.createDocumentType(); myKMLDocument.setName("the root document"); myKML.setAbstractFeatureGroup(kmlObjectFactory.createDocument(myKMLDocument)); mainKMLFolder = kmlObjectFactory.createFolderType(); mainKMLFolder.setName("Shops of 2005"); mainKMLFolder.setDescription("All revealed shops of 2005."); myKMLDocument.getAbstractFeatureGroup().add(kmlObjectFactory.createFolder(mainKMLFolder)); }
From source file:playground.meisterk.org.matsim.run.facilities.ShopsOf2005ToFacilities.java
private static void shopsToOpentimesKML() { // variables used Day[] days = Day.values();//from w w w .j a v a 2 s .co m String facilityId = null; CH1903LV03toWGS84 trafo = new CH1903LV03toWGS84(); FolderType aShop = null; PlacemarkType aShopOpeningPeriod = null; PointType aPointType = null; TimeSpanType aTimeSpanType = null; Coord northWestCH1903 = null; Coord northWestWGS84 = null; // as a start, let's use the week April, 21 to April 27, 2008 as THE week final int MONDAY_DAY = 21; // we produce two kml files: // 1, the shops of 2005 // 2, the shops from enterprise census final Integer SHOPS_OF_2005 = Integer.valueOf(0); final Integer SHOPS_FROM_ENTERPRISE_CENSUS = Integer.valueOf(1); TreeMap<Integer, String> shopsNames = new TreeMap<Integer, String>(); shopsNames.put(SHOPS_OF_2005, "shopsOf2005"); shopsNames.put(SHOPS_FROM_ENTERPRISE_CENSUS, "shopsFromEnterpriseCensus2000"); TreeMap<Integer, String> facilitiesInputFilenames = new TreeMap<Integer, String>(); facilitiesInputFilenames.put(SHOPS_OF_2005, "/home/meisterk/sandbox00/ivt/studies/switzerland/facilities/shopsOf2005/facilities_shopsOf2005.xml"); facilitiesInputFilenames.put(SHOPS_FROM_ENTERPRISE_CENSUS, "/home/meisterk/workspace/MATSim/output/facilities_KTIYear2.xml.gz"); TreeMap<Integer, String> kmlOutputFilenames = new TreeMap<Integer, String>(); kmlOutputFilenames.put(SHOPS_OF_2005, "/home/meisterk/sandbox00/ivt/studies/switzerland/facilities/shopsOf2005/shopsOf2005.kml"); kmlOutputFilenames.put(SHOPS_FROM_ENTERPRISE_CENSUS, "/home/meisterk/sandbox00/ivt/studies/switzerland/facilities/facilities_KTIYear2.kml"); TreeMap<Integer, String> shopStyleNames = new TreeMap<Integer, String>(); shopStyleNames.put(SHOPS_OF_2005, "shopsOf2005Style"); shopStyleNames.put(SHOPS_FROM_ENTERPRISE_CENSUS, "shopsEC2000Style"); TreeMap<Integer, Double> shopIconScales = new TreeMap<Integer, Double>(); shopIconScales.put(SHOPS_OF_2005, 1.0); shopIconScales.put(SHOPS_FROM_ENTERPRISE_CENSUS, 2.0); ActivityFacilities facilities = null; for (int dataSetIndex : new int[] { SHOPS_OF_2005/*, SHOPS_FROM_ENTERPRISE_CENSUS*/ }) { ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig()); facilities = scenario.getActivityFacilities(); facilities.setName(shopsNames.get(Integer.valueOf(dataSetIndex))); System.out.println("Reading facilities xml file... "); FacilitiesReaderMatsimV1 facilities_reader = new FacilitiesReaderMatsimV1(scenario); facilities_reader.readFile(facilitiesInputFilenames.get(new Integer(dataSetIndex))); System.out.println("Reading facilities xml file...done."); System.out.println("Initializing KML... "); // kml and document JAXBContext jaxbContext = null; try { jaxbContext = JAXBContext.newInstance("com.google.earth.kml._2"); } catch (JAXBException e) { e.printStackTrace(); } ObjectFactory factory = new ObjectFactory(); KmlType kml = factory.createKmlType(); DocumentType document = factory.createDocumentType(); document.setName(shopsNames.get(new Integer(dataSetIndex))); kml.setAbstractFeatureGroup(factory.createDocument(document)); // styles StyleType shopStyle = factory.createStyleType(); document.getAbstractStyleSelectorGroup().add(factory.createStyle(shopStyle)); shopStyle.setId(shopStyleNames.get(new Integer(dataSetIndex))); IconStyleType shopIconStyle = factory.createIconStyleType(); shopStyle.setIconStyle(shopIconStyle); BasicLinkType shopIconLink = factory.createBasicLinkType(); shopIconStyle.setIcon(shopIconLink); shopIconStyle.setScale(shopIconScales.get(new Integer(dataSetIndex))); shopIconLink.setHref("http://maps.google.com/mapfiles/kml/paddle/S.png"); System.out.println("Initializing KML...done."); Iterator<? extends ActivityFacility> facilityIterator = facilities.getFacilities().values().iterator(); while (facilityIterator.hasNext()) { ActivityFacilityImpl facility = (ActivityFacilityImpl) facilityIterator.next(); facilityId = facility.getId().toString(); // System.out.println(facility.toString()); //System.out.println(facilityId); aShop = factory.createFolderType(); document.getAbstractFeatureGroup().add(factory.createFolder(aShop)); aShop.setName(facilityId.split("_", 2)[0]); aShop.setDescription(facilityId); // transform coordinates incl. toggle easting and northing northWestCH1903 = new CoordImpl(facility.getCoord().getX(), facility.getCoord().getY()); northWestWGS84 = trafo.transform(northWestCH1903); // have to iterate this over opening times int dayCounter = 0; if (facility.getActivityOptions().get(ACTIVITY_TYPE_SHOP) != null) { Set<OpeningTime> dailyOpentimes = facility.getActivityOptions().get(ACTIVITY_TYPE_SHOP) .getOpeningTimes(); if (dailyOpentimes != null) { for (OpeningTime opentime : dailyOpentimes) { // build up placemark structure aShopOpeningPeriod = factory.createPlacemarkType(); aShop.getAbstractFeatureGroup().add(factory.createPlacemark(aShopOpeningPeriod)); aShopOpeningPeriod.setStyleUrl(shopStyleNames.get(new Integer(dataSetIndex))); aShopOpeningPeriod.setName(facilityId.split("_", 2)[0]); aShopOpeningPeriod.setDescription(facilityId); aPointType = factory.createPointType(); aShopOpeningPeriod.setAbstractGeometryGroup(factory.createPoint(aPointType)); aPointType.getCoordinates() .add(northWestWGS84.getX() + "," + northWestWGS84.getY() + ",0.0"); // transform opening times to GE time primitives aTimeSpanType = factory.createTimeSpanType(); aShopOpeningPeriod.setAbstractTimePrimitiveGroup( factory.createAbstractTimePrimitiveGroup(aTimeSpanType)); aTimeSpanType.setBegin("2008-04-" + Integer.toString(MONDAY_DAY + dayCounter) + "T" + Time.writeTime(opentime.getStartTime()) + "+01:00"); aTimeSpanType.setEnd("2008-04-" + Integer.toString(MONDAY_DAY + dayCounter) + "T" + Time.writeTime(opentime.getEndTime()) + "+01:00"); } } } dayCounter++; } System.out.println("Writing out KML..."); try { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(factory.createKml(kml), new FileOutputStream(kmlOutputFilenames.get(new Integer(dataSetIndex)))); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Writing out KML...done."); } }
From source file:Sandbox.ZipExtractor.ProcessZip.java
private boolean mergeConfigurationsWithStaticXmlNode() { boolean status = false; try {/*from w ww.java 2 s. c o m*/ StaticData staticData = XmlUtils.unMarshal(staticXmlNode, StaticData.class); for (ZipFileEntry practiceLicense : practiceLicences) { Configuration configuration = practiceLicense.getXmlPayload(); configuration.setAny(staticData); practiceLicense.setXmlPayload(configuration); //System.out.println(XmlUtils.marshal(configuration)); } status = true; } catch (JAXBException e) { e.printStackTrace(); } return status; }
From source file:SeedGenerator.MainForm.java
private void writeSearchEngines(SearchEngines se) { try {//from w ww.j a v a 2 s . c o m File file = new File("file.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(SearchEngine.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(se, file); jaxbMarshaller.marshal(se, System.out); } catch (JAXBException e) { e.printStackTrace(); } }
From source file:SeedGenerator.MainForm.java
private SearchEngines getSearchEnginesFromXml() { try {/*w w w. j av a 2 s. c o m*/ CodeSource codeSource = MainForm.class.getProtectionDomain().getCodeSource(); File jarFile = new File(codeSource.getLocation().toURI().getPath()); String jarDir = jarFile.getParentFile().getPath(); File file = new File(jarDir + "/SearchEngines.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(SearchEngines.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); SearchEngines searchEngineList = (SearchEngines) jaxbUnmarshaller.unmarshal(file); return searchEngineList; // System.out.println(searchEngineList.getSearchEngines()); } catch (JAXBException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:tds.itemscoringengine.ItemScoreResponse.java
private void writeXmlInternal(Object out) throws XMLStreamException { try {/* w w w .j a v a 2 s .c om*/ Marshaller jaxbMarshaller = JAXBContext.newInstance(ItemScoreResponse.class).createMarshaller(); // Shiva: We do not want to escape CDATA. JaxB does not internally // support // it. // Here is an alternate way to achieve the same thing: // http://odedpeer.blogspot.com/2010/07/jaxb-sun-and-how-to-marshal-cdata.html // However this is a sun internal class and we probably should not // be // using. TODO. There may be "access restriction" issues: // http://stackoverflow.com/questions/860187/access-restriction-on-class-due-to-restriction-on-required-library-rt-jar // http://stackoverflow.com/questions/16653519/jaxb-marshal-setproperty-com-sun-xml-bind-characterescapehandler jaxbMarshaller.setProperty("com.sun.xml.bind.characterEscapeHandler", new CharacterEscapeHandler() { @Override public void escape(char[] ac, int i, int j, boolean flag, Writer writer) throws IOException { if (ac != null && i < ac.length && (i + j) <= ac.length) { StringBuilder incomingStringBuilder = new StringBuilder(); for (int counter1 = i; counter1 < i + j; ++counter1) { incomingStringBuilder.append(ac[counter1]); } String incomingString = incomingStringBuilder.toString(); final String BEGIN_CDATA = "<![CDATA["; final String END_CDATA = "]]>"; StringBuilder outgoingString = new StringBuilder(); // there may be multiple CDATA sections. first lets find the index // of "<![CDATA[". // Shiva: Assumptions 1) the CDATA section is whole i.e. we will not // see something like "abc <!CDATA[ x y z". instead we will see // "abc <!CDATA[ x y z ]]> m n o p" // 2) CDATA may be anywhere. 3) there may be multiple CDATA segments // but each will be whole. int currentIndex = 0; while (currentIndex < incomingString.length()) { int indexOfBeginCdata = incomingString.indexOf(BEGIN_CDATA, currentIndex); if (indexOfBeginCdata >= 0) { if (indexOfBeginCdata != currentIndex) { // we will copy everything upto the begining of CDATA and // escape it. String substr = incomingString.substring(currentIndex, indexOfBeginCdata); outgoingString.append(StringEscapeUtils.escapeXml(substr)); } // lets move the current index to at least after the match. currentIndex = indexOfBeginCdata + BEGIN_CDATA.length(); // do we have a end cdata int indexOfEndCData = incomingString.indexOf(END_CDATA, currentIndex); // because of our assumptions above we are not going to check if // this is < 0. outgoingString.append(incomingString.subSequence(indexOfBeginCdata, indexOfEndCData + END_CDATA.length())); // move currentIndex again. currentIndex = indexOfEndCData + END_CDATA.length(); } else { // no more CDATA sections left. outgoingString.append(StringEscapeUtils.escapeXml( incomingString.substring(currentIndex, incomingString.length()))); break; } } writer.write(outgoingString.toString()); // do not escape } else { // TODO Shiva: if they are not within the range then I do not know // what to do. i will just let it go. writer.write(ac, i, j); } } }); if (out instanceof OutputStream) jaxbMarshaller.marshal(this, (OutputStream) out); else if (out instanceof XMLStreamWriter) jaxbMarshaller.marshal(this, (XMLStreamWriter) out); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); _logger.error("Exception writing ItemScoreResponse", e); throw new XMLStreamException(e); } }
From source file:views.MetadataUploadView.java
private String parseXMLConditionValue(String xml, String label, properties.PropertyType type) { List<Property> props = new ArrayList<Property>(); try {/*w w w.ja va2s .c o m*/ props = xmlParser.getAllPropertiesFromXML(xml); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } String res = ""; for (Property f : props) { if (f.getLabel().equals(label) && f.getType().equals(type)) { res = f.getValue(); if (f.hasUnit()) res += " " + f.getUnit(); } } return res; }