Java Code Examples for javax.xml.bind.JAXBContext

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Aion-Extreme, under directory /AE-go_GameServer/src/com/aionemu/gameserver/utils/xml/.

Source file: SchemaGen.java

  34 
vote

public static void main(String[] args) throws Exception {
  final File baseDir=new File("./data/static_data");
class MySchemaOutputResolver extends SchemaOutputResolver {
    public Result createOutput(    String namespaceUri,    String suggestedFileName) throws IOException {
      return new StreamResult(new File(baseDir,"static_data1.xsd"));
    }
  }
  JAXBContext context=JAXBContext.newInstance(StaticData.class);
  context.generateSchema(new MySchemaOutputResolver());
}
 

Example 2

From project Activiti-KickStart, under directory /activiti-kickstart-java/src/main/java/org/activiti/kickstart/service/.

Source file: MarshallingServiceImpl.java

  33 
vote

public String marshallWorkflow(KickstartWorkflow kickstartWorkflow){
  try {
    JAXBContext jaxbContext=JAXBContext.newInstance(Definitions.class);
    Marshaller marshaller=jaxbContext.createMarshaller();
    StringWriter writer=new StringWriter();
    marshaller.marshal(convertToBpmn(kickstartWorkflow),writer);
    return writer.toString();
  }
 catch (  JAXBException e) {
    throw new RuntimeException("Could not marshal workflow",e);
  }
}
 

Example 3

From project ALP, under directory /workspace/alp-reporter/src/main/java/com/lohika/alp/log4j/xml/.

Source file: XMLLayout.java

  32 
vote

@Override public void activateOptions(){
  buffer=new StringWriter();
  XMLOutputFactory factory=XMLOutputFactory.newInstance();
  try {
    xmlWriter=factory.createXMLStreamWriter(buffer);
    JAXBContext jc=JAXBContext.newInstance(contextPath);
    marshaller=jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT,true);
  }
 catch (  Exception e) {
    LogLog.error("XMLLayout error",e);
  }
}
 

Example 4

From project arquillian-rusheye, under directory /rusheye-impl/src/main/java/org/jboss/rusheye/result/writer/.

Source file: XmlResultWriter.java

  32 
vote

private Marshaller createMarshaller() throws JAXBException {
  JAXBContext context=JAXBContext.newInstance("org.jboss.rusheye.suite");
  Marshaller marshaller=context.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
  return marshaller;
}
 

Example 5

From project blog_1, under directory /miniprojects/generic-pojo-mappers/src/main/java/net/jakubholy/blog/genericmappers/xml/.

Source file: XmlElements.java

  32 
vote

@SuppressWarnings("unchecked") private <T>T mapNodeToPojo(Node entryNode,Class<T> entryPojoType){
  try {
    JAXBContext jaxb=JAXBContext.newInstance(entryPojoType);
    Unmarshaller unmarshaller=jaxb.createUnmarshaller();
    unmarshaller.setListener(BEAN_VALIDATOR);
    unmarshaller.setEventHandler(new UnknownElementLoggingHandler());
    return (T)unmarshaller.unmarshal(entryNode);
  }
 catch (  JAXBException e) {
    throw new RuntimeException("Mapping XML to Java Bean failed for " + entryPojoType.getName() + " and XML "+ xmlStart+ ": "+ e.getMessage(),e);
  }
}
 

Example 6

From project blueprint-namespaces, under directory /blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/.

Source file: BlueprintAnnotationScannerImpl.java

  32 
vote

private void marshallOBRModel(Tblueprint tblueprint,File blueprintFile) throws JAXBException {
  JAXBContext context=JAXBContext.newInstance(Tblueprint.class);
  Marshaller marshaller=context.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);
  marshaller.marshal(tblueprint,blueprintFile);
}
 

Example 7

From project bundlemaker, under directory /main/org.bundlemaker.core/src/org/bundlemaker/core/internal/projectdescription/.

Source file: XmlProjectDescriptionExporterUtils.java

  32 
vote

/** 
 * <p> </p>
 * @param outputStream
 * @return
 */
public static XmlProjectDescriptionType unmarshal(InputStream inputStream){
  try {
    JaxbCompoundClassLoader jaxbCompoundClassLoader=new JaxbCompoundClassLoader();
    JAXBContext jaxbContext=JAXBContext.newInstance(jaxbCompoundClassLoader.getPackageString(),jaxbCompoundClassLoader.getCompoundClassLoader());
    Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
    JAXBElement<XmlProjectDescriptionType> root=unmarshaller.unmarshal(new StreamSource(inputStream),XmlProjectDescriptionType.class);
    return root.getValue();
  }
 catch (  Exception e) {
    throw new RuntimeException(e.getMessage(),e);
  }
}
 

Example 8

From project CampusLifePortlets, under directory /src/main/java/org/jasig/portlet/campuslife/athletics/dao/.

Source file: AthleticsDaoMockImpl.java

  32 
vote

@Override public void afterPropertiesSet() throws Exception {
  try {
    JAXBContext jaxbContext=JAXBContext.newInstance(AthleticsFeed.class);
    Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
    this.feed=(AthleticsFeed)unmarshaller.unmarshal(mockData.getInputStream());
  }
 catch (  IOException e) {
    log.error("Failed to read mock data",e);
  }
catch (  JAXBException e) {
    log.error("Failed to unmarshall mock data",e);
  }
}
 

Example 9

From project cdk, under directory /attributes/src/test/java/org/richfaces/cdk/attributes/.

Source file: AttributesTest.java

  32 
vote

private String marshal(SchemaSet schemaSet) throws Exception {
  StringWriter writer=new StringWriter();
  JAXBContext jc=JAXBContext.newInstance(SchemaSet.class);
  Marshaller marshaller=jc.createMarshaller();
  marshaller.setProperty("jaxb.formatted.output",Boolean.TRUE);
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
  marshaller.marshal(schemaSet,new StreamResult(writer));
  return writer.toString();
}
 

Example 10

From project cloudify, under directory /esc/src/main/java/org/cloudifysource/esc/driver/provisioning/azure/client/.

Source file: MicrosoftAzureModelUtils.java

  32 
vote

/** 
 * @param entity - the string representation off the object in XML form
 * @return - an instance of {@link Object} representing the XML that can becast to a specific type
 * @throws MicrosoftAzureException .
 */
public static Object unmarshall(final String entity) throws MicrosoftAzureException {
  JAXBContext context=ModelContextFactory.createInstance();
  Document xmlDoc=parse(entity);
  Unmarshaller um=null;
  try {
    um=context.createUnmarshaller();
    return um.unmarshal(xmlDoc);
  }
 catch (  JAXBException e) {
    throw new MicrosoftAzureException(e);
  }
}
 

Example 11

From project cogroo4, under directory /cogroo-ann/src/main/java/org/cogroo/config/.

Source file: LanguageConfigurationUtil.java

  32 
vote

private static LanguageConfiguration unmarshal(InputStream inputStream) throws JAXBException {
  String packageName=LanguageConfiguration.class.getPackage().getName();
  ClassLoader cl=ObjectFactory.class.getClassLoader();
  JAXBContext jc=JAXBContext.newInstance(packageName,cl);
  Unmarshaller u=jc.createUnmarshaller();
  return (LanguageConfiguration)u.unmarshal(inputStream);
}
 

Example 12

From project CoursesPortlet, under directory /courses-portlet-webapp/src/main/java/org/jasig/portlet/courses/dao/xml/.

