repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper";
import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import javax.annotation.Priority; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Priorities; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.core.Context; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME;
public void filter(ContainerRequestContext requestContext) { // return in case filter if registered twice if (requestContext.getProperty(PROPERTY_NAME) != null || matchesSkipPattern(requestContext)) { return; } if (tracer != null) { SpanContext parentSpanContext = parentSpanContext(requestContext); Span span = tracer.buildSpan(operationNameProvider.operationName(requestContext)) .ignoreActiveSpan() .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .asChildOf(parentSpanContext) .start(); if (spanDecorators != null) { for (ServerSpanDecorator decorator: spanDecorators) { decorator.decorateRequest(requestContext, span); } } // override operation name set by @Traced if (this.operationName != null) { span.setOperationName(operationName); } if (log.isLoggable(Level.FINEST)) { log.finest("Creating server span: " + operationName); }
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import javax.annotation.Priority; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Priorities; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.core.Context; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME; public void filter(ContainerRequestContext requestContext) { // return in case filter if registered twice if (requestContext.getProperty(PROPERTY_NAME) != null || matchesSkipPattern(requestContext)) { return; } if (tracer != null) { SpanContext parentSpanContext = parentSpanContext(requestContext); Span span = tracer.buildSpan(operationNameProvider.operationName(requestContext)) .ignoreActiveSpan() .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .asChildOf(parentSpanContext) .start(); if (spanDecorators != null) { for (ServerSpanDecorator decorator: spanDecorators) { decorator.decorateRequest(requestContext, span); } } // override operation name set by @Traced if (this.operationName != null) { span.setOperationName(operationName); } if (log.isLoggable(Level.FINEST)) { log.finest("Creating server span: " + operationName); }
requestContext.setProperty(PROPERTY_NAME, new SpanWrapper(span, tracer.activateSpan(span)));
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper";
import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import javax.annotation.Priority; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Priorities; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.core.Context; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME;
if (log.isLoggable(Level.FINEST)) { log.finest("Creating server span: " + operationName); } requestContext.setProperty(PROPERTY_NAME, new SpanWrapper(span, tracer.activateSpan(span))); } } /** * Returns a parent for a span created by this filter (jax-rs span). * The context from the active span takes precedence over context in the request, * but only if joinExistingActiveSpan has been set. * The current active span should be child-of extracted context and for example * created at a lower level e.g. jersey filter. */ private SpanContext parentSpanContext(ContainerRequestContext requestContext) { Span activeSpan = tracer.activeSpan(); if (activeSpan != null && this.joinExistingActiveSpan) { return activeSpan.context(); } else { return tracer.extract( Format.Builtin.HTTP_HEADERS, new ServerHeadersExtractTextMap(requestContext.getHeaders()) ); } } @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingFilter.java import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import javax.annotation.Priority; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Priorities; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.core.Context; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME; if (log.isLoggable(Level.FINEST)) { log.finest("Creating server span: " + operationName); } requestContext.setProperty(PROPERTY_NAME, new SpanWrapper(span, tracer.activateSpan(span))); } } /** * Returns a parent for a span created by this filter (jax-rs span). * The context from the active span takes precedence over context in the request, * but only if joinExistingActiveSpan has been set. * The current active span should be child-of extracted context and for example * created at a lower level e.g. jersey filter. */ private SpanContext parentSpanContext(ContainerRequestContext requestContext) { Span activeSpan = tracer.activeSpan(); if (activeSpan != null && this.joinExistingActiveSpan) { return activeSpan.context(); } else { return tracer.extract( Format.Builtin.HTTP_HEADERS, new ServerHeadersExtractTextMap(requestContext.getHeaders()) ); } } @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
SpanWrapper spanWrapper = CastUtils.cast(requestContext.getProperty(PROPERTY_NAME), SpanWrapper.class);
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/SpanFinishingFilter.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // }
import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.tag.Tags; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
package io.opentracing.contrib.jaxrs2.server; /** * Filter which finishes span after server processing. It is required to be registered. * * @author Pavol Loffay */ public class SpanFinishingFilter implements Filter { public SpanFinishingFilter() { } /** * @param tracer * @deprecated use no-args constructor */ @Deprecated public SpanFinishingFilter(Tracer tracer){ } @Override public void init(FilterConfig filterConfig) { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse)response; HttpServletRequest httpRequest = (HttpServletRequest)request; try { chain.doFilter(request, response); } catch (Exception ex) {
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/SpanFinishingFilter.java import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.tag.Tags; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; package io.opentracing.contrib.jaxrs2.server; /** * Filter which finishes span after server processing. It is required to be registered. * * @author Pavol Loffay */ public class SpanFinishingFilter implements Filter { public SpanFinishingFilter() { } /** * @param tracer * @deprecated use no-args constructor */ @Deprecated public SpanFinishingFilter(Tracer tracer){ } @Override public void init(FilterConfig filterConfig) { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse)response; HttpServletRequest httpRequest = (HttpServletRequest)request; try { chain.doFilter(request, response); } catch (Exception ex) {
SpanWrapper spanWrapper = getSpanWrapper(httpRequest);
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/SpanFinishingFilter.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // }
import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.tag.Tags; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse)response; HttpServletRequest httpRequest = (HttpServletRequest)request; try { chain.doFilter(request, response); } catch (Exception ex) { SpanWrapper spanWrapper = getSpanWrapper(httpRequest); if (spanWrapper != null) { Tags.HTTP_STATUS.set(spanWrapper.get(), httpResponse.getStatus()); addExceptionLogs(spanWrapper.get(), ex); } throw ex; } finally { SpanWrapper spanWrapper = getSpanWrapper(httpRequest); if (spanWrapper != null) { spanWrapper.getScope().close(); if (request.isAsyncStarted()) { request.getAsyncContext().addListener(new SpanFinisher(spanWrapper), request, response); } else { spanWrapper.finish(); } } } } private SpanWrapper getSpanWrapper(HttpServletRequest request) {
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/SpanFinishingFilter.java import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.tag.Tags; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse)response; HttpServletRequest httpRequest = (HttpServletRequest)request; try { chain.doFilter(request, response); } catch (Exception ex) { SpanWrapper spanWrapper = getSpanWrapper(httpRequest); if (spanWrapper != null) { Tags.HTTP_STATUS.set(spanWrapper.get(), httpResponse.getStatus()); addExceptionLogs(spanWrapper.get(), ex); } throw ex; } finally { SpanWrapper spanWrapper = getSpanWrapper(httpRequest); if (spanWrapper != null) { spanWrapper.getScope().close(); if (request.isAsyncStarted()) { request.getAsyncContext().addListener(new SpanFinisher(spanWrapper), request, response); } else { spanWrapper.finish(); } } } } private SpanWrapper getSpanWrapper(HttpServletRequest request) {
return CastUtils.cast(request.getAttribute(SpanWrapper.PROPERTY_NAME), SpanWrapper.class);
opentracing-contrib/java-jaxrs
opentracing-jaxrs2-itest/common/src/main/java/io/opentracing/contrib/jaxrs2/itest/common/rest/TestHandler.java
// Path: opentracing-jaxrs2-itest/common/src/main/java/io/opentracing/contrib/jaxrs2/itest/common/rest/InstrumentedRestApplication.java // public static class MappedException extends WebApplicationException { // }
import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.itest.common.rest.InstrumentedRestApplication.MappedException; import io.opentracing.noop.NoopTracer; import java.net.URI; import java.util.Random; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.client.Client; import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.container.Suspended; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.eclipse.microprofile.opentracing.Traced; import org.junit.Assert;
} catch (InterruptedException e) { e.printStackTrace(); } finally { // this exception is not propagated to AsyncListener asyncResponse.resume(new RuntimeException("asyncError")); } } }).start(); } @GET @Path("/redirect") public Response redirect(@Context HttpServletRequest request) { assertActiveSpan(); String url = String.format("localhost:%d/%s/hello/1", request.getLocalPort(), request.getContextPath()).replace("//", "/"); return Response.seeOther(URI.create("http://" + url)).build(); } @GET @Path("/exception") public Response exception(@Context HttpServletRequest request) { assertActiveSpan(); throw new IllegalStateException("error"); } @GET @Path("/mappedException") public Response customException(@Context HttpServletRequest request) { assertActiveSpan();
// Path: opentracing-jaxrs2-itest/common/src/main/java/io/opentracing/contrib/jaxrs2/itest/common/rest/InstrumentedRestApplication.java // public static class MappedException extends WebApplicationException { // } // Path: opentracing-jaxrs2-itest/common/src/main/java/io/opentracing/contrib/jaxrs2/itest/common/rest/TestHandler.java import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.itest.common.rest.InstrumentedRestApplication.MappedException; import io.opentracing.noop.NoopTracer; import java.net.URI; import java.util.Random; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.client.Client; import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.container.Suspended; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.eclipse.microprofile.opentracing.Traced; import org.junit.Assert; } catch (InterruptedException e) { e.printStackTrace(); } finally { // this exception is not propagated to AsyncListener asyncResponse.resume(new RuntimeException("asyncError")); } } }).start(); } @GET @Path("/redirect") public Response redirect(@Context HttpServletRequest request) { assertActiveSpan(); String url = String.format("localhost:%d/%s/hello/1", request.getLocalPort(), request.getContextPath()).replace("//", "/"); return Response.seeOther(URI.create("http://" + url)).build(); } @GET @Path("/exception") public Response exception(@Context HttpServletRequest request) { assertActiveSpan(); throw new IllegalStateException("error"); } @GET @Path("/mappedException") public Response customException(@Context HttpServletRequest request) { assertActiveSpan();
throw new MappedException();
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/serialization/TracingInterceptor.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // }
import io.opentracing.References; import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.noop.NoopSpan; import io.opentracing.tag.Tags; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Objects; import javax.ws.rs.WebApplicationException; import javax.ws.rs.ext.InterceptorContext; import javax.ws.rs.ext.ReaderInterceptor; import javax.ws.rs.ext.ReaderInterceptorContext; import javax.ws.rs.ext.WriterInterceptor; import javax.ws.rs.ext.WriterInterceptorContext;
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { Span span = buildSpan(context, "serialize"); try (Scope scope = tracer.activateSpan(span)) { decorateWrite(context, span); context.proceed(); } catch (Exception e) { Tags.ERROR.set(span, true); throw e; } finally { span.finish(); } } /** * Client requests : * <ul> * <li>Serialization of request body happens between the tracing filter invocation so we can use child_of.</li> * <li>Deserialization happens after the request is processed by the client filter therefore we can use follows_from only.</li> * </ul> * Server requests : * <ul> * <li>Deserialization happens between the span in the server filter is started and finished so we can use child_of.</li> * <li>Serialization of response entity happens after the server span if finished so we can use only follows_from.</li> * </ul> * @param context Used to retrieve the current span wrapper created by the jax-rs request filter. * @param operationName "serialize" or "deserialize" depending on the context * @return a noop span is no span context is registered in the context. Otherwise a new span related to the current on retrieved from the context. */ private Span buildSpan(InterceptorContext context, String operationName) {
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/serialization/TracingInterceptor.java import io.opentracing.References; import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.noop.NoopSpan; import io.opentracing.tag.Tags; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Objects; import javax.ws.rs.WebApplicationException; import javax.ws.rs.ext.InterceptorContext; import javax.ws.rs.ext.ReaderInterceptor; import javax.ws.rs.ext.ReaderInterceptorContext; import javax.ws.rs.ext.WriterInterceptor; import javax.ws.rs.ext.WriterInterceptorContext; public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { Span span = buildSpan(context, "serialize"); try (Scope scope = tracer.activateSpan(span)) { decorateWrite(context, span); context.proceed(); } catch (Exception e) { Tags.ERROR.set(span, true); throw e; } finally { span.finish(); } } /** * Client requests : * <ul> * <li>Serialization of request body happens between the tracing filter invocation so we can use child_of.</li> * <li>Deserialization happens after the request is processed by the client filter therefore we can use follows_from only.</li> * </ul> * Server requests : * <ul> * <li>Deserialization happens between the span in the server filter is started and finished so we can use child_of.</li> * <li>Serialization of response entity happens after the server span if finished so we can use only follows_from.</li> * </ul> * @param context Used to retrieve the current span wrapper created by the jax-rs request filter. * @param operationName "serialize" or "deserialize" depending on the context * @return a noop span is no span context is registered in the context. Otherwise a new span related to the current on retrieved from the context. */ private Span buildSpan(InterceptorContext context, String operationName) {
final SpanWrapper spanWrapper = findSpan(context);
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerSpanDecorator.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/URIUtils.java // public class URIUtils { // private URIUtils() {} // // /** // * Returns path of given URI. If the first character of path is '/' then it is removed. // * // * @param uri // * @return path or null // */ // public static String path(URI uri) { // String path = uri.getPath(); // if (path != null && path.startsWith("/")) { // path = path.substring(1); // } // // return path; // } // // /** // * Returns string representation of supplied URL. // * // * @param uri // * @return string URL or null // */ // public static String url(URI uri) { // String urlStr = null; // try { // URL url = uri.toURL(); // urlStr = url.toString(); // } catch (MalformedURLException e) { // // ignoring returning null // } // // return urlStr; // } // }
import io.opentracing.Span; import io.opentracing.contrib.jaxrs2.internal.URIUtils; import io.opentracing.tag.Tags; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext;
package io.opentracing.contrib.jaxrs2.server; /** * @author Pavol Loffay */ public interface ServerSpanDecorator { /** * Decorate span by incoming object. * * @param requestContext * @param span */ void decorateRequest(ContainerRequestContext requestContext, Span span); /** * Decorate spans by outgoing object. * * @param responseContext * @param span */ void decorateResponse(ContainerResponseContext responseContext, Span span); /** * Adds standard tags: {@link io.opentracing.tag.Tags#SPAN_KIND}, * {@link io.opentracing.tag.Tags#HTTP_METHOD}, {@link io.opentracing.tag.Tags#HTTP_URL} and * {@link io.opentracing.tag.Tags#HTTP_STATUS} */ ServerSpanDecorator STANDARD_TAGS = new ServerSpanDecorator() { @Override public void decorateRequest(ContainerRequestContext requestContext, Span span) { Tags.COMPONENT.set(span, "jaxrs"); Tags.HTTP_METHOD.set(span, requestContext.getMethod());
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/URIUtils.java // public class URIUtils { // private URIUtils() {} // // /** // * Returns path of given URI. If the first character of path is '/' then it is removed. // * // * @param uri // * @return path or null // */ // public static String path(URI uri) { // String path = uri.getPath(); // if (path != null && path.startsWith("/")) { // path = path.substring(1); // } // // return path; // } // // /** // * Returns string representation of supplied URL. // * // * @param uri // * @return string URL or null // */ // public static String url(URI uri) { // String urlStr = null; // try { // URL url = uri.toURL(); // urlStr = url.toString(); // } catch (MalformedURLException e) { // // ignoring returning null // } // // return urlStr; // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerSpanDecorator.java import io.opentracing.Span; import io.opentracing.contrib.jaxrs2.internal.URIUtils; import io.opentracing.tag.Tags; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; package io.opentracing.contrib.jaxrs2.server; /** * @author Pavol Loffay */ public interface ServerSpanDecorator { /** * Decorate span by incoming object. * * @param requestContext * @param span */ void decorateRequest(ContainerRequestContext requestContext, Span span); /** * Decorate spans by outgoing object. * * @param responseContext * @param span */ void decorateResponse(ContainerResponseContext responseContext, Span span); /** * Adds standard tags: {@link io.opentracing.tag.Tags#SPAN_KIND}, * {@link io.opentracing.tag.Tags#HTTP_METHOD}, {@link io.opentracing.tag.Tags#HTTP_URL} and * {@link io.opentracing.tag.Tags#HTTP_STATUS} */ ServerSpanDecorator STANDARD_TAGS = new ServerSpanDecorator() { @Override public void decorateRequest(ContainerRequestContext requestContext, Span span) { Tags.COMPONENT.set(span, "jaxrs"); Tags.HTTP_METHOD.set(span, requestContext.getMethod());
String url = URIUtils.url(requestContext.getUriInfo().getRequestUri());
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/client/ClientSpanDecorator.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/URIUtils.java // public class URIUtils { // private URIUtils() {} // // /** // * Returns path of given URI. If the first character of path is '/' then it is removed. // * // * @param uri // * @return path or null // */ // public static String path(URI uri) { // String path = uri.getPath(); // if (path != null && path.startsWith("/")) { // path = path.substring(1); // } // // return path; // } // // /** // * Returns string representation of supplied URL. // * // * @param uri // * @return string URL or null // */ // public static String url(URI uri) { // String urlStr = null; // try { // URL url = uri.toURL(); // urlStr = url.toString(); // } catch (MalformedURLException e) { // // ignoring returning null // } // // return urlStr; // } // }
import io.opentracing.Span; import io.opentracing.contrib.jaxrs2.internal.URIUtils; import io.opentracing.tag.Tags; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientResponseContext;
package io.opentracing.contrib.jaxrs2.client; /** * @author Pavol Loffay */ public interface ClientSpanDecorator { /** * Decorate get by incoming object. * * @param requestContext * @param span */ void decorateRequest(ClientRequestContext requestContext, Span span); /** * Decorate spans by outgoing object. * * @param responseContext * @param span */ void decorateResponse(ClientResponseContext responseContext, Span span); /** * Adds standard tags: {@link io.opentracing.tag.Tags#SPAN_KIND}, * {@link io.opentracing.tag.Tags#PEER_HOSTNAME}, {@link io.opentracing.tag.Tags#PEER_PORT}, * {@link io.opentracing.tag.Tags#HTTP_METHOD}, {@link io.opentracing.tag.Tags#HTTP_URL} and * {@link io.opentracing.tag.Tags#HTTP_STATUS} */ ClientSpanDecorator STANDARD_TAGS = new ClientSpanDecorator() { @Override public void decorateRequest(ClientRequestContext requestContext, Span span) { Tags.COMPONENT.set(span, "jaxrs"); Tags.PEER_HOSTNAME.set(span, requestContext.getUri().getHost()); Tags.PEER_PORT.set(span, requestContext.getUri().getPort()); Tags.HTTP_METHOD.set(span, requestContext.getMethod());
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/URIUtils.java // public class URIUtils { // private URIUtils() {} // // /** // * Returns path of given URI. If the first character of path is '/' then it is removed. // * // * @param uri // * @return path or null // */ // public static String path(URI uri) { // String path = uri.getPath(); // if (path != null && path.startsWith("/")) { // path = path.substring(1); // } // // return path; // } // // /** // * Returns string representation of supplied URL. // * // * @param uri // * @return string URL or null // */ // public static String url(URI uri) { // String urlStr = null; // try { // URL url = uri.toURL(); // urlStr = url.toString(); // } catch (MalformedURLException e) { // // ignoring returning null // } // // return urlStr; // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/client/ClientSpanDecorator.java import io.opentracing.Span; import io.opentracing.contrib.jaxrs2.internal.URIUtils; import io.opentracing.tag.Tags; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientResponseContext; package io.opentracing.contrib.jaxrs2.client; /** * @author Pavol Loffay */ public interface ClientSpanDecorator { /** * Decorate get by incoming object. * * @param requestContext * @param span */ void decorateRequest(ClientRequestContext requestContext, Span span); /** * Decorate spans by outgoing object. * * @param responseContext * @param span */ void decorateResponse(ClientResponseContext responseContext, Span span); /** * Adds standard tags: {@link io.opentracing.tag.Tags#SPAN_KIND}, * {@link io.opentracing.tag.Tags#PEER_HOSTNAME}, {@link io.opentracing.tag.Tags#PEER_PORT}, * {@link io.opentracing.tag.Tags#HTTP_METHOD}, {@link io.opentracing.tag.Tags#HTTP_URL} and * {@link io.opentracing.tag.Tags#HTTP_STATUS} */ ClientSpanDecorator STANDARD_TAGS = new ClientSpanDecorator() { @Override public void decorateRequest(ClientRequestContext requestContext, Span span) { Tags.COMPONENT.set(span, "jaxrs"); Tags.PEER_HOSTNAME.set(span, requestContext.getUri().getHost()); Tags.PEER_PORT.set(span, requestContext.getUri().getPort()); Tags.HTTP_METHOD.set(span, requestContext.getMethod());
String url = URIUtils.url(requestContext.getUri());
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingDynamicFeature.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/serialization/InterceptorSpanDecorator.java // public interface InterceptorSpanDecorator { // // /** // * Decorate spans by outgoing object. // * // * @param context // * @param span // */ // void decorateRead(InterceptorContext context, Span span); // // /** // * Decorate spans by outgoing object. // * // * @param context // * @param span // */ // void decorateWrite(InterceptorContext context, Span span); // // /** // * Adds tags: \"media.type\", \"entity.type\" // */ // InterceptorSpanDecorator STANDARD_TAGS = new InterceptorSpanDecorator() { // @Override // public void decorateRead(InterceptorContext context, Span span) { // span.setTag("media.type", context.getMediaType().toString()); // span.setTag("entity.type", context.getType().getName()); // } // // @Override // public void decorateWrite(InterceptorContext context, Span span) { // decorateRead(context, span); // } // }; // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/OperationNameProvider.java // class WildcardOperationName implements OperationNameProvider { // static class Builder implements OperationNameProvider.Builder { // @Override // public OperationNameProvider build(Class<?> clazz, Method method) { // String classPath = extractPath(clazz); // String methodPath = extractPath(method); // if (classPath == null || methodPath == null) { // for (Class<?> i: clazz.getInterfaces()) { // if (classPath == null) { // String intfPath = extractPath(i); // if (intfPath != null) { // classPath = intfPath; // } // } // if (methodPath == null) { // for (Method m: i.getMethods()) { // if (Objects.equals(m.getName(), method.getName()) && Arrays.deepEquals(m.getParameterTypes(), method.getParameterTypes())) { // methodPath = extractPath(m); // } // } // } // } // } // return new WildcardOperationName(classPath == null ? "" : classPath, methodPath == null ? "" : methodPath); // } // private static String extractPath(AnnotatedElement element) { // Path path = element.getAnnotation(Path.class); // if (path != null) { // return path.value(); // } // return null; // } // } // // private final String path; // // WildcardOperationName(String clazz, String method) { // if (clazz.isEmpty() || clazz.charAt(0) != '/') { // clazz = "/" + clazz; // } // if (clazz.endsWith("/")) { // clazz = clazz.substring(0, clazz.length() - 1); // } // if (method.isEmpty() || method.charAt(0) != '/') { // method = "/" + method; // } // this.path = clazz + method; // } // // @Override // public String operationName(ContainerRequestContext requestContext) { // return requestContext.getMethod() + ":" + path; // } // // public static Builder newBuilder() { // return new Builder(); // } // }
import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.serialization.InterceptorSpanDecorator; import io.opentracing.contrib.jaxrs2.server.OperationNameProvider.WildcardOperationName; import io.opentracing.util.GlobalTracer; import org.eclipse.microprofile.opentracing.Traced; import javax.ws.rs.Priorities; import javax.ws.rs.container.DynamicFeature; import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.FeatureContext; import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern;
protected Traced closestTracedAnnotation(ResourceInfo resourceInfo) { Traced tracedAnnotation = resourceInfo.getResourceMethod().getAnnotation(Traced.class); if (tracedAnnotation == null) { tracedAnnotation = resourceInfo.getResourceClass().getAnnotation(Traced.class); } return tracedAnnotation; } protected boolean tracingDisabled(ResourceInfo resourceInfo) { Traced traced = closestTracedAnnotation(resourceInfo); return traced == null ? !builder.allTraced : !traced.value(); } protected String operationName(ResourceInfo resourceInfo) { Traced traced = closestTracedAnnotation(resourceInfo); return traced != null && !traced.operationName().isEmpty() ? traced.operationName() : null; } /** * Builder for creating JAX-RS dynamic feature for tracing server requests. * * By default span's operation name is HTTP method and span is decorated with * {@link ServerSpanDecorator#STANDARD_TAGS} which adds standard tags. * If you want to set different span name provide custom span decorator {@link ServerSpanDecorator}. */ public static class Builder { private final Tracer tracer; private boolean allTraced; private List<ServerSpanDecorator> spanDecorators;
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/serialization/InterceptorSpanDecorator.java // public interface InterceptorSpanDecorator { // // /** // * Decorate spans by outgoing object. // * // * @param context // * @param span // */ // void decorateRead(InterceptorContext context, Span span); // // /** // * Decorate spans by outgoing object. // * // * @param context // * @param span // */ // void decorateWrite(InterceptorContext context, Span span); // // /** // * Adds tags: \"media.type\", \"entity.type\" // */ // InterceptorSpanDecorator STANDARD_TAGS = new InterceptorSpanDecorator() { // @Override // public void decorateRead(InterceptorContext context, Span span) { // span.setTag("media.type", context.getMediaType().toString()); // span.setTag("entity.type", context.getType().getName()); // } // // @Override // public void decorateWrite(InterceptorContext context, Span span) { // decorateRead(context, span); // } // }; // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/OperationNameProvider.java // class WildcardOperationName implements OperationNameProvider { // static class Builder implements OperationNameProvider.Builder { // @Override // public OperationNameProvider build(Class<?> clazz, Method method) { // String classPath = extractPath(clazz); // String methodPath = extractPath(method); // if (classPath == null || methodPath == null) { // for (Class<?> i: clazz.getInterfaces()) { // if (classPath == null) { // String intfPath = extractPath(i); // if (intfPath != null) { // classPath = intfPath; // } // } // if (methodPath == null) { // for (Method m: i.getMethods()) { // if (Objects.equals(m.getName(), method.getName()) && Arrays.deepEquals(m.getParameterTypes(), method.getParameterTypes())) { // methodPath = extractPath(m); // } // } // } // } // } // return new WildcardOperationName(classPath == null ? "" : classPath, methodPath == null ? "" : methodPath); // } // private static String extractPath(AnnotatedElement element) { // Path path = element.getAnnotation(Path.class); // if (path != null) { // return path.value(); // } // return null; // } // } // // private final String path; // // WildcardOperationName(String clazz, String method) { // if (clazz.isEmpty() || clazz.charAt(0) != '/') { // clazz = "/" + clazz; // } // if (clazz.endsWith("/")) { // clazz = clazz.substring(0, clazz.length() - 1); // } // if (method.isEmpty() || method.charAt(0) != '/') { // method = "/" + method; // } // this.path = clazz + method; // } // // @Override // public String operationName(ContainerRequestContext requestContext) { // return requestContext.getMethod() + ":" + path; // } // // public static Builder newBuilder() { // return new Builder(); // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingDynamicFeature.java import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.serialization.InterceptorSpanDecorator; import io.opentracing.contrib.jaxrs2.server.OperationNameProvider.WildcardOperationName; import io.opentracing.util.GlobalTracer; import org.eclipse.microprofile.opentracing.Traced; import javax.ws.rs.Priorities; import javax.ws.rs.container.DynamicFeature; import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.FeatureContext; import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; protected Traced closestTracedAnnotation(ResourceInfo resourceInfo) { Traced tracedAnnotation = resourceInfo.getResourceMethod().getAnnotation(Traced.class); if (tracedAnnotation == null) { tracedAnnotation = resourceInfo.getResourceClass().getAnnotation(Traced.class); } return tracedAnnotation; } protected boolean tracingDisabled(ResourceInfo resourceInfo) { Traced traced = closestTracedAnnotation(resourceInfo); return traced == null ? !builder.allTraced : !traced.value(); } protected String operationName(ResourceInfo resourceInfo) { Traced traced = closestTracedAnnotation(resourceInfo); return traced != null && !traced.operationName().isEmpty() ? traced.operationName() : null; } /** * Builder for creating JAX-RS dynamic feature for tracing server requests. * * By default span's operation name is HTTP method and span is decorated with * {@link ServerSpanDecorator#STANDARD_TAGS} which adds standard tags. * If you want to set different span name provide custom span decorator {@link ServerSpanDecorator}. */ public static class Builder { private final Tracer tracer; private boolean allTraced; private List<ServerSpanDecorator> spanDecorators;
private List<InterceptorSpanDecorator> serializationSpanDecorators;
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingDynamicFeature.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/serialization/InterceptorSpanDecorator.java // public interface InterceptorSpanDecorator { // // /** // * Decorate spans by outgoing object. // * // * @param context // * @param span // */ // void decorateRead(InterceptorContext context, Span span); // // /** // * Decorate spans by outgoing object. // * // * @param context // * @param span // */ // void decorateWrite(InterceptorContext context, Span span); // // /** // * Adds tags: \"media.type\", \"entity.type\" // */ // InterceptorSpanDecorator STANDARD_TAGS = new InterceptorSpanDecorator() { // @Override // public void decorateRead(InterceptorContext context, Span span) { // span.setTag("media.type", context.getMediaType().toString()); // span.setTag("entity.type", context.getType().getName()); // } // // @Override // public void decorateWrite(InterceptorContext context, Span span) { // decorateRead(context, span); // } // }; // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/OperationNameProvider.java // class WildcardOperationName implements OperationNameProvider { // static class Builder implements OperationNameProvider.Builder { // @Override // public OperationNameProvider build(Class<?> clazz, Method method) { // String classPath = extractPath(clazz); // String methodPath = extractPath(method); // if (classPath == null || methodPath == null) { // for (Class<?> i: clazz.getInterfaces()) { // if (classPath == null) { // String intfPath = extractPath(i); // if (intfPath != null) { // classPath = intfPath; // } // } // if (methodPath == null) { // for (Method m: i.getMethods()) { // if (Objects.equals(m.getName(), method.getName()) && Arrays.deepEquals(m.getParameterTypes(), method.getParameterTypes())) { // methodPath = extractPath(m); // } // } // } // } // } // return new WildcardOperationName(classPath == null ? "" : classPath, methodPath == null ? "" : methodPath); // } // private static String extractPath(AnnotatedElement element) { // Path path = element.getAnnotation(Path.class); // if (path != null) { // return path.value(); // } // return null; // } // } // // private final String path; // // WildcardOperationName(String clazz, String method) { // if (clazz.isEmpty() || clazz.charAt(0) != '/') { // clazz = "/" + clazz; // } // if (clazz.endsWith("/")) { // clazz = clazz.substring(0, clazz.length() - 1); // } // if (method.isEmpty() || method.charAt(0) != '/') { // method = "/" + method; // } // this.path = clazz + method; // } // // @Override // public String operationName(ContainerRequestContext requestContext) { // return requestContext.getMethod() + ":" + path; // } // // public static Builder newBuilder() { // return new Builder(); // } // }
import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.serialization.InterceptorSpanDecorator; import io.opentracing.contrib.jaxrs2.server.OperationNameProvider.WildcardOperationName; import io.opentracing.util.GlobalTracer; import org.eclipse.microprofile.opentracing.Traced; import javax.ws.rs.Priorities; import javax.ws.rs.container.DynamicFeature; import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.FeatureContext; import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern;
return traced != null && !traced.operationName().isEmpty() ? traced.operationName() : null; } /** * Builder for creating JAX-RS dynamic feature for tracing server requests. * * By default span's operation name is HTTP method and span is decorated with * {@link ServerSpanDecorator#STANDARD_TAGS} which adds standard tags. * If you want to set different span name provide custom span decorator {@link ServerSpanDecorator}. */ public static class Builder { private final Tracer tracer; private boolean allTraced; private List<ServerSpanDecorator> spanDecorators; private List<InterceptorSpanDecorator> serializationSpanDecorators; private int priority; private int serializationPriority; private OperationNameProvider.Builder operationNameBuilder; private boolean traceSerialization; private String skipPattern; private boolean joinExistingActiveSpan; public Builder(Tracer tracer) { this.tracer = tracer; this.spanDecorators = Collections.singletonList(ServerSpanDecorator.STANDARD_TAGS); this.serializationSpanDecorators = Collections.singletonList(InterceptorSpanDecorator.STANDARD_TAGS); // by default do not use Priorities.AUTHENTICATION due to security concerns this.priority = Priorities.HEADER_DECORATOR; this.serializationPriority = Priorities.ENTITY_CODER; this.allTraced = true;
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/serialization/InterceptorSpanDecorator.java // public interface InterceptorSpanDecorator { // // /** // * Decorate spans by outgoing object. // * // * @param context // * @param span // */ // void decorateRead(InterceptorContext context, Span span); // // /** // * Decorate spans by outgoing object. // * // * @param context // * @param span // */ // void decorateWrite(InterceptorContext context, Span span); // // /** // * Adds tags: \"media.type\", \"entity.type\" // */ // InterceptorSpanDecorator STANDARD_TAGS = new InterceptorSpanDecorator() { // @Override // public void decorateRead(InterceptorContext context, Span span) { // span.setTag("media.type", context.getMediaType().toString()); // span.setTag("entity.type", context.getType().getName()); // } // // @Override // public void decorateWrite(InterceptorContext context, Span span) { // decorateRead(context, span); // } // }; // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/OperationNameProvider.java // class WildcardOperationName implements OperationNameProvider { // static class Builder implements OperationNameProvider.Builder { // @Override // public OperationNameProvider build(Class<?> clazz, Method method) { // String classPath = extractPath(clazz); // String methodPath = extractPath(method); // if (classPath == null || methodPath == null) { // for (Class<?> i: clazz.getInterfaces()) { // if (classPath == null) { // String intfPath = extractPath(i); // if (intfPath != null) { // classPath = intfPath; // } // } // if (methodPath == null) { // for (Method m: i.getMethods()) { // if (Objects.equals(m.getName(), method.getName()) && Arrays.deepEquals(m.getParameterTypes(), method.getParameterTypes())) { // methodPath = extractPath(m); // } // } // } // } // } // return new WildcardOperationName(classPath == null ? "" : classPath, methodPath == null ? "" : methodPath); // } // private static String extractPath(AnnotatedElement element) { // Path path = element.getAnnotation(Path.class); // if (path != null) { // return path.value(); // } // return null; // } // } // // private final String path; // // WildcardOperationName(String clazz, String method) { // if (clazz.isEmpty() || clazz.charAt(0) != '/') { // clazz = "/" + clazz; // } // if (clazz.endsWith("/")) { // clazz = clazz.substring(0, clazz.length() - 1); // } // if (method.isEmpty() || method.charAt(0) != '/') { // method = "/" + method; // } // this.path = clazz + method; // } // // @Override // public String operationName(ContainerRequestContext requestContext) { // return requestContext.getMethod() + ":" + path; // } // // public static Builder newBuilder() { // return new Builder(); // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/server/ServerTracingDynamicFeature.java import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.serialization.InterceptorSpanDecorator; import io.opentracing.contrib.jaxrs2.server.OperationNameProvider.WildcardOperationName; import io.opentracing.util.GlobalTracer; import org.eclipse.microprofile.opentracing.Traced; import javax.ws.rs.Priorities; import javax.ws.rs.container.DynamicFeature; import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.FeatureContext; import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; return traced != null && !traced.operationName().isEmpty() ? traced.operationName() : null; } /** * Builder for creating JAX-RS dynamic feature for tracing server requests. * * By default span's operation name is HTTP method and span is decorated with * {@link ServerSpanDecorator#STANDARD_TAGS} which adds standard tags. * If you want to set different span name provide custom span decorator {@link ServerSpanDecorator}. */ public static class Builder { private final Tracer tracer; private boolean allTraced; private List<ServerSpanDecorator> spanDecorators; private List<InterceptorSpanDecorator> serializationSpanDecorators; private int priority; private int serializationPriority; private OperationNameProvider.Builder operationNameBuilder; private boolean traceSerialization; private String skipPattern; private boolean joinExistingActiveSpan; public Builder(Tracer tracer) { this.tracer = tracer; this.spanDecorators = Collections.singletonList(ServerSpanDecorator.STANDARD_TAGS); this.serializationSpanDecorators = Collections.singletonList(InterceptorSpanDecorator.STANDARD_TAGS); // by default do not use Priorities.AUTHENTICATION due to security concerns this.priority = Priorities.HEADER_DECORATOR; this.serializationPriority = Priorities.ENTITY_CODER; this.allTraced = true;
this.operationNameBuilder = WildcardOperationName.newBuilder();
opentracing-contrib/java-jaxrs
opentracing-jaxrs2-itest/jersey/src/test/java/io/opentracing/contrib/jaxrs2/itest/jersey/JerseyHelper.java
// Path: opentracing-jaxrs2-itest/common/src/main/java/io/opentracing/contrib/jaxrs2/itest/common/rest/InstrumentedRestApplication.java // public class InstrumentedRestApplication extends Application { // // private Client client; // private Tracer tracer; // private ServerTracingDynamicFeature serverTracingFeature; // // public InstrumentedRestApplication(@Context ServletContext context) { // this.serverTracingFeature = (ServerTracingDynamicFeature) context.getAttribute( // AbstractJettyTest.SERVER_TRACING_FEATURE); // this.client = (Client) context.getAttribute(AbstractJettyTest.CLIENT_ATTRIBUTE); // this.tracer = (Tracer) context.getAttribute(AbstractJettyTest.TRACER_ATTRIBUTE); // // if (serverTracingFeature == null || client == null || tracer == null) { // throw new IllegalArgumentException("Instrumented application is not initialized correctly. serverTracing:" // + serverTracingFeature + ", clientTracing: " + client); // } // } // // @Override // public Set<Object> getSingletons() { // Set<Object> objects = new HashSet<>(); // // objects.add(serverTracingFeature); // objects.add(new TestHandler(tracer, client)); // objects.add(new DisabledTestHandler(tracer)); // objects.add(new ServicesImpl()); // objects.add(new ServicesImplOverrideClassPath()); // objects.add(new ServicesImplOverrideMethodPath()); // objects.add(new DenyFilteredFeature()); // objects.add(new MappedExceptionMapper()); // // return Collections.unmodifiableSet(objects); // } // // /** // * A dynamic feature that introduces a request filter denying all requests to "filtered" // * endpoints. // * // * @author Maxime Petazzoni // */ // private static final class DenyFilteredFeature implements DynamicFeature { // @Override // public void configure(ResourceInfo resourceInfo, FeatureContext context) { // context.register(new ContainerRequestFilter() { // @Override // public void filter(ContainerRequestContext requestContext) throws IOException { // if (requestContext.getUriInfo().getPath().endsWith("filtered")) { // throw new ForbiddenException(); // } // } // }, Priorities.AUTHORIZATION); // } // } // // public static class MappedException extends WebApplicationException { // } // // private static class MappedExceptionMapper implements ExceptionMapper<MappedException> { // @Override // public Response toResponse(MappedException exception) { // return Response.status(405).build(); // } // } // }
import io.opentracing.contrib.jaxrs2.itest.common.rest.InstrumentedRestApplication; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder;
package io.opentracing.contrib.jaxrs2.itest.jersey; /** * @author Pavol Loffay */ public class JerseyHelper { private JerseyHelper() { } public static void initServletContext(ServletContextHandler context) { ServletHolder jerseyServlet = context.addServlet( org.glassfish.jersey.servlet.ServletContainer.class, "/*"); jerseyServlet.setInitOrder(0); jerseyServlet.setInitParameter(
// Path: opentracing-jaxrs2-itest/common/src/main/java/io/opentracing/contrib/jaxrs2/itest/common/rest/InstrumentedRestApplication.java // public class InstrumentedRestApplication extends Application { // // private Client client; // private Tracer tracer; // private ServerTracingDynamicFeature serverTracingFeature; // // public InstrumentedRestApplication(@Context ServletContext context) { // this.serverTracingFeature = (ServerTracingDynamicFeature) context.getAttribute( // AbstractJettyTest.SERVER_TRACING_FEATURE); // this.client = (Client) context.getAttribute(AbstractJettyTest.CLIENT_ATTRIBUTE); // this.tracer = (Tracer) context.getAttribute(AbstractJettyTest.TRACER_ATTRIBUTE); // // if (serverTracingFeature == null || client == null || tracer == null) { // throw new IllegalArgumentException("Instrumented application is not initialized correctly. serverTracing:" // + serverTracingFeature + ", clientTracing: " + client); // } // } // // @Override // public Set<Object> getSingletons() { // Set<Object> objects = new HashSet<>(); // // objects.add(serverTracingFeature); // objects.add(new TestHandler(tracer, client)); // objects.add(new DisabledTestHandler(tracer)); // objects.add(new ServicesImpl()); // objects.add(new ServicesImplOverrideClassPath()); // objects.add(new ServicesImplOverrideMethodPath()); // objects.add(new DenyFilteredFeature()); // objects.add(new MappedExceptionMapper()); // // return Collections.unmodifiableSet(objects); // } // // /** // * A dynamic feature that introduces a request filter denying all requests to "filtered" // * endpoints. // * // * @author Maxime Petazzoni // */ // private static final class DenyFilteredFeature implements DynamicFeature { // @Override // public void configure(ResourceInfo resourceInfo, FeatureContext context) { // context.register(new ContainerRequestFilter() { // @Override // public void filter(ContainerRequestContext requestContext) throws IOException { // if (requestContext.getUriInfo().getPath().endsWith("filtered")) { // throw new ForbiddenException(); // } // } // }, Priorities.AUTHORIZATION); // } // } // // public static class MappedException extends WebApplicationException { // } // // private static class MappedExceptionMapper implements ExceptionMapper<MappedException> { // @Override // public Response toResponse(MappedException exception) { // return Response.status(405).build(); // } // } // } // Path: opentracing-jaxrs2-itest/jersey/src/test/java/io/opentracing/contrib/jaxrs2/itest/jersey/JerseyHelper.java import io.opentracing.contrib.jaxrs2.itest.common.rest.InstrumentedRestApplication; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; package io.opentracing.contrib.jaxrs2.itest.jersey; /** * @author Pavol Loffay */ public class JerseyHelper { private JerseyHelper() { } public static void initServletContext(ServletContextHandler context) { ServletHolder jerseyServlet = context.addServlet( org.glassfish.jersey.servlet.ServletContainer.class, "/*"); jerseyServlet.setInitOrder(0); jerseyServlet.setInitParameter(
"javax.ws.rs.Application", InstrumentedRestApplication.class.getCanonicalName());
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/client/ClientTracingFilter.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // }
import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.noop.NoopScopeManager.NoopScope; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Priority; import javax.ws.rs.Priorities; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.ClientResponseContext; import javax.ws.rs.client.ClientResponseFilter; import org.eclipse.microprofile.opentracing.Traced;
package io.opentracing.contrib.jaxrs2.client; /** * @author Pavol Loffay */ @Priority(Priorities.HEADER_DECORATOR) public class ClientTracingFilter implements ClientRequestFilter, ClientResponseFilter { private static final Logger log = Logger.getLogger(ClientTracingFilter.class.getName()); private Tracer tracer; private List<ClientSpanDecorator> spanDecorators; public ClientTracingFilter(Tracer tracer, List<ClientSpanDecorator> spanDecorators) { this.tracer = tracer; this.spanDecorators = new ArrayList<>(spanDecorators); } @Override public void filter(ClientRequestContext requestContext) { if (tracingDisabled(requestContext)) { log.finest("Client tracing disabled"); return; } // in case filter is registered twice
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/client/ClientTracingFilter.java import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.noop.NoopScopeManager.NoopScope; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Priority; import javax.ws.rs.Priorities; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.ClientResponseContext; import javax.ws.rs.client.ClientResponseFilter; import org.eclipse.microprofile.opentracing.Traced; package io.opentracing.contrib.jaxrs2.client; /** * @author Pavol Loffay */ @Priority(Priorities.HEADER_DECORATOR) public class ClientTracingFilter implements ClientRequestFilter, ClientResponseFilter { private static final Logger log = Logger.getLogger(ClientTracingFilter.class.getName()); private Tracer tracer; private List<ClientSpanDecorator> spanDecorators; public ClientTracingFilter(Tracer tracer, List<ClientSpanDecorator> spanDecorators) { this.tracer = tracer; this.spanDecorators = new ArrayList<>(spanDecorators); } @Override public void filter(ClientRequestContext requestContext) { if (tracingDisabled(requestContext)) { log.finest("Client tracing disabled"); return; } // in case filter is registered twice
if (requestContext.getProperty(PROPERTY_NAME) != null) {
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/client/ClientTracingFilter.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // }
import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.noop.NoopScopeManager.NoopScope; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Priority; import javax.ws.rs.Priorities; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.ClientResponseContext; import javax.ws.rs.client.ClientResponseFilter; import org.eclipse.microprofile.opentracing.Traced;
package io.opentracing.contrib.jaxrs2.client; /** * @author Pavol Loffay */ @Priority(Priorities.HEADER_DECORATOR) public class ClientTracingFilter implements ClientRequestFilter, ClientResponseFilter { private static final Logger log = Logger.getLogger(ClientTracingFilter.class.getName()); private Tracer tracer; private List<ClientSpanDecorator> spanDecorators; public ClientTracingFilter(Tracer tracer, List<ClientSpanDecorator> spanDecorators) { this.tracer = tracer; this.spanDecorators = new ArrayList<>(spanDecorators); } @Override public void filter(ClientRequestContext requestContext) { if (tracingDisabled(requestContext)) { log.finest("Client tracing disabled"); return; } // in case filter is registered twice if (requestContext.getProperty(PROPERTY_NAME) != null) { return; } Tracer.SpanBuilder spanBuilder = tracer.buildSpan(requestContext.getMethod()) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/client/ClientTracingFilter.java import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.noop.NoopScopeManager.NoopScope; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Priority; import javax.ws.rs.Priorities; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.ClientResponseContext; import javax.ws.rs.client.ClientResponseFilter; import org.eclipse.microprofile.opentracing.Traced; package io.opentracing.contrib.jaxrs2.client; /** * @author Pavol Loffay */ @Priority(Priorities.HEADER_DECORATOR) public class ClientTracingFilter implements ClientRequestFilter, ClientResponseFilter { private static final Logger log = Logger.getLogger(ClientTracingFilter.class.getName()); private Tracer tracer; private List<ClientSpanDecorator> spanDecorators; public ClientTracingFilter(Tracer tracer, List<ClientSpanDecorator> spanDecorators) { this.tracer = tracer; this.spanDecorators = new ArrayList<>(spanDecorators); } @Override public void filter(ClientRequestContext requestContext) { if (tracingDisabled(requestContext)) { log.finest("Client tracing disabled"); return; } // in case filter is registered twice if (requestContext.getProperty(PROPERTY_NAME) != null) { return; } Tracer.SpanBuilder spanBuilder = tracer.buildSpan(requestContext.getMethod()) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
SpanContext parentSpanContext = CastUtils.cast(requestContext.getProperty(TracingProperties.CHILD_OF),
opentracing-contrib/java-jaxrs
opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/client/ClientTracingFilter.java
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // }
import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.noop.NoopScopeManager.NoopScope; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Priority; import javax.ws.rs.Priorities; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.ClientResponseContext; import javax.ws.rs.client.ClientResponseFilter; import org.eclipse.microprofile.opentracing.Traced;
if (requestContext.getProperty(PROPERTY_NAME) != null) { return; } Tracer.SpanBuilder spanBuilder = tracer.buildSpan(requestContext.getMethod()) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); SpanContext parentSpanContext = CastUtils.cast(requestContext.getProperty(TracingProperties.CHILD_OF), SpanContext.class); if (parentSpanContext != null) { spanBuilder.ignoreActiveSpan() .asChildOf(parentSpanContext); } /** * Do not create Scope - there is no way to deactivate it on UnknownHostException */ final Span span = spanBuilder.start(); if (spanDecorators != null) { for (ClientSpanDecorator decorator: spanDecorators) { decorator.decorateRequest(requestContext, span); } } if (log.isLoggable(Level.FINEST)) { log.finest("Starting client span"); } tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new ClientHeadersInjectTextMap(requestContext.getHeaders()));
// Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/CastUtils.java // public class CastUtils { // private static final Logger log = Logger.getLogger(CastUtils.class.getName()); // // private CastUtils() {} // // /** // * Casts given object to the given class. // * // * @param object // * @param clazz // * @param <T> // * @return casted object, or null if there is any error // */ // public static <T> T cast(Object object, Class<T> clazz) { // if (object == null || clazz == null) { // return null; // } // // try { // return clazz.cast(object); // } catch (ClassCastException ex) { // log.severe("Cannot cast to " + clazz.getName()); // return null; // } // } // } // // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/internal/SpanWrapper.java // public class SpanWrapper { // // public static final String PROPERTY_NAME = SpanWrapper.class.getName() + ".activeSpanWrapper"; // // private Scope scope; // private Span span; // private AtomicBoolean finished = new AtomicBoolean(); // // public SpanWrapper(Span span, Scope scope) { // this.span = span; // this.scope = scope; // // } // // public Span get() { // return span; // } // // public Scope getScope() { // return scope; // } // // public void finish() { // if (finished.compareAndSet(false, true)) { // span.finish(); // } // } // // public boolean isFinished() { // return finished.get(); // } // } // Path: opentracing-jaxrs2/src/main/java/io/opentracing/contrib/jaxrs2/client/ClientTracingFilter.java import static io.opentracing.contrib.jaxrs2.internal.SpanWrapper.PROPERTY_NAME; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.contrib.jaxrs2.internal.CastUtils; import io.opentracing.contrib.jaxrs2.internal.SpanWrapper; import io.opentracing.noop.NoopScopeManager.NoopScope; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Priority; import javax.ws.rs.Priorities; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.ClientResponseContext; import javax.ws.rs.client.ClientResponseFilter; import org.eclipse.microprofile.opentracing.Traced; if (requestContext.getProperty(PROPERTY_NAME) != null) { return; } Tracer.SpanBuilder spanBuilder = tracer.buildSpan(requestContext.getMethod()) .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT); SpanContext parentSpanContext = CastUtils.cast(requestContext.getProperty(TracingProperties.CHILD_OF), SpanContext.class); if (parentSpanContext != null) { spanBuilder.ignoreActiveSpan() .asChildOf(parentSpanContext); } /** * Do not create Scope - there is no way to deactivate it on UnknownHostException */ final Span span = spanBuilder.start(); if (spanDecorators != null) { for (ClientSpanDecorator decorator: spanDecorators) { decorator.decorateRequest(requestContext, span); } } if (log.isLoggable(Level.FINEST)) { log.finest("Starting client span"); } tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new ClientHeadersInjectTextMap(requestContext.getHeaders()));
requestContext.setProperty(PROPERTY_NAME, new SpanWrapper(span, new NoopScope() {
open-io/oio-api-java
src/main/java/io/openio/sds/models/LinkedServiceInfo.java
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import io.openio.sds.common.MoreObjects;
public String type() { return type; } public LinkedServiceInfo type(String type) { this.type = type; return this; } public String host() { return host; } public LinkedServiceInfo host(String host) { this.host = host; return this; } public String args() { return args; } public LinkedServiceInfo args(String args) { this.args = args; return this; } @Override public String toString(){
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/LinkedServiceInfo.java import io.openio.sds.common.MoreObjects; public String type() { return type; } public LinkedServiceInfo type(String type) { this.type = type; return this; } public String host() { return host; } public LinkedServiceInfo host(String host) { this.host = host; return this; } public String args() { return args; } public LinkedServiceInfo args(String args) { this.args = args; return this; } @Override public String toString(){
return MoreObjects.toStringHelper(this)
open-io/oio-api-java
src/main/java/io/openio/sds/common/JsonUtils.java
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/models/Position.java // public class Position { // // private static final Pattern POSITION_PATTERN = Pattern // .compile("^([\\d]+)(\\.([\\d]+))?$"); // // private int meta; // private int sub; // // private Position(int meta, int sub) { // this.meta = meta; // this.sub = sub; // } // // public static Position parse(String pos) { // Matcher m = POSITION_PATTERN.matcher(pos); // checkArgument(m.matches(), // String.format("Invalid position %s", pos)); // if (null == m.group(2)) // return simple(Integer.parseInt(m.group(1))); // return composed(Integer.parseInt(m.group(1)), // Integer.parseInt(m.group(3))); // } // // public static Position simple(int meta) { // checkArgument(0 <= meta, "Invalid position"); // return new Position(meta, -1); // } // // public static Position composed(int meta, int sub) { // checkArgument(0 <= meta, "Invalid meta position"); // checkArgument(0 <= sub, "Invalid sub position"); // return new Position(meta, sub); // } // // public int meta() { // return meta; // } // // public int sub() { // return sub; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder().append(meta); // if (-1 != sub) // sb.append(".").append(sub); // return sb.toString(); // } // // /** // * Returns negative, 0 or positive int if the position is lower, equals or // * higher than the specified one . // * <p> // * This method compares the meta position, if equals, // * it compares the sub position. // * // * @param pos // * the position to compare to // * @return negative, 0 or positive int if the position is lower, equals or // * higher than the specified one . // */ // public int compare(Position pos) { // if (meta == pos.meta()) return sub - pos.sub(); // else return meta - pos.meta(); // } // }
import static io.openio.sds.common.OioConstants.OIO_CHARSET; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; import java.util.Map; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import io.openio.sds.models.Position;
package io.openio.sds.common; /** * Gson utility class */ public class JsonUtils { private static final GsonBuilder builder = new GsonBuilder()
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/models/Position.java // public class Position { // // private static final Pattern POSITION_PATTERN = Pattern // .compile("^([\\d]+)(\\.([\\d]+))?$"); // // private int meta; // private int sub; // // private Position(int meta, int sub) { // this.meta = meta; // this.sub = sub; // } // // public static Position parse(String pos) { // Matcher m = POSITION_PATTERN.matcher(pos); // checkArgument(m.matches(), // String.format("Invalid position %s", pos)); // if (null == m.group(2)) // return simple(Integer.parseInt(m.group(1))); // return composed(Integer.parseInt(m.group(1)), // Integer.parseInt(m.group(3))); // } // // public static Position simple(int meta) { // checkArgument(0 <= meta, "Invalid position"); // return new Position(meta, -1); // } // // public static Position composed(int meta, int sub) { // checkArgument(0 <= meta, "Invalid meta position"); // checkArgument(0 <= sub, "Invalid sub position"); // return new Position(meta, sub); // } // // public int meta() { // return meta; // } // // public int sub() { // return sub; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder().append(meta); // if (-1 != sub) // sb.append(".").append(sub); // return sb.toString(); // } // // /** // * Returns negative, 0 or positive int if the position is lower, equals or // * higher than the specified one . // * <p> // * This method compares the meta position, if equals, // * it compares the sub position. // * // * @param pos // * the position to compare to // * @return negative, 0 or positive int if the position is lower, equals or // * higher than the specified one . // */ // public int compare(Position pos) { // if (meta == pos.meta()) return sub - pos.sub(); // else return meta - pos.meta(); // } // } // Path: src/main/java/io/openio/sds/common/JsonUtils.java import static io.openio.sds.common.OioConstants.OIO_CHARSET; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; import java.util.Map; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import io.openio.sds.models.Position; package io.openio.sds.common; /** * Gson utility class */ public class JsonUtils { private static final GsonBuilder builder = new GsonBuilder()
.registerTypeAdapter(Position.class, new PositionAdapter());
open-io/oio-api-java
src/main/java/io/openio/sds/common/JsonUtils.java
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/models/Position.java // public class Position { // // private static final Pattern POSITION_PATTERN = Pattern // .compile("^([\\d]+)(\\.([\\d]+))?$"); // // private int meta; // private int sub; // // private Position(int meta, int sub) { // this.meta = meta; // this.sub = sub; // } // // public static Position parse(String pos) { // Matcher m = POSITION_PATTERN.matcher(pos); // checkArgument(m.matches(), // String.format("Invalid position %s", pos)); // if (null == m.group(2)) // return simple(Integer.parseInt(m.group(1))); // return composed(Integer.parseInt(m.group(1)), // Integer.parseInt(m.group(3))); // } // // public static Position simple(int meta) { // checkArgument(0 <= meta, "Invalid position"); // return new Position(meta, -1); // } // // public static Position composed(int meta, int sub) { // checkArgument(0 <= meta, "Invalid meta position"); // checkArgument(0 <= sub, "Invalid sub position"); // return new Position(meta, sub); // } // // public int meta() { // return meta; // } // // public int sub() { // return sub; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder().append(meta); // if (-1 != sub) // sb.append(".").append(sub); // return sb.toString(); // } // // /** // * Returns negative, 0 or positive int if the position is lower, equals or // * higher than the specified one . // * <p> // * This method compares the meta position, if equals, // * it compares the sub position. // * // * @param pos // * the position to compare to // * @return negative, 0 or positive int if the position is lower, equals or // * higher than the specified one . // */ // public int compare(Position pos) { // if (meta == pos.meta()) return sub - pos.sub(); // else return meta - pos.meta(); // } // }
import static io.openio.sds.common.OioConstants.OIO_CHARSET; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; import java.util.Map; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import io.openio.sds.models.Position;
package io.openio.sds.common; /** * Gson utility class */ public class JsonUtils { private static final GsonBuilder builder = new GsonBuilder() .registerTypeAdapter(Position.class, new PositionAdapter()); private static final ObjectMapper mapper = new ObjectMapper(); private static final Type MAP_TYPE = new TypeToken<Map<String, String>>() { }.getType(); private static final Type MAP_MAP_TYPE = new TypeToken<Map<String, Map<String, String>>>() { }.getType(); /** * Returns a new {@code Gson} instance with OpenIO adapters * * @return the gson instance */ public static Gson gson() { return builder.create(); } public static Gson gsonForObject() { return builder.serializeNulls().create(); } public static Map<String, String> jsonToMap(String map) { return gson().fromJson(map, MAP_TYPE); } public static Map<String, String> jsonToMap(InputStream in) { return gson().fromJson(
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/models/Position.java // public class Position { // // private static final Pattern POSITION_PATTERN = Pattern // .compile("^([\\d]+)(\\.([\\d]+))?$"); // // private int meta; // private int sub; // // private Position(int meta, int sub) { // this.meta = meta; // this.sub = sub; // } // // public static Position parse(String pos) { // Matcher m = POSITION_PATTERN.matcher(pos); // checkArgument(m.matches(), // String.format("Invalid position %s", pos)); // if (null == m.group(2)) // return simple(Integer.parseInt(m.group(1))); // return composed(Integer.parseInt(m.group(1)), // Integer.parseInt(m.group(3))); // } // // public static Position simple(int meta) { // checkArgument(0 <= meta, "Invalid position"); // return new Position(meta, -1); // } // // public static Position composed(int meta, int sub) { // checkArgument(0 <= meta, "Invalid meta position"); // checkArgument(0 <= sub, "Invalid sub position"); // return new Position(meta, sub); // } // // public int meta() { // return meta; // } // // public int sub() { // return sub; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder().append(meta); // if (-1 != sub) // sb.append(".").append(sub); // return sb.toString(); // } // // /** // * Returns negative, 0 or positive int if the position is lower, equals or // * higher than the specified one . // * <p> // * This method compares the meta position, if equals, // * it compares the sub position. // * // * @param pos // * the position to compare to // * @return negative, 0 or positive int if the position is lower, equals or // * higher than the specified one . // */ // public int compare(Position pos) { // if (meta == pos.meta()) return sub - pos.sub(); // else return meta - pos.meta(); // } // } // Path: src/main/java/io/openio/sds/common/JsonUtils.java import static io.openio.sds.common.OioConstants.OIO_CHARSET; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; import java.util.Map; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import io.openio.sds.models.Position; package io.openio.sds.common; /** * Gson utility class */ public class JsonUtils { private static final GsonBuilder builder = new GsonBuilder() .registerTypeAdapter(Position.class, new PositionAdapter()); private static final ObjectMapper mapper = new ObjectMapper(); private static final Type MAP_TYPE = new TypeToken<Map<String, String>>() { }.getType(); private static final Type MAP_MAP_TYPE = new TypeToken<Map<String, Map<String, String>>>() { }.getType(); /** * Returns a new {@code Gson} instance with OpenIO adapters * * @return the gson instance */ public static Gson gson() { return builder.create(); } public static Gson gsonForObject() { return builder.serializeNulls().create(); } public static Map<String, String> jsonToMap(String map) { return gson().fromJson(map, MAP_TYPE); } public static Map<String, String> jsonToMap(InputStream in) { return gson().fromJson(
new JsonReader(new InputStreamReader(in, OIO_CHARSET)),
open-io/oio-api-java
src/main/java/io/openio/sds/models/ProxyError.java
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final String PROXY_ERROR_FORMAT = "(%d) %s";
import static io.openio.sds.common.OioConstants.PROXY_ERROR_FORMAT; import static java.lang.String.format;
package io.openio.sds.models; /** * * @author Christopher Dedeurwaerder * */ public class ProxyError { private Integer status; private String message; public ProxyError() { } public Integer status() { return status; } public ProxyError status(Integer status) { this.status = status; return this; } public String message() { return message; } public ProxyError message(String message) { this.message = message; return this; } @Override public String toString() {
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final String PROXY_ERROR_FORMAT = "(%d) %s"; // Path: src/main/java/io/openio/sds/models/ProxyError.java import static io.openio.sds.common.OioConstants.PROXY_ERROR_FORMAT; import static java.lang.String.format; package io.openio.sds.models; /** * * @author Christopher Dedeurwaerder * */ public class ProxyError { private Integer status; private String message; public ProxyError() { } public Integer status() { return status; } public ProxyError status(Integer status) { this.status = status; return this; } public String message() { return message; } public ProxyError message(String message) { this.message = message; return this; } @Override public String toString() {
return format(PROXY_ERROR_FORMAT, status, message);
open-io/oio-api-java
src/main/java/io/openio/sds/common/AbstractSocketProvider.java
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // // Path: src/main/java/io/openio/sds/http/OioHttpSettings.java // public class OioHttpSettings { // // private Integer sendBufferSize = 131072; // private Integer receiveBufferSize = 131072; // private Boolean setSocketBufferSize = false; // private Integer connectTimeout = 30000; // private Integer readTimeout = 60000; // private String userAgent = "oio-http"; // // public OioHttpSettings() { // } // // public Integer sendBufferSize() { // return sendBufferSize; // } // // public OioHttpSettings sendBufferSize(Integer sendBufferSize) { // this.sendBufferSize = sendBufferSize; // return this; // } // // public Integer receiveBufferSize() { // return receiveBufferSize; // } // // public OioHttpSettings receiveBufferSize(Integer receiveBufferSize) { // this.receiveBufferSize = receiveBufferSize; // return this; // } // // /** // * Should the size of the socket buffers be explicitly set? // * When true, explicitly set the send buffer size (resp. receive buffer // * size) to {@link #sendBufferSize} (resp. {@link #receiveBufferSize}). // * When false, let the kernel adjust the size automatically. // * // * @return true when the API should set the socket buffer sizes, // * false when it should let the kernel decide. // */ // public Boolean setSocketBufferSize() { // return this.setSocketBufferSize; // } // // /** // * Should the size of the socket buffers be explicitly set? // * When true, explicitly set the send buffer size (resp. receive buffer // * size) to {@link #sendBufferSize} (resp. {@link #receiveBufferSize}). // * When false, let the kernel adjust the size automatically. // * // * @param setSocketBufferSize // * @return this // */ // public OioHttpSettings setSocketBufferSize(Boolean setSocketBufferSize) { // this.setSocketBufferSize = setSocketBufferSize; // return this; // } // // public Integer connectTimeout() { // return connectTimeout; // } // // public OioHttpSettings connectTimeout(Integer connectTimeout) { // this.connectTimeout = connectTimeout; // return this; // } // // public Integer readTimeout() { // return readTimeout; // } // // public OioHttpSettings readTimeout(Integer readTimeout) { // this.readTimeout = readTimeout; // return this; // } // // public String userAgent() { // return userAgent; // } // // public OioHttpSettings userAgent(String userAgent) { // this.userAgent = userAgent; // return this; // } // } // // Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // }
import static java.lang.String.format; import io.openio.sds.exceptions.OioException; import io.openio.sds.http.OioHttpSettings; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import static io.openio.sds.common.Check.checkArgument;
package io.openio.sds.common; /** * * @author Florent Vennetier * */ public abstract class AbstractSocketProvider implements SocketProvider { /** * Configure an already created Socket with provided settings, and establish the connection. * * @param sock A Socket instance * @param target The address to connect the socket to * @param http The settings to apply * @throws OioException if an error occurs during connection */ protected void configureAndConnect(Socket sock, InetSocketAddress target, OioHttpSettings http)
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // // Path: src/main/java/io/openio/sds/http/OioHttpSettings.java // public class OioHttpSettings { // // private Integer sendBufferSize = 131072; // private Integer receiveBufferSize = 131072; // private Boolean setSocketBufferSize = false; // private Integer connectTimeout = 30000; // private Integer readTimeout = 60000; // private String userAgent = "oio-http"; // // public OioHttpSettings() { // } // // public Integer sendBufferSize() { // return sendBufferSize; // } // // public OioHttpSettings sendBufferSize(Integer sendBufferSize) { // this.sendBufferSize = sendBufferSize; // return this; // } // // public Integer receiveBufferSize() { // return receiveBufferSize; // } // // public OioHttpSettings receiveBufferSize(Integer receiveBufferSize) { // this.receiveBufferSize = receiveBufferSize; // return this; // } // // /** // * Should the size of the socket buffers be explicitly set? // * When true, explicitly set the send buffer size (resp. receive buffer // * size) to {@link #sendBufferSize} (resp. {@link #receiveBufferSize}). // * When false, let the kernel adjust the size automatically. // * // * @return true when the API should set the socket buffer sizes, // * false when it should let the kernel decide. // */ // public Boolean setSocketBufferSize() { // return this.setSocketBufferSize; // } // // /** // * Should the size of the socket buffers be explicitly set? // * When true, explicitly set the send buffer size (resp. receive buffer // * size) to {@link #sendBufferSize} (resp. {@link #receiveBufferSize}). // * When false, let the kernel adjust the size automatically. // * // * @param setSocketBufferSize // * @return this // */ // public OioHttpSettings setSocketBufferSize(Boolean setSocketBufferSize) { // this.setSocketBufferSize = setSocketBufferSize; // return this; // } // // public Integer connectTimeout() { // return connectTimeout; // } // // public OioHttpSettings connectTimeout(Integer connectTimeout) { // this.connectTimeout = connectTimeout; // return this; // } // // public Integer readTimeout() { // return readTimeout; // } // // public OioHttpSettings readTimeout(Integer readTimeout) { // this.readTimeout = readTimeout; // return this; // } // // public String userAgent() { // return userAgent; // } // // public OioHttpSettings userAgent(String userAgent) { // this.userAgent = userAgent; // return this; // } // } // // Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // Path: src/main/java/io/openio/sds/common/AbstractSocketProvider.java import static java.lang.String.format; import io.openio.sds.exceptions.OioException; import io.openio.sds.http.OioHttpSettings; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import static io.openio.sds.common.Check.checkArgument; package io.openio.sds.common; /** * * @author Florent Vennetier * */ public abstract class AbstractSocketProvider implements SocketProvider { /** * Configure an already created Socket with provided settings, and establish the connection. * * @param sock A Socket instance * @param target The address to connect the socket to * @param http The settings to apply * @throws OioException if an error occurs during connection */ protected void configureAndConnect(Socket sock, InetSocketAddress target, OioHttpSettings http)
throws OioException {
open-io/oio-api-java
src/main/java/io/openio/sds/common/AbstractSocketProvider.java
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // // Path: src/main/java/io/openio/sds/http/OioHttpSettings.java // public class OioHttpSettings { // // private Integer sendBufferSize = 131072; // private Integer receiveBufferSize = 131072; // private Boolean setSocketBufferSize = false; // private Integer connectTimeout = 30000; // private Integer readTimeout = 60000; // private String userAgent = "oio-http"; // // public OioHttpSettings() { // } // // public Integer sendBufferSize() { // return sendBufferSize; // } // // public OioHttpSettings sendBufferSize(Integer sendBufferSize) { // this.sendBufferSize = sendBufferSize; // return this; // } // // public Integer receiveBufferSize() { // return receiveBufferSize; // } // // public OioHttpSettings receiveBufferSize(Integer receiveBufferSize) { // this.receiveBufferSize = receiveBufferSize; // return this; // } // // /** // * Should the size of the socket buffers be explicitly set? // * When true, explicitly set the send buffer size (resp. receive buffer // * size) to {@link #sendBufferSize} (resp. {@link #receiveBufferSize}). // * When false, let the kernel adjust the size automatically. // * // * @return true when the API should set the socket buffer sizes, // * false when it should let the kernel decide. // */ // public Boolean setSocketBufferSize() { // return this.setSocketBufferSize; // } // // /** // * Should the size of the socket buffers be explicitly set? // * When true, explicitly set the send buffer size (resp. receive buffer // * size) to {@link #sendBufferSize} (resp. {@link #receiveBufferSize}). // * When false, let the kernel adjust the size automatically. // * // * @param setSocketBufferSize // * @return this // */ // public OioHttpSettings setSocketBufferSize(Boolean setSocketBufferSize) { // this.setSocketBufferSize = setSocketBufferSize; // return this; // } // // public Integer connectTimeout() { // return connectTimeout; // } // // public OioHttpSettings connectTimeout(Integer connectTimeout) { // this.connectTimeout = connectTimeout; // return this; // } // // public Integer readTimeout() { // return readTimeout; // } // // public OioHttpSettings readTimeout(Integer readTimeout) { // this.readTimeout = readTimeout; // return this; // } // // public String userAgent() { // return userAgent; // } // // public OioHttpSettings userAgent(String userAgent) { // this.userAgent = userAgent; // return this; // } // } // // Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // }
import static java.lang.String.format; import io.openio.sds.exceptions.OioException; import io.openio.sds.http.OioHttpSettings; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import static io.openio.sds.common.Check.checkArgument;
package io.openio.sds.common; /** * * @author Florent Vennetier * */ public abstract class AbstractSocketProvider implements SocketProvider { /** * Configure an already created Socket with provided settings, and establish the connection. * * @param sock A Socket instance * @param target The address to connect the socket to * @param http The settings to apply * @throws OioException if an error occurs during connection */ protected void configureAndConnect(Socket sock, InetSocketAddress target, OioHttpSettings http) throws OioException {
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // // Path: src/main/java/io/openio/sds/http/OioHttpSettings.java // public class OioHttpSettings { // // private Integer sendBufferSize = 131072; // private Integer receiveBufferSize = 131072; // private Boolean setSocketBufferSize = false; // private Integer connectTimeout = 30000; // private Integer readTimeout = 60000; // private String userAgent = "oio-http"; // // public OioHttpSettings() { // } // // public Integer sendBufferSize() { // return sendBufferSize; // } // // public OioHttpSettings sendBufferSize(Integer sendBufferSize) { // this.sendBufferSize = sendBufferSize; // return this; // } // // public Integer receiveBufferSize() { // return receiveBufferSize; // } // // public OioHttpSettings receiveBufferSize(Integer receiveBufferSize) { // this.receiveBufferSize = receiveBufferSize; // return this; // } // // /** // * Should the size of the socket buffers be explicitly set? // * When true, explicitly set the send buffer size (resp. receive buffer // * size) to {@link #sendBufferSize} (resp. {@link #receiveBufferSize}). // * When false, let the kernel adjust the size automatically. // * // * @return true when the API should set the socket buffer sizes, // * false when it should let the kernel decide. // */ // public Boolean setSocketBufferSize() { // return this.setSocketBufferSize; // } // // /** // * Should the size of the socket buffers be explicitly set? // * When true, explicitly set the send buffer size (resp. receive buffer // * size) to {@link #sendBufferSize} (resp. {@link #receiveBufferSize}). // * When false, let the kernel adjust the size automatically. // * // * @param setSocketBufferSize // * @return this // */ // public OioHttpSettings setSocketBufferSize(Boolean setSocketBufferSize) { // this.setSocketBufferSize = setSocketBufferSize; // return this; // } // // public Integer connectTimeout() { // return connectTimeout; // } // // public OioHttpSettings connectTimeout(Integer connectTimeout) { // this.connectTimeout = connectTimeout; // return this; // } // // public Integer readTimeout() { // return readTimeout; // } // // public OioHttpSettings readTimeout(Integer readTimeout) { // this.readTimeout = readTimeout; // return this; // } // // public String userAgent() { // return userAgent; // } // // public OioHttpSettings userAgent(String userAgent) { // this.userAgent = userAgent; // return this; // } // } // // Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // Path: src/main/java/io/openio/sds/common/AbstractSocketProvider.java import static java.lang.String.format; import io.openio.sds.exceptions.OioException; import io.openio.sds.http.OioHttpSettings; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import static io.openio.sds.common.Check.checkArgument; package io.openio.sds.common; /** * * @author Florent Vennetier * */ public abstract class AbstractSocketProvider implements SocketProvider { /** * Configure an already created Socket with provided settings, and establish the connection. * * @param sock A Socket instance * @param target The address to connect the socket to * @param http The settings to apply * @throws OioException if an error occurs during connection */ protected void configureAndConnect(Socket sock, InetSocketAddress target, OioHttpSettings http) throws OioException {
checkArgument(sock != null, "'sock' argument should not be null");
open-io/oio-api-java
src/main/java/io/openio/sds/models/OioUrl.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects;
package io.openio.sds.models; /** * * * */ public class OioUrl { private static final byte[] BACK_ZERO = { '\0' }; private String ns; private String account; private String container; private String cid; private String object; private OioUrl(String ns, String account, String container, String cid, String object) { this.ns = ns; this.account = account; this.container = container; this.cid = cid; this.object = object; } public static OioUrl url(String account, String container) { return url(account, container, null); } public static OioUrl url(String account, String container, String object) {
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/OioUrl.java import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects; package io.openio.sds.models; /** * * * */ public class OioUrl { private static final byte[] BACK_ZERO = { '\0' }; private String ns; private String account; private String container; private String cid; private String object; private OioUrl(String ns, String account, String container, String cid, String object) { this.ns = ns; this.account = account; this.container = container; this.cid = cid; this.object = object; } public static OioUrl url(String account, String container) { return url(account, container, null); } public static OioUrl url(String account, String container, String object) {
checkArgument(!nullOrEmpty(account),
open-io/oio-api-java
src/main/java/io/openio/sds/models/OioUrl.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects;
package io.openio.sds.models; /** * * * */ public class OioUrl { private static final byte[] BACK_ZERO = { '\0' }; private String ns; private String account; private String container; private String cid; private String object; private OioUrl(String ns, String account, String container, String cid, String object) { this.ns = ns; this.account = account; this.container = container; this.cid = cid; this.object = object; } public static OioUrl url(String account, String container) { return url(account, container, null); } public static OioUrl url(String account, String container, String object) {
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/OioUrl.java import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects; package io.openio.sds.models; /** * * * */ public class OioUrl { private static final byte[] BACK_ZERO = { '\0' }; private String ns; private String account; private String container; private String cid; private String object; private OioUrl(String ns, String account, String container, String cid, String object) { this.ns = ns; this.account = account; this.container = container; this.cid = cid; this.object = object; } public static OioUrl url(String account, String container) { return url(account, container, null); } public static OioUrl url(String account, String container, String object) {
checkArgument(!nullOrEmpty(account),
open-io/oio-api-java
src/main/java/io/openio/sds/models/OioUrl.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects;
public OioUrl account(String account) { this.account = account; return this; } public String container() { return container; } public OioUrl container(String container) { this.container = container; return this; } public String object() { return object; } public OioUrl object(String object) { this.object = object; return this; } public String cid() { return cid; } @Override public String toString() {
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/OioUrl.java import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects; public OioUrl account(String account) { this.account = account; return this; } public String container() { return container; } public OioUrl container(String container) { this.container = container; return this; } public String object() { return object; } public OioUrl object(String object) { this.object = object; return this; } public String cid() { return cid; } @Override public String toString() {
return MoreObjects.toStringHelper(this)
open-io/oio-api-java
src/main/java/io/openio/sds/models/OioUrl.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects;
public OioUrl object(String object) { this.object = object; return this; } public String cid() { return cid; } @Override public String toString() { return MoreObjects.toStringHelper(this) .omitNullValues() .add("namespace", ns) .add("account", account) .add("container", container) .add("object", object) .toString(); } /** * Generates the container id from the specified account and container name * * @param account * the name of the account * @param container * the name of the container * @return the generated id */ public static String cid(String account, String container) {
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/OioUrl.java import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects; public OioUrl object(String object) { this.object = object; return this; } public String cid() { return cid; } @Override public String toString() { return MoreObjects.toStringHelper(this) .omitNullValues() .add("namespace", ns) .add("account", account) .add("container", container) .add("object", object) .toString(); } /** * Generates the container id from the specified account and container name * * @param account * the name of the account * @param container * the name of the container * @return the generated id */ public static String cid(String account, String container) {
return Hash.sha256()
open-io/oio-api-java
src/main/java/io/openio/sds/models/OioUrl.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects;
this.object = object; return this; } public String cid() { return cid; } @Override public String toString() { return MoreObjects.toStringHelper(this) .omitNullValues() .add("namespace", ns) .add("account", account) .add("container", container) .add("object", object) .toString(); } /** * Generates the container id from the specified account and container name * * @param account * the name of the account * @param container * the name of the container * @return the generated id */ public static String cid(String account, String container) { return Hash.sha256()
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // // Path: src/main/java/io/openio/sds/common/Hash.java // public class Hash { // // private MessageDigest md; // // private Hash(MessageDigest md) { // this.md = md; // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash md5() { // try { // return new Hash(MessageDigest.getInstance("MD5")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Returns an {@link Hash} instance ready to compute a md5 hash // * // * @return an {@link Hash} instance ready to compute a md5 hash // */ // public static Hash sha256() { // try { // return new Hash(MessageDigest.getInstance("SHA-256")); // } catch (NoSuchAlgorithmException e) { // throw new RuntimeException(e); // } // } // // /** // * Updates the current hash with the specified bytes // * // * @param bytes // * the bytes to add // * @return this // */ // public Hash putBytes(byte[] bytes) { // this.md.update(bytes); // return this; // } // // /** // * Completes the current hash computation // * // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hash() { // return Hex.fromBytes(this.md.digest()); // } // // /** // * Add a final update to the current hash and completes it // * // * @param bytes // * the final bytes to add // * @return an {@link Hex} instance handling the computed hash // */ // public Hex hashBytes(byte[] bytes) { // return Hex.fromBytes(this.md.digest(bytes)); // } // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/OioUrl.java import static io.openio.sds.common.Check.checkArgument; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import io.openio.sds.common.Hash; import io.openio.sds.common.MoreObjects; this.object = object; return this; } public String cid() { return cid; } @Override public String toString() { return MoreObjects.toStringHelper(this) .omitNullValues() .add("namespace", ns) .add("account", account) .add("container", container) .add("object", object) .toString(); } /** * Generates the container id from the specified account and container name * * @param account * the name of the account * @param container * the name of the container * @return the generated id */ public static String cid(String account, String container) { return Hash.sha256()
.putBytes(account.getBytes(OIO_CHARSET))
open-io/oio-api-java
src/main/java/io/openio/sds/models/ChunkInfo.java
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import io.openio.sds.common.MoreObjects;
} public ChunkInfo size(Long size) { this.size = size; return this; } public ChunkInfo hash(String hash) { this.hash = hash; return this; } public ChunkInfo pos(Position pos) { this.pos = pos; return this; } public String id(){ return url.substring(url.lastIndexOf("/") + 1); } public String finalUrl() { if (real_url != null && real_url.length() > 0) { return real_url; } return url; } @Override public String toString() {
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/ChunkInfo.java import io.openio.sds.common.MoreObjects; } public ChunkInfo size(Long size) { this.size = size; return this; } public ChunkInfo hash(String hash) { this.hash = hash; return this; } public ChunkInfo pos(Position pos) { this.pos = pos; return this; } public String id(){ return url.substring(url.lastIndexOf("/") + 1); } public String finalUrl() { if (real_url != null && real_url.length() > 0) { return real_url; } return url; } @Override public String toString() {
return MoreObjects.toStringHelper(this)
open-io/oio-api-java
src/main/java/io/openio/sds/common/IdGen.java
// Path: src/main/java/io/openio/sds/common/Hex.java // public static String toHex(byte[] bytes) { // char[] hexChars = new char[bytes.length * 2]; // for (int j = 0; j < bytes.length; j++) { // int v = bytes[j] & 0xFF; // hexChars[j * 2] = hexArray[v >>> 4]; // hexChars[j * 2 + 1] = hexArray[v & 0x0F]; // } // return new String(hexChars); // }
import static io.openio.sds.common.Hex.toHex; import java.util.Random;
package io.openio.sds.common; /** * * @author Christopher Dedeurwaerder * */ public class IdGen { private static final int REQ_ID_LENGTH = 16; private static Random rand = new Random(); /** * Generates a new random request id * @return the generated id */ public static String requestId() {
// Path: src/main/java/io/openio/sds/common/Hex.java // public static String toHex(byte[] bytes) { // char[] hexChars = new char[bytes.length * 2]; // for (int j = 0; j < bytes.length; j++) { // int v = bytes[j] & 0xFF; // hexChars[j * 2] = hexArray[v >>> 4]; // hexChars[j * 2 + 1] = hexArray[v & 0x0F]; // } // return new String(hexChars); // } // Path: src/main/java/io/openio/sds/common/IdGen.java import static io.openio.sds.common.Hex.toHex; import java.util.Random; package io.openio.sds.common; /** * * @author Christopher Dedeurwaerder * */ public class IdGen { private static final int REQ_ID_LENGTH = 16; private static Random rand = new Random(); /** * Generates a new random request id * @return the generated id */ public static String requestId() {
return toHex(bytes(REQ_ID_LENGTH));
open-io/oio-api-java
src/main/java/io/openio/sds/http/OioHttpRequest.java
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // }
import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.util.HashMap; import java.util.Map; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import static java.lang.String.format;
package io.openio.sds.http; public class OioHttpRequest { private static final int R = 1; private static final int RN = 2; private static final int RNR = 3; private static final int RNRN = 3; private static byte BS_R = '\r'; private static byte BS_N = '\n'; private RequestHead head; private InputStream is; public OioHttpRequest(InputStream is) { this.is = is; } public static OioHttpRequest build(InputStream is) throws IOException { OioHttpRequest r = new OioHttpRequest(is); r.parseHead(); return r; } private void parseHead() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int state = 0; while (state < RNRN) { state = next(bos, state); } read();
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // Path: src/main/java/io/openio/sds/http/OioHttpRequest.java import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.util.HashMap; import java.util.Map; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import static java.lang.String.format; package io.openio.sds.http; public class OioHttpRequest { private static final int R = 1; private static final int RN = 2; private static final int RNR = 3; private static final int RNRN = 3; private static byte BS_R = '\r'; private static byte BS_N = '\n'; private RequestHead head; private InputStream is; public OioHttpRequest(InputStream is) { this.is = is; } public static OioHttpRequest build(InputStream is) throws IOException { OioHttpRequest r = new OioHttpRequest(is); r.parseHead(); return r; } private void parseHead() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int state = 0; while (state < RNRN) { state = next(bos, state); } read();
head = RequestHead.parse(new String(bos.toByteArray(), OIO_CHARSET));
open-io/oio-api-java
src/main/java/io/openio/sds/http/OioHttpRequest.java
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // }
import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.util.HashMap; import java.util.Map; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import static java.lang.String.format;
public String header(String key) { return head.headers().get(key.toLowerCase()); } public static class RequestHead { private RequestLine requestLine; private BufferedReader reader; private HashMap<String, String> headers = new HashMap<String, String>(); private RequestHead(BufferedReader reader) { this.reader = reader; } static RequestHead parse(String head) throws IOException { RequestHead h = new RequestHead(new BufferedReader(new StringReader(head))); h.parseRequestLine(); h.parseHeaders(); return h; } private void parseRequestLine() throws IOException { requestLine = RequestLine.parse(reader.readLine()); } private void parseHeaders() throws IOException { String line; while (null != (line = reader.readLine())) {
// Path: src/main/java/io/openio/sds/common/OioConstants.java // public static final Charset OIO_CHARSET = Charset.forName("UTF-8"); // // Path: src/main/java/io/openio/sds/common/Strings.java // public static boolean nullOrEmpty(String string) { // return null == string || 0 == string.length(); // } // Path: src/main/java/io/openio/sds/http/OioHttpRequest.java import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.util.HashMap; import java.util.Map; import static io.openio.sds.common.OioConstants.OIO_CHARSET; import static io.openio.sds.common.Strings.nullOrEmpty; import static java.lang.String.format; public String header(String key) { return head.headers().get(key.toLowerCase()); } public static class RequestHead { private RequestLine requestLine; private BufferedReader reader; private HashMap<String, String> headers = new HashMap<String, String>(); private RequestHead(BufferedReader reader) { this.reader = reader; } static RequestHead parse(String head) throws IOException { RequestHead h = new RequestHead(new BufferedReader(new StringReader(head))); h.parseRequestLine(); h.parseHeaders(); return h; } private void parseRequestLine() throws IOException { requestLine = RequestLine.parse(reader.readLine()); } private void parseHeaders() throws IOException { String line; while (null != (line = reader.readLine())) {
if (nullOrEmpty(line))
open-io/oio-api-java
src/main/java/io/openio/sds/storage/Target.java
// Path: src/main/java/io/openio/sds/models/ChunkInfo.java // public class ChunkInfo { // // public ChunkInfo() { // } // // private String url; // private String real_url; // private Long size; // private String hash; // private Position pos; // // public String url() { // return url; // } // // public String hash() { // return hash; // } // // public Position pos() { // return pos; // } // // public Long size() { // return size; // } // // public ChunkInfo url(String url) { // this.url = url; // return this; // } // // public ChunkInfo real_url(String real_url) { // this.real_url = real_url; // return this; // } // // public ChunkInfo size(Long size) { // this.size = size; // return this; // } // // public ChunkInfo hash(String hash) { // this.hash = hash; // return this; // } // // public ChunkInfo pos(Position pos) { // this.pos = pos; // return this; // } // // public String id(){ // return url.substring(url.lastIndexOf("/") + 1); // } // // public String finalUrl() { // if (real_url != null && real_url.length() > 0) { // return real_url; // } // return url; // } // // @Override // public String toString() { // return MoreObjects.toStringHelper(this) // .omitNullValues() // .add("url", url) // .add("real_url", real_url) // .add("size", size) // .add("hash", hash) // .add("pos", pos) // .toString(); // } // } // // Path: src/main/java/io/openio/sds/models/Range.java // public class Range { // // private static final Pattern RANGE_PATTERN = Pattern // .compile("^([\\d]+)?-([\\d]+)?$"); // // private long from = 0; // private long to = -1; // // private Range(long from, long to) { // this.from = from; // this.to = to; // } // // public static Range upTo(long to) { // checkArgument(0 < to); // return new Range(0, to); // } // // public static Range from(long from) { // checkArgument(0 <= from); // return new Range(from, -1); // } // // public static Range between(long from, long to) { // checkArgument(from >= 0 && to > 0 && to >= from, // "Invalid range"); // return new Range(from, to); // } // // public static Range parse(String str) { // Matcher m = RANGE_PATTERN.matcher(str); // checkArgument(m.matches()); // if (null == m.group(1)) { // checkArgument(null != m.group(2), "useless range"); // return upTo(parseInt(m.group(2))); // } // return (null == m.group(2)) ? from(parseInt(m.group(1))) // : between(parseInt(m.group(1)), parseInt(m.group(2))); // } // // public long from() { // return from; // } // // public long to() { // return to; // } // // public String headerValue() { // return to < 0 // ? format("bytes=%d-", from) // : format("bytes=%d-%d", from, to); // } // // public String rangeValue() { // return to < 0 // ? format("%d-", from) // : format("%d-%d", from, to); // } // // @Override // public String toString() { // return MoreObjects.toStringHelper(this) // .add("from", from) // .add("to", to) // .toString(); // } // }
import java.util.List; import io.openio.sds.models.ChunkInfo; import io.openio.sds.models.Range;
package io.openio.sds.storage; /** * * @author Christopher Dedeurwaerder * */ public class Target { private List<ChunkInfo> ci;
// Path: src/main/java/io/openio/sds/models/ChunkInfo.java // public class ChunkInfo { // // public ChunkInfo() { // } // // private String url; // private String real_url; // private Long size; // private String hash; // private Position pos; // // public String url() { // return url; // } // // public String hash() { // return hash; // } // // public Position pos() { // return pos; // } // // public Long size() { // return size; // } // // public ChunkInfo url(String url) { // this.url = url; // return this; // } // // public ChunkInfo real_url(String real_url) { // this.real_url = real_url; // return this; // } // // public ChunkInfo size(Long size) { // this.size = size; // return this; // } // // public ChunkInfo hash(String hash) { // this.hash = hash; // return this; // } // // public ChunkInfo pos(Position pos) { // this.pos = pos; // return this; // } // // public String id(){ // return url.substring(url.lastIndexOf("/") + 1); // } // // public String finalUrl() { // if (real_url != null && real_url.length() > 0) { // return real_url; // } // return url; // } // // @Override // public String toString() { // return MoreObjects.toStringHelper(this) // .omitNullValues() // .add("url", url) // .add("real_url", real_url) // .add("size", size) // .add("hash", hash) // .add("pos", pos) // .toString(); // } // } // // Path: src/main/java/io/openio/sds/models/Range.java // public class Range { // // private static final Pattern RANGE_PATTERN = Pattern // .compile("^([\\d]+)?-([\\d]+)?$"); // // private long from = 0; // private long to = -1; // // private Range(long from, long to) { // this.from = from; // this.to = to; // } // // public static Range upTo(long to) { // checkArgument(0 < to); // return new Range(0, to); // } // // public static Range from(long from) { // checkArgument(0 <= from); // return new Range(from, -1); // } // // public static Range between(long from, long to) { // checkArgument(from >= 0 && to > 0 && to >= from, // "Invalid range"); // return new Range(from, to); // } // // public static Range parse(String str) { // Matcher m = RANGE_PATTERN.matcher(str); // checkArgument(m.matches()); // if (null == m.group(1)) { // checkArgument(null != m.group(2), "useless range"); // return upTo(parseInt(m.group(2))); // } // return (null == m.group(2)) ? from(parseInt(m.group(1))) // : between(parseInt(m.group(1)), parseInt(m.group(2))); // } // // public long from() { // return from; // } // // public long to() { // return to; // } // // public String headerValue() { // return to < 0 // ? format("bytes=%d-", from) // : format("bytes=%d-%d", from, to); // } // // public String rangeValue() { // return to < 0 // ? format("%d-", from) // : format("%d-%d", from, to); // } // // @Override // public String toString() { // return MoreObjects.toStringHelper(this) // .add("from", from) // .add("to", to) // .toString(); // } // } // Path: src/main/java/io/openio/sds/storage/Target.java import java.util.List; import io.openio.sds.models.ChunkInfo; import io.openio.sds.models.Range; package io.openio.sds.storage; /** * * @author Christopher Dedeurwaerder * */ public class Target { private List<ChunkInfo> ci;
private Range range;
open-io/oio-api-java
src/main/java/io/openio/sds/models/ListOptions.java
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import io.openio.sds.common.MoreObjects;
public String delimiter() { return delimiter; } public ListOptions delimiter(String delimiter) { this.delimiter = delimiter; return this; } public String prefix() { return prefix; } public ListOptions prefix(String prefix) { this.prefix = prefix; return this; } public String marker() { return marker; } public ListOptions marker(String marker) { this.marker = marker; return this; } @Override public String toString() {
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/ListOptions.java import io.openio.sds.common.MoreObjects; public String delimiter() { return delimiter; } public ListOptions delimiter(String delimiter) { this.delimiter = delimiter; return this; } public String prefix() { return prefix; } public ListOptions prefix(String prefix) { this.prefix = prefix; return this; } public String marker() { return marker; } public ListOptions marker(String marker) { this.marker = marker; return this; } @Override public String toString() {
return MoreObjects.toStringHelper(this)
open-io/oio-api-java
src/main/java/io/openio/sds/models/Position.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // }
import static io.openio.sds.common.Check.checkArgument; import java.util.regex.Matcher; import java.util.regex.Pattern;
package io.openio.sds.models; /** * * * */ public class Position { private static final Pattern POSITION_PATTERN = Pattern .compile("^([\\d]+)(\\.([\\d]+))?$"); private int meta; private int sub; private Position(int meta, int sub) { this.meta = meta; this.sub = sub; } public static Position parse(String pos) { Matcher m = POSITION_PATTERN.matcher(pos);
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // Path: src/main/java/io/openio/sds/models/Position.java import static io.openio.sds.common.Check.checkArgument; import java.util.regex.Matcher; import java.util.regex.Pattern; package io.openio.sds.models; /** * * * */ public class Position { private static final Pattern POSITION_PATTERN = Pattern .compile("^([\\d]+)(\\.([\\d]+))?$"); private int meta; private int sub; private Position(int meta, int sub) { this.meta = meta; this.sub = sub; } public static Position parse(String pos) { Matcher m = POSITION_PATTERN.matcher(pos);
checkArgument(m.matches(),
open-io/oio-api-java
src/main/java/io/openio/sds/models/ContainerInfo.java
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import io.openio.sds.common.MoreObjects;
public String versionMainChunks() { return versionMainChunks; } public ContainerInfo versionMainChunks(String versionMainChunks) { this.versionMainChunks = versionMainChunks; return this; } public String versionMainContents() { return versionMainContents; } public ContainerInfo versionMainContents(String versionMainContents) { this.versionMainContents = versionMainContents; return this; } public String versionMainProperties() { return versionMainProperties; } public ContainerInfo versionMainProperties( String versionMainProperties) { this.versionMainProperties = versionMainProperties; return this; } @Override public String toString() {
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/ContainerInfo.java import io.openio.sds.common.MoreObjects; public String versionMainChunks() { return versionMainChunks; } public ContainerInfo versionMainChunks(String versionMainChunks) { this.versionMainChunks = versionMainChunks; return this; } public String versionMainContents() { return versionMainContents; } public ContainerInfo versionMainContents(String versionMainContents) { this.versionMainContents = versionMainContents; return this; } public String versionMainProperties() { return versionMainProperties; } public ContainerInfo versionMainProperties( String versionMainProperties) { this.versionMainProperties = versionMainProperties; return this; } @Override public String toString() {
return MoreObjects.toStringHelper(this)
open-io/oio-api-java
src/main/java/io/openio/sds/models/ServiceInfo.java
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import java.util.Map; import io.openio.sds.common.MoreObjects;
package io.openio.sds.models; /** * * @author Christopher Dedeurwaerder * */ public class ServiceInfo { private String addr; private Integer score; private Map<String, String> tags; public ServiceInfo() { } public String addr() { return addr; } public ServiceInfo addr(String addr) { this.addr = addr; return this; } public Integer score() { return score; } public ServiceInfo score(Integer score) { this.score = score; return this; } public Map<String, String> tags() { return tags; } public ServiceInfo tags(Map<String, String> tags) { this.tags = tags; return this; } @Override public String toString(){
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/ServiceInfo.java import java.util.Map; import io.openio.sds.common.MoreObjects; package io.openio.sds.models; /** * * @author Christopher Dedeurwaerder * */ public class ServiceInfo { private String addr; private Integer score; private Map<String, String> tags; public ServiceInfo() { } public String addr() { return addr; } public ServiceInfo addr(String addr) { this.addr = addr; return this; } public Integer score() { return score; } public ServiceInfo score(Integer score) { this.score = score; return this; } public Map<String, String> tags() { return tags; } public ServiceInfo tags(Map<String, String> tags) { this.tags = tags; return this; } @Override public String toString(){
return MoreObjects.toStringHelper(this)
open-io/oio-api-java
src/main/java/io/openio/sds/RequestContext.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/DeadlineManager.java // public class DeadlineManager { // // public interface ClockSource { // /** // * // * @return the current time in milliseconds // */ // int now(); // } // // private class SystemClockSource implements ClockSource { // // public SystemClockSource() { // } // // @Override // public int now() { // return (int) (System.nanoTime() / 1000000); // } // } // // // private static volatile DeadlineManager instance = null; // // private ClockSource clock; // // private DeadlineManager() { // useSystemClockSource(); // } // // /** // * Get the single instance of {@link DeadlineManager}. // * @return the single instance of {@link DeadlineManager} // */ // public static DeadlineManager instance() { // if (instance == null) { // synchronized (DeadlineManager.class) { // if (instance == null) { // instance = new DeadlineManager(); // } // } // } // return instance; // } // // /** // * Force the DeadlineManager to use a mocked {@link ClockSource} // * @param clockSource The new clock source to use // */ // public void useMockedClockSource(ClockSource clockSource) { // this.clock = clockSource; // } // // /** // * Force the DeadlineManager to use the system monotonic clock source. // */ // public void useSystemClockSource() { // this.clock = this.new SystemClockSource(); // } // // /** // * Raise an exception when a deadline has been reached. // * // * @param deadline the deadline, in milliseconds // * @throws DeadlineReachedException when the deadline has been reached // */ // public void checkDeadline(int deadline) throws DeadlineReachedException { // checkDeadline(deadline, now()); // } // // /** // * Raise an exception when a deadline has been reached. // * // * @param deadline the deadline, in milliseconds // * @param refTime the reference time for the deadline, in milliseconds // * @throws DeadlineReachedException when the deadline has been reached // */ // public void checkDeadline(int deadline, int refTime) throws DeadlineReachedException { // int diff = deadline - refTime; // if (diff <= 0) { // throw new DeadlineReachedException(-diff); // } // } // // /** // * Convert a deadline to a timeout. // * // * @param deadline the deadline to convert, in milliseconds // * @return a timeout in milliseconds // */ // public int deadlineToTimeout(int deadline) { // return deadline - now(); // } // // /** // * Convert a deadline to a timeout. // * // * @param deadline the deadline to convert, in milliseconds // * @param refTime the reference time for the deadline, in monotonic milliseconds // * @return a timeout in milliseconds // */ // public int deadlineToTimeout(int deadline, int refTime) { // return deadline - refTime; // } // // /** // * Get the current monotonic time in milliseconds. // * // * @return The current monotonic time in milliseconds // */ // public int now() { // return clock.now(); // } // // /** // * Convert a timeout to a deadline. // * // * @param timeout the timeout in milliseconds // * @return a deadline in monotonic milliseconds // */ // public int timeoutToDeadline(int timeout) { // return timeoutToDeadline(timeout, now()); // } // // /** // * Convert a timeout to a deadline. // * // * @param timeout the timeout in milliseconds // * @param refTime the reference time for the deadline, in milliseconds // * @return a deadline in monotonic milliseconds // */ // public int timeoutToDeadline(int timeout, int refTime) { // return refTime + timeout; // } // } // // Path: src/main/java/io/openio/sds/common/IdGen.java // public class IdGen { // // private static final int REQ_ID_LENGTH = 16; // // private static Random rand = new Random(); // // /** // * Generates a new random request id // * @return the generated id // */ // public static String requestId() { // return toHex(bytes(REQ_ID_LENGTH)); // } // // private static byte[] bytes(int size){ // byte[] b = new byte[size]; // rand.nextBytes(b); // return b; // } // }
import static io.openio.sds.common.Check.checkArgument; import io.openio.sds.common.DeadlineManager; import io.openio.sds.common.IdGen;
package io.openio.sds; /** * Generic parameters and context for all OpenIO SDS requests, * including a request ID, a timeout (or deadline), etc. * * @author Florent Vennetier * */ public class RequestContext { private DeadlineManager dm; private String reqId = null; private int reqStart = -1; private int rawTimeout = -1; private int deadline = -1; /** * Build a new {@link RequestContext} with a default 30s timeout. */ public RequestContext() { this.dm = DeadlineManager.instance(); } /** * Copy constructor. Build a new {@link RequestContext} from another one. * This will keep the request ID, the timeout and the deadline (if there is one). * * @param src The {@link RequestContext} to copy. */ public RequestContext(RequestContext src) { this.withRequestId(src.requestId()); this.deadline = src.deadline; this.rawTimeout = src.rawTimeout; } /* -- Request IDs ----------------------------------------------------- */ /** * Ensure this request has an ID and it is at least 8 characters. * * @return this */ public RequestContext ensureRequestId() { if (this.reqId == null)
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/DeadlineManager.java // public class DeadlineManager { // // public interface ClockSource { // /** // * // * @return the current time in milliseconds // */ // int now(); // } // // private class SystemClockSource implements ClockSource { // // public SystemClockSource() { // } // // @Override // public int now() { // return (int) (System.nanoTime() / 1000000); // } // } // // // private static volatile DeadlineManager instance = null; // // private ClockSource clock; // // private DeadlineManager() { // useSystemClockSource(); // } // // /** // * Get the single instance of {@link DeadlineManager}. // * @return the single instance of {@link DeadlineManager} // */ // public static DeadlineManager instance() { // if (instance == null) { // synchronized (DeadlineManager.class) { // if (instance == null) { // instance = new DeadlineManager(); // } // } // } // return instance; // } // // /** // * Force the DeadlineManager to use a mocked {@link ClockSource} // * @param clockSource The new clock source to use // */ // public void useMockedClockSource(ClockSource clockSource) { // this.clock = clockSource; // } // // /** // * Force the DeadlineManager to use the system monotonic clock source. // */ // public void useSystemClockSource() { // this.clock = this.new SystemClockSource(); // } // // /** // * Raise an exception when a deadline has been reached. // * // * @param deadline the deadline, in milliseconds // * @throws DeadlineReachedException when the deadline has been reached // */ // public void checkDeadline(int deadline) throws DeadlineReachedException { // checkDeadline(deadline, now()); // } // // /** // * Raise an exception when a deadline has been reached. // * // * @param deadline the deadline, in milliseconds // * @param refTime the reference time for the deadline, in milliseconds // * @throws DeadlineReachedException when the deadline has been reached // */ // public void checkDeadline(int deadline, int refTime) throws DeadlineReachedException { // int diff = deadline - refTime; // if (diff <= 0) { // throw new DeadlineReachedException(-diff); // } // } // // /** // * Convert a deadline to a timeout. // * // * @param deadline the deadline to convert, in milliseconds // * @return a timeout in milliseconds // */ // public int deadlineToTimeout(int deadline) { // return deadline - now(); // } // // /** // * Convert a deadline to a timeout. // * // * @param deadline the deadline to convert, in milliseconds // * @param refTime the reference time for the deadline, in monotonic milliseconds // * @return a timeout in milliseconds // */ // public int deadlineToTimeout(int deadline, int refTime) { // return deadline - refTime; // } // // /** // * Get the current monotonic time in milliseconds. // * // * @return The current monotonic time in milliseconds // */ // public int now() { // return clock.now(); // } // // /** // * Convert a timeout to a deadline. // * // * @param timeout the timeout in milliseconds // * @return a deadline in monotonic milliseconds // */ // public int timeoutToDeadline(int timeout) { // return timeoutToDeadline(timeout, now()); // } // // /** // * Convert a timeout to a deadline. // * // * @param timeout the timeout in milliseconds // * @param refTime the reference time for the deadline, in milliseconds // * @return a deadline in monotonic milliseconds // */ // public int timeoutToDeadline(int timeout, int refTime) { // return refTime + timeout; // } // } // // Path: src/main/java/io/openio/sds/common/IdGen.java // public class IdGen { // // private static final int REQ_ID_LENGTH = 16; // // private static Random rand = new Random(); // // /** // * Generates a new random request id // * @return the generated id // */ // public static String requestId() { // return toHex(bytes(REQ_ID_LENGTH)); // } // // private static byte[] bytes(int size){ // byte[] b = new byte[size]; // rand.nextBytes(b); // return b; // } // } // Path: src/main/java/io/openio/sds/RequestContext.java import static io.openio.sds.common.Check.checkArgument; import io.openio.sds.common.DeadlineManager; import io.openio.sds.common.IdGen; package io.openio.sds; /** * Generic parameters and context for all OpenIO SDS requests, * including a request ID, a timeout (or deadline), etc. * * @author Florent Vennetier * */ public class RequestContext { private DeadlineManager dm; private String reqId = null; private int reqStart = -1; private int rawTimeout = -1; private int deadline = -1; /** * Build a new {@link RequestContext} with a default 30s timeout. */ public RequestContext() { this.dm = DeadlineManager.instance(); } /** * Copy constructor. Build a new {@link RequestContext} from another one. * This will keep the request ID, the timeout and the deadline (if there is one). * * @param src The {@link RequestContext} to copy. */ public RequestContext(RequestContext src) { this.withRequestId(src.requestId()); this.deadline = src.deadline; this.rawTimeout = src.rawTimeout; } /* -- Request IDs ----------------------------------------------------- */ /** * Ensure this request has an ID and it is at least 8 characters. * * @return this */ public RequestContext ensureRequestId() { if (this.reqId == null)
this.reqId = IdGen.requestId();
open-io/oio-api-java
src/main/java/io/openio/sds/RequestContext.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/DeadlineManager.java // public class DeadlineManager { // // public interface ClockSource { // /** // * // * @return the current time in milliseconds // */ // int now(); // } // // private class SystemClockSource implements ClockSource { // // public SystemClockSource() { // } // // @Override // public int now() { // return (int) (System.nanoTime() / 1000000); // } // } // // // private static volatile DeadlineManager instance = null; // // private ClockSource clock; // // private DeadlineManager() { // useSystemClockSource(); // } // // /** // * Get the single instance of {@link DeadlineManager}. // * @return the single instance of {@link DeadlineManager} // */ // public static DeadlineManager instance() { // if (instance == null) { // synchronized (DeadlineManager.class) { // if (instance == null) { // instance = new DeadlineManager(); // } // } // } // return instance; // } // // /** // * Force the DeadlineManager to use a mocked {@link ClockSource} // * @param clockSource The new clock source to use // */ // public void useMockedClockSource(ClockSource clockSource) { // this.clock = clockSource; // } // // /** // * Force the DeadlineManager to use the system monotonic clock source. // */ // public void useSystemClockSource() { // this.clock = this.new SystemClockSource(); // } // // /** // * Raise an exception when a deadline has been reached. // * // * @param deadline the deadline, in milliseconds // * @throws DeadlineReachedException when the deadline has been reached // */ // public void checkDeadline(int deadline) throws DeadlineReachedException { // checkDeadline(deadline, now()); // } // // /** // * Raise an exception when a deadline has been reached. // * // * @param deadline the deadline, in milliseconds // * @param refTime the reference time for the deadline, in milliseconds // * @throws DeadlineReachedException when the deadline has been reached // */ // public void checkDeadline(int deadline, int refTime) throws DeadlineReachedException { // int diff = deadline - refTime; // if (diff <= 0) { // throw new DeadlineReachedException(-diff); // } // } // // /** // * Convert a deadline to a timeout. // * // * @param deadline the deadline to convert, in milliseconds // * @return a timeout in milliseconds // */ // public int deadlineToTimeout(int deadline) { // return deadline - now(); // } // // /** // * Convert a deadline to a timeout. // * // * @param deadline the deadline to convert, in milliseconds // * @param refTime the reference time for the deadline, in monotonic milliseconds // * @return a timeout in milliseconds // */ // public int deadlineToTimeout(int deadline, int refTime) { // return deadline - refTime; // } // // /** // * Get the current monotonic time in milliseconds. // * // * @return The current monotonic time in milliseconds // */ // public int now() { // return clock.now(); // } // // /** // * Convert a timeout to a deadline. // * // * @param timeout the timeout in milliseconds // * @return a deadline in monotonic milliseconds // */ // public int timeoutToDeadline(int timeout) { // return timeoutToDeadline(timeout, now()); // } // // /** // * Convert a timeout to a deadline. // * // * @param timeout the timeout in milliseconds // * @param refTime the reference time for the deadline, in milliseconds // * @return a deadline in monotonic milliseconds // */ // public int timeoutToDeadline(int timeout, int refTime) { // return refTime + timeout; // } // } // // Path: src/main/java/io/openio/sds/common/IdGen.java // public class IdGen { // // private static final int REQ_ID_LENGTH = 16; // // private static Random rand = new Random(); // // /** // * Generates a new random request id // * @return the generated id // */ // public static String requestId() { // return toHex(bytes(REQ_ID_LENGTH)); // } // // private static byte[] bytes(int size){ // byte[] b = new byte[size]; // rand.nextBytes(b); // return b; // } // }
import static io.openio.sds.common.Check.checkArgument; import io.openio.sds.common.DeadlineManager; import io.openio.sds.common.IdGen;
public RequestContext startTiming() { this.reqStart = dm.now(); return this; } /** * Get the timeout for the request. * * If {@link #hasDeadline()} returns {@code true}, successive calls to this * method will return decreasing values, and negative values when the * deadline has been exceeded. * * @return the timeout for this request, in milliseconds */ public int timeout() { if (this.hasDeadline()) return this.dm.deadlineToTimeout(this.deadline); return this.rawTimeout; } /** * Set a deadline on the whole request. * * This will reset any previous timeout set with {@link #withTimeout(int)} to the duration * from now to the deadline. * * @param deadline the deadline in milliseconds * @return this */ public RequestContext withDeadline(int deadline) {
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/DeadlineManager.java // public class DeadlineManager { // // public interface ClockSource { // /** // * // * @return the current time in milliseconds // */ // int now(); // } // // private class SystemClockSource implements ClockSource { // // public SystemClockSource() { // } // // @Override // public int now() { // return (int) (System.nanoTime() / 1000000); // } // } // // // private static volatile DeadlineManager instance = null; // // private ClockSource clock; // // private DeadlineManager() { // useSystemClockSource(); // } // // /** // * Get the single instance of {@link DeadlineManager}. // * @return the single instance of {@link DeadlineManager} // */ // public static DeadlineManager instance() { // if (instance == null) { // synchronized (DeadlineManager.class) { // if (instance == null) { // instance = new DeadlineManager(); // } // } // } // return instance; // } // // /** // * Force the DeadlineManager to use a mocked {@link ClockSource} // * @param clockSource The new clock source to use // */ // public void useMockedClockSource(ClockSource clockSource) { // this.clock = clockSource; // } // // /** // * Force the DeadlineManager to use the system monotonic clock source. // */ // public void useSystemClockSource() { // this.clock = this.new SystemClockSource(); // } // // /** // * Raise an exception when a deadline has been reached. // * // * @param deadline the deadline, in milliseconds // * @throws DeadlineReachedException when the deadline has been reached // */ // public void checkDeadline(int deadline) throws DeadlineReachedException { // checkDeadline(deadline, now()); // } // // /** // * Raise an exception when a deadline has been reached. // * // * @param deadline the deadline, in milliseconds // * @param refTime the reference time for the deadline, in milliseconds // * @throws DeadlineReachedException when the deadline has been reached // */ // public void checkDeadline(int deadline, int refTime) throws DeadlineReachedException { // int diff = deadline - refTime; // if (diff <= 0) { // throw new DeadlineReachedException(-diff); // } // } // // /** // * Convert a deadline to a timeout. // * // * @param deadline the deadline to convert, in milliseconds // * @return a timeout in milliseconds // */ // public int deadlineToTimeout(int deadline) { // return deadline - now(); // } // // /** // * Convert a deadline to a timeout. // * // * @param deadline the deadline to convert, in milliseconds // * @param refTime the reference time for the deadline, in monotonic milliseconds // * @return a timeout in milliseconds // */ // public int deadlineToTimeout(int deadline, int refTime) { // return deadline - refTime; // } // // /** // * Get the current monotonic time in milliseconds. // * // * @return The current monotonic time in milliseconds // */ // public int now() { // return clock.now(); // } // // /** // * Convert a timeout to a deadline. // * // * @param timeout the timeout in milliseconds // * @return a deadline in monotonic milliseconds // */ // public int timeoutToDeadline(int timeout) { // return timeoutToDeadline(timeout, now()); // } // // /** // * Convert a timeout to a deadline. // * // * @param timeout the timeout in milliseconds // * @param refTime the reference time for the deadline, in milliseconds // * @return a deadline in monotonic milliseconds // */ // public int timeoutToDeadline(int timeout, int refTime) { // return refTime + timeout; // } // } // // Path: src/main/java/io/openio/sds/common/IdGen.java // public class IdGen { // // private static final int REQ_ID_LENGTH = 16; // // private static Random rand = new Random(); // // /** // * Generates a new random request id // * @return the generated id // */ // public static String requestId() { // return toHex(bytes(REQ_ID_LENGTH)); // } // // private static byte[] bytes(int size){ // byte[] b = new byte[size]; // rand.nextBytes(b); // return b; // } // } // Path: src/main/java/io/openio/sds/RequestContext.java import static io.openio.sds.common.Check.checkArgument; import io.openio.sds.common.DeadlineManager; import io.openio.sds.common.IdGen; public RequestContext startTiming() { this.reqStart = dm.now(); return this; } /** * Get the timeout for the request. * * If {@link #hasDeadline()} returns {@code true}, successive calls to this * method will return decreasing values, and negative values when the * deadline has been exceeded. * * @return the timeout for this request, in milliseconds */ public int timeout() { if (this.hasDeadline()) return this.dm.deadlineToTimeout(this.deadline); return this.rawTimeout; } /** * Set a deadline on the whole request. * * This will reset any previous timeout set with {@link #withTimeout(int)} to the duration * from now to the deadline. * * @param deadline the deadline in milliseconds * @return this */ public RequestContext withDeadline(int deadline) {
checkArgument(deadline >= 0, "deadline cannot be negative");
open-io/oio-api-java
src/main/java/io/openio/sds/storage/rawx/UploadResult.java
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // // Path: src/main/java/io/openio/sds/models/ChunkInfo.java // public class ChunkInfo { // // public ChunkInfo() { // } // // private String url; // private String real_url; // private Long size; // private String hash; // private Position pos; // // public String url() { // return url; // } // // public String hash() { // return hash; // } // // public Position pos() { // return pos; // } // // public Long size() { // return size; // } // // public ChunkInfo url(String url) { // this.url = url; // return this; // } // // public ChunkInfo real_url(String real_url) { // this.real_url = real_url; // return this; // } // // public ChunkInfo size(Long size) { // this.size = size; // return this; // } // // public ChunkInfo hash(String hash) { // this.hash = hash; // return this; // } // // public ChunkInfo pos(Position pos) { // this.pos = pos; // return this; // } // // public String id(){ // return url.substring(url.lastIndexOf("/") + 1); // } // // public String finalUrl() { // if (real_url != null && real_url.length() > 0) { // return real_url; // } // return url; // } // // @Override // public String toString() { // return MoreObjects.toStringHelper(this) // .omitNullValues() // .add("url", url) // .add("real_url", real_url) // .add("size", size) // .add("hash", hash) // .add("pos", pos) // .toString(); // } // }
import io.openio.sds.exceptions.OioException; import io.openio.sds.models.ChunkInfo;
package io.openio.sds.storage.rawx; public class UploadResult { ChunkInfo chunkInfo;
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // // Path: src/main/java/io/openio/sds/models/ChunkInfo.java // public class ChunkInfo { // // public ChunkInfo() { // } // // private String url; // private String real_url; // private Long size; // private String hash; // private Position pos; // // public String url() { // return url; // } // // public String hash() { // return hash; // } // // public Position pos() { // return pos; // } // // public Long size() { // return size; // } // // public ChunkInfo url(String url) { // this.url = url; // return this; // } // // public ChunkInfo real_url(String real_url) { // this.real_url = real_url; // return this; // } // // public ChunkInfo size(Long size) { // this.size = size; // return this; // } // // public ChunkInfo hash(String hash) { // this.hash = hash; // return this; // } // // public ChunkInfo pos(Position pos) { // this.pos = pos; // return this; // } // // public String id(){ // return url.substring(url.lastIndexOf("/") + 1); // } // // public String finalUrl() { // if (real_url != null && real_url.length() > 0) { // return real_url; // } // return url; // } // // @Override // public String toString() { // return MoreObjects.toStringHelper(this) // .omitNullValues() // .add("url", url) // .add("real_url", real_url) // .add("size", size) // .add("hash", hash) // .add("pos", pos) // .toString(); // } // } // Path: src/main/java/io/openio/sds/storage/rawx/UploadResult.java import io.openio.sds.exceptions.OioException; import io.openio.sds.models.ChunkInfo; package io.openio.sds.storage.rawx; public class UploadResult { ChunkInfo chunkInfo;
OioException exception;
open-io/oio-api-java
src/main/java/io/openio/sds/common/DeadlineManager.java
// Path: src/main/java/io/openio/sds/exceptions/DeadlineReachedException.java // public class DeadlineReachedException extends OioException { // // private static final long serialVersionUID = -3825904433261832246L; // // /** // * @param message A message for the exception // */ // public DeadlineReachedException(String message) { // super(message); // } // // /** // * // * @param excess by how much time the deadline has been exceeded (milliseconds) // */ // public DeadlineReachedException(int excess) { // super("Request deadline exceeded by " + excess + " milliseconds"); // } // // public DeadlineReachedException() { // super("Request deadline reached"); // } // }
import io.openio.sds.exceptions.DeadlineReachedException;
synchronized (DeadlineManager.class) { if (instance == null) { instance = new DeadlineManager(); } } } return instance; } /** * Force the DeadlineManager to use a mocked {@link ClockSource} * @param clockSource The new clock source to use */ public void useMockedClockSource(ClockSource clockSource) { this.clock = clockSource; } /** * Force the DeadlineManager to use the system monotonic clock source. */ public void useSystemClockSource() { this.clock = this.new SystemClockSource(); } /** * Raise an exception when a deadline has been reached. * * @param deadline the deadline, in milliseconds * @throws DeadlineReachedException when the deadline has been reached */
// Path: src/main/java/io/openio/sds/exceptions/DeadlineReachedException.java // public class DeadlineReachedException extends OioException { // // private static final long serialVersionUID = -3825904433261832246L; // // /** // * @param message A message for the exception // */ // public DeadlineReachedException(String message) { // super(message); // } // // /** // * // * @param excess by how much time the deadline has been exceeded (milliseconds) // */ // public DeadlineReachedException(int excess) { // super("Request deadline exceeded by " + excess + " milliseconds"); // } // // public DeadlineReachedException() { // super("Request deadline reached"); // } // } // Path: src/main/java/io/openio/sds/common/DeadlineManager.java import io.openio.sds.exceptions.DeadlineReachedException; synchronized (DeadlineManager.class) { if (instance == null) { instance = new DeadlineManager(); } } } return instance; } /** * Force the DeadlineManager to use a mocked {@link ClockSource} * @param clockSource The new clock source to use */ public void useMockedClockSource(ClockSource clockSource) { this.clock = clockSource; } /** * Force the DeadlineManager to use the system monotonic clock source. */ public void useSystemClockSource() { this.clock = this.new SystemClockSource(); } /** * Raise an exception when a deadline has been reached. * * @param deadline the deadline, in milliseconds * @throws DeadlineReachedException when the deadline has been reached */
public void checkDeadline(int deadline) throws DeadlineReachedException {
open-io/oio-api-java
src/main/java/io/openio/sds/pool/Pool.java
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // // Path: src/main/java/io/openio/sds/logging/SdsLogger.java // public interface SdsLogger { // // /** // * Logs a message at {@link Level#FINEST}. // * // * @param message // * the message to log. // */ // public void trace(String message); // // /** // * Logs a throwable at {@link Level#FINEST}. The message of the Throwable // * will be the message. // * // * @param thrown // * the Throwable to log. // */ // public void trace(Throwable thrown); // // /** // * Logs message with associated throwable information at // * {@link Level#FINEST}. // * // * @param message // * the message to log // * @param thrown // * the Throwable associated to the message. // */ // public void trace(String message, Throwable thrown); // // /** // * Checks if the {@link Level#FINEST} is enabled. // * // * @return true if enabled, false otherwise. // */ // public boolean isTraceEnabled(); // // /** // * Logs a message at {@link Level#FINE}. // * // * @param message // * the message to log. // */ // public void debug(String message); // // /** // * Logs message with associated throwable information at // * {@link Level#FINE}. // * // * @param message // * the message to log // * @param thrown // * the Throwable associated to the message. // */ // public void debug(String message, Throwable thrown); // // /** // * Checks if the {@link Level#FINE} is enabled. // * // * @return true if enabled, false otherwise. // */ // public boolean isDebugEnabled(); // // /** // * Logs a message at {@link Level#INFO}. // * // * @param message // * the message to log. // */ // public void info(String message); // // /** // * Logs a message at {@link Level#WARNING}. // * // * @param message // * the message to log. // */ // public void warn(String message); // // /** // * Logs a throwable at {@link Level#WARNING}. The message of the Throwable // * will be the message. // * // * @param thrown // * the Throwable to log. // */ // public void warn(Throwable thrown); // // /** // * Logs message with associated throwable information at // * {@link Level#WARNING}. // * // * @param message // * the message to log // * @param thrown // * the Throwable associated to the message. // */ // public void warn(String message, Throwable thrown); // // /** // * Logs a message at {@link Level#SEVERE}. // * // * @param message // * the message to log. // */ // public void error(String message); // // /** // * Logs a throwable at {@link Level#SEVERE}. The message of the Throwable // * will be the message. // * // * @param thrown // * the Throwable to log. // */ // public void error(Throwable thrown); // // /** // * Logs message with associated throwable information at // * {@link Level#SEVERE}. // * // * @param message // * the message to log // * @param thrown // * the Throwable associated to the message. // */ // public void error(String message, Throwable thrown); // } // // Path: src/main/java/io/openio/sds/logging/SdsLoggerFactory.java // public class SdsLoggerFactory { // // private static int loaded = -1; // // public static SdsLogger getLogger(Class<?> c) { // ensureLoaded(); // switch (loaded) { // case 1: // return new Log4jLogger(c); // case 0: // default: // return new BaseLogger(c); // } // } // // private static void ensureLoaded() { // if (-1 == loaded) { // try { // Class.forName("org.apache.log4j.LogManager"); // loaded = 1; // } catch (ClassNotFoundException e) { // loaded = 0; // } // } // } // // }
import java.util.Iterator; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import io.openio.sds.exceptions.OioException; import io.openio.sds.logging.SdsLogger; import io.openio.sds.logging.SdsLoggerFactory;
} protected boolean timedOut(T item, long now) { return now >= item.lastUsage() + settings.idleTimeout(); } /** * @return the first item of the queue that has not timed out. */ protected T leaseLoop() { long now = monotonicMillis(); T item = q.poll(); while (item != null && this.timedOut(item, now)) { destroy(item); item = q.poll(); } return item; } public T lease() { T item = leaseLoop(); if (item == null) { item = tryCreate(); if (item == null) { try { item = q.poll(settings.maxWait(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { logger.debug("connection wait interrrupted"); } if (item == null)
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // // Path: src/main/java/io/openio/sds/logging/SdsLogger.java // public interface SdsLogger { // // /** // * Logs a message at {@link Level#FINEST}. // * // * @param message // * the message to log. // */ // public void trace(String message); // // /** // * Logs a throwable at {@link Level#FINEST}. The message of the Throwable // * will be the message. // * // * @param thrown // * the Throwable to log. // */ // public void trace(Throwable thrown); // // /** // * Logs message with associated throwable information at // * {@link Level#FINEST}. // * // * @param message // * the message to log // * @param thrown // * the Throwable associated to the message. // */ // public void trace(String message, Throwable thrown); // // /** // * Checks if the {@link Level#FINEST} is enabled. // * // * @return true if enabled, false otherwise. // */ // public boolean isTraceEnabled(); // // /** // * Logs a message at {@link Level#FINE}. // * // * @param message // * the message to log. // */ // public void debug(String message); // // /** // * Logs message with associated throwable information at // * {@link Level#FINE}. // * // * @param message // * the message to log // * @param thrown // * the Throwable associated to the message. // */ // public void debug(String message, Throwable thrown); // // /** // * Checks if the {@link Level#FINE} is enabled. // * // * @return true if enabled, false otherwise. // */ // public boolean isDebugEnabled(); // // /** // * Logs a message at {@link Level#INFO}. // * // * @param message // * the message to log. // */ // public void info(String message); // // /** // * Logs a message at {@link Level#WARNING}. // * // * @param message // * the message to log. // */ // public void warn(String message); // // /** // * Logs a throwable at {@link Level#WARNING}. The message of the Throwable // * will be the message. // * // * @param thrown // * the Throwable to log. // */ // public void warn(Throwable thrown); // // /** // * Logs message with associated throwable information at // * {@link Level#WARNING}. // * // * @param message // * the message to log // * @param thrown // * the Throwable associated to the message. // */ // public void warn(String message, Throwable thrown); // // /** // * Logs a message at {@link Level#SEVERE}. // * // * @param message // * the message to log. // */ // public void error(String message); // // /** // * Logs a throwable at {@link Level#SEVERE}. The message of the Throwable // * will be the message. // * // * @param thrown // * the Throwable to log. // */ // public void error(Throwable thrown); // // /** // * Logs message with associated throwable information at // * {@link Level#SEVERE}. // * // * @param message // * the message to log // * @param thrown // * the Throwable associated to the message. // */ // public void error(String message, Throwable thrown); // } // // Path: src/main/java/io/openio/sds/logging/SdsLoggerFactory.java // public class SdsLoggerFactory { // // private static int loaded = -1; // // public static SdsLogger getLogger(Class<?> c) { // ensureLoaded(); // switch (loaded) { // case 1: // return new Log4jLogger(c); // case 0: // default: // return new BaseLogger(c); // } // } // // private static void ensureLoaded() { // if (-1 == loaded) { // try { // Class.forName("org.apache.log4j.LogManager"); // loaded = 1; // } catch (ClassNotFoundException e) { // loaded = 0; // } // } // } // // } // Path: src/main/java/io/openio/sds/pool/Pool.java import java.util.Iterator; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import io.openio.sds.exceptions.OioException; import io.openio.sds.logging.SdsLogger; import io.openio.sds.logging.SdsLoggerFactory; } protected boolean timedOut(T item, long now) { return now >= item.lastUsage() + settings.idleTimeout(); } /** * @return the first item of the queue that has not timed out. */ protected T leaseLoop() { long now = monotonicMillis(); T item = q.poll(); while (item != null && this.timedOut(item, now)) { destroy(item); item = q.poll(); } return item; } public T lease() { T item = leaseLoop(); if (item == null) { item = tryCreate(); if (item == null) { try { item = q.poll(settings.maxWait(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { logger.debug("connection wait interrrupted"); } if (item == null)
throw new OioException(String.format("Unable to get pooled element"));
open-io/oio-api-java
src/test/java/io/openio/sds/proxy/ProxySettingsTest.java
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // }
import io.openio.sds.exceptions.OioException; import org.junit.Test; import java.net.InetSocketAddress; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail;
package io.openio.sds.proxy; public class ProxySettingsTest { @Test public void noURLset() { ProxySettings settings = new ProxySettings(); try { settings.url(); fail("Expected OioException");
// Path: src/main/java/io/openio/sds/exceptions/OioException.java // @SuppressWarnings("deprecation") // public class OioException extends SdsException { // // /** // * // */ // private static final long serialVersionUID = 3270900242235005338L; // // public OioException(String message) { // super(message); // } // // public OioException(String message, Throwable t) { // super(message, t); // } // } // Path: src/test/java/io/openio/sds/proxy/ProxySettingsTest.java import io.openio.sds.exceptions.OioException; import org.junit.Test; import java.net.InetSocketAddress; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; package io.openio.sds.proxy; public class ProxySettingsTest { @Test public void noURLset() { ProxySettings settings = new ProxySettings(); try { settings.url(); fail("Expected OioException");
} catch (OioException e) {
open-io/oio-api-java
src/main/java/io/openio/sds/models/Range.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import static io.openio.sds.common.Check.checkArgument; import static java.lang.Integer.parseInt; import static java.lang.String.format; import java.util.regex.Matcher; import java.util.regex.Pattern; import io.openio.sds.common.MoreObjects;
package io.openio.sds.models; public class Range { private static final Pattern RANGE_PATTERN = Pattern .compile("^([\\d]+)?-([\\d]+)?$"); private long from = 0; private long to = -1; private Range(long from, long to) { this.from = from; this.to = to; } public static Range upTo(long to) {
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/Range.java import static io.openio.sds.common.Check.checkArgument; import static java.lang.Integer.parseInt; import static java.lang.String.format; import java.util.regex.Matcher; import java.util.regex.Pattern; import io.openio.sds.common.MoreObjects; package io.openio.sds.models; public class Range { private static final Pattern RANGE_PATTERN = Pattern .compile("^([\\d]+)?-([\\d]+)?$"); private long from = 0; private long to = -1; private Range(long from, long to) { this.from = from; this.to = to; } public static Range upTo(long to) {
checkArgument(0 < to);
open-io/oio-api-java
src/main/java/io/openio/sds/models/Range.java
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import static io.openio.sds.common.Check.checkArgument; import static java.lang.Integer.parseInt; import static java.lang.String.format; import java.util.regex.Matcher; import java.util.regex.Pattern; import io.openio.sds.common.MoreObjects;
if (null == m.group(1)) { checkArgument(null != m.group(2), "useless range"); return upTo(parseInt(m.group(2))); } return (null == m.group(2)) ? from(parseInt(m.group(1))) : between(parseInt(m.group(1)), parseInt(m.group(2))); } public long from() { return from; } public long to() { return to; } public String headerValue() { return to < 0 ? format("bytes=%d-", from) : format("bytes=%d-%d", from, to); } public String rangeValue() { return to < 0 ? format("%d-", from) : format("%d-%d", from, to); } @Override public String toString() {
// Path: src/main/java/io/openio/sds/common/Check.java // public static void checkArgument(boolean condition, String msg) { // if (!condition) // throw new IllegalArgumentException(msg); // } // // Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/Range.java import static io.openio.sds.common.Check.checkArgument; import static java.lang.Integer.parseInt; import static java.lang.String.format; import java.util.regex.Matcher; import java.util.regex.Pattern; import io.openio.sds.common.MoreObjects; if (null == m.group(1)) { checkArgument(null != m.group(2), "useless range"); return upTo(parseInt(m.group(2))); } return (null == m.group(2)) ? from(parseInt(m.group(1))) : between(parseInt(m.group(1)), parseInt(m.group(2))); } public long from() { return from; } public long to() { return to; } public String headerValue() { return to < 0 ? format("bytes=%d-", from) : format("bytes=%d-%d", from, to); } public String rangeValue() { return to < 0 ? format("%d-", from) : format("%d-%d", from, to); } @Override public String toString() {
return MoreObjects.toStringHelper(this)
open-io/oio-api-java
src/main/java/io/openio/sds/models/ReferenceInfo.java
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // }
import java.util.List; import io.openio.sds.common.MoreObjects;
package io.openio.sds.models; /** * * @author Christopher Dedeurwaerder * */ public class ReferenceInfo { private List<LinkedServiceInfo> dir; private List<LinkedServiceInfo> srv; public ReferenceInfo() { } public List<LinkedServiceInfo> dir() { return dir; } public ReferenceInfo dir(List<LinkedServiceInfo> dir) { this.dir = dir; return this; } public List<LinkedServiceInfo> srv() { return srv; } public ReferenceInfo srv(List<LinkedServiceInfo> srv) { this.srv = srv; return this; } @Override public String toString(){
// Path: src/main/java/io/openio/sds/common/MoreObjects.java // public class MoreObjects { // // public static ToStringHelper toStringHelper(String name) { // return new ToStringHelper(name); // } // // public static ToStringHelper toStringHelper(Object o) { // return new ToStringHelper(o.getClass().getSimpleName()); // } // // public static class ToStringHelper { // // private String name; // private HashMap<String, Object> fields = new HashMap<String, Object>(); // private boolean skipNulls = false; // // private ToStringHelper(String name) { // this.name = name; // } // // public ToStringHelper add(String key, Object value) { // if (null != key && (null != value || !skipNulls)) // fields.put(key, value); // return this; // } // // public ToStringHelper omitNullValues(){ // this.skipNulls = true; // return this; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name) // .append("={"); // for (Entry<String, Object> e : fields.entrySet()) { // sb.append("\"") // .append(e.getKey()) // .append("\":\"") // .append(e.getValue()) // .append("\","); // } // // return sb.replace(sb.length() - 1, sb.length(), "}") // .toString(); // } // } // } // Path: src/main/java/io/openio/sds/models/ReferenceInfo.java import java.util.List; import io.openio.sds.common.MoreObjects; package io.openio.sds.models; /** * * @author Christopher Dedeurwaerder * */ public class ReferenceInfo { private List<LinkedServiceInfo> dir; private List<LinkedServiceInfo> srv; public ReferenceInfo() { } public List<LinkedServiceInfo> dir() { return dir; } public ReferenceInfo dir(List<LinkedServiceInfo> dir) { this.dir = dir; return this; } public List<LinkedServiceInfo> srv() { return srv; } public ReferenceInfo srv(List<LinkedServiceInfo> srv) { this.srv = srv; return this; } @Override public String toString(){
return MoreObjects.toStringHelper(this)
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/providers/CombinedDataProvider.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataProvider.java // public interface DataProvider<DATA> { // // void setFetcher(DataFetcher<DATA> fetcher); // // /** // * Add the observer into watch list, when data changed, notify it. // * // * @param observer // */ // void registerDataObserver(DataObserver<DATA> observer); // // /** // * Remove observer from watch list. // * // * @param observer // */ // void unregisterDataObserver(DataObserver<DATA> observer); // // /** // * Refresh data. // */ // void refresh(); // // /** // * Notify observers data changed. // */ // void notifyDataChanged(); // // DATA getData(); // // /** // * @return If the data need update, return true. // */ // boolean isDataNeedUpdate(); // // /** // * Release the resources when destroy. If the worker thread is working, stop it. // */ // void release(); // }
import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.core.DataProvider; import java.util.HashMap; import java.util.Map;
* Refresh the target provider. * * @param key */ public void refresh(String key) { DataProvider provider = getProvider(key); if (provider == null) { throw new IllegalArgumentException(); } provider.refresh(); } @Override public synchronized void notifyDataChanged() { for (DataProvider provider : mCombinedProviders.values()) { if (provider.isDataNeedUpdate()) { provider.notifyDataChanged(); } } } public synchronized void notifyDataChanged(String key) { DataProvider provider = getProvider(key); if (provider == null) { throw new IllegalArgumentException(); } provider.notifyDataChanged(); } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataProvider.java // public interface DataProvider<DATA> { // // void setFetcher(DataFetcher<DATA> fetcher); // // /** // * Add the observer into watch list, when data changed, notify it. // * // * @param observer // */ // void registerDataObserver(DataObserver<DATA> observer); // // /** // * Remove observer from watch list. // * // * @param observer // */ // void unregisterDataObserver(DataObserver<DATA> observer); // // /** // * Refresh data. // */ // void refresh(); // // /** // * Notify observers data changed. // */ // void notifyDataChanged(); // // DATA getData(); // // /** // * @return If the data need update, return true. // */ // boolean isDataNeedUpdate(); // // /** // * Release the resources when destroy. If the worker thread is working, stop it. // */ // void release(); // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/providers/CombinedDataProvider.java import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.core.DataProvider; import java.util.HashMap; import java.util.Map; * Refresh the target provider. * * @param key */ public void refresh(String key) { DataProvider provider = getProvider(key); if (provider == null) { throw new IllegalArgumentException(); } provider.refresh(); } @Override public synchronized void notifyDataChanged() { for (DataProvider provider : mCombinedProviders.values()) { if (provider.isDataNeedUpdate()) { provider.notifyDataChanged(); } } } public synchronized void notifyDataChanged(String key) { DataProvider provider = getProvider(key); if (provider == null) { throw new IllegalArgumentException(); } provider.notifyDataChanged(); } @Override
public void registerDataObserver(DataObserver observer) {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/DataConverter.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // }
import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException;
package com.kifile.android.cornerstone.impl.fetchers; /** * DataConverter is used to invoke the exist data in DataConverter. * * @author kifile */ public class DataConverter<DATA> implements DataFetcher<DATA> { private final DATA mData; public DataConverter(DATA data) { mData = data; } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/DataConverter.java import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; package com.kifile.android.cornerstone.impl.fetchers; /** * DataConverter is used to invoke the exist data in DataConverter. * * @author kifile */ public class DataConverter<DATA> implements DataFetcher<DATA> { private final DATA mData; public DataConverter(DATA data) { mData = data; } @Override
public DATA fetch() throws FetchException, ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/DataConverter.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // }
import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException;
package com.kifile.android.cornerstone.impl.fetchers; /** * DataConverter is used to invoke the exist data in DataConverter. * * @author kifile */ public class DataConverter<DATA> implements DataFetcher<DATA> { private final DATA mData; public DataConverter(DATA data) { mData = data; } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/DataConverter.java import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; package com.kifile.android.cornerstone.impl.fetchers; /** * DataConverter is used to invoke the exist data in DataConverter. * * @author kifile */ public class DataConverter<DATA> implements DataFetcher<DATA> { private final DATA mData; public DataConverter(DATA data) { mData = data; } @Override
public DATA fetch() throws FetchException, ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/AnnotationCursorConverter.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // }
import android.database.Cursor; import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.impl.annotations.Property; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
package com.kifile.android.cornerstone.impl.fetchers; /** * Use annotation build result. * <p/> * Created by kifile on 15/9/10. */ public class AnnotationCursorConverter<DATA> extends AbstractFetcherConverter<Cursor, List<DATA>> { private final Class<DATA> mDataClazz; private Map<String, Field> mAnnotationMap = new HashMap<>(); /** * Wrap the DataFetcher will be transformed. * * @param proxy */
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/AnnotationCursorConverter.java import android.database.Cursor; import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.impl.annotations.Property; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; package com.kifile.android.cornerstone.impl.fetchers; /** * Use annotation build result. * <p/> * Created by kifile on 15/9/10. */ public class AnnotationCursorConverter<DATA> extends AbstractFetcherConverter<Cursor, List<DATA>> { private final Class<DATA> mDataClazz; private Map<String, Field> mAnnotationMap = new HashMap<>(); /** * Wrap the DataFetcher will be transformed. * * @param proxy */
public AnnotationCursorConverter(DataFetcher<Cursor> proxy, Class<DATA> clazz) {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/AnnotationCursorConverter.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // }
import android.database.Cursor; import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.impl.annotations.Property; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
package com.kifile.android.cornerstone.impl.fetchers; /** * Use annotation build result. * <p/> * Created by kifile on 15/9/10. */ public class AnnotationCursorConverter<DATA> extends AbstractFetcherConverter<Cursor, List<DATA>> { private final Class<DATA> mDataClazz; private Map<String, Field> mAnnotationMap = new HashMap<>(); /** * Wrap the DataFetcher will be transformed. * * @param proxy */ public AnnotationCursorConverter(DataFetcher<Cursor> proxy, Class<DATA> clazz) { super(proxy); mDataClazz = clazz; processAnnotation(); } private void processAnnotation() { Field[] fields = mDataClazz.getFields(); if (fields != null) { for (Field field : fields) { Property property = field.getAnnotation(Property.class); if (property != null) { String name = property.name(); mAnnotationMap.put(name, field); } } } } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/AnnotationCursorConverter.java import android.database.Cursor; import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.impl.annotations.Property; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; package com.kifile.android.cornerstone.impl.fetchers; /** * Use annotation build result. * <p/> * Created by kifile on 15/9/10. */ public class AnnotationCursorConverter<DATA> extends AbstractFetcherConverter<Cursor, List<DATA>> { private final Class<DATA> mDataClazz; private Map<String, Field> mAnnotationMap = new HashMap<>(); /** * Wrap the DataFetcher will be transformed. * * @param proxy */ public AnnotationCursorConverter(DataFetcher<Cursor> proxy, Class<DATA> clazz) { super(proxy); mDataClazz = clazz; processAnnotation(); } private void processAnnotation() { Field[] fields = mDataClazz.getFields(); if (fields != null) { for (Field field : fields) { Property property = field.getAnnotation(Property.class); if (property != null) { String name = property.name(); mAnnotationMap.put(name, field); } } } } @Override
protected List<DATA> convert(@NonNull Cursor cursor) throws ConvertException {
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/SampleFragment.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // }
import android.app.Activity; import android.app.Fragment; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.SampleDataProvider;
package com.kifile.android.sample.cornerstone; /** * The sample of using DataProvider in Fragment. * * @author kifile */ public class SampleFragment extends Fragment { private SampleDataProvider mProvider; // private DataObserver<JSONObject> mObserver = new DataObserver<JSONObject>() { // @Override // public void onDataChanged(JSONObject jsonObject) { // getActivity().setTitle(jsonObject.toString()); // } // }; @Override public void onAttach(Activity activity) { super.onAttach(activity); if (mProvider == null) { mProvider =
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/SampleFragment.java import android.app.Activity; import android.app.Fragment; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.SampleDataProvider; package com.kifile.android.sample.cornerstone; /** * The sample of using DataProvider in Fragment. * * @author kifile */ public class SampleFragment extends Fragment { private SampleDataProvider mProvider; // private DataObserver<JSONObject> mObserver = new DataObserver<JSONObject>() { // @Override // public void onDataChanged(JSONObject jsonObject) { // getActivity().setTitle(jsonObject.toString()); // } // }; @Override public void onAttach(Activity activity) { super.onAttach(activity); if (mProvider == null) { mProvider =
(SampleDataProvider) Cornerstone.obtainProvider(SampleDataProvider.KEY);
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/widget/PageAdapter.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/providers/PageDataProvider.java // public abstract class PageDataProvider<DATA> extends AbstractDataProvider<PageDataProvider.PageData<DATA>> { // // private DataFetcher<DATA> mFetcher; // // @Override // public void setFetcher(DataFetcher<PageData<DATA>> fetcher) { // throw new UnsupportedOperationException("Should call #setPageFetcher to setFetcher"); // } // // public void setPageFetcher(DataFetcher<DATA> fetcher) { // mFetcher = fetcher; // } // // /** // * When refresh, load the page at 0. // */ // @Override // public final void refresh() { // loadPage(0); // } // // public void loadPage(final int page) { // if (mIsAsync) { // executeFetchTask(new Runnable() { // @Override // public void run() { // if (mFetcher != null) { // try { // final DATA data = mFetcher.fetch(); // // Always use handler to post the notify task. // sHandler.post(new Runnable() { // @Override // public void run() { // setPageData(page, data); // } // }); // } catch (Exception e) { // handleException(e); // } // } // } // }); // } else { // if (mFetcher != null) { // try { // setPageData(page, mFetcher.fetch()); // } catch (Exception e) { // handleException(e); // } // } // } // } // // @Override // public boolean isDataNeedUpdate() { // PageData<DATA> page = getData(); // return page == null || page.page != 0; // } // // @Override // protected void setData(PageData<DATA> dataPageData) { // throw new UnsupportedOperationException("Should call #setPageData to setData"); // } // // public void setPageData(int page, DATA data) { // super.setData(new PageData<>(page, data)); // } // // @Override // protected void handleException(Exception e) { // super.handleException(e); // if (mIsAsync) { // sHandler.post(new Runnable() { // @Override // public void run() { // setPageData(-1, null); // } // }); // } else { // setPageData(-1, null); // } // } // // public static class PageData<DATA> { // // public int page; // // public DATA data; // // public PageData(int page, DATA data) { // this.page = page; // this.data = data; // } // } // }
import android.support.v7.widget.RecyclerView; import com.kifile.android.cornerstone.impl.providers.PageDataProvider; import java.util.ArrayList; import java.util.List;
package com.kifile.android.cornerstone.widget; /** * @author kifile */ public abstract class PageAdapter<VH extends RecyclerView.ViewHolder, DATA> extends RecyclerView.Adapter<VH> { private final List<DATA> mData = new ArrayList<>(); private int mPage; @Override public final int getItemCount() { return mData.size(); } public DATA getItem(int position) { return mData.get(position); }
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/providers/PageDataProvider.java // public abstract class PageDataProvider<DATA> extends AbstractDataProvider<PageDataProvider.PageData<DATA>> { // // private DataFetcher<DATA> mFetcher; // // @Override // public void setFetcher(DataFetcher<PageData<DATA>> fetcher) { // throw new UnsupportedOperationException("Should call #setPageFetcher to setFetcher"); // } // // public void setPageFetcher(DataFetcher<DATA> fetcher) { // mFetcher = fetcher; // } // // /** // * When refresh, load the page at 0. // */ // @Override // public final void refresh() { // loadPage(0); // } // // public void loadPage(final int page) { // if (mIsAsync) { // executeFetchTask(new Runnable() { // @Override // public void run() { // if (mFetcher != null) { // try { // final DATA data = mFetcher.fetch(); // // Always use handler to post the notify task. // sHandler.post(new Runnable() { // @Override // public void run() { // setPageData(page, data); // } // }); // } catch (Exception e) { // handleException(e); // } // } // } // }); // } else { // if (mFetcher != null) { // try { // setPageData(page, mFetcher.fetch()); // } catch (Exception e) { // handleException(e); // } // } // } // } // // @Override // public boolean isDataNeedUpdate() { // PageData<DATA> page = getData(); // return page == null || page.page != 0; // } // // @Override // protected void setData(PageData<DATA> dataPageData) { // throw new UnsupportedOperationException("Should call #setPageData to setData"); // } // // public void setPageData(int page, DATA data) { // super.setData(new PageData<>(page, data)); // } // // @Override // protected void handleException(Exception e) { // super.handleException(e); // if (mIsAsync) { // sHandler.post(new Runnable() { // @Override // public void run() { // setPageData(-1, null); // } // }); // } else { // setPageData(-1, null); // } // } // // public static class PageData<DATA> { // // public int page; // // public DATA data; // // public PageData(int page, DATA data) { // this.page = page; // this.data = data; // } // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/widget/PageAdapter.java import android.support.v7.widget.RecyclerView; import com.kifile.android.cornerstone.impl.providers.PageDataProvider; import java.util.ArrayList; import java.util.List; package com.kifile.android.cornerstone.widget; /** * @author kifile */ public abstract class PageAdapter<VH extends RecyclerView.ViewHolder, DATA> extends RecyclerView.Adapter<VH> { private final List<DATA> mData = new ArrayList<>(); private int mPage; @Override public final int getItemCount() { return mData.size(); } public DATA getItem(int position) { return mData.get(position); }
public final void appendData(PageDataProvider.PageData<List<DATA>> pageData) {
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/ContactFetcherActivity.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // }
import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import java.util.List;
package com.kifile.android.sample.cornerstone; /** * Created by kifile on 15/8/25. */ public class ContactFetcherActivity extends ListActivity { private ContactsProvider mProvider;
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/ContactFetcherActivity.java import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import java.util.List; package com.kifile.android.sample.cornerstone; /** * Created by kifile on 15/8/25. */ public class ContactFetcherActivity extends ListActivity { private ContactsProvider mProvider;
private DataObserver<List<ContactsProvider.Contact>> mContactObserver = new DataObserver<List<ContactsProvider.Contact>>() {
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/ContactFetcherActivity.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // }
import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import java.util.List;
package com.kifile.android.sample.cornerstone; /** * Created by kifile on 15/8/25. */ public class ContactFetcherActivity extends ListActivity { private ContactsProvider mProvider; private DataObserver<List<ContactsProvider.Contact>> mContactObserver = new DataObserver<List<ContactsProvider.Contact>>() { @Override public void onDataChanged(List<ContactsProvider.Contact> contacts) { setListAdapter(new ContactAdapter(ContactFetcherActivity.this, contacts)); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (mProvider == null) {
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/ContactFetcherActivity.java import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import java.util.List; package com.kifile.android.sample.cornerstone; /** * Created by kifile on 15/8/25. */ public class ContactFetcherActivity extends ListActivity { private ContactsProvider mProvider; private DataObserver<List<ContactsProvider.Contact>> mContactObserver = new DataObserver<List<ContactsProvider.Contact>>() { @Override public void onDataChanged(List<ContactsProvider.Contact> contacts) { setListAdapter(new ContactAdapter(ContactFetcherActivity.this, contacts)); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (mProvider == null) {
mProvider = (ContactsProvider) Cornerstone.obtainProvider(ContactsProvider.KEY);
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/CursorFetcher.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // }
import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException;
public CursorFetcher setProjection(String[] projections) { mProjections = projections; return this; } public CursorFetcher setSelection(String selection, String[] selectionArgs) { mSelection = selection; mSelectionArgs = selectionArgs; return this; } public CursorFetcher setOrderBy(String orderBy) { mOrderBy = orderBy; return this; } /** * If you want to change the params of fetcher, call it to reset the old params. * * @return */ public CursorFetcher clear() { mProjections = null; mSelection = null; mSelectionArgs = null; mOrderBy = null; return this; } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/CursorFetcher.java import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; public CursorFetcher setProjection(String[] projections) { mProjections = projections; return this; } public CursorFetcher setSelection(String selection, String[] selectionArgs) { mSelection = selection; mSelectionArgs = selectionArgs; return this; } public CursorFetcher setOrderBy(String orderBy) { mOrderBy = orderBy; return this; } /** * If you want to change the params of fetcher, call it to reset the old params. * * @return */ public CursorFetcher clear() { mProjections = null; mSelection = null; mSelectionArgs = null; mOrderBy = null; return this; } @Override
public Cursor fetch() throws FetchException, ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/CursorFetcher.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // }
import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException;
public CursorFetcher setProjection(String[] projections) { mProjections = projections; return this; } public CursorFetcher setSelection(String selection, String[] selectionArgs) { mSelection = selection; mSelectionArgs = selectionArgs; return this; } public CursorFetcher setOrderBy(String orderBy) { mOrderBy = orderBy; return this; } /** * If you want to change the params of fetcher, call it to reset the old params. * * @return */ public CursorFetcher clear() { mProjections = null; mSelection = null; mSelectionArgs = null; mOrderBy = null; return this; } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/CursorFetcher.java import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; public CursorFetcher setProjection(String[] projections) { mProjections = projections; return this; } public CursorFetcher setSelection(String selection, String[] selectionArgs) { mSelection = selection; mSelectionArgs = selectionArgs; return this; } public CursorFetcher setOrderBy(String orderBy) { mOrderBy = orderBy; return this; } /** * If you want to change the params of fetcher, call it to reset the old params. * * @return */ public CursorFetcher clear() { mProjections = null; mSelection = null; mSelectionArgs = null; mOrderBy = null; return this; } @Override
public Cursor fetch() throws FetchException, ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/providers/ContentDataProvider.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/CursorFetcher.java // public class CursorFetcher implements DataFetcher<Cursor> { // // private ContentResolver mResolver; // // private Uri mUri; // // private String[] mProjections; // // private String mSelection; // // private String[] mSelectionArgs; // // private String mOrderBy; // // public CursorFetcher(ContentResolver resolver, Uri uri) { // mResolver = resolver; // mUri = uri; // } // // public CursorFetcher setProjection(String[] projections) { // mProjections = projections; // return this; // } // // public CursorFetcher setSelection(String selection, String[] selectionArgs) { // mSelection = selection; // mSelectionArgs = selectionArgs; // return this; // } // // public CursorFetcher setOrderBy(String orderBy) { // mOrderBy = orderBy; // return this; // } // // /** // * If you want to change the params of fetcher, call it to reset the old params. // * // * @return // */ // public CursorFetcher clear() { // mProjections = null; // mSelection = null; // mSelectionArgs = null; // mOrderBy = null; // return this; // } // // @Override // public Cursor fetch() throws FetchException, ConvertException { // return mResolver.query(mUri, mProjections, mSelection, mSelectionArgs, mOrderBy); // } // }
import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import com.kifile.android.cornerstone.impl.fetchers.CursorFetcher;
package com.kifile.android.cornerstone.impl.providers; /** * ContentProvider数据获取基类,加入对数据变化的监听处理. * * @author kifile */ public class ContentDataProvider<DATA> extends AbstractDataProvider<DATA> { private final Uri mUri;
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/CursorFetcher.java // public class CursorFetcher implements DataFetcher<Cursor> { // // private ContentResolver mResolver; // // private Uri mUri; // // private String[] mProjections; // // private String mSelection; // // private String[] mSelectionArgs; // // private String mOrderBy; // // public CursorFetcher(ContentResolver resolver, Uri uri) { // mResolver = resolver; // mUri = uri; // } // // public CursorFetcher setProjection(String[] projections) { // mProjections = projections; // return this; // } // // public CursorFetcher setSelection(String selection, String[] selectionArgs) { // mSelection = selection; // mSelectionArgs = selectionArgs; // return this; // } // // public CursorFetcher setOrderBy(String orderBy) { // mOrderBy = orderBy; // return this; // } // // /** // * If you want to change the params of fetcher, call it to reset the old params. // * // * @return // */ // public CursorFetcher clear() { // mProjections = null; // mSelection = null; // mSelectionArgs = null; // mOrderBy = null; // return this; // } // // @Override // public Cursor fetch() throws FetchException, ConvertException { // return mResolver.query(mUri, mProjections, mSelection, mSelectionArgs, mOrderBy); // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/providers/ContentDataProvider.java import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import com.kifile.android.cornerstone.impl.fetchers.CursorFetcher; package com.kifile.android.cornerstone.impl.providers; /** * ContentProvider数据获取基类,加入对数据变化的监听处理. * * @author kifile */ public class ContentDataProvider<DATA> extends AbstractDataProvider<DATA> { private final Uri mUri;
private CursorFetcher mCursorFetcher;
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/String2JSONArrayConverter.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // }
import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import org.json.JSONArray; import org.json.JSONException;
package com.kifile.android.cornerstone.impl.fetchers; /** * Convert String to JSONArray. * * @author kifile */ public class String2JSONArrayConverter extends AbstractFetcherConverter<String, JSONArray> { public String2JSONArrayConverter(DataFetcher<String> proxy) { super(proxy); } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/String2JSONArrayConverter.java import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import org.json.JSONArray; import org.json.JSONException; package com.kifile.android.cornerstone.impl.fetchers; /** * Convert String to JSONArray. * * @author kifile */ public class String2JSONArrayConverter extends AbstractFetcherConverter<String, JSONArray> { public String2JSONArrayConverter(DataFetcher<String> proxy) { super(proxy); } @Override
protected JSONArray convert(@NonNull String s) throws ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/String2JSONObjectConverter.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // }
import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import org.json.JSONException; import org.json.JSONObject;
package com.kifile.android.cornerstone.impl.fetchers; /** * Convert String to JSONObject. * * @author kifile */ public class String2JSONObjectConverter extends AbstractFetcherConverter<String, JSONObject> { public String2JSONObjectConverter(DataFetcher<String> proxy) { super(proxy); } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/String2JSONObjectConverter.java import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import org.json.JSONException; import org.json.JSONObject; package com.kifile.android.cornerstone.impl.fetchers; /** * Convert String to JSONObject. * * @author kifile */ public class String2JSONObjectConverter extends AbstractFetcherConverter<String, JSONObject> { public String2JSONObjectConverter(DataFetcher<String> proxy) { super(proxy); } @Override
protected JSONObject convert(@NonNull String s) throws ConvertException {
kifile/Cornerstone
framework/src/androidTest/java/com/kifile/android/cornerstone/impl/CornerstoneTest.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/providers/CombinedDataProvider.java // public abstract class CombinedDataProvider extends AbstractDataProvider { // // private final Map<String, DataProvider> mCombinedProviders = new HashMap<>(); // // /** // * It should only be called in your constructor. // * // * @param key // * @param provider // */ // protected void put(String key, DataProvider provider) { // if (mCombinedProviders.containsKey(key)) { // throw new IllegalArgumentException("The key[" + key + "] has been registered."); // } // mCombinedProviders.put(key, provider); // } // // public DataProvider getProvider(String key) { // return mCombinedProviders.get(key); // } // // /** // * When asked refresh, always notify {@link #mCombinedProviders} to refresh. // * <p/> // * Otherwise, it won't call {@link #setData(Object)}, so {@link #isDataNeedUpdate()} // * always return true. // */ // @Override // public void refresh() { // for (DataProvider provider : mCombinedProviders.values()) { // if (provider.isDataNeedUpdate()) { // provider.refresh(); // } // } // } // // /** // * Refresh the target provider. // * // * @param key // */ // public void refresh(String key) { // DataProvider provider = getProvider(key); // if (provider == null) { // throw new IllegalArgumentException(); // } // provider.refresh(); // } // // @Override // public synchronized void notifyDataChanged() { // for (DataProvider provider : mCombinedProviders.values()) { // if (provider.isDataNeedUpdate()) { // provider.notifyDataChanged(); // } // } // } // // public synchronized void notifyDataChanged(String key) { // DataProvider provider = getProvider(key); // if (provider == null) { // throw new IllegalArgumentException(); // } // provider.notifyDataChanged(); // } // // @Override // public void registerDataObserver(DataObserver observer) { // throw new UnsupportedOperationException("Cannot register observer in " + getClass().getName()); // } // // @Override // public void unregisterDataObserver(DataObserver observer) { // throw new UnsupportedOperationException("Cannot register observer in " + getClass().getName()); // } // // public void registerDataObserver(String key, DataObserver observer) { // DataProvider provider = getProvider(key); // if (provider == null) { // throw new IllegalArgumentException(); // } // provider.registerDataObserver(observer); // } // // public void unregisterDataObserver(String key, DataObserver observer) { // DataProvider provider = getProvider(key); // if (provider == null) { // throw new IllegalArgumentException(); // } // provider.unregisterDataObserver(observer); // } // // @Override // public void release() { // super.release(); // for (DataProvider provider : mCombinedProviders.values()) { // provider.release(); // } // mCombinedProviders.clear(); // } // // }
import com.kifile.android.cornerstone.impl.providers.CombinedDataProvider; import junit.framework.TestCase;
package com.kifile.android.cornerstone.impl; /** * Testcase for {@link Cornerstone}. * * @author kifile */ public class CornerstoneTest extends TestCase { public static final String KEY_TEST_PROVIDER = "key_test_provider"; @Override protected void setUp() throws Exception { super.setUp(); Cornerstone manager = Cornerstone.getInstance();
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/providers/CombinedDataProvider.java // public abstract class CombinedDataProvider extends AbstractDataProvider { // // private final Map<String, DataProvider> mCombinedProviders = new HashMap<>(); // // /** // * It should only be called in your constructor. // * // * @param key // * @param provider // */ // protected void put(String key, DataProvider provider) { // if (mCombinedProviders.containsKey(key)) { // throw new IllegalArgumentException("The key[" + key + "] has been registered."); // } // mCombinedProviders.put(key, provider); // } // // public DataProvider getProvider(String key) { // return mCombinedProviders.get(key); // } // // /** // * When asked refresh, always notify {@link #mCombinedProviders} to refresh. // * <p/> // * Otherwise, it won't call {@link #setData(Object)}, so {@link #isDataNeedUpdate()} // * always return true. // */ // @Override // public void refresh() { // for (DataProvider provider : mCombinedProviders.values()) { // if (provider.isDataNeedUpdate()) { // provider.refresh(); // } // } // } // // /** // * Refresh the target provider. // * // * @param key // */ // public void refresh(String key) { // DataProvider provider = getProvider(key); // if (provider == null) { // throw new IllegalArgumentException(); // } // provider.refresh(); // } // // @Override // public synchronized void notifyDataChanged() { // for (DataProvider provider : mCombinedProviders.values()) { // if (provider.isDataNeedUpdate()) { // provider.notifyDataChanged(); // } // } // } // // public synchronized void notifyDataChanged(String key) { // DataProvider provider = getProvider(key); // if (provider == null) { // throw new IllegalArgumentException(); // } // provider.notifyDataChanged(); // } // // @Override // public void registerDataObserver(DataObserver observer) { // throw new UnsupportedOperationException("Cannot register observer in " + getClass().getName()); // } // // @Override // public void unregisterDataObserver(DataObserver observer) { // throw new UnsupportedOperationException("Cannot register observer in " + getClass().getName()); // } // // public void registerDataObserver(String key, DataObserver observer) { // DataProvider provider = getProvider(key); // if (provider == null) { // throw new IllegalArgumentException(); // } // provider.registerDataObserver(observer); // } // // public void unregisterDataObserver(String key, DataObserver observer) { // DataProvider provider = getProvider(key); // if (provider == null) { // throw new IllegalArgumentException(); // } // provider.unregisterDataObserver(observer); // } // // @Override // public void release() { // super.release(); // for (DataProvider provider : mCombinedProviders.values()) { // provider.release(); // } // mCombinedProviders.clear(); // } // // } // Path: framework/src/androidTest/java/com/kifile/android/cornerstone/impl/CornerstoneTest.java import com.kifile.android.cornerstone.impl.providers.CombinedDataProvider; import junit.framework.TestCase; package com.kifile.android.cornerstone.impl; /** * Testcase for {@link Cornerstone}. * * @author kifile */ public class CornerstoneTest extends TestCase { public static final String KEY_TEST_PROVIDER = "key_test_provider"; @Override protected void setUp() throws Exception { super.setUp(); Cornerstone manager = Cornerstone.getInstance();
manager.register(KEY_TEST_PROVIDER, CombinedDataProvider.class);
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/FileFetcher.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // }
import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream;
package com.kifile.android.cornerstone.impl.fetchers; /** * Fetch the InputStream of a file. * * @author kifile */ public class FileFetcher implements DataFetcher<InputStream> { private File mFile; public FileFetcher(String path) { mFile = new File(path); } public FileFetcher(File file) { mFile = file; } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/FileFetcher.java import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; package com.kifile.android.cornerstone.impl.fetchers; /** * Fetch the InputStream of a file. * * @author kifile */ public class FileFetcher implements DataFetcher<InputStream> { private File mFile; public FileFetcher(String path) { mFile = new File(path); } public FileFetcher(File file) { mFile = file; } @Override
public InputStream fetch() throws FetchException, ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/FileFetcher.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // }
import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream;
package com.kifile.android.cornerstone.impl.fetchers; /** * Fetch the InputStream of a file. * * @author kifile */ public class FileFetcher implements DataFetcher<InputStream> { private File mFile; public FileFetcher(String path) { mFile = new File(path); } public FileFetcher(File file) { mFile = file; } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/FileFetcher.java import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; package com.kifile.android.cornerstone.impl.fetchers; /** * Fetch the InputStream of a file. * * @author kifile */ public class FileFetcher implements DataFetcher<InputStream> { private File mFile; public FileFetcher(String path) { mFile = new File(path); } public FileFetcher(File file) { mFile = file; } @Override
public InputStream fetch() throws FetchException, ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/InputStream2StringConverter.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // }
import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringWriter;
package com.kifile.android.cornerstone.impl.fetchers; /** * Convert a InputStream to String. * * @author kifile */ public class InputStream2StringConverter extends AbstractFetcherConverter<InputStream, String> { public InputStream2StringConverter(DataFetcher<InputStream> proxy) { super(proxy); } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/AbstractFetcherConverter.java // public abstract class AbstractFetcherConverter<FROM, TO> implements DataFetcher<TO> { // // private DataFetcher<FROM> mProxy; // // /** // * Wrap the DataFetcher will be transformed. // * // * @param proxy // */ // public AbstractFetcherConverter(DataFetcher<FROM> proxy) { // mProxy = proxy; // } // // @Override // public TO fetch() throws FetchException, ConvertException { // FROM data = mProxy.fetch(); // if (data == null) { // throw new FetchException("Proxy return null."); // } // return convert(data); // } // // protected abstract TO convert(@NonNull FROM from) throws ConvertException; // // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/InputStream2StringConverter.java import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.AbstractFetcherConverter; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringWriter; package com.kifile.android.cornerstone.impl.fetchers; /** * Convert a InputStream to String. * * @author kifile */ public class InputStream2StringConverter extends AbstractFetcherConverter<InputStream, String> { public InputStream2StringConverter(DataFetcher<InputStream> proxy) { super(proxy); } @Override
protected String convert(@NonNull InputStream inputStream) throws ConvertException {
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/HttpActivity.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // }
import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider;
package com.kifile.android.sample.cornerstone; public class HttpActivity extends AppCompatActivity { private HttpSampleProvider mProvider; FloatingActionButton fab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/HttpActivity.java import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; package com.kifile.android.sample.cornerstone; public class HttpActivity extends AppCompatActivity { private HttpSampleProvider mProvider; FloatingActionButton fab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
mProvider = (HttpSampleProvider) Cornerstone.obtainProvider(HttpSampleProvider.KEY);
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/HttpActivity.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // }
import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider;
package com.kifile.android.sample.cornerstone; public class HttpActivity extends AppCompatActivity { private HttpSampleProvider mProvider; FloatingActionButton fab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mProvider = (HttpSampleProvider) Cornerstone.obtainProvider(HttpSampleProvider.KEY); setContentView(R.layout.activity_http); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); }
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/HttpActivity.java import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; package com.kifile.android.sample.cornerstone; public class HttpActivity extends AppCompatActivity { private HttpSampleProvider mProvider; FloatingActionButton fab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mProvider = (HttpSampleProvider) Cornerstone.obtainProvider(HttpSampleProvider.KEY); setContentView(R.layout.activity_http); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); }
private final DataObserver<String> mObserver = new DataObserver<String>() {
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/SampleApplication.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // }
import android.app.Application; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; import com.kifile.android.sample.cornerstone.data.SampleDataProvider;
package com.kifile.android.sample.cornerstone; /** * Register the providers int application class. * <p/> * Created by kifile on 15/8/25. */ public class SampleApplication extends Application { public static Application instance; static {
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/SampleApplication.java import android.app.Application; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; import com.kifile.android.sample.cornerstone.data.SampleDataProvider; package com.kifile.android.sample.cornerstone; /** * Register the providers int application class. * <p/> * Created by kifile on 15/8/25. */ public class SampleApplication extends Application { public static Application instance; static {
Cornerstone.registerProvider(SampleDataProvider.KEY, SampleDataProvider.class);
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/SampleApplication.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // }
import android.app.Application; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; import com.kifile.android.sample.cornerstone.data.SampleDataProvider;
package com.kifile.android.sample.cornerstone; /** * Register the providers int application class. * <p/> * Created by kifile on 15/8/25. */ public class SampleApplication extends Application { public static Application instance; static {
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/SampleApplication.java import android.app.Application; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; import com.kifile.android.sample.cornerstone.data.SampleDataProvider; package com.kifile.android.sample.cornerstone; /** * Register the providers int application class. * <p/> * Created by kifile on 15/8/25. */ public class SampleApplication extends Application { public static Application instance; static {
Cornerstone.registerProvider(SampleDataProvider.KEY, SampleDataProvider.class);
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/SampleApplication.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // }
import android.app.Application; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; import com.kifile.android.sample.cornerstone.data.SampleDataProvider;
package com.kifile.android.sample.cornerstone; /** * Register the providers int application class. * <p/> * Created by kifile on 15/8/25. */ public class SampleApplication extends Application { public static Application instance; static { Cornerstone.registerProvider(SampleDataProvider.KEY, SampleDataProvider.class);
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/SampleApplication.java import android.app.Application; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; import com.kifile.android.sample.cornerstone.data.SampleDataProvider; package com.kifile.android.sample.cornerstone; /** * Register the providers int application class. * <p/> * Created by kifile on 15/8/25. */ public class SampleApplication extends Application { public static Application instance; static { Cornerstone.registerProvider(SampleDataProvider.KEY, SampleDataProvider.class);
Cornerstone.registerProvider(ContactsProvider.KEY, ContactsProvider.class);
kifile/Cornerstone
app/src/main/java/com/kifile/android/sample/cornerstone/SampleApplication.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // }
import android.app.Application; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; import com.kifile.android.sample.cornerstone.data.SampleDataProvider;
package com.kifile.android.sample.cornerstone; /** * Register the providers int application class. * <p/> * Created by kifile on 15/8/25. */ public class SampleApplication extends Application { public static Application instance; static { Cornerstone.registerProvider(SampleDataProvider.KEY, SampleDataProvider.class); Cornerstone.registerProvider(ContactsProvider.KEY, ContactsProvider.class);
// Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java // public class Cornerstone extends AbstractDataProviderManager { // // private static Cornerstone sInstance; // // private Cornerstone() { // // Make Cornerstone singleton. // } // // /** // * Use singleton here. // * // * @return // */ // public static Cornerstone getInstance() { // if (sInstance == null) { // synchronized (Cornerstone.class) { // if (sInstance == null) { // sInstance = new Cornerstone(); // } // } // } // return sInstance; // } // // public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) { // getInstance().register(key, providerClazz); // } // // public static DataProvider obtainProvider(String key) { // return getInstance().obtain(key); // } // // public static void releaseProvider(String key) { // getInstance().release(key); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/ContactsProvider.java // public class ContactsProvider extends ContentDataProvider<List<ContactsProvider.Contact>> { // // public static final String KEY = ContactsProvider.class.getSimpleName(); // // public ContactsProvider() { // super(SampleApplication.instance, ContactsContract.Contacts.CONTENT_URI); // setFetcher(new AnnotationCursorConverter<>(buildCursorFetcher(), Contact.class)); // } // // // public class ContactConverter extends AbstractFetcherConverter<Cursor, List<Contact>> { // // // // /** // // * Wrap the DataFetcher will be transformed. // // * // // * @param proxy // // */ // // public ContactConverter(DataFetcher<Cursor> proxy) { // // super(proxy); // // } // // // // @Override // // protected List<Contact> convert(Cursor cursor) { // // if (cursor != null) { // // int nameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); // // List<Contact> contacts = new ArrayList<>(); // // for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // // String name = cursor.getString(nameColumn); // // Contact contact = new Contact(); // // contact.name = name; // // contacts.add(contact); // // } // // cursor.close(); // // return contacts; // // } // // return null; // // } // // } // // public static class Contact { // // @Property(name = ContactsContract.Contacts.DISPLAY_NAME) // public String name; // // } // // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/HttpSampleProvider.java // public class HttpSampleProvider extends AbstractDataProvider<String> { // // public static final String KEY = HttpSampleProvider.class.getName(); // // public HttpSampleProvider() { // HttpFetcher fetcher = new HttpFetcher(HttpFetcher.METHOD_GET, "https://baidu.com"); // setAsync(true); // setFetcher(new InputStream2StringConverter(fetcher)); // } // } // // Path: app/src/main/java/com/kifile/android/sample/cornerstone/data/SampleDataProvider.java // public class SampleDataProvider extends AbstractDataProvider<List<Class>> { // // public static final String KEY = SampleDataProvider.class.getSimpleName(); // // public SampleDataProvider() { // SampleActivityFetcher fetcher = new SampleActivityFetcher(); // fetcher.addActivity(SampleActivity.class); // fetcher.addActivity(ContactFetcherActivity.class); // fetcher.addActivity(HttpActivity.class); // setFetcher(fetcher); // } // // public class SampleActivityFetcher implements DataFetcher<List<Class>> { // // private List<Class> mActivities; // // public SampleActivityFetcher() { // mActivities = new ArrayList<>(); // } // // public void addActivity(Class clazz) { // mActivities.add(clazz); // } // // @Override // public List<Class> fetch() { // return mActivities; // } // } // // } // Path: app/src/main/java/com/kifile/android/sample/cornerstone/SampleApplication.java import android.app.Application; import com.kifile.android.cornerstone.impl.Cornerstone; import com.kifile.android.sample.cornerstone.data.ContactsProvider; import com.kifile.android.sample.cornerstone.data.HttpSampleProvider; import com.kifile.android.sample.cornerstone.data.SampleDataProvider; package com.kifile.android.sample.cornerstone; /** * Register the providers int application class. * <p/> * Created by kifile on 15/8/25. */ public class SampleApplication extends Application { public static Application instance; static { Cornerstone.registerProvider(SampleDataProvider.KEY, SampleDataProvider.class); Cornerstone.registerProvider(ContactsProvider.KEY, ContactsProvider.class);
Cornerstone.registerProvider(HttpSampleProvider.KEY, HttpSampleProvider.class);
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataProvider.java // public interface DataProvider<DATA> { // // void setFetcher(DataFetcher<DATA> fetcher); // // /** // * Add the observer into watch list, when data changed, notify it. // * // * @param observer // */ // void registerDataObserver(DataObserver<DATA> observer); // // /** // * Remove observer from watch list. // * // * @param observer // */ // void unregisterDataObserver(DataObserver<DATA> observer); // // /** // * Refresh data. // */ // void refresh(); // // /** // * Notify observers data changed. // */ // void notifyDataChanged(); // // DATA getData(); // // /** // * @return If the data need update, return true. // */ // boolean isDataNeedUpdate(); // // /** // * Release the resources when destroy. If the worker thread is working, stop it. // */ // void release(); // }
import com.kifile.android.cornerstone.core.AbstractDataProviderManager; import com.kifile.android.cornerstone.core.DataProvider;
package com.kifile.android.cornerstone.impl; /** * Cornerstone is a simple implement of {@link AbstractDataProviderManager}. * * @author kifile */ public class Cornerstone extends AbstractDataProviderManager { private static Cornerstone sInstance; private Cornerstone() { // Make Cornerstone singleton. } /** * Use singleton here. * * @return */ public static Cornerstone getInstance() { if (sInstance == null) { synchronized (Cornerstone.class) { if (sInstance == null) { sInstance = new Cornerstone(); } } } return sInstance; }
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataProvider.java // public interface DataProvider<DATA> { // // void setFetcher(DataFetcher<DATA> fetcher); // // /** // * Add the observer into watch list, when data changed, notify it. // * // * @param observer // */ // void registerDataObserver(DataObserver<DATA> observer); // // /** // * Remove observer from watch list. // * // * @param observer // */ // void unregisterDataObserver(DataObserver<DATA> observer); // // /** // * Refresh data. // */ // void refresh(); // // /** // * Notify observers data changed. // */ // void notifyDataChanged(); // // DATA getData(); // // /** // * @return If the data need update, return true. // */ // boolean isDataNeedUpdate(); // // /** // * Release the resources when destroy. If the worker thread is working, stop it. // */ // void release(); // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/Cornerstone.java import com.kifile.android.cornerstone.core.AbstractDataProviderManager; import com.kifile.android.cornerstone.core.DataProvider; package com.kifile.android.cornerstone.impl; /** * Cornerstone is a simple implement of {@link AbstractDataProviderManager}. * * @author kifile */ public class Cornerstone extends AbstractDataProviderManager { private static Cornerstone sInstance; private Cornerstone() { // Make Cornerstone singleton. } /** * Use singleton here. * * @return */ public static Cornerstone getInstance() { if (sInstance == null) { synchronized (Cornerstone.class) { if (sInstance == null) { sInstance = new Cornerstone(); } } } return sInstance; }
public static void registerProvider(String key, Class<? extends DataProvider> providerClazz) {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/HttpFetcher.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/utils/HttpUtils.java // public class HttpUtils { // // private static final OkHttpClient sClient = new OkHttpClient(); // // static { // // 设置连接 5 秒超时. // sClient.setWriteTimeout(5, TimeUnit.SECONDS); // sClient.setConnectTimeout(5, TimeUnit.SECONDS); // sClient.setReadTimeout(5, TimeUnit.SECONDS); // } // // /** // * 执行Request命令. // * // * @param request // * @return // * @throws IOException // */ // public static Response getResponse(Request request) throws IOException { // return sClient.newCall(request).execute(); // } // // public static OkHttpClient getClient() { // return sClient; // } // }
import android.util.Log; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import com.kifile.android.cornerstone.utils.HttpUtils; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.Headers; import com.squareup.okhttp.MediaType; import com.squareup.okhttp.MultipartBuilder; import com.squareup.okhttp.Request; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.util.Map;
public void reset() { mBodyType = BODY_TYPE_FORM; mParams = null; mFileParams = null; mHttpHeader = null; } public void setParams(Map<String, String> params) { mParams = params; } public void setFileParams(Map<String, FileEntry> fileParams) { mFileParams = fileParams; } public void setHttpHeader(Map<String, String> headers) { if (headers != null) { Headers.Builder headerBuilder = new Headers.Builder(); for (Map.Entry<String, String> header : headers.entrySet()) { headerBuilder.add(header.getKey(), header.getValue()); } setHttpHeader(headerBuilder.build()); } } public void setHttpHeader(Headers header) { mHttpHeader = header; } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/utils/HttpUtils.java // public class HttpUtils { // // private static final OkHttpClient sClient = new OkHttpClient(); // // static { // // 设置连接 5 秒超时. // sClient.setWriteTimeout(5, TimeUnit.SECONDS); // sClient.setConnectTimeout(5, TimeUnit.SECONDS); // sClient.setReadTimeout(5, TimeUnit.SECONDS); // } // // /** // * 执行Request命令. // * // * @param request // * @return // * @throws IOException // */ // public static Response getResponse(Request request) throws IOException { // return sClient.newCall(request).execute(); // } // // public static OkHttpClient getClient() { // return sClient; // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/HttpFetcher.java import android.util.Log; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import com.kifile.android.cornerstone.utils.HttpUtils; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.Headers; import com.squareup.okhttp.MediaType; import com.squareup.okhttp.MultipartBuilder; import com.squareup.okhttp.Request; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.util.Map; public void reset() { mBodyType = BODY_TYPE_FORM; mParams = null; mFileParams = null; mHttpHeader = null; } public void setParams(Map<String, String> params) { mParams = params; } public void setFileParams(Map<String, FileEntry> fileParams) { mFileParams = fileParams; } public void setHttpHeader(Map<String, String> headers) { if (headers != null) { Headers.Builder headerBuilder = new Headers.Builder(); for (Map.Entry<String, String> header : headers.entrySet()) { headerBuilder.add(header.getKey(), header.getValue()); } setHttpHeader(headerBuilder.build()); } } public void setHttpHeader(Headers header) { mHttpHeader = header; } @Override
public String fetch() throws FetchException, ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/HttpFetcher.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/utils/HttpUtils.java // public class HttpUtils { // // private static final OkHttpClient sClient = new OkHttpClient(); // // static { // // 设置连接 5 秒超时. // sClient.setWriteTimeout(5, TimeUnit.SECONDS); // sClient.setConnectTimeout(5, TimeUnit.SECONDS); // sClient.setReadTimeout(5, TimeUnit.SECONDS); // } // // /** // * 执行Request命令. // * // * @param request // * @return // * @throws IOException // */ // public static Response getResponse(Request request) throws IOException { // return sClient.newCall(request).execute(); // } // // public static OkHttpClient getClient() { // return sClient; // } // }
import android.util.Log; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import com.kifile.android.cornerstone.utils.HttpUtils; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.Headers; import com.squareup.okhttp.MediaType; import com.squareup.okhttp.MultipartBuilder; import com.squareup.okhttp.Request; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.util.Map;
public void reset() { mBodyType = BODY_TYPE_FORM; mParams = null; mFileParams = null; mHttpHeader = null; } public void setParams(Map<String, String> params) { mParams = params; } public void setFileParams(Map<String, FileEntry> fileParams) { mFileParams = fileParams; } public void setHttpHeader(Map<String, String> headers) { if (headers != null) { Headers.Builder headerBuilder = new Headers.Builder(); for (Map.Entry<String, String> header : headers.entrySet()) { headerBuilder.add(header.getKey(), header.getValue()); } setHttpHeader(headerBuilder.build()); } } public void setHttpHeader(Headers header) { mHttpHeader = header; } @Override
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/utils/HttpUtils.java // public class HttpUtils { // // private static final OkHttpClient sClient = new OkHttpClient(); // // static { // // 设置连接 5 秒超时. // sClient.setWriteTimeout(5, TimeUnit.SECONDS); // sClient.setConnectTimeout(5, TimeUnit.SECONDS); // sClient.setReadTimeout(5, TimeUnit.SECONDS); // } // // /** // * 执行Request命令. // * // * @param request // * @return // * @throws IOException // */ // public static Response getResponse(Request request) throws IOException { // return sClient.newCall(request).execute(); // } // // public static OkHttpClient getClient() { // return sClient; // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/HttpFetcher.java import android.util.Log; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import com.kifile.android.cornerstone.utils.HttpUtils; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.Headers; import com.squareup.okhttp.MediaType; import com.squareup.okhttp.MultipartBuilder; import com.squareup.okhttp.Request; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.util.Map; public void reset() { mBodyType = BODY_TYPE_FORM; mParams = null; mFileParams = null; mHttpHeader = null; } public void setParams(Map<String, String> params) { mParams = params; } public void setFileParams(Map<String, FileEntry> fileParams) { mFileParams = fileParams; } public void setHttpHeader(Map<String, String> headers) { if (headers != null) { Headers.Builder headerBuilder = new Headers.Builder(); for (Map.Entry<String, String> header : headers.entrySet()) { headerBuilder.add(header.getKey(), header.getValue()); } setHttpHeader(headerBuilder.build()); } } public void setHttpHeader(Headers header) { mHttpHeader = header; } @Override
public String fetch() throws FetchException, ConvertException {
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/HttpFetcher.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/utils/HttpUtils.java // public class HttpUtils { // // private static final OkHttpClient sClient = new OkHttpClient(); // // static { // // 设置连接 5 秒超时. // sClient.setWriteTimeout(5, TimeUnit.SECONDS); // sClient.setConnectTimeout(5, TimeUnit.SECONDS); // sClient.setReadTimeout(5, TimeUnit.SECONDS); // } // // /** // * 执行Request命令. // * // * @param request // * @return // * @throws IOException // */ // public static Response getResponse(Request request) throws IOException { // return sClient.newCall(request).execute(); // } // // public static OkHttpClient getClient() { // return sClient; // } // }
import android.util.Log; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import com.kifile.android.cornerstone.utils.HttpUtils; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.Headers; import com.squareup.okhttp.MediaType; import com.squareup.okhttp.MultipartBuilder; import com.squareup.okhttp.Request; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.util.Map;
} case METHOD_GET: { String url = appendParams(mUrl, mParams); requestBuilder = new Request.Builder().url(url).get(); break; } case METHOD_POST: { requestBuilder = new Request.Builder().url(mUrl).post(getRequestBody(mParams, mFileParams)); break; } case METHOD_DELETE: { requestBuilder = new Request.Builder().url(mUrl).delete(getRequestBody(mParams, mFileParams)); break; } case METHOD_PUT: { requestBuilder = new Request.Builder().url(mUrl).put(getRequestBody(mParams, mFileParams)); break; } case METHOD_PATCH: { requestBuilder = new Request.Builder().url(mUrl).patch(getRequestBody(mParams, mFileParams)); break; } default: throw new IllegalArgumentException("Unsupported method:" + mMethod); } if (requestBuilder != null) { try { if (mHttpHeader != null) { requestBuilder.headers(mHttpHeader); }
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/FetchException.java // public class FetchException extends Exception { // // public FetchException() { // } // // public FetchException(String detailMessage) { // super(detailMessage); // } // // public FetchException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public FetchException(Throwable throwable) { // super(throwable); // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/utils/HttpUtils.java // public class HttpUtils { // // private static final OkHttpClient sClient = new OkHttpClient(); // // static { // // 设置连接 5 秒超时. // sClient.setWriteTimeout(5, TimeUnit.SECONDS); // sClient.setConnectTimeout(5, TimeUnit.SECONDS); // sClient.setReadTimeout(5, TimeUnit.SECONDS); // } // // /** // * 执行Request命令. // * // * @param request // * @return // * @throws IOException // */ // public static Response getResponse(Request request) throws IOException { // return sClient.newCall(request).execute(); // } // // public static OkHttpClient getClient() { // return sClient; // } // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/fetchers/HttpFetcher.java import android.util.Log; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.FetchException; import com.kifile.android.cornerstone.utils.HttpUtils; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.Headers; import com.squareup.okhttp.MediaType; import com.squareup.okhttp.MultipartBuilder; import com.squareup.okhttp.Request; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.util.Map; } case METHOD_GET: { String url = appendParams(mUrl, mParams); requestBuilder = new Request.Builder().url(url).get(); break; } case METHOD_POST: { requestBuilder = new Request.Builder().url(mUrl).post(getRequestBody(mParams, mFileParams)); break; } case METHOD_DELETE: { requestBuilder = new Request.Builder().url(mUrl).delete(getRequestBody(mParams, mFileParams)); break; } case METHOD_PUT: { requestBuilder = new Request.Builder().url(mUrl).put(getRequestBody(mParams, mFileParams)); break; } case METHOD_PATCH: { requestBuilder = new Request.Builder().url(mUrl).patch(getRequestBody(mParams, mFileParams)); break; } default: throw new IllegalArgumentException("Unsupported method:" + mMethod); } if (requestBuilder != null) { try { if (mHttpHeader != null) { requestBuilder.headers(mHttpHeader); }
Response response = HttpUtils.getResponse(requestBuilder.build());
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/providers/AbstractDataProvider.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataProvider.java // public interface DataProvider<DATA> { // // void setFetcher(DataFetcher<DATA> fetcher); // // /** // * Add the observer into watch list, when data changed, notify it. // * // * @param observer // */ // void registerDataObserver(DataObserver<DATA> observer); // // /** // * Remove observer from watch list. // * // * @param observer // */ // void unregisterDataObserver(DataObserver<DATA> observer); // // /** // * Refresh data. // */ // void refresh(); // // /** // * Notify observers data changed. // */ // void notifyDataChanged(); // // DATA getData(); // // /** // * @return If the data need update, return true. // */ // boolean isDataNeedUpdate(); // // /** // * Release the resources when destroy. If the worker thread is working, stop it. // */ // void release(); // }
import android.os.Handler; import android.os.Looper; import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.core.DataProvider; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executor; import java.util.concurrent.Executors;
package com.kifile.android.cornerstone.impl.providers; /** * The implement of {@link DataProvider}. * * @author kifile */ public abstract class AbstractDataProvider<DATA> implements DataProvider<DATA> { private static Executor EXECUTOR;
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataProvider.java // public interface DataProvider<DATA> { // // void setFetcher(DataFetcher<DATA> fetcher); // // /** // * Add the observer into watch list, when data changed, notify it. // * // * @param observer // */ // void registerDataObserver(DataObserver<DATA> observer); // // /** // * Remove observer from watch list. // * // * @param observer // */ // void unregisterDataObserver(DataObserver<DATA> observer); // // /** // * Refresh data. // */ // void refresh(); // // /** // * Notify observers data changed. // */ // void notifyDataChanged(); // // DATA getData(); // // /** // * @return If the data need update, return true. // */ // boolean isDataNeedUpdate(); // // /** // * Release the resources when destroy. If the worker thread is working, stop it. // */ // void release(); // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/providers/AbstractDataProvider.java import android.os.Handler; import android.os.Looper; import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.core.DataProvider; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executor; import java.util.concurrent.Executors; package com.kifile.android.cornerstone.impl.providers; /** * The implement of {@link DataProvider}. * * @author kifile */ public abstract class AbstractDataProvider<DATA> implements DataProvider<DATA> { private static Executor EXECUTOR;
private final List<DataObserver<DATA>> mObservers = new CopyOnWriteArrayList<>();
kifile/Cornerstone
framework/src/main/java/com/kifile/android/cornerstone/impl/providers/AbstractDataProvider.java
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataProvider.java // public interface DataProvider<DATA> { // // void setFetcher(DataFetcher<DATA> fetcher); // // /** // * Add the observer into watch list, when data changed, notify it. // * // * @param observer // */ // void registerDataObserver(DataObserver<DATA> observer); // // /** // * Remove observer from watch list. // * // * @param observer // */ // void unregisterDataObserver(DataObserver<DATA> observer); // // /** // * Refresh data. // */ // void refresh(); // // /** // * Notify observers data changed. // */ // void notifyDataChanged(); // // DATA getData(); // // /** // * @return If the data need update, return true. // */ // boolean isDataNeedUpdate(); // // /** // * Release the resources when destroy. If the worker thread is working, stop it. // */ // void release(); // }
import android.os.Handler; import android.os.Looper; import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.core.DataProvider; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executor; import java.util.concurrent.Executors;
package com.kifile.android.cornerstone.impl.providers; /** * The implement of {@link DataProvider}. * * @author kifile */ public abstract class AbstractDataProvider<DATA> implements DataProvider<DATA> { private static Executor EXECUTOR; private final List<DataObserver<DATA>> mObservers = new CopyOnWriteArrayList<>(); private DATA mData;
// Path: framework/src/main/java/com/kifile/android/cornerstone/core/ConvertException.java // public class ConvertException extends Exception { // // private Object o; // // public ConvertException() { // } // // public ConvertException(String detailMessage) { // super(detailMessage); // } // // public ConvertException(String detailMessage, Throwable throwable) { // super(detailMessage, throwable); // } // // public ConvertException(Throwable throwable) { // super(throwable); // } // // public void setError(Object error) { // o = error; // } // // public Object getError() { // return o; // } // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataFetcher.java // public interface DataFetcher<DATA> { // // /** // * Fetch data. // * // * @return If fetch successful, return the data. // * @throws FetchException Throw FetchException when you cannot fetch a data. // * @throws ConvertException Throw ConvertException when you cannot convert the data to another type. // */ // DATA fetch() throws FetchException, ConvertException; // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataObserver.java // public interface DataObserver<DATA> { // // /** // * Watch if the data of {@link DataProvider} is changed. // * // * @param data // */ // void onDataChanged(DATA data); // } // // Path: framework/src/main/java/com/kifile/android/cornerstone/core/DataProvider.java // public interface DataProvider<DATA> { // // void setFetcher(DataFetcher<DATA> fetcher); // // /** // * Add the observer into watch list, when data changed, notify it. // * // * @param observer // */ // void registerDataObserver(DataObserver<DATA> observer); // // /** // * Remove observer from watch list. // * // * @param observer // */ // void unregisterDataObserver(DataObserver<DATA> observer); // // /** // * Refresh data. // */ // void refresh(); // // /** // * Notify observers data changed. // */ // void notifyDataChanged(); // // DATA getData(); // // /** // * @return If the data need update, return true. // */ // boolean isDataNeedUpdate(); // // /** // * Release the resources when destroy. If the worker thread is working, stop it. // */ // void release(); // } // Path: framework/src/main/java/com/kifile/android/cornerstone/impl/providers/AbstractDataProvider.java import android.os.Handler; import android.os.Looper; import android.support.annotation.NonNull; import com.kifile.android.cornerstone.core.ConvertException; import com.kifile.android.cornerstone.core.DataFetcher; import com.kifile.android.cornerstone.core.DataObserver; import com.kifile.android.cornerstone.core.DataProvider; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executor; import java.util.concurrent.Executors; package com.kifile.android.cornerstone.impl.providers; /** * The implement of {@link DataProvider}. * * @author kifile */ public abstract class AbstractDataProvider<DATA> implements DataProvider<DATA> { private static Executor EXECUTOR; private final List<DataObserver<DATA>> mObservers = new CopyOnWriteArrayList<>(); private DATA mData;
protected DataFetcher<DATA> mFetcher;
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ComponentNamedInjectionTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/ConverterFactory.java // @Name("converterFactory") // @Scope(ScopeType.APPLICATION) // @Startup // public class ConverterFactory // { // @Factory(value = "converter", autoCreate = true) // public FluidOuncesConverter createNamedConverter() // { // return new FluidOuncesConverter("created-by-factory"); // } // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.ConverterFactory; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentNamedInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/ConverterFactory.java // @Name("converterFactory") // @Scope(ScopeType.APPLICATION) // @Startup // public class ConverterFactory // { // @Factory(value = "converter", autoCreate = true) // public FluidOuncesConverter createNamedConverter() // { // return new FluidOuncesConverter("created-by-factory"); // } // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ComponentNamedInjectionTestCase.java import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.ConverterFactory; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentNamedInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(FluidOuncesConverter.class, ConverterFactory.class)
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ComponentNamedInjectionTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/ConverterFactory.java // @Name("converterFactory") // @Scope(ScopeType.APPLICATION) // @Startup // public class ConverterFactory // { // @Factory(value = "converter", autoCreate = true) // public FluidOuncesConverter createNamedConverter() // { // return new FluidOuncesConverter("created-by-factory"); // } // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.ConverterFactory; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentNamedInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/ConverterFactory.java // @Name("converterFactory") // @Scope(ScopeType.APPLICATION) // @Startup // public class ConverterFactory // { // @Factory(value = "converter", autoCreate = true) // public FluidOuncesConverter createNamedConverter() // { // return new FluidOuncesConverter("created-by-factory"); // } // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ComponentNamedInjectionTestCase.java import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.ConverterFactory; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentNamedInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(FluidOuncesConverter.class, ConverterFactory.class)
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/EventTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionEmitter.java // @Name("emitter") // public class ConversionEmitter // { // // public void convertToMilliliters(Double oz) // { // Events.instance().raiseEvent(Event.CONVERT_OZ_TO_ML, oz); // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java // @Name("holder") // public class ConversionResultHolder // { // private Double milliliters = Double.NaN; // // @In // private FluidOuncesConverter converter; // // @Observer(Event.CONVERT_OZ_TO_ML) // public void observe(Double oz) // { // milliliters = converter.convertToMillilitres(oz); // } // // public Double getMilliliters() // { // return milliliters; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/Event.java // public class Event // { // public static final String CONVERT_OZ_TO_ML = "CONVERT_OZ_TO_ML"; // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.event.ConversionEmitter; import org.jboss.arquillian.seam2.test.event.ConversionResultHolder; import org.jboss.arquillian.seam2.test.event.Event; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class EventTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionEmitter.java // @Name("emitter") // public class ConversionEmitter // { // // public void convertToMilliliters(Double oz) // { // Events.instance().raiseEvent(Event.CONVERT_OZ_TO_ML, oz); // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java // @Name("holder") // public class ConversionResultHolder // { // private Double milliliters = Double.NaN; // // @In // private FluidOuncesConverter converter; // // @Observer(Event.CONVERT_OZ_TO_ML) // public void observe(Double oz) // { // milliliters = converter.convertToMillilitres(oz); // } // // public Double getMilliliters() // { // return milliliters; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/Event.java // public class Event // { // public static final String CONVERT_OZ_TO_ML = "CONVERT_OZ_TO_ML"; // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/EventTestCase.java import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.event.ConversionEmitter; import org.jboss.arquillian.seam2.test.event.ConversionResultHolder; import org.jboss.arquillian.seam2.test.event.Event; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class EventTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addPackages(true, Event.class.getPackage(), FluidOuncesConverter.class.getPackage())
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/EventTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionEmitter.java // @Name("emitter") // public class ConversionEmitter // { // // public void convertToMilliliters(Double oz) // { // Events.instance().raiseEvent(Event.CONVERT_OZ_TO_ML, oz); // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java // @Name("holder") // public class ConversionResultHolder // { // private Double milliliters = Double.NaN; // // @In // private FluidOuncesConverter converter; // // @Observer(Event.CONVERT_OZ_TO_ML) // public void observe(Double oz) // { // milliliters = converter.convertToMillilitres(oz); // } // // public Double getMilliliters() // { // return milliliters; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/Event.java // public class Event // { // public static final String CONVERT_OZ_TO_ML = "CONVERT_OZ_TO_ML"; // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.event.ConversionEmitter; import org.jboss.arquillian.seam2.test.event.ConversionResultHolder; import org.jboss.arquillian.seam2.test.event.Event; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class EventTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionEmitter.java // @Name("emitter") // public class ConversionEmitter // { // // public void convertToMilliliters(Double oz) // { // Events.instance().raiseEvent(Event.CONVERT_OZ_TO_ML, oz); // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java // @Name("holder") // public class ConversionResultHolder // { // private Double milliliters = Double.NaN; // // @In // private FluidOuncesConverter converter; // // @Observer(Event.CONVERT_OZ_TO_ML) // public void observe(Double oz) // { // milliliters = converter.convertToMillilitres(oz); // } // // public Double getMilliliters() // { // return milliliters; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/Event.java // public class Event // { // public static final String CONVERT_OZ_TO_ML = "CONVERT_OZ_TO_ML"; // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/EventTestCase.java import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.event.ConversionEmitter; import org.jboss.arquillian.seam2.test.event.ConversionResultHolder; import org.jboss.arquillian.seam2.test.event.Event; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class EventTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addPackages(true, Event.class.getPackage(), FluidOuncesConverter.class.getPackage())
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/EventTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionEmitter.java // @Name("emitter") // public class ConversionEmitter // { // // public void convertToMilliliters(Double oz) // { // Events.instance().raiseEvent(Event.CONVERT_OZ_TO_ML, oz); // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java // @Name("holder") // public class ConversionResultHolder // { // private Double milliliters = Double.NaN; // // @In // private FluidOuncesConverter converter; // // @Observer(Event.CONVERT_OZ_TO_ML) // public void observe(Double oz) // { // milliliters = converter.convertToMillilitres(oz); // } // // public Double getMilliliters() // { // return milliliters; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/Event.java // public class Event // { // public static final String CONVERT_OZ_TO_ML = "CONVERT_OZ_TO_ML"; // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.event.ConversionEmitter; import org.jboss.arquillian.seam2.test.event.ConversionResultHolder; import org.jboss.arquillian.seam2.test.event.Event; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class EventTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackages(true, Event.class.getPackage(), FluidOuncesConverter.class.getPackage()) .addPackages(true, "org.fest") .addPackages(true, "org.dom4j") // Required for JBoss AS 4.2.3.GA .addAsResource(EmptyAsset.INSTANCE, "seam.properties") .setWebXML("web.xml"); } @In
// Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionEmitter.java // @Name("emitter") // public class ConversionEmitter // { // // public void convertToMilliliters(Double oz) // { // Events.instance().raiseEvent(Event.CONVERT_OZ_TO_ML, oz); // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java // @Name("holder") // public class ConversionResultHolder // { // private Double milliliters = Double.NaN; // // @In // private FluidOuncesConverter converter; // // @Observer(Event.CONVERT_OZ_TO_ML) // public void observe(Double oz) // { // milliliters = converter.convertToMillilitres(oz); // } // // public Double getMilliliters() // { // return milliliters; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/Event.java // public class Event // { // public static final String CONVERT_OZ_TO_ML = "CONVERT_OZ_TO_ML"; // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/EventTestCase.java import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.event.ConversionEmitter; import org.jboss.arquillian.seam2.test.event.ConversionResultHolder; import org.jboss.arquillian.seam2.test.event.Event; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class EventTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackages(true, Event.class.getPackage(), FluidOuncesConverter.class.getPackage()) .addPackages(true, "org.fest") .addPackages(true, "org.dom4j") // Required for JBoss AS 4.2.3.GA .addAsResource(EmptyAsset.INSTANCE, "seam.properties") .setWebXML("web.xml"); } @In
ConversionEmitter emitter;
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/EventTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionEmitter.java // @Name("emitter") // public class ConversionEmitter // { // // public void convertToMilliliters(Double oz) // { // Events.instance().raiseEvent(Event.CONVERT_OZ_TO_ML, oz); // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java // @Name("holder") // public class ConversionResultHolder // { // private Double milliliters = Double.NaN; // // @In // private FluidOuncesConverter converter; // // @Observer(Event.CONVERT_OZ_TO_ML) // public void observe(Double oz) // { // milliliters = converter.convertToMillilitres(oz); // } // // public Double getMilliliters() // { // return milliliters; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/Event.java // public class Event // { // public static final String CONVERT_OZ_TO_ML = "CONVERT_OZ_TO_ML"; // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.event.ConversionEmitter; import org.jboss.arquillian.seam2.test.event.ConversionResultHolder; import org.jboss.arquillian.seam2.test.event.Event; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class EventTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackages(true, Event.class.getPackage(), FluidOuncesConverter.class.getPackage()) .addPackages(true, "org.fest") .addPackages(true, "org.dom4j") // Required for JBoss AS 4.2.3.GA .addAsResource(EmptyAsset.INSTANCE, "seam.properties") .setWebXML("web.xml"); } @In ConversionEmitter emitter; @In
// Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionEmitter.java // @Name("emitter") // public class ConversionEmitter // { // // public void convertToMilliliters(Double oz) // { // Events.instance().raiseEvent(Event.CONVERT_OZ_TO_ML, oz); // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java // @Name("holder") // public class ConversionResultHolder // { // private Double milliliters = Double.NaN; // // @In // private FluidOuncesConverter converter; // // @Observer(Event.CONVERT_OZ_TO_ML) // public void observe(Double oz) // { // milliliters = converter.convertToMillilitres(oz); // } // // public Double getMilliliters() // { // return milliliters; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/event/Event.java // public class Event // { // public static final String CONVERT_OZ_TO_ML = "CONVERT_OZ_TO_ML"; // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/EventTestCase.java import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.event.ConversionEmitter; import org.jboss.arquillian.seam2.test.event.ConversionResultHolder; import org.jboss.arquillian.seam2.test.event.Event; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class EventTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackages(true, Event.class.getPackage(), FluidOuncesConverter.class.getPackage()) .addPackages(true, "org.fest") .addPackages(true, "org.dom4j") // Required for JBoss AS 4.2.3.GA .addAsResource(EmptyAsset.INSTANCE, "seam.properties") .setWebXML("web.xml"); } @In ConversionEmitter emitter; @In
ConversionResultHolder holder;
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ConversationTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/conversation/Item.java // public class Item // { // // private final String name; // // private final BigDecimal price; // // public Item(String name, BigDecimal price) // { // this.name = name; // this.price = price; // } // // // Public methods // // @Override // public int hashCode() // { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((price == null) ? 0 : price.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) // { // if (this == obj) // { // return true; // } // if (!(obj instanceof Item)) // { // return false; // } // // final Item other = (Item) obj; // // if (name == null && other.getName() != null) // { // return false; // } // else if (!name.equals(other.getName())) // { // return false; // } // // if (price == null && other.getPrice() != null) // { // return false; // } // else if (!price.equals(other.getPrice())) // { // return false; // } // // return true; // } // // // Accessor methods // // public String getName() // { // return name; // } // // public BigDecimal getPrice() // { // return price; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/conversation/ShoppingCart.java // @Name("shoppingCart") // @Conversational // public class ShoppingCart // { // // private final Map<Item, Integer> basket = new HashMap<Item, Integer>(); // // @Begin(join = true) // public void add(Item item) // { // add(item, 1); // } // // @Begin(join = true) // public void add(Item item, Integer amount) // { // Integer currentAmount = basket.get(item); // if (currentAmount == null) // { // currentAmount = Integer.valueOf(0); // } // basket.put(item, currentAmount + amount); // } // // @End // public BigDecimal checkout() // { // BigDecimal result = BigDecimal.ZERO; // for (Item item : basket.keySet()) // { // result = result.add(item.getPrice().multiply(BigDecimal.valueOf(basket.get(item)))); // } // // return result; // } // // }
import static org.fest.assertions.Assertions.*; import java.math.BigDecimal; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.conversation.Item; import org.jboss.arquillian.seam2.test.conversation.ShoppingCart; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith;
package org.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ConversationTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/conversation/Item.java // public class Item // { // // private final String name; // // private final BigDecimal price; // // public Item(String name, BigDecimal price) // { // this.name = name; // this.price = price; // } // // // Public methods // // @Override // public int hashCode() // { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((price == null) ? 0 : price.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) // { // if (this == obj) // { // return true; // } // if (!(obj instanceof Item)) // { // return false; // } // // final Item other = (Item) obj; // // if (name == null && other.getName() != null) // { // return false; // } // else if (!name.equals(other.getName())) // { // return false; // } // // if (price == null && other.getPrice() != null) // { // return false; // } // else if (!price.equals(other.getPrice())) // { // return false; // } // // return true; // } // // // Accessor methods // // public String getName() // { // return name; // } // // public BigDecimal getPrice() // { // return price; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/conversation/ShoppingCart.java // @Name("shoppingCart") // @Conversational // public class ShoppingCart // { // // private final Map<Item, Integer> basket = new HashMap<Item, Integer>(); // // @Begin(join = true) // public void add(Item item) // { // add(item, 1); // } // // @Begin(join = true) // public void add(Item item, Integer amount) // { // Integer currentAmount = basket.get(item); // if (currentAmount == null) // { // currentAmount = Integer.valueOf(0); // } // basket.put(item, currentAmount + amount); // } // // @End // public BigDecimal checkout() // { // BigDecimal result = BigDecimal.ZERO; // for (Item item : basket.keySet()) // { // result = result.add(item.getPrice().multiply(BigDecimal.valueOf(basket.get(item)))); // } // // return result; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ConversationTestCase.java import static org.fest.assertions.Assertions.*; import java.math.BigDecimal; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.conversation.Item; import org.jboss.arquillian.seam2.test.conversation.ShoppingCart; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; package org.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ConversationTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addPackage(Item.class.getPackage())
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ConversationTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/conversation/Item.java // public class Item // { // // private final String name; // // private final BigDecimal price; // // public Item(String name, BigDecimal price) // { // this.name = name; // this.price = price; // } // // // Public methods // // @Override // public int hashCode() // { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((price == null) ? 0 : price.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) // { // if (this == obj) // { // return true; // } // if (!(obj instanceof Item)) // { // return false; // } // // final Item other = (Item) obj; // // if (name == null && other.getName() != null) // { // return false; // } // else if (!name.equals(other.getName())) // { // return false; // } // // if (price == null && other.getPrice() != null) // { // return false; // } // else if (!price.equals(other.getPrice())) // { // return false; // } // // return true; // } // // // Accessor methods // // public String getName() // { // return name; // } // // public BigDecimal getPrice() // { // return price; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/conversation/ShoppingCart.java // @Name("shoppingCart") // @Conversational // public class ShoppingCart // { // // private final Map<Item, Integer> basket = new HashMap<Item, Integer>(); // // @Begin(join = true) // public void add(Item item) // { // add(item, 1); // } // // @Begin(join = true) // public void add(Item item, Integer amount) // { // Integer currentAmount = basket.get(item); // if (currentAmount == null) // { // currentAmount = Integer.valueOf(0); // } // basket.put(item, currentAmount + amount); // } // // @End // public BigDecimal checkout() // { // BigDecimal result = BigDecimal.ZERO; // for (Item item : basket.keySet()) // { // result = result.add(item.getPrice().multiply(BigDecimal.valueOf(basket.get(item)))); // } // // return result; // } // // }
import static org.fest.assertions.Assertions.*; import java.math.BigDecimal; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.conversation.Item; import org.jboss.arquillian.seam2.test.conversation.ShoppingCart; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith;
package org.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ConversationTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackage(Item.class.getPackage()) .addPackages(true, "org.fest") .addPackages(true, "org.dom4j") // Required for JBoss AS 4.2.3.GA .addAsResource(EmptyAsset.INSTANCE, "seam.properties") .setWebXML("web.xml"); } @In
// Path: src/test/java/org/jboss/arquillian/seam2/test/conversation/Item.java // public class Item // { // // private final String name; // // private final BigDecimal price; // // public Item(String name, BigDecimal price) // { // this.name = name; // this.price = price; // } // // // Public methods // // @Override // public int hashCode() // { // final int prime = 31; // int result = 1; // result = prime * result + ((name == null) ? 0 : name.hashCode()); // result = prime * result + ((price == null) ? 0 : price.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) // { // if (this == obj) // { // return true; // } // if (!(obj instanceof Item)) // { // return false; // } // // final Item other = (Item) obj; // // if (name == null && other.getName() != null) // { // return false; // } // else if (!name.equals(other.getName())) // { // return false; // } // // if (price == null && other.getPrice() != null) // { // return false; // } // else if (!price.equals(other.getPrice())) // { // return false; // } // // return true; // } // // // Accessor methods // // public String getName() // { // return name; // } // // public BigDecimal getPrice() // { // return price; // } // // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/conversation/ShoppingCart.java // @Name("shoppingCart") // @Conversational // public class ShoppingCart // { // // private final Map<Item, Integer> basket = new HashMap<Item, Integer>(); // // @Begin(join = true) // public void add(Item item) // { // add(item, 1); // } // // @Begin(join = true) // public void add(Item item, Integer amount) // { // Integer currentAmount = basket.get(item); // if (currentAmount == null) // { // currentAmount = Integer.valueOf(0); // } // basket.put(item, currentAmount + amount); // } // // @End // public BigDecimal checkout() // { // BigDecimal result = BigDecimal.ZERO; // for (Item item : basket.keySet()) // { // result = result.add(item.getPrice().multiply(BigDecimal.valueOf(basket.get(item)))); // } // // return result; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ConversationTestCase.java import static org.fest.assertions.Assertions.*; import java.math.BigDecimal; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.conversation.Item; import org.jboss.arquillian.seam2.test.conversation.ShoppingCart; import org.jboss.seam.annotations.In; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; package org.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ConversationTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackage(Item.class.getPackage()) .addPackages(true, "org.fest") .addPackages(true, "org.dom4j") // Required for JBoss AS 4.2.3.GA .addAsResource(EmptyAsset.INSTANCE, "seam.properties") .setWebXML("web.xml"); } @In
ShoppingCart shoppingCart;
arquillian/arquillian-extension-seam2
src/main/java/org/jboss/arquillian/seam2/client/Seam2Extension.java
// Path: src/main/java/org/jboss/arquillian/seam2/configuration/Seam2ConfigurationProducer.java // public class Seam2ConfigurationProducer // { // @Inject @ApplicationScoped // InstanceProducer<Seam2Configuration> configurationProducer; // // public void configure(@Observes ArquillianDescriptor descriptor) // { // ConfigurationImporter extractor = new ConfigurationImporter(); // Seam2Configuration configuration = extractor.from(descriptor); // configurationProducer.set(configuration); // } // // }
import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender; import org.jboss.arquillian.core.spi.LoadableExtension; import org.jboss.arquillian.seam2.configuration.Seam2ConfigurationProducer;
/* * JBoss, Home of Professional Open Source * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors * as indicated by the @authors tag. All rights reserved. * See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2.client; /** * * @author <a href="mailto:[email protected]">Bartosz Majsak</a> * * @version $Revision: $ */ public class Seam2Extension implements LoadableExtension { @Override public void register(ExtensionBuilder builder) { builder.service(ApplicationArchiveProcessor.class, Seam2ArchiveProcessor.class) .service(AuxiliaryArchiveAppender.class, Seam2ArchiveAppender.class)
// Path: src/main/java/org/jboss/arquillian/seam2/configuration/Seam2ConfigurationProducer.java // public class Seam2ConfigurationProducer // { // @Inject @ApplicationScoped // InstanceProducer<Seam2Configuration> configurationProducer; // // public void configure(@Observes ArquillianDescriptor descriptor) // { // ConfigurationImporter extractor = new ConfigurationImporter(); // Seam2Configuration configuration = extractor.from(descriptor); // configurationProducer.set(configuration); // } // // } // Path: src/main/java/org/jboss/arquillian/seam2/client/Seam2Extension.java import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender; import org.jboss.arquillian.core.spi.LoadableExtension; import org.jboss.arquillian.seam2.configuration.Seam2ConfigurationProducer; /* * JBoss, Home of Professional Open Source * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors * as indicated by the @authors tag. All rights reserved. * See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2.client; /** * * @author <a href="mailto:[email protected]">Bartosz Majsak</a> * * @version $Revision: $ */ public class Seam2Extension implements LoadableExtension { @Override public void register(ExtensionBuilder builder) { builder.service(ApplicationArchiveProcessor.class, Seam2ArchiveProcessor.class) .service(AuxiliaryArchiveAppender.class, Seam2ArchiveAppender.class)
.observer(Seam2ConfigurationProducer.class);
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Observer;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2.test.event; @Name("holder") public class ConversionResultHolder { private Double milliliters = Double.NaN; @In
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/test/event/ConversionResultHolder.java import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Observer; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2.test.event; @Name("holder") public class ConversionResultHolder { private Double milliliters = Double.NaN; @In
private FluidOuncesConverter converter;
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ComponentInjectionNonSeam2WebDescriptorArchiveTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentInjectionNonSeam2WebDescriptorArchiveTestCase extends ComponentInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ComponentInjectionNonSeam2WebDescriptorArchiveTestCase.java import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentInjectionNonSeam2WebDescriptorArchiveTestCase extends ComponentInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(FluidOuncesConverter.class)
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ComponentInjectionNoSeamPropertiesArchiveTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentInjectionNoSeamPropertiesArchiveTestCase extends ComponentInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ComponentInjectionNoSeamPropertiesArchiveTestCase.java import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentInjectionNoSeamPropertiesArchiveTestCase extends ComponentInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(FluidOuncesConverter.class)
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ComponentInjectionNonWebDescriptorArchiveTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentInjectionNonWebDescriptorArchiveTestCase extends ComponentInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ComponentInjectionNonWebDescriptorArchiveTestCase.java import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentInjectionNonWebDescriptorArchiveTestCase extends ComponentInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(FluidOuncesConverter.class)
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/assertions/WebArchiveAssert.java
// Path: src/main/java/org/jboss/arquillian/seam2/enhancement/WebArchiveExtractor.java // public class WebArchiveExtractor // { // // private static final String WAR_PATTERN = ".*\\.war"; // // /** // * Returns open stream of web.xml found in the archive, but // * only if single file have been found. // * // * @param archive // * @return Input stream of web.xml found or null if zero or multiple found in the archive. // */ // public InputStream getWebAppDescriptorAsStream(final Archive<?> archive) // { // final Archive<?> testable = findTestableWebArchive(archive); // final Collection<Node> values = collectWebXml(testable); // if (values.size() == 1) // { // return values.iterator().next().getAsset().openStream(); // } // // return null; // } // // /** // * Inspects archive in order to find nested testable archive, assuming // * @param archive // * @return testable archive or null if nothing found // */ // public WebArchive findTestableWebArchive(final Archive<?> archive) // { // final Map<ArchivePath, Node> nestedArchives = archive.getContent(Filters.include(WAR_PATTERN)); // if (!nestedArchives.isEmpty()) // { // for (ArchivePath path : nestedArchives.keySet()) // { // try // { // final WebArchive webArchive = archive.getAsType(WebArchive.class, path); // boolean onlyOneWebArchiveNested = webArchive != null && nestedArchives.size() == 1; // if (Testable.isArchiveToTest(webArchive) || onlyOneWebArchiveNested) // { // return webArchive; // } // } // catch (IllegalArgumentException e) // { // // no-op, Nested archive is not a ShrinkWrap archive. // } // } // } // // if (archive instanceof WebArchive) // { // return (WebArchive) archive; // } // // return null; // } // // /** // * Recursively scans archive content (including sub archives) for web.xml descriptors. // * // * @param archive // * @return // */ // private Collection<Node> collectWebXml(final Archive<?> archive) // { // final Collection<Node> nodes = new LinkedList<Node>(getWebAppDescriptors(archive)); // for (Node node : collectSubArchives(archive)) // { // if (node.getAsset() instanceof ArchiveAsset) // { // final ArchiveAsset archiveAsset = (ArchiveAsset) node.getAsset(); // nodes.addAll(collectWebXml(archiveAsset.getArchive())); // } // } // return nodes; // } // // private Collection<Node> getWebAppDescriptors(final Archive<?> archive) // { // return archive.getContent(Filters.include(".*web.xml")).values(); // } // // private Collection<Node> collectSubArchives(final Archive<?> archive) // { // return archive.getContent(Filters.include(WAR_PATTERN)).values(); // } // }
import org.fest.assertions.Assertions; import org.fest.assertions.GenericAssert; import org.jboss.arquillian.seam2.enhancement.WebArchiveExtractor; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.descriptor.api.Descriptors; import org.jboss.shrinkwrap.descriptor.api.webapp25.WebAppDescriptor; import java.io.InputStream;
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2.assertions; public class WebArchiveAssert extends GenericAssert<WebArchiveAssert, WebArchive> { protected WebArchiveAssert(Class<WebArchiveAssert> selfType, WebArchive webArchive) { super(selfType, webArchive); } public static WebArchiveAssert assertThat(WebArchive archive) { return new WebArchiveAssert(WebArchiveAssert.class, archive); } public WebDescriptorAssert containsWebDescriptor() {
// Path: src/main/java/org/jboss/arquillian/seam2/enhancement/WebArchiveExtractor.java // public class WebArchiveExtractor // { // // private static final String WAR_PATTERN = ".*\\.war"; // // /** // * Returns open stream of web.xml found in the archive, but // * only if single file have been found. // * // * @param archive // * @return Input stream of web.xml found or null if zero or multiple found in the archive. // */ // public InputStream getWebAppDescriptorAsStream(final Archive<?> archive) // { // final Archive<?> testable = findTestableWebArchive(archive); // final Collection<Node> values = collectWebXml(testable); // if (values.size() == 1) // { // return values.iterator().next().getAsset().openStream(); // } // // return null; // } // // /** // * Inspects archive in order to find nested testable archive, assuming // * @param archive // * @return testable archive or null if nothing found // */ // public WebArchive findTestableWebArchive(final Archive<?> archive) // { // final Map<ArchivePath, Node> nestedArchives = archive.getContent(Filters.include(WAR_PATTERN)); // if (!nestedArchives.isEmpty()) // { // for (ArchivePath path : nestedArchives.keySet()) // { // try // { // final WebArchive webArchive = archive.getAsType(WebArchive.class, path); // boolean onlyOneWebArchiveNested = webArchive != null && nestedArchives.size() == 1; // if (Testable.isArchiveToTest(webArchive) || onlyOneWebArchiveNested) // { // return webArchive; // } // } // catch (IllegalArgumentException e) // { // // no-op, Nested archive is not a ShrinkWrap archive. // } // } // } // // if (archive instanceof WebArchive) // { // return (WebArchive) archive; // } // // return null; // } // // /** // * Recursively scans archive content (including sub archives) for web.xml descriptors. // * // * @param archive // * @return // */ // private Collection<Node> collectWebXml(final Archive<?> archive) // { // final Collection<Node> nodes = new LinkedList<Node>(getWebAppDescriptors(archive)); // for (Node node : collectSubArchives(archive)) // { // if (node.getAsset() instanceof ArchiveAsset) // { // final ArchiveAsset archiveAsset = (ArchiveAsset) node.getAsset(); // nodes.addAll(collectWebXml(archiveAsset.getArchive())); // } // } // return nodes; // } // // private Collection<Node> getWebAppDescriptors(final Archive<?> archive) // { // return archive.getContent(Filters.include(".*web.xml")).values(); // } // // private Collection<Node> collectSubArchives(final Archive<?> archive) // { // return archive.getContent(Filters.include(WAR_PATTERN)).values(); // } // } // Path: src/test/java/org/jboss/arquillian/seam2/assertions/WebArchiveAssert.java import org.fest.assertions.Assertions; import org.fest.assertions.GenericAssert; import org.jboss.arquillian.seam2.enhancement.WebArchiveExtractor; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.shrinkwrap.descriptor.api.Descriptors; import org.jboss.shrinkwrap.descriptor.api.webapp25.WebAppDescriptor; import java.io.InputStream; /* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2.assertions; public class WebArchiveAssert extends GenericAssert<WebArchiveAssert, WebArchive> { protected WebArchiveAssert(Class<WebArchiveAssert> selfType, WebArchive webArchive) { super(selfType, webArchive); } public static WebArchiveAssert assertThat(WebArchive archive) { return new WebArchiveAssert(WebArchiveAssert.class, archive); } public WebDescriptorAssert containsWebDescriptor() {
final InputStream webAppDescriptor = new WebArchiveExtractor().getWebAppDescriptorAsStream(this.actual);
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ComponentInjectionUsingManuallyPackagedArchiveTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentInjectionUsingManuallyPackagedArchiveTestCase extends ComponentInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ComponentInjectionUsingManuallyPackagedArchiveTestCase.java import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.runner.RunWith; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class ComponentInjectionUsingManuallyPackagedArchiveTestCase extends ComponentInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(FluidOuncesConverter.class)
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/ComponentInjectionTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.junit.Test; import static org.fest.assertions.Assertions.assertThat;
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; public abstract class ComponentInjectionTestCase { @In
// Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/ComponentInjectionTestCase.java import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.junit.Test; import static org.fest.assertions.Assertions.assertThat; /* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; public abstract class ComponentInjectionTestCase { @In
FluidOuncesConverter fluidOuncesConverter;
arquillian/arquillian-extension-seam2
src/test/java/org/jboss/arquillian/seam2/IdentityInjectionTestCase.java
// Path: src/test/java/org/jboss/arquillian/seam2/test/identity/IdentityStub.java // @Name("org.jboss.seam.security.identity") // @Scope(ScopeType.SESSION) // @Install(precedence = Install.APPLICATION) // @BypassInterceptors // @Startup // public class IdentityStub extends Identity // { // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // }
import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.identity.IdentityStub; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.seam.security.Identity; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat;
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class IdentityInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
// Path: src/test/java/org/jboss/arquillian/seam2/test/identity/IdentityStub.java // @Name("org.jboss.seam.security.identity") // @Scope(ScopeType.SESSION) // @Install(precedence = Install.APPLICATION) // @BypassInterceptors // @Startup // public class IdentityStub extends Identity // { // } // // Path: src/test/java/org/jboss/arquillian/seam2/test/simple/FluidOuncesConverter.java // @Name("fluidOuncesConverter") // public class FluidOuncesConverter // { // // private static final double OUNCES_MULTIPLIER = 29.5735296; // // private String identifier; // // public FluidOuncesConverter() // { // } // // FluidOuncesConverter(String identifier) // { // this.identifier = identifier; // } // // public Double convertToMillilitres(Double ounces) // { // return ounces * OUNCES_MULTIPLIER; // } // // public Double convertToFluidOunces(Double ml) // { // return ml / OUNCES_MULTIPLIER; // } // // public String getIdentifier() // { // return identifier; // } // // } // Path: src/test/java/org/jboss/arquillian/seam2/IdentityInjectionTestCase.java import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.seam2.test.identity.IdentityStub; import org.jboss.arquillian.seam2.test.simple.FluidOuncesConverter; import org.jboss.seam.annotations.In; import org.jboss.seam.security.Identity; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import static org.fest.assertions.Assertions.assertThat; /* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * Licensed 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.jboss.arquillian.seam2; @RunWith(Arquillian.class) public class IdentityInjectionTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(IdentityStub.class)
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/particles/Emitter.java
// Path: src/main/java/sk/mrtn/pixi/client/particles/config/EmitterConfig.java // @JsType(isNative = true) // public class EmitterConfig { // // @JsProperty // public Alpha alpha; // // @JsProperty // public Scale scale; // // @JsProperty // public Color color; // // @JsProperty // public Speed speed; // // @JsProperty // public Acceleration acceleration; // // @JsProperty // public StartRotation startRotation; // // @JsProperty // public Boolean noRotation; // // @JsProperty // public RotationSpeed rotationSpeed; // // @JsProperty // public LifeTime lifetime; // // /** // * add, multiply, screen, overlay // * Canvas only: // * TODO: Create enum // */ // @JsProperty // public String blendMode; // // @JsProperty // public Double frequency; // // @JsProperty // public Double emitterLifetime; // // @JsProperty // public Integer maxParticles; // // @JsProperty // public Position pos; // // @JsProperty // public Boolean addAtBack; // // /** // * point, rect, circle, ring, burst // */ // @JsProperty // public String spawnType; // // @JsProperty // public SpawnCircle spawnCircle; // // @JsProperty // public SpawnRect spawnRect; // // @JsProperty // public Double particlesPerWave; // // @JsProperty // public Double particleSpacing; // // @JsProperty // public Double angleStart; // // @JsMethod(namespace="JSON") // public static native EmitterConfig parse(String text); // // }
import com.google.auto.factory.AutoFactory; import jsinterop.annotations.JsConstructor; import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.*; import sk.mrtn.pixi.client.particles.config.EmitterConfig;
package sk.mrtn.pixi.client.particles; /** * Created by klaun on 25/04/16. * TODO: test and add constructors for PathParticle */ @AutoFactory @JsType(isNative = true, namespace = "PIXI.particles") public class Emitter { @JsConstructor public Emitter(Container container){} /** * suitable for AnimatedParticle * @param container * @param animatedParticleArtTextures */ @JsConstructor
// Path: src/main/java/sk/mrtn/pixi/client/particles/config/EmitterConfig.java // @JsType(isNative = true) // public class EmitterConfig { // // @JsProperty // public Alpha alpha; // // @JsProperty // public Scale scale; // // @JsProperty // public Color color; // // @JsProperty // public Speed speed; // // @JsProperty // public Acceleration acceleration; // // @JsProperty // public StartRotation startRotation; // // @JsProperty // public Boolean noRotation; // // @JsProperty // public RotationSpeed rotationSpeed; // // @JsProperty // public LifeTime lifetime; // // /** // * add, multiply, screen, overlay // * Canvas only: // * TODO: Create enum // */ // @JsProperty // public String blendMode; // // @JsProperty // public Double frequency; // // @JsProperty // public Double emitterLifetime; // // @JsProperty // public Integer maxParticles; // // @JsProperty // public Position pos; // // @JsProperty // public Boolean addAtBack; // // /** // * point, rect, circle, ring, burst // */ // @JsProperty // public String spawnType; // // @JsProperty // public SpawnCircle spawnCircle; // // @JsProperty // public SpawnRect spawnRect; // // @JsProperty // public Double particlesPerWave; // // @JsProperty // public Double particleSpacing; // // @JsProperty // public Double angleStart; // // @JsMethod(namespace="JSON") // public static native EmitterConfig parse(String text); // // } // Path: src/main/java/sk/mrtn/pixi/client/particles/Emitter.java import com.google.auto.factory.AutoFactory; import jsinterop.annotations.JsConstructor; import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.*; import sk.mrtn.pixi.client.particles.config.EmitterConfig; package sk.mrtn.pixi.client.particles; /** * Created by klaun on 25/04/16. * TODO: test and add constructors for PathParticle */ @AutoFactory @JsType(isNative = true, namespace = "PIXI.particles") public class Emitter { @JsConstructor public Emitter(Container container){} /** * suitable for AnimatedParticle * @param container * @param animatedParticleArtTextures */ @JsConstructor
public Emitter(Container container, AnimatedParticleArtTextures[] animatedParticleArtTextures, EmitterConfig config){}
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/particles/ParticleContainer.java
// Path: src/main/java/sk/mrtn/pixi/client/Container.java // @JsType(isNative = true, namespace = "PIXI") // public class Container extends DisplayObject { // // /** // * The array of children of this container. // */ // @JsProperty // public DisplayObject[] children; // // /** // * The height of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double height; // // /** // * The width of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double width; // // @Inject // @JsConstructor // public Container(){} // // // PUBLIC METHODS // @JsMethod // public native void onChildrenChange(); // // /** // * Adds a child or multiple children to the container. // * Multple items can be added like so: // * myContainer.addChild(thinkOne, thingTwo, thingThree) // * @param child - repeatable, The DisplayObject(s) to add to the container // * @return The first child that was added. // */ // @JsMethod // public native DisplayObject addChild(DisplayObject... child); // // /** // * Adds a child to the container at a specified index. // * If the index is out of bounds an error will be thrown // * @param child The child to add // * @param index The index to place the child in // * @return The child that was added. // */ // @JsMethod // public native DisplayObject addChildAt(DisplayObject child, int index); // // // /** // * Swaps the position of 2 Display Objects within this container. // * @param child - First display object to swap // * @param child2 - Second display object to swap // */ // @JsMethod // public native void swapChildren(DisplayObject child, DisplayObject child2); // // /** // * TODO:check if can be null // * Returns the index position of a child DisplayObject instance // * @param child The DisplayObject instance to identify // * @return The index position of the child display object to identify // */ // @JsMethod // public native int getChildIndex(DisplayObject child); // // /** // * Changes the position of an existing child in the display object container // * @param child - The child DisplayObject instance for which you want to change the index number // * @param index - The resulting index number for the child display object // */ // @JsMethod // public native void setChildIndex(DisplayObject child, int index); // // /** // * Returns the child at the specified index // * @param index The index to get the child at // * @return The child at the given index, if any. // */ // @JsMethod // public native DisplayObject getChildAt(int index); // // /** // * Removes a child from the container. // * @param child - The DisplayObject to remove // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChild(DisplayObject child); // // /** // * Removes a child from the specified index position. // * @param index - The index to get the child from // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChildAt(int index); // // /** // * TODO:check behavior when parameters omitted, add overload methods // * Removes all children from this container that are within the begin and end indexes. // * @param beginIndex (default 0) The beginning position. // * @param endIndex (this.children.length) The ending position. Default value is size of the container. // */ // @JsMethod // public native void removeChildren(int beginIndex, int endIndex); // @JsMethod // public native Texture generateTexture(Renderer renderer, int resolution, int scaleMode); // // /** // * Removes all internal references and listeners as well // * as removes children from the display list. // * Do not use a Container after calling destroy. // * TODO: test actual functionality and add Typed variable // * @param options // */ // @JsMethod // public native void destroy(Object options); // // @JsMethod // public native DisplayObject getChildByName(String name); // // }
import com.google.auto.factory.AutoFactory; import jsinterop.annotations.JsConstructor; import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.Container; import javax.inject.Inject;
package sk.mrtn.pixi.client.particles; /** * Created by klaun on 20/08/16. * The ParticleContainer class is a really fast version of the * Container built solely for speed, so use when you need a lot * of sprites or particles. The tradeoff of the ParticleContainer * is that advanced functionality will not work. ParticleContainer * implements only the basic object transform (position, scale, rotation). * Any other functionality like tinting, masking, etc will not * work on sprites in this batch. * @see <a href="https://pixijs.github.io/docs/PIXI.particles.ParticleContainer.html">ParticleContainer</a> */ @AutoFactory @JsType(isNative = true, namespace = "PIXI.particles")
// Path: src/main/java/sk/mrtn/pixi/client/Container.java // @JsType(isNative = true, namespace = "PIXI") // public class Container extends DisplayObject { // // /** // * The array of children of this container. // */ // @JsProperty // public DisplayObject[] children; // // /** // * The height of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double height; // // /** // * The width of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double width; // // @Inject // @JsConstructor // public Container(){} // // // PUBLIC METHODS // @JsMethod // public native void onChildrenChange(); // // /** // * Adds a child or multiple children to the container. // * Multple items can be added like so: // * myContainer.addChild(thinkOne, thingTwo, thingThree) // * @param child - repeatable, The DisplayObject(s) to add to the container // * @return The first child that was added. // */ // @JsMethod // public native DisplayObject addChild(DisplayObject... child); // // /** // * Adds a child to the container at a specified index. // * If the index is out of bounds an error will be thrown // * @param child The child to add // * @param index The index to place the child in // * @return The child that was added. // */ // @JsMethod // public native DisplayObject addChildAt(DisplayObject child, int index); // // // /** // * Swaps the position of 2 Display Objects within this container. // * @param child - First display object to swap // * @param child2 - Second display object to swap // */ // @JsMethod // public native void swapChildren(DisplayObject child, DisplayObject child2); // // /** // * TODO:check if can be null // * Returns the index position of a child DisplayObject instance // * @param child The DisplayObject instance to identify // * @return The index position of the child display object to identify // */ // @JsMethod // public native int getChildIndex(DisplayObject child); // // /** // * Changes the position of an existing child in the display object container // * @param child - The child DisplayObject instance for which you want to change the index number // * @param index - The resulting index number for the child display object // */ // @JsMethod // public native void setChildIndex(DisplayObject child, int index); // // /** // * Returns the child at the specified index // * @param index The index to get the child at // * @return The child at the given index, if any. // */ // @JsMethod // public native DisplayObject getChildAt(int index); // // /** // * Removes a child from the container. // * @param child - The DisplayObject to remove // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChild(DisplayObject child); // // /** // * Removes a child from the specified index position. // * @param index - The index to get the child from // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChildAt(int index); // // /** // * TODO:check behavior when parameters omitted, add overload methods // * Removes all children from this container that are within the begin and end indexes. // * @param beginIndex (default 0) The beginning position. // * @param endIndex (this.children.length) The ending position. Default value is size of the container. // */ // @JsMethod // public native void removeChildren(int beginIndex, int endIndex); // @JsMethod // public native Texture generateTexture(Renderer renderer, int resolution, int scaleMode); // // /** // * Removes all internal references and listeners as well // * as removes children from the display list. // * Do not use a Container after calling destroy. // * TODO: test actual functionality and add Typed variable // * @param options // */ // @JsMethod // public native void destroy(Object options); // // @JsMethod // public native DisplayObject getChildByName(String name); // // } // Path: src/main/java/sk/mrtn/pixi/client/particles/ParticleContainer.java import com.google.auto.factory.AutoFactory; import jsinterop.annotations.JsConstructor; import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.Container; import javax.inject.Inject; package sk.mrtn.pixi.client.particles; /** * Created by klaun on 20/08/16. * The ParticleContainer class is a really fast version of the * Container built solely for speed, so use when you need a lot * of sprites or particles. The tradeoff of the ParticleContainer * is that advanced functionality will not work. ParticleContainer * implements only the basic object transform (position, scale, rotation). * Any other functionality like tinting, masking, etc will not * work on sprites in this batch. * @see <a href="https://pixijs.github.io/docs/PIXI.particles.ParticleContainer.html">ParticleContainer</a> */ @AutoFactory @JsType(isNative = true, namespace = "PIXI.particles")
public class ParticleContainer extends Container {
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/particles/PathParticle.java
// Path: src/main/java/sk/mrtn/pixi/client/Point.java // @JsType(isNative = true, namespace = "PIXI") // public class Point { // // @JsConstructor // public Point(double x, double y){}; // // // PUBLIC FIELDS // @JsProperty // public double x; // @JsProperty // public double y; // // // PUBLIC METHODS // @JsMethod // public native Point clone(); // @JsMethod // public native Point copy(Point point); // @JsMethod // public native boolean equals(Point point); // @JsMethod // public native void set(double x, double y); // // @JsOverlay // public final String toString() { // return "Point {x: "+x+", y: "+y+"}"; // } // // @JsOverlay // public final String asString() { // return "Point {x: "+x+", y: "+y+"}"; // } // }
import jsinterop.annotations.JsConstructor; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.Point;
package sk.mrtn.pixi.client.particles; /** * Created by klaun on 25/04/16. */ @JsType(isNative = true, namespace = "PIXI.particles") public class PathParticle extends Particle { // PUBLIC STATIC FIELDS // PUBLIC STATIC METHODS @JsConstructor public PathParticle(Emitter emitter){} // PUBLIC FIELDS /** * The function representing the path the particle should take. */ @JsProperty public Object path; /** * The initial rotation in degrees of the particle, * because the direction of the path is based on that. */ @JsProperty public int initialRotation; /** * The initial position of the particle, as all path movement is added to that. */ @JsProperty
// Path: src/main/java/sk/mrtn/pixi/client/Point.java // @JsType(isNative = true, namespace = "PIXI") // public class Point { // // @JsConstructor // public Point(double x, double y){}; // // // PUBLIC FIELDS // @JsProperty // public double x; // @JsProperty // public double y; // // // PUBLIC METHODS // @JsMethod // public native Point clone(); // @JsMethod // public native Point copy(Point point); // @JsMethod // public native boolean equals(Point point); // @JsMethod // public native void set(double x, double y); // // @JsOverlay // public final String toString() { // return "Point {x: "+x+", y: "+y+"}"; // } // // @JsOverlay // public final String asString() { // return "Point {x: "+x+", y: "+y+"}"; // } // } // Path: src/main/java/sk/mrtn/pixi/client/particles/PathParticle.java import jsinterop.annotations.JsConstructor; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.Point; package sk.mrtn.pixi.client.particles; /** * Created by klaun on 25/04/16. */ @JsType(isNative = true, namespace = "PIXI.particles") public class PathParticle extends Particle { // PUBLIC STATIC FIELDS // PUBLIC STATIC METHODS @JsConstructor public PathParticle(Emitter emitter){} // PUBLIC FIELDS /** * The function representing the path the particle should take. */ @JsProperty public Object path; /** * The initial rotation in degrees of the particle, * because the direction of the path is based on that. */ @JsProperty public int initialRotation; /** * The initial position of the particle, as all path movement is added to that. */ @JsProperty
public Point initialPosition;
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/mesh/MeshShader.java
// Path: src/main/java/sk/mrtn/pixi/client/ShaderManager.java // @JsType(isNative = true, namespace = "PIXI") // public class ShaderManager { // // // PUBLIC STATIC FIELDS // // // PUBLIC STATIC METHODS // @JsConstructor // public ShaderManager(Renderer renderer){}; // // }
import jsinterop.annotations.JsConstructor; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.ShaderManager;
package sk.mrtn.pixi.client.mesh; /** * Created by klaun on 21/08/16. */ @JsType(isNative = true, namespace = "PIXI.mesh") public class MeshShader { // PUBLIC STATIC FIELDS // PUBLIC STATIC METHODS @JsConstructor
// Path: src/main/java/sk/mrtn/pixi/client/ShaderManager.java // @JsType(isNative = true, namespace = "PIXI") // public class ShaderManager { // // // PUBLIC STATIC FIELDS // // // PUBLIC STATIC METHODS // @JsConstructor // public ShaderManager(Renderer renderer){}; // // } // Path: src/main/java/sk/mrtn/pixi/client/mesh/MeshShader.java import jsinterop.annotations.JsConstructor; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.ShaderManager; package sk.mrtn.pixi.client.mesh; /** * Created by klaun on 21/08/16. */ @JsType(isNative = true, namespace = "PIXI.mesh") public class MeshShader { // PUBLIC STATIC FIELDS // PUBLIC STATIC METHODS @JsConstructor
public MeshShader(ShaderManager shaderManager){};
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/DisplayObject.java
// Path: src/main/java/sk/mrtn/pixi/client/interaction/EventListener.java // @JsFunction // public interface EventListener { // void handleEvent(Event event); // }
import jsinterop.annotations.*; import sk.mrtn.pixi.client.interaction.EventListener; import java.util.Collection; import java.util.Collections; import java.util.HashSet;
* @param skewX * @param skewY * @param pivotX * @param pivotY * @return */ @JsMethod public native boolean setTransform(double x, double y, double scaleX, double scaleY, double rotation, double skewX, double skewY, double pivotX, double pivotY); /** * Base destroy method for generic display objects. This will automatically * remove the display object from its parent Container as well as remove * all current event listeners and internal references. Do not use a DisplayObject * after calling destroy. */ @JsMethod public native void destroy(); @JsMethod public native Point getGlobalPosition(Point point); @JsMethod public native Texture generateTexture(Renderer renderer, double scaleMode, double resolution); /** * method allows to add interaction for object * @param eventType * @param eventListener */ @JsMethod
// Path: src/main/java/sk/mrtn/pixi/client/interaction/EventListener.java // @JsFunction // public interface EventListener { // void handleEvent(Event event); // } // Path: src/main/java/sk/mrtn/pixi/client/DisplayObject.java import jsinterop.annotations.*; import sk.mrtn.pixi.client.interaction.EventListener; import java.util.Collection; import java.util.Collections; import java.util.HashSet; * @param skewX * @param skewY * @param pivotX * @param pivotY * @return */ @JsMethod public native boolean setTransform(double x, double y, double scaleX, double scaleY, double rotation, double skewX, double skewY, double pivotX, double pivotY); /** * Base destroy method for generic display objects. This will automatically * remove the display object from its parent Container as well as remove * all current event listeners and internal references. Do not use a DisplayObject * after calling destroy. */ @JsMethod public native void destroy(); @JsMethod public native Point getGlobalPosition(Point point); @JsMethod public native Texture generateTexture(Renderer renderer, double scaleMode, double resolution); /** * method allows to add interaction for object * @param eventType * @param eventListener */ @JsMethod
public native void on(String eventType, EventListener eventListener);
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/stage/DefaultResponsiveController.java
// Path: src/main/java/sk/mrtn/pixi/client/Container.java // @JsType(isNative = true, namespace = "PIXI") // public class Container extends DisplayObject { // // /** // * The array of children of this container. // */ // @JsProperty // public DisplayObject[] children; // // /** // * The height of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double height; // // /** // * The width of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double width; // // @Inject // @JsConstructor // public Container(){} // // // PUBLIC METHODS // @JsMethod // public native void onChildrenChange(); // // /** // * Adds a child or multiple children to the container. // * Multple items can be added like so: // * myContainer.addChild(thinkOne, thingTwo, thingThree) // * @param child - repeatable, The DisplayObject(s) to add to the container // * @return The first child that was added. // */ // @JsMethod // public native DisplayObject addChild(DisplayObject... child); // // /** // * Adds a child to the container at a specified index. // * If the index is out of bounds an error will be thrown // * @param child The child to add // * @param index The index to place the child in // * @return The child that was added. // */ // @JsMethod // public native DisplayObject addChildAt(DisplayObject child, int index); // // // /** // * Swaps the position of 2 Display Objects within this container. // * @param child - First display object to swap // * @param child2 - Second display object to swap // */ // @JsMethod // public native void swapChildren(DisplayObject child, DisplayObject child2); // // /** // * TODO:check if can be null // * Returns the index position of a child DisplayObject instance // * @param child The DisplayObject instance to identify // * @return The index position of the child display object to identify // */ // @JsMethod // public native int getChildIndex(DisplayObject child); // // /** // * Changes the position of an existing child in the display object container // * @param child - The child DisplayObject instance for which you want to change the index number // * @param index - The resulting index number for the child display object // */ // @JsMethod // public native void setChildIndex(DisplayObject child, int index); // // /** // * Returns the child at the specified index // * @param index The index to get the child at // * @return The child at the given index, if any. // */ // @JsMethod // public native DisplayObject getChildAt(int index); // // /** // * Removes a child from the container. // * @param child - The DisplayObject to remove // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChild(DisplayObject child); // // /** // * Removes a child from the specified index position. // * @param index - The index to get the child from // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChildAt(int index); // // /** // * TODO:check behavior when parameters omitted, add overload methods // * Removes all children from this container that are within the begin and end indexes. // * @param beginIndex (default 0) The beginning position. // * @param endIndex (this.children.length) The ending position. Default value is size of the container. // */ // @JsMethod // public native void removeChildren(int beginIndex, int endIndex); // @JsMethod // public native Texture generateTexture(Renderer renderer, int resolution, int scaleMode); // // /** // * Removes all internal references and listeners as well // * as removes children from the display list. // * Do not use a Container after calling destroy. // * TODO: test actual functionality and add Typed variable // * @param options // */ // @JsMethod // public native void destroy(Object options); // // @JsMethod // public native DisplayObject getChildByName(String name); // // }
import sk.mrtn.pixi.client.Container; import javax.inject.Inject;
package sk.mrtn.pixi.client.stage; /** * Created by martinliptak on 27/12/2016. */ public class DefaultResponsiveController extends AResponsiveController { @Inject
// Path: src/main/java/sk/mrtn/pixi/client/Container.java // @JsType(isNative = true, namespace = "PIXI") // public class Container extends DisplayObject { // // /** // * The array of children of this container. // */ // @JsProperty // public DisplayObject[] children; // // /** // * The height of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double height; // // /** // * The width of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double width; // // @Inject // @JsConstructor // public Container(){} // // // PUBLIC METHODS // @JsMethod // public native void onChildrenChange(); // // /** // * Adds a child or multiple children to the container. // * Multple items can be added like so: // * myContainer.addChild(thinkOne, thingTwo, thingThree) // * @param child - repeatable, The DisplayObject(s) to add to the container // * @return The first child that was added. // */ // @JsMethod // public native DisplayObject addChild(DisplayObject... child); // // /** // * Adds a child to the container at a specified index. // * If the index is out of bounds an error will be thrown // * @param child The child to add // * @param index The index to place the child in // * @return The child that was added. // */ // @JsMethod // public native DisplayObject addChildAt(DisplayObject child, int index); // // // /** // * Swaps the position of 2 Display Objects within this container. // * @param child - First display object to swap // * @param child2 - Second display object to swap // */ // @JsMethod // public native void swapChildren(DisplayObject child, DisplayObject child2); // // /** // * TODO:check if can be null // * Returns the index position of a child DisplayObject instance // * @param child The DisplayObject instance to identify // * @return The index position of the child display object to identify // */ // @JsMethod // public native int getChildIndex(DisplayObject child); // // /** // * Changes the position of an existing child in the display object container // * @param child - The child DisplayObject instance for which you want to change the index number // * @param index - The resulting index number for the child display object // */ // @JsMethod // public native void setChildIndex(DisplayObject child, int index); // // /** // * Returns the child at the specified index // * @param index The index to get the child at // * @return The child at the given index, if any. // */ // @JsMethod // public native DisplayObject getChildAt(int index); // // /** // * Removes a child from the container. // * @param child - The DisplayObject to remove // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChild(DisplayObject child); // // /** // * Removes a child from the specified index position. // * @param index - The index to get the child from // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChildAt(int index); // // /** // * TODO:check behavior when parameters omitted, add overload methods // * Removes all children from this container that are within the begin and end indexes. // * @param beginIndex (default 0) The beginning position. // * @param endIndex (this.children.length) The ending position. Default value is size of the container. // */ // @JsMethod // public native void removeChildren(int beginIndex, int endIndex); // @JsMethod // public native Texture generateTexture(Renderer renderer, int resolution, int scaleMode); // // /** // * Removes all internal references and listeners as well // * as removes children from the display list. // * Do not use a Container after calling destroy. // * TODO: test actual functionality and add Typed variable // * @param options // */ // @JsMethod // public native void destroy(Object options); // // @JsMethod // public native DisplayObject getChildByName(String name); // // } // Path: src/main/java/sk/mrtn/pixi/client/stage/DefaultResponsiveController.java import sk.mrtn.pixi.client.Container; import javax.inject.Inject; package sk.mrtn.pixi.client.stage; /** * Created by martinliptak on 27/12/2016. */ public class DefaultResponsiveController extends AResponsiveController { @Inject
public DefaultResponsiveController(Container container) {
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/PIXI.java
// Path: src/main/java/sk/mrtn/pixi/client/ticker/Ticker.java // @JsType(isNative = true, namespace = "PIXI.ticker") // public class Ticker { // // // PUBLIC STATIC FIELDS // // // PUBLIC STATIC METHODS // // @Inject // @JsConstructor // public Ticker(){} // // // PUBLIC FIELDS // @JsProperty // public boolean autoStart; // // in milliseconds // @JsProperty // public int deltaTime; // @JsProperty // public double elapsedMS; // @JsProperty // public int lastTime; // @JsProperty // public int speed; // @JsProperty // public boolean started; // // // PUBLIC METHODS // @JsMethod // public native Ticker add(ITickable tickable); // @JsMethod // public native Ticker addOnce(ITickable tickable); // @JsMethod // public native Ticker remove(ITickable tickable); // @JsMethod // public native void start(); // @JsMethod // public native void stop(); // @JsMethod // public native void update(double currentTime); // // }
import jsinterop.annotations.*; import sk.mrtn.pixi.client.ticker.Ticker;
public double PI_2; @JsProperty public double RAD_TO_DEG; @JsProperty public double DEG_TO_RAD; @JsProperty public double TARGET_FPMS; @JsProperty public RendererType RENDERER_TYPE; @JsProperty public BlendModes BLEND_MODES; @JsProperty public DrawModes DRAW_MODES; @JsProperty public ScaleModes SCALE_MODES; @JsProperty public String RETINA_PREFIX; @JsProperty public int RESOLUTION; @JsProperty public int FILTER_RESOLUTION; @JsProperty public DefaultRendererOptions DEFAULT_RENDER_OPTIONS; @JsProperty public Shapes SHAPES; @JsProperty public int SPRITE_BATCH_SIZE; @JsProperty public GroupD8 GroupD8; @JsProperty
// Path: src/main/java/sk/mrtn/pixi/client/ticker/Ticker.java // @JsType(isNative = true, namespace = "PIXI.ticker") // public class Ticker { // // // PUBLIC STATIC FIELDS // // // PUBLIC STATIC METHODS // // @Inject // @JsConstructor // public Ticker(){} // // // PUBLIC FIELDS // @JsProperty // public boolean autoStart; // // in milliseconds // @JsProperty // public int deltaTime; // @JsProperty // public double elapsedMS; // @JsProperty // public int lastTime; // @JsProperty // public int speed; // @JsProperty // public boolean started; // // // PUBLIC METHODS // @JsMethod // public native Ticker add(ITickable tickable); // @JsMethod // public native Ticker addOnce(ITickable tickable); // @JsMethod // public native Ticker remove(ITickable tickable); // @JsMethod // public native void start(); // @JsMethod // public native void stop(); // @JsMethod // public native void update(double currentTime); // // } // Path: src/main/java/sk/mrtn/pixi/client/PIXI.java import jsinterop.annotations.*; import sk.mrtn.pixi.client.ticker.Ticker; public double PI_2; @JsProperty public double RAD_TO_DEG; @JsProperty public double DEG_TO_RAD; @JsProperty public double TARGET_FPMS; @JsProperty public RendererType RENDERER_TYPE; @JsProperty public BlendModes BLEND_MODES; @JsProperty public DrawModes DRAW_MODES; @JsProperty public ScaleModes SCALE_MODES; @JsProperty public String RETINA_PREFIX; @JsProperty public int RESOLUTION; @JsProperty public int FILTER_RESOLUTION; @JsProperty public DefaultRendererOptions DEFAULT_RENDER_OPTIONS; @JsProperty public Shapes SHAPES; @JsProperty public int SPRITE_BATCH_SIZE; @JsProperty public GroupD8 GroupD8; @JsProperty
public Ticker ticker;
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/particles/ParticleUtils.java
// Path: src/main/java/sk/mrtn/pixi/client/Point.java // @JsType(isNative = true, namespace = "PIXI") // public class Point { // // @JsConstructor // public Point(double x, double y){}; // // // PUBLIC FIELDS // @JsProperty // public double x; // @JsProperty // public double y; // // // PUBLIC METHODS // @JsMethod // public native Point clone(); // @JsMethod // public native Point copy(Point point); // @JsMethod // public native boolean equals(Point point); // @JsMethod // public native void set(double x, double y); // // @JsOverlay // public final String toString() { // return "Point {x: "+x+", y: "+y+"}"; // } // // @JsOverlay // public final String asString() { // return "Point {x: "+x+", y: "+y+"}"; // } // }
import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.Point;
package sk.mrtn.pixi.client.particles; /** * Created by klaun on 25/04/16. */ @JsType(isNative = true, namespace = "PIXI.particles") public class ParticleUtils { // PUBLIC FIELDS @JsProperty public double DEG_TO_RADS; @JsProperty public boolean useAPI3; // PUBLIC METHODS /** * Rotates a point by a given angle. * @param angle * @param point */ @JsMethod
// Path: src/main/java/sk/mrtn/pixi/client/Point.java // @JsType(isNative = true, namespace = "PIXI") // public class Point { // // @JsConstructor // public Point(double x, double y){}; // // // PUBLIC FIELDS // @JsProperty // public double x; // @JsProperty // public double y; // // // PUBLIC METHODS // @JsMethod // public native Point clone(); // @JsMethod // public native Point copy(Point point); // @JsMethod // public native boolean equals(Point point); // @JsMethod // public native void set(double x, double y); // // @JsOverlay // public final String toString() { // return "Point {x: "+x+", y: "+y+"}"; // } // // @JsOverlay // public final String asString() { // return "Point {x: "+x+", y: "+y+"}"; // } // } // Path: src/main/java/sk/mrtn/pixi/client/particles/ParticleUtils.java import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.Point; package sk.mrtn.pixi.client.particles; /** * Created by klaun on 25/04/16. */ @JsType(isNative = true, namespace = "PIXI.particles") public class ParticleUtils { // PUBLIC FIELDS @JsProperty public double DEG_TO_RADS; @JsProperty public boolean useAPI3; // PUBLIC METHODS /** * Rotates a point by a given angle. * @param angle * @param point */ @JsMethod
public native void rotatePoint(double angle, Point point);
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/stage/IResponsiveController.java
// Path: src/main/java/sk/mrtn/pixi/client/Container.java // @JsType(isNative = true, namespace = "PIXI") // public class Container extends DisplayObject { // // /** // * The array of children of this container. // */ // @JsProperty // public DisplayObject[] children; // // /** // * The height of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double height; // // /** // * The width of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double width; // // @Inject // @JsConstructor // public Container(){} // // // PUBLIC METHODS // @JsMethod // public native void onChildrenChange(); // // /** // * Adds a child or multiple children to the container. // * Multple items can be added like so: // * myContainer.addChild(thinkOne, thingTwo, thingThree) // * @param child - repeatable, The DisplayObject(s) to add to the container // * @return The first child that was added. // */ // @JsMethod // public native DisplayObject addChild(DisplayObject... child); // // /** // * Adds a child to the container at a specified index. // * If the index is out of bounds an error will be thrown // * @param child The child to add // * @param index The index to place the child in // * @return The child that was added. // */ // @JsMethod // public native DisplayObject addChildAt(DisplayObject child, int index); // // // /** // * Swaps the position of 2 Display Objects within this container. // * @param child - First display object to swap // * @param child2 - Second display object to swap // */ // @JsMethod // public native void swapChildren(DisplayObject child, DisplayObject child2); // // /** // * TODO:check if can be null // * Returns the index position of a child DisplayObject instance // * @param child The DisplayObject instance to identify // * @return The index position of the child display object to identify // */ // @JsMethod // public native int getChildIndex(DisplayObject child); // // /** // * Changes the position of an existing child in the display object container // * @param child - The child DisplayObject instance for which you want to change the index number // * @param index - The resulting index number for the child display object // */ // @JsMethod // public native void setChildIndex(DisplayObject child, int index); // // /** // * Returns the child at the specified index // * @param index The index to get the child at // * @return The child at the given index, if any. // */ // @JsMethod // public native DisplayObject getChildAt(int index); // // /** // * Removes a child from the container. // * @param child - The DisplayObject to remove // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChild(DisplayObject child); // // /** // * Removes a child from the specified index position. // * @param index - The index to get the child from // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChildAt(int index); // // /** // * TODO:check behavior when parameters omitted, add overload methods // * Removes all children from this container that are within the begin and end indexes. // * @param beginIndex (default 0) The beginning position. // * @param endIndex (this.children.length) The ending position. Default value is size of the container. // */ // @JsMethod // public native void removeChildren(int beginIndex, int endIndex); // @JsMethod // public native Texture generateTexture(Renderer renderer, int resolution, int scaleMode); // // /** // * Removes all internal references and listeners as well // * as removes children from the display list. // * Do not use a Container after calling destroy. // * TODO: test actual functionality and add Typed variable // * @param options // */ // @JsMethod // public native void destroy(Object options); // // @JsMethod // public native DisplayObject getChildByName(String name); // // }
import sk.mrtn.pixi.client.Container;
package sk.mrtn.pixi.client.stage; /** * Created by martinliptak on 02/10/16. * Main purpose of this class/object is to wrap {@link Container} * react to resizing of parent controllers. and sending * resize behavior to added children */ public interface IResponsiveController { void onResized(double width, double height);
// Path: src/main/java/sk/mrtn/pixi/client/Container.java // @JsType(isNative = true, namespace = "PIXI") // public class Container extends DisplayObject { // // /** // * The array of children of this container. // */ // @JsProperty // public DisplayObject[] children; // // /** // * The height of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double height; // // /** // * The width of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double width; // // @Inject // @JsConstructor // public Container(){} // // // PUBLIC METHODS // @JsMethod // public native void onChildrenChange(); // // /** // * Adds a child or multiple children to the container. // * Multple items can be added like so: // * myContainer.addChild(thinkOne, thingTwo, thingThree) // * @param child - repeatable, The DisplayObject(s) to add to the container // * @return The first child that was added. // */ // @JsMethod // public native DisplayObject addChild(DisplayObject... child); // // /** // * Adds a child to the container at a specified index. // * If the index is out of bounds an error will be thrown // * @param child The child to add // * @param index The index to place the child in // * @return The child that was added. // */ // @JsMethod // public native DisplayObject addChildAt(DisplayObject child, int index); // // // /** // * Swaps the position of 2 Display Objects within this container. // * @param child - First display object to swap // * @param child2 - Second display object to swap // */ // @JsMethod // public native void swapChildren(DisplayObject child, DisplayObject child2); // // /** // * TODO:check if can be null // * Returns the index position of a child DisplayObject instance // * @param child The DisplayObject instance to identify // * @return The index position of the child display object to identify // */ // @JsMethod // public native int getChildIndex(DisplayObject child); // // /** // * Changes the position of an existing child in the display object container // * @param child - The child DisplayObject instance for which you want to change the index number // * @param index - The resulting index number for the child display object // */ // @JsMethod // public native void setChildIndex(DisplayObject child, int index); // // /** // * Returns the child at the specified index // * @param index The index to get the child at // * @return The child at the given index, if any. // */ // @JsMethod // public native DisplayObject getChildAt(int index); // // /** // * Removes a child from the container. // * @param child - The DisplayObject to remove // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChild(DisplayObject child); // // /** // * Removes a child from the specified index position. // * @param index - The index to get the child from // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChildAt(int index); // // /** // * TODO:check behavior when parameters omitted, add overload methods // * Removes all children from this container that are within the begin and end indexes. // * @param beginIndex (default 0) The beginning position. // * @param endIndex (this.children.length) The ending position. Default value is size of the container. // */ // @JsMethod // public native void removeChildren(int beginIndex, int endIndex); // @JsMethod // public native Texture generateTexture(Renderer renderer, int resolution, int scaleMode); // // /** // * Removes all internal references and listeners as well // * as removes children from the display list. // * Do not use a Container after calling destroy. // * TODO: test actual functionality and add Typed variable // * @param options // */ // @JsMethod // public native void destroy(Object options); // // @JsMethod // public native DisplayObject getChildByName(String name); // // } // Path: src/main/java/sk/mrtn/pixi/client/stage/IResponsiveController.java import sk.mrtn.pixi.client.Container; package sk.mrtn.pixi.client.stage; /** * Created by martinliptak on 02/10/16. * Main purpose of this class/object is to wrap {@link Container} * react to resizing of parent controllers. and sending * resize behavior to added children */ public interface IResponsiveController { void onResized(double width, double height);
Container getContainer();
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/GroupD8.java
// Path: src/main/java/sk/mrtn/pixi/client/Matrix.java // @JsType(isNative = true, namespace = "PIXI") // public class Matrix { // // // PUBLIC STATIC FIELDS // // // PUBLIC STATIC METHODS // // @JsConstructor // public Matrix(){}; // // // PUBLIC FIELDS // @JsProperty // public int a; // @JsProperty // public int b; // @JsProperty // public int c; // @JsProperty // public int d; // @JsProperty // public int tx; // @JsProperty // public int ty; // // // PUBLIC METHODS // @JsMethod // public native Matrix fromArray(int[] array); // // // UNDOCUMENTED // @JsMethod // public native Matrix set(int a, int b, int c, int d, int tx, int ty); // @JsMethod // public native int[] toArray(boolean transpose); // @JsMethod // public native Point apply(Point pos, Point newPos); // @JsMethod // public native Point applyInverse(Point pos, Point newPos); // @JsMethod // public native Matrix translate(double x, double y); // @JsMethod // public native Matrix scale(double x, double y); // @JsMethod // public native Matrix rotate(double angle); // @JsMethod // public native Matrix append(Matrix matrix); // // UNDOCUMENTED // @JsMethod // public native Matrix setTransform(double x, double y, double pivotX, double pivotY, double scaleX, double scaleY, double rotation, double skewX, double skewY); // @JsMethod // public native Matrix prepend(Matrix matrix); // @JsMethod // public native Matrix invert(); // @JsMethod // public native Matrix identity(); // @JsMethod // public native Matrix clone(); // @JsMethod // public native Matrix copy(Matrix matrix); // // }
import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.Matrix;
public int N; @JsProperty public int NE; @JsProperty public int MIRROR_VERTICAL; @JsProperty public int MIRROR_HORIZONTAL; // PUBLIC METHODS @JsMethod public native int uX(int ind); @JsMethod public native int uY(int ind); @JsMethod public native int vX(int ind); @JsMethod public native int vY(int ind); @JsMethod public native double inv(double rotation); @JsMethod public native int add(int rotationSecond, int rotationFirst); @JsMethod public native int sub(int rotationSecond, int rotationFirst); @JsMethod public native double rotate180(double rotation); @JsMethod public native boolean isSwapWidthHeight(double rotation); @JsMethod public native int byDirection(double dx, double dy); @JsMethod
// Path: src/main/java/sk/mrtn/pixi/client/Matrix.java // @JsType(isNative = true, namespace = "PIXI") // public class Matrix { // // // PUBLIC STATIC FIELDS // // // PUBLIC STATIC METHODS // // @JsConstructor // public Matrix(){}; // // // PUBLIC FIELDS // @JsProperty // public int a; // @JsProperty // public int b; // @JsProperty // public int c; // @JsProperty // public int d; // @JsProperty // public int tx; // @JsProperty // public int ty; // // // PUBLIC METHODS // @JsMethod // public native Matrix fromArray(int[] array); // // // UNDOCUMENTED // @JsMethod // public native Matrix set(int a, int b, int c, int d, int tx, int ty); // @JsMethod // public native int[] toArray(boolean transpose); // @JsMethod // public native Point apply(Point pos, Point newPos); // @JsMethod // public native Point applyInverse(Point pos, Point newPos); // @JsMethod // public native Matrix translate(double x, double y); // @JsMethod // public native Matrix scale(double x, double y); // @JsMethod // public native Matrix rotate(double angle); // @JsMethod // public native Matrix append(Matrix matrix); // // UNDOCUMENTED // @JsMethod // public native Matrix setTransform(double x, double y, double pivotX, double pivotY, double scaleX, double scaleY, double rotation, double skewX, double skewY); // @JsMethod // public native Matrix prepend(Matrix matrix); // @JsMethod // public native Matrix invert(); // @JsMethod // public native Matrix identity(); // @JsMethod // public native Matrix clone(); // @JsMethod // public native Matrix copy(Matrix matrix); // // } // Path: src/main/java/sk/mrtn/pixi/client/GroupD8.java import jsinterop.annotations.JsMethod; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; import sk.mrtn.pixi.client.Matrix; public int N; @JsProperty public int NE; @JsProperty public int MIRROR_VERTICAL; @JsProperty public int MIRROR_HORIZONTAL; // PUBLIC METHODS @JsMethod public native int uX(int ind); @JsMethod public native int uY(int ind); @JsMethod public native int vX(int ind); @JsMethod public native int vY(int ind); @JsMethod public native double inv(double rotation); @JsMethod public native int add(int rotationSecond, int rotationFirst); @JsMethod public native int sub(int rotationSecond, int rotationFirst); @JsMethod public native double rotate180(double rotation); @JsMethod public native boolean isSwapWidthHeight(double rotation); @JsMethod public native int byDirection(double dx, double dy); @JsMethod
public native void matrixAppendRotationInv(Matrix matrix, double rotation, double tx, double ty);