Java Code Examples for org.jibx.runtime.IBindingFactory#createMarshallingContext()

The following examples show how to use org.jibx.runtime.IBindingFactory#createMarshallingContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: M2Model.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void toXML(ModelDefinition.XMLBindingType bindingType, OutputStream xml)
{
    try
    {
    	if(bindingType == null)
    	{
    		bindingType = ModelDefinition.XMLBindingType.DEFAULT;
    	}

    	String bindingName = bindingType.toString();
        IBindingFactory factory = (bindingName != null) ? BindingDirectory.getFactory(bindingName, M2Model.class) :
        	BindingDirectory.getFactory("default", M2Model.class);
        IMarshallingContext context = factory.createMarshallingContext();
        context.setIndent(4);
        context.marshalDocument(this, "UTF-8", null, xml);
    }
    catch(JiBXException e)
    {
        throw new DictionaryException(ERR_CREATE_M2MODEL_FAILURE, e);
    }
}
 
Example 2
Source File: SystemInfo.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create XML representation of System Info
 * 
 * @param xml  xml representation of system info
 */
public void toXML(OutputStream xml)
{
    try
    {
        IBindingFactory factory = BindingDirectory.getFactory(SystemInfo.class);
        IMarshallingContext context = factory.createMarshallingContext();
        context.setIndent(4);
        context.marshalDocument(this, "UTF-8", null, xml);    
    }
    catch(JiBXException e)
    {
        throw new DictionaryException("Failed to create System Info", e);
    }
}
 
