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


Java NamespacePrefixMapper类代码示例

本文整理汇总了Java中com.sun.xml.bind.marshaller.NamespacePrefixMapper的典型用法代码示例。如果您正苦于以下问题:Java NamespacePrefixMapper类的具体用法?Java NamespacePrefixMapper怎么用?Java NamespacePrefixMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: save

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
/**
 * Marshall the object to disk...
 * 
 * @param obj
 */
private void save(Object obj) {
	if(myResource == null)
		return;
	
	try {
		Marshaller marshaller = getJAXBContext().createMarshaller();
		NamespacePrefixMapper nspm = getNamespacePrefixMapper();

		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
		if (nspm != null)
			marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", nspm);
		
		marshaller.marshal(obj, getCacheFile());
	} catch (JAXBException e) {
		log.error("Couldn't save cache for "
				+ myResource.getResourceName() + ": " + e.getMessage());
	}
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:24,代码来源:ResourceCacher.java

示例2: JAXBWriter

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public JAXBWriter(NamespacePrefixMapper mapper) {
	super();
	this.mapper = mapper;
	try {
		List<Class<?>> clazz = new ArrayList<Class<?>>();
		for (Class<?> each : ScanUtil.getClasses(this.protocol)) {
			if (each.getAnnotation(XmlRootElement.class) != null) {
				clazz.add(each);
			}
		}
		this.context = JAXBContext.newInstance(clazz.toArray(new Class[] {}));
		this.log.info("All classes in JAXB Context: " + clazz);
	} catch (Exception e) {
		this.log.error(e.toString());
		Trace.trace(this.log, e);
		throw new RuntimeException("Can't init JAXB context", e);
	}
}
 
开发者ID:KimShen,项目名称:sissi,代码行数:19,代码来源:JAXBWriter.java

示例3: setProperty

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) && value instanceof String ) {
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) ) {
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        printXmlDeclaration = ((Boolean)value).booleanValue();
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        header = (String)value;
        return;
    }
        
    super.setProperty(name, value);
}
 
开发者ID:nhrdl,项目名称:javacash,代码行数:25,代码来源:MarshallerImpl.java

