org.jibx.runtime.BindingDirectory Java Examples

The following examples show how to use org.jibx.runtime.BindingDirectory. 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: JibxHelper.java    From tr069-simulator with MIT License 6 votes vote down vote up
/**
 * Unmarshal this xml Message to an object.
 * @param xml
 * @param system
 * @return
 */
public static Object unmarshalMessage(String xml, String version)
{
	String packageName = "org.dslforum." + version;
	String bindingName = "binding";

	try {
		IBindingFactory jc = BindingDirectory.getFactory(bindingName, packageName);
		IUnmarshallingContext unmarshaller = jc.createUnmarshallingContext();
		Reader inStream = new StringReader(xml);
		Object message = unmarshaller.unmarshalDocument( inStream, bindingName);
		return message;
	} catch (JiBXException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example #2
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 #3
Source File: LegendGraphicServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
public SimpleRulesData(String ruleName, int width, int height) throws JiBXException {
	this.width = width;
	this.height = height;
	IBindingFactory bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	Object object = uctx.unmarshalDocument(
			getClass().getResourceAsStream("/org/geomajas/testdata/sld/simple_rules.sld"), null);
	StyledLayerDescriptorInfo sld = (StyledLayerDescriptorInfo) object;
	NamedLayerInfo namedLayerInfo = sld.getChoiceList().get(0).getNamedLayer();
	UserStyleInfo userStyleInfo = namedLayerInfo.getChoiceList().get(0).getUserStyle();
	FeatureTypeStyleInfo featureTypeStyleInfo = userStyleInfo.getFeatureTypeStyleList().get(0);
	for (RuleInfo rule : featureTypeStyleInfo.getRuleList()) {
		if (ruleName.equals(rule.getName())) {
			ruleInfo = rule;
		}
	}
}
 
Example #4
Source File: StyleConverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testStyleWithExternalGraphicNoSize() throws JiBXException, LayerException {
	IBindingFactory bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	Object object = uctx.unmarshalDocument(
			getClass().getResourceAsStream("/org/geomajas/testdata/sld/point_externalgraphicnosize.sld"),
					null);
	StyledLayerDescriptorInfo sld = (StyledLayerDescriptorInfo) object;
	NamedStyleInfo info = styleConverterService.convert(sld.getChoiceList().get(0).getNamedLayer().getChoiceList()
			.get(0).getUserStyle(), featureInfo);
	Assert.assertNotNull(info);
}
 
Example #5
Source File: WorldPaintableDirectLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private SymbolizerTypeInfo toStyle(String sld) throws Exception {
	String style = "<StyledLayerDescriptor version=\"1.0.0\"\n" + 
			"    xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" \n" + 
			"    xmlns=\"http://www.opengis.net/sld\" \n" + 
			"    xmlns:ogc=\"http://www.opengis.net/ogc\" \n" + 
			"    xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n" + 
			"    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + 
			"  <NamedLayer>\n" + 
			"    <Name>test</Name>\n" + 
			"    <UserStyle>\n" + 
			"      <Title>test</Title>\n" + 
			"      <FeatureTypeStyle>\n" + 
			"        <Rule>\n" + 
			""+sld+"       </Rule>\n" + 
					"      </FeatureTypeStyle>\n" + 
					"    </UserStyle>\n" + 
					"  </NamedLayer>\n" + 
					"</StyledLayerDescriptor>";
	IBindingFactory bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	Object object = uctx.unmarshalDocument(new StringReader(style), null);
	return ((StyledLayerDescriptorInfo) object).getChoiceList().get(0).getNamedLayer().getChoiceList().get(0)
			.getUserStyle().getFeatureTypeStyleList().get(0).getRuleList().get(0).getSymbolizerList().get(0);
}
 
Example #6
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 #7
Source File: JibXXMLMapper.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Convert Java Object to XML String
 */
public String serialize(Object obj) {
        IBindingFactory bfact = null;
        StringWriter sw = new StringWriter();
        try {
                bfact =  BindingDirectory.getFactory(obj.getClass());
                bfact.createMarshallingContext().marshalDocument(obj, "UTF-8", null, sw );
        } catch (JiBXException e) {
                log.error(e);
                throw new XMLMappingException("Can't serialize object: " + obj.toString(), e );
        }
        return sw.toString();
}
 
Example #8
Source File: JibXXMLMapper.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Convert xml string to Java Objects
 */
public Object deserialize(String xml) {
IBindingFactory bfact = null;
StringReader sr = new StringReader(xml);
Object obj = null;
try {
        bfact = BindingDirectory.getFactory(bindingName, packageName);
        obj = bfact.createUnmarshallingContext().unmarshalDocument(sr);
} catch (JiBXException e) {
        log.error(e);
        throw new XMLMappingException("Can't deserialize xml: " + xml, e);
}
        return obj;
}
 
Example #9
Source File: JibxHelper.java    From tr069-simulator with MIT License 5 votes vote down vote up
public static Object unmarshalMessage(Class className, String xml, String version) {
	String packageName = "org.dslforum." + version;
	String bindingName = "binding";
	try {
		IBindingFactory jc = BindingDirectory.getFactory(bindingName, className);
		IUnmarshallingContext unmarshaller = jc.createUnmarshallingContext();
		Reader inStream = new StringReader(xml);
		Object message = unmarshaller.unmarshalDocument( inStream, bindingName);
		return message;
	} catch (JiBXException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example #10
Source File: CustomerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void WhenUnmarshal_ThenPhoneMappingRead() throws JiBXException, FileNotFoundException {
	IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
	Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);
	
	assertEquals("234678", customer.getHomePhone().getNumber());

}
 
Example #11
Source File: CustomerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void WhenUnmarshal_ThenMappingInherited() throws JiBXException, FileNotFoundException {
	IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
	Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);

	assertEquals(12345, customer.getPerson().getCustomerId());

}
 
Example #12
Source File: CustomerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenUnmarshalXML_ThenFieldsAreMapped() throws JiBXException, FileNotFoundException {
	IBindingFactory bfact = BindingDirectory.getFactory(Customer.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	InputStream inputStream = classLoader.getResourceAsStream("Customer1.xml");
	Customer customer = (Customer) uctx.unmarshalDocument(inputStream, null);

	assertEquals("Stefan Jaeger", customer.getPerson().getName());
	assertEquals("Davos Dorf", customer.getCity());

}
 
Example #13
Source File: StyleConverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testStyleWithLiteralCssParameter() throws JiBXException, LayerException {
	IBindingFactory bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	Object object = uctx.unmarshalDocument(
			getClass().getResourceAsStream("/org/geomajas/testdata/sld/polygon_literalcssparameter.sld"),
					null);
	StyledLayerDescriptorInfo sld = (StyledLayerDescriptorInfo) object;
	NamedStyleInfo info = styleConverterService.convert(sld.getChoiceList().get(0).getNamedLayer().getChoiceList()
			.get(0).getUserStyle(), featureInfo);
	Assert.assertNotNull(info);
}
 
Example #14
Source File: StyleConverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testStyleWithLiteralLabel() throws JiBXException, LayerException {
	IBindingFactory bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	Object object = uctx.unmarshalDocument(
			getClass().getResourceAsStream("/org/geomajas/testdata/sld/line_literallabelfollowingline.sld"),
					null);
	StyledLayerDescriptorInfo sld = (StyledLayerDescriptorInfo) object;
	NamedStyleInfo info = styleConverterService.convert(sld.getChoiceList().get(0).getNamedLayer().getChoiceList()
			.get(0).getUserStyle(), featureInfo);
	Assert.assertNotNull(info);
	
	Assert.assertEquals("'\u2192'", info.getLabelStyle().getLabelValueExpression());

}
 
Example #15
Source File: StyleConverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testStyleWithAttributeLabel() throws JiBXException, LayerException {
	IBindingFactory bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	Object object = uctx.unmarshalDocument(
			getClass().getResourceAsStream("/org/geomajas/testdata/sld/line_labelfollowingline.sld"),
					null);
	StyledLayerDescriptorInfo sld = (StyledLayerDescriptorInfo) object;
	NamedStyleInfo info = styleConverterService.convert(sld.getChoiceList().get(0).getNamedLayer().getChoiceList()
			.get(0).getUserStyle(), featureInfo);
	Assert.assertNotNull(info);
	
	Assert.assertEquals("name", info.getLabelStyle().getLabelAttributeName());

}
 
Example #16
Source File: StyleConverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testSingleStyle() throws JiBXException, LayerException {
	IBindingFactory bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
	IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
	Object object = uctx.unmarshalDocument(
			getClass().getResourceAsStream("/org/geomajas/testdata/sld/single_layer_no_stylename.sld"), null);
	StyledLayerDescriptorInfo sld = (StyledLayerDescriptorInfo) object;
	NamedStyleInfo info = styleConverterService.convert(sld.getChoiceList().get(0).getNamedLayer().getChoiceList()
			.get(0).getUserStyle(), featureInfo);
	Assert.assertNotNull(info);
	Assert.assertEquals("Some title", info.getName());
}
 
Example #17
Source File: JibxMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws JiBXException {
	if (this.targetClass != null) {
		if (StringUtils.hasLength(this.bindingName)) {
			if (logger.isDebugEnabled()) {
				logger.debug("Configured for target class [" + this.targetClass +
						"] using binding [" + this.bindingName + "]");
			}
			this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetClass);
		}
		else {
			if (logger.isDebugEnabled()) {
				logger.debug("Configured for target class [" + this.targetClass + "]");
			}
			this.bindingFactory = BindingDirectory.getFactory(this.targetClass);
		}
	}
	else if (this.targetPackage != null) {
		if (!StringUtils.hasLength(this.bindingName)) {
			this.bindingName = DEFAULT_BINDING_NAME;
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Configured for target package [" + this.targetPackage +
					"] using binding [" + this.bindingName + "]");
		}
		this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetPackage);
	}
	else {
		throw new IllegalArgumentException("Either 'targetClass' or 'targetPackage' is required");
	}
}
 
Example #18
Source File: MLPRequest.java    From gmlc with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parse incoming XML request data via JiBX's unmarshaller and return only the MSISDN being requested
 *
 * @param requestStream InputStream (likely directly from the HTTP POST) of the XML input data
 * @return MSISDN of device to locate
 * @throws MLPException
 */
public String parseRequest(InputStream requestStream) throws MLPException {
  // Result XML
  String requestingserviceid, requestingMSISDN = null;

  // Process the request
  try {
    // Create the JiBX unmarshalling object
    IBindingFactory jc = BindingDirectory.getFactory(org.oma.protocols.mlp.svc_init.SvcInit.class);
    IUnmarshallingContext unmarshaller = jc.createUnmarshallingContext();

    // Unmarshal directly from the POST input stream
    org.oma.protocols.mlp.svc_init.SvcInit svcInit = (org.oma.protocols.mlp.svc_init.SvcInit) unmarshaller.unmarshalDocument(requestStream, "UTF-8");

    // Process the location request for the specified MSISDN
    org.oma.protocols.mlp.svc_init.Msids msids = svcInit.getSlir().getMsids();
    org.oma.protocols.mlp.svc_init.Msids.Choice c = msids.getChoiceList().get(0);
    org.oma.protocols.mlp.svc_init.Msid msisdn = c.getMsid();
    requestingMSISDN = msisdn.getString();
    //Process the location request for serviceid
    org.oma.protocols.mlp.svc_init.Serviceid serviceidd = svcInit.getHdr().getClient().getServiceid();
    requestingserviceid = serviceidd.getServiceid();
    this.logger.info("Parsed location request for MSISDN: " + requestingMSISDN);
    return requestingMSISDN + ";" + requestingserviceid;
  } catch (JiBXException e) {
    e.printStackTrace();
    this.logger.info("Exception while unmarshalling XML request data: " + e.getMessage());

    // Set a custom error message for delivering directly to the client
    // and throw a new exception
    MLPException mlpException = new MLPException(e.getMessage());
    mlpException.setMlpClientErrorMessage("Invalid XML received: " + e.getMessage());
    mlpException.setMlpClientErrorType(MLPResponse.MLPResultType.FORMAT_ERROR);
    throw mlpException;
  }
}
 
Example #19
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 #20
Source File: JibxTest.java    From journaldev with MIT License 5 votes vote down vote up
public void unMarshalEmployee(String inputXml){
	try {
		IBindingFactory bfact = BindingDirectory.getFactory(Employee.class);
		IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
		StringReader stringReader = new StringReader(inputXml);
		Employee employee  = (Employee) uctx.unmarshalDocument(stringReader, null);
		System.out.println("Employee ID:"+employee.getId());
	} catch (JiBXException e) {
		e.printStackTrace();
	}	
}
 
Example #21
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 #22
Source File: JibxMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws JiBXException {
	if (this.targetClass != null) {
		if (StringUtils.hasLength(this.bindingName)) {
			if (logger.isInfoEnabled()) {
				logger.info("Configured for target class [" + this.targetClass + "] using binding [" + this.bindingName + "]");
			}
			this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetClass);
		}
		else {
			if (logger.isInfoEnabled()) {
				logger.info("Configured for target class [" + this.targetClass + "]");
			}
			this.bindingFactory = BindingDirectory.getFactory(this.targetClass);
		}
	}
	else if (this.targetPackage != null) {
		if (!StringUtils.hasLength(bindingName)) {
			bindingName = DEFAULT_BINDING_NAME;
		}
		if (logger.isInfoEnabled()) {
			logger.info("Configured for target package [" + this.targetPackage	+ "] using binding [" + this.bindingName + "]");
		}
		this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetPackage);
	}
	else {
		throw new IllegalArgumentException("Either 'targetClass' or 'targetPackage' is required");
	}
}
 
