http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/ASTranslator.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/ASTranslator.java b/core/src/flex/messaging/io/amf/translator/ASTranslator.java deleted file mode 100644 index b193a7c..0000000 --- a/core/src/flex/messaging/io/amf/translator/ASTranslator.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator; - -import flex.messaging.io.SerializationContext; -import flex.messaging.io.TypeMarshaller; -import flex.messaging.io.amf.translator.decoder.ActionScriptDecoder; -import flex.messaging.io.amf.translator.decoder.DecoderFactory; -import flex.messaging.util.ClassUtil; -import flex.messaging.util.Trace; - -/** - * ASTranslator provides the ability to convert between ASObjects used by - * Flex and Java objects in your application. - */ -public class ASTranslator implements TypeMarshaller -{ - /** {@inheritDoc} */ - public Object createInstance(Object source, Class desiredClass) - { - ActionScriptDecoder decoder = DecoderFactory.getDecoderForShell(desiredClass); - - Object instance = null; - if (decoder.hasShell()) - { - instance = decoder.createShell(source, desiredClass); - } - else - { - instance = ClassUtil.createDefaultInstance(desiredClass, null); - } - - return instance; - } - - /** - * Translate an object to another object of type class. - * obj types should be ASObject, Boolean, String, Double, Date, ArrayList - */ - public Object convert(Object source, Class desiredClass) - { - if (source == null && !desiredClass.isPrimitive()) - { - return null; - } - - SerializationContext serializationContext = SerializationContext.getSerializationContext(); - - ActionScriptDecoder decoder; - if (serializationContext.restoreReferences) - decoder = DecoderFactory.getReferenceAwareDecoder(source, desiredClass); - else - decoder = DecoderFactory.getDecoder(source, desiredClass); - - if (Trace.remote) - { - Trace.trace("Decoder for " + (source == null ? "null" : source.getClass().toString()) + - " with desired " + desiredClass + " is " + decoder.getClass()); - } - - Object result = decoder.decodeObject(source, desiredClass); - return result; - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/TranslationException.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/TranslationException.java b/core/src/flex/messaging/io/amf/translator/TranslationException.java deleted file mode 100644 index e4e41ed..0000000 --- a/core/src/flex/messaging/io/amf/translator/TranslationException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator; - -import flex.messaging.MessageException; - -/** - * - */ -public class TranslationException extends MessageException -{ - static final long serialVersionUID = 3312487017261810877L; - - public TranslationException(String message) - { - super(message); - } - - public TranslationException(String message, Throwable rootCause) - { - super(message); - setRootCause(rootCause); - } - - public TranslationException(String message, String details) - { - super(message); - setDetails(details); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/ActionScriptDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/ActionScriptDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/ActionScriptDecoder.java deleted file mode 100644 index 0ca6c36..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/ActionScriptDecoder.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.SerializationContext; - -import java.util.Calendar; -import java.util.Date; - -/** - * Decode an ActionScript object (of some type) to a Java object (of some type). - * - * - */ -public abstract class ActionScriptDecoder -{ - /** - * Does this type have a placeholder shell? - * @return boolean true if there is a placeholder shell - */ - public boolean hasShell() - { - return false; - } - - /** - * Used for calls only interested in creating a placeholder shell for a type. - * @param encodedObject the encoded object - * @param desiredClass the desired class for the decoded object - * @return Object the shell placeholder object - */ - public Object createShell(Object encodedObject, Class desiredClass) - { - return null; - } - - /** - * Used by calls to decode an object has a shell placeholder. - * @param shell the placeholder shell - * @param encodedObject the encoded object - * @param desiredClass the desired class for the decoded object - * @return Object the decoded object - */ - public abstract Object decodeObject(Object shell, Object encodedObject, Class desiredClass); - - /** - * Used by calls wanted to decode an object. If the decoder requires a place holder shell one is created - * and then the encodedObject is decoded to fill the object shell. - * @param encodedObject the encoded object - * @param desiredClass the desire class for the decoded object - * @return Object the decoded object - */ - public Object decodeObject(Object encodedObject, Class desiredClass) - { - Object shell = null; - - if (hasShell()) - { - shell = createShell(encodedObject, desiredClass); - } - - return decodeObject(shell, encodedObject, desiredClass); - } - - protected boolean canUseByReference(Object o) - { - if (o == null) - return false; - - else if (o instanceof String) - return false; - - else if (o instanceof Number) - return false; - - else if (o instanceof Boolean) - return false; - - else if (o instanceof Date) - { - return SerializationContext.getSerializationContext().supportDatesByReference; - } - - else if (o instanceof Calendar) - return false; - - else if (o instanceof Character) - return false; - - return true; - } - - protected static Object getDefaultPrimitiveValue(Class type) - { - if (type == Boolean.TYPE) - return Boolean.FALSE; - else if (type == Integer.TYPE) - return new Integer(0); - else if (type == Double.TYPE) - return new Double(0); - else if (type == Long.TYPE) - return new Long(0); - else if (type == Float.TYPE) - return new Float(0); - else if (type == Character.TYPE) - return new Character(Character.MIN_VALUE); - else if (type == Short.TYPE) - return new Short((short)0); - else if (type == Byte.TYPE) - return new Byte((byte)0); - - return null; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/ArrayDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/ArrayDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/ArrayDecoder.java deleted file mode 100644 index 8563504..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/ArrayDecoder.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.SerializationContext; -import flex.messaging.io.amf.translator.TranslationException; - -import java.lang.reflect.Array; -import java.util.Collection; - -/** - * - * Decodes native Java Array, java.util.Collection, or - * java.lang.String (to char[]) instances to a native - * Java Array instance with desired component type. - * - * This class does not handle the case where the source - * encodedObject is modified while decoding. - */ -public class ArrayDecoder extends ActionScriptDecoder -{ - @Override public boolean hasShell() - { - return true; - } - - @Override public Object createShell(Object encodedObject, Class desiredClass) - { - Class<?> arrayElementClass = desiredClass.getComponentType(); - - int size = 10; - - // If we have an encodedObject as a source then we check it's size to optimize - // array creation. We may have been called by - if (encodedObject != null) - { - if (encodedObject.getClass().isArray()) - { - size = Array.getLength(encodedObject); - } - else if (encodedObject instanceof Collection) - { - size = ((Collection<?>)encodedObject).size(); - } - else if (encodedObject instanceof String) - { - size = ((String)encodedObject).length(); - } - else - { - TranslationException ex = new TranslationException("Could not create Array " + arrayElementClass); - ex.setCode("Server.Processing"); - throw ex; - } - } - - Object shell = Array.newInstance(arrayElementClass, size); - return shell; - } - - @Override public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - if (shell == null || encodedObject == null) - return null; - - Class<?> arrayElementClass = desiredClass.getComponentType(); - - if (encodedObject instanceof Collection) - return decodeArray(shell, (Collection<?>)encodedObject, arrayElementClass); - - if (encodedObject.getClass().isArray()) - return decodeArray(shell, encodedObject, arrayElementClass); - - if (encodedObject instanceof String && isCharacter(arrayElementClass)) - return decodeArray(shell, (String)encodedObject, arrayElementClass); - - return null; // FIXME: Throw an exception! - } - - protected Object decodeArray(Object shellArray, String string, Class arrayElementClass) - { - if (char.class.equals(arrayElementClass)) - return string.toCharArray(); - - if (Character.class.equals(arrayElementClass)) - { - char[] temp = string.toCharArray(); - Character[] charArray= new Character[temp.length]; - for (int i = 0; i < temp.length; i++) - charArray[i] = Character.valueOf(temp[i]); - return charArray; - } - - return null; - } - - protected Object decodeArray(Object shellArray, Collection collection, Class arrayElementClass) - { - return decodeArray(shellArray, collection.toArray(), arrayElementClass); - } - - protected Object decodeArray(Object shellArray, Object array, Class arrayElementClass) - { - Object encodedValue = null; - Object decodedValue = null; - - int n = 0; - int len = Array.getLength(array); - - for (int i = 0; i < len; i++) - { - encodedValue = Array.get(array, i); - - if (encodedValue == null) - { - Array.set(shellArray, n, null); - } - else - { - // We may need to honor our loose-typing rules for individual types as, - // unlike a Collection, an Array has a fixed element type. We'll use our handy - // decoder suite again to find us the right decoder... - ActionScriptDecoder decoder; - if (SerializationContext.getSerializationContext().restoreReferences) - decoder = DecoderFactory.getReferenceAwareDecoder(encodedValue, arrayElementClass); - else - decoder = DecoderFactory.getDecoder(encodedValue, arrayElementClass); - - decodedValue = decoder.decodeObject(encodedValue, arrayElementClass); - - try - { - Array.set(shellArray, n, decodedValue); - } - catch (IllegalArgumentException ex) - { - // FIXME: At least log this as a error... - // TODO: Should we report a failed Array element set? - // Perhaps the action here could be configurable on the translation context? - Array.set(shellArray, n, null); - } - } - n++; - } - - return shellArray; - } - - private boolean isCharacter(Class<?> classType) - { - return Character.class.equals(classType) || char.class.equals(classType); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/BooleanDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/BooleanDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/BooleanDecoder.java deleted file mode 100644 index ae3e79d..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/BooleanDecoder.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -/** - * Translates a java.lang.Boolean or java.lang.String instances - * into a java.lang.Boolean instance. - * <p> - * Note that for Strings, only "true" - * will be (case insensitively) converted to a true Boolean value. All other - * values will be interpreted as false. - * </p> - * - * - */ -public class BooleanDecoder extends ActionScriptDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - Object result = null; - - if (encodedObject == null) - { - result = Boolean.FALSE; - } - else if (encodedObject instanceof Boolean) - { - result = encodedObject; - } - else if (encodedObject instanceof String) - { - String str = (String)encodedObject; - result = Boolean.valueOf(str); - } - else - { - DecoderFactory.invalidType(encodedObject, desiredClass); - } - - return result; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/CalendarDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/CalendarDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/CalendarDecoder.java deleted file mode 100644 index 285775b..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/CalendarDecoder.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import java.util.Calendar; -import java.util.Date; - -/** - * Converts instances of java.util.Date, java.util.Calendar, and - * java.lang.Number to instances of java.util.Calendar. If the incoming - * object was not a Calendar, we create a new Calendar instance using the - * default timezone and locale. - * - * If the incoming type was an AMF 3 Date we remember the translation - * to Calendar in our list of known objects as Dates are considered - * complex objects and can be sent by reference. We want to retain - * pointers to Date instances in our representation of an ActionScript - * object graph. - * - * - */ -public class CalendarDecoder extends ActionScriptDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - Object result = null; - - if (encodedObject instanceof Date) - { - Calendar calendar = Calendar.getInstance(); - calendar.setTime((Date)encodedObject); - result = calendar; - } - else if (encodedObject instanceof Calendar) - { - result = encodedObject; - } - else if (encodedObject instanceof Number) - { - Calendar calendar = Calendar.getInstance(); - Number number = (Number)encodedObject; - calendar.setTimeInMillis(number.longValue()); - result = calendar; - } - else - { - DecoderFactory.invalidType(encodedObject, desiredClass); - } - - - return result; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/CharacterDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/CharacterDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/CharacterDecoder.java deleted file mode 100644 index b58c37f..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/CharacterDecoder.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -/** - * Decode a java.lang.String or java.lang.Character to - * a java.lang.Character instance. - * <p> - * Note that a String must be non-zero length and only the first - * character in the String will be used. - * </p> - * - * - */ -public class CharacterDecoder extends ActionScriptDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - Character result = null; - - if (encodedObject == null) - { - char c = 0; - result = new Character(c); - } - else if (encodedObject instanceof String) - { - String str = (String)encodedObject; - - char[] chars = str.toCharArray(); - - if (chars.length > 0) - { - result = new Character(chars[0]); - } - } - else if (encodedObject instanceof Character) - { - result = (Character)encodedObject; - } - - if (result == null) - { - DecoderFactory.invalidType(encodedObject, desiredClass); - } - - return result; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/CollectionDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/CollectionDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/CollectionDecoder.java deleted file mode 100644 index f733adc..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/CollectionDecoder.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.amf.translator.TranslationException; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * Decodes a java.lang.reflect.Array, java.util.Collection, - * java.lang.String (using toCharArray), to a java.util.Collection - * instance. - * <p> - * If the desired Collection class is an interface then an instance - * of a standard implementation will be created. - * </p> - * <p> - * If java.util.SortedSet is desired, then a java.util.TreeSet will be created. - * </p> - * <p> - * If a java.util.Set is desired, then a java.util.HashSet will be created. - * </p> - * <p> - * If a java.util.List is desired, then a java.util.ArrayList will be created. - * </p> - * <p> - * If a java.util.Collection is desired, then a java.util.ArrayList will be created. - * </p> - * - * @see java.util.Collection - * - * - */ -public class CollectionDecoder extends ActionScriptDecoder -{ - public boolean hasShell() - { - return true; - } - - protected boolean isSuitableCollection(Object encodedObject, Class desiredClass) - { - return (encodedObject instanceof Collection && desiredClass.isAssignableFrom(encodedObject.getClass())); - } - - public Object createShell(Object encodedObject, Class desiredClass) - { - Collection col = null; - - try - { - if (encodedObject != null) - { - if (isSuitableCollection(encodedObject, desiredClass)) - { - col = (Collection)encodedObject; - } - else - { - if (desiredClass.isInterface()) - { - if (List.class.isAssignableFrom(desiredClass)) - { - col = new ArrayList(); - } - else if (SortedSet.class.isAssignableFrom(desiredClass)) - { - col = new TreeSet(); - } - else if (Set.class.isAssignableFrom(desiredClass)) - { - col = new HashSet(); - } - else if (Collection.class.isAssignableFrom(desiredClass)) - { - col = new ArrayList(); - } - } - else - { - col = (Collection)desiredClass.newInstance(); - } - } - } - else - { - col = (Collection)desiredClass.newInstance(); - } - } - catch (Exception e) - { - TranslationException ex = new TranslationException("Could not create Collection " + desiredClass, e); - ex.setCode("Server.Processing"); - throw ex; - } - - if (col == null) - { - DecoderFactory.invalidType(encodedObject, desiredClass); - } - - return col; - } - - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - if (shell == null || encodedObject == null) - return null; - - // Don't decode if we already have a suitable Collection. - if (isSuitableCollection(encodedObject, desiredClass)) - { - return encodedObject; - } - - return decodeCollection((Collection)shell, encodedObject); - } - - protected Collection decodeCollection(Collection collectionShell, Object encodedObject) - { - Object obj = null; - - if (encodedObject instanceof String) - { - encodedObject = ((String)encodedObject).toCharArray(); - } - else if (encodedObject instanceof Collection) - { - encodedObject = ((Collection)encodedObject).toArray(); - } - - int len = Array.getLength(encodedObject); - - for (int i = 0; i < len; i++) - { - obj = Array.get(encodedObject, i); - collectionShell.add(obj); - } - - return collectionShell; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/DateDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/DateDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/DateDecoder.java deleted file mode 100644 index 5aac5cb..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/DateDecoder.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import java.util.Calendar; - -/** - * Converts java.util.Date, java.sql.Date, java.util.Calendar or - * java.lang.Number (via longValue) instances to a java.util.Date, - * taking into consideration the SQL specific java.sql.Date type - * which is required by Hibernate users. - * - * If the incoming type was an AMF 3 Date, we remember the translation - * to Calendar in our list of known objects as Dates are considered - * complex objects and can be sent by reference. We want to retain - * pointers to Date instances in our representation of an ActionScript - * object graph. - * - * - */ -public class DateDecoder extends ActionScriptDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - java.util.Date result = null; - - if (java.sql.Date.class.isAssignableFrom(desiredClass)) - { - if (encodedObject instanceof java.util.Date) - { - java.util.Date date = (java.util.Date)encodedObject; - result = new java.sql.Date(date.getTime()); - } - else if (encodedObject instanceof Calendar) - { - Calendar calendar = (Calendar)encodedObject; - result = new java.sql.Date(calendar.getTimeInMillis()); - } - else if (encodedObject instanceof Number) - { - Number number = (Number)encodedObject; - result = new java.sql.Date(number.longValue()); - } - } - else if (java.sql.Timestamp.class.isAssignableFrom(desiredClass)) - { - if (encodedObject instanceof java.util.Date) - { - java.util.Date date = (java.util.Date)encodedObject; - result = new java.sql.Timestamp(date.getTime()); - } - else if (encodedObject instanceof Calendar) - { - Calendar calendar = (Calendar)encodedObject; - result = new java.sql.Timestamp(calendar.getTimeInMillis()); - } - else if (encodedObject instanceof Number) - { - Number number = (Number)encodedObject; - result = new java.sql.Timestamp(number.longValue()); - } - } - else if (java.sql.Time.class.isAssignableFrom(desiredClass)) - { - if (encodedObject instanceof java.util.Date) - { - java.util.Date date = (java.util.Date)encodedObject; - result = new java.sql.Time(date.getTime()); - } - else if (encodedObject instanceof Calendar) - { - Calendar calendar = (Calendar)encodedObject; - result = new java.sql.Time(calendar.getTimeInMillis()); - } - else if (encodedObject instanceof Number) - { - Number number = (Number)encodedObject; - result = new java.sql.Time(number.longValue()); - } - } - else if (java.util.Date.class.isAssignableFrom(desiredClass)) - { - if (encodedObject instanceof java.util.Date) - { - result = (java.util.Date)encodedObject; - } - else if (encodedObject instanceof Calendar) - { - Calendar calendar = (Calendar)encodedObject; - result = calendar.getTime(); - } - else if (encodedObject instanceof Number) - { - Number number = (Number)encodedObject; - result = new java.util.Date(number.longValue()); - } - } - - if (result == null) - { - DecoderFactory.invalidType(encodedObject, desiredClass); - } - - return result; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/DecoderFactory.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/DecoderFactory.java b/core/src/flex/messaging/io/amf/translator/decoder/DecoderFactory.java deleted file mode 100644 index 71f366b..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/DecoderFactory.java +++ /dev/null @@ -1,378 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.TypeMarshallingContext; -import flex.messaging.io.amf.ASObject; -import flex.messaging.io.amf.translator.TranslationException; - -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.Map; - -/** - * Utility class that tries to find an ActionScriptDecoder that will be able - * to convert the encoded object into an instance of the desired class. - * - * @see ActionScriptDecoder - * - * - */ -public class DecoderFactory -{ - // The identity transform - private static final NativeDecoder nativeDecoder = new NativeDecoder(); - - // Special null transform, always returns null - private static final NullDecoder nullDecoder = new NullDecoder(); - - // Simple types (do not have the concept of a creating a placeholder or 'shell') - private static final NumberDecoder numberDecoder = new NumberDecoder(); - private static final StringDecoder stringDecoder = new StringDecoder(); - private static final BooleanDecoder booleanDecoder = new BooleanDecoder(); - private static final CharacterDecoder characterDecoder = new CharacterDecoder(); - - // Historically dates are simple types, but they are now considered complex - // via AMF 3 (though they can not have empty placeholders or 'shells') - private static final DateDecoder dateDecoder = new DateDecoder(); - private static final CalendarDecoder calendarDecoder = new CalendarDecoder(); - - // Complex types (can also be used to create empty placeholders to be populated at decode time) - private static final ArrayDecoder arrayDecoder = new ArrayDecoder(); - private static EnumDecoder enumDecoder = new EnumDecoder(); - private static final MapDecoder mapDecoder = new MapDecoder(); - private static final CollectionDecoder collectionDecoder = new CollectionDecoder(); - private static final TypedObjectDecoder typedObjectDecoder = new TypedObjectDecoder(); - - // If we require references to be tracked and restored, we use deep, recursive decoders - // however these are very expensive in terms of processing time - private static final ArrayDecoder deepArrayDecoder = new ReferenceAwareArrayDecoder(); - private static final MapDecoder deepMapDecoder = new ReferenceAwareMapDecoder(); - private static final CollectionDecoder deepCollectionDecoder = new ReferenceAwareCollectionDecoder(); - private static final TypedObjectDecoder deepTypedObjectDecoder = new ReferenceAwareTypedObjectDecoder(); - - - /** - * A simple method for obtaining a placeholder or 'shell' object that will be subsequently - * populated by potentially some other deserializer. Decoders contain special logic to implement well - * known Collections interfaces such as java.util.Map, java.util.Set, etc - * and also contain utilities to create native Arrays, so this functionality has been - * made available to other classes besides decoders. - * - * @param desiredClass the desire class for the decoded object - * @return The <tt>ActionScriptDecoder</tt> to use for instances of the desired class. - */ - public static ActionScriptDecoder getDecoderForShell(Class desiredClass) - { - if (desiredClass == null) - return nullDecoder; - - if (Collection.class.isAssignableFrom(desiredClass)) - return collectionDecoder; - - if (Map.class.isAssignableFrom(desiredClass)) - return mapDecoder; - - if (desiredClass.isArray()) - return arrayDecoder; - - if (desiredClass.isEnum()) - return enumDecoder; - - return nativeDecoder; - } - - /** - * This is a faster implementation than getReferenceAwareDecoder as it doesn't track - * or care about restoring references in the event that an instance was converted to - * a new type. Since the all MessageDeserializes now convert directly to strongly - * typed instances it is less likely that references will need to be tracked. - * - * A case where a reference may have needed to be tracked would be that a Class has - * several properties of a subtype of Object[] (i.e. Array), Collection or Map but these - * properties were not of the default type returned by the MessageDeserializer, that - * is ArrayList or HashMap, and that each property had the potential to point to the same - * instance. If we didn't track the reference, then the conversion to the subtype - * (say HashMap -> TreeMap) would effectively clone these instances. - * - * @param encodedObject the encoded object - * @param desiredClass the desire class for the decoded object - * @return The <tt>ActionScriptDecoder</tt> to use for instances of the desired class. - */ - public static ActionScriptDecoder getDecoder(Object encodedObject, Class desiredClass) - { - if (encodedObject != null) - { - // If we already have a suitable instance, return immediately! - if (desiredClass.isAssignableFrom(encodedObject.getClass())) - return nativeDecoder; - - if (String.class.equals(desiredClass)) - return stringDecoder; - - // We check Number and Boolean here as well as the encodedObejct == null case - // as they're very common property types... - if (isNumber(desiredClass)) - return numberDecoder; - - if (isBoolean(desiredClass)) - return booleanDecoder; - - if (Collection.class.isAssignableFrom(desiredClass)) - return collectionDecoder; - - if (Map.class.isAssignableFrom(desiredClass)) - return mapDecoder; - - if (desiredClass.isArray()) - return arrayDecoder; - - // Special Case - we have a typed ASObject and we're expecting it to - // be converted into a new class... this would be an usual situation - // for Mistral, however, since we now create strongly typed instances - // from a stream - if (isTypedObject(encodedObject)) - return typedObjectDecoder; - - if (Date.class.isAssignableFrom(desiredClass)) - return dateDecoder; - - if (Calendar.class.isAssignableFrom(desiredClass)) - return calendarDecoder; - } - - // Null may have been sent to a primitive Java type, in which case - // we create a default value, such as new Integer(0) for int rather - // than create a null Integer() instance... - if (isNumber(desiredClass)) - return numberDecoder; - - if (isBoolean(desiredClass)) - return booleanDecoder; - - if (isCharacter(desiredClass)) - return characterDecoder; - - if (encodedObject == null) - return nullDecoder; - - if (desiredClass.isEnum()) - return enumDecoder; - - DecoderFactory.invalidType(encodedObject, desiredClass); - - // Never reached... - return nativeDecoder; - } - - /** - * A considerably slower entry point for decoders as it both changes the - * assumptions we can make about type translation and also keeps track of - * a lot of information when a complex type is converted. - * - * @param encodedObject the encoded object - * @param desiredClass the desire class for the decoded object - * @return The <tt>ActionScriptDecoder</tt> to use for instances of the desired class. - */ - public static ActionScriptDecoder getReferenceAwareDecoder(Object encodedObject, Class desiredClass) - { - if (encodedObject != null) - { - if (String.class.equals(desiredClass)) - return stringDecoder; - - // We check Number and Boolean here as well as the encodedObejct == null case - // as they're very common property types... - if (isNumber(desiredClass)) - return numberDecoder; - - if (isBoolean(desiredClass)) - return booleanDecoder; - - if (Collection.class.isAssignableFrom(desiredClass)) - return deepCollectionDecoder; - - if (Map.class.isAssignableFrom(desiredClass)) - return deepMapDecoder; - - if (desiredClass.isArray()) - return deepArrayDecoder; - - // Special Case - we have a typed ASObject and we're expecting it to - // be converted into a new class... this would be an usual situation - // for Mistral, however, since we now create strongly typed instances - // from a stream. - if (isTypedObject(encodedObject)) - return deepTypedObjectDecoder; - - if (Date.class.isAssignableFrom(desiredClass)) - return dateDecoder; - - if (Calendar.class.isAssignableFrom(desiredClass)) - return calendarDecoder; - - if (isCharacter(desiredClass)) - return characterDecoder; - - // Last resort, just try and return the object undecoded if it's the right type - // We do this last because at this stage if it is a complex object we won't catch - // any Typed Object translations for properties on this type... - if (desiredClass.isAssignableFrom(encodedObject.getClass())) - return nativeDecoder; - } - - // Null may have been sent to a primitive Java type, in which case - // we create a default value, such as new Integer(0) for int rather than create - // a null Integer() instance... - if (isNumber(desiredClass)) - return numberDecoder; - - if (isBoolean(desiredClass)) - return booleanDecoder; - - if (isCharacter(desiredClass)) - return characterDecoder; - - if (encodedObject == null) - return nullDecoder; - - DecoderFactory.invalidType(encodedObject, desiredClass); - - // Never reached... - return nativeDecoder; - } - - public static boolean isNumber(Class desiredClass) - { - boolean isNum = false; - - if (desiredClass.isPrimitive()) - { - if (desiredClass.equals(Integer.TYPE) - || desiredClass.equals(Double.TYPE) - || desiredClass.equals(Long.TYPE) - || desiredClass.equals(Float.TYPE) - || desiredClass.equals(Short.TYPE) - || desiredClass.equals(Byte.TYPE)) - { - isNum = true; - } - } - else if (Number.class.isAssignableFrom(desiredClass)) - { - isNum = true; - } - - return isNum; - } - - public static boolean isCharacter(Class desiredClass) - { - boolean isChar = false; - - if (desiredClass.isPrimitive() && desiredClass.equals(Character.TYPE)) - { - isChar = true; - } - else if (desiredClass.equals(Character.class)) - { - isChar = true; - } - - return isChar; - } - - public static boolean isBoolean(Class desiredClass) - { - boolean isBool = false; - - if (desiredClass.isPrimitive() && desiredClass.equals(Boolean.TYPE)) - { - isBool = true; - } - else if (desiredClass.equals(Boolean.class)) - { - isBool = true; - } - - return isBool; - } - - public static boolean isCharArray(Class desiredClass) - { - boolean isCharArray = false; - - if (desiredClass.isArray()) - { - Class type = desiredClass.getComponentType(); - if (type != null && type.equals(Character.TYPE)) - { - isCharArray = true; - } - } - - return isCharArray; - } - - public static boolean isTypedObject(Object encodedObject) - { - boolean typed = false; - - if (encodedObject instanceof ASObject) - { - typed = TypeMarshallingContext.getType(encodedObject) != null; - } - - return typed; - } - - public static void invalidType(Object object, Class desiredClass) - { - String inputType = null; - - if (object != null) - { - inputType = object.getClass().getName(); - } - - StringBuffer message = new StringBuffer("Cannot convert "); - if (inputType != null) - { - message.append("type ").append(inputType).append(" "); - } - - if (object != null && (object instanceof String - || object instanceof Number - || object instanceof Boolean - || object instanceof Date)) - { - message.append("with value '").append(object.toString()).append("' "); - } - else if (object instanceof ASObject) - { - ASObject aso = (ASObject)object; - message.append("with remote type specified as '").append(aso.getType()).append("' "); - } - - message.append("to an instance of ").append(desiredClass.toString()); - - TranslationException ex = new TranslationException(message.toString()); - ex.setCode("Client.Message.Deserialize.InvalidType"); - throw ex; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/EnumDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/EnumDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/EnumDecoder.java deleted file mode 100644 index 926ae26..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/EnumDecoder.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -/** - * Decode an ActionScript enumeration object (generally a string) to a Java enum. - * - */ -public class EnumDecoder extends ActionScriptDecoder -{ - /** - * Does this type have a placeholder shell? - * True for Enumerations. - * @return boolean true if it has a shell - */ - @Override - public boolean hasShell() - { - return true; - } - - /** - * Create the enumeration object based on the string. - * - * @param encodedObject the object - * @param desiredClass ignored - * @return Object the created shell object - */ - @Override - public Object createShell(Object encodedObject, Class desiredClass) - { - if (encodedObject instanceof Enum) - return encodedObject; - - if (encodedObject == null) - return null; - - @SuppressWarnings("unchecked") - Enum value = Enum.valueOf(desiredClass, encodedObject.toString()); - return value; - } - - /** - * Decode an object. - * For the enum type, the createShell has already done the work, so we just - * return the shell itself. - * @param shell the shell object - * @param encodedObject the encodedObject - * @param desiredClass the desired class for decoded object - * @return Object the decoded object - */ - @Override - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - return (shell == null || encodedObject == null)? null : shell; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/MapDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/MapDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/MapDecoder.java deleted file mode 100644 index 60cbe15..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/MapDecoder.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.amf.translator.TranslationException; - -import java.util.HashMap; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; - -/** - * Decodes an ActionScript object to a Java Map. - * - * - */ -public class MapDecoder extends ActionScriptDecoder -{ - public boolean hasShell() - { - return true; - } - - protected boolean isSuitableMap(Object encodedObject, Class desiredClass) - { - return (encodedObject != null && encodedObject instanceof Map && desiredClass.isAssignableFrom(encodedObject.getClass())); - } - - public Object createShell(Object encodedObject, Class desiredClass) - { - try - { - if (isSuitableMap(encodedObject, desiredClass)) - { - return encodedObject; - } - else - { - if (desiredClass.isInterface() || !Map.class.isAssignableFrom(desiredClass)) - { - if (SortedMap.class.isAssignableFrom(desiredClass)) - { - return new TreeMap(); - } - else - { - return new HashMap(); - } - } - else - { - return desiredClass.newInstance(); - } - } - } - catch (Exception e) - { - TranslationException ex = new TranslationException("Could not create Map " + desiredClass, e); - ex.setCode("Server.Processing"); - throw ex; - } - } - - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - if (shell == null || encodedObject == null) - return null; - - // Don't decode if we already have a suitable Map. - if (isSuitableMap(encodedObject, desiredClass)) - { - return encodedObject; - } - - return decodeMap((Map)shell, (Map)encodedObject); - } - - protected Map decodeMap(Map shell, Map map) - { - if (shell != map) - shell.putAll(map); - else - shell = map; - - return shell; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/NativeDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/NativeDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/NativeDecoder.java deleted file mode 100644 index 8f9a775..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/NativeDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -/** - * Decodes an ActionScript native object to a Java native object. - * - * - */ -public class NativeDecoder extends ActionScriptDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - return encodedObject; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/NullDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/NullDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/NullDecoder.java deleted file mode 100644 index 26e1b7d..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/NullDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -/** - * - */ -public class NullDecoder extends ActionScriptDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - return null; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/NumberDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/NumberDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/NumberDecoder.java deleted file mode 100644 index 90ce221..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/NumberDecoder.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import flex.messaging.io.SerializationContext; - -/** - * Decode an ActionScript type (a string or a double) to a Java number (of any type). - * - * - */ -public class NumberDecoder extends ActionScriptDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - Object result = null; - - if (encodedObject != null && encodedObject instanceof String) - { - String str = ((String)encodedObject).trim(); - try - { - // Short-ciruit String -> BigInteger,BigDecimal to avoid loss - // of precision that occurs if we go through Double - if (!SerializationContext.getSerializationContext().legacyBigNumbers) - { - if (BigInteger.class.equals(desiredClass)) - { - result = new BigInteger(str); - return result; - } - else if (BigDecimal.class.equals(desiredClass)) - { - result = new BigDecimal(str); - return result; - } - } - - Double dbl = new Double(str); - encodedObject = dbl; - } - catch (NumberFormatException nfe) - { - DecoderFactory.invalidType(encodedObject, desiredClass); - } - } - - if (encodedObject instanceof Number || encodedObject == null) - { - Double dbl; - - if (desiredClass.isPrimitive()) - { - if (encodedObject == null) - dbl = new Double(0); - else - dbl = new Double(((Number)encodedObject).doubleValue()); - - if (Object.class.equals(desiredClass) || Double.TYPE.equals(desiredClass)) - result = dbl; - else if (Integer.TYPE.equals(desiredClass)) - result = new Integer(dbl.intValue()); - else if (Long.TYPE.equals(desiredClass)) - result = new Long(dbl.longValue()); - else if (Float.TYPE.equals(desiredClass)) - result = new Float(dbl.floatValue()); - else if (Short.TYPE.equals(desiredClass)) - result = new Short(dbl.shortValue()); - else if (Byte.TYPE.equals(desiredClass)) - result = new Byte(dbl.byteValue()); - } - else if (encodedObject != null) - { - dbl = new Double(((Number)encodedObject).doubleValue()); - - if (Object.class.equals(desiredClass) || Number.class.equals(desiredClass) || - Double.class.equals(desiredClass)) - result = dbl; - else if (Integer.class.equals(desiredClass)) - result = dbl.isNaN() ? null : new Integer(dbl.intValue()); - else if (Long.class.equals(desiredClass)) - result = dbl.isNaN() ? null : new Long(dbl.longValue()); - else if (Float.class.equals(desiredClass)) - result = new Float(dbl.floatValue()); - else if (Short.class.equals(desiredClass)) - result = dbl.isNaN() ? null : new Short(dbl.shortValue()); - else if (Byte.class.equals(desiredClass)) - result = dbl.isNaN() ? null : new Byte(dbl.byteValue()); - else if (BigDecimal.class.equals(desiredClass)) - { - // Though this is a little slower than using the - // double constructor for BigDecimal, it yields a rounded - // result which is more predicable (see the Javadoc for - // BigDecimal and bug: 182378). - if (SerializationContext.getSerializationContext().legacyBigNumbers) - result = new BigDecimal(dbl.doubleValue()); - else - result = new BigDecimal(String.valueOf(dbl)); - } - else if (BigInteger.class.equals(desiredClass)) - { - // Must have no special characters or whitespace - String val = null; - long l = dbl.longValue(); - if (l > Integer.MAX_VALUE) - { - Long lo = new Long(dbl.longValue()); - val = lo.toString().toUpperCase(); - int suffix = val.indexOf('L'); - if (suffix != -1) - val = val.substring(0, suffix); - } - else - { - Integer i = new Integer(dbl.intValue()); - val = i.toString(); - } - result = new BigInteger(val.trim()); - } - } - else - { - result = null; - } - } - else - { - DecoderFactory.invalidType(encodedObject, desiredClass); - } - - return result; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareArrayDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareArrayDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareArrayDecoder.java deleted file mode 100644 index 7101cfe..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareArrayDecoder.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import java.lang.reflect.Array; -import java.util.Collection; - -import flex.messaging.io.TypeMarshallingContext; - -/** - * - */ -public class ReferenceAwareArrayDecoder extends ArrayDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - if (shell == null || encodedObject == null) - return null; - - Class arrayElementClass = desiredClass.getComponentType(); - - if (encodedObject instanceof Collection) - { - return decodeArray(shell, (Collection)encodedObject, arrayElementClass); - } - else if (encodedObject.getClass().isArray()) - { - return decodeArray(shell, encodedObject, arrayElementClass); - } - else if (encodedObject instanceof String && Character.class.equals(arrayElementClass)) - { - return decodeArray(shell, (String)encodedObject, arrayElementClass); - } - else - { - return shell; - } - } - - protected Object decodeArray(Object shellArray, Collection collection, Class arrayElementClass) - { - Object[] array = collection.toArray(); - TypeMarshallingContext.getTypeMarshallingContext().getKnownObjects().put(array, shellArray); - return decodeArray(shellArray, array, arrayElementClass); - } - - protected Object decodeArray(Object shellArray, Object array, Class arrayElementClass) - { - Object encodedValue = null; - Object decodedValue = null; - TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); - - ActionScriptDecoder decoder = null; - int n = 0; - int len = Array.getLength(array); - for (int i = 0; i < len; i++) - { - encodedValue = Array.get(array, i); - - if (encodedValue == null) - { - Array.set(shellArray, n, null); - } - else - { - //Check whether we need to restore a client - //side reference to a known object - Object ref = null; - - if (canUseByReference(encodedValue)) - ref = context.getKnownObjects().get(encodedValue); - - if (ref == null) - { - decoder = DecoderFactory.getReferenceAwareDecoder(encodedValue, arrayElementClass); - decodedValue = decoder.decodeObject(encodedValue, arrayElementClass); - - if (canUseByReference(decodedValue)) - { - context.getKnownObjects().put(encodedValue, decodedValue); - } - } - else - { - decodedValue = ref; - } - - try - { - Array.set(shellArray, n, decodedValue); - } - catch (IllegalArgumentException ex) - { - Array.set(shellArray, n, null); - } - } - n++; - } - - return shellArray; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareCalendarDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareCalendarDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareCalendarDecoder.java deleted file mode 100644 index e9d6dfb..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareCalendarDecoder.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.SerializationContext; -import flex.messaging.io.TypeMarshallingContext; - -/** - * - */ -public class ReferenceAwareCalendarDecoder extends CalendarDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - Object result = super.decodeObject(shell, encodedObject, desiredClass); - - // Only AMF 3 Dates can be sent by reference so we only - // need to remember this translation to re-establish pointers - // to the encodedObject if the incoming type was a Date object. - if (result != null - && SerializationContext.getSerializationContext().supportDatesByReference - && encodedObject instanceof java.util.Date) - { - TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); - context.getKnownObjects().put(encodedObject, result); - } - - return result; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareCollectionDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareCollectionDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareCollectionDecoder.java deleted file mode 100644 index 60b5681..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareCollectionDecoder.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.TypeMarshallingContext; - -import java.util.Collection; -import java.lang.reflect.Array; - -/** - * A special version of CollectionDecoder than runs a new decoder - * over every item before it is added to the decoded collection - * to restore references to any instances that may have undergone - * translation to another type. - * - * Note that tracking references is an expensive exercise and will - * scale poorly with larger amounts of data.` - * - * - */ -public class ReferenceAwareCollectionDecoder extends CollectionDecoder -{ - /** - * We want to iterate through all of the contents of the Collection - * to check for references that need to be restored and translations - * that may still be required (in the case of typed ASObjects). - * - * Return false to ensure we create a new collection and copy - * all of the contents. - */ - protected boolean isSuitableCollection(Object encodedObject, Class desiredClass) - { - return false; - } - - protected Collection decodeCollection(Collection shell, Object encodedObject) - { - Collection decodedCollection = shell; - Object decodedObject = null; - Object obj = null; - - TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); - ActionScriptDecoder decoder = null; - - if (encodedObject instanceof String) - { - encodedObject = ((String)encodedObject).toCharArray(); - } - else - { - if (encodedObject instanceof Collection) - { - encodedObject = ((Collection)encodedObject).toArray(); - } - - context.getKnownObjects().put(encodedObject, shell); - } - - int len = Array.getLength(encodedObject); - - for (int i = 0; i < len; i++) - { - obj = Array.get(encodedObject, i); - - if (obj == null) - { - decodedCollection.add(null); - } - else - { - //Check whether we need to restore a client - //side reference to a known object - Object ref = null; - - if (canUseByReference(obj)) - ref = context.getKnownObjects().get(obj); - - if (ref == null) - { - decoder = DecoderFactory.getReferenceAwareDecoder(obj, obj.getClass()); - decodedObject = decoder.decodeObject(obj, obj.getClass()); - - if (canUseByReference(decodedObject)) - { - context.getKnownObjects().put(obj, decodedObject); - } - } - else - { - decodedObject = ref; - } - - decodedCollection.add(decodedObject); - } - } - - return decodedCollection; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareDateDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareDateDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareDateDecoder.java deleted file mode 100644 index 849a85e..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareDateDecoder.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.SerializationContext; -import flex.messaging.io.TypeMarshallingContext; - -/** - * - */ -public class ReferenceAwareDateDecoder extends DateDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - Object result = super.decodeObject(shell, encodedObject, desiredClass); - - // Only AMF 3 Dates can be sent by reference so we only - // need to remember this translation to re-establish pointers - // to the encodedObject if the incoming type was a Date object. - if (result != null - && SerializationContext.getSerializationContext().supportDatesByReference - && encodedObject instanceof java.util.Date) - { - TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); - context.getKnownObjects().put(encodedObject, result); - } - - return result; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareMapDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareMapDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareMapDecoder.java deleted file mode 100644 index 85dcb85..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareMapDecoder.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import flex.messaging.io.TypeMarshallingContext; - -import java.util.Map; -import java.util.Iterator; - -/** - * - */ -public class ReferenceAwareMapDecoder extends MapDecoder -{ - public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) - { - if (shell == null) return null; - - Map shellMap = (Map)shell; - Map encodedMap = (Map)encodedObject; - - TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); - context.getKnownObjects().put(encodedObject, shell); - - ActionScriptDecoder decoder = null; - Object key = null; - Object value = null; - Object decodedValue = null; - for (Iterator keys = encodedMap.keySet().iterator(); keys.hasNext();) - { - key = keys.next(); - value = encodedMap.get(key); - - if (value == null) - { - shellMap.put(key, null); - continue; - } - - //Check whether we need to restore a client - //side reference to a known object - Object ref = null; - - if (canUseByReference(value)) - ref = context.getKnownObjects().get(value); - - if (ref == null) - { - decoder = DecoderFactory.getReferenceAwareDecoder(value, value.getClass()); - decodedValue = decoder.decodeObject(value, value.getClass()); - - if (canUseByReference(decodedValue)) - { - context.getKnownObjects().put(value, decodedValue); - } - } - else - { - decodedValue = ref; - } - - shellMap.put(key, decodedValue); - } - - return shellMap; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareTypedObjectDecoder.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareTypedObjectDecoder.java b/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareTypedObjectDecoder.java deleted file mode 100644 index 4d38d38..0000000 --- a/core/src/flex/messaging/io/amf/translator/decoder/ReferenceAwareTypedObjectDecoder.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package flex.messaging.io.amf.translator.decoder; - -import java.util.Iterator; -import java.util.List; - -import flex.messaging.io.PropertyProxy; -import flex.messaging.io.PropertyProxyRegistry; -import flex.messaging.io.TypeMarshallingContext; - -import flex.messaging.io.amf.translator.TranslationException; - -/** - * - */ -public class ReferenceAwareTypedObjectDecoder extends TypedObjectDecoder -{ - protected Object decodeTypedObject(Object bean, Object encodedObject) - { - TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); - context.getKnownObjects().put(encodedObject, bean); - - PropertyProxy beanProxy = PropertyProxyRegistry.getProxy(bean); - PropertyProxy encodedProxy = PropertyProxyRegistry.getProxy(encodedObject); - - List propertyNames = beanProxy.getPropertyNames(bean); - if (propertyNames != null) - { - Iterator it = propertyNames.iterator(); - while (it.hasNext()) - { - String propName = (String)it.next(); - - Class wClass = beanProxy.getType(bean, propName); - - // get property value from encodedObject - Object value = encodedProxy.getValue(encodedObject, propName); - - Object decodedObject = null; - try - { - if (value != null) - { - //Check whether we need to restore a client - //side reference to a known object - Object ref = null; - - if (canUseByReference(value)) - ref = context.getKnownObjects().get(value); - - if (ref == null) - { - ActionScriptDecoder decoder = DecoderFactory.getReferenceAwareDecoder(value, wClass); - decodedObject = decoder.decodeObject(value, wClass); - - if (canUseByReference(decodedObject)) - { - context.getKnownObjects().put(value, decodedObject); - } - } - else - { - decodedObject = ref; - } - } - - // TODO: Perhaps we could update NumberDecoder, CharacterDecoder and - // BooleanDecoder to do this for us? - if (decodedObject == null && wClass.isPrimitive()) - { - decodedObject = getDefaultPrimitiveValue(wClass); - } - - beanProxy.setValue(bean, propName, decodedObject); - } - catch (Exception e) - { - TranslationException ex = new TranslationException("Could not set object " + decodedObject + " on " + bean.getClass() + "'s " + propName); - ex.setCode("Server.Processing"); - ex.setRootCause(e); - throw ex; - } - } - } - - return bean; - } - - -}