示例4: XbelMarshaller

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public XbelMarshaller(String nn) {
	Preconditions.checkArgument(!Strings.isNullOrEmpty(nn),
			"A export file name is required");
	this.exportedFilename = nn;

	try {
		
		this.context = JAXBContext.newInstance(Document.class);
		this.marshaller = context.createMarshaller();
           this.marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //NOI18N
		this.marshaller.setProperty(Marshaller.JAXB_FRAGMENT,
				Boolean.TRUE);
		this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
				Boolean.TRUE);
		NamespacePrefixMapper npm = new XbelPrefixMapper();
		this.marshaller.setProperty(
				"com.sun.xml.bind.namespacePrefixMapper", npm);

	} catch (JAXBException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:ndexbio,项目名称:ndex-common,代码行数:24,代码来源:XbelNetworkExporter.java

示例5: marshallToDocument

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
/**
 * Marshall this object to a JDOM Document
 * 
 * @param context
 * @param object
 * @param prefixMapper an implementation of namespacePrefixMapper
 * @return
 * @throws JAXBException
 */
protected static Document marshallToDocument(JAXBContext context,
		Object object, NamespacePrefixMapper prefixMapper)
		throws JAXBException {
	JDOMResult result = new JDOMResult();
	Marshaller m = context.createMarshaller();

	// set a namespace prefix mapper
	if (prefixMapper != null)
		m.setProperty("com.sun.xml.bind.namespacePrefixMapper", prefixMapper);

	m.marshal(object, result);

	return result.getDocument();
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:24,代码来源:WebJaxbAccessor.java

示例6: marshal

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public static void marshal(JAXBContext jc, Object toMarshall, NamespacePrefixMapper mapper) {
    System.out.println("Mapper: " + ((mapper == null) ? " not set. " : (mapper.getClass().getSimpleName())));
    try {
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        if (mapper != null) {
            m.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
        }
        m.marshal(toMarshall, System.out);
        System.out.println("-----------------------");
    } catch(Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:micromata,项目名称:javaapiforkml,代码行数:15,代码来源:JAXBSample.java

示例7: handle

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public String handle(JAXBElement<T> e, NamespacePrefixMapper namespacePrefixMapper) throws JAXBException
{
	if (e == null)
		return null;
	StringWriter result = new StringWriter();
	Marshaller marshaller = context.createMarshaller();
	marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);
	marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",namespacePrefixMapper);
	marshaller.marshal(e,result);
	result.flush();
	return result.toString();
}
 
开发者ID:eluinstra,项目名称:bag-etl,代码行数:13,代码来源:XMLMessageBuilder.java

示例8: MarshallImpl

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
/**
 * Constructor with the package parameter. This is used to set the context
 * of the marshaler.
 *
 * @param packageInstance	package instance of the object to marshal
 * @throws JAXBException
 */
public MarshallImpl(Package packageInstance, boolean formattedOutput)
		throws JAXBException {
	JAXBContext context = JAXBContext.newInstance(packageInstance.getName());
	marshaller = context.createMarshaller();
	marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
			formattedOutput);
	NamespacePrefixMapper m = new PreferredMapper();
	marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", m);
}
 
开发者ID:fdicerbo,项目名称:fiware-ppl,代码行数:17,代码来源:MarshallImpl.java

示例9: SAXMarshaller

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
/**
 * Creates a marshalling context by designating the ContentHandler
 * that receives generated SAX2 events.
 */
public SAXMarshaller( ContentHandler _writer, NamespacePrefixMapper prefixMapper, MarshallerImpl _owner ) {
    this.writer = _writer;
    this.owner = _owner;
    this.nsContext = new NamespaceContextImpl(
        prefixMapper!=null?prefixMapper:defaultNamespacePrefixMapper);
}
 
开发者ID:nhrdl,项目名称:javacash,代码行数:11,代码来源:SAXMarshaller.java

示例10: NamespaceContextImpl

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public NamespaceContextImpl(NamespacePrefixMapper _prefixMapper) {
        this.prefixMapper = _prefixMapper;
        // declare the default namespace binding
        // which are effective because of the way XML1.0 is made
        nss.declarePrefix("","");
        nss.declarePrefix( "xmlns", XMLConstants.XMLNS_ATTRIBUTE_NS_URI );
// this one is taken care of by the NamespaceSupport class by default.
//        nss.declarePrefix( "xml",   XMLConstants.XML_NS_URI );
    }
 
开发者ID:nhrdl,项目名称:javacash,代码行数:10,代码来源:NamespaceContextImpl.java

示例11: getNamespacePrefixMapper

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
protected NamespacePrefixMapper getNamespacePrefixMapper() {
	return null;
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:4,代码来源:ResourceCacher.java

示例12: getNamespacePrefixMapper

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
@Override
protected NamespacePrefixMapper getNamespacePrefixMapper() {
	return new TellervoNamespacePrefixMapper();
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:5,代码来源:TellervoWsiAccessor.java

示例13: getXml

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public StringWriter getXml() throws JAXBException, SAXException,
			ParserConfigurationException, TransformerException {

		final Map<String, Object> properties = new HashMap<String, Object>();

		Class[] classes = { Definitions.class };

		/* Perform XML creation */
		JAXBContext context = JAXBContext.newInstance(classes, properties);
		Marshaller marshaller = context.createMarshaller();
		marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.omg.org/spec/BPMN/20100524/MODEL http://www.omg.org/spec/BPMN/2.0/20100501/BPMN20.xsd");

		NamespacePrefixMapper nsp = new BPMNPrefixMapper();
		((BPMNPrefixMapper) nsp).setNsDefs(bpmnDefinitions.externalNSDefs);
		
		marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", nsp);

		/* Marshal BPMN 2.0 XML */

		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		dbf.setNamespaceAware(true);
		DocumentBuilder db = dbf.newDocumentBuilder();
		Document doc = db.newDocument();
		marshaller.marshal(bpmnDefinitions, doc);
		
		/*
		 * Remove unused namespace prefixes
		 */
		
		for(String prefix : bpmnDefinitions.unusedNamespaceDeclarations) {
			doc.getDocumentElement().removeAttribute("xmlns:" + prefix);
		}
		
		String styleSheet = "<!DOCTYPE stylesheet [  <!ENTITY cr \"<xsl:text></xsl:text>\">]> <xsl:stylesheet    xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"     xmlns:xalan=\"http://xml.apache.org/xslt\"     version=\"1.0\">        <xsl:output method=\"xml\" indent=\"yes\" xalan:indent-amount=\"3\"/>           <!-- copy out the xml -->    <xsl:template match=\"* | @*\">        <xsl:copy><xsl:copy-of select=\"@*\"/><xsl:apply-templates/></xsl:copy>    </xsl:template> </xsl:stylesheet>";
		StreamSource styleStream = new StreamSource(new ByteArrayInputStream(styleSheet.getBytes()));
		DOMSource domSource = new DOMSource(doc);
		StringWriter writer = new StringWriter();
		StreamResult result = new StreamResult(writer);
		TransformerFactory tf = TransformerFactory.newInstance();
//		tf.setAttribute("indent-amount", new Integer(4));
		Transformer transformer = tf.newTransformer(styleStream);
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
		transformer.transform(domSource, result);
		return writer;

	}
 
开发者ID:iotsap,项目名称:FiWare-Template-Handler,代码行数:47,代码来源:Bpmn2XmlConverter.java

示例14: getValidationResults

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public StringBuilder getValidationResults() throws JAXBException,
		SAXException {
	
	final Map<String, Object> properties = new HashMap<String, Object>();

	Class[] classes = { Definitions.class };
	
	JAXBContext context = JAXBContext.newInstance(classes, properties);
	Marshaller marshaller = context.createMarshaller();
	marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

	NamespacePrefixMapper nsp = new BPMNPrefixMapper();
	marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", nsp);

	/* Set Schema validation properties */
	SchemaFactory sf = SchemaFactory
			.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

	Schema schema = sf.newSchema(new File(bpmn20XsdPath));
	marshaller.setSchema(schema);

	ExportValidationEventCollector vec = new ExportValidationEventCollector();
	marshaller.setEventHandler(vec);

	StringWriter writer = new StringWriter();

	/* Marshal BPMN 2.0 XML */
	marshaller.marshal(bpmnDefinitions, writer);

	/* Retrieve validation results */
	ValidationEvent[] events = vec.getEvents();

	StringBuilder builder = new StringBuilder();
	builder.append("Validation Errors: \n\n");

	for (ValidationEvent event : Arrays.asList(events)) {

		builder.append("\nError: ");
		builder.append(event.getMessage());
		builder.append("\n\n\n");
	}

	return builder;
}
 
开发者ID:iotsap,项目名称:FiWare-Template-Handler,代码行数:45,代码来源:Bpmn2XmlConverter.java

示例15: getNamespacePrefixMapper

import com.sun.xml.bind.marshaller.NamespacePrefixMapper; //导入依赖的package包/类
public final NamespacePrefixMapper getNamespacePrefixMapper() {
    return prefixMapper;
}
 
开发者ID:nhrdl,项目名称:javacash,代码行数:4,代码来源:NamespaceContextImpl.java


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