Source file: MockCoursesDaoImpl.java

  32 
vote

@Override public void afterPropertiesSet() throws Exception {
  try {
    JAXBContext jaxbContext=JAXBContext.newInstance(TermsAndCourses.class);
    Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
    this.summary=(TermsAndCourses)unmarshaller.unmarshal(mockData.getInputStream());
  }
 catch (  IOException e) {
    log.error("Failed to read mock data",e);
  }
catch (  JAXBException e) {
    log.error("Failed to unmarshall mock data",e);
  }
}
 

Example 13

From project crest, under directory /core/src/test/java/org/codegist/crest/serializer/jaxb/.

Source file: SimpleJaxbTest.java

  32 
vote

private SimpleJaxb newToTest(){
  JAXBContext mockJaxbContext=mock(JAXBContext.class);
  try {
    when(mockJaxbContext.createMarshaller()).thenReturn(mockMarshaller);
    when(mockJaxbContext.createUnmarshaller()).thenReturn(mockUnmarshaller);
    return new SimpleJaxb(mockJaxbContext);
  }
 catch (  JAXBException e) {
    throw new ExceptionInInitializerError(e);
  }
}
 

Example 14

From project dev-examples, under directory /input-demo/src/main/java/org/richfaces/demo/.

Source file: CountriesBean.java

  32 
vote

@PostConstruct public void initialize(){
  try {
    JAXBContext countryContext=JAXBContext.newInstance(Countries.class);
    Unmarshaller unmarshaller=countryContext.createUnmarshaller();
    ClassLoader classLoader=Thread.currentThread().getContextClassLoader();
    URL dataUrl=classLoader.getResource("org/richfaces/demo/countries.xml");
    countries=((Countries)unmarshaller.unmarshal(dataUrl)).getCountries();
  }
 catch (  JAXBException e) {
    throw new FacesException(e.getMessage(),e);
  }
}
 

Example 15

From project drools-chance, under directory /drools-pmml/src/main/java/org/drools/pmml_4_1/.

Source file: PMML4Compiler.java

  32 
vote

/** 
 * Imports a PMML source file, returning a Java descriptor
 * @param model			the PMML package name (classes derived from a specific schema)
 * @param source		the name of the PMML resource storing the predictive model
 * @return				the Java Descriptor of the PMML resource
 */
public PMML loadModel(String model,InputStream source){
  try {
    JAXBContext jc=JAXBContext.newInstance(model);
    Unmarshaller unmarshaller=jc.createUnmarshaller();
    return (PMML)unmarshaller.unmarshal(source);
  }
 catch (  JAXBException e) {
    e.printStackTrace();
    return null;
  }
}
 

Example 16

From project droolsjbpm-integration, under directory /drools-camel/src/test/java/org/drools/camel/component/.

Source file: JaxbTest.java

  32 
vote

@Test public void testFactHandleMarshall() throws JAXBException {
  JAXBContext jaxbContext=getJaxbContext();
  KnowledgeBase kbase=KnowledgeBaseFactory.newKnowledgeBase();
  StatefulKnowledgeSession ksession=kbase.newStatefulKnowledgeSession();
  FactHandle fh1=ksession.insert(new Person("darth",105));
  Marshaller marshaller=jaxbContext.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  marshaller.marshal(fh1,baos);
  assertXMLEqual("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<fact-handle external-form=\"" + fh1.toExternalForm() + "\"/>",new String(baos.toByteArray()));
  Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
  FactHandle fh2=(FactHandle)unmarshaller.unmarshal(new StringReader(baos.toString()));
  assertEquals(fh1,fh2);
}
 

Example 17

From project ds-annotation-builder, under directory /com.wuetherich.osgi.ds.annotations/src/com/wuetherich/osgi/ds/annotations/internal/.

Source file: AbstractComponentDescription.java

  32 
vote

/** 
 * <p> </p>
 * @param xmlProjectDescription
 * @param outputStream
 */
public String toXml(){
  try {
    JAXBContext jaxbContext=createJAXBContext();
    Marshaller marshaller=jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
    StringWriter result=new StringWriter();
    marshaller.marshal(new ObjectFactory().createComponent(_tcomponent),result);
    return result.toString();
  }
 catch (  JAXBException e) {
    e.printStackTrace();
    throw new RuntimeException(e.getMessage(),e);
  }
}
 

Example 18

From project Easy-Cassandra, under directory /src/main/java/org/easycassandra/util/.

Source file: DomUtil.java

  32 
vote

/** 
 * Create a Object from XML Document
 * @param file - a XML Document
 * @param objClass -
 * @return the Object
 */
public static Object getDom(File file,@SuppressWarnings("rawtypes") Class objClass){
  try {
    JAXBContext jAXBContext=JAXBContext.newInstance(objClass);
    Unmarshaller unmarshaller=jAXBContext.createUnmarshaller();
    return unmarshaller.unmarshal(file);
  }
 catch (  JAXBException exception) {
    file.delete();
    Logger.getLogger(DomUtil.class.getName()).log(Level.SEVERE,null,exception);
  }
  return null;
}
 

Example 19

From project gmc, under directory /src/org.gluster.storage.management.gateway/src/org/gluster/storage/management/gateway/utils/.

Source file: ServerUtil.java

  32 
vote

/** 
 * Unmarshals given input string into object of given class
 * @param expectedClass Class whose object is expected
 * @param input Input string
 * @return Object of given expected class
 */
public <T>T unmarshal(Class<T> expectedClass,String input){
  try {
    JAXBContext context=JAXBContext.newInstance(expectedClass);
    Unmarshaller um=context.createUnmarshaller();
    return (T)um.unmarshal(new ByteArrayInputStream(input.getBytes()));
  }
 catch (  JAXBException e) {
    String errMsg="Error during unmarshalling string [" + input + "] for class ["+ expectedClass.getName()+ ": ["+ e.getMessage()+ "]";
    logger.error(errMsg,e);
    throw new GlusterRuntimeException(errMsg,e);
  }
}
 

Example 20

From project hackergarten-moreunit, under directory /org.moreunit.mock/src/org/moreunit/mock/templates/.

Source file: XmlTemplateDefinitionReader.java

  32 
vote

public MockingTemplates read(InputStream is) throws MockingTemplateException {
  try {
    JAXBContext jc=JAXBContext.newInstance(MockingTemplates.class);
    Unmarshaller unmarshaller=jc.createUnmarshaller();
    return (MockingTemplates)unmarshaller.unmarshal(is);
  }
 catch (  JAXBException e) {
    throw new MockingTemplateException("Could not read XML definition",e);
  }
}
 

Example 21

From project hbc-maven-core, under directory /src/main/java/org/hardisonbrewing/jaxb/.

Source file: JAXB.java

  32 
vote

public static JAXBContext getJAXBContext(Class<?> clazz) throws JAXBException {
  JAXBContext jaxbContext=jaxbContexts.get(clazz);
  if (jaxbContext != null) {
    return jaxbContext;
  }
  jaxbContext=JAXBContext.newInstance(clazz.getPackage().getName(),Thread.currentThread().getContextClassLoader());
  jaxbContexts.put(clazz,jaxbContext);
  return jaxbContext;
}
 

Example 22

From project hibernate-validator, under directory /engine/src/main/java/org/hibernate/validator/internal/xml/.

Source file: ValidationXmlParser.java

  32 
vote

