View Javadoc
1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.ui.dnd;
26  
27  import org.eclipse.swt.dnd.ByteArrayTransfer;
28  import java.io.*;
29  import java.util.*;
30  
31  import org.eclipse.swt.dnd.TransferData;
32  import org.wsmo.common.*;
33  
34  public class WSMOTransfer extends ByteArrayTransfer {
35      
36      protected static WSMOTransfer instance = new WSMOTransfer();
37      private static final String TYPE_NAME = "wsmo-transfer-format";
38      private static final int TYPEID = registerType(TYPE_NAME);
39      
40      public static WSMOTransfer getInstance() {
41          return instance;
42      }
43      
44      protected String[] fromByteArray(byte[] bytes) {
45          
46          DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
47          List<String> buffer = new LinkedList<String>();
48          String iriStr;
49          do {
50              iriStr = null;
51              try {
52                  iriStr = in.readUTF();
53                  buffer.add(iriStr);
54              }
55              catch (IOException e) {
56                  break;
57              }
58          }
59          while(iriStr != null);
60          String[] result = new String[buffer.size()];
61          return buffer.toArray(result);
62      }
63      /*
64       * Method declared on Transfer.
65       */
66      protected int[] getTypeIds() {
67          return new int[] { TYPEID };
68      }
69      /*
70       * Method declared on Transfer.
71       */
72      protected String[] getTypeNames() {
73          return new String[] { TYPE_NAME };
74      }
75      
76      /*
77       * Method declared on Transfer.
78       */
79      protected void javaToNative(Object object, TransferData transferData) {
80          byte[] bytes = toByteArray((List<Entity>)object);
81          if (bytes != null)
82              super.javaToNative(bytes, transferData);
83      }
84      /*
85       * Method declared on Transfer.
86       */
87      protected Object nativeToJava(TransferData transferData) {
88          byte[] bytes = (byte[])super.nativeToJava(transferData);
89          return fromByteArray(bytes);
90      }
91      
92      protected byte[] toByteArray(List<Entity> entities) {
93          ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
94          DataOutputStream out = new DataOutputStream(byteOut);
95          
96          byte[] bytes = null;
97          
98          try {
99              for (Entity entity : entities) {
100                 out.writeUTF(entity.getIdentifier().toString());
101             }
102             out.close();
103             bytes = byteOut.toByteArray();
104         } 
105         catch (IOException e) {}
106         return bytes;
107     }
108 }
109 
110 /*
111  * $Log: WSMOTransfer.java,v $
112  * Revision 1.2  2006/01/09 12:51:13  alex_simov
113  * Copyright message in header updated
114  *
115  * Revision 1.1  2005/11/15 15:55:20  alex_simov
116  * Drag-and-drop support added from WSMO Navigator to related (ontology) editors
117  *
118  */