Java Code Examples for javax.xml.bind.annotation.XmlElement

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project commons-j, under directory /src/main/java/nerds/antelax/commons/xml/saxbp/.

Source file: ParseInterest.java

  32 
vote

static Pair<QName,Class<?>> checkQName(final Method method) throws SAXBPException {
  final XmlElement element=method.getAnnotation(JAXBHandler.class).value();
  if (element.name() == null || element.name().trim().isEmpty())   throw new SAXBPException("Null or empty element name in [embedded] XmlElement annotation");
  final QName qName=new QName(element.namespace(),element.name());
  return new Pair<QName,Class<?>>(qName,checkAndGetJaxbClass(method));
}
 

Example 2

From project commons-j, under directory /src/main/java/nerds/antelax/commons/xml/.

Source file: JAXBUtils.java

  31 
vote

/** 
 * Checks a JAXB-annotated object to make sure all required data is present, however it does not check any data formatting constraints. Traverses the entire object graph to make sure sub-elements are also correctly populated.
 * @return <code>true</code> if all attributes and fields (and sub-fields) that are required are present, or if the object isnot a JAXB-generated class. Returns <code>false</code> otherwise.
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws IntrospectionException
 */
public static boolean hasAllRequiredData(final Object jaxb) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException, IntrospectionException {
  Preconditions.checkNotNull(jaxb);
  final Class<?> clazz=jaxb.getClass();
  final XmlAccessorType xmlAccessorType=clazz.getAnnotation(XmlAccessorType.class);
  final XmlType xmlType=clazz.getAnnotation(XmlType.class);
  if (xmlAccessorType == null)   return true;
  Preconditions.checkArgument(xmlAccessorType.value() == XmlAccessType.FIELD,"Only JAXB fields are supported at this time");
  if (xmlType == null)   return true;
  final String[] properties=combine(xmlType.propOrder(),xmlAttributeProperties(clazz));
  for (  final String property : properties) {
    final Field field=clazz.getDeclaredField(property);
    Preconditions.checkNotNull(field);
    final boolean isList=field.getType() == List.class;
    if (field.getAnnotation(XmlTransient.class) != null)     continue;
    final XmlElement elementAnnotation=field.getAnnotation(XmlElement.class);
    final XmlAttribute attributeAnnotation=field.getAnnotation(XmlAttribute.class);
    final boolean required=elementAnnotation != null ? elementAnnotation.required() : attributeAnnotation != null ? attributeAnnotation.required() : false;
    if (isList) {
      final List<?> list=(List<?>)getJaxbProperty(jaxb,property);
      final Boolean emptyList=(Boolean)findMethod(list,"isEmpty").invoke(list);
      if (required && emptyList)       return false;
 else       for (      final Object listElement : list)       if (!hasAllRequiredData(listElement))       return false;
    }
 else {
      final Object propertyValue=getJaxbProperty(jaxb,property);
      if (required && propertyValue == null)       return false;
 else       if (propertyValue != null)       if (!hasAllRequiredData(propertyValue))       return false;
    }
  }
  return true;
}
 

Example 3

From project entando-core-engine, under directory /src/main/java/org/entando/entando/aps/system/services/api/model/.

Source file: BaseApiResponse.java

  30 
vote

@XmlElement(name="result",required=false) public String getResult(){
  if (null != super.getResult()) {
    return super.getResult().toString();
  }
  return null;
}
 

Example 4

From project arquillian-rusheye, under directory /rusheye-api/src/main/java/org/jboss/rusheye/suite/.

Source file: ComparisonResult.java

  29 
vote

/** 
 * <p> Gets the rectangles. </p> <p> During first invocation of this method, new empty list of rectangles is created. </p>
 * @return the rectangles
 */
@XmlElement(name="rectangle") public List<Rectangle> getRectangles(){
  if (rectangles == null) {
    rectangles=new LinkedList<Rectangle>();
  }
  return rectangles;
}
 

Example 5

From project arquillian-rusheye, under directory /rusheye-api/src/main/java/org/jboss/rusheye/suite/.

Source file: Configuration.java

  29 
vote

/** 
 * Gets the list of all masks.
 * @return the list of all masks
 */
@XmlElement(name="mask") @Nullify(VisualSuiteResult.class) public List<Mask> getMasks(){
  if (masks == null) {
    masks=new ArrayList<Mask>();
  }
  return this.masks;
}
 

Example 6

From project cdk, under directory /generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/.

Source file: Child.java

  29 
vote

@XmlElement(namespace=Root.HTTP_FOO_BAR_SCHEMA) public Extension getExtension(){
  if (extension == null) {
    extension=new Extension();
  }
  return extension;
}
 

Example 7

From project chukwa, under directory /src/main/java/org/apache/hadoop/chukwa/rest/bean/.

Source file: ParametersBean.java

  29 
vote

@XmlElement public OptionBean[] getOptions(){
  if (options == null) {
    options=new OptionBean[1];
  }
  return options.clone();
}
 

Example 8

From project entando-core-engine, under directory /src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/model/.

Source file: SymbolicLink.java

  29 
vote

/** 
 * Imposta la destinazione del link sulla destinazione specificata. 
 * @param symbolicDestination Destinazione simbolica, ottenuta in precedenzatramite il corrispondente metodo get di questa stessa classe.
 * @return True se la stringa simbolica ? corretta, false se la stringa simbolica ? malformata.
 */
@XmlElement(name="symbolicDestination",required=true) public boolean setSymbolicDestination(String symbolicDestination){
  boolean ok=false;
  String params[]=this.extractParams(symbolicDestination);
  if (params != null) {
    if (params[0].equals("U")) {
      if (params.length >= 2) {
        int length=symbolicDestination.length();
        String urlDest=symbolicDestination.substring(4,length - 2);
        this.setDestinationToUrl(urlDest);
        ok=true;
      }
    }
 else     if (params[0].equals("P")) {
      if (params.length == 2) {
        this.setDestinationToPage(params[1]);
        ok=true;
      }
    }
 else     if (params[0].equals("C")) {
      ok=false;
      if (params.length == 2) {
        this.setDestinationToContent(params[1]);
        ok=true;
      }
    }
 else     if (params[0].equals("O")) {
      ok=false;
      if (params.length == 3) {
        this.setDestinationToContentOnPage(params[1],params[2]);
        ok=true;
      }
    }
 else {
      ok=false;
    }
  }
  return ok;
}
 

Example 9

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/sql/.

Source file: AbstractDatabase.java

  29 
vote

@XmlElement(name="property") private Property[] getXmlProperties(){
  List<Property> properties=new ArrayList<Property>(this.properties.size());
  for (  Map.Entry<String,String> entry : this.properties.entrySet()) {
    Property property=new Property();
    property.setName(entry.getKey());
    property.setValue(entry.getValue());
    properties.add(property);
  }
  return properties.toArray(new Property[properties.size()]);
}
 

Example 10

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/sql/.

Source file: AbstractDatabaseClusterConfiguration.java

  29 
vote

@XmlElement(name="sync") private SynchronizationStrategyDescriptor[] getSynchronizationStrategyDescriptors() throws Exception {
  List<SynchronizationStrategyDescriptor> results=new ArrayList<SynchronizationStrategyDescriptor>(this.synchronizationStrategies.size());
  SynchronizationStrategyDescriptorAdapter adapter=new SynchronizationStrategyDescriptorAdapter();
  for (  Map.Entry<String,SynchronizationStrategy> entry : this.synchronizationStrategies.entrySet()) {
    SynchronizationStrategyDescriptor result=adapter.marshal(entry.getValue());
    result.setId(entry.getKey());
    results.add(result);
  }
  return results.toArray(new SynchronizationStrategyDescriptor[results.size()]);
}
 

Example 11

From project jbpm-form-builder, under directory /jbpm-gwt-form-builder/src/main/java/org/jbpm/formbuilder/server/xml/.

Source file: PackageDTO.java

  29 
vote

@XmlElement public List<String> getAssets(){
  if (_assets == null) {
    _assets=new ArrayList<String>();
  }
  return _assets;
}
 

Example 12

From project jbpm-form-builder, under directory /jbpm-gwt-form-builder/src/main/java/org/jbpm/formbuilder/server/xml/.

Source file: PackageListDTO.java

  29 
vote

@XmlElement public List<PackageDTO> getPackage(){
  if (_package == null) {
    _package=new ArrayList<PackageDTO>();
  }
  return _package;
}
 

Example 13

From project maven-deployit-plugin, under directory /spring-petclinic/src/main/java/org/springframework/samples/petclinic/.

Source file: Vets.java

  29 
vote

@XmlElement public List<Vet> getVetList(){
  if (vets == null) {
    vets=new ArrayList<Vet>();
  }
  return vets;
}
 

Example 14

From project MCStats3, under directory /src/com/ubempire/MCStats3/model/.

Source file: PlayerStatistics.java

  29 
vote

@XmlElement public boolean getIsOnline(){
  Player player=StatsPlugin.currentServer.getPlayer(playerName);
  if (player != null) {
    return player.isOnline();
  }
 else {
    return false;
  }
}
 

Example 15

From project MCStats3, under directory /src/com/ubempire/MCStats3/model/.

Source file: PlayerStatistics.java

  29 
vote

@XmlElement public String getSessionPlaytime(){
  if (getIsOnline()) {
    long seccondsInSession=(new Date().getTime() - lastLogin.getTime()) / 1000;
    return secondsToTimestamp(seccondsInSession);
  }
 else {
    return "";
  }
}
 

Example 16

From project Places, under directory /standardize/src/main/java/org/folg/places/standardize/.

Source file: Place.java

  29 
vote

@XmlElement public String getFullName(){
  StringBuilder buf=new StringBuilder();
  if (standardizer != null) {
    buf.append(getName());
    int locatedIn=getLocatedInId();
    while (locatedIn > 0) {
      Place p=standardizer.getPlace(locatedIn);
      buf.append(", ");
      buf.append(p.getName());
      locatedIn=p.getLocatedInId();
    }
  }
  return buf.toString();
}
 

Example 17

From project portalexample, under directory /src/main/java/org/entando/entando/portalexample/aps/system/services/card/api/.

Source file: CardsResponseResult.java

  29 
vote

@XmlElement(name="items",required=false) public ListResponse<Card> getResult(){
  if (this.getMainResult() instanceof Collection) {
    List<Card> cards=new ArrayList<Card>();
    cards.addAll((Collection<Card>)this.getMainResult());
    ListResponse<Card> entity=new ListResponse<Card>(cards){
    }
;
    return entity;
  }
  return null;
}
 

Example 18

From project rave, under directory /rave-components/rave-jpa/src/main/java/org/apache/rave/portal/model/.

Source file: JpaRegion.java

  29 
vote

@SuppressWarnings("unused") @XmlElement(name="widget") private List<Widget> getWidgets(){
  ArrayList<Widget> widgets=new ArrayList<Widget>();
  for (  RegionWidget rw : regionWidgets) {
    widgets.add(rw.getWidget());
  }
  return widgets;
}
 

Example 19

From project showcase, under directory /src/main/java/org/richfaces/demo/common/navigation/.

Source file: DemoDescriptor.java

  29 
vote

@XmlElementWrapper(name="samples") @XmlElement(name="sample") public Collection<SampleDescriptor> getSamples(){
  if (samples == null) {
    return null;
  }
  return Collections2.filter(samples,new Predicate<SampleDescriptor>(){
    public boolean apply(    SampleDescriptor sample){
      return sample.isCurrentlyEnabled();
    }
  }
);
}
 

Example 20

From project showcase, under directory /src/main/java/org/richfaces/demo/common/navigation/.

Source file: GroupDescriptor.java

  29 
vote

/** 
 * "This method must be present for JAXB - you should be calling {link #getFilteredDemos} instead"
 */
@XmlElementWrapper(name="demos") @XmlElement(name="demo") public Collection<DemoDescriptor> getDemos(){
  if (demos == null) {
    return null;
  }
  return Collections2.filter(demos,new Predicate<DemoDescriptor>(){
    public boolean apply(    DemoDescriptor demo){
      return demo.hasEnabledItems();
    }
  }
);
}
 

Example 21

From project tools4j, under directory /support/support-jse/src/test/java/org/deephacks/tools4j/support/.

Source file: ClassIntrospectorTest.java

  29 
vote

@Test public void test1(){
  ClassIntrospector i=new ClassIntrospector(Test1.class);
  assertThat(i.getName(),is(Test1.class.getName()));
  assertThat(i.getAnnotation(XmlRootElement.class).name(),is("name"));
  Map<String,FieldWrap<XmlElement>> fields=i.getFieldMap(XmlElement.class);
  FieldWrap<XmlElement> f=fields.get("var1");
  assertThat(f.getFieldName(),is("var1"));
  assertEquals(f.getType(),String.class);
  assertNull(f.getDefaultValue());
  f=fields.get("var2");
  assertThat(f.getFieldName(),is("var2"));
  assertEquals(f.getType(),Boolean.class);
  assertNull(f.getDefaultValue());
  f=fields.get("var3");
  assertThat(f.getFieldName(),is("var3"));
  assertTrue(f.isCollection());
  assertEquals(f.getCollRawType(),List.class);
  assertEquals(f.getType(),String.class);
  assertNull(f.getDefaultValues());
  f=fields.get("var4");
  assertThat(f.getFieldName(),is("var4"));
  assertTrue(f.isCollection());
  assertEquals(f.getCollRawType(),List.class);
  assertEquals(f.getType(),Test2.class);
  Collection<?> values=f.getDefaultValues();
  Test2 value=(Test2)values.iterator().next();
  assertThat(1.0,is(value.var1));
  assertThat(2,is(value.var2));
  assertThat(2,is(value.units.size()));
  f=fields.get("var5");
  assertThat(f.getFieldName(),is("var5"));
  assertTrue(f.isCollection());
  assertEquals(f.getCollRawType(),Set.class);
  assertEquals(f.getType(),Double.class);
  assertNull(f.getDefaultValue());
}
 

Example 22

From project YAMA, under directory /src/main/java/org/papaours/yama/model/.

Source file: AbstractYamaQuestion.java

  29 
vote

/** 
 * Returns whether the  {@link AbstractYamaQuestion} answers are shuffled or not as an integer.
 * @return 1 for true and 0 for false
 */
@XmlElement(name="shuffleanswers") public String isShuffledString(){
  String requestedShuffled="false";
  if (isShuffled) {
    requestedShuffled="true";
  }
  return requestedShuffled;
}
 

Example 23

From project YAMA, under directory /src/main/java/org/papaours/yama/model/.

Source file: AbstractYamaQuestion.java

  29 
vote

/** 
 * Returns whether the  {@link AbstractYamaQuestion} is hidden or not as an integer.
 * @return 1 for true and 0 for false
 */
@XmlElement(name="hidden") public String isHiddenString(){
  String requestedHidden="false";
  if (isHidden) {
    requestedHidden="true";
  }
  return requestedHidden;
}