private ValidationConfigType unmarshal(InputStream inputStream,Schema schema){
  log.parsingXMLFile(VALIDATION_XML_FILE);
  try {
    JAXBContext jc=JAXBContext.newInstance(ValidationConfigType.class);
    Unmarshaller unmarshaller=jc.createUnmarshaller();
    unmarshaller.setSchema(schema);
    StreamSource stream=new StreamSource(inputStream);
    JAXBElement<ValidationConfigType> root=unmarshaller.unmarshal(stream,ValidationConfigType.class);
    return root.getValue();
  }
 catch (  JAXBException e) {
    throw log.getUnableToParseValidationXmlFileException(VALIDATION_XML_FILE,e);
  }
}
 

Example 23

From project hqapi, under directory /hqapi1/src/main/java/org/hyperic/hq/hqapi1/.

Source file: XmlUtil.java

  32 
vote

private static synchronized JAXBContext getCachedContext(String pkg) throws JAXBException {
  JAXBContext ctx=_ctxMap.get(pkg);
  if (ctx == null) {
    ctx=JAXBContext.newInstance(pkg);
    _ctxMap.put(pkg,ctx);
  }
  return ctx;
}
 

Example 24

From project Ivory, under directory /webapp/src/test/java/org/apache/ivory/resource/.

Source file: AbstractTestBase.java

  32 
vote

public AbstractTestBase(){
  try {
    JAXBContext jaxbContext=JAXBContext.newInstance(APIResult.class,Feed.class,Process.class,Cluster.class,InstancesResult.class);
    unmarshaller=jaxbContext.createUnmarshaller();
    marshaller=jaxbContext.createMarshaller();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 25

From project jbosgi, under directory /testsuite/example/src/test/java/org/jboss/test/osgi/example/jaxb/.

Source file: XMLBindingTestCase.java

  32 
vote

@Test @SuppressWarnings("unchecked") public void testUnmarshaller() throws Exception {
  JAXBContext jaxbContext=JAXBContext.newInstance(ObjectFactory.class.getPackage().getName(),ObjectFactory.class.getClassLoader());
  Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
  URL resURL=bundle.getResource("booking.xml");
  JAXBElement<CourseBooking> rootElement=(JAXBElement<CourseBooking>)unmarshaller.unmarshal(resURL.openStream());
  assertNotNull("root element not null",rootElement);
  CourseBooking booking=rootElement.getValue();
  assertNotNull("booking not null",booking);
  CompanyType company=booking.getCompany();
  assertNotNull("company not null",company);
  assertEquals("ACME Consulting",company.getName());
}
 

Example 26

From project jbpm-form-builder, under directory /jbpm-gwt-form-builder/src/main/java/org/jbpm/formbuilder/server/.

Source file: GuvnorHelper.java

  32 
vote

@SuppressWarnings("unchecked") public <T>T jaxbTransformation(Class<T> retType,InputStream input,Class<?>... boundTypes) throws JAXBException, IOException {
  String content=IOUtils.toString(input);
  StringReader reader=new StringReader(content);
  JAXBContext ctx=JAXBContext.newInstance(boundTypes);
  Unmarshaller unmarshaller=ctx.createUnmarshaller();
  Object obj=unmarshaller.unmarshal(reader);
  return (T)obj;
}
 

Example 27

From project jDTO-Binder, under directory /jdto/src/main/java/org/jdto/impl/.

Source file: XMLBeanInspector.java

  32 
vote

/** 
 * Perform the parsing of the XML File
 * @param xmlStream
 * @return 
 */
private DTOMappings parseXML(InputStream xmlStream){
  try {
    JAXBContext context=JAXBContext.newInstance(DTOMappings.class);
    Unmarshaller unmarshaller=context.createUnmarshaller();
    DTOMappings inputMappings=(DTOMappings)unmarshaller.unmarshal(xmlStream);
    return inputMappings;
  }
 catch (  Exception ex) {
    logger.error("Got exception while parsing xml file",ex);
    throw new RuntimeException(ex);
  }
}
 

Example 28

From project jira-hudson-integration, under directory /hudson-apiv2-wsclient/src/main/java/com/marvelution/hudson/plugins/apiv2/client/unmarshallers/.

Source file: Unmarshallers.java

  32 
vote

/** 
 * Method to get an  {@link Unmarshaller} for the given {@link Class}
 * @param model the model {@link Class} to get the {@link Unmarshaller} for
 * @return the {@link Unmarshaller}
 * @throws JAXBException in case of exceptions
 */
public static Unmarshaller forModel(Class<? extends Model> model) throws JAXBException {
  JAXBContext context;
  try {
    context=JAXBContext.newInstance(model);
  }
 catch (  JAXBException e) {
    context=JAXBContext.newInstance(model.getPackage().getName(),model.getClassLoader());
  }
  return context.createUnmarshaller();
}
 

Example 29

From project JMaNGOS, under directory /Commons/src/main/java/org/jmangos/commons/dataholder/.

Source file: XmlDataLoader.java

  32 
vote

/** 
 * Load static data.
 * @param < T >
 * @param clazz
 * @param Schema
 * @param XmlFile
 * @return
 */
public <T>T loadStaticData(final Class<T> clazz,final String Schema,final String XmlFile){
  try {
    final JAXBContext jc=JAXBContext.newInstance(clazz);
    final Unmarshaller un=jc.createUnmarshaller();
    un.setSchema(getSchema(Schema));
    return clazz.cast(un.unmarshal(new File(XmlFile)));
  }
 catch (  final JAXBException e) {
    System.err.println("Error while loading xml data for class: " + clazz.getCanonicalName());
    e.printStackTrace();
  }
  return null;
}
 

Example 30

From project jninka, under directory /jninka-parent/jninka-core/src/main/java/org/whitesource/jninka/model/.

Source file: ScanResults.java

  32 
vote

/** 
 * The method write this scan results to a XML file.
 * @param target Output file location.
 */
public void writeXML(File target){
  try {
    JAXBContext jc=JAXBContext.newInstance(ScanResults.class);
    Marshaller marshaller=jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);
    marshaller.marshal(this,target);
  }
 catch (  JAXBException e) {
    Logger.getLogger(ScanResults.class.getCanonicalName()).log(Level.SEVERE,"Unable to marshal " + e.getMessage(),e);
  }
}
 

Example 31

From project Karaf-Tutorial, under directory /cameljpa/jpa2jms/src/main/java/net/lr/tutorial/karaf/camel/jpa2jms/.

Source file: Jpa2JmsRoute.java

  32 
vote

private JaxbDataFormat createPersonJaxbDataFormat() throws JAXBException {
  JAXBContext jaxbContext=JAXBContext.newInstance(Person.class);
  JaxbDataFormat df=new JaxbDataFormat(jaxbContext);
  df.setContextPath(Person.class.getPackage().toString());
  return df;
}
 

Example 32

From project LABPipe, under directory /src/org/bultreebank/labpipe/data/.

Source file: WebLicht.java

  32 
vote

/** 
 * Unmarshalls <code>InputStream</code> into a <code>DSpin</code> object and then imports its content into this object.
 * @param is 
 */
public final void unmarshall(InputStream is){
  try {
    JAXBContext context=JAXBContext.newInstance("de.dspin.data");
    Unmarshaller u=context.createUnmarshaller();
    importDSpin((DSpin)u.unmarshal(is));
  }
 catch (  JAXBException ex) {
    logger.log(Level.SEVERE,ServiceConstants.EXCEPTION_JAXB,ex);
  }
}
 

Example 33

From project lightfish, under directory /lightfish/src/main/java/org/lightfish/business/heartbeat/control/.

Source file: Serializer.java

  32 
vote

@PostConstruct public void initialize(){
  try {
    JAXBContext jaxb=JAXBContext.newInstance(Snapshot.class);
    this.marshaller=jaxb.createMarshaller();
  }
 catch (  JAXBException ex) {
    throw new IllegalStateException("Cannot initialize JAXB context " + ex);
  }
}
 

Example 34

From project litle-sdk-for-java, under directory /lib/jaxb/samples/character-escape/src/.

Source file: Main.java

  32 
vote

public static void main(String[] args) throws Exception {
  JAXBContext context=JAXBContext.newInstance(ObjectFactory.class);
  ObjectFactory of=new ObjectFactory();
  JAXBElement<String> e=of.createE("G\u00F6del & his friends");
  Marshaller marshaller=context.createMarshaller();
  marshaller.setProperty("jaxb.encoding","US-ASCII");
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
  marshaller.marshal(e,System.out);
  marshaller=context.createMarshaller();
  marshaller.setProperty("jaxb.encoding","US-ASCII");
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
  marshaller.setProperty(CharacterEscapeHandler.class.getName(),new CustomCharacterEscapeHandler());
  marshaller.marshal(e,System.out);
}
 

Example 35

From project addis, under directory /application/src/main/java/org/drugis/addis/imports/.

Source file: ClinicaltrialsImporter.java

  31 
vote

static void getClinicaltrialsData(Study study,InputStream is,boolean importResults){
  JAXBContext jc;
  try {
    jc=JAXBContext.newInstance("org.drugis.addis.imports");
    ClinicalStudy studyImport=(ClinicalStudy)jc.createUnmarshaller().unmarshal(is);
    new ClinicaltrialsImporter(study,studyImport,importResults).importStudy();
  }
 catch (  Exception e) {
    String exceptionTitle="Could not complete import from ClinicalTrials.gov";
    StringBuilder errorMessage=new StringBuilder();
    errorMessage.append("Something went wrong while importing from ClinicalTrials.gov.");
    if (importResults) {
      errorMessage.append(" Please try again without importing results.");
    }
    errorMessage.append("\n\nWhen reporting this problem please include the NCT-ID where possible.");
    ErrorDialog.showDialog(e,exceptionTitle,errorMessage.toString(),true);
  }
}
 

Example 36

From project ANNIS, under directory /annis-service/src/main/java/annis/.

Source file: AnnisRunner.java

  31 
vote

public void doFind(String annisQuery){
  List<Match> matches=annisDao.find(analyzeQuery(annisQuery,"find"));
  JAXBContext jc=null;
  try {
    jc=JAXBContext.newInstance(annis.service.objects.Match.class);
  }
 catch (  JAXBException ex) {
    log.error("Problems with writing XML",ex);
  }
  for (int i=0; i < matches.size(); i++) {
    try {
      jc.createMarshaller().marshal(matches.get(i),out);
    }
 catch (    JAXBException ex) {
      log.error("Problems with writing XML",ex);
    }
    out.println();
  }
}
 

Example 37

From project bdd-security, under directory /src/main/java/net/continuumsecurity/reporting/.

Source file: ScannerReporter.java

  31 
vote

public void write(String reference,ScanIssueList issueList){
  try {
    File f=new File(path);
    if (!f.exists()) {
      f.mkdirs();
    }
    JAXBContext jaxbContext=new JAXBContextResolver().getContext(ScanIssueList.class);
    Marshaller marshaller=jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,new Boolean(true));
    marshaller.marshal(issueList,new FileOutputStream(path + reference + ".xml"));
  }
 catch (  PropertyException e) {
    e.printStackTrace();
  }
catch (  JAXBException e) {
    e.printStackTrace();
  }
catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 38

From project bpm-console, under directory /server/war/src/main/java/org/jboss/bpm/console/server/util/.

Source file: Payload2XML.java

  31 
vote

public StringBuffer convert(String refId,Map<String,Object> javaPayload){
  StringBuffer sb=new StringBuffer();
  try {
    List<Class> clz=new ArrayList<Class>(javaPayload.size() + 2);
    clz.add(PayloadCollection.class);
    clz.add(PayloadEntry.class);
    List<PayloadEntry> data=new ArrayList<PayloadEntry>();
    for (    String key : javaPayload.keySet()) {
      Object payload=javaPayload.get(key);
      clz.add(payload.getClass());
      data.add(new PayloadEntry(key,payload));
    }
    PayloadCollection dataset=new PayloadCollection(refId,data);
    JAXBContext jaxbContext=JAXBContext.newInstance(clz.toArray(new Class[]{}));
    ByteArrayOutputStream bout=new ByteArrayOutputStream();
    Marshaller m=jaxbContext.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);
    m.marshal(dataset,bout);
    sb.append(new String(bout.toByteArray()));
  }
 catch (  JAXBException e) {
    throw new RuntimeException("Payload2XML conversion failed",e);
  }
  return sb;
}
 

