View Javadoc

1   /**
2    *  BlueCove - Java library for Bluetooth
3    *  Copyright (C) 2006-2008 Vlad Skarzhevskyy
4    * 
5    *  Licensed to the Apache Software Foundation (ASF) under one
6    *  or more contributor license agreements.  See the NOTICE file
7    *  distributed with this work for additional information
8    *  regarding copyright ownership.  The ASF licenses this file
9    *  to you under the Apache License, Version 2.0 (the
10   *  "License"); you may not use this file except in compliance
11   *  with the License.  You may obtain a copy of the License at
12   *
13   *    http://www.apache.org/licenses/LICENSE-2.0
14   *
15   *  Unless required by applicable law or agreed to in writing,
16   *  software distributed under the License is distributed on an
17   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   *  KIND, either express or implied.  See the License for the
19   *  specific language governing permissions and limitations
20   *  under the License.
21   *
22   *  @author vlads
23   *  @version $Id: DeviceInfo.java 2471 2008-12-01 03:44:20Z skarzhevskyy $
24   */
25  package net.sf.bluecove.obex;
26  
27  import java.io.IOException;
28  import java.util.StringTokenizer;
29  
30  class DeviceInfo implements Storable {
31  
32  	String btAddress;
33  
34  	String name;
35  
36  	String obexUrl;
37  
38  	boolean obexServiceFound = false;
39  
40  	public String toString() {
41  		if ((name != null) && (name.length() > 0)) {
42  			return name;
43  		} else {
44  			return btAddress;
45  		}
46  	}
47  
48  	private String fixNull(String str) {
49  		if (str.equalsIgnoreCase("null")) {
50  			return null;
51  		}
52  		return str;
53  	}
54  
55  	public void loadFromLine(String line) throws IOException {
56  		StringTokenizer st = new StringTokenizer(line, "|");
57  		if (!st.hasMoreTokens()) {
58  			throw new IOException();
59  		}
60  		btAddress = fixNull(st.nextToken());
61  		if (!st.hasMoreTokens()) {
62  			throw new IOException();
63  		}
64  		name = fixNull(st.nextToken());
65  		if (!st.hasMoreTokens()) {
66  			throw new IOException();
67  		}
68  		obexUrl = fixNull(st.nextToken());
69  	}
70  
71  	public String saveAsLine() {
72  		return btAddress + "|" + name + "|" + obexUrl;
73  	}
74  
75  	public boolean isValid() {
76  		if ((obexUrl == null) || (btAddress == null)) {
77  			return false;
78  		}
79  		return (obexUrl.toLowerCase().indexOf("://" + btAddress.toLowerCase() + ":") != -1);
80  	}
81  }