/*
(non-Javadoc)

@see
com.impetus.kundera.property.PropertyAccessor#fromString(java.lang.String
)
960180
@Override
    public Date fromString(Class targetClass, String s)
    {

        if (s == null)
        {
            return null;
        }
        if (StringUtils.isNumeric(s))
        {
            return new Date(Long.parseLong(s));
        }
        Date d = Date.valueOf(s);
        return d;
    }
284330
public static UUID fromString( String name ) {
        UUID newUUID = new UUID();
        newUUID.uuidValue = name;
        return newUUID;
    }
1053328
@Override
    public String convertToString(T object) {
        try {
            return (String) toString.invoke(object);
        } catch (IllegalAccessException ex) {
            throw new IllegalStateException("Method is not accessible: " + toString);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() instanceof RuntimeException) {
                throw (RuntimeException) ex.getCause();
            }
            throw new RuntimeException(ex.getMessage(), ex.getCause());
        }
    }
455583
@Override
    public Character fromString(Class targetClass, String s)
    {
        try
        {
            if (s == null)
            {
                log.error("Can't convert String " + s + " to character");
                throw new PropertyAccessException("Can't convert String " + s + " to character");
            }

            Character c = null;
            if (s.length() == 1)
            {
                c = s.charAt(0);
            }
            else
            {
                c = Character.MIN_VALUE;
            }

            return c;
        }
        catch (NumberFormatException e)
        {
            log.error("Number format exception caught,Caused by {}.", e);
            throw new PropertyAccessException(e);
        }
    }
1116404
@Override
    public final String fromBytes(Class targetClass, byte[] bytes)
    {

        try
        {
            return bytes != null ? new String(bytes, Constants.CHARSET_UTF8) : null;
        }
        catch (UnsupportedEncodingException e)
        {
            log.error("Unsupported encoding exception, Caused by {}.", e);
            throw new PropertyAccessException(e);
        }

    }
699562
public static <T> T fromJsonString(String jsonString, Class<T> clazz) {
        return fromJsonString(jsonString, clazz, null);
    }
539021
@NonNull
    @Override
    public From from(@NonNull DataSource dataSource) {
        if (dataSource == null) {
            throw new IllegalArgumentException("dataSource cannot be null.");
        }
        return new From(this, dataSource);
    }
1222644
@Override
    public Timestamp fromBytes(Class targetClass, byte[] b)
    {

        // String s;
        // try
        // {
        // if(b == null)
        // {
        // return null;
        // }
        // s = new String(b, Constants.ENCODING);
        // }
        // catch (UnsupportedEncodingException e)
        // {
        // throw new PropertyAccessException(e);
        // }
        // return fromString(targetClass, s);
        try
        {
            if (b == null)
            {
                return null;
            }

            // In case date.getTime() is stored in DB.
            LongAccessor longAccessor = new LongAccessor();

            return new Timestamp(longAccessor.fromBytes(targetClass, b));
        }
        catch (Exception e)
        {
            log.error("Error occured, Caused by {}.", e);
            throw new PropertyAccessException(e);
        }
    }
1168449
public static function fromString(string $propertyString): self
    {
        $propertyData = @parse_ini_string($propertyString, true);
        if (false === $propertyData) {
            throw new \InvalidArgumentException(
                    'Property string contains errors and can not be parsed: '
                    . lastErrorMessage()->value()
            );
        }

        return new static($propertyData);
    }
654995
public String write(Object from) {
    try {
      StringWriter output = new StringWriter();
      write(from, output);
      
      return output.toString();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
639154
public String parseString(String name) {
        String property = getProperties().getProperty(name);
        if (property == null) {
            throw new NullPointerException();
        }
        return property;
    }
717187
@Override
    public Integer fromString(Class targetClass, String s)
    {
        try
        {
            if (s == null)
            {
                return null;
            }
            Integer i = new Integer(s);
            return i;
        }
        catch (NumberFormatException e)
        {
            log .error("Number format exception, Caused by {}.", e);
            throw new PropertyAccessException(e);
        }
    }
964549
@Override
    protected String convertToString(Object value) throws Throwable {
		Key key = (Key) value;
		return KeyFactory.keyToString(key);
    }
305701
public Expression getFromExpression() {
        if (_fromExpression == null && _from != null) {
            _fromExpression = ExpressionFactory.INSTANCE.create(_from, null, _propertyResolver);
        }
        return _fromExpression;
    }
541432
@Override
	public BubingJob fromString(final String s) {
		final URI url = BURL.parse(s);
		if (url != null && url.isAbsolute()) return new BubingJob(ByteArrayList.wrap(BURL.toByteArray(url)));
		throw new IllegalArgumentException();
	}
1168116
public Properties parsePropertiesString(String propertiesAsString) {
        final Properties p = new Properties();
        try (StringReader reader = new StringReader(propertiesAsString)) {
            p.load(reader);
        } catch (IOException e) {
            throw new IllegalArgumentException("Unable to parse .properties: " + propertiesAsString, e);
        }
        return p;
    }
1181660
@Pure
	protected XExpression fromString(String expression) {
		if (!Strings.isEmpty(expression)) {
			ResourceSet resourceSet = this.context.eResource().getResourceSet();
			URI uri = computeUnusedUri(resourceSet);
			Resource resource = getResourceFactory().createResource(uri);
			resourceSet.getResources().add(resource);
			try (StringInputStream is = new StringInputStream(generateExpressionCode(expression))) {
				resource.load(is, null);
				SarlScript script = resource.getContents().isEmpty() ? null : (SarlScript) resource.getContents().get(0);
				SarlEvent topElement = (SarlEvent) script.getXtendTypes().get(0);
				SarlField member = (SarlField) topElement.getMembers().get(0);
				return member.getInitialValue();
			} catch (Throwable exception) {
				throw new RuntimeException(exception);
			} finally {
				resourceSet.getResources().remove(resource);
			}
		}
		throw new IllegalArgumentException("not a valid expression");
	}