Example 39

From project CCR-Validator, under directory /src/main/java/org/openhealthdata/validation/.

Source file: CCRV1SchemaValidator.java

  31 
vote

private void validate(StreamSource src){
  ccr=null;
  try {
    validator.validate(src);
    Document xml=parseStreamSource(src,false);
    if (xml != null) {
      JAXBContext jc=JAXBContext.newInstance("org.astm.ccr");
      Unmarshaller um=jc.createUnmarshaller();
      ccr=(ContinuityOfCareRecord)um.unmarshal(xml);
    }
  }
 catch (  SAXException e) {
    logger.log(Level.SEVERE,"Not Valid CCR XML: " + e.getMessage());
  }
catch (  IOException e) {
    logger.log(Level.SEVERE,"Exception during validating",e);
    e.printStackTrace();
  }
catch (  JAXBException e) {
    logger.log(Level.SEVERE,"Exception during unmarshalling XML DOM",e);
    e.printStackTrace();
  }
}
 

Example 40

From project chargifyService, under directory /src/main/java/com/mondora/chargify/controller/.

Source file: Chargify.java

  31 
vote

protected Object parse(Class clazz,InputStream inputStream) throws ChargifyException {
  byte[] in=null;
  try {
    JAXBContext context=JAXBContext.newInstance(clazz);
    Unmarshaller unmarshaller=context.createUnmarshaller();
    unmarshaller.setSchema(null);
    if (logger.isTraceEnabled()) {
      try {
        in=readByteStream(inputStream);
        logger.trace("Response input " + new String(in));
        inputStream=new ByteArrayInputStream(in);
      }
 catch (      IOException e) {
      }
    }
    Object xmlObject=clazz.cast(unmarshaller.unmarshal(inputStream));
    return xmlObject;
  }
 catch (  JAXBException e) {
    if (logger.isTraceEnabled())     logger.trace(e.getMessage(),e);
    if (logger.isInfoEnabled())     logger.info(e.getMessage());
    throw new ChargifyException("Unparsable Entity " + new String(in));
  }
}
 

Example 41

From project demonstrator-backend, under directory /demonstrator-backend-ejb/src/main/java/org/marssa/demonstrator/beans/.

Source file: DAQBean.java

  31 
vote

