org.apache.activemq.protobuf.compiler.ProtoDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activemq-all Show documentation
Show all versions of activemq-all Show documentation
Puts together an ActiveMQ jar bundle
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.activemq.protobuf.compiler;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class ProtoDescriptor {
private String packageName;
private Map options = new LinkedHashMap();
private Map messages = new LinkedHashMap();
private Map enums = new LinkedHashMap();
private List extendsList = new ArrayList();
private Map services = new LinkedHashMap();
List imports = new ArrayList();
Map importProtoDescriptors = new LinkedHashMap();
private String name;
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public void setOptions(Map options) {
this.options = options;
}
public void setMessages(Map messages) {
this.messages = messages;
}
public void setEnums(Map enums) {
this.enums = enums;
}
public void setExtends(List extendsList) {
this.extendsList = extendsList;
}
public List getExtends() {
return extendsList;
}
public String getPackageName() {
return packageName;
}
public Map getOptions() {
return options;
}
public Map getMessages() {
return messages;
}
public Map getEnums() {
return enums;
}
public void setServices(Map services) {
this.services = services;
}
public Map getServices() {
return services;
}
/**
* Checks for validation errors in the proto definition and fills them
* into the errors list.
*
* @return
*/
public void validate(List errors) {
for (ProtoDescriptor o : importProtoDescriptors.values()) {
o.validate(errors);
}
for (OptionDescriptor o : options.values()) {
o.validate(errors);
}
for (MessageDescriptor o : messages.values()) {
o.validate(errors);
}
for (EnumDescriptor o : enums.values()) {
o.validate(errors);
}
for (MessageDescriptor o : extendsList) {
o.validate(errors);
}
for (ServiceDescriptor o : services.values()) {
o.validate(errors);
}
}
public List getImports() {
return imports;
}
public void setImports(List imports) {
this.imports = imports;
}
public Map getImportProtoDescriptors() {
return importProtoDescriptors;
}
public void setImportProtoDescriptors(Map importProtoDescriptors) {
this.importProtoDescriptors = importProtoDescriptors;
}
public TypeDescriptor getType(String type) {
for (MessageDescriptor o : messages.values()) {
if( type.equals(o.getName()) ) {
return o;
}
if( type.startsWith(o.getName()+".") ) {
return o.getType( type.substring(o.getName().length()+1) );
}
}
for (EnumDescriptor o : enums.values()) {
if( type.equals(o.getName()) ) {
return o;
}
}
// Check to see if the type was qualified with the package name...
for (ProtoDescriptor o : importProtoDescriptors.values()) {
if( o.getPackageName()!=null && type.startsWith(o.getPackageName()+".") ) {
return o.getType( type.substring(o.getPackageName().length()+1) );
}
}
for (ProtoDescriptor o : importProtoDescriptors.values()) {
TypeDescriptor rc = o.getType(type);
if (rc != null) {
return rc;
}
}
return null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}