List of usage examples for javax.xml.bind JAXBException JAXBException
public JAXBException(Throwable exception)
From source file:Main.java
public static <T> void marshal(Object jaxbElement, Class<T> jaxbFactory, OutputStream out) throws JAXBException { if (!(jaxbElement instanceof JAXBElement<?>)) { throw new JAXBException("Must be a instance of JAXBElement<?>"); }/*from w ww.ja v a 2 s .c o m*/ try { JAXBContext jc = JAXBContext.newInstance(jaxbFactory); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(jaxbElement, out); } catch (PropertyException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } }
From source file:Main.java
public static <T> Document marshal(Object jaxbElement, Class<T> jaxbFactory) throws JAXBException { if (!(jaxbElement instanceof JAXBElement<?>)) { throw new JAXBException("Must be a instance of JAXBElement<?>"); }//from w w w. j a v a 2 s . co m Document doc = null; try { JAXBContext jc = JAXBContext.newInstance(jaxbFactory); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.newDocument(); marshaller.marshal(jaxbElement, doc); } catch (PropertyException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return doc; }
From source file:com.radialpoint.uima.typemapper.RulesFileLoader.java
public static Rules loadRulesFromStream(InputStream stream) throws JAXBException, FileNotFoundException { Rules rules = new Rules(); // Unmarshal/*from w w w . ja v a 2 s . c om*/ JAXBContext jc = JAXBContext.newInstance(Rules.class, Rule.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); rules = (Rules) unmarshaller.unmarshal(stream); if (rules == null || CollectionUtils.isEmpty(rules.getRuleList())) { throw new JAXBException("Rules list is empty. Binding error?"); } return rules; }
From source file:gov.hhs.fha.nhinc.lift.proxy.util.ProxyUtil.java
public static org.w3c.dom.Element marshal(Object obj) throws JAXBException { try {/* www . java 2s . c om*/ Document doc = null; JAXBContext jc = JAXBContext.newInstance(obj.getClass()); Marshaller marshaller = jc.createMarshaller(); javax.xml.parsers.DocumentBuilderFactory dbf; dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); doc = dbf.newDocumentBuilder().newDocument(); marshaller.marshal(obj, doc); log.info("Marshal: " + doc.getNodeValue()); return doc.getDocumentElement(); } catch (ParserConfigurationException ex) { throw new JAXBException("Unable to create document: " + ex.getMessage()); } }
From source file:de.xirp.profile.ProfileGenerator.java
/** * Generates a PRO file with the given path from the given * {@link de.xirp.profile.Profile profile} bean. * /*from w ww .j a v a 2s. c om*/ * @param profile * The profile to generate the XML for. * @param proFile * The file to write the result to. Must be the full path. * * @throws JAXBException if the given profile was null, or something * went wrong generating the xml. * @throws FileNotFoundException if something went wrong generating the xml. * * @see de.xirp.profile.Profile */ public static void generatePRO(Profile profile, File proFile) throws JAXBException, FileNotFoundException { if (profile == null) { throw new JAXBException(I18n.getString("ProfileGenerator.exception.profileNull")); //$NON-NLS-1$ } String fileName = FilenameUtils.getBaseName(proFile.getName()); JAXBContext jc = JAXBContext.newInstance(Profile.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(profile, new FileOutputStream( Constants.CONF_PROFILES_DIR + File.separator + fileName + Constants.PROFILE_POSTFIX)); }
From source file:com.wso2telco.config.ConfigLoader.java
/** * Inits the claims config.//from w w w. j a v a 2 s . c o m * * @return the scope configs * @throws JAXBException the JAXB exception */ private ScopeConfigs initClaimsConfig() throws JAXBException { Unmarshaller um = null; ScopeConfigs userClaims = null; String configPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "scope-config.xml"; File file = new File(configPath); try { JAXBContext ctx = JAXBContext.newInstance(ScopeConfigs.class); um = ctx.createUnmarshaller(); userClaims = (ScopeConfigs) um.unmarshal(file); } catch (JAXBException e) { throw new JAXBException("Error unmarshalling file :" + configPath); } return userClaims; }
From source file:Main.java
private static JAXBContext getJAXBContext(Class<?>[] clazzs) throws JAXBException { if (clazzs != null) { StringBuilder sb = new StringBuilder(); for (Class<?> c : clazzs) { sb.append(c.getName()).append(","); }/* w ww . j av a2 s .c om*/ String str = sb.toString(); if (contextbuf.containsKey(str)) { return contextbuf.get(str); } else { JAXBContext c = JAXBContext.newInstance(clazzs); contextbuf.put(str, c); return c; } } else { throw new JAXBException(new NullPointerException("Class")); } }
From source file:de.xirp.profile.ProfileGenerator.java
/** * Generates a BOT file with the given path from the given * {@link de.xirp.profile.Robot robot} bean. * //from w ww . j a va2 s. co m * @param robot * The robot to generate the XML for. * @param botFile * The file to write the result to. Must be the full path. * * @throws JAXBException if the given robot was null, or something * went wrong generating the xml. * @throws FileNotFoundException if something went wrong generating the xml. */ public static void generateBOT(Robot robot, File botFile) throws FileNotFoundException, JAXBException { if (robot == null) { throw new JAXBException(I18n.getString("ProfileGenerator.exception.robotNull")); //$NON-NLS-1$ } String fileName = FilenameUtils.getBaseName(botFile.getName()); JAXBContext jc = JAXBContext.newInstance(Robot.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(robot, new FileOutputStream( Constants.CONF_ROBOTS_DIR + File.separator + fileName + Constants.ROBOT_POSTFIX)); }
From source file:com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb.JAXBPlistParser.java
public void save(Plist plist, File projectFile) throws JAXBException { try {//from www .j a va 2 s .c o m save(plist, new FileWriter(projectFile)); } catch (IOException ex) { throw new JAXBException(ex); } }
From source file:org.dasein.cloud.azure.tests.compute.AzureAffinityGroupSupportTests.java
@Test(expected = InternalException.class) public void createShouldThrowExceptionIfParsingRequestEntityFailed() throws InternalException, CloudException { new MockUp<AzureMethod>() { @Mock/*from w w w . j ava 2s.co m*/ <T> String post(String resource, T object) throws JAXBException, CloudException, InternalException { throw new JAXBException("parsing object failed"); } }; AffinityGroupCreateOptions options = AffinityGroupCreateOptions.getInstance(AFFINITY_GROUP_ID, AFFINITY_GROUP_ID, REGION); new AzureAffinityGroupSupport(azureMock).create(options); }