Java Code Examples for com.thoughtworks.xstream.io.HierarchicalStreamReader#getAttribute()

The following examples show how to use com.thoughtworks.xstream.io.HierarchicalStreamReader#getAttribute() . 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: StringKeyMapConverter.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void unmarshalStringKey(HierarchicalStreamReader reader, UnmarshallingContext context, Map map, String key) {
    String type = reader.getAttribute("type");
    Object value;
    if (type==null && reader.hasMoreChildren()) {
        reader.moveDown();
        value = readItem(reader, context, map);
        reader.moveUp();
    } else {
        Class typeC = type!=null ? mapper().realClass(type) : String.class;
        try {
            value = TypeCoercions.coerce(reader.getValue(), typeC);
        } catch (Exception e) {
            log.warn("FAILED to coerce "+reader.getValue()+" to "+typeC+": "+e);
            throw Exceptions.propagate(e);
        }
    }
    map.put(key, value);
}
 
Example 2
Source File: ModelSerializer.java    From mql-editor with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Object unmarshal( HierarchicalStreamReader reader, UnmarshallingContext context ) {
  reader.moveDown();
  Condition condition = new Condition();
  String combinationType = reader.getAttribute( "combinationType" );
  condition.setCombinationType( StringUtils.isNotEmpty( combinationType ) ? CombinationType
      .getByName( combinationType ) : null );
  String aggType = reader.getAttribute( "selectedAggType" );
  condition.setSelectedAggType( StringUtils.isNotEmpty( aggType ) ? AggType.valueOf( aggType ) : null );
  condition.setOperator( Operator.parse( reader.getAttribute( "operator" ) ) );
  condition.setDefaultValue( reader.getAttribute( "defaultValue" ) );
  condition.setValue( reader.getAttribute( "value" ) );
  reader.moveDown();
  Column col = (Column) context.convertAnother( condition, Column.class );
  reader.moveUp();
  condition.setColumn( col );
  reader.moveUp();

  return condition;
}
 
Example 3
Source File: FileDocumentReferenceConverter.java    From depan with Apache License 2.0 6 votes vote down vote up
/**
 * {@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) {

  reader.moveDown();
  String docPath = reader.getAttribute(DOC_PATH_ATTR);
  reader.moveUp();

  IContainer project =
      PropertyDocumentReferenceContext.getProjectSource(context);
  IWorkspaceRoot wkspRoot =  project.getWorkspace().getRoot();
  IFile docFile = PlatformTools.buildResourceFile(wkspRoot, docPath);
  PropertyDocument<?> doc = 
      ResourceDocumentConfigRegistry.loadRegistryResourceDocument(docFile);
  return FileDocumentReference.buildFileReference(docFile, doc);
}
 
Example 4
Source File: PolygonConverter.java    From Digital with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) {
    String path = reader.getAttribute("path");
    boolean evenOdd = Boolean.parseBoolean(reader.getAttribute("evenOdd"));
    final Polygon polygon = Polygon.createFromPath(path);
    if (polygon != null)
        polygon.setEvenOdd(evenOdd);
    return polygon;
}
 
Example 5
Source File: EdgeConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
private Relation unmarshallRelation(
    HierarchicalStreamReader reader, UnmarshallingContext context) {
  String classAttribute =
      reader.getAttribute(mapper.aliasForAttribute("class"));
  Class<?> resultClass = mapper.realClass(classAttribute);
  Relation relation = (Relation) context.convertAnother(null, resultClass);
  return relation;
}
 
Example 6
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 7
Source File: Resources.java    From Digital with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 8
Source File: ConfigDescriptionParameterGroupConverter.java    From smarthome with Eclipse Public License 2.0 5 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 new ConfigDescriptionParameterGroup(name, context, advanced, label, description);
}
 
Example 9
Source File: XmlMementoSerializer.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private static String readClassAttribute(HierarchicalStreamReader reader, Mapper mapper) {
    String attributeName = mapper.aliasForSystemAttribute("resolves-to");
    String classAttribute = attributeName == null ? null : reader.getAttribute(attributeName);
    if (classAttribute == null) {
        attributeName = mapper.aliasForSystemAttribute("class");
        if (attributeName != null) {
            classAttribute = reader.getAttribute(attributeName);
        }
    }
    return classAttribute;
}
 
Example 10
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 11
Source File: LocaleConverter.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 )
{
    // Reading language
    final String language = reader.getAttribute ( "language" );

    // Reading country
    final String country = reader.getAttribute ( "country" );

    // Reading variant
    final String variant = reader.getAttribute ( "variant" );

    // Creating Text object
    return new Locale ( language, TextUtils.notEmpty ( country ) ? country : "", TextUtils.notEmpty ( variant ) ? variant : "" );
}
 
Example 12
Source File: MapConverter.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
/**
 * map的键值解析类
 *
 */
