id
stringlengths 7
14
| text
stringlengths 1
106k
|
---|---|
225211_1 | public static <T> Class<? extends T> locate(Class<T> factoryId) {
return locate(factoryId, factoryId.getName());
} |
225211_2 | public static <T> Class<? extends T> locate(Class<T> factoryId) {
return locate(factoryId, factoryId.getName());
} |
225211_3 | public static <T> Class<? extends T> locate(Class<T> factoryId) {
return locate(factoryId, factoryId.getName());
} |
229738_0 | @Override
public boolean accepts(Class<?> extensionType) {
if (looksLikeSqlObject(extensionType)) {
if (extensionType.getAnnotation(GenerateSqlObject.class) != null) {
return true;
}
if (!extensionType.isInterface()) {
throw new IllegalArgumentException("SQL Objects are only supported for interfaces.");
}
return true;
}
return false;
} |
229738_1 | @Override
public Optional<RowMapper<?>> build(Type type, ConfigRegistry config) {
Class<?> erasedType = getErasedType(type);
boolean emptyTupleType = Tuple0.class.equals(erasedType) || Tuple.class.equals(erasedType);
boolean mappableTupleType = type instanceof ParameterizedType && Tuple.class.isAssignableFrom(erasedType);
if (mappableTupleType && !emptyTupleType) {
Class<? extends Tuple> tupleClass = (Class<? extends Tuple>) erasedType;
Array<Tuple2<Type, Integer>> tupleTypes = Array.of(tupleClass.getTypeParameters())
.map(tp -> resolveType(tp, type))
.zipWithIndex((t, i) -> Tuple.of(t, i + 1));
Array<Tuple3<Type, Integer, Option<String>>> withConfiguredColumnName;
if (Tuple2.class.equals(erasedType)) {
withConfiguredColumnName = resolveKeyValueColumns(config, tupleTypes);
} else {
withConfiguredColumnName = tupleTypes
.map(t -> Tuple.of(t._1, t._2, getConfiguredColumnName(t._2, config)));
}
boolean anyColumnSet = withConfiguredColumnName.map(t -> t._3).exists(Option::isDefined);
if (anyColumnSet) {
Array<Optional<RowMapper<?>>> mappers = withConfiguredColumnName
.map(t -> t._3.isDefined()
? getColumnMapperForDefinedColumn(t._1, t._3.get(), config)
: getRowMapper(t._1, config));
boolean mappableWithConfigured = mappers.forAll(Optional::isPresent);
if (mappableWithConfigured) {
return buildMapper(tupleClass, mappers);
}
Array<String> configuredColumns = withConfiguredColumnName
.map(t -> t._2 + ": " + t._3.getOrNull());
throw new NoSuchMapperException(type + " cannot be mapped. "
+ "If tuple columns are configured (TupleMappers config class), "
+ "each tuple entry must be mappable via "
+ "specified column name or existing RowMapper. "
+ "Currently configured: " + configuredColumns.mkString(", "));
} else {
Array<Optional<RowMapper<?>>> colMappers = tupleTypes
.map(t -> getColumnMapper(t._1, t._2, config));
boolean mappableByColumn = colMappers.forAll(Optional::isPresent);
if (mappableByColumn) {
return buildMapper(tupleClass, colMappers);
}
Array<Optional<RowMapper<?>>> rowMappers = tupleTypes
.map(t -> getRowMapper(t._1, config));
boolean mappableByRowMappers = rowMappers.forAll(Optional::isPresent);
if (mappableByRowMappers) {
return buildMapper(tupleClass, rowMappers);
}
throw new NoSuchMapperException(type + " cannot be mapped. "
+ "All tuple elements must be mappable by ColumnMapper or all by RowMapper. "
+ "If you want to mix column- and rowmapped entries, you must configure "
+ "columns via TupleMappers config class");
}
}
return Optional.empty();
} |
229738_2 | @Override
public Optional<RowMapper<?>> build(Type type, ConfigRegistry config) {
Class<?> erasedType = getErasedType(type);
boolean emptyTupleType = Tuple0.class.equals(erasedType) || Tuple.class.equals(erasedType);
boolean mappableTupleType = type instanceof ParameterizedType && Tuple.class.isAssignableFrom(erasedType);
if (mappableTupleType && !emptyTupleType) {
Class<? extends Tuple> tupleClass = (Class<? extends Tuple>) erasedType;
Array<Tuple2<Type, Integer>> tupleTypes = Array.of(tupleClass.getTypeParameters())
.map(tp -> resolveType(tp, type))
.zipWithIndex((t, i) -> Tuple.of(t, i + 1));
Array<Tuple3<Type, Integer, Option<String>>> withConfiguredColumnName;
if (Tuple2.class.equals(erasedType)) {
withConfiguredColumnName = resolveKeyValueColumns(config, tupleTypes);
} else {
withConfiguredColumnName = tupleTypes
.map(t -> Tuple.of(t._1, t._2, getConfiguredColumnName(t._2, config)));
}
boolean anyColumnSet = withConfiguredColumnName.map(t -> t._3).exists(Option::isDefined);
if (anyColumnSet) {
Array<Optional<RowMapper<?>>> mappers = withConfiguredColumnName
.map(t -> t._3.isDefined()
? getColumnMapperForDefinedColumn(t._1, t._3.get(), config)
: getRowMapper(t._1, config));
boolean mappableWithConfigured = mappers.forAll(Optional::isPresent);
if (mappableWithConfigured) {
return buildMapper(tupleClass, mappers);
}
Array<String> configuredColumns = withConfiguredColumnName
.map(t -> t._2 + ": " + t._3.getOrNull());
throw new NoSuchMapperException(type + " cannot be mapped. "
+ "If tuple columns are configured (TupleMappers config class), "
+ "each tuple entry must be mappable via "
+ "specified column name or existing RowMapper. "
+ "Currently configured: " + configuredColumns.mkString(", "));
} else {
Array<Optional<RowMapper<?>>> colMappers = tupleTypes
.map(t -> getColumnMapper(t._1, t._2, config));
boolean mappableByColumn = colMappers.forAll(Optional::isPresent);
if (mappableByColumn) {
return buildMapper(tupleClass, colMappers);
}
Array<Optional<RowMapper<?>>> rowMappers = tupleTypes
.map(t -> getRowMapper(t._1, config));
boolean mappableByRowMappers = rowMappers.forAll(Optional::isPresent);
if (mappableByRowMappers) {
return buildMapper(tupleClass, rowMappers);
}
throw new NoSuchMapperException(type + " cannot be mapped. "
+ "All tuple elements must be mappable by ColumnMapper or all by RowMapper. "
+ "If you want to mix column- and rowmapped entries, you must configure "
+ "columns via TupleMappers config class");
}
}
return Optional.empty();
} |
229738_3 | @Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> rawType = GenericTypes.getErasedType(type);
if (VALUE_CLASSES.stream().anyMatch(vc -> vc.isAssignableFrom(rawType))) {
return buildValueArgument(type, config, (Value) value);
}
return Optional.empty();
} |
229738_4 | @Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> rawType = GenericTypes.getErasedType(type);
if (VALUE_CLASSES.stream().anyMatch(vc -> vc.isAssignableFrom(rawType))) {
return buildValueArgument(type, config, (Value) value);
}
return Optional.empty();
} |
229738_5 | @Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> rawType = GenericTypes.getErasedType(type);
if (VALUE_CLASSES.stream().anyMatch(vc -> vc.isAssignableFrom(rawType))) {
return buildValueArgument(type, config, (Value) value);
}
return Optional.empty();
} |
229738_6 | @Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> rawType = GenericTypes.getErasedType(type);
if (VALUE_CLASSES.stream().anyMatch(vc -> vc.isAssignableFrom(rawType))) {
return buildValueArgument(type, config, (Value) value);
}
return Optional.empty();
} |
229738_7 | @Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> rawType = GenericTypes.getErasedType(type);
if (VALUE_CLASSES.stream().anyMatch(vc -> vc.isAssignableFrom(rawType))) {
return buildValueArgument(type, config, (Value) value);
}
return Optional.empty();
} |
229738_8 | @Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> rawType = GenericTypes.getErasedType(type);
if (VALUE_CLASSES.stream().anyMatch(vc -> vc.isAssignableFrom(rawType))) {
return buildValueArgument(type, config, (Value) value);
}
return Optional.empty();
} |
229738_9 | @Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> rawType = GenericTypes.getErasedType(type);
if (VALUE_CLASSES.stream().anyMatch(vc -> vc.isAssignableFrom(rawType))) {
return buildValueArgument(type, config, (Value) value);
}
return Optional.empty();
} |
231990_0 | public static List<String> parseArtist(String artist) {
Pattern pattern = Pattern.compile("(.+)(( (F|f)eat(\\. |\\.| |uring ))(.+))");
Matcher matcher = pattern.matcher(artist);
boolean matches = matcher.matches();
if (matches) {
String lead = matcher.group(1).trim();
String featuring = matcher.group(6).trim();
return createContributorList(lead, featuring);
}
pattern = Pattern.compile("(.+)(( (A|a|U|u)nd )|&)(.+)");
matcher = pattern.matcher(artist);
matches = matcher.matches();
if (matches) {
String lead = matcher.group(1).trim();
String featuring = matcher.group(5).trim();
return createContributorList(lead, featuring);
}
return singletonList(artist);
} |
231990_1 | public static List<String> parseTrack(String track) {
Pattern pattern = Pattern.compile("(.+)(\\((F|f)eat(\\. |\\.| |uring )(.+))\\)");
Matcher matcher = pattern.matcher(track);
boolean matches = matcher.matches();
if (matches) {
String title = matcher.group(1).trim();
String featuring = matcher.group(5).trim();
return createContributorList(title, featuring);
}
pattern = Pattern.compile("(.+)(\\((W|w)ith(.+))\\)");
matcher = pattern.matcher(track);
matches = matcher.matches();
if (matches) {
String title = matcher.group(1).trim();
String featuring = matcher.group(4).trim();
return createContributorList(title, featuring);
}
return singletonList(track);
} |
231990_2 | public static String formatContributors(String artist, List<String> contributors) {
StringBuilder buffer = new StringBuilder();
buffer.append(artist);
if (contributors.size() > 0)
buffer.append(" featuring ");
for (int i = 0, c = contributors.size(); i < c; i++) {
String contributor = contributors.get(i);
buffer.append(contributor);
if (i < c - 1)
buffer.append(", ");
}
return buffer.toString();
} |
235076_0 | public JenaObjectWrapper() {
super();
} |
235076_1 | public TemplateModel wrap(Object obj) throws TemplateModelException {
if (obj instanceof Resource) {
return new ResourceHashModel((Resource) obj);
} else {
return super.wrap(obj);
}
} |
235076_2 | @Override
public int size() throws TemplateModelException {
StmtIterator iterator = resource.listProperties();
return iterator.toList().size();
} |
235076_3 | @Override
public int size() throws TemplateModelException {
StmtIterator iterator = resource.listProperties();
return iterator.toList().size();
} |
235076_4 | @Override
public TemplateCollectionModel keys() throws TemplateModelException {
ArrayList<String> list = new ArrayList<String>();
StmtIterator iterator = resource.listProperties();
while (iterator.hasNext()) {
list.add(iterator.next().getPredicate().getURI());
}
return new SimpleCollection(list);
} |
235076_5 | @Override
public TemplateCollectionModel values() throws TemplateModelException {
ArrayList<String> list = new ArrayList<String>();
StmtIterator iterator = resource.listProperties();
while (iterator.hasNext()) {
RDFNode node = iterator.next().getObject();
if (node.isLiteral()) {
list.add(((Literal) node).getLexicalForm());
} else if (node.isResource()) {
list.add(((Resource) node).getURI());
}
}
return new SimpleCollection(list);
} |
235076_6 | @Override
public TemplateModel get(String s) throws TemplateModelException {
String uri = prefixMapping.expandPrefix(s);
Property property = ResourceFactory.createProperty(uri);
if (!resource.hasProperty(property)) {
return null; // bail
}
List<TemplateModel> list = new ArrayList<TemplateModel>();
StmtIterator iter = resource.listProperties(property);
while (iter.hasNext()) {
list.add(resolveModel(iter.next().getObject()));
}
Collections.sort(list, new McaJenaResourceComparator());
return new SimpleSequence(list);
} |
235076_7 | @Override
public boolean isEmpty() throws TemplateModelException {
StmtIterator iterator = resource.listProperties();
return iterator.toList().size() == 0;
} |
235076_8 | @Override
public String getAsString() throws TemplateModelException {
if (resource.getURI() == null) {
return INVALID_URL; // b-nodes return null and their ids are useless
} else {
return resource.getURI();
}
} |
235076_9 | @Override
public String getAsString() throws TemplateModelException {
if (resource.getURI() == null) {
return INVALID_URL; // b-nodes return null and their ids are useless
} else {
return resource.getURI();
}
} |
237920_0 | public void setProjects(Projects projects) {
this.projects = projects;
} |
237920_1 | public void setProjects(Projects projects) {
this.projects = projects;
} |
240464_0 | public static JsonProvider provider() {
return CACHE.get();
} |
240464_1 | public static JsonProvider provider() {
return CACHE.get();
} |
240464_2 | public String getMessage() {
if (causeException == null) return super.getMessage();
StringBuilder sb = new StringBuilder();
if (super.getMessage() != null) {
sb.append(super.getMessage());
sb.append("; ");
}
sb.append("nested exception is: ");
sb.append(causeException.toString());
return sb.toString();
} |
240464_3 | @Override
public Throwable getCause() {
return super.getCause() != null ? super.getCause() : getCausedByException();
} |
240464_4 | public Exception getCausedByException() {
return causeException;
} |
240464_5 | public void printStackTrace(PrintStream ps) {
if (causeException == null || super.getCause() == null || causeException == super.getCause()) {
super.printStackTrace(ps);
} else synchronized (ps) {
ps.println(this);
causeException.printStackTrace(ps);
super.printStackTrace(ps);
}
} |
240466_0 | public static boolean canConvert(final String type, final ClassLoader classLoader) {
if (type == null) {
throw new NullPointerException("type is null");
}
if (classLoader == null) {
throw new NullPointerException("classLoader is null");
}
try {
return REGISTRY.findConverter(Class.forName(type, true, classLoader)) != null;
} catch (ClassNotFoundException e) {
throw new PropertyEditorException("Type class could not be found: " + type);
}
} |
240466_1 | public static Object getValue(final String type, final String value, final ClassLoader classLoader) throws PropertyEditorException {
return REGISTRY.getValue(type, value, classLoader);
} |
240466_2 | public static Object getValue(final String type, final String value, final ClassLoader classLoader) throws PropertyEditorException {
return REGISTRY.getValue(type, value, classLoader);
} |
240466_3 | public static Object getValue(final String type, final String value, final ClassLoader classLoader) throws PropertyEditorException {
return REGISTRY.getValue(type, value, classLoader);
} |
240466_4 | static List<Method> getCandidates(final Class type) {
final List<Method> candidates = new ArrayList<Method>();
for (final Method method : type.getMethods()) {
if (!Modifier.isStatic(method.getModifiers())) continue;
if (!Modifier.isPublic(method.getModifiers())) continue;
if (!method.getReturnType().equals(type)) continue;
if (method.getParameterTypes().length != 1) continue;
if (!method.getParameterTypes()[0].equals(String.class)) continue;
candidates.add(method);
}
return candidates;
} |
240466_5 | static void sort(final List<Method> candidates) {
Collections.sort(candidates, new Comparator<Method>() {
public int compare(final Method a, final Method b) {
int av = grade(a);
int bv = grade(b);
return (a.getName().compareTo(b.getName()) + (av - bv));
}
});
} |
240466_6 | public static boolean isConvertable(Type type, Object propertyValue, PropertyEditorRegistry registry) {
if (propertyValue instanceof Recipe) {
Recipe recipe = (Recipe) propertyValue;
return recipe.canCreate(type);
}
return (propertyValue instanceof String && (registry == null ? PropertyEditors.registry() : registry).findConverter(toClass(type)) != null)
|| (type == String.class && char[].class.isInstance(propertyValue));
} |
240466_7 | public static Object convert(Type expectedType, Object value, boolean lazyRefAllowed, PropertyEditorRegistry registry) {
if (value instanceof Recipe) {
Recipe recipe = (Recipe) value;
value = recipe.create(expectedType, lazyRefAllowed);
}
// some shortcuts for common string operations
if (char[].class == expectedType && String.class.isInstance(value)) {
return String.class.cast(value).toCharArray();
}
if (String.class == expectedType && char[].class.isInstance(value)) {
return new String(char[].class.cast(value));
}
if (value instanceof String && (expectedType != Object.class)) {
String stringValue = (String) value;
value = (registry == null ? PropertyEditors.registry() : registry).getValue(expectedType, stringValue);
}
return value;
} |
240466_8 | public InputStream getBytecode(String className) throws IOException, ClassNotFoundException {
int pos = className.indexOf("<");
if (pos > -1) {
className = className.substring(0, pos);
}
pos = className.indexOf(">");
if (pos > -1) {
className = className.substring(0, pos);
}
if (!className.endsWith(".class")) {
className = className.replace('.', '/') + ".class";
}
ZipEntry entry = jar.getEntry(className);
if (entry == null) throw new ClassNotFoundException(className);
return jar.getInputStream(entry);
} |
240466_9 | public Class<?> loadClass(String className) throws ClassNotFoundException {
// assume the loader knows how to handle mjar release if activated
return loader.loadClass(className);
} |
247823_0 | private HttpStatus(int code, String message, boolean register) {
this.code = code;
this.message = message;
if (register) {
valuesByInt.put(code, this);
}
} |
247823_1 | public static HttpStatus valueOf(int code) {
return valuesByInt.get(code);
} |
247823_2 | public String getStatusLine() {
StringBuilder builder = new StringBuilder(SL_11_START.length() + 4 + message.length());
builder.append(SL_11_START).append(code).append(' ').append(message);
return builder.toString();
} |
247823_3 | public boolean isError() {
return code >= 400;
} |
247823_4 | public Application generate(String baseURI, Set<Class<?>> classes) {
/*
* the idea is that classes comes from the Application subclass
*/
Application app = new Application();
if (classes == null || classes.isEmpty()) {
return app;
}
Resources resources = new Resources();
resources.setBase(baseURI);
Set<ClassMetadata> metadataSet = buildClassMetdata(classes);
resources.getResource().addAll(buildResources(metadataSet));
app.getResources().add(resources);
return app;
} |
247823_5 | Set<ClassMetadata> buildClassMetdata(Set<Class<?>> classes) {
Set<ClassMetadata> metadataSet = new HashSet<ClassMetadata>(classes.size());
for (Class<?> c : classes) {
if (!isResource(c)) {
/* not a resource, so skip it */
continue;
}
ClassMetadata metadata = ResourceMetadataCollector.collectMetadata(c);
metadataSet.add(metadata);
}
return metadataSet;
} |
247823_6 | Set<ClassMetadata> buildClassMetdata(Set<Class<?>> classes) {
Set<ClassMetadata> metadataSet = new HashSet<ClassMetadata>(classes.size());
for (Class<?> c : classes) {
if (!isResource(c)) {
/* not a resource, so skip it */
continue;
}
ClassMetadata metadata = ResourceMetadataCollector.collectMetadata(c);
metadataSet.add(metadata);
}
return metadataSet;
} |
247823_7 | Set<ClassMetadata> buildClassMetdata(Set<Class<?>> classes) {
Set<ClassMetadata> metadataSet = new HashSet<ClassMetadata>(classes.size());
for (Class<?> c : classes) {
if (!isResource(c)) {
/* not a resource, so skip it */
continue;
}
ClassMetadata metadata = ResourceMetadataCollector.collectMetadata(c);
metadataSet.add(metadata);
}
return metadataSet;
} |
247823_8 | Set<ClassMetadata> buildClassMetdata(Set<Class<?>> classes) {
Set<ClassMetadata> metadataSet = new HashSet<ClassMetadata>(classes.size());
for (Class<?> c : classes) {
if (!isResource(c)) {
/* not a resource, so skip it */
continue;
}
ClassMetadata metadata = ResourceMetadataCollector.collectMetadata(c);
metadataSet.add(metadata);
}
return metadataSet;
} |
247823_9 | Resource buildResource(ClassMetadata metadata) {
Resource r = new Resource();
if (metadata != null) {
Class<?> resClass = metadata.getResourceClass();
if (resClass != null) {
WADLDoc d = resClass.getAnnotation(WADLDoc.class);
if (d != null) {
r.getDoc().add(getDocument(d));
}
}
}
/* set the path */
String path = metadata.getPath();
if (path == null) {
Class<?> resClass = metadata.getResourceClass();
if (DynamicResource.class.isAssignableFrom(resClass)) {
try {
DynamicResource dynRes = (DynamicResource)resClass.newInstance();
path = dynRes.getPath();
} catch (Exception e) {
// Drop through and look for @Path annotation.
}
}
}
UriTemplateProcessor processor = JaxRsUriTemplateProcessor.newNormalizedInstance(path);
String pathStr = processor.getTemplate();
for (String var : processor.getVariableNames()) {
pathStr = pathStr.replaceAll("\\{(\\s)*" + var + "(\\s)*:.*\\}", "{" + var + "}");
}
r.setPath(pathStr);
List<Object> methodOrSubresource = r.getMethodOrResource();
List<Param> resourceParams = r.getParam();
List<MethodMetadata> methodMetadata = metadata.getResourceMethods();
if (methodMetadata != null && !methodMetadata.isEmpty()) {
for (MethodMetadata methodMeta : methodMetadata) {
Method m = buildMethod(metadata, methodMeta);
methodOrSubresource.add(m);
/* also scan for all the path and matrix parameters */
List<Injectable> params = methodMeta.getFormalParameters();
if (params != null && params.size() > 0) {
for (Injectable p : params) {
Param param = null;
boolean isUnique = true;
switch (p.getParamType()) {
case QUERY:
/* do nothing */
break;
case HEADER:
/* do nothing */
break;
case ENTITY:
/* do nothing */
break;
case COOKIE:
/* not supported in WADL */
break;
case FORM:
/* should show up in the representation instead */
break;
case PATH:
param = buildParam(p);
for (Param rParam : resourceParams) {
if (param.getName() != null && param.getName().equals(rParam
.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
resourceParams.add(param);
}
break;
case MATRIX:
param = buildParam(p);
for (Param rParam : resourceParams) {
if (param.getName() != null && param.getName().equals(rParam
.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
resourceParams.add(param);
}
break;
case CONTEXT:
/* do nothing */
break;
}
}
}
}
}
/*
* list the class level parameters
*/
List<Injectable> fields = metadata.getInjectableFields();
if (fields != null) {
for (Injectable p : metadata.getInjectableFields()) {
Param param = null;
boolean isUnique = true;
switch (p.getParamType()) {
case QUERY:
resourceParams.add(buildParam(p));
break;
case HEADER:
resourceParams.add(buildParam(p));
break;
case ENTITY:
/* do nothing */
break;
case COOKIE:
/* not supported in WADL */
break;
case FORM:
/* should show up in the representation instead */
break;
case PATH:
param = buildParam(p);
for (Param rParam : resourceParams) {
if (param.getName() != null && param.getName().equals(rParam.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
resourceParams.add(param);
}
break;
case MATRIX:
param = buildParam(p);
for (Param rParam : resourceParams) {
if (param.getName() != null && param.getName().equals(rParam.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
resourceParams.add(param);
}
break;
case CONTEXT:
/* do nothing */
break;
}
}
}
/*
* list subresource methods
*/
methodMetadata = metadata.getSubResourceMethods();
if (methodMetadata != null && !methodMetadata.isEmpty()) {
for (MethodMetadata methodMeta : methodMetadata) {
Resource subRes = new Resource();
Method m = buildMethod(metadata, methodMeta);
subRes.getMethodOrResource().add(m);
subRes.setPath(methodMeta.getPath());
methodOrSubresource.add(subRes);
List<Param> subResParams = subRes.getParam();
/* also scan for all the path and matrix parameters */
List<Injectable> params = methodMeta.getFormalParameters();
if (params != null && params.size() > 0) {
for (Injectable p : params) {
Param param = null;
boolean isUnique = true;
switch (p.getParamType()) {
case QUERY:
/* do nothing */
break;
case HEADER:
/* do nothing */
break;
case ENTITY:
/* do nothing */
break;
case COOKIE:
/* not supported in WADL */
break;
case FORM:
/* should show up in the representation instead */
break;
case PATH:
param = buildParam(p);
for (Param rParam : subResParams) {
if (param.getName() != null && param.getName().equals(rParam
.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
subRes.getParam().add(param);
}
break;
case MATRIX:
param = buildParam(p);
for (Param rParam : subResParams) {
if (param.getName() != null && param.getName().equals(rParam
.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
subRes.getParam().add(param);
}
break;
case CONTEXT:
/* do nothing */
break;
}
}
}
}
}
/*
* list subresource locators
*/
methodMetadata = metadata.getSubResourceLocators();
if (methodMetadata != null && !methodMetadata.isEmpty()) {
for (MethodMetadata methodMeta : methodMetadata) {
Resource subRes = new Resource();
subRes.setPath(methodMeta.getPath());
if (methodMeta != null) {
java.lang.reflect.Method reflMethod = methodMeta.getReflectionMethod();
if (reflMethod != null) {
WADLDoc d = reflMethod.getAnnotation(WADLDoc.class);
if (d != null) {
subRes.getDoc().add(getDocument(d));
}
}
}
methodOrSubresource.add(subRes);
/* also scan for all the path and matrix parameters */
List<Injectable> params = methodMeta.getFormalParameters();
List<Param> subResParams = subRes.getParam();
if (params != null && params.size() > 0) {
for (Injectable p : params) {
Param param = null;
boolean isUnique = true;
switch (p.getParamType()) {
case QUERY:
param = buildParam(p);
for (Param rParam : subResParams) {
if (param.getName() != null && param.getName().equals(rParam
.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
subRes.getParam().add(param);
}
break;
case HEADER:
param = buildParam(p);
for (Param rParam : subResParams) {
if (param.getName() != null && param.getName().equals(rParam
.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
subRes.getParam().add(param);
}
break;
case ENTITY:
/* do nothing */
break;
case COOKIE:
/* not supported in WADL */
break;
case FORM:
/* should show up in the representation instead */
break;
case PATH:
param = buildParam(p);
for (Param rParam : subResParams) {
if (param.getName() != null && param.getName().equals(rParam
.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
subRes.getParam().add(param);
}
break;
case MATRIX:
param = buildParam(p);
for (Param rParam : subResParams) {
if (param.getName() != null && param.getName().equals(rParam
.getName())
&& rParam.getStyle().equals(param.getStyle())) {
isUnique = false;
}
}
if (isUnique) {
subRes.getParam().add(param);
}
break;
case CONTEXT:
/* do nothing */
break;
}
}
}
}
}
return r;
} |
249855_0 | public String receiveAndSaveToFile(String objectName, File toFile) {
return receiveAndSaveToFile(defaultContainerName, objectName, toFile);
} |
249855_1 | public void deleteContainer(String containerName) {
try {
restService.deleteContainer(containerName);
} catch (AzureRestCommunicationException e) {
throw new StorageCommunicationException(e,
"Azure cloud storage request 'delete container' has failed [container: '%s'].", containerName);
} catch (AzureRestResponseHandlingException e) {
throw new StorageCommunicationException(
e,
"Response handling for Azure cloud storage request 'delete container' has failed [container: '%s'].",
containerName);
}
} |
249855_2 | public void deleteObject(String objectName) {
deleteObject(defaultContainerName, objectName);
} |
249855_3 | public List<BlobDetails> filter(final List<BlobDetails> objects) {
if (objects == null) {
return null;
}
List<BlobDetails> accepted = new ArrayList<BlobDetails>(objects);
for (int i = 0; i < blobDetailsFilters.size() && !accepted.isEmpty(); i++) {
accepted = blobDetailsFilters.get(0).filter(accepted);
}
return accepted;
} |
249855_4 | public List<BlobDetails> filter(final List<BlobDetails> objects) {
if (objects == null) {
return null;
}
List<BlobDetails> accepted = new ArrayList<BlobDetails>(objects);
for (int i = 0; i < blobDetailsFilters.size() && !accepted.isEmpty(); i++) {
accepted = blobDetailsFilters.get(0).filter(accepted);
}
return accepted;
} |
249855_5 | public int compare(BlobDetails b1, BlobDetails b2) {
Date b1LastModifiedDate = b1.getLastModified();
Date b2LastModifiedDate = b2.getLastModified();
if (b1LastModifiedDate.after(b2LastModifiedDate)) {
return 1;
}
else if (b1LastModifiedDate.before(b2LastModifiedDate)) {
return -1;
}
else {
return 0;
}
} |
249855_6 | public boolean createContainer(String containerName) {
Assert.notNull(containerName, BUCKET_NAME_CANNOT_BE_NULL);
try {
final S3Bucket bucket = s3Service.createBucket(new S3Bucket(containerName));
return bucket != null;
} catch (S3ServiceException e) {
throw new StorageCommunicationException("Bucket creation problem", e);
}
} |
249855_7 | public boolean createContainer(String containerName) {
Assert.notNull(containerName, BUCKET_NAME_CANNOT_BE_NULL);
try {
final S3Bucket bucket = s3Service.createBucket(new S3Bucket(containerName));
return bucket != null;
} catch (S3ServiceException e) {
throw new StorageCommunicationException("Bucket creation problem", e);
}
} |
249855_8 | public void deleteContainer(String containerName) {
Assert.notNull(containerName, BUCKET_NAME_CANNOT_BE_NULL);
LOG.debug("Delete bucket '{}'", containerName);
try {
s3Service.deleteBucket(new S3Bucket(containerName));
} catch (S3ServiceException e) {
throw new StorageCommunicationException(BUCKET_DELETION_PROBLEM, e);
}
} |
249855_9 | public void deleteContainer(String containerName) {
Assert.notNull(containerName, BUCKET_NAME_CANNOT_BE_NULL);
LOG.debug("Delete bucket '{}'", containerName);
try {
s3Service.deleteBucket(new S3Bucket(containerName));
} catch (S3ServiceException e) {
throw new StorageCommunicationException(BUCKET_DELETION_PROBLEM, e);
}
} |
279216_1 | public static <T> T match(String URL, Visitor<T> matcher) {
Matcher patternMatcher = pattern.matcher(URL);
if (!patternMatcher.matches()) {
throw new DespotifyException("Not a valid URL: " + URL);
}
URLtype urlType = patternMatcher.group(2) != null ? URLtype.httpURL : URLtype.spotifyURL;
if (patternMatcher.group(5) != null) {
return matcher.playlist(urlType, patternMatcher.group(6), patternMatcher.group(7));
} else if ("track".equals(patternMatcher.group(4))) {
return matcher.track(urlType, patternMatcher.group(7));
} else if ("album".equals(patternMatcher.group(4))) {
return matcher.album(urlType, patternMatcher.group(7));
} else if ("artist".equals(patternMatcher.group(4))) {
return matcher.artist(urlType, patternMatcher.group(7));
} else {
throw new RuntimeException();
}
} |
279216_2 | public static Visitable browse(String URL, final Store store, final DespotifyManager connectionManager) {
return match(URL, new Visitor<Visitable>(){
public Visitable track(URLtype type, String URI) {
Track track = store.getTrack(SpotifyURI.toHex(URI));
try {
new LoadTracks(store, track).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return track;
}
public Visitable album(URLtype type, String URI) {
Album album = store.getAlbum(SpotifyURI.toHex(URI));
try {
new LoadAlbum(store, album).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return album;
}
public Visitable artist(URLtype type, String URI) {
Artist artist = store.getArtist(SpotifyURI.toHex(URI));
try {
new LoadArtist(store, artist).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return artist;
}
public Visitable playlist(URLtype type, String user, String URI) {
Playlist playlist = store.getPlaylist(SpotifyURI.toHex(URI));
try {
new LoadPlaylist(store, playlist).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return playlist;
}
});
} |
279216_3 | public static Visitable browse(String URL, final Store store, final DespotifyManager connectionManager) {
return match(URL, new Visitor<Visitable>(){
public Visitable track(URLtype type, String URI) {
Track track = store.getTrack(SpotifyURI.toHex(URI));
try {
new LoadTracks(store, track).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return track;
}
public Visitable album(URLtype type, String URI) {
Album album = store.getAlbum(SpotifyURI.toHex(URI));
try {
new LoadAlbum(store, album).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return album;
}
public Visitable artist(URLtype type, String URI) {
Artist artist = store.getArtist(SpotifyURI.toHex(URI));
try {
new LoadArtist(store, artist).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return artist;
}
public Visitable playlist(URLtype type, String user, String URI) {
Playlist playlist = store.getPlaylist(SpotifyURI.toHex(URI));
try {
new LoadPlaylist(store, playlist).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return playlist;
}
});
} |
279216_4 | public static Visitable browse(String URL, final Store store, final DespotifyManager connectionManager) {
return match(URL, new Visitor<Visitable>(){
public Visitable track(URLtype type, String URI) {
Track track = store.getTrack(SpotifyURI.toHex(URI));
try {
new LoadTracks(store, track).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return track;
}
public Visitable album(URLtype type, String URI) {
Album album = store.getAlbum(SpotifyURI.toHex(URI));
try {
new LoadAlbum(store, album).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return album;
}
public Visitable artist(URLtype type, String URI) {
Artist artist = store.getArtist(SpotifyURI.toHex(URI));
try {
new LoadArtist(store, artist).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return artist;
}
public Visitable playlist(URLtype type, String user, String URI) {
Playlist playlist = store.getPlaylist(SpotifyURI.toHex(URI));
try {
new LoadPlaylist(store, playlist).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return playlist;
}
});
} |
279216_5 | public static Visitable browse(String URL, final Store store, final DespotifyManager connectionManager) {
return match(URL, new Visitor<Visitable>(){
public Visitable track(URLtype type, String URI) {
Track track = store.getTrack(SpotifyURI.toHex(URI));
try {
new LoadTracks(store, track).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return track;
}
public Visitable album(URLtype type, String URI) {
Album album = store.getAlbum(SpotifyURI.toHex(URI));
try {
new LoadAlbum(store, album).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return album;
}
public Visitable artist(URLtype type, String URI) {
Artist artist = store.getArtist(SpotifyURI.toHex(URI));
try {
new LoadArtist(store, artist).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return artist;
}
public Visitable playlist(URLtype type, String user, String URI) {
Playlist playlist = store.getPlaylist(SpotifyURI.toHex(URI));
try {
new LoadPlaylist(store, playlist).send(connectionManager);
} catch (DespotifyException e) {
throw new RuntimeException(e);
}
return playlist;
}
});
} |
279216_6 | public Result send(DespotifyManager connectionManager) throws DespotifyException {
/* Create channel callback */
ChannelCallback callback = new ChannelCallback();
byte[] utf8Bytes = query.getBytes(Charset.forName("UTF8"));
/* Create channel and buffer. */
Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, callback);
ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + utf8Bytes.length);
/* Check offset and limit. */
if (offset < 0) {
throw new IllegalArgumentException("Offset needs to be >= 0");
}
else if ((maxResults < 0 && maxResults != -1) || maxResults == 0) {
throw new IllegalArgumentException("Limit needs to be either -1 for no limit or > 0");
}
/* Append channel id, some values, query length and query. */
buffer.putShort((short) channel.getId());
buffer.putInt(offset); /* Result offset. */
buffer.putInt(maxResults); /* Reply limit. */
buffer.putShort((short) 0x0000);
buffer.put((byte) utf8Bytes.length);
buffer.put(utf8Bytes);
buffer.flip();
/* Register channel. */
Channel.register(channel);
/* Send packet. */
ManagedConnection connection = connectionManager.getManagedConnection();
connection.getProtocol().sendPacket(PacketType.search, buffer, "search");
/* Get data and inflate it. */
byte[] data = GZIP.inflate(callback.getData("gzipped search response"));
connection.close();
if (log.isInfoEnabled()) {
log.info("received search response packet, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log));
}
/* Cut off that last 0xFF byte... */
data = Arrays.copyOfRange(data, 0, data.length - 1);
String xml = new String(data, Charset.forName("UTF-8"));
if (log.isDebugEnabled()) {
log.debug(xml);
}
XMLElement root = XML.load(xml);
/* Create result from XML. */
return Result.fromXMLElement(root, store);
} |
279216_7 | @Override
public Artist send(DespotifyManager connectionManager) throws DespotifyException {
Date now = new Date();
/* Create channel callback */
ChannelCallback callback = new ChannelCallback();
/* Send browse request. */
/* Create channel and buffer. */
Channel channel = new Channel("Browse-Channel", Channel.Type.TYPE_BROWSE, callback);
ByteBuffer buffer = ByteBuffer.allocate(2 + 1 + 16 + 4);
buffer.putShort((short) channel.getId());
buffer.put((byte) BrowseType.artist.getValue());
buffer.put(artist.getByteUUID());
buffer.putInt(0); // unknown
buffer.flip();
/* Register channel. */
Channel.register(channel);
/* Send packet. */
ManagedConnection connection = connectionManager.getManagedConnection();
connection.getProtocol().sendPacket(PacketType.browse, buffer, "load artist");
/* Get data and inflate it. */
byte[] data = GZIP.inflate(callback.getData("gzipped load artist response"));
connection.close();
if (log.isInfoEnabled()) {
log.info("load artist response, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log));
}
if (data.length == 0) {
if ("Various Artists".equals(artist.getName())) {
artist.setLoaded(now);
// good stuff // todo figure this out, various artists does not seem to get loaded> 19334eaffa3f4f2282e251e36611e26f
} else {
throw new ReceivedEmptyResponseException("This might be a real problem while communicting with Spotify, it can also be that you tried to load an artist representing 'Various Artists' Spotify will return an empty result. The official client does not seem to ever load such an artist.");
}
} else {
/* Cut off that last 0xFF byte... */
data = Arrays.copyOfRange(data, 0, data.length - 1);
try {
String xml = new String(data, Charset.forName("UTF-8"));
Writer out = new OutputStreamWriter(new FileOutputStream(new java.io.File("tmp/load_artist_"+artist.getId()+".xml")), "UTF8");
out.write(xml);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new ByteArrayInputStream(data), Charset.forName("UTF-8")));
ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr);
responseUnmarshaller.skip();
if (!"artist".equals(xmlr.getLocalName())) {
throw new DespotifyException("Expected document root to be of type <artist>");
}
Artist artist = responseUnmarshaller.unmarshallArtist(new Date());
if (!this.artist.equals(artist)) {
throw new DespotifyException("Artist in response has different UUID than the requested artist!");
}
} catch (XMLStreamException e) {
throw new DespotifyException(e);
}
}
return (Artist) store.persist(artist);
} |
279216_8 | @Override
public Album send(DespotifyManager connectionManager) throws DespotifyException {
Create channel callback */
ChannelCallback callback = new ChannelCallback();
/* Send browse request. */
/* Create channel and buffer. */
Channel channel = new Channel("Browse-Channel", Channel.Type.TYPE_BROWSE, callback);
ByteBuffer buffer = ByteBuffer.allocate(2 + 1 + 16 + 4);
buffer.putShort((short) channel.getId());
buffer.put((byte) BrowseType.album.getValue());
buffer.put(album.getByteUUID());
buffer.putInt(0); // unknown
buffer.flip();
/* Register channel. */
Channel.register(channel);
/* Send packet. */
ManagedConnection connection = connectionManager.getManagedConnection();
connection.getProtocol().sendPacket(PacketType.browse, buffer, "load album");
INFO Protocol - sending load album, 26 bytes:
1 3 5 7 |9 11 13 15 |17 19 21 23 |25 27 29 31 | 1111111112222222222333
2 4 6 8 | 10 12 14 16| 18 20 22 24| 26 28 31 32| 12345678901234567890123456789012
----------------|----------------|----------------|----------------|----------------------------------
30001700000202f8 df4ad52d449caca8 c6a25d2eca080000 0000 [0????????J?-D?????].??????]
/* Get data and inflate it. */
byte[] data = GZIP.inflate(callback.getData("gzipped load album response"));
connection.close();
if (log.isInfoEnabled()) {
log.info("load album response, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log));
}
/* Cut off that last 0xFF byte... */
data = Arrays.copyOfRange(data, 0, data.length - 1);
/* Load XML. */
try {
String xml = new String(data, Charset.forName("UTF-8"));
Writer out = new OutputStreamWriter(new FileOutputStream(new File("tmp/load_album_"+album.getId()+".xml")), "UTF8");
out.write(xml);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new ByteArrayInputStream(data), Charset.forName("UTF-8")));
ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr);
responseUnmarshaller.skip();
if (!"album".equals(xmlr.getLocalName())) {
throw new DespotifyException("Expected document root to be of type <album>");
}
album = responseUnmarshaller.unmarshallAlbum(new Date());
} catch (XMLStreamException e) {
throw new DespotifyException(e);
}
if (!this.album.equals(album)) {
throw new DespotifyException("Album in response has different UUID than the requested album!");
}
return (Album) store.persist(album);
} |
279216_9 | @Override
public Boolean send(DespotifyManager connectionManager) throws DespotifyException {
ChannelCallback callback = new ChannelCallback();
Channel channel = new Channel("Playlist-Channel", Channel.Type.TYPE_PLAYLIST, callback);
ByteBuffer buffer = ByteBuffer.allocate(2 + 16 + 1 + 4 + 4 + 4 + 1);
buffer.putShort((short)channel.getId()); // channel id
buffer.put(Hex.toBytes("00000000000000000000000000000000")); // uuid? not used
buffer.put((byte)0x00); // unknown
buffer.putInt(-1); // playlist history. -1: current. 0: changes since version 0, 1: since version 1, etc.
buffer.putInt(0); // unknown
buffer.putInt(-1); // unknown
buffer.put((byte)0x00); // 00 = get playlist ids, 01 = do not get playlist ids?
buffer.flip();
Channel.register(channel);
ManagedConnection connection = connectionManager.getManagedConnection();
connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "request list of user playlists");
byte[] data = callback.getData("user playlists response");
connection.close();
if (data.length == 0) {
throw new DespotifyException("received an empty response!");
}
String xml =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?><playlist>" +
new String(data, Charset.forName("UTF-8")) +
"</playlist>";
if (log.isDebugEnabled()) {
log.debug(xml);
}
XMLElement playlistElement = XML.load(xml);
if (user.getPlaylists() == null) {
user.setPlaylists(new PlaylistContainer());
}
PlaylistContainer.fromXMLElement(playlistElement, store, user.getPlaylists());
if (playlistElement.hasChild("next-change")) {
user.getPlaylists().setLoaded(new Date());
return true;
} else {
throw new RuntimeException("Unknown server response:\n" + xml);
}
} |
283187_0 | public static String pop() {
int next = size();
if (next == 0) {
return "";
}
int last = next - 1;
String key = PREFIX + last;
String val = MDC.get(key);
MDC.remove(key);
return val;
} |
283187_1 | public static String render(Object o) {
if (o == null) {
return String.valueOf(o);
}
Class<?> objectClass = o.getClass();
if (unrenderableClasses.containsKey(objectClass) == false) {
try {
if (objectClass.isArray()) {
return renderArray(o, objectClass).toString();
} else {
return o.toString();
}
} catch (Exception e) {
Long now = new Long(System.currentTimeMillis());
System.err.println("Disabling exception throwing class " + objectClass.getName() + ", " + e.getMessage());
unrenderableClasses.put(objectClass, now);
}
}
String name = o.getClass().getName();
return name + "@" + Integer.toHexString(o.hashCode());
} |
283187_2 | static DurationUnit selectDurationUnitForDisplay(StopWatch sw) {
return selectDurationUnitForDisplay(sw.elapsedTime());
} |
283187_3 | String recursivelyComputeLevelString() {
String tempName = name;
String levelString = null;
int indexOfLastDot = tempName.length();
while ((levelString == null) && (indexOfLastDot > -1)) {
tempName = tempName.substring(0, indexOfLastDot);
levelString = CONFIG_PARAMS.getStringProperty(SimpleLogger.LOG_KEY_PREFIX + tempName, null);
indexOfLastDot = String.valueOf(tempName).lastIndexOf(".");
}
return levelString;
} |
283187_4 | String recursivelyComputeLevelString() {
String tempName = name;
String levelString = null;
int indexOfLastDot = tempName.length();
while ((levelString == null) && (indexOfLastDot > -1)) {
tempName = tempName.substring(0, indexOfLastDot);
levelString = CONFIG_PARAMS.getStringProperty(SimpleLogger.LOG_KEY_PREFIX + tempName, null);
indexOfLastDot = String.valueOf(tempName).lastIndexOf(".");
}
return levelString;
} |
283187_5 | String recursivelyComputeLevelString() {
String tempName = name;
String levelString = null;
int indexOfLastDot = tempName.length();
while ((levelString == null) && (indexOfLastDot > -1)) {
tempName = tempName.substring(0, indexOfLastDot);
levelString = CONFIG_PARAMS.getStringProperty(SimpleLogger.LOG_KEY_PREFIX + tempName, null);
indexOfLastDot = String.valueOf(tempName).lastIndexOf(".");
}
return levelString;
} |
283187_6 | String recursivelyComputeLevelString() {
String tempName = name;
String levelString = null;
int indexOfLastDot = tempName.length();
while ((levelString == null) && (indexOfLastDot > -1)) {
tempName = tempName.substring(0, indexOfLastDot);
levelString = CONFIG_PARAMS.getStringProperty(SimpleLogger.LOG_KEY_PREFIX + tempName, null);
indexOfLastDot = String.valueOf(tempName).lastIndexOf(".");
}
return levelString;
} |
283187_7 | static void init() {
CONFIG_PARAMS = new SimpleLoggerConfiguration();
CONFIG_PARAMS.init();
} |
283187_8 | static void init() {
CONFIG_PARAMS = new SimpleLoggerConfiguration();
CONFIG_PARAMS.init();
} |
283187_9 | synchronized public Logger getLogger(String name) {
SubstituteLogger logger = loggers.get(name);
if (logger == null) {
logger = new SubstituteLogger(name, eventQueue, postInitialization);
loggers.put(name, logger);
}
return logger;
} |
283325_0 | public LoggerContext getLoggerContext() {
String contextName = null;
Context ctx = null;
// First check if ThreadLocal has been set already
LoggerContext lc = threadLocal.get();
if (lc != null) {
return lc;
}
try {
// We first try to find the name of our
// environment's LoggerContext
ctx = JNDIUtil.getInitialContext();
contextName = (String) JNDIUtil.lookup(ctx, JNDI_CONTEXT_NAME);
} catch (NamingException ne) {
// We can't log here
}
if (contextName == null) {
// We return the default context
return defaultContext;
} else {
// Let's see if we already know such a context
LoggerContext loggerContext = synchronizedContextMap.get(contextName);
if (loggerContext == null) {
// We have to create a new LoggerContext
loggerContext = new LoggerContext();
loggerContext.setName(contextName);
synchronizedContextMap.put(contextName, loggerContext);
URL url = findConfigFileURL(ctx, loggerContext);
if (url != null) {
configureLoggerContextByURL(loggerContext, url);
} else {
try {
new ContextInitializer(loggerContext).autoConfig();
} catch (JoranException je) {
}
}
// logback-292
if (!StatusUtil.contextHasStatusListener(loggerContext))
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
}
return loggerContext;
}
} |
283325_1 | public LoggerContext getLoggerContext() {
String contextName = null;
Context ctx = null;
// First check if ThreadLocal has been set already
LoggerContext lc = threadLocal.get();
if (lc != null) {
return lc;
}
try {
// We first try to find the name of our
// environment's LoggerContext
ctx = JNDIUtil.getInitialContext();
contextName = (String) JNDIUtil.lookup(ctx, JNDI_CONTEXT_NAME);
} catch (NamingException ne) {
// We can't log here
}
if (contextName == null) {
// We return the default context
return defaultContext;
} else {
// Let's see if we already know such a context
LoggerContext loggerContext = synchronizedContextMap.get(contextName);
if (loggerContext == null) {
// We have to create a new LoggerContext
loggerContext = new LoggerContext();
loggerContext.setName(contextName);
synchronizedContextMap.put(contextName, loggerContext);
URL url = findConfigFileURL(ctx, loggerContext);
if (url != null) {
configureLoggerContextByURL(loggerContext, url);
} else {
try {
new ContextInitializer(loggerContext).autoConfig();
} catch (JoranException je) {
}
}
// logback-292
if (!StatusUtil.contextHasStatusListener(loggerContext))
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
}
return loggerContext;
}
} |
283325_2 | public void remove(String key) {
if (key == null) {
return;
}
Map<String, String> oldMap = copyOnThreadLocal.get();
if (oldMap == null)
return;
Integer lastOp = getAndSetLastOperation(WRITE_OPERATION);
if (wasLastOpReadOrNull(lastOp)) {
Map<String, String> newMap = duplicateAndInsertNewMap(oldMap);
newMap.remove(key);
} else {
oldMap.remove(key);
}
} |
283325_3 | public void remove(String key) {
if (key == null) {
return;
}
Map<String, String> oldMap = copyOnThreadLocal.get();
if (oldMap == null)
return;
Integer lastOp = getAndSetLastOperation(WRITE_OPERATION);
if (wasLastOpReadOrNull(lastOp)) {
Map<String, String> newMap = duplicateAndInsertNewMap(oldMap);
newMap.remove(key);
} else {
oldMap.remove(key);
}
} |
283325_4 | public void put(String key, String val) throws IllegalArgumentException {
if (key == null) {
throw new IllegalArgumentException("key cannot be null");
}
Map<String, String> oldMap = copyOnThreadLocal.get();
Integer lastOp = getAndSetLastOperation(WRITE_OPERATION);
if (wasLastOpReadOrNull(lastOp) || oldMap == null) {
Map<String, String> newMap = duplicateAndInsertNewMap(oldMap);
newMap.put(key, val);
} else {
oldMap.put(key, val);
}
} |
283325_5 | public void autoConfig() throws JoranException {
StatusListenerConfigHelper.installIfAsked(loggerContext);
URL url = findURLOfDefaultConfigurationFile(true);
if (url != null) {
configureByResource(url);
} else {
Configurator c = EnvUtil.loadFromServiceLoader(Configurator.class);
if (c != null) {
try {
c.setContext(loggerContext);
c.configure(loggerContext);
} catch (Exception e) {
throw new LogbackException(String.format("Failed to initialize Configurator: %s using ServiceLoader", c != null ? c.getClass()
.getCanonicalName() : "null"), e);
}
} else {
BasicConfigurator basicConfigurator = new BasicConfigurator();
basicConfigurator.setContext(loggerContext);
basicConfigurator.configure(loggerContext);
}
}
} |
283325_6 | public void autoConfig() throws JoranException {
StatusListenerConfigHelper.installIfAsked(loggerContext);
URL url = findURLOfDefaultConfigurationFile(true);
if (url != null) {
configureByResource(url);
} else {
Configurator c = EnvUtil.loadFromServiceLoader(Configurator.class);
if (c != null) {
try {
c.setContext(loggerContext);
c.configure(loggerContext);
} catch (Exception e) {
throw new LogbackException(String.format("Failed to initialize Configurator: %s using ServiceLoader", c != null ? c.getClass()
.getCanonicalName() : "null"), e);
}
} else {
BasicConfigurator basicConfigurator = new BasicConfigurator();
basicConfigurator.setContext(loggerContext);
basicConfigurator.configure(loggerContext);
}
}
} |
283325_7 | public void autoConfig() throws JoranException {
StatusListenerConfigHelper.installIfAsked(loggerContext);
URL url = findURLOfDefaultConfigurationFile(true);
if (url != null) {
configureByResource(url);
} else {
Configurator c = EnvUtil.loadFromServiceLoader(Configurator.class);
if (c != null) {
try {
c.setContext(loggerContext);
c.configure(loggerContext);
} catch (Exception e) {
throw new LogbackException(String.format("Failed to initialize Configurator: %s using ServiceLoader", c != null ? c.getClass()
.getCanonicalName() : "null"), e);
}
} else {
BasicConfigurator basicConfigurator = new BasicConfigurator();
basicConfigurator.setContext(loggerContext);
basicConfigurator.configure(loggerContext);
}
}
} |
283325_8 | public static List<String> computeNameParts(String loggerName) {
List<String> partList = new ArrayList<String>();
int fromIndex = 0;
while (true) {
int index = getSeparatorIndexOf(loggerName, fromIndex);
if (index == -1) {
partList.add(loggerName.substring(fromIndex));
break;
}
partList.add(loggerName.substring(fromIndex, index));
fromIndex = index + 1;
}
return partList;
} |
283325_9 | public static List<String> computeNameParts(String loggerName) {
List<String> partList = new ArrayList<String>();
int fromIndex = 0;
while (true) {
int index = getSeparatorIndexOf(loggerName, fromIndex);
if (index == -1) {
partList.add(loggerName.substring(fromIndex));
break;
}
partList.add(loggerName.substring(fromIndex, index));
fromIndex = index + 1;
}
return partList;
} |
291242_0 | public String getBaseName() {
BaseName rbnAnnotation = enumClass.getAnnotation(BaseName.class);
if (rbnAnnotation == null) {
return null;
}
return rbnAnnotation.value();
} |
291242_1 | List<Token> tokenize() {
List<Token> tokenList = new ArrayList<Token>();
while (true) {
String currentLine;
try {
currentLine = lineReader.readLine();
} catch (IOException e) {
throw new MessageConveyorException("Failed to read input stream", e);
}
if (currentLine == null) {
break;
}
if(state != State.TRAILING_BACKSLASH) {
state = State.START;
}
tokenizeLine(tokenList, currentLine);
tokenList.add(Token.EOL);
}
return tokenList;
} |
291242_2 | List<Token> tokenize() {
List<Token> tokenList = new ArrayList<Token>();
while (true) {
String currentLine;
try {
currentLine = lineReader.readLine();
} catch (IOException e) {
throw new MessageConveyorException("Failed to read input stream", e);
}
if (currentLine == null) {
break;
}
if(state != State.TRAILING_BACKSLASH) {
state = State.START;
}
tokenizeLine(tokenList, currentLine);
tokenList.add(Token.EOL);
}
return tokenList;
} |
291242_3 | List<Token> tokenize() {
List<Token> tokenList = new ArrayList<Token>();
while (true) {
String currentLine;
try {
currentLine = lineReader.readLine();
} catch (IOException e) {
throw new MessageConveyorException("Failed to read input stream", e);
}
if (currentLine == null) {
break;
}
if(state != State.TRAILING_BACKSLASH) {
state = State.START;
}
tokenizeLine(tokenList, currentLine);
tokenList.add(Token.EOL);
}
return tokenList;
} |
291242_4 | void parseAndPopulate() {
E();
} |
291242_5 | void parseAndPopulate() {
E();
} |
291242_6 | void parseAndPopulate() {
E();
} |