-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAA-343: Updated java sdk generation and added profile serializer tem…
…plate.
- Loading branch information
Igor Khanenko
committed
Feb 10, 2015
1 parent
26e49ef
commit 742a8c1
Showing
5 changed files
with
168 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
server/control/src/main/resources/sdk/java/profile/DefaultProfileSerializer.java.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2014 CyberVision, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kaaproject.kaa.client.profile; | ||
|
||
import java.io.IOException; | ||
|
||
import org.kaaproject.kaa.common.avro.AvroByteArrayConverter; | ||
import ${profile_class_package}.${profile_class}; | ||
|
||
/** | ||
* This class serialize entity defined in profile schema and returned by profile container. | ||
* This class have a special behavior in case of default schema and serialize default profile | ||
* disregarding empty profile container. | ||
* <p/> | ||
* This implementation is auto-generated. Please modify corresponding template file. | ||
* | ||
* @author Andrew Shvayka | ||
*/ | ||
class ProfileSerializer { | ||
|
||
private final AvroByteArrayConverter<${profile_class}> converter = new AvroByteArrayConverter<${profile_class}>(${profile_class}.class); | ||
|
||
byte[] toByteArray(ProfileContainer container) throws IOException { | ||
${profile_class} profile; | ||
if (container != null) { | ||
profile = container.getProfile(); | ||
} | ||
if (profile == null) { | ||
profile = new ${profile_class}(); | ||
} | ||
return converter.toByteArray(profile); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
server/control/src/main/resources/sdk/java/profile/ProfileContainer.java.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2014 CyberVision, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kaaproject.kaa.client.profile; | ||
|
||
import ${profile_class_package}.${profile_class}; | ||
|
||
/** | ||
* Interface for the profile container. | ||
*/ | ||
public interface ProfileContainer { | ||
|
||
/** | ||
* Retrieves serialized profile | ||
* | ||
* @return byte array with serialized profile | ||
* | ||
*/ | ||
${profile_class} getProfile(); | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
server/control/src/main/resources/sdk/java/profile/ProfileSerializer.java.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2014 CyberVision, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kaaproject.kaa.client.profile; | ||
|
||
import java.io.IOException; | ||
|
||
import org.kaaproject.kaa.common.avro.AvroByteArrayConverter; | ||
import ${profile_class_package}.${profile_class}; | ||
|
||
/** | ||
* This class serialize entity defined in profile schema and returned by profile container. | ||
* This class have a special behavior in case of default schema and serialize default profile | ||
* disregarding empty profile container. | ||
* <p/> | ||
* This implementation is auto-generated. Please modify corresponding template file. | ||
* | ||
* @author Andrew Shvayka | ||
*/ | ||
class ProfileSerializer { | ||
|
||
private final AvroByteArrayConverter<${profile_class}> converter = new AvroByteArrayConverter<${profile_class}>(${profile_class}.class); | ||
|
||
byte[] toByteArray(ProfileContainer container) throws IOException { | ||
${profile_class} profile; | ||
if (container == null) { | ||
throw new RuntimeException("Profile container is not set!"); | ||
} else { | ||
profile = container.getProfile(); | ||
} | ||
if (profile != null) { | ||
return converter.toByteArray(profile); | ||
} else { | ||
throw new RuntimeException("Profile is not set!"); | ||
} | ||
} | ||
} |