@PostConstruct private void init() throws ConfigurationError, NoConnection, UnknownHostException, JAXBException, FileNotFoundException {
  logger.info("Initializing DAQ Bean");
  JAXBContext context=JAXBContext.newInstance(new Class[]{Settings.class});
  Unmarshaller unmarshaller=context.createUnmarshaller();
  InputStream is=this.getClass().getClassLoader().getResourceAsStream("configuration/settings.xml");
  Settings settings=(Settings)unmarshaller.unmarshal(is);
  for (  DAQType daq : settings.getDaqs().getDaq()) {
    AddressType addressElement=daq.getSocket();
    MString address;
    if (addressElement.getHost().getIp() == null || addressElement.getHost().getIp().isEmpty()) {
      String hostname=addressElement.getHost().getHostname();
      address=new MString(Inet4Address.getByName(hostname).getAddress().toString());
    }
 else {
      address=new MString(addressElement.getHost().getIp());
    }
    logger.info("Found configuration for {} connected to {}, port {}",new Object[]{daq.getDAQname(),address,addressElement.getPort()});
    LabJack lj;
switch (daq.getType()) {
case LAB_JACK_U_3:
      lj=LabJackU3.getInstance(address,new MInteger(daq.getSocket().getPort()));
    break;
case LAB_JACK_UE_9:
  lj=LabJackUE9.getInstance(address,new MInteger(daq.getSocket().getPort()));
break;
default :
throw new ConfigurationError("Unknown DAQ type: " + daq.getType());
}
daqs.put(address.toString() + ":" + addressElement.getPort(),lj);
}
logger.info("Initialized DAQ Bean");
}
 

Example 42

From project en, under directory /src/l1j/server/server/model/item/.

Source file: L1TreasureBox.java

  31 
vote

public static void load(){
  PerformanceTimer timer=new PerformanceTimer();
  System.out.print("loading TreasureBox...");
  try {
    JAXBContext context=JAXBContext.newInstance(L1TreasureBox.TreasureBoxList.class);
    Unmarshaller um=context.createUnmarshaller();
    File file=new File(PATH);
    TreasureBoxList list=(TreasureBoxList)um.unmarshal(file);
    for (    L1TreasureBox each : list) {
      each.init();
      _dataMap.put(each.getBoxId(),each);
    }
  }
 catch (  Exception e) {
    _log.log(Level.SEVERE,PATH + " is invalid for a TreasureBox load.",e);
    System.exit(0);
  }
  System.out.println("    OK!     " + timer.elapsedTimeMillis() + "ms");
}
 

Example 43

From project entando-core-engine, under directory /src/main/java/org/entando/entando/aps/system/services/api/server/.

Source file: ApiRestServer.java

  31 
vote

protected Object buildPostPutResponse(String langCode,ApiMethod.HttpMethod httpMethod,String namespace,String resourceName,HttpServletRequest request,HttpServletResponse response,UriInfo ui,MediaType mediaType){
  Object responseObject=null;
  try {
    IResponseBuilder responseBuilder=(IResponseBuilder)ApsWebApplicationUtils.getBean(SystemConstants.API_RESPONSE_BUILDER,request);
    Properties properties=this.extractRequestParameters(ui);
    properties.put(SystemConstants.API_LANG_CODE_PARAMETER,langCode);
    ApiMethod apiMethod=responseBuilder.extractApiMethod(httpMethod,namespace,resourceName);
    this.extractOAuthParameters(apiMethod,request,response,properties);
    Class expectedType=apiMethod.getExpectedType();
    Object bodyObject=null;
    if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
      JSONProvider jsonProvider=new JSONProvider();
      bodyObject=jsonProvider.readFrom(expectedType,expectedType.getGenericSuperclass(),expectedType.getAnnotations(),mediaType,null,request.getInputStream());
    }
 else {
      JAXBContext context=JAXBContext.newInstance(expectedType);
      Unmarshaller unmarshaller=context.createUnmarshaller();
      bodyObject=(Object)unmarshaller.unmarshal(request.getInputStream());
    }
    responseObject=responseBuilder.createResponse(apiMethod,bodyObject,properties);
  }
 catch (  ApiException ae) {
    responseObject=this.buildErrorResponse(httpMethod,resourceName,ae);
  }
catch (  Throwable t) {
    responseObject=this.buildErrorResponse(httpMethod,resourceName,t);
  }
  return this.createResponse(responseObject);
}
 

Example 44

From project faces, under directory /Proyectos/richfaces4-iteration/src/main/java/pe/joedayz/ejemplos/demo/util/.

Source file: GamesParser.java

  31 
vote

public synchronized List<GameDescriptor> getGameDescriptorsList(){
  if (gamesList == null) {
    ClassLoader ccl=Thread.currentThread().getContextClassLoader();
    URL resource=ccl.getResource("games.xml");
    JAXBContext context;
    try {
      context=JAXBContext.newInstance(GameDescriptorsHolder.class);
      GameDescriptorsHolder gamesHolder=(GameDescriptorsHolder)context.createUnmarshaller().unmarshal(resource);
      gamesList=gamesHolder.getGameDescriptors();
    }
 catch (    JAXBException e) {
      throw new FacesException(e.getMessage(),e);
    }
  }
  return gamesList;
}
 

Example 45

From project fedora-client, under directory /fedora-client-core/src/main/java/com/yourmediashelf/fedora/client/response/.

Source file: FedoraResponseImpl.java

  31 
vote

/** 
 * Unmarshall the Fedora ClientResponse using the JAXB schema-generated classes (see: target/generated-sources/).
 * @param contextPath JAXB contextPath
 * @return the unmarshalled XML
 * @throws FedoraClientException
 */
public Object unmarshallResponse(ContextPath contextPath) throws FedoraClientException {
  Object response=null;
  Schema schema=null;
  if (validateSchema()) {
    try {
      SchemaFactory schemaFactory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      schema=schemaFactory.newSchema();
    }
 catch (    SAXException e) {
      throw new FedoraClientException(e.getMessage(),e);
    }
  }
  try {
    JAXBContext context=JAXBContext.newInstance(contextPath.path());
    Unmarshaller unmarshaller=context.createUnmarshaller();
    unmarshaller.setSchema(schema);
    response=unmarshaller.unmarshal(new BufferedReader(new InputStreamReader(getEntityInputStream())));
  }
 catch (  JAXBException e) {
    throw new FedoraClientException(e.getMessage(),e);
  }
  return response;
}
 

Example 46

From project flip, under directory /core/src/main/java/com/tacitknowledge/flip/properties/.

Source file: XmlPropertyReader.java

  31 
vote

/** 
 * {@inheritDoc }
 */
@Override protected void readDescriptors(){
  try {
    final InputStream in=getConfigurationStream(getConfig());
    if (in == null) {
      return;
    }
    final JAXBContext context=JAXBContext.newInstance(FeatureDescriptors.class);
    final Unmarshaller unmarshaller=context.createUnmarshaller();
    final FeatureDescriptors descriptors=(FeatureDescriptors)unmarshaller.unmarshal(in);
    cache.clear();
    if (descriptors != null && descriptors.getFeatures() != null) {
      for (      final FeatureDescriptor descriptor : descriptors.getFeatures()) {
        cache.put(descriptor.getName(),descriptor);
      }
    }
  }
 catch (  final JAXBException ex) {
    Logger.getLogger(XmlPropertyReader.class.getName()).log(Level.WARNING,null,ex);
  }
}
 

Example 47

From project hibernate-metamodelgen, under directory /src/main/java/org/hibernate/jpamodelgen/xml/.

Source file: XmlParser.java

  31 
vote

