diff --git a/pax-swissbox-converter/pom.xml b/pax-swissbox-converter/pom.xml deleted file mode 100644 index 01433cf..0000000 --- a/pax-swissbox-converter/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - 4.0.0 - - - org.ops4j.pax - swissbox - 1.8.6-SNAPSHOT - - - org.ops4j.pax.swissbox - pax-swissbox-converter - bundle - - OPS4J Pax Swissbox :: Converter - - OPS4J Pax Swissbox - Utilities related to converting types. - - - - org.ops4j.pax.swissbox.converter - org.ops4j.pax.swissbox.converter - - - - - - org.apache.felix - maven-bundle-plugin - - - - - - - com.google.code.findbugs - annotations - 3.0.1 - provided - - - com.google.code.findbugs - - jsr305 - - - net.jcip - - jcip-annotations - - - - - - - junit - junit - - - - diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/BlueprintConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/BlueprintConverter.java deleted file mode 100644 index e674dcd..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/BlueprintConverter.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter; - -import org.osgi.service.blueprint.container.Converter; -import static org.ops4j.pax.swissbox.converter.JavaLangConverter.*; -import static org.ops4j.pax.swissbox.converter.JavaUtilConverter.*; -import org.ops4j.pax.swissbox.converter.helpers.ImmutableCompositeConverter; -import static org.ops4j.pax.swissbox.converter.helpers.ImmutableCompositeConverter.*; -import org.ops4j.pax.swissbox.converter.helpers.WrapperConverter; -import org.ops4j.pax.swissbox.converter.loader.Loader; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class BlueprintConverter - extends WrapperConverter - implements Converter -{ - - public static final BlueprintConverter INSTANCE = new BlueprintConverter(); - - public BlueprintConverter() - { - delegate( - immutableCompositeConverter( - javaLangConverter(), - javaUtilConverter( this ) - ) - ); - } - - public BlueprintConverter( final Converter escape ) - { - final ImmutableCompositeConverter includingThisEscape = immutableCompositeConverter( escape, this ); - - delegate( - immutableCompositeConverter( - javaLangConverter(), - javaUtilConverter( includingThisEscape ) - ) - ); - } - - public BlueprintConverter( final Loader loader ) - { - delegate( - immutableCompositeConverter( - javaLangConverter( loader ), - javaUtilConverter( this ) - ) - ); - } - - public BlueprintConverter( final Converter escape, - final Loader loader ) - { - final ImmutableCompositeConverter includingThisEscape = immutableCompositeConverter( escape, this ); - - delegate( - immutableCompositeConverter( - javaLangConverter( loader ), - javaUtilConverter( includingThisEscape ) - ) - ); - } - - public static BlueprintConverter blueprintConverter() - { - return INSTANCE; - } - - public static BlueprintConverter blueprintConverter( final Converter escape ) - { - return new BlueprintConverter( escape ); - } - - public static BlueprintConverter blueprintConverter( final Loader loader ) - { - return new BlueprintConverter( loader ); - } - - public static BlueprintConverter blueprintConverter( final Converter escape, - final Loader loader ) - { - return new BlueprintConverter( escape, loader ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/GenericType.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/GenericType.java deleted file mode 100644 index ea4b6b5..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/GenericType.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter; - -import java.lang.reflect.Array; -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.lang.reflect.WildcardType; -import java.util.Arrays; -import org.osgi.service.blueprint.container.ReifiedType; -import org.ops4j.pax.swissbox.converter.internal.Primitives; -import org.ops4j.pax.swissbox.converter.loader.Loader; - -/** - * Generic Type. - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class GenericType extends ReifiedType -{ - - private static final GenericType[] EMPTY = new GenericType[0]; - - private final GenericType[] parameters; - - public GenericType( final Type type ) - { - this( getConcreteClass( type ), parametersOf( type ) ); - } - - public GenericType( final Class clazz, - final GenericType... parameters ) - { - super( clazz ); - - this.parameters = parameters; - } - - @Override - public ReifiedType getActualTypeArgument( final int index ) - { - if( parameters.length == 0 ) - { - return super.getActualTypeArgument( index ); - } - return parameters[ index ]; - } - - @Override - public int size() - { - return parameters.length; - } - - @Override - public String toString() - { - final Class clazz = getRawClass(); - - if( clazz.isArray() ) - { - if( parameters.length > 0 ) - { - return parameters[ 0 ].toString() + "[]"; - } - else - { - return clazz.getComponentType().getName() + "[]"; - } - } - - if( parameters.length > 0 ) - { - final StringBuilder sb = new StringBuilder(); - sb.append( clazz.getName() ); - sb.append( "<" ); - for( int i = 0; i < parameters.length; i++ ) - { - if( i > 0 ) - { - sb.append( "," ); - } - sb.append( parameters[ i ].toString() ); - } - sb.append( ">" ); - return sb.toString(); - } - - return clazz.getName(); - } - - public static GenericType parse( final String type, - final Loader loader ) - throws ClassNotFoundException, IllegalArgumentException - { - assert type != null : "Type must be specified (cannot be null)"; - assert loader != null : "Loader must be specified (cannot be null)"; - - final String localType = type.trim(); - - // Check if this is an array - if( localType.endsWith( "[]" ) ) - { - final GenericType parsedType = parse( localType.substring( 0, localType.length() - 2 ), loader ); - return new GenericType( Array.newInstance( parsedType.getRawClass(), 0 ).getClass(), parsedType ); - } - - // Check if this is a generic - int genericIndex = localType.indexOf( '<' ); - if( genericIndex > 0 ) - { - if( !localType.endsWith( ">" ) ) - { - throw new IllegalArgumentException( "Can not load type: " + localType ); - } - - final GenericType baseType = parse( localType.substring( 0, genericIndex ), loader ); - - final String[] params = localType.substring( genericIndex + 1, localType.length() - 1 ).split( "," ); - - GenericType[] types = new GenericType[params.length]; - for( int i = 0; i < params.length; i++ ) - { - types[ i ] = parse( params[ i ], loader ); - } - return new GenericType( baseType.getRawClass(), types ); - } - - // Primitive - if( Primitives.isPrimitive( localType ) ) - { - return new GenericType( Primitives.primitive( localType ) ); - } - - return new GenericType( loader.loadClass( localType ) ); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + Arrays.hashCode(parameters); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof GenericType)) { - return false; - } - GenericType other = (GenericType) obj; - if (!Arrays.equals(parameters, other.parameters)) { - return false; - } - return true; - } - - private static GenericType[] parametersOf( final Type type ) - { - if( type instanceof Class ) - { - Class clazz = (Class) type; - if( clazz.isArray() ) - { - GenericType t = new GenericType( clazz.getComponentType() ); - if( t.size() > 0 ) - { - return new GenericType[]{ t }; - } - else - { - return EMPTY; - } - } - else - { - return EMPTY; - } - } - - if( type instanceof ParameterizedType ) - { - ParameterizedType pt = (ParameterizedType) type; - Type[] parameters = pt.getActualTypeArguments(); - GenericType[] gts = new GenericType[parameters.length]; - for( int i = 0; i < gts.length; i++ ) - { - gts[ i ] = new GenericType( parameters[ i ] ); - } - return gts; - } - - if( type instanceof GenericArrayType ) - { - return new GenericType[]{ new GenericType( ( (GenericArrayType) type ).getGenericComponentType() ) }; - } - - if( type instanceof WildcardType ) - { - return EMPTY; - } - - if( type instanceof TypeVariable ) - { - return EMPTY; - } - - throw new RuntimeException( "Unknown type " + type ); - } - - private static Class getConcreteClass( final Type type ) - { - final Type collapsed = collapse( type ); - - if( collapsed instanceof Class ) - { - return (Class) collapsed; - } - - if( collapsed instanceof ParameterizedType ) - { - return getConcreteClass( collapse( ( (ParameterizedType) collapsed ).getRawType() ) ); - } - - throw new RuntimeException( "Unknown type " + type ); - } - - private static Type collapse( final Type type ) - { - if( type instanceof Class || type instanceof ParameterizedType ) - { - return type; - } - else if( type instanceof TypeVariable ) - { - return collapse( ( (TypeVariable) type ).getBounds()[ 0 ] ); - } - else if( type instanceof GenericArrayType ) - { - Type arrayType = collapse( ( (GenericArrayType) type ).getGenericComponentType() ); - while( arrayType instanceof ParameterizedType ) - { - arrayType = collapse( ( (ParameterizedType) arrayType ).getRawType() ); - } - return Array.newInstance( (Class) arrayType, 0 ).getClass(); - } - else if( type instanceof WildcardType ) - { - WildcardType wildcardType = (WildcardType) type; - if( wildcardType.getLowerBounds().length == 0 ) - { - return collapse( wildcardType.getUpperBounds()[ 0 ] ); - } - else - { - return collapse( wildcardType.getLowerBounds()[ 0 ] ); - } - } - - throw new RuntimeException( "Unknown type " + type ); - } - - public static GenericType genericType( final Type type ) - { - return new GenericType( type ); - } - - public static GenericType genericType( final Class clazz, - final GenericType... parameters ) - { - return new GenericType( clazz, parameters ); - } - -} diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaConverter.java deleted file mode 100644 index 291ecbd..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaConverter.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter; - -import org.osgi.service.blueprint.container.Converter; -import static org.ops4j.pax.swissbox.converter.JavaIOConverter.*; -import static org.ops4j.pax.swissbox.converter.JavaLangConverter.*; -import static org.ops4j.pax.swissbox.converter.JavaUtilConverter.*; -import org.ops4j.pax.swissbox.converter.helpers.ImmutableCompositeConverter; -import static org.ops4j.pax.swissbox.converter.helpers.ImmutableCompositeConverter.*; -import org.ops4j.pax.swissbox.converter.helpers.WrapperConverter; -import org.ops4j.pax.swissbox.converter.loader.Loader; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class JavaConverter - extends WrapperConverter - implements Converter -{ - - public static final JavaConverter INSTANCE = new JavaConverter(); - - public JavaConverter() - { - delegate( - immutableCompositeConverter( - javaLangConverter(), - javaUtilConverter( this ), - javaIOConverter( this ) - ) - ); - } - - public JavaConverter( final Converter escape ) - { - final ImmutableCompositeConverter includingThisEscape = immutableCompositeConverter( escape, this ); - - delegate( - immutableCompositeConverter( - javaLangConverter(), - javaUtilConverter( includingThisEscape ), - javaIOConverter( includingThisEscape ) - ) - ); - } - - public JavaConverter( final Loader loader ) - { - delegate( - immutableCompositeConverter( - javaLangConverter( loader ), - javaUtilConverter( this ), - javaIOConverter( this ) - ) - ); - } - - public JavaConverter( final Converter escape, - final Loader loader ) - { - final ImmutableCompositeConverter includingThisEscape = immutableCompositeConverter( escape, this ); - - delegate( - immutableCompositeConverter( - javaLangConverter( loader ), - javaUtilConverter( includingThisEscape ), - javaIOConverter( includingThisEscape ) - ) - ); - } - - public static JavaConverter javaConverter() - { - return INSTANCE; - } - - public static JavaConverter javaConverter( final Converter escape ) - { - return new JavaConverter( escape ); - } - - public static JavaConverter javaConverter( final Loader loader ) - { - return new JavaConverter( loader ); - } - - public static JavaConverter javaConverter( final Converter escape, - final Loader loader ) - { - return new JavaConverter( escape, loader ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaIOConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaIOConverter.java deleted file mode 100644 index 80d2a54..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaIOConverter.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter; - -import org.osgi.service.blueprint.container.Converter; -import static org.ops4j.pax.swissbox.converter.helpers.ImmutableCompositeConverter.*; -import org.ops4j.pax.swissbox.converter.helpers.WrapperConverter; -import static org.ops4j.pax.swissbox.converter.java.io.ToInputStreamConverter.*; -import static org.ops4j.pax.swissbox.converter.java.io.ToOutputStreamConverter.*; -import org.ops4j.pax.swissbox.converter.java.io.ToPrintStreamConverter; -import static org.ops4j.pax.swissbox.converter.java.io.ToPrintStreamConverter.*; -import static org.ops4j.pax.swissbox.converter.java.io.ToReaderConverter.*; -import static org.ops4j.pax.swissbox.converter.java.io.ToURIConverter.*; -import static org.ops4j.pax.swissbox.converter.java.io.ToURLConverter.*; -import static org.ops4j.pax.swissbox.converter.java.io.ToWriterConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class JavaIOConverter - extends WrapperConverter - implements Converter -{ - - public static final JavaIOConverter INSTANCE = new JavaIOConverter(); - - public JavaIOConverter() - { - delegate( - immutableCompositeConverter( - toURLConverter(), - toURIConverter(), - toInputStreamConverter(), - toOutputStreamConverter(), - toReaderConverter(), - toWriterConverter(), - toPrintStreamConverter() - ) - ); - } - - public JavaIOConverter( final Converter escape ) - { - delegate( - immutableCompositeConverter( - toURLConverter( escape ), - toURIConverter( escape ), - toInputStreamConverter( escape ), - toOutputStreamConverter( escape ), - toReaderConverter( escape ), - toWriterConverter( escape ), - toPrintStreamConverter( escape ) - ) - ); - } - - public static JavaIOConverter javaIOConverter() - { - return INSTANCE; - } - - public static JavaIOConverter javaIOConverter( final Converter escape ) - { - return new JavaIOConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaLangConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaLangConverter.java deleted file mode 100644 index af7d9f1..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaLangConverter.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter; - -import org.osgi.service.blueprint.container.Converter; -import static org.ops4j.pax.swissbox.converter.helpers.ImmutableCompositeConverter.*; -import org.ops4j.pax.swissbox.converter.helpers.WrapperConverter; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromStringConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromStringToClassConverter.*; -import org.ops4j.pax.swissbox.converter.java.lang.ToCharSequenceConverter; -import static org.ops4j.pax.swissbox.converter.java.lang.ToCharSequenceConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.ToNumberConverter.*; -import org.ops4j.pax.swissbox.converter.java.lang.ToStringConverter; -import static org.ops4j.pax.swissbox.converter.java.lang.ToStringConverter.*; -import org.ops4j.pax.swissbox.converter.loader.Loader; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class JavaLangConverter - extends WrapperConverter - implements Converter -{ - - public static final JavaLangConverter INSTANCE = new JavaLangConverter(); - - public JavaLangConverter() - { - delegate( - immutableCompositeConverter( - fromNullConverter(), - assignableConverter(), - toNumberConverter(), - fromStringConverter(), - toStringConverter(), - toCharSequenceConverter() - ) - ); - } - - public JavaLangConverter( final Loader loader ) - { - delegate( - immutableCompositeConverter( - fromNullConverter(), - assignableConverter(), - toNumberConverter(), - fromStringConverter(), - fromStringToClassConverter( loader ), - toStringConverter(), - toCharSequenceConverter() - ) - ); - } - - public static JavaLangConverter javaLangConverter() - { - return INSTANCE; - } - - public static JavaLangConverter javaLangConverter( final Loader loader ) - { - return new JavaLangConverter( loader ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaUtilConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaUtilConverter.java deleted file mode 100644 index a5cc133..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/JavaUtilConverter.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter; - -import org.osgi.service.blueprint.container.Converter; -import org.ops4j.pax.swissbox.converter.helpers.ImmutableCompositeConverter; -import static org.ops4j.pax.swissbox.converter.helpers.ImmutableCompositeConverter.*; -import org.ops4j.pax.swissbox.converter.helpers.WrapperConverter; -import static org.ops4j.pax.swissbox.converter.java.util.ToArrayConverter.*; -import static org.ops4j.pax.swissbox.converter.java.util.ToCollectionConverter.*; -import static org.ops4j.pax.swissbox.converter.java.util.ToDictionaryConverter.*; -import static org.ops4j.pax.swissbox.converter.java.util.ToMapConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class JavaUtilConverter - extends WrapperConverter - implements Converter -{ - - public static final JavaUtilConverter INSTANCE = new JavaUtilConverter(); - - public JavaUtilConverter() - { - delegate( - immutableCompositeConverter( - toArrayConverter( this ), - toCollectionConverter( this ), - toDictionaryConverter( this ), - toMapConverter( this ) - ) - ); - } - - public JavaUtilConverter( final Converter escape ) - { - final ImmutableCompositeConverter includingThisEscape = immutableCompositeConverter( escape, this ); - - delegate( - immutableCompositeConverter( - toArrayConverter( includingThisEscape ), - toCollectionConverter( includingThisEscape ), - toDictionaryConverter( includingThisEscape ), - toMapConverter( includingThisEscape ) - ) - ); - } - - public static JavaUtilConverter javaUtilConverter() - { - return INSTANCE; - } - - public static JavaUtilConverter javaUtilConverter( final Converter escape ) - { - return new JavaUtilConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/CompositeConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/CompositeConverter.java deleted file mode 100644 index 2d9dd1d..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/CompositeConverter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.helpers; - -import java.util.Collection; -import org.osgi.service.blueprint.container.Converter; -import org.ops4j.pax.swissbox.converter.internal.AbstractCompositeConverter; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class CompositeConverter - extends AbstractCompositeConverter - implements Converter -{ - - public CompositeConverter( final Converter... converters ) - { - super( converters ); - } - - public CompositeConverter( final Collection converters ) - { - super( converters ); - } - - public CompositeConverter add( final Converter converter ) - { - assert converter != null : "Converter must be specified (cannot be null)"; - - converters.add( converter ); - - return this; - } - - public CompositeConverter remove( final Converter converter ) - { - assert converter != null : "Converter must be specified (cannot be null)"; - - converters.remove( converter ); - - return this; - } - - public static CompositeConverter compositeConverter( final Converter... converters ) - { - return new CompositeConverter( converters ); - } - - public static CompositeConverter compositeConverter( final Collection converters ) - { - return new CompositeConverter( converters ); - } - -} diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/EmptyConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/EmptyConverter.java deleted file mode 100644 index b13616a..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/EmptyConverter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.helpers; - -import static java.lang.String.*; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class EmptyConverter - implements Converter -{ - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return false; - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - throw new Exception( format( "Unable to convert from %s to %s", sourceObject, targetType ) ); - } - - public static EmptyConverter noConversionConverter() - { - return new EmptyConverter(); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/ImmutableCompositeConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/ImmutableCompositeConverter.java deleted file mode 100644 index 499740d..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/ImmutableCompositeConverter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.helpers; - -import java.util.Collection; -import org.osgi.service.blueprint.container.Converter; -import org.ops4j.pax.swissbox.converter.internal.AbstractCompositeConverter; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class ImmutableCompositeConverter - extends AbstractCompositeConverter - implements Converter -{ - - public ImmutableCompositeConverter( final Converter... converters ) - { - super( converters ); - } - - public ImmutableCompositeConverter( final Collection converters ) - { - super( converters ); - } - - public static ImmutableCompositeConverter immutableCompositeConverter( final Converter... converters ) - { - return new ImmutableCompositeConverter( converters ); - } - - public static ImmutableCompositeConverter immutableCompositeConverter( final Collection converters ) - { - return new ImmutableCompositeConverter( converters ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/WrapperConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/WrapperConverter.java deleted file mode 100644 index 1406ef9..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/helpers/WrapperConverter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.helpers; - -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.helpers.EmptyConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class WrapperConverter - implements Converter -{ - - private Converter converter; - - public WrapperConverter() - { - converter = noConversionConverter(); - } - - public WrapperConverter( final Converter converter ) - { - assert converter != null : "Converter must be specified (cannot be null)"; - - this.converter = converter; - } - - protected WrapperConverter delegate( final Converter converter ) - { - assert converter != null : "Converter must be specified (cannot be null)"; - - this.converter = converter; - - return this; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return converter.canConvert( sourceObject, targetType ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - return converter.convert( sourceObject, targetType ); - } - - public static WrapperConverter wrapperConverter( final Converter converter ) - { - return new WrapperConverter( converter ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/AbstractCompositeConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/AbstractCompositeConverter.java deleted file mode 100644 index b69e4ad..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/AbstractCompositeConverter.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.internal; - -import static java.lang.String.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class AbstractCompositeConverter - implements Converter -{ - - protected Collection converters; - - public AbstractCompositeConverter( final Converter... converters ) - { - this( converters == null ? null : Arrays.asList( converters ) ); - } - - public AbstractCompositeConverter( final Collection converters ) - { - this.converters = new ArrayList(); - if( converters != null && !converters.isEmpty() ) - { - for( Converter converter : converters ) - { - assert converter != null : "Converters cannot contain null converters"; - } - this.converters.addAll( converters ); - } - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - for( Converter converter : converters ) - { - if( converter.canConvert( sourceObject, targetType ) ) - { - return true; - } - } - - return false; - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - for( Converter converter : converters ) - { - try - { - if( converter.canConvert( sourceObject, targetType ) ) - { - return converter.convert( sourceObject, targetType ); - } - } - catch( Exception e ) - { - // try with next converter - } - } - - throw new Exception( format( "Unable to convert from %s to %s", sourceObject, targetType ) ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/Primitives.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/Primitives.java deleted file mode 100644 index 11875a2..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/Primitives.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.internal; - -import java.util.HashMap; -import java.util.Map; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class Primitives -{ - - private static final Map PRIMITIVES = new HashMap(); - - static - { - PRIMITIVES.put( "int", int.class ); - PRIMITIVES.put( "integer", int.class ); - PRIMITIVES.put( "short", short.class ); - PRIMITIVES.put( "long", long.class ); - PRIMITIVES.put( "byte", byte.class ); - PRIMITIVES.put( "char", char.class ); - PRIMITIVES.put( "character", char.class ); - PRIMITIVES.put( "float", float.class ); - PRIMITIVES.put( "double", double.class ); - PRIMITIVES.put( "boolean", boolean.class ); - } - - private static final Map PRIMITIVES_WRAPPERS = new HashMap(); - - static - { - PRIMITIVES_WRAPPERS.put( byte.class, Byte.class ); - PRIMITIVES_WRAPPERS.put( short.class, Short.class ); - PRIMITIVES_WRAPPERS.put( char.class, Character.class ); - PRIMITIVES_WRAPPERS.put( int.class, Integer.class ); - PRIMITIVES_WRAPPERS.put( long.class, Long.class ); - PRIMITIVES_WRAPPERS.put( float.class, Float.class ); - PRIMITIVES_WRAPPERS.put( double.class, Double.class ); - PRIMITIVES_WRAPPERS.put( boolean.class, Boolean.class ); - } - - private Primitives() - { - // utility class - } - - public static Class unwrap( final Class clazz ) - { - final Class unwrapped = PRIMITIVES_WRAPPERS.get( clazz ); - return unwrapped != null ? unwrapped : clazz; - } - - public static boolean isPrimitive( final String clazz ) - { - return PRIMITIVES.containsKey( clazz == null ? null : clazz.trim() ); - } - - public static Class primitive( final String clazz ) - { - return PRIMITIVES.get( clazz == null ? null : clazz.trim() ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/Reflection.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/Reflection.java deleted file mode 100644 index 32acfc3..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/Reflection.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.internal; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class Reflection -{ - - public static boolean hasDefaultConstructor( final Class type ) - { - if( !Modifier.isPublic( type.getModifiers() ) ) - { - return false; - } - if( Modifier.isAbstract( type.getModifiers() ) ) - { - return false; - } - Constructor[] constructors = type.getConstructors(); - for( Constructor constructor : constructors ) - { - if( Modifier.isPublic( constructor.getModifiers() ) && - constructor.getParameterTypes().length == 0 ) - { - return true; - } - } - return false; - } - - public static T newInstance( final Class clazz ) - throws Exception - { - return newInstance( null, clazz ); - } - - public static T newInstance( final AccessControlContext acc, - final Class clazz ) - throws Exception - { - if( acc == null ) - { - return clazz.newInstance(); - } - else - { - try - { - return AccessController.doPrivileged( - new PrivilegedExceptionAction() - { - public T run() - throws Exception - { - return clazz.newInstance(); - } - }, - acc - ); - } - catch( PrivilegedActionException e ) - { - throw e.getException(); - } - } - } - -} diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToInputStreamConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToInputStreamConverter.java deleted file mode 100644 index a9b9a55..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToInputStreamConverter.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.io; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToInputStreamConverter - implements Converter -{ - - public static final ToInputStreamConverter INSTANCE = new ToInputStreamConverter(); - - private final Converter escape; - - public ToInputStreamConverter() - { - this.escape = null; - } - - public ToInputStreamConverter( final Converter escape ) - { - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( InputStream.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ) - && ( sourceObject instanceof URL - || sourceObject instanceof URI - || sourceObject instanceof File - || sourceObject instanceof CharSequence - || ( escape != null - && ( escape.canConvert( sourceObject, new ReifiedType( URL.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( URI.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToInputStreamConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToInputStream( sourceObject, targetType ); - } - - public InputStream convertToInputStream( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( sourceObject instanceof URL ) - { - return ( (URL) sourceObject ).openStream(); - } - - if( sourceObject instanceof URI ) - { - return ( (URI) sourceObject ).toURL().openStream(); - } - - if( sourceObject instanceof File ) - { - return new FileInputStream( (File) sourceObject ); - } - - if( sourceObject instanceof CharSequence ) - { - try - { - return new URL( sourceObject.toString() ).openStream(); - } - catch( MalformedURLException e ) - { - return new FileInputStream( sourceObject.toString() ); - } - } - - if( escape != null ) - { - if( escape.canConvert( sourceObject, new ReifiedType( URL.class ) ) ) - { - try - { - return ( (URL) escape.convert( sourceObject, new ReifiedType( URL.class ) ) ).openStream(); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( URI.class ) ) ) - { - try - { - return ( (URI) escape.convert( sourceObject, new ReifiedType( URI.class ) ) ).toURL().openStream(); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) - { - try - { - return new FileInputStream( (File) escape.convert( sourceObject, new ReifiedType( File.class ) ) ); - } - catch( Exception ignore ) - { - // ignore - } - } - } - - throw new Exception( String.format( "Unable to convert number %s to %s", sourceObject, targetType ) ); - } - - public static ToInputStreamConverter toInputStreamConverter() - { - return INSTANCE; - } - - public static ToInputStreamConverter toInputStreamConverter( final Converter escape ) - { - return new ToInputStreamConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToOutputStreamConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToOutputStreamConverter.java deleted file mode 100644 index 56f5899..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToOutputStreamConverter.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.io; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToOutputStreamConverter - implements Converter -{ - - public static final ToOutputStreamConverter INSTANCE = new ToOutputStreamConverter(); - - private final Converter escape; - - public ToOutputStreamConverter() - { - this.escape = null; - } - - public ToOutputStreamConverter( final Converter escape ) - { - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( OutputStream.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ) - && ( sourceObject instanceof File - || sourceObject instanceof CharSequence - || ( escape != null - && escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToOutputStreamConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToOutputStream( sourceObject, targetType ); - } - - public OutputStream convertToOutputStream( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( sourceObject instanceof File ) - { - return new FileOutputStream( (File) sourceObject ); - } - - if( sourceObject instanceof CharSequence ) - { - return new FileOutputStream( sourceObject.toString() ); - } - - if( escape != null ) - { - if( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) - { - try - { - return new FileOutputStream( (File) escape.convert( sourceObject, new ReifiedType( File.class ) ) ); - } - catch( Exception ignore ) - { - // ignore - } - } - } - - throw new Exception( String.format( "Unable to convert number %s to %s", sourceObject, targetType ) ); - } - - public static ToOutputStreamConverter toOutputStreamConverter() - { - return INSTANCE; - } - - public static ToOutputStreamConverter toOutputStreamConverter( final Converter escape ) - { - return new ToOutputStreamConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToPrintStreamConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToPrintStreamConverter.java deleted file mode 100644 index 5319e8f..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToPrintStreamConverter.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.io; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToPrintStreamConverter - implements Converter -{ - - public static final ToPrintStreamConverter INSTANCE = new ToPrintStreamConverter(); - - private final Converter escape; - - public ToPrintStreamConverter() - { - this.escape = null; - } - - public ToPrintStreamConverter( final Converter escape ) - { - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( PrintStream.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ) - && ( sourceObject instanceof File - || sourceObject instanceof CharSequence - || sourceObject instanceof OutputStream - || ( escape != null - && ( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( OutputStream.class ) ) ) ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToPrintStreamConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToPrintStream( sourceObject, targetType ); - } - - public PrintStream convertToPrintStream( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( sourceObject instanceof File ) - { - return new PrintStream( new BufferedOutputStream( new FileOutputStream( (File) sourceObject ) ) ); - } - - if( sourceObject instanceof OutputStream ) - { - return new PrintStream( new BufferedOutputStream( (OutputStream) sourceObject ) ); - } - - if( sourceObject instanceof CharSequence ) - { - return new PrintStream( new BufferedOutputStream( new FileOutputStream( sourceObject.toString() ) ) ); - } - - if( escape != null ) - { - if( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) - { - try - { - return new PrintStream( - new BufferedOutputStream( - new FileOutputStream( (File) escape.convert( sourceObject, new ReifiedType( File.class ) ) ) - ) - ); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( OutputStream.class ) ) ) - { - try - { - return new PrintStream( - new BufferedOutputStream( - (OutputStream) escape.convert( sourceObject, new ReifiedType( OutputStream.class ) ) - ) - ); - } - catch( Exception ignore ) - { - // ignore - } - } - } - - throw new Exception( String.format( "Unable to convert number %s to %s", sourceObject, targetType ) ); - } - - public static ToPrintStreamConverter toPrintStreamConverter() - { - return INSTANCE; - } - - public static ToPrintStreamConverter toPrintStreamConverter( final Converter escape ) - { - return new ToPrintStreamConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToReaderConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToReaderConverter.java deleted file mode 100644 index 39a090e..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToReaderConverter.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.io; - -import java.io.File; -import java.io.FileReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToReaderConverter - implements Converter -{ - - public static final ToReaderConverter INSTANCE = new ToReaderConverter(); - - private final Converter escape; - - public ToReaderConverter() - { - this.escape = null; - } - - public ToReaderConverter( final Converter escape ) - { - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( Reader.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ) - && ( sourceObject instanceof URL - || sourceObject instanceof URI - || sourceObject instanceof File - || sourceObject instanceof InputStream - || sourceObject instanceof CharSequence - || ( escape != null - && ( escape.canConvert( sourceObject, new ReifiedType( URL.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( URI.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( File.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( InputStream.class ) ) ) ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToReaderConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToReader( sourceObject, targetType ); - } - - public Reader convertToReader( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( sourceObject instanceof URL ) - { - return new InputStreamReader( ( (URL) sourceObject ).openStream() ); - } - - if( sourceObject instanceof URI ) - { - return new InputStreamReader( ( (URI) sourceObject ).toURL().openStream() ); - } - - if( sourceObject instanceof File ) - { - return new FileReader( (File) sourceObject ); - } - - if( sourceObject instanceof InputStream ) - { - return new InputStreamReader( (InputStream) sourceObject ); - } - - if( sourceObject instanceof CharSequence ) - { - try - { - return new InputStreamReader( new URL( sourceObject.toString() ).openStream() ); - } - catch( MalformedURLException e ) - { - return new FileReader( sourceObject.toString() ); - } - } - - if( escape != null ) - { - if( escape.canConvert( sourceObject, new ReifiedType( URL.class ) ) ) - { - try - { - return new InputStreamReader( - ( (URL) escape.convert( sourceObject, new ReifiedType( URL.class ) ) ).openStream() - ); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( URI.class ) ) ) - { - try - { - return new InputStreamReader( - ( (URI) escape.convert( sourceObject, new ReifiedType( URI.class ) ) ).toURL().openStream() - ); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) - { - try - { - return new FileReader( (File) escape.convert( sourceObject, new ReifiedType( File.class ) ) ); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( InputStream.class ) ) ) - { - try - { - return new InputStreamReader( - (InputStream) escape.convert( sourceObject, new ReifiedType( InputStream.class ) ) - ); - } - catch( Exception ignore ) - { - // ignore - } - } - } - - throw new Exception( String.format( "Unable to convert number %s to %s", sourceObject, targetType ) ); - } - - public static ToReaderConverter toReaderConverter() - { - return INSTANCE; - } - - public static ToReaderConverter toReaderConverter( final Converter escape ) - { - return new ToReaderConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToURIConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToURIConverter.java deleted file mode 100644 index 10eca5b..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToURIConverter.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.io; - -import java.io.File; -import java.net.URI; -import java.net.URL; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToURIConverter - implements Converter -{ - - public static final ToURIConverter INSTANCE = new ToURIConverter(); - - private final Converter escape; - - public ToURIConverter() - { - this.escape = null; - } - - public ToURIConverter( final Converter escape ) - { - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( URI.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ) - && ( sourceObject instanceof URL - || sourceObject instanceof File - || sourceObject instanceof CharSequence - || ( escape != null - && ( escape.canConvert( sourceObject, new ReifiedType( URL.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToURIConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToURI( sourceObject, targetType ); - } - - public URI convertToURI( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( sourceObject instanceof URL ) - { - return ( (URL) sourceObject ).toURI(); - } - - if( sourceObject instanceof File ) - { - return ( (File) sourceObject ).toURI(); - } - - if( sourceObject instanceof CharSequence ) - { - return new URI( sourceObject.toString() ); - } - - if( escape != null ) - { - if( escape.canConvert( sourceObject, new ReifiedType( URL.class ) ) ) - { - try - { - return ( (URL) escape.convert( sourceObject, new ReifiedType( URL.class ) ) ).toURI(); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) - { - try - { - return ( (File) escape.convert( sourceObject, new ReifiedType( File.class ) ) ).toURI(); - } - catch( Exception ignore ) - { - // ignore - } - } - } - - throw new Exception( String.format( "Unable to convert number %s to %s", sourceObject, targetType ) ); - } - - public static ToURIConverter toURIConverter() - { - return INSTANCE; - } - - public static ToURIConverter toURIConverter( final Converter escape ) - { - return new ToURIConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToURLConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToURLConverter.java deleted file mode 100644 index f56a40e..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToURLConverter.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.io; - -import java.io.File; -import java.net.URI; -import java.net.URL; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToURLConverter - implements Converter -{ - - public static final ToURLConverter INSTANCE = new ToURLConverter(); - - private final Converter escape; - - public ToURLConverter() - { - this.escape = null; - } - - public ToURLConverter( final Converter escape ) - { - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( URL.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ) - && ( sourceObject instanceof URI - || sourceObject instanceof File - || sourceObject instanceof CharSequence - || ( escape != null - && ( escape.canConvert( sourceObject, new ReifiedType( URI.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToURLConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToURL( sourceObject, targetType ); - } - - public URL convertToURL( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( sourceObject instanceof URI ) - { - return ( (URI) sourceObject ).toURL(); - } - - if( sourceObject instanceof File ) - { - return ( (File) sourceObject ).toURI().toURL(); - } - - if( sourceObject instanceof CharSequence ) - { - return new URL( sourceObject.toString() ); - } - - if( escape != null ) - { - if( escape.canConvert( sourceObject, new ReifiedType( URI.class ) ) ) - { - try - { - return ( (URI) escape.convert( sourceObject, new ReifiedType( URI.class ) ) ).toURL(); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) - { - try - { - return ( (File) escape.convert( sourceObject, new ReifiedType( File.class ) ) ).toURI().toURL(); - } - catch( Exception ignore ) - { - // ignore - } - } - } - - throw new Exception( String.format( "Unable to convert number %s to %s", sourceObject, targetType ) ); - } - - public static ToURLConverter toURLConverter() - { - return INSTANCE; - } - - public static ToURLConverter toURLConverter( final Converter escape ) - { - return new ToURLConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToWriterConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToWriterConverter.java deleted file mode 100644 index 3872fd0..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/io/ToWriterConverter.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.io; - -import java.io.File; -import java.io.FileWriter; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToWriterConverter - implements Converter -{ - - public static final ToWriterConverter INSTANCE = new ToWriterConverter(); - - private final Converter escape; - - public ToWriterConverter() - { - this.escape = null; - } - - public ToWriterConverter( final Converter escape ) - { - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( Reader.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ) - && ( sourceObject instanceof File - || sourceObject instanceof OutputStream - || sourceObject instanceof CharSequence - || ( escape != null - && ( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) - || escape.canConvert( sourceObject, new ReifiedType( OutputStream.class ) ) ) ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToWriterConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToWriter( sourceObject, targetType ); - } - - public Writer convertToWriter( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( sourceObject instanceof File ) - { - return new FileWriter( (File) sourceObject ); - } - - if( sourceObject instanceof OutputStream ) - { - return new OutputStreamWriter( (OutputStream) sourceObject ); - } - - if( sourceObject instanceof CharSequence ) - { - return new FileWriter( sourceObject.toString() ); - } - - if( escape != null ) - { - if( escape.canConvert( sourceObject, new ReifiedType( File.class ) ) ) - { - try - { - return new FileWriter( (File) escape.convert( sourceObject, new ReifiedType( File.class ) ) ); - } - catch( Exception ignore ) - { - // ignore - } - } - - if( escape.canConvert( sourceObject, new ReifiedType( OutputStream.class ) ) ) - { - try - { - return new OutputStreamWriter( - (OutputStream) escape.convert( sourceObject, new ReifiedType( OutputStream.class ) ) - ); - } - catch( Exception ignore ) - { - // ignore - } - } - } - - throw new Exception( String.format( "Unable to convert number %s to %s", sourceObject, targetType ) ); - } - - public static ToWriterConverter toWriterConverter() - { - return INSTANCE; - } - - public static ToWriterConverter toWriterConverter( final Converter escape ) - { - return new ToWriterConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/AssignableConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/AssignableConverter.java deleted file mode 100644 index dbd3894..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/AssignableConverter.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.lang; - -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class AssignableConverter - implements Converter -{ - - public static final AssignableConverter INSTANCE = new AssignableConverter(); - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return FromNullConverter.fromNullConverter().canConvert( sourceObject, targetType ) - || ( targetType.size() == 0 - && unwrap( targetType.getRawClass() ).isAssignableFrom( unwrap( sourceObject.getClass() ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", AssignableConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - return sourceObject; - } - - public static AssignableConverter assignableConverter() - { - return INSTANCE; - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromNullConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromNullConverter.java deleted file mode 100644 index 126ccb7..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromNullConverter.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.lang; - -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class FromNullConverter - implements Converter -{ - - public static final FromNullConverter INSTANCE = new FromNullConverter(); - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return sourceObject == null; - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", FromNullConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - return null; - } - - public static FromNullConverter fromNullConverter() - { - return INSTANCE; - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromStringConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromStringConverter.java deleted file mode 100644 index 19f32c9..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromStringConverter.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.lang; - -import java.io.ByteArrayInputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; -import java.util.Locale; -import java.util.Properties; -import java.util.regex.Pattern; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class FromStringConverter - implements Converter -{ - - public static final FromStringConverter INSTANCE = new FromStringConverter(); - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( sourceObject instanceof String - && targetType != null - && !( targetType.getRawClass() == Class.class ) - && !( targetType.getRawClass() == ReifiedType.class ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", FromStringConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertFromString( (String) sourceObject, targetType.getRawClass() ); - } - - public Object convertFromString( final String sourceObject, - final Class targetType ) - throws Exception - { - final Class type = unwrap( targetType ); - - if( Locale.class == type ) - { - String[] tokens = sourceObject.split( "_" ); - if( tokens.length == 1 ) - { - return new Locale( tokens[ 0 ] ); - } - else if( tokens.length == 2 ) - { - return new Locale( tokens[ 0 ], tokens[ 1 ] ); - } - else if( tokens.length == 3 ) - { - return new Locale( tokens[ 0 ], tokens[ 1 ], tokens[ 2 ] ); - } - else - { - throw new Exception( "Invalid locale string:" + sourceObject ); - } - } - - if( Pattern.class == type ) - { - return Pattern.compile( sourceObject ); - } - - if( Properties.class == type ) - { - Properties props = new Properties(); - ByteArrayInputStream in = new ByteArrayInputStream( sourceObject.getBytes( "UTF8" ) ); - props.load( in ); - return props; - } - - if( Boolean.class == type ) - { - if( "yes".equalsIgnoreCase( sourceObject ) - || "true".equalsIgnoreCase( sourceObject ) - || "on".equalsIgnoreCase( sourceObject ) ) - { - return Boolean.TRUE; - } - else if( "no".equalsIgnoreCase( sourceObject ) - || "false".equalsIgnoreCase( sourceObject ) - || "off".equalsIgnoreCase( sourceObject ) ) - { - return Boolean.FALSE; - } - else - { - throw new RuntimeException( "Invalid boolean value: " + sourceObject ); - } - } - - if( Integer.class == type ) - { - return Integer.valueOf( sourceObject ); - } - - if( Short.class == type ) - { - return Short.valueOf( sourceObject ); - } - - if( Long.class == type ) - { - return Long.valueOf( sourceObject ); - } - - if( Float.class == type ) - { - return Float.valueOf( sourceObject ); - } - - if( Double.class == type ) - { - return Double.valueOf( sourceObject ); - } - - if( Character.class == type ) - { - if( sourceObject.length() == 6 && sourceObject.startsWith( "\\u" ) ) - { - int code = Integer.parseInt( sourceObject.substring( 2 ), 16 ); - return (char) code; - } - else if( sourceObject.length() == 1 ) - { - return sourceObject.charAt( 0 ); - } - else - { - throw new Exception( "Invalid value for character type: " + sourceObject ); - } - } - - if( Byte.class == type ) - { - return Byte.valueOf( sourceObject ); - } - - if( Enum.class.isAssignableFrom( type ) ) - { - return Enum.valueOf( (Class) type, sourceObject ); - } - - return createObject( sourceObject, type ); - } - - private Object createObject( final String sourceObject, - final Class targetType ) - throws Exception - { - if( targetType.isInterface() - || Modifier.isAbstract( targetType.getModifiers() ) ) - { - throw new Exception( - "Unable to convert value " + sourceObject + " to type " + targetType + ". Type " + targetType - + " is an interface or an abstract class" - ); - } - - try - { - final Constructor constructor = targetType.getConstructor( String.class ); - return constructor.newInstance( sourceObject ); - } - catch( NoSuchMethodException e ) - { - throw new RuntimeException( "Unable to convert to " + targetType ); - } - } - - public static FromStringConverter fromStringConverter() - { - return INSTANCE; - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromStringToClassConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromStringToClassConverter.java deleted file mode 100644 index 0503ced..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/FromStringToClassConverter.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.lang; - -import static java.lang.String.*; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import org.ops4j.pax.swissbox.converter.GenericType; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; -import org.ops4j.pax.swissbox.converter.loader.Loader; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class FromStringToClassConverter - implements Converter -{ - - private final Loader loader; - - public FromStringToClassConverter( final Loader loader ) - { - this.loader = loader; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( sourceObject instanceof String - && targetType != null - && ( targetType.getRawClass() == Class.class - || targetType.getRawClass() == ReifiedType.class ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - format( - "%s cannot convert an %s", FromStringConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertFromString( (String) sourceObject, targetType.getRawClass() ); - } - - public Object convertFromString( final String sourceObject, - final Class targetType ) - throws Exception - { - - if( ReifiedType.class == targetType ) - { - try - { - return GenericType.parse( sourceObject, loader ); - } - catch( ClassNotFoundException e ) - { - throw new Exception( "Unable to convert", e ); - } - } - - if( Class.class == targetType ) - { - try - { - return GenericType.parse( sourceObject, loader ).getRawClass(); - } - catch( ClassNotFoundException e ) - { - throw new Exception( "Unable to convert", e ); - } - } - - throw new Exception( format( "Unable to convert string [%s] to %s", sourceObject, targetType ) ); - } - - public static FromStringToClassConverter fromStringToClassConverter( final Loader loader ) - { - return new FromStringToClassConverter( loader ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToCharSequenceConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToCharSequenceConverter.java deleted file mode 100644 index 9672b2c..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToCharSequenceConverter.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.lang; - -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.ToStringConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToCharSequenceConverter - implements Converter -{ - - public static final ToCharSequenceConverter INSTANCE = new ToCharSequenceConverter(); - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || CharSequence.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToCharSequenceConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToCharSequence( sourceObject ); - } - - public CharSequence convertToCharSequence( final Object sourceObject ) - throws Exception - { - return toStringConverter().convertToString( sourceObject ); - } - - public static ToCharSequenceConverter toCharSequenceConverter() - { - return INSTANCE; - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToNumberConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToNumberConverter.java deleted file mode 100644 index 6b73484..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToNumberConverter.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.lang; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToNumberConverter - implements Converter -{ - - public static final ToNumberConverter INSTANCE = new ToNumberConverter(); - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( sourceObject instanceof Number - && Number.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToNumberConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToNumber( (Number) sourceObject, targetType.getRawClass() ); - } - - public Object convertToNumber( final Number sourceObject, - final Class targetType ) - throws Exception - { - final Class type = unwrap( targetType ); - - if( AtomicInteger.class == type ) - { - return new AtomicInteger( (Integer) convertToNumber( sourceObject, Integer.class ) ); - } - - if( AtomicLong.class == type ) - { - return new AtomicLong( (Long) convertToNumber( sourceObject, Long.class ) ); - } - - if( Integer.class == type ) - { - return sourceObject.intValue(); - } - - if( Short.class == type ) - { - return sourceObject.shortValue(); - } - - if( Long.class == type ) - { - return sourceObject.longValue(); - } - - if( Float.class == type ) - { - return sourceObject.floatValue(); - } - - if( Double.class == type ) - { - return sourceObject.doubleValue(); - } - - if( Byte.class == type ) - { - return sourceObject.byteValue(); - } - - if( BigInteger.class == type ) - { - return new BigInteger( sourceObject.toString() ); - } - - if( BigDecimal.class == type ) - { - return new BigDecimal( sourceObject.toString() ); - } - - throw new Exception( String.format( "Unable to convert number %s to %s", sourceObject, type ) ); - } - - public static ToNumberConverter toNumberConverter() - { - return INSTANCE; - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToStringConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToStringConverter.java deleted file mode 100644 index 375dcf9..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/lang/ToStringConverter.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.lang; - -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.internal.Primitives.*; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToStringConverter - implements Converter -{ - - public static final ToStringConverter INSTANCE = new ToStringConverter(); - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || String.class.isAssignableFrom( unwrap( targetType.getRawClass() ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - String.format( - "%s cannot convert an %s", ToStringConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToString( sourceObject ); - } - - public String convertToString( final Object sourceObject ) - throws Exception - { - if( sourceObject instanceof Class ) - { - return ( (Class) sourceObject ).getName(); - } - - return sourceObject.toString(); - } - - public static ToStringConverter toStringConverter() - { - return INSTANCE; - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToArrayConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToArrayConverter.java deleted file mode 100644 index ed5afcc..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToArrayConverter.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.util; - -import static java.lang.String.*; -import java.lang.reflect.Array; -import java.util.Collection; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import org.ops4j.pax.swissbox.converter.GenericType; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToArrayConverter - implements Converter -{ - - private final Converter escape; - - public ToArrayConverter( final Converter escape ) - { - - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || ( targetType.getRawClass().isArray() - && ( sourceObject instanceof Collection - || sourceObject.getClass().isArray() ) ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - format( - "%s cannot convert an %s", ToArrayConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToArray( sourceObject, targetType ); - } - - private Object convertToArray( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - Object toConvert = sourceObject; - - if( toConvert instanceof Collection ) - { - toConvert = ( (Collection) toConvert ).toArray(); - } - - if( !toConvert.getClass().isArray() ) - { - throw new Exception( format( "Unable to convert from [%s] to [%s]", sourceObject, targetType ) ); - } - - ReifiedType componentType; - if( targetType.size() > 0 ) - { - componentType = targetType.getActualTypeArgument( 0 ); - } - else - { - componentType = new GenericType( targetType.getRawClass().getComponentType() ); - } - - final Object array = Array.newInstance( componentType.getRawClass(), Array.getLength( toConvert ) ); - - for( int i = 0; i < Array.getLength( toConvert ); i++ ) - { - try - { - Array.set( array, i, escape.convert( Array.get( toConvert, i ), componentType ) ); - } - catch( Exception t ) - { - throw new Exception( - "Unable to convert from " + toConvert + " to " + targetType + "(error converting array element)", t - ); - } - } - return array; - } - - public static ToArrayConverter toArrayConverter( final Converter escape ) - { - return new ToArrayConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToCollectionConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToCollectionConverter.java deleted file mode 100644 index 771b139..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToCollectionConverter.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.util; - -import static java.lang.String.*; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import org.ops4j.pax.swissbox.converter.internal.Reflection; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToCollectionConverter - implements Converter -{ - - private final Converter escape; - - public ToCollectionConverter( final Converter escape ) - { - - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || Collection.class.isAssignableFrom( targetType.getRawClass() ) - && ( sourceObject instanceof Collection - || sourceObject.getClass().isArray() ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - format( - "%s cannot convert an %s", ToCollectionConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToCollection( sourceObject, targetType ); - } - - private Object convertToCollection( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - final ReifiedType valueType = targetType.getActualTypeArgument( 0 ); - - if( sourceObject.getClass().isArray() ) - { - final Collection converted = createCollection( getCollectionType( targetType.getRawClass() ) ); - - for( int i = 0; i < Array.getLength( sourceObject ); i++ ) - { - try - { - converted.add( escape.convert( Array.get( sourceObject, i ), valueType ) ); - } - catch( Exception e ) - { - throw new Exception( - format( - "Unable to convert from %s to %s (error converting map entry)", sourceObject, targetType - ), - e - ); - } - } - - return converted; - } - - if( sourceObject instanceof Collection ) - { - final Collection converted = createCollection( getCollectionType( targetType.getRawClass() ) ); - - for( Object item : (Collection) sourceObject ) - { - try - { - converted.add( convert( item, valueType ) ); - } - catch( Exception e ) - { - throw new Exception( - format( - "Unable to convert from %s to %s (error converting map entry)", sourceObject, targetType - ), - e - ); - } - } - - return converted; - } - - throw new Exception( format( "Unable to convert from %s to %s", sourceObject, targetType ) ); - } - - private static Collection createCollection( final Class type ) - throws Exception - { - return Reflection.newInstance( type ); - } - - private static Class getCollectionType( final Class type ) - { - if( Reflection.hasDefaultConstructor( type ) ) - { - return type; - } - else if( SortedSet.class.isAssignableFrom( type ) ) - { - return TreeSet.class; - } - else if( Set.class.isAssignableFrom( type ) ) - { - return LinkedHashSet.class; - } - else if( List.class.isAssignableFrom( type ) ) - { - return ArrayList.class; - } - else if( Queue.class.isAssignableFrom( type ) ) - { - return LinkedList.class; - } - else - { - return ArrayList.class; - } - } - - public static ToCollectionConverter toCollectionConverter( final Converter escape ) - { - return new ToCollectionConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToDictionaryConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToDictionaryConverter.java deleted file mode 100644 index 02139b5..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToDictionaryConverter.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.util; - -import static java.lang.String.*; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Map; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToDictionaryConverter - implements Converter -{ - - private final Converter escape; - - public ToDictionaryConverter( final Converter escape ) - { - - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || Dictionary.class.isAssignableFrom( targetType.getRawClass() ) - && ( sourceObject instanceof Map - || sourceObject instanceof Dictionary ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - format( - "%s cannot convert an %s", ToDictionaryConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToDictionary( sourceObject, targetType ); - } - - private Object convertToDictionary( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - final ReifiedType keyType = targetType.getActualTypeArgument( 0 ); - final ReifiedType valueType = targetType.getActualTypeArgument( 1 ); - - if( sourceObject instanceof Dictionary ) - { - final Dictionary converted = new Hashtable(); - - final Dictionary toConvert = (Dictionary) sourceObject; - - for( Enumeration keys = toConvert.keys(); keys.hasMoreElements(); ) - { - final Object key = keys.nextElement(); - try - { - converted.put( - escape.convert( key, keyType ), - escape.convert( toConvert.get( key ), valueType ) - ); - } - catch( Exception e ) - { - throw new Exception( - format( - "Unable to convert from %s to %s (error converting map entry)", sourceObject, targetType - ), - e - ); - } - } - - return converted; - } - - if( sourceObject instanceof Map ) - { - final Dictionary converted = new Hashtable(); - - for( Map.Entry entry : ( (Map) sourceObject ).entrySet() ) - { - try - { - converted.put( - escape.convert( entry.getKey(), keyType ), - escape.convert( entry.getValue(), valueType ) - ); - } - catch( Exception e ) - { - throw new Exception( - format( - "Unable to convert from %s to %s (error converting map entry)", sourceObject, targetType - ), - e - ); - } - } - - return converted; - } - - throw new Exception( format( "Unable to convert from %s to %s", sourceObject, targetType ) ); - } - - public static ToDictionaryConverter toDictionaryConverter( final Converter escape ) - { - return new ToDictionaryConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToMapConverter.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToMapConverter.java deleted file mode 100644 index 61cf803..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/java/util/ToMapConverter.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.java.util; - -import static java.lang.String.*; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; -import org.ops4j.pax.swissbox.converter.internal.Reflection; -import static org.ops4j.pax.swissbox.converter.java.lang.AssignableConverter.*; -import static org.ops4j.pax.swissbox.converter.java.lang.FromNullConverter.*; - -/** - * JAVADOC - * - * NOTICE: This class contains code originally developed by "Apache Geronimo Project", OSGi Blueprint Implementation. - * - * @author Apache Geronimo Project - * @author Alin Dreghiciu (adreghiciu@gmail.com) - */ -public class ToMapConverter - implements Converter -{ - - private final Converter escape; - - public ToMapConverter( final Converter escape ) - { - - this.escape = escape; - } - - public boolean canConvert( final Object sourceObject, - final ReifiedType targetType ) - { - return fromNullConverter().canConvert( sourceObject, targetType ) - || assignableConverter().canConvert( sourceObject, targetType ) - || Map.class.isAssignableFrom( targetType.getRawClass() ) - && ( sourceObject instanceof Map - || sourceObject instanceof Dictionary ); - } - - public Object convert( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - if( !canConvert( sourceObject, targetType ) ) - { - throw new Exception( - format( - "%s cannot convert an %s", ToMapConverter.class.getSimpleName(), sourceObject.getClass() - ) - ); - } - - if( fromNullConverter().canConvert( sourceObject, targetType ) ) - { - return fromNullConverter().convert( sourceObject, targetType ); - } - - if( assignableConverter().canConvert( sourceObject, targetType ) ) - { - return assignableConverter().convert( sourceObject, targetType ); - } - - return convertToMap( sourceObject, targetType ); - } - - private Object convertToMap( final Object sourceObject, - final ReifiedType targetType ) - throws Exception - { - final ReifiedType keyType = targetType.getActualTypeArgument( 0 ); - final ReifiedType valueType = targetType.getActualTypeArgument( 1 ); - - if( sourceObject instanceof Dictionary ) - { - final Map converted = createMap( getMapType( targetType.getRawClass() ) ); - - final Dictionary toConvert = (Dictionary) sourceObject; - - for( Enumeration keys = toConvert.keys(); keys.hasMoreElements(); ) - { - final Object key = keys.nextElement(); - - try - { - converted.put( - escape.convert( key, keyType ), - escape.convert( toConvert.get( key ), valueType ) - ); - } - catch( Exception e ) - { - throw new Exception( - format( - "Unable to convert from %s to %s (error converting map entry)", sourceObject, targetType - ), - e - ); - } - } - - return converted; - } - - if( sourceObject instanceof Map ) - { - final Map converted = createMap( getMapType( targetType.getRawClass() ) ); - - for( Map.Entry entry : ( (Map) sourceObject ).entrySet() ) - { - try - { - converted.put( - escape.convert( entry.getKey(), keyType ), - escape.convert( entry.getValue(), valueType ) - ); - } - catch( Exception e ) - { - throw new Exception( - format( - "Unable to convert from %s to %s (error converting map entry)", sourceObject, targetType - ), - e - ); - } - } - - return converted; - } - - throw new Exception( format( "Unable to convert from %s to %s", sourceObject, targetType ) ); - } - - private static Map createMap( final Class type ) - throws Exception - { - return Reflection.newInstance( type ); - } - - private static Class getMapType( final Class type ) - { - if( Reflection.hasDefaultConstructor( type ) ) - { - return type; - } - else if( SortedMap.class.isAssignableFrom( type ) ) - { - return TreeMap.class; - } - else if( ConcurrentMap.class.isAssignableFrom( type ) ) - { - return ConcurrentHashMap.class; - } - else - { - return LinkedHashMap.class; - } - } - - public static ToMapConverter toMapConverter( final Converter escape ) - { - return new ToMapConverter( escape ); - } - -} \ No newline at end of file diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/BundleLoader.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/BundleLoader.java deleted file mode 100644 index 6f38d16..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/BundleLoader.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.loader; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class BundleLoader - implements Loader -{ - - private final BundleLoader bundle; - - public BundleLoader( final BundleLoader bundle ) - { - this.bundle = bundle; - } - - public Class loadClass( final String className ) - throws ClassNotFoundException - { - return bundle.loadClass( className ); - } - -} diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/ClassicLoader.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/ClassicLoader.java deleted file mode 100644 index 8dd7fe7..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/ClassicLoader.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.loader; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public class ClassicLoader - implements Loader -{ - - private final ClassicLoader classLoader; - - public ClassicLoader( final ClassicLoader classLoader ) - { - this.classLoader = classLoader; - } - - public Class loadClass( final String className ) - throws ClassNotFoundException - { - return classLoader.loadClass( className ); - } - -} diff --git a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/Loader.java b/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/Loader.java deleted file mode 100644 index 56ad29d..0000000 --- a/pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/loader/Loader.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.ops4j.pax.swissbox.converter.loader; - -/** - * JAVADOC - * - * @author Alin Dreghiciu - */ -public interface Loader -{ - - Class loadClass( java.lang.String className ) - throws ClassNotFoundException; - - -} diff --git a/pax-swissbox-converter/src/main/java/org/osgi/service/blueprint/container/Converter.java b/pax-swissbox-converter/src/main/java/org/osgi/service/blueprint/container/Converter.java deleted file mode 100644 index 3983bd5..0000000 --- a/pax-swissbox-converter/src/main/java/org/osgi/service/blueprint/container/Converter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.osgi.service.blueprint.container; - -import javax.annotation.concurrent.ThreadSafe; - -/** - * Type converter to convert an object to a target type. - * - * @version $Revision: 7564 $ - */ -@ThreadSafe -public interface Converter -{ - - /** - * Return if this converter is able to convert the specified object to the - * specified type. - * - * @param sourceObject The source object s to convert. - * @param targetType The target type T. - * - * @return true if the conversion is possible, - * false otherwise. - */ - boolean canConvert( Object sourceObject, ReifiedType targetType ); - - /** - * Convert the specified object to an instance of the specified type. - * - * @param sourceObject The source object s to convert. - * @param targetType The target type T. - * - * @return An instance with a type that is assignable from targetType's raw - * class - * - * @throws Exception If the conversion cannot succeed. This exception should - * not be thrown when the {@link #canConvert canConvert} method has - * returned true. - */ - Object convert( Object sourceObject, ReifiedType targetType) - throws Exception; -} diff --git a/pax-swissbox-converter/src/main/java/org/osgi/service/blueprint/container/ReifiedType.java b/pax-swissbox-converter/src/main/java/org/osgi/service/blueprint/container/ReifiedType.java deleted file mode 100644 index 6593549..0000000 --- a/pax-swissbox-converter/src/main/java/org/osgi/service/blueprint/container/ReifiedType.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2009 Alin Dreghiciu. - * - * 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.osgi.service.blueprint.container; - -import javax.annotation.concurrent.Immutable; - -/** - * Provides access to a concrete type and its optional generic type parameters. - * - *

- * Java 5 and later support generic types. These types consist of a raw class - * with type parameters. This class models such a Type class but - * ensures that the type is reified. Reification means that the Type - * graph associated with a Java 5 Type instance is traversed until - * the type becomes a concrete class. This class is available with the - * {@link #getRawClass()} method. The optional type parameters are recursively - * represented as Reified Types. - * - *

- * In Java 1.4, a class has by definition no type parameters. This class - * implementation provides the Reified Type for Java 1.4 by making the raw class - * the Java 1.4 class and using a Reified Type based on the Object - * class for any requested type parameter. - * - *

- * A Blueprint extender implementations can subclass this class and provide - * access to the generic type parameter graph for conversion. Such a subclass - * must reify the different Java 5 Type instances into the - * reified form. That is, a form where the raw Class is available with its - * optional type parameters as Reified Types. - * - * @version $Revision: 7564 $ - */ -@Immutable -public class ReifiedType -{ - - private final static ReifiedType OBJECT = new ReifiedType( Object.class ); - - private final Class clazz; - - /** - * Create a Reified Type for a raw Java class without any generic type - * parameters. Subclasses can provide the optional generic type parameter - * information. Without subclassing, this instance has no type parameters. - * - * @param clazz The raw class of the Reified Type. - */ - public ReifiedType( Class clazz ) - { - this.clazz = clazz; - } - - /** - * Return the raw class represented by this type. - * - * The raw class represents the concrete class that is associated with a - * type declaration. This class could have been deduced from the generics - * type parameter graph of the declaration. For example, in the following - * example: - * - *

-     * Map<String, ? extends Metadata>
-     * 
- * - * The raw class is the Map class. - * - * @return The raw class represented by this type. - */ - public Class getRawClass() - { - return clazz; - } - - /** - * Return a type parameter for this type. - * - * The type parameter refers to a parameter in a generic type declaration - * given by the zero-based index i. - * - * For example, in the following example: - * - *
-     * Map<String, ? extends Metadata>
-     * 
- * - * type parameter 0 is String, and type parameter 1 is - * Metadata. - * - *

- * This implementation returns a Reified Type that has Object - * as class. Any object is assignable to Object and therefore no conversion - * is then necessary. This is compatible with versions of Java language - * prior to Java 5. - * - * This method should be overridden by a subclass that provides access to - * the generic type parameter information for Java 5 and later. - * - * @param i The zero-based index of the requested type parameter. - * - * @return The ReifiedType for the generic type parameter at - * the specified index. - */ - public ReifiedType getActualTypeArgument( int i ) - { - return OBJECT; - } - - /** - * Return the number of type parameters for this type. - * - *

- * This implementation returns 0. This method should be - * overridden by a subclass that provides access to the generic type - * parameter information for Java 5 and later. - * - * @return The number of type parameters for this type. - */ - public int size() { - return 0; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + clazz.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ReifiedType other = (ReifiedType) obj; - return clazz.equals(other.clazz); - } - - @Override - public String toString() { - return "ReifiedType [clazz=" + clazz + "]"; - } - -} diff --git a/pom.xml b/pom.xml index b0108d1..e0f24f9 100644 --- a/pom.xml +++ b/pom.xml @@ -191,7 +191,6 @@ pax-swissbox-bnd - pax-swissbox-converter pax-swissbox-core pax-swissbox-extender pax-swissbox-framework @@ -207,7 +206,6 @@ release pax-swissbox-bnd - pax-swissbox-converter pax-swissbox-core pax-swissbox-extender pax-swissbox-framework