Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Extract isWritable/isReadable checks from the abstract provider (#97)
Browse files Browse the repository at this point in the history
* Extract isWritable/isReadable checks from the abstract provider
* added a single resource check to the Object provider; fixes #96
* no longer needed to list all names in the copyright header
  (https://bugs.eclipse.org/bugs/show_bug.cgi?id=435933)

Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
  • Loading branch information
berezovskyi committed Jun 10, 2019
1 parent 45f543e commit c65e91f
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 388 deletions.
@@ -1,5 +1,5 @@
/*!*****************************************************************************
* Copyright (c) 2012 - 2018 IBM Corporation and others.
/*
* Copyright (c) 2012-2019 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -8,15 +8,7 @@
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
*
* Russell Boykin - initial API and implementation
* Alberto Giammaria - initial API and implementation
* Chris Peters - initial API and implementation
* Gianluca Bernardini - initial API and implementation
* Andrew Berezovskyi - JSON-LD support
*******************************************************************************/
*/
package org.eclipse.lyo.oslc4j.provider.jena;

import java.io.InputStream;
Expand All @@ -43,8 +35,6 @@
import org.apache.jena.util.FileUtils;
import org.eclipse.lyo.oslc4j.core.OSLC4JConstants;
import org.eclipse.lyo.oslc4j.core.OSLC4JUtils;
import org.eclipse.lyo.oslc4j.core.annotation.OslcNotQueryResult;
import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape;
import org.eclipse.lyo.oslc4j.core.exception.MessageExtractor;
import org.eclipse.lyo.oslc4j.core.model.Error;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
Expand All @@ -55,6 +45,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author Russell Boykin, Alberto Giammaria, Chris Peters, Gianluca Bernardini, Andrew Berezovskyi
*/
public abstract class AbstractOslcRdfXmlProvider
{
private static final Logger log = LoggerFactory.getLogger(AbstractOslcRdfXmlProvider.class.getName
Expand Down Expand Up @@ -92,14 +85,6 @@ protected AbstractOslcRdfXmlProvider()
super();
}

protected static boolean isWriteable(final Class<?> type,
final Annotation[] annotations,
final MediaType actualMediaType,
final MediaType ... requiredMediaTypes)
{
return true;
}

protected void writeTo(final Object[] objects,
final MediaType baseMediaType,
final MultivaluedMap<String, Object> map,
Expand Down Expand Up @@ -214,7 +199,7 @@ protected void writeTo(final boolean queryResult,

final String queryString = httpServletRequest.getQueryString();
if ((queryString != null) &&
(isOslcQuery(queryString)))
(ProviderHelper.isOslcQuery(queryString)))
{
responseInfoURI += "?" + queryString;
}
Expand Down Expand Up @@ -295,32 +280,6 @@ private String getSerializationLanguage(final MediaType baseMediaType) {
throw new IllegalArgumentException("Base media type can't be matched to any writer");
}

protected static boolean isReadable(final Class<?> type,
final MediaType actualMediaType,
final MediaType ... requiredMediaTypes)
{
if (type.getAnnotation(OslcResourceShape.class) != null)
{
return isCompatible(actualMediaType, requiredMediaTypes);
}

return false;
}

protected static boolean isCompatible(final MediaType actualMediaType,
final MediaType... requiredMediaTypes)
{
for (final MediaType requiredMediaType : requiredMediaTypes)
{
if (requiredMediaType.isCompatible(actualMediaType))
{
return true;
}
}

return false;
}

protected Object[] readFrom(final Class<?> type,
final MediaType mediaType,
final MultivaluedMap<String, String> map,
Expand Down Expand Up @@ -471,17 +430,4 @@ private boolean isAcceptableMediaType(final MediaType mediaType)
ANNOTATIONS_EMPTY_ARRAY,
mediaType) != null);
}

protected static boolean isOslcQuery(final String parmString)
{
boolean containsOslcParm = false;

final String [] uriParts = parmString.toLowerCase().split("oslc\\.",2);
if (uriParts.length > 1)
{
containsOslcParm = true;
}

return containsOslcParm;
}
}

This file was deleted.

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 IBM Corporation.
/*
* Copyright (c) 2012-2019 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -8,14 +8,7 @@
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
*
* Russell Boykin - initial API and implementation
* Alberto Giammaria - initial API and implementation
* Chris Peters - initial API and implementation
* Gianluca Bernardini - initial API and implementation
*******************************************************************************/
*/
package org.eclipse.lyo.oslc4j.provider.jena;

import java.io.IOException;
Expand All @@ -36,6 +29,9 @@
import org.eclipse.lyo.oslc4j.core.model.Compact;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;

/**
* @author Russell Boykin, Alberto Giammaria, Chris Peters, Gianluca Bernardini
*/
@Provider
@Produces(OslcMediaType.APPLICATION_X_OSLC_COMPACT_XML)
@Consumes(OslcMediaType.APPLICATION_X_OSLC_COMPACT_XML)
Expand All @@ -50,26 +46,15 @@ public OslcCompactRdfProvider()
}

