当前位置: 首页>>代码示例>>Java>>正文


Java JAXBContext.newInstance方法代码示例

本文整理汇总了Java中javax.xml.bind.JAXBContext.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java JAXBContext.newInstance方法的具体用法?Java JAXBContext.newInstance怎么用?Java JAXBContext.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.bind.JAXBContext的用法示例。


在下文中一共展示了JAXBContext.newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendAlert

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@Override
public void sendAlert(Observable observable) {
	if (observable instanceof AbstarctMower) {
		try {
			AbstarctMower mower = (AbstarctMower) observable;
			SettingInterface settingLoader = SettingLoaderFactory.getSettingLoader(DEFAULT);
			StringBuilder br = new StringBuilder(settingLoader.getSerFolder());
			br.append(BACKSLASH).append(settingLoader.getReportingFolder()).append(BACKSLASH)
					.append(mower.getIdentifier()).append(new Date().getTime()).append(XML_EXTENTION);
			File file = new File(br.toString());
			JAXBContext jaxbContext = JAXBContext.newInstance(AbstarctMower.class);
			Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
			jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
			jaxbMarshaller.marshal(mower, file);
		} catch (Exception e) {
			throw new MowerException(e);
		}
	}
}
 
开发者ID:camy2408,项目名称:automatic-mower,代码行数:20,代码来源:MowerStatusChangedXMLReport.java

示例2: createHydrographDebugInfo

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
/**
 * Creates the object of type {@link HydrographDebugInfo} from the graph xml of type
 * {@link Document}.
 * <p>
 * The method uses jaxb framework to unmarshall the xml document
 *
 * @param graphDocument the xml document with all the graph contents to unmarshall
 * @return an object of type {@link HydrographDebugInfo}
 * @throws SAXException
 */
