Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.amfx;
import flex.messaging.MessageException;
import flex.messaging.io.amf.ASObject;
import flex.messaging.io.amf.AbstractAmfOutput;
import flex.messaging.io.amf.Amf3Types;
import flex.messaging.io.PagedRowSet;
import flex.messaging.io.PropertyProxy;
import flex.messaging.io.PropertyProxyRegistry;
import flex.messaging.io.SerializationContext;
import flex.messaging.io.SerializationDescriptor;
import flex.messaging.io.StatusInfoProxy;
import flex.messaging.io.amf.TraitsInfo;
import flex.messaging.io.amf.Amf3Output;
import flex.messaging.io.ArrayCollection;
import flex.messaging.io.BeanProxy;
import flex.messaging.util.Hex;
import flex.messaging.util.Trace;
import org.w3c.dom.Document;
import java.io.IOException;
import java.io.Externalizable;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.sql.RowSet;
/**
* Serializes Java types to ActionScript 3 types via AMFX, an XML
* based representation of AMF 3.
*
* XML is formatted using using UTF-8 encoding.
*
*
* @see AmfxMessageSerializer
* @see AmfxInput
*/
public class AmfxOutput extends AbstractAmfOutput implements AmfxTypes
{
/**
* A mapping of object instances to their serialization numbers
* for storing object references on the stream.
*/
protected IdentityHashMap objectTable;
protected HashMap traitsTable;
protected HashMap stringTable;
public AmfxOutput(SerializationContext context)
{
super(context);
objectTable = new IdentityHashMap(64);
traitsTable = new HashMap(10);
stringTable = new HashMap(64);
}
public void reset()
{
super.reset();
objectTable.clear();
traitsTable.clear();
stringTable.clear();
}
/**
* Creates a new Amf3Output instance which is initialized with the
* current SerializationContext, OutputStream and debug trace settings
* to switch the version of the AMF protocol mid-stream.
*/
protected Amf3Output createAMF3Output()
{
return new Amf3Output(context);
}
//
// java.io.ObjectOutput IMPLEMENTATIONS
//
public void writeObject(Object o) throws IOException
{
if (o == null)
{
writeAMFNull();
return;
}
if (!context.legacyExternalizable && o instanceof Externalizable)
{
writeCustomObject(o);
}
else if (o instanceof String || o instanceof Character)
{
String s = o.toString();
writeString(s);
}
else if (o instanceof Number)
{
if (o instanceof Integer || o instanceof Short || o instanceof Byte)
{
int i = ((Number)o).intValue();
writeAMFInt(i);
}
else if (!context.legacyBigNumbers &&
(o instanceof BigInteger || o instanceof BigDecimal))
{
// Using double to write big numbers such as BigInteger or
// BigDecimal can result in information loss so we write
// them as String by default...
writeString(o.toString());
}
else
{
double d = ((Number)o).doubleValue();
writeAMFDouble(d);
}
}
else if (o instanceof Boolean)
{
writeAMFBoolean(((Boolean)o).booleanValue());
}
// We have a complex type...
else if (o instanceof Date)
{
writeDate((Date)o);
}
else if (o instanceof Calendar)
{
writeDate(((Calendar)o).getTime());
}
else if (o instanceof Document)
{
String xml = documentToString(o);
int len = xml.length() + 15; // ...
StringBuffer sb = new StringBuffer(len);
sb.append(XML_OPEN_TAG);
writeEscapedString(sb, xml);
sb.append(XML_CLOSE_TAG);
writeUTF(sb);
if (isDebug)
trace.writeString(xml);
}
// If there is a proxy for this,write it as a custom object so the default
// behavior can be overriden.
else if (o instanceof Enum && PropertyProxyRegistry.getRegistry().getProxy(o.getClass()) == null)
{
Enum> enumValue = (Enum>)o;
writeString(enumValue.name());
}
else
{
//We have an Object or Array type...
Class cls = o.getClass();
if (o instanceof Map && context.legacyMap && !(o instanceof ASObject))
{
writeMapAsECMAArray((Map)o);
}
else if (!context.legacyDictionary && o instanceof Dictionary)
{
writeDictionary((Dictionary)o);
}
else if (o instanceof Collection)
{
if (context.legacyCollection)
writeCollection((Collection)o, null);
else
writeArrayCollection((Collection)o, null);
}
else if (cls.isArray())
{
writeAMFArray(o, cls.getComponentType());
}
else
{
//Special Case: wrap RowSet in PageableRowSet for Serialization
if (o instanceof RowSet)
{
o = new PagedRowSet((RowSet)o, Integer.MAX_VALUE, false);
}
else if (o instanceof Throwable && context.legacyThrowable)
{
o = new StatusInfoProxy((Throwable)o);
}
writeCustomObject(o);
}
}
}
public void writeObjectTraits(TraitsInfo ti) throws IOException
{
String className = ti.getClassName();
if (className == null || className.length() == 0)
{
writeUTF(OBJECT_OPEN_TAG);
}
else
{
int len = 127; //