/** 
 * Tries to open the specified xml file and return an instance of the specified class using JAXB.
 * @param resource the xml file name
 * @param clazz The type of jaxb node to return
 * @param schemaName The schema to validate against (can be {@code null});
 * @return The top level jaxb instance contained in the xml file or {@code null} in case the file could not be foundor could not be unmarshalled.
 */
private <T>T parseXml(String resource,Class<T> clazz,String schemaName){
  InputStream stream=getInputStreamForResource(resource);
  if (stream == null) {
    context.logMessage(Diagnostic.Kind.OTHER,resource + " not found.");
    return null;
  }
  try {
    JAXBContext jc=JAXBContext.newInstance(ObjectFactory.class);
    Unmarshaller unmarshaller=jc.createUnmarshaller();
    if (schemaName != null) {
      unmarshaller.setSchema(getSchema(schemaName));
    }
    return clazz.cast(unmarshaller.unmarshal(stream));
  }
 catch (  JAXBException e) {
    String message="Error unmarshalling " + resource + " with exception :\n "+ e;
    context.logMessage(Diagnostic.Kind.WARNING,message);
    return null;
  }
catch (  Exception e) {
    String message="Error reading " + resource + " with exception :\n "+ e;
    context.logMessage(Diagnostic.Kind.WARNING,message);
    return null;
  }
}
 

Example 48

From project interoperability-framework, under directory /toolwrapper/src/test/java/eu/impact_project/iif/tw/gen/.

Source file: ToolspecValidatorTest.java

  31 
vote

private ToolspecValidator getToolspecValidator(String toospecXml) throws GeneratorException {
  ToolspecValidator tv;
  try {
    Configuration ioc=new Configuration();
    ioc.setXmlConf(new File(Constants.DEFAULT_TOOLSPEC));
    ioc.setProjConf(new File(Constants.DEFAULT_PROJECT_PROPERTIES));
    JAXBContext context;
    context=JAXBContext.newInstance("eu.impact_project.iif.tw.toolspec");
    Unmarshaller unmarshaller=context.createUnmarshaller();
    Toolspec toolspec=(Toolspec)unmarshaller.unmarshal(new File(ioc.getXmlConf()));
    tv=new ToolspecValidator(toolspec,ioc);
    return tv;
  }
 catch (  JAXBException ex) {
    logger.error("JAXBException",ex);
    throw new GeneratorException("JAXBException occurred.");
  }
}
 

Example 49

From project JasigWidgetPortlets, under directory /src/main/java/org/jasig/portlet/widget/service/.

Source file: GoogleGadgetService.java

  31 
vote

public Module getModule(String url){
  Module module=null;
  try {
    InputStream stream=getStreamFromUrl(url);
    JAXBContext jc=JAXBContext.newInstance(Module.class);
    Unmarshaller unmarshaller=jc.createUnmarshaller();
    module=(Module)unmarshaller.unmarshal(stream);
  }
 catch (  JAXBException e) {
    log.error(e);
  }
catch (  ClientProtocolException e) {
    log.error(e);
  }
catch (  IOException e) {
    log.error(e);
  }
  return module;
}
 

Example 50

From project jobcreator-tool, under directory /src/main/java/dk/hlyh/hudson/tools/jobcreator/input/xml/.

Source file: XmlLoader.java

  31 
vote

dk.hlyh.hudson.tools.jobcreator.input.xml.model.Pipeline loadXml(){
  File inputFile=arguments.getInput();
  if (inputFile == null || !inputFile.exists()) {
    throw new ImportException("Pipline file '" + inputFile + "' cannot be found");
  }
  try {
    JAXBContext context=JAXBContext.newInstance(ROOT_NODE);
    Unmarshaller unmarshaller=context.createUnmarshaller();
    Schema schema=loadSchema();
    unmarshaller.setSchema(schema);
    dk.hlyh.hudson.tools.jobcreator.input.xml.model.Pipeline pipeline=(dk.hlyh.hudson.tools.jobcreator.input.xml.model.Pipeline)unmarshaller.unmarshal(new FileInputStream(inputFile));
    LogFacade.info("Successfully loaded pipline from {0}",inputFile);
    return pipeline;
  }
 catch (  FileNotFoundException ex) {
    throw new ImportException("Could not find pipeline file: " + inputFile);
  }
catch (  UnmarshalException ex) {
    if (ex.getCause() instanceof org.xml.sax.SAXParseException) {
      SAXParseException pe=(SAXParseException)ex.getCause();
      LogFacade.severe("Failed to validate the pipeline definition against the schema: \"{0}\"  at line {1}, column={2}",pe.getMessage(),pe.getLineNumber(),pe.getColumnNumber());
    }
 else {
      LogFacade.severe(ex);
    }
    throw new ImportException("Failed to validate the pipeline definition against the schema" + ex);
  }
catch (  JAXBException ex) {
    throw new ImportException("Failed to configure JAXB",ex);
  }
}
 

Example 51

From project jOOX, under directory /jOOX/src/main/java/org/joox/.

Source file: JOOX.java

  31 
vote

/** 
 * Get a constant content that returns a marshalled, JAXB-annotated <code>value</code> for all elements.
 * @see #$(Object)
 * @see Match#content(Object)
 */
public static Content content(final Object value){
  if (value == null) {
    return content("");
  }
  return new Content(){
    private String marshalled;
    @Override public String content(    Context context){
      if (marshalled == null) {
        try {
          JAXBContext jaxb=JAXBContext.newInstance(value.getClass());
          Marshaller marshaller=jaxb.createMarshaller();
          marshaller.setProperty("jaxb.fragment",true);
          StringWriter writer=new StringWriter();
          marshaller.marshal(value,writer);
          marshalled=writer.toString();
        }
 catch (        JAXBException e) {
          throw new DataBindingException(e);
        }
      }
      return marshalled;
    }
  }
;
}
 

Example 52

From project JRebirth, under directory /org.jrebirth/presentation/src/main/java/org/jrebirth/presentation/service/.

Source file: PresentationService.java

  31 
vote

/** 
 * {@inheritDoc}
 */
@Override public void ready() throws CoreException {
  super.ready();
  try {
    final JAXBContext jaxbContext=JAXBContext.newInstance("org.jrebirth.presentation.model");
    final Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
    final InputStreamReader in=new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIG_NAME + ".xml"),Charset.forName("UTF-8"));
    final XMLStreamReader xsr=XMLInputFactory.newInstance().createXMLStreamReader(in);
    this.presentation=Presentation.class.cast(JAXBElement.class.cast(unmarshaller.unmarshal(xsr)).getValue());
  }
 catch (  final JAXBException|XMLStreamException|FactoryConfigurationError e) {
    System.err.println("Impossible to open " + CONFIG_NAME + ".xml");
    e.printStackTrace();
    throw new CoreException("Xml file incorrectly parsed !",e);
  }
}
 

Example 53

From project JSocksProxy, under directory /src/main/java/nu/najt/kecon/jsocksproxy/admin/.

Source file: JSocksProxyAdmin.java

  31 
vote

/** 
 * Load configuration from file
 * @param file the file
 */
public boolean loadConfiguration(final File file){
  if (file == null) {
    return false;
  }
  try {
    final JAXBContext context=JAXBContext.newInstance(Configuration.class);
    final Unmarshaller unmarshaller=context.createUnmarshaller();
    this.configuration=(Configuration)unmarshaller.unmarshal(file);
    this.outgoingAddressTextField.setText(this.configuration.getOutgoingAddresses().get(0));
    this.backlogTextField.setText(Integer.toString(this.configuration.getBacklog()));
    this.allowSocks4Checkbox.setSelected(this.configuration.isAllowSocks4());
    this.allowSocks5Checkbox.setSelected(this.configuration.isAllowSocks5());
  }
 catch (  final JAXBException e) {
    return false;
  }
  this.reloadListenBox();
  return true;
}
 

