KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > property > view > impl > PropertyViewFactoryImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * PropertyViewFactoryImpl.java
22  *
23  * Created on January 29, 2007, 6:14 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.wsdl.ui.property.view.impl;
30
31 import java.io.IOException JavaDoc;
32 import java.util.Collection JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.HashSet JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.Set JavaDoc;
39 import java.util.TreeMap JavaDoc;
40
41 import javax.xml.namespace.QName JavaDoc;
42
43 import org.netbeans.modules.xml.schema.model.Attribute;
44 import org.netbeans.modules.xml.schema.model.Element;
45 import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
46 import org.netbeans.modules.xml.schema.model.SchemaModel;
47 import org.netbeans.modules.xml.schema.model.SchemaModelFactory;
48 import org.netbeans.modules.xml.schema.model.SimpleType;
49 import org.netbeans.modules.xml.schema.model.SimpleTypeRestriction;
50 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
51 import org.netbeans.modules.xml.wsdl.ui.api.property.ExtensibilityElementPropertyAdapter;
52 import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyAdapter;
53 import org.netbeans.modules.xml.wsdl.ui.api.property.StringAttributeProperty;
54 import org.netbeans.modules.xml.wsdl.ui.commands.CommonAttributePropertyAdapter;
55 import org.netbeans.modules.xml.wsdl.ui.commands.OtherAttributePropertyAdapter;
56 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
57 import org.netbeans.modules.xml.wsdl.ui.property.model.BuiltInCustomizer;
58 import org.netbeans.modules.xml.wsdl.ui.property.model.BuiltInCustomizerGroupedProperty;
59 import org.netbeans.modules.xml.wsdl.ui.property.model.DependsOnCustomizer;
60 import org.netbeans.modules.xml.wsdl.ui.property.model.ElementProperties;
61 import org.netbeans.modules.xml.wsdl.ui.property.model.GroupedProperty;
62 import org.netbeans.modules.xml.wsdl.ui.property.model.Property;
63 import org.netbeans.modules.xml.wsdl.ui.property.model.PropertyGroup;
64 import org.netbeans.modules.xml.wsdl.ui.property.model.PropertyModelException;
65 import org.netbeans.modules.xml.wsdl.ui.property.model.PropertyModelFactory;
66 import org.netbeans.modules.xml.wsdl.ui.property.model.SimpleCustomizer;
67 import org.netbeans.modules.xml.wsdl.ui.property.model.StaticCustomizer;
68 import org.netbeans.modules.xml.wsdl.ui.property.view.BuiltInCustomizerFactory;
69 import org.netbeans.modules.xml.wsdl.ui.property.view.GroupedBuiltInCustomizerFactory;
70 import org.netbeans.modules.xml.wsdl.ui.property.view.PropertyViewFactory;
71 import org.netbeans.modules.xml.wsdl.ui.schema.visitor.OptionalAttributeFinderVisitor;
72 import org.netbeans.modules.xml.wsdl.ui.schema.visitor.SchemaAttributeTypeFinderVisitor;
73 import org.netbeans.modules.xml.wsdl.ui.schema.visitor.SchemaDocumentationFinderVisitor;
74 import org.netbeans.modules.xml.wsdl.ui.schema.visitor.SchemaElementAttributeFinderVisitor;
75 import org.netbeans.modules.xml.wsdl.ui.schema.visitor.SchemaUtility;
76 import org.netbeans.modules.xml.wsdl.ui.spi.ExtensibilityElementConfigurator;
77 import org.netbeans.modules.xml.wsdl.ui.spi.ExtensibilityElementConfiguratorFactory;
78 import org.netbeans.modules.xml.wsdl.ui.spi.NewCustomizerProvider;
79 import org.netbeans.modules.xml.wsdl.ui.spi.WSDLLookupProviderFactory;
80 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
81 import org.netbeans.modules.xml.wsdl.ui.view.property.XSDBooleanAttributeProperty;
82 import org.netbeans.modules.xml.wsdl.ui.view.property.XSDEnumeratedAttributeProperty;
83 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.ExtensibilityElementNode;
84 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.MixedContentFinderVisitor;
85 import org.netbeans.modules.xml.xam.Nameable;
86 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
87 import org.openide.ErrorManager;
88 import org.openide.nodes.Node;
89 import org.openide.nodes.Sheet;
90 import org.openide.util.NbBundle;
91
92 /**
93  *
94  * @author radval
95  */

