-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-72981] Inline EZMorph repository (#8)
Signed-off-by: Bob Du <[email protected]>
- Loading branch information
Showing
119 changed files
with
18,140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2006-2007 the original author or authors. | ||
* | ||
* 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 net.sf.ezmorph; | ||
|
||
import org.apache.commons.lang.exception.NestableRuntimeException; | ||
|
||
/** | ||
* A <strong>MorphException</strong> indicates that a call to | ||
* <code>Morpher.morph()</code> has failed to complete successfully.<br> | ||
* Based on common-beauntils ConversionException.<br> | ||
* | ||
* @author Andres Almiray <a href="mailto:[email protected]">[email protected]</a> | ||
*/ | ||
public class MorphException extends NestableRuntimeException | ||
{ | ||
private static final long serialVersionUID = -540093801787033824L; | ||
|
||
// ----------------------------------------------------------- Constructors | ||
|
||
/** | ||
* The root cause of this <code>ConversionException</code>, compatible | ||
* with JDK 1.4's extensions to <code>java.lang.Throwable</code>. | ||
*/ | ||
protected Throwable cause = null; | ||
|
||
/** | ||
* Construct a new exception with the specified message. | ||
* | ||
* @param message The message describing this exception | ||
*/ | ||
public MorphException( String message ) | ||
{ | ||
super( message ); | ||
} | ||
|
||
/** | ||
* Construct a new exception with the specified message and root cause. | ||
* | ||
* @param message The message describing this exception | ||
* @param cause The root cause of this exception | ||
*/ | ||
public MorphException( String message, Throwable cause ) | ||
{ | ||
super( message ); | ||
this.cause = cause; | ||
} | ||
|
||
// ------------------------------------------------------------- Properties | ||
|
||
/** | ||
* Construct a new exception with the specified root cause. | ||
* | ||
* @param cause The root cause of this exception | ||
*/ | ||
public MorphException( Throwable cause ) | ||
{ | ||
super( cause.getMessage() ); | ||
this.cause = cause; | ||
} | ||
|
||
/** | ||
* Returns the cause of this exception. | ||
* | ||
* @return a Throwable that represents the cause of this exception | ||
*/ | ||
public Throwable getCause() | ||
{ | ||
return this.cause; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
/* | ||
* Copyright 2006-2007 the original author or authors. | ||
* | ||
* 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 net.sf.ezmorph; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
|
||
import net.sf.ezmorph.array.BooleanArrayMorpher; | ||
import net.sf.ezmorph.array.ByteArrayMorpher; | ||
import net.sf.ezmorph.array.CharArrayMorpher; | ||
import net.sf.ezmorph.array.DoubleArrayMorpher; | ||
import net.sf.ezmorph.array.FloatArrayMorpher; | ||
import net.sf.ezmorph.array.IntArrayMorpher; | ||
import net.sf.ezmorph.array.LongArrayMorpher; | ||
import net.sf.ezmorph.array.ObjectArrayMorpher; | ||
import net.sf.ezmorph.array.ShortArrayMorpher; | ||
import net.sf.ezmorph.object.BooleanObjectMorpher; | ||
import net.sf.ezmorph.object.CharacterObjectMorpher; | ||
import net.sf.ezmorph.object.ClassMorpher; | ||
import net.sf.ezmorph.object.NumberMorpher; | ||
import net.sf.ezmorph.object.StringMorpher; | ||
import net.sf.ezmorph.primitive.BooleanMorpher; | ||
import net.sf.ezmorph.primitive.ByteMorpher; | ||
import net.sf.ezmorph.primitive.CharMorpher; | ||
import net.sf.ezmorph.primitive.DoubleMorpher; | ||
import net.sf.ezmorph.primitive.FloatMorpher; | ||
import net.sf.ezmorph.primitive.IntMorpher; | ||
import net.sf.ezmorph.primitive.LongMorpher; | ||
import net.sf.ezmorph.primitive.ShortMorpher; | ||
|
||
/** | ||
* Covenient class for registering standard morphers to a ConvertRegistry.<br> | ||
* | ||
* @author Andres Almiray <a href="mailto:[email protected]">[email protected]</a> | ||
*/ | ||
public class MorphUtils | ||
{ | ||
/** Constant value for BigDecimal(1) */ | ||
public static final BigDecimal BIGDECIMAL_ONE = new BigDecimal( "1" ); | ||
/** Constant value for BigDecimal(0) */ | ||
public static final BigDecimal BIGDECIMAL_ZERO = new BigDecimal( "0" ); | ||
|
||
/** | ||
* Clears and registers all standard morpehrs. | ||
* | ||
* @param morpherRegistry | ||
*/ | ||
public static void registerStandardMorphers( MorpherRegistry morpherRegistry ) | ||
{ | ||
morpherRegistry.clear(); | ||
registerStandardPrimitiveMorphers( morpherRegistry ); | ||
registerStandardPrimitiveArrayMorphers( morpherRegistry ); | ||
registerStandardObjectMorphers( morpherRegistry ); | ||
registerStandardObjectArrayMorphers( morpherRegistry ); | ||
} | ||
|
||
/** | ||
* Registers morphers for arrays of wrappers and String with standard default | ||
* values.<br> | ||
* <ul> | ||
* <li>Boolean - Boolean.FALSE</li> | ||
* <li>Character - new Character('\0')</li> | ||
* <li>Byte - new Byte( (byte)0 )</li> | ||
* <li>Short - new Short( (short)0 )</li> | ||
* <li>Integer - new Integer( 0 )</li> | ||
* <li>Long - new Long( 0 )</li> | ||
* <li>Float - new Float( 0 )</li> | ||
* <li>Double - new Double( 0 )</li> | ||
* <li>String - null</li> | ||
* <li>BigInteger - BigInteger.ZERO</li> | ||
* <li>BigDecimal - MorphUtils.BIGDECIMAL_ZERO</li> | ||
* </ul> | ||
* | ||
* @param morpherRegistry | ||
*/ | ||
public static void registerStandardObjectArrayMorphers( MorpherRegistry morpherRegistry ) | ||
{ | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new BooleanObjectMorpher( | ||
Boolean.FALSE ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new CharacterObjectMorpher( | ||
new Character( '\0' ) ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( StringMorpher.getInstance() ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new NumberMorpher( Byte.class, | ||
new Byte( (byte) 0 ) ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new NumberMorpher( Short.class, | ||
new Short( (short) 0 ) ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new NumberMorpher( Integer.class, | ||
new Integer( 0 ) ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new NumberMorpher( Long.class, | ||
new Long( 0 ) ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new NumberMorpher( Float.class, | ||
new Float( 0 ) ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new NumberMorpher( Double.class, | ||
new Double( 0 ) ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new NumberMorpher( BigInteger.class, | ||
BigInteger.ZERO ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( new NumberMorpher( BigDecimal.class, | ||
MorphUtils.BIGDECIMAL_ZERO ) ) ); | ||
morpherRegistry.registerMorpher( new ObjectArrayMorpher( ClassMorpher.getInstance() ) ); | ||
} | ||
|
||
/** | ||
* Registers morphers for wrappers and String with standard default values.<br> | ||
* <ul> | ||
* <li>Boolean - Boolean.FALSE</li> | ||
* <li>Character - new Character('\0')</li> | ||
* <li>Byte - new Byte( (byte)0 )</li> | ||
* <li>Short - new Short( (short)0 )</li> | ||
* <li>Integer - new Integer( 0 )</li> | ||
* <li>Long - new Long( 0 )</li> | ||
* <li>Float - new Float( 0 )</li> | ||
* <li>Double - new Double( 0 )</li> | ||
* <li>String - null</li> | ||
* <li>BigInteger - BigInteger.ZERO</li> | ||
* <li>BigDecimal - MorphUtils.BIGDECIMAL_ZERO</li> | ||
* </ul> | ||
* | ||
* @param morpherRegistry | ||
*/ | ||
public static void registerStandardObjectMorphers( MorpherRegistry morpherRegistry ) | ||
{ | ||
morpherRegistry.registerMorpher( new BooleanObjectMorpher( Boolean.FALSE ) ); | ||
morpherRegistry.registerMorpher( new CharacterObjectMorpher( new Character( '\0' ) ) ); | ||
morpherRegistry.registerMorpher( StringMorpher.getInstance() ); | ||
morpherRegistry.registerMorpher( new NumberMorpher( Byte.class, new Byte( (byte) 0 ) ) ); | ||
morpherRegistry.registerMorpher( new NumberMorpher( Short.class, new Short( (short) 0 ) ) ); | ||
morpherRegistry.registerMorpher( new NumberMorpher( Integer.class, new Integer( 0 ) ) ); | ||
morpherRegistry.registerMorpher( new NumberMorpher( Long.class, new Long( 0 ) ) ); | ||
morpherRegistry.registerMorpher( new NumberMorpher( Float.class, new Float( 0 ) ) ); | ||
morpherRegistry.registerMorpher( new NumberMorpher( Double.class, new Double( 0 ) ) ); | ||
morpherRegistry.registerMorpher( new NumberMorpher( BigInteger.class, BigInteger.ZERO ) ); | ||
morpherRegistry.registerMorpher( new NumberMorpher( BigDecimal.class, | ||
MorphUtils.BIGDECIMAL_ZERO ) ); | ||
morpherRegistry.registerMorpher( ClassMorpher.getInstance() ); | ||
} | ||
|
||
/** | ||
* Registers morphers for arrays of primitives with standard default values.<br> | ||
* <ul> | ||
* <li>boolean - false</li> | ||
* <li>char - '\0'</li> | ||
* <li>byte - 0</li> | ||
* <li>short - 0</li> | ||
* <li>int - 0</li> | ||
* <li>long - 0</li> | ||
* <li>float - 0</li> | ||
* <li>double - 0</li> | ||
* </ul> | ||
* | ||
* @param morpherRegistry | ||
*/ | ||
public static void registerStandardPrimitiveArrayMorphers( MorpherRegistry morpherRegistry ) | ||
{ | ||
morpherRegistry.registerMorpher( new BooleanArrayMorpher( false ) ); | ||
morpherRegistry.registerMorpher( new CharArrayMorpher( '\0' ) ); | ||
morpherRegistry.registerMorpher( new ByteArrayMorpher( (byte) 0 ) ); | ||
morpherRegistry.registerMorpher( new ShortArrayMorpher( (short) 0 ) ); | ||
morpherRegistry.registerMorpher( new IntArrayMorpher( 0 ) ); | ||
morpherRegistry.registerMorpher( new LongArrayMorpher( 0 ) ); | ||
morpherRegistry.registerMorpher( new FloatArrayMorpher( 0 ) ); | ||
morpherRegistry.registerMorpher( new DoubleArrayMorpher( 0 ) ); | ||
} | ||
|
||
/** | ||
* Registers morphers for primitives with standard default values.<br> | ||
* <ul> | ||
* <li>boolean - false</li> | ||
* <li>char - '\0'</li> | ||
* <li>byte - 0</li> | ||
* <li>short - 0</li> | ||
* <li>int - 0</li> | ||
* <li>long - 0</li> | ||
* <li>float - 0</li> | ||
* <li>double - 0</li> | ||
* </ul> | ||
* | ||
* @param morpherRegistry | ||
*/ | ||
public static void registerStandardPrimitiveMorphers( MorpherRegistry morpherRegistry ) | ||
{ | ||
morpherRegistry.registerMorpher( new BooleanMorpher( false ) ); | ||
morpherRegistry.registerMorpher( new CharMorpher( '\0' ) ); | ||
morpherRegistry.registerMorpher( new ByteMorpher( (byte) 0 ) ); | ||
morpherRegistry.registerMorpher( new ShortMorpher( (short) 0 ) ); | ||
morpherRegistry.registerMorpher( new IntMorpher( 0 ) ); | ||
morpherRegistry.registerMorpher( new LongMorpher( 0 ) ); | ||
morpherRegistry.registerMorpher( new FloatMorpher( 0 ) ); | ||
morpherRegistry.registerMorpher( new DoubleMorpher( 0 ) ); | ||
} | ||
|
||
private MorphUtils() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2006-2007 the original author or authors. | ||
* | ||
* 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 net.sf.ezmorph; | ||
|
||
/** | ||
* Marker interface for morphers.<br> | ||
* All implementations must have a <code>morph( Object value )</code> method | ||
* that returns the appropiate morphed value. | ||
* | ||
* @author Andres Almiray <a href="mailto:[email protected]">[email protected]</a> | ||
*/ | ||
public interface Morpher | ||
{ | ||
/** | ||
* Returns the target Class for conversion. | ||
* | ||
* @return the target Class for conversion. | ||
*/ | ||
Class morphsTo(); | ||
|
||
/** | ||
* Returns true if the Morpher supports conversion from this Class. | ||
* | ||
* @param clazz the source Class | ||
* @return true if clazz is supported by this morpher, false otherwise. | ||
*/ | ||
boolean supports( Class clazz ); | ||
} |
Oops, something went wrong.