public static HydrographDebugInfo createHydrographDebugInfo(Document graphDocument, String debugXSDLocation) throws SAXException {
    try {
        LOG.trace("Creating DebugJAXB object.");
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(ClassLoader.getSystemResource(debugXSDLocation));
        JAXBContext context = JAXBContext.newInstance(Debug.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        unmarshaller.setSchema(schema);
        unmarshaller.setEventHandler(new ComponentValidationEventHandler());
        Debug debug = (Debug) unmarshaller.unmarshal(graphDocument);
        HydrographDebugInfo hydrographDebugInfo = new HydrographDebugInfo(debug);
        LOG.trace("DebugJAXB object created successfully");
        return hydrographDebugInfo;
    } catch (JAXBException e) {
        LOG.error("Error while creating JAXB objects from debug XML.", e);
        throw new RuntimeException("Error while creating JAXB objects from debug XML.", e);
    }
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:29,代码来源:DebugUtils.java

示例3: getOauthMetadata

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public Metadata getOauthMetadata() throws IOException, JAXBException {
    if (wadlModel == null) {
        throw new IllegalStateException("Should transition state to at least RETRIEVED");
    }
    if (wadlModel.getGrammars() == null || wadlModel.getGrammars().getAny() == null) {
        return null;
    }
    List<Object> otherGrammars = wadlModel.getGrammars().getAny();
    for (Object g : otherGrammars) {
        if (g instanceof Element) {
            Element el = (Element)g;
            if ("http://netbeans.org/ns/oauth/metadata/1".equals(el.getNamespaceURI()) && //NOI18N
                    "metadata".equals(el.getLocalName())) { //NOI18N
                JAXBContext jc = JAXBContext.newInstance("org.netbeans.modules.websvc.saas.model.oauth"); //NOI18N
                Unmarshaller u = jc.createUnmarshaller();
                JAXBElement<Metadata> jaxbEl = u.unmarshal(el, Metadata.class);
                return jaxbEl.getValue();
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:WadlSaas.java

示例4: setUp

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@Before
public void setUp() throws JAXBException {
    start = new ModifiableBigInteger();
    start.setOriginalValue(BigInteger.TEN);
    expectedResult = null;
    result = null;

    writer = new StringWriter();
    context = JAXBContext.newInstance(ModifiableBigInteger.class, BigIntegerAddModification.class,
            ByteArrayModificationFactory.class, BigIntegerInteractiveModification.class);
    m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    um = context.createUnmarshaller();

    BigIntegerModificationFactory
            .setStandardInteractiveModification(new BigIntegerInteractiveModification.InteractiveBigIntegerModification() {
                public BigInteger modify(BigInteger oldVal) {
                    return new BigInteger("12");
                }
            });
}
 
开发者ID:RUB-NDS,项目名称:ModifiableVariable,代码行数:22,代码来源:BigIntegerSerializationTest.java

示例5: testCustomFilter

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@Test
public void testCustomFilter() throws IOException, JAXBException {
  StringBuilder builder = new StringBuilder();
  builder = new StringBuilder();
  builder.append("/a*");
  builder.append("?");
  builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
  builder.append("&");
  builder.append(Constants.SCAN_FILTER + "=" + URLEncoder.encode("CustomFilter('abc')", "UTF-8"));
  Response response =
      client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
  assertEquals(200, response.getCode());
  JAXBContext ctx = JAXBContext.newInstance(CellSetModel.class);
  Unmarshaller ush = ctx.createUnmarshaller();
  CellSetModel model = (CellSetModel) ush.unmarshal(response.getStream());
  int count = TestScannerResource.countCellSet(model);
  assertEquals(1, count);
  assertEquals("abc", new String(model.getRows().get(0).getCells().get(0).getValue()));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:TestTableScan.java

示例6: loadFromXml

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public void loadFromXml(File file) throws JAXBException, SteamApiException
{
    if(file != null)
    {
            JAXBContext context = JAXBContext.newInstance(this.getClass());
            Unmarshaller um;
            um = context.createUnmarshaller();
            Preferences prefs = Preferences.userNodeForPackage(com.matthieu42.steamtradertools.controller.AppController.class);
            prefs.put(PreferencesKeys.SAVE_PATH.toString(),file.getAbsolutePath());
            UserAppList loadedList = (UserAppList) um.unmarshal(file);
            this.setAppList(loadedList.getAppList());
            this.nbTotalKey = loadedList.nbTotalKey;


    }
}
 
开发者ID:Matthieu42,项目名称:Steam-trader-tools,代码行数:17,代码来源:UserAppList.java

示例7: doImportFromXmlNode

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
/**
 * Imports a {@link StvsRootModel} from {@code source}.
 *
 * @param source Node to import
 * @return imported model
 * @throws ImportException Exception while importing.
 */
@Override
public StvsRootModel doImportFromXmlNode(Node source) throws ImportException {
  try {
    JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    Session importedSession =
        ((JAXBElement<Session>) jaxbUnmarshaller.unmarshal(source)).getValue();

    // Code
    Code code = new Code();
    code.updateSourcecode(importedSession.getCode().getPlaintext());
    VerificationScenario scenario = new VerificationScenario(code);

    List<Type> typeContext = Optional.ofNullable(code.getParsedCode())
        .map(ParsedCode::getDefinedTypes).orElse(Arrays.asList(TypeInt.INT, TypeBool.BOOL));

    // Tabs
    List<HybridSpecification> hybridSpecs = importTabs(importedSession, typeContext);

    return new StvsRootModel(hybridSpecs, currentConfig, currentHistory, scenario,
        new File(System.getProperty("user.home")), "");
  } catch (JAXBException e) {
    throw new ImportException(e);
  }
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:33,代码来源:XmlSessionImporter.java

示例8: loadExamFromFile

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public static Exam loadExamFromFile(File file){
	Exam ex = new Exam("","");
	try {
		JAXBContext context = JAXBContext.newInstance(Exam.class);
		Unmarshaller um = context.createUnmarshaller();
		Exam exam = (Exam) um.unmarshal(file);
		ex = exam;
	}catch (Exception e){
		e.printStackTrace();
	}
	return ex;
}
 
开发者ID:eacp,项目名称:Luna-Exam-Builder,代码行数:13,代码来源:Data.java

示例9: setUpBeforeClass

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  SUPERUSER = User.createUserForTesting(conf, "admin",
      new String[] { "supergroup" });
  conf = TEST_UTIL.getConfiguration();
  conf.setClass(VisibilityUtils.VISIBILITY_LABEL_GENERATOR_CLASS,
      SimpleScanLabelGenerator.class, ScanLabelGenerator.class);
  conf.setInt("hfile.format.version", 3);
  conf.set("hbase.superuser", SUPERUSER.getShortName());
  conf.set("hbase.coprocessor.master.classes", VisibilityController.class.getName());
  conf.set("hbase.coprocessor.region.classes", VisibilityController.class.getName());
  TEST_UTIL.startMiniCluster(1);
  // Wait for the labels table to become available
  TEST_UTIL.waitTableEnabled(VisibilityConstants.LABELS_TABLE_NAME.getName(), 50000);
  createLabels();
  setAuths();
  REST_TEST_UTIL.startServletContainer(conf);
  client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
  context = JAXBContext.newInstance(CellModel.class, CellSetModel.class, RowModel.class,
      ScannerModel.class);
  marshaller = context.createMarshaller();
  unmarshaller = context.createUnmarshaller();
  Admin admin = TEST_UTIL.getHBaseAdmin();
  if (admin.tableExists(TABLE)) {
    return;
  }
  HTableDescriptor htd = new HTableDescriptor(TABLE);
  htd.addFamily(new HColumnDescriptor(CFA));
  htd.addFamily(new HColumnDescriptor(CFB));
  admin.createTable(htd);
  insertData(TABLE, COLUMN_1, 1.0);
  insertData(TABLE, COLUMN_2, 0.5);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:34,代码来源:TestScannersWithLabels.java

示例10: save

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public String save(String fileName) {
  if (fileName == null || fileName.isEmpty()) {
    return null;
  }

  String fileNameWithExtension = fileName;
  if (!fileNameWithExtension.endsWith("." + FILE_EXTENSION)) {
    fileNameWithExtension += "." + FILE_EXTENSION;
  }

  File newFile = new File(fileNameWithExtension);

  try (FileOutputStream fileOut = new FileOutputStream(newFile)) {
    JAXBContext jaxbContext = JAXBContext.newInstance(Map.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);

    final ByteArrayOutputStream out = new ByteArrayOutputStream();

    // first: marshal to byte array
    jaxbMarshaller.marshal(this, out);
    out.flush();

    // second: postprocess xml and then write it to the file
    XmlUtilities.saveWithCustomIndetation(new ByteArrayInputStream(out.toByteArray()), fileOut, 1);
    out.close();

    jaxbMarshaller.marshal(this, out);
  } catch (JAXBException | IOException e) {
    log.log(Level.SEVERE, e.getMessage(), e);
  }

  return newFile.toString();
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:35,代码来源:Map.java

示例11: serialize

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
private String serialize(Object jaxbTree) throws JAXBException,
        PropertyException {
    JAXBContext jc = JAXBContext.newInstance(jaxbTree.getClass());
    System.out.println(jc.getClass().getCanonicalName());
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    marshaller.marshal(jaxbTree, bos);
    String xmlAsString = Strings.toString(bos.toByteArray());
    return xmlAsString;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:13,代码来源:MpOwnerShareResultAssemblerTest.java

示例12: parseXml

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public Optional<Entries> parseXml(Path path) {
  try {
    JAXBContext context = JAXBContext.newInstance(Entries.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    return Optional.of((Entries) unmarshaller.unmarshal(path.toFile()));
  } catch (JAXBException e) {
    log.error("Error parsing the XML file", e);
  }
  return Optional.empty();
}
 
开发者ID:durimkryeziu,项目名称:family-tree-xml-parser,代码行数:11,代码来源:EntriesXmlParser.java

示例13: getLibraryTypes

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
private HashMap<String, Library> getLibraryTypes() throws IOException, JAXBException {
	HashMap<String, Library> ret = new HashMap<String, Library>();
	ArrayList<String> types = util.getResourcesWithExtension("types", containerName);
	for (String type : types) {
		File file = new File(type);
		String content = FileUtils.readFileToString(file);
		JAXBContext ctx = JAXBContext.newInstance(Library.class);
		Library lib = (Library) ctx.createUnmarshaller().unmarshal(new StringReader(content));
		ret.put(LibraryUtil.getLibraryNameFromFile(file.getName()), lib);
	}
	return ret;
}
 
开发者ID:dstl,项目名称:Open_Source_ECOA_Toolset_AS5,代码行数:13,代码来源:TypesUtil.java

示例14: loadConfig

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
private void loadConfig(ServletContext servletContext) {
    try {
        final JAXBContext context = JAXBContext
                .newInstance(RoleBasedFilterConfig.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        StreamSource source = new StreamSource(
                servletContext.getResourceAsStream(CONFIG_FILE_LOCATION));
        config = unmarshaller.unmarshal(source, RoleBasedFilterConfig.class)
                .getValue();
    } catch (JAXBException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:14,代码来源:RoleBasedFilter.java

示例15: readCollection

import javax.xml.bind.JAXBContext; //导入方法依赖的package包/类
public Collection readCollection() throws JAXBException {
    File file = targetFile();
    JAXBContext jaxbContext = JAXBContext.newInstance(Collection.class);

    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    return (Collection) jaxbUnmarshaller.unmarshal(file);
}
 
开发者ID:AntonioGabrielAndrade,项目名称:LIRE-Lab,代码行数:8,代码来源:CollectionXMLDAO.java


注:本文中的javax.xml.bind.JAXBContext.newInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。