96 public class PropertyViewFactoryImpl extends PropertyViewFactory {
97     
98     /** Creates a new instance of PropertyViewFactoryImpl */
99     public PropertyViewFactoryImpl() {
100     }
101
102     @Override JavaDoc
103     public Sheet.Set[] getPropertySets(ExtensibilityElement exElement,
104                                               QName JavaDoc elementQName,
105                                               Element schemaElement) {
106         Set JavaDoc<QName JavaDoc> processAttributeQNames = new HashSet JavaDoc<QName JavaDoc>();
107         Sheet.Set defaultPropertiesSheetSet = Sheet.createPropertiesSet();
108         ElementProperties elemProperties = null;
109         try {
110             PropertyModelFactory instance = PropertyModelFactory.getInstance();
111             elemProperties = instance.getElementProperties(elementQName);
112         } catch (PropertyModelException e) {
113             e.printStackTrace();
114         }
115         Sheet.Set[] nodePropertySet = null;
116         if (elemProperties != null) {
117             PropertyGroup[] pGroups = elemProperties.getPropertyGroup();
118             Map JavaDoc<String JavaDoc, Integer JavaDoc> groupList = new HashMap JavaDoc<String JavaDoc, Integer JavaDoc>();
119
120             nodePropertySet = new Sheet.Set[pGroups.length + 1];
121             boolean defaultPropertiesSet = false;
122             //Create Property Sheets for each Group
123
for (PropertyGroup group : pGroups) {
124                 String JavaDoc gName = group.getName();
125                 int groupNumber = group.getGroupOrder() - 1; //Starts with 1.
126
groupList.put(gName, new Integer JavaDoc(groupNumber));
127                 nodePropertySet[groupNumber] = new Sheet.Set();
128                 nodePropertySet[groupNumber].setName(gName);
129                 String JavaDoc displayName = gName; //TODO: get from Bundle
130
nodePropertySet[groupNumber].setDisplayName(displayName);
131                 if (group.isIsDefault()) {
132                     defaultPropertiesSheetSet = nodePropertySet[groupNumber];
133                     defaultPropertiesSet = true;
134                 }
135             }
136
137             //Add default properties group at the end.
138
if (!defaultPropertiesSet) {
139                 int lastIndex = nodePropertySet.length - 1;
140                 nodePropertySet[lastIndex] = defaultPropertiesSheetSet;
141                 groupList.put(null, new Integer JavaDoc(lastIndex));
142             }
143
144             //Generate Node.Property for each attribute, and add into each group according to the defined order
145
Property[] props = elemProperties.getProperty();
146             Map JavaDoc<String JavaDoc, Map JavaDoc<Integer JavaDoc, Node.Property>> map = new HashMap JavaDoc<String JavaDoc, Map JavaDoc<Integer JavaDoc, Node.Property>>();
147             Map JavaDoc<Integer JavaDoc, Node.Property> list = null;
148             for (Property prop : props) {
149                 QName JavaDoc attributeQName = new QName JavaDoc(elementQName.getNamespaceURI(), prop.getAttributeName());
150                 Attribute attribute = getAttribute(attributeQName.getLocalPart(), schemaElement);
151
152                 boolean isOptional = isAttributeOptional(attribute, attributeQName.getLocalPart());
153                 
154                 //Generate property as per specifications
155
Node.Property nodeProperty = getNodeProperty(exElement, elementQName, attributeQName, prop, isOptional);
156                 
157                 //if not generated, generate default way.
158
if (nodeProperty == null) {
159                     
160                     nodeProperty = createDefaultNodeProperty(attribute, exElement, attributeQName, isOptional);
161                     
162                 }
163                 //Mark this attribute as processed
164
processAttributeQNames.add(attributeQName);
165
166                 if (map.containsKey(prop.getGroupName())) {
167                     list = map.get(prop.getGroupName());
168                 } else {
169                     list = new TreeMap JavaDoc<Integer JavaDoc, Node.Property>(); //we dont know in advance how many will be in each group, so assume it to be as long as the number of properties
170
map.put(prop.getGroupName(), list);
171                 }
172                 //set Name and description if not done so before.
173
setNameAndDescription(nodeProperty, attributeQName.getLocalPart(), null, getAttributeShortDescription(schemaElement, attributeQName));
174                 list.put(new Integer JavaDoc(prop.getPropertyOrder() - 1), nodeProperty);//PropertyOrder starts with one
175
}
176
177             GroupedProperty[] groupedProps = elemProperties.getGroupedProperty();
178             for (GroupedProperty groupedProp : groupedProps) {
179                 String JavaDoc groupedAttrNames = groupedProp.getGroupedAttributeNames();
180                 String JavaDoc[] attrNames = groupedAttrNames.split(" ");
181                 Node.Property prop = getGroupedNodeProperty(elementQName.getNamespaceURI(), exElement, groupedProp);
182                 if (prop != null) {
183                     for (String JavaDoc attrName : attrNames) {
184                         processAttributeQNames.add(new QName JavaDoc(elementQName.getNamespaceURI(), attrName));
185                     }
186                 } else {
187                     // add it individually in the group name at the same property order sequentially
188

189                 }
190                 
191                 Map JavaDoc<Integer JavaDoc, Node.Property> nodeProps = null;
192                 if (map.containsKey(groupedProp.getGroupName())) {
193                     nodeProps = map.get(groupedProp.getGroupName());
194                 } else {
195                     nodeProps = new TreeMap JavaDoc<Integer JavaDoc, Node.Property>();
196                     map.put(groupedProp.getGroupName(), nodeProps);
197                 }
198                 setNameAndDescription(prop, groupedProp.getDisplayName(), groupedProp.getDisplayName(), "TODO: Set documentation for Grouped Property.");
199                 nodeProps.put(new Integer JavaDoc(groupedProp.getPropertyOrder() - 1), prop);
200             }
201             
202             //form return value
203
for (String JavaDoc groupName : map.keySet()) {
204                 Integer JavaDoc i = groupList.get(groupName);
205                 Map JavaDoc<Integer JavaDoc, Node.Property> properties = map.get(groupName);
206                 for (Node.Property prop : properties.values()) {
207                     if (prop != null) {
208                         nodePropertySet[i.intValue()].put(prop);
209                     }
210                 }
211             }
212         } else {
213             nodePropertySet = new Sheet.Set[] {defaultPropertiesSheetSet};
214         }
215         
216         //Add all remaining attributes which are not processed into default properties group.
217
populateDefaultPropertySet(defaultPropertiesSheetSet, schemaElement, elementQName, exElement, processAttributeQNames);
218
219         return nodePropertySet;
220
221     }
222
223     private org.openide.nodes.Node.Property getNodeProperty(ExtensibilityElement extensibilityElement, QName JavaDoc elementQName, QName JavaDoc attributeQName, Property prop, boolean isOptional) {
224         BuiltInCustomizer bCustomizer = prop.getBuiltInCustomizer();
225         if (bCustomizer != null) {
226             DependsOnCustomizer dCustomizer = bCustomizer.getDependsOnCustomizer();
227             if (dCustomizer != null) {
228                 String JavaDoc nameOfCustomizer = dCustomizer.getName();
229                 StaticCustomizer sCustomizer = dCustomizer.getStaticCustomizer();
230                 if (sCustomizer != null) {
231                     QName JavaDoc qname = sCustomizer.getDependsOnAttributeName();
232                     //create builtin property adapter with dependson func.\
233
return BuiltInCustomizerFactory.getProperty(extensibilityElement, attributeQName, qname, nameOfCustomizer, isOptional);
234                 }
235                 
236 /*No use case as of now: commented DynamicCustomizer ddCustomizer = dCustomizer.getDynamicCustomizer();
237                 if (ddCustomizer != null) {
238                     String className = ddCustomizer.getAttributeValueProviderClass();
239                     String valueType = ddCustomizer.getDependsOnAttributeValueType();
240                     return BuiltInCustomizerFactory.getProperty(extensibilityElement, attributeQName, nameOfCustomizer, className, valueType);
241                 }*/

242                 //no customizer defined
243
assert false : "Invalid Customizer defined for " + attributeQName.toString();
244             } else {
245                 SimpleCustomizer sCustomizer = bCustomizer.getSimpleCustomizer();
246                 if (sCustomizer != null) {
247                     String JavaDoc name = sCustomizer.getName();
248                     return BuiltInCustomizerFactory.getProperty(extensibilityElement, attributeQName, name, isOptional);
249                 }
250                 assert false : "Invalid Customizer defined for " + attributeQName.toString();
251             }
252         } else {
253             String JavaDoc nCustomizer = prop.getNewCustomizer();
254             if (nCustomizer != null) {
255                 NewCustomizerProvider prov = WSDLLookupProviderFactory.getObject(elementQName.getNamespaceURI(), NewCustomizerProvider.class);
256                 assert prov != null : "Couldnt create the NewCustomizer";
257                 Node.Property property = prov.getProperty(extensibilityElement, elementQName, attributeQName, isOptional);
258                 assert property != null : "Couldnt create the property using this NewCustomizer";
259                 return property;
260             }
261         }
262         //Probably SchemaCustomizer
263
return null;
264     }
265     
266     private Node.Property getGroupedNodeProperty(String JavaDoc namespace, ExtensibilityElement extensibilityElement, GroupedProperty gProp) {
267         BuiltInCustomizerGroupedProperty bCustomizer = gProp.getBuiltInCustomizer();
268         if (bCustomizer != null) {
269             return GroupedBuiltInCustomizerFactory.getProperty(extensibilityElement, bCustomizer);
270         }
271         
272         String JavaDoc nCustomizer = gProp.getNewCustomizer();
273         if (nCustomizer != null) {
274             
275         }
276         return null;
277     }
278     
279     private org.openide.nodes.Node.Property createDefaultNodeProperty(Attribute attr, ExtensibilityElement exElement, QName JavaDoc attributeQName, boolean isOptional) {
280         Node.Property attrValueProperty = null;
281         QName JavaDoc elementQName = new QName JavaDoc(attributeQName.getNamespaceURI(), exElement.getQName().getLocalPart());
282         ExtensibilityElementConfigurator configurator = new ExtensibilityElementConfiguratorFactory().getExtensibilityElementConfigurator(
283                 elementQName);
284         if (configurator != null) {
285             if (configurator.isHidden(exElement, elementQName, attributeQName.getLocalPart())) {
286                 return null;
287             }
288             
289             attrValueProperty = configurator.getProperty(exElement, elementQName, attributeQName.getLocalPart());
290             if (attrValueProperty != null) return attrValueProperty;
291         }
292         
293         SimpleType gst = findAttributeType(attr);
294         
295         if(gst != null) {
296             try {
297                 ExtensibilityElementPropertyAdapter adapter = null;
298                 if (attr.getDefault() != null) {
299                     adapter = new ExtensibilityElementPropertyAdapter(exElement, attributeQName.getLocalPart(), attr.getDefault());
300                 } else {
301                     adapter = new ExtensibilityElementPropertyAdapter(exElement, attributeQName.getLocalPart(), isOptional);
302                 }
303                 attrValueProperty = processSimpleType(gst, adapter, isOptional);
304             } catch (NoSuchMethodException JavaDoc e) {
305                 // TODO Auto-generated catch block
306
e.printStackTrace();
307             }
308
309             if (attrValueProperty == null) {
310                 //create default property
311
attrValueProperty = createAttributeProperty(exElement, attributeQName, isOptional, attr.getDefault());
312             }
313         }
314         return attrValueProperty;
315     }
316
317     private boolean isAttributeOptional(Attribute attribute, String JavaDoc localPart) {
318         OptionalAttributeFinderVisitor visitor = new OptionalAttributeFinderVisitor(localPart);
319         attribute.accept(visitor);
320         return visitor.isOptional();
321     }
322
323     private Attribute getAttribute(String JavaDoc attrName, Element schemaElement) {
324         SchemaElementAttributeFinderVisitor seaFinder = new SchemaElementAttributeFinderVisitor(schemaElement);
325         schemaElement.accept(seaFinder);
326
327         List JavaDoc<Attribute> attributes = seaFinder.getAttributes();
328         Iterator JavaDoc<Attribute> it = attributes.iterator();
329
330         while(it.hasNext()) {
331             Attribute attr = it.next();
332             if(attr instanceof Nameable) {
333                 Nameable namedAttr = (Nameable) attr;
334                 if(attrName.equals(namedAttr.getName())) {
335                     return attr;
336                 }
337             }
338         }
339         return null;
340     }
341     
342     private SimpleType findAttributeType(Attribute attr) {
343         if (attr == null) return null;
344         
345         SchemaAttributeTypeFinderVisitor typeFinder = new SchemaAttributeTypeFinderVisitor();
346         attr.accept(typeFinder);
347         return typeFinder.getSimpleType();
348     }
349
350     private Node.Property processSimpleType(SimpleType gst, PropertyAdapter propertyAdapter, boolean isOptional) throws NoSuchMethodException JavaDoc {
351         Node.Property attrValueProperty = null;
352         //for boolean type we show true/false drop down
353
if(gst != null) {
354             String JavaDoc simpleTypeName = null;
355             if (gst instanceof GlobalSimpleType) {
356                 simpleTypeName = ((GlobalSimpleType) gst).getName();
357             }
358             String JavaDoc namesapce = gst.getModel().getSchema().getTargetNamespace();
359             SchemaModel primitiveTypesModel = SchemaModelFactory.getDefault().getPrimitiveTypesModel();
360             String JavaDoc primitiveTypeNamesapce = primitiveTypesModel.getSchema().getTargetNamespace();
361             if(namesapce != null
362                     && namesapce.equals(primitiveTypeNamesapce)
363                     && simpleTypeName != null && simpleTypeName.equals("boolean")) {//NOI18N
364
attrValueProperty =
365                     new XSDBooleanAttributeProperty(propertyAdapter, String JavaDoc.class, "getValue", "setValue", isOptional);//NOI18N
366

367             } else if(gst.getDefinition() instanceof SimpleTypeRestriction) {
368                 //if attribute has enumeration facet
369
//then use the first enumeration value
370
SimpleTypeRestriction sr = (SimpleTypeRestriction) gst.getDefinition();
371                 Collection JavaDoc enumerations = sr.getEnumerations();
372                 if(enumerations != null && enumerations.size() > 0) {
373                     attrValueProperty =
374                         new XSDEnumeratedAttributeProperty(gst, propertyAdapter, String JavaDoc.class, "getValue", "setValue", isOptional);//NOI18N
375

376                 }
377             }
378         }
379         
380         
381         return attrValueProperty;
382     }
383     
384     private void populateDefaultPropertySet(Sheet.Set propertySet, Element schemaElement, QName JavaDoc elementQName, ExtensibilityElement exElement, Set JavaDoc<QName JavaDoc> processAttributeQNames) {
385         SchemaElementAttributeFinderVisitor seaFinder = new SchemaElementAttributeFinderVisitor(schemaElement, true);
386         schemaElement.accept(seaFinder);
387         List JavaDoc<Attribute> attributes = seaFinder.getAttributes();
388         for (Attribute attr : attributes) {
389             if(attr instanceof Nameable) {
390                 Nameable namedAttr = (Nameable) attr;
391
392                 QName JavaDoc attrQName = new QName JavaDoc(schemaElement.getModel().getSchema().getTargetNamespace(), namedAttr.getName());
393                 if (!processAttributeQNames.contains(attrQName)) {
394                     boolean isOptional = isAttributeOptional(attr, namedAttr.getName());
395                     Node.Property attrValueProperty = createDefaultNodeProperty(attr, exElement, attrQName, isOptional);
396                     setNameAndDescription(attrValueProperty, namedAttr.getName(), null, getAttributeShortDescription(schemaElement, attrQName));
397                     propertySet.put(attrValueProperty);
398                 }
399             }
400         }
401
402         //find if there needs to be a any element tag, display a simple string property editor.
403
MixedContentFinderVisitor aeFinder = new MixedContentFinderVisitor(schemaElement);
404         schemaElement.accept(aeFinder);
405         if (aeFinder.hasMixedContent()) {
406             Node.Property attrValueProperty;
407             try {
408                 attrValueProperty = new BaseAttributeProperty(new AnyElementPropertyAdapter(exElement, elementQName), String JavaDoc.class, "value");
409                 attrValueProperty.setName(NbBundle.getMessage(ExtensibilityElementNode.class, "PROP_NAME_ANY_CONTENT"));
410                 propertySet.put(attrValueProperty);
411             } catch (NoSuchMethodException JavaDoc e) {
412                 ErrorManager.getDefault().notify(e);
413             }
414         }
415
416     }
417     
418     private String JavaDoc getAttributeShortDescription(Element schemaElement, QName JavaDoc attrQName) {
419         if (schemaElement != null) {
420             Attribute attribute = SchemaUtility.findAttribute(attrQName, schemaElement);
421             if(attribute != null) {
422                 SchemaDocumentationFinderVisitor sdfFinder = new SchemaDocumentationFinderVisitor();
423                 attribute.accept(sdfFinder);
424                 return sdfFinder.getDocumentation();
425             }
426         }
427         return null;
428     }
429     
430     private Node.Property createAttributeProperty(ExtensibilityElement exElement, QName JavaDoc attrQName, boolean isOptional, String JavaDoc defaultValue) {
431         Node.Property attrValueProperty = null;
432         
433         try {
434             AbstractDocumentComponent adc = (AbstractDocumentComponent) exElement;
435             QName JavaDoc elementQName = adc.getQName();
436             String JavaDoc namespace = elementQName.getNamespaceURI();
437             String JavaDoc ns = attrQName.getNamespaceURI();
438             //if attribute are from non wsdl namespace
439
//in that case we will have a namspace
440
//for wsdl namspace attribute ns is empty string
441
if(ns == null || ns.trim().equals("") || ns.equals(namespace)) {
442                 ExtensibilityElementPropertyAdapter propertyAdapter =
443                     defaultValue != null
444                     ? new ExtensibilityElementPropertyAdapter(exElement, attrQName.getLocalPart(), defaultValue)
445                     : new ExtensibilityElementPropertyAdapter(exElement, attrQName.getLocalPart(), isOptional);
446                     
447                 attrValueProperty = getAttributeNodeProperty(propertyAdapter);
448                 
449             } else {
450                 OtherAttributePropertyAdapter propertyAdapter =
451                     new OtherAttributePropertyAdapter(attrQName, exElement);
452                 //attributes
453
attrValueProperty = getOtherAttributeNodeProperty(attrQName, propertyAdapter);
454                 
455             }
456         } catch(Exception JavaDoc ex) {
457             // mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
458
ErrorManager.getDefault().notify(ex);
459         }
460         
461         return attrValueProperty;
462     }
463     
464     protected Node.Property getAttributeNodeProperty(ExtensibilityElementPropertyAdapter propertyAdapter) throws NoSuchMethodException JavaDoc {
465         Node.Property attrValueProperty = new StringAttributeProperty(propertyAdapter, String JavaDoc.class, "getValue", "setValue");
466         return attrValueProperty;
467     }
468     
469     protected Node.Property getOtherAttributeNodeProperty(QName JavaDoc attrQName,
470             OtherAttributePropertyAdapter propertyAdapter) throws NoSuchMethodException JavaDoc {
471         Node.Property attrValueProperty = new BaseAttributeProperty(propertyAdapter, String JavaDoc.class, CommonAttributePropertyAdapter.VALUE);
472         attrValueProperty.setName(Utility.fromQNameToString(attrQName));
473         return attrValueProperty;
474     }
475     
476     private void setNameAndDescription(Node.Property property, String JavaDoc name, String JavaDoc displayName, String JavaDoc description) {
477         if (property == null) return;
478         if (isNullOrBlank(property.getName())) {
479             assert name != null : "Name cannot be null";
480             property.setName(name);
481         }
482         if (isNullOrBlank(property.getDisplayName()) && displayName != null) {
483             property.setDisplayName(displayName);
484         }
485         if (isNullOrBlank(property.getShortDescription()) || property.getShortDescription().equals(property.getDisplayName())) {
486             property.setShortDescription(description);
487         }
488     }
489     
490     private boolean isNullOrBlank(String JavaDoc str) {
491         return str == null || str.trim().length() == 0;
492     }
493     
494     
495     public class AnyElementPropertyAdapter extends PropertyAdapter {
496         QName JavaDoc qname;
497         
498         public AnyElementPropertyAdapter(ExtensibilityElement delegate, QName JavaDoc qname) {
499             super(delegate);
500             this.qname = qname;
501         }
502         
503         public String JavaDoc getValue() {
504             String JavaDoc content = ((ExtensibilityElement)getDelegate()).getContentFragment();
505             if (content != null) {
506                 return content;
507             }
508             return "";
509         }
510         
511         public void setValue(String JavaDoc string) {
512             
513             boolean isInTransaction = Utility.startTransaction(getDelegate().getModel());
514             try {
515                 ((ExtensibilityElement)getDelegate()).setContentFragment(string);
516             } catch (IOException JavaDoc e) {
517                 ErrorManager.getDefault().notify(e);
518             } finally {
519                 if (!isInTransaction) {
520                     Utility.endTransaction(getDelegate().getModel(), isInTransaction);
521                 }
522             }
523         }
524         
525         
526     }
527     
528 }
529
Popular Tags