Java Code Examples for org.jibx.runtime.BindingDirectory#getFactory()
The following examples show how to use
org.jibx.runtime.BindingDirectory#getFactory() .
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 |
/** * 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 |
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 |
@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 |
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: M2Model.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
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 6
Source File: CustomerUnitTest.java From tutorials with MIT License | 5 votes |
@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 7
Source File: JibxMarshaller.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 8
Source File: JibxTest.java From journaldev with MIT License | 5 votes |
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 9
Source File: JibxTest.java From journaldev with MIT License | 5 votes |
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 10
Source File: MLPResponse.java From gmlc with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 11
Source File: JibxHelper.java From tr069-simulator with MIT License | 5 votes |
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 12
Source File: SystemInfo.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 13
Source File: CustomerUnitTest.java From tutorials with MIT License | 5 votes |
@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 14
Source File: StyleConverterServiceTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@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 15
Source File: StyleConverterServiceTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@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: CustomerUnitTest.java From tutorials with MIT License | 5 votes |
@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 17
Source File: StyleConverterServiceTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@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 18
Source File: SystemInfo.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 19
Source File: JibxMarshaller.java From spring-analysis-note with MIT License | 5 votes |
@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 20
Source File: MLPResponse.java From gmlc with GNU Affero General Public License v3.0 | 4 votes |
/** * 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; }