--- /dev/null
+package org.apache.archiva.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Thrown, if conversion to a specific class is not possible.
+ */
+public class UnsupportedConversionException extends RepositoryException
+{
+ public UnsupportedConversionException( )
+ {
+ }
+
+ public UnsupportedConversionException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public UnsupportedConversionException( String message )
+ {
+ super( message );
+ }
+
+ public UnsupportedConversionException( Throwable cause )
+ {
+ super( cause );
+ }
+}
*
* @author Martin Stockhammer <martin_s@apache.org>
*/
-public interface Artifact extends Comparable<Artifact>
+public interface Artifact extends ContentItem
{
/**
* The namespace is the location of the artifact.
*/
StorageAsset getAsset();
- /**
- * Returns additional attributes of the artifact. Implementations may add additional attributes, e.g. author name
- * or creation date. Specific implementation attributes can be accessed either by the {@link #getAttributes()} method
- * or by a specific implementation class (see {@link #adapt(Class)}. Use via the adapter is type safe.
- *
- * @return a map of attribute key, value pairs
- */
- Map<String,String> getAttributes();
-
-
- /**
- * Returns the repository type specific implementation
- * @param clazz the specific implementation class
- * @param <T> the class or interface
- * @return the specific project implementation
- */
- <T extends Artifact> T adapt(Class<T> clazz) throws UnsupportedRepositoryTypeException;
-
- /**
- * Returns <code>true</code>, if this project supports the given adaptor class.
- * @param clazz the class to convert this project to
- * @param <T> the type
- * @return <code>true/code>, if the implementation is supported, otherwise false
- */
- <T extends Artifact> boolean supports(Class<T> clazz);
}
--- /dev/null
+package org.apache.archiva.repository.content;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.repository.UnsupportedConversionException;
+
+import java.util.Map;
+
+public interface ContentItem
+{
+ /**
+ * Returns the repository type specific implementation
+ * @param clazz the specific implementation class
+ * @param <T> the class or interface
+ * @return the specific project implementation
+ */
+ <T extends Project> T adapt( Class<T> clazz ) throws UnsupportedConversionException;
+
+ /**
+ * Returns <code>true</code>, if this project supports the given adaptor class.
+ * @param clazz the class to convert this project to
+ * @param <T> the type
+ * @return <code>true/code>, if the implementation is supported, otherwise false
+ */
+ <T extends Project> boolean supports( Class<T> clazz );
+
+ /**
+ * Additional attributes
+ * @return the additional attributes
+ */
+ Map<String, String> getAttributes( );
+
+ /**
+ * Returns the attribute value for the given key.
+ *
+ * @param key the attribute key
+ * @return the value, if the key exists, otherwise <code>null</code>
+ *
+ */
+ String getAttribute( String key );
+}
*/
import org.apache.archiva.repository.RepositoryContent;
+import org.apache.archiva.repository.UnsupportedConversionException;
import org.apache.archiva.repository.UnsupportedRepositoryTypeException;
import java.util.Map;
*
* @author Martin Stockhammer <martin_s@apache.org>
*/
-public interface Project extends Comparable<Project>
+public interface Project extends ContentItem
{
/**
*/
RepositoryContent getRepository();
- /**
- * Additional attributes
- * @return the additional attributes
- */
- Map<String, String> getAttributes();
-
- /**
- * Returns the repository type specific implementation
- * @param clazz the specific implementation class
- * @param <T> the class or interface
- * @return the specific project implementation
- */
- <T extends Project> T adapt(Class<T> clazz) throws UnsupportedRepositoryTypeException;
-
- /**
- * Returns <code>true</code>, if this project supports the given adaptor class.
- * @param clazz the class to convert this project to
- * @param <T> the type
- * @return <code>true/code>, if the implementation is supported, otherwise false
- */
- <T extends Project> boolean supports(Class<T> clazz);
}
*
* @author Martin Stockhammer <martin_s@apache.org>
*/
-public interface Version extends Comparable<Version>
+public interface Version extends ContentItem
{
/**
* Returns the version string.
*/
Project getProject();
- /**
- * Returns additional attributes.
- * @return the map of attribute key, value pairs
- */
- Map<String,String> getAttributes();
-
- /**
- * Returns the repository type specific implementation
- * @param clazz the specific implementation class
- * @param <T> the class or interface
- * @return the specific project implementation
- */
- <T extends Project> T adapt(Class<T> clazz) throws UnsupportedRepositoryTypeException;
-
- /**
- * Returns <code>true</code>, if this project supports the given adaptor class.
- * @param clazz the class to convert this project to
- * @param <T> the type
- * @return <code>true/code>, if the implementation is supported, otherwise false
- */
- <T extends Project> boolean supports(Class<T> clazz);
}
--- /dev/null
+package org.apache.archiva.repository.content.base;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.repository.UnsupportedConversionException;
+import org.apache.archiva.repository.content.ContentItem;
+import org.apache.archiva.repository.content.Project;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Abstract implementation of ContentItem interface.
+ *
+ * The attribute map is created, when the first values are put to the map.
+ *
+ */
+public abstract class ArchivaContentItem implements ContentItem
+{
+
+ private Map<String, String> attributes;
+
+ @Override
+ public abstract <T extends Project> T adapt( Class<T> clazz ) throws UnsupportedConversionException;
+
+ @Override
+ public abstract <T extends Project> boolean supports( Class<T> clazz );
+
+
+ /**
+ * Does lazy initialization of the attributes map.
+ * Returns a unmodifiable map.
+ *
+ * @return unmodifiable map of attributes
+ */
+ @Override
+ public Map<String, String> getAttributes( )
+ {
+ if (this.attributes==null) {
+ return Collections.emptyMap( );
+ } else
+ {
+ return Collections.unmodifiableMap( this.attributes );
+ }
+ }
+
+ /**
+ * Adds a attribute value. The key must not be <code>null</code>.
+ *
+ * @param key the attribute key
+ * @param value the attribute value
+ * @throws IllegalArgumentException if the key is <code>null</code> or empty
+ */
+ public void putAttribute(String key, String value) throws IllegalArgumentException {
+ if (this.attributes==null) {
+ this.attributes = new HashMap<>( );
+ }
+ if ( StringUtils.isEmpty( key ) ) {
+ throw new IllegalArgumentException( "Key value must not be empty or null" );
+ }
+ this.attributes.put( key, value );
+ }
+
+ @Override
+ public String getAttribute( String key )
+ {
+ if (this.attributes==null) {
+ return null;
+ } else
+ {
+ return this.attributes.get( key );
+ }
+ }
+}
--- /dev/null
+package org.apache.archiva.repository.content.base;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.repository.RepositoryContent;
+import org.apache.archiva.repository.UnsupportedConversionException;
+import org.apache.archiva.repository.content.Project;
+
+import java.util.Map;
+
+/**
+ * Immutable class, that represents a project.
+ */
+public class ArchivaProject extends ArchivaContentItem implements Project
+{
+ String namespace;
+ String id;
+ RepositoryContent repositoryContent;
+ Map<String, String> attributes;
+
+
+ @Override
+ public String getNamespace( )
+ {
+ return null;
+ }
+
+ @Override
+ public String getId( )
+ {
+ return null;
+ }
+
+ @Override
+ public RepositoryContent getRepository( )
+ {
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getAttributes( )
+ {
+ return null;
+ }
+
+ @Override
+ public <T extends Project> T adapt( Class<T> clazz ) throws UnsupportedConversionException
+ {
+ if (clazz != ArchivaProject.class) {
+ throw new UnsupportedConversionException( "Cannot convert to class: " + clazz );
+ } else {
+ return (T) this;
+ }
+ }
+
+ @Override
+ public <T extends Project> boolean supports( Class<T> clazz )
+ {
+ return false;
+ }
+}