Example 54

From project Kayak, under directory /Kayak-kcd/src/test/java/com/github/kayak/canio/kcd/.

Source file: NetworkDefinitionTest.java

  31 
vote

/** 
 * @throws java.lang.Exception Methods with the annotation 'Before' are executed before every test. The test object should be brought to the initial state all tests assume it to be in.
 */
@Before public void setUp() throws Exception {
  JAXBContext context=null;
  try {
    context=JAXBContext.newInstance(new Class[]{com.github.kayak.canio.kcd.NetworkDefinition.class});
    assertNotNull("Failed to create context",context);
    Unmarshaller umarshall=context.createUnmarshaller();
    assertNotNull("Failed to create unmarshaller",umarshall);
    object=umarshall.unmarshal(file);
    assertNotNull("Failed to unmarshall file",object);
    marshall=context.createMarshaller();
    assertNotNull("Failed to create marshaller",marshall);
  }
 catch (  JAXBException e) {
    e.printStackTrace();
  }
  assertTrue("Expected unmarshalled object is of type NetworkDefinition(" + object.getClass() + "."+ NetworkDefinition.class+ ")",(object.getClass() == NetworkDefinition.class));
  if (object.getClass() == NetworkDefinition.class) {
    netdef=(NetworkDefinition)object;
  }
}
 

Example 55

From project l2jserver2, under directory /l2jserver2-gameserver/l2jserver2-gameserver-core/src/main/java/com/l2jserver/service/game/scripting/.

Source file: ScriptingServiceImpl.java

  31 
vote

/** 
 * Loads script contexes from descriptor
 * @param scriptDescriptor xml file that describes contexes
 * @throws Exception if can't load file
 */
@Override public synchronized List<ScriptContext> load(File scriptDescriptor) throws Exception {
  Preconditions.checkNotNull(scriptDescriptor,"scriptDescriptor");
  final JAXBContext c=JAXBContext.newInstance(ScriptInfo.class,ScriptList.class);
  final Unmarshaller u=c.createUnmarshaller();
  final ScriptList list=(ScriptList)u.unmarshal(scriptDescriptor);
  final List<ScriptContext> contexts=CollectionFactory.newList();
  for (  ScriptInfo si : list.getScriptInfos()) {
    final ScriptContext context=createContext(si,null);
    if (context != null) {
      this.contexts.add(context);
      context.init();
      contexts.add(context);
    }
  }
  return contexts;
}
 

Example 56

From project astyanax, under directory /src/main/java/com/netflix/astyanax/serializers/.

Source file: JaxbSerializer.java

  29 
vote

/** 
 * Constructor.
 * @param serializableClasses List of classes which can be serialized by this instance. Note that concrete classes directly referenced by any class in the list will also be serializable through this instance.
 */
public JaxbSerializer(final Class... serializableClasses){
  marshaller=new ThreadLocal<Marshaller>(){
    @Override protected Marshaller initialValue(){
      try {
        return JAXBContext.newInstance(serializableClasses).createMarshaller();
      }
 catch (      JAXBException e) {
        throw new IllegalArgumentException("Classes to serialize are not JAXB compatible.",e);
      }
    }
  }
;
  unmarshaller=new ThreadLocal<Unmarshaller>(){
    @Override protected Unmarshaller initialValue(){
      try {
        return JAXBContext.newInstance(serializableClasses).createUnmarshaller();
      }
 catch (      JAXBException e) {
        throw new IllegalArgumentException("Classes to serialize are not JAXB compatible.",e);
      }
    }
  }
;
}
 

Example 57

From project com.cedarsoft.serialization, under directory /test/performance/src/test/java/com/cedarsoft/serialization/test/performance/.

Source file: XmlParserPerformance.java

  29 
vote