@Override
public long getSize(final Compact compact,
final Class<?> type,
final Type genericType,
final Annotation[] annotation,
final MediaType mediaType)
{
return -1;
public boolean isWriteable(final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType) {
return ProviderHelper.isCompactResource(type);
}

@Override
public boolean isWriteable(final Class<?> type,
final Type genericType,
final Annotation[] annotations,
final MediaType mediaType)
{
return (Compact.class.isAssignableFrom(type)) &&
(isWriteable(type,
annotations,
mediaType,
OslcMediaType.APPLICATION_X_OSLC_COMPACT_XML_TYPE));
public boolean isReadable(final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType) {
return ProviderHelper.isCompactResource(type);
}

@Override
Expand All @@ -90,17 +75,7 @@ public void writeTo(final Compact compact,
outputStream);
}

@Override
public boolean isReadable(final Class<?> type,
final Type genericType,
final Annotation[] annotations,
final MediaType mediaType)
{
return (Compact.class.isAssignableFrom(type)) &&
(isReadable(type,
mediaType,
OslcMediaType.APPLICATION_X_OSLC_COMPACT_XML_TYPE));
}


@Override
public Compact readFrom(final Class<Compact> type,
Expand Down Expand Up @@ -130,4 +105,10 @@ public Compact readFrom(final Class<Compact> type,

return null;
}
}

@Override
public long getSize(final Compact compact, final Class<?> type, final Type genericType,
final Annotation[] annotation, final MediaType mediaType) {
return ProviderHelper.CANNOT_BE_DETERMINED_IN_ADVANCE;
}
}
@@ -1,4 +1,4 @@
/*******************************************************************************
/*
* Copyright (c) 2018 Andrew Berezovskyi.
*
* All rights reserved. This program and the accompanying materials
Expand All @@ -8,11 +8,7 @@
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
*
* Andrew Berezovskyi - initial implementation
*******************************************************************************/
*/
package org.eclipse.lyo.oslc4j.provider.jena;

import javax.ws.rs.Consumes;
Expand All @@ -21,10 +17,7 @@
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;

/**
* Created on 2018-03-03
*
* @author Andrew Berezovskyi (andriib@kth.se)
* @version $version-stub$
* @author Andrew Berezovskyi
* @since 2.4.0
*/
@Provider
Expand Down
@@ -1,4 +1,4 @@
/*******************************************************************************
/*
* Copyright (c) 2018 Andrew Berezovskyi.
*
* All rights reserved. This program and the accompanying materials
Expand All @@ -8,11 +8,7 @@
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
*
* Andrew Berezovskyi - initial implementation
*******************************************************************************/
*/
package org.eclipse.lyo.oslc4j.provider.jena;

import javax.ws.rs.Consumes;
Expand All @@ -21,10 +17,7 @@
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;

/**
* Created on 2018-03-03
*
* @author Andrew Berezovskyi (andriib@kth.se)
* @version $version-stub$
* @author Andrew Berezovskyi
* @since 2.4.0
*/
@Provider
Expand Down
@@ -1,4 +1,4 @@
/*******************************************************************************
/*
* Copyright (c) 2018 Andrew Berezovskyi.
*
* All rights reserved. This program and the accompanying materials
Expand All @@ -8,11 +8,7 @@
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
*
* Andrew Berezovskyi - initial implementation
*******************************************************************************/
*/
package org.eclipse.lyo.oslc4j.provider.jena;

import javax.ws.rs.Consumes;
Expand All @@ -21,10 +17,7 @@
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;

/**
* Created on 2018-03-03
*
* @author Andrew Berezovskyi (andriib@kth.se)
* @version $version-stub$
* @author Andrew Berezovskyi
* @since 2.4.0
*/
@Provider
Expand Down

0 comments on commit c65e91f

Please sign in to comment.