001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.tmap.model.impl;
020:
021: import java.util.List;
022: import org.netbeans.modules.xml.wsdl.model.ReferenceableWSDLComponent;
023: import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
024: import org.netbeans.modules.xml.xam.dom.Attribute;
025: import org.netbeans.modules.xml.xam.dom.DocumentModelAccess;
026: import org.netbeans.modules.xslt.tmap.model.api.ExNamespaceContext;
027: import org.netbeans.modules.xslt.tmap.model.api.TMapComponent;
028: import org.netbeans.modules.xslt.tmap.model.api.TMapReference;
029: import org.netbeans.modules.xslt.tmap.model.api.TMapReferenceable;
030: import org.netbeans.modules.xslt.tmap.model.api.TMapVisitor;
031: import org.netbeans.modules.xslt.tmap.model.api.Variable;
032: import org.netbeans.modules.xslt.tmap.model.api.VariableReference;
033: import org.netbeans.modules.xslt.tmap.model.api.WSDLReference;
034: import org.w3c.dom.Element;
035: import org.w3c.dom.Node;
036: import org.w3c.dom.NodeList;
037:
038: /**
039: *
040: * @author Vitaly Bychkov
041: * @version 1.0
042: */
043: public abstract class TMapComponentAbstract extends
044: AbstractDocumentComponent<TMapComponent> implements
045: TMapComponent, DocumentModelAccess.NodeUpdater {
046: private AttributeAccess myAttributeAcces;
047:
048: public TMapComponentAbstract(TMapModelImpl model, Element e) {
049: super (model, e);
050: myAttributeAcces = new AttributeAccess(this );
051: }
052:
053: public TMapComponentAbstract(TMapModelImpl model,
054: TMapComponents type) {
055: super (model, createNewElement(type, model));
056: myAttributeAcces = new AttributeAccess(this );
057: }
058:
059: @Override
060: public TMapModelImpl getModel() {
061: return (TMapModelImpl) super .getModel();
062: }
063:
064: protected void populateChildren(List<TMapComponent> children) {
065: NodeList nl = getPeer().getChildNodes();
066: if (nl != null) {
067: for (int i = 0; i < nl.getLength(); i++) {
068: Node n = nl.item(i);
069: if (n instanceof Element) {
070: TMapComponent comp = (TMapComponent) getModel()
071: .getFactory().create((Element) n, this );
072: if (comp != null) {
073: children.add(comp);
074: }
075: }
076: }
077: }
078: }
079:
080: public ExNamespaceContext getNamespaceContext() {
081: return new ExNamespaceContextImpl(this );
082: }
083:
084: protected <T extends ReferenceableWSDLComponent> WSDLReference<T> getWSDLReference(
085: Attribute attr, Class<T> clazz) {
086: return getAttributeAccess().getWSDLReference(attr, clazz);
087: }
088:
089: protected Object getAttributeValueOf(Attribute attr,
090: String stringValue) {
091: return getAttributeAccess().getAttributeValueOf(attr,
092: stringValue);
093: }
094:
095: public <T extends ReferenceableWSDLComponent> WSDLReference<T> createWSDLReference(
096: T target, Class<T> type) {
097: // TODO m | r
098: ////// readLock();
099: ////// try {
100: return WSDLReferenceBuilder.getInstance().build(target, type,
101: this );
102: ////// }
103: ////// finally {
104: ////// readUnlock();
105: ////// }
106: }
107:
108: @Override
109: public void setAttribute(String eventPropertyName, Attribute attr,
110: Object value) {
111: boolean isTransact = true;
112: if (!getModel().isIntransaction()) {
113: getModel().startTransaction();
114: } else {
115: isTransact = true;
116: }
117:
118: try {
119:
120: super .setAttribute(eventPropertyName, attr, value);
121:
122: } finally {
123: if (!isTransact) {
124: getModel().endTransaction();
125: }
126: }
127: }
128:
129: protected VariableReference getTMapVarReference(Attribute attr) {
130: return getAttributeAccess().getTMapVarReference(attr);
131: }
132:
133: protected void setTMapVarReference(Attribute attr,
134: VariableReference ref) {
135: getAttributeAccess().setTMapVarReference(attr, ref);
136: }
137:
138: protected <T extends ReferenceableWSDLComponent> void setWSDLReference(
139: Attribute attr, WSDLReference<T> ref) {
140: getAttributeAccess().setWSDLReference(attr, ref);
141: }
142:
143: protected static Element createNewElement(TMapComponents type,
144: TMapModelImpl model) {
145: return model.getDocument().createElement(type.getTagName());
146: }
147:
148: protected final AttributeAccess getAttributeAccess() {
149: return myAttributeAcces;
150: }
151:
152: protected final String getComponentName() {
153: return getPeer().getLocalName();
154: }
155:
156: //
157: // protected final void readLock() {
158: // getModel().readLock();
159: // }
160: //
161: // protected final void readUnlock() {
162: // getModel().readUnlock();
163: // }
164: //
165: // protected final void writeLock() {
166: // getModel().writeLock();
167: // }
168: //
169: // protected final void writeUnlock() {
170: // getModel().writeUnlock();
171: // }
172: //
173: //
174: //
175: }
|