org.jibx.runtime.IUnmarshallingContext Java Examples

The following examples show how to use org.jibx.runtime.IUnmarshallingContext. 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: 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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #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 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 #14
Source File: JibxMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
	try {
		IUnmarshallingContext unmarshallingContext = createUnmarshallingContext();
		return unmarshallingContext.unmarshalDocument(inputStream, this.encoding);
	}
	catch (JiBXException ex) {
		throw convertJibxException(ex, false);
	}
}
 
Example #15
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 #16
Source File: JibxMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
	try {
		IUnmarshallingContext unmarshallingContext = createUnmarshallingContext();
		return unmarshallingContext.unmarshalDocument(reader);
	}
	catch (JiBXException ex) {
		throw convertJibxException(ex, false);
	}
}
 
Example #17
Source File: JibxMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
	try {
		IUnmarshallingContext unmarshallingContext = createUnmarshallingContext();
		return unmarshallingContext.unmarshalDocument(inputStream, encoding);
	}
	catch (JiBXException ex) {
		throw convertJibxException(ex, false);
	}
}
 
Example #18
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 #19
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 #20
Source File: JibxMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
	try {
		IUnmarshallingContext unmarshallingContext = createUnmarshallingContext();
		return unmarshallingContext.unmarshalDocument(reader);
	}
	catch (JiBXException ex) {
		throw convertJibxException(ex, false);
	}
}
 
Example #21
Source File: JibxMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException {
	try {
		IUnmarshallingContext unmarshallingContext = createUnmarshallingContext();
		return unmarshallingContext.unmarshalDocument(inputStream, this.encoding);
	}
	catch (JiBXException ex) {
		throw convertJibxException(ex, false);
	}
}
 
Example #22
Source File: JibxMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException {
	try {
		IUnmarshallingContext unmarshallingContext = createUnmarshallingContext();
		return unmarshallingContext.unmarshalDocument(reader);
	}
	catch (JiBXException ex) {
		throw convertJibxException(ex, false);
	}
}
 
Example #23
Source File: JibxMarshaller.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new {@code IUnmarshallingContext}.
 * @return the created unmarshalling context
 * @throws JiBXException in case of errors
 */
protected IUnmarshallingContext createUnmarshallingContext() throws JiBXException {
	return this.bindingFactory.createUnmarshallingContext();
}
 
Example #24
Source File: JibxMarshaller.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a new {@code IUnmarshallingContext}.
 * @return the created unmarshalling context
 * @throws JiBXException in case of errors
 */
protected IUnmarshallingContext createUnmarshallingContext() throws JiBXException {
	Assert.state(this.bindingFactory != null, "JibxMarshaller not initialized");
	return this.bindingFactory.createUnmarshallingContext();
}
 
Example #25
Source File: JibxMarshaller.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a new {@code IUnmarshallingContext}.
 * @return the created unmarshalling context
 * @throws JiBXException in case of errors
 */
protected IUnmarshallingContext createUnmarshallingContext() throws JiBXException {
	Assert.state(this.bindingFactory != null, "JibxMarshaller not initialized");
	return this.bindingFactory.createUnmarshallingContext();
}