List of usage examples for javax.xml.bind JAXBException getLocalizedMessage
public String getLocalizedMessage()
From source file:net.emotivecloud.scheduler.drp4ost.DRP4OST.java
private OVFWrapper parse(String ovfXml) { OVFWrapper rv = null;/*from ww w.ja v a 2s . co m*/ StringBuilder cause = new StringBuilder(); try { rv = OVFWrapperFactory.parse(ovfXml); } catch (JAXBException e) { if (e instanceof PropertyException) { cause.append("Access to property failed: " + e.getErrorCode()); } else if (e instanceof MarshalException) { cause.append("Marshalling failed: " + e.getLocalizedMessage()); } else if (e instanceof UnmarshalException) { cause.append("Unmarshalling failed: " + e.getCause()); } else if (e instanceof ValidationException) { cause.append("XML Validation failed: " + e.getErrorCode()); } else { cause.append("Unespected " + e.getErrorCode()); cause.append(e.getClass().getName()); cause.append(": "); } cause.append(e.getMessage()); throw new DRPOSTException(cause.toString(), e, StatusCodes.XML_PROBLEM); } catch (OVFException e) { cause.append("Problems parsing OVF file: "); cause.append(e.getMessage()); throw new DRPOSTException(cause.toString(), e, StatusCodes.XML_PROBLEM); } return rv; }
From source file:eu.scape_project.service.ConnectorService.java
/** * Update an {@link IntellectualEntity} in Fedora * /* www . j a v a 2 s . c o m*/ * @param session * the {@link Session} to use for the update operation * @param src * the updated {@link IntellectualEntity}'s METS representation * @param entityId * the id of the {@link IntellectualEntity} to update * @throws RepositoryException * if an error occurred while updating the * {@link IntellectualEntity} */ public void updateEntity(final Session session, final InputStream src, final String entityId) throws RepositoryException { final String entityPath = ENTITY_FOLDER + "/" + entityId; final FedoraObject entityObject = this.objectService.getObject(session, entityPath); final IdentifierTranslator subjects = new DefaultIdentifierTranslator(); final String uri = subjects.getSubject(entityObject.getPath()).getURI(); /* fetch the current version number from the repo */ final String oldVersionPath = getCurrentVersionPath( SerializationUtils.unifyDatasetModel(entityObject.getPropertiesDataset(subjects)), uri); final String oldVersionUri = subjects.getSubject(oldVersionPath).getURI(); int versionNumber = Integer.parseInt(oldVersionPath.substring(oldVersionPath.lastIndexOf('-') + 1)) + 1; final String newVersionPath = entityPath + "/version-" + versionNumber; final String newVersionUri = subjects.getSubject(newVersionPath).getURI(); try { /* read the post body into an IntellectualEntity object */ final IntellectualEntity ie = this.marshaller.deserialize(IntellectualEntity.class, src); final StringBuilder sparql = new StringBuilder("PREFIX scape: <" + SCAPE_NAMESPACE + "> "); final FedoraObject versionObject = objectService.createObject(session, newVersionPath); /* add the metadata datastream for descriptive metadata */ if (ie.getDescriptive() != null) { addMetadata(session, ie.getDescriptive(), newVersionPath + "/DESCRIPTIVE"); } /* add all the representations */ addRepresentations(session, ie.getRepresentations(), newVersionPath); sparql.append("INSERT DATA {<" + uri + "> " + prefix(HAS_VERSION) + " <" + newVersionUri + ">};"); sparql.append( "INSERT DATA {<" + uri + "> " + prefix(HAS_CURRENT_VERSION) + " <" + newVersionUri + ">};"); /* update the object and it's child's using sparql */ entityObject.updatePropertiesDataset(subjects, sparql.toString()); /* save the changes made to the objects */ session.save(); } catch (JAXBException e) { LOG.error(e.getLocalizedMessage(), e); throw new RepositoryException(e); } }
From source file:eu.scape_project.service.ConnectorService.java
/** * Save an {@link IntellectualEntity} in Fedora using a given id * /* w w w . j a va2 s . com*/ * @param session * the {@link Session} to use for the operation * @param src * the {@link IntellectualEntity}'s METS representation * @param entityId * the id to use for the entity. if <code>null</code> then a * random UUID will be used as an identifier for the * {@link IntellectualEntity} * @return the id of the {@link IntellectualEntity} as saved in Fedora * @throws RepositoryException * if an error occurred while saving the * {@link IntellectualEntity} */ public String addEntity(final Session session, final InputStream src, String entityId) throws RepositoryException { try { /* read the post body into an IntellectualEntity object */ final IntellectualEntity ie = this.marshaller.deserialize(IntellectualEntity.class, src); final StringBuilder sparql = new StringBuilder("PREFIX scape: <" + SCAPE_NAMESPACE + "> "); if (entityId == null) { if (ie.getIdentifier() != null) { entityId = ie.getIdentifier().getValue(); this.validateId(entityId); } else { entityId = UUID.randomUUID().toString(); } } /* create the entity top level object in fcrepo as a first version */ final String entityPath = ENTITY_FOLDER + "/" + entityId; final String versionPath = entityPath + "/version-1"; if (this.objectService.exists(session, "/" + entityPath)) { /* return a 409: Conflict result */ throw new ItemExistsException("Entity '" + entityId + "' already exists"); } final FedoraObject entityObject = objectService.createObject(session, entityPath); entityObject.getNode().addMixin("scape:intellectual-entity"); final FedoraObject versionObject = objectService.createObject(session, versionPath); versionObject.getNode().addMixin("scape:intellectual-entity-version"); final IdentifierTranslator subjects = new DefaultIdentifierTranslator(); final String entityUri = subjects.getSubject(entityObject.getPath()).getURI(); final String versionUri = subjects.getSubject(versionObject.getPath()).getURI(); /* add the metadata datastream for descriptive metadata */ if (ie.getDescriptive() != null) { addMetadata(session, ie.getDescriptive(), versionPath + "/DESCRIPTIVE"); } /* add all the representations */ for (String repUri : addRepresentations(session, ie.getRepresentations(), versionPath)) { sparql.append("INSERT DATA {<" + versionUri + "> " + prefix(HAS_REPRESENTATION) + " \"" + repUri + "\"};"); } /* update the intellectual entity's properties */ sparql.append("INSERT DATA {<" + entityUri + "> " + prefix(HAS_LIFECYCLESTATE) + " \"" + LifecycleState.State.INGESTED + "\"};"); sparql.append("INSERT DATA {<" + entityUri + "> " + prefix(HAS_LIFECYCLESTATE_DETAILS) + " \"successfully ingested at " + new Date().getTime() + "\"};"); sparql.append("INSERT DATA {<" + entityUri + "> " + prefix(HAS_TYPE) + " \"intellectualentity\"};"); sparql.append("INSERT DATA {<" + entityUri + "> " + prefix(HAS_VERSION) + " \"" + versionUri + "\"};"); sparql.append("INSERT DATA {<" + entityUri + "> " + prefix(HAS_CURRENT_VERSION) + " <" + versionUri + "> };"); /* update the object and it's child's using sparql */ entityObject.updatePropertiesDataset(subjects, sparql.toString()); /* save the changes made to the objects */ session.save(); return entityId; } catch (JAXBException e) { LOG.error(e.getLocalizedMessage(), e); throw new RepositoryException(e); } }
From source file:eu.scape_project.service.ConnectorService.java
private void addMetadata(final Session session, final Object metadata, final String path) throws RepositoryException { final StringBuilder sparql = new StringBuilder("PREFIX scape: <" + SCAPE_NAMESPACE + "> "); try {/*from w w w .ja v a 2 s . co m*/ /* use piped streams to copy the data to the repo */ final PipedInputStream dcSrc = new PipedInputStream(); final PipedOutputStream dcSink = new PipedOutputStream(); dcSink.connect(dcSrc); new Thread(new Runnable() { @Override public void run() { try { ConnectorService.this.marshaller.getJaxbMarshaller().marshal(metadata, dcSink); dcSink.flush(); dcSink.close(); } catch (JAXBException e) { LOG.error(e.getLocalizedMessage(), e); } catch (IOException e) { LOG.error(e.getLocalizedMessage(), e); } } }).start(); final Datastream ds = datastreamService.createDatastream(session, path, "text/xml", null, dcSrc); final Node desc = ds.getNode(); desc.addMixin("scape:metadata"); final IdentifierTranslator subjects = new DefaultIdentifierTranslator(); final String dsUri = subjects.getSubject(desc.getPath()).getURI(); /* get the type of the metadata */ String type = "unknown"; String schema = ""; if (metadata.getClass() == ElementContainer.class) { type = "dublin-core"; schema = "http://purl.org/dc/elements/1.1/"; } else if (metadata.getClass() == GbsType.class) { type = "gbs"; schema = "http://books.google.com/gbs"; } else if (metadata.getClass() == Fits.class) { type = "fits"; schema = "http://hul.harvard.edu/ois/xml/ns/fits/fits_output"; } else if (metadata.getClass() == AudioType.class) { type = "audiomd"; schema = "http://www.loc.gov/audioMD/"; } else if (metadata.getClass() == RecordType.class) { type = "marc21"; schema = "http://www.loc.gov/MARC21/slim"; } else if (metadata.getClass() == Mix.class) { type = "mix"; schema = "http://www.loc.gov/mix/v20"; } else if (metadata.getClass() == VideoType.class) { type = "videomd"; schema = "http://www.loc.gov/videoMD/"; } else if (metadata.getClass() == PremisComplexType.class) { type = "premis-provenance"; schema = "info:lc/xmlns/premis-v2"; } else if (metadata.getClass() == RightsComplexType.class) { type = "premis-rights"; schema = "info:lc/xmlns/premis-v2"; } else if (metadata.getClass() == TextMD.class) { type = "textmd"; schema = "info:lc/xmlns/textmd-v3"; } /* add a sparql query to set the type of this object */ sparql.append("INSERT DATA {<" + dsUri + "> " + prefix(HAS_TYPE) + " '" + type + "'};"); sparql.append("INSERT DATA {<" + dsUri + "> " + prefix(HAS_SCHEMA) + " '" + schema + "'};"); ds.updatePropertiesDataset(subjects, sparql.toString()); } catch (IOException e) { throw new RepositoryException(e); } catch (InvalidChecksumException e) { throw new RepositoryException(e); } }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private OCAComputeWrapper parseOcaCompute(String s) { OCAComputeWrapper rv = null;//w w w . ja v a 2 s. c o m StringBuilder cause = new StringBuilder(); try { rv = OCAComputeWrapperFactory.parse(s); } catch (SAXException se) { throw new DRPOneException("XML Parsing error", se, StatusCodes.INTERNAL); } catch (JAXBException e) { if (e instanceof PropertyException) { cause.append("Access to property failed: " + e.getErrorCode()); } else if (e instanceof MarshalException) { cause.append("Marshalling failed: " + e.getLocalizedMessage()); } else if (e instanceof UnmarshalException) { cause.append("Unmarshalling failed: " + e.getCause()); } else if (e instanceof ValidationException) { cause.append("XML Validation failed: " + e.getErrorCode()); } else { cause.append("Unespected " + e.getErrorCode()); cause.append(e.getClass().getName()); cause.append(": "); } cause.append(e.getMessage()); log.error(cause.toString()); if (log.isTraceEnabled()) { log.trace(cause, e); } throw new DRPOneException(cause.toString(), e, StatusCodes.ONE_FAILURE); } return rv; }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private OCAComputeListWrapper parseOcaComputeList(String s) { OCAComputeListWrapper rv = null;/*from w w w . ja va2 s .c o m*/ StringBuilder cause = new StringBuilder(); try { rv = OCAComputeListWrapperFactory.parseList(s); } catch (SAXException se) { throw new DRPOneException("XML Parsing error", se, StatusCodes.INTERNAL); } catch (JAXBException e) { if (e instanceof PropertyException) { cause.append("Access to property failed: " + e.getErrorCode()); } else if (e instanceof MarshalException) { cause.append("Marshalling failed: " + e.getLocalizedMessage()); } else if (e instanceof UnmarshalException) { cause.append("Unmarshalling failed: " + e.getCause()); } else if (e instanceof ValidationException) { cause.append("XML Validation failed: " + e.getErrorCode()); } else { cause.append("Unespected " + e.getErrorCode()); cause.append(e.getClass().getName()); cause.append(": "); } cause.append(e.getMessage()); log.error(cause.toString()); if (log.isTraceEnabled()) { log.trace(cause, e); } throw new DRPOneException(cause.toString(), e, StatusCodes.ONE_FAILURE); } return rv; }
From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java
private OVFWrapper parse(String ovfXml) throws DRPOneException { OVFWrapper rv = null;//from w w w .j a va 2 s . c om StringBuilder cause = new StringBuilder(); try { rv = OVFWrapperFactory.parse(ovfXml); } catch (JAXBException e) { if (e instanceof PropertyException) { cause.append("Access to property failed: " + e.getErrorCode()); } else if (e instanceof MarshalException) { cause.append("Marshalling failed: " + e.getLocalizedMessage()); } else if (e instanceof UnmarshalException) { cause.append("Unmarshalling failed: " + e.getCause()); } else if (e instanceof ValidationException) { cause.append("XML Validation failed: " + e.getErrorCode()); } else { cause.append("Unespected " + e.getErrorCode()); cause.append(e.getClass().getName()); cause.append(": "); } cause.append(e.getMessage()); log.error(cause.toString()); if (log.isTraceEnabled()) { log.trace(cause, e); } throw new DRPOneException(cause.toString(), e, StatusCodes.XML_PROBLEM); } catch (OVFException e) { cause.append("Problems parsing OVF file: "); cause.append(e.getMessage()); log.error(cause.toString()); if (log.isTraceEnabled()) { log.trace(cause, e); } throw new DRPOneException(cause.toString(), e, StatusCodes.XML_PROBLEM); } return rv; }
From source file:org.apache.openaz.xacml.util.XACMLPolicyWriter.java
/** * Helper static class that does the work to write a policy set to a file on disk. */// w w w. ja v a2s. co m public static Path writePolicyFile(Path filename, PolicySetType policySet) { JAXBElement<PolicySetType> policySetElement = new ObjectFactory().createPolicySet(policySet); try { JAXBContext context = JAXBContext.newInstance(PolicySetType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policySetElement, filename.toFile()); if (Files.exists(filename)) { return filename; } else { logger.error("File does not exist after marshalling."); return null; } } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); return null; } }
From source file:org.apache.openaz.xacml.util.XACMLPolicyWriter.java
/** * Helper static class that does the work to write a policy set to an output stream. *///from w ww. j a v a 2s .co m public static void writePolicyFile(OutputStream os, PolicySetType policySet) { JAXBElement<PolicySetType> policySetElement = new ObjectFactory().createPolicySet(policySet); try { JAXBContext context = JAXBContext.newInstance(PolicySetType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policySetElement, os); } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); } }
From source file:org.apache.openaz.xacml.util.XACMLPolicyWriter.java
/** * Helper static class that does the work to write a policy to a file on disk. *//* ww w . j a v a 2 s . c om*/ public static Path writePolicyFile(Path filename, PolicyType policy) { JAXBElement<PolicyType> policyElement = new ObjectFactory().createPolicy(policy); try { JAXBContext context = JAXBContext.newInstance(PolicyType.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policyElement, filename.toFile()); if (Files.exists(filename)) { return filename; } else { logger.error("File does not exist after marshalling."); return null; } } catch (JAXBException e) { logger.error("writePolicyFile failed: " + e.getLocalizedMessage()); return null; } }