001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * E2EDataObject.java
044: *
045: * Created on June 27, 2005, 2:51 PM
046: *
047: */
048: package org.netbeans.modules.mobility.end2end;
049:
050: import java.io.ByteArrayOutputStream;
051: import java.io.File;
052: import java.io.IOException;
053: import java.io.OutputStream;
054: import java.util.ArrayList;
055: import java.util.HashSet;
056: import java.util.List;
057: import java.util.Properties;
058: import java.util.Set;
059: import javax.swing.SwingUtilities;
060: import org.netbeans.api.java.classpath.ClassPath;
061: import org.netbeans.api.java.project.JavaProjectConstants;
062: import org.netbeans.api.java.source.ClasspathInfo;
063: import org.netbeans.api.project.FileOwnerQuery;
064: import org.netbeans.api.project.Project;
065: import org.netbeans.api.project.ProjectInformation;
066: import org.netbeans.api.project.SourceGroup;
067: import org.netbeans.api.project.Sources;
068: import org.netbeans.api.project.ui.OpenProjects;
069: import org.netbeans.modules.mobility.e2e.classdata.ClassDataRegistry;
070: import org.netbeans.modules.mobility.e2e.mapping.JavonMappingImpl;
071: import org.netbeans.modules.mobility.end2end.classdata.AbstractService;
072: import org.netbeans.modules.mobility.end2end.classdata.ClassData;
073: import org.netbeans.modules.mobility.end2end.classdata.OperationData;
074: import org.netbeans.modules.mobility.end2end.classdata.WSDLService;
075: import org.netbeans.modules.mobility.end2end.client.config.ClientConfiguration;
076: import org.netbeans.modules.mobility.end2end.client.config.Configuration;
077: import org.netbeans.modules.mobility.end2end.client.config.ConfigurationReader;
078: import org.netbeans.modules.mobility.end2end.client.config.ConfigurationWriter;
079: import org.netbeans.modules.mobility.end2end.client.config.ServerConfiguration;
080: import org.netbeans.modules.mobility.end2end.util.Util;
081: import org.netbeans.modules.mobility.javon.JavonMapping;
082: import org.netbeans.modules.xml.multiview.DesignMultiViewDesc;
083: import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject;
084: import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer;
085: import org.netbeans.modules.xml.multiview.XmlMultiViewEditorSupport;
086: import org.netbeans.spi.mobility.end2end.E2EServiceProvider;
087: import org.netbeans.spi.mobility.end2end.ServiceGeneratorResult;
088: import org.openide.DialogDisplayer;
089: import org.openide.ErrorManager;
090: import org.openide.NotifyDescriptor;
091: import org.openide.filesystems.FileLock;
092: import org.openide.filesystems.FileObject;
093: import org.openide.filesystems.FileUtil;
094: import org.openide.loaders.DataObjectExistsException;
095: import org.openide.loaders.MultiFileLoader;
096: import org.openide.nodes.Node;
097: import org.openide.util.Lookup;
098: import org.openide.util.NbBundle;
099: import org.openide.util.RequestProcessor;
100: import org.openide.util.lookup.Lookups;
101:
102: /**
103: *
104: * @author Michal Skvor
105: */
106: public class E2EDataObject extends XmlMultiViewDataObject {
107:
108: public static RequestProcessor rp; //generator
109:
110: // Configuration
111: transient protected Configuration configuration;
112: // Project the file is in
113: transient private Project clientProject;
114: transient private Project serverProject;
115:
116: transient protected Set<SaveCallback> saveCallbacks;
117:
118: transient protected boolean generating;
119:
120: public static final String PROP_GENERATING = "generating"; //NOI18N
121:
122: final private static String TRUE = "true";
123:
124: private ModelSynchronizer synchronizer;
125:
126: /** Creates a new instance of E2EDataObject */
127: public E2EDataObject(FileObject file, MultiFileLoader ldr)
128: throws DataObjectExistsException {
129: super (file, ldr);
130:
131: synchronizer = new ModelSynchronizer(this );
132:
133: saveCallbacks = new HashSet<SaveCallback>();
134: }
135:
136: /**
137: * Adds callback to callback list
138: *
139: * @param callBack callback to be called before the file is written to the disc
140: */
141: public void addSaveCallback(final SaveCallback callBack) {
142: saveCallbacks.add(callBack);
143: }
144:
145: /**
146: * Removes callback from the callback list
147: *
148: * @param callBack callback to be called before the file is written to the disc
149: */
150: public void removeSaveCallback(final SaveCallback callBack) {
151: saveCallbacks.remove(callBack);
152: }
153:
154: @Override
155: protected Node createNodeDelegate() {
156: Node node;
157:
158: node = new E2EDataNode(this );
159: return node;
160: }
161:
162: @Override
163: public void setModified(final boolean modif) {
164: super .setModified(modif);
165: if (modif) {
166: synchronizer.requestUpdateData();
167: }
168: }
169:
170: public Configuration getConfiguration() {
171: if (configuration == null) {
172: try {
173: configuration = ConfigurationReader.read(this );
174: } catch (Exception e) {
175: configuration = null;
176: ErrorManager.getDefault().log(e.getMessage());
177: }
178: }
179: return configuration;
180: }
181:
182: public void setConfiguration(final Configuration configuration) {
183: this .configuration = configuration;
184: setModified(true);
185: }
186:
187: public Project getClientProject() {
188: if (clientProject == null)
189: clientProject = FileOwnerQuery.getOwner(getPrimaryFile());
190: return clientProject;
191: }
192:
193: public Project getServerProject() {
194: final Configuration config = getConfiguration();
195: if (serverProject == null) {
196: final OpenProjects openProject = OpenProjects.getDefault();
197: final Project[] openedProjects = openProject
198: .getOpenProjects();
199: if (config.getServerConfigutation() == null) {
200: return null;
201: }
202: final String serverProjectName = config
203: .getServerConfigutation().getProjectName();
204: for (final Project p : openedProjects) {//
205: final ProjectInformation pi = p.getLookup().lookup(
206: ProjectInformation.class);
207: final String webProjectName = pi.getName();
208: if (serverProjectName.equals(webProjectName)) {
209: serverProject = p;
210: break;
211: }
212: }
213:
214: if (serverProject == null) {
215: // TODO: add some dialog to inform user that his Web project is not there ...
216: //System.err.println( "Cannot find server node" );
217: }
218: }
219: return serverProject;
220: }
221:
222: // FIXME: this method should be rather in GenerateAction
223: public JavonMappingImpl getMapping() throws Exception {
224: // //System.err.println(" - GET MAPPING START - ");
225: // // run always
226: final Configuration config = getConfiguration();
227: final List<String> classPath = new ArrayList<String>();
228: //
229: final ServerConfiguration sc = config.getServerConfigutation();
230: final Properties sprops = sc.getProperties();
231: final Sources ssources = getServerProject().getLookup().lookup(
232: Sources.class);
233: final SourceGroup[] ssg = ssources
234: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
235: List<ClasspathInfo> classpaths = new ArrayList<ClasspathInfo>();
236: for (int i = 0; i < ssg.length; i++) {
237: final ClassPath cp = ClassPath.getClassPath(ssg[i]
238: .getRootFolder(), ClassPath.SOURCE);
239: final FileObject[] roots = cp.getRoots();
240: for (int j = 0; j < roots.length; j++) {
241: File f;
242: if ((f = FileUtil.toFile(roots[j])) != null)
243: classPath.add(f.getAbsolutePath());
244: classpaths.add(ClasspathInfo.create(roots[j]));
245: }
246: }
247:
248: //
249: // for (int i = 0; i < ssg.length; i++) {
250: // final ClassPath cp = ClassPath.getClassPath(ssg[i].getRootFolder() ,ClassPath.EXECUTE);
251: // final FileObject[] roots = cp.getRoots(); //only returns folders. How to handle jars?
252: // for (int j = 0; j < roots.length; j++) {
253: // File f;
254: // if ((f = FileUtil.toFile(roots[j])) != null)
255: // classPath.add(f.getAbsolutePath());
256: // }
257: // }
258: //
259: //TODO: Dirty hack
260: List<ClasspathInfo> classpathInfos = new ArrayList<ClasspathInfo>();
261: classpathInfos
262: .add(ClasspathInfo.create(ssg[0].getRootFolder())); // TODO: fix this!!!
263: if (config.getServiceType()
264: .equals(Configuration.WSDLCLASS_TYPE)) {
265: FileObject projectFO = getServerProject()
266: .getProjectDirectory().getFileObject(
267: "build/generated/wsimport/client");
268: if (projectFO != null) {
269: classpathInfos.add(ClasspathInfo.create(projectFO));
270: }
271: }
272: // TODO: fix
273: // System.err.println(" - classpathInfos: " + classpathInfos.size());
274: final ClassDataRegistry registry = ClassDataRegistry
275: .getRegistry(ClassDataRegistry.DEFAULT_PROFILE,
276: classpathInfos);
277: // final ClassDataRegistry registry =
278: // getClassDataRegistryFactory().create( classPath );
279: // mapping = new MutableJavonMapping( registry );
280: //
281: // // FIXME: devel hack
282: // final MutableJavonMapping m = new MutableJavonMapping( mapping );
283: // Create new mapping
284: JavonMappingImpl mapping = new JavonMappingImpl(registry);
285:
286: // Client part of the mapping
287: final ClientConfiguration cc = config.getClientConfiguration();
288: final JavonMappingImpl.Client jcc = new JavonMappingImpl.Client();
289: final Properties cprops = cc.getProperties();
290: jcc.setClassName(cc.getClassDescriptor().getLeafClassName());
291: jcc.setPackageName(cc.getClassDescriptor().getPackageName());
292: final Sources csources = getClientProject().getLookup().lookup(
293: Sources.class);
294: final SourceGroup csg = Util
295: .getPreselectedGroup(
296: csources
297: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA),
298: cc.getClassDescriptor().getLocation());
299: // //System.err.println(" - client path: " + FileUtil.getFileDisplayName( csg.getRootFolder()));
300: // m.setClientRootDirectory( FileUtil.toFile( csg.getRootFolder()).getPath());
301: jcc.setOutputDirectory(FileUtil.toFile(csg.getRootFolder())
302: .getPath());
303: // if( TRUE.equals(cprops.getProperty( "trace" ))) { // NOI18N
304: // m.setClientTraceLevel( 1 );
305: // } else {
306: // m.setClientTraceLevel( 0 );
307: // }
308: // m.setDynamicInvocationSupported( false );
309: // m.setGroupingSupported( cprops.getProperty( "multipleCall" ).equals( TRUE )); // NOI18N
310: mapping.setProperty(JavonMapping.CREATE_STUBS, cprops
311: .getProperty("createStubs").equals(TRUE)); // NOI18N
312: mapping.setProperty(JavonMapping.DATABINDING, cprops
313: .getProperty("DataBinding"));
314: // m.setSynchronousSupported( true );
315: mapping.setProperty(JavonMapping.FLOATING_POINT_SUPPORT, cprops
316: .getProperty("floatingPoint").equals(TRUE)); // NOI18N
317: mapping.setClientMapping(jcc);
318:
319: /* Server part of the mapping */
320: final ProjectInformation pi = getServerProject().getLookup()
321: .lookup(ProjectInformation.class);
322: final JavonMappingImpl.Server jsc = new JavonMappingImpl.Server();
323: jsc.setProjectName(pi.getName());
324: jsc.setClassName(sc.getClassDescriptor().getLeafClassName());
325: jsc.setPackageName(sc.getClassDescriptor().getPackageName());
326: // //System.err.println(" - server path: " + FileUtil.getFileDisplayName( ssg.getRootFolder()));
327: jsc.setOutputDirectory(FileUtil.toFile(
328: Util.getPreselectedGroup(ssg,
329: sc.getClassDescriptor().getLocation())
330: .getRootFolder()).getPath());
331: // m.setServerRootDirectory(
332: // FileUtil.toFile( Util.getPreselectedGroup(ssg, sc.getClassDescriptor().getLocation()).getRootFolder()).getPath());
333: // if( TRUE.equals(sprops.getProperty( "trace" ))) { // NOI18N
334: // m.setClientTraceLevel( 1 );
335: // } else {
336: // m.setClientTraceLevel( 0 );
337: // }
338:
339: jsc.setLocation(Util.getServerLocation(getServerProject()));
340: jsc.setPort(Util.getServerPort(getServerProject()));
341: jsc.setServletLocation(configuration.getServerConfigutation()
342: .getProjectName()
343: + "/servlet/" + //NOI18N
344: configuration.getServerConfigutation()
345: .getClassDescriptor().getType());
346: mapping.setServerMapping(jsc);
347: //
348: // final JavonMapping.Service jss = mapping.new Service();
349: int methodID = 1;
350: final List<AbstractService> services = config.getServices();
351: // // there must be one and just one service
352:
353: final List<ClassData> classes = services.get(0).getData();
354: for (final ClassData ccd : classes) {
355: JavonMappingImpl.Service javonService = new JavonMappingImpl.Service();
356: javonService.setPackageName(ccd.getPackageName());
357: if (Configuration.WSDLCLASS_TYPE.equals(config
358: .getServiceType())) {
359: WSDLService wsdlService = (WSDLService) services.get(0);
360: javonService.setClassName(wsdlService.getType());
361: } else {
362: javonService.setClassName(ccd.getClassName());
363: }
364:
365: String className = ccd.getProxyClassType();
366: if (className == null) {
367: className = ccd.getType();
368: }
369: mapping.setProperty("instance", className);
370:
371: // while( SourceUtils.isScanInProgress()) {}
372: //todo!!!!!
373: Thread.sleep(5000);
374:
375: registry.updateClassDataTree();
376: final org.netbeans.modules.mobility.e2e.classdata.ClassData classData = registry
377: .getClassData(className);
378: // System.err.println(" - classdata = " + classData);
379: if (classData == null)
380: continue;
381:
382: final List<OperationData> methods = ccd.getOperations();
383: final List<org.netbeans.modules.mobility.e2e.classdata.MethodData> methodsData = classData
384: .getMethods();
385: for (int j = 0; j < methods.size(); j++) {
386: // System.err.println(" - method: " + methods.get( j ).getMethodName());
387: String methodName = null;
388: if (Configuration.WSDLCLASS_TYPE.equals(config
389: .getServiceType())) {
390: methodName = methods.get(j).getMethodName();
391: } else {
392: methodName = methods.get(j).getName();
393: }
394: final int methodIndex = findMethodIndex(methodsData,
395: methodName);
396: if (methodIndex >= 0) {
397: org.netbeans.modules.mobility.e2e.classdata.MethodData mmd = methodsData
398: .get(methodIndex);
399: mmd.setRequestID(methodID++);
400: javonService.addMethod(mmd);
401: }
402: }
403: mapping.addServiceMaping(javonService);
404: }
405: mapping.setServletURL(Util.getServerURL(getServerProject(),
406: getConfiguration()));
407:
408: // System.err.println(" - mapping :" + mapping.getServiceMappings().toString());
409: return mapping;
410: }
411:
412: private int findMethodIndex(
413: final List<org.netbeans.modules.mobility.e2e.classdata.MethodData> methods,
414: final String methodName) {
415: int result = 0;
416: for (org.netbeans.modules.mobility.e2e.classdata.MethodData method : methods) {
417: // for( int i = 0; i < methods.size(); i++ ) {
418: // FIXME: check parameters and return types
419: if (method.getName().equals(methodName)) {
420: return result;
421: }
422: result++;
423: }
424:
425: return -1;
426: }
427:
428: protected String getPrefixMark() {
429: // FIXME: What the heck is this method for?
430: return "";
431: }
432:
433: protected boolean parseDocument(@SuppressWarnings("unused")
434: final boolean updateModel) {
435: // FIXME: devel hack
436: return true;
437: }
438:
439: protected boolean isModelCreated() {
440: // FIXME: devel hack
441: return false;
442: }
443:
444: protected String generateDocumentFromModel() {
445: return "";
446: }
447:
448: public synchronized void generate() {
449: generating = true;
450: // Save document before generation of files
451: try {
452: getEditorSupport().saveDocument();
453: } catch (IOException ex) {
454: ex.printStackTrace();
455: }
456: firePropertyChange(PROP_GENERATING, Boolean.FALSE, Boolean.TRUE);
457: SwingUtilities.invokeLater(new Runnable() {
458: @SuppressWarnings("synthetic-access")
459: public void run() {
460: if (rp == null) {
461: rp = new RequestProcessor("End2EndGenerator", 5); //NOI18N
462: }
463: rp.post(new Runnable() {
464: @SuppressWarnings("synthetic-access")
465: public void run() {
466: final Lookup.Result<E2EServiceProvider> result = Lookup
467: .getDefault()
468: .lookup(
469: new Lookup.Template<E2EServiceProvider>(
470: E2EServiceProvider.class));
471: for (final E2EServiceProvider elem : result
472: .allInstances()) {
473: if (E2EDataObject.this .getConfiguration()
474: .getServiceType().equals(
475: elem.getServiceType())) {
476: final ServiceGeneratorResult service = elem
477: .generateStubs(Lookups
478: .singleton(E2EDataObject.this ));
479: // if (generateMidlet && service != null && service.getAccessMethods().length != 0 && Util.isSuitableProjectConfiguration( getClientProject())){
480: // final VisualDesignGenerator designGenerator = new VisualDesignGenerator(service);
481: // DataObject generated;
482: // if ((generated = designGenerator.generateDesign(getFolder())) == null){
483: // StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage( E2EDataObject.class, "MSG_SampleNotGenerated" )); // NOI18N
484: // } else {
485: // final Project p = getClientProject();
486: // final AntProjectHelper h = p.getLookup().lookup(AntProjectHelper.class);
487: // if (p instanceof J2MEProject && h != null) {
488: // // set the server url as a custom prperty in jad
489: // setServerUrlInJad((J2MEProject) p, service.getDeploymentUrl());
490: // JavaModel.getJavaRepository().beginTrans(false);
491: // try {
492: // final Resource resource = JavaModel.getResource(generated.getPrimaryFile());
493: // final JavaClass jc = (JavaClass) resource.getClassifiers().get(0);
494: //
495: // J2MEProjectGenerator.addMIDletProperty(p, h,
496: // generated.getName(),
497: // jc.getName(),
498: // ""
499: // );
500: // ProjectManager.getDefault().saveProject(p);
501: // } catch (IOException e) {
502: // ErrorManager.getDefault().notify(e);
503: // } finally {
504: // JavaModel.getJavaRepository().endTrans();
505: // }
506: // }
507: // }
508: // }
509: // generating = false;
510: // E2EDataObject.this.firePropertyChange(PROP_GENERATING, Boolean.TRUE, Boolean.FALSE);
511: // return;
512: }
513: }
514: generating = false;
515: E2EDataObject.this .firePropertyChange(
516: PROP_GENERATING, Boolean.TRUE,
517: Boolean.FALSE);
518: }
519: });
520: // }
521: //
522: // private void setServerUrlInJad( J2MEProject project, String url ) {
523: // final AntProjectHelper helper = project.getLookup().lookup( AntProjectHelper.class );
524: // final EditableProperties props = helper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH );
525: // final HashMap<String,String> jad = (HashMap<String,String>)DefaultPropertyParsers.MANIFEST_PROPERTY_PARSER.decode(props.getProperty(DefaultPropertiesDescriptor.MANIFEST_JAD), null, null);
526: // jad.put( "serverURL", url );
527: // props.setProperty( DefaultPropertiesDescriptor.MANIFEST_JAD, DefaultPropertyParsers.MANIFEST_PROPERTY_PARSER.encode(jad, null, null));
528: // helper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, props );
529: // }
530: // });
531: // }
532: // }, NbBundle.getMessage(E2EDataObject.class, "MSG_GeneratingStubs"))){ //NOI18N
533: // generating = false;
534: // E2EDataObject.this.firePropertyChange(PROP_GENERATING, Boolean.TRUE, Boolean.FALSE);
535: // }
536: }
537: });
538: }
539:
540: public boolean isGenerating() {
541: return generating;
542: }
543:
544: protected DesignMultiViewDesc[] getMultiViewDesc() {
545: final Lookup.Result<E2EServiceProvider> result = Lookup
546: .getDefault().lookup(
547: new Lookup.Template<E2EServiceProvider>(
548: E2EServiceProvider.class));
549: for (final E2EServiceProvider elem : result.allInstances()) {
550: if (getConfiguration().getServiceType().equals(
551: elem.getServiceType())) {
552: return elem.getMultiViewDesc(Lookups.singleton(this ));
553: }
554: }
555: return null;
556: }
557:
558: public interface SaveCallback {
559: public void save();
560: }
561:
562: private XmlMultiViewEditorSupport editorSupport;
563:
564: protected synchronized XmlMultiViewEditorSupport getEditorSupport() {
565: if (editorSupport == null) {
566: editorSupport = new ValidatedXmlMultiViewEditorSupport(this );
567: }
568: return editorSupport;
569: }
570:
571: private static class ValidatedXmlMultiViewEditorSupport extends
572: XmlMultiViewEditorSupport {
573:
574: final protected E2EDataObject dataObject;
575:
576: public ValidatedXmlMultiViewEditorSupport(
577: XmlMultiViewDataObject dObj) {
578: super (dObj);
579: // setSuppressXmlView(true);
580: this .dataObject = (E2EDataObject) dObj;
581: }
582:
583: @Override
584: public void open() {
585: SwingUtilities.invokeLater(new Runnable() {
586: public void run() {
587: // JavaMetamodel.getManager().invokeAfterScanFinished( new Runnable() {
588: // public void run() {
589: final Configuration configuration = dataObject
590: .getConfiguration();
591: if (configuration == null) {
592: final NotifyDescriptor.Message dd = new NotifyDescriptor.Message(
593: NbBundle
594: .getMessage(
595: E2EDataObject.class,
596: "ERR_ConfigurationFileCorrupted"));
597: DialogDisplayer.getDefault().notify(dd);
598: return;
599: }
600: //resolve broken reference here if this can be broken --> depends on server project
601: if (dataObject.getConfiguration()
602: .getServerConfigutation() != null
603: && dataObject.getServerProject() == null) {
604: final NotifyDescriptor.Message dd = new NotifyDescriptor.Message(
605: NbBundle
606: .getMessage(
607: E2EDataObject.class,
608: "ERR_ServerProjectNotOpened",
609: configuration
610: .getServerConfigutation()
611: .getProjectName()));
612: DialogDisplayer.getDefault().notify(dd);
613: if (Util.openProject(dataObject
614: .getConfiguration()
615: .getServerConfigutation()
616: .getProjectPath()) == null) {
617: return;
618: }
619: return;
620: }
621: openme();
622: // }
623: // }, NbBundle.getMessage(E2EDataObject.class, "MSG_OpeningConfigFile" ));
624: }
625: });
626: }
627:
628: protected void openme() {
629: super .open();
630: }
631: }
632:
633: private class ModelSynchronizer extends
634: XmlMultiViewDataSynchronizer {
635:
636: public ModelSynchronizer(XmlMultiViewDataObject dataObject) {
637: super (dataObject, 100);
638: }
639:
640: protected boolean mayUpdateData(@SuppressWarnings("unused")
641: final boolean allowDialog) {
642: return true;
643: }
644:
645: protected void updateDataFromModel(final Object model,
646: final FileLock lock, final boolean modify) {
647: if (model == null) {
648: return;
649: }
650:
651: for (final SaveCallback callBack : saveCallbacks) {
652: callBack.save();
653: }
654:
655: try {
656: final ByteArrayOutputStream out = new ByteArrayOutputStream();
657: if (configuration != null) {
658: try {
659: ConfigurationWriter.write(out,
660: (Configuration) model);
661: } catch (Exception e) {
662: ErrorManager.getDefault().notify(e);
663: }
664: }
665: out.close();
666: final OutputStream outputStream = getDataCache()
667: .createOutputStream(lock, modify);
668: try {
669: outputStream.write(out.toByteArray());
670: } finally {
671: outputStream.close();
672: }
673: } catch (IOException e) {
674: ErrorManager.getDefault().notify(
675: ErrorManager.INFORMATIONAL, e);
676: }
677: }
678:
679: protected Object getModel() {
680: return getConfiguration();
681: }
682:
683: protected void reloadModelFromData() {
684: getConfiguration();
685: }
686: }
687: }
|