public void benchJAXB(){
  runBenchmark(new Runnable(){
    @Override public void run(){
      try {
        Unmarshaller unmarshaller=JAXBContext.newInstance(com.cedarsoft.serialization.test.performance.jaxb.FileType.class).createUnmarshaller();
        for (int i=0; i < MEDIUM; i++) {
          assertNotNull(unmarshaller.unmarshal(new StringReader(CONTENT_SAMPLE_JAXB)));
        }
      }
 catch (      Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
,4);
}
 

Example 58

From project commons-j, under directory /src/main/java/nerds/antelax/commons/xml/saxbp/.

Source file: ParseInterest.java

  29 
vote

private ParseInterest(final QName qName,final JAXBContext jaxbContext,final Class<?> jaxbClass,final Object handler,final Method handlerMethod) throws JAXBException {
  Preconditions.checkNotNull(qName,"QName cannot be null");
  Preconditions.checkNotNull(handler,"Handler cannot be null");
  Preconditions.checkNotNull(handlerMethod,"Handler method cannot be null");
  this.qName=qName;
  if (jaxbClass != null) {
    Preconditions.checkNotNull(jaxbContext,"JAXBContext cannot be null when using @JAXBHandler annotated methods");
    jaxbUnmarshaller=jaxbContext.createUnmarshaller();
  }
 else {
    jaxbUnmarshaller=null;
  }
  this.jaxbClass=jaxbClass;
  this.handler=handler;
  this.handlerMethod=handlerMethod;
}
 

Example 59

From project components, under directory /camel/camel-core/src/main/java/org/switchyard/component/camel/config/model/v1/.

Source file: V1CamelImplementationModel.java

  29 
vote

private static JAXBContext createJAXBInstance(){
  try {
    return JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
  }
 catch (  JAXBException e) {
    throw new SwitchYardException(e);
  }
}
 

Example 60

From project core_1, under directory /transform/src/main/java/org/switchyard/transform/jaxb/internal/.

Source file: JAXBMarshalTransformer.java

  29 
vote

/** 
 * Public constructor.
 * @param from From type.
 * @param to To type.
 * @param contextPath JAXB context path (Java package).
 * @throws SwitchYardException Failed to create JAXBContext.
 */
public JAXBMarshalTransformer(QName from,QName to,String contextPath) throws SwitchYardException {
  super(from,to);
  try {
    if (contextPath != null) {
      _jaxbContext=JAXBContext.newInstance(contextPath);
    }
 else {
      _jaxbContext=JAXBContext.newInstance(QNameUtil.toJavaMessageType(from));
    }
  }
 catch (  JAXBException e) {
    throw new SwitchYardException("Failed to create JAXBContext for '" + from + "'.",e);
  }
}
 

Example 61

From project gedcomx, under directory /enunciate-gedcomx-support/src/main/java/org/gedcomx/build/enunciate/rdf/.

Source file: RDFProcessor.java

  29 
vote

protected void loadKnownRDFSchemaDescriptions(){
  Unmarshaller unmarshaller;
  try {
    unmarshaller=JAXBContext.newInstance(RDFSchema.class).createUnmarshaller();
  }
 catch (  JAXBException e) {
    throw new RuntimeException(e);
  }
  URL resource=RDFProcessor.class.getResource("dcterms.rdf.xml");
  if (resource != null) {
    loadRDFSchema(unmarshaller,resource);
  }
  addDescription(RDFSchema.RDF_NAMESPACE,"ID",true,true);
  addDescription(RDFSchema.RDF_NAMESPACE,"about",true,true);
  addDescription(RDFSchema.RDF_NAMESPACE,"resource",true,true);
  addDescription(RDFSchema.RDF_NAMESPACE,"value",true,true);
  addDescription(RDFSchema.RDF_NAMESPACE,"type",true,false);
  addDescription(RDFSchema.RDF_NAMESPACE,"Description",true,false);
  addDescription(XMLConstants.XML_NS_URI,"lang",true,true);
}
 

Example 62

From project geolatte-maprenderer, under directory /src/main/java/org/geolatte/maprenderer/sld/.

Source file: SLD.java

  29 
vote

private SLD(){
  try {
    ctxt=JAXBContext.newInstance("net.opengis.sld.v_1_1_0:net.opengis.wms.v_1_3_0");
    objectFactory=new ObjectFactory();
  }
 catch (  JAXBException e) {
    throw new IllegalStateException("Can't instantiate SLD static factory",e);
  }
}
 

Example 63

From project geolatte-mapserver, under directory /src/main/java/org/geolatte/mapserver/wms/.

Source file: JAXB.java

  29 
vote

private JAXB(){
  try {
    ctxt=JAXBContext.newInstance("net.opengis.wms.v_1_1_1");
    objectFactory=new ObjectFactory();
  }
 catch (  JAXBException e) {
    throw new IllegalStateException("Can't instantiate JAXB static factory",e);
  }
}
 

Example 64

From project GNDMS, under directory /model/src/de/zib/gndms/c3resource/.

Source file: C3ResourceReader.java

  29 
vote

public C3ResourceReader(){
  try {
    context=JAXBContext.newInstance("de.zib.gndms.c3resource.jaxb");
    evFactory=XMLEventFactory.newInstance();
    inFactory=XMLInputFactory.newInstance();
    outFactory=XMLOutputFactory.newInstance();
    unmarshaller=context.createUnmarshaller();
    unmarshaller.setSchema(null);
  }
 catch (  JAXBException jxe) {
    throw new RuntimeException("Failed to initialize C3ResourceReader",jxe);
  }
}
 

Example 65

From project GoFleetLSServer, under directory /src/main/java/org/gofleet/openLS/ddbb/dao/.

Source file: RoutingDAO.java

  29 
vote

/** 
 */
public RoutingDAO(){
  try {
    unmarshaller=JAXBContext.newInstance(LineStringType.class).createUnmarshaller();
    context=JAXBContext.newInstance("org.jvnet.ogc.gml.v_3_1_1.jts");
    marshaller=context.createMarshaller();
  }
 catch (  JAXBException e) {
    LOG.error(e,e);
  }
}
 

Example 66

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/xml/.

Source file: XMLDatabaseClusterConfigurationFactory.java

  29 
vote

/** 
 * {@inheritDoc}
 * @see net.sf.hajdbc.DatabaseClusterConfigurationFactory#createConfiguration()
 */
@Override public DatabaseClusterConfiguration<Z,D> createConfiguration() throws SQLException {
  logger.log(Level.INFO,Messages.HA_JDBC_INIT.getMessage(),Version.getVersion(),this.streamFactory);
  try {
    SchemaFactory schemaFactory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema=schemaFactory.newSchema(SCHEMA);
    Unmarshaller unmarshaller=JAXBContext.newInstance(this.targetClass).createUnmarshaller();
    unmarshaller.setSchema(schema);
    XMLReader reader=new PropertyReplacementFilter(XMLReaderFactory.createXMLReader());
    InputSource source=SAXSource.sourceToInputSource(this.streamFactory.createSource());
    return this.targetClass.cast(unmarshaller.unmarshal(new SAXSource(reader,source)));
  }
 catch (  JAXBException e) {
    throw new SQLException(e);
  }
catch (  SAXException e) {
    throw new SQLException(e);
  }
}
 

Example 67

From project harmony, under directory /harmony.common.serviceinterface/src/main/java/org/opennaas/extensions/idb/serviceinterface/databinding/utils/.

Source file: JaxbSerializer.java

  29 
vote

/** 
 * Method to create the JaxbContext.
 * @return new JaxbContext
 */
private final JAXBContext createContext(){
  try {
    return JAXBContext.newInstance(Config.getString("databinding","jaxb.path"));
  }
 catch (  final JAXBException e) {
    throw new RuntimeException("Cannot create JAXB context",e);
  }
}
 

Example 68

From project HMS, under directory /common/src/main/java/org/apache/hms/common/entity/action/.

Source file: ActionContextProvider.java

  29 
vote

public JAXBContext getContext(Class<?> objectType){
  for (  Class type : types) {
    if (type.equals(objectType))     return context;
  }
  return null;
}
 

Example 69

From project java-maven-tests, under directory /src/jersey-sample/src/main/java/com/truward/web/jerseysample/rest/exposure/.

Source file: HelloJAXBContextResolver.java

  29 
vote

/** 
 * {@inheritDoc}
 */
public JAXBContext getContext(Class<?> type){
  boolean supported=false;
  for (  final Class<?> supportedClass : SUPPORTED_CLASSES) {
    if (type.equals(supportedClass)) {
      supported=true;
      break;
    }
  }
  if (!supported) {
    return null;
  }
  if (context == null) {
    try {
      context=new JSONJAXBContext(JSONConfiguration.natural().build(),SUPPORTED_CLASSES);
    }
 catch (    JAXBException e) {
      throw new UnsupportedOperationException("Can't create JAXB context for supported classes",e);
    }
  }
  return context;
}
 

Example 70

From project JavaEe6WebApp, under directory /src/main/java/uk/me/doitto/webapp/dao/.

Source file: AbstractEntity.java

  29 
vote

protected static JAXBContext initJaxbContext(final Class<? extends AbstractEntity> clazz){
  try {
    return JAXBContext.newInstance(clazz);
  }
 catch (  JAXBException e) {
    throw new RuntimeException(e);
  }
}
 

Example 71

From project jetty-project, under directory /jetty-jmx-ws/src/main/java/org/mortbay/jetty/jmx/ws/web/.

Source file: JAXBContextResolver.java

  29 
vote

public JAXBContext getContext(Class<?> objectType){
  for (  Class<?> type : types) {
    if (type == objectType) {
      return context;
    }
  }
  return null;
}
 

Example 72

From project karaf, under directory /region/persist/src/main/java/org/apache/karaf/region/persist/internal/.

Source file: RegionsPersistenceImpl.java

  29 
vote

public RegionsPersistenceImpl(RegionDigraph regionDigraph,Bundle framework) throws JAXBException, BundleException, IOException, InvalidSyntaxException {
  log.info("Loading region digraph persistence");
  this.framework=framework;
  this.regionDigraph=regionDigraph;
  kernel=regionDigraph.getRegion(0);
  jaxbContext=JAXBContext.newInstance(RegionsType.class);
  load();
}
 

Example 73

From project leviathan, under directory /scrapper/src/main/java/com/zaubersoftware/leviathan/api/engine/impl/pipe/.

Source file: ToJavaObjectPipe.java

  29 
vote

/** 
 * Creates the ToJavaObjectPipe  
 */
public ToJavaObjectPipe(final Class<T> classToBeBounded){
  Validate.notNull(classToBeBounded);
  try {
    newInstance=JAXBContext.newInstance(classToBeBounded);
  }
 catch (  final JAXBException e) {
    throw new UnhandledException(e);
  }
}