LightJason - AgentSpeak(L++)
CXMLObject.java
Go to the documentation of this file.
1 /*
2  * @cond LICENSE
3  * ######################################################################################
4  * # LGPL License #
5  * # #
6  * # This file is part of the LightJason AgentSpeak(L++) #
7  * # Copyright (c) 2015-19, LightJason (info@lightjason.org) #
8  * # This program is free software: you can redistribute it and/or modify #
9  * # it under the terms of the GNU Lesser General Public License as #
10  * # published by the Free Software Foundation, either version 3 of the #
11  * # License, or (at your option) any later version. #
12  * # #
13  * # This program is distributed in the hope that it will be useful, #
14  * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16  * # GNU Lesser General Public License for more details. #
17  * # #
18  * # You should have received a copy of the GNU Lesser General Public License #
19  * # along with this program. If not, see http://www.gnu.org/licenses/ #
20  * ######################################################################################
21  * @endcond
22  */
23 
24 package org.lightjason.agentspeak.action.builtin.web.rest;
25 
31 
32 import javax.annotation.Nonnull;
33 import java.io.IOException;
34 import java.util.List;
35 import java.util.Map;
36 
37 
48 public class CXMLObject extends IBaseRest
49 {
53  private static final long serialVersionUID = 8156192343303737293L;
54 
58  public CXMLObject()
59  {
60  super( 3 );
61  }
62 
63  @Nonnull
64  @Override
65  public final IFuzzyValue<Boolean> execute( final boolean p_parallel, @Nonnull final IContext p_context,
66  @Nonnull final List<ITerm> p_argument, @Nonnull final List<ITerm> p_return
67  )
68  {
69  try
70  {
71  final Map<String, ?> l_data = IBaseRest.xml( p_argument.get( 0 ).<String>raw() );
72  p_return.add(
73  p_argument.size() == 2
74  ? CLiteral.from( p_argument.get( p_argument.size() - 1 ).<String>raw(), flatterm( l_data ) )
76  p_argument.stream().skip( 1 ).map( ITerm::<String>raw ),
77  flatterm( l_data )
78  )
79  );
80 
81  return CFuzzyValue.from( true );
82  }
83  catch ( final IOException l_exception )
84  {
85  return CFuzzyValue.from( false );
86  }
87  }
88 }
static Stream< ITerm > flatterm( @Nullable final Object p_object)
converts an object into a term stream
Definition: IBaseWeb.java:178
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
static Map< String, ?> xml( @Nonnull final String p_url)
reads a xml structure from an url
Definition: IBaseRest.java:98
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
Definition: CXMLObject.java:65
static ITerm baseliteral( @Nonnull final Stream< String > p_functor, @Nonnull final Stream< ITerm > p_values)
creates a literal structure from a stream of string elements, the string stream will be build in a tr...
Definition: IBaseWeb.java:159
action to call a restful webservice with XML data.
Definition: CXMLObject.java:48
execution context with local data
Definition: IContext.java:42
result for an immutable fuzzy value
default generic literal class for agent beliefs a literal consists of a functor, an optional list of ...
Definition: CLiteral.java:64
static ILiteral from( @Nonnull final String p_functor, @Nullable final ITerm... p_values)
factory
Definition: CLiteral.java:161
base class to read data from the restful service
Definition: IBaseRest.java:42