Example 3
Source File: JibxTest.java    From journaldev with MIT License 5 votes vote down vote up
public String marshalEmployee(Employee employee){
	try {
		IBindingFactory bfact = BindingDirectory.getFactory(Employee.class);
		IMarshallingContext mctx = bfact.createMarshallingContext();
		mctx.setIndent(2);
		StringWriter stringWriter = new StringWriter();
		mctx.setOutput(stringWriter);
		mctx.marshalDocument(employee, "UTF-8", null);
		String output = stringWriter.toString();
		return output;
	} catch (JiBXException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: MLPResponse.java    From gmlc with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create the svc_result XML result for any type of result (error or success)
 *
 * @param mlpSvcResult  Fully filled in SvcResult object to marshal (convert to XML)
 * @return              String of XML result to send to client
 * @throws org.jibx.runtime.JiBXException JiBX had an internal failure of some kind while marshalling the XML
 * @throws IOException  IO error occurred while generating the XML result
 */
private String marshalMlpResult(org.oma.protocols.mlp.svc_result.SvcResult mlpSvcResult)
    throws org.jibx.runtime.JiBXException, IOException {
  String lXml = null;

  IBindingFactory jc = BindingDirectory.getFactory(org.oma.protocols.mlp.svc_result.SvcResult.class);
  IMarshallingContext marshaller = jc.createMarshallingContext();
  ByteArrayOutputStream lOutputStream = new ByteArrayOutputStream();
  marshaller.setOutput(lOutputStream, "UTF-8");
  IXMLWriter ix = marshaller.getXmlWriter();

  // Add XML and DOCTYPE headers
  ix.writeXMLDecl("1.0", "UTF-8", null);
  ix.writeDocType("svc_result", "MLP_SVC_RESULT_310.DTD", null, null);

  // Set 4 spaces as the default indenting
  marshaller.setIndent(4);

  // Generate the XML
  marshaller.marshalDocument(mlpSvcResult);

  // Convert the stream to a string
  lXml = new String(lOutputStream.toByteArray(), "UTF-8");

  // Return our XML string result
  return lXml;
}
 
Example 5
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Style convert(UserStyleInfo userStyleInfo) throws LayerException {
	IBindingFactory bindingFactory;
	try {
		// create a dummy SLD root
		StyledLayerDescriptorInfo sld = new StyledLayerDescriptorInfo();
		sld.setVersion(SLD_VERSION);
		StyledLayerDescriptorInfo.ChoiceInfo choice = new StyledLayerDescriptorInfo.ChoiceInfo();
		NamedLayerInfo namedLayerInfo = new NamedLayerInfo();
		namedLayerInfo.setName(DUMMY_NAMED_LAYER);
		NamedLayerInfo.ChoiceInfo userChoice = new NamedLayerInfo.ChoiceInfo();
		userChoice.setUserStyle(userStyleInfo);
		namedLayerInfo.getChoiceList().add(userChoice);
		choice.setNamedLayer(namedLayerInfo);
		sld.getChoiceList().add(choice);

		// force through Geotools parser
		bindingFactory = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
		IMarshallingContext marshallingContext = bindingFactory.createMarshallingContext();
		StringWriter sw = new StringWriter();
		marshallingContext.setOutput(sw);
		marshallingContext.marshalDocument(sld);

		SLDParser parser = new SLDParser(styleFactory, filterService.getFilterFactory());
		parser.setOnLineResourceLocator(new ResourceServiceBasedLocator());
		parser.setInput(new StringReader(sw.toString()));

		Style[] styles = parser.readXML();
		if (styles.length != 0) {
			return styles[0];
		} else {
			throw new LayerException(ExceptionCode.INVALID_USER_STYLE, userStyleInfo.getName());
		}
	} catch (Exception e) {
		throw new LayerException(e, ExceptionCode.INVALID_USER_STYLE, userStyleInfo.getName());
	}
}
 
Example 6
Source File: MLPResponse.java    From gmlc with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Internal XML generation support function for above getSystemErrorResponseXML()
 *
 * @param mlpClientErrorType                Error type to return to client
 * @param mlpClientErrorMessage             Error message to send to client
 * @return                                  String XML result to return to client
 * @throws org.jibx.runtime.JiBXException   JiBX had an internal failure of some kind while marshalling the XML
 * @throws IOException                      IO error occurred while generating the XML result
 */
private String generateSystemErrorXML(MLPResultType mlpClientErrorType, String mlpClientErrorMessage)
    throws org.jibx.runtime.JiBXException, IOException {
  String lXml = null;
  String ver = "3.1.0";

  // Create all the objects we'll use to generate our svc_result XML
  org.oma.protocols.mlp.svc_result.SvcResult mlpSvcResult = new org.oma.protocols.mlp.svc_result.SvcResult();
  org.oma.protocols.mlp.svc_result.Slia mlpSlia = new org.oma.protocols.mlp.svc_result.Slia();
  org.oma.protocols.mlp.svc_result.Result mlpResult = new org.oma.protocols.mlp.svc_result.Result();
  org.oma.protocols.mlp.svc_result.AddInfo mlpAddInfo = new org.oma.protocols.mlp.svc_result.AddInfo();

  // Set the additional data error message if one is available
  if (mlpClientErrorMessage != null) {
    mlpAddInfo.setAddInfo(mlpClientErrorMessage);
    mlpSlia.setAddInfo(mlpAddInfo);
  }

  mlpResult.setString(MLPResponse.getResultStringForType(mlpClientErrorType));
  mlpResult.setResid(MLPResponse.getResultCodeForType(mlpClientErrorType));
  mlpSlia.setResult(mlpResult);
  mlpSlia.setVer(ver);
  mlpSvcResult.setSlia(mlpSlia);
  mlpSvcResult.setVer(ver);

  IBindingFactory jc = BindingDirectory.getFactory(org.oma.protocols.mlp.svc_result.SvcResult.class);
  IMarshallingContext marshaller = jc.createMarshallingContext();
  ByteArrayOutputStream lOutputStream = new ByteArrayOutputStream();
  marshaller.setOutput(lOutputStream, "UTF-8");
  IXMLWriter ix = marshaller.getXmlWriter();

  // Add XML and DOCTYPE headers
  ix.writeXMLDecl("1.0", "UTF-8", null);
  ix.writeDocType("svc_result", "MLP_SVC_RESULT_310.DTD", null, null);

  // Set 4 spaces as the default indenting
  marshaller.setIndent(4);

  // Generate the XML
  marshaller.marshalDocument(mlpSvcResult);

  // Convert the stream to a string
  lXml = new String(lOutputStream.toByteArray(), "UTF-8");

  // Return our XML string result
  return lXml;
}