Example #23
Source File: M2Model.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static M2Model createModel(String bindingName, InputStream xml)
{
    try
    {
        IBindingFactory factory = BindingDirectory.getFactory(bindingName, M2Model.class);
        IUnmarshallingContext context = factory.createUnmarshallingContext();
        Object obj = context.unmarshalDocument(xml, null);
        return (M2Model)obj;
    }
    catch(JiBXException e)
    {
        throw new DictionaryException(ERR_PARSE_FAILURE, e);
    }        
}
 
Example #24
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 #25
Source File: SystemInfo.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create System Info from XML representation
 *  
 * @param xml  xml representation of system info
 * @return  the System Info
 */
public static SystemInfo createSystemInfo(InputStream xml)
{
    try
    {
        IBindingFactory factory = BindingDirectory.getFactory(SystemInfo.class);
        IUnmarshallingContext context = factory.createUnmarshallingContext();
        Object obj = context.unmarshalDocument(xml, null);
        return (SystemInfo)obj;
    }
    catch(JiBXException e)
    {
        throw new DictionaryException("Failed to parse System Info", e);
    }
}
 
Example #26
Source File: JibxMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws JiBXException {
	if (this.targetClass != null) {
		if (StringUtils.hasLength(this.bindingName)) {
			if (logger.isDebugEnabled()) {
				logger.debug("Configured for target class [" + this.targetClass +
						"] using binding [" + this.bindingName + "]");
			}
			this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetClass);
		}
		else {
			if (logger.isDebugEnabled()) {
				logger.debug("Configured for target class [" + this.targetClass + "]");
			}
			this.bindingFactory = BindingDirectory.getFactory(this.targetClass);
		}
	}
	else if (this.targetPackage != null) {
		if (!StringUtils.hasLength(this.bindingName)) {
			this.bindingName = DEFAULT_BINDING_NAME;
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Configured for target package [" + this.targetPackage +
					"] using binding [" + this.bindingName + "]");
		}
		this.bindingFactory = BindingDirectory.getFactory(this.bindingName, this.targetPackage);
	}
	else {
		throw new IllegalArgumentException("Either 'targetClass' or 'targetPackage' is required");
	}
}
 
Example #27
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;
}