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 File: TextConverter.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
@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 #2
Source File: ConfigDescriptionParameterGroupConverter.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@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 #3
Source File: ConverterValueMap.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: CameraDirConverter.java    From depan with Apache License 2.0 6 votes vote down vote up
@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 File: ValueRangeConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 #6
Source File: CameraPosConverter.java    From depan with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: TranslationInformationConverter.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
@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 #8
Source File: XStreamer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #9
Source File: UserXmlUtil.java    From auction-website with MIT License 6 votes vote down vote up
@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 #10
Source File: MeasureConverter.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
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 File: GamaMapConverter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext arg1) {
	// reader.moveDown();
	final GamaMapReducer rmt = (GamaMapReducer) arg1.convertAnother(null, GamaMapReducer.class);
	// reader.moveUp();
	return rmt.constructObject(convertScope.getScope());
}
 
Example #12
Source File: BridgeTypeConverter.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected BridgeTypeXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context,
        Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
    BridgeTypeXmlResult bridgeTypeXmlResult = new BridgeTypeXmlResult(new ThingTypeUID(getUID(attributes, context)),
            readSupportedBridgeTypeUIDs(nodeIterator, context), readLabel(nodeIterator),
            readDescription(nodeIterator), readCategory(nodeIterator), getListed(attributes),
            getExtensibleChannelTypeIds(attributes), getChannelTypeReferenceObjects(nodeIterator),
            getProperties(nodeIterator), getRepresentationProperty(nodeIterator),
            getConfigDescriptionObjects(nodeIterator));

    return bridgeTypeXmlResult;
}
 
Example #13
Source File: StyleConverterUtils.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #14
Source File: ReplaceableConverter.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@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 #15
Source File: ChannelConverter.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
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 #16
Source File: GamaAgentConverterNetwork.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext arg1) {
	
	final SavedAgent rmt = (SavedAgent) arg1.convertAnother(null, SavedAgent.class);
	//reader.moveUp();
//	System.out.println("lecture d'un save agent " + rmt.getName()+" " +rmt.values());
	
	return rmt;
}
 
Example #17
Source File: XMLConfigurer.java    From oval with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Pattern unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
   final String pattern = reader.getAttribute("pattern");
   final String flags = reader.getAttribute("flags");
   if (flags == null || flags.trim().length() == 0)
      return Pattern.compile(pattern);
   return Pattern.compile(pattern, Integer.parseInt(flags));
}
 
Example #18
Source File: NodeListDocumentConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
private boolean isNodeList(HierarchicalStreamReader reader) {
  String childName = reader.getNodeName();
  if (NODE_LIST.equals(childName)) {
    return true;
  }
  return false;
}
 
Example #19
Source File: ValueConverter.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal ( final HierarchicalStreamReader reader, final UnmarshallingContext context )
{
    final Value value = new Value ();

    // Reading language
    final String locale = reader.getAttribute ( LANGUAGE );
    value.setLocale ( LanguageUtils.fromString ( locale ) );

    // Reading possible single-value case attributes
    final String state = reader.getAttribute ( STATE );
    final String character = reader.getAttribute ( MNEMONIC );
    final int mnemonic = character != null ? character.charAt ( 0 ) : -1;

    // Reading texts and tooltips
    final String text = reader.getValue ();
    final List<Text> texts = new ArrayList<Text> ();
    while ( reader.hasMoreChildren () )
    {
        reader.moveDown ();
        texts.add ( ( Text ) context.convertAnother ( value, Text.class ) );
        reader.moveUp ();
    }

    // Determining what should we save
    if ( texts.size () == 0 )
    {
        // Saving single text
        value.addText ( new Text ( text, state, mnemonic ) );
    }
    else
    {
        // Saving multiple texts
        value.setTexts ( texts );
    }

    return value;
}
 
Example #20
Source File: SubjectConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Set principals = unmarshalPrincipals(reader, context);
    Set publicCredentials = unmarshalPublicCredentials(reader, context);
    Set privateCredentials = unmarshalPrivateCredentials(reader, context);
    boolean readOnly = unmarshalReadOnly(reader);
    return new Subject(readOnly, principals, publicCredentials, privateCredentials);
}
 
Example #21
Source File: NamedMapConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected Object readItem(Class type, HierarchicalStreamReader reader,
    UnmarshallingContext context, Object current) {
    String className = HierarchicalStreams.readClassAttribute(reader, mapper());
    Class itemType = className == null ? type : mapper().realClass(className);
    if (Mapper.Null.class.equals(itemType)) {
        return null;
    } else {
        return context.convertAnother(current, itemType);
    }
}
 
Example #22
Source File: Dom4JDriver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 1.4
 */
public HierarchicalStreamReader createReader(File in) {
    try {
        final Document document = createReader().read(in);
        return new Dom4JReader(document, getNameCoder());
    } catch (DocumentException e) {
        throw new StreamException(e);
    }
}
 
Example #23
Source File: ViewExtensionConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example #24
Source File: Dom4JDriver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #25
Source File: CGLIBEnhancedConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #26
Source File: JavaBeanConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 File: SystemClockConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 #28
Source File: DatabaseMetaConverter.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext arg1) {
  try {
    return new DatabaseMeta(reader.getValue());
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}
 
Example #29
Source File: XStream.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #30
Source File: VersionedExternalizable.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@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);
      }