public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException { if (data instanceof XMLGregorianCalendar) { String escaped = JavascriptUtil.escapeJavaScript(data.toString()); return new SimpleOutboundVariable('\"' + escaped + '\"', outctx, true); } throw new MarshallException(data.getClass()); }
protected Map<String, String> extractInboundTokens(Class<?> paramType, String value) throws MarshallException { Map<String, String> tokens = new HashMap<String, String>(); StringTokenizer st = new StringTokenizer(value, ProtocolConstants.INBOUND_MAP_SEPARATOR); int size = st.countTokens(); for (int i = 0; i < size; i++) { String token = st.nextToken(); if (token.trim().length() == 0) { continue; } int colonpos = token.indexOf(ProtocolConstants.INBOUND_MAP_ENTRY); if (colonpos == -1) { throw new MarshallException(paramType, Messages.getString("BeanConverter.MissingSeparator", //$NON-NLS-1$ ProtocolConstants.INBOUND_MAP_ENTRY, token)); } String key = token.substring(0, colonpos).trim(); String val = token.substring(colonpos + 1).trim(); tokens.put(key, val); } return tokens; }
public JAXBRIContext getJAXBRIContext() throws MarshallException { if (context == null) { try { this.context = (JAXBRIContext) ContextFactory.createContext(getContextPath(), Thread .currentThread() .getContextClassLoader(), Collections.<String, Object> emptyMap()); } catch (JAXBException jaxbex) { throw new MarshallException(JAXBElement.class, jaxbex); } } return context; }
@Override public Point createGeometry(double[] coordinates) throws MarshallException { if (coordinates == null) { return null; } else if (coordinates.length == 2) { return getGeometryFactory().createPoint(new Coordinate(coordinates[0], coordinates[1])); } else if (coordinates.length == 3) { return getGeometryFactory().createPoint( new Coordinate(coordinates[0], coordinates[1], coordinates[2])); } else { throw new MarshallException(Point.class, MessageFormat.format( "Incorrect number of coordinate components [{0}].", //$NON-NLS-1$ coordinates.length)); } }
@Override public Object convertInbound( @SuppressWarnings({ "rawtypes" }) Class paramType, InboundVariable data, InboundContext inctx) throws MarshallException { String value = data.getValue(); // If the text is null then the whole bean is null if (value.trim().equals(ProtocolConstants.INBOUND_NULL)) { return null; } if (!value.startsWith(ProtocolConstants.INBOUND_MAP_START)) { throw new MarshallException(paramType, Messages.getString("BeanConverter.FormatError", //$NON-NLS-1$ ProtocolConstants.INBOUND_MAP_START)); } if (!value.endsWith(ProtocolConstants.INBOUND_MAP_END)) { throw new MarshallException(paramType, Messages.getString("BeanConverter.FormatError", //$NON-NLS-1$ ProtocolConstants.INBOUND_MAP_START)); } value = value.substring(1, value.length() - 1); final Map<String, String> tokens = extractInboundTokens(paramType, value); return convertInbound(paramType, data, tokens, inctx, value); }
@Override public Object convertInbound(Class paramClass, InboundVariable paramInboundVariable, InboundContext paramInboundContext) throws MarshallException { //Convert from string to Unit try{ //For the ONE unit if(paramInboundVariable.getValue().equals("ONE")) return Unit.ONE; else return UnitUtil.parseLocal(URLDecoder.decode(paramInboundVariable.getValue(), Common.UTF8)); }catch(Exception e){ throw new MarshallException(paramClass); } }
@Override protected MultiPoint createGeometry(double[][] coordinates) throws MarshallException { if (coordinates == null) { return null; } else if (coordinates.length > 0) { final Point[] geometries = new Point[coordinates.length]; for (int index = 0; index < coordinates.length; index++) { geometries[index] = converter.createGeometry(coordinates[index]); } return getGeometryFactory().createMultiPoint(geometries); } else { throw new MarshallException(MultiPoint.class, MessageFormat.format( "Incorrect number of coordinate components [{0}].", //$NON-NLS-1$ coordinates.length)); } }
@Override protected MultiPolygon createGeometry(double[][][][] coordinates) throws MarshallException { if (coordinates == null) { return null; } else if (coordinates.length > 0) { final Polygon[] geometries = new Polygon[coordinates.length]; for (int index = 0; index < coordinates.length; index++) { geometries[index] = converter.createGeometry(coordinates[index]); } return getGeometryFactory().createMultiPolygon(geometries); } else { throw new MarshallException(MultiPolygon.class, MessageFormat.format( "Incorrect number of coordinate components [{0}].", //$NON-NLS-1$ coordinates.length)); } }
@Override public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException { for (AbstractGeometryConverter<?, ?> converter : converters) { try { converter.setConverterManager(getConverterManager()); return converter.convertOutbound(data, outctx); } catch (Exception e) { continue; } } //unsure about this throw new MarshallException( this.getClass(), "The given object could not be marshalled as a geometry object."); }
@Override protected MultiLineString createGeometry(double[][][] coordinates) throws MarshallException { if (coordinates == null) { return null; } else if (coordinates.length > 0) { final LineString[] geometries = new LineString[coordinates.length]; for (int index = 0; index < coordinates.length; index++) { geometries[index] = converter.createGeometry(coordinates[index]); } return getGeometryFactory().createMultiLineString(geometries); } else { throw new MarshallException(MultiLineString.class, MessageFormat.format( "Incorrect number of coordinate components [{0}].", //$NON-NLS-1$ coordinates.length)); } }
@Override protected double[][] createCoordinates(LineStringType geometry) throws MarshallException { try { final LineString lineString = (LineString) getConverter().createGeometry( new DefaultRootObjectLocator(geometry), geometry); return createCoordinates(lineString); } catch (ConversionFailedException cfex) { throw new MarshallException(LineStringType.class, cfex); } }
@Override public LineString createGeometry(double[][] coordinates) throws MarshallException { if (coordinates == null) { return null; } else if (coordinates.length >= 2) { Coordinate[] coordinateArray = new Coordinate[coordinates.length]; for (int index = 0; index < coordinates.length; index++) { coordinateArray[index] = pointConverter.createGeometry(coordinates[index]).getCoordinate(); } return getGeometryFactory().createLineString(coordinateArray); } else { throw new MarshallException(Point.class, MessageFormat.format( "Incorrect number of coordinate components [{0}].", //$NON-NLS-1$ coordinates.length)); } }
@Override protected Object convertInbound( @SuppressWarnings("rawtypes") Class paramType, InboundVariable data, Map<String, String> tokens, InboundContext inctx, String value) throws MarshallException { for (AbstractGeometryConverter<?, ?> converter : converters) { try { //unsure about this converter.setConverterManager(getConverterManager()); return converter.convertInbound(paramType, data, tokens, inctx, value); } catch (Exception e) { continue; } } throw new MarshallException(paramType, "No geometry could be created from the given object."); }
@Override protected double[][][] createCoordinates(PolygonType polygonType) throws MarshallException { try { final Polygon polygon = (Polygon) getConverter().createGeometry( new DefaultRootObjectLocator(polygonType), polygonType); return createCoordinates(polygon); } catch (ConversionFailedException cfex) { throw new MarshallException(PolygonType.class, cfex); } }
@Override protected double[] createCoordinates(PointType pointType) throws MarshallException { try { final Point point = (Point) getConverter().createGeometry( new DefaultRootObjectLocator(pointType), pointType); return createCoordinate(point); } catch (ConversionFailedException cfex) { throw new MarshallException(PointType.class, cfex); } }
@Override public OutboundVariable convertOutbound(Object paramObject, OutboundContext paramOutboundContext) throws MarshallException { //Convert from Unit to String // Check to see if we have done this one already OutboundVariable ov = paramOutboundContext.get(paramObject); if (ov != null) { // So the object as been converted already, we just need to refer to it. return ov.getReferenceVariable(); } if(paramObject instanceof Unit<?>){ Unit<?> unit = (Unit<?>)paramObject; String unitString = UnitUtil.formatLocal(unit); if(unit == unit.ONE) unitString = "ONE"; return new SimpleOutboundVariable("'" + unitString + "';",paramOutboundContext,false); }else{ throw new MarshallException(paramObject.getClass()); } }
@Override protected Object convertInbound( @SuppressWarnings("unchecked") Class paramType, InboundVariable data, Map<String, String> tokens, InboundContext inctx, String value) throws MarshallException { QName name = getValue("name", QName.class, data, tokens, inctx); //$NON-NLS-1$ for (RuntimeElementInfo elementInfo : getJAXBRIContext() .getRuntimeTypeInfoSet() .getAllElements()) { if (ObjectUtils.equals(name, elementInfo.getElementName())) { @SuppressWarnings("unchecked") final Class<Object> type = (Class<Object>) elementInfo.getContentInMemoryType(); final Object content = getValue("value", type, data, tokens, inctx); //$NON-NLS-1$ return new JAXBElement<Object>(name, type, content); } } throw new MarshallException(JAXBElement.class); }
@Override protected double[][] createCoordinates(MultiPointType multiPointType) throws MarshallException { try { final MultiPoint multiPoint = (MultiPoint) getConverter().createGeometry( new DefaultRootObjectLocator(multiPointType), multiPointType); int numGeometries = multiPoint.getNumGeometries(); double[][] coordinates = new double[numGeometries][]; for (int i = 0; i < numGeometries; i++) { coordinates[i] = pointTypeConverter.createCoordinate((Point) multiPoint.getGeometryN(i)); } return coordinates; } catch (ConversionFailedException cfex) { throw new MarshallException(PointType.class, cfex); } }
@Override protected double[][][][] createCoordinates(MultiPolygonType multiPolygonType) throws MarshallException { try { final MultiPolygon multiPolygon = (MultiPolygon) getConverter().createGeometry( new DefaultRootObjectLocator(multiPolygonType), multiPolygonType); final int numGeometries = multiPolygon.getNumGeometries(); double[][][][] coordinates = new double[numGeometries][][][]; for (int index = 0; index < numGeometries; index++) { coordinates[index] = polygonTypeConverter.createCoordinates((Polygon) multiPolygon .getGeometryN(index)); } return coordinates; } catch (ConversionFailedException cfex) { throw new MarshallException(MultiPolygonType.class, cfex); } }
@Override protected double[][][] createCoordinates(MultiLineStringType multiLineStringType) throws MarshallException { try { final MultiLineString multiLineString = (MultiLineString) getConverter().createGeometry( new DefaultRootObjectLocator(multiLineStringType), multiLineStringType); final int numGeometries = multiLineString.getNumGeometries(); double[][][] coordinates = new double[numGeometries][][]; for (int index = 0; index < numGeometries; index++) { coordinates[index] = lineStringTypeConverter.createCoordinates((LineString) multiLineString .getGeometryN(index)); } return coordinates; } catch (ConversionFailedException cfex) { throw new MarshallException(LineStringType.class, cfex); } }