com.thoughtworks.xstream.io.HierarchicalStreamReader Java Examples
The following examples show how to use
com.thoughtworks.xstream.io.HierarchicalStreamReader.
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 Project: auction-website Author: jimouris File: UserXmlUtil.java License: MIT License | 6 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) { // create a user String username, country; country = "Ελλάδα"; username = reader.getAttribute("UserID"); String city = "Αθήνα"; String password = "123456"; String name = username; String lastname = username; String email = username + "@email.com"; String phonenumber = "12312341234"; String vat = "12345"; String homeaddress = "Αθήνα"; String lat = "37.968196"; String longi = "23.77868710000007"; byte[] salt = PasswordAuthentication.genSalt(); byte[] hash = PasswordAuthentication.hash(password.toCharArray(), salt); UserEntity user = new UserEntity(username, hash, salt, name, lastname, email, phonenumber, vat, homeaddress, lat, longi, city, country); user.setIsApproved((byte) 1); return user; }
Example #2
Source Project: lams Author: lamsfoundation File: XStreamer.java License: GNU General Public License v2.0 | 6 votes |
/** * Deserialize a self-contained XStream with object from an XML Reader. * * @param driver the implementation to use * @param xml the {@link Reader} providing the XML data * @param permissions the permissions to use (ensure that they include the defaults) * @throws IOException if an error occurs reading from the Reader. * @throws ClassNotFoundException if a class in the XML stream cannot be found * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized * @since 1.4.7 */ public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission[] permissions) throws IOException, ClassNotFoundException { final XStream outer = new XStream(driver); XStream.setupDefaultSecurity(outer); for(int i = 0; i < permissions.length; ++i) { outer.addPermission(permissions[i]); } final HierarchicalStreamReader reader = driver.createReader(xml); final ObjectInputStream configIn = outer.createObjectInputStream(reader); try { final XStream configured = (XStream)configIn.readObject(); final ObjectInputStream in = configured.createObjectInputStream(reader); try { return in.readObject(); } finally { in.close(); } } finally { configIn.close(); } }
Example #3
Source Project: openhab-core Author: openhab File: ConfigDescriptionParameterGroupConverter.java License: Eclipse Public License 2.0 | 6 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext marshallingContext) { String name = reader.getAttribute("name"); // Read values ConverterValueMap valueMap = new ConverterValueMap(reader, marshallingContext); String context = valueMap.getString("context"); String description = valueMap.getString("description"); String label = valueMap.getString("label"); Boolean advanced = valueMap.getBoolean("advanced", false); return ConfigDescriptionParameterGroupBuilder.create(name) // .withContext(context) // .withAdvanced(advanced) // .withLabel(label) // .withDescription(description) // .build(); }
Example #4
Source Project: depan Author: google File: CameraDirConverter.java License: Apache License 2.0 | 6 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { try { String textX = reader.getAttribute("x"); String textY = reader.getAttribute("y"); String textZ = reader.getAttribute("z"); Float dirX = Float.valueOf(textX); Float dirY = Float.valueOf(textY); Float dirZ = Float.valueOf(textZ); return new CameraDirPreference(dirX, dirY, dirZ); } catch (RuntimeException err) { err.printStackTrace(); throw err; } }
Example #5
Source Project: depan Author: google File: CameraPosConverter.java License: Apache License 2.0 | 6 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { try { String textX = reader.getAttribute("x"); String textY = reader.getAttribute("y"); String textZ = reader.getAttribute("z"); Float posX = Float.valueOf(textX); Float posY = Float.valueOf(textY); Float posZ = Float.valueOf(textZ); return new CameraPosPreference(posX, posY, posZ); } catch (RuntimeException err) { err.printStackTrace(); throw err; } }
Example #6
Source Project: weblaf Author: mgarin File: TextConverter.java License: GNU General Public License v3.0 | 6 votes |
@Override public Object unmarshal ( final HierarchicalStreamReader reader, final UnmarshallingContext context ) { // Reading state final String state = reader.getAttribute ( STATE ); // Reading mnemonic final String m = reader.getAttribute ( MNEMONIC ); final int mnemonic = TextUtils.notEmpty ( m ) ? m.charAt ( 0 ) : -1; // Reading value final String value = reader.getValue (); // Creating Text object return new Text ( value, state, mnemonic ); }
Example #7
Source Project: lams Author: lamsfoundation File: ValueRangeConverter.java License: GNU General Public License v2.0 | 6 votes |
@Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { final boolean oldFormat = "custom".equals(reader.getAttribute(mapper.aliasForSystemAttribute("serialization"))); if (oldFormat) { reader.moveDown(); reader.moveDown(); } final Map<String, Long> elements = new HashMap<>(); while (reader.hasMoreChildren()) { reader.moveDown(); final String name = reader.getNodeName(); elements.put(oldFormat ? name : mapper.realMember(ValueRange.class, name), Long.valueOf(reader.getValue())); reader.moveUp(); } if (oldFormat) { reader.moveUp(); reader.moveUp(); } return ValueRange.of(elements.get("minSmallest").longValue(), elements.get("minLargest").longValue(), elements .get("maxSmallest") .longValue(), elements.get("maxLargest").longValue()); }
Example #8
Source Project: openhab-core Author: openhab File: ConverterValueMap.java License: Eclipse Public License 2.0 | 6 votes |
/** * Reads-in {@code N} children in a key-value map and returns it. * * @param reader the reader to be used to read-in the children (must not be null) * @param numberOfValues the number of children to be read in (< 0 = until end of section) * @param context * @return the key-value map containing the read-in children (not null, could be empty) * @throws ConversionException if not all children could be read-in */ public static Map<String, Object> readValueMap(HierarchicalStreamReader reader, int numberOfValues, UnmarshallingContext context) throws ConversionException { Map<String, Object> valueMap = new HashMap<>((numberOfValues >= 0) ? numberOfValues : 10); int counter = 0; while (reader.hasMoreChildren() && ((counter < numberOfValues) || (numberOfValues == -1))) { reader.moveDown(); if (reader.hasMoreChildren()) { List<?> list = (List<?>) context.convertAnother(context, List.class); valueMap.put(reader.getNodeName(), list); } else { valueMap.put(reader.getNodeName(), reader.getValue()); } reader.moveUp(); counter++; } if ((counter < numberOfValues) && (numberOfValues > 0)) { throw new ConversionException("Not all children could be read-in!"); } return valueMap; }
Example #9
Source Project: weblaf Author: mgarin File: TranslationInformationConverter.java License: GNU General Public License v3.0 | 6 votes |
@Override public Object unmarshal ( final HierarchicalStreamReader reader, final UnmarshallingContext context ) { final TranslationInformation value = new TranslationInformation (); // Reading language final String locale = reader.getAttribute ( LANGUAGE ); value.setLocale ( LanguageUtils.fromString ( locale ) ); // Reading title final String title = reader.getAttribute ( TITLE ); value.setTitle ( title ); // Reading authoer final String author = reader.getAttribute ( AUTHOR ); value.setAuthor ( author ); return value; }
Example #10
Source Project: pentaho-aggdesigner Author: pentaho File: MeasureConverter.java License: GNU General Public License v2.0 | 6 votes |
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); String label = reader.getValue(); reader.moveUp(); reader.moveDown(); String tableLabel = reader.getValue(); reader.moveUp(); Measure foundMeasure = null; for (Measure measure : schema.getMeasures()) { if (measure.getLabel().equals(label) && measure.getTable().getLabel().equals(tableLabel)) { foundMeasure = measure; break; } } if (foundMeasure == null) { throw new RuntimeException("Error: Unable to find measure"); } return foundMeasure; }
Example #11
Source Project: saros Author: saros-project File: ReplaceableConverter.java License: GNU General Public License v2.0 | 5 votes |
@Override public synchronized Object unmarshal( HierarchicalStreamReader reader, UnmarshallingContext context) { if (isReset()) { log.debug("Tried to unmarshal with inactive converter " + delegate); return null; } return delegate.unmarshal(reader, context); }
Example #12
Source Project: kogito-runtimes Author: kiegroup File: RuleTemplateModelImpl.java License: Apache License 2.0 | 5 votes |
public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) { RuleTemplateModelImpl rtm = new RuleTemplateModelImpl(); rtm.setDtable(reader.getAttribute("dtable")); rtm.setTemplate(reader.getAttribute("template")); rtm.setRow(Integer.parseInt( reader.getAttribute("row")) ); rtm.setCol(Integer.parseInt( reader.getAttribute( "col" ) ) ); return rtm; }
Example #13
Source Project: depan Author: google File: GraphModelReferenceConverter.java License: Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * <p> * Obtain the {@link GraphModelReference}, including loading the saved * {@link GraphModel} from a project-based or file-system relative location. * * @see EdgeConverter#unmarshal(HierarchicalStreamReader, UnmarshallingContext) */ @Override public Object unmarshal( HierarchicalStreamReader reader, UnmarshallingContext context) { String graphPath = (String) context.convertAnother(null, String.class); if (null == graphPath) { throw new RuntimeException("Missing location for dependencies"); } if (graphPath.startsWith("/")) { return unmarshalProjectGraphFile(graphPath, context); } return unmarshalRelativeGraphFile(graphPath, context); }
Example #14
Source Project: ET_Redux Author: CIRDLES File: SESARSampleMetadataXMLConverter.java License: Apache License 2.0 | 5 votes |
/** * reads a <code>Tracer</code> from the XML file specified through <code>reader</code> * * @pre <code>reader</code> leads to a valid <code>Tracer</code> * @post the <code>Tracer</code> is read from the XML file and returned * @param reader stream to read through * @param context <code>UnmarshallingContext</code> used to store generic data * @return <code>Object</code> - <code>Tracer</code> read from file * specified by <code>reader</code> */ public Object unmarshal ( HierarchicalStreamReader reader, UnmarshallingContext context ) { SESARSampleMetadata SESARSampleMetadata = new SESARSampleMetadata(); reader.moveDown(); SESARSampleMetadata.setStratigraphicFormationName( reader.getValue() ); reader.moveUp(); reader.moveDown(); SESARSampleMetadata.setStratigraphicGeologicAgeMa( reader.getValue() ); reader.moveUp(); reader.moveDown(); SESARSampleMetadata.setStratigraphicMinAbsoluteAgeMa( Double.valueOf( reader.getValue() ) ); reader.moveUp(); reader.moveDown(); SESARSampleMetadata.setStratigraphicMaxAbsoluteAgeMa( Double.valueOf( reader.getValue() ) ); reader.moveUp(); reader.moveDown(); SESARSampleMetadata.setDetritalType( reader.getValue() ); reader.moveUp(); return SESARSampleMetadata; }
Example #15
Source Project: ET_Redux Author: CIRDLES File: MineralStandardUPbRatioModelXMLConverter.java License: Apache License 2.0 | 5 votes |
/** * reads a <code>ValueModelReferenced</code> from the XML file specified * through <code>reader</code> * * @pre <code>reader</code> leads to a valid <code>ValueModelReferenced</code> * @post returns the <code>ValueModelReferenced</code> read from the XML file * @param reader stream to read through * @param context <code>UnmarshallingContext</code> used to store generic data * @return <code>ValueModelReferenced</code> - <code>ValueModelReferenced</code> * read from file specified by <code>reader</code> */ @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { ValueModel valueModel = new MineralStandardUPbRatioModel(); reader.moveDown(); valueModel.setName(reader.getValue()); reader.moveUp(); reader.moveDown(); valueModel.setValue(new BigDecimal(reader.getValue())); reader.moveUp(); reader.moveDown(); valueModel.setUncertaintyType(reader.getValue()); reader.moveUp(); reader.moveDown(); valueModel.setOneSigma(new BigDecimal(reader.getValue())); reader.moveUp(); reader.moveDown(); ((MineralStandardUPbRatioModel)valueModel).setMeasured( (reader.getValue().equalsIgnoreCase("true")) ? true : false); reader.moveUp(); return valueModel; }
Example #16
Source Project: weblaf Author: mgarin File: ComponentStyleConverter.java License: GNU General Public License v3.0 | 5 votes |
/** * Reads {@link PainterStyle} for the specified {@link ComponentStyle}. * * @param style {@link ComponentStyle} to read {@link PainterStyle} for * @param descriptor {@link ComponentDescriptor} * @param reader {@link HierarchicalStreamReader} * @param context {@link UnmarshallingContext} */ private void readPainterStyle ( @NotNull final ComponentStyle style, @NotNull final ComponentDescriptor descriptor, @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context ) { // Retrieving overwrite policy final String ow = reader.getAttribute ( OVERWRITE_ATTRIBUTE ); final Boolean overwrite = ow != null ? Boolean.parseBoolean ( ow ) : null; // Retrieving default painter class from component descriptor final Class<? extends Painter> defaultPainter = descriptor.getPainterClass (); // Unmarshalling painter class final Class<? extends Painter> painterClass = PainterStyleConverter.unmarshalPainterClass ( reader, context, mapper, defaultPainter, style.getId () ); // Providing painter class to subsequent converters final Object opc = context.get ( CONTEXT_PAINTER_CLASS ); context.put ( CONTEXT_PAINTER_CLASS, painterClass ); // Creating painter style final PainterStyle painterStyle = new PainterStyle (); painterStyle.setOverwrite ( overwrite ); painterStyle.setPainterClass ( painterClass.getCanonicalName () ); // Reading painter style properties // Using LinkedHashMap to keep properties order final LinkedHashMap<String, Object> painterProperties = new LinkedHashMap<String, Object> (); StyleConverterUtils.readProperties ( reader, context, mapper, painterProperties, painterClass, style.getId () ); painterStyle.setProperties ( painterProperties ); // Saving painter style style.setPainterStyle ( painterStyle ); // Cleaning up context context.put ( CONTEXT_PAINTER_CLASS, opc ); }
Example #17
Source Project: sdb-mall Author: yjjdick File: MapCustomConverter.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Map map = (Map) createCollection(context.getRequiredType()); populateMap(reader, context, map); return map; }
Example #18
Source Project: PoseidonX Author: ucarGroup File: MapConverter.java License: Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { TreeMap map = (TreeMap)createCollection(context.getRequiredType()); populateMap(reader, map); return map; }
Example #19
Source Project: depan Author: google File: ReferencedGraphDocumentConverter.java License: Apache License 2.0 | 5 votes |
/** * Unmarshal a sequence of nodes. In contrast to * {@link #marshalNodes(Collection, String, HierarchicalStreamWriter, MarshallingContext)}, * this method does not handle the enclosing XML element. * The caller is responsible for validating any surrounding element tag. */ protected Collection<GraphNode> unmarshalGraphNodes( HierarchicalStreamReader reader, UnmarshallingContext context) { Set<GraphNode> result = Sets.newHashSet(); while (reader.hasMoreChildren()) { GraphNode node = (GraphNode) unmarshalObject(reader, context); result.add(node); } return result; }
Example #20
Source Project: Digital Author: hneemann File: Resources.java License: GNU General Public License v3.0 | 5 votes |
/** * Unmarshals a object * * @param reader the reader to read the xml from * @param context the context of the unmarshaler * @return the read object */ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Map<String, String> map = new TreeMap<>(); while (reader.hasMoreChildren()) { reader.moveDown(); String key = reader.getAttribute("name"); String value = reader.getValue(); map.put(key, value); reader.moveUp(); } return map; }
Example #21
Source Project: lams Author: lamsfoundation File: CGLIBEnhancedConverter.java License: GNU General Public License v2.0 | 5 votes |
private void readCallback(HierarchicalStreamReader reader, UnmarshallingContext context, List callbacksToEnhance, List callbacks) { Callback callback = (Callback)context.convertAnother(null, mapper.realClass(reader .getNodeName())); callbacks.add(callback); if (callback == null) { callbacksToEnhance.add(NoOp.INSTANCE); } else { callbacksToEnhance.add(callback); } }
Example #22
Source Project: sakai Author: sakaiproject File: VersionedExternalizable.java License: Educational Community License v2.0 | 5 votes |
@Override public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) { final String currentVersion = ((VersionedExternalizable) result).getExternalizableVersion(); final String oldVersion = reader.getAttribute(VERSION_ATTRIBUTE); if ((oldVersion == null) || !currentVersion.equals(oldVersion)) { // This is one place we might put a version translation method in the future.... throw new ConversionException("Cannot convert " + result + " from version " + oldVersion + " to version " + currentVersion); } return super.doUnmarshal(result, reader, context); }
Example #23
Source Project: lams Author: lamsfoundation File: XStream.java License: GNU General Public License v2.0 | 5 votes |
/** * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream. * * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.4.10 */ public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader, final DataHolder dataHolder) throws IOException { return new CustomObjectInputStream(new CustomObjectInputStream.StreamCallback() { public Object readFromStream() throws EOFException { if (!reader.hasMoreChildren()) { throw new EOFException(); } reader.moveDown(); final Object result = unmarshal(reader, dataHolder); reader.moveUp(); return result; } public Map readFieldsFromStream() throws IOException { throw new NotActiveException("not in call to readObject"); } public void defaultReadObject() throws NotActiveException { throw new NotActiveException("not in call to readObject"); } public void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException { throw new NotActiveException("stream inactive"); } public void close() { reader.close(); } }, classLoaderReference); }
Example #24
Source Project: pentaho-aggdesigner Author: pentaho File: DatabaseMetaConverter.java License: GNU General Public License v2.0 | 5 votes |
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext arg1) { try { return new DatabaseMeta(reader.getValue()); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #25
Source Project: lams Author: lamsfoundation File: SystemClockConverter.java License: GNU General Public License v2.0 | 5 votes |
@Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { reader.moveDown(); final ZoneId zone = (ZoneId)context.convertAnother(null, ZoneId.class); reader.moveUp(); return Clock.system(zone); }
Example #26
Source Project: lams Author: lamsfoundation File: JavaBeanConverter.java License: GNU General Public License v2.0 | 5 votes |
private Class determineType(HierarchicalStreamReader reader, Object result, String fieldName) { final String classAttributeName = classAttributeIdentifier != null ? classAttributeIdentifier : mapper.aliasForSystemAttribute("class"); String classAttribute = classAttributeName == null ? null : reader.getAttribute(classAttributeName); if (classAttribute != null) { return mapper.realClass(classAttribute); } else { return mapper.defaultImplementationOf(beanProvider.getPropertyType(result, fieldName)); } }
Example #27
Source Project: lams Author: lamsfoundation File: Dom4JDriver.java License: GNU General Public License v2.0 | 5 votes |
public HierarchicalStreamReader createReader(Reader text) { try { final Document document = createReader().read(text); return new Dom4JReader(document, getNameCoder()); } catch (DocumentException e) { throw new StreamException(e); } }
Example #28
Source Project: weblaf Author: mgarin File: StyleConverterUtils.java License: GNU General Public License v3.0 | 5 votes |
/** * Read properties for the specified class into the provided properties map. * * @param reader {@link HierarchicalStreamReader} * @param context {@link UnmarshallingContext} * @param mapper {@link Mapper} * @param properties map to read properties into * @param clazz class to read properties for, it will be used to retrieve properties field types * @param styleId component {@link com.alee.managers.style.StyleId}, might be used to report problems */ public static void readProperties ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context, @NotNull final Mapper mapper, @NotNull final Map<String, Object> properties, @NotNull final Class clazz, final String styleId ) { while ( reader.hasMoreChildren () ) { reader.moveDown (); readProperty ( reader, context, mapper, styleId, properties, clazz, reader.getNodeName () ); reader.moveUp (); } }
Example #29
Source Project: smarthome Author: eclipse-archived File: ChannelConverter.java License: Eclipse Public License 2.0 | 5 votes |
protected ChannelXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException { String id = attributes.get("id"); String typeId = attributes.get("typeId"); String label = (String) nodeIterator.nextValue("label", false); String description = (String) nodeIterator.nextValue("description", false); List<NodeValue> properties = getProperties(nodeIterator); AutoUpdatePolicy autoUpdatePolicy = readAutoUpdatePolicy(nodeIterator); ChannelXmlResult channelXmlResult = new ChannelXmlResult(id, typeId, label, description, properties, autoUpdatePolicy); return channelXmlResult; }
Example #30
Source Project: depan Author: google File: ViewExtensionConverter.java License: Apache License 2.0 | 5 votes |
private String getExtensionId(HierarchicalStreamReader reader) { try { return reader.getAttribute(VIEW_EXT_ATTR); } catch (RuntimeException err) { ViewDocLogger.LOG.error("Unable to locate extension id", err); throw err; } }