protected void populateMap(HierarchicalStreamReader reader, TreeMap map)
{
    while (reader.hasMoreChildren())
    {
        reader.moveDown();
        Object key = reader.getAttribute("key");
        Object value = reader.getAttribute("value");
        map.put(key, value);
        reader.moveUp();
    }
}
 
Example 13
Source File: MapConverter.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected Object readCompleteItem(HierarchicalStreamReader reader, UnmarshallingContext context, Object current) {
	if (reader.getAttribute("revision") != null) 
		return VersionedXmlDoc.unmarshall(reader);
	else 
		return super.readCompleteItem(reader, context, current);
}
 
Example 14
Source File: CollectionConverter.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected Object readCompleteItem(HierarchicalStreamReader reader, UnmarshallingContext context, Object current) {
	if (reader.getAttribute("revision") != null) 
		return VersionedXmlDoc.unmarshall(reader);
	else 
		return super.readCompleteItem(reader, context, current);
}
 
Example 15
Source File: XmlUtils.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns {@link Resource} based on the available attributes in the current node.
 *
 * @param reader  {@link HierarchicalStreamReader}
 * @param context {@link UnmarshallingContext}
 * @param mapper  {@link Mapper}
 * @return {@link Resource} based on the available attributes in the current node
 */
@NotNull
public static Resource readResource ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context,
                                      @NotNull final Mapper mapper )
{
    final Resource resource;
    final String path = reader.getAttribute ( "path" );
    final String contextBase = ( String ) context.get ( CONTEXT_BASE );
    if ( path != null )
    {
        final String completePath = contextBase != null ? NetUtils.joinUrlPaths ( contextBase, path ) : path;
        final String nearClass = reader.getAttribute ( "nearClass" );
        if ( nearClass != null )
        {
            resource = new ClassResource ( mapper.realClass ( nearClass ), completePath );
        }
        else
        {
            final String contextNearClass = ( String ) context.get ( CONTEXT_NEAR_CLASS );
            if ( contextNearClass != null )
            {
                resource = new ClassResource ( mapper.realClass ( contextNearClass ), completePath );
            }
            else
            {
                resource = new FileResource ( completePath );
            }
        }
    }
    else
    {
        final String url = reader.getAttribute ( "url" );
        if ( url != null )
        {
            final String completeURL = contextBase != null ? NetUtils.joinUrlPaths ( contextBase, url ) : url;
            resource = new UrlResource ( completeURL );
        }
        else
        {
            throw new UtilityException ( "Unable to find any Resource type in node attributes: " + reader.getNodeName () );
        }
    }
    return resource;
}
 
Example 16
Source File: Config.java    From elasticsearch-jenkins with MIT License 4 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) {
    final String url = hierarchicalStreamReader.getAttribute("url");
    final String indexName = hierarchicalStreamReader.getAttribute("indexName");
    final String typeName = hierarchicalStreamReader.getAttribute("typeName");
    return new Config(url, indexName, typeName);
}
 
Example 17
Source File: FilterCriteriaConverter.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String name = reader.getAttribute("name");
    String criteria = reader.getValue();
    return new FilterCriteria(name, criteria);
}
 
Example 18
Source File: XMLConfigurer.java    From oval with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AssertCheck unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
   final AssertCheck assertCheck = new AssertCheck();
   assertCheck.setLang(reader.getAttribute("lang"));
   assertCheck.setMessage(reader.getAttribute("message"));
   assertCheck.setErrorCode(reader.getAttribute("errorCode"));
   if (reader.getAttribute("severity") != null) {
      assertCheck.setSeverity(Integer.parseInt(reader.getAttribute("severity")));
   }
   if (reader.getAttribute("expr") != null) {
      assertCheck.setExpr(reader.getAttribute("expr"));
   }
   assertCheck.setTarget(reader.getAttribute("target"));
   assertCheck.setWhen(reader.getAttribute("when"));

   while (reader.hasMoreChildren()) {
      reader.moveDown();
      switch (reader.getNodeName()) {
         case "appliesTo":
            final List<ConstraintTarget> targets = new ArrayList<>(2);
            while (reader.hasMoreChildren()) {
               reader.moveDown();
               switch (reader.getNodeName()) {
                  case "constraintTarget":
                     targets.add(ConstraintTarget.valueOf(reader.getValue()));
                     break;
               }
               reader.moveUp();
            }
            assertCheck.setAppliesTo(targets.toArray(new ConstraintTarget[targets.size()]));
            break;
         case "expr":
            assertCheck.setExpr(reader.getValue());
            break;
         case "profiles":
            final List<String> profiles = new ArrayList<>(4);
            while (reader.hasMoreChildren()) {
               reader.moveDown();
               switch (reader.getNodeName()) {
                  case "string":
                     profiles.add(reader.getValue());
                     break;
               }
               reader.moveUp();
            }
            assertCheck.setProfiles(profiles.toArray(new String[profiles.size()]));
            break;
      }
      reader.moveUp();
   }

   onCheckInitialized(assertCheck);
   return assertCheck;
}
 
Example 19
Source File: PainterStyleConverter.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@NotNull
@Override
public Object unmarshal ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context )
{
    // Retrieving style identifier from context
    // It must be there at all times, whether this painter is read from style or another painter
    final String styleId = ( String ) context.get ( ComponentStyleConverter.CONTEXT_STYLE_ID );
    if ( styleId == null )
    {
        throw new StyleException ( "Context style identifier must be specified" );
    }

    // Retrieving overwrite policy
    final String ow = reader.getAttribute ( ComponentStyleConverter.OVERWRITE_ATTRIBUTE );
    final Boolean overwrite = ow != null ? Boolean.parseBoolean ( ow ) : null;

    // Retrieving default painter class based on parent painter and this node name
    // Basically we are reading this painter as a field of another painter here
    final Class<? extends Painter> parent = ( Class<? extends Painter> ) context.get ( ComponentStyleConverter.CONTEXT_PAINTER_CLASS );
    final Class<? extends Painter> defaultPainter = getDefaultPainter ( parent, reader.getNodeName () );

    // Unmarshalling painter class
    final Class<? extends Painter> painterClass =
            PainterStyleConverter.unmarshalPainterClass ( reader, context, mapper, defaultPainter, styleId );

    // Providing painter class to subsequent converters
    context.put ( ComponentStyleConverter.CONTEXT_PAINTER_CLASS, painterClass );

    // 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, styleId );

    // Creating painter style
    final PainterStyle painterStyle = new PainterStyle ();
    painterStyle.setOverwrite ( overwrite );
    painterStyle.setPainterClass ( painterClass.getCanonicalName () );
    painterStyle.setProperties ( painterProperties );

    // Cleaning up context
    context.put ( ComponentStyleConverter.CONTEXT_PAINTER_CLASS, parent );

    return painterStyle;
}
 
Example 20
Source File: SvgIconSourceConverter.java    From weblaf with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Returns preferred {@link SvgIcon} size or {@code null} if none specified in XML.
 *
 * @param reader  {@link HierarchicalStreamReader}
 * @param context {@link UnmarshallingContext}
 * @return preferred {@link SvgIcon} size or {@code null} if none specified in XML
 */
@Nullable
protected Dimension readSize ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context )
{
    final String size = reader.getAttribute ( SIZE_ATTRIBUTE );
    return size != null ? DimensionConverter.dimensionFromString ( size ) : null;
}