diff --git a/java/src/main/java/org/msgpack/annotation/Ignore.java b/java/src/main/java/org/msgpack/annotation/Ignore.java new file mode 100644 index 0000000..dfe9f7e --- /dev/null +++ b/java/src/main/java/org/msgpack/annotation/Ignore.java @@ -0,0 +1,28 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// 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.msgpack.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Ignore { +} diff --git a/java/src/main/java/org/msgpack/annotation/Index.java b/java/src/main/java/org/msgpack/annotation/Index.java new file mode 100644 index 0000000..b567012 --- /dev/null +++ b/java/src/main/java/org/msgpack/annotation/Index.java @@ -0,0 +1,29 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// 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.msgpack.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Index { + int value(); +} diff --git a/java/src/main/java/org/msgpack/annotation/Required.java b/java/src/main/java/org/msgpack/annotation/Required.java new file mode 100644 index 0000000..00d4ecb --- /dev/null +++ b/java/src/main/java/org/msgpack/annotation/Required.java @@ -0,0 +1,28 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// 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.msgpack.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Required { +} diff --git a/java/src/main/java/org/msgpack/template/FieldList.java b/java/src/main/java/org/msgpack/template/FieldList.java new file mode 100644 index 0000000..8d6f28f --- /dev/null +++ b/java/src/main/java/org/msgpack/template/FieldList.java @@ -0,0 +1,96 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// 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.msgpack.template; + +import java.util.List; +import java.util.ArrayList; + +public class FieldList { + public static class Entry { + public Entry() { + this.name = null; + this.option = null; + } + + public Entry(String name, FieldOption option) { + this.name = name; + this.option = option; + } + + private String name; + private FieldOption option; + + public String getName() { + return name; + } + + public FieldOption getOption() { + return option; + } + + boolean isAvailable() { + return this.name != null; + } + + boolean isRequired() { + return this.option == FieldOption.REQUIRED; + } + + boolean isOptional() { + return this.option == FieldOption.OPTIONAL; + } + + boolean isNullable() { + return this.option == FieldOption.NULLABLE; + } + } + + private ArrayList list; + + public FieldList() { + list = new ArrayList(); + } + + public void add(final String name) { + add(name, FieldOption.REQUIRED); + } + + public void add(final String name, final FieldOption option) { + list.add(new Entry(name, option)); + } + + public void put(int index, final String name) { + put(index, name, FieldOption.REQUIRED); + } + + public void put(int index, final String name, final FieldOption option) { + if(list.size() < index) { + do { + list.add(new Entry()); + } while(list.size() < index); + list.add(new Entry(name, option)); + } else { + list.set(index, new Entry(name, option)); + } + } + + List getList() { + return list; + } +} + diff --git a/java/src/main/java/org/msgpack/template/FieldOption.java b/java/src/main/java/org/msgpack/template/FieldOption.java new file mode 100644 index 0000000..41f152f --- /dev/null +++ b/java/src/main/java/org/msgpack/template/FieldOption.java @@ -0,0 +1,27 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// 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.msgpack.template; + +public enum FieldOption { + IGNORE, + REQUIRED, + OPTIONAL, + NULLABLE, + DEFAULT; +} +