You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/11/12 16:02:59 UTC
[isis] branch v2 updated: ISIS-2006: AnyIn/AnyOut/Try removed,
to revert todays changes
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new 25a20e6 ISIS-2006: AnyIn/AnyOut/Try removed, to revert todays changes
25a20e6 is described below
commit 25a20e6900cdb1d39c1dbe47fbaf11c317b9f6e1
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Nov 12 17:02:50 2018 +0100
ISIS-2006: AnyIn/AnyOut/Try removed, to revert todays changes
does not provide much of a value, so removed, in order to not bloat
applib
---
.../java/org/apache/isis/applib/anyio/AnyIn.java | 73 ---------------------
.../isis/applib/anyio/AnyIn_InputStream.java | 56 ----------------
.../java/org/apache/isis/applib/anyio/AnyOut.java | 68 --------------------
.../org/apache/isis/applib/anyio/AnyOutBuffer.java | 63 ------------------
.../isis/applib/anyio/AnyOut_OutputStream.java | 55 ----------------
.../java/org/apache/isis/applib/anyio/Try.java | 74 ----------------------
.../java/org/apache/isis/applib/util/JaxbUtil.java | 73 ---------------------
7 files changed, 462 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyIn.java b/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyIn.java
deleted file mode 100644
index 7e5d6dc..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyIn.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.applib.anyio;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-import org.apache.isis.commons.internal.base._Strings;
-
-/**
- * Universal data source.
- *
- * @since 2.0.0-M2
- */
-public interface AnyIn {
-
- // -- INTERFACE
-
- <T> Try<T> tryApplyInputStream(Function<InputStream, Try<T>> inputConsumer);
-
- // -- FACTORIES
-
- static AnyIn ofTryInputStream(final Supplier<Try<InputStream>> inputStreamSupplier) {
- return new AnyIn_InputStream(inputStreamSupplier);
- }
-
- static AnyIn ofFile(final File file) {
- return ofTryInputStream(()->{
- try {
- InputStream fis = new FileInputStream(file);
- return Try.success(fis);
- } catch (FileNotFoundException e) {
- return Try.failure(e);
- }
- });
- }
-
- static AnyIn ofInputStream(final Supplier<InputStream> inputStreamSupplier) {
- return ofTryInputStream(()->Try.success(inputStreamSupplier.get()));
- }
-
- static AnyIn ofBytes(final byte[] bytes) {
- return ofInputStream(()->new ByteArrayInputStream(bytes));
- }
-
- static AnyIn ofString(final String string, Charset charset) {
- return ofBytes(_Strings.toBytes(string, charset));
- }
-
-}
-
diff --git a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyIn_InputStream.java b/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyIn_InputStream.java
deleted file mode 100644
index 9d980e8..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyIn_InputStream.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.applib.anyio;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-class AnyIn_InputStream implements AnyIn {
-
- private final Supplier<Try<InputStream>> inputStreamSupplier;
-
- public AnyIn_InputStream(Supplier<Try<InputStream>> inputStreamSupplier) {
- this.inputStreamSupplier = inputStreamSupplier;
- }
-
- @Override
- public <T> Try<T> tryApplyInputStream(Function<InputStream, Try<T>> inputConsumer) {
-
- Try<InputStream> try_is = inputStreamSupplier.get();
- if(try_is.isFailure()) {
- return Try.failure(try_is.getFailure());
- }
-
- try(InputStream is = try_is.getResult()) {
-
- Try<T> _try = inputConsumer.apply(is);
- return _try;
-
- } catch (IOException e) {
-
- return Try.failure(e);
-
- }
-
- }
-
-}
-
diff --git a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOut.java b/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOut.java
deleted file mode 100644
index 5577b8c..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOut.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.applib.anyio;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-/**
- * Universal data sink.
- *
- * @since 2.0.0-M2
- */
-public interface AnyOut {
-
- // -- INTERFACE
-
- <T> Try<T> tryApplyOutputStream(Function<OutputStream, Try<T>> outputConsumer);
-
- // -- FACTORIES
-
- static AnyOut ofTryOutputStream(final Supplier<Try<OutputStream>> outputStreamSupplier) {
- return new AnyOut_OutputStream(outputStreamSupplier);
- }
-
- static AnyOut ofFile(final File file) {
- return ofTryOutputStream(()->{
- try {
- OutputStream fos = new FileOutputStream(file);
- return Try.success(fos);
- } catch (FileNotFoundException e) {
- return Try.failure(e);
- }
- });
- }
-
- static AnyOut ofOutputStream(final Supplier<OutputStream> outputStreamSupplier) {
- return ofTryOutputStream(()->Try.success(outputStreamSupplier.get()));
- }
-
- static AnyOutBuffer buffer(final int buffersize) {
- return new AnyOutBuffer(buffersize);
- }
-
- static AnyOutBuffer buffer16k() {
- return buffer(1024*16);
- }
-
-}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOutBuffer.java b/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOutBuffer.java
deleted file mode 100644
index eafa3cd..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOutBuffer.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.applib.anyio;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-import java.util.function.Function;
-
-import org.apache.isis.commons.internal.base._Strings;
-
-/**
- * Universal in-memory sink, that can be read from after having been written to.
- *
- * @since 2.0.0-M2
- */
-public class AnyOutBuffer implements AnyOut {
-
- private final ByteArrayOutputStream buffer;
- private Try<?> lastTry;
-
- AnyOutBuffer(int buffersize) {
- buffer = new ByteArrayOutputStream(buffersize);
- }
-
- @Override
- public <T> Try<T> tryApplyOutputStream(Function<OutputStream, Try<T>> outputConsumer) {
- if(lastTry!=null) {
- throw new IllegalStateException("Buffer was already written to.");
- }
- Try<T> _try = outputConsumer.apply(buffer);
- lastTry = _try;
- return _try;
- }
-
- public Try<byte[]> tryReadBytes(){
- if(lastTry!=null && lastTry.isFailure()) {
- return Try.failure(lastTry.getFailure());
- }
- return Try.success(buffer.toByteArray());
- }
-
- public Try<CharSequence> tryReadCharacters(Charset charset){
- return tryReadBytes().map(bytes->_Strings.ofBytes(bytes, charset));
- }
-
-}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOut_OutputStream.java b/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOut_OutputStream.java
deleted file mode 100644
index ae45bef..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/anyio/AnyOut_OutputStream.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.applib.anyio;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.function.Function;
-import java.util.function.Supplier;
-
-class AnyOut_OutputStream implements AnyOut {
-
- private final Supplier<Try<OutputStream>> outputStreamSupplier;
-
- public AnyOut_OutputStream(Supplier<Try<OutputStream>> outputStreamSupplier) {
- this.outputStreamSupplier = outputStreamSupplier;
- }
-
- @Override
- public <T> Try<T> tryApplyOutputStream(Function<OutputStream, Try<T>> outputConsumer) {
-
- Try<OutputStream> try_os = outputStreamSupplier.get();
- if(try_os.isFailure()) {
- return Try.failure(try_os.getFailure());
- }
-
- try(OutputStream os = try_os.getResult()) {
-
- Try<T> _try = outputConsumer.apply(os);
- return _try;
-
- } catch (IOException e) {
-
- return Try.failure(e);
-
- }
- }
-
-
-}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/anyio/Try.java b/core/applib/src/main/java/org/apache/isis/applib/anyio/Try.java
deleted file mode 100644
index 1a59caa..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/anyio/Try.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.applib.anyio;
-
-import java.util.function.Function;
-
-/**
- * Immutable data class, holds either a result or a failure object.
- *
- * @since 2.0.0-M2
- *
- * @param <T>
- */
-public final class Try<T> {
-
- private final T result;
- private final Exception failure;
-
- public static <T> Try<T> success(T result) {
- return new Try<>(result, null);
- }
-
- public static <T> Try<T> failure(Exception failure) {
- return new Try<>(null, failure);
- }
-
- private Try(T result, Exception failure) {
- this.result = result;
- this.failure = failure;
- }
-
- public boolean isSuccess() {
- return failure==null;
- }
-
- public boolean isFailure() {
- return failure!=null;
- }
-
- public Exception getFailure() {
- return failure;
- }
-
- public T getResult() {
- return result;
- }
-
- public void throwIfFailure() throws Exception {
- if(isFailure()) {
- throw failure;
- }
- }
-
- public <R> Try<R> map(Function<T, R> mapper) {
- return isSuccess() ? Try.success(mapper.apply(getResult())) : Try.failure(getFailure());
- }
-
-}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/util/JaxbUtil.java b/core/applib/src/main/java/org/apache/isis/applib/util/JaxbUtil.java
index fbdda51..e0515d6 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/util/JaxbUtil.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/util/JaxbUtil.java
@@ -28,11 +28,7 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
-import javax.xml.transform.stream.StreamSource;
-import org.apache.isis.applib.anyio.AnyIn;
-import org.apache.isis.applib.anyio.AnyOut;
-import org.apache.isis.applib.anyio.Try;
import org.apache.isis.commons.internal.base._Casts;
import org.apache.isis.commons.internal.collections._Maps;
import org.apache.isis.commons.internal.resources._Resources;
@@ -51,75 +47,6 @@ public class JaxbUtil {
private JaxbUtil(){}
- // -- READ - implemented for AnyIn
-
- /**
- * Tries to read the object from universal source {@code in}.
- * @param in - universal source {@link AnyIn}
- * @param dtoClass - object type to be read
- * @return
- */
- public static <T> Try<T> tryReadXml(AnyIn in, final Class<T> dtoClass) {
-
- return in.tryApplyInputStream(is->{
-
- try {
-
- Unmarshaller unmarshaller = jaxbContextFor(dtoClass).createUnmarshaller();
-
- StreamSource source = new StreamSource(is);
- T dto = unmarshaller.unmarshal(source, dtoClass).getValue();
-
- return Try.success(dto);
-
- } catch (JAXBException e) {
-
- return Try.failure(e);
- }
-
- });
-
- }
-
- // -- WRITE - implemented for AnyOut
-
- /**
- * Tries to write the object to universal sink {@code output}.
- * @param dto - object to be written
- * @param output - universal sink {@link AnyOut}
- * @return
- */
- public static <T> Try<Void> tryWriteXml(final T dto, AnyOut output) {
- return output.tryApplyOutputStream(os->{
-
- try {
-
- final Marshaller marshaller = jaxbContextFor(dto.getClass()).createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
- marshaller.marshal(dto, os);
- return Try.success(null);
-
- } catch (JAXBException e) {
-
- return Try.failure(e);
- }
-
- });
- }
-
- /**
- * Writes the object to universal sink {@code output}.
- * @param dto - object to be written
- * @param output - universal sink {@link AnyOut}
- * @throws Exception
- */
- public static <T> void writeXml(final T dto, AnyOut output) throws Exception {
-
- Try<Void> _try = tryWriteXml(dto, output);
- _try.throwIfFailure();
-
- }
-
// -- READ
public static <T> T fromXml(