001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.object.applicator;
005:
006: import com.tc.object.ClientObjectManager;
007: import com.tc.object.ObjectID;
008: import com.tc.object.SerializationUtil;
009: import com.tc.object.TCObject;
010: import com.tc.object.TraversedReferences;
011: import com.tc.object.dna.api.DNA;
012: import com.tc.object.dna.api.DNACursor;
013: import com.tc.object.dna.api.DNAEncoding;
014: import com.tc.object.dna.api.DNAWriter;
015: import com.tc.object.dna.api.LogicalAction;
016: import com.tc.object.tx.optimistic.OptimisticTransactionManager;
017: import com.tc.util.Assert;
018:
019: import java.io.IOException;
020: import java.net.URL;
021: import java.util.Map;
022:
023: /**
024: * ChangeApplicator for URLs.
025: */
026: public class URLApplicator extends BaseApplicator {
027:
028: public URLApplicator(DNAEncoding encoding) {
029: super (encoding);
030: }
031:
032: public void hydrate(ClientObjectManager objectManager,
033: TCObject tcObject, DNA dna, Object pojo)
034: throws IOException, ClassNotFoundException {
035: TCURL url = (TCURL) pojo;
036: DNACursor cursor = dna.getCursor();
037:
038: while (cursor.next(encoding)) {
039: LogicalAction action = cursor.getLogicalAction();
040: int method = action.getMethod();
041: Object[] params = action.getParameters();
042: switch (method) {
043: case SerializationUtil.URL_SET:
044: Assert.assertNotNull(params[0]);
045: Assert.assertNotNull(params[1]);
046: Assert.assertNotNull(params[2]);
047: Assert.assertNotNull(params[3]);
048: Assert.assertNotNull(params[4]);
049: Assert.assertNotNull(params[5]);
050: Assert.assertNotNull(params[6]);
051: Assert.assertNotNull(params[7]);
052:
053: String protocol = null;
054: String host = null;
055: int port = -1;
056: String authority = null;
057: String userInfo = null;
058: String path = null;
059: String query = null;
060: String ref = null;
061: if (!ObjectID.NULL_ID.equals(params[0])) {
062: protocol = params[0].toString();
063: }
064: if (!ObjectID.NULL_ID.equals(params[1])) {
065: host = params[1].toString();
066: }
067: if (!ObjectID.NULL_ID.equals(params[2])) {
068: port = ((Integer) params[2]).intValue();
069: }
070: if (!ObjectID.NULL_ID.equals(params[3])) {
071: authority = params[3].toString();
072: }
073: if (!ObjectID.NULL_ID.equals(params[4])) {
074: userInfo = params[4].toString();
075: }
076: if (!ObjectID.NULL_ID.equals(params[5])) {
077: path = params[5].toString();
078: }
079: if (!ObjectID.NULL_ID.equals(params[6])) {
080: query = params[6].toString();
081: }
082: if (!ObjectID.NULL_ID.equals(params[7])) {
083: ref = params[7].toString();
084: }
085:
086: url.__tc_set_logical(protocol, host, port, authority,
087: userInfo, path, query, ref);
088: break;
089: default:
090: throw new AssertionError("invalid action:" + method);
091: }
092: }
093: }
094:
095: public void dehydrate(ClientObjectManager objectManager,
096: TCObject tcObject, DNAWriter writer, Object pojo) {
097: URL url = (URL) pojo;
098: writer.addLogicalAction(SerializationUtil.URL_SET,
099: new Object[] { url.getProtocol(), url.getHost(),
100: new Integer(url.getPort()), url.getAuthority(),
101: url.getUserInfo(), url.getPath(),
102: url.getQuery(), url.getRef() });
103: }
104:
105: public TraversedReferences getPortableObjects(Object pojo,
106: TraversedReferences addTo) {
107: addTo.addAnonymousReference(pojo);
108: return addTo;
109: }
110:
111: public Object getNewInstance(ClientObjectManager objectManager,
112: DNA dna) {
113: throw new UnsupportedOperationException();
114: }
115:
116: public Map connectedCopy(Object source, Object dest, Map visited,
117: ClientObjectManager objectManager,
118: OptimisticTransactionManager txManager) {
119: throw new UnsupportedOperationException();
120: }
121: }
|