1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*******************************************************************************
* Copyright (c) 2010 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.orcs.db.internal.exchange.transform;
import java.util.Map;
import javax.xml.stream.XMLStreamException;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.enums.TxChange;
import org.eclipse.osee.framework.database.operation.Address;
import org.eclipse.osee.framework.jdk.core.type.HashCollection;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.io.xml.SaxTransformer;
import org.xml.sax.Attributes;
/**
* @author Ryan D. Brooks
*/
public class V0_9_2TxsConsolidateParser extends SaxTransformer {
private long targetBranchId;
private String targetBranchIdStr;
private final Map<Long, Long> artifactGammaToNetGammaId;
private final HashCollection<Long, Address> addressMap;
private boolean isWriteAllowed = true;
private boolean skipWrite;
public V0_9_2TxsConsolidateParser(Map<Long, Long> artifactGammaToNetGammaId, HashCollection<Long, Address> addressMap) {
this.artifactGammaToNetGammaId = artifactGammaToNetGammaId;
this.addressMap = addressMap;
}
public void setBranchId(long targetBranchId) {
this.isWriteAllowed = false;
this.targetBranchId = targetBranchId;
this.targetBranchIdStr = String.valueOf(targetBranchId);
}
@Override
public void startElementFound(String uri, String localName, String qName, Attributes attributes) throws XMLStreamException {
skipWrite = false;
Long gammaId = null;
if (isWriteAllowed) {
if (localName.equals("entry")) {
gammaId = artifactGammaToNetGammaId.get(Long.valueOf(attributes.getValue("gamma_id")));
}
if (gammaId == null) {
super.startElementFound(uri, localName, qName, attributes);
} else {
skipWrite = true;
}
} else if (localName.equals("entry")) {
if (targetBranchIdStr.equals(attributes.getValue("branch_id"))) {
gammaId = artifactGammaToNetGammaId.get(Long.valueOf(attributes.getValue("gamma_id")));
if (gammaId != null) {
addressMap.put(gammaId, createAddress(attributes, gammaId));
}
}
}
}
@Override
public void endElementFound(String uri, String localName, String qName) throws XMLStreamException {
if (isWriteAllowed && !skipWrite && !localName.equals("data")) {
super.endElementFound(uri, localName, qName);
}
}
private Address createAddress(Attributes attributes, long gammaId) throws XMLStreamException {
try {
int modType = Integer.parseInt(attributes.getValue("mod_type"));
ModificationType modificationType = ModificationType.getMod(modType);
int transactionId = Integer.parseInt(attributes.getValue("transaction_id"));
TxChange txCurrent = TxChange.getChangeType(Integer.parseInt(attributes.getValue("tx_current")));
return new Address(false, targetBranchId, -1, transactionId, gammaId, modificationType, txCurrent);
} catch (OseeCoreException ex) {
throw new XMLStreamException(ex);
}
}
}
|