{
16 | private final String appId;
17 | private final String namespace;
18 |
19 | private static final String BAD_APP_ID_MESSAGE =
20 | "appId or namespace cannot contain '" + NamespaceResources.NAMESPACE_SEPARATOR + "'";
21 |
22 | /**
23 | * Constructs an {@link AppIdNamespace} given {@code #appId} and {@code #namespace}.
24 | */
25 | public AppIdNamespace(String appId, String namespace) {
26 | if (appId == null || namespace == null) {
27 | throw new IllegalArgumentException("appId or namespace may not be null");
28 | }
29 | if (appId.indexOf(NamespaceResources.NAMESPACE_SEPARATOR) != -1 ||
30 | namespace.indexOf(NamespaceResources.NAMESPACE_SEPARATOR) != -1) {
31 | throw new IllegalArgumentException(BAD_APP_ID_MESSAGE);
32 | }
33 | this.appId = appId;
34 | this.namespace = namespace;
35 | }
36 |
37 | /**
38 | * Converts an encoded appId/namespace to {@link AppIdNamespace}.
39 | *
40 | * Only one form of an appId/namespace pair will be allowed. i.e. "app!"
41 | * is an illegal form and must be encoded as "app".
42 | *
43 | *
An appId/namespace pair may contain at most one "!" character.
44 | *
45 | * @param encodedAppIdNamespace The encoded application Id/namespace string.
46 | */
47 | public static AppIdNamespace parseEncodedAppIdNamespace(String encodedAppIdNamespace) {
48 | if (encodedAppIdNamespace == null) {
49 | throw new IllegalArgumentException("appIdNamespaceString may not be null");
50 | }
51 | int index = encodedAppIdNamespace.indexOf(NamespaceResources.NAMESPACE_SEPARATOR);
52 | if (index == -1) {
53 | return new AppIdNamespace(encodedAppIdNamespace, "");
54 | }
55 | String appId = encodedAppIdNamespace.substring(0, index);
56 | String namespace = encodedAppIdNamespace.substring(index + 1);
57 | if (namespace.length() == 0) {
58 | throw new IllegalArgumentException(
59 | "encodedAppIdNamespace with empty namespace may not contain a '" +
60 | NamespaceResources.NAMESPACE_SEPARATOR + "'");
61 | }
62 | return new AppIdNamespace(appId, namespace);
63 | }
64 |
65 | /**
66 | * Perform a "lexical" comparison to {@code other} {@link AppIdNamespace}.
67 | * @return See {@link String#compareTo(String)}.
68 | */
69 | @Override
70 | public int compareTo(AppIdNamespace other) {
71 | int appidCompare = appId.compareTo(other.appId);
72 | if (appidCompare == 0) {
73 | return namespace.compareTo(other.namespace);
74 | }
75 | return appidCompare;
76 | }
77 |
78 | public String getAppId() {
79 | return appId;
80 | }
81 |
82 | public String getNamespace() {
83 | return namespace;
84 | }
85 |
86 | /**
87 | * Returns an "encoded" appId/namespace string.
88 | *
89 | *
Note: If the {@link #namespace} is empty, the return value is exactly the {@link #appId}.
90 | */
91 | public String toEncodedString() {
92 | if (namespace.equals("")) {
93 | return appId;
94 | } else {
95 | return appId + NamespaceResources.NAMESPACE_SEPARATOR + namespace;
96 | }
97 | }
98 |
99 | @Override
100 | public int hashCode() {
101 | final int prime = 31;
102 | int result = 1;
103 | result = prime * result + ((appId == null) ? 0 : appId.hashCode());
104 | result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
105 | return result;
106 | }
107 |
108 | @Override
109 | public boolean equals(Object obj) {
110 | if (this == obj) {
111 | return true;
112 | }
113 | if (obj == null) {
114 | return false;
115 | }
116 | if (getClass() != obj.getClass()) {
117 | return false;
118 | }
119 | AppIdNamespace other = (AppIdNamespace) obj;
120 | if (appId == null) {
121 | if (other.appId != null) {
122 | return false;
123 | }
124 | } else if (!appId.equals(other.appId)) {
125 | return false;
126 | }
127 | if (namespace == null) {
128 | if (other.namespace != null) {
129 | return false;
130 | }
131 | } else if (!namespace.equals(other.namespace)) {
132 | return false;
133 | }
134 | return true;
135 | }
136 |
137 | @Override
138 | public String toString() {
139 | return toEncodedString();
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Blob.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.google.appengine.api.datastore;
17 |
18 | import java.io.Serializable;
19 | import java.util.Arrays;
20 |
21 | /**
22 | * {@code Blob} contains an array of bytes. This byte array can be no bigger
23 | * than 1MB. To store files, particularly files larger than this 1MB limit,
24 | * look at the Blobstore API.
25 | *
26 | */
27 | public final class Blob implements Serializable {
28 |
29 | private static final long serialVersionUID = 6210713401925622518L;
30 |
31 | private byte[] bytes;
32 |
33 | /**
34 | * Construct a new {@code Blob} with the specified bytes. Since
35 | * {@code Blobs} can be quite large we do not perform a defensive copy of the
36 | * provided byte array. It is the programmer's responsibility to avoid
37 | * making changes to this array once the {@code Blob} has been constructed.
38 | */
39 | public Blob(byte[] bytes) {
40 | this.bytes = bytes;
41 | }
42 |
43 | /**
44 | * This constructor exists for frameworks (e.g. Google Web Toolkit)
45 | * that require it for serialization purposes. It should not be
46 | * called explicitly.
47 | */
48 | @SuppressWarnings("unused")
49 | private Blob(){
50 | }
51 |
52 | /**
53 | * Return the bytes stored in this {@code Blob}.
54 | */
55 | public byte[] getBytes() {
56 | return bytes;
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | return Arrays.hashCode(bytes);
62 | }
63 |
64 | /**
65 | * Two {@code Blob} objects are considered equal if their contained
66 | * bytes match exactly.
67 | */
68 | @Override
69 | public boolean equals(Object object) {
70 | if (object instanceof Blob) {
71 | Blob key = (Blob) object;
72 | return Arrays.equals(bytes, key.bytes);
73 | }
74 | return false;
75 | }
76 |
77 | /**
78 | * Simply prints the number of bytes contained in this {@code Blob}.
79 | */
80 | @Override
81 | public String toString() {
82 | return "";
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Category.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.google.appengine.api.datastore;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * A tag, ie a descriptive word or phrase. Entities may be tagged by users,
22 | * and later returned by a queries for that tag. Tags can also be used for
23 | * ranking results (frequency), photo captions, clustering, activity, etc.
24 | *
25 | * @see Jeffrey Zeldmans blog post
26 | * on tag clouds for a more in-depth description.
27 | */
28 | public final class Category implements Serializable, Comparable {
29 |
30 | public static final long serialVersionUID = 8556134984576082397L;
31 |
32 | private String category;
33 |
34 | public Category(String category) {
35 | if (category == null) {
36 | throw new NullPointerException("category must not be null");
37 | }
38 | this.category = category;
39 | }
40 |
41 | /**
42 | * This constructor exists for frameworks (e.g. Google Web Toolkit)
43 | * that require it for serialization purposes. It should not be
44 | * called explicitly.
45 | */
46 | @SuppressWarnings("unused")
47 | private Category() {
48 | this.category = null;
49 | }
50 |
51 | public String getCategory() {
52 | return category;
53 | }
54 |
55 | @Override
56 | public int compareTo(Category o) {
57 | return category.compareTo(o.category);
58 | }
59 |
60 | @Override
61 | public boolean equals(Object o) {
62 | if (this == o) {
63 | return true;
64 | }
65 | if (o == null || getClass() != o.getClass()) {
66 | return false;
67 | }
68 |
69 | Category category1 = (Category) o;
70 |
71 | if (!category.equals(category1.category)) {
72 | return false;
73 | }
74 |
75 | return true;
76 | }
77 |
78 | @Override
79 | public int hashCode() {
80 | return category.hashCode();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Cursor.java:
--------------------------------------------------------------------------------
1 | package com.google.appengine.api.datastore;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * GWT emulation class, much different from the official source code because it only wraps the websafestring.
7 | * Will not have the same hashCode() value as the non-emulated version. This class will not have the same
8 | * toString() value as the non-emulated version.
9 | */
10 | @SuppressWarnings("serial")
11 | public final class Cursor implements Serializable
12 | {
13 | private String webString;
14 |
15 | public Cursor(String webString)
16 | {
17 | this.webString = webString;
18 | }
19 |
20 | public String toWebSafeString()
21 | {
22 | return webString;
23 | }
24 |
25 | public static Cursor fromWebSafeString(String encodedCursor)
26 | {
27 | if (encodedCursor == null)
28 | throw new NullPointerException("encodedCursor must not be null");
29 |
30 | return new Cursor(encodedCursor);
31 | }
32 |
33 | @Override
34 | public boolean equals(Object o)
35 | {
36 | if (this == o) return true;
37 | if (o == null || getClass() != o.getClass()) return false;
38 |
39 | Cursor cursor = (Cursor) o;
40 |
41 | if (!webString.equals(cursor.webString)) return false;
42 |
43 | return true;
44 | }
45 |
46 | @Override
47 | public int hashCode()
48 | {
49 | return webString.hashCode();
50 | }
51 |
52 | public String toString()
53 | {
54 | return webString;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/DataTypeUtils.java:
--------------------------------------------------------------------------------
1 | package com.google.appengine.api.datastore;
2 |
3 | /**
4 | * GWT emulation class.
5 | */
6 | public class DataTypeUtils
7 | {
8 | public static final int MAX_STRING_PROPERTY_LENGTH = 500;
9 | public static final int MAX_SHORT_BLOB_PROPERTY_LENGTH = 500;
10 | public static final int MAX_LINK_PROPERTY_LENGTH = 2038;
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Email.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.google.appengine.api.datastore;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * An e-mail address datatype. Makes no attempt at validation.
22 | *
23 | * @see RFC 2822
24 | * for the e-mail address specification.
25 | */
26 | public final class Email implements Serializable, Comparable {
27 | static final long serialVersionUID = -4807513785819575482L;
28 |
29 | private String email;
30 |
31 | public Email(String email) {
32 | if (email == null) {
33 | throw new NullPointerException("email must not be null");
34 | }
35 | this.email = email;
36 | }
37 |
38 | /**
39 | * This constructor exists for frameworks (e.g. Google Web Toolkit)
40 | * that require it for serialization purposes. It should not be
41 | * called explicitly.
42 | */
43 | @SuppressWarnings("unused")
44 | private Email() {
45 | this.email = null;
46 | }
47 |
48 | public String getEmail() {
49 | return email;
50 | }
51 |
52 | @Override
53 | public int compareTo(Email e) {
54 | return email.compareTo(e.email);
55 | }
56 |
57 | @Override
58 | public boolean equals(Object o) {
59 | if (this == o) {
60 | return true;
61 | }
62 | if (o == null || getClass() != o.getClass()) {
63 | return false;
64 | }
65 |
66 | Email email1 = (Email) o;
67 |
68 | if (!email.equals(email1.email)) {
69 | return false;
70 | }
71 |
72 | return true;
73 | }
74 |
75 | @Override
76 | public int hashCode() {
77 | return email.hashCode();
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/EntityNotFoundException.java:
--------------------------------------------------------------------------------
1 | // Copyright 2007 Google Inc. All rights reserved.
2 |
3 | package com.google.appengine.api.datastore;
4 |
5 | /**
6 | * {@code EntityNotFoundException} is thrown when no {@code Entity}
7 | * with the specified {@code Key} could be found.
8 | *
9 | */
10 | public class EntityNotFoundException extends Exception {
11 | private final Key key;
12 |
13 | public EntityNotFoundException(Key key) {
14 | super("No entity was found matching the key: " + key);
15 | this.key = key;
16 | }
17 |
18 | public Key getKey() {
19 | return key;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/GeoPt.java:
--------------------------------------------------------------------------------
1 | // Copyright 2008 Google Inc. All Rights Reserved.
2 |
3 | package com.google.appengine.api.datastore;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * A geographical point, specified by float latitude and longitude coordinates.
9 | * Often used to integrate with mapping sites like Google Maps.
10 | */
11 | public final class GeoPt implements Serializable, Comparable {
12 |
13 | public static final long serialVersionUID = 349808987517153697L;
14 |
15 | private float latitude;
16 | private float longitude;
17 |
18 | /**
19 | * Constructs a {@code GeoPt}.
20 | *
21 | * @param latitude
22 | * The latitude. Must be between -90 and 90 (inclusive).
23 | * @param longitude
24 | * The longitude. Must be between -180 and 180 (inclusive).
25 | * @throws IllegalArgumentException
26 | * If {@code latitude} or {@code longitude} is outside the legal
27 | * range.
28 | */
29 | public GeoPt(float latitude, float longitude) {
30 | if (Math.abs(latitude) > 90) {
31 | throw new IllegalArgumentException("Latitude must be between -90 and 90 (inclusive).");
32 | }
33 |
34 | if (Math.abs(longitude) > 180) {
35 | throw new IllegalArgumentException("Longitude must be between -180 and 180.");
36 | }
37 |
38 | this.latitude = latitude;
39 | this.longitude = longitude;
40 | }
41 |
42 | /**
43 | * This constructor exists for frameworks (e.g. Google Web Toolkit) that
44 | * require it for serialization purposes. It should not be called
45 | * explicitly.
46 | */
47 | @SuppressWarnings("unused")
48 | private GeoPt() {
49 | this(0, 0);
50 | }
51 |
52 | public float getLatitude() {
53 | return latitude;
54 | }
55 |
56 | public float getLongitude() {
57 | return longitude;
58 | }
59 |
60 | /**
61 | * Sort first by latitude, then by longitude
62 | */
63 | @Override
64 | public int compareTo(GeoPt o) {
65 | int latResult = ((Float) latitude).compareTo(o.latitude);
66 | if (latResult != 0) {
67 | return latResult;
68 | }
69 | return ((Float) longitude).compareTo(o.longitude);
70 | }
71 |
72 | @Override
73 | public boolean equals(Object o) {
74 | if (this == o) {
75 | return true;
76 | }
77 | if (o == null || getClass() != o.getClass()) {
78 | return false;
79 | }
80 |
81 | GeoPt geoPt = (GeoPt) o;
82 |
83 | if (Float.compare(geoPt.latitude, latitude) != 0) {
84 | return false;
85 | }
86 | if (Float.compare(geoPt.longitude, longitude) != 0) {
87 | return false;
88 | }
89 |
90 | return true;
91 | }
92 |
93 | @Override
94 | public int hashCode() {
95 | int result;
96 | result = (latitude != +0.0f ? Float.floatToIntBits(latitude) : 0);
97 | result = 31 * result + (longitude != +0.0f ? Float.floatToIntBits(longitude) : 0);
98 | return result;
99 | }
100 |
101 | @Override
102 | public String toString() {
103 | // String.format() is not part of GWT's JRE emulation
104 | //return String.format("%f,%f", latitude, longitude);
105 | return "GeoPt(" + latitude + ", " + longitude + ")";
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/IMHandle.java:
--------------------------------------------------------------------------------
1 | // Copyright 2009 Google Inc. All Rights Reserved.
2 | package com.google.appengine.api.datastore;
3 |
4 | import java.io.Serializable;
5 | import java.net.URL;
6 |
7 | /**
8 | * An instant messaging handle. Includes both an address and its protocol. The
9 | * protocol value is either a standard IM scheme (legal scheme values are
10 | * defined by {@link Scheme} or a URL identifying the IM network for the
11 | * protocol (e.g. http://aim.com/).
12 | *
13 | */
14 | public final class IMHandle implements Serializable, Comparable {
15 |
16 | public static final long serialVersionUID = 6963426833434504530L;
17 |
18 | /**
19 | * Supported IM schemes.
20 | */
21 | public enum Scheme {
22 | sip, unknown, xmpp
23 | }
24 |
25 | private String protocol;
26 | private String address;
27 |
28 | public IMHandle(Scheme scheme, String address) {
29 | if (scheme == null) {
30 | throw new NullPointerException("scheme must not be null");
31 | }
32 | validateAddress(address);
33 | this.protocol = scheme.name();
34 | this.address = address;
35 | }
36 |
37 | // URL is not part of GWT JRE emulation
38 | //
39 | // public IMHandle(URL network, String address) {
40 | // if (network == null) {
41 | // throw new NullPointerException("network must not be null");
42 | // }
43 | // validateAddress(address);
44 | // this.protocol = network.toString();
45 | // this.address = address;
46 | // }
47 |
48 | /**
49 | * This constructor exists for frameworks (e.g. Google Web Toolkit) that
50 | * require it for serialization purposes. It should not be called
51 | * explicitly.
52 | */
53 | @SuppressWarnings("unused")
54 | private IMHandle() {
55 | this.protocol = null;
56 | this.address = null;
57 | }
58 |
59 | /**
60 | * Constructs an {@code IMHandle} from a string in the format returned by
61 | * {@link #toDatastoreString()}.
62 | *
63 | * @throws IllegalArgumentException
64 | * If the provided string does not match the format returned by
65 | * {@link #toDatastoreString()} or the first component of the
66 | * string is not a valid {@link Scheme} and is not a valid
67 | * {@link URL}.
68 | */
69 | // URL and MalformedURLException are not part of GWT JRE emulation
70 | //
71 | // static IMHandle fromDatastoreString(String datastoreString) {
72 | // if (datastoreString == null) {
73 | // throw new NullPointerException("datastoreString must not be null");
74 | // }
75 | // String[] split = datastoreString.split(" ", 2);
76 | // if (split.length != 2) {
77 | // throw new IllegalArgumentException("Datastore string must have at least one space: " + datastoreString);
78 | // }
79 | // try {
80 | // return new IMHandle(IMHandle.Scheme.valueOf(split[0]), split[1]);
81 | // } catch (IllegalArgumentException iae) {
82 | // try {
83 | // return new IMHandle(new URL(split[0]), split[1]);
84 | // } catch (MalformedURLException e) {
85 | // throw new IllegalArgumentException("String in datastore could not be parsed into a valid IMHandle. "
86 | // + "Protocol must either be a valid scheme or url: " + split[0]);
87 | // }
88 | // }
89 | // }
90 |
91 | private static void validateAddress(String address) {
92 | if (address == null) {
93 | throw new NullPointerException("address must not be null");
94 | }
95 | }
96 |
97 | /**
98 | * The datastore representation of the {@code IMHandle}. This must not
99 | * change.
100 | */
101 | String toDatastoreString() {
102 | // GWT JRE emulation missing
103 | //return String.format("%s %s", protocol, address);
104 | return protocol + " " + address;
105 | }
106 |
107 | public String getProtocol() {
108 | return protocol;
109 | }
110 |
111 | public String getAddress() {
112 | return address;
113 | }
114 |
115 | @Override
116 | public boolean equals(Object o) {
117 | if (this == o) {
118 | return true;
119 | }
120 | if (o == null || getClass() != o.getClass()) {
121 | return false;
122 | }
123 |
124 | IMHandle imHandle = (IMHandle) o;
125 |
126 | if (!address.equals(imHandle.address)) {
127 | return false;
128 | }
129 | if (!protocol.equals(imHandle.protocol)) {
130 | return false;
131 | }
132 |
133 | return true;
134 | }
135 |
136 | @Override
137 | public int hashCode() {
138 | int result;
139 | result = protocol.hashCode();
140 | result = 31 * result + address.hashCode();
141 | return result;
142 | }
143 |
144 | /**
145 | * Sorts first by protocol, then by address.
146 | */
147 | @Override
148 | public int compareTo(IMHandle o) {
149 | return toDatastoreString().compareTo(o.toDatastoreString());
150 | }
151 |
152 | @Override
153 | public String toString() {
154 | return toDatastoreString();
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Key.java:
--------------------------------------------------------------------------------
1 | package com.google.appengine.api.datastore;
2 |
3 | import java.io.Serializable;
4 | import java.util.Iterator;
5 | import java.util.LinkedList;
6 |
7 | /**
8 | * GWT emulation class. Will not have the same hashCode() value as the non-emulated version.
9 | * This class does not transmit the appId, and when deserializing on the server side, it just uses
10 | * the appId of the environment.
11 | *
12 | * Does not take applicationID of parents/children into consideration wrt Comparable, assumes they are both the same.
13 | */
14 | public final class Key implements Serializable, Comparable
15 | {
16 | static final long serialVersionUID = -448150158203091507L;
17 |
18 | private Key parentKey;
19 | private String kind;
20 | //private String appId;
21 | private long id;
22 | private String name;
23 | //private transient AppIdNamespace appIdNamespace;
24 |
25 | @SuppressWarnings("unused")
26 | private Key()
27 | {
28 | parentKey = null;
29 | kind = null;
30 | id = 0;
31 | name = null;
32 | }
33 |
34 | Key(String kind, String name)
35 | {
36 | this(kind, null, name);
37 | }
38 |
39 | Key(String kind, Key parentKey)
40 | {
41 | this(kind, parentKey, 0);
42 | }
43 |
44 | Key(String kind, Key parentKey, long id)
45 | {
46 | this(kind, parentKey, id, null);
47 | }
48 |
49 | Key(String kind, Key parentKey, String name)
50 | {
51 | this(kind, parentKey, 0, name);
52 | }
53 |
54 | Key(String kind, Key parentKey, long id, String name)
55 | {
56 | if (kind == null || kind.length() == 0)
57 | throw new IllegalArgumentException("No kind specified.");
58 | if (name != null)
59 | {
60 | if (name.length() == 0)
61 | throw new IllegalArgumentException("Name may not be empty.");
62 | if (id != 0)
63 | throw new IllegalArgumentException("Id and name may not both be specified at once.");
64 | }
65 | this.name = name;
66 | this.id = id;
67 | this.parentKey = parentKey;
68 | this.kind = kind;
69 | }
70 |
71 | public String getKind()
72 | {
73 | return kind;
74 | }
75 |
76 | public Key getParent()
77 | {
78 | return parentKey;
79 | }
80 |
81 | @Override
82 | public boolean equals(Object o)
83 | {
84 | if (this == o) return true;
85 | if (o == null || getClass() != o.getClass()) return false;
86 |
87 | Key key = (Key) o;
88 |
89 | if (id != key.id) return false;
90 | if (!kind.equals(key.kind)) return false;
91 | if (name != null ? !name.equals(key.name) : key.name != null) return false;
92 | if (parentKey != null ? !parentKey.equals(key.parentKey) : key.parentKey != null) return false;
93 |
94 | return true;
95 | }
96 |
97 | @Override
98 | public int hashCode()
99 | {
100 | int result = parentKey != null ? parentKey.hashCode() : 0;
101 | result = 31 * result + kind.hashCode();
102 | result = 31 * result + (int) (id ^ (id >>> 32));
103 | result = 31 * result + (name != null ? name.hashCode() : 0);
104 | return result;
105 | }
106 |
107 | public String toString()
108 | {
109 | StringBuilder buffer = new StringBuilder();
110 | appendToString(buffer);
111 | return buffer.toString();
112 | }
113 |
114 | private void appendToString(StringBuilder buffer)
115 | {
116 | if (parentKey != null)
117 | {
118 | parentKey.appendToString(buffer);
119 | buffer.append("/");
120 | }
121 | buffer.append(kind);
122 | buffer.append("(");
123 | if (name != null)
124 | buffer.append('"').append(name).append('"');
125 | else
126 | buffer.append(id);
127 | buffer.append(")");
128 | }
129 |
130 | public long getId()
131 | {
132 | return id;
133 | }
134 |
135 | public String getName()
136 | {
137 | return name;
138 | }
139 |
140 | public Key getChild(String kind, long id)
141 | {
142 | return new Key(kind, this, id);
143 | }
144 |
145 | public Key getChild(String kind, String name)
146 | {
147 | return new Key(kind, this, name);
148 | }
149 |
150 | private static Iterator getPathIterator(Key key)
151 | {
152 | LinkedList stack = new LinkedList();
153 | do
154 | {
155 | stack.addFirst(key);
156 | key = key.getParent();
157 | } while (key != null);
158 |
159 | return stack.iterator();
160 | }
161 |
162 | public int compareTo(Key other)
163 | {
164 | if (this == other)
165 | return 0;
166 | Iterator thisPath = getPathIterator(this);
167 | Iterator otherPath = getPathIterator(other);
168 | while (thisPath.hasNext())
169 | {
170 | Key thisKey = (Key) thisPath.next();
171 | if (otherPath.hasNext())
172 | {
173 | Key otherKey = (Key) otherPath.next();
174 | int result = compareToInternal(thisKey, otherKey);
175 | if (result != 0)
176 | return result;
177 | }
178 | else
179 | {
180 | return 1;
181 | }
182 | }
183 | return otherPath.hasNext() ? -1 : 0;
184 | }
185 |
186 | private static int compareToInternal(Key thisKey, Key otherKey)
187 | {
188 | if (thisKey == otherKey)
189 | return 0;
190 | int result = thisKey.getKind().compareTo(otherKey.getKind());
191 | if (result != 0)
192 | return result;
193 | if (thisKey.getId() != 0)
194 | if (otherKey.getId() == 0)
195 | return -1;
196 | else
197 | return Long.valueOf(thisKey.getId()).compareTo(Long.valueOf(otherKey.getId()));
198 | if (otherKey.getId() != 0)
199 | return 1;
200 | else
201 | return thisKey.getName().compareTo(otherKey.getName());
202 | }
203 | }
204 |
205 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/KeyFactory.java:
--------------------------------------------------------------------------------
1 | package com.google.appengine.api.datastore;
2 |
3 | /**
4 | * GWT emulation class, with most of the methods from KeyFactory.
5 | * Does not support the keyToString()/stringToKey() methods.
6 | */
7 | public class KeyFactory
8 | {
9 | public static final class Builder
10 | {
11 | public Builder addChild(String kind, String name)
12 | {
13 | current = KeyFactory.createKey(current, kind, name);
14 | return this;
15 | }
16 |
17 | public Builder addChild(String kind, long id)
18 | {
19 | current = KeyFactory.createKey(current, kind, id);
20 | return this;
21 | }
22 |
23 | public Key getKey()
24 | {
25 | return current;
26 | }
27 |
28 | private Key current;
29 |
30 | public Builder(String kind, String name)
31 | {
32 | current = KeyFactory.createKey(null, kind, name);
33 | }
34 |
35 | public Builder(String kind, long id)
36 | {
37 | current = KeyFactory.createKey(null, kind, id);
38 | }
39 |
40 | public Builder(Key key)
41 | {
42 | current = key;
43 | }
44 | }
45 |
46 | public static Key createKey(String kind, long id)
47 | {
48 | return createKey(null, kind, id);
49 | }
50 |
51 | public static Key createKey(Key parent, String kind, long id)
52 | {
53 | if (id == 0L)
54 | throw new IllegalArgumentException("id cannot be zero");
55 | else
56 | return new Key(kind, parent, id);
57 | }
58 |
59 | public static Key createKey(String kind, String name)
60 | {
61 | return createKey(null, kind, name);
62 | }
63 |
64 | public static Key createKey(Key parent, String kind, String name)
65 | {
66 | if (name == null || name.length() == 0)
67 | throw new IllegalArgumentException("name cannot be null or empty");
68 | else
69 | return new Key(kind, parent, name);
70 | }
71 |
72 | private KeyFactory()
73 | {
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Key_CustomFieldSerializer.java:
--------------------------------------------------------------------------------
1 | package com.google.appengine.api.datastore;
2 |
3 | import com.google.gwt.user.client.rpc.CustomFieldSerializer;
4 | import com.google.gwt.user.client.rpc.SerializationException;
5 | import com.google.gwt.user.client.rpc.SerializationStreamReader;
6 | import com.google.gwt.user.client.rpc.SerializationStreamWriter;
7 |
8 | /**
9 | * Custom field serializer for the datastore Key class. Does not transmit appid,
10 | * just parent/kind/id/name.
11 | */
12 | public class Key_CustomFieldSerializer extends CustomFieldSerializer {
13 |
14 | public static void deserialize(SerializationStreamReader streamReader, Key instance) {
15 | }
16 |
17 | public static Key instantiate(SerializationStreamReader streamReader) throws SerializationException {
18 | Key parent = (Key) streamReader.readObject();
19 | String kind = streamReader.readString();
20 | long id = streamReader.readLong();
21 | String name = streamReader.readString();
22 |
23 | // @SuppressWarnings("unused")
24 | // AppIdNamespace appIdNamespace =
25 | // (AppIdNamespace)streamReader.readObject();
26 |
27 | if (name == null)
28 | return KeyFactory.createKey(parent, kind, id);
29 | else
30 | return KeyFactory.createKey(parent, kind, name);
31 | }
32 |
33 | public static void serialize(SerializationStreamWriter streamWriter, Key instance) throws SerializationException {
34 | streamWriter.writeObject(instance.getParent());
35 | streamWriter.writeString(instance.getKind());
36 | streamWriter.writeLong(instance.getId());
37 | streamWriter.writeString(instance.getName());
38 | // streamWriter.writeObject(instance.getAppIdNamespace());
39 | }
40 |
41 | @Override
42 | public boolean hasCustomInstantiateInstance() {
43 | return true;
44 | }
45 |
46 | public Key instantiateInstance(SerializationStreamReader streamReader) throws SerializationException {
47 | return instantiate(streamReader);
48 | }
49 |
50 | @Override
51 | public void deserializeInstance(SerializationStreamReader streamReader, Key instance) throws SerializationException {
52 | deserialize(streamReader, instance);
53 | }
54 |
55 | @Override
56 | public void serializeInstance(SerializationStreamWriter streamWriter, Key instance) throws SerializationException {
57 | serialize(streamWriter, instance);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Link.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.google.appengine.api.datastore;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * A {@code Link} is a URL of limited length.
22 | *
23 | * In addition to adding the meaning of {@code URL} onto a String, a {@code Link}
24 | * can also be longer than a Text value, with a limit of 2038 characters.
25 | *
26 | */
27 | public final class Link implements Serializable, Comparable {
28 |
29 | public static final long serialVersionUID = 731239796613544443L;
30 |
31 | private String value;
32 |
33 | /**
34 | * This constructor exists for frameworks (e.g. Google Web Toolkit)
35 | * that require it for serialization purposes. It should not be
36 | * called explicitly.
37 | */
38 | @SuppressWarnings("unused")
39 | private Link() {
40 | value = null;
41 | }
42 |
43 | /**
44 | * Constructs a new {@code Link} object with the specified value.
45 | * This object cannot be modified after construction.
46 | */
47 | public Link(String value) {
48 | this.value = value;
49 | }
50 |
51 | /**
52 | * Returns the value of this {@code Link}.
53 | */
54 | public String getValue() {
55 | return value;
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | return value.hashCode();
61 | }
62 |
63 | /**
64 | * Two {@code Link} objects are considered equal if their content
65 | * strings match exactly.
66 | */
67 | @Override
68 | public boolean equals(Object object) {
69 | if (object instanceof Link) {
70 | Link key = (Link) object;
71 | return value.equals(key.value);
72 | }
73 | return false;
74 | }
75 |
76 | /**
77 | * Returns the entire text of this {@code Link}.
78 | */
79 | @Override
80 | public String toString() {
81 | return value;
82 | }
83 |
84 | @Override
85 | public int compareTo(Link l) {
86 | return value.compareTo(l.value);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/PhoneNumber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.google.appengine.api.datastore;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * A human-readable phone number. No validation is performed because phone
22 | * numbers have many different formats - local, long distance, domestic,
23 | * international, internal extension, TTY, VOIP, SMS, and alternative networks
24 | * like Skype, XFire and Roger Wilco. They all have their own numbering and
25 | * addressing formats.
26 | *
27 | */
28 | public final class PhoneNumber implements Serializable, Comparable {
29 |
30 | public static final long serialVersionUID = -8968032543663409348L;
31 |
32 | private String number;
33 |
34 | public PhoneNumber(String number) {
35 | if (number == null) {
36 | throw new NullPointerException("number must not be null");
37 | }
38 | this.number = number;
39 | }
40 |
41 | /**
42 | * This constructor exists for frameworks (e.g. Google Web Toolkit)
43 | * that require it for serialization purposes. It should not be
44 | * called explicitly.
45 | */
46 | @SuppressWarnings("unused")
47 | private PhoneNumber() {
48 | number = null;
49 | }
50 |
51 | public String getNumber() {
52 | return number;
53 | }
54 |
55 | @Override
56 | public boolean equals(Object o) {
57 | if (this == o) {
58 | return true;
59 | }
60 | if (o == null || getClass() != o.getClass()) {
61 | return false;
62 | }
63 |
64 | PhoneNumber that = (PhoneNumber) o;
65 |
66 | if (!number.equals(that.number)) {
67 | return false;
68 | }
69 |
70 | return true;
71 | }
72 |
73 | @Override
74 | public int hashCode() {
75 | return number.hashCode();
76 | }
77 |
78 | @Override
79 | public int compareTo(PhoneNumber o) {
80 | return number.compareTo(o.number);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/PostalAddress.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.google.appengine.api.datastore;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * A human-readable mailing address. Mailing address formats vary widely so
22 | * no validation is performed.
23 | *
24 | */
25 | public final class PostalAddress implements Serializable, Comparable {
26 |
27 | public static final long serialVersionUID = -1090628591187239495L;
28 |
29 | private String address;
30 |
31 | public PostalAddress(String address) {
32 | if (address == null) {
33 | throw new NullPointerException("address must not be null");
34 | }
35 | this.address = address;
36 | }
37 |
38 | /**
39 | * This constructor exists for frameworks (e.g. Google Web Toolkit)
40 | * that require it for serialization purposes. It should not be
41 | * called explicitly.
42 | */
43 | @SuppressWarnings("unused")
44 | private PostalAddress() {
45 | address = null;
46 | }
47 |
48 | public String getAddress() {
49 | return address;
50 | }
51 |
52 | @Override
53 | public boolean equals(Object o) {
54 | if (this == o) {
55 | return true;
56 | }
57 | if (o == null || getClass() != o.getClass()) {
58 | return false;
59 | }
60 |
61 | PostalAddress that = (PostalAddress) o;
62 |
63 | if (!address.equals(that.address)) {
64 | return false;
65 | }
66 |
67 | return true;
68 | }
69 |
70 | @Override
71 | public int hashCode() {
72 | return address.hashCode();
73 | }
74 |
75 | @Override
76 | public int compareTo(PostalAddress o) {
77 | return address.compareTo(o.address);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Rating.java:
--------------------------------------------------------------------------------
1 | // Copyright 2009 Google Inc. All Rights Reserved.
2 | package com.google.appengine.api.datastore;
3 |
4 | import java.io.Serializable;
5 |
6 | /**
7 | * A user-provided integer rating for a piece of content. Normalized to a 0-100
8 | * scale.
9 | *
10 | */
11 | public final class Rating implements Serializable, Comparable {
12 |
13 | public static final long serialVersionUID = 362898405551261187L;
14 |
15 | /**
16 | * The minimum legal value for a rating.
17 | */
18 | public static final int MIN_VALUE = 0;
19 |
20 | /**
21 | * The maximum legal value for a rating.
22 | */
23 | public static final int MAX_VALUE = 100;
24 |
25 | private int rating;
26 |
27 | /**
28 | * @throws IllegalArgumentException
29 | * If {@code rating} is smaller than {@link #MIN_VALUE} or
30 | * greater than {@link #MAX_VALUE}
31 | */
32 | public Rating(int rating) {
33 | if (rating < MIN_VALUE || rating > MAX_VALUE) {
34 | // String.format() not part of GWT JRE emulation
35 | // throw new IllegalArgumentException(String.format(
36 | // "rating must be no smaller than %d and no greater than %d (received %d)", MIN_VALUE, MAX_VALUE,
37 | // rating));
38 | throw new IllegalArgumentException(
39 | "rating must be no smaller than " + MIN_VALUE + " and no greater than " + MAX_VALUE + " (received " + rating + ")");
40 | }
41 | this.rating = rating;
42 | }
43 |
44 | /**
45 | * This constructor exists for frameworks (e.g. Google Web Toolkit) that
46 | * require it for serialization purposes. It should not be called
47 | * explicitly.
48 | */
49 | @SuppressWarnings("unused")
50 | private Rating() {
51 | this(0);
52 | }
53 |
54 | public int getRating() {
55 | return rating;
56 | }
57 |
58 | @Override
59 | public boolean equals(Object o) {
60 | if (this == o) {
61 | return true;
62 | }
63 | if (o == null || getClass() != o.getClass()) {
64 | return false;
65 | }
66 |
67 | Rating rating1 = (Rating) o;
68 |
69 | if (rating != rating1.rating) {
70 | return false;
71 | }
72 |
73 | return true;
74 | }
75 |
76 | @Override
77 | public int hashCode() {
78 | return rating;
79 | }
80 |
81 | @Override
82 | public int compareTo(Rating o) {
83 | return Integer.valueOf(rating).compareTo(o.rating);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/ShortBlob.java:
--------------------------------------------------------------------------------
1 | package com.google.appengine.api.datastore;
2 |
3 | import java.io.Serializable;
4 | import java.util.Arrays;
5 |
6 | /**
7 | * GWT emulation class, leaves off some references to not-gwt-safe code. In particular, the Comparable
8 | * interface implementation.
9 | */
10 | @SuppressWarnings("serial")
11 | public class ShortBlob implements Serializable
12 | {
13 | private byte bytes[];
14 |
15 | @SuppressWarnings("unused")
16 | private ShortBlob()
17 | {
18 | bytes = null;
19 | }
20 |
21 | public ShortBlob(byte bytes[])
22 | {
23 | this.bytes = new byte[bytes.length];
24 | System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
25 | }
26 |
27 | public byte[] getBytes()
28 | {
29 | return bytes;
30 | }
31 |
32 | public int hashCode()
33 | {
34 | return Arrays.hashCode(bytes);
35 | }
36 |
37 | public boolean equals(Object object)
38 | {
39 | if (object instanceof ShortBlob)
40 | {
41 | ShortBlob other = (ShortBlob) object;
42 | return Arrays.equals(bytes, other.bytes);
43 | }
44 | else
45 | {
46 | return false;
47 | }
48 | }
49 |
50 | public String toString()
51 | {
52 | return (new StringBuilder()).append("").toString();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/datastore/Text.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package com.google.appengine.api.datastore;
17 |
18 | import java.io.Serializable;
19 |
20 | /**
21 | * {@code Text} wraps around a string of unlimited size.
22 | *
23 | * Ordinary Java strings stored as properties in {@code Entity}
24 | * objects are limited to 500 characters. However, {@code Text}
25 | * objects can also be stored in properties, and are unlimited in
26 | * size. However, they will not be indexed for query purposes.
27 | *
28 | */
29 | public final class Text implements Serializable {
30 |
31 | public static final long serialVersionUID = -8389037235415462280L;
32 |
33 | private String value;
34 |
35 | /**
36 | * This constructor exists for frameworks (e.g. Google Web Toolkit)
37 | * that require it for serialization purposes. It should not be
38 | * called explicitly.
39 | */
40 | @SuppressWarnings("unused")
41 | private Text() {
42 | }
43 |
44 | /**
45 | * Construct a new {@code Text} object with the specified value.
46 | * This object cannot be modified after construction.
47 | */
48 | public Text(String value) {
49 | this.value = value;
50 | }
51 |
52 | /**
53 | * Return the value of this {@code Text}. Can be {@code null}.
54 | */
55 | public String getValue() {
56 | return value;
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | if (value == null) {
62 | return -1;
63 | }
64 | return value.hashCode();
65 | }
66 |
67 | /**
68 | * Two {@code Text} objects are considered equal if their content
69 | * strings match exactly.
70 | */
71 | @Override
72 | public boolean equals(Object object) {
73 | if (object instanceof Text) {
74 | Text key = (Text) object;
75 | if (value == null) {
76 | return key.value == null;
77 | }
78 | return value.equals(key.value);
79 | }
80 | return false;
81 | }
82 |
83 | /**
84 | * Returns the first 70 characters of the underlying string.
85 | */
86 | @Override
87 | public String toString() {
88 | if (value == null) {
89 | return "";
90 | }
91 | String text = value;
92 | if (text.length() > 70) {
93 | text = text.substring(0, 70) + "...";
94 | }
95 | return "";
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/appengine/api/users/User.java:
--------------------------------------------------------------------------------
1 | package com.google.appengine.api.users;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * GWT emulation class.
7 | */
8 | public class User implements Serializable, Comparable
9 | {
10 | static final long serialVersionUID = 8691571286358652288L;
11 |
12 | private String email;
13 | private String authDomain;
14 | private String userId;
15 |
16 | @SuppressWarnings("unused")
17 | private User()
18 | {
19 | }
20 |
21 | public User(String email, String authDomain)
22 | {
23 | this(email, authDomain, null);
24 | }
25 |
26 | public User(String email, String authDomain, String userId)
27 | {
28 | if (email == null)
29 | throw new NullPointerException("email must be specified");
30 | if (authDomain == null)
31 | {
32 | throw new NullPointerException("authDomain must be specified");
33 | }
34 | else
35 | {
36 | this.email = email;
37 | this.authDomain = authDomain;
38 | this.userId = userId;
39 | return;
40 | }
41 | }
42 |
43 | public String getNickname()
44 | {
45 | int indexOfDomain = email.indexOf("@" + authDomain);
46 | if (indexOfDomain == -1)
47 | return email;
48 | else
49 | return email.substring(0, indexOfDomain);
50 | }
51 |
52 | public String getAuthDomain()
53 | {
54 | return authDomain;
55 | }
56 |
57 | public String getEmail()
58 | {
59 | return email;
60 | }
61 |
62 | public String getUserId()
63 | {
64 | return userId;
65 | }
66 |
67 | public String toString()
68 | {
69 | return email;
70 | }
71 |
72 | public boolean equals(Object object)
73 | {
74 | if (!(object instanceof User))
75 | {
76 | return false;
77 | }
78 | else
79 | {
80 | User user = (User) object;
81 | return user.email.equals(email) && user.authDomain.equals(authDomain);
82 | }
83 | }
84 |
85 | public int hashCode()
86 | {
87 | return 17 * email.hashCode() + authDomain.hashCode();
88 | }
89 |
90 | public int compareTo(User user)
91 | {
92 | return email.compareTo(user.email);
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/resources/com/google/appengine/super/com/google/apphosting/api/NamespaceResources.java:
--------------------------------------------------------------------------------
1 | // Copyright 2009 Google Inc. All Rights Reserved.
2 |
3 | package com.google.apphosting.api;
4 |
5 | /**
6 | * Reources for namespaces used by front end and back end.
7 | *
8 | */
9 | public final class NamespaceResources {
10 |
11 | /**
12 | * The separator character used to encode the appId/namespace pair.
13 | */
14 | public static final char NAMESPACE_SEPARATOR = '!';
15 |
16 | private NamespaceResources() {
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/resources/com/googlecode/objectify/Objectify.gwt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/com/googlecode/objectify/super/com/googlecode/objectify/Key.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.objectify;
2 |
3 | import java.io.Serializable;
4 |
5 | import com.googlecode.objectify.Key;
6 | import com.googlecode.objectify.Ref;
7 |
8 | /**
9 | * We need to provide an alternate, stripped-down version of this so that we
10 | * can exclude the constructors that tie into non-GWT-safe code (the factories).
11 | *
12 | * @author Jeff Schnitzer
13 | */
14 | public class Key implements Serializable, Comparable>
15 | {
16 | private static final long serialVersionUID = 2L;
17 |
18 | /** Key.create(key) is easier to type than new Key(key) */
19 | public static Key create(com.google.appengine.api.datastore.Key raw) {
20 | if (raw == null)
21 | throw new NullPointerException("Cannot create a Key> from a null datastore Key");
22 |
23 | return new Key(raw);
24 | }
25 |
26 | /** */
27 | protected com.google.appengine.api.datastore.Key raw;
28 |
29 | /** Cache the instance of the parent wrapper to avoid unnecessary garbage */
30 | transient protected Key> parent;
31 |
32 | /** For GWT serialization */
33 | protected Key() {}
34 |
35 | /** Wrap a raw Key */
36 | private Key(com.google.appengine.api.datastore.Key raw) {
37 | this.raw = raw;
38 | }
39 |
40 | /**
41 | * @return the raw datastore version of this key
42 | */
43 | public com.google.appengine.api.datastore.Key getRaw() {
44 | return this.raw;
45 | }
46 |
47 | /**
48 | * @return the id associated with this key, or 0 if this key has a name.
49 | */
50 | public long getId() {
51 | return this.raw.getId();
52 | }
53 |
54 | /**
55 | * @return the name associated with this key, or null if this key has an id
56 | */
57 | public String getName() {
58 | return this.raw.getName();
59 | }
60 |
61 | /**
62 | * @return the low-level datastore kind associated with this Key
63 | */
64 | public String getKind() {
65 | return this.raw.getKind();
66 | }
67 |
68 | /**
69 | * @return the parent key, or null if there is no parent. Note that
70 | * the parent could potentially have any type.
71 | */
72 | @SuppressWarnings("unchecked")
73 | public Key getParent() {
74 | if (this.parent == null && this.raw.getParent() != null)
75 | this.parent = new Key(this.raw.getParent());
76 |
77 | return (Key)this.parent;
78 | }
79 |
80 | /**
81 | * Gets the root of a parent graph of keys. If a Key has no parent, it is the root.
82 | *
83 | * @return the topmost parent key, or this object itself if it is the root.
84 | * Note that the root key could potentially have any type.
85 | */
86 | @SuppressWarnings("unchecked")
87 | public Key getRoot() {
88 | if (this.getParent() == null)
89 | return (Key)this;
90 | else
91 | return this.getParent().getRoot();
92 | }
93 |
94 | /** A type-safe equivalence comparison */
95 | public boolean equivalent(Key other) {
96 | return equals(other);
97 | }
98 |
99 | /** A type-safe equivalence comparison */
100 | public boolean equivalent(Ref other) {
101 | return (other == null) ? false : equals(other.key());
102 | }
103 |
104 | /**
105 | * Compares based on comparison of the raw key
106 | */
107 | @Override
108 | public int compareTo(Key> other) {
109 | return this.raw.compareTo(other.raw);
110 | }
111 |
112 | /** */
113 | @Override
114 | public boolean equals(Object obj) {
115 | if (obj == null)
116 | return false;
117 |
118 | if (!(obj instanceof Key>))
119 | return false;
120 |
121 | return this.compareTo((Key>)obj) == 0;
122 | }
123 |
124 | /** */
125 | @Override
126 | public int hashCode() {
127 | return this.raw.hashCode();
128 | }
129 |
130 | /** Creates a human-readable version of this key */
131 | @Override
132 | public String toString() {
133 | return "Key>(" + this.raw + ")";
134 | }
135 |
136 | /**
137 | * Easy null-safe conversion of the raw key.
138 | */
139 | public static Key key(com.google.appengine.api.datastore.Key raw) {
140 | if (raw == null)
141 | return null;
142 | else
143 | return new Key(raw);
144 | }
145 |
146 | /**
147 | * Easy null-safe conversion of the typed key.
148 | */
149 | public static com.google.appengine.api.datastore.Key raw(Key> typed) {
150 | if (typed == null)
151 | return null;
152 | else
153 | return typed.getRaw();
154 | }
155 | }
--------------------------------------------------------------------------------
/src/main/resources/com/googlecode/objectify/super/com/googlecode/objectify/NotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.objectify;
2 |
3 |
4 | /**
5 | * Exception thrown when a fetch for something could not be found. This is associated with the
6 | * getSafe() and keySafe() methods on Ref; if the item being sought in the Ref couldn't be found,
7 | * this will be thrown.
8 | */
9 | public class NotFoundException extends RuntimeException
10 | {
11 | private static final long serialVersionUID = 1L;
12 |
13 | /** */
14 | private Key> key;
15 |
16 | /** Thrown when there is no key context (eg, query.first() on an empty result set) */
17 | public NotFoundException() {
18 | this(null);
19 | }
20 |
21 | /** Thrown when we at least know what we are looking for! */
22 | public NotFoundException(Key> key) {
23 | super(key == null ? "No entity was found" : "No entity was found matching the key: " + key);
24 | this.key = key;
25 | }
26 |
27 | /** @return the key we are looking for, if known */
28 | public Key> getKey() {
29 | return this.key;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/resources/com/googlecode/objectify/super/com/googlecode/objectify/Ref.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.objectify;
2 |
3 | import java.io.Serializable;
4 | import com.googlecode.objectify.Key;
5 | import com.googlecode.objectify.NotFoundException;
6 | import com.googlecode.objectify.impl.ref.LiveRef;
7 |
8 | /**
9 | * GWT emulation of the Ref> class. Not complete; there's a lot we can't do client-side.
10 | *
11 | * @author Jeff Schnitzer
12 | */
13 | public class Ref implements Serializable, Comparable[>
14 | {
15 | private static final long serialVersionUID = 1L;
16 |
17 | Key key;
18 | T value;
19 |
20 | /** */
21 | public static Ref create(Key key) {
22 | if (key == null)
23 | throw new NullPointerException("Cannot create a Ref from a null key");
24 |
25 | return new LiveRef(key);
26 | }
27 |
28 | /** For GWT */
29 | protected Ref() {}
30 |
31 | /** */
32 | public Ref(Key key) {
33 | this.key = key;
34 | }
35 |
36 | /** */
37 | public Ref(Key key, T value) {
38 | this.key = key;
39 | this.value = value;
40 | }
41 |
42 | /**
43 | */
44 | public Key key() {
45 | if (key == null)
46 | throw new IllegalStateException("This ref was created without a key, and we cannot determine keys on GWT client-side");
47 |
48 | return key;
49 | }
50 |
51 | /**
52 | */
53 | public T get() {
54 | return value;
55 | }
56 |
57 | /**
58 | */
59 | public T getValue() {
60 | return value;
61 | }
62 |
63 | /**
64 | */
65 | final public Key getKey() {
66 | return key();
67 | }
68 |
69 | /**
70 | */
71 | final public T safe() {
72 | T t = this.get();
73 | if (t == null)
74 | throw new NotFoundException(key());
75 | else
76 | return t;
77 | }
78 |
79 | /** Comparison is based on key */
80 | @Override
81 | public int compareTo(Ref o) {
82 | return this.key().compareTo(o.key());
83 | }
84 |
85 | /** Equality comparison is based on key equivalence */
86 | @Override
87 | public boolean equals(Object obj) {
88 | return obj != null && obj instanceof Ref && key().equals(((Ref>)obj).key());
89 | }
90 |
91 | /** Type-safe comparison for key equivalence */
92 | public boolean equivalent(Ref other) {
93 | return equals(other);
94 | }
95 |
96 | /** Type safe comparison for key equivalence */
97 | public boolean equivalent(Key other) {
98 | return key().equivalent(other);
99 | }
100 |
101 | /** Hash code is simply that of key */
102 | @Override
103 | public int hashCode() {
104 | return key().hashCode();
105 | }
106 |
107 | /** Renders some info about the key */
108 | @Override
109 | public String toString() {
110 | return "Ref>(key=" + key() + ", value=" + value + ")";
111 | }
112 | }
--------------------------------------------------------------------------------
/src/main/resources/com/googlecode/objectify/super/com/googlecode/objectify/impl/ref/LiveRef.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.objectify.impl.ref;
2 |
3 | import com.googlecode.objectify.Key;
4 | import com.googlecode.objectify.Ref;
5 |
6 | /**
7 | * ]GWT emulation of Ref is contained within Ref; this class is necessary only to keep serialization working.
8 | *
9 | * @author Jeff Schnitzer
10 | */
11 | public class LiveRef extends Ref
12 | {
13 | /** Make GWT happy */
14 | protected LiveRef() {}
15 |
16 | /** */
17 | public LiveRef(Key key) {
18 | super(key);
19 | }
20 |
21 | /** */
22 | public LiveRef(Key key, T value) {
23 | super(key, value);
24 | }
25 | }
--------------------------------------------------------------------------------
/src/main/resources/com/googlecode/objectify/super/com/googlecode/objectify/impl/ref/LiveRef_CustomFieldSerializer.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.objectify.impl.ref;
2 |
3 | import com.google.gwt.user.client.rpc.CustomFieldSerializer;
4 | import com.google.gwt.user.client.rpc.SerializationException;
5 | import com.google.gwt.user.client.rpc.SerializationStreamReader;
6 | import com.google.gwt.user.client.rpc.SerializationStreamWriter;
7 | import com.googlecode.objectify.Key;
8 |
9 | /**
10 | * Custom field serializer for the LiveRef class.
11 | */
12 | public class LiveRef_CustomFieldSerializer extends CustomFieldSerializer> {
13 |
14 | public static void deserialize(SerializationStreamReader streamReader, LiveRef> instance) {
15 | }
16 |
17 | public static LiveRef> instantiate(SerializationStreamReader streamReader) throws SerializationException {
18 | @SuppressWarnings("unchecked")
19 | Key