List of usage examples for javax.xml.bind JAXBException getMessage
public String getMessage()
From source file:org.codice.ddf.spatial.ogc.wfs.catalog.endpoint.TestWfsEndpoint.java
private String marshalXmlObject(WFSCapabilitiesType marshalMe) { StringWriter writer = new StringWriter(); try {// w w w. j av a 2 s .c om JAXBContext contextObj = JAXBContext.newInstance(WFSCapabilitiesType.class); Marshaller marshallerObj = contextObj.createMarshaller(); marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshallerObj.marshal(wfsCapabilityObjectFactory.createWFSCapabilities(marshalMe), writer); } catch (JAXBException e) { fail(e.getMessage()); } return writer.toString(); }
From source file:org.codice.ddf.spatial.ogc.wfs.v110.catalog.source.WfsSourceTest.java
@BeforeClass public static void setupClass() { try {/* ww w .jav a 2s. c om*/ jaxbContext = JAXBContext.newInstance("net.opengis.wfs.v_1_1_0"); } catch (JAXBException e) { fail(e.getMessage()); } }
From source file:org.dasein.cloud.azure.compute.AzureAffinityGroupSupport.java
/** * Creates an affinity group in the cloud * * @param options the options used when creating the affinity group * @return the provider ID of the affinity group * @throws org.dasein.cloud.InternalException an error occurred within the Dasein Cloud implementation creating the affinity group * @throws org.dasein.cloud.CloudException an error occurred within the service provider creating the affinity group *///from w w w .j av a 2 s. co m @Nonnull @Override public AffinityGroup create(@Nonnull AffinityGroupCreateOptions options) throws InternalException, CloudException { if (options == null && options.getName() == null) throw new InternalException( "Cannot create AffinityGroup. Create options or affinity group name cannot be null."); CreateAffinityGroupModel createAffinityGroupModel = new CreateAffinityGroupModel(); createAffinityGroupModel.setName(options.getName()); createAffinityGroupModel.setDescription(options.getDescription()); createAffinityGroupModel.setLocation(provider.getContext().getRegionId()); createAffinityGroupModel.setLabel(new String(Base64.encodeBase64(options.getName().getBytes()))); AzureMethod azureMethod = new AzureMethod(this.provider); try { azureMethod.post(RESOURCE_AFFINITYGROUPS, createAffinityGroupModel); } catch (JAXBException e) { logger.error(e.getMessage()); throw new InternalException(e); } return AffinityGroup.getInstance(createAffinityGroupModel.getName(), createAffinityGroupModel.getName(), createAffinityGroupModel.getDescription(), createAffinityGroupModel.getLocation(), null); }
From source file:org.dasein.cloud.azure.compute.AzureAffinityGroupSupport.java
/** * Modifies details of the specified affinity group * * @param affinityGroupId the ID of the affinity group to be modified * @param options the options containing the modified data * @return the newly modified Dasein AffinityGroup object * @throws org.dasein.cloud.InternalException an error occurred within the Dasein Cloud implementation modifying the affinity group * @throws org.dasein.cloud.CloudException an error occurred within the service provider modifying the affinity group *///www .j a va 2 s .c o m @Override public AffinityGroup modify(@Nonnull String affinityGroupId, @Nonnull AffinityGroupCreateOptions options) throws InternalException, CloudException { if (affinityGroupId == null || affinityGroupId.isEmpty()) throw new InternalException("Cannot modify an affinity group: affinityGroupId cannot be null or empty"); if (options == null && options.getDescription() == null) throw new InternalException( "Cannot create AffinityGroup. Create options or affinity group description cannot be null."); UpdateAffinityGroupModel updateAffinityGroupModel = new UpdateAffinityGroupModel(); updateAffinityGroupModel.setDescription(options.getDescription()); AzureMethod method = new AzureMethod(this.provider); try { method.put(String.format(RESOURCE_AFFINITYGROUP, affinityGroupId), updateAffinityGroupModel); } catch (JAXBException e) { logger.error(e.getMessage()); throw new InternalException(e); } return get(affinityGroupId); }
From source file:org.dasein.cloud.azure.network.AzureIpAddressSupport.java
private void updateVMRole(String vmId, PersistentVMRoleModel persistentVMRoleModel) throws CloudException, InternalException { AzureRoleDetails roleDetails = AzureRoleDetails.fromString(vmId); try {/* w ww. j av a 2 s . c o m*/ new AzureMethod(this.provider).put(String.format(RESOURCE_ROLE, roleDetails.getServiceName(), roleDetails.getDeploymentName(), roleDetails.getRoleName()), persistentVMRoleModel); } catch (JAXBException e) { logger.error(e.getMessage()); throw new InternalException(e); } }
From source file:org.docx4j.openpackaging.parts.JaxbXmlPart.java
/** * Get the live contents of this part (the JAXB object model). * (An alias/synonym for older getJaxbElement(), but now throws exception) * @throws Docx4JException//from w w w. ja v a 2 s. c o m * @return * @since 3.0 */ public E getContents() throws Docx4JException { // Lazy unmarshal InputStream is = null; if (jaxbElement == null) { if (this.getPackage() == null) { log.warn("This part not added to a package, so its contents can't be retrieved. "); return null; } PartStore partStore = this.getPackage().getSourcePartStore(); if (partStore == null) { log.info("No PartStore defined for this package (it was probably created, not loaded). "); log.info(this.getPartName().getName() + ": did you initialise its contents to something?"); return null; // or we could create it, with a bit of effort; // as to which see http://stackoverflow.com/questions/1090458/instantiating-a-generic-class-in-java } try { String name = this.getPartName().getName(); try { if (partStore != null) { this.setContentLengthAsLoaded(partStore.getPartSize(name.substring(1))); } } catch (UnsupportedOperationException uoe) { } is = partStore.loadPart(name.substring(1)); if (is == null) { log.warn(name + " missing from part store"); } else { log.debug("Lazily unmarshalling " + name); unmarshal(is); } } catch (JAXBException e) { log.error("Problem with part " + this.getPartName()); throw new Docx4JException(e.getMessage(), e); // } catch (Docx4JException e) { // log.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(is); } } return jaxbElement; }
From source file:org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware.java
/** * Enables synchronization between XML infoset nodes and JAXB objects * representing same XML document.// w w w. ja v a 2 s. c om * * An instance of this class maintains the association between XML nodes * of an infoset preserving view and a JAXB representation of an XML document. * Navigation between the two views is provided by the methods * getXMLNode(Object) and getJAXBNode(Object) . * * In theory, modifications can be made to either the infoset preserving view or * the JAXB representation of the document while the other view remains * unmodified. The binder ought to be able to synchronize the changes made in * the modified view back into the other view using the appropriate * Binder update methods, #updateXML(Object, Object) or #updateJAXB(Object). * * But JAXB doesn't currently work as advertised .. access to this * object is offered for advanced users on an experimental basis only. */ public Binder<Node> getBinder() { if (jaxbElement == null) { // Test jaxbElement, since we don't want to do the // below if jaxbElement has already been set // using setJaxbElement (which doesn't create // binder) PartStore partStore = this.getPackage().getSourcePartStore(); InputStream is = null; try { String name = this.getPartName().getName(); try { this.setContentLengthAsLoaded(partStore.getPartSize(name.substring(1))); } catch (UnsupportedOperationException uoe) { } is = partStore.loadPart(name.substring(1)); if (is == null) { log.warn(name + " missing from part store"); } else { log.debug("Lazily unmarshalling " + name); unmarshal(is); } } catch (JAXBException e) { log.error(e.getMessage(), e); } catch (Docx4JException e) { log.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(is); } } else if (binder == null) { // User might have set jaxb element, without creating a binder try { log.debug("creating binder for " + this.getJaxbElement().getClass().getName()); org.w3c.dom.Document doc = XmlUtils.neww3cDomDocument(); this.marshal(doc); unmarshal(doc.getDocumentElement()); } catch (JAXBException e) { log.error(e.getMessage(), e); } } return binder; }
From source file:org.eclipse.winery.repository.importing.CSARImporter.java
/** * Imports a self-service meta data description (if available) * /*from w w w. j a v a 2 s .co m*/ * The first service template in the provided entry definitions is taken * * @param tmf * * @param errors */ private void importSelfServiceMetaData(final TOSCAMetaFile tmf, final Path rootPath, Path entryDefinitions, final List<String> errors) { final Path selfServiceDir = rootPath.resolve(Constants.DIRNAME_SELF_SERVICE_METADATA); if (!Files.exists(selfServiceDir)) { CSARImporter.logger.debug("Self-service Portal directory does not exist in CSAR"); return; } if (!Files.exists(entryDefinitions)) { CSARImporter.logger.debug("Entry definitions does not exist."); return; } Unmarshaller um = JAXBSupport.createUnmarshaller(); TDefinitions defs; try { defs = (TDefinitions) um.unmarshal(entryDefinitions.toFile()); } catch (JAXBException e) { errors.add("Could not unmarshal definitions " + entryDefinitions.getFileName() + " " + e.getMessage()); return; } catch (ClassCastException e) { errors.add( "Definitions " + entryDefinitions.getFileName() + " is not a TDefinitions " + e.getMessage()); return; } final int cutLength = selfServiceDir.toString().length() + 1; Iterator<TExtensibleElements> iterator = defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation() .iterator(); boolean found = false; TExtensibleElements next = null; while (iterator.hasNext() && !found) { next = iterator.next(); if (next instanceof TServiceTemplate) { found = true; } } if (found) { TServiceTemplate serviceTemplate = (TServiceTemplate) next; String namespace = serviceTemplate.getTargetNamespace(); if (namespace == null) { namespace = defs.getTargetNamespace(); } ServiceTemplateId stId = new ServiceTemplateId(namespace, serviceTemplate.getId(), false); final SelfServiceMetaDataId id = new SelfServiceMetaDataId(stId); // QUICK HACK: We just import all data without any validation // Reason: the metadata resource can deal with nearly arbitrary formats of the data, therefore // we do not do any checking here try { Files.walkFileTree(selfServiceDir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String name = file.toString().substring(cutLength); // check: if name contains "/", this could lead to exceptions RepositoryFileReference ref = new RepositoryFileReference(id, name); if (name.equals("data.xml")) { // we have to check whether the data.xml contains // (uri:"http://opentosca.org/self-service", local:"application") // instead of // (uri:"http://www.eclipse.org/winery/model/selfservice", local:"Application" // We quickly replace it via String replacement instead of XSLT try { String oldContent = org.apache.commons.io.FileUtils.readFileToString(file.toFile(), "UTF-8"); String newContent = oldContent.replace("http://opentosca.org/self-service", "http://www.eclipse.org/winery/model/selfservice"); newContent = newContent.replace(":application", ":Application"); if (!oldContent.equals(newContent)) { // we replaced something -> write new content to old file org.apache.commons.io.FileUtils.writeStringToFile(file.toFile(), newContent, "UTF-8"); } } catch (IOException e) { CSARImporter.logger.debug("Could not replace content in data.xml", e); } } CSARImporter.this.importFile(file, ref, tmf, rootPath, errors); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { CSARImporter.logger.debug(e.getMessage(), e); errors.add("Self-service Meta Data: " + e.getMessage()); } } }
From source file:org.eclipse.winery.repository.importing.CSARImporter.java
private TDefinitions getXMLDefs(final List<String> errors, Path defsPath) { TDefinitions defs = null;//w w w .j av a2 s. com try { Unmarshaller um = JAXBSupport.createUnmarshaller(); defs = (TDefinitions) um.unmarshal(defsPath.toFile()); } catch (JAXBException e) { Throwable cause = e; String eMsg = ""; do { String msg = cause.getMessage(); if (msg != null) { eMsg = eMsg + msg + "; "; } cause = cause.getCause(); } while (cause != null); errors.add("Could not unmarshal definitions " + defsPath.getFileName() + " " + eMsg); CSARImporter.logger.debug("Unmarshalling error", e); } catch (ClassCastException e) { errors.add("Definitions " + defsPath.getFileName() + " is not a TDefinitions " + e.getMessage()); } return defs; }
From source file:org.energy_home.jemma.javagal.rest.util.Util.java
/** * Marshal class./* www.j a va2 s. c o m*/ * * @param o * the object to marshall. * * @return the marshalled representation. */ @SuppressWarnings("unchecked") synchronized public static <T> String marshal(Object o) { StringWriter stringWriter = new StringWriter(); try { JAXBContext jc = JAXBContext.newInstance(o.getClass()); Marshaller m = jc.createMarshaller(); QName _qname = new QName("http://www.zigbee.org/GWGRESTSchema", o.getClass().getSimpleName()); JAXBElement<T> je = new JAXBElement<T>(_qname, (Class<T>) o.getClass(), ((T) o)); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl()); m.setProperty("com.sun.xml.internal.bind.xmlDeclaration", Boolean.FALSE); m.marshal(je, stringWriter); String _tores = stringWriter.toString(); return _tores; } catch (JAXBException e) { logger.error("Exception on marshal : " + e.getMessage()); return EMPTY_STRING; } }