Skip to content

Commit

Permalink
Added javadoc for protobuf (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
garethahealy authored Sep 7, 2017
1 parent 1aa0792 commit 213a9c0
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,53 @@
import org.dozer.propertydescriptor.PropertyDescriptorFactory;

/**
* @author Dmitry Spikhalskiy
* {@link DozerModule} which adds support for Protobuf.
* This is the main integration point into Dozer and is loaded via an SPI mechanism.
*/
public class ProtobufSupportModule implements DozerModule {

private BeanContainer beanContainer;
private DestBeanCreator destBeanCreator;
private PropertyDescriptorFactory propertyDescriptorFactory;

/**
* {@inheritDoc}
*/
@Deprecated
@Override
public void init(BeanContainer beanContainer, DestBeanCreator destBeanCreator, PropertyDescriptorFactory propertyDescriptorFactory) {
this.beanContainer = beanContainer;
this.destBeanCreator = destBeanCreator;
this.propertyDescriptorFactory = propertyDescriptorFactory;
}

/**
* {@inheritDoc}
*/
@Override
public void init() {

}

/**
* {@inheritDoc}
*/
@Override
public Collection<BeanBuilderCreationStrategy> getBeanBuilderCreationStrategies() {
return Collections.singleton(new ByProtobufBuilder());
}

/**
* {@inheritDoc}
*/
@Override
public Collection<BeanFieldsDetector> getBeanFieldsDetectors() {
return Collections.singleton(new ProtobufBeanFieldsDetector());
}

/**
* {@inheritDoc}
*/
@Override
public Collection<PropertyDescriptorCreationStrategy> getPropertyDescriptorCreationStrategies() {
return Collections.singleton(new ProtoFieldPropertyDescriptorCreationStrategy(beanContainer, destBeanCreator, propertyDescriptorFactory));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@
import org.dozer.factory.BeanCreationDirective;

/**
* @author Dmitry Spikhalskiy
* {@link BeanBuilderCreationStrategy} that is applicable to {@link Message}
*/
public class ByProtobufBuilder implements BeanBuilderCreationStrategy {

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(BeanCreationDirective directive) {
return Message.class.isAssignableFrom(directive.getActualClass());
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public BeanBuilder create(BeanCreationDirective directive) {
Class<? extends Message> messageClass = (Class<? extends Message>)directive.getActualClass();
final Message.Builder protoBuilder = ProtoUtils.getBuilder(messageClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,45 @@
import org.dozer.BeanBuilder;

/**
* @author Dmitry Spikhalskiy
* {@link BeanBuilder} that instantiates {@link Message}
*/
public class ProtoBeanBuilder implements BeanBuilder {

protected Message.Builder internalProtoBuilder;
protected Class<? extends Message> beanClass;

/**
* {@link BeanBuilder} which is used to create instances of {@link Message} via {@link Message.Builder}
*
* @param internalProtoBuilder builder for {@link Message}
* @param beanClass type of {@link Message} to create
*/
public ProtoBeanBuilder(Message.Builder internalProtoBuilder, Class<? extends Message> beanClass) {
this.internalProtoBuilder = internalProtoBuilder;
this.beanClass = beanClass;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends Message> beanClass() {
return beanClass;
}

/**
* Get the {@link Message.Builder}
*
* @return instance of {@link Message.Builder}
*/
public Message.Builder internalProtoBuilder() {
return internalProtoBuilder;
}

/**
* {@inheritDoc}
*/
@Override
public Object build() {
return internalProtoBuilder.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2005-2017 Dozer Project
*
* 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.
*/
/**
* BeanBuilder extensions for Protbuf
*/
package com.github.dozermapper.protobuf.builder;
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,32 @@
import org.dozer.classmap.generator.BeanFieldsDetector;

/**
* @author Dmitry Spikhalskiy
* {@link BeanFieldsDetector} that accepts {@link Message}
*/
public class ProtobufBeanFieldsDetector implements BeanFieldsDetector {

/**
* {@inheritDoc}
*/
@Override
public boolean accepts(Class<?> clazz) {
return Message.class.isAssignableFrom(clazz);
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Set<String> getReadableFieldNames(Class<?> clazz) {
return getFieldNames((Class<? extends Message>)clazz);
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Set<String> getWritableFieldNames(Class<?> clazz) {
return getFieldNames((Class<? extends Message>)clazz);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2005-2017 Dozer Project
*
* 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.
*/
/**
* {@link org.dozer.classmap.generator.BeanFieldsDetector} extensions for Protbuf
*/
package com.github.dozermapper.protobuf.classmap.generator;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2005-2017 Dozer Project
*
* 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.
*/
/**
* Extension classes to integrate Dozer with Protobuf as a first-class-citizen
*/
package com.github.dozermapper.protobuf;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.slf4j.LoggerFactory;

/**
* @author Dmitry Spikhalskiy
* {@link org.dozer.propertydescriptor.DozerPropertyDescriptor} which resolves Protobuf fields
*/
public class ProtoFieldPropertyDescriptor extends AbstractPropertyDescriptor {

Expand All @@ -52,6 +52,19 @@ public class ProtoFieldPropertyDescriptor extends AbstractPropertyDescriptor {
private Class<?> genericType;
private Descriptors.FieldDescriptor fieldDescriptor;

/**
* {@link org.dozer.propertydescriptor.DozerPropertyDescriptor} which resolves Protobuf fields
*
* @param clazz clazz to work on
* @param fieldName field name to resolve
* @param isIndexed whether the mapping is indexed
* @param index current index
* @param srcDeepIndexHintContainer source hint
* @param destDeepIndexHintContainer destination hint
* @param beanContainer {@link BeanContainer} instance
* @param destBeanCreator {@link DestBeanCreator} instance
* @param propertyDescriptorFactory {@link PropertyDescriptorFactory} instance
*/
public ProtoFieldPropertyDescriptor(Class<?> clazz, String fieldName, boolean isIndexed, int index, HintContainer srcDeepIndexHintContainer,
HintContainer destDeepIndexHintContainer, BeanContainer beanContainer, DestBeanCreator destBeanCreator,
PropertyDescriptorFactory propertyDescriptorFactory) {
Expand All @@ -62,6 +75,9 @@ public ProtoFieldPropertyDescriptor(Class<?> clazz, String fieldName, boolean is
this.propertyDescriptorFactory = propertyDescriptorFactory;
}

/**
* {@inheritDoc}
*/
@Override
public Class<?> getPropertyType() {
if (this.propertyType == null) {
Expand Down Expand Up @@ -90,6 +106,9 @@ public Class<?> getPropertyType() {
return this.propertyType;
}

/**
* {@inheritDoc}
*/
@Override
public Object getPropertyValue(Object bean) {
Object result;
Expand Down Expand Up @@ -119,6 +138,9 @@ private Object getSimplePropertyValue(Object bean) {
return ProtoUtils.unwrapEnums(value, beanContainer);
}

/**
* {@inheritDoc}
*/
@Override
public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) {
if (!(bean instanceof ProtoBeanBuilder)) {
Expand Down Expand Up @@ -148,6 +170,9 @@ public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) {
}
}

/**
* {@inheritDoc}
*/
@Override
public Class<?> genericType() {
if (this.genericType == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,41 @@
import org.dozer.util.MappingUtils;

/**
* @author Dmitry Spikhalskiy
* {@link PropertyDescriptorCreationStrategy} which is used to build {@link ProtoFieldPropertyDescriptor}
* via {@link #buildFor(Class, String, boolean, int, HintContainer, HintContainer)}.
*/
public class ProtoFieldPropertyDescriptorCreationStrategy implements PropertyDescriptorCreationStrategy {

private final BeanContainer beanContainer;
private final DestBeanCreator destBeanCreator;
private final PropertyDescriptorFactory propertyDescriptorFactory;

/**
* {@link PropertyDescriptorCreationStrategy} which is used to create instances of {@link DozerPropertyDescriptor}
*
* @param beanContainer {@link BeanContainer} instance
* @param destBeanCreator {@link DestBeanCreator} instance
* @param propertyDescriptorFactory {@link PropertyDescriptorFactory} instance
*/
public ProtoFieldPropertyDescriptorCreationStrategy(BeanContainer beanContainer, DestBeanCreator destBeanCreator, PropertyDescriptorFactory propertyDescriptorFactory) {
this.beanContainer = beanContainer;
this.destBeanCreator = destBeanCreator;
this.propertyDescriptorFactory = propertyDescriptorFactory;
}

/**
* {@inheritDoc}
*/
@Override
public DozerPropertyDescriptor buildFor(Class<?> clazz, String fieldName, boolean isIndexed, int index, HintContainer srcDeepIndexHintContainer,
HintContainer destDeepIndexHintContainer) {
return new ProtoFieldPropertyDescriptor(clazz, fieldName, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer,
beanContainer, destBeanCreator, propertyDescriptorFactory);
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public boolean isApplicable(Class<?> clazz, String fieldName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2005-2017 Dozer Project
*
* 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.
*/
/**
* PropertyDescriptor extensions for Protbuf
*/
package com.github.dozermapper.protobuf.propertydescriptor;
Loading

0 comments on commit 213a